akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;
 
    vl broken(n+1);
    rep(i, m) {
        ll a;
        cin >> a;
        broken[a] = 1;
    }
 
    vl dp(n+2);  // dp[i] : i段目からn段目に上る場合の数
 
    dp[n] = 1;
    for(ll i = n-1; i >= 0; i--) {
        if(broken[i]) {
            dp[i] = 0;
            continue;
        }
        dp[i] = dp[i+1] + dp[i+2];
        dp[i] %= mod;
    }
    
    out(dp[0]);
    re0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 1e9;
long long mod = 1000000007 ;
long long n, k, u, ans;

int main(){
  cin>>n>>k;
  ans = 0;
  for(long long i = k; i <= n + 1; ++i){
    ans += (n + 1 - i) * i % mod + 1;
    ans %= mod;
  }
  cout<<(ans)<<endl;
  return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;

vector<int> invert(vector<int> const & p) {
    vector<int> q(p.size());
    REP (i, p.size()) {
        q[p[i]] = i;
    }
    return q;
}

vector<int> multiply(vector<int> const & p, vector<int> const & q) {
    assert (p.size() == q.size());
    vector<int> r(p.size());
    REP (i, p.size()) {
        r[i] = p[q[i]];
    }
    return r;
}

vector<int> power(vector<int> p, ll k) {
    vector<int> q(p.size());
    iota(ALL(q), 0);
    for (ll i = 1; i <= k; i <<= 1) {
        if (k & i) q = multiply(q, p);
        p = multiply(p, p);
    }
    return q;
}

vector<int> solve(int n, ll k, vector<int> const & p, vector<int> const & q) {
    int kq = (k - 1) / 6;
    int kr = (k - 1) % 6;
    vector<int> a = power(multiply(q, multiply(invert(p), multiply(invert(q), p))), kq);
    switch (kr) {
        case 3:
            a = multiply(a, q);
            break;
        case 4:
        case 5:
            a = multiply(a, multiply(q, invert(p)));
            break;
    }
    vector<int> b =
        kr == 0 ? p :
        kr == 1 ? q :
        kr == 2 ? multiply(q, invert(p)) :
        kr == 3 ? invert(p) :
        kr == 4 ? invert(q) :
                  multiply(invert(q), p);
    return multiply(a, multiply(b, invert(a)));
}

int main() {
    // input
    int n; ll k; cin >> n >> k;
    vector<int> p(n);
    REP (i, n) {
        cin >> p[i];
        -- p[i];
    }
    vector<int> q(n);
    REP (i, n) {
        cin >> q[i];
        -- q[i];
    }

    // solve
    vector<int> r = solve(n, k, p, q);

    // output
    REP (i, n) {
        cout << r[i] + 1 << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3824
import Control.Applicative
main = do
    ss <- lines <$> getContents
    solve [] ss
solve :: [Int] -> [String] -> IO ()
solve ns ss = do
    let n = read $ head ss :: Int
    if n == 0
        then do
            putStrLn $ show $ last ns
            if isNull ss then return ()
            else solve (init ns) (tail ss)
        else do
            if isNull ss then return ()
            else solve (ns ++ [n]) (tail ss)
isNull :: [String] -> Bool
isNull ss = if null $ init ss then True else False

Measured memory_bytes: 3936
#include<stdio.h>

int n,N[20],sign[2000];


void cal(int p,int SUM){
  if(p==n){
    sign[SUM]=1;
    return;
  }
  cal(p+1,SUM);
  cal(p+1,SUM+N[p]);
}

int main(){
  int i,q,flag;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
  }
  cal(0,0);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&flag);
    if( sign[flag]==1 ){
      printf("yes");
      printf("\n");
    }else{
      printf("no");
      printf("\n");
    }
  }
  return 0;
}




Measured memory_bytes: 2108
h,w,k = map(int,input().split())
cake = []
st = []
c = 0
for i in range (h):
    cur = list(input())
    cake.append(cur)
    if '#' in cur:
        st.append(1)
    else:
        st.append(0)
peach = 0
l = 0
for i in range(h):
    if st[i]== 1:
        c+=1
        l = i
        peach+=1
        start =0
        balance = 0
        while start<w:
            if cake[i][start]=='.':
                cake[i][start] = peach
                for r in range(i-1,-1,-1):
                    if cake[r][start]== '.':
                        cake[r][start]= peach
                    else:
                        break
            else:
                if balance ==0:
                    balance =1
                    cake[i][start] = peach
                else:
                    peach+=1
                    balance=1
                    cake[i][start]=peach
                for r in range(i-1,-1,-1):
                    if cake[r][start]== '.':
                        cake[r][start]= peach
                    else:
                        break
            start+=1
for i in range(l+1,h):
    for j in range(w):
        cake[i][j] = cake[i-1][j]
for v in cake:
    print(*v)

Measured memory_bytes: 7560
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		n = 1000 - n;
		int count = 0;
		count += n / 500;
		n %= 500;
		count += n / 100;
		n %= 100;
		count += n / 50;
		n %= 50;
		count += n / 10;
		n %= 10;
		count += n / 5;
		n %= 5;
		count += n;
		cout << count << endl;
	}
}

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

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int w, a, b;
    cin >> w >> a >> b;
    if (a + w < b) {
        cout << b - a - w << endl;
        return 0;
    }
    if (b + w < a) {
        cout << a - w - b << endl;
        return 0;
    }
    cout << 0 << endl;
}




Measured memory_bytes: 3636
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [input() for _ in range(n)]

d = int(input())

if d==25:
    print("Christmas")
elif d==24:
    print("Christmas Eve")
elif d==23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")










Measured memory_bytes: 8972
n = int(input())
 
_sum = 0
_tmp = 0
while _sum <= n:
    _tmp += 1
    _sum += _tmp
    if _sum >= n:
        break
 
ans = []
while n:
    if n - _tmp < 0:
        _tmp -= 1
    else:
        ans.append(_tmp)
        n -= _tmp
        _tmp -= 1
 
for i in ans:
    print(i)

Measured memory_bytes: 74400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	int n, m;
	cin >> n >> m;
	vi place(m), year(m);
	vvi perp(n + 1, vi());
	rep(i, m) {
		cin >> place[i] >> year[i];
		perp[place[i]].push_back(year[i]);
	}
	rep(i, n + 1) {
		if (!perp[i].empty()) {
			sort(all(perp[i]));
		}
	}
	rep(i, m) {
		cout << setfill('0') << setw(6) << right << place[i];
		auto itr = lower_bound(all(perp[place[i]]), year[i]);
		cout << setfill('0') << setw(6) << right << itr- perp[place[i]].begin()+1 << endl;
	}
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define fi first
#define se second
#define int long long
//template

std::vector<int> w(1000000);
int pw(int n,int k){
  int res=1;
  while(k){
    if(k%2)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k/=2;
  }
  return res;
}
int nCk(int n,int k){
  if(n<k)return 0;
  int res=w[n];
  res*=pw(w[k],MOD-2);res%=MOD;
  res*=pw(w[n-k],MOD-2);res%=MOD;
  return res;
}

//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N+1,-1);
  w[0]=1;for(int i=1;i<1000000;i++)w[i]=w[i-1]*i%MOD;
  int a,b;
  for(int i=0;i<N+1;i++){
    int s;cin>>s;
    if(v[s]!=-1){
      a=v[s];
      b=i;
    }
    else v[s]=i;
  }
  //cout<<a<<" "<<b<<endl;
  for(int i=1;i<=N+1;i++)Cout((nCk(N+1,i)-nCk(a+N-b,i-1)+MOD)%MOD);
}


Measured memory_bytes: 9856
import java.util.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String n = sc.next();
		String t = sc.next();
		String f = sc.next();
		BigInteger bi = BigInteger.ZERO;
		for(int i=2;i<f.length();i+=4){
			bi = bi.add(new BigInteger(n).pow(f.codePointAt(i)-48));
		}
		bi = bi.multiply(new BigInteger(t));
		if(bi.compareTo(new BigInteger("1000000000"))>0) System.out.println("TLE");
		else System.out.println(bi);
	}

}

Measured memory_bytes: 17372
a = input().split(" ")
t8 = int(a[0])
t10 = int(a[1])

for i in range(13, 1001):
	b = int(i * 0.08)
	c = int(i * 0.1)
	if b == t8 and c == t10:
		print(i)
		break
	if i == 1000:
		print(-1)
		break

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n);
  for(Int i=0;i<n;i++) cin>>x[i];
  Int m,k;
  cin>>m>>k;
  vector<Int> a(m);
  for(Int i=0;i<m;i++) cin>>a[i];

  vector<Int> s(n-1);
  for(Int i=0;i<n-1;i++) s[i]=x[i+1]-x[i];
  
  vector<Int> ord(n-1);
  iota(ord.begin(),ord.end(),0);

  vector<Int> mov(ord);
  for(Int i=0;i<m;i++)
    swap(mov[a[i]-2],mov[a[i]-1]);

  //for(Int i=0;i<n-1;i++) cout<<ord[i]<<":"<<mov[i]<<endl;

  while(k){
    if(k&1){
      vector<Int> nxt(n-1);
      for(Int i=0;i<n-1;i++) nxt[i]=mov[ord[i]];      
      swap(ord,nxt);
    }
    vector<Int> nxt(n-1);
    for(Int i=0;i<n-1;i++) nxt[i]=mov[mov[i]];
    swap(mov,nxt);
    k>>=1;
  }

  Int pos=x[0];
  cout<<pos<<endl;
  for(Int i=0;i<n-1;i++){
    pos+=s[ord[i]];
    cout<<pos<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 5968
//Name: Vampire
//Level: 2
//Category: 幾何
//Note:

/**
 * 第一象限に注目すると、太陽のうち区間[x,x+1)にある箇所が影から出るとき、
 * もっとも早く出るのは座標xの点である（太陽の中心、建物の座標がともに整数であり、太陽は上に凸であるため）。
 * したがって、[x,x+1)が影から出るイベントに対しては、xのみを調べればよい（このとき、xが建物の右端でも出ていると判定することに注意）。
 * 第二象限についても同様。
 *
 * オーダーはO(R)。
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

bool solve() {
    int R, N;
    if(!(cin >> R >> N)) return false;
    if(!R && !N) return false;

    vector<int> hs(R+1), nhs(R+1);
    for(int i = 0; i < N; ++i) {
        int xl, xr, h;
        cin >> xl >> xr >> h;
        for(int x = max(0, xl); x < xr; ++x) {
            if(0 <= x && x <= R) hs[x] = max(hs[x], h);
        }
        for(int x = min(0, xr); x > xl; --x) {
            if(0 <= -x && -x <= R) nhs[-x] = max(nhs[-x], h);
        }
    }
    double ans = 1000000;
    for(int x = 0; x < R; ++x) {
        const double t = hs[x] + R - sqrt(R*R - x*x);
        ans = min(ans, t);
    }
    for(int x = 0; x > -R; --x) {
        const double t = nhs[-x] + R - sqrt(R*R - x*x);
        ans = min(ans, t);
    }
    cout.precision(10);
    cout << fixed << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll llINF=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  string s;
  cin>>s;
  char state;
  rep(i,len(s)-1){
    state=s[i];
    if(state==s[i+1]){
      cout<<"Bad"<<endl;
      return 0;
    }
  }
  cout<<"Good"<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
ll a[305][305], b[305][305];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ll sum = 0;
	FOR(i, n) FOR(j, n) {
		cin >> a[i][j];
		b[i][j] = a[i][j];
		sum += a[i][j];
	}
	FOR(k, n) FOR(i, n) FOR(j, n) b[i][j] = min(b[i][j], b[i][k]+b[k][j]);
	FOR(i, n) FOR(j, n) {
		if (a[i][j] != b[i][j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	sum /= 2;
	FOR(i, n) {
		for (int j = i+1; j < n; j++) {
			bool ok = false;
			FOR(k, n) {
				if (k == i || k == j) continue;
				if (!ok && a[i][k] + a[k][j] == a[i][j]) {
					sum -= a[i][j];
					ok = true;
				}
			}
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1664
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> edge(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    cout << "Yes" << '\n';

    vector<int> ans(n);

    queue<int> q;
    vector<bool> visited(n, false);

    q.push(0);
    visited[0] = true;

    while (!q.empty()) {
        int cur = q.front();
        q.pop();

        for (int ch : edge[cur]) {
            if (visited[ch]) continue;
            visited[ch] = true;
            ans[ch] = cur;
            q.push(ch);
        }
    }

    for (int i = 1; i < n; i++) {
        cout << ans[i] + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 10232
// [abhishekvtangod]
// g++ -Wall -Wextra -Wshadow filename.cpp
#include<bits/stdc++.h>
using namespace std; 

#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)

typedef long long int ll;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset<pair<ll,ll>> indexed_set;


#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif


// struct HASH{
//   size_t operator()(const pair<int,int>&x)const{
//     return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
//   }
// };




void solve()
{
	ll n,m;cin>>n>>m;
	ll sum=0,x;vector<ll> a;
	for(ll i=0;i<n;i++)
	{
		cin>>x;
		a.push_back(x);
		sum+=x;
	}
	
	
	ll cnt=0,flag=0;
	
	for(ll i=0; i<n;i++)
	{
		if(a[i]*4.0*m>=sum)
		{
			cnt++;
		}
		if(cnt>=m)
		{
			flag =1 ;break;
		}
	}
	cout<<((flag)?"Yes":"No");
}


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

	//ll t;cin>>t;
	//while(t--)
	//{
		solve();
	//}
	

    return 0;
}


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

int main() {
  int x, t;
  cin >> x >> t;
  int ans = max(0, x-t);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {
			var inputArray = retreiveIntArray();
			var N = inputArray[0];
			var M = inputArray[1];

			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var conditionArray = new int[M][];
			//条件を格納する
			for (int i = 0; i < M; i++) {
				var conArray = retreiveIntArray();
				conditionArray[i]= conArray;
			}


			//答えの出力
			var ans = getAnswer(N, conditionArray);
			Console.WriteLine(ans);

		}

		private static int getAnswer(int N, int[][] conditionArray) {

			var min = (int)Math.Pow(10 , N-1);
			var max = (int)Math.Pow(10, N) - 1;
			
			//1桁の場合は0を含める
			if(N == 1) {
				min = min - 1;
			}

			//Console.WriteLine($"max{max}min{min}:{conditionArray[0][1]} ");


			//Nの条件を満たす数を、小さいほうから順番に試す
			for (int i = min; i <= max; i++) {

				var result = true;
				foreach (var item in conditionArray) {
					var Nstr = i.ToString();
					var hidariketa = item[0];

					//桁が大きすぎづ場合はダメとして次へ
					if (Nstr.Length < hidariketa) {
						result = false;
						continue;
					}

					//　指定した桁の数値が正しい
					if (Nstr[hidariketa - 1] != item[1].ToString()[0]) {
						result =false;
					}
				}
				if (result) {
					return i;
				}
			}
			return -1;

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static int[] retreiveIntArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var intArray = inputArray.Select(s => int.Parse(s));
			return intArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int N;
  cin >> N;

  vector<ull> A(N);
  rep(i, N) cin >> A[i];
  std::sort(A.rbegin(), A.rend());

  ull answer {};
  std::queue<ull> que;
  que.push(A[0]);
  srep(i, 1, N) {
    answer += que.front();
    //cout << answer <<' ';
    que.pop();
    que.push(A[i]); que.push(A[i]);
  }
  cout << answer << '\n';
}


Measured memory_bytes: 6364
def comb(x,y,sum,g,t)
  if (sum <= g) && (t[sum] == 0)
    t[sum] = 1
    comb(x,y,sum+x,g,t)
    comb(x,y,sum+y,g,t)
  end
end

def main()
  t = gets.chomp.split(' ').map(&:to_f)
  sw,s = Hash.new(0),Hash.new(0)
  comb(100 * t[0],100 * t[1], 0, t[5], sw)
  comb(t[2], t[3], 0, t[5], s)
  target = 0.0
  ans_sw,ans_s = 0,0
  sw.each_key{|x|
    next if x == 0
    s.each_key{|y|
      if (100.0 * y <= x * t[4]) && (x + y <= t[5])
        if (100.0 * y) >= (x + y) * target
          target = (100.0 * y) / (x + y)
          ans_sw,ans_s = x,y
        end
      end
    }
  }
  puts "#{(ans_sw+ans_s).to_i} #{ans_s.to_i}"
end

main()

Measured memory_bytes: 2044
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans = A[0]
cnt = 1
num = 2
for i in range(N-2):
    
    ans += A[cnt]
    num += 1
    if num == N:
        break
        
    ans += A[cnt]
    num += 1
    if num == N:
        break
        
    cnt += 1
    

print(ans)

Measured memory_bytes: 31448
n,x,y = (int(x) for x in input().split())
x-=1
y-=1
middle=(y+x)/2
dic={}
for i in range(n-1):
    for j in range(i+1,n):
        if i<=x and j<=x:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif j==middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i==middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i<=x and j>=x and j<=middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i<=x and j>=middle and j<=y:
            k = (x-i) + 1 + (y-j)
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i<=x and j>=middle and j>=y:
            k = (x-i) + 1 + (j-y)
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=x and i<=middle and j<=middle:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=x and i<=middle and j>=middle and j<=y:
            k = min(j-i, i-x+y-j+1)
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=x and i<=middle and j>=y:
            k = i-x + j-y + 1
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=middle and j<=y:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=middle and j>=y:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
        elif i>=y and j>=y:
            k = j-i
            if k not in dic:
            	dic[k]=1
            else:
            	dic[k]+=1
for i in range(1,n):
    if i not in dic:
        print(0)
    else:
        print(dic[i])



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


typedef pair<int, int> P;
typedef long long ll;

const int INF = INT_MAX / 2;

ll n;
ll a[200001];

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

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  long long c[n];
  for(int i=0;i<n;i++){
    cin >> c[i];
  }
  if(n==1){
    cout << abs(c[0]-b) << endl;
  }else{    
    cout << max(abs(b-c[n-1]),abs(c[n-1]-c[n-2])) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

template <unsigned T>
bool nextBitset(bitset<T> &bs, int digit)
{
    if(bs.none())
        return false;
    bitset<T> x, y, z;
    x = bs.to_ulong() & (~(bs.to_ulong()) + 1ULL);
    y = bs.to_ulong() + x.to_ulong() + 0ULL;
    z = bs & ~y;
    if(bs[digit-1] && bs == z)
        return false;
    bs = ((z.to_ulong() / x.to_ulong()) >> 1) + 0ULL;
    bs |= y;
    return true;
}

int main()
{
    vector<vector<int> > dp(1<<10, vector<int>(331, 0));
    dp[0][0] = 1;
    for(int i=0; i<(1<<10); ++i){
        bitset<10> bs(i);
        for(int j=0; j<10; ++j){
            if(bs[j])
                continue;
            bitset<10> bs1 = bs;
            bs1[j] = true;
            int a = j * bs1.count();
            for(int k=0; k+a<331; ++k)
                dp[bs1.to_ulong()][k+a] += dp[bs.to_ulong()][k];
        }
    }

    for(;;){
        int n, s;
        if(!(cin >> n >> s))
            return 0;

        if(n > 10 || s > 330){
            cout << 0 << endl;
            continue;
        }

        int ret = 0;
        bitset<10> bs((1<<n)-1);
        do{
            ret += dp[bs.to_ulong()][s];
        }while(nextBitset(bs, 10));
        cout << ret << endl;
    }
}

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

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

	char zoo_s[n];    

	cin >> zoo_s;

	char zoo[n + 1];
	int i = 0;

	while(1){
		switch(i){
			case 0:
				zoo[0] = zoo[1] = 'S';
				break;
			case 1:
				zoo[0] = 'S';
				zoo[1] = 'W';
				break;
			case 2:
				zoo[0] = 'W';
				zoo[1] = 'S';
				break;
			case 3:
				zoo[0] = zoo[1] = 'W';
				break;
		}

		for(int k = 1; k < n; ++k){
			if(zoo[k] == 'S'){
				if(zoo[k - 1] == 'S' && zoo_s[k] == 'o'){
					zoo[k + 1] = 'S';
				}else if(zoo[k - 1] == 'S' && zoo_s[k] == 'x'){
					zoo[k + 1] = 'W';
				}else if(zoo[k - 1] == 'W' && zoo_s[k] == 'o'){
					zoo[k + 1] = 'W';
				}else{
					zoo[k + 1] = 'S';
				}
			}else{
				if(zoo[k - 1] == 'S' && zoo_s[k] == 'o'){
					zoo[k + 1] = 'W';
				}else if(zoo[k - 1] == 'S' && zoo_s[k] == 'x'){
					zoo[k + 1] = 'S';
				}else if(zoo[k - 1] == 'W' && zoo_s[k] == 'o'){
					zoo[k + 1] = 'S';
				}else{
					zoo[k + 1] = 'W';
				}
			}
		}

		if(zoo[n] == zoo[0]){
			if(i == 0){
				if(zoo_s[0] == 'o'){
					if(zoo[n - 1] == 'S'){
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}else{
					if(zoo[n - 1] == 'W'){ 
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}
			}else if(i == 1){
				if(zoo_s[0] == 'o'){
					if(zoo[n - 1] == 'W'){ 
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}else{
					if(zoo[n - 1] == 'S'){ 
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}
			}else if(i == 2){
				if(zoo_s[0] == 'o'){
					if(zoo[n - 1] == 'W'){ 
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}else{
					if(zoo[n - 1] == 'S'){ 
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}
			}else if(i == 3){
				if(zoo_s[0] == 'o'){
					if(zoo[n - 1] == 'S'){ 
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}else{
					if(zoo[n - 1] == 'W'){ 
						for(int j = 0; j < n; ++j){ 
							cout << zoo[j];
						}
							cout << "\n";
						break;
					}else{
						++i;
					}
				}
			}
		}else{
			++i;
		}

		if(i >= 4){
			cout << -1 << "\n";
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a;
    cin >> a;
    if (a < 1200)
    {
        cout << "ABC";
    }
    else if (a < 2800)
    {
        cout << "ARC";
    }
    else
    {
        cout << "AGC";
    }
}


Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using T = ll;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
   ll n;
   cin >> n;
   vector<ll> a(n);
   rep(i, n)cin >> a[i];
   ll res = 0;
   rep(i, n){
      if(i == 0)continue;
      if(a[i] >= a[i - 1])continue;
      res += (a[i - 1] - a[i]);
      a[i] = a[i - 1];
   }
   cout << res << endl;
}


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

int main () {

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

    int ans = INT_MAX;
    do {

        int t = 0;

        for (int i = 0; i < 5; i++) {
            t += orders[i];
            if (t % 10 != 0 && i != 4) {
                t = t + (10 - t % 10);
            }
        }

        ans = min(ans, t);
    } while (next_permutation(orders, orders + 5));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N;
    cin>>N;
    vector<int64> A(N+1);
    A[0]=0;
    A[1]=0;
    for (int64 i = 2; i < N+1; i++)
    {
        cin>>A[i];
    }
    vector<int64> B(N+1);
    for (int64 i = 0; i < N+1; i++)
    {
        B[i]=0;
    }
    for (int64 i = 1; i < N+1; i++)
    {
        B[A[i]]++;
    }
    for (int64 i = 1; i < N+1; i++)
    {
        cout<<B[i]<<endl;
    }
    
    return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	int X, Y; cin >> X >> Y;


	bool ok = false;
	REP(t,X+1){
		REP(k, X+1){
			int sum = t*2 + k*4;
			int n = t + k;
			if(n == X and sum == Y) ok = true;
		}
	}

	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	


	return 0;

}


Measured memory_bytes: 3632
used = [[False for i in range(13)] for i in range(4)]
mark = "SHCD"
dic = {"S": 0, "H": 1, "C": 2, "D": 3}

n = int(input())
for i in range(n):
    li = input().split()
    m = li[0]
    k = int(li[1])

    used[dic[m]][k - 1] = True

for i in range(4):
    for j in range(13):
        if (not used[i][j]):
            print("{0} {1}".format(mark[i], j+1))


Measured memory_bytes: 5608
package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		n   int
		tmp int
		cnt int
	)
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		if isPrime(tmp) {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func isPrime(a int) bool {
	if a == 2 {
		return true
	}

	if a%2 == 0 {
		return false
	}

	root := int(math.Sqrt(float64(a)))

	for i := 3; i <= root; i += 2 {
		if a%i == 0 {
			return false
		}
	}

	return true
}



Measured memory_bytes: 1648
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int fastexp(int a,int b){
  int res=1;
  while(b){
	if(b&1)res=res*a;
	a=(a*a),b>>=1; 
	 }
  return res;	
}
void solve(){
 	int d,n;
 	cin>>d>>n;
	int x=fastexp(100,d);
	if(n<=99)cout<<n*x<<endl;
	else cout<<x*101<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String t = sc.nextLine();
        boolean b = true;
        for (int i = 0; i < s.length() && b; i++) {
            b &= s.indexOf(s.charAt(i), i + 1) == t.indexOf(t.charAt(i), i + 1);
        }
        System.out.println(b ? "Yes" : "No");
    }
}

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

int main(){
    int n;
    cin >> n;
    int ans = 111;
    for(int i=0; i<9; i++){
        if(n <= ans){
            cout << ans << endl;
            return 0;
        }
        ans += 111;
    }
    return 0;
}

Measured memory_bytes: 3628
import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		DecimalFormat df = new DecimalFormat("0.000000000000000000000000000000");
		System.out.print(a / b + " " + a % b + " " + df.format((double)a / b));
		
		sc.close();
	}

}

Measured memory_bytes: 26520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main(){
    int N;
    cin >> N;
    double ans;
    if(N%2==1){
        ans = (double(N+1)/2)/double(N);
        cout << ans;
    }else{
        ans = double(N/2)/double(N);
        cout << ans;
    }
}

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

using namespace std;
char ax[200005];
int en[30];
int n;

int main()
{
    scanf("%s",ax);
    n = strlen(ax);
    int i,j,a,b;
    for(i=0;i<n;i++){
        en[ax[i]-'a']++;
    }
    long long res=1;
    for(i=0;i<n;i++){
        en[ax[i]-'a']--;
        res += (n-i-1)-en[ax[i]-'a'];
    }
    printf("%lld",res);
    return 0;
}


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

using namespace std;

bool second_compare(pair < string, int >a, pair < string, int >b)
{
	if (a.second != b.second) {
		return a.second < b.second;
	} else {
		return a.first < b.first;
	}
}

int main()
{
	int N;
	cin >> N;
	vector < string > S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

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

	map < string, int >freq;
	for (int i = 0; i < N; i++) {
		freq[S[i]]++;
	}

	int freqMax = 0;
	for (int i = 0; i < N; i++) {
		freqMax = max(freqMax, freq[S[i]]);
	}
 for (auto mp:freq) {
		if (mp.second == freqMax) {
			cout << mp.first << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 26752
#include <bits/stdc++.h>
using namespace std;
char A[51][51];
int main() {
	int h, w;
	cin>>h>>w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			cin>>A[i][j];
		}
		
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			if(A[i][j]=='.'){
				int c=0;
				if(A[i][j+1]=='#' && j+1<w ) c++;
				if(A[i][j-1]=='#' && j-1>=0 ) c++;
				if(A[i+1][j+1]=='#' && j+1<w && i+1<h) c++;
				if(A[i-1][j+1]=='#' && j+1<w && i-1>=0 ) c++;
				if(A[i-1][j-1]=='#' && j-1>=0 && i-1>=0 ) c++;
				if(A[i+1][j-1]=='#' && j-1>=0 && i+1<h ) c++;
				if(A[i+1][j]=='#' && i+1<h ) c++;
				if(A[i-1][j]=='#' && i-1>=0 ) c++;
				A[i][j]='0'+c;
				
			}
		}
		
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)
			cout<<A[i][j];
		cout<<endl;		
	}
			
	return 0;
}

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

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll x; cin >> x;
	rep(i, 1, 100000) {
		if (i *(i + 1) / 2 >= x) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef long double ld;
const ld pi = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 0;

ll x, k, d;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> x >> k >> d;
	ll dif = abs(x) / d;
	if(dif <= k){
		if(x < 0){
			x += dif * d;
		}
		else{
			x -= dif * d;
		}
		k -= dif;
		if(k & 1){
			if(x < 0){
				x += d;
			}
			else{
				x -= d;
			}
		}
		cout << abs(x) << '\n';
	}
	else{
		if(x < 0){
			x += k * d;
		}
		else{
			x -= k * d;
		}
		cout << abs(x) << '\n';
	}
}



Measured memory_bytes: 3656
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {  // O( log(a) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }  // O( log(a) )
bool isPrime(ll n) {                                  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) flag = false;
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

ll f(ll a, ll b, ll x) { return (a * x) / b - a * (x / b); }

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll ans;
  if (n >= b - 1)
    ans = f(a, b, b - 1);
  else
    ans = f(a, b, n);

  cout << ans << endl;
}

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

#define MOD (1000000007)

using namespace std;

int main(void){
    long long N, K;
    cin >> N >> K;
    set<long long> s;
    for(int i = 1; i * i <= N; i++){
        s.insert(i);
        s.insert(N / i);
    }
    int S = s.size();

    vector<pair<long long, long long>> interval;
    interval.reserve(S);
    for(int i : s) interval.push_back(make_pair(0LL, i));
    interval[0].first = 0;
    for(int i = 1; i < S; i++) interval[i].first = interval[i - 1].second;

    vector<long long> dp(S);

    for(int i = 0; i < S; i++) dp[i] = interval[i].second - interval[i].first;

    vector<long long> cumsum(S + 1);
    for(int k = 2; k <= K; k++){
        cumsum[0] = 0;
        for(int i = 0; i < S; i++){
            cumsum[0] += dp[i];
            cumsum[S - i] = -dp[i];
        }

        // for(int i = 0; i < S; i++) cout << i << " " << cumsum[i] << endl;

        long long s = 0; //cumsum[0];
        for(int i = 0; i < S; i++){
            s += MOD + cumsum[i];
            s %= MOD;
            dp[i] = s * (interval[i].second - interval[i].first);
            dp[i] %= MOD;
        }

    }

    long long ans = 0;
    for(int i = 0; i < S; i++){
        ans += dp[i];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;


//std::vector<std::set<int>> g;

int main(){
    int n;
    std::cin >> n;
    VEC(int,a,n);
    rep(i,n-1){
        std::cout << a[i] << ' ';
    }
    std::cout  <<a[n-1]<< std::endl;
    rrep(i,1,n){
        int v=a[i];
        int j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        rep(i,n-1){
            std::cout << a[i] << ' ';
        }
        std::cout  <<a[n-1]<< std::endl;
    }
}


Measured memory_bytes: 3212
use std::collections::*;
use std::io::*;
use std::*;
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    // iterator(splitted input-string) => iterator(output-type)
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:ty),+) => {
        ($(_get!($it; $t)),*)
    };
}

fn main() {
    let n = get!(i32);
    let mut s = get!([char];n as usize);
    let mut map = HashMap::new();
    let mut ans: i64 = 0;
    for mut i in s {
        i.sort();
        let key = i.iter().collect::<String>();
        let counter = map.entry(key).or_insert(0 as i64);
        ans += *counter;
        *counter += 1;
    }
    println!("{}", ans);
}


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

int main(){
	int x,h;
	double ans;

	while(scanf("%d\n%d", &x, &h)){
		if(x==0 && h==0) break;
		ans = 0;
		ans += (double)x*x;
		double ah = sqrt(x/2.0*x/2.0+h*h);
		ans += (ah*x)/2.0*4.0;
		printf("%f\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

hash = {}
a.each do |v|
  if hash[v] == nil then
    hash[v] = 1
  else
    hash[v] += 1
  end
end

c = 0
hash.each do |k, v|
  if k <= v then
    c += v - k
  else
    c += v
  end
end

puts c.to_s

Measured memory_bytes: 15492
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	aa := make([]int64, n)
	bb := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[n-1-i] = getNextInt64(scanner)
		bb[n-1-i] = getNextInt64(scanner)
	}

	var ans int64
	for i := 0; i < n; i++ {
		m := (aa[i] + ans) % bb[i]
		if m == 0 {
			continue
		}
		ans += bb[i] - m
	}

	fmt.Println(ans)
	writer.Flush()
}


Measured memory_bytes: 5504
n = int(input())
a = input().strip().split()
#Bubble sort
b = a[:]
for i in range(n):
    for j in range(n-1,i,-1):
        if b[j][1] < b[j-1][1]:
            b[j],b[j-1] = b[j-1],b[j]
print(' '.join(b))
print('Stable')
#Selection sort
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j][1] < a[minj][1]:
            minj = j
    a[i],a[minj] = a[minj],a[i]
print(' '.join(a))
print('Stable' if b == a else 'Not stable')

Measured memory_bytes: 7752