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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/04  Problem: ABC 044 D / Link: http://abc044.contest.atcoder.jp/tasks/abc044_d  ----- */


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

	// nをb進数にして、その桁和がsになるようなbは存在するか?
	LL N, S; cin >> N >> S;
	LL ans = LINF;
	function<LL(LL, LL)> f = [&](LL b, LL n) {
		if (n < b)return n;
		else return f(b, n / b) + (n % b);
	};

	for (LL b = 2; b*b <= N; b++) {
		if (f(b, N) == S) {
			ans = min(ans, b);
		}
	}

	// 大きいbに対しては2桁であるから、式変形で解ける
	// xb+y = N, x+y=S
	// x+N-xb =S, b =(x+N-S )// x

	// x=0
	if (N == S)ans = min(ans, N + 1);
	for (LL x = 1; x*x <= N; x++) {
		LL b = (x + N - S) / x;
		LL y = S - x;
		if (b > 1 && x < b && y >= 0 && y < b&& f(b, N) == S) {
			ans = min(ans, b);
		}
	}
	if (ans == LINF)ans = -1;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
import fractions
n = int(input())
a = list(map(int, input().split()))

mx = 0
gd_pos = [] # 0からiまでのgcd
gd_pos.append(a[0])
for i in range(1, n):
    gd_pos.append(fractions.gcd(gd_pos[i-1], a[i]))
gd_neg = [] # 末尾からiまでのgcd
gd_neg.append(a[-1])
a_rev = a[::-1]
for i in range(1, n):
    gd_neg.append(fractions.gcd(gd_neg[i-1], a_rev[i]))

def popped_g(i):
    if i == 0: return gd_neg[n-2]
    elif i == n-1: return gd_pos[n-2]
    else:
        return fractions.gcd(gd_pos[i-1], gd_neg[n-i-2])

ans = [popped_g(i) for i in range(n)]
print(max(ans))

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N), lsum(N + 1), rsum(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		lsum[i + 1] = __gcd(lsum[i], A[i]);
	}
	for (int i = N - 1; i >= 0; i--) {
		rsum[i] = __gcd(rsum[i + 1], A[i]);
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		res = max(res, __gcd(lsum[i], rsum[i + 1]));
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1408
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, M = map(int, input().split())
    edges = [[] for _ in range(N)]

    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edges[a].append(b)
        edges[b].append(a)

    path = deque([0])
    visited = [False] * N
    visited[0] = True

    for _ in range(N - 1):
        for to in edges[path[-1]]:
            if not visited[to]:
                path.append(to)
                visited[to] = True
                break
        for leaf in edges[path[-1]]:
            if not visited[leaf]:
                break
        else:
            break

    for _ in range(N - 1):
        for to in edges[path[0]]:
            if not visited[to]:
                path.appendleft(to)
                visited[to] = True
                break
        for leaf in edges[path[0]]:
            if not visited[leaf]:
                break
        else:
            break

    print(len(path))
    ans = [p + 1 for p in path]
    print(*ans)


sol()

Measured memory_bytes: 29424
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <set>

using namespace std;


typedef pair<string, int> P;

multimap <int, string> road[41];
set < P,less<P> > dp;

int reachable[41][41];

main(){
	int n,a,s,g,i,j,k;
	map<int, string>::iterator it;
	while(cin>>n>>a>>s>>g,n){
		memset(reachable, 0, sizeof(reachable));
		while(a--){
			int x, y;
			string lab;
			cin>>x>>y>>lab;
			road[x].insert(make_pair(y, lab));
			reachable[x][y]=1;
		}
		
		for(k=0;k<n;k++){
			reachable[k][k]=1;
			for(i=0;i<n;i++)
				for(j=0;j<n;j++)
					reachable[i][j] |= reachable[i][k] && reachable[k][j];
		}

		dp.insert( make_pair("", s) );
		string lab;
		while(s!=g){
			if(dp.empty()) break;
			s = dp.begin()->second;
			lab = dp.begin()->first;
			dp.erase(dp.begin());
			if(lab.size()>6*n) break;

			for(it=road[s].begin();it!=road[s].end();it++){
				if(!reachable[it->first][g]) continue;
				dp.insert( make_pair(lab+it->second, it->first) );
			}
		}
		if(s==g) cout << lab << endl;
		else cout << "NO" << endl;
		dp.clear();
		for(i=0;i<n;i++) road[i].clear();
	}
}

Measured memory_bytes: 1428
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    int a[100100];
    cin >> n >> m;
    rep(i, n) cin >> a[i];

    priority_queue<int> q;
    rep(i, n) q.push(a[i]);

    rep(mi, m) {
        int x = q.top();
        q.pop();
        q.push(x / 2);
    }

    int64 ans = 0;
    while(!q.empty()) {
        ans += (int64) q.top();
        q.pop();
    }

    print(ans);

    return 0;
}



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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int N, K;

ll cpow (ll b, int e)
{
    if (e == 1) return b % MOD;
    if (e == 0) return 1;

    ll v = cpow (b, e / 2);
    v = (v * v) % MOD;
    if (e & 1) v = (v * b) % MOD;
    return v;
}

ll inv (ll b)
{
    return cpow (b, MOD - 2);
}

ll fac[200100];
ll ifac[200100];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> K;
    K = min (K, N - 1);

    fac[0] = 1;
    for (int i = 1; i <= N; i++)
        fac[i] = (fac[i-1] * i) % MOD;
    ifac[N] = inv (fac[N]);
    for (int i = N - 1; i >= 0; i--)
    {
        ifac[i] = (ifac[i+1] * (i + 1)) % MOD;
    }

    ll ans = 0;
    for (int i = N - K; i <= N; i++)
    {
        // N choose i * (N - 1) choose i - 1
        ll res = fac[N] * ifac[i];
        res = ((res % MOD) * ifac[N-i]) % MOD;
        ll res2 = (fac[N-1] * ifac[i-1]) % MOD;
        res2 = (res2 * ifac[N-i]) % MOD;
        ans += (res * res2) % MOD;
    }
    cout << ans % MOD << "\n";
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int pre[5][4005];
int suf[5][4005];

map <char, int> idx;

int main()
{
	IOS
	
	int n; cin >> n;
	string s; cin >> s;
	
	idx['R'] = 0;
	idx['G'] = 1;
	idx['B'] = 2;
	
	// prefix + suffix
		pre[idx[s[0]] ][0]++;
		
		for(int i = 1; i < n; i++){
			for(int j = 0; j <= 2; j++){
				pre[j][i] = pre[j][i - 1];
			}
			pre[idx[s[i]] ][i]++;
		}
		
		suf[idx[s[n - 1]] ][n - 1]++;
		for(int i = n - 2; i >= 0; i--){
			for(int j = 0; j <= 2; j++){
				suf[j][i] = suf[j][i + 1];
			}
			suf[idx[s[i]] ][i]++;
		}
	// prefix + suffix
	
	ll total = 0;
	
	// case 1
		for(int j = 1; j < n - 1; j++){
			total += 1LL * pre[(idx[s[j]] + 1) % 3][j] * suf[(idx[s[j]] + 2) % 3][j];
			total += 1LL * pre[(idx[s[j]] + 2) % 3][j] * suf[(idx[s[j]] + 1) % 3][j];
			
			for(int i = 0; i < j; i++){
				if(2 * j - i < n and s[i] != s[j] and s[i] != s[2 * j - i] and s[j] != s[2 * j - i]){
					total--;
				}
			}
		}
	// case 1
	cout << total << endl;
}

Measured memory_bytes: 3704
import Foundation

func terms1(s:String) -> Bool {
    return s == String(s.reversed())
}

func terms2(s:String) -> Bool {
    return s.prefix((s.count - 1) / 2) == String(s.prefix((s.count - 1) / 2).reversed())
}

func terms3(s:String) -> Bool {
    return s.suffix(s.count - (s.count + 3) / 2 + 1) == s.suffix(s.count - (s.count + 3) / 2 + 1).reversed()
}



func main() {
    let s = readLine()!
    
    print(terms1(s: s) && terms2(s: s) && terms3(s: s) ? "Yes": "No")
}
main()


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

int main() {
  int n, a, b; cin >> n >> a >> b;
  int ans = 0;
  for (int i = 1; i<=n; i++) {
    int nn = i, sum = 0;
    while (nn != 0) {
      sum += nn % 10;
      nn /= 10;
    }

    if (a <= sum && sum <= b) {
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#066b
S = str(input())

S = list(S)

if len(S)==2:
    print(1)
else:
    for i in range(len(S)):
        S.pop()
        S.pop()
        if S[0:len(S)//2] == S[len(S)//2:]:
            print(len(S))
            break

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

const int N = 100010;
int n;

int main() {
	cin >> n; int ans = 0;
	for(int i = 1; i <= n; ++i) {
		int x = i, len = 0;
		while(x) ++len, x /= 10;
		if(len & 1) ++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll H , W , K; cin >> H >> W >> K;
  vector<string> field(H);
  vector<string> s(H);

  rep(i,H) cin >> field[i];
  ll ans = 0;

  rep(i , (1 << H)){
    rep(j , (1 << W)){
      s = field;

      bitset<10> bsw(i);
      bitset<10> bsh(j);
      rep(k , H){
        if(bsw.test(k)){
          rep(l , W){
            s[k][l] = 'r';
          }
        }
      }
      rep(k , W){
        if(bsh.test(k)){
          rep(l , H){
            s[l][k] = 'r';
          }
        }
      }

      ll cnt = 0;
      rep(k, H){
        rep(l ,W){
          if(s[k][l] == '#') cnt ++;
        }
      }
      if(cnt == K){
        ans ++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
N = int(input())
X = input()

l = [0] * (2*10**5+1)
ans = [0] * (2*10**5+1)
for i in range(2*10**5+1):
  l[i] = bin(i).count('1')
  
for i in range(2*10**5+1):
  x = i
  y = 0
  while x!=0:
    y += 1
    x %= l[x]
    
  ans[i] = y
  
X_count = X.count('1')
plu = X_count + 1
mi = X_count - 1
plu_res = 0
mi_res = 0
X_int = int(X,2)

for i in range(N):
  if X[i]=='0':
    continue
  else:
    plu_res += pow(2,N-i-1,plu)
    plu_res %= plu
    if mi>0:
      mi_res += pow(2,N-i-1,mi)
      mi_res %= mi
      
for i in range(N):
  if X[i]=='0':
    x = (plu_res + pow(2,N-i-1,plu)) % plu
    print(1 + ans[x])
  else:
    if mi!=0:
      x = (mi_res - pow(2,N-i-1,mi)) % mi
      print(1 + ans[x])
    else:
      print(0)

Measured memory_bytes: 77904
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a[5];
  for(int i = 0; i < 5; i++){
    cin >> a[i];
  }

  int p[5] = {0, 1, 2, 3, 4};

  int ans = INF_INT;
  do{
    int tmp = 0;
    for(int i = 0; i < 5; i++){
      if(tmp % 10 != 0){
        tmp += (10 - tmp % 10);
      }
      tmp += a[p[i]];
    }
    ans = min(ans, tmp);
  } while(next_permutation(p, p + 5));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def selectionSort a, n 
    count = 0
    for i in 0 .. n - 2
        minj = i;
        for j in i + 1 .. n - 1
            minj = j if a[j] < a[minj]
        end
        if i != minj
            temp = a[i]
            a[i] = a[minj]
            a[minj] = temp
            count += 1
        end
    end
    return count
end

n = gets.to_i
arr = gets.chomp.split.map(&:to_i)
count = selectionSort(arr, n);
puts arr.join(" ")
puts count

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

int main()
{
	int visited[2*100000 + 1] = {};
	long long int k;
	long long int n;
	int retsu[2*100000 + 1] = {};
	int A[2*100000 + 1];
	cin >> n >> k;
	for (int i = 1; i <= n; ++i)
	{
		cin >> A[i];
	}
	int now = 1;
	retsu[0] = 1;
	int counter = 1;
	int startCount;
	while(1)
	{
		if(visited[now] == 0)
		{
			visited[now] = counter;
			retsu[counter++] = A[now];
			now = A[now];
		}
		else
		{
			startCount = visited[now];
			break;
		}
	}
	counter -= 1;
	if(k < startCount)
	{
		cout << retsu[k] << endl;
	}
	else if(k >= startCount && k < counter)
	{
		cout << retsu[k] << endl;
	}
	else
	{
		cout << retsu[(k - startCount + 1)%(counter - startCount + 1) + startCount - 1] << endl;
	}
	return 0;
}

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

int ar[200007];
int cnt[2000000];

bool find(ll n)
{
  ll ok=0;
  for(int i=1; i*i<=n; i++)
  {
    if(n%i==0)
    {
      if(cnt[i])
      {
        ok++;
      }
      if(i*i==n)continue;
      if(cnt[n/i])
      {
        ok++;
      }
    }
  }
  if(ok>1)return false;
  else return true;

}

int main()
{
  ll n, i, ans=0;

  scanf("%lld",&n);

  for(i=0; i<n; i++)
  {
    scanf("%d",&ar[i]);
    cnt[ar[i]]++;
  }

  sort(ar,ar+n);
  for(i=0; i<n; i++)
  {
    if(cnt[ar[i]]>1)continue;
    if(find(ar[i]))
    {
      ans++;
    }
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 8412
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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, R;
	cin >> N >> R;
	while (N != 0) {
		vi V(N);
		REP(i, N) {
			V[i] = N-i;
		}
		REP(i, R) {
			int p, c;
			cin >> p >> c;
			vi New(N);
			int ind = 0;
			FOR(j, p - 1,p - 1 + c) {
				New[ind] = V[j];
				ind++;
			}
			REP(j, p-1) {
				New[ind] = V[j];
				ind++;
			}
			FOR(j,p-1+c,N) {
				New[ind] = V[j];
				ind++;
			}
			V = New;
		}
		cout << V[0] << endl;
		cin >> N >> R;
	}
	return 0;
}



Measured memory_bytes: 3092
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

func main() {
	s := readString()
	t := readString()
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	move := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, m+1)
		move[i] = make([]int, m+1)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if s[i] == t[j] {
				dp[i+1][j+1] = dp[i][j] + 1
				move[i+1][j+1] = 0
			} else {
				if dp[i][j+1] > dp[i+1][j] {
					dp[i+1][j+1] = dp[i][j+1]
					move[i+1][j+1] = 1
				} else {
					dp[i+1][j+1] = dp[i+1][j]
					move[i+1][j+1] = 2
				}
			}
		}
	}

	i, j := n, m
	var ans string
	for i > 0 && j > 0 {
		if move[i][j] == 0 {
			ans = string(s[i-1]) + ans
			i--
			j--
		} else if move[i][j] == 1 {
			i--
		} else {
			j--
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 155392
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
 
  int i,j,k,t,tmp;
  string s;
  int N;
  int a,b,c;
  a=b=c=0;
  cin>>s;
  N=s.length();
  for(i=0;i<N;i++){
    if(s[i]=='g'){
      if(a<b){
        a++;
        c++;
      }
      else{
        b++;
      }
    }
    else{
      if(a<b){
        a++;
      }
      else{
        b++;
        c--;
      }
    }
  }
  cout<<c<<endl;
  return 0;
}

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

int main(){
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	bool jud = true;
	rep(i, n){
		cin >> p.at(i);
		if(p.at(i) == x) jud = false;
	}

	if(jud){
		cout << x << endl;
		return 0;
	}

	sort(p.begin(), p.end());

	vector<bool> ju(102);
	rep(i, n){
		ju.at(p.at(i)) = true;
	}

//	int max_v = ju.size();
	int diff = 1000;
	int ans = 1000;
	for(int i = 0; i <= 101; i++){
		if(!ju.at(i)){
			if(abs(i-x) == diff){
				ans = min(ans, i);
			}else if(abs(i-x) < diff){
				diff = abs(i-x);
				ans = i;
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();
        int a = 0;
        for (int i = 0; i < n; i++) {
            a += sc.nextInt();
        }
        System.out.println(a < h ? "No" : "Yes");
        sc.close();

    }

}


Measured memory_bytes: 46956
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9

vector<ll> daikus(vector<vector<mp> > &g,int s){
	ll v = g.size();
	vector<ll> res(v,inf);
	priority_queue<mp,vector<mp>,greater<mp> > q;
	q.push(mp(0,s) );
	while(!q.empty()){
		mp now = q.top();
		q.pop();
		ll nn = now.second;
		ll cost = now.first;
		if( res[nn] < cost) continue;
		res[nn] = cost;
		for(int i=0;i<g[nn].size();i++){
			ll next = g[nn][i].second;
			ll nc = cost + g[nn][i].first;
			if( res[next] < cost ) continue;
			q.push( mp(nc,next) );
		}
	}
	return res;
}

int main(){
	
    ll v,e,r;
    cin>>v>>e>>r;
    vector<vector<mp> > g(v);
    for(int i=0;i<e;i++){
	ll s,t,d;
	cin>>s>>t>>d;
	g[s].push_back( mp(d,t) );
	//g[t].push_back( mp(d,s) );
    }
    vector<ll> res = daikus(g,r);
    for(int i=0;i<v;i++)if(res[i] == inf) cout<<"INF"<<endl;
    else cout<<res[i]<<endl;
	return 0;
}



Measured memory_bytes: 21480
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#define loop(i,n) for(int i = 0; i < n; i++)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define INM 1145141919;
#define VEC vector<int>
#define in push_back
#define ans(x) cout<<x<<endl
#define ll long long int 

using namespace std;

long long int dp[100][21] = { 0 };
int num[101];

int main()
{
	int n;
	cin >> n;
	loop(i, n)
	{
		cin >> num[i];
	}
	dp[0][num[0]] = 1;
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 21; j++)
		{
			if (dp[i - 1][j] != 0)
			{
				int bef = num[i];
				if (j + bef <= 20)
				{
					dp[i][j + bef] += dp[i - 1][j];
				}
				if (j - bef >= 0)
				{
					dp[i][j - bef] += dp[i - 1][j];
				}
				continue;
			}
		}
	}
	cout << dp[n - 1][0] << endl;
}

Measured memory_bytes: 3096
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val v = readLine()!!.split(" ").map { it.toInt() }
    if(v.all { it == v[0] }){
        println(n/2)
        return
    }

    val aOdd = mutableMapOf(Pair(0, 0))
    val aEven = mutableMapOf(Pair(0, 0))
    for(i in 1..n){
        val a = v[i-1]
        if(i % 2 == 0){
            if(aEven.containsKey(a)){
                aEven[a] = aEven[a]!! + 1
            }else{
                aEven[a] = 1
            }
        }
        if(i % 2 == 1){
            if(aOdd.containsKey(a)){
                aOdd[a] = aOdd[a]!! + 1
            }else{
                aOdd[a] = 1
            }
        }
    }

    val maxEven = aEven.toList().sortedBy { it.second }.let { it[it.size - 1] }
    val nextMaxEven = aEven.toList().sortedBy { it.second }.let { it[it.size - 2] }
    val maxOdd = aOdd.toList().sortedBy { it.second }.let { it[it.size - 1] }
    val nextMaxOdd = aOdd.toList().sortedBy { it.second }.let { it[it.size - 2] }
    if(maxEven.first != maxOdd.first){
        println(n - maxEven.second - maxOdd.second)
    }else{
        println(Math.min(n - maxEven.second - nextMaxOdd.second, n - nextMaxEven.second - maxOdd.second))
    }
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n;
  while (cin >> n, n){
    int table[n][n], x[n], y[n], sum = 0;
    REP(i, n){
      REP(j, n) cin >> table[i][j];
      x[i] = y[i] = 0;
    }
    REP(i, n){
      cout << setw(5) << right << table[i][0];
      x[i] = table[i][0];
      FOR(j, 1, n){
        cout << setw(5) << right << table[i][j];
        x[i] += table[i][j];
      }
      cout << setw(5) << right << x[i] << endl;
    }
    REP(i, n){
      REP(j, n) y[i] += table[j][i];
    }
    cout << setw(5) << right << y[0];
    FOR(i, 1, n) cout << setw(5) << right << y[i];
    REP(i, n) sum += x[i];
    cout << setw(5) << right << sum << endl;
  }
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int h,w;
    cin>>h>>w;
    vector<vector<int>> a;
    for(int i=0;i<h;i++){
        a.push_back(vector<int>());
        string s;
        cin>>s;
        for(int j=0;j<w;j++){
            a[i].push_back(s[j]=='.'?0:1);
        }
    }
    vector<bool> hb(h),wb(w);
    for(int i=0;i<h;i++){
        bool b=false;
        for(int j=0;j<w;j++){
            if(a[i][j]==1)b=true;
        }
        if(!b)hb[i]=true;
    }
    for(int i=0;i<w;i++){
        bool b=false;
        for(int j=0;j<h;j++){
            if(a[j][i]==1)b=true;
        }
        if(!b)wb[i]=true;
    }
    for(int i=0;i<h;i++){
        if(hb[i])continue;
        for(int j=0;j<w;j++){
            if(wb[j])continue;
            cout<<(a[i][j]==1?'#':'.');
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll gcd(ll a, ll b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int main(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    n=s.size();
    for(int i=0;i<n;i++){
        cout<<s[i]<<t[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a1 = sc.nextInt();
        int a2 = sc.nextInt();
        int a3 = sc.nextInt();
        int A = a1 + a2 + a3;

        if(A>=22){
            System.out.println("bust");
        }
        else{
            System.out.println("win");
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <iomanip>

using namespace std;

int K;

int pow_kai(int a, int n) {
  int x = 1;
  while(n > 0){
    if(n & 1) {
      x = x * a;
    }
    a = a * a;
    n >>= 1;
  }
  return x;
}

int count(int n)
{
	int cnt = 0;
	int sum = n;
	while (sum < K)
	{
		sum = sum * 2;
		cnt++;
	}

	return pow_kai(2, cnt);
}

int main()
{
	int N;
	cin >> N >> K;
    
	int sum = 0;
	int cnt = 0;
	double ans = 0;	
	vector<int> list(N);
	for (int i = 1; i <= N; i++)
	{
		ans += 1.0 / (count(i) * N);
	}

	cout << fixed;
	cout << setprecision(12) << ans << endl;

	return 0;
}

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

int main() {
  int a, b;
  char op;
  
  cin >> a >> op >> b;
  
  if(op == '+'){
    cout << a+b << endl;
  }
  else if(op == '-') {
    cout << a-b << endl;
  }
  
}


Measured memory_bytes: 256
k = int(input())
num = 0
for _ in range(k):
  num += 1
  digit = list(map(int, str(num)))
  len_digit = len(digit)
  for i in range(1, len_digit):
    if digit[-i] > min(digit[-i-1] + 1, 9):
      digit[-i-1] += 1
      digit[-i] = -1
    elif digit[-i] < digit[-i-1] - 1:
      digit[-i] = -1
  for i in range(1, len_digit):
    if digit[i] == -1:
      for j in range(i, len_digit):
        digit[j] = max(digit[j-1] - 1, 0)
      break
  num = int(''.join(map(str, digit)))
print(num)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N, M, X);
    vector<int> x(M);
    read(x);

    auto itr = lower_bound(all(x), X);
    print(min(itr - begin(x), end(x) - itr));
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
monster=sum(A)
for i in range(N):
  if A[i]<B[i]:
    B[i]=B[i]-A[i]
    A[i]=0
    if A[i+1]<B[i]:
      A[i+1]=0
    else:
      A[i+1]=A[i+1]-B[i]
  else:
    A[i]=A[i]-B[i]
print(monster-sum(A))

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

int main()
{
    int n;
    cin >> n;
    int a[n];
    int c = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
        {
            c++;
        }
    }
    cout << c;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long int (i)=(a); (i)<=(b); ++(i))
#define ll long long
double dp[3005][3005];
int n;
int main(){
	dp[0][0]=1;
	cin >> n;
	ref(i,1,n){
		double p;
		cin >> p;
		rep(j,i){
			if (dp[i - 1][j] < 1e-40)dp[i - 1][j] = 0;
			dp[i][j + 1] += dp[i - 1][j] * p;
			dp[i][j] += dp[i - 1][j] * (1-p);
		}
	}
	double res = 0.0;
	for (int i = n / 2 + 1; i <= n; i++)res += dp[n][i];
	printf("%.15f\n", res);
}

Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
// const int INF = 1e9 + 7;

void test_case() {
    int n;
    cin >> n;
    vector<int> dp(3);
    for (int day = 0; day < n; day++) {
        vector<int> new_dp(3);
        vector<int> h(3);
        for (int i = 0; i < 3; i++) cin >> h[i];

        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (i != j) new_dp[j] = max(new_dp[j], h[j] + dp[i]);
		dp = new_dp;
    }
	cout<<max({dp[0], dp[1],dp[2]})<<endl;
}

int main() {
    int t = 1;
    // cin >> t;
    while (t--) test_case();
    return 0;
}

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

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

    int r = 0, b = 0;
    for (int i = 0; i < n; i++) {
        if (s[i]=='R') r++;
        else b++;
    }
    if (r > b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define inf (ll)1e9

#define debugone(x) cout << #x << " " << x << "\n"; cout.flush();
#define debugtwo(x) cout << #x << "-------------" << "\n";for(auto &it: x) cout << it << " ";cout << "\n"; cout.flush();
#define debugthree(x, i, j) cout << #x << "------------" << "\n";cout << "from " << i << " to " << j << "\n";for(ll k=i; k<=j; k++) cout << x[k] << " ";cout << "\n"; cout.flush();



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

	int n;
	cin >> n;
	int a[n+2];

	for(int i=1; i<=n; i++){
		cin >> a[i];
	}

	a[0] = a[1];
	a[n+1] = a[n];

	int gcd[n+2][2];

	gcd[0][0] = a[1];
	gcd[n+1][0] = a[n];

	gcd[0][1] = a[1];
	gcd[n+1][1] = a[n];

	int maxi = -1;
	for(int i=1; i<=n; i++){
		gcd[i][0] = __gcd(gcd[i-1][0], a[i]);
	}


	for(int i=n; i>=1; i--){
		gcd[i][1] = __gcd(gcd[i+1][1], a[i]);
	}
	
	for(int i=2; i<n; i++){
		maxi = max(maxi, __gcd(gcd[i-1][0], gcd[i+1][1]));
	}

	maxi = max(maxi, gcd[2][1]);
	maxi = max(maxi, gcd[n-1][0]);
	cout << maxi << endl;
	return 0;	

}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int t; cin >> t;
    m[t]++;
  }
  if (n % 2 == 0 && m[0] != 0) {
    cout << 0 << '\n';
    return;
  }
  if (n % 2 == 1 && m[0] != 1) {
    cout << 0 << '\n';
    return;
  }
  int ans = 1;
  for (auto &i : m) {
    if (i.fi == 0) continue;
    if (i.sc != 2) {
      cout << 0 << '\n';
      return;
    }
    (ans *= 2) %= MOD;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 7584
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int ans = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int o = 1; o < N; o++)
	{
		for (int i = 1; i <= n; i++)
		{
			if ((a[i] > 0) && (a[i - 1] == 0)) ans++;
		}
		for (int i = 1; i <= n; i++)
			a[i] = max(0, a[i] - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]
kk = inputs[0][1]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p nn
  p kk
end

max = (nn-1)*(nn-2)/2
if kk > max
  puts "-1"
  exit
end

arr = []
(nn-1).times do |i|
  arr << "1 #{i+2}"
end

#cur = nn - 2
cur = 2
itr = cur + 1
res = max - kk
pd max
pd "res=#{res}"
while res > 0
  arr << "#{cur} #{itr}"
  res -= 1
  if(itr == nn)
    cur += 1
    itr = cur + 1
  else
    itr += 1
  end
end

puts arr.size
arr.each do |a_i|
  puts a_i
end


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int>vec(N);
  for (int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(), vec.end());
  double M=vec.at(0);
  for (int j=1;j<N;j++){
    M+=vec.at(j);
    M /= 2;
  }
  cout << M << endl;
}


Measured memory_bytes: 3756
#include<stdio.h>

int main()
{
  int a, b, i, sum;

  scanf("%d%d", &a, &b);

  sum=0;
  for(i=0;i<2;i++){
    if(a>=b){
      sum+=a;
      a--;
    }
    else{
      sum+=b;
      b--;
    }
  }

  printf("%d", sum);

  return 0;
}

Measured memory_bytes: 128
s=input()
n=len(s)
dp=[13*[0]for _ in range(n+1)]
dp[0][0]=1
mod=10**9+7
for i in range(1,n+1):
  if s[i-1]=="?":
    for j in range(13):
      for k in range(10):
        m=(j*10+k)%13
        dp[i][m]+=dp[i-1][j]
        dp[i][m]%=mod
  else:
    for j in range(13):
      m=(j*10+int(s[i-1]))%13
      dp[i][m]+=dp[i-1][j]
      dp[i][m]%=mod
print(dp[-1][5])

Measured memory_bytes: 61916
x = int(input())

if x <= 6:
    print(1)
elif 7 <= x <= 10:
    print(2)
else:
    div = x % 11
    shou = x // 11
    if div == 0:
        print(2 * shou)
    elif div <= 6:
        print(2 * shou + 1)
    else:
        print(2 * shou + 2)

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, mod;
int dp[6005][2005]; // doing number i, with j blocks of size 2 or 3

int main(){
	scanf("%d %d", &n, &mod);
	memset(dp, 0, sizeof(dp));
	dp[3 * n][0] = 1;
	for(int i = 3 * n; i > 0; i--){
		for(int j = 0; j <= min(3 * n - i, n); j++){
			// case 1: fill a hole (hole means _XX)
			dp[i - 1][j] = (dp[i - 1][j] + dp[i][j]) % mod;
			// case 2: create block of size 2
			if(i > 1 && j < n){
				dp[i - 2][j + 1] = (dp[i - 2][j + 1] + 1LL * dp[i][j] * (i - 1)) % mod;
			}
			// case 3: create block of size 3
			if(i > 2 && j < n){
				int addi = dp[i][j];
				addi = 1LL * addi * (i - 1) % mod;
				addi = 1LL * addi * (i - 2) % mod;
				dp[i - 3][j + 1] = (dp[i - 3][j + 1] + addi) % mod;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i <= n; i++){
		ans = (ans + dp[0][i]) % mod;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 47232
#include<stdio.h>

int main (){
	int x,a,b;
	scanf ("%d %d %d", &x,&a,&b);
	int n1 = x-a;
	int n2 = x-b;
	
	if (n1 < 0){
		n1=-n1;
	}
	
	if (n2<0){
		n2=-n2;
	} 
	
	if (n1<n2){
		printf("A\n");
	}
	else {
		printf("B\n");
	}
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  auto p = find(a.begin(), a.end(), 1);
  
  if(p==a.end()) cout << -1 << endl;
  else {
    int num = 0, ans = 0;
    for(int i=0; i<n; i++) {
      if(a[i]!=num+1) ans++;
      else num++;
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4028
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <string.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define rep(i,n) for (int i=0; i < (n); i++)

struct Point { int xl, yl, xr, yr; };

const int MAX_W = 50 + 3;
bool visited[MAX_W][MAX_W][MAX_W][MAX_W];  // xl, yl, xr, yr

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

int main() {
  int w,h;

  while(cin >> w >> h, w||h) {
    memset(visited, 0, sizeof(visited));

    vector<string> roomL, roomR;
    rep(i,2*h) {
      string s;
      cin >> s;
      (i % 2 == 0 ? roomL : roomR).push_back( "#" + s + "#" );
    }
    string longWall(w+2, '#');
    roomL.push_back(longWall);
    roomL.insert(roomL.begin(), longWall);
    roomR.push_back(longWall);
    roomR.insert(roomR.begin(), longWall);

    w += 2;
    h += 2;
    Point start;
    rep(y,h) rep(x,w)  if (roomL[y][x] == 'L') {
      start.xl = x;
      start.yl = y;
    }
    rep(y,h) rep(x,w)  if (roomR[y][x] == 'R') {
      start.xr = x;
      start.yr = y;
    }

    queue<Point> que;
    que.push(start);
    while(!que.empty()) {
      Point p = que.front();
      que.pop();

      // cout << p.xl << " " << p.yl << " " << p.xr << " " << p.yr << endl;
      if (roomL[p.yl][p.xl] == '%' ^  roomR[p.yr][p.xr] == '%') continue;
      if (roomL[p.yl][p.xl] == '%' && roomR[p.yr][p.xr] == '%') goto yes;

      rep(i,4) {
        int nxl = p.xl + dx[i];
        int nyl = p.yl + dy[i];
        int nxr = p.xr - dx[i];  // reflect
        int nyr = p.yr + dy[i];

        if (roomL[nyl][nxl] == '#') nxl = p.xl, nyl = p.yl;
        if (roomR[nyr][nxr] == '#') nxr = p.xr, nyr = p.yr;
        if (visited[nxl][nyl][nxr][nyr]) continue;

        visited[nxl][nyl][nxr][nyr] = true;
        que.push((Point){ nxl, nyl, nxr, nyr });
      }
    }

    cout << "No" << endl;
    continue;
    yes:
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 9860
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int M;
    cin>>M;
    vector<int> h(n+10,0);
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    vector<int> m[n+10];
    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        m[a].push_back(b);
        m[b].push_back(a);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        bool flag=true;
        for(int j=0;j<m[i].size();j++){
            if(h[i]<=h[m[i][j]]){
                flag=false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout<<ans<<"\n";
    return(0);
}

Measured memory_bytes: 8784
import java.util.*;

class Main {

    static void solve (double w) {
        String res = "";

        if ( w <= 48.0 )        res = "light fly";
        else if ( w <= 51.0 )   res = "fly";
        else if ( w <= 54.0 )   res = "bantam";
        else if ( w <= 57.0 )   res = "feather";
        else if ( w <= 60.0 )   res = "light";
        else if ( w <= 64.0 )   res = "light welter";
        else if ( w <= 69.0 )   res = "welter";
        else if ( w <= 75.0 )   res = "light middle";
        else if ( w <= 81.0 )   res = "middle";
        else if ( w <= 91.0 )   res = "light heavy";
        else                    res = "heavy";

        System.out.println(res);

    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()) {
            double weight = sc.nextDouble();
            solve(weight);
        }

    }
}

Measured memory_bytes: 12000
n = int(input())
ans = [61, 230, 865, 3247, 12185, 45719, 171531, 643550, 2414454, 9058467, 33985227, 127504505, 478366600, 794717734, 733354121, 261943303, 776803305, 580025381, 51688048, 44657419, 737209731, 604119499, 159693437, 858533109, 639056669, 549054109, 996291083, 531294469, 23314687, 783022045, 855462856, 649970414, 68697295, 409213624, 604356692, 88638656, 978442997, 534833116, 763737161, 785892908, 123883652, 639213333, 181836645, 998121103, 124885216, 501575626, 39816123, 113468411, 799008836, 775465589, 256852905, 664630886, 971550783, 751629411, 51018086, 702530485, 725438992, 696683714, 792638194, 221791721, 149602322, 414054379, 986519078, 981760191, 305799096, 515140586, 406959393, 975058685, 245601370, 324759692, 673385295, 191483611, 570246669, 427196161, 781042769, 569725155, 842176273, 25328739, 847501730, 206282374, 353770801, 323137024, 371653459, 940737264, 123820509, 915711339, 847205021, 252858375, 718889563, 866398347, 738390145, 133009077, 333099663, 170591295, 329869205, 616680192, 597534442, 388130742]
print(ans[n - 3])


Measured memory_bytes: 3064
def main():
    s = input()
    mod = 10 ** 9 + 7
    table1 = [0] * 13
    table2 = [0] * 13
    table1[0] = 1
    pre = [[((10 * i + j) % 13) for j in range(10)] for i in range(13)]

    for l in s:
        for i in range(13):
            q = table1[i] % mod
            if q == 0:
                continue
            if l == '?':
                for k in pre[i]:
                    table2[k] += q
            else:
                k = (10 * i + int(l)) % 13
                table2[k] += q

        table1 = table2
        table2 = [0] * 13

    print(table1[5] % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188