akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int,input().split()))

count = 0
for i in range(0,N-1):
  if A[i] <= A[i+1]:
    count
  else:
    count = count + A[i]-A[i+1]
    A[i+1] = A[i]

print(count)

Measured memory_bytes: 32228
#include<bits/stdc++.h>
using namespace std;
int w,q;
int main() {
	cin>>q;
	if(q==100000) q--;
	for(int l=1;l<=q;l++) {
		if(l>=10&&l<100||l>=1000&&l<10000) continue;
		w++;
	}
	cout<<w;
	return 0;
}

Measured memory_bytes: 256
(function main() {
  const n = Number(require('fs').readFileSync('/dev/stdin', 'utf8'));

  const cache = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144];
  const fib = function fib(n) {
    if (cache[n]) return cache[n];
    cache[n] = fib(n - 1) + fib(n - 2);
    return cache[n]
  };
  console.log(fib(n));
})();



Measured memory_bytes: 15128
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 100000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
vector<long long> stones;
long long dp[6][300000] = {};
int main() {
	int n;
	cin >> n;
	REP(i, n) {
		int b;
		cin >> b;
		stones.push_back(b);
	}
	for (int i = 1; i < 300000; ++i) {
		REP(q, 6) {
			dp[q][i] = LONG_INF;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int q = 0; q < 5; ++q) {
			for (int j = q; j < 5; ++j) {
				switch (j) {
					case 0:
						dp[0][i + 1] = min(dp[0][i + 1], dp[q][i] + stones[i]);
						break;
					case 1:
						if (stones[i] != 0)
							dp[1][i + 1] = min(dp[1][i + 1], dp[q][i] + (stones[i] % 2LL));
						else
							dp[1][i + 1] = min(dp[1][i + 1], dp[q][i] + 2LL);
						break;
					case 2:
						dp[2][i + 1] = min(dp[2][i + 1], dp[q][i] + (stones[i] + 1LL) % 2LL);
						break;
					case 3:
						if (stones[i] != 0)
							dp[3][i + 1] = min(dp[3][i + 1], dp[q][i] + stones[i] % 2LL);
						else
							dp[3][i + 1] = min(dp[3][i + 1], dp[q][i] + 2LL);
						break;
					case 4:
						dp[4][i + 1] = min(dp[4][i + 1], dp[q][i] + stones[i]);
				}
			}
		}
	}
	long long ans = dp[0][n];
	REP(i, 5) {
		ans = min(ans, dp[i][n]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 16496
#include<iostream>
using namespace std;
int main(){
    int n,m,sum,count;
    int a[n];
    sum = 0;
    count = 0;
    cin >> n >> m;
    int m4 = m * 4;
    //cout << m << endl;
    for (int i=0; i < n; i++){
        cin >> a[i];
        sum += a[i];
        //int abc = a[i] * m4;
        //cout <<"a[i];" << a[i] << " " <<"m;"<< m <<" "<<"abc;"<<abc<< endl;
    }
    for(int j=0; j < n; j++){
        if(a[j] * m4 >= sum){
            count ++;
        }
    }
    //cout << sum << " " << count << " " << m << endl;
    if(count >= m ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long ll; 
typedef map<ll,int>::iterator M;
map <ll,int> r;
 
void W(){
  ll a,b,pre=0;
  cin>>a>>b;
  M it=r.begin();
  
  while(it!=r.end()){
    if(it->s==-1){
      if((it->f)-pre>=b){
	r[pre+b]=a;
	return;
      }
      it->s=a;
      b-=((it->f)-pre);
    }
    pre=it->f;
    it++;
  }
}
 
void D(){
  int a;
  cin>>a;
  M it=r.begin();
  while(it!=r.end()){
    if(it->s==a)it->s=-1;
    it++;
  }
}
 
int R(){
  ll a;
  cin>>a;a++;
  M it=r.begin();
  while(it!=r.end()){
    if((it->f)>=a)return it->s;
    it++;
  }
  return -1;
}
 
int main(){
  int n;
  while(cin>>n,n){
    r.clear();
    r[1000000000000000LL]=-1;
    
    while(n--){
      char c;
      cin>>c;
      if(c=='W')W();
      else if(c=='D')D();
      else if(c=='R')cout<<R()<<endl;
    }
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1488
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
/* contest template */
int a[10000],b[10000],c[10000];
int N;
long long sumA, sumB,stepA,stepB;

int main()
{
    cin>>N;
    for(int i=0; i<N;i++){
        cin>>a[i];
        sumA+=a[i];
    }
    for(int i=0; i<N;i++){
        cin>>b[i];
        sumB+=b[i];
    }
    for(int i=0; i<N;i++){
        c[i]=a[i]-b[i];
        if(c[i]<0){
            if(c[i]%2==0){
                stepA+=-c[i]/2;
            }else{
                stepA+=(-c[i]+1)/2;
                stepB++;
            }
        }else if(c[i]>0){
            stepB+=c[i];
        }
    }
    if(sumB-sumA<0) cout<<"No"<<endl;
    else if(stepA-stepB<0) cout<<"No"<<endl;
    else if(2*stepA-stepB!=sumB-sumA) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 384
def check(s):
    counter = [False,False,False]
    for c in s:
        if c == "3":
            counter[0] = True
        elif c == "5":
            counter[1] = True
        elif c == "7":
            counter[2] = True
        if counter[0] and counter[1] and counter[2]:
            return True
    return False

def f(s,maxi):
    if int(s) > maxi:
        return 0
    if s == "0":
        s = ""
    if check(s):
        return f(s+"3",maxi) + f(s+"5",maxi) + f(s+"7",maxi) + 1
    
    return f(s+"3",maxi) + f(s+"5",maxi) + f(s+"7",maxi)
   
   
print(f("0",int(input())))

Measured memory_bytes: 3064
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll a, b;
    cin >> a >> b;

    ll c = a+b;

    if(c%2==0){
        p(c/2);
    }else{
        p(c/2+1);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isPossible(x) printf("%s\n",(x) ? "Possible" : "Impossible")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// #define INF (1<<29)

const long long INF = 1LL<<60;

#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
// const int mod =(int)998244353;
const int mod =(int)1e9+7;

const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
  if(a<0)a=-a;
  if(b<0)b=-b;
    ll g;g=gcd(a,b);
    return b/g*a;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll RS(ll N,ll P,ll m){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,m);
            return t*t%m;
        }else{
            return N*RS(N,P-1,m)%m;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N=in();
    cout<<(10000-N)%1000<<endl;
    return 0;
} 


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdint>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string X;
    cin >> X;
    int scnt = 0;
    int res = X.size();
    rep(i, X.size()) {
        if(X[i] == 'S')
            scnt++;
        else if(X[i] == 'T' && scnt) {
            scnt--;
            res -= 2;
        }
    }
    cout << res << endl;
    return 0;
}

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

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;

#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define int long long
#define sz(v) (int)v.size()
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define f(i,l,r) for(long long i=l;i<=r;i++)
#define rf(i,r,l) for(long long i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }


const int N=1e5+5,mod=1e9+7,bit=61;


signed main()
{
    fast;

    int t=1;
    //cin>>t;
    f(tc,1,t)
    {
        ll n;
        cin>>n;
        ll s[n];
        f(i,0,n-1)
        {
            cin>>s[i];
        }
        ll ans=0;
        sort(s,s+n);
        f(i,0,n-1)
        {
            f(j,i+1,n-1)
            {
                f(k,j+1,n-1)
                {
                    if(s[i]==s[j] or s[j]==s[k] or (s[i]+s[j]<=s[k]))
                    {
                        continue;
                    }
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp(const void *a, const void *b){
return strcmp(a,b);
}
char s[200015][15];
int main(void){
    int n;
    
    int dif=1;
    scanf("%d",&n);

    for(int i=0;i<n;i++){
        scanf("%s",s[i]);
    }

    qsort(s,n,sizeof(char)*15,cmp);
    if(strcmp(s[0],s[n-1])==0){printf("1\n");return 0;}

    for(int i=1;i<n;i++){
        if(strcmp(s[i-1],s[i])!=0){dif++;}
    }
    printf("%d\n",dif);
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int odd = 0;
    odd += (A%2) + (B%2) + (C%2);
    cout << (odd >= 2 ? "Hom" : "Tem") << endl;
    return 0;
}



Measured memory_bytes: 3092
# 2019-11-12 21:58:02(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def main():
    a, b, k = [int(x) for x in sys.stdin.readline().split()]

    n = gcd(a, b)
    count = 0
    while True:
        if a % n == 0 and b % n == 0:
            count += 1
            if count == k:
                print(n)
                sys.exit()
        n -= 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args)
    {
		Scanner sc=new Scanner(System.in);
			String s1=sc.next();
			int n1=s1.length();
			String s2=sc.next();
			int n2=s2.length();
			int min=Integer.MAX_VALUE;
			for(int i=0;i<n1-n2+1;i++) {
				String temp=s1.substring(i,i+n2);
				int count=0;
				for(int j=0;j<temp.length();j++) {
					if(temp.charAt(j)!=s2.charAt(j)) count++;
				}
				min=Math.min(count, min);
            }
			System.out.println(min);
	}
}


Measured memory_bytes: 36368
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xmod int(1e9+7)
#define hmod 1223334444555553LL
using namespace std;

int n,ans,m; 
int main(){
	scanf("%d%d",&n,&m);
	printf("%d\n",6-m-n);
	return 0;
} 

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int cnt = 0;
	rep(i, n) {
		int j = i + 1;
		while (s[i] == s[j] && j < s.size()) j++;
		i = j - 1;
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 512
package main

import (
        "fmt"
)

func solution(o, e string) string {
        out := make([]byte, len(o)+len(e))
        for i := range out {
                if (i-1)&1 == 1 {
                        out[i] = o[i/2]
                } else {
                        out[i] = e[i/2]
                }
        }
        return string(out)
}

func main() {
        var o, e string
        fmt.Scan(&o, &e)
        fmt.Println(solution(o, e))
}

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

using namespace std;

int main(){
	int n, a, b, s=0;
	cin >> n >> a >> b;
	int k = 0;
	int temp;
	for(int i=1; i<=n; i++){
		temp = i;
		while(temp!=0){
			k+=temp%10;
			temp/=10;
		}
		if(k >= a && k<=b){
			s += i;
		}
		k=0;
	}
	cout << s << endl;
}


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

lst = []
for i in range(N):
    lst.append(list(map(int,input().split())))


x_left,x_right = 0, W
y_under, y_up = 0,H

for i in range(N):
    x,y = lst[i][0], lst[i][1]
    if lst[i][2] == 1:
        if x_left < x: 
            x_left = x
    elif lst[i][2] == 2:
        if x_right > x:
            x_right = x
            if x_right == 0:
                print(0)
                exit()
    elif lst[i][2] == 3:
        if y_under < y:
            y_under = y
    elif lst[i][2] == 4:
        if y_up > y:
            y_up = y
            if y_up == 0:
                print(0)
                exit()

yoko = x_right - x_left
tate = y_up - y_under
if tate * yoko <= 0:
    print(0)
else:
    print(tate * yoko)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int count(int p,int q,int n,int i,int max,int acc){
    if(p==0) return 1;
    if(n==0) return 0;
    int result = 0;
    for(;i*acc<=max;i++){
        result += count(p*i-q,i*q,n-1,i,max,i*acc);
    }
    return result;
}
 
int main(void){
    int p,q,a,n;
    while(cin>>p>>q>>a>>n,p|q|a|n){
        cout<<count(p,q,n,1,a,1)<<endl;
    }

    return 0;
}

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  string s;
  cin >> s;
  if(s.length() == 2) {
    if(s[0] == s[1]) cout << 1 << " " << 2 << endl;
    else cout << -1 << " " << -1 << endl;
    return 0;
  }
  rep(i, 0, s.length() - 2) {
    if(s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 512
import Data.Function (fix)
import Control.Monad
import System.IO
import Text.Printf
import Control.Applicative
main :: IO ()
main = fix $ \loop -> do
     end <- isEOF
     unless end $ do
       a:b:c:d:e:f:_ <- map read . words <$> getLine
       let (x,y) = solve a b c d e f
       printf "%.3f %.3f\n" x y
       loop


solve :: Double -> Double -> Double -> Double -> Double -> Double -> (Double, Double)
solve a b c d e f = (x,y)
  where
    x = (/1000) $ fromInteger $ round $ (*1000) $ ( (e * c - b * f) / (a * e - d * b))
    y = (/1000) $ fromInteger $ round $ (*1000) $ ( (a * f - d * c) / (a * e - d * b))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string s; cin >> s;
	int N = s.size();
	vector<int> v(N+1, 0);
	REP(i, N) {
		int d = s[i] == '/' ? 1 : s[i] == '_' ? 0 : -1;
		v[i+1] = v[i]+d;
	}
	vector<int> h(N);
	REP(i, N) {
		h[i] = max(v[i], v[i+1]);
	}
	int hm = inf;
	REP(i, N) hm = min(hm, h[i]);
	REP(i, N) h[i] -= hm;
	map<int, set<int> > m;
	REP(i, N) {
		m[h[i]].insert(i);
	}
	vector< pair<P, int> > a;
	REP(i, N) {
		if (s[i] == '\\') {
			set<int>& x = m[h[i]];
			auto it = x.upper_bound(i);
			if (it != x.end()) {
//				cout << i << " " << *it << endl;
				a.pb( pair<P, int>(P(i, *it), *it-i) );
			}
		}
	}
	auto it = a.begin();
	while (it != a.end()) {
		auto nxt = it; ++nxt;
		if (nxt == a.end()) break;
		if (nxt->first.second <= it->first.second) {
			nxt->first = it->first;
			nxt->second += it->second;
			it->second = 0;
		}
		++it;
	}
	ll sum = 0;
	vector<ll> ans;
	EACH(p, a) {
		if (p.second == 0) continue;
		ans.pb( p.second );
		sum += p.second;
	}
	cout << sum << endl;
	cout << ans.size();
	REP(i, ans.size()) {
		cout << " " << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 5584
n = gets.chomp.to_i
x = gets.chomp.split(' ').map(&:to_i)

sorted_x = x.sort
median_right_i = n / 2
median_left_i = median_right_i - 1
median_left = sorted_x[median_left_i]
median_right = sorted_x[median_right_i]

if median_left == median_right
  n.times { puts median_left }
else
  x.each do |xi|
    puts xi <= median_left ? median_right : median_left
  end
end


Measured memory_bytes: 25316
#include<bits/stdc++.h>
using namespace std;
 
double dp[3010][3010];
 
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);

  dp[0][0] = 1;
  int n; cin >> n;

  for (int i = 0; i < n; ++i) {
    double p; cin >> p;
    for (int j = 0; j < 3000; ++j) {
      dp[i + 1][j + 1] += dp[i][j] * p;
      dp[i + 1][j] += dp[i][j] * (1 - p);
    }
  }
  double ans = 0;
  for (int i = 0; i <= n; ++i) if (i > n - i) ans += dp[n][i];
  cout << fixed << setprecision(20) << ans << '\n';
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

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

  set<int> st;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    st.insert(a);
  }
  if ((int)st.size() == n) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 12944
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int people;
	int button;
	int *student;
	cin >> people >> button;
	student = new int[people];
	for (int i = 0; i < people; ++i) {
		cin >> student[i];
	}
	for (int i = 2; i <= button; ++i) {
		for (int k = 0; k < people - 1; ++k) {
			if (student[k] % i > student[k + 1] % i) {
				swap(student[k], student[k + 1]);
			}
		}
	}
	for (int i = 0; i < people; ++i) {
		cout << student[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
  int q,w,o,p,z,x,n,m;
  cin >> q >> w >> o >> p;
  z = w-p + o;
  x = o+p - q;
  n = q+w - p;
  m = w-q + o;
  cout << z __ x __ n __ m fin;
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

using namespace std;

int main()
{
    map<vector<int>, int> mp;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        vector<int> tmp(26);
        string s;
        cin >> s;
        for (int j = 0; j < (int) s.length(); j++){
            tmp[s[j] - 'a']++;
        }
        mp[tmp]++;
    }
    long long ans = 0;
    for (auto elem : mp){
        long long n = elem.second;
        ans += n * (n - 1) / 2;
    }
    cout << ans;
    return 0;
}


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

int H, W;
char field[105][105];
bool visited[105][105];
int dx[] = {1,0,-1,}, dy[] = {0,1,0,-1};

void dfs(int x, int y, char sign) {
  visited[y][x] = true;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == sign && !visited[ny][nx]) {
      dfs(nx, ny, sign);
    }
  }
}

int main() {
  while (true) {
    cin >> H >> W;
    if (!(H|W)) break;
    for (int i = 0; i < H; i++) {
      cin >> field[i];
    }
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        visited[y][x] = false;
      }
    }
    int res = 0;
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        if (!visited[y][x]) {
          char sign = field[y][x];
          dfs(x, y, sign);
          res++;
        }
      }
    }
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 3556
#include <stdio.h>

int main(void) {
    int n, m, k;
    bool ok = false;

    scanf(" %d %d %d", &n, &m, &k);

    for (int row = 0; row <= n; row++) {
        for (int col = 0; col <= m; col++) {
            int got = row * m + col * n - 2 * row * col;
            if (got == k) {
                ok = true;
                col = m + 1;
                break;
            }
        }
    }

    if (ok) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int height, width, i;
  scanf("%d %d", &height, &width);
  char input_str[width+1];
  for(i = 0; i < width + 2; i++) {
    printf("#");
  }
  printf("\n");
  for(i = 0; i < height; i++) {
    scanf("%s", input_str);
    printf("#%s#\n", input_str);
  }
  for(i = 0; i < width + 2; i++) {
    printf("#");
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;
int Q;
deque<char> T;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	FORR(c,S) T.push_back(c);
	
	int order=0;
	cin>>Q;
	while(Q--) {
		cin>>i;
		if(i==1) {
			order^=1;
		}
		else {
			cin>>i>>s;
			i--;
			if(order==i) {
				T.push_front(s[0]);
			}
			else {
				T.push_back(s[0]);
			}
		}
	}
	
	S.clear();
	FORR(c,T) S.push_back(c);
	if(order) reverse(ALL(S));
	cout<<S<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1168
#include <bits/stdc++.h>
//#include <rng_58>
//#include <chokudai>
//#include <tourist>
using namespace std;
 
// Macro and Macro Functions
#define rep(a, b) for(int a = 0; a < b; ++a)
#define REP(a, b, c) for(int a = b; a < c; ++a)
#define drep(a, b, c) for(int a=0,b=0;b<c?:(b=0,++a<c);++b)
#define int long long
#define SORT(a) sort(ALL(a))
#define RSORT(a) sort(RALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MOD 1000000007
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define ALLIN(a) rep(nanika,a.size()) cin>>a[nanika]
#define ALLINDE(a) rep(kyawa,a.size()){cin>>a[kyawa]; --a[kyawa];}
#define YN(a) do{if(a) cout<<"YES"; else cout<<"NO";}while(0)
#define Yn(a) do{if(a) cout<<"Yes"; else cout<<"No";}while(0)
#define yn(a) do{if(a) cout<<"yes"; else cout<<"no";}while(0)
#define spa " "
#define dspa "  "
#define ctoi(c) (c)-'0'
#define altoi(a) (a)-'a'
#define fi first
#define se second
#define dvec_int(name,row,column,value) vector<vector<int>> name(row,vector<int>(column,value))
 
// List of using
using ll   = signed long long;
using ull  = unsigned long long;
using pint = pair<int,  int>;
using pong = pair<long, long>;
using tint = tuple<int,  int,  int>;
using tong = tuple<long, long, long>;
using vint = vector<int>;
using vll  = vector<long long>;
using vbol = vector<bool>;
using vstr = vector<string>;
using vull = vector<unsigned long long>;
using dvin = vector<vector<int>>;
using dvbo = vector<vector<bool>>;
using mint = map<int,int>;
 
// Common Variable
bool DEBUG=false;
long long INF=2000000000;
 
void print(){
  cout<<'\n';
}
 
template<class HEAD,class... TAIL>
void print(HEAD&& head,TAIL&&... tail){
  cout<<head<<spa;
  print(forward<TAIL>(tail)...);
}
 
void scan(){}
 
template<class HEAD,class... TAIL>
void scan(HEAD&& head,TAIL&&... tail){
  cin>>head;
  scan(forward<TAIL>(tail)...);
}
 
template<typename t>
void print(vector<t> &v){
  rep(i,v.size()){
    cout<<v[i]<<spa;
  }
  cout<<endl;
}
 
template<typename t, typename u>
void print(vector<pair<t,u>> &v){
  rep(i,v.size()){
    cout<<i<<" : "<<v[i].first<<" "<<v[i].second<<endl;
  }
}
 
template<typename t,typename u>
t min(t a,u b){
  return a<=b?a:b;
}
 
//--------------------------------
// Template Place
//--------------------------------
int dx[]={ 1, 0,-1, 0};
int dy[]={ 0,-1, 0, 1};
 
signed main(){
  int n,x; cin>>n>>x;
  vint a(n); ALLIN(a);
  //dvec_int(dp,n,n,0);
  vector<vector<int>> dp(n,vector<int>(n,0));
 
  int ans=0,ans_i=0;
  for(int j=0; j<n; ++j){
    dp[0][j]=a[j];
    ans+=a[j];
  }
  for(int i=1; i<n; ++i){
    int tmp=0;
    for(int j=0; j<n; ++j){
      dp[i][j]=min(dp[i-1][j],a[(j-i+n)%n]);
      tmp+=dp[i][j];
    }
    // print(i,":",tmp,"+",i*x,"=",tmp+i*x,"Minimum :",ans,ans_i);
    tmp+=i*x;
    if(ans>tmp){
      ans=tmp;
      ans_i=i;
    }
  }
 
  // rep(i,n){
  //   rep(j,n){
  //     cout<<setw(4)<<dp[i][j];
  //   }
  //   cout<<endl;
  // }
 
  cout<<ans;
}

Measured memory_bytes: 31744
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n,i,temp,max=0,c=1,x=0,fo=0,go=0;
    cin>>m;
    string s[101],r[101];
    for(i=0; i<m; i++)
        cin>>s[i];
    cin>>n;
    for(i=0; i<n; i++)
        cin>>r[i];
    sort(s,s+m);
    sort(r,r+n);
    temp=0;
    while(1)
    {
        c=1;
        x=temp;
        if(go>0)
            go++;
        for(i=temp+1; i<m; i++)
        {
            if(s[temp]==s[i])
            {
                c++;
                if(i==(m-1))
                    fo=i;
            }
            else
            {
                if(i==(m-1))
                    go=i;
                temp=i;
                break;
            }
        }
        for(i=0; i<n; i++)
        {
            if(s[x]==r[i])
                c--;
        }
        if(c>max)
            max=c;
        if(fo==(m-1))
            break;
        if(go==m)
            break;
    }
    cout<<max<<endl;
    return 0;
}


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

using namespace std;


int main()
{

    string s1,s2;
    int m=0;
    cin>>s1>>s2;

    if(s1.length()<s2.length())
    {

        for(int i=0; i<s1.length(); i++)
        {
            if(s1[i]==s2[i])
            {

                m++;

            }
            else
                break;

        }

        if(m==s1.length())
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;


    }
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int m, f, r;
        cin >> m >> f >> r;
    if(m==-1 && f==-1 && r==-1) break;
    if(m==-1 || f==-1) cout << "F" << endl;
    else if(m+f>=80) { cout << "A" << endl; }
    else if(m+f>=65){ cout << "B" << endl; }
    else if(m+f>=50){ cout << "C" << endl; }
    else if(m+f>=30){ 
        if(r>=50){cout << "C" << endl;}
        else {cout << "D" << endl;} 
    }else{ cout << "F" << endl; }
    }
    return 0;
}


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

int main(){
  int a,b,x;
  cin >>a >>b >>x;
  if(a+b>=x) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
	int n,m;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];

	cin >> m;
	vector<int> b(m);
	for(int i=0;i<m;i++)cin>>b[i];


	if(b>a){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
 	}

}


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

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}


Measured memory_bytes: 256
def main():
    n, *s = open(0).read().split()
    ac, wa, tle = s.count('AC'), s.count('WA'), s.count('TLE')
    re = int(n) - (ac + wa + tle)
    print('AC x', ac)
    print('WA x', wa)
    print('TLE x', tle)
    print('RE x', re)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17120
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
const ll mod=233231123112313ll;
int n;
ll ANS;
char s[40];
unordered_map<ll,int> mp1[20],mp2[20];
void solve(char s[])
{
	for(int i=0;i<(1<<n);i++)
	{
		ll hs=0;
		int cnt=0;
		for(int j=0;j<n;j++)
		{
			if((i>>j)&1)
			{
				(hs=1ll*hs*233+s[j])%mod;
				cnt++;
			}
		}
		for(int j=n-1;j>=0;j--)
		{
			if(!((i>>j)&1))(hs=1ll*hs*233+s[j])%mod;
		}
		mp1[cnt][hs]++;
	}
}
void query(char s[])
{
	for(int i=0;i<(1<<n);i++)
	{
		ll hs=0;
		int cnt=0;
		for(int j=0;j<n;j++)
		{
			if((i>>j)&1)
			{
				(hs=1ll*hs*233+s[j])%mod;
				cnt++;
			}
		}
		for(int j=n-1;j>=0;j--)
		{
			if(!((i>>j)&1))(hs=1ll*hs*233+s[j])%mod;
		}
		ANS+=mp1[cnt][hs];
	}
}

int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	solve(s);
	reverse(s+n,s+n+n);
	query(s+n);
	cout<<ANS<<endl;
	return 0;
}


Measured memory_bytes: 23452
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(rall(arr));
    int ans=arr[0];
    int p=1;
    bool flg=true;
    for(int i=0;i<n-2;i++)
    {
        // cout<<arr[p]<<endl;
        ans+=arr[p];
        if(flg)
        {
            flg=false;
        }
        else
        {
            flg=true;
            p++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4784
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int V, E;
struct edge { LL to, cost; };
int start;
LL d[100100]; //距離
vector<edge> vec[1010];

void dijkstra() {
	for (int i = 0; i < 100100; i++)d[i] = HINF<LL>();
	priority_queue<pii, std::vector<pii>, std::greater<pii>> pq;
	d[start] = 0;
	pq.push(make_pair(d[start], start));//cost,to
	while (!pq.empty()) {
		pii p = pq.top();
		pq.pop();
		int i = p.second;
		if (d[i] < p.first)continue;
		for (int k = 0; k < vec[i].size(); k++) {
			edge e = vec[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
}

int main() {
	cin >> V;
	REP(i, V) {
		int u;
		cin >> u;
		int num;
		cin >> num;
		REP(j, num) {
			int v, c;
			cin >> v >> c;
			vec[u].emplace_back(edge{ v,c });
		}
	}
	dijkstra();
	REP(i, V) {
		cout << i << " " << d[i] << endl;
	}
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;
using PII = pair<int, int>;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  ll h, w, n; cin >> h >> w >> n;
  map<PII, ll> mp;
  REP(i,n) {
    int a, b; cin >> a >> b;
    a--; b--;
    REP(j, 3) REP(k, 3) {
      if (a - j >= 0 && b - k >= 0
          && a - j < h-2 && b - k < w-2) mp[make_pair(a-j, b-k)]++;
    }
  }
  vector<ll> ans(10,0);
  for (const auto &p : mp) {
    ans[p.second]++;
  }
  ans[0] = (h-2)*(w-2) - whole(accumulate, ans, 0L);
  REP(i,10) cout << ans[i] << endl;
  return 0;
}


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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	/*
	{
		int sum = 0;
		for (int i = 1; i <= 20; i++) {
			sum ^= i;
			cerr << "f(" << i << ") = " << sum << endl;
		}
	}*/

	auto get = [&](ll n) -> ll {
		if (n <= 0) return 0;
		int r = n % 4;
		if (r == 0) return n;
		else if (r == 1) return 1;
		else if (r == 2) return n + 1;
		else if (r == 3) return 0;
		else assert(false);
	};

	ll L, R; cin >> L >> R;
	cout << (get(L - 1) ^ get(R)) << '\n';

	return 0;
}


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

int main() {
int n,m;
cin >> n;
vector<int> T(n);
rep(i,n) cin >> T.at(i);
int sum = 0;
rep(i,n) sum += T.at(i);
cin >> m;
vector<vector<int>> P(m,vector<int>(2));
rep(i,m){
  cin >> P.at(i).at(0);
  cin >> P.at(i).at(1);
}
rep(i,m){
  int ans = sum - T.at(P.at(i).at(0)-1) + P.at(i).at(1);
  cout << ans  << endl;
}


}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
void dfs(vector<pair<int, int>> p, double res, set<ll>& ans, int d) {
    if (d == p.size()) {
        ans.insert((ll)res);
        return;
    }
    int freq, base;
    tie(base, freq) = p[d];
    for(int i = 0; i <= freq; i++) {
        dfs(p, res*pow(base, i), ans, d+1);
    }
}
int main() {
    ll n, m, m2, m3;
    cin >> n >> m;
    m3 = m;
    map<int, int> prime;
    while(m % 2 == 0) {
        m/=2;
        prime[2] += 1;
    }
    m2 = m;
    for(ll i = 3; i*i < m2; i+=2) {
        while (m % i == 0) {
            m/= i;
            prime[i] += 1;
        }
    }
    if (m > 0)
        prime[m] += 1;
    vector<pair<int, int>> p2;
    for(auto& p: prime) {
        p2.push_back({p.first, p.second});
    }
    set<ll> ans;
    dfs(p2, 1.0, ans, 0);

    cout << m3 / (*ans.lower_bound(n)) << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N, L=0;
    int abs_min=1000;
    int apple=0;
    cin >> N >> L;
    for (int i=0; i < N; i++){
        if (abs(abs_min) > abs(L+ i)){
            abs_min = L+i;
        }
        apple +=(L+i);
        //cout << L+i << endl;
    }
    cout << apple -abs_min;
    //cout << abs_min;
}

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

int main(){
  string S;
  cin >> S;
  vector<int> seq(S.size());
  int i, j, max;
  j=0;
  for(i=0;i<S.size();i++){
    if(S[i]=='A'||S[i]=='T'||S[i]=='G'||S[i]=='C'){
      seq[j]++;
    } else if(seq[j]!=0) {
      j++;
    }
  }
  max = 0;
  for(i=0;i<S.size();i++){
    if(max < seq[i]) max = seq[i];
  }
  cout << max << endl;
  return 0;
}





Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Integer N = new Integer(scanner.next());

		ArrayList<Integer> input = new ArrayList<Integer>();
		for(int i = 0;i<N;i++) {
			input.add(new Integer(scanner.next()));
		}

		Integer max = Collections.max(input);
		Integer min = Collections.min(input);
		String output = String.valueOf((max-min));

		System.out.println(output);

		scanner.close();
	}
}


Measured memory_bytes: 23252