akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll n;
    cin >> n;
    vector<ll> h(n+2);
    h.at(0)=0;
    h.at(n+1)=0;
    rep(i,n) cin >> h.at(i+1);
    ll ans=0;
    while(h.size()>2){
        rep(i,h.size()-2){
            if(h[i] < h[i+1] && h[i+1] > h[i+2]){
                ans += h[i+1] - max(h[i],h[i+2]);
                h.erase(h.begin()+i+1);
                break;
            }
        }
        rep(i,h.size()-1){
        if(h.at(i) == h.at(i+1)){
            h.erase(h.begin()+i);
            break;
        }
    }
    }
    cout << ans << endl;
}

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

using namespace std;

int m[20], x[20][20], y[20][20];
int n;
int temp[20];

int find(int mask){
	memset(temp,-1,sizeof temp);
	for(int i=0; i<n; i++){
		int vv = (mask & (1 << i)) > 0 ? 1 : 0;
		if(temp[i] == -1) temp[i] = vv;
		if(temp[i] != vv) return -1;
		if(temp[i] == 0) continue;
		for(int j=0; j<m[i]; j++){
			int id = x[i][j]-1;
			int v = y[i][j];
			if(temp[id] != -1 && temp[id] != v) return -1;
			temp[id] = v;
		}
	}
	int ret = 0;
	for(int i=0; i<n; i++) if(temp[i] == 1) ret++;
	return ret;
}


int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> m[i];
		for(int j=0; j<m[i]; j++) cin >> x[i][j] >> y[i][j];
	}
	int maxi = 1 << n;
	int ans = 0;
	for(int mask=0; mask < maxi; mask++) ans = max(ans, find(mask));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int compare(const void *a,const void *b){
  return *(long*)a - *(long*)b;
}

int main(){
  long n = 0;
  long a[100000] = {};
  long num[100000] = {};
  long kosu[100000] = {};
  
  long i = 0;
  long cnt = 0;
  long rmv = 0;
  
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
    //printf("%ld**",a[i]);
  }
  qsort(a,n,sizeof(long),compare);
  /*for(i=0;i<n;i++){
    printf("%ld",a[i]);
  }*/
  num[0] = a[0];
  kosu[0] = 1;
  for(i=1;i<n;i++){
    if(num[cnt] == a[i]){
      kosu[cnt]++;
    }else{
      cnt++;
      num[cnt]=a[i];
      kosu[cnt]=1;
    }
  }
  
  /*for(i=0;i<=cnt;i++){
    printf("%ld %ld #",num[i],kosu[i]);
  }*/
  for(i=0;i<=cnt;i++){
    if(num[i] > kosu[i]){
      rmv += kosu[i];
    }else{
      rmv += kosu[i] - num[i];
    }
  }
  if(n==0){
    rmv = 0;
  }
  printf("%ld",rmv);
  return 0;
}
  

Measured memory_bytes: 3324
#include <iostream>
#include <vector>

using namespace std;

void print(vector<int32_t> v) {
    for (uint32_t i = 0; i < v.size() - 1; i++) {
        cout << v[i] << " ";
    }
    cout << v[v.size() - 1] << endl;
}

int main() {
    int32_t N, steps = 0;

    cin >> N;

    vector<int32_t> A(N);

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

    for (int32_t i = 0; i < N; i++) {
        for (int32_t j = N - 1; j > i; j--) {
            if (A[j] < A[j - 1]) {
                int32_t temp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = temp;
                steps++;
            }
        }
    }

    print(A);
    cout << steps << endl;

    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	sort(a.rbegin(),a.rend());
	int ans=1e9,dif=1e9,opt=(a.front()+1)/2;
	for(auto&&i:a){
		int tdif=abs(opt-i);
		if(tdif<dif)dif=tdif,ans=i;
		else if(tdif==dif&&i<ans)ans=i;
	}
	cout<<a.front()<<" "s<<ans<<"\n"s;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, n, a) for(int i=n; i>=a; i--)
#define lep(i, n, a) for(int i=n; i>a; i--)
#define mem(a, b) memset(a, b, sizeof(a))
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rlf(a) scanf("%lf", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define al(x)  x + 1, x + 1 + n
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vii vector<pii>
#define pb push_back
#define MP make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fi first
#define se second
#define inf 0x3f3f3f3f
const int maxn = 3e5 + 10;
const int maxm = 5e5 + 10;
const ll mod = 10007;
const double pi = acos(-1.0);
const double eps = 1e-8;




int main(){
  ll n, u, v;
  rlld(n);
  ll ans = n * (n + 1) * (n + 2) / 6;
  for(int i = 1; i < n; i ++){
    rlld(u), rlld(v);
    if(u > v) swap(u, v);
    ans -= u * (n - v + 1);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3788
#include <iostream>

int main()
{
        while(true)
        {
                std::string str;
                std::cin >> str;

                if(str[0] == '0')       break;

                int ans = 0;
                for(int i=0;i<str.size();i++)
                {
                        ans += (str[i] - '0');
                }
                std::cout << ans << std::endl;
        }
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,p;
  int i,j,ctr=0,minctr=1e9;
  cin>>s>>p;
  for(i=0;i<(s.length()-p.length()+1);i++)
  {
    ctr=0;
    for(j=0;j<p.length();j++)
    {
      if(s[i+j]!=p[j])
      {
        ctr++;
      }
    }
    minctr=min(minctr,ctr);
  }
  cout<<minctr;
  return 0;
}
    

Measured memory_bytes: 3600
#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<int, int> P;

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    int n; cin >> n;
    char f[2][n];
    rep(i,2) rep(j,n) cin >> f[i][j];
    ll ans = 1;
    rep(i,n){
        if(i == 0){
            ans *= 3;
            if(f[0][i] != f[1][i]) ans *= 2;
        }else{
            if(f[0][i-1] == f[0][i]) ans *= 1;
            else {
                if(f[0][i] == f[1][i] && f[0][i-1] != f[1][i-1]) ans *= 1;
                else if(f[0][i] != f[1][i] && f[0][i-1] != f[1][i-1]) ans *= 3;
                else ans *= 2;
            }
        }
        ans %= mod;
    }
    cout << ans << endl;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    vector<long long int> v;
    while(n--){
    	long long int x;
    	cin>>x;
    	v.push_back(x);
	}
	sort(v.begin(),v.end());
	long long int sum=0;
	for(long long int i=0;i<k;i++){
		sum+=v[i];
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3628
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

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

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

use std::collections::HashSet;
fn main() {
    input! {
        n: u32,
        d: [u32; n],
    };
    println!("{}", d.iter().collect::<HashSet<_>>().len());
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<double> money(N);
    vector<string> unit(N);
    for(int d = 0;d < N; d++){
        cin >> money.at(d) >>unit.at(d);
    }
    double sum = 0;
    for(int g = 0;g < N;g++){
        if(unit.at(g) == "JPY"){
            sum += money.at(g);
        }
        if(unit.at(g) == "BTC"){
            sum += money.at(g)*380000.0;
        }

    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def binary_search(l, r, pred):
    while l < r:
        mid = (l + r) // 2
        if pred(mid):
            r = mid
        else:
            l = mid + 1
    return l


def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]"):
    ans = 0
    cA = [0] * (N + 1)
    cB = [0] * (M + 1)
    for i, a in enumerate(A):
        cA[i + 1] = cA[i] + a
    for i, b in enumerate(B):
        cB[i + 1] = cB[i] + b
    if cA[-1] + cB[-1] <= K:
        print(N + M)
        return

    def min_time(x):
        # x個選んだときの最小時間
        return min((cA[i] + cB[x - i] for i in range(N + 1) if 0 <= x - i <= M))

    ans = binary_search(0, N + M, lambda x: min_time(x) > K) - 1
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, K, A, B)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63168
#include<iostream>
using namespace std;
int main()
{

    string s;
    cin>>s;
    int count1=0;
    for(int i=0;i<=s.size();i++)
    {
        if(s[i]=='+')
        {
            count1++;
        }
        if(s[i]=='-')
        {
            count1--;
        }

    }
    cout<<count1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second

void solve(void){
	int N, ans = 0;
	string S;
	cin >> N >> S;
	rep(N-1, i) {
		set <int> s;
		vector <bool> flag(26, false);
		int tmp = 0;
		rep(N, j) {
			if (j <= i) s.insert(S[j]-'a');
			else if (!flag[S[j]-'a'] && s.count(S[j]-'a')){
				tmp++;
				flag[S[j]-'a'] = true;
			}
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())
s=[[]*N for i in range(2)]
s[0]=input()
s[1]=input()

prev=0#タテなら1 ヨコなら-1
ans=1
i=0
while i!=N:
    if s[0][i]==s[1][i]:
        if prev==1:
            ans=ans*2
        elif prev==-1:
            pass
        else:
            ans=ans*3
        prev=1
    else:
        if prev==1:
            ans=ans*2
        elif prev==-1:
            ans=ans*3
        else:
            ans=ans*6
        prev=-1
        i+=1
    i+=1
print(ans%(10**9+7))

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static char check(char ch[]) {
		int i;
		for(i=0;i<9;i+=3){//tate
			if(ch[i]==ch[i+1] && ch[i+1]==ch[i+2] && ch[i]!='s') return ch[i];
		}
		for(i=0;i<3;i++){//yoko
			if(ch[i]==ch[i+3] && ch[i+3]==ch[i+6] && ch[i]!='s') return ch[i];
		}
		i=0;//naname
		if(ch[i]==ch[i+4] && ch[i+4]==ch[i+8] && ch[i]!='s') return ch[i];
		
		i=2;	
		if(ch[i]==ch[i+2] && ch[i+2]==ch[i+4] && ch[i]!='s') return ch[i];	
		
		return 'd';
	}
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String str=sc.next();
			char ch[]=str.toCharArray();
			char ans=check(ch);
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 11000
gohyakuen_list = []
    hyakuen_list = []
    gojyuen_list = []

    for cnt in 0..gets.to_i do
        gohyakuen_list.push(500 * cnt)
    end
    for cnt in 0..gets.to_i do
        hyakuen_list.push(100 * cnt)
    end
    for cnt in 0..gets.to_i do
        gojyuen_list.push(50 * cnt)
    end
    # print(gohyakuen_list)
    # print(hyakuen_list)
    # print(gojyuen_list)

    target_amount = gets.to_i
    result_cnt = 0 

    gohyakuen_list.each do |gohyakuen|
        next if gohyakuen > target_amount
        hyakuen_list.each do |hyakuen|
            next if gohyakuen + hyakuen > target_amount
            gojyuen_list.each do |gojyuen|
                result_cnt = result_cnt + (gohyakuen + hyakuen + gojyuen == target_amount ? 1 : 0)
            end
        end
    end

    print(result_cnt)

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int max_n = 200005;

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

	int n, c;
	cin >> n >> c;

	int s[n], t[n], cc[n];
	rep(i, n){
		cin >> s[i] >> t[i] >> cc[i];
		s[i] = 2*s[i] - 1;
		t[i] = 2*t[i];
		cc[i]--;
	}

	int prog[max_n];
	rep(i, max_n) prog[i] = 0;

	rep(i, c){

		int cp[max_n];
		rep(j, max_n) cp[j] = 0;

		rep(j, n){
			if(cc[j] == i){
				cp[s[j]]++;
				cp[t[j]]--;
			}
		}

		rep(j, max_n-1){
			cp[j+1] += cp[j];
		}

		// rep(j, 200) cout << cp[j];
		// cout << endl;		

		rep(j, max_n){
			if(cp[j] > 0) prog[j]++;
		}
	}

	int ans = 0;
	rep(i, max_n) ans = max(ans, prog[i]);
	cout << ans << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,D;
  cin>>N>>D;
  
  vector<vector<int>> vec(N,vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>vec[i][j];
    }
  }
  
  int ans=0;
  
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int x=0;
      for(int k=0;k<D;k++){
        x+=(vec[i][k]-vec[j][k])*(vec[i][k]-vec[j][k]);
      }
      for(int l=0;l<200;l++){
        if(x==l*l){
          ans++;
          break;
        }
      }
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  int n = s.size();
  if( n % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  for(int i = 0; i < n / 2; i++) {
    string t = s.substr(2 * i, 2);
    if(t != "hi") {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			break;
		}
	}
	return 0;
}


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

int **w, **h, **t;

void init(){
  w = new int*[3]; h = new int*[3]; t = new int*[3];
  for(int i = 0; i < 3; i++){
    w[i] = new int[3];  h[i] = new int[3];  t[i] = new int[3];
  }
  
  scanf("%d %d %d", &w[0][0], &w[0][1], &w[0][2]);
  scanf("%d %d %d", &h[0][0], &h[0][1], &h[0][2]);
  scanf("%d %d %d", &w[1][0], &w[1][1], &w[1][2]);
  scanf("%d %d %d", &h[1][0], &h[1][1], &h[1][2]);
  scanf("%d %d %d", &w[2][0], &w[2][1], &w[2][2]);
  scanf("%d %d %d", &h[2][0], &h[2][1], &h[2][2]);
}

void solve(int i){
  //cal second
  if(w[i][2] > h[i][2]){
    t[i][2] = h[i][2] + 60 - w[i][2];
    h[i][1]--;
  }else{
    t[i][2] = h[i][2] - w[i][2];
  }

  //cal min
  if(w[i][1] > h[i][1]){
    t[i][1] = h[i][1] + 60 - w[i][1];
    h[i][0]--;
  }else{
    t[i][1] = h[i][1] - w[i][1];
  }

  //cal hour
  t[i][0] = h[i][0] - w[i][0];

  printf("%d %d %d\n", t[i][0], t[i][1], t[i][2]);
}

int main(void){
  init();
  for(int i = 0; i < 3; i++){
    solve(i);
  }
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
using std::cin;
using std::cout;
using std::endl;
using std::ios;

long long int absolute(long long int input) {
    if(input < 0) {
        return input * -1;
    } else {
        return input;
    }
}


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

    int D, N;
    cin >> D >> N;
    int divisible[3] = {1, 100, 10000};
    int ans = 0;
    rep(i , N) {
        ans += divisible[D];
    }

    if((ans / divisible[D]) % 100 == 0) ans += divisible[D];

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int n, k, A[200000];
    scanf("%i%i", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%i", A + i);
        if (i >= k && A[i - k] >= A[i]) {
            printf("No\n");
        }
        if (i >= k && A[i - k] < A[i]) {
            printf("Yes\n");
        }
    }
}


Measured memory_bytes: 2400
var input=require("fs").readFileSync("/dev/stdin","utf8");
var x,cnt=0;

input=input.split(" ");
var a=parseInt(input[0]);
var b=parseInt(input[1]);
var c=parseInt(input[2]);

for(x=a;x<=b;x++){
    if(c%x==0){
        cnt++;
    }
}

console.log(cnt);


Measured memory_bytes: 15128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<limits>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define INF 1e9
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int n;
  int data[300001];
  ll s1[300001] = {0};
  ll s2[300001] = {0};
  
  scanf("%d", &n);
  REP(i, 1, 3 * n + 1) scanf("%d", data+i);
  
  priority_queue<int> q;
  
  REP(i, 1, n+1){
    q.push(-data[i]);
    s1[n]+= data[i];
  }

  REP(i, n+1, 2 * n + 1){
    s1[i] = s1[i-1];
    q.push(-data[i]);
    s1[i] += data[i];
    int _min = q.top();
    s1[i] += _min;
    q.pop();
  }

  //q = priority_queue<int>();
  priority_queue<int> q2;
  
  for(int i = 3 * n ; i > 2 * n ; i--){
    q2.push(data[i]);
    s2[2*n+1] += data[i];
  }
  
  for(int i = 2 * n ; i > n ; i--){
    s2[i] = s2[i+1];
    q2.push(data[i]);
    s2[i] += data[i];
    int _max = q2.top();
    s2[i] -= _max;
    q2.pop();
  }
  
  ll _max = numeric_limits<ll>::min();
  REP(i, n, 2*n+1){
    //printf("%d\n", s1[i]);
    //printf("%d\n", s2[i+1]);
    _max = max(_max, s1[i] - s2[i+1]);
  }

  printf("%lld\n", _max);
}


Measured memory_bytes: 7288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define mod (1000000007)
void solve() 
{
    ll n;cin>>n;
    string s;cin>>s;
    map<int,int>g;
    REP(i,n)g[s[i]]++;
    ll ans=1;
    REP(i,26)(ans*=g['a'+i]+1)%=mod;
    cout<<ans-1<<endl;
}

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

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>

int main() {
	std::string s, t;

	std::cin >> s >> t;

	std::cout << t << s << std::endl;

	return 0;
}

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

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

		int n = sc.nextInt();
		int[] a = new int[n];
		int sum = 0;

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}

		int sumA = 0;

		Arrays.sort(a);

		for (int i = n - 1; i >= 0; i -= 2) {
			sumA += a[i];
		}

		System.out.println(2 * sumA - sum);
	}

}


Measured memory_bytes: 21204
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    ios::sync_with_stdio(false);

    int N[4];
    for(int i=0; i<4; i++){
        cin >> N[i];
    }
    sort(N, N+4);
    if(N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) cout << "YES" << endl;
    else cout << "NO" << endl;


    return 0;
}

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

int main(void){
  int N, Y;
  cin >> N >> Y;
  for(int i = 0; i <= N; i++){
    for(int j = 0; i+j <= N; j++){
      int k = N - i - j;
      if(i * 10000 + j * 5000 + k * 1000 == Y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


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

using namespace std;

#define LCM(a,b)                (a / __gcd(a,b) ) *b
#define GCD(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define LL                      long long
#define ULL                     unsigned long long
#define pb                      push_back
#define tcase                   cout<<"Case "<<C++<<": ";
#define all(a)                  a.begin(),a.end()
#define Unique(a)               sort(all(a)),a.erase(unique(all(a)),a.end
#define ABS(x)                  ((x)<0?-(x):(x))
#define min3(a,b,c)             min(a,min(b,c))
#define min4(a,b,c,d)           min(a,min(b,min(c,d)))
#define max3(a,b,c)             max(a,max(b,c))
#define max4(a,b,c,d)           max(a,max(b,max(c,d)))
#define PI                      acos(-1.0)
#define ff                      first
#define ss                      second
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define FastRead                ios_base::sync_with_stdio(0);cin.tie(NULL);
#define FOR(x, l, r)            for (int x = l; x<=r; ++x)
#define REP(x,r)               for (int x = 0; x <r; ++x)
#define NN                      cout<<"\n";
#define NNN                     cout<<"\n------------------------------\n";

//***********************************************************************//
//                      SHAHED AHMED, CSE'15, IUT                        //
//***********************************************************************//


int  a[100010];
int b[100010];
int c[100010];

int hp[100010][3];

int main()
{
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
                cin>>a[i]>>b[i]>>c[i];
        }
        // type : 0 --> a, 1 --> b, 2 --> c
        hp[1][0]= a[1];
        hp[1][1]=  b[1];
        hp[1][2] = c[1];

        for(int i=2;i<=n;i++)
        {
                hp[i][0] = a[i] + max(hp[i-1][1],hp[i-1][2]);

                hp[i][1] = b[i] + max(hp[i-1][0],hp[i-1][2]);

                hp[i][2] = c[i] + max(hp[i-1][0],hp[i-1][1]);

        }

        cout<<max3(hp[n][0],hp[n][1],hp[n][2]);
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

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

    string t, s;
    cin >> t >> s;

    int dp[1010][1010];
    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;

    REP(i, Size(t))
    {
        REP(j, Size(s) + 1)
        {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;

            if(t[i] == s[j])
            {
                dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD;
            }
        }
    }

    Cout(dp[Size(t)][Size(s)] % MOD);

    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int cnt, A[500010];

void mergeSort(int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    cnt += right - left;
  }
}

int main() {
  int N;
  scanf("%d", &N);
  REP(i, N) scanf("%d", A+i);
  mergeSort(0, N);
  sort(A, A + N);
  REP(i, N) {
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n%d\n", cnt);
  return 0;
}

Measured memory_bytes: 3144
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
using ll = int64_t; using ull = uint64_t; using ld = long double;

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

const int N = 1e5 + 5;
int n, m;
vector<int> g[N];
int vis[N];
deque<int> path;

int main() {
    fast_io;
    cin >> n >> m;
    int a, b;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    path.push_front(a); vis[a] = 1;
    path.push_back(b); vis[b] = 1;
    found_front:
    for (auto &u : g[path.front()]) {
        if (vis[u]) continue;
        vis[u] = 1;
        path.push_front(u);
        goto found_front;
    }
    found_back:
    for (auto &u : g[path.back()]) {
        if (vis[u]) continue;
        vis[u] = 1;
        path.push_back(u);
        goto found_back;
    }
    cout << path.size() << '\n';
    for (auto &u : path) {
        cout << u << ' ';
    }
    cout << '\n';
}


Measured memory_bytes: 7168
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		new Main();	
	}

	public Main() {
		while(sc.hasNext()){
			new aoj1153().doIt();
		}
	}
	class aoj1153 {
		void doIt() {
			while(true){
				int n = sc.nextInt();
				ArrayList<Integer> array = new ArrayList<Integer>();
				if(n == 1)break;
				System.out.print(n+":");
				for(int i = 0;i <= n;i++){
					if(i == 1)continue;
					boolean sosu = true;
					if(i % 7 == 1 || i % 7 == 6){
						if(n % i == 0){
							for(int j = 0;j < array.size();j++){
								if(i % array.get(j) == 0)sosu = false;
							}
							if(sosu){
								array.add(i);
								System.out.print(" "+i);
							}
						}
					}
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 23836
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    n = int(input())
    s = input()
    r = [0] * n
    g = [0] * n
    b = [0] * n
    if s[0] == 'R':
        r[0] = 1
    elif s[0] == 'G':
        g[0] = 1
    else:
        b[0] = 1
    for i, v in enumerate(s[1:]):
        if v == 'R':
            r[i+1] = 1
        elif v == 'G':
            g[i+1] = 1
        else:
            b[i+1] = 1
        r[i+1] += r[i]
        g[i+1] += g[i]
        b[i+1] += b[i]
    ans = 0
    for j, v in enumerate(s[:-1]):
        if j == 0:
            continue
        if v == 'R':
            ans += g[j-1] * (b[-1] - b[j]) + b[j-1] * (g[-1] - g[j])
        elif v == 'G':
            ans += r[j-1] * (b[-1] - b[j]) + b[j-1] * (r[-1] - r[j])
        else:
            ans += r[j-1] * (g[-1] - g[j]) + g[j-1] * (r[-1] - r[j])
        for d in range(1, j + 1):
            i = j - d
            k = j + d
            if i < 0 or k >= n:
                break
            if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                ans -= 1
    print(ans)

main()

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    int a, b;
    cin >> a >> b;

    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3632
///Nahid Hasan Raju
#include <bits/stdc++.h>
#define ll long long
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
using namespace std;

#define P1(XX) cerr<<"db1: "<<XX<<endl
#define P2(XX,YY) cerr<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cerr<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007ll
#define MX 2000006  ///200005


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

ll m, n;
ll a[MX], b[MX];
string s,s1;
map<ll,int>mp;

///cerr<<   how to use it?
int main()
{
    #ifndef ONLINE_JUDGE
    Fin;
    #endif
    int test=1, tc=0, i, j;
    ll k, ans;
    ll c,p;
    //scanf("%d", &test);
    //precalc(1);
    while(test--)
    {
        ans=1;
        ll pp=7;
        cin>>n;
        while(pp<n){
            pp*=10;
            pp+=7;
            ans++;
        }
        c=0;
        while(pp%n!=0)
        {
            mp[pp]=1;
            pp%=n;
            pp*=10;
            pp+=7;
            if(mp[pp]==1){
                c=1;
                break;
            }
            ans++;
        }
        if(c)puts("-1");
        else printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 66100
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){

       string n;
       cin>>n;
       int sum=0,a;
       for(int i=0;i<n.size();i++){
        char c=n[i];
       a=(int)c-48;
       sum+=a;

       }
       //cout<<sum<<endl;
       if(sum%9==0){
        cout<<"Yes"<<endl;
       }
       else{
        cout<<"No"<<endl;
       }
}



Measured memory_bytes: 3716
n=int(input())
*a,=map(int,input().split())
s=list(set(a))
s.sort()
ans="No"
if len(s)==1:
  if 0 in s:
    ans="Yes"
elif len(s)==2:
  if a.count(0)*2==a.count(s[1]):
    ans="Yes"
elif len(s)==3 and a.count(s[0])==a.count(s[1])==a.count(s[2]) and s[0]^s[1]^s[2]==0:
  ans="Yes"
print(ans)

Measured memory_bytes: 14116
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>

using namespace std;


int main() {

	vector<string> subs;
	string n;
	string s,t;
	char backs;
	bool flag = true;
	int k;
	cin >> s >> k;
	t = s;
	sort(t.begin(), t.end());
	for (auto& ab : t) {
		if (flag) {
			flag = false;
		}
		else {
			if (backs == ab) {
				continue;
			}
		}
		if (k == 1) {
			cout << ab << endl;
			return 0;
		}
		backs = ab;
		n = backs;
		subs.push_back(n);
		for (int i = 0; i < s.length();i++) {
			if (ab == s[i]) {
				n = ab;
				for (int j = i+1; j < i+k ;j++) {
					if (j >= s.length())
						break;
					n += s[j];
					subs.push_back(n);
				}
			}
		}
		sort(subs.begin(),subs.end());
		n = subs[0];
		k--;
		for (auto& sss : subs) {
			if (sss != n) {
				k--;
				if (k == 0) {
					cout << sss << endl;
					return 0;
				}
				n = sss;
			}
		}
		subs.clear();
	}
	

	return 0;
}

Measured memory_bytes: 1404
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include <sstream>
using namespace std;
int main(void){
    double a,b,c,d,e,f,x,y;
    while(cin >> a >> b >> c >> d >> e >> f){
        x=(e*c-b*f)/(a*e-b*d);
        y=(-d*c+a*f)/(a*e-b*d);
        if(x==0)x=0;
        if(y==0)y=0;
        cout<<fixed<<setprecision(3)<<x<<" "<<fixed<<setprecision(3)<<y<<endl;
    }
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 100005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(time(0));

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int num_nodes,M;
ll dp[MAXN],ans[MAXN],pref[MAXN],suff[MAXN];
vector<int> connections[MAXN];
vector<ll> v[MAXN];

ll dfs(int node, int prev){
	dp[node] = 1;
	for(int check:connections[node]){
		if(check == prev) continue;
		dp[node] = (dp[node]*(dfs(check,node)+1))%M;
	}
	return dp[node];
}

ll solve(int node, int prev){
	ans[node] = dp[node];
//	pref[node].resize(connections[node].size()+2);
//	suff[node].resize(connections[node].size()+2);
	pref[0] = suff[connections[node].size()+1] = 1;

	for(int i=1; i<=connections[node].size(); i++){
		int check = connections[node][i-1];
//		if(check == prev) continue;
		pref[i] = (pref[i-1]*(dp[check]+1))%M;
	}
	for(int i=(int)connections[node].size(); i>=1; i--){
		int check = connections[node][i-1];
//		if(check == prev) continue;
		suff[i] = (suff[i+1]*(dp[check]+1))%M;
	}
	v[node].resize(connections[node].size()+2);
	for(int i=1; i<=connections[node].size(); i++)
		v[node][i] = (pref[i-1]*suff[i+1])%M;
	ll ov1 = dp[node];
	for(int i=1; i<=connections[node].size(); i++){
		int check = connections[node][i-1];
		if(check == prev) continue;
		ll o_v = dp[check];

		ll n_v = v[node][i];
		dp[node] = n_v;

		n_v = ((n_v+1)*dp[check])%M;
		dp[check] = n_v;

		solve(check,node);
		dp[check] = o_v;
		dp[node] = ov1;
	}
}

int main(){
	scanf("%d %d",&num_nodes,&M);
	for(int i=1; i<num_nodes; i++){
		int a,b; scanf(" %d %d",&a,&b);
		connections[a].pb(b);
		connections[b].pb(a);
	}
	dfs(1,-1);
	solve(1,-1);
	for(int i=1; i<=num_nodes; i++)
		printf("%lld\n",ans[i]);
}

Measured memory_bytes: 23168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

bool cmp(int a, int b){
    return a>b;
}

int main() {
    fast;
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0; i<n; i++) cin>>v[i];
    sort(v.begin(), v.end(), cmp);
    ll sum=0; int r=n-2;
    sum+=v[0];
    for(int i=1; i<v.size(); i++) {
        sum += v[i] * (min(r, 2));
        if(r<=1) break;
        r-=2;
    }
    cout<<sum<<'\n';
    return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
using namespace std;

typedef pair<int,int> P;

int main(){
	int N, K;
	cin >> N >> K;
	// v[i] := ボート i に乗るうさぎの番号. 
	vector<int> v[51];
	
	for(int i=0 ; i < K ; i++ ){
		int m;
		cin >> m;
		for(int j=0 ; j < m ; j++ ){
			int bunny;
			cin >> bunny;
			bunny--;
			v[i].push_back(bunny);
		}
	}
	
	// m[(i,j)] := うさぎ i と うさぎ j が仲が悪いかどうか.
	map<P,bool> m;
	for(int i=0 ; i < N ; i++ ){
		for(int j=0 ; j < N ; j++ ){
			m[P(i,j)] = false;
		}
	}
	// is_bad[i] := うさぎ i が気分が悪いかどうか.
	bool is_bad[101] = {false};
	
	int R;
	cin >> R;
	for(int i=0 ; i < R ; i++ ){
		int p, q;
		cin >> p >> q;
		p--; q--;
		m[P(p,q)] = m[P(q,p)] = true;
	}
	
	for(int k=0 ; k < K ; k++ ){
		for(int i=0 ; i < v[k].size() ; i++ ){
			for(int j=i+1 ; j < v[k].size() ; j++ ){
				int a = v[k][i], b = v[k][j];
				if( m[P(a,b)] ){
					is_bad[a] = is_bad[b] = true;
				}
			}
		}
	}
	int ans = 0;
	for(int i=0 ; i < N ; i++ ){
		if( is_bad[i] ) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 0
N=int(input())
suits=["S","H","C","D"]
cards=[]
for _ in range(N):
    s,n=input().split()
    if s=="S":
        cards.append(int(n))   
    elif s=="H":
        cards.append(13+int(n))   
    elif s=="C":
        cards.append(26+int(n))
    else:
        cards.append(39+int(n))

for i in range(1,53):
    if i not in cards:
        print(suits[(i-1)//13],(i-1)%13+1)


Measured memory_bytes: 5600
#if 0
date +%Y.%m.%d

假设已知 N 的长度 len ，考虑如何搞出 N 。
不难想到二分，但如果询问一个长度为 len 的 x ，那么得到的一定是 yes ，
因为相同长度的两个数的字典序比较和值比较无异。
但只要询问 10x ，10x 的长度为 len + 1 ，值一定比 N 大，
那么得到 yes 当且仅当 x 的值不比 N 小，可以据此二分。

现在的问题是得到 N 的长度，事实上只需要拿 10 的整次幂一个一个试即可。
特别的是当 N 是 10 的整次幂的情况无法据此得出长度，需要特判。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

bool query(ll x) {
	printf("? %lld\n", x);
	fflush(stdout);
	static char s[10];
	scanf("%s", s);
	return *s == 'Y';
}

int main() {
	ll test = 1;

	while(test <= 100000000000ll and query(test))
		test *= 10;

	if(test > 100000000000ll) {
		test = 9;
		while(!query(test))
			test = test * 10 + 9;
		printf("! %lld\n", test / 10 + 1);
		return 0;
	}

	ll l = test / 10, r = test - 1;
	while(l < r) {
		ll mid = (l + r) >> 1;
		if(query(mid * 10))
			r = mid;
		else
			l = mid + 1;
	}

	printf("! %lld\n", l);
}


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

char s[100001];

int main() {
  scanf("%s", s);
  int n = strlen(s);

  int ans = n;
  for (int i = (n+1)>>1; i < n; ++i) {
    if (s[i-1] != s[i] || s[n-i-1] != s[n-i]) {
      ans = i;
      break;
    }
  }

  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

int main() {
    int n, W; cin >> n >> W;
    long long dp[W + 1];
    memset(dp, 0, sizeof(dp));

    for(int i = 0; i < n; ++i) {
        int w, v; cin >> w >> v;
        if(w > W) continue;

        for(int j = W; j - w >= 0; --j) {
            dp[j] = max(dp[j], dp[j - w] + v);
        }
        // for(int j = 0; j <= W; ++j) {
        //     cout << dp[j] << " ";
        // }
        // cout << "\n";
    }
    long long ans = 0;
    for(int i = 0; i <= W; ++i) ans = max(ans, dp[i]);

    cout << ans;

    
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var (
		n int
	)

	fmt.Scan(&n)

	h := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	cnt := 1
	disabled := false

	for i := 1; i < n; i++ {
		for j := 0; j < i; j++ {
			if h[j] > h[i] {
				disabled = true
			}
		}
		if !disabled {
			cnt++
		}
		disabled = false
	}

	fmt.Print(cnt)

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
ll M = 1e9 + 7;

ll power(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1) res = (res*x)%M;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}

int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	ll n,k; cin>>n>>k;
	ll gcd[k+1];
	gcd[k]=1;
	ll ans = k;
	for(int i=k-1;i>=1;i--)
	{
	    gcd[i] = power((ll)k/i,n);
	    for(int j=2*i;j<=k;j+=i)
	    {
	        gcd[i] = gcd[i] - gcd[j];
	        if(gcd[i]<0) gcd[i] += M;
	    }
	    gcd[i] %= M;
	    ans = (ans + (ll)i*gcd[i])%M; 
	    
	}
	cout<<ans;
	
	
	
	return 0;
}


Measured memory_bytes: 4392
#include <iostream>
using namespace std;
int main(){
	int n,t,c[200],a[200],i,ans=10000;
	cin >> n >> t;
	for(i=0;i<n;i++){
		cin >> c[i] >> a[i];
		if(a[i]>t) continue;
		ans = min(ans,c[i]);
	}
	if(ans!=10000){
		cout << ans << endl;
	}else{
		cout <<"TLE" << endl;
	}
}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
print('R'*dx + 'U'*dy + 'L'*dx + 'D'*dy + 'D' + 'R'*(dx+1) +
      'U'*(dy+1) + 'L' + 'U' + 'L'*(dx+1) + 'D'*(dy+1) + 'R')


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int n;
main()
{
    while(cin>>n,n)
    {
        int ans=0;
        for(;n--;)
        {
            int a,b,c,w;cin>>a>>b>>c>>w;
            int s=a+b+c;
            if(s<=60&&w<=2)ans+=600;
            else if(s<=80&&w<=5)ans+=800;
            else if(s<=100&&w<=10)ans+=1000;
            else if(s<=120&&w<=15)ans+=1200;
            else if(s<=140&&w<=20)ans+=1400;
            else if(s<=160&&w<=25)ans+=1600;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3076
import sys

readline = sys.stdin.readline
N, M = map(int, readline().split())
A = [readline().rstrip() for _ in range(N)]
B = [readline().rstrip() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        if all(A[i+x][j:j+M] == B[x] for x in range(M)):
            print('Yes')
            sys.exit()
print('No')


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
ll n,m,v,p;
 
int main(){
  ll ans=-1;
  cin >> n >> m>>v>>p;
  vi a(n),sm(n);
  REP(i,n)cin>>a[i];
  
  sort(a.begin(), a.end());
  REP(i,n){
    if (i==0){
      sm[0]=a[0]; 
    }else{
      sm[i]=sm[i-1]+a[i];
    }
  }
 
  ll pmonmescore;
  pmonmescore=a[n-p];
  ll lastm=n-p+1;
  REP(i,n){
    if (pmonmescore==a[i]){
      lastm--;
    }
  }
  //ここでlastmはありうる問題を含めた最低番号
  if (lastm==0){
    cout<<n<<endl;
    return 0;
  }
 
  ll canusep=n-lastm;
  ll menseki=m*v;//使える面積
 
  //cout<<"lastm"<<lastm<<endl;
 
  REP(i,lastm){
    ll ii=lastm-i-1;
    if (a[ii]+m<pmonmescore){
      ans=ii;//ありえない番号をいれてbreak
      break;
    }
 
    ll maxscore=a[ii]+m;
    //auto Iter2 = upper_bound(a.begin(),a.end()-p+1, maxscore-1);
    //1,2,2,3・・のときl=3なら2が返る
    //ll henlen=Iter2-a.begin();
    //cout<<henlen<<endl;
    ll henlen=n-p+1;
 
    //使わないといけない面積計算
    menseki=m*(v-(p-1)-1-ii);
    if (menseki<0)
      menseki=0;
    //
    ll umemen//埋めないといけない面積
    =(henlen-1-ii)*(maxscore);
    umemen-=sm[henlen-1]-sm[ii];
 
    if (umemen<menseki){//であれば不可能。==までは大丈夫
      ans=ii;//ありえない番号をいれてbreak
      break;
    }
 
  }
 
//cout<<endl;
  cout<<(n-ans-1)<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  string c;
  cin >> N >> c;
  int a = 0, b = 0;
  rep(i,N) if (c[i] == 'R') a++;
  int ans = max(a, b);
  rep(i,N){
    if (c[i] == 'R') a--;
    else b++;
    int now = max(a, b);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3744