akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){

const int MAX_NO=100000;
int m[MAX_NO],f[MAX_NO],r[MAX_NO];
char hyouka[MAX_NO];
int a=0;
long long int b=0;
long long int c=0;

for(int i=1;i<MAX_NO;i++){

cin>>m[i]>>f[i]>>r[i];

a++;

if(m[i]==-1 && f[i]==-1 && r[i]==-1){
goto aa;
}

if(m[i]==-1 || f[i]==-1){
hyouka[i]='F';
}

else if((m[i]+f[i])>=80){
hyouka[i]='A';
}
else if((m[i]+f[i])>=65){
hyouka[i]='B';
}

else if((m[i]+f[i])>=50){
hyouka[i]='C';
}

else if((m[i]+f[i])>=30 && r[i]<50){
hyouka[i]='D';
}
else if((m[i]+f[i])>=30 && r[i]>=50){
hyouka[i]='C';
}

else if((m[i]+f[i])<30){
hyouka[i]='F';
}

}

aa:;

for(int i=1;i<a;i++){

for(long long int j=1;j<2000000000;j++){
b++;
b--;
b++;
if(b%2==0){
c++;
}
}

cout<<hyouka[i]<<endl;

}

return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K; cin >> N >> K;
  double ans=0;
  double now=1;
  double score=0;
  for(int i=1;i<=N;i++){
    score=i;
      while(true){
        if(score>=K){
          ans+=now;
          break;
        }
        else {
          score*=2;
          now/=2;
        }
      }
    now=1;
  }
  ans/=N;
  cout << fixed << setprecision(19);
  cout << ans << endl;
}
        
      
    

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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] line = br.readLine().split(" ");
            int a = Integer.parseInt(line[0]);
            int b = Integer.parseInt(line[2]);
            if (line[1].equals("+")){
            	System.out.println(a + b);
            }
            else if (line[1].equals("-")) {
            	System.out.println(a - b);
            }
            else if (line[1].equals("*")){
            	System.out.println(a * b);
            }
            else if (line[1].equals("/")){
            	System.out.println(a / b);
            }
            else{
            	break;
            }
        }
    }
}

Measured memory_bytes: 17056
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

vector<int> nxt(const vector<int> &vs){
	const int n=vs.size();
	vector<int> re(n+1);
	rep(i,n){
		++re[max(0,i-vs[i])];
		--re[min(n,i+vs[i]+1)];
	}
	rep(i,n) re[i+1]+=re[i];
	re.pop_back();
	return re;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int n,t;
	cin>>n>>t;
	vector<int> a(n);
	for(auto &x:a) cin>>x;
	// vector<int> a(100);
	int cnt=0;
	rep(_,t){
		auto nx=nxt(a);
		if(nx==a) break;
		a=nx;
		out(nx,1);
		++cnt;
	}
	rep(i,n) cout<<a[i]<<" \n"[i+1==n];
  return 0;
}


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

using namespace std;

int main()
{
    string S;
    string T;
    cin >> S >> T;

    bool req = false;

    for (int i = S.size() - 1; i >= 0; i--)
    {
        int count = 0;
        for (int j = 0; j < T.size(); j++)
        {
            if (i - j >= 0)
                if (S[i - j] == T[T.size() - 1 - j] || S[i - j] == '?')
                    count++;
        }

        if (count == T.size())
        {
            for (int j = 0; j < T.size(); j++){
                S[j + i - T.size() + 1] = T[j];
            }


            req = true;
            break;
        }
    }

    if (req)
    {
        for (int i = 0; i < S.size(); i++)
            if (S[i] == '?')
                S[i] = 'a';

        cout << S << endl;
    }
    else
    {
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e6
using namespace std;

bool dt[100][100];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m;

bool inside(int x,int y){
	if(x>=0 && x<m && y>=0 && y<n)return true;
	else return false;
}
	
int func(int x,int y){
	int res=1;
	dt[y][x]=0;
	rep(i,4){
		if(dt[y+dy[i]][x+dx[i]] && inside(x+dx[i],y+dy[i]))res=max(res,func(x+dx[i],y+dy[i])+1);
	}
	dt[y][x]=1;
	return res;
}

int main(){
	while(cin>>n>>m && n||m){
		if(!n&&!m)break;
		rep(i,100)rep(j,100)dt[i][j]=0;
		rep(i,n)rep(j,m)cin>>dt[i][j];
		int ans=-1;
		rep(i,n){
			rep(j,m){
				if(dt[i][j])ans=max(ans,func(j,i));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <stdlib.h>
int pop();
void push(int);
int stack[1000];
int num=0;
void push(int j){
  stack[num++]=j;
}
int pop(){
  if(num<=0) return 0;
  return stack[--num];
}

int main(){
  int i,j,k=0,Ans,a,b;
  char s[100];
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      Ans=a+b;
      push(Ans);
    }
    else if(s[0]=='-'){
      a=pop();
      b=pop();
      Ans=b-a;
      push(Ans);
      
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      Ans=a*b;
      push(Ans);
      
    }
    else {
      j=atoi(s);    
      push(j);
    }
  }
  Ans=pop();
  printf("%d\n",Ans);
  return 0;
}



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

const int MAXN = 505;

int n, a[MAXN];
int v[MAXN*MAXN];

pair<int,int> pos[MAXN];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]), v[a[i]] = i, pos[i] = make_pair(a[i], i);
	sort(pos+1, pos+n+1);
	int j = 1;
	for (int t = 1; t <= n; t++) {
		int i = pos[t].second;
		for (int k = 1; k < i; k++) {
			while (j <= n*n && v[j]) j++;
			if (j >= a[i]) {
				puts("No");
				return 0;
			}
			v[j++] = i;
		}
	}
	j = n*n;
	for (int t = n; t >= 1; t--) {
		int i = pos[t].second;
		for (int k = 1; k <= n-i; k++) {
			while (j > 0 && v[j]) j--;
			if (j <= a[i]) {
				puts("No");
				return 0;
			}
			v[j--] = i;
		}
	}
	puts("Yes");
	for (int i = 1; i <= n*n; i++)
	        printf("%d ", v[i]);
	puts("");
	return 0;
}


Measured memory_bytes: 2176
//sppsfver - 05.08.2020
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair <ll, ll>;

ll n, a, ans = 1;
bool flag, zero;

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

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a;
        if (a == 0) return cout << 0 << endl, 0;
        a <= (ll)(1e18)/ans ? ans *= a : flag = 1;
    }
    cout << (flag ? -1 : ans) << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll dp[100005],h[100005],k;

ll f(ll x){
	if(x<0)return 1e10;
	if(x==0){
		return 0;
	}
	if(dp[x]>=0){
		return dp[x];
	}
	dp[x]=1e10;
	fore(i,1,k+1){
		dp[x]=min(dp[x],f(x-i)+abs(h[x]-h[x-i]));
	}
	//dp[x]=min(f(x-1)+abs(h[x-1]-h[x]),f(x-2)+abs(h[x-2]-h[x]));
	return dp[x];
}

int main(){FIN;
	ll n; cin>>n>>k;
	memset(dp,-1,sizeof dp);
	fore(i,0,n)cin>>h[i];
	cout<<f(n-1);
	return 0;
}


Measured memory_bytes: 4992
/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz
 *    created:
 */
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;

using namespace std;
const int maxn = 110;
int a[maxn];
int main(){
    int n, d, x, sum = 0;
    scanf("%d%d%d", &n, &d, &x);
    REP(i, 0, n){
        scanf("%d", &a[i]);
        sum += (d-1)/a[i]+1;
    }
    printf("%d", sum + x);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define be(v) v.begin(), v.end()
#define ll long long
ll INF = 1e9;

int main() {
  int n; cin >> n;
  vector<int> w(n);
  int ans = 0;
  rep(i,n) {
  	cin >> w[i];
  	ans+=w[i];
  }
  int mi = ans;
  int p_sum=0;
  rep(i,n) {
  	p_sum+=w[i];
  	mi = min(mi,abs(p_sum-(ans-p_sum)));
  }
  cout << mi << endl;
}


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

int n, m;
char grid[1005][1005];
int ans[1005][1005];
const int mod = 1e9 + 7;

int solve(int i, int j)
{
    if(i >= n || j >= m || grid[i][j] == '#')
        return 0;
    if(i == n - 1 && j == m - 1)
        return 1;
    int &ret = ans[i][j];
    if(~ret)
        return ret;
    ret = (solve(i + 1, j) + solve(i, j + 1)) % mod;
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> grid[i][j];
    memset(ans, -1, sizeof ans);
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 5248
#! /usr/bin/python3
# Between a and b ...

"""
非負の整数 a, b (a≤b) と、正の整数 x が与えられます。
a 以上 b 以下の整数のうち、x で割り切れるものの個数を求めてください。
"""

test_mode = False

a, b, x = map(int, input().split())

if a%x != 0:
    limit_min = a//x +1
else:
    limit_min = a//x

limit_max = b//x


ans = limit_max - limit_min + 1

print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}

int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}


signed main() {
	string s;
	cin >> s;
	sort(all(s));
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll cb (ll a) {
	return a * a * a;
}

ll slow(int N, int K) {
	ll res = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			for (int k  = 1; k <= N; k++) {
				if ((i + j) % K == 0 && (j + k) % K == 0 && (k + i) % K == 0) {
					res ++;
				}
			}
		}
	}
	return res;
}

ll go(int N, int K) {
	ll res = cb(N / K);
	if (K % 2 == 0) {
		res += cb((N + K / 2) / K);
	}
	return res;
}

int main() {
	for (int i = 1; i <= 20; i++) {
		for (int j = 1; j <= 20; j++) {
			assert(go(i, j) == slow(i, j));
		}
	}
	int N, K; cin >> N >> K;
	cout << go(N, K) << '\n';

	return 0;
}


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

typedef pair<int,int> P;

const int MAX = 10000;
const int INF = 999999;

int V;
int m;

int prim (vector<vector<P> > G) {
    set<int> used;
    priority_queue<P, vector<P>, greater<P> > que;
    for (int i = 0; i < V; i++) {
        used.insert(i);
    }
    int res = 0;
    int v = 0;
    while (!used.empty()) {
        for (auto i : G[v])   que.push(i);
        P p;
        while (used.find(que.top().second) == used.end() || que.top().second == v) {
            que.pop();
            if (que.empty()) break;
        }
        if (que.empty()) break;
        used.erase(used.find(v));
        p = que.top(); que.pop();
        v = p.second;
        res += p.first;
    }

    return res;
}

int main ()
{
    while (cin >> V, V) {
        cin >> m;
        vector<vector<P> >  G(V);
        for (int i = 0; i < m; i++) {
            int a, b, c;
            scanf("%d,%d,%d", &a, &b, &c);
            c /= 100;
            G[a].push_back(P(c,b));
            G[b].push_back(P(c,a));
        }

        cout << prim(G) - V + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1552
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

var line;
while (line = lines.shift()) {
	var cnt = 0;
	var num = +line;
	for (var i1 = 0; i1 <= 9; i1++) {
	for (var i2 = 0; i2 <= 9; i2++) {
	for (var i3 = 0; i3 <= 9; i3++) {
	for (var i4 = 0; i4 <= 9; i4++) {
		if (i1 + i2 + i3 + i4 == num)
			cnt++;
	}}}}
	console.log(cnt);
}

Measured memory_bytes: 8696
let rec knapsack q vs ws =
  let n = List.length ws in
  let xs = Array.init (n+1) (fun _ -> Array.make (q+1) @@ Lazy.from_val 0) in
  let ks = function
      (0,_) -> 0
    | (_,0) -> 0
    | (i,w) when w >= List.nth ws (i-1) -> max (Lazy.force xs.(i-1).(w)) (Lazy.force xs.(i-1).(w - (List.nth ws (i-1))) + List.nth vs (i-1))
    | (i,w) -> Lazy.force xs.(i-1).(w) in
  for i = 0 to n do
    for j = 0 to q do
      xs.(i).(j) <- Lazy.from_val @@ ks (i,j)
    done;
  done;
  ks (n,q)

let _ =
  let (n, w) = Scanf.scanf "%d %d\n" (fun a b -> (a, b)) in
  let vs = ref [] in
  let ws = ref [] in
  for i = 1 to n do
    vs := Scanf.scanf "%d " (fun a -> a) :: !vs;
    ws := Scanf.scanf "%d\n" (fun a -> a) :: !ws;
  done;
  Printf.printf "%d\n" @@ knapsack w !vs !ws




Measured memory_bytes: 10508
#include <iostream>

//setprecisionのため
#include <iomanip>
using namespace std;

int main(){
    int N;
    double ans = 0.0, A;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A;
        ans += 1/A;
    }
    ans = 1.0/ans;
    cout << setprecision(16) << ans <<endl;
}

Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */




import java.util.* ;

/**
 *
 * @author nai
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int max = -1;
        int min = 10000;
        
        int N = sc.nextInt();
        for(int i = 0 ; i < N ; i++){
            int temp = sc.nextInt();
            if(max < temp){
                max = temp;
            }
            if(temp < min){
                min = temp;
            }
        }
        
        System.out.println(max - min);
    }
  }
    



Measured memory_bytes: 23764
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
int main() {
	long long int n, a, b; std::cin >> n >> a >> b;
	const auto cycle = n / (a + b);
	const auto rest = std::min(a, n % (a + b));
	std::cout << cycle * a + rest << '\n';
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import collections
n = int(input())
a = [int(i) for i in input().split()]

#累積和を求める
sum_a = [0 for _ in range(n+1)]
for i in range(1, n+1):
    sum_a[i] = sum_a[i-1] + a[i-1]
#print(sum_a)

ans = 0
c = collections.Counter(sum_a)
for i in set(sum_a):
    tmp = c[i]
    if tmp >= 2:
        ans += (tmp * (tmp - 1)) // 2
print(ans)


Measured memory_bytes: 119296
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  var a, b = sc.nextLong

  val ans = lcm(a, b)
  println(ans)

  def gcd(x: Long, y: Long): Long = {
    if (y == 0) x
    else gcd(y, x % y)
  }

  def lcm(x: Long, y: Long): Long = {
    if (x == 0 || y == 0) 0
    else (x * y / gcd(x, y))
  }
}


Measured memory_bytes: 25676
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
using ll = long long;
using ld = long double;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/*
.-.. . -. -.- .- / .. ... / .-.. --- ...- . -.-.--
 */
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    ll n;
    cin >> n;
    vi vec(n);
    for(ll &x : vec)
        cin >> x;
    
    sort(all(vec), greater<ll>());

    ll ans = 0;
    ans += vec.front();
    ll cnt = n-2;

    for(ll i=1; i<n && cnt>0; i++){
        if(cnt == 1){
            ans += vec[i];
            cnt--;
        }
        else{
            cnt -= 2;
            ans += vec[i] * 2;
        }
    }

    cout << ans << endl;


    return 0;
}


signed main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}

/*******************************************************************************/
// Remeber - In a custom comparator cmp(a, b) a==b must always return to false.



Measured memory_bytes: 4776
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
tes = [[-1]*N for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x,y = map(int,readline().rstrip().split())
        tes[i][x-1] = y

cnt = 0
for i in range(2**N):
    hon = [0]*N
    for j in range(N):
        if (i>>j)&1:
            hon[j] = 1
    flag = True
    for j in range(N):
        if not flag:
            break
        if hon[j]:
            for k in range(N):
                if tes[j][k] == -1:
                    continue
                if tes[j][k] != hon[k]:
                    flag = False
                    break
            
    if flag:
        cnt = max(cnt,hon.count(1))
print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      int n;
      cin >> n;
      ll a[n],b[n];
      rep(i,n)cin >> a[i] >> b[i];
      pair<ll,int> c[n];
      rep(i,n){
        c[i].first=a[i]+b[i];
        c[i].second=i;
      }
      sort(c,c+n);
      reverse(c,c+n);
      ll ans=0;
      rep(i,n){
        if(i%2==0){
         ans+=a[c[i].second]; 
        }
        else ans-=b[c[i].second];
      }
      cout << ans << endl;
      return 0;}


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

int main() {
  ll N, M;
  cin >> N >> M;
  ll arr[N + 2] = {};
  ll L, R;
  for (int i = 0; i < M; i++) {
    cin >> L >> R;
    arr[L]++;
    arr[R + 1]--;
  }
  ll count = 0, ans = 0;
  for (int i = 0; i < N; i++) {
    count += arr[i + 1];
    if (count == M) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int n,k;
  cin>>n>>k;
  std::vector<int> h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  int result=0;
  for(int i=0;i<n;i++){
    if(h[i]>=k) result++;
  }
  cout<<result<<endl;



  return 0;
}


Measured memory_bytes: 640
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int c=0;c<n;c++) {
			int d = sc.nextInt();
			boolean map[][] = new boolean[d+4][d+4];
			for(boolean[] a: map) fill(a, true);
			for(int i=1;i<d+3;i++) for(int j=1;j<d+3;j++)
				map[i][j] = false;
			
			int sx = 2;
			int sy = d+1;
			int dir = 1;
			int cnt=0;
			for(;;) {
				map[sy][sx] = true;
				if(map[sy+2*dy[dir]][sx+2*dx[dir]]) {
					dir = (dir+1)%4;
					cnt++;
				}
				if(cnt==d) break;
				sx+=dx[dir];
				sy+=dy[dir];
			}
			for(int i=2;i<d+2;i++) {
				for(int j=2;j<d+2;j++) {
					if(map[i][j]) System.out.print("#");
					else System.out.print(" ");
				}
				System.out.println();
			}
			if(c!=n-1)
				System.out.println();
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


template< int char_size >
struct TrieNode {
  int nxt[char_size];

  int exist;
  vector< int > accept;

  TrieNode() : exist(0) {
    memset(nxt, -1, sizeof(nxt));
  }
};

template< int char_size, int margin >
struct Trie {
  using Node = TrieNode< char_size >;

  vector< Node > nodes;
  int root;

  Trie() : root(0) {
    nodes.push_back(Node());
  }

  void update_direct(int node, int id) {
    nodes[node].accept.push_back(id);
  }

  void update_child(int node, int child, int id) {
    ++nodes[node].exist;
  }

  void add(const string &str, int str_index, int node_index, int id) {
    if(str_index == str.size()) {
      update_direct(node_index, id);
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) {
        nodes[node_index].nxt[c] = (int) nodes.size();
        nodes.push_back(Node());
      }
      add(str, str_index + 1, nodes[node_index].nxt[c], id);
      update_child(node_index, nodes[node_index].nxt[c], id);
    }
  }

  void add(const string &str, int id) {
    add(str, 0, 0, id);
  }

  void add(const string &str) {
    add(str, nodes[0].exist);
  }

  void query(const string &str, const function< void(int) > &f, int str_index, int node_index) {
    for(auto &idx : nodes[node_index].accept) f(idx);
    if(str_index == str.size()) {
      return;
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) return;
      query(str, f, str_index + 1, nodes[node_index].nxt[c]);
    }
  }

  void query(const string &str, const function< void(int) > &f) {
    query(str, f, 0, 0);
  }

  int count() const {
    return (nodes[0].exist);
  }

  int size() const {
    return ((int) nodes.size());
  }
};

int main(){
    int D,T,S;
    cin>>D>>T>>S;
    if(T*S>=D)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }
template< typename T, typename Compare = greater< T > >
vector< T > knapsack_limitations(const vector< int > &w, const vector< int > &m, const vector< T > &v,
                                 const int &W, const T &NG, const Compare &comp = Compare()) {
    const int N = (int) w.size();
    vector< T > dp(W + 1, NG), deqv(W + 1);
    dp[0] = T();
    vector< int > deq(W + 1);
    for(int i = 0; i < N; i++) {
        for(int a = 0; a < w[i]; a++) {
            int s = 0, t = 0;
            for(int j = 0; w[i] * j + a <= W; j++) {
                if(dp[w[i] * j + a] != NG) {
                    auto val = dp[w[i] * j + a] - j * v[i];
                    while(s < t && comp(val, deqv[t - 1])) --t;
                    deq[t] = j;
                    deqv[t++] = val;
                }
                if(s < t) {
                    dp[j * w[i] + a] = deqv[s] + j * v[i];
                    if(deq[s] == j - m[i]) ++s;
                }
            }
        }
    }
    return dp;
}

int main() {
    int N, W;
    cin >> N >> W;
    vector< int > v(N), w(N), m(N);
    for(int i = 0; i < N; i++) {
        cin >> v[i] >> w[i] >> m[i];
    }
    auto ret = knapsack_limitations(w, m, v, W, -1);
    cout << *max_element(begin(ret), end(ret)) << endl;
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
typedef long long int ll;
int combination(int n,int k)
{
  ll ans=1;
  for(int i=0;i<k;++i)
  {
    ans*=(n-i);
    ans/=(i+1);
  }
    return ans;
  }

  int main()
  {
    int N,M;
    ll res;
   std::cin>>N>>M;
    if(N>=2 && M>=2)
    res=combination(N,2)+combination(M,2);
    else if(N>=2 && M<2)
      res=combination(N,2);
    else if(M>=2&& N<2)
      res=combination(M,2);
    else if(M<2 && N<2)
      res=0;
    std::cout<<res;
    return 0;
  }
      
    
    

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a >= b){
        if(c >= a){
            cout<< b << " " << a << " " << c << endl;
        } else if((c >= b) && (c <= a)) {
            cout<< b << " " << c << " " << a << endl;
        } else {
            cout<< c << " " << b << " " << a << endl;
        }
    } else if (a <= b){
        if(c >= b){
            cout<< a << " " << b << " " << c << endl;
        } else if((c <= b) && (c >= a)){
            cout<< a << " " << c << " " << b << endl;
        } else {
            cout<< c << " " << a << " " << b << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3104
n,m,k = map(int,input().split())
ans = 0
g = [[i for i in input()] for i in range(n)]

for maskY in range(1 << n):
   ng = [[0]*m for i in range(n)]
   for bit in range(n):
       if maskY & (1 << bit):
           for i in range(m):
               ng[bit][i] = 1
   for maskX in range(1 << m):
       ngg = [[i for i in j] for j in ng]
   #    print(ngg)
       for bit in range(m):
           if maskX & (1 << bit):
               for i in range(n):
                   ngg[i][bit] = 1
       cnt = 0
       for y in range(n):
           for x in range(m):
               if g[y][x]=="#" and ngg[y][x]==0:
                   cnt += 1
   #    print(cnt)
       if cnt == k:
           ans += 1
print(ans)

Measured memory_bytes: 9244
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main(){
    int N;
    cin >> N;
    vector<string> s(2);
    cin >> s[0] >> s[1];
    int t = 0;
    long long ans = 1;
    int flag = 0;
    while(t < N){
        if(s[0][t] == s[1][t]){
            if(t == 0) ans = ans * 3 % MOD;
            else if(flag == 0) ans = ans * 2 % MOD;
            flag = 0;
            t++;
        }
        else{
            if(t == 0) ans = ans * 6 % MOD;
            else if(flag == 0)ans = ans * 2 % MOD;
            else if(flag == 1) ans = ans * 3 % MOD;
            t += 2;
            flag = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h> 
#define lowbit(x) x&(-x)
using namespace std;
typedef unsigned long long ll;
const int N = 1e4+5;

void dfs(int now,int n,string ans,int k){
	if(now == n){
		cout << ans << "\n";
		return ;
	}
	
	for(int i = 0;i <= k;++i) dfs(now+1,n,ans+(char)('a'+i),max(k,i+1));
	return ;
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    int n;
	cin >> n;
	dfs(0,n,"",0);
    return 0;
}


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

using namespace std;

const int INF=1e9+10;

int main()
{
    int n,t;
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin>>n>>t)
    {
        vector<int> T(t+1);
        for(int i=0;i<n;i++)
        {
            int a,b;
            cin>>a>>b;
            T[a]++;T[b]--;
        }
        int Max=-INF;
        for(int i=0;i<t;i++)
        {
            Max=max(Max,T[i]);
            T[i+1]+=T[i];
        }
        cout<<Max<<endl;
    }

    return 0;
}



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

int main() {
  int N,K,A,B,sum;
  cin >> N >>K;
  sum=0;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    A = K-x;
    B = min(x,A);
    sum += B*2;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
using namespace std;


int main()
{
	char ch,str;
	int cnt[26] = {};

	while (scanf("%c",&ch)!=EOF) {
		ch = tolower(ch);
		if (isalpha(ch)) {
			cnt[ch - 'a'] += 1;
		}
	}

	for (int i = 0; i < 26;i++) {
		printf("%c : %d\n",i+'a',cnt[i]);
	}

	return 0;
}


Measured memory_bytes: 3212
S = input()
rests = [chr(i) for i in range(97, 97+26)]

def is_only(s, c):
  for sc in s:
    if sc != c:
      return False
  return True

def shrink(s, c):
  res = ''
  for i in range(len(s)-1):
    if s[i+1] == c:
      res += c
    else:
      res += s[i]
  return res

ans = 10**3
for c in rests:
  if not c in S:
    continue
  s = S
  cnt = 0
  while not is_only(s, c):
    s = shrink(s, c)
    cnt += 1
  ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 67568
S=str(input())
N=len(S)
str1=''
str2=''
for n in range(N//2):
    str1=str1+'01'
    str2=str2+'10'
if N%2:
    str1=str1+'0'
    str2=str2+'1'
min1=sum(str1[i]!=S[i] for i in range(N))
min2=sum(str2[i]!=S[i] for i in range(N))
print(min(min1,min2))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main()
{
    // long long i,j,t,a,b,n,c,d,y,x,temp,m,r,sum,count,l,k,s,ans,rr,prev;
    int t=1;
    // cin>>t;
    while(t--)
    {
        string s1,s2;
        cin>>s1>>s2;
        if(s1==s2.substr(0,s1.length()))cout<<"Yes";
        else cout<<"No";
    }
}

Measured memory_bytes: 3592
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

var sum = 0

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := nextInt()
	b := nextInt()

	for i := 1; i <= n; i++ {
		tmp := split(i)
		if tmp >= a && tmp <= b {
			sum += i
		}
	}

	fmt.Println(sum)
}

func split(n int) int {
	sum := 0
	for n > 0 {
		sum += (n % 10)
		n /= 10
	}
	return sum
}


Measured memory_bytes: 1772
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47488
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i > 0; i--)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
template <typename Iter> std::string join(Iter begin, Iter end, std::string const& separator){ std::ostringstream result; if (begin != end){ result << *begin++; }; while (begin != end){ result << separator << *begin++; }; return result.str(); }
using namespace std;
typedef long long ll;
void solve() {
  ll N; cin >> N;
  vector<double> v(N);
  REP(i, N) {
    cin >> v[i];
  }
  sort(ALL(v));
  cout << fixed;
  cout << setprecision(6) << accumulate(v.begin() + 1, v.end(), v[0], [](double acc, double v) {
    return (acc + v) / 2.0;
  }) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using INT = mp::cpp_int;

int main() {
	ll n;
	cin >> n;
	INT ans = 1;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i)cin >> a[i];
	if (find(a.begin(), a.end(), 0ll) != a.end()) {
		cout << 0 << endl;
		return 0;
	}
	for (ll i = 0; i < n; ++i) {
		ans *= a[i];
		if (ans > (ll)1e18) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4100
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

const int p=1000000007;
int n,k,f[2010][2010],ans;

int main()
{
    scanf("%d%d",&n,&k);
    if (n==1)
    {
        puts("1");
        return 0;
    }
    f[n][0]=1;
    repd(i,n,2)
        repu(j,0,n-i)
        {
            if (j)
                (f[i][j]+=f[i][j-1])%=p;
            (f[i-1][j]+=f[i][j])%=p;
        }
    repu(i,0,k-1)
        (ans+=f[2][i])%=p;
    repu(i,1,n-k-1)
        (ans<<=1)%=p;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 15232
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

int N;

struct Point
{
    Point(s64 x, s64 y)
    : x(x), y (y)
    {}
    s64 x, y;
};

bool operator < (const Point &p1, const Point &p2)
{
    return ((p1.x == p2.x) ? (p1.y < p2.y) : p1.x < p2.x);
}

vector<Point> vecPoint;

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

    cin >> N;

    s64 x, y;
    rep (i, N)
    {
        cin >> x >> y;
        vecPoint.push_back(Point{x, y});
    }

    std::sort(vecPoint.begin(), vecPoint.end());

    s64 p, q;
    int sum;
    map<Point, int> ans;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i + 1; j < N; ++j)
        {
            p = vecPoint[j].x - vecPoint[i].x;
            q = vecPoint[j].y - vecPoint[i].y;
            auto itr = ans.find(Point{p, q});
            if (itr != ans.end())
            {
                ++(itr->second);
            }
            else
            {
                ans[Point{p, q}] = 1;
            }
        }
    }

    s64 ret = 0;
    for (auto a : ans)
    {
        ret = MAX(ret, a.second);
    }

    cout << N - ret << "\n";

    return 0;
}



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


int main() {
    int num;
    int cnt = 1;
    while(1){
        cin >> num;
        if (num == 0){
            break;
        }
        cout << "Case " << cnt << ":" << " " << num << endl;
        cnt++;
    }

    return 0;
}


Measured memory_bytes: 3052
import sys
input = sys.stdin.readline

def main():
	s = input().strip()
	for c in s:
		if c == '1':
			print('9', end='')
		elif c == '9':
			print('1', end='')
		else:
			print(c, end='')
	print('')
if __name__ == '__main__':
	main()


Measured memory_bytes: 38384
import java.util.Scanner;


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

		while(true) {
			String str = sc.next();
			if(str.equals("-")) {
				break;
			}
			int m = sc.nextInt();

			for(int i=0; i<m; i++) {
				int h=sc.nextInt();
				str =str.substring(h,str.length()) + str.substring(0,h);
			}
			System.out.println(str);
		}
	}
}


Measured memory_bytes: 26632
import sys
from itertools import starmap
readline = sys.stdin.readline
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
s = Segment(*starmap(complex, zip(*[map(int, readline().split())] * 2)))
n = int(readline())
for _ in [0] * n:
    p2 = complex(*map(int, readline().split()))
    ap = project(s, p2)
    print(ap.real, ap.imag)

Measured memory_bytes: 8008
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MD = 1e9 + 7;
void add(int& x, int y) {
    x += y;
    if(x >= MD) x -= MD;
    if(x < 0) x += MD;
}
int cal(int l, int r) {
    return 1LL * (l + r) * (r - l + 1) / 2 % MD;
}
int main() {
    int n, k, ans = 0;
    scanf("%d%d", &n, &k);
    for(int i = k; i <= n + 1; i++) {
        add(ans, cal(n + 1 - i, n) - cal(0, i - 1) + 1);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

template <typename T>
struct segtree{
	//元データx[i]はv[n+i]
	//v[i]の親はv[i/2],子はv[i*2]とv[i*2+1]
	vector<T> v;
	int n;
	
	const T init_value = 0;
	
	segtree(int sz){
		n=1;
		while(true){
			if(n>=sz)break;
			n*=2;
		}
		v.resize(2*n,init_value);

		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i*2],v[i*2+1]);
		}
	}
	
	segtree(vector<T> &x){
		n=1;
		while(true){
			if(n>=x.size())break;
			n*=2;
		}
		v.resize(2*n,init_value);
		
		for(int i=0;i<x.size();i++){
			v[n+i]=x[i];
		}
		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i*2],v[i*2+1]);
		}
	}

	void update(int x,T val){
		x+=n;
		v[x]=val;
		while(true){
			x=(x)/2;
			v[x]=func(v[x*2],v[x*2+1]);
			if(x<=0)break;
		}
	}
	
	//区間[l,r)におけるクエリ処理
	T query(int l,int r){
		T res1 = init_value;
		T res2 = init_value;
		if(l>=r)return res1;
		l+=n;
		r+=n;
		while(true){
			if(l%2==1){
				res1=func(res1,v[l]);
				l++;
			}
			if(r%2==1){
				res2=func(v[r-1],res2);
				r--;
			}
			if(l>=r)break;
			l/=2;r/=2;
		}
		return func(res1,res2);
	}
	T func(T a,T b){
		return max(a,b);
	}
	
	void show(){
		int n = 1;
		for(int i=1;i<v.size();i++){
			for(int j=0;j<n;j++){
				if(j!=0)cout<<' ';
				cout<<v[i+j];
			}
			cout<<endl;
			i+=n-1;
			n*=2;
		}
	}
	
};

int main(){
	
	int N;
	cin>>N;
	
	vector<pair<int,int>> P(N);
	
	for(int i=0;i<N;i++){
		cin>>P[i].first>>P[i].second;
	}
	
	sort(P.begin(),P.end());
	
	segtree<int> seg(N);
	
	vector<vector<int>> dp(N+1,vector<int>(2,0));
	
	dp[N][0] = 1;
	
	for(int i=N-1;i>=0;i--){
		dp[i][1] = mod(dp[i+1][0]+dp[i+1][1]);
		pair<int,int> p = make_pair(P[i].first+P[i].second,-1);
		
		int ind = distance(P.begin(),lower_bound(P.begin(),P.end(),p));
		int k = seg.query(i,ind);
		k = max(k,i+1);
		seg.update(i,k);
		
		dp[i][0] = mod(dp[k][0] + dp[k][1]);
	}
	
	cout<<mod(dp[0][0]+dp[0][1])<<endl;
	
    return 0;
}



Measured memory_bytes: 14848
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<string>
#define LL long long
#define li i<<1
#define ri i<<1|1
using namespace std;
inline LL read()
{
    char c=getchar();LL x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
LL n,ans;
int main()
{
	n=read();
	for(LL i=1;i<=n;++i){
		LL up=n/i;
		ans+=up*i+up*(up-1)/2*i;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3748
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    println!("{}", solve(sc.next(), sc.next(), sc.next()));
}


fn solve(a: u32, b: u32, c: u32) -> u32 {
    (&[a + b, b + c, c + a]).iter().map(|p| *p).min().unwrap()
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut c = self.bytes.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = self.bytes.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = self.bytes.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug,
              <C as FromStr>::Err: Debug
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_foreach<T: Display>(answer: &[T]) {
    for x in answer {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_yn(answer: bool, yes: &str, no: &str) {
    println!("{}", if answer { yes } else { no });
}


#[allow(dead_code)]
fn print_or<T: Display>(answer: &Option<T>, or: &T) {
    match *answer {
        Some(ref x) => println!("{}", x),
        None => println!("{}", or),
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

const int N = 21;
const int N2 = (1 << N);

int n;
int dp[N2];
int cnt[N2];
int ar[N][N];

int main() {
	cin >> n;
	for( int i = 0 ; i < n ; i++ )
		for( int j = 0 ; j < n ; j++ )
			cin >> ar[i][j];
	for( int i = 1 ; i < N2 ; i++ )
		cnt[i] = cnt[i-(i&(-i))] + 1;
	dp[0] = 1;
	for( int bmask = 1 ; bmask < (1<<n) ; bmask++ ) {
		int id = cnt[bmask] - 1;
		for( int i = 0 ; i < n ; i++ )
			if( bmask & (1<<i) )
				if( ar[id][i] )
					dp[bmask] = ( dp[bmask] + dp[bmask^(1<<i)] ) % mod;
	}
	cout << dp[(1<<n)-1] << endl;
}


Measured memory_bytes: 16640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(),
			w = sc.nextInt();
		for(int i = 0; i < h; i++){
			String c = sc.next();
			System.out.println(c);
			System.out.println(c);
		}
	}
}

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

double d[16][16];

int main() {
  int N; cin>>N;
  vector<int> r(N);
  REP(i,N) r[i] = i;
  vector<double> x(N), y(N);
  REP(i,N) cin>>x[i]>>y[i];
  REP(i,N) REP(j,N) {
    double dx = abs(x[i] - x[j]);
    double dy = abs(y[i] - y[j]);
    d[i][j] = sqrt(dx*dx + dy*dy);
  }
  double total = 0.0;
  double cnt = 0;
  do {
    double tmp = 0.0;
    REP(i, N-1) {
      tmp += d[r[i]][r[i+1]];
    }
    total += tmp;
    cnt++;

  } while(next_permutation(r.begin(), r.end()));
  double ans =	total/cnt;
  printf("%0.10f\n", ans);
  return 0;
}


Measured memory_bytes: 256