akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}


const int MOD = 1E9 + 7, MAXN = 2E5 + 100;
ll f[MAXN], f_inv[MAXN];

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp)%MOD;
	if(y%2 == 1)
		temp *= x;
	return temp%MOD;
}

int main(){ 
	f[0] = 1;
	for(int i = 1; i < MAXN; i++)
		f[i] = (f[i - 1]*i)%MOD;
	f_inv[0] = 1;
	for(int i = 1; i < MAXN; i++) {
		int tmp = pow(i*1ll, MOD - 2ll);
		f_inv[i] = (tmp*f_inv[i - 1])%MOD;
	}
	int n, k;
	cin >> n >> k;
	k = min(k, n - 1);
	ll res = 0;
	for(int i = 0; i <= k; i++) {
		ll tmp = 0;
		tmp = (f[n]*f[n - 1])%MOD;
		tmp = (tmp*f_inv[i])%MOD;
		tmp = (tmp*f_inv[i])%MOD;
		tmp = (tmp*f_inv[n - i])%MOD;
		tmp = (tmp*f_inv[n - i - 1])%MOD;
		res = (res + tmp)%MOD;
	}
	cout << res;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main{
  public static void main(String[] args){
  	Scanner sc=new Scanner(System.in);
    int H1=sc.nextInt();
    int M1=sc.nextInt();
    int H2=sc.nextInt();
    int M2=sc.nextInt();
    int K=sc.nextInt();
    
    int awakeTime=60*H2+M2-60*H1-M1;
    int startLength=awakeTime-K;
    System.out.println(startLength);
  }
}

Measured memory_bytes: 35776
#include <cstdio>
#include <cstdlib>
//#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;


int main(void){

	int n;
	bool nonprime[300010] = { false };


	set<int> result;
	list<int> prime;


	for (int i = 1; i * 7 <= 300000; i++){
		if (!nonprime[i * 7 - 1]){
			prime.push_back(i * 7 - 1);
			for (int j = 2; (i * 7 - 1) * j <= 300000; j++){
				nonprime[(i * 7 - 1) * j] = true;
			}
		}
		if (!nonprime[i * 7 + 1]){
			prime.push_back(i * 7 + 1);
			for (int j = 2; (i * 7 + 1) * j <= 300000; j++){
				nonprime[(i * 7 + 1) * j] = true;
			}
		}
	}

	while (cin >> n, n != 1){

		cout << n << ":";
		list<int>::iterator it = prime.begin();
		while (it != prime.end()){
			if (n % *it == 0) cout << " " << *it;
			++it;
		}
		cout << endl;
	}

	return 0;
}

/*
for(i=0;i<N;i++){
cin >> X[i];
}


for(i=0;i<N;i++){
for(j=0;j<N;j++){
cin >> X[i][j];
}
}
*/

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;

void run_case()
{
    int n;
    cin >> n;
    vector<int> B(n), A(n + 1);
    for (int i = 1; i <= n - 1; i++)
        cin >> B[i];
    int ans = 0;
    A[1] = B[1], A[n] = B[n - 1];
    ans += (A[1] + A[n]);
    for (int i = 2; i <= n - 1; i++)
    {
        A[i] = min(B[i - 1], B[i]);
        ans += A[i];
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int P = sc.nextInt();
			int[] c = new int[N];
			int rest = P;
			OUT: while (true) {
				for (int i = 0; i < N; ++i) {
					if (rest == 0) {
						rest = c[i];
						c[i] = 0;
					} else {
						++c[i];
						--rest;
						if (c[i] == P) {
							System.out.println(i);
							break OUT;
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 20204
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> a(5);
  rep(i, 5) cin >> a[i];
  sort(a.begin(), a.end());
  int k;
  cin >> k;
  if (a[4]-a[0] <= k)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main()
{
	int N;
	int a, b;
	scanf("%d", &N);
	int cnt = 0;
	for (int i = 0; i < N; i++)
	{
		scanf("%d %d", &a, &b);
		if (a == b)
		{
			cnt++;
		}
		else
		{
			cnt = 0;
		}
		if (cnt >= 3)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 1608
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	int n;
	scanf("%d", &n);
	int[] a = new int[n+2];
	foreach (i; 0..n) {
		scanf("%d", &a[i+1]);
	}
	int ans = 0;
	foreach (i; 0..n+1) {
		ans += abs(a[i+1]-a[i]);
	}
	foreach (i; 1..n+1) {
		int diff = 0;
		diff += abs(a[i]-a[i-1]);
		diff += abs(a[i+1]-a[i]);
		diff -= abs(a[i+1]-a[i-1]);
		writeln(ans-diff);
	}
}

Measured memory_bytes: 1660
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

bool applecheck(string s,int i){
	bool flag = true;
	string apple = "apple";
	for(int j=0;j<5;j++){
		if(s[i+j] != apple[j]){
			flag = false;
		}
	}
	return flag;
}

bool peachcheck(string s,int i){
	bool flag = true;
	string peach = "peach";
	for(int j=0;j<5;j++){
		if(s[i+j] != peach[j]){
			flag = false;
		}
	}
	return flag;
}

int main(){
	string s;
	getline(cin, s);
	int index = 0;
	for(int i=0;i<s.length()-4;i++){
		if(applecheck(s,i)){
			cout << s.substr(index,i-index);
			cout << "peach";
			index = i+5;
			i += 5;
			continue;
		}
		if(peachcheck(s,i)){
			cout << s.substr(index,i-index);
			cout << "apple";
			index = i+5;
			i += 5;
		}
	}

	cout << s.substr(index) << endl;
}

Measured memory_bytes: 1184
N = int(input())
S = list(input())
r, g, b = 0, 0, 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
ans = r * g * b
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = 2 * j - i
        if k < N:
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
print(ans)

Measured memory_bytes: 9132
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n, m; cin >> n >> m;
    vll a(n); 
    ll tot = 0;
    rep(i, n) {
        cin >> a[i];
        tot += a[i];
    }
    sort(all(a));

    vector<P> q(m);
    rep(i, m) cin >> q[i].fi >> q[i].se;
    sort(all(q), [&](P x, P y){ 
        return x.se > y.se;
    });
    
    int now = 0;
    rep(i, m){
        // cout << q[i].fi << " " << q[i].se << endl;
        int cnt = q[i].fi; 
        ll val = q[i].se;
        rep3(j, now, now + cnt - 1) {
            if(j >= n) {
                cout << tot << endl;
                return;
            }
            tot += max(0LL, val - a[j]);
        }
        now += cnt;            
    }
    
    cout << tot << endl;
    return;
}

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

Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
int value(string S){
  int N = S.size();
  int num = 1;
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (isdigit(S[i])){
      num = S[i] - '0';
    } else {
      if (S[i] == 'm'){
        ans += num * 1000;
      }
      if (S[i] == 'c'){
        ans += num * 100;
      }
      if (S[i] == 'x'){
        ans += num * 10;
      }
      if (S[i] == 'i'){
        ans += num * 1;
      }
      num = 1;
    }
  }
  return ans;
}
string mcxi(int x){
  string S1 = to_string(x);
  while (S1.size() < 4){
    S1 = '0' + S1;
  }
  string S2 = "mcxi";
  string S;
  for (int i = 0; i < 4; i++){
    S += S1[i];
    S += S2[i];
  }
  string ans;
  for (int i = 0; i < 8; i++){
    if (S[i] == '0'){
      i++;
    } else if (S[i] != '1'){
      ans += S[i];
    }
  }
  return ans;
}
int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    string S, T;
    cin >> S >> T;
    cout << mcxi(value(S) + value(T)) << endl;
  }
}


Measured memory_bytes: 3240
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.12.28 20:13:56
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int a, b, c, x, y;
    scanf("%d%d", &x, &y);
    int ret = x + y / 2;

    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

char map[12][13];

void flging(int y,int x){
  map[y][x]='f';
  if(y-1>-1&&map[y-1][x]=='1')
    flging(y-1,x);
  if(y+1<12&&map[y+1][x]=='1')
    flging(y+1,x);
  if(x+1<12&&map[y][x+1]=='1')
    flging(y,x+1);
  if(x-1>-1&&map[y][x-1]=='1')
    flging(y,x-1);
}

int main(){
  int i,j,ic;
  while(scanf("%s",map[0])!=EOF){
    ic=0;
    for(i=0;i<11;i++)
      scanf("%s",map[i+1]);
    for(i=0;i<12;i++){
      for(j=0;j<12;j++){
	if(map[i][j]=='1'){
	  ic++;
	  flging(i,j);
	}
      }
    }
    printf("%d\n",ic);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<limits.h>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	cout << (A - 1)*(B - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static int M;
    public static int N;
    	public static void main(String[] a)throws java.io.IOException{
    		Scanner scan=new Scanner(System.in);
    		while(true){
    				N=scan.nextInt();
    				M=scan.nextInt();
    				if((N|M)==0)break;
                    int ans =0;
                    int [][] field =new int[M][N];
                    for(int i=0;i<M;i++){
                        for(int j=0;j<N ;j++){
                            field[i][j] = scan.nextInt();
                        }
                    }
 
                    for(int i=0;i<M;i++){
                        for(int j=0;j<N;j++){
                            if(field[i][j] == 1){
                                ++ans;
                                dfs(i,j,field);
 
                            }
                        }
                    }
                    System.out.println(ans);
                    scan.nextLine();
 
            }
    }
 
 
          public static void dfs(int y,int x,int [][] field){
              field[y][x] = 0;
              for(int i=-1;i<=1;i++){
            	  for(int j=-1;j<=1;j++){
                  int nx =x+j;
                  int ny =y+i;
                  if(0<=nx && nx< N &&0<=ny && ny <M &&field[ny][nx]==1)
                      dfs(ny,nx,field);
            	  }
              }
              return;
          }
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

vector<bool> dc_seen, dc_finished;

int dc_pos = -1;
vector<int> dc_hist;

const int MAX_V = 1000;
vector<int> dc_G[MAX_V];

void dc_dfs(int v) {
    dc_seen[v] = true;
    dc_hist.push_back(v);
    for(auto nv : dc_G[v]) {
        if (dc_finished[nv]) continue;
        if (dc_seen[nv] && !dc_finished[nv]) {
            dc_pos = nv;
            return;
        }
        dc_dfs(nv);
        if(dc_pos != -1) return;
    }
    dc_hist.pop_back();
    dc_finished[v] = true;
}

vector<int> detectCycle(int N) {
    dc_seen.assign(N, false);
    dc_finished.assign(N, false);
    rep(v, N) {
        dc_pos = -1;
        dc_dfs(v);
        if(dc_pos != -1) break;
    }
    vector<int> cycle;
    if(dc_pos==-1) return cycle;
    while(!dc_hist.empty()){
        int t = dc_hist.back();
        cycle.push_back(t);
        dc_hist.pop_back();
        if (t == dc_pos) break;
    }
    reverse(cycle.begin(), cycle.end());
    return cycle;
}

int main() {
    ll N, M;
    cin >> N >> M;
    set<pii> edges;
    rep(i,M){
        int a,b;
        cin >> a >> b;
        dc_G[a-1].push_back(b-1);
        edges.insert(make_pair(a-1,b-1));
    }

    vector<int> cycle = detectCycle((int)N);
    if(cycle.size() == 0) {
        cout << -1 << endl;
        return 0;
    }
    while(1) {
        set<pii> resedges = edges;
        set<int> cyclev;
        int from = -1;
        int to = -1;
        for(int i = 0; i < cycle.size(); i++) {
            int a = cycle[i];
            cyclev.insert(a);
            int b = cycle[(i+1)%cycle.size()];
            resedges.erase(make_pair(a,b));
        }
        for(auto e : resedges) {
            if(cyclev.count(e.first) == 1 && cyclev.count(e.second) == 1) {
                from = e.first;
                to = e.second;
                break;
            }
        }
        if(from == -1) break;
        vector<int> ncycle;
        ncycle.push_back(from);
        ncycle.push_back(to);
        int ind = -1;
        for(int i = 0; i < cycle.size(); i++) {
            if(to == cycle[i]) {
                ind = i;
                break;
            }
        }
        ++ind;
        while(cycle[ind] != from) {
            ncycle.push_back(cycle[ind]);
            ind = (ind+1) % cycle.size();
        }
        cycle = ncycle;
    }

    cout << cycle.size() << endl;
    for(auto v : cycle) cout << v + 1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
    char c;
    cin >> c;
    switch(c){
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':
            cout << "vowel"     << endl; break;
        default:
            cout << "consonant" << endl; break;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N;
	cin >> N;
	
	VL S;
	multiset<ll> mst;
	set<ll> st;
	REP(i, N) {
		ll a;
		cin >> a;
		mst.insert(a);
		st.insert(a);
	}

	for (auto itr = st.rbegin() ; itr != st.rend() ; itr++) {
		
		if (mst.count(*itr) >= 4) {
			S.push_back(*itr);
			S.push_back(*itr);
		}
		
		if (mst.count(*itr) >= 2) {
			S.push_back(*itr);
			if (S.size() >= 2) {
				cout << S[0] * S[1] << endl;
				return 0;
			}
		}
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 9600
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        long y = 0;

        for(int i=1; i<n; i++) {
            if(aa[i-1] > aa[i]) {
                var add = aa[i-1] - aa[i];
                y += add;
                aa[i] += add;
            }
        }

        return y;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 46388
#include <bits/stdc++.h>
using namespace std;
int main(){
    long k,a,b,c;
    cin >> k >> a >> b;
    c = k+1;
    for(int i=0;i*2<=k;i++){
        long x = k-2*i;
        if(x+1>=a) c = max(c,x+1+i*(b-a));
    }
    cout << c << endl;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    
    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K; cin >> K;
    cout << arr[K - 1] << endl;
}


Measured memory_bytes: 256
import std.stdio,std.string,std.conv;

int main()
{
	string s;
	int count = 0;
	while((s = readln.chomp).length != 0)
	{
		if(s.length == 1)
		{
			count++;
		}
		else
		{
			bool flag = true;
			foreach(i;0..s.length/2)
			{
				if(s[i] != s[s.length - i - 1])
				{
					flag = false;
				}
			}

			if(flag)
			{
				count++;
			}
		}
	}
	count.writeln;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<tuple<string, int, int>> data;
  tuple<string, int, int> p;

  for (int i = 0; i < N; i++){
    cin >> get<0>(p) >> get<1>(p);
    get<2>(p) = i + 1;
    data.push_back(p);
  }

  sort(data.begin(), data.end());
  int flag = 0;
  
  while(flag == 0){
    flag = 1;
    for (int i = 0; i < N - 1; i++){
      if (get<0>(data.at(i)) == get<0>(data.at(i + 1)) && get<1>(data.at(i)) < get<1>(data.at(i + 1))){
        swap(data.at(i), data.at(i + 1));
        flag = 0;
      }
    }
  }

  for (int i = 0; i < data.size(); i++){
    cout << get<2>(data.at(i)) << endl;
  }
}

Measured memory_bytes: 256
n=int(raw_input())
buildings=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    b,f,r,v=map(int,raw_input().split())
    buildings[b-1][f-1][r-1]+=v
#print buildings                                                                                                    
for i in range(4):
    for j in range(3):
        ln=''
        for k in range(10):
            ln+=' '+str(buildings[i][j][k])
        print ln
    if i!=3:print '#'*20

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

int N, M, TC, PT, A[100005], P[100005];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= N; i++) cin >> A[i];
	sort(A + 1, A + 1 + N);
	for (int i = N; i >= 1; i--) P[i] = A[i] + P[i + 1];
	int lo = 0, hi = 1e12, ans = 0;
	while (lo <= hi) {
		int mid = (lo + hi) >> 1ll, T = 0;
		for (int i = N; i >= 1; i--) T += N - (upper_bound(A + 1, A + 1 + N, mid - A[i]) - (A + 1));
		if (T >= M) lo = mid + 1;
		else ans = mid, hi = mid - 1;
	}
	for (int i = 1; i <= N; i++) {
		int lo = 1, hi = N, ans2 = N + 1;
		while (lo <= hi) {
			int mid = (lo + hi) >> 1;
			if (A[mid] >= ans - A[i]) ans2 = mid, hi = mid - 1;
			else lo = mid + 1;
		}
		if (ans2 <= N) TC += P[ans2] + (N - ans2 + 1) * A[i], PT += (N - ans2 + 1);
	}
	cout << TC + (M - PT) * ans << '\n';
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define FOR(i,a) for(auto i:a)
#define pub push_back
#define pob pop_buck
#define all(in) in.begin(),in.end()

using ll = long long; // typedef long long ll; と同意
using ull = unsigned long long;
using namespace std;

int main(){
    int x, y; cin >> x >> y;
    bool count = false;
    rep(i, 100){
        rep(j, 100){
            if(i+j == x && 2*i+4*j == y) count = true;
        }
    }
    if(count) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		// cin.ignore(); must be there when using getline(cin, s)
		string s,t;
		cin>>s>>t;
		ll sl=s.length();
		ll tl=t.length();
		//cout<<sl<<" "<<tl<<endl;
		ll dp[sl+1][tl+1]={0};
		for(ll i=0;i<=sl;i++)
		{
			for(ll j=0;j<=tl;j++)
			{
				if(i==0 || j==0)
					dp[i][j]=0;
				else if(s[i-1]==t[j-1])
					dp[i][j]=dp[i-1][j-1]+1;
				else 
					dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
		// for(ll i=0;i<=sl;i++)
		// {
		// 	for(ll j=0;j<=tl;j++)
		// 	{
		// 		cout<<dp[i][j]<<" ";
		// 	}
		// 	cout<<endl;
		// }
		string lcs;
		ll i=sl,j=tl;
		while(i>0 && j>0)
		{
			//cout<<i<<" "<<j;
			if(s[i-1]==t[j-1])
			{
				lcs.push_back(s[i-1]);
				i--;j--;
			}
			else if(dp[i][j]==dp[i][j-1])
				j--;
			else
				i--;
		}
		ll len=lcs.length();
		i=len-1;
		for(;i>=0;i--)
			cout<<lcs[i];
		//cout<<endl;
		//cout<<dp[sl][tl];
		return 0;
	}


Measured memory_bytes: 70656
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   bool ok =false;
   while(N!=0){
      if(N%10==7){
         ok = true;
      }
      N/=10;
   }
   if(ok) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 3588
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] nums = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int k = 0; k < m; k++) {
				int a = sc.nextInt();
				nums[i][k] = a;
			}
		}
		
		int[] vector = new int[m];
		for (int j = 0; j < m; j++) {
			int b = sc.nextInt();
			vector[j] = b;
		}

		for (int L = 0; L < n; L++) {
			int c = 0;
			for (int P = 0; P < m; P++) {
				c = nums[L][P] * vector[P] + c;
			}
			System.out.println(c);
		}
    }
}



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

using i64 = long long int;

int main(){
    int n;
    cin >> n;
    set<int> st;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        if(st.count(a))st.erase(a);
        else st.insert(a);
    }

    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 4864
program main
  implicit none
  integer(8) :: n, i, j, cnt(26), res
  integer(8), parameter :: m = 10 ** 9 + 7
  character(100000) :: s

  read (*, *) n
  read (*, *) s

  cnt(:) = 1
  do i = 1, n
    j = iachar(s(i:i)) - iachar("a") + 1
    cnt(j) = cnt(j) + 1
  end do

  res = 1
  do i = 1, 26
    res = res * cnt(i)
    res = modulo(res, m)
  end do
  write (*, "(i0)") modulo(res - 1, m)

end program main


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

int main()
{
	int n;
	cin >> n;

	int ans = 0;
	for (int i = 1; i <= n; i += 2)
	{
		int buf = 0;

		for (int j = 1; j <= i; ++j)
		{
			if (i % j == 0)
			{
				buf++;
			}
		}

		if (buf == 8)
		{
			ans++;
		}
	}

	cout << ans << "\n";
	return 0;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N + 1);
    for (int i = 1; i <= N; i++)
    {
        int a;
        cin >> a;
        A[a]++;
    }

    sort(A.begin(), A.end());

    // for (int i = 1; i <= N; i++)
    // {
    //     cout << A[i] << " ";
    // }
    // cout << endl;

    int cnt = 0;
    for (int i = 1; i <= N - K; i++)
    {
        cnt += A[i];
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3952
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i,B in enumerate(b):
    tmp=a[i]
    if tmp<=B:
        ans+=tmp
        B-=tmp
        if a[i+1]<=B:
            ans+=a[i+1]
            a[i+1]=0
        else:
            ans+=B
            a[i+1]-=B
    else:
        ans+=B
print(ans)

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

int n,q,l[100004],r[100004],ppap[100004];
string str;
queue<pair<int,int>> qu;
int main(){
	cin>>n>>q>>str;
	if(str[0]=='A'&&str[1]=='C')ppap[0]=1;
	for(int i=2;i<n;i++){
		if(str[i-1]=='A'&&str[i]=='C')ppap[i-1]=ppap[i-2]+1;
		else ppap[i-1]=ppap[i-2];
	}
	for(int i=0;i<q;i++){
		cin>>l[i]>>r[i];
		cout<<ppap[r[i]-2]-ppap[l[i]-2]<<endl;
	}
}



Measured memory_bytes: 2304
Books,Cost,X=None,None,None
DP={}

def getUnderstanding(prev,curr):
    global Books
    L=[]
    for i in range(len(prev)):
        L.append(prev[i]+Books[curr][i])
    return L
def isUnderstandingReached(prev):
    global X
    for u in prev:
        if u<X:
            return False
    return True

def F(curr,prev):
    global Books,Cost,X,DP
    #if (curr,tuple(prev)) in DP:
    #    return DP[(curr,prev)]
    if isUnderstandingReached(prev):
        return 0
    if curr==len(Books):
        return float('inf')
    DP[(curr,tuple(prev))]=min(Cost[curr]+F(curr+1,getUnderstanding(prev,curr)),F(curr+1,prev))
    return DP[(curr,tuple(prev))]

N,M,X=map(int,input().strip().split())
Books=[]
Cost=[]
for i in range(N):
    L=list(map(int,input().strip().split()))
    Books.append(L[1:])
    Cost.append(L[0])
res=F(0,[0]*len(Books[0]))
if res==float('inf'):
    print(-1)
else:
    print(res)

Measured memory_bytes: 10928
s = input()
s_list1 = []
s_list2 = []
for i in range(len(s)):
    if (i+1)%2 == 0:
        s_list2.append(s[i:i+1])
    else:
        s_list1.append(s[i:i+1])
#print(s_list1)
#print(s_list2)
if s_list1.count("L") == 0 and s_list2.count("R") == 0:
    print("Yes")
else:
    print("No")

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

//#define int long long
using ll = long long;
const int INF = 1<<29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var)  std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(int i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(int i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

signed main() {
	ll N,M;
	cin >> N >> M;
	vector<ll> a(N,0);
	rep(i,N)cin >> a[i];

	vector<ll> rui(N+1,0);
	rep(i,N)rui[i+1]=(rui[i]+a[i])%M;

	unordered_map<ll,ll> map;
	rep(i,N+1){
      map[rui[i]]++;
	}

	ll ans=0;
	for(auto it=map.begin();it!=map.end();it++){
		ll t=(*it).second;
		if(t>0){
			ans+=t*(t-1)/2;
		}
	}

	p(ans);

	return 0;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct S009 {
  template<typename a>
  a operator()(a x, long n) {
    if( n == 0 ) return a(1);
    a t = (*this)(x, n / 2);
    return t * t * (n % 2 ? x : a(1));
  }
};

template<long p = 1000000007>
struct S010 {
  long x;
  S010() : x(0) {}
  S010(long x_) : x(x_ % p) {}
  S010<p> operator + (S010<p> y) const { return (x + y.x) % p; }
  S010<p> operator - (S010<p> y) const { return (x + p - y.x) % p; }
  S010<p> operator * (S010<p> y) const { return (x * y.x) % p; }
  S010<p> operator / (S010<p> y) const { S009 pow_; return x * pow_(y, p-2); }
};
template<long p>
S002& operator >= (S002& r, S010<p>& x) {
  long y;
  r >= y;
  x = S010<p>(y);
  return r;
}
template<long p>
S010<p> operator * (int x, S010<p> y) {
  return x * y.x;
}

struct Solver {
  typedef S010<> Mod;
  long n;
  Solver() {
    S002 reader;
    reader >= n;
  }
  void solve() {
    std::vector<Mod> dp(2123456, 1);
    std::vector<Mod> sum(2123456);
    sum[2123456-1] = dp[2123456-1];
    for(long i = 2123456 - 1 - 1; i >= 0; --i) {
      sum[i] = dp[i] + sum[i+1];
    }
    dp[n] = n;
    sum[n] = dp[n] + sum[n+1];
    for(long i = n - 1; i >= 1; --i) {
      dp[i] = Mod(n - 1) * (n - 1) + dp[i+1] + sum[i+3] - sum[i+n+1+1];
      sum[i] = dp[i] + sum[i+1];
    }
    printf("%ld\n", dp[1].x);
  }    
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 33408
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h>
using namespace std;
int main(void){
   int A,B;
   cin >> A >> B;
   int count = 0;
   for(int i = A;i <= B; i++){
       if(i%10 == (i / 10000)%10){
           if((i/10)%10 == (i/1000)%10){
               count++;
           }
       }
   }
   cout << count << endl;
}

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

MOD = 1000000007  # type: int


def solve(N: int, K: int):
    sum = 0
    for k in range(K, N + 2):
        sum += k * (N - k + 1) + 1
    
    print(sum % MOD)
    return


# Generated by 1.1.6 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
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


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

class Main{

	static char[][] map;
	static int H;
	static int W;

	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		String string = sc.next();		
		int ans = 0;

		for(int i = 0;i < N;i++){
			int sub = 0;
			char[] mae = string.substring(0,i).toCharArray();
			char[] ushiro = string.substring(i).toCharArray();

			Arrays.sort(mae);
			//Arrays.sort(ushiro);

			int j = 0;
			while(true){
				if(j >= mae.length){
					break;
				}



				while(true){
					if(j == mae.length-1){
						break;
					}
					if(mae[j] != mae[j+1]){			//aab みたいな時二つ目に移動
						break;
					}
					j++;
				}
				
				for(int k = 0;k < ushiro.length;k++){			//後ろにあるか判定
					if(mae[j] == ushiro[k]){
						sub++;
						break;
					}

				}
				j++;

			}
			ans = Math.max(ans, sub);

		}

		System.out.println(ans);

	}
}




class Pair implements Comparable{
	String from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}





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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x;
string s[10], t;
ll cou = 0;
ll a[300000];
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	for (ll i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);

	ll ans = a[0];
	ll flag = 0;
	ll ind = 1;
	ll turn = n-2;
	while(turn -- ) {
		ans += a[ind];
			
		if(flag) {
			ind ++;
		}

		flag^=1;
	}
	cout<<ans;
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 239584
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll k;
  cin >> k;
  vector<string> v;
  REP(i, 9) v.emplace_back(to_string(i+1));
  int i = 0;
  while(v.size() <= 100000){
    char c = v[i].back();
    if(c != '0') v.emplace_back(v[i]+(char)(c-1));
    v.emplace_back(v[i]+c);
    if(c != '9') v.emplace_back(v[i]+(char)(c+1));
    i++;
  }
  cout << v[k-1] << endl;
  return 0;
}

Measured memory_bytes: 7028
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        s: [String; n],
    }
    let h = s.iter().collect::<std::collections::HashSet<_>>();
    let ans = if h.iter().count() == 4 {
        "Four"
    } else {
        "Three"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
int n, m, x, y;
int dp[100005];
vector<bool> visited(100005, false);
vector<int> adj_list[100005];

void dfs(int src) {
	visited[src] = 1;

	for (int i = 0; i < adj_list[src].size(); i++) {
		int child = adj_list[src][i];
		if (!visited[child]) {
			dfs(child);
		}
		dp[src] = max(dp[src], dp[child] + 1);
	}
	return;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		adj_list[x].push_back(y);
	}

	for (int i = 1; i <= n; i++) {
		if (!visited[i]) {
			dfs(i);
		}
	}

	int max_path_len = -1;
	for (int i = 1; i <= n; i++) {
		max_path_len = max(dp[i], max_path_len);
	}

	cout << max_path_len << endl;
	return 0;
}

Measured memory_bytes: 12040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin >> N;
    vec S(N); rep(i,N) cin >> S[i];

    vei r(N,0), l(N,0);

    rep1(i,N) {
        if(S[i-1] == 'W') l[i] = l[i-1] + 1;
        else l[i] = l[i-1];
    }

    for(int i = N-2; i >= 0; i--) {
        if(S[i+1] == 'E') r[i] = r[i+1] + 1;
        else r[i] = r[i+1];
    }

    int ans = 1000000; 
    rep(i,N) {
        int temp = r[i] + l[i];
        ans = min(ans, temp);
    }
    cout << ans << endl;
    return 0;

}



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

//Ennichi
public class Main{

	int h, w, N;
	
	boolean f(char[][] a){
		boolean con = true;
		boolean[][] del = new boolean[h][w];
		while(con){
			con = false;
			for(int j=0;j<w;j++)for(int i=h-1;i>0;i--)if(a[i][j]=='.'){
				for(int k=i-1;k>=0;k--)if(a[k][j]!='.'){
					a[i][j] = a[k][j]; a[k][j] = '.'; break;
				}
			}
			for(int j=0;j<w;j++)if(a[h-1][j]!='.')con = true;
			if(!con)return true;
			con = false;
			for(boolean[]v:del)Arrays.fill(v, false);
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				if(a[i][j]=='.')continue;
				int L = 0;
				while(j+L<w&&a[i][j+L]==a[i][j])L++;
				if(N<=L)for(int k=j;k<j+L;k++)del[i][k] = true;
				L = 0;
				while(i+L<h&&a[i+L][j]==a[i][j])L++;
				if(N<=L)for(int k=i;k<i+L;k++)del[k][j] = true;
			}
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(del[i][j]){
				a[i][j] = '.'; con = true;
			}
		}
		return false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt(); w = sc.nextInt(); N = sc.nextInt();
		char[][] m = new char[h][], t = new char[h][w];
		for(int i=0;i<h;i++)m[i]=sc.next().toCharArray();
		boolean ok = false;
		for(int i=0;i<h&&!ok;i++)for(int j=0;j<w-1&&!ok;j++){
			if(m[i][j]!=m[i][j+1]){
				for(int y=0;y<h;y++)for(int x=0;x<w;x++)t[y][x]=m[y][x];
				char x = t[i][j];
				t[i][j] = t[i][j+1]; t[i][j+1] = x;
				ok = f(t);
			}
		}
		System.out.println(ok?"YES":"NO");
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000