akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<set>
using namespace std;
int main(){
  int N;
  int d[N];
  cin>>N;

  for(int i=0;i<N;i++)cin>>d[i];

  set<int>values;//insertするときに重複を取り除いてくれる
  for(int i=0;i<N;i++){
    values.insert(d[i]);
  }

  //setのサイズを出力
  cout<<values.size()<<endl;
}

Measured memory_bytes: 256
import bisect
N = int(input())
L = list(int(l) for l in input().split())
L.sort()
num=0

for i in range(N-2):
    for j in range(i+1,N-1):
        a = L[i]
        b = L[j]
        idx = bisect.bisect_left(L, a+b)
#        print("(a,b)=(%d,%d) : idx=%d : (i,j)=(%d,%d)"%(a,b,idx-(j+1),i,j))
        num += idx-(j+1)
print(num)

Measured memory_bytes: 3188
<?php
fscanf(STDIN, "%s %s", $s, $t);
fscanf(STDIN, "%s %s", $a, $b);
fscanf(STDIN, "%s", $u);

if ($u == "$s") {
    $a -= 1;
} else {
    $b -= 1;
}

echo "$a $b";



Measured memory_bytes: 4604
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

ll g(ll N, ll p) {
  if (N < p) return 0;
  return (N / p) + g(N / p, p);
}

ll f(ll N, ll p) {
  if (N < p) return 0;
  ll res = 0;
  if (N % 2 == 1) {
    res += g(N, p);
    res -= f(N - 1, p);
    return res;
  }
  res = g(N / 2, p);
  if (p == 2) {
    res += N / 2;
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  ll N;
  while (cin >> N) {
    ll res = min(f(N, 2), f(N, 5));
    cout << res << endl;
  }
  return 0;
}


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

int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n;
    string s;
    cin>>s;

    int ans = 0;
    for(int i = 0; i < s.length();i++) {
    	int j = i + 1;
    	//cout<<i<<" : "<<s[i]<<" , "<<j<<" : "<<s[j]<<endl;
    	
    	if(s[i] != s[j] && j < s.length()) {
    		ans += 2;
    		s.erase(i,2);
    		i-2 >= 0 ? i-=2 : i=-1;
    		//i-=2;
    	}
    }
    cout<<ans<<endl;


	return 0;		
}


//1011




Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	cin >> s;
	int cun = 0;
	for (int i = 0; i < s.length(); i++) {
		for (int j = i + 1; j < s.length(); j++) {
			if (s[i] == s[j]) {
				cun++;
			}
		}
	}
	if (cun == 0) {
		cout << "yes" << "\n";
	} else {
		cout << "no" << "\n";
	}
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int x; cin >> x;
    if(x == 7 || x == 5 || x == 3) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N;
    cin >> N;
    for (int i = 1; i < 10; i++) {
        if (N <= i*111) {
            cout << i*111 << endl;
            return;
        }
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

int main(){
				int a,b,c;
				cin >> a >> b >> c;

				int i = 0;
				int x;
				while(i < 2){
						if(a > b){
									x = a;
									a = b;
									b = x;
						}
						if(b > c){
									x = b;
									b = c;
									c = x;
						}
						if(a > c){
									x = a;
									a = c;
									c = x;
						}
						i += 1;
				}
				cout << a << " " << b << " " << c << endl;
}



Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n, x, y, a, b, aa, bb, ans;
int main(){
	int i;
	cin >> n >> x >> y;
	a=b=x+y;
	aa=bb=x-y;
	n--;
	while(n--){
		cin >> x >> y;
		a=min(a,x+y);
		b=max(b,x+y);
		aa=min(aa,x-y);
		bb=max(bb,x-y);
	}
	ans=max(b-a,bb-aa);
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 3176
fun main(args: Array<String>) {
    val (a, b, c) = readLine()!!.split(" ").map { it.toLong() }
    println(when {
        a % 2 == 0L ||
        b % 2 == 0L ||
        c % 2 == 0L -> 0
        else -> Math.min(b * c, Math.min(a * b, a * c))
    })
}

Measured memory_bytes: 35976
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n, x;
  cin >> n >> x;
  vector<int> a(n), d(n + 1, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int cnt = 0;
  for(int i = 1; i <= n; i++) {
    d[i] = d[i - 1] + a[i - 1];
    if(d[i] <= x){
      cnt++;
    }
  }
  cout << cnt + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while(true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            break;
        }

        a -= d;

        if (a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3632
li = list(input())
l = [int(n) for n in li]
x = len(l)
li_0 = [0 for i in range(x)]
li_1 = [0 for i in range(x)]
for i in range(x):
    if i % 2 == 0:
        li_0[i] = 1
    else:
        li_1[1] = 1
a = 0
b = 0
for i in range(x):
    if li_0[i] != l[i]:
        a += 1
    else:
        b += 1
print(min(a,b))

Measured memory_bytes: 12132
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    if(A>=13)
    {
        B=B;
    }
    else if(A>=6 && A<=12)
    {
        B=B/2;
    }
    else if(A>=0 && A<6)
    {
        B=0;
    }
    printf("%d\n",B);

    return 0;
}


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

using namespace std;

using ll = long long;

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

    int n;

    cin >> n;

    vector<int> a(n), nsize(n);

    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
        --a.at(i);
        ++nsize.at(a.at(i));
    }

    ll tot;

    for(int i = 0; i < n; ++i) {
        tot += static_cast<ll>(nsize.at(i)) * (nsize.at(i) - 1) / 2;
    }

    for(int k = 0; k < n; ++k) {
        printf("%lld\n", tot + 1 - nsize.at(a.at(k)));
    }

    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

struct edge {
    int to, cost;
    edge(){}
    edge(int _to, int _cost) : to(_to), cost(_cost) {}
};
const int INF = 1e15;
typedef vector<vector<edge>> Graph;

int N, M, L, K, s, t;
vector<bool> canFreeze;
Graph G;

VV dijkstra() {
    priority_queue<TUPLE, vector<TUPLE>, greater<TUPLE>> que;   // cost, vertex, life
    VV d(N, V(M + 1, INF));
    d[s][M] = 0;
    que.push(TUPLE(0, s, M));

    while (!que.empty()) {
        int c, v, m;
        tie(c, v, m) = que.top(); que.pop();
        if (d[v][m] < c) continue;

        // charge
        if (canFreeze[v]) {
            rep2(nm, m + 1, M + 1) {
                int nc = c + (nm - m);
                if (d[v][nm] > nc) {
                    d[v][nm] = nc;
                    que.push(TUPLE(nc, v, nm));
                }
            }
        }

        // move
        for (auto e : G[v]) {
            int nv = e.to;
            int nm = m - e.cost;
            int nc = c + e.cost;
            if (nm < 0) continue;  // die
            if (d[nv][nm] > nc) {
                d[nv][nm] = nc;
                que.push(TUPLE(nc, nv, nm));
            }
        }
    }
    return d;
}

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

    while (cin >> N >> M >> L >> K >> s >> t, N) {
        canFreeze.clear();
        canFreeze.resize(N, false);
        canFreeze[s] = canFreeze[t] = true;
        rep(i, L) {
            int l;
            cin >> l;
            canFreeze[l] = true;
        }

        G.clear();
        G.resize(N);
        rep(i, K) {
            int x, y, c;
            cin >> x >> y >> c;
            G[x].emplace_back(y, c);
            G[y].emplace_back(x, c);
        }

        auto d = dijkstra();
        int ans = INF;
        rep(j, M + 1) ans = min(ans, d[t][j]);

        if (ans == INF) {
            cout << "Help!" << endl;
        } else {
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 3544
/*
      H   H
       \ / 	
        C
       / \ 
      H   H
*/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		string s, t;
		cin >> s >> t;
		int n = sz(s), m = sz(t);
		if(t.substr(0, n)!=s)
			cout << "No";
		else
			cout << "Yes";
	}
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>
#include <vector>
#include<bitset>
using namespace std;

int main() {
	int n, q; string s; cin >> n >> q >> s;
	vector<int>sum(n, 0);
	bool a = 0;
	for (int i = 0; i < n; i++) {
		if (a && s[i] == 'C') {
			sum[i] = 1 + sum[i - 1]; a = 0;
		}
		else if (s[i] == 'A') {
			sum[i] = sum[i - 1]; a = 1; continue;
		}
		else {
			sum[i] = sum[i - 1]; a = 0;
		}
	}
	for (int i = 0; i < q; i++) {
		int l, r; cin >> l >> r;
		cout << sum[r - 1] - sum[l - 1] << endl;
	}
}

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

vector<int> adj[100005];
int ind[100005];
int used[100005];

int main() {
    int n, m;
    cin >> n >> m;
    
    while (m--) {
        int i, j;
        cin >> i >> j;
        adj[i].push_back(j);
        adj[j].push_back(i);
    }
    
    deque<int> D;
    D.push_back(1); used[1] = 1;
    
    while (1) {
        int i = D.back();
        while (ind[i] < adj[i].size() && used[adj[i][ind[i]]]) ind[i]++;
        if (ind[i] < adj[i].size()) {
            D.push_back(adj[i][ind[i]]);
            used[D.back()] = 1;
            ind[i]++;
        } else break;
    }

    while (1) {
        int i = D.front();
        while (ind[i] < adj[i].size() && used[adj[i][ind[i]]]) ind[i]++;
        if (ind[i] < adj[i].size()) {
            D.push_front(adj[i][ind[i]]);
            used[D.front()] = 1;
            ind[i]++;
        } else break;
    }
    
    cout << D.size() << endl;
    for (int i = 0; i < D.size(); i++) cout << D[i] << " "; 
    
    return 0;
}

Measured memory_bytes: 7424
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

	string str;
	vector<int> m('z'-'a'+1);
	FOR(i, 'a', 'z'+1) {
		m.at(i-'a') = 0;
	}
	while(getline(cin, str)) {
		transform(str.begin(), str.end(), str.begin(), ::tolower);
		while(str != "") {
			int index = str[0] - 'a';
			if(index >= 0 && index < 'z' - 'a' + 1)
				m.at(index)++;
			str = str.substr(1);
		}
	}
	FOR(i, 'a', 'z'+1) {
		cout << (char)(i) << " : " << m.at(i-'a') << endl;
	}
}


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

int main() {
	int n,i;
  	int a[200];
  	int flag,ans;
  
  	cin >> n;
  	for (i=0;i<n;++i)
    {
      cin >> a[i];
    }
  
  	ans=0;
  	while (1)
    {
	  	flag=0;
	  	for (i=0;i<n;++i)
    	{
	 		if (a[i] % 2 == 0 )
            {
              	a[i] /= 2;
            }
          	else
            {
              	flag = 1;
		    	break;
            }
        }
      if (flag == 1)
        break;
      
      ++ans;
    }
  	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)

int main() {
	string s; cin >> s;
	int k; cin >> k;

	set<string> st;
	rep(i, 0, s.size()) {
		rep(j, 0, k) {
			if (j + 1 > s.size()) break;
			st.insert(s.substr(i, j + 1));
		}
	}
	auto itr = st.begin();
	rep(i, 1, k) ++itr;

	cout << *itr << endl;

	return 0;
}

Measured memory_bytes: 1664
/// input macro from https://qiita.com/tanakh/items/1ba42c7ca36cd29d0ac8
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 , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
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 ) * } } ; }
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 ) * } } ; }

fn main() {
    input!(_n: String);
    let n: Vec<char> = _n.chars().collect();

    let mut m = 0;
    for c in n {
        let tmp: u32 = c as u32 - 48;
        m += tmp;
        m %= 9;
    }

    if m % 9 == 0 {
        println!("Yes");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    REP(i,0,n) cin >> a[i];
    REP(i,0,n) a[i] -= i+1;
    sort(a,a+n);
    int b = a[(n+1)/2-1];
    ll ans = 0;
    REP(i,0,n) ans += abs(a[i]-b);
    cout << ans << endl;
    return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int r;
    cin >> r;
    double ans = 2 * PI * r;
    printf("%.20f\n", ans);
    return 0;
}


Measured memory_bytes: 3768
N, K = map(int, input().split())
from itertools import accumulate
from bisect import bisect_left

lis = []
lis = [tuple(map(int, input().split())) for i in range(N)]
lis.sort()
Bs = [y for x, y in lis]
cB = list(accumulate(Bs))

print(lis[bisect_left(cB, K)][0])


Measured memory_bytes: 65240
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        int[] X = new int[1_000_00];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
            X[a[i]]++;
        }
        int res = 0;
        for (int i = 0; i < 1_000_00; i++) {
            if (i != 0 && i != 1_000_00 - 1) {
                res = Math.max(res, X[i - 1] + X[i] + X[i + 1]);
            }
            if (i == 0) {
                res = Math.max(res, X[0] + X[1]);
            }
            if (i == 1_000_00 - 1) {
                res = Math.max(res, X[1_000_00 - 1] + X[1_000_00 - 1 - 1]);
            }
        }
        System.out.println(res);

    }

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

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

    private long lcm(long[] a) {
        long x = a[0];
        for (int i = 0; i < a.length; i++) {
            x = lcm(a[i], x);
        }
        return x;
    }
}


Measured memory_bytes: 50496
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll m = 1000000000000000000;
int main() {
  int n;
  cin >> n;
  ll ans = 1;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
    if(a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  for(auto num : a) {
    if(m / ans < num) {
      cout << -1 << endl;
      return 0;
    }
    ans *= num;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4052
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>
#include <stack>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    int N;
    string s;
    cin >> N >> s;
    vl a(N);
    stack<char> st;
    rep(i, 0, N) {
        if (st.empty()) {
            st.push(s[i]);
        } else {
            if (st.top() == s[i]) {
            } else {
                st.push(s[i]);
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

ll solve(ll ai, ll aj, ll bi, ll bj)
{
    if(aj > bj)
    {
        swap(ai, bi);
        swap(aj, bj);
    }
    ll s = 1;
    rep(i,30) s *= 3;
    ll dist = abs(ai-bi) + abs(aj-bj);
    ll res = dist;
    while(1)
    {
        s /= 3;
        if(s <= 0) break;
        ll nai = ai/s, nbi = bi/s;
        if(nai != nbi) break;
        ll naj = aj/s, nbj = bj/s;
        if(nai%3 == 1 && abs(naj-nbj) > 1)
        {
            ll up = s*nai - 1;
            ll bot = s*(nai+1);
            ll loss = min(ai, bi) - up;
            loss = min(loss, bot - max(ai, bi));
            res = dist + loss*2;
            break;
        }
    }
    return res;
}

int main()
{
    int q;
    cin >> q;
    rep(qi,q)
    {
        ll ai, aj, bi, bj;
        cin >> ai >> aj >> bi >> bj;
        ai--; aj--;
        bi--; bj--;
        ll ans = 0;
        ans = max(ans, solve(ai, aj, bi, bj));
        ans = max(ans, solve(aj, ai, bj, bi));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))

sa=float("inf")


wa1=0
wa2=sum(a)

for i in range(n-1):
  wa1+=a[i]
  wa2-=a[i]
  temp=abs(wa1-wa2)
  sa=min(sa,temp)
print(sa)

Measured memory_bytes: 26220
#include <iostream>
using namespace std;
const int SIZE = 100000;

int Partition(int *A, int p, int r)
{
    int x = A[r - 1];
    int i = p;
    for (int j = p; j < r - 1; j++)
    {
        if (A[j] <= x)
        {
            int tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;

            i++;
        }
    }

    int tmp = A[i];
    A[i] = A[r - 1];
    A[r - 1] = tmp;

    return i;
}

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

    int A[SIZE];
    int n;

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

    int par = Partition(A, 0, n);

    int i;
    for (i = 0; i < par; i++)
    {
        cout << A[i] << ' ';
    }
    cout << '[' << A[i] << ']' << ' ';
    i++;
    for (; i < n - 1; i++)
    {
        cout << A[i] << ' ';
    }
    cout << A[i] << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

using namespace std;

int Limit(int X, int base) {
	int limit = base;
	while (limit * base <= X) {
		limit *= base;
	}
	return limit;
}

int main() {
	int X;
	cin >> X;
	int Max = (int)sqrt(X);
	int Answer = 1;
	for (int i = 2; i <= Max; i++) {
		Answer = max(Answer, Limit(X, i));
	}
	cout << Answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{char n,m,a,b;
scanf("%c %c",&n,&m);
{if(n=='A')
a=10;
else if(n=='B')
a=11;
else if(n=='C')
a=12;
else if(n=='D')
a=13;
else if(n=='E')
a=14;
else if(n=='F')
a=15;
}
{if(m=='A')
b=10;
else if(m=='B')
b=11;
else if(m=='C')
b=12;
else if(m=='D')
b=13;
else if(m=='E')
b=14;
else if(m=='F')
b=15;
}
if(a>b) printf(">\n");
else if(a==b) printf("=\n");
else if(a<b) printf("<\n");

return 0;	
}

Measured memory_bytes: 128
n = int(input())
l = list(map(int,input().split()))

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]==l[j] or l[j]==l[k] or l[k]==l[i]:
                continue
            else:
                t=[l[i],l[j],l[k]]
                t.sort()
                if t[0]+t[1]>t[2]:
                    ans+=1
print(ans)


Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define pii pair<int,int>
#define f first
#define se second
using namespace std;
double pi=acos(-1.0);
int m=1000000007;
bool cmp2(int n,pii p)
 {return n<p.f;}
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};
int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%m;n=(n*n)%m;x=x>>1;}
 return ans;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int32_t main(){
//ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int dp[n];
dp[0]=0;dp[1]=abs(a[0]-a[1]);
for(int i=2;i<n;i++)
dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
cout<<dp[n-1];
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 1e5 + 7;
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int main()
{
	ios::sync_with_stdio(false);
	int n, k;
	while (cin >> n >> k) {
		int maxV, odd = 0, even = 0, tmp, mod;
		cin >> mod;
		maxV = mod;
		for (int i = 1; i < n; ++i) {
			cin >> tmp;
			mod = gcd(mod, tmp);
			maxV = max(maxV, tmp);
		}
		if (maxV < k) puts("IMPOSSIBLE");
		else {
			if (mod == gcd(mod, k)) puts("POSSIBLE");
			else puts("IMPOSSIBLE");
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    int a,b,c;
    cin >> a >>b >> c;
    if(b / a > c) cout << c << '\n';
    else cout << b / a << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,k,s;
int arr[100001];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k>>s;
    if (k==n){
        for (int i=0;i<n;i++){
            cout<<s<<' ';
        }
        return 0;
    }
    if (s==1){
        for (int i=0;i<k;i++) cout<<1<<' ';
        for (int i=k;i<n;i++){
            cout<<2<<' ';
        }
        return 0;
    }
    for (int i=0;i<n;i++){
        arr[i]=1;
    }
    for (int i=0;i<=k/2;i++){
        arr[i*2]=s-1;
    }
    for (int i=k+1;i<n;i++){
        if (s==1e9){
            arr[i]=2;
        }
        else {
            arr[i]=s+1;
        }
    }
    for (int i=0;i<n;i++){
        cout<<arr[i]<<' ';
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
	int N;

	cin >> N;

	map<long long, long long> count;
	vector<int> A(N);

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

	long long total = 0;

	for (auto i : count) {
		total += i.second * (i.second - 1) / 2;
	}

	for (int i = 0; i < N; i++) {
		long long ans;
		ans = total - count[A[i]] + 1;

		cout << ans << endl;
	}


	return 0;
}

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

int main()
{
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long ans = 0;
    if (k <= a)
    {
        cout << k << endl;
        return 0;
    }
    else
    {
        k -= a;
        ans += a;
        if (k <= b)
        {
            cout << ans << endl;
            return 0;
        }
        else
        {
            ans -= (k - b);
            cout << ans << endl;
        }
    }
    return 0;
}

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

swap_count=0
for i in range(N):
    minj  = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j

    if i != minj:
        A[i], A[minj] = A[minj], A[i]
        swap_count += 1
print(*A)
print(swap_count)

Measured memory_bytes: 7752
A, B, C, D = map(int, input().split())
if C <= A <= D <= B:
    print(D - A)
elif C <= A <= B <= D:
    print(B - A)
elif A <= C <= D <= B:
    print(D - C)
elif A <= C <= B <= D:
    print(B - C)
else:
    print(0)

Measured memory_bytes: 3060
// Aizu Vol-1 0107: Carry a Cheese
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

long long min3(long long d1, long long d2, long long d3)
{
	if (d2 < d1) d1 = d2;
	if (d3 < d1) d1 = d3;
	return d1;
}

int main()
{
	long long d, w, h, min, r;
	int i, n;

	while (1) {
		gets(p = buf); d = getInt(), w = getInt(), h = getInt();
		if (!d && !w && !h) break;
		min = min3(d*d + w*w, d*d + h*h, w*w + h*h);
		gets(p = buf); n = getInt();
		for (i = 0; i < n; i++) {
			gets(p = buf); r = getInt(); r = 4 * r * r;
			puts(r > min ? "OK" : "NA");
		}
	}
	return 0;
}

Measured memory_bytes: 524
using namespace std;

#include <bits/stdc++.h>

int main(){
    long long N;
    cin >> N;
    set< int > a;
    long long ans = N;
    long long ans1 = 0;
    for ( int i = 1; i <= pow ( 10, 6 ); i ++ ){
        if ( N % i == 0 ) {
            long long t = abs( ( N / i ) - i );
            if ( t < ans ){
                ans1 = N / i + i - 2;
                ans = t;
            }
        }
    }
    cout << ans1;

    return 0;
}


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

int main(){
        int n;
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n;i++){
                cin>>a[i];
                if(a[i]%2==0){
                        if(a[i]%3==0||a[i]%5==0)continue;
                        else{
                                cout<<"DENIED"<<endl;
                                return 0;
                        }
                }
        }
        cout<<"APPROVED"<<endl;
        return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(M)]
ans = min(a)+min(b)
for x, y, c in xyc:
    ans = min(ans, a[x-1]+b[y-1]-c)
print(ans)


Measured memory_bytes: 38820
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> T(N), A(N);
    rep(i,N){
        cin >> T[i] >> A[i];
    }
    ll ct=0,ca=0;
    rep(i,N){
        ll c =  __gcd(T[i],A[i]);
        ll mt = T[i]/c;
        ll ma = A[i]/c;
        ll nt = mt;
        ll na = ma;
        if(ct > nt || ca > na){
            ll q = max(((ct-nt+mt-1)/mt), ((ca-na+ma-1)/ma));
            nt = q*mt + mt;
            na = q*ma + ma;
        }
        ct = nt;
        ca = na;
    }
    cout << ct + ca << endl;
}

Measured memory_bytes: 3624
use std::cmp::{max, min};

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    // for k in 2..10 {
    //     let mut v = vec![0; 100];
    //     for a in 1..100 {
    //         let w = a / k;

    //         let mut tt = vec![];
    //         for i in 0..w {
    //             if a > i + 1 {
    //                 tt.push(v[a - i - 1]);
    //             }
    //         }
    //         tt.sort();

    //         for x in 0.. {
    //             if !tt.contains(&x) {
    //                 v[a] = x;
    //                 break;
    //             }
    //         }
    //     }

    //     println!("{}: {:?}", k, v);
    //     println!();

    //     let w: Vec<i64> = (0..100).map(|a| g(a, k as i64)).collect();
    //     assert_eq!(v, w);
    // }

    let n = reads()[0];

    let ak: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let t = reads();
            (t[0], t[1])
        })
        .collect();

    let g = ak.iter().map(|&(a, k)| g(a, k)).fold(0, |x, y| x ^ y);

    println!("{}", if g == 0 { "Aoki" } else { "Takahashi" });
}

fn g(a: i64, k: i64) -> i64 {
    // if a % k == 0 {
    //     a / k
    // } else {
    //     g(a / k * (k - 1) + a % k - 1, k)
    // }

    let mut a = a;

    while a > k && a % k > 0 {
        let d = a / k + 1;
        let n = (a % k + d - 1) / d;
        a -= n * d;

        // a = a / k * (k - 1) + a % k - 1;
    }

    a / k
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  int k,t;
  cin >> k >> t;
  std::vector<int> v;
  for(int i=0;i<t;i++){
    int a;
    cin >> a;
    v.push_back(a);
  }
    v.push_back(0);
  int ans=0;
  sort(v.begin(),v.end(),std::greater<int>());
  int sum=0;
  for(int i=1;i<t;i++) sum+= v[i];
  ans=max(0,v[0]-sum-1);

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    double arr[n], val = 0.0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        val += (1.0/arr[i]);
    }
    double ans = 1.0/val;
    cout<<setprecision(10)<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	int N, M;
  	cin >> N >> M;
  	int a[100] = {0}, num[N+1] = {0};	
  
  	for(int i=0; i < 2*M ;i++){
       cin >> a[i];
    }
  
  	for(int i =0; i < 2*M; i++){
       num[a[i]]++ ;
    }
  
 	for(int i=0 ;i < N ; i++){
      	cout << num[i+1] << endl;
    }
}
  	

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
  
  string m="kstnhmyrw";
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++)
    {
      if(s[i]>'1' && s[i]<='9')
	cout<<m[s[i]-'0'-2];
	//	cout<<(char)m[s[i]-'0'+1];
      if(s[i]=='0' && s[i+1]!='U')
	cout<<'w';
      if(s[i]=='T')
	cout<<'a';
      if(s[i]=='L')
	cout<<'i';
      if(s[i]=='U')
	if(s[i-1]!='0')
	  cout<<'u';
	else 
	  cout<<"nn";
      if(s[i]=='R')
	cout<<'e';
      if(s[i]=='D')
	cout<<'o';
    }
  cout<<endl;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000

void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  cout<<n/3<<endl;

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


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n, m, ans= 0;
  cin>>n>>m;
  if(n>=2){
    ans += (n*(n-1))/2;
  }
  if(m>=2){
    ans += (m*(m-1))/2;
  }
  cout<<ans<<"\n";
  return 0;
}

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

long long pow_ans(long long x, int n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main(){
	string s;
    int n, ans=0;
	cin >> s;
    n=stoi(s);
    for(int i=2; i<=s.size(); i+=2){
        ans += pow_ans(10, i-1)-pow_ans(10, i-2);
    }
    if(s.size()%2==1){
        ans += n-pow_ans(10, s.size()-1)+1;
    }
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] A = in.Int(N);

            Arrays.sort(A);
            long ans = A[N - 1];
            for (int i = 1; i < N / 2; i++) {
                ans += A[N - 1 - i] * 2;
            }
            if (N % 2 == 1) ans += A[(N / 2)];
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 55292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repe(i, n) for(int (i) = 0; i <= (n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) > 0; --(i))
#define repre(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define elm1(pair) (pair).first
#define elm2(pair) (pair)).second
typedef long long ll;
typedef unsigned long long ull;
const ull MOD = 1000000007;
ull mpow(ull a, ull n);
ull inv_mod(ull a){return mpow(a, MOD-2);}

ull mpow(ull a, ull n)
{
    ull ans = 1;
    while(n>>=1){
        if(n & 1)(ans *= a)%= MOD;
        (a*=a)%=MOD;
    }
    return ans;
}

ull nCr(ull n, ull r)
{
    vector<ull> factorial(n+1);
    factorial[0]=1;
    rep(i, n)factorial[i+1] = factorial[i]*(i+1)%MOD;
    return factorial[n]*(inv_mod(factorial[n-r])%MOD*inv_mod(factorial[r])%MOD) % MOD;
}

struct Edge{
    int to, id;
};

vector<vector<Edge>> to;
vector<int> ans;

void dfs(int v, int c =-1, int p=-1)
{
    int k = 1;
    rep(i, to[v].size()){
        int u = to[v][i].to, ei = to[v][i].id;
        if(u == p)continue;
        if(k == c)++k;
        ans[ei] = k; ++k;
        dfs(u,ans[ei], v);
    }
}

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

    int a = N / 100;
    int b = N % 100;
    int flag = 0;
    int max_k;
    if(a > 99)max_k = 99;
    else max_k = a;
    if(b == 0){
        flag = 1;
    }
    else{
        for(auto c = 0; c<= max_k; c++){
            for(auto d = 0; d<=(max_k-c); d++) {
                for (int e = 0; e<=(max_k-c-d); e++) {
                    for (int f = 0; f<=(max_k-c-d-e); f++){
                        for(int g = 0; g<=(max_k-c-d-e-f);g++) {
                            if (c + d * 2 + e*3 + f * 4 + g * 5 == b) {
                                flag = 1;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    if(flag)cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, L = map(int,input().split())

taste = []
for i in range(1,N + 1):
    taste.append(L + i - 1)

SUM = sum(taste)

DIF = abs(SUM - (SUM - taste[0]))
ans = SUM - taste[0]
for i in range(1,N):
    x = SUM - taste[i]
    if abs(SUM - x) < DIF:
        DIF = abs(SUM - x)
        ans = x
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>

using namespace std;

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

    string ans1;
    string ans2;
    string ans;
    

    for(int i=0; i<m; i++){
        char x = '0' + n;
        ans1.push_back(x);
    }

    for(int i=0; i<n; i++){
        char x = '0' + m;
        ans2.push_back(x);
    }

    if(ans1<ans2)
        ans = ans1;
    else
        ans = ans2;    

    std::cout << ans << std::endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main ()
{
	int a[3][3];
	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	int k,l;
	k=2*(a[0][0]+a[1][1]+a[2][2]);
	l=a[0][1]+a[0][2]+a[1][0]+a[1][2]+a[2][0]+a[2][1];
	
	if (k==l)
	{
		cout<<"Yes";
	}
	else 
	{
		cout<<"No";
	}
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        
        //set array
        String[] st = br.readLine().split(" ");
        int[] array = new int[n];
        for (int i = 0; i < n; i++){
            int a = Integer.parseInt(st[i]);
            array[i] = a;
        }
        
        int count = bubbleSort(array);
        printArray2(array);
        System.out.println(count);
        
    }
    static void printArray(int[] arr){
        for (int i = 0; i < arr.length - 1; i++){
            System.out.print(arr[i]);
            System.out.print(" ");
        }
        System.out.println(arr[arr.length-1]);
    }
    static void printArray2(int[] arr){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length - 1; i++){
            sb.append(arr[i]);
            sb.append(" ");
        }
        sb.append(arr[arr.length - 1]);
        System.out.println(sb.toString());
    }
    static int bubbleSort(int[] arr){
        //bubble sort and count swaps
        int swapcnt = 0;
        for (int i = 0; i < arr.length; i++){
            for (int j = arr.length - 1; j > i; j--){
                if ( arr[j] < arr[j-1]){
                    swap(arr, j, j - 1);
                    swapcnt += 1;
                }
            }
        }
        return swapcnt;
    }
    static void swap(int[] arr, int i, int j){
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}

Measured memory_bytes: 17044
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 

int  A(int x){
    if(x>=0)return x;
    else return -x;
}

ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x%N;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N)*(y%N) % N;
		k /= 2;
	}
	return res;
}

unsigned long long popCount64bitB(unsigned long long x) 
{ 
    x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) 
      +  (x & 0x5555555555555555UL); 
    x = ((x & 0xccccccccccccccccUL) >> 2) 
      +  (x & 0x3333333333333333UL); 
    x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) 
      +  (x & 0x0f0f0f0f0f0f0f0fUL); 
    x = ((x & 0xff00ff00ff00ff00UL) >> 8) 
      +  (x & 0x00ff00ff00ff00ffUL); 
    x = ((x & 0xffff0000ffff0000UL) >> 16) 
      +  (x & 0x0000ffff0000ffffUL); 
    x = ((x & 0xffffffff00000000UL) >> 32) 
      +  (x & 0x00000000ffffffffUL); 
    return x; 
} 

bool g[13][13];

int main(void){
    int n,k;
    cin>>n>>k;
    int index = 1;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a==1){
            index = i+1;
        }
    }
    int ans = 0;
    int length = 0;
    while(true){
        ans++;
        length+=k;
        if(length>=n)break;
        else length--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256