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

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
const int INF = 0x3f3f3f3f;

int main() {
	for (int N, M; cin >> N >> M&&N;) {
		vector<int> s(N);
		rep(i, 0, N)cin >> s[i];
		int minX = s[0];
		auto f = [&](int x) {
			//cout << "x " << x << endl;
			int L = 1;
			rep(i, 0, M - 1) {
				auto e = lower_bound(all(s), L);
				//cout << " *e " << *e << endl;
				//cout << " L" << L << endl;
				if (s.back() < L + x)
					return true;
				if (e == s.begin()) {
					if (*e < L + x) {
						// ???????????? ??????????????? ???????????????????????£????????¢??????
						if (*e == s.back())
							return true;
						L += max(1, x - abs(L - *e));
					}
					else {
						// ???????????? ?????????????????? ??¶???????????????
						return true;
					}
				}
				else {
					int maxi = 0;
					if (*e < L + x) {
						// ??????????????? ???????????????????????£????????¢??????
						if (*e == s.back())
							return true;
						chmax(maxi, max(1, x - abs(L - *e)));
					}
					// ????????????
					chmax(maxi, max(1, x - abs(L - *prev(e))));
					L += maxi;
				}
			}
			return false;
		};
		// false true
		auto binary_search = [&](int l, int r) {
			if (f(l))return l;
			while (l + 1 < r) {
				int m = (l + r) / 2;
				if (f(m))
					r = m;
				else
					l = m;
			}
			return r;
		};
		//cout << "minX " << minX << endl;
		int res = binary_search(minX, s.back() * 2) - 1;
		if (res < minX)
			cout << -1 << endl;
		else
			cout << res << endl;

	}
	return 0;
}

Measured memory_bytes: 3412
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 2510;
const int MAXM = 200010;
const int MAXK = 110;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, res = 0;
    cin >> n;
    FOR(i,1,n) {
        int h = i, cnt = 0;
        while (h) {
            cnt++;
            h /= 10;
        }
        // cout << cnt << endl;
        res += (cnt % 2);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, k = LI()
    a = LI()
    a.sort(key=abs, reverse=True)
    ans = 1
    if n - a.count(0) < k:
        print(0)
        return
    t = 0
    L = None
    R= inf
    for ai in a[:k]:
        if ai < 0:
            t ^= 1
            L = ai
        if ai > 0:
            R = ai
        ans *= ai
        ans %= mod
    if k == n:
        print(ans)
        return
    if t:
        if max(a) <= 0:
            ans = 1
            for i in range(k):
                ans *= a[-i - 1]
                ans %= mod
            print(ans)
        else:
            A = min(a[k:])
            B = max(a[k:])
            if A >= 0:
                ans *= pow(L, mod - 2, mod)
                ans *= B
            else:
                if A * L > B * R:
                    ans *= pow(R, mod - 2, mod)
                    ans *= A
                else:
                    ans *= pow(L, mod - 2, mod)
                    ans *= B
            print(ans % mod)
    else:
        print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 109564
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n, k, cnt = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= k) cnt++;
    }
    OUT(cnt);
}


Measured memory_bytes: 256
hw = [int(i) for i in input().split()]
ans = "Yes"

#low efficientcy
field = ["." * (hw[1] + 2)]
for h_i in range(hw[0]):
    field.append("." + input() + ".")
field.append("." * (hw[1] + 2))

for h_i in range(1, hw[0] + 1):
    if ans == "No":
        break
    for w_i in range(1, hw[1] + 1):
        if field[h_i][w_i] == "#":
            if field[h_i - 1][w_i] == "#" or field[h_i + 1][w_i] == "#"\
            or field[h_i][w_i - 1] == "#" or field[h_i][w_i + 1] == "#":
                continue
            ans = "No"
            break
print(ans)

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d=0;
    cin>>n;
    while(n!=0)
    {
        d=n%10;
        if(d==7){cout<<"Yes";return 0;}
        n/=10;
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main()
{
    int n;
    cin >> n;
    ll a[n];
    REP(i, n) cin >> a[i];
    ll sum = 0;
    REP(i, n) sum += a[i];
    ll ss = 0, tt = 0;
    ss += a[0], tt = sum - a[0];
    ll ans = abs(ss - tt);
    for (int i = 1; i < n - 1; i++) {
        ss += a[i];
        tt -= a[i];
        if (ans > abs(ss - tt)) {
            ans = abs(ss - tt);
        }
    }
    cout << ans << endl;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	bool flag = (s[0] == 'W');
	int cnt = 0;
	REP(i, s.size()) {
		if (flag) {
			if (s[i] == 'B') {
				cnt++;
				flag = false;
			}
		}
		else {
			if (s[i] == 'W') {
				cnt++;
				flag = true;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll fenw[MX],h[MX],a[MX];

void upd(int p,ll v) {
    for(; p < MX; p += p&-p) fenw[p] = max(fenw[p],v);
}

ll query(int p) {
    ll res = 0; for(; p; p -= p&-p) res = max(res,fenw[p]);
    return res;
}

int main() {

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

    int N; cin >> N;

    FOR(i,1,N+1) cin >> h[i];
    FOR(i,1,N+1) cin >> a[i];

    ll res = 0;
    FOR(i,1,N+1) {
        ll cur = query(h[i]);
        res = max(res,cur+a[i]);
        upd(h[i],cur+a[i]);
    }

    cout << res << "\n";
}


Measured memory_bytes: 4992
#include <iostream>
#include <map>
#include <algorithm>

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

using namespace std;

const int inf = 1e6;

typedef long long ll;

int n, m, w, t;
map<string, int> s;
int v[7];
int p[7];
int x[8];
int y[8];
int q[7][7];
int ptrl[1 << 7];
int dpw[1 << 7][8][10001];
ll dpt[(1 << 7) + 1][10001];

int dist(int i, int j){
	int dx = x[i] - x[j];
	int dy = y[i] - y[j];
	return abs(dx) + abs(dy);
}

void patrol(int i, int d, int v){
	if(i == n && v & 1 << i){
		int w = v - (1 << i);
		ptrl[w] = min(d, ptrl[w]);
		return;
	}
	rep(j, n + 1){
		if(!(v & 1 << j)){
			patrol(j, d + dist(i, j), v + (1 << j));
		}
	}
}

void knapsack_weight(){
	for(int i = 0; i < 1 << n; ++i){
		int mp[7];
		fill_n(mp, m, 0);
		rep(j, n){
			if(!(i & 1 << j)){
				continue;
			}
			rep(k, m){
				mp[k] = max(q[j][k], mp[k]);
			}
		}

		for(int j = 1; j <= m; ++j){
			rep(k, w + 1){
				dpw[i][j][k] = dpw[i][j - 1][k];
				if(k >= v[j - 1]){
					dpw[i][j][k] = max(dpw[i][j][k - v[j - 1]] + mp[j - 1], dpw[i][j][k]);
				}
			}
		}
	}
}

void knapsack_time(){
	for(int i = 1; i <= 1 << n; ++i){
		rep(j, t + 1){
			dpt[i][j] = dpt[i - 1][j];
			if(j >= ptrl[i - 1]){
				dpt[i][j] = max(dpt[i][j - ptrl[i - 1]] + dpw[i - 1][m][w], dpt[i][j]);
			}
		}
	}
}

int main(){
	cin >> n >> m >> w >> t;
	rep(i, m){
		string k;
		cin >> k >> v[i] >> p[i];
		s[k] = i;
	}
	rep(i, n){
		fill_n(q[i], m, 0);
		int l;
		cin >> l >> x[i] >> y[i];
		rep(j, l){
			string r;
			int x;
			cin >> r >> x;
			int k = s[r];
			q[i][k] = p[k] - x;
		}
	}

	fill_n(ptrl, 1 << n, inf);
	patrol(n, 0, 0);
	
	knapsack_weight();
	knapsack_time();

	cout << dpt[1 << n][t] << endl;
	return 0;
}

Measured memory_bytes: 51120
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var a=arr.shift().split("");
   if(a.join("")=="-")break;
   var b=arr.shift().split("");
   var c=arr.shift().split("");
   var obj={};
   a.forEach(function(v){
      obj[v]=true;
   });
   var str="";
   var m="";
   c.forEach(function(v){
      if(obj.hasOwnProperty(v)){
         if(m==""){
            m=a.shift();
            m=a.shift();
         }else{
            m=a.shift();
         }
      }else{
         while(true){
            if(m==v){
               m=a.shift();
               break;
            }else{
               str+=m;
               m=b.shift();
            }
         }
      }
   });
   str+=m;
   str+=b.join("");
   console.log(str);
}

Measured memory_bytes: 15516
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    string s;cin>>s;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='o')cnt++;
    }
    if(cnt+15-s.length()>=8)cout<<"YES"<<endl;
    else cout<<"NO"<<Endl;
    //-------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------








































Measured memory_bytes: 256
import sys
import numpy as np
from numba import njit
 
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
@njit
def update(A):
  N = len(A)
  B = np.zeros_like(A)
  for i,x in enumerate(A):
    l = max(0, i-x)
    r = min(N-1, i+x)
    B[l] += 1
    if r + 1 < N:
      B[r+1] -= 1
  B = np.cumsum(B)
  return B
    
    
N,K = map(int, readline().split())
A = np.array(read().split(), np.int64)
 
K = min(K, 100)
for _ in range(K):
  A = update(A)
print(' '.join(A.astype(str)))

Measured memory_bytes: 152856
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int n, a, b;

bool judge(int k, vector<int>& v) {
    int attack = 0;
    for (int i = 0; i < n; i++) {
        int t = v[i] - b * k;
        if (t <= 0) continue;
        attack += t / (a - b);
        if (t % (a - b) != 0)
            attack++;
    }
    return k >= attack;
}

signed main() {
    cin >> n >> a >> b;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    int r = 0;
    int l = (int)1e9;
    while (l - r > 1) {
        int mid = (l + r) / 2;
        if (judge(mid, v))
            l = mid;
        else
            r = mid;
    }
    cout << l << "\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

const int maxn = 200000 + 10;

int main()
{
    int n , minP , maxP = - 2000000000, now;
    while (scanf("%d",&n)!= EOF){
        cin >> minP;
        for (int i = 1 ; i < n ; i ++){
            scanf("%d",&now);
            maxP = max(maxP , now - minP);
            minP = min(minP , now);
        }
        cout << maxP << endl;
    }
    return 0;
}



Measured memory_bytes: 3236
from collections import deque

Height, Width = map(int, input().split())
Map = [input() for _ in range(Height)]
min_step_map = [[10**6]*Width for _ in range(Height)]
research_point = deque()

# Find the minimum number of steps from all blacks.
# The maximum number of the obtained minimum steps is the answer.
def search_min_step():
    while len(research_point) > 0:
        y_now, x_now = research_point.popleft()
        
        for dy, dx in [(-1,0), (0,-1), (1,0), (0,1)]:
            y_next, x_next = y_now+dy, x_now+dx
            if (y_next <= -1 or Height <= y_next) or \
                                              (x_next <= -1 or Width <= x_next):
                continue
            
            if Map[y_next][x_next] == '#' or \
                 min_step_map[y_next][x_next] <= min_step_map[y_now][x_now] + 1:
                continue
            else:
                min_step_map[y_next][x_next] = min_step_map[y_now][x_now] + 1
                research_point.append([y_next, x_next])

for y in range(Height):
    for x in range(Width):
        if Map[y][x] == '#':
            min_step_map[y][x] = 0
            research_point.append([y, x])

search_min_step()

max_step = 0
for y in range(Height):
    max_step = max(max_step, max(min_step_map[y]))

print(max_step)

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


typedef long long ll;
    typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int m;
int ans;
string str;

int main(){
    int a,b,t;
    cin>>a>>b>>t;
    cout<<(t/a)*b<<endl;
    return 0;
}

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

const int N = 100010;
std::multiset <int> a, b;
std::map <int, int> Hash;
int fa[N], numa[N], numb[N];
int n;

int find(int u){
	return u == fa[u] ? u : fa[u] = find(fa[u]);
}

void unite(int u, int v){
	int _u = find(u), _v = find(v);
	if (_u == _v){
		return;
	}
	fa[_u] = _v;
}

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &numa[i]);
		a.insert(numa[i]);
		numa[0] ^= numa[i];
	}
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &numb[i]);
		b.insert(numb[i]);
		numb[0] ^= numb[i];
	}
	a.insert(numa[0]);
	b.insert(numb[0]);
	if (a != b){
		return printf("-1\n"), 0;
	}
	Hash[numa[0]] = Hash[numb[0]] = 0;
	for (int i = 1; i <= n; ++ i){
		if (numa[i] != numb[i]){
			Hash[numa[i]] = Hash[numb[i]] = 0;
		}
	}
	int cnt = 0;
	for (auto &u : Hash){
		u.second = cnt ++;
	}
	for (int i = 0; i < N; ++ i){
		fa[i] = i;
	}
	int ans = -1;
	for (int i = 1; i <= n; ++ i){
		if (numa[i] != numb[i]){
			unite(Hash[numa[i]], Hash[numb[i]]);
			++ ans;
		}
	}
	for (int i = 0; i < cnt; ++ i){
		find(i);
		if (fa[i] == i){
			++ ans;
		}
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    char str[1001] = {0} ;
    cin >> str ;
    for ( int i = 0 ; i < strlen(str) ; i++ )
    {
        str[i] -= 3 ;
        if ( str[i] < 'A' ) str[i] += 26 ;
    }
    cout << str << endl ;
    return 0 ;
}

Measured memory_bytes: 3056
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		double s[]=new double[n];
		
		for(int i=0;i<n;i++) {
			s[i]=sc.nextDouble();
		}
		for(int i=0;i<n-1;i++) {
			
			for(int j=n-1;j>i;j--) {
				if(s[j-1]>s[j]) {
					double c=s[j];
					s[j]=s[j-1];
					s[j-1]=c;
				}
					
			}
		}
		for(int i=0;i<n-1;i++) {
			s[i+1]=((s[i]+s[i+1])/2);
		}
		System.out.println(s[n-1]);
			
		
		
	}

}

Measured memory_bytes: 25044
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define N 6

int main(void){
    int a[N];
    int ans[4]={0,0,0,0};
    int cnt=0;

    for(int i=0;i<N;i++){
        cin>>a[i];
        ans[a[i]-1]+=1;
    }

    for(int i=0;i<4;i++){
        if(ans[i]==2)
            cnt+=1;
    }

    if(cnt==2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            price = i * 500 + j * 100 + k * 50
            if price == X:
                count += 1
print(count)

Measured memory_bytes: 9092
#include<cstdio>
int n,ma=0,mi=2e9;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		int x;scanf("%d",&x);
		if (x<mi) mi=x;
		if (x>ma) ma=x;
	}
	printf("%d\n",ma-mi);
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var A uint64
	var B string
	fmt.Scan(&A)
	fmt.Scan(&B)
	var B100 int
	s := strings.Split(B, ".")
	b0, _ := strconv.Atoi(s[0])
	b1, _ := strconv.Atoi(s[1])
	B100 = b0*100 + b1
	fmt.Println(A * uint64(B100) / 100)
}


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

int main(){
  long long N,A,B; cin >> N >> A >> B;
  if(N>=3){
    if(A<B){
      cout << B*(N-1)+A-A*(N-1)-B+1 << endl;
    }else if(A==B){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }else if(N==2){
    if(A<=B){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }else{
    if(A==B){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }
}

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

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] H = new int[N];
    for (int i = 0; i < N; i++) {
      H[i] = Integer.parseInt(sc.next());
    }

    if (N == 1) {
      System.out.println("Yes");
      return;
    }
    
    if (H[0] > H[1]) {
      H[0]--;
    }
    for (int i = 1; i < N; i++) {
      if (H[i-1] > H[i]) {
        System.out.println("No");
        return;
      }
      if (H[i] > H[i-1]) {
        H[i]--;
      }
    }
    
    if (H[N-1] < H[N-2]) {
      System.out.println("No");
      return;
    }
    
    System.out.println("Yes");
  }
}

Measured memory_bytes: 48852
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

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

    vector<pair<long long, long long>> goods(n + 1);
    for (int i = 1; i <= n; ++i) {
        int w, v;
        cin >> w >> v;
        goods[i] = make_pair(w, v);
    }

    vector<vector<long long>> dp(n + 1, vector<long long>(w + 1, 0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= w; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j >= goods[i].first) {
                dp[i][j] = max(dp[i][j],
                               dp[i - 1][j - goods[i].first] + goods[i].second);
            }
        }
    }

    cout << dp[n][w] << '\n';
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i, end) for (long long int i=0; i<end; i++)
#define repp(i, begin, end) for (long long int i=begin; i<end; i+)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vllvll = vector<vll>;
using vs = vector<string>;
ll sm(vll x) {ll sum=0; rep(i, x.size()) sum+=x[i]; return sum;}
void vdeb(string s, vll x) {cout<<s<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<endl;}

//=======================================================================================================

int main()
{
    ll n, d;
    cin >> n >> d;
    ll dd = 2 * d + 1;
    ll x = n / dd;
    if(dd*x >= n) cout << x << endl;
    else cout << x + 1 << endl;
}

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

const int l = 10;

int main() {
    string S;
    cin >> S;
    long int s = 0;
    long int cs;
    bitset<l> b;
    for (int i = 0; i < 1 << S.size()-1; i++) {
        b = i;
        cs = 0;
        for (int j = 0; j < S.size(); j++) {
            cs = 10 * cs + S.at(j) - '0';
            if (b.test(j)) {
                s += cs;
                cs = 0;
            }
        }
        s += cs;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n ;
  cin >> n ;
  int ans = 0 ;
  vector<int> num(n) ;
  REP(i,n){
    cin >> num.at(i) ;
  }
  int small = n+1 ;
  REP(i,n){
    if(num.at(i)<=small){
      small = num.at(i) ;
      ans++ ;
    }
  }
  
  cout << ans <<endl ;
      
  
  
  
  return 0 ;
}




Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    string s1,s2,s3;
    int A,B;
    cin>>s1>>s2>>A>>B>>s3;
    if(s1==s3) A--;
    if(s2==s3) B--;
    cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define f(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define len(s) s.size()
#define all(v) v.begin(), v.end()
#define tr(it, v) for (auto &it : v)
#define bit(x) __builtin_popcount(x)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
// =================
void impgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1e7;
const int N = 3e5 + 1;

vi g[N];
int a[N];

void solve()
{
    int n, m, ans = 0, k;
    cin>>n;
    int h[n+1];
    f(i,1,n+1) cin>>h[i];
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    f(i,3,n+1) {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    // f(i,1,n+1) cout<<i<<" "<<dp[i]<<endl;
    cout<<dp[n];

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}

void impgraph(int n, int m)
{
    int i, u, v;
    while (m--)
    {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (a[v])
        {
        }
        dfs(v, 0);
    }
}

Measured memory_bytes: 11444
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N=0,x=0,y=0;
	int price=800;
	scanf("%i",&N);
	if(N>=1 && N<=100){
		 x=price*N;
		 if(N>=15){
		 	for(int i=15;i<=N;i+=15)
		 		y+=200;
		 }
	}
	printf("%i",x-y);
}

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

int main() {
  int n, cnt=0;
  cin>>n;
  
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      if(i*j==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  
  cout<<"No"<<endl;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";
/*
class Compare
{
  public:
    bool operator()(pi a,pi b)
    {
      if(a.first<b.first || (a.first==b.first && a.second>b.second))
        return true;
      return false;
    }
};
*/
int main() 
{
  ll n;
  cin>>n;
  int num=n%10;
  if(num==2 ||num==4||num==5||num==7||num==9)
    cout<<"hon\n";
  else if(num==0 ||num==1||num==6||num==8)
    cout<<"pon\n";
  else if(num==3)
    cout<<"bon\n";
  return 0;
}






























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

int main(){
    ll n;
    cin >> n;
    vector<ll> data(n);
    vector<ll> a(1000000,0);
    ll count=0;
    map<ll,ll> hindo;
    for(int i=0;i<n;i++){
        cin >> data[i];
    }
    for(int i=0;i<n;i++){
        if(n>=data[i])
        a[data[i]+i]++;
    } 
    for(int i=0;i<n;i++){
        if(i>data[i])
        count+=a[i-data[i]];
    } 
    cout << count << endl;
    return 0 ;
}

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

#define         eps         10e-9
#define         pi          2*acos(0)
#define         P1          1e9+7
#define         P2          1e9+9
#define         lli         long long int

using namespace std;

///ISNNJB

/**int fx[]={+1,-1,+0,+0};
int fy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};*/

int main()
{
    /***freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b+c)>=22)
        cout<<"bust"<<endl;
    else
        cout<<"win"<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define exchange(a,b) do{__typeof(a) __t; __t=a; a=b; b=__t;}while(0)
#define parent(i) (i/2)
#define left(i) (i*2)
#define right(i) (i*2+1)
#define MAX_N 2000002

int N;
int heap[MAX_N];

void maxHeapify(int A[], int i) {
  int l = left(i);
  int r = right(i);
  int largest;
  if(l <= N && A[l] > A[i]) {
    largest = l;
  } else {
    largest = i;
  }
  if(r <= N && A[r] > A[largest]) {
    largest = r;
  }
  if(largest != i) {
    exchange(A[i], A[largest]);
    maxHeapify(A, largest);
  }
}

void heapIncreaseKey(int A[], int i, int key) {
  if(key < A[i]) {
    // error
    printf("error\n");
  }
  A[i] = key;
  while(i > 1 && A[parent(i)] < A[i]) {
    exchange(A[i], A[parent(i)]);
    i = parent(i);
  }
}

void maxHeapInsert(int A[], int key) {
  ++N;
  A[N] = INT_MIN;
  heapIncreaseKey(A, N, key);
}

int heapExtractMax(int A[]) {
  if(N < 1) {
    printf("heap under flow\n");
  }
  int max = A[1];
  A[1] = A[N];
  N = N-1;
  maxHeapify(A, 1);
  return max;
}


int main() {
  int i;
  char str[128];
  int key;
  N = 0;
  while(scanf("%s", str)) {
    if(str[2] == 's') { // insert
      scanf("%d", &key);
      maxHeapInsert(heap, key);
    } else if(str[2] == 't') { // extract
      printf("%d\n", heapExtractMax(heap));
    } else { // end
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll sum = 0, n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum;
}


Measured memory_bytes: 3620
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n = INT()
    s = input()
    l = [0] * (n + 1)

    for i in range(n):
        if s[i] == "I":
            l[i] = l[i-1] + 1
        else:
            l[i] = l[i-1] - 1
    print(max(l))
if __name__ == "__main__":
    main()




Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
long long a[200001];
int main()
{
	long long n;
	cin>>n;
	long long ans=0;
	long long lot=n;
	int k=0;
	while(1)
	{
		 lot/=2;
		 ans+=pow(2,k);
		 k++;
		 if(lot<1)
		 break;
	}
	cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
 
#define ll long long
#define MP make_pair

int main(void){
    ll int x, ans=0, tmp;
    cin >> x;
    if(x%11==0) tmp=0;
    else if(x%11 >= 1 && x%11 <= 6) tmp=1;
    else tmp=2;
    cout << (x/11)*2+tmp << endl; 
    return 0;
}

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

using namespace std;
typedef long long ll;


int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int ans=0;
  for(int i=0;i!=N;i++){
    if(s[i]=='R'){
      ans++;
    }
    else{
      ans--;
    }
  }
  if(ans>0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e5+7;


int  main()
{
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    ll pos;
    for(i=1;i<=5;i++)
    {
        cin>>m;
        if(m==0)
        {
            pos=i;
        }
    }
    cout<<pos<<endl;
    return 0;
}


Measured memory_bytes: 3560
def solve_commentary():
    N, K = map(int, input().split())
    R = N - K  # 赤玉の数
    MOD = 10 ** 9 + 7
    for i in range(1, K + 1):
        if N - K + 1 >= i:
            print((combinations_count(N - K + 1, i) * combinations_count(K - 1, i - 1)) % (MOD))
        else:
            print(0)
        pass
    pass


def combinations_count(n, r):
    import math
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def ppprint(itr_obj):
    for ite in itr_obj:
        print(ite)


if __name__ == '__main__':
    # solve()
    solve_commentary()


Measured memory_bytes: 3316
#include <stdio.h>
#define D_SIZE_BUFF 200000

int main()
{
    int input = 0;
    scanf("%d", &input);

    if( 1 == input ) printf("1");
    else if( 0 == input%2) printf("0.5");
    else printf("%lf",(input/2+1.0)/(double)input);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N, C; cin >> N >> C;
    ve_vei Dif(C, vei(C)); rep(i,C) rep(j,C) cin >> Dif[i][j];
    ve_vei board(N, vei(N)); rep(i,N) rep(j,N) { cin >> board[i][j]; board[i][j]--; }

    ve_vei cnt(3, vei(C, 0));

    rep(i,N) rep(j,N) cnt[(i+j)%3][board[i][j]]++;
    
    ll res = INF;
    rep(i,C) rep(j,C) rep(k,C) {
        if(i == j or j == k or i == k) continue;
        ll temp = 0;
        rep(color, C) temp += Dif[color][i] * cnt[0][color];
        rep(color, C) temp += Dif[color][j] * cnt[1][color];
        rep(color, C) temp += Dif[color][k] * cnt[2][color];
        res = min(res, temp);
    }
    cout << res << endl;
    return 0;
}



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

using namespace std;

constexpr int maxn = 1e5 + 100;
map<int, int> nr_ops;

const int inf=1e9;
struct heap
{
    int nod,c;
    bool operator <(const heap &aux) const
    {
        return c>aux.c;
    }
};
vector<heap> g[1<<16];
priority_queue<heap> h;
int d[1<<16];

int stupid_subproblem(vector<int>& v)
{
    int lim=1<<15;
    for(int mask=1;mask<lim;mask++)
    {
        int s=0;
        for(int i=0;i<15;i++)
            if(mask&(1<<i)) s^=(i+1);
        if(s!=0) continue;
        for(int i=0;i<15;i++)
            if(mask&(1<<i))
                for(int j=i+1;j<15;j++)
                    if(mask&(1<<j))
                        for(int x=1;x<16;x++)
                        {
                            int a=(i+1)^x;
                            int b=(j+1)^x;
                            int s=1;
                            if(a!=0 && mask&(1<<(a-1))) s++;
                            if(b!=0 && mask&(1<<(b-1))) s++;
                            int mask1=mask^(1<<i)^(1<<j);
                            if(a!=0) mask1^=(1<<(a-1));
                            if(b!=0) mask1^=(1<<(b-1));
                            g[mask1].push_back({mask,s});
                        }
    }
    for(int i=0;i<lim;i++) d[i]=inf;
    h.push({0,0});
    d[0]=0;
    while(!h.empty())
    {
        int nod=h.top().nod,c=h.top().c;
        h.pop();
        if(d[nod]!=c) continue;
        for(auto vec : g[nod])
            if(d[vec.nod]> d[nod]+vec.c)
            {
                d[vec.nod]=d[nod]+vec.c;
                h.push({vec.nod,d[vec.nod]});
            }
    }
    int mask=0;
    for(int i=0;i<v.size();i++)
        mask^=1<<(v[i]-1);
    return d[mask];
}

int main(){
    //ifstream cin("file.in");
    int n;
    cin >> n;
    vector<int> v(n, 0);
    for(int i = 0, x, y, a; i < n-1; ++i){
        cin >> x >> y >> a;
        v[x] ^= a;
        v[y] ^= a; }
    for(int i = 0; i < n; ++i) nr_ops[v[i]]++;

    int rez = 0;
    vector<int> thing;
    for(auto& x : nr_ops){
        if(x.first == 0) continue;
        if(x.second % 2 == 1) thing.push_back(x.first);
        rez += x.second/2; }
    rez += stupid_subproblem(thing);
    cout << rez << endl;
    return 0; }


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

int main() {
  int N;
  cin >> N;
  //cout << M << endl;*/

  //int N = 3;
  //vector<int> vec(N);
  //string input;
  vector<int> C(4);
  for (int i = 0; i < 4; i++){
    C[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    string input;
    cin >> input;
    if(input == "AC"){
      C[0]++;
    }
    else if(input == "WA"){
      C[1]++;
    }
    else if(input == "TLE"){
      C[2]++;
    }
    else if(input == "RE"){
      C[3]++;
    }
  }

  cout << "AC x " << C[0] << endl;
  cout << "WA x " << C[1] << endl;
  cout << "TLE x " << C[2] << endl;
  cout << "RE x " << C[3] << endl;

  /*for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}


Measured memory_bytes: 3624
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        int count = 0;
        for(int i = 1; i + 1 < n; i++){
            if((p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0){
                count++;
            }
        }
        System.out.println(count);    
    }
}

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

using namespace std;

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

  int ans=0, acount=0, bcount=0, abcount=0;

  for (int i = 0; i < N; i++){
    if (s[i][0]=='B'){
      bcount++;
    }
    if (s[i][s[i].size()-1]=='A'){
      acount++;
    }
    if (s[i][0]=='B' && s[i][s[i].size()-1]=='A'){
      abcount++;
    }

    while(s[i].find("AB") != string::npos){
      int p = s[i].find("AB");
      s[i] = s[i].substr(p+2);
      ans++;
    }

  }

  if (acount < bcount) {
    ans += acount;
  }else{
    if (abcount != 0 && abcount==bcount && abcount==acount){
      ans += bcount - 1;
    }else{
      ans += bcount;
    }
  }
  
  printf("%d\n", ans);
  
}


Measured memory_bytes: 4040
h,w = gets.split.map &:to_i

hoge = []
h.times do |i|
    line = gets
    hoge[i] = line.chomp
end

h.times do |i|
    w.times do |j|
        c = hoge[i][j]
        if c == "#"
            huga = []
            if i > 0
                huga << hoge[i-1][j]
            end
            if j > 0
                huga << hoge[i][j-1]
            end
            if (i+1) <  h
                huga << hoge[i+1][j]
            end
            huga << hoge[i][j+1]
            unless huga.include?("#")
                puts "No"
                exit
            end
        end
    end
end
puts "Yes"

Measured memory_bytes: 1916
n=int(input())
a=list(map(int,input().split()))
d=[0 for i in range(n)]
for i in range(n):
  t=i-a[i]
  if t>=0:
    d[t]+=1
s=0
for i in range(n):
  t=i+a[i]
  if t<n:
    s+=d[t]
print(s)

Measured memory_bytes: 32376
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def ang(n) Array.new(n){gsmi} end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def arrays(n,num) #要素数、配列数
  ret = Array.new(num){Array.new(n)}
  n.times do |i|
    ins = gsmi
    num.times{|j| ret[j][i] = ins[j] }
  end
  ret
end
inf = Float::INFINITY
$stdin = File.open('input.txt') if File.exist?('input.txt')
n,w_max = gsmi #100, 10**9
ws,vs = arrays(n,2) #w, 10**5
ws.unshift 0
vs.unshift 0

v_max = 100001
dp = Array.new(n+1) do
  [inf] * (v_max + 1)
end
dp[0][0] = 0
(1..n).each do |i|
  v_max.times do |j|
    if(j-vs[i]>=0)
      #puts vs[i] if i==1 && j==1
      dp[i][j] = min(dp[i-1][j], dp[i-1][j-vs[i]]+ws[i])
    else
      dp[i][j] = dp[i-1][j]
    end
    #dp[i][j] = dp[i-1][j] if dp[i][j] > dp[i-1][j]
  end
end

(v_max-1).downto(0) do |j|
  if dp[-1][j]<=w_max
    puts j
    exit
  end
end


Measured memory_bytes: 93400
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
	pair<int, int> road[20000];
	int i, n, money, a, b, j = 0, kitai = 0;
	cin >> n; //road????????°
	cin >> money; //money
	while (n != 0 || money != 0) {
		for (i = 0; i < n; i++) {
			cin >> a >> b;
			road[i] = make_pair(b, a);
			kitai += a*b;//[][1]???????????????[][2]???????????????
		};
		sort(road, road + n);
		reverse(road, road + n);

		while (money > 0 && kitai > 0 ) {
			if (money >= road[j].second) {
				money -= road[j].second;
				kitai -= road[j].first * road[j].second;
				j++;
			}
			else {
				kitai -= road[j].first * money;
				money = 0;
			};
		};
		cout << kitai << endl;
		cin >> n >> money;
		kitai = 0;
		j = 0; //????????????????????????????????????????????¨????????°???????????????????????????(????????§30????????????)

	};
	return 0;
}

Measured memory_bytes: 3164