akhauriyash/Code-Regression huggingface dataset:
module.exports=function(r){var t={};function n(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return r[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=r,n.c=t,n.d=function(r,t,e){n.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:e})},n.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},n.t=function(r,t){if(1&t&&(r=n(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)n.d(e,o,function(t){return r[t]}.bind(null,o));return e},n.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return n.d(t,"a",t),t},n.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},n.p="",n(n.s=0)}([function(r,t,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,t){function n(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var n=[],e=!0,o=!1,u=void 0;try{for(var i,f=r[Symbol.iterator]();!(e=(i=f.next()).done)&&(n.push(i.value),!t||n.length!==t);e=!0);}catch(r){o=!0,u=r}finally{try{e||null==f.return||f.return()}finally{if(o)throw u}}return n}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var t=n(r[0].split(" ").map(function(r){return Number(r)}),2),e=t[0],o=t[1],u=r[1].split(" ").map(function(r){return Number(r)}),i=[],f=0;f<o;f++){var c=n(r[f+2].split(" ").map(function(r){return Number(r)}),2),l=c[0],a=c[1];i.push({b:l,c:a})}i.sort(function(r,t){return t.c-r.c}),u.sort(function(r,t){return r-t});for(var s=0,p=0;p<o&&!(s>=e||u[s]>=i[p].c);p++)for(lastb=i[p].b;lastb>0&&s<e&&!(u[s]>=i[p].c);)u[s]=i[p].c,s++,lastb--;for(var d=0,b=0;b<e;b++)d+=u[b];console.log(d)}},function(r,t){r.exports=require("fs")}]);

Measured memory_bytes: 56616
s = int(input())
a = [0] * (s+1)

if s == 1:
    print(0)
else:
    a[0]=1
    a[1]=0
    a[2]=0
    mod = 10**9+7
    for i in range(3,s+1):
        a[i] = a[i-1]+a[i-3]
    print(int(a[s] % mod))

Measured memory_bytes: 9164
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
using namespace std;
using ll = long long;
int main()
{
	ll h, w;
	cin >> h >> w;
	if (w == 1 || h == 1) {
		cout << 1 << endl;
	}
	else if (h % 2 == 1 && w % 2 == 1)	cout << setprecision(18) << ll(h*w) / ll(2) + 1 << endl;
	else {
		cout << setprecision(18) << h*w / ll(2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<ll> as(n), bs(n);
	as[0] = 1;
	rep(i,1,n){
		as[i] = as[i-1] + 2*n;
	}
	ll sum = as[0] + as[n-1];
	rep(i,0,n) bs[i] = sum - as[i];
	vi p(n);
	rep(i,0,n) cin >> p[i];
	trav(x, p) --x;
	rep(i,0,n)
		as[p[i]] += i;
	trav(x,as) cout << x << ' ';
	cout << endl;
	trav(x, bs) cout << x << ' ';
	cout << endl;
}

Measured memory_bytes: 1024
"use strict";
function Main(input) {
    const S = input.split("\n")[0];
    const len = S.length;
    let min = Number.MAX_SAFE_INTEGER;
    for (let n = 0; n < len - 3 + 1; n++) {
        const x = S.substr(n, 3) - 0;
        min = Math.min(min, Math.abs(753 - x));
    }

    console.log(min);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
#include <bits/stdc++.h>
/* #defineと書くとマクロが定義できる
   rep(i,n) { //処理 }　と書くとn回ループが回せるようにしている*/
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using ll = long long;

/* n個のボールから2個選ぶ組み合わせを計算する -> nC2
   mainメソッドの後ろに書くとエラーになるのでココに書く*/
ll choose2(ll n) {
  return n*(n-1)/2;
}

int main() {
  // 入力1行目をnで受け取る
  int n;
  cin >> n;

  /* 2行目以降がn行存在するので、サイズnの配列aに格納する
     vectorは便利な配列みたいなものらしい*/
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;

  /* それぞれの番号が何個存在するかをカウントし
     配列cntに格納する*/
  vector<int> cnt(n);
  rep(i,n) cnt[a[i]]++;

  ll total = 0;

  /* それぞれの番号の数から2個選ぶ組み合わせを計算する
     組み合わせの合計数が求められる(total)*/
  rep(i,n) {
    total += choose2(cnt[i]);
  }

  /* 現時点ではkを除外していないので
     ・除外していない状態の組み合わせを除算
     ・除外した(-1した）状態の組み合わせを加算
     することで求めたい数へと修正し、出力する
  */

  rep(i,n) {
    ll ans = total;
    ans -= choose2(cnt[a[i]]);
    ans += choose2(cnt[a[i]]-1);

    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4096
#include<stdio.h>
#define LEN 500000

void merge(int [], int, int, int);
void merge_sort(int [], int, int);

int n, S[LEN];
int count=0;

int main()
{
  int left, right;
  int i, j, k;

  //read S
  scanf("%d", &n);
  for(i=0; i<n; i++)scanf("%d", &S[i]);

  //Sort
  left=0;
  right=n;
  merge_sort(S, left, right);

  //print
  printf("%d ", S[0]);
  for(i=1; i<n-1; i++)  printf("%d ", S[i]);
  printf("%d\n%d\n", S[n-1], count);
  return 0;
}

//Marge method
void merge(int S[], int left, int mid, int right)
{
  int i, j, k;
  int n1=mid-left;
  int n2=right-mid;
  int L[LEN], R[LEN];

  for(i=0; i<n1; i++)L[i]=S[left+i];
  for(i=0; i<n2; i++)R[i]=S[mid+i];

  L[n1]=1000000001;
  R[n2]=1000000001;
  i=0;
  j=0;
  for(k=left; k<right; k++)
    {
      if(L[i]<=R[j])
        {
          count++;
          S[k]=L[i];
          i++;
        }
      else 
        {
          count++;
          S[k]=R[j];
          j++;
        }
    }
}

void merge_sort(int S[], int left, int right)
{
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      merge_sort(S, left, mid);
      merge_sort(S, mid, right);
      merge(S, left, mid, right);
    }
}

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

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  string result = "NG";
  int tmp = K;
  int count = 2;
  while (tmp <= B) {
  	if (tmp >= A && tmp <= B) {
      result = "OK";
      break;
    }
    tmp = count * K;
    count++;
  }
  cout << result << endl;
}


Measured memory_bytes: 3588
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

//main
int main(){
  string b;
  cin >> b;
  if(b=="A") cout << "T" << endl;
  else if(b=="T") cout<< "A" << endl;
  else if(b=="C") cout<< "G" << endl;
  else cout<< "C" << endl;
}


Measured memory_bytes: 256
//To infinity

#include <iostream>


using namespace std;

int main()
{
	char s[100];
	for(int i = 0; i < 100; i++)	s[i]=0;

	int k;

	cin >> s;
	cin >> k;

//2の5000兆乗は少なくとも500兆桁の数であるが，kは最大18桁である．
//s[k-1]までがすべて1でない限り，5000兆日後の文字列のk番目は文字列sの1ではない最初の数である．


	int answer = -1;

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

	if(answer ==-1)	cout <<	'1' << '\n';

	if(answer !=-1)	cout << s[answer] << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
using namespace std;

typedef set<string> set_t;
set_t A;
int main()
{
	int n;
	string cmd,word;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> cmd >> word;
		if (cmd == "insert")
		{
			A.insert(word);
		}
		if (cmd == "find")
		{
			if (A.count(word)==1)
			{
				cout << "yes" << endl;
			}
			else
			{
				cout << "no" << endl;
			}
		}
	}
	return 0;

}



Measured memory_bytes: 32616
import java.util.Scanner;

//Sum of Integers II
public class Main{

	long[][][] dp;
	
	long get(int rest, int x, int s){
		if(rest==0 && s==0)return 1;
		if(rest<0 || x<0 || s<0)return 0;
		if(dp[rest][x][s]!=-1)return dp[rest][x][s];
		long res = 0;
		for(int nx=x;nx>=0;nx--)res+=get(rest-1, nx-1, s-nx);
		return dp[rest][x][s] = res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), S = sc.nextInt();
			if((n|S)==0)break;
			dp = new long[n+1][101][S+1];
			for(int i=0;i<=n;i++)for(int j=0;j<=100;j++)for(int k=0;k<=S;k++)dp[i][j][k]=-1;
			System.out.println(get(n, 100, S));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 71136
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int dfs(int now,vec<vec<int>> &G, vec<int> &tpl, vec<bool> &visited){
    if(tpl[now] != -1) return tpl[now];
    if(tpl[now] == -1 && visited[now]) return -1;
    visited[now] = true;

    if(G[now].size() == 0) {
        tpl[now] = 1;
        return 1;
    }

    int tmpOrder = -1;
    for(auto e:G[now]){
        int tmp = dfs(e,G,tpl,visited);
        if(tmp == -1) return -1;
        tmpOrder = max(tmpOrder,tmp+1);
    }
    tpl[now] = tmpOrder;
    return tpl[now];
}

vector<int> topological_sort(vec<vec<int>> &G){
    int N = G.size();
    vec<int> topolo(N,-1);
    vec<bool> visited(N,false);
    rep(i,N) dfs(i,G,topolo,visited);
    // {-1,-1,-1,…} の時はトポロジカルソート不可
    return topolo;
}

int main() {
    int N;
    cin >> N;
    vec<vec<int>> A(N, vec<int>(N - 1));
    rep(i, N) rep(j, N - 1) {
        cin >> A[i][j];
        --A[i][j];
    }
    vec<vec<int>> id(N, vec<int>(N, -1));
    int now = 0;
    rep(i, N) rep(j, N) {
        if (i == j || i > j) continue;
        id[i][j] = now, ++now;
    }
    
    vec<vec<int>> games(N,vec<int>(N-1));
    rep(i, N) rep(j, N - 1) {
        int me = i;
        int vs = A[i][j];
        if (me > vs) swap(me, vs);
        games[i][j] = id[me][vs];
    }
    
    vec<vec<int>> G(now,vec<int>());
    rep(i,N)rep(j,N-2){
        G[games[i][j+1]].push_back(games[i][j]);
    }

    vec<int> a = topological_sort(G);
    int ans = 0;
    for(auto e:a) {
        if(e==-1) {
            cout << -1 << endl;
            return 0;
        }
        ans= max(ans,e);
    }
    cout << ans << endl;
}

Measured memory_bytes: 41472
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
int main(){
  map<string,int> t;
  string s, mxc, mxl;
  int freq = 0, len = 0;
  while(cin >> s){
    if(t.find(s) == t.end()){
      t[s] = 1;
    }
    else{
      t[s]++;
    }

    if(t[s] > freq){
      freq = t[s];
      mxc = s;
    }
    if(s.size() > len){
      len = s.size();
      mxl = s;
    }
  }
  cout << mxc << " " << mxl << endl;
}

Measured memory_bytes: 3184
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N) { cout << 800 * N - (N / 15) * 200 << endl; }

int main() {
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////
int dp[100010];
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n+1);
    for (int i = 1;i <= n;i++){
        cin >> h[i];
    }

    dp[1] = 0;
    for (int i = 2;i <= n;i++){
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for (int j = 2;j <= k;j++){
            if (i - j >= 1){
                dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
            }
        }
    }

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

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
ll mod=1e9+7;
long long modpow(long long a, long long n, long long mod=(1LL<<62)){
	long long res = 1;
	while (n > 0){
		if (n & 1)
		res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main(){
	ll n;
	ll ans=0LL;
	cin >>n;
	ll a;
	int c=0;
	map<int,int>dis;
	rep(i,n){
		c=0;
		cin>>a;
		while(a!=0){
			dis[c]+=(a%2LL);
			a/=2LL;
			c++;
		}
	}
	repi(itr,dis){
	//	clog<<(itr->F)<<" "<<(itr->S)<<endl;
		ans+=modpow(2,itr->F,mod)*(itr->S)%mod*(n-itr->S)%mod;
		ans%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=(1LL<<63) - 600;
const ll mod=1e9+7 ;


int main(){
  int N, K; cin >> N >> K; ll a[N];
  rep(i, N){
    cin >> a[i];
  }
  ll cum[N+1]; cum[0]=0;
  rep(i, N){
    cum[i+1] = cum[i]+a[i];
  }
  vector<ll> b;
  rep(L, N){
    for(int R=L+1; R<=N; R++){
      b.push_back(cum[R] - cum[L]);
    }
  }
  ll ans = 0;
  for(int i=40; i>=0; i--){
    int cnt = 0;
    rep(j, b.size()){
      if((1LL<<i)&b[j]){cnt++;}
    }
    if(cnt>=K){
      rep(j, b.size()){
        if(!((1LL<<i)&b[j])) b[j]=0;
      }
      ans+=(1LL<<i);
    }
  }
  cout << ans << endl; 
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int a[110];

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++)
			cin>>a[i];
		sort(a,a+n);
		int sum=0;
		for(int i=1;i<n-1;i++){
			sum+=a[i];
		}
		cout<<sum/(n-2)<<endl;
	}
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
void read() {}
template<class T, class... Arg>
void read(T &x, Arg&&... args) {
	cin >> x;
	read(args...);
}
void print_err() {
	cerr << "\n";
}
template <class T, class... Arg>
void print_err(T x, Arg&&... args) {
	cerr << x << " ";
	print_err(args...);
}
template<class T>
void print_container(T &cont) {
	for (auto iter : cont) {
		cerr << iter << " ";
	}
	cerr << "\n";
}
#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#define debug_c(container) print_container(container)
#else
#define debug(...)
#define debug_c(container)
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vl vector<ll>
#define vpll vector<pair<ll,ll>>
#define mll map<ll,ll>
#define mllrev map<ll,ll,greater<int>>
#define ps(x,y) fixed<<setprecision(y)<<x//it will give upto y decimal places
#define w(t) ll t;cin>>t;while(t--)
#define fo(i,n) for(ll i=0;i<n;++i)
#define foab(i,a,b) for(ll i=a;i<b;++i)
#define inp cin>>
#define pr cout<<
#define pqb priority_queue<ll>//max heap
#define pqs priority_queue<ll,vl,greater<int>>//min heap
#define mk(arr,n,type) type *arr=new type[n];
#define all(A) (A).begin(),(A).end()
#define fastio ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
void CP() {
	fastio
#ifdef local
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
	return;
}
class Graph {
public:
	list<ll> *adj_list;
	ll v;
	Graph(ll v) {
		this->v = v;
		adj_list = new list<ll>[v];
	}
	void add_edge(ll u, ll v, bool bidirectional = true) {
		adj_list[u].push_back(v);
		if (bidirectional) {
			adj_list[v].push_back(u);
		}
	}
	void print();
	void connected_compo();
	void dfs(vector<vector<ll>> vect, ll k1, ll k2, ll n);
	void bfs(ll v, bool visited[]);
};
const int d4i[4] = { -1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void solve() {
	ll n;
	read(n);
	vl vect;
	ll temp;
	fo(i, n) {
		read(temp);
		vect.pb(temp);
	}
	sort(all(vect));
	ll ans = 0;
	map<string , ll>m1;
	for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			for (ll k = j + 1; k < n; k++) {
				if ((vect[i] + vect[j]) > vect[k]) {
					if ((vect[i] + vect[k]) > vect[j]) {
						if ((vect[j] + vect[k]) > vect[i]) {
							if (vect[i] != vect[j] and vect[j] != vect[k] and vect[i] != vect[k]) {
								ans++;
							}
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return ;
}
int main() {
	CP();
	// w(t) {
	solve();
	// }
	return 0;
}

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

using namespace std;

const int N = 1000005;

int cnt[N];
int n, a[N / 5];

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

	for(int i = 1; i < N; i++) if(cnt[i]) {
		for(int j = i + i; j < N; j += i) {
			cnt[j] += cnt[i];
		}
	}

	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += cnt[ a[i] ] == 1;
	}

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


Measured memory_bytes: 8432
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


#define int long long
int n, m;

vector<long double> inputs[17];
long double dp[(1 << 16)][17] = {};
long double dfs(int a, int b) {
    if (dp[b][a] != -1) return dp[b][a];
    long double ans = 0.0;
    REP(i, m) {
        if ((1 << i) & b) continue;
        long double now = 0;
        long double hoge = 1;
        for (int q = a; q < n; ++q) {
            now += (1.0 - inputs[i][q]) * hoge * dfs(q, (1 << i) + b);
            hoge *= inputs[i][q];
        }
        now += hoge;
        ans = max(ans, now);
    }
    return dp[b][a] = ans;
}
void solve(){
    cin >> m >> n;
    REP(i, m) {
        REP(q, n) {
            long double a;
            cin >> a;
            inputs[i].push_back(a);
        }
    }
    REP(i, (1 << 16)) {
        REP(q, 17) {
            dp[i][q] = -1;
        }
    }
    cout << dfs(0, 0) << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 20740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define lin puts("");
ll n,x,y,a[300000],b[300000],c=0,t=0,sum=0,z=0,i,j,f=0;
char ch[101],cr,ss[101];
string s;
int main()
{
    cin>>n;
    rep(i,1,n)
    {
        if(i%3!=0&&i%5!=0)
            sum+=i;
    }
    cout<<sum;
    return 0;
}


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

int main(int argc, char *argv[])
{
    int n, m, a, h, p, q;
    vector<vector<pair<int, int> > > amida(1001);
    vector<pair<int, int> >::iterator itr;
    while (cin >> n >> m >> a, n) {
        for (int i = 0; i < m; ++i) {
            cin >> h >> p >> q;
            amida[h].push_back(make_pair(p, q));
        }
        for (int i = 1000; i > 0; --i) {
            itr = amida[i].begin();
            while (itr != amida[i].end()) {
                if (itr->first == a) {
                    a = itr->second;
                    break;
                } else if (itr->second == a) {
                    a = itr->first;
                    break;
                }
                itr++;
            }
        }
        cout << a << endl;
        for (int i = 0; i < 1001; ++i) {
            amida[i].clear();
        }
    }
    return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    int N, D1, D2, cnt;
    bool flag = false;
    cin >> N;

    cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> D1 >> D2;
        if(D1 == D2) {
            cnt++;
            if(cnt >= 3){
                flag = true;
            }
        } else {
            cnt = 0;
        }
    }

    Yes(flag);

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,r,p,c,i,j,a[50],x,pp;
	while(1)	{
		scanf("%d %d",&n,&p);
		if(n==0 && p==0)	break;
		for(i=0;i<n;i++)	a[i]=0;
		x=0;
		pp=p;
		while(1)	{
			if(pp!=0)	{
				a[x]++;
				pp--;
			}
			else {
				pp=a[x];
				a[x]=0;
			}
			if(a[x]==p)	{
				break;
			}
			x++;
			x=x%n;
		}
		printf("%d\n",x);
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
ll N, M, K;
ll MOD = 1000000007;
ll ans = 0;

//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<ll, ll> firstElof, pair<ll, ll> secondElof)
{
	return firstElof.second > secondElof.second;
}
//////////////
int main()
{
	cin >> N;
	vector<ll> A(N);
	ll sum = 0;
	for (i = 0; i < N; i++) {
		ll a;
		cin >> a;
		A[i] = a - i - 1;
		sum += A[i];
	}
  	sort(A.begin(), A.end());
	ll mid = A[N/2];
	ll ans = 0;
	for (i = 0; i < N; i++) {
		ans += abs(A[i] - mid);
	}
	cout << ans;
}

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

int main() {
    int N;

    std::cin >> N;

    std::vector<int> A(N);
    std::vector<int> A_even;

    // O(n)
    for (auto& v : A) {
        std::cin >> v;
        if (v % 2 == 0) {
            A_even.emplace_back(v);
        }
    }

    // O(n)
    for (auto& v: A_even) {
        if (v % 3 != 0 && v % 5 != 0) {
            std::cout << "DENIED" << std::endl;
            return 0;
        }
    }

    std::cout << "APPROVED" << std::endl;

    return 0;
}

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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 102;
ll v[T];
int n;

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

    ll mmc = 1;
    ll den = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        mmc = (mmc*v[i])/__gcd(mmc,v[i]);
    }

    for(int i = 0; i < n; i++) den += mmc/v[i];

    double ans = (double)mmc/(double)den;

    cout << fixed << setprecision(5) << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//18:08~
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	int n,mae=-1,ans=0,gen=0;cin>>n;
	while(n--){
		int x;cin>>x;gen++;
		if(mae<x){gen=0;}
		maxeq(ans,gen);
		mae=x;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
# 参考　yy4さん
from heapq import heappush, heappop
import sys    
input = sys.stdin.readline    
n, m = map(int, input().split())
    
vmax = pow(10, 5)
jobs = {i:[] for i in range(1,vmax + 1)}
for _ in range(n):
    a, b = map(int, input().split())
    jobs[a].append(-b)
    

ans =0
hq = []
for i in range(1, m + 1):
    for j in jobs[i]:
        heappush(hq, j)
    if hq:
        v = heappop(hq)
        v *= -1
        ans += v
print(ans)

Measured memory_bytes: 26472
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 200001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------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
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

//double rat;

int main()
{
    double d;

    cin>>d;
    d=(2*pi*d);
    printf("%.12f\n",d);
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3788
import sys
from bisect import bisect_left, bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

    A.sort()
    C.sort()

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 22892
# include <vector>
# include <stdio.h>
# include <string.h>
# include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

# define FO_OPEN 0
# define RG register
# define ST static

const int M = 5e5 + 10, N = 2e6 + 10;
const int mod = 1e9 + 7;

int n, m;
int head[M], nxt[M], to[M], tot=0;

inline void add(int u, int v) {
	++tot; nxt[tot] = head[u]; head[u] = tot; to[tot] = v;
}
inline void adde(int u, int v) {
	add(u, v); add(v, u);
}

inline ll Abs(ll x) {
	return x<0 ? -x : x;
}

namespace solveCycleTree {
	ll w[M], f[M], g[M], tem[M];
	int tn, cir1, cir2, odd;
	
	inline void dfs_w(int x, int fa) {
		for (int i=head[x]; i; i=nxt[i]) {
			int y = to[i];
			if(y == fa) continue;
			if(w[y] == 0) {
				w[y] = -w[x];
				dfs_w(y, x);
			} else {
				cir1 = x, cir2 = y;
				odd = (w[x] == w[y]);
			}
		}
	}
	
	
	inline void dp(int x, int fa) {
		f[x] = w[x];
		for (int i=head[x]; i; i=nxt[i]) {
			if(to[i] == fa || (to[i] == cir1 && x == cir2) || (to[i] == cir2 && x == cir1)) continue;
			dp(to[i], x);
			f[x] = f[x] + f[to[i]];
			g[x] = g[x] + g[to[i]];
		}
	}
	
	inline void treeMain() {
		memset(w, 0, sizeof w);
		cir1 = cir2 = -1; odd = -1; w[1] = 1; 
		dfs_w(1, 0);
		dp(1, 0);
		if(f[1] != 0) {
			puts("-1");
			return ;
		}
		ll ans = 0;
		for (int i=1; i<=n; ++i) ans += Abs(f[i]);
		printf("%lld\n", ans);
	}
	
	inline void main() {
		memset(w, 0, sizeof w);
		ll ans = 0;
		cir1 = cir2 = -1; odd = -1; w[1] = 1; 
		dfs_w(1, 0);
		if(odd) {
			dp(1, 0);
			if(f[1]&1) {
				puts("-1");
				return ;
			}
			ll t = f[1];
			w[cir1] -= t/2, w[cir2] -= t/2; ans += Abs(t/2);
			dp(1, 0);
			for (int i=1; i<=n; ++i) ans += Abs(f[i]);
			printf("%lld\n", ans);
		} else {
			memset(g, 0, sizeof g);
			g[cir1] ++, g[cir2] --;
			
			dp(1, 0);
			
			if(f[1] != 0) {
				puts("-1");
				return ;
			}
			
			tn = 0;
			for (int i=1; i<=n; ++i) {
				if(g[i] == 0) {
					ans = ans + Abs(f[i]);
					continue;
				}
				if(g[i] == 1) tem[++tn] = -f[i];
				else tem[++tn] = f[i];
			}
			tem[++tn] = 0;
			
			sort(tem+1, tem+tn+1);
			
			ll ansid = tem[(1+tn)>>1];
			for (int i=1; i<=tn; ++i) ans = ans + Abs(ansid - tem[i]);
			printf("%lld\n", ans);
		}
		
	}
	
}

inline void sol() {
	tot = 0; memset(head, 0, sizeof head);
	
	scanf("%d%d", &n, &m);
	for (int i=1, u, v; i<=m; ++i) {
		scanf("%d%d", &u, &v);
		adde(u, v);
	}
	
	bool taskTree = (m+1 == n);
	bool taskCycleTree = (m == n);

	if(taskTree) {
		solveCycleTree::treeMain();
		return ;
	}
	solveCycleTree::main();
}	


int main() {
	sol();
	
	return 0;
}


Measured memory_bytes: 22784
program scoring
    implicit none
    integer(8)::D,C(26),last(26,365),last_sim(26),i,j,k,vmax,tbest
    integer(8),allocatable::S(:,:),T(:),V(:),Vorigin(:)
    !時間計測開始

    !入力
    read*,D,C
    allocate(S(26,D))
    allocate(T(D))
    allocate(V(D))
    allocate(Vorigin(D))
    read*,S
    T=0
    V=0
    last=0
    last_sim=0

    !貪欲法による初期解の生成
    do i=1,D
        do j=1,26
            !得点の初期化
            if(i==1)V(i)=0
            if(i>1)V(i)=V(i-1)

            !lastの初期化
            if(i==1)last(:,i)=0
            if(i>1)last(:,i)=last(:,i-1)

            last(j,i)=i
            V(i)=V(i)+S(j,i)
            
            do k=1,26
                V(i)=V(i)-C(k)*(i-last(k,i))
            end do

            if(j==1)then
                vmax=V(i)
                tbest=j
            else if(V(i)>vmax)then
                vmax=V(i)
                tbest=j
            end if
        end do
        if(i==1)last(:,i)=0
        if(i>1)last(:,i)=last(:,i-1)
        T(i)=tbest
        last(tbest,i)=i
    end do


    !答えの出力
    do i=1,D
        print'(i0)',T(i)
    end do
end program scoring

subroutine rnd_int(rnd,rnd_max)
    integer(8),intent(in)::rnd_max
    integer(8),intent(out)::rnd
    real::rnd_real
    call random_number(rnd_real)
    rnd=mod(int(rnd_real*100000000),rnd_max)+1
    return
end subroutine rnd_int

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

#define MAX 200010

using namespace std;
typedef long long int lli;

int n;

int v[MAX];
int L[MAX];
int R[MAX];

lli ans;

int main()
{
	scanf("%d",&n);

	v[0] = v[n + 1] = -MAX;

	for(int g = 1 ; g <= n ; g++)
		scanf("%d",&v[g]);

	for(int g = 1 ; g <= n ; g++)
	{
		int cur = g - 1;

		while(v[cur] > v[g]) cur = L[cur];

		L[g] = cur;
	}

	for(int g = n ; g >= 1 ; g--)
	{
		int cur = g + 1;

		while(v[cur] > v[g]) cur = R[cur];

		R[g] = cur;
	}

	for(lli g = 1 ; g <= n ; g++)
	{
		lli qtd = (R[g] - g)*(g - L[g]);
		ans += qtd*v[g];
	}

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

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#define ll long long
using namespace std;
int main(){
    string s;
    cin >> s;
    ll count=-1,ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='W'){
            count++;
            ans = ans + (i-count);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7
n=I()
ans=0
for i in range(1,n+1):
    ans+=(n-1)//i

print(ans)

Measured memory_bytes: 76764
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
template<class T> inline void chmax(T &a,T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a,T b){if(a>b)a=b;}


int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a,b,c;cin>>a>>b>>c;
    cout << (a-c) / (b+c) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];
    sort(all(A), greater<ll>());

    ll cnt = 1, ans = A[0];
    repe(i, 1, N){
        if (cnt == N - 1) break;
        if(N - 1 - cnt== 1){
            ans += A[i];
            break;
        }
        ans += A[i] * 2;
        cnt += 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> p(n),q(n),r(n);
  rep(i,n){cin>>p[i];}
  rep(i,n){cin>>q[i];}
  rep(i,n){r[i]=i+1;}
  sort(all(r));
  int a,b,k=1;
  do{bool ansp=true,ansq=true;
     rep(i,n){if(r[i]!=p[i]){ansp=false;}
              if(r[i]!=q[i]){ansq=false;}}
     if(ansp){a=k;}
     if(ansq){b=k;}
     k++;
      } while (next_permutation(all(r)));
  cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

set<string> ans;

const int MAX_N = 10;
// used[i] := base[i] を選んだかどうか
bool used[MAX_N];

// 初期化
void clear_used(){
	for(int i = 0 ; i < MAX_N ; i++ ) used[i] = false;
}

// baseの先頭から n 個の要素 から k 個選ぶ組合せの列挙
void comb(const vector<string>& base, vector<string> c, int pos,int last, int n, int k){
	if( pos == k ){
		// 組合せ c に対する操作
		sort( c.begin() , c.end() );
		do{
			string s;
			for(int i=0 ; i < c.size() ; i++ ){
				s += c[i];
			}
			string t;
			bool flag = false;
			for(int i=0 ; i < s.size() ; i++ ){
				if( s[i] >= '1' && s[i] <= '9' ){
					flag = true;
				}
				if( flag ) t.push_back( s[i] );
			}
			ans.insert( t );
		}while( next_permutation(c.begin(),c.end()) );
		return ;
	}
	for(int i = last+1 ; i < n ; i++ ){
		if( !used[i] ){
			c.push_back( base[i] );
			used[i] = true;
			comb( base , c , pos+1 , i , n , k );
			c.pop_back();
			used[i] = false;
		}
	}
}

int main(){
	int n, k;
	while( cin >> n >> k, n || k ){
		vector<string> a(n);
		ans.clear();
		
		for(int i=0 ; i < n ; i++ ){
			cin >> a[i];
		}
		
		clear_used();
		comb( a , vector<string>() , 0 , -1 , n , k );
		
		/*for(set<string>::iterator it = ans.begin() ; it != ans.end() ; ++it ){
			cout << *it << endl;
		}*/
		cout << ans.size() << endl;
	} 
}

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

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] cs = s.toCharArray();
		Arrays.sort(cs);

		String t = sc.next();
		char[] ct = t.toCharArray();
		Arrays.sort(ct);

		s = new String(cs);

		t = new String(ct);
		t = new StringBuilder(t).reverse().toString();

		System.out.println(s.compareTo(t) < 0  ? "Yes" : "No");
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,R;
int main(){
    cin>>N>>R;
    if(N>=10){
        cout<<R<<endl;
    }else{
        cout<<R+100*(10-N)<<endl;
    }

    return 0;
}

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

int main(){
  int D; cin >> D;
  vector<int> c(26);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D,vector<int>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }
  for(int i=0; i<D; i++) cout << rand()%26+1 << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    rep(i, n) cin >> h[i];
    
    sort(h.begin(), h.end());
    
    int ans = 1e9;
    rep(i, n-k+1){
        int tmp = h[i+k-1] - h[i];
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

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

int main(int argc, const char * argv[]) {
    
    char S[20];
    int i, count = 0;
    
    cin >> S;
    
    for(i=0; S[i] != NULL; i++){
        if(S[i] == 'x') count++;
    }
    
    if(count > 7) cout << "NO";
    else cout << "YES";
    
    return 0;
}



Measured memory_bytes: 256
use std::collections::HashMap;

fn main() {
    let mut hm = HashMap::new();

    let n = read::<usize>();
    for _ in 0..n {
        let b = read::<String>();
        let count = hm.entry(b).or_insert(0);
        *count += 1;
    }
    let m = read::<usize>();
    for _ in 0..m {
        let r = read::<String>();
        let count = hm.entry(r).or_insert(0);
        *count -= 1;
    }
    println!("{}", std::cmp::max(*hm.values().max().unwrap(), 0));
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	char x;
    cin>>x;
    if(x>='a'&&x<='z')
    cout<<'a';
    else
    {
        cout<<'A';
    }
    

return 0;
}

Measured memory_bytes: 3628
from itertools import accumulate
n = int(input())
S = input().replace("R", "1").replace("G", "2").replace("B", "3")
RGB = [[0]*n for _ in range(4)]
for i, s in enumerate(S):
    RGB[int(s)][i] = 1
for i in range(4):
    RGB[i] = list(accumulate(RGB[i]))
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        t = int(S[i]) ^ int(S[j])
        ans += RGB[t][-1] - RGB[t][j]
        if 2*j-i < n and int(S[2*j-i]) == t:
            ans -= 1
print(ans)

Measured memory_bytes: 68680
#include<iostream>
using namespace std;
int main() {
	int n, date[11],date2[11], a, kake,dai,syo,dai1,syo2;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		kake = 10000000;
		cin >> a;
		for (int z = 1; z <= 8; z++) {
			date[z] = a - a % kake;
			date[z] /= kake;
			a = a % kake;
			kake = kake / 10;
		}
		dai = -1;
		for (int m = 1; m <= 8; m++) {
			dai = -1;
			for (int z = 1; z <= 8; z++) {
				if (date[z] >= dai) {
					dai = date[z];
					dai1 = z;
				}
			}
			date[dai1] = -1;
			date2[m] = dai;
		}
		int aa, bb;
		aa = 0;
		bb = 0;
		kake = 10000000;
		for (int m = 1; m <= 8; m++) {
			aa = aa + kake * date2[m];
			kake /= 10;
		}
		kake = 10000000;
		for (int m = 8; m >= 1; m--) {
			bb = bb + kake * date2[m];
			kake /= 10;
		}
		cout << aa - bb << endl;
	}
}


Measured memory_bytes: 3092