akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] array = new int[N];

        for(int i = 0; i < N; i++){
            array[i] = scan.nextInt();
        }

        int flag = N, count = 0;
        while(flag != 0){
            flag--;
            for(int j = N-1; j >= 1; j--){
                if(array[j] < array[j-1]){
                    int temp = array[j];
                    array[j] = array[j-1];
                    array[j-1] = temp;
                    count++;
                }
            }
        }
        for(int i= 0; i < array.length; i++){
        System.out.print(array[i]);
        if(i < array.length-1){
            System.out.print(" ");
        } else {
            System.out.println();
            System.out.println(count);
        }

        }
    }
}


Measured memory_bytes: 26308
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;
const int inf = 1e17+21;



int32_t main(){
    FAST;

   int n;   cin >> n;
   int h[n+2];
   for(int x=1;x<=n;x++)    cin >> h[x];

   int dp[n+2] = {inf};

    dp[1] = 0 , dp[2] = abs(h[2] - h[1]);

    for(int x=3;x<=n;x++){

        dp[x] = min(dp[x-1] + abs(h[x] - h[x-1]) , dp[x-2] + abs(h[x] - h[x-2]));

    }

     cout << dp[n];



    return 0;
}


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

const int MOD = (int)1e9+7;

int dfs(vector<vector<bool>> &graph,vector<bool> &flag,int v,int N,int &ans){
  bool check=true;
  for(int i=0;i<N;i++)  if(!flag.at(i)) check=false;
  if(check){
    ans++;
    return 0;
  }

  for(int i=0;i<N;i++){
    if(graph.at(v).at(i)==true && flag.at(i)==false){
      flag.at(i)=true;
      dfs(graph,flag,i,N,ans);
      flag.at(i)=false;
    }
  }

  return ans;
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  for(int i=0;i<M;i++){
    cin >> a.at(i) >> b.at(i);
    a.at(i)--;
    b.at(i)--;
  }

  vector<vector<bool>>  graph(N,vector<bool>(N,false));
  for(int i=0;i<M;i++){
    graph.at(a.at(i)).at(b.at(i))=true;
    graph.at(b.at(i)).at(a.at(i))=true;
  }

  vector<bool> flag(N,false);
  flag.at(0)=true;
  int ans=0;

  cout << dfs(graph,flag,0,N,ans) << endl;

  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> count(N);
    for (int i = 1; i < N; i++) {
        int A;
        cin >> A;
        count.at(A - 1)++;
    }

    for (int i = 0; i < N; i++) {
        cout << count.at(i)<< endl;
    }

    return 0;
}

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

using namespace std;

const int max_n = 2022, inf = 1000111222;

int n, sz[max_n], dpl[max_n], dpr[max_n], res[max_n];
char s[max_n];
vector<int> g[max_n];

int get_l(int l1, int r1, int l2, int r2) {
    if (l1 > l2) {
        swap(l1, l2);
        swap(r1, r2);
    }
    if (l1 % 2 == l2 % 2) {
        if (l2 <= r1) {
            return 0;
        }
        return l2 - r1;
    } else {
        if (l2 <= r1) {
            return 1;
        }
        return l2 - r1;
    }
}

int get_r(int l1, int r1, int l2, int r2) {
    return r1 + r2;
}

void get_dp(int v, int p) {
    sz[v] = s[v] - '0';
    res[v] = 0;
    dpl[v] = 0;
    dpr[v] = 0;
    for (int to : g[v]) {
        if (to == p) {
            continue;
        }
        get_dp(to, v);
        sz[v] += sz[to];
        res[v] += res[to] + sz[to];

        int nl = get_l(dpl[v], dpr[v], dpl[to] + sz[to], dpr[to] + sz[to]);
        int nr = get_r(dpl[v], dpr[v], dpl[to] + sz[to], dpr[to] + sz[to]);
        dpl[v] = nl;
        dpr[v] = nr;
    }
    //cout << v << ": [" << dpl[v] << " " << dpr[v] << "], res = " << res[v] << ", sz = " << sz[v] << endl;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%s", &n, s);
    for (int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        --u;
        --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans = inf;
    for (int i = 0; i < n; ++i) {
        get_dp(i, -1);
        //cout << i << ": " << dpl[i] << " " << dpr[i] << " " << res[i] << endl;
        if (dpl[i] == 0) {
            ans = min(ans, res[i] / 2);
        }
    }
    if (ans == inf) {
        ans = -1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};

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

	vector<int> one_case;
	vector<int>x(N), y(N);
	rep(i, N) {
		cin >> x[i] >> y[i];
	}
	double ans=0;
	double tmp;
	for (int i = 0; i < N; i++) { // one_case = {0,1,2,3,...n-1} とする
		one_case.emplace_back(i);
	}
	
	do {
		for (int i = 0; i < N-1; i++) {
			
			tmp = pow((x[one_case[i]] - x[one_case[i+1]]),2)+ pow(y[one_case[i]] - y[one_case[i+1]],2);
			ans += pow(tmp, 0.5);
		}
		
		
	} while (next_permutation(one_case.begin(), one_case.end()));
	ll wari=1;
	for (int i = 1; i <= N; i++) {
		wari *= i;
	}
	ans=ans/wari;
	cout << fixed << setprecision(10) << ans;
}


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

typedef long long ll;
ll n, m, ans = 1, c[100035][35];
ll M = 1e9 + 7;
int main()
{
	ll i, j;
	cin >> n >> m;
	for (i = 0; i <= n + 33; i++) {
		c[i][0] = 1;
		for (j = 1; j <= min(i, 33LL); j++) {
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % M;
		}
	}
	for (i = 2; i <= m; i++) {
		for (j = 0; m % i == 0; m /= i, j++);
		ans = ans * c[n + j - 1][j] % M;
	}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27648
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
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);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn


int main()
{
	IO;
	int n{},a{},b{},cn{},cnb{};
	cin>>n>>a>>b;
	string s;
	cin>>s;
	For(i,0,s.size())
	{
		if(s[i]=='a'){
		 	if(cn<a+b)cout<<"Yes\n",cn+=1;
		 	else cout<<"No\n";
		}
		else if(s[i]=='b'){
			if(cn<a+b && cnb<b){
				cnb+=1,cn+=1;
				cout<<"Yes\n";
			}else
			cout<<"No\n";
		}
		else cout<<"No\n";
	}
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 3680
n, t, h, l = gets.chomp.split.map(&:to_i)
arr = []
n.times{arr << gets.chomp.split.map(&:to_i)}
turn, bank, flag = 0, 0, false
while true
    if arr[turn] == [0, 0]
        flag = true
    else
        if arr[turn][0] > 0
            arr[turn][0] -= 1
            bank += 10
            t += 1
            flag = true if t > l
        else
            arr[turn][1] -= 1
            bank += 100
        end
        if bank >= 90
            rest = (bank - 90) / 10
            if rest > t
                flag = true
            else
                t -= rest
                arr[turn][0] += rest
                bank = 0
            end
        end
    end
    break if flag
    turn = (turn + 1) % n
end
puts turn + 1


Measured memory_bytes: 6884
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 600000;
int n,m,mtr[800][800];
bitset<800> f,g;
int col[N]; bool vis[N];
void GG() {puts("-1"); exit(0);}
void dfs(int u, int c, int &cnt, int &sum) {
	vis[u]=1; col[u]=c; cnt+=c; sum++;
	rep(i,1,n) if (mtr[u][i]&&!vis[i]) dfs(i,c^1,cnt,sum);
	else if (mtr[u][i]&&col[u]==col[i]) GG();
}
int main() {
	read(n); read(m); int x,y;
	rep(i,1,n) rep(j,1,n) if (i!=j) mtr[i][j]=1;
	rep(i,1,m) read(x),read(y),mtr[x][y]=mtr[y][x]=0;
	f[0]=1;
	rep(i,1,n) if (!vis[i]) {
		int a=0,b=0; dfs(i,1,a,b);
		g=f; f=(g<<a)|(g<<(b-a));
	}
	int res=1e9;
	rep(i,0,n) if (f[i]) res=min(res,i*(i-1)/2+(n-i)*(n-i-1)/2);
	cout<<res;
	return 0;
}


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

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	for (int i = 0; i < s.size(); i++) {
		s[i] = 'A' + (s[i] + n - 'A') % 26;
	}
	
	cout << s << endl;
}

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

int main() {
    while (true) {
        int n, q;
        cin >> n >> q;
        if ((n | q) == 0) {
            break;
        }
        map<int, pair<int, string> > eras;
        vector<int> firstYears;
        for (int i = 0; i < n; i++) {
            string eraName;
            int eraBasedYear, westernYear;
            cin >> eraName >> eraBasedYear >> westernYear;
            int firstYear = westernYear - eraBasedYear + 1;
            eras.insert(make_pair(firstYear, make_pair(westernYear, eraName)));
            firstYears.push_back(firstYear);
        }
        sort(firstYears.begin(), firstYears.end());
        for (int i = 0; i < q; i++) {
            int year;
            cin >> year;
            int firstYear = -1;
            for (int i = n - 1; i >= 0; i--) {
                if (firstYears[i] <= year) {
                    firstYear = firstYears[i];
                    break;
                }
            }
            if (firstYear < 0 || eras[firstYear].first < year) {
                cout << "Unknown" << endl;
            } else {
                cout << eras[firstYear].second << " " << year - firstYear + 1 << endl;
            }
        }
    }
}

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

int main(){
  int n,x;
  cin >> n >> x;
  map<int,int>suki;
  int m;
  for(int i=0;i<n;i++){
    cin >> m;
    int s;
    for(int j=0;j<m;j++){
      cin >> s;
      suki[s]++;
    }
  }
  int ans=0;
  for(auto i:suki){
    if(i.second==n)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
   /*Code*/
   int a, b;
   
   cin>>a>>b;
   
   bool no=false;
   if(b%2) no =false;
   else{
      no= (b>=a*2 and b<=a*4);
   }
 
   
   cout<<(no? "Yes" :"No" )<<endl ;
   return 0;
}
    

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

ll n;
ll a[100100];
vl adj[100100];

bool ok = true;

ll dfs(ll i, ll p = -1) {
	if (sz(adj[i]) == 1) {
		if (p != -1) return a[i];
		assert(false);	
	} else {
		ll sum = 0;
		for (ll j: adj[i]) if (j != p) {
			ll cur = dfs(j,i);
			if (cur > a[i]) ok = false;
			sum += cur;
		}
		ll res = 2*a[i]-sum;
		if (res > a[i]) ok = false;
		if (res < 0) ok = false;
		return res;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	FOR(i,0,n) cin >> a[i];
	FOR(i,1,n) {
		ll u, v; cin >> u >> v;
		u--, v--;
		adj[u].pb(v), adj[v].pb(u);
	}
	
	if (n == 2) {
		ok = a[0] == a[1];
	} else {
		FOR(i,0,n) if (sz(adj[i]) > 1) {
			ll res = dfs(i);
			if (res) ok = false;
			break;
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
}



Measured memory_bytes: 10496
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
 
#define FOR(idx, begin, end) for(int idx = (begin); idx < (end); ++idx)
#define DMP(x) cerr << #x << ": " << x << "\n"
 
using namespace std;
typedef long long lint;
const int MOD = 1000000007;
 
int main() {
 
	cin.tie(0);
 
	int N, M;
	cin >> N >> M;
 
	vector<int> visited(N, 0);
 
	vector<int> a(M), b(M);
	FOR(i, 0, M) cin >> a[i] >> b[i];
 
	vector<vector<int>> path(N, vector<int>(N, 0));
	FOR(i, 0, M) {
		path[a[i] - 1][b[i] - 1] = 1;
		path[b[i] - 1][a[i] - 1] = 1;
	}
 
	int ans = 0;
 
	stack<pair<int, vector<int>>> node;
	node.push({0, visited});
 
	while (!node.empty()) {
		
		auto now = node.top();
		now.second[now.first] = 1;
		node.pop();
 
		FOR(i, 0, N) {
			if (now.second[i] == 0 && path[now.first][i] == 1) {
 
				node.push({i, now.second});
			}
		}
 
		FOR(i, 0, N) {
 
			if (now.second[i] == 0) break;
			if (i == N - 1) ans++;
		}
	
	}
 
	cout << ans;
 
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanInit()

	n := nextInt()
	l := make([]int, n)

	sum := 0
	for i := 0; i < n; i++ {
		l[i] = nextInt()
		sum += l[i]
	}
	if sum%10 != 0 {
		fmt.Println(sum)
		return
	}

	sort.Ints(l)
	for _, v := range l {
		if v%10 != 0 {
			fmt.Println(sum - v)
			return
		}
	}

	fmt.Println(0)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int min(int a,int b){
  if(a < b){
    return a;
  }else{
    return b;
  }
}

int main(){
  int N,A,B;
  scanf("%d%d%d",&N,&A,&B);
  int P[N];
  for(int i = 0;i < N;i++){
    scanf("%d",&P[i]);
  }
  int n1,n2,n3;
  n1 = 0;
  n2 = 0;
  n3 = 0;

  for(int i = 0;i < N;i++){
    if(P[i] <= A){
      n1++;
    }else if(P[i] <= B){
      n2++;
    }else{
      n3++;
    }
  }
  printf("%d\n",min(n1,min(n2,n3)));
  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;

	void solve() {
		int n = readNum();
		int[] ia = readNums();
		int min = _intMax;
		int max = _intMin;
		for (int i = 0; i < n; i++) {
			int v = ia[i];
			min = min(min, v);
			max = max(max, v);
		}
		pln(max - min);
	}

	// -----------------------------------------------------
	// 2018/04/26 r2
	// -----------------------------------------------------
	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	long abs(long a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	long max(long a, long b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	long min(long a, long b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	long readLong() {
		String line = readLine();
		return plong(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = pint(flds[i]);
		return nums;
	}

	long[] readLongs() {
		String[] flds = readFlds();
		long[] nums = new long[flds.length];
		for (int i = 0; i < flds.length; i++)
			nums[i] = plong(flds[i]);
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	void pln(int[] ia) {
		for (int i = 0; i < ia.length; i++)
			pln(ia[i]);
	}

	void pln(long[] la) {
		for (int i = 0; i < la.length; i++)
			pln(la[i]);
	}

	static BufferedReader _in;
	static PrintWriter _out;
	static boolean _bElapsed = false;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (_bElapsed)
			System.err.println((end - start) + "ms");
	}
}


Measured memory_bytes: 21204
#include<iostream>
#include<string>

int main(){
int H,W;
while(true){
std::cin>>H>>W;
if(H==0&&W==0)break;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
std::cout<<"#";
}
std::cout<<std::endl;
}
std::cout<<std::endl;
}
return 0;
}


Measured memory_bytes: 3080
package main

import (
	"fmt"
)

func main() {
	var w int
	var a int
	var b int
	fmt.Scan(&w, &a, &b)
	if a+w < b {
		fmt.Println(b-a-w)
	} else if b+w < a {
		fmt.Println(a-b-w)
	} else {
		fmt.Println(0)
	}
}

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

int main()
{
    int a,b,num;
    scanf("%d %d",&a,&b);
    if(2*b<a)
    {
        printf("%d\n",(a-2*b));
    }
    else
    {
        printf("0\n");
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[100005];
int a[100005];
const int inf=1000000005;
int main(){
	int n;cin>>n;
	fill(dp,dp+n+2,inf);
	dp[0]=-inf;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		int jb=lower_bound(dp,dp+n+2,a[i])-dp;
		dp[jb]=a[i];
	}
	for(int i=0;i<=n+1;i++)if(dp[i]==inf){
		cout<<i-1<<endl;
		break;
	}
	return 0;
}


Measured memory_bytes: 3888
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
A, B, C, D = [], [], [], []
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
    C.append(c)
    D.append(d)
res = 0
for p in combinations_with_replacement(list(range(1, M + 1)), N):
    cur = 0
    for a, b, c, d in zip(A, B, C, D):
        if p[b] - p[a] == c:
            cur += d
    res = max(res, cur)
print(res)

Measured memory_bytes: 9184
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

bool isMAX(string S, int MAX) {
    if (SIZE(S) != MAX) return false;
    REP(i, MAX) {
        char ch = 'a' + (MAX - i - 1);
        if (S[i] != ch) return false;
    }
    return true;
}

string solve(string S, int MAX) {
    if (isMAX(S, MAX)) {
        return "-1";
    }
    else if (SIZE(S) != MAX) {
        set<char> seen(ALL(S));
        REP(i, MAX) {
            auto ch = 'a' + i;
            if (!seen.count(ch)) {
                S += ch;
                return S;
            }
        }
    }
    else if (S[MAX-2] < S[MAX-1]) {
        string ans;
        REP(i, MAX-2) ans += S[i];
        ans += S[MAX-1];
        return ans;
    } else {
        char prev = S[MAX-1];
        for(int i = MAX-2; i >= 0; --i) {
            char ch = S[i];
            if (ch > prev) {
                prev = ch;
            }
            else {
                string ans;
                REP(j, i) ans += S[j];

                char add = S[i+1];
                FOR(j, i+2, MAX) {
                    if (S[j] > S[i] && S[j] < add) add = S[j];
                }
                ans += add;
                return ans;
            }
        }
    }
    
}

int main(void)
{
    cin.sync_with_stdio(false);

    // vector<string> check {
    //     "a", "ab", "abc", "ac", "acb",
    //     "b", "ba", "bac", "bc", "bca",
    //     "c", "ca", "cab", "cb", "cba",
    // };
    // REP(i, SIZE(check)-1) {
    //     auto ans = solve(check[i], 3);
    //     auto expected = check[i+1];
    //     if (ans != expected) {
    //         cout << "error! query = " << check[i] << ", ans = " << ans << ", expected = " << expected << endl;
    //     }
    // }

    string S;
    cin >> S;
    cout << solve(S, 26) << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

//Mo's algorithum

int main() {
    int N,Q; scanf("%d %d",&N,&Q);
    vector<int> C(N);
    rep(i,N) scanf("%d",&C[i]);
    vector<int> L(Q),R(Q),idx(Q);
    rep(i,Q) {
        int l,r; scanf("%d %d",&l,&r);
        --l;
        L[i] = l; R[i] = r; idx[i] = i;
    }

    int sq = sqrt(N);
    sort(idx.begin(),idx.end(),[&](int a,int b){
        return L[a]/sq ==  L[b]/sq ? R[a] < R[b] : L[a] < L[b];
    });

    vector<int> color(N + 1,0);
    vector<int> ans(Q);
    int ret = 0;
    auto add = [&](int i){color[C[i]]++; if (color[C[i]] == 1) ++ret;};
    auto del = [&](int i){color[C[i]]--; if (color[C[i]] == 0) --ret;};
    
    int l = 0,r = 0; //[l,r)
    for (int i:idx) {
        while (l > L[i]) --l,add(l);
        while (r < R[i]) add(r),++r;
        while (l < L[i]) del(l),++l;
        while (r > R[i]) --r,del(r);
        ans[i] = ret;
    }
    rep(i,Q) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 15452
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

//FUNCTION
void solve(void)
{
  int K;cin>>K;
  string str;cin>>str;
  if(str.size() <= K)
  {
    cout<<str<<endl;
  }
  else
  {
    cout<<str.substr(0,K)<<"..."<<endl;
  }
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int k,s; cin>>k>>s;
	int cnt=0;
	rep(i,0,k+1){
		rep(j,0,k+1){
			int z=s-i-j;
			if(z<0 || z>k) continue;
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

#define N_MAX 200

/* 正方形の位置を記録する構造体 */
typedef struct {
  int x;
  int y;
} Square;

int main(void) {
  int N;
  
 
  
  while(scanf("%d", &N) != EOF) { // 作品の制作手数を読み込む
    /* x,y座標で最大と最小を記録しておく */
    int max_x = 0;
    int min_x = 0;
    int max_y = 0;
    int min_y = 0;
    
    int i;

    /* 一番最初の正方形を(0,0)として，付け足してゆく正方形の座標を測る */
    Square sqrs[N_MAX];
    sqrs[0].x = 0;
    sqrs[0].y = 0;
    
    if (N == 0)
      break; // Nが0だったら終了

    for (i=1; i<N; i++) { // 制作手順を一行ずつ読んで，正方形を付け足してゆく
      int x, y; // 新しく付け足す正方形の座標
      int n, d; // 新しい正方形を付け足すすでにある正方形の番号と，正方形付け足す向き
      scanf("%d %d", &n, &d); // 手順を読み込む

      x = sqrs[n].x; // 付け足す元の正方形の座標を読み込んでおく
      y = sqrs[n].y;
      /* 指定された向きより付けたす正方形の座標を決める */
      switch(d) {
      case 0: // 左側
	x--;
	break;
      case 1: // 下側
	y--;
	break;
      case 2: // 右側
	x++;
	break;
      case 3: // 上川
	y++;
	break;
      }

      /* 新しく付け足す正方形の座標を代入*/
      sqrs[i].x = x;
      sqrs[i].y = y;

      /* 新しく付け足す正方形の座標が最大，最小であれば，更新 */
      if (x > max_x) {
	max_x = x;
      } else if (x < min_x) {
	min_x = x;
      }
      if (y > max_y) {
	max_y = y;
      } else if (y < min_y) {
	min_y = y;
      }

    }

    /* 作品の幅と高さは，x,y座標それぞれぞれの最大と最小の差+1（正方形の中心を座標としてとっているため） */
    printf("%d %d\n", max_x-min_x+1, max_y-min_y+1);
  }
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int n;
    while(cin>>n, n) {
        string ans = "";
        while(n != 0) {
            int k = n%(-10);
            n /= -10;
            if(k < 0) {
                k += 10;
                n++;
            }
            ans += string(1, '0'+k);
        }
        reverse(ans.begin(), ans.end());
        cout<<ans<<endl;
    }
}

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

int main() {
        int n; cin >> n;
        string a, b, c; cin >> a >> b >> c;
        int ans = 0;
        for(int i = 1; i <= n; i++) {
                if(a[i - 1] == b[i - 1] && a[i - 1] == c[i - 1]) continue;
                if(a[i - 1] == b[i - 1] || a[i - 1] == c[i - 1] || c[i - 1] == b[i - 1]) ++ans;
                else ans += 2;
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

int  main()
{
	string a,b,c;cin >> a >> b >> c;
	if (a.back() == b.front() && b.back() == c.front())
		cout << "YES\n";
	else
		cout << "NO\n";
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll h,n;
    cin>>h>>n;
    ve <ll> arr(n);
    rep (i,0,n)
    {
        cin>>arr[i];
    }
    sort (all(arr));
    rev(i,n,0)
    {
        h-=arr[i];
    }
    if (h<=0)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
}

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int diff = 999;

    for(int i = 0; i < s.size() - 2; ++i) {
        int x = stoi(s.substr(i, 3));
        diff = min(diff, abs(x - 753));
    }
    cout << diff << endl;
}

Measured memory_bytes: 256
def ma(li):
    # ループごとにifで大小比較
    max_num = 0
    for i in li:
        if max_num < i:
            max_num = i
    return max_num

def appen(li,yousa):
    li.append(yousa)
    return li
    
def main():
    res=0
    n,m=map(int,input().split())
    h=list(map(int,input().split()))
    
    a=[list(map(int,input().split())) for i in range(m)]
    f=[]
    for i in range(n):
        f.append([0])
    for i in a:
        f[i[0]-1].append(h[i[1]-1])
        f[i[1]-1].append(h[i[0]-1])
    p=-1
    for i in f:
        p+=1
        if len(i)==1:
            res+=1
        elif ma(i)<h[p]:
            res+=1
        else:
            continue

    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 44120
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jun 28 20:59:50 JST 2020
 **/

std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

Int D;
std::vector<Int> c;
std::vector<std::vector<Int>> s;
constexpr Int K = 26;

Int calc_score(const std::vector<Int>& a) {
    assert(a.size() == D);
    Int ret = 0;
    Int sum = std::accumulate(c.begin(), c.end(), 0LL);
    Int cur_minus = 0;
    std::vector<Int> last(K, -1);
    REP(d, D) {
        cur_minus += sum - c[a[d]] * (d - last[a[d]]);
        ret += s[d][a[d]] - cur_minus;
        last[a[d]] = d;
    }
    return ret;
}

std::vector<Int> ans(D);
Int best_score;
void hill_climb() {
    REP(t, 10000) {
        std::vector<Int> nxt = ans;
        // change
        if (t % 2) {
            Int idx = rnd() % (D - 1);
            std::swap(nxt[idx], nxt[idx + 1]);
        } else {
            Int idx = rnd() % D;
            nxt[idx] = rnd() % K;
        }

        Int nxt_score = calc_score(nxt);
        if (nxt_score >= best_score) {
            dump(t, best_score, nxt_score);
            best_score = nxt_score;
            ans = std::move(nxt);
        }
    }
}

signed main() {
    // input
    std::cin >> D;
    c.resize(K);
    s = make_vec<Int>(D, K, 0);
    REP(i, K) std::cin >> c[i];
    REP(i, D) REP(j, K) std::cin >> s[i][j];

    // hoge
    ans.resize(D);
    REP(i, D) ans[i] = i % K;
    best_score = calc_score(ans);
    hill_climb();
    // dump(calc_score(ans));
    // REP(i, D) { ans[i] = std::max_element(s[i].begin(), s[i].end()) - s[i].begin(); }
    // dump(calc_score(ans));

    // output
    for (Int x : ans) std::cout << x + 1 << "\n";
    std::cout << std::endl;
}


Measured memory_bytes: 3740
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author rizhiy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int x = in.nextInt();
            int answ = 0;
            for (int i = 0; i <= a; i++) {
                for (int j = 0; j <= b; j++) {
                    for (int k = 0; k <= c; k++) {
                        if (i * 500 + j * 100 + k * 50 == x) {
                            answ++;
                        }
                    }
                }
            }
            out.println(answ);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int N, M;
    std::cin >> N >> M;
    if (N == 1) {
        std::cout << 1 << std::endl;
        return 0;
    }
    std::vector<int> as(M);
    for (int i = 0; i < M; i++) {
        std::cin >> as.at(i);
    }
    bint p_i = 1;
    bint p_i1 = 1;
    bint p_i2;
    for (int i = 0; i < N - 1; i++) {
        p_i2 = ((std::binary_search(as.begin(), as.end(), i) ? 0 : p_i)
            + (std::binary_search(as.begin(), as.end(), i + 1) ? 0 : p_i1)) % 1000000007;
        p_i = p_i1;
        p_i1 = p_i2;

    }
    std::cout << p_i2 << std::endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A + B > C + D) {
        cout << "Left" << endl;
        return 0;
    } else if(A + B == C + D) {
        cout << "Balanced" << endl;
        return 0;
    }
    cout << "Right" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
//AOJ1020
//10 A E C ->0.12537479
int n,c;
char s,t,b;
double p,p1,nn;
int d1[4]={0,1,0,-1},d2[4]={1,0,-1,0};
char map[3][3]={{'A','B','C'},{'D','E','F'},{'G','H','I'}};
double df[10][16];//df[i][j]=i番の部屋にバッテリーjでいたときの確率
void dfs(int y,int x,int n1){
    double p1;
	int st=y*3+x;
	if(n1==0){
        if(map[y][x]==t){
			p+=pow(0.25,nn);
			c++;
		}
        return;
    }else{
		if(df[st][n1]>=0){
			p+=df[st][n1];
			c++;
			return;
		}else{
		    for(int i=0;i<4;i++){
				int my=y+d1[i],mx=x+d2[i];
				if(0<=my&&my<=2&&0<=mx&&mx<=2){//外壁にはぶつからない
					if(map[my][mx]==b){//倉庫にぶつかる
						p1=p;
						dfs(y,x,n1-1);
						df[st][n1-1]=p-p1;
					}else{//普通に進む
						p1=p;
						dfs(my,mx,n1-1);
						df[my*3+mx][n1-1]=p-p1;
					}
				}else{//外壁にぶつかる
					p1=p;
					dfs(y,x,n1-1);
					df[st][n1-1]=p-p1;
				}
		    }
		}
	}
    return;
}

int main(){
    while(1){
		int y1,x1;
        p=0;c=0;
        cin>>n;
        nn=(double)n;
        if(n==0)break;
        for(int i=0;i<10;i++){
            for(int j=0;j<16;j++){
                df[i][j]=-1;
            }
        }
		cin>>s>>t>>b;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(map[i][j]==s){
					y1=i;x1=j;
				}
			}
		}
        dfs(y1,x1,n);
        printf("%f\n",p);
    }
    return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;

int N;
vector<string> S;

int op(int a, char op, int b) {
    if (op == '+') return a + b;
    if (op == '-') return a - b;
    if (op == '*') return a * b;
    return a / b;
}

pair<int, char> parse_line(string s) {
    int depth = 0;
    while (s[depth] == '.') ++depth;
    return make_pair(depth, s.back());
}

pair<int, int> calc(int idx, int depth = 0) {
    auto pr = parse_line(S[idx++]);
    assert(pr.first == depth);
    char ch = pr.second;
    if (isdigit(ch)) return make_pair((int)(ch - '0'), idx);

    pr = calc(idx, depth+1);
    int val = pr.first;
    idx = pr.second;
    while (idx < N) {
        auto lookahead = parse_line(S[idx]);
        if (lookahead.first <= depth) break;
        auto tmp = calc(idx, depth+1);
        val = op(val, ch, tmp.first);
        idx = tmp.second;
    }

    return make_pair(val, idx);
}

int main(void) {
    while (true) {
        cin >> N;
        if (N == 0) break;
        S.resize(N);
        for (int i = 0; i < N; ++i) cin >> S[i];
        cout << calc(0).first << endl;
    }
    return 0;
}



Measured memory_bytes: 3172
module Main where
-- import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Data.Functor
import Control.Monad

rollData :: [(Int, [[(Int, Int)]])]
rollData =
        [
            (0, []),                                -- e
            (3,[
                [(0, 2), (2, 5), (3, 0), (5, 3)],      -- x
                [(0, 4), (1, 0), (4, 5), (5, 1)],      -- y
                [(1, 3), (2, 1), (3, 4), (4, 2)]]),    -- z
            (2,[
                [(0, 3), (1, 5), (2, 1), (3, 4), (4, 0), (5, 2)],  -- d1
                [(0, 1), (1, 3), (2, 5), (3, 0), (4, 2), (5, 4)],  -- d2
                [(0, 2), (1, 0), (2, 1), (3, 4), (4, 5), (5, 3)],  -- d3
                [(0, 4), (1, 3), (2, 0), (3, 5), (4, 2), (5, 1)]]), -- d4
            (1,[
                [(0, 1), (1, 0), (2, 3), (3, 3), (4, 5), (5, 4)],  -- p1 
                [(0, 2), (1, 4), (2, 0), (3, 5), (4, 1), (5, 3)],  -- p2 
                [(0, 4), (1, 5), (2, 3), (3, 2), (4, 0), (5, 1)],  -- p3 
                [(0, 3), (1, 4), (2, 5), (3, 0), (4, 1), (5, 2)],  -- p4 
                [(0, 5), (1, 2), (2, 1), (3, 4), (4, 3), (5, 0)],  -- p5 
                [(0, 5), (1, 3), (2, 4), (3, 1), (4, 2), (5, 0)]])  -- p6 
        ]

solve :: [[Int]] -> String
solve l = if any (\[x, y] -> eq x y) (comb l 2) then "No" else "Yes" 

eq :: [Int] -> [Int] -> Bool
eq d1 d2 = -- trace ("tr0 d1:"++show d1++" d2:"++show d2) $
            any (\(n, rs) -> checkRolls n rs) rollData where
    checkRolls 0 [] = d1 == d2
    checkRolls _ [] = False
    checkRolls n (m:ms) = -- trace ("tr1 n:"++show n++" m:"++show m++" ms:"++show ms) $ 
                          if checkRoll n m dice then True else checkRolls n ms where
        checkRoll 0 _ _ = False
        checkRoll n m d = -- trace ("tr2 n:"++show n++" m:"++show m++" d:"++show d++" r:"++show rolled) $ 
                          if checkFaces rolled then True else checkRoll (n-1) m rolled where
            checkFaces d = iter [0..5] d1 where
                iter [] [] = True
                iter (i:xs) (j:ys) 
                    | d!i == j = iter xs ys
                    | otherwise = False
            rolled = roll [] m where
                roll ac [] = d // ac
                roll ac ((i, j):xs) = roll ((i, d!j):ac) xs
        dice = listArray (0, 5) d2

comb :: [a] -> Int-> [[a]]
comb _ 0 = [[]]
comb [] _ = []
comb (x:xs) r = map (x:) (comb xs (r-1)) ++ comb xs r 

readLine:: IO [Int]
readLine = map read . words <$> getLine

main :: IO() 
main = do
    n  <- readLn
    l <- replicateM n readLine
--    print l
    putStrLn (solve l)



Measured memory_bytes: 4468
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n;
	double num[10000];
	double ans;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num[i];
	}
	sort(num,num+n);
	ans=num[0];
	for(int i=1;i<n;i++){
		ans+=num[i];
		ans/=2.0;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256