akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){
    ll N; cin >> N;
    if(N%10==2||N%10==4||N%10==5||N%10==7||N%10==9) cout << "hon" << endl;
    else if(N%10==0||N%10==1||N%10==6||N%10==8)cout << "pon"<<endl;
    else cout << "bon"<<endl;
}
void b(){
    ll K; cin >> K;
    string S; cin >> S;
    if(S.size()<=K) cout << S << endl;
    else{
        rep(i,K) cout << S[i];
        cout << "..."<<endl;
    }
}

void c(){
    double A,B,H,M; cin >> A >> B >> H >> M;
    double theta = abs((H/12+M/(12*60)-M/60)*2*M_PI);
    cout << fixed << setprecision(15) <<sqrt(A*A+B*B-2*A*B*cos(theta));
}

void d(){
}
void e(){
}
void f(){}
int main(){
    c();
    return 0;
}


Measured memory_bytes: 4200
import math

mod = (int)(1e9+7)

def fat(N):
    ret = 1

    for i in range(1, N+1):
        ret*=i
        ret%=mod

    return ret

def modInverse(b): 
    g = math.gcd(b, mod)  
    if (g != 1): 
        return -1
    else:
        return pow(b, mod-2, mod) 
  
  
def modDivide(a, b): 
    a %= mod
    inv = modInverse(b) 
    
    return (inv*a) % mod 

S = (int)(input())

resp = 0

for i in range(1, S):
    n = i
    k = S-3*i

    if (k < 0):
        break

    resp += modDivide(fat(n+k-1), fat(n-1)*fat(k))
    resp%=mod

print(resp)

Measured memory_bytes: 9164
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

ll llmax(ll a, ll b){
  return a > b ? a : b;
}

int main(){
  ll H, W;
  cin >> H >> W;
  string s;
  ll grid[H][W] = {};
  rep(h, H){
    cin >> s;
    rep(w, W) if(s[w] == '#') grid[h][w] = 1;
  }
  ll ans = 0;
  ll n_tate[W];
  ll n_yoko = -1;
  rep(w, W) n_tate[w] = -1;
  rep(h, H){
     rep(w, W){
      if(grid[h][w]){
        n_tate[w] = -1;
        n_yoko = -1;
      }
      else{
        if(n_tate[w] < 0){
          n_tate[w] = 0;
          repi(i, h, H){
            if(grid[i][w]) break;
            n_tate[w]++;
          }
        }
        if(n_yoko < 0){
          n_yoko = 0;
          repi(i, w, W){
            if(grid[h][i]) break;
            n_yoko++;
          }
        }
        // cout << n_tate[w] << " " << n_yoko << endl;
        ans = llmax(ans, n_tate[w] + n_yoko - 1);
      }
    }
    n_yoko = -1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
bool debug = false;

int main() {
  int Ans = 0;  // 回答：ｉ番目が最小値となる場合の数：必ず１つ目は成立する。
  int N; cin >> N; // 数値の個数

  // P[]の i-1 までの最小値を保管しておき、それよりも小さければ、カウントして最小値更新。
  int Min = 1e9;  // 前回までの最小値
  int P;
  rep(i,N){
    cin >> P;
    if ( P < Min ) {
      Ans++;
      Min = P;
    }
  }
  cout << Ans << endl;
}


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

class Timer {
private:
    chrono::high_resolution_clock::time_point start;
public:
    Timer() {
        reset();
    }
    void reset() {
        start = chrono::high_resolution_clock::now();
    }
    chrono::milliseconds::rep elapsed() {
        auto end = chrono::high_resolution_clock::now();
        return chrono::duration_cast<chrono::milliseconds>(end - start).count();
    }
} timer;

const int D = 365, N = 26;

int ans = 0;

vector<int> C(N), T(D), score(N);
vector<vector<int>> S(D, vector<int>(N));
vector<vector<int>> L(N, vector<int>(D, -1));
vector<set<int>> H(N);

int calc(int t) {
    int res = 0;
    for(auto &d : H[t]) res += S[d][t];
    for(int d = 0; d < D; ++d) res -= C[t] * (d - L[t][d]);
    return res;
}

void updateLast(int t) {
    L[t].assign(D, -1);
    for(auto &i : H[t]) L[t][i] = i;
    for(int _d = 1; _d < D; ++_d) L[t][_d] = max(L[t][_d], L[t][_d - 1]);
}

int temp(int time) {
    return (2000 - time) / 200 + 1;
}

int main() {
    srand(time(NULL));
    int _; cin >> _;
    for(int i = 0; i < N; ++i) cin >> C[i];
    for(int i = 0; i < D; ++i) {
        for(int j = 0; j < N; ++j) cin >> S[i][j];
    }

    for(int i = 0; i < D; ++i) {
        int mx = max_element(S[i].begin(), S[i].end()) - S[i].begin();
        T[i] = mx;
        L[T[i]][i] = i;
        H[T[i]].insert(i);
    }
    for(int d = 1; d < D; ++d) {
        for(int i = 0; i < N; ++i) {
            L[i][d] = max(L[i][d], L[i][d - 1]);
        }
    }

    for(int t = 0; t < N; ++t) {
        score[t] = calc(t);
        ans += score[t];
    }

    auto time = timer.elapsed();
    while(time < 1900) {
        time  = timer.elapsed();
        int best = ans;
        vector<int> T_pre(T), score_pre(score);
        vector<vector<int>> L_pre(L);
        vector<set<int>> H_pre(H);

        set<int> changed;
        int roop = temp(time);
        while(roop--) {
            int d = rand() % D;
            int q = rand() % N;
            int p = T[d];
            if(p == q) continue;
            changed.insert(p);
            changed.insert(q);
            H[p].erase(d);
            H[q].insert(d);
            T[d] = q;
        }
        for(auto &p : changed) {
            best -= score[p];
            updateLast(p);
            score[p] = calc(p);
            best += score[p];
        }
        if(ans < best) {
            ans = best;
        } else {
            T = T_pre;
            score = score_pre;
            L = L_pre;
            H = H_pre;
        }
    }
    for(int d = 0; d < D; ++d) cout << T[d] + 1 << '\n';
    return 0;
}


Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = 0;
		int M = 0;
		N = sc.nextInt();
		M = sc.nextInt();
		int ans = 0;
		ans = N * (N - 1) / 2 + M * (M - 1) / 2;
		System.out.println(ans);
		sc.close();
	}

}

Measured memory_bytes: 22600
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a;
    int temp;

    for (int i = 0; i < n; i++) {
        cin >> temp;
        a.push_back(temp);
    }

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

    double ans = a[0];

    for (int i = 0; i < n-1; i++) {
        ans = (ans + a[i + 1]) / 2.0;
    }
    cout << setprecision(100) << ans;

    
    return 0;
}

Measured memory_bytes: 256
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

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

const int N = 1e5 + 5;
const ll X = 1e5 - 1;

int main()
{
	ll l = 2, r = 1e9, temp = 10;
	while (l <= r)
	{
		cout << "? " << temp << endl;
		char c;
		cin >> c;
		if (c == 'Y')
		{
			l = temp + 1;
			temp *= 10;
		}

		else
		{
			r = temp - 1;
			break;
		}
	}

	--l;
	ll st = l;
	while (l < r)
	{
		ll mid = (l + r) / 2;
		cout << "? " << mid << X << endl;
		char c;
		cin >> c;
		if (c == 'Y')
			r = mid;
		else
			l = mid + 1;
	}

	if (l > st)
	{
		cout << "! " << l << endl;
		return 0;
	}

	vector <ll> v;
	for (temp = 1; temp <= st; temp *= 10)
		v.pb(temp);

	int n = v.size();
	l = 0, r = n - 1;
	while (l < r)
	{
		int mid = (l + r) / 2;
		cout << "? " << 2 * v[mid] << endl;
		char c;
		cin >> c;
		if (c == 'Y')
			r = mid;
		else
			l = mid + 1;
	}

	cout << "! " << v[l] << endl;
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll inf = (1LL<<60);

int N, Q, K;
vector<pair<int,ll>> adj[100005];
bool seen[100005];
ll dist[100005];

void bfs(){
    queue<int> q;
    q.push(K);
    seen[K] = true;
    dist[K] = 0;

    while(!q.empty()){
        int now = q.front(); q.pop();
        for(auto u:adj[now]){
            if(dist[u.first] > dist[now]+u.second){
                dist[u.first] = dist[now]+u.second;
                seen[u.first] = true;
                q.push(u.first);
            }
        }
    }
}

int main(){
    cin >> N;
    for(int i=0; i<N-1; i++){
        ll a, b, c; cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c}); 
    }

    int q; cin >> q;
    cin >> K;

    for(int i=0; i<100005; i++) dist[i] = inf;
    bfs();

    vector<int> x(q), y(q);
    for(int i=0; i<q; i++) cin >> x[i] >> y[i];
    for(int i=0; i<q; i++) cout << dist[x[i]]+dist[y[i]] << endl;
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)    cerr<<#x<<" : "<<x<<endl;
#define trace2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl;
#define fast_io 	std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;
int solve(vi &e,vi &w,int i,int n)
{
	int ans=0;
	int wl,el,wr,er;
	wl=w[i-1];
	el=w[i-1];
	wr=w[n-1]-w[i];
	er=e[n-1]-e[i];
	ans=er+wl;
	//trace3(i,er,wl)
	return ans;
}

int main()
{
	fast_io;
	int n;
	string s;
	cin>>n>>s;
	int ans=1e9+7;
	vi w(n,0),e(n,0);
	if(s[0]=='W')w[0]++;
	else e[0]++;
	for(int i=1;i<n;i++){
		w[i]+=w[i-1];e[i]+=e[i-1];
		if(s[i]=='W'){
			w[i]++;
		}
		else{
			e[i]++;
		}
	}
	//for(int i=0;i<n;i++)trace2(e[i],w[i])
	for(int i=1;i<n-1;i++){
		ans=min(ans,solve(e,w,i,n));
	}
	int er,wl;
	er=e[n-1]-e[0];
	wl=0;
	ans=min(ans,er);
	er=0;
	wl=w[n-2];
	ans=min(ans,wl);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2964
(* O(2^d d) *)
Scanf.scanf " %d %d" @@ fun d g ->
  let pcs = Array.init d @@ fun _ -> Scanf.scanf " %d %d" @@ fun p c -> p, c in
  let ans = ref max_int in
  let rec find acc rest i bits =
    if rest <= 0 then acc
    else if i < 0 then max_int
    else if bits lsr i land 1 = 1 then find acc rest (i - 1) bits
    else
      let p, _ = pcs.(i) in
      let m = (i + 1) * 100 in
      let n = min (p - 1) @@ (rest + m - 1) / m in
      find (acc + n) (rest - n * m) (i - 1) bits in
  let points = Array.init d @@ fun i -> let p, c = pcs.(i) in i, p, p * (i + 1) * 100 + c in
  let f bits =
    let g (c, sum) (i, p, s) = if bits lsr i land 1 = 1 then c + p, sum + s else c, sum in
    Array.fold_left g (0, 0) points in
  for i = 0 to 1 lsl d - 1 do
    let c, s = f i in
    ans := min !ans @@ find c (g - s) (d - 1) i
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 640
H, W = map(int, input().split())


def f(x, y):
    res = float('inf')
    w = x // 2
    for h in range(1, y):
        a = h * x
        b = (y - h) * w
        c = (y - h) * (x - w)
        s = max(a, b, c) - min(a, b, c)
        res = min(s, res)

        h2 = (y - h) // 2
        if h2 == 0:
            continue
        b = h2 * x
        c = (y - h - h2) * x
        s = max(a, b, c) - min(a, b, c)
        res = min(s, res)
    return res


ans = float('inf')
ans = min(f(W, H), ans)
ans = min(f(H, W), ans)

print(ans)


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int l;
  cin >> l;
  int c = 1;
  int r = 0;
  for (; c <= l; r++) {
    c <<= 1;
  }
  r--;
  cout << r + 1 << " ";
  vector<vector<int>> ans;
  int cur = 0;
  c = 1;
  for (int i = 1; i <= r; i++) {
    ans.push_back({i, i + 1, 0});
    ans.push_back({i, i + 1, c});
    cur += c;
    c <<= 1;
  }
  for (int i = r; i >= 1; i--) {
    int gain = (1 << (i - 1));
    if (gain + cur <= l - 1) {
      ans.push_back({i, r + 1, cur + 1});
      cur += gain;
    }
  }
  cout << ans.size() << '\n';
  for (auto v : ans) {
    cout << v[0] << " " << v[1] << " " << v[2] << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
/* 
****	
	AUTHOR :- @soham01 
****
*/
#include "bits/stdc++.h"
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long int n,m;
  cin>>n>>m;
  if(m==n)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a_arr = gets.chomp.split.map(&:to_i)

hash = {}
hash2 = {}
a_arr.each_with_index do |a, i|
  if i + a < n
    hash[i + a] ||= []
    hash[i + a] << i
  end
  if i - a > 0
    hash2[i - a] ||= []
    hash2[i - a] << i
  end
end
count = 0
hash.each do |k, arr|
  count += arr.length * (hash2[k] || []).length
end
puts count


Measured memory_bytes: 49048
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<math.h>
using namespace std;

void a()
{
    string s,t;
    cin >> s >> t;
    if (t.substr(0,t.length()-1)==s)
    cout << "Yes";
    else cout << "No"; 

    return;
}
void b()
{
    int a,b,c,k;
    cin >>a >> b >> c >> k;
    if(a>k)cout <<k;
    else{
        if(a+b>=k)cout <<a;
        else cout << 2*a+b-k;
    }
    return;
}
void c()
{
    int n,m,x;
    cin >> n >> m >> x;
    vector<int>c;
    vector<vector<int>>a(n);
    for(int i=0;i<n;i++)
    {
        int t_c;
        cin >> t_c;
        c.push_back(t_c);
        for(int j=0;j<m;j++)
        {
            int t_a;
            cin >> t_a;
            a[i].push_back(t_a);
        }
    }
    long long int cost = INT64_MAX;
    int flag = 0;
    for (int bit = 0;bit<(int)pow(2,n);bit++)
    {
        int p[m]={0};
        int t_cost=0;
        for(int i = 0;i<n;i++)
        {
            if((int)(bit & (1 << i))!=0)
            {
                t_cost+=c[i];
                for(int j=0;j<m;j++)
                {
                    p[j]+=a[i][j];
                }
            }

        }
        int judge=0;
        for(int i=0;i<m;i++)
        {
            if(p[i]<x)judge=1;
        }
        if(judge==0&&cost>t_cost){
            cost=t_cost;
            flag=1;}
    }
    if(flag==1)cout << cost;
    else cout<< -1;
    return;
}
void d()
{
    long long int n=0;
    long long int k=0;
    cin >> n >> k;
    long long int a[n]={0};
    for (long long int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]--;
    }
    long long int count_to_loop= 0ll;
    long long int loop_p=0ll;
    long long int loop_size = 0ll;
    
    for (int i=0;i<1;i++)
    {
        map<long long int,long long int>m;
        int flag=0;
        long long int t=0;
        long long int now = i;
        while(flag==0)
        {

            now = a[now];
            t++;
            if(m.count(now)!=0)
            {
                loop_size = t - m[now];
                loop_p = now;
                count_to_loop = m[now];
                flag=1;
                break;
            }
            m[now] = t;
        }
    }
    long long int now = 0ll;
    if(k>count_to_loop)
    {
        k -= count_to_loop;
        k = k%loop_size;
       now = loop_p;
    }
    for(long long int i=0;i<k;i++)
    {now = a[now];}
    
    cout <<now+1ll;

    return;
}
void e()
{
    return;
}
void f()
{
    return;
}
int main(void){
    //a();
    //b();
    //c();
    d();
    //e();
    //f();

    return 0;
}

Measured memory_bytes: 17340
#include <cstdio>
#include <queue>
using namespace std;
typedef pair<int,int> pii;
#define MP make_pair<int,int>
int q,a,v,score[1000001];
pii P;
priority_queue<pii> Q;
int main(){
  scanf("%d%d",&q,&q);
  Q.push(MP(0,-1));
  while(q--){
    scanf("%d%d",&a,&v);
    score[a] += v;
    Q.push(MP(score[a],-a));
    while(true){
      P = Q.top();
      if(score[-P.second]!=P.first)Q.pop();
      else{
        printf("%d %d\n",-P.second,P.first);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 5840
class Solution:
    def solve(self, D, T, S):
        time = D/S
        if time <= T:
            return 'Yes'
        else:
            return 'No'

if __name__ == '__main__':
    D, T, S = map(int, input().split())
    A = Solution()
    print(A.solve(D, T, S))

Measured memory_bytes: 9196
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 0;
    for(int i=0; i<N-2; i++) {
        if(S.substr(i,3) == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::mem::{replace, swap};

// [NOTE] つかうときには trim() 入れないと RE になるので注意
// abcde
fn read_as_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line
}

fn read_as_primitive<T: FromStr>() -> T {
    let s = read_as_line();
    s.trim().parse().ok().expect("failed to parse input")
}

fn main() {
    let n: usize = read_as_primitive();
    let mut a: Vec<i64> = vec![0; n];
    let mut first_two: ((usize, i64), (usize, i64)) = ((0, -10), (0, -10));

    for i in 0..n {
        a[i] = read_as_primitive();
        if (first_two.0).1 < a[i] {
            let prev = first_two.0;
            first_two = ((i, a[i]), prev);
        } else if (first_two.1).1 < a[i] {
            first_two = (first_two.0, (i, a[i]));
        }
    }

    for i in 0..n {
        if i == (first_two.0).0 {
            println!("{}", (first_two.1).1);
        } else {
            println!("{}", (first_two.0).1);
        }
    }

}

Measured memory_bytes: 7676
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n+1, true);
    for(int i=0; i<m; ++i){
        int a;
        cin >> a;
        ok[a] = false;
    }

    vector<int> dp(n+1, 0);
    dp[0] = 1;
    for(int i=1; i<=n; ++i){
        if(ok[i-1]){
            dp[i] += dp[i-1];
            dp[i] %= MOD;
        }
        if(i > 1 && ok[i-2]){
            dp[i] += dp[i-2];
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 640
#include  <iostream>
#include  <vector>
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

typedef long long ll;

vector <int> ki[200005];
vector <int> ans;

void dfs(int u, int p = -1)
{
	//範囲for
	for (int v : ki[u]) {
		if (v == p)  continue;
		ans[v] += ans[u];
		dfs(v, u);
	}
}

int main()
{
	int n, q;
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a;  //0ori
		--b;
		ki[a].push_back(b);
		ki[b].push_back(a);
	}
	ans.resize(n);
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;  //0ori
	}
	dfs(0);
	rep(i, n) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 23424
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int a[5] = {},s=0,m=10;
    for (int i = 0; i < 5;i++) {
        cin >> a[i];
        s += (a[i] - 1) / 10 + 1;
        if (m > (a[i]-1)%10) m = (a[i] - 1) % 10 ;
    }
    cout << s * 10 + m - 9 << endl;

}
     


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		long N = scan.nextLong();
		long a,a_len;
		long b,b_len;
		long min = 99999999;
		
		for(long i=(long) Math.sqrt(N);i>=1;i--){
			if(N % i == 0){
				a = i;
				b = N / i;
				
				a_len = String.valueOf(a).length();
				b_len = String.valueOf(b).length();
				
				if(a_len > b_len){
					min = a_len;
				}else{
					min = b_len;
				}
				break;
			}
		}
		
		System.out.println(min);
	}

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(){
  int A,B;
  string S;
  cin >> A >> B >> S;
  
  bool flag=true;
  for(int i=0;i<A+B+1;i++){
    if(S[i]!='-' && i==A) flag=false;
    if(S[i]=='-' && i!=A) flag=false; 
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){

  int H, W;


  while(1){
    cin >> H >> W;
    if(W==0&&H==0) break;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) {
      printf("#");
    }
    printf("\n");
  }
  printf("\n");
}



}



Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main()
{
  long long n, sum=0;
  std::vector<long long> list;
  std::cin >> n;
  list.resize(n);
  for(std::size_t i=0;i<n;i++) {
    std::cin >> list[i];
    sum += list[i];
  }
  std::cout << *std::min_element(list.begin(), list.end()) << " " << *std::max_element(list.begin(), list.end()) << " " << sum << std::endl;
  return 0;
}



Measured memory_bytes: 3184
N = int(input())
S = input()
SL = [0]
for i in range(N):
    if S[i] == '(':
        SL.append(SL[i] + 1)
    else:
        SL.append(SL[i] - 1)

mi = min(SL)
la = SL[-1]
if mi < 0:
    S = '(' * ((-1)*mi) + S
    la -= mi
if la >= 0:
    S += ')' * la
else:
    p = (-1)*la
    S = '(' * p + S

print(S)


Measured memory_bytes: 3064
#![allow(unused_imports)]

mod pcl {

}




fn comb(n: usize) -> usize {
    if n & 1 == 0 {
        (n / 2) * (n - 1)
    } else {
        ((n - 1) / 2) * n
    }
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n = s.trim().parse::<usize>().unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let a: Vec<_> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap() - 1)
        .collect();

    let mut s = vec![0; n];
    for &i in a.iter() {
        s[i] += 1;
    }

    let mut sum = 0;
    let mut minus = vec![0; n];
    for (i, &num) in s.iter().enumerate() {
        if num <= 1 {
            continue;
        }

        let c1 = comb(num);
        let c2 = comb(num - 1);
        assert!(c1 >= c2);
        sum += c1;
        minus[i] = c1 - c2;
    }

    for k in 0..n {
        println!("{}", sum - minus[a[k]]);
    }
}


Measured memory_bytes: 16248
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
 char x ;
 cin >> x ;
 if(x>='A' && x<='Z'){
    cout << 'A';
 }
 else{
    cout << 'a';
 }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}


Measured memory_bytes: 3608
#include<iostream>

using namespace std;

int main(){
  int a,b;
  cin >> a;
  cin >> b;
  int diff = b - a;

  int aa=0;
  int bb=0;
  for(int i = 1;i<diff;i++){
    aa = aa + i;
  }
  bb = aa + diff;

  cout << bb-b<<endl;
  return 0;
}

Measured memory_bytes: 256
C = [list(map(int,input().split())) for i in range(3)]

ans = "No"

for i in range(0,101):
  a = i
  b = [C[0][0] - a,C[0][1] - a,C[0][2] - a]
  for j in range(1,3):
    v = C[j]
    diff = [v[k] - b[k] for k in range(3)]
    if len(set(diff)) != 1 or any([i < 0 for i in diff]):
      break
  else:
    ans = "Yes"
    break

print(ans)

Measured memory_bytes: 3064
n, y = readline.split(' ').map(&:to_i)
r = '-1 -1 -1'

0.upto(n) do |a|
  0.upto(n - a) do |b|
    c = n - a - b

    if a * 10_000 + b * 5000 + c * 1000 == y
      r = "#{a} #{b} #{c}"
      break
    end
  end
end

puts r


Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int calc_gcd(int a, int b)
{
  if (b == 0)
    return a;
  return calc_gcd(b, a%b);
}

int main()
{
  int n;
  
  cin >> n;
  
  int a[n];
  for (int i=0;i<n;++i) {
    cin >> a[i];
  }
  
  int gcd[n][2];
  for (int i=0;i<n;++i) {
    gcd[i][0] = 0;
    gcd[i][1] = 0;
  }
  
  //[0-i)のgcd
  for (int i=0;i<n;++i) {
    if (i == 0) {
      gcd[i][0] = 0;
    } else if (i == 1) {
      gcd[i][0] = a[0];
    } else {
	  gcd[i][0] = calc_gcd(gcd[i-1][0], a[i-1]);
    }
  }
 
  // (i-(n-1)]のgcd
  for (int i=n-1;i>=0;--i) {
    //(i-(n-1)]のgcd
    if (i == n-1) {
      gcd[i][1] = 0;
    } else if (i == n-2) {
      gcd[i][1] = a[n-1];
    } else {
      gcd[i][1] = calc_gcd(gcd[i+1][1], a[i+1]);
    }
  }
  
  for (int i=0;i<n;++i) {
    if (gcd[i][0] == 0) {
      gcd[i][0] = gcd[i][1];
    } 
    else if (gcd[i][1] == 0) {
      gcd[i][1] = gcd[i][0];
    } 
  }
  /*
  for (int i=0;i<n;++i) {
    cout << gcd[i][0];
    cout << ',';
    cout << gcd[i][1];
    cout << endl;
  }
  */
  
  int max_gcd = 0;
  for (int i=0;i<n;++i) {
    int tmp_gcd = calc_gcd(gcd[i][0], gcd[i][1]);
    if (max_gcd < tmp_gcd)
      max_gcd = tmp_gcd;
  }
  

  int ans = max_gcd;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var wr *bufio.Writer = bufio.NewWriter(os.Stdout)

func nextInt() int {
	sc.Scan()
	val, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return val
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

type edge struct {
	to  int
	col int
	idx int
}

func main() {
	sc.Split(bufio.ScanWords)
	//
	s := nextLine()
	m := make(map[byte]int)
	for i := 0; i < len(s); i++ {
		m[s[i]]++
	}
	letters := make([]byte, len(s))
	for l := range m {
		letters = append(letters, l)
	}
	N := len(s)
	res := N
	for _, letter := range letters {
		tmp := 0
		for i := 0; i < N; i++ {
			if s[i] != letter {
				ni := i
				for j := i + 1; j < N; j++ {
					if s[j] == letter {
						tmp = max(tmp, j-i)
						ni = j
						break
					}
				}
				if ni == i {
					tmp = max(tmp, N-i)
					break
				} else {
					i = ni
				}
			}
		}
		res = min(res, tmp)
	}

	fmt.Fprintln(wr, res)
	wr.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	ll N,M;
	cin >> N >> M;
	vector<ll> s[M],p(M);
	FOR(i,0,M){
		ll k;
		cin >> k;
		FOR(j,0,k){
			ll x;
			cin >> x;
			s[i].push_back(x-1);
		}
	}
	FOR(i,0,M){
		cin >> p[i];
	}
	ll ans = 0;
	FOR(i,0,(1LL<<(N))){
		ll on = 0;
		FOR(j,0,M){
			ll onnum = 0;
			for(auto x:s[j]){
				if(i&(1<<x))onnum++;
			}
			if(onnum%2==p[j])on++;
		}
		if(on==M)ans++;
	}
	cout << ans << endl;
}


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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'

int main()
{
	int n,k,coun = 0,a;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
	{
		cin >> a;
		if(a >= k) coun++;
	}
	cout<< coun << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    cout << ((n + 999) / 1000) * 1000 - n << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int ans=0;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
for(int o=i+1;o<n;o++)
{
ans+=a[i]*a[o];
}
}
cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define LOCAL 0
#define lli long long int
const int mod=(int)(1e8);
const lli pINF=(lli)(1e15);
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
const int INT=1000000000;
const int INF=0x3f3f3f3f;
#define Pa pair<int,int>
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define ld long double
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}

int main() 
{
    int w;
    string s;
    cin>>s;
    cin>>w;
    int n=s.size();
    string ans="";
    
    for(int i=0;i<n;i+=w) ans+=s[i];
    
    cout<<ans<<endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  if(N%2 == 0){
    cout << 0.50000000 << endl;
  }else{
    float M = (N/2 + 1.0)/N;
    cout << M << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
      public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int k = sc.nextInt();
	if(k>0){
	    if(k<a){
		System.out.println(k);
	    }else if(k<=a+b){
		System.out.println(a);
	    }else{
		System.out.println(2*a+b-k);
	    }
	}else{
	    System.out.println(0);
	}
      }
}


Measured memory_bytes: 35848
#include <iostream>
#include <map>
#include <tuple>
#include <string>
using namespace std;

int main(){
	map<tuple<int, int, int>, int> map;
	int b, f, r, v, n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		map[make_tuple(b, f, r)] += v;
	}
	for(b = 1; b <= 4; b++){
		for(f = 1; f <= 3; f++){
			for(r = 1; r <= 10; r++){
				cout << " " << map[make_tuple(b, f, r)];
			}
			cout << endl;
		}
		if(b == 4) break;
		string str(20, '#');
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;


        signed main() {
      int x,y;
      cin>>x>>y;
      if(x%y==0){
              cout<<-1;
              return 0;
      }
      cout<<x;
        


      }


        


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

const int mod=1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;return 0;
    }
    ll ans=1;
    if(abs(n-m)==0){
        FOR(i,1,m+1) ans=(ans*i)%mod;
        FOR(i,1,n+1) ans=(ans*i)%mod;
        cout<<(ans*2)%mod<<endl;
    }
    if(abs(n-m)==1){
        FOR(i,1,m+1) ans=(ans*i)%mod;
        FOR(i,1,n+1) ans=(ans*i)%mod;
        cout<<ans%mod<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n;
ll a[maxn];
ll b[maxn];
ll c[maxn];
ll dp[maxn][5];

int main()
{
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    repd(i,2,n)
    {
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

Measured memory_bytes: 9804
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);

	ll ans = a[n-1];
	int num = 1;
	rrep(i, n - 2) {
		if (n - num - 1 >= 2) {
			ans += a[i] * 2;
			num += 2;
		}
		else if (n - num - 1 == 1) {
			ans += a[i];
			break;
		}
		else {
			break;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 5184
#include<cstdio>
using namespace std;
int ans,a,b;
char op,stp1,stp2;
int main(){
	scanf("%d",&a);
	scanf("%c",&stp1);
	scanf("%c",&op);
	scanf("%c",&stp2);
	scanf("%d",&b);
	if (op=='+'){
		ans=a+b;
	}else if (op=='-'){
		ans=a-b;
	}
	printf("%d",ans);
return 0;} 

Measured memory_bytes: 1688
import sys
input_data = int(input())

if __name__ == '__main__':
    hours = int(input_data / 3600)
    minutes = int((input_data - hours * 3600) / 60)
    seconds = int((input_data - hours * 3600 - minutes * 60))
    print('{0}:{1}:{2}'.format(hours, minutes, seconds))


Measured memory_bytes: 5596
#include <iostream>
#include <cmath>

using namespace std;

int main() {

    int bills,money;
    int ten_thousand_yen = -1;
    int five_thousand_yen = -1;
    int one_thousand_yen = -1;

    cin >> bills >> money;

    for(int a = 0; a <= bills; ++a) {
        for(int b = 0; b + a <= bills; ++b) {
            int c = bills - a - b;
            int total = 10000 * a + 5000 * b + 1000 * c;
            if(total == money){
                ten_thousand_yen = a;
                five_thousand_yen = b;
                one_thousand_yen = c;
            }
        }
    }

    cout << ten_thousand_yen << " " << five_thousand_yen << " " << one_thousand_yen;
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i;
    int counter[26]={0};
    char ch;
     
    while(scanf("%c",&ch)!=EOF){
        if(ch==EOF) break;
        int num=ch-'a';
        if(0<=num && num<26){
            counter[num]++;
        }else if(-32<=num && num<-6){
            counter[num+32]++;
        }
    }
     
    for(i=0;i<26;i++){
        printf("%c : %d\n",'a'+i,counter[i]);
    }
    return 0;
}


Measured memory_bytes: 2032
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if (a%2==0||b%2==0){
            System.out.println("Even");
        }else{
            System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 21716
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
k, n = map(int, input().split()) # 入力が複数
houses = list(input().split())
houses = [int(h) for h in houses]
houses.sort()
max_dist = 0
total = 0
for i in range(n):
    if i == n - 1:
        d = abs(k - houses[i] + houses[0])
    else:
        d = houses[i + 1] - houses[i]
    max_dist = max(max_dist, d)
    total += d

ans = total - max_dist
print(ans)


Measured memory_bytes: 74572
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;




int main(){
    int N,K;

    cin>> N>>K;

    int Ai[100];

    for(int i=0;i<N;i++){
        Ai[i]=0;
    }

    for(int j=0;j<K;j++){
        int dtemp;
        cin >> dtemp;
        for(int i=0;i<dtemp;i++){
            int Atemp;
            cin>>Atemp;
            Ai[Atemp-1]++;
        }
    }
    int countnum=0;
    for(int i=0;i<N;i++){
        if(Ai[i]==0){
            countnum++;
        }

    }
    cout<<countnum<<endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


int N, M;
int A[100010];
int acc[100010];
map<int, int> m;


signed main(){
    cin >> N >> M;
    rep(i, 0, N) cin >> A[i];

    m[0] = 1;
    repe(i, 1, N) (acc[i] = acc[i-1]+A[i-1])%=M, m[acc[i]]++;

    int ans = 0;
    for(auto p : m) ans += p.second*(p.second-1)/2;

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){

    int n, i, j, k;

    cin >> n;

    vector<int>dp(3);

    vector<int>new_dp(3, 0);

    for(i = 0; i < n; i++){

        vector<int>c(3);

        for(j = 0; j < 3; j++){

            cin >> c[j];
        }
        for(j = 0; j < 3; j++){

            for(k = 0; k < 3; k++){

                if(k != j){

                    new_dp[k] = max(new_dp[k], dp[j] + c[k]);
                }
            }
        }
        dp = new_dp;
    }
    cout << max({dp[0], dp[1], dp[2]});

    return 0;
}

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

using namespace std;

typedef struct node_{
    int id;
    node_* left;
    node_* right;
}* node;

void printPreorder(node root){
    printf(" %d", root -> id);
    if(root -> left != NULL){
        printPreorder(root -> left);
    }
    if(root -> right != NULL){
        printPreorder(root -> right);
    }
}

void printInorder(node root){
    if(root -> left != NULL){
        printInorder(root -> left);
    }
    printf(" %d", root -> id);
    if(root -> right != NULL){
        printInorder(root -> right);
    }
}

void printTree(node root){
    if(root == NULL){
        printf("\n\n");
    }else{
        printInorder(root);
        printf("\n");
        printPreorder(root);
        printf("\n");
    }
}

void nodeInsert(node root, node nd){
    if(root -> id > nd -> id){
        if(root -> left == NULL){
            root -> left = nd;
        }else{
            nodeInsert(root -> left, nd);
        }
    }else{
        if(root -> right == NULL){
            root -> right = nd;
        }else{
            nodeInsert(root -> right, nd);
        }
    }
    
}

int main(){
    int n;
    scanf("%d", &n);
    char* option = new char[7];
    node root = NULL;
    for(int i = 0; i < n; i++){
        scanf("%s", option);
        if(strcmp(option, "insert") == 0){
                int id;
                scanf("%d", &id);
                node nd = new node_;
                nd -> id = id;
                nd -> left = NULL;
                nd -> right = NULL;
            if(root == NULL){
                root = nd;    
            }else{
                nodeInsert(root, nd);
            }
        }else{
            printTree(root);
        }
    }
    return 0;
}


Measured memory_bytes: 18784
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String x;
    int S = 0;
    while(true){
      x = sc.next();
      if(x.equals("0")){
        break;
      }
      for(int i=0;i<x.length();i++){
        S += x.charAt(i) - '0';
      }
      System.out.println(S);
      S = 0;
    }
  }
}


Measured memory_bytes: 26120