akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	sort(a.rbegin(),a.rend());

	lint ans=a[0];
	rep(i,n-2) ans+=a[i/2+1];
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 4028
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction




def main():
    num = int(input())
    ans = num - 1

    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            ans = min(ans, i + num // i - 2)

    print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 63084
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;
const int INF = 0x3f3f3f3f;
//static const auto _____ = []()
//{
//	ios::sync_with_stdio(false);
//	cin.tie(nullptr);
//	return nullptr;
//}();

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    int v[N + 1][3]; //  v[day][i] 表示第day天进行第i项饿的幸福值
    memset(v, 0, sizeof(v));
    for (int i = 1; i <= N; i++) {
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }
    int dp[N + 1][3];
    for (int i = 0; i < 3; i++) {
        dp[1][i] = v[1][i];
    }
    for (int day = 2; day <= N; day++) {
        for (int cur = 0; cur < 3; cur++) {
            dp[day][cur] = 0;
            for (int last = 0; last < 3; last++) {
                if (cur != last) {
                    dp[day][cur] = max(dp[day][cur], dp[day - 1][last] + v[day][cur]);
                }
            }
        }
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2]));
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n, q, t, c = 0;
  cin >> n;
  vector<int> s(n);
  rep(i, n) cin >> s[i];
  
  cin >> q;
  rep(i, q) {
    cin >> t;
    rep(i, n) {
      if (t == s[i]) {
        c++;
        break;
      }
    }
  }

  cout << c << endl;
  
  return 0;
}


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

int main(){
    long int X;
    cin >> X;

    long int a = X/500;
    X -= a*500;
    long int b = X/5;

    cout << a*1000 + b*5 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int x1 = scanner.nextInt();
    int y1 = scanner.nextInt();
    int x2 = scanner.nextInt();
    int y2 = scanner.nextInt();

    int xlen = x2 - x1;
    int ylen = y2 - y1;

    System.out.printf("%d %d %d %d\n", x2 - ylen, y2 + xlen, x1 - ylen, y1 + xlen);
  }

}


Measured memory_bytes: 23636
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	while(cin>>n,n){
		int c;
		double h,w;
		vector<pair<double,int> >data;
		data.clear();
		for(int i =0;i <n;i++){
			cin>>c>>h>>w;
			double bmi =(w/((h/100)*(h/100)));
			bmi =fabs(22.0-bmi);
			//cout <<bmi<<endl;
			data.push_back(mp(bmi,-c));
		}
		sort(data.begin(),data.end());
		//cout <<data[0].first<<endl;
		cout <<-data[0].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 1264
import static java.lang.Character.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int[] count = new int[26];
		while((str = br.readLine()) != null){
			str = str.toLowerCase();
			for(int i = 0;i < str.length();i++){
				char c = str.charAt(i);
				if(isLetter(c)){
					count[c - 'a']++;
				}
			}
		}
		for(int i = 0;i < count.length;i++){
			System.out.print((char)('a' + i));
			System.out.print(" : ");
			System.out.println(count[i]);
		}
	}

}

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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
ll dp [100];

int main()
{
	scanf("%d",&N);
	dp [0] = 2;
	dp [1] = 1;

	FOR(i,2,N + 1){
		dp [i] = dp [i - 1] + dp [i - 2];
	}
	printf("%lld\n",dp [N]);

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 200'009;

int t[4 * N];

void put(int x, int l, int r, int p, int v) {
  if (l == r) {
    t[x] = v;
    return;
  }
  int s = (l + r) / 2;
  if (p <= s) {
    put(2 * x, l, s, p, v);
  } else {
    put(2 * x + 1, s + 1, r, p, v);
  }
  t[x] = max(t[2 * x], t[2 * x + 1]);
}

int get(int x, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) {
    return -1;
  }
  if (l >= ql && r <= qr) {
    return t[x];
  }
  int s = (l + r) / 2;
  return max(get(2 * x, l, s, ql, qr), get(2 * x + 1, s + 1, r, ql, qr));
}

int x[N];
int d[N];
int o[N];
int f[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", x + i, d + i);
    o[i] = i;
  }
  sort(o, o + n, [](int i, int j) {
    return x[i] < x[j];
  });
  const int mod = 998244353;
  f[n] = 1;
  for (int i = n - 1; i >= 0; --i) {
    int l = i, r = n;
    while (r - l > 1) {
      int s = (l + r) / 2;
      if (x[o[i]] + d[o[i]] - 1 >= x[o[s]]) {
        l = s;
      } else {
        r = s;
      }
    }
    int j = l == i ? i : get(1, 0, n - 1, i, l);
    put(1, 0, n - 1, i, j);
    f[i] = (f[i + 1] + f[j + 1]) % mod;
  }
  printf("%d\n", f[0]);
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const ll INF = 1001001001001001LL;

ll D, G; 
ll p[20], c[20];
ll dp[20][150010];

void print() {
   rep (i, D+1) {
      for (int j = 0; j <= G; j++) {
         if (dp[i][j] == INF) {
            printf("%2c ", 'I');
         } else {
            printf("%2d ", dp[i][j]);
         }
      }
      puts("");
   }
}

int main() {
   // 初期化:
   cin >> D >> G;
   G /= 100;

   // 入力
   rep (i, D) {
      cin >> p[i] >> c[i];
      c[i] /= 100;
   }

   // DPテーブル初期化
   fill(dp[0], dp[20], INF);
   dp[0][0] = 0;

   // DP
   rep (i, D) { // 問題i
      for (ll k = 0; k <= p[i]; k++) { // 問題iのk個目
         ll bonus = (k == p[i] ? c[i] : 0);
         ll score = k*(i+1) + bonus;

         for (ll j = 0; j <= G; j++) {
            ll nj = min(G, j + score);
            chmin(dp[i+1][nj], dp[i][j]+k);
         }
      }
   }

   cout << dp[D][G] << endl;

   return 0;
}

Measured memory_bytes: 23680
def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    if M == 0:
        if N != 1:
            print(10**(N-1))
        else:
            print(0)
    else:
        ans = "-1"
        flag = False
        for i in range(10**N):
            if flag:
                break
            tmp = str(i)
            if len(tmp) < N:
                continue
            for j in range(M):
                if tmp[sc[j][0]-1] != str(sc[j][1]):
                    break
                if j == M-1:
                    ans = i
                    flag = True
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
local n=io.read("*n")
local a_map={}
for i=(n%2==0 and 1 or 0),n,2 do
    a_map[i]=(i==0 and 1 or 2)
end

local a={}
for i=1,n do
    local input=io.read("*n")
    a[input]=(a[input] or 0)+1
end

local counter=1
for k,v in pairs(a) do
    local checker=(a[k] and a_map[k] and a[k]==a_map[k])
    counter=(checker and counter*v%1000000007 or 0)
end
print(counter)


Measured memory_bytes: 3256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,a,b;
Vi h;
Vi h2;
bool ck(ll num){
    bool ans = false;
    h2.clear();
    h2 = h;
    rep(i,n){
        h2[i] -= a*num;
    }
    ll tmp = 0;
    rep(i,n){
        if(h2[i]>0){
            if(h2[i]%(b-a)==0){
                tmp += h2[i]/(b-a);
            }else{
                tmp += (h2[i]/(b-a)) + 1;
            }
        }
    }
    if(tmp > num)return false;
    else return true;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>b>>a;
    h.resize(n);
    rep(i,n){
        cin>>h[i];
    }
    sort(all(h));
    ll mid, ok = (h[n-1]/a)+1, ng = 0;
    while(abs(ok-ng)>1){
        mid = (ok+ng)/2;
        if(ck(mid))ok = mid;
        else ng = mid;
    }
    print(ok);
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
	int i,j;
	int a,b;
	int q;
	char tmp[1000];
	char op[9];
	char s[1000];
	char tmp1;

	scanf("%s", s);
	scanf("%d", &q);
	for(i=0; i<q; i++){
		scanf("%s", op);
		if(!strcmp(op,"replace")){
			scanf("%d%d", &a, &b);
			scanf("%s", tmp);
			for(j=0; j<b-a+1; j++){
				s[a+j] = tmp[j];	
			}
		} else if(!strcmp(op, "reverse")){
			scanf("%d%d", &a, &b);
			for(j=0; j< (b-a+1)/2; j++){
				tmp1 = s[a+j];
				s[a+j] = s[b-j];
				s[b-j] = tmp1;
			}
		} else{
			scanf("%d %d", &a, &b);
			for(j=a; j<=b; j++)
				printf("%c", s[j]);
			printf("\n");
		}
	}

	return 0;
}

Measured memory_bytes: 572
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int ans=K;
  for( int i = 1 ; i < N; i++ ){
      ans*=(K-1);
  }
  cout << ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define NIL -1

struct Node {int p,l,r;};
void setDepth(int ,int);
void printchildren(int);

struct Node T[100005];
int D[100005];

int main(){
  int n,i,j,r,l;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }
  for(i=0;i<n;i++){
    int id,k,c;
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0)T[id].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=id;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }
  setDepth(r,0);
  for(i=0;i<n;i++){
    printchildren(i);
  }
  return 0;
}

void setDepth(int u, int p){
  D[u]=p; // Depth Array
  if(T[u].r != NIL)setDepth(T[u].r,p);
  if(T[u].l != NIL)setDepth(T[u].l,p+1);
}

void  printchildren(int u){
  int c=T[u].l,i;

  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);
  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}



Measured memory_bytes: 6384
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> N >> K;

	int cnt = 0;
	int A;
	vector<int> nv, pv;
	rep(i, 0, N)
	{
		cin >> A;
		if (A < 0)
		{
			cnt++;
			nv.push_back(-A);
		}
		else
		{
			pv.push_back(A);
		}
	}

	sort(all(pv)), sort(all(nv));

	if (cnt*(N - cnt) < K)
	{
		K -= cnt * (N - cnt);
		int l = -1, r = (int)(1e9)*(int)(1e9);
		while (r - l > 1)
		{
			int mid = (l + r) / 2;
			int sum = 0;

			rep(i, 0, SZ(nv))
			{
				sum += max(0LL, upper_bound(all(nv), mid / nv[i]) - nv.begin() - i - 1);
			}
			rep(i, 0, SZ(pv))
			{
				if (pv[i] == 0)
				{
					if (mid >= 0)sum += SZ(pv) - 1 - i;
				}
				else
				{
					sum += max(0LL, upper_bound(all(pv), mid / pv[i]) - pv.begin() - i - 1);
				}
			}
			if (sum >= K)
			{
				r = mid;
			}
			else
			{
				l = mid;
			}
		}
		cout << r << endl;
	}
	else
	{
		int l = -1, r = (int)(1e9)*(int)(1e9);
		while (r - l > 1)
		{
			int mid = (l + r) / 2;
			int sum = 0;
			for (auto v : nv)
			{
				sum += pv.end() - upper_bound(all(pv), mid / v);
			}
			if (sum < K)
			{
				r = mid;
			}
			else
			{
				l = mid;
			}
		}
		cout << -r << endl;
	}

	return 0;
}

Measured memory_bytes: 2548
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int, int>P;
P a[114514];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		a[i] = P(b, i);
	}
	int ans = 0;
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (a[i].second % 2 != i % 2)ans++;
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((L + R + 1) >> 1)
using namespace std;
const int MAXN = 100050;
const int mod = 998244353;
typedef long long LL;
int n;
int a[MAXN], h[MAXN];
LL ans[MAXN];
bool cmp(const int &o, const int &p) { return a[o] > a[p]; }
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]), h[i] = i;
	sort(h, h + n, cmp);
	int now = h[0];
	for (int i = 1; i < n; ++i) {
		ans[now] += 1LL * i * (a[h[i - 1]] - a[h[i]]);
		if (now > h[i]) now = h[i];
	}
	ans[now] += 1LL * n * a[h[n - 1]];
	for (int i = 0; i < n; ++i) {
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 2688
df = [0, 0, 0]
gets.to_i.times do
  o = 0
  p = 0
  f = df.dup
  until o == 3
    case gets.chomp
    when 'HIT'
      p += f.pop
      f.unshift 1
    when 'HOMERUN'
      p += f.reduce(:+) + 1
      f = df.dup
    else
      o += 1
    end
  end
  puts p
end

Measured memory_bytes: 6092
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <sstream>
#include <climits>
#include <fstream>
#include <cmath>

using namespace std;

/// ********* debug template by Bidhan Roy *********

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const unordered_set< T > &v ) {
    os << "[";
    typename unordered_set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const unordered_map< F, S > &v ) {
    os << "[";
    typename unordered_map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    } 
    return os << "]";
}

#define debug(x) cerr << #x << " = " << x << endl;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<LL> VLL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<VB> VVB;
typedef vector<VI> VVI;
typedef vector<VC> VVC;
typedef vector<VLL> VVLL;
typedef vector<VD> VVD;
typedef vector<VS> VVS;
typedef vector<PII> VPII;

// TEMPLATE DEFINITIONS END

string s;

void read_input(){
    cin >> s;
}

void solve(){
    if(s.size() % 2){
        cout << "No\n";
        return;
    }

    for(int i=0;i+1<s.size();i+=2){
        // debug(i);
        if(s[i] != 'h' || s[i+1] != 'i'){
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read_input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	D = defaultdict(int)
	a = getlist()
	for i in a:
		D[i] += 1
	if len(D) >= 3:
		print("No")
	elif len(D) == 1:
		if a[i] * 2 <= N:
			print("Yes")
		elif a[i] + 1 == N:
			print("Yes")
		else:
			print("No")
	else:
		L = []
		for i in D:
			L.append([i, D[i]])
		L = sorted(L)
		if L[0][0] + 1 != L[1][0]:
			print("No")
		else:
			x = L[0][1]
			y = L[1][1]
			A = L[0][0]
			if y < (A - x + 1) * 2 or A - x + 1 <= 0:
				print("No")
			else:
				print("Yes")


if __name__ == '__main__':
	main()

Measured memory_bytes: 57628
from fractions import gcd
N , X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [abs(x[i]-X) for i in range(N)]
res = y[0]
for i in range(1,N):
    res = gcd(res,y[i])
print(res)


Measured memory_bytes: 16280
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using ll=long long int;
using namespace std;


int main() {

	int a, b;
	cin >> a >> b;

	int ans = 0;

	for (int i = a; i <= b; i++) {
		if (i /10000== i % 10 && i / 1000%10 == i /10%10) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); i++)
#define rrep(i, to) for (int i = (to) - 1; i >= 0; i--)
#define repf(i, from, to) for (int i = (from); i < (to); i++)
#define all(v) v.begin(), v.end()
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n, l;

  cin >> n >> l;
  V<string> s(n);

  rep(i, n) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());

  string ans = "";
  rep(i, n) {
    ans = ans + s[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 3688
N = int(input())
a = list(map(int,input().split()))

lst = [0]*(N-1)
x = [a[0]]*(N-1)
y = [sum(a)-a[0]]*(N-1)
lst[0] = abs(x[0]-y[0])

for i in range(1,N-1):
    x[i] = x[i-1]+a[i]
    y[i] = y[i-1]-a[i]
    lst[i] = abs(x[i]-y[i])

ans = min(lst)
print(ans)


Measured memory_bytes: 9080
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	int a, b;
	cin >> a >> b;
	if (a == 1) a = 14;
	if (b == 1) b = 14;
	if (a > b) {
		cout << "Alice";
	}
	else if (a < b) {
		cout << "Bob";
	}
	else {
		cout << "Draw";
	}


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

void _main() {
  int N;
  cin >> N;
  unordered_set<int> us;
  rep(i, 0, N) {
    int tmp;
    cin >> tmp;
    if (us.end() != us.find(tmp))
      us.erase(tmp);
    else
      us.insert(tmp);
  }

  cout << us.size() << "\n";
}

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

typedef long long LL;

LL a[10005];

LL M = 1e9 + 7;

LL pow(LL a,LL b,LL M)
{ 
   LL c = a * b - (LL)(a*b/M + 0.5)*M; 
   return c < 0 ? c + M : c;
}

int main()
{
   LL n,m;
   cin>>n>>m;
   for(int i = 1; i<=n; ++i)
     cin>>a[i];
     
     LL num1= 0,num2 =0;
     
    for(int i = 1; i<n; ++i){
      for(int j = i+1; j<=n; ++j){
       if(a[i]>a[j])
        num1 ++;
      }
    } 
    
    sort(a+1,a+n+1,greater<LL>());
    for(int i = 1; i<n; ++i){
      for(int j = i+1; j<=n; ++j){
          if(a[i]>a[j])
            num2++;
         }
      }
      
    LL flag1 = m,flag2 = m;
    
      if(flag1 % 2==0){
      	flag1 = m/2;
		flag2 = m-1;
	  }
	  
      else{
      	flag1 = m;
	    flag2  = (m-1)/2;
	  }
	   
      cout<<(pow(num1,m,M)%M + pow(flag1,flag2,M)*num2 )%M<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,j,n,m;
int wall[200][3],tx,ty,sx,sy;

int crosscheck(int tx,int ty,int sx,int sy,int wx,int wy,int rr){

	int abx=tx-sx,aby=ty-sy;
	int awx=wx-sx,awy=wy-sy;
	int bwx=wx-tx,bwy=wy-ty;

	int rr2=rr*rr;
	int aw2=awx*awx+awy*awy;
	int bw2=bwx*bwx+bwy*bwy;
	int ab2=abx*abx+aby*aby;

	int tim=abx*awy-aby*awx;
	int abw=abx*awx+aby*awy;

	if(aw2<rr2 && bw2<rr2)return 0;
	if(aw2<rr2 || bw2<rr2)return 1;
	if(abw<0)return 0;
	if(abw>ab2)return 0;

	if( tim*tim/ab2 <= (double)rr2)return 1;

	return 0;
}

int main(){
	while(scanf("%d",&n)*n){

		for(i=0;i<n;i++)scanf("%d %d %d",&wall[i][0],&wall[i][1],&wall[i][2]);

		for(scanf("%d",&m);m>0;m--){
			scanf("%d %d %d %d",&tx,&ty,&sx,&sy);
			int sss=0;
			for(i=0;i<n;i++){
				int wx=wall[i][0],wy=wall[i][1],rr=wall[i][2];
				if(crosscheck(tx,ty,sx,sy,wx,wy,rr))break;
			}
			if(i<n)printf("Safe\n"); else printf("Danger\n");
		}
	}
	return 0;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

bool check(ll x, std::vector<ll> A, std::vector<ll> F, ll K) {
  int N = (int) A.size();
  rep(i, N) {
    if(A[i] * F[i] <= x) {
      continue;
    } else {
      ll train = (A[i] * F[i] - x + F[i] - 1) / F[i];
      if(train > A[i] or train > K) {
        return false;
      } else {
        K -= train;
      }
    }
  }
  return true;
}

int main() {
  int N;
  ll K;
  std::cin >> N >> K;

  std::vector<ll> A(N), F(N);
  rep(i, N) {
    std::cin >> A[i];
  }
  rep(i, N) {
    std::cin >> F[i];
  }
  std::sort(A.begin(), A.end());
  std::sort(F.rbegin(), F.rend());

  ll l = -1;
  ll r = 0;
  rep(i, N) {
    r += A[i] * F[i];
  }

  while(r - l > 1) {
    ll c = (l + r) / 2;
    if(check(c, A, F, K)) {
      r = c;
    } else {
      l = c;
    }
  }

  std::cout << r << '\n';
}


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

int main()
{
  	double N, K, ans = 0.0;
  	cin >> N >> K;
  	for (int i = 1; i <= N; i++){
    	double score = i;
      	double prop = 1 / N;
      	while (score <= K - 1){
        	score *= 2;
          	prop *= 0.5;
        }
      	ans += prop;
    }
  	cout << setprecision(12) << ans << endl;
}



Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (N, X) = readLine()!!.split(" ").map { it.toLong() }
    val L = readLine()!!.split(" ").map { it.toLong() }
    val D = LongArray(N.toInt() +1)
    D[0] = 0

    var count = 1L
    (1..N.toInt()).forEach {
        D[it] = D[it - 1] + L[it - 1]
        if (D[it] <= X) {
            count++
        }
    }

    println(count)
}

Measured memory_bytes: 37900
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;

int main()
{
	int a,b;
	cin >> a >> b;
	
	int ans = 0;
	if (a > 12) {
		ans = b;
	}
	else if (a > 5) {
		ans = b / 2;
	}
	cout << ans << endl;
	return 0;

}


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

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s;
  std::cin >> s;
  std::cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << std::endl;
  return 0;
}


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

signed main(){
    int n,k,s,t;
    int ans;
    cin>>n>>k;
    t = n/k;
    if(k%2==0){
        s = (n+(k/2))/k;
        ans = s*s*s + t*t*t;
    }
    else{
        ans = t*t*t;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[],int b[],int c[],int d[],int p,int q,int m,int n){
  int sm=0;
  if(p!=m){
    if(d[p]+q>=n){
      sm+=f(a,b,c,d,p+1,q,m,n);
      for(c[p]++;c[p]<b[p]+1;c[p]++){
	q+=a[p];
	if(0){
	}else if(q>n){
	  break;
	}else if(q<n){
	  sm+=f(a,b,c,d,p+1,q,m,n);
	}else{
	  sm++;
	  break;
	}
      }
      c[p]=0;
    }
  }
  return sm;
}
int main(){
  int i;
  int a[7],b[7],c[7],d[8],z[10],m,n,o;
  memset(c,0,sizeof(c));
  while(cin>>m&&m){
    for(i=0;i<m;i++)
      cin>>a[i]>>b[i];
    d[m]=0;
    for(i=m-1;i>-1;i--)
      d[i]=d[i+1]+a[i]*b[i];
    cin>>o;
    for(i=0;i<o;i++){
      cin>>n;
      z[i]=f(a,b,c,d,0,0,m,n);
    }
    for(i=0;i<o;i++)
      cout<<z[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 868
def is753(n):
    if n % 10 != 3 and n % 10 != 5 and n % 10 !=7:
        return False
    exist3 = False
    exist5 = False
    exist7 = False
    a = str(n)
    for i in range (len(a)):
        x = n % 10
        if x == 3 :
            exist3 = True
        elif x == 5 :
            exist5 = True
        elif x == 7 :
            exist7 = True
        else :
            return False
        n = n // 10
    if exist3 and exist5 and exist7:
        return True
    else :
        return False

n = int(input())
a = len(str(n))
lst = [[3,5,7]]
tfs = [3,5,7]
for i in range(1,a):
    l = []
    for v in lst[i-1]:
        for t in tfs:
            l.append(int(str(v) + str(t)))
    lst.append(l)
s = 0
for l in lst:
    for v in l:
        if is753(v) and v <= n:
            s+=1
print(s)

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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	int x, a, b;
	while(cin >> x >> a >> b) {
		if(b - a <= 0) puts("delicious");
		else if(b - a <= x) puts("safe");
		else puts("dangerous");
	}
	return 0;
}


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

int main() {
  
  int A,B;
  cin >> A>>B;
  int a=1;
  int counter=0;

for(int i=0;i<999;i++){
  if(a>=B){break;}
  a+=A-1;
  counter++;



  }
    
  cout << counter<<endl;
}


Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>
#include "atcoder/all"
using namespace std;
using namespace atcoder;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int n,q;
    cin>>n>>q;
    dsu d(n);
    while(q--){
        int t,u,v;
        cin>>t>>u>>v;
        if(t)
            cout<<d.same(u,v)<<endl;
        else
            d.merge(u,v);
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3792
#include <iostream>
using namespace std;
int main(){
  int a,b,c=0,d;
  cin>>a>>b;
  for(int i=0;i<b;i++){
    cin>>d;
    c+=d;
  }
  if(a-c<0){
    cout <<"-1"<<endl;
  }else{
    cout << a-c<<endl;
  }
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(int argc, char* argv[])
{
	int N, M;
	int A[100];
	scanf("%d %d", &N, &M);

	for(int i=0; i<N; i++){
		scanf("%d", &A[i]);
	}

//	printf("%d %d %d\n", N, M, A[N-1]);

	int sum_A = 0;

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


	int count = 0;
	double standard = (double)sum_A / (4.0 * (double)M);

	for(int i=0; i<N; i++){
		if((double)A[i] >= standard ){
			count++;
		}
	}

//	printf("%d %lf\n", sum_A, standard);
	if(count >= M){
		printf("Yes\n");

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





Measured memory_bytes: 256
def powmod(b,r,mod)
  a = 1
  while r > 0
    if r%2 == 1
      a = a * b % mod
    end
    b = b * b % mod
    r /= 2
  end
  a
end
 
def invmod(f, mod)
  powmod(f, mod-2, mod)
end


Mod = 1000003
fs = [1]
(1...Mod).each{ |n|
  fs << (fs[-1] * n % Mod)
}
Q = gets.to_i
Q.times {
  x,d,n = gets.split.map &:to_i
  if d == 0
    p powmod(x, n, Mod)
    next
  end

  id = invmod(d, Mod)
  b = x * id % Mod
  if b+n-1 >= Mod
    p 0
    next
  end
  dn = powmod(d, n, Mod) 
  fact = fs[b+n-1]
  invf = invmod(fs[b-1], Mod)
  p dn * fact % Mod * invf % Mod
}



Measured memory_bytes: 12028
A=list(map(int,input().split()))
A.sort()
count=0
while(1):
    i=0
    j=0
    if(A[1]+2<=A[2]):
        A[1]+=2
        count+=1
        i=1
    if(A[0]+2<=A[2]):
        A[0]+=2
        count+=1
        j=1
    if(i==0 and j==0):    break
    
if(A[0]==A[1] and A[0]!=A[2]):    print(count+1) #(0,0,1)
elif(A[0]!=A[1]):    print(count+2) ##(0,1,1)
else:    print(count) #(0,0,0)

Measured memory_bytes: 3064
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#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(int 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 pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

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

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

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

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

    // input
    ll N, A, B;
    cin >> N >> A >> B;

    ll max_num = min(A, B);

    ll min_num;
    if(A+B <= N){
        min_num = 0;
    }else{
        min_num = A+B-N;
    }

    p2(max_num, min_num);
    
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = int(1e5);
int N;
ll a[MAX_N];
vector<ll> v;

void solve() {
    sort(v.begin(), v.end());
    ll ans[2][N];

    int center = 0;
    if (N % 2 == 0) center = N / 2 - 1;
    else center = N / 2;

    REP(k, 2) {
        bool is_small = k % 2 == 0;
        int small = 0, big = static_cast<int>(v.size() - 1);
        REP(i, N / 2 + 1) {
            if (is_small) {
                if (center + i < N) ans[k][center + i] = v[small++];
                if (i != 0 && center - i >= 0) ans[k][center - i] = v[small++];
            } else {
                if (center + i < N) ans[k][center + i] = v[big--];
                if (i != 0 && center - i >= 0) ans[k][center - i] = v[big--];
            }
            is_small = !is_small;
        }
    }
    ll ret = 0;
    REP(k, 2) {
        ll n = 0;
        REP(i, N - 1) n += abs(ans[k][i] - ans[k][i + 1]);
        ret = max(n, ret);
    }
    cout << ret << endl;
}

int main() {
    cin >> N;
    ll temp;
    REP(i, N) {
        cin >> temp;
        v.emplace_back(temp);
    }
    solve();
    return 0;
}

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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
     int A, B, C, D;
    cin >> A >> B >> C >> D;

    if(A + B == C + D)
        cout << "Balanced" << endl;
    else 
        cout << (A + B > C + D ? "Left" : "Right") << endl;
        
    return 0;
}











Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(RALL(x))
#define SUM(x) accumulate(ALL(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

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

  cout << fixed << setprecision(10);
  cout << (double)dup(n,2)/n << endl;
}

Measured memory_bytes: 256
//Waqt Ha Badal Jayega//

#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ld long double
using namespace std;


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k <= a)
	{
		cout << k << "\n";
	}
	else if (k - a <= b)
	{
		cout << a << "\n";
	}
	else
	{
		cout << a - (k - a - b) << "\n";
	}
	return 0;

}

Measured memory_bytes: 3648
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	c := stdin.Read()
	alphabets := strings.Split("abcdefghijklmnopqrstuvwxyz", "")
	for i := 0; i < len(alphabets); i++ {
		if alphabets[i] == c {
			stdout.Println(alphabets[i+1])
			return
		}
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<size_t I,class H,class...T>struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template<class H,class...T>struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class...T>istream&operator>>(istream&i,tuple<T...>&t){t=TupleReaderWriter<sizeof...(T),T...>::r(i);return i;}
template<class...T>ostream&operator<<(ostream&o,tuple<T...>&t){string delim=" ";TupleReaderWriter<sizeof...(T)-1,T...>::w(o,t,delim);return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int M;
    cin >> M;
    i64 S = 0, L = 0;
    for(int i = 0; i < M; i++) {
        i64 d, c;
        cin >> d >> c;
        S += d * c;
        L += c;
    }
    S = (S - 1) / 9;
    cout << ( S + L - 1 ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  for(int i = 10; i <= n; i *= 10) {
    if(i == n) {
      std::cout << 10;
      return 0;
    }
  }
  int sum = 0;
  while(0 < n) {
    sum += n % 10;
    n /= 10;
  }
  std::cout << sum;
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int n = sc.nextInt();
		int x = sc.nextInt();
		int COUNT = 0;
		
		if(n == 0 && x == 0)
				break;

		for(int a = 1; a < n+1; a++)
			for(int b = a+1; b < n+1; b++)
				for(int c = b+1; c < n+1; c++)
					if (a+b+c == x)
						COUNT++;

		System.out.println(COUNT);
		
		}
	}
}



Measured memory_bytes: 26648
//Author : Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)
#define REPV(i,a,b) for(int i = a; i>= b; --i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
#define INF 100000
#define ff first
#define ss second
const int M=1e9+7;

void solve()
{
	int n;
	cin>>n;
	int A[n];
	REP(i,0,n)
	{
		cin>>A[i];
	}
	sort(A, A+n);
	int ans = 0;
	REP(i,0,n)
	{
		REP(j,i+1,n)
		{
			REP(k,j+1,n)
			{
				if(A[i] + A[j] > A[k] && (A[i] != A[j]) && (A[j] != A[k]) && (A[i] != A[k]))
				++ans;
			}
		}
	}
	cout<<ans<<"\n";
}

int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  
  	solve();
  
  return 0;
}


Measured memory_bytes: 3644