akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <tuple>
#include <cassert>
using namespace std;
using int64 = long long int;

struct UnionFind {
    vector<int> par, node, anc, color;
    UnionFind(int n) : node(n, 1), anc(n), color(n) {
        for(int i=0; i<n; i++) par.push_back(i);
    }
    int find(int k) { return par[k] == k ? k : find(par[k]); }
    bool same(int u, int v) { return find(u) == find(v); }
    bool unite(int u, int v) {
        if(same(u, v)) return false;
        u = find(u), v = find(v);
        if(node[u] > node[v]) {
            par[v] = u;
        }
        else if(node[u] < node[v]) {
            par[u] = v;
        }
        else {
            par[u] = v; node[v]++;
        }
        return true;
    }
};

int main() {
    int N, Q; scanf("%d%d", &N, &Q);
    vector< vector< tuple<int, int, int> > > G(N);
    for(int i=0; i<N-1; i++) {
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
        a--; b--; c--;
        G[a].emplace_back(b, c, d);
        G[b].emplace_back(a, c, d);
    }

    vector<int64> ans(Q), neg(Q);
    vector< vector< tuple<int, int, int, int> > > info(N), tmp(N);
    for(int i=0; i<Q; i++) {
        int x, y, u, v; scanf("%d%d%d%d", &x, &y, &u, &v);
        x--; u--; v--;
        info[u].emplace_back(x, y, i, v);
        info[v].emplace_back(x, y, i, u);
    }

    UnionFind uf(N);
    function<void(int, int)> find_lca = [&](int cur, int par) {
        uf.anc[cur] = cur;
        for(auto e : G[cur]) {
            int to = get<0>(e);
            if(to == par) continue;
            find_lca(to, cur);
            uf.unite(to, cur);
            uf.anc[uf.find(cur)] = cur;
        }
        uf.color[cur] = 1;
        for(auto e : info[cur]) {
            int col, d, idx, to; tie(col, d, idx, to) = e;
            if(to < 0) continue;
            if(uf.color[to] == 1 and neg[idx]++ == 0) {
                int lca = uf.anc[uf.find(to)];
                tmp[lca].emplace_back(col, d, idx, -1);
            }
        }
    };

    vector<int64> sum(N), cnt(N);
    int64 cost = 0;
    function<void(int, int)> go = [&](int cur, int par) {
        for(auto e : info[cur]) {
            int col, d, idx, p; tie(col, d, idx, p) = e;
            int64 diff = cost + cnt[col] * d - sum[col];
            if(p < 0) {
                ans[idx] -= 2 * diff;
            }
            else { 
                ans[idx] += diff;
            }
        }

        for(auto e : G[cur]) {
            int to, col, dist; tie(to, col, dist) = e;
            if(to == par) continue;
            sum[col] += dist;
            cnt[col]++;
            cost += dist;
            go(to, cur);
            sum[col] -= dist;
            cnt[col]--;
            cost -= dist;
        }
    };

    find_lca(0, -1);
    for(int i=0; i<N; i++) for(auto e : tmp[i]) info[i].push_back(e);
    go(0, -1);
    for(auto a : ans) printf("%lld\n", abs(a));
    return 0;
}


Measured memory_bytes: 33144
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    x, a, b = il()
    print('B' if abs(x-a) >abs(x-b) else 'A')


if __name__ == '__main__':
    main()


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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

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

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}
//int sum_digits(int num) {
//    int rtn = 0;
//    string num_str = to_string(num);
//    for(int i=0; i<num_str.size(); i++) {
//        rtn += num_str[i] - '0';
//    }   
//    return rtn;
//}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, c;
    int n, i;
    scanf("%d %d", &n,&i);
    
    for(i=0; i<n; i++){
        scanf("%d %d %d", &a,&b,&c);
        a*=a, b*=b, c*=c;
    
        if(a == b+c || b == a+c || c == a+b){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}



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

int main(void){
  int x,y,z;
  cin >> x >> y >> z;
  if(x== y && y == z){
    cout << "1" << endl;
  }else if(x==y || y==z || x==z){
    cout << "2" << endl;
  }else{
    cout << "3" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define rep(index,num) for(int index=0;index<num;index++)
#define eps 1e-15
typedef long long ll;
int temp[200000];
void MergeSort(int x[], int left, int right)
{
    int mid, i, j, k;

    if (left >= right)
        return;
    mid = (left + right) / 2;
    MergeSort(x, left, mid);
    MergeSort(x, mid + 1, right);
    for (i = left; i <= mid; i++)
        temp[i] = x[i];
    for (i = mid + 1, j = right; i <= right; i++, j--)
        temp[i] = x[j];

    i = left;
    j = right;

    for (k = left; k <= right; k++)
        if (temp[i] <= temp[j])
            x[k] = temp[i++];
        else
            x[k] = temp[j--];
}
int main(){
	int N,Asub[200000];
	scanf("%d",&N);
	rep(i,N){
		int A;
		scanf("%d",&A);
		Asub[i]=A-(i+1);
	}
	MergeSort(Asub,0,N-1);
	int b=Asub[(N+1)/2-1];
	ll kanasisa=0;
	rep(i,N){
		kanasisa+=abs(Asub[i]-b);
	}
	printf("%lld\n",kanasisa);
	return 0;
}


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

int main(){
    int n ;
    cin >> n;
    vector<double> x(n), y(n);
    for (int i=0;i<n;i++) cin >> x.at(i);
    for (int i=0;i<n;i++) cin >> y.at(i);

    double D, p = 1;
    double sum = 0;
    for (int i=0; i<n;i++) sum += pow(abs(x.at(i) - y.at(i)), p);
    D = pow(sum, 1/p);
    printf("%6f\n",D); 

    p = 2;
    sum=0;
    for (int i=0; i<n;i++) sum += pow(abs(x.at(i) - y.at(i)), p);
    D = pow(sum, 1/p);
    printf("%6f\n",D); 

    p = 3;
    sum=0;
    for (int i=0; i<n;i++) sum += pow(abs(x.at(i) - y.at(i)), p);
    D = pow(sum, 1/p);
    printf("%6f\n",D); 

    double max_inf = 0;
    for (int i=0; i<n;i++) if (max_inf < abs(x.at(i) - y.at(i))) max_inf = abs(x.at(i) - y.at(i));
    D = max_inf;
    printf("%6f\n",D); 

    return 0;
}



Measured memory_bytes: 3380
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int N, T;

int dp[3000 + 10][3000 + 10][2];//dp[i][j][k] := i品目まで食べるかを選んで、jの時間がかかったときのおいしさの最大値 
//kが0の時は、最後に食べるものをまだ選んでない 1の時は最後に食べるものをもう選んでる状態
vector<int> A, B;

int main() {
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		A.push_back(a), B.push_back(b);
	}
	
	dp[0][0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= T - 1; j++) {
			for (int k = 0; k < 2; k++) {
				dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
				if (j - A[i - 1] >= 0)
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - A[i - 1]][k] + B[i - 1]);
				//最後に食べるとする
				if (k == 0) {
					dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k] + B[i - 1]);
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= T - 1; i++)for (int j = 0; j < 2; j++)
		ans = max(ans, dp[N][i][j]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70912
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

  string s; cin >> s;
  vector<int> backet(300, 0);

  rep(i, s.length()) {
    backet[s[i]]++;
  }
  bool flag = true;
  rep(i, backet.size()) {
    if(backet[i]%2 != 0) flag = false;
  }
  cout << (flag ? "Yes" : "No") << '\n';
  return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int32 n = s.size();
  int32 ans = 0;
  int32 acnt = 0;
  REP(i,n){
    if(s[i] == 'A'){
      acnt++;
    }else{
      if(s[i] == 'B' && i+1 < n && s[i+1] == 'C'){
        ans += acnt;
        ++i;
      }else{
        acnt = 0;
      }
    }
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 3748
#include<iostream>
#include<map>
#include<set>
using namespace std;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0)  break;

        map<string, int> table;

        string s;
        int p;

        for(int i = 0; i < n; i++){
            cin >> s >> p;
            table[s] = p;
        }

        int m;
        cin >> m;

        map<string, set<string>> recipe;
        for(int i = 0; i < m; i++){
            cin >> s >> p;
            string ingre;
            for(int i = 0; i < p; i++){
                cin >> ingre;
                recipe[s].insert(ingre);
            }
        }

        bool update = true;
        while(update){
            update = false;
            for(pair<string, set<string>> re : recipe){
                int cost = 0;
                //bool judge = true;

                for(string x : re.second){
                    // if(table.count(x) == 0){
                    //     judge = false;
                    //     break;
                    // }
                    cost += table[x];
                }

                if(/*judge && */
                    (table.count(re.first) == 0 || table[re.first] > cost)){
                        update = true;
                        table[re.first] = cost;
                }

            }
        }

        string t;
        cin >> t;

        cout << table[t] << endl;
    }

    return 0;
}


Measured memory_bytes: 3060
#include <stdio.h>

#define getBMI(w, h) (w / (h * h))
#define abs(x) ((x) < 0.0 ? -(x) : (x))

static const double app_val = 22.0;

int main(void) {
    int n, i, id, h, w;
    int a_id;
    double min_diff, diff;

    while (EOF != scanf("%d", &n)) {
        if (n == 0) {
            break;
        }

        a_id = 1000000 + 1;
        min_diff = 0xfffffff;
        diff = 0;

        for (i = 0; i < n; ++i) {
            scanf("%d %d %d", &id, &h, &w);

            diff = abs(app_val - getBMI(w, (h / 100.0)));

            /* printf("id is %d\n bmi is %f\ndiff is %f\n", id, getBMI(w, (h / 100.0)), diff); */

            if (diff < min_diff || (diff == min_diff && id < a_id)) {
                min_diff = diff;
                a_id = id;
            }
        }

        printf("%d\n", a_id);
    }

    return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  for ( ; ; ) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main{
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt(), N=sc.nextInt(), min=1001, sa, ans=-100;
    String p[] = new String[N];
    for(int i=0; i<N; i++) {
      p[i] = sc.next();
	}
    
    for(int j=0; j<=101; j++) {
      if(!Arrays.asList(p).contains(String.valueOf(j))) {
        if(X>=j) {
          sa=X-j;
        } else {
          sa=j-X;
        }
        if(min>sa) {
          ans = j;
          min=sa;
        }
      }  
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35872
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int go[200000] = {};
int now[200000] = {};
int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> inputs;
	set<int> aa, bb;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		aa.insert(a);
		bb.insert(b);
		inputs.push_back(make_pair(a, b));
	}
	if (aa.size() + bb.size() != 2 * n) {
		cout << -1 << endl;
		return 0;
	}
	sort(inputs.begin(), inputs.end());
	REP(i, n) {
		go[inputs[i].second] = i+1;
		now[i + 1] = inputs[i].second;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if(go[i] != i){
			int kotti = i;
			int atti = go[i];
			swap(now[kotti], now[atti]);
			go[now[kotti]] = kotti;
			go[now[atti]] = atti;
			ans++;
			//swap with now[i] 
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 13768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll a,b,k;cin>>a>>b>>k;
  bool flg=true;
  rep(i,k){
    if(flg){
      if(a%2==1){
        a--;
      }
      b+=a/2;
      a/=2;
    }else{
      if(b%2==1){
        b--;
      }
      a+=b/2;
      b/=2;
    }
    flg=!flg;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}

Measured memory_bytes: 256
data = [
    "{0} {1}".format(s, r)
    for s in ('S', 'H', 'C', 'D')
    for r in range(1, 13 + 1)
]
count = int(input())
for c in range(count):
    card = input()
    data.remove(card)

for c in data:
    print(c)

Measured memory_bytes: 7712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++)
			values[i] = i + 1;
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int temp;
			temp = values[a];
			values[a] = values[b];
			values[b] = temp;
		}
		for (int i = 0; i < values.length; i++)
			System.out.println(values[i]);
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n), r(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    for(int i = 0; i < n; i++){
        cin >> q[i];
    }
    iota(begin(r), end(r), 1);
    int a, b, j = 0;
    do{
        if(r == p) a = j;
        if(r == q) b = j;
        j++;
    } while(next_permutation(begin(r), end(r)));
    cout << abs(a - b) << endl;
    return 0;
}

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

using namespace std;
#define PI              3.1415926536

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int32_t main()
{
	//c_p_c();
	FIO;


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

	int ans = 0;

	int res = 1;

	while (res < b)
	{
		--res;
		res += a;
		ans++;
	}
	cout << ans;



}








Measured memory_bytes: 3624
# coding: utf-8
N=int(input())
Sa=list(input())
Sb=list(input())

MOD=10**9+7

k=0
ans=1
swich=0

while k<N:
    if Sa[k]==Sb[k]:
        k+=1
        if swich==0:
            ans*=3
            ans=ans%MOD
        elif swich==1:
            ans*=2
            ans=ans%MOD
        elif swich==2:
            ans*=1
            ans=ans%MOD
        swich=1
    else:
        k+=2
        if swich==0:
            ans*=6
            ans=ans%MOD
        elif swich==1:
            ans*=2
            ans=ans%MOD
        elif swich==2:
            ans*=3
            ans=ans%MOD
        swich=2
print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
 
#define REP(i,b,n) for(int i=b;i<n;++i)
#define REPR(i,b,n) for(int i=n-1;i>=b;--i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef pair<pii, int> stt;
typedef long long ll;

enum{RIGHT, UP, LEFT, DOWN};

int h, w;
int field[32][32];
int vtx[32][32][4];
int cost[4];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int rev[] = {0, -1, 2, 1};

bool border(int lw, int mid, int hg){
	return lw <= mid && mid <= hg;
}

int solve(){

	queue<stt> qu;
	qu.push(make_pair( make_pair(1,1), (int)(RIGHT)));
	vtx[1][1][RIGHT] = 0;
	
	stt now;
	int x, y, dir, nx, ny, ndir, pay;
	
	while(!qu.empty()){
		
		now = qu.front();
		x = now.first.first, y = now.first.second, dir = now.second;
		qu.pop();
		
		switch(field[y][x] == 4)
			continue;
		
		for(int i=0; i<4; ++i){
			
			if(i==field[y][x])
				pay = 0;
			else
				pay = cost[i];
			
			ndir = (4+dir+rev[i])%4;
			nx = x+dx[ndir];
			ny = y+dy[ndir];
			
			if(border(1,nx,w) && border(1,ny,h) && vtx[ny][nx][ndir] > vtx[y][x][dir] + pay){
				vtx[ny][nx][ndir] = vtx[y][x][dir] + pay;
				qu.push(make_pair( make_pair(nx,ny), ndir));
			}
		}
	}
		
	int res = INT_MAX;
	
	for(int i=0; i<4; ++i){
		
		res = min(res, vtx[h][w][i]);
	}
	
	return res;
}

int main(){
	
	while(cin >> w >> h, (w||h)){
		
		for(int y=1; y<=h; ++y){
			for(int x=1; x<=w; ++x){
			
				cin >> field[y][x];
				
				for(int k=0; k<4; ++k){
					vtx[y][x][k] = INT_MAX;
				}
			}
		}
		
		for(int i=0; i<4; ++i){
			cin>> cost[i];
		}
		
		cout << solve() << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 1260
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

int main(void){
    int N;
    scanf("%d", &N);

    int i;
    int A[100001];
    A[0] = 0;
    A[N] = 0;

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

    for(int i = 1; i <= N; i++){
        if((A[i] - A[i - 1]) * (A[i + 1] - A[i]) < 0){
            printf("%d\n", sum - min(abs(A[i] - A[i - 1]), abs(A[i + 1] - A[i])) * 2);
        }else{
            printf("%d\n", sum);
        }
    }

    return 0;
}


Measured memory_bytes: 2168
#include <stdio.h>
#include <string.h>

int main(void) {

	int frg = 0, n, i;
	char s[100];

	scanf("%s", s);

	n = strlen(s);

	for (i = 0; i<n / 2; i++) {
		if (s[i] != s[n - 1 - i]) {
			printf("No");
			return 0;
		}
	}
	for (i = 0; i<(n - 1) / 4; i++) {
		if (s[i] != s[(n - 1) / 2 - 1 - i]) {
			printf("No");
			return 0;
		}
	}
	for (i = (n + 1) / 2; i<n; i++) {
		if (s[i] != s[n + (n + 1) / 2 - i - 1]) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
a[99],b[99];main(i,n){
	for(;scanf("%d",&n),n;){
		//if(n>90)exit(1);
		for(i=0;i<=n;i++)scanf("%d",a+i);
		for(i=1;i<=n;i++)b[i]=a[i]-a[i-1];
		if(b[1]==b[2]&&b[2]==b[3]&&b[3]==b[4]){
			for(i=5;i<=n;i++)if(b[i]!=b[1])break;
			printf("%d\n",a[i]);
		}
		else if(b[2]==b[3]&&b[3]==b[4])printf("%d\n",a[0]);
		else if(b[1]==b[2]&&b[2]==b[3])printf("%d\n",a[4]);
		else if(a[2]-a[0]==b[3]&&b[3]==b[4])printf("%d\n",a[1]);
		else if(b[1]==b[2]&&b[2]==a[4]-a[2])printf("%d\n",a[3]);
		else if(b[1]==a[3]-a[1]&&a[3]-a[1]==b[4])printf("%d\n",a[2]);
		else exit(1);
	}
exit(0);}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair <int, int> ii;

const ll siz = 1e5 + 10;
const ll SIZ = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll maxx = 2e9;
const ll MAXX = 1e18;

int n, m, a;
int s;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen ("IN_4.INP", "r", stdin);
//    freopen ("OUT_4.OUT", "w", stdout);
    cin >> n >> m;
    while (m--)
    {
        cin >> a;
        s += a;
    }
    if (n - s < 0) cout << "-1";
    else cout << n - s;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////

int main(){fastio
    ll n;cin>>n;
    ll a[n][n];rep(i,0,n-1)rep(j,0,n-1)cin>>a[i][j];
    ll dp[2][1<<n];memset(dp,0,sizeof(dp));
    rep(j,0,n-1){
        if(a[0][j]==1)dp[0][1<<j]=1;
    }
    rep(i,1,n-1){
        rep(j,0,(1<<n)-1){
            ll cnt=0;rep(k,0,n-1)if((j&(1<<k)))cnt++;
            if(cnt!=i+1)continue;
            rep(op,0,n-1){
                if(a[i][op]==0)continue;
                if((j&(1<<op))==0)continue;
                Add(dp[i&1][j],dp[(i-1)&1][j-(1<<op)]);
            }
        }
    }
    cout<<dp[(n-1)&1][(1<<n)-1]<<endl;
    
    return 0;
}



Measured memory_bytes: 33152
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <numeric>
#include <list>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int, int>PII;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), rend()
#define PB pushback
#define SORT(c) sort((c).begin(),(c).end())

const LL INF = 1LL << 60;

//priority_queue<int> p;


string s;

//scanf("%d",&N);

//printf("%d", ans);

//cout <<  << endl;

//買った人に足していくようにする
LL limit = 0;//勝ち負けが決まるライン

LL i, j, k, tmp, ans, cnt, N, K, Q, M;

int main(void) {
	priority_queue<LL> p;
	
	scanf("%d %d", &N, &M);
	REP(i, N) {
		scanf("%lld", &tmp);
		p.push(tmp);
	}
	REP(i, M) {
		j = p.top() / 2;
		p.pop();
		p.push(j);		
	}
	
	REP(i, N) {
		ans += p.top();
		p.pop();
	}
	printf("%lld", ans);

	return 0;
}

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

int main(){
  int N,a;
  cin>>N;
  vector<int> S(N+1);
  for(int i=1; i<=N-1; i++){
    cin>>a;
    S.at(a)++;
  }
  for(int i=1; i<=N; i++){
    cout<<S.at(i)<<endl;
  }
}
  

Measured memory_bytes: 4040
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int n,m;
  while(true){
    cin >>n >>m;
    if (!n&&!m)
      break;
    int t[n+m+1];
    for(int i=0;i<n;i++)
      cin >> t[i];
    for(int i=n;i<n+m;i++)
      cin >> t[i];
    t[n+m] = 0;
    sort(t,t+n+m+1);
    int max = 0;
    for(int i=0;i<n+m;i++)
      if (max<(t[i+1]-t[i]))
	max = t[i+1]-t[i];
    cout <<max << endl;
  }
  return 0;
}

Measured memory_bytes: 940
import java.util.*;
class Main
{
    static long mod = 1000000007;
    static long[] p = new long[1000001];
    String yes = "Yes";
    String no = "No";
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int[] x = new int[10000001];
        x[s] = 1;
        int cnt = 1;
        while(true){
            cnt++;
            if(s % 2 == 0){
                s /= 2;
            }
            else{
                s = s * 3 + 1;
            }
            if(x[s] == 1){
                System.out.println(cnt);
                break;
            }
            x[s] = 1;
        }
    }
}

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

int main(){
  int ans = 0;
  int N, D, X;
  cin >> N >> D >> X;
  int a;
  for ( int i = 0; i < N; i++ ){
    cin >> a;
    int j = 0;
    while (1){
      if (a * j + 1 <= D){
        ans++;
        j++;
      } else {
        break;
      }
    }
  }
  
  cout << ans+X << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  bool ok = true;
  if(s == "AAA" || s == "BBB") ok = false;
  cout << (ok ? "Yes" : "No") << endl;
}

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

int main(){
  vector<string> Letter(3);
  cin >> Letter.at(0) >> Letter.at(1) >> Letter.at(2);

  for(int i = 0; i < 3; i++){
    char x = Letter.at(i).at(0);
  
  if( x == 'A' || x == 'a'){
    cout << "A";
  }
   if( x == 'B' || x == 'b'){
    cout << "B";
  }
  if( x == 'C' || x == 'c'){
    cout << "C";
  }
   if( x == 'D' || x == 'd'){
    cout << "D";
  }  
  if( x == 'E' || x == 'e'){
    cout << "E";
  }
   if( x == 'F' || x == 'f'){
    cout << "F";
  }
  if( x == 'G' || x == 'g'){
    cout << "G";
  }
   if( x == 'H' || x == 'h'){
    cout << "H";
  }  
   if( x == 'I' || x == 'i'){
    cout << "I";
  }
   if( x == 'J' || x == 'j'){
    cout << "J";
  }
  if( x == 'K' || x == 'k'){
    cout << "K";
  }
   if( x == 'L' || x == 'l'){
    cout << "L";
  }  
  if( x == 'M' || x == 'm'){
    cout << "M";
  }
   if( x == 'N' || x == 'n'){
    cout << "N";
  }
  if( x == 'O' || x == 'o'){
    cout << "O";
  }
   if( x == 'P' || x == 'p'){
    cout << "P";
  }    
  if( x == 'Q' || x == 'q'){
    cout << "Q";
  }
   if( x == 'R' || x == 'r'){
    cout << "R";
  }
  if( x == 'S' || x == 's'){
    cout << "S";
  }
   if( x == 'T' || x == 't'){
    cout << "T";
  }  
  if( x == 'U' || x == 'u'){
    cout << "U";
  }
   if( x == 'V' || x == 'v'){
    cout << "V";
  }
  if( x == 'W' || x == 'w'){
    cout << "W";
  }
   if( x == 'X' || x == 'x'){
    cout << "X";
  }  
   if( x == 'Y' || x == 'y'){
    cout << "Y";
  }
   if( x == 'Z' || x == 'z'){
    cout << "Z";
  }
  }
  cout << endl;
}
 
  
  


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().strip().split(' ')))
total=sum(A)
temp_total=sum([A[i] for i in range(N) if i%2==0])
Ans=[0]*N
Ans[0]=2*temp_total-total
for i in range(N-1):
    Ans[i+1]=2*A[i]-Ans[i]
Ans=[str(x) for  x in Ans]
print(" ".join(Ans))

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

const int mxn = 2e5 + 1;
vvi grid(mxn);
vi vis(mxn);
int c = 0;

void dfs(int u)
{
	vis[u] = 1;
	c++;
	for (auto v : grid[u])
	{
		if (vis[v])
			continue;
		dfs(v);
	}
}

int main()
{
	fast;
	int n, m;
	cin >> n >> m;
	FOR(m)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		grid[x].pb(y);
		grid[y].pb(x);
	}
	int ans = 0;
	FOR(n)
	{
		c = 0;
		if (!vis[i])
		{
			dfs(i);
			chmax(ans, c);
		}
	}
	cout << ans;
}

Measured memory_bytes: 21020
#include<bits/stdc++.h>
#define l long 
#define ll long long 
#define ld long double 
#define INF 1000000000000
#define MOD 1000000007
#define MAX_N 1000006
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    vector<ll> a;
    ll x;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);
    }
    ll dp[n][n][2];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            dp[i][j][0]=0;
            dp[i][j][1]=INF;
        }
    }
    for(int len=1;len<=n;len++)
    {
        for(int i=0;i<n;i++)
        {
            if(i+len-1>=n)
            continue;
            if(len==1)
            {
                dp[i][i][0]=a[i];
                dp[i][i][1]=-a[i];
            }
            else 
            {
                dp[i][i+len-1][0]=max(dp[i][i+len-2][1]+a[i+len-1],dp[i+1][i+len-1][1]+a[i]);
                dp[i][i+len-1][1]=min(dp[i][i+len-2][0]-a[i+len-1],dp[i+1][i+len-1][0]-a[i]);
            }
        }
    }
    cout<<dp[0][n-1][0]<<endl;
}

Measured memory_bytes: 144280
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N;
    cin >> N;
    vector<int>C(N+1,0);
    vector<int>S(N+1,0);
    vector<int>F(N+1,1);
    for(int i = 0; i < N-1; i++) {
        int c,s,f;
        cin >> c >> s >> f;
        C[i] = c; S[i] = s; F[i] = f;
    }
    for(int i = 0; i < N; i++) {
        int cnt = S[i]+C[i];
        for(int j = i+1; j < N-1; j++) {
            if(cnt <= S[j]) {
                cnt = S[j]+C[j];
            }
            else {
                if(cnt%F[j] == 0) {
                    cnt+=C[j];
                }
                else {
                    cnt+=F[j]-cnt%F[j]+C[j];
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
  int H = sc.nextInt();
  int W = sc.nextInt();
  String[] s = new String[H];
  for(int i = 0;i < W+1;i++)System.out.print("#");
  System.out.println("#");
  for(int i = 0;i < H;i++){
    s[i] = sc.next();
    System.out.println("#" + s[i] + "#");
  }
  for(int i = 0;i < W+1;i++)System.out.print("#");
  System.out.println("#");
}}


Measured memory_bytes: 23764
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif




int main() {
	int a,b;
	cin>>a>>b;
	if (a<=9&&b<=9) cout<<a*b<<endl;
	else cout<<-1<<endl;
}









Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10**9+7

def cmb2(n, r, mod):
    res = 1
    for k in range(1, r+1):
        res *= (n-k+1)*pow(k,(mod-2),mod)%mod
        res %= mod
    return res

def power(a, n, mod):
  bi=str(format(n,"b")) #2進数
  res=1
  for i in range(len(bi)):
    res=(res*res) %mod
    if bi[i]=="1":
      res=(res*a) %mod
  return res

ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) -1
ans %= mod
print(ans)

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 100000;

string S, T;
int Q;
int sumA[2][MAX_N + 1], sumB[2][MAX_N + 1];

signed main()
{
	cin >> S >> T >> Q;
	for (int i = 0; i < S.size(); i++)
	{
		sumA[0][i + 1] = sumA[0][i] + (S[i] == 'A');
		sumB[0][i + 1] = sumB[0][i] + (S[i] == 'B');
	}
	for (int i = 0; i < T.size(); i++)
	{
		sumA[1][i + 1] = sumA[1][i] + (T[i] == 'A');
		sumB[1][i + 1] = sumB[1][i] + (T[i] == 'B');
	}
	for (int i = 0; i < Q; i++)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; c--;
		int x = (3*MAX_N + sumA[0][b] - sumA[0][a] + sumB[0][a] - sumB[0][b]) % 3;
		int y = (3*MAX_N + sumA[1][d] - sumA[1][c] + sumB[1][c] - sumB[1][d]) % 3;
		puts(x == y ? "YES" : "NO");
	}
	return 0;
}

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

int main() {

  int x,a,b;
	cin >> a >> b;
	x=a+b;

	if(x==3){
	cout << "3" << endl;
	}
	if(x==4){
	cout << "2" << endl;
	}
	if(x==5){
	cout << "1" << endl;
	}
	

}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
  ll n;
  cin >> n;
  n = n%10;
  if(n==0||n==1||n==6||n==8)  cout << "pon";
  else if(n==3) cout << "bon";
  else cout << "hon";
}

Measured memory_bytes: 3632
// kartikay26
#include <bits/stdc++.h>
using namespace std;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#include "prettyprint.hpp"
#else
#define debug(...)
#define debuga(arr, n)
#define debugg(grid, n) 
#endif
typedef long long int ll;
#define int ll
#define F first
#define S second
#define float double
const int inf = LLONG_MAX;
int get() { int x; cin >> x; return x; }
void getl(int* ar, int sz){ for(int i=0; i<sz; i++) cin >> ar[i];}
template <typename T> void print(T x) { cout << x << "\n";}
template <typename T> void prints(T x) { cout << x << " ";}
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int mod = 1e9+7;
const int N = 1e6+1;

int32_t main(){
	fast_io();
	int n = get();
	vi a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(all(a));
	db ans = a[0];
	for (int i = 0; i < n; ++i) {
		ans = (ans + a[i]) / 2.0;
	}
	print(ans);
	return 0;
}

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


/*
期末試験の成績
私は，中学校の教師である． ちょうど期末試験が終わったところで，すべての科目について全生徒の点数が手元にある．
どれぐらい高い合計点を得た生徒がいるのか知りたいのだが，科目ごとの得点データになっているので，作業が容易でない．
そこで，優秀なプログラマであるあなたに手助けしてほしい．
具体的には，合計点が最も高い生徒の合計点を求めるプログラムを書いてほしい．

Input
入力は複数のデータセットからなる． 各データセットは次の形式で表される．

n m
p1,1 p1,2 … p1,n
p2,1 p2,2 … p2,n
…
pm,1 pm,2 … pm,n
データセットの最初の行は，二つの整数 n と m からなる．
n は生徒の人数 (1 ≤ n ≤ 1000)，m は科目数 (1 ≤ m ≤ 50) である．
それに続く m 行のそれぞれには，特定の科目に対する n 人の生徒の得点がある．
pj,k は，生徒 k の科目 j に対する得点を表す整数である (1 ≤ j ≤ m，1 ≤ k ≤ n)．
この値は，0 ≤ pj,k ≤ 1000 を満たす．

入力の終わりは二つのゼロからなる行で表される． データセットの個数は 100 を超えない．

Output
各データセットについて，合計点が最も高い生徒の合計点を出力せよ．
生徒 k の合計点 sk とは sk = p1,k + … + pm,k のことである．

Sample Input
5 2
10 20 30 40 50
15 25 35 45 55
6 3
10 20 30 15 25 35
21 34 11 52 20 18
31 15 42 10 21 19
4 2
0 0 0 0
0 0 0 0
0 0
Output for the Sample Input
105
83
0

 */

/**
 * URL
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1632&lang=ja
 */

class Main {

	public static void main(String[] args) throws Exception {
		try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
			Integer numDataSet = 0;
			String[] data;
			Integer numStudent;
			Integer numSubject;
			Integer[] total;
			String[] point;
			Integer max;
			Integer[] result = new Integer[100];

			while(true){
				data = reader.readLine().split(" ");
				numStudent = Integer.parseInt(data[0]);
				numSubject = Integer.parseInt(data[1]);
				// 生徒数と科目数がどちらも0の場合、ループを抜ける
				if(numStudent == 0 && numSubject == 0) break;

				total = new Integer[numStudent];

				// 科目の数分ループ
				for(int i=0;i<numSubject;i++){
					point = reader.readLine().split(" ");

					// 生徒の人数分ループ
					for(int j=0;j<numStudent;j++){
						if(i==0) total[j] = Integer.parseInt(point[j]);
						else total[j] += Integer.parseInt(point[j]);
					}
				}

				max = total[0];
				for(int i=1;i<total.length;i++){
					int val = total[i];
					if(val > max) max = val;
				}

				result[numDataSet] = max;
				numDataSet++;

			}

			for(int i=0;i<numDataSet;i++){
				System.out.println(result[i]);
			}

		}
	}
}









Measured memory_bytes: 43008
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n , ans , sum ,W,w[mx2],v[mx2];
ll dp[mx2][mx5];
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n>>W;
		fo(i,n)
		{
			cin>>w[i]>>v[i];
		}
		memset(dp,-1 ,sizeof(dp));
		dp[n][0]=0;
		for(int i=n-1 ; i>=0 ; i--)
		{
			
			for(int j=0 ;j<mx5 ; j++)
			{
				if(j>=v[i] && dp[i+1][j-v[i]]!=-1)
				{
					if(dp[i+1][j]==-1)
					{
						dp[i][j]=dp[i+1][j-v[i]]+w[i];
					}
					else
					{
						dp[i][j]=min(dp[i+1][j],dp[i+1][j-v[i]]+w[i]);
					}
				}
				else
				{
					dp[i][j]=dp[i+1][j];
				}
			}
		}
		for(int i=mx5-5 ; i>=0 ; i--)
		{
			if(dp[0][i]<=W && dp[0][i]!=-1)
			{
				cout<<i;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 80000
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

string s;
int n;

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    cin >> s;
    n = s.size();
    
    string one = s.substr(0, (n-1)/2);
    string two = s.substr((n+3)/2-1, n);
   // cout << "one: " << one << endl;
   // cout << "two: " << two << endl;
    if(one == two){
		cout << "Yes" << endl;
 	}
 	else cout << "No" << endl;
    
    
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <cctype>
#include <complex>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <typeinfo>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define PB(e) push_back(e)
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;

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

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b, a % b);
}

int main(int argc, char *argv[])
{
  int T;
  ll A, B, C, D;
  cin >> T;
  REP(t, T) {
    cin >> A >> B >> C >> D;
    if (D < B || A < B) {
      cout << "No" << endl;
    } else if (B <= C) {
      cout << "Yes" << endl;
    } else {
      ll d = gcd(B, D);
      ll p = (C - A) / d * d;
      while (p <= C - A) {
        p += d;
      }
      if (p < B - A) {
        cout << "No" << endl;
      } else {
        cout << "Yes" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256