akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

const int mx = 106001;

int func(vector<int> vec, int n, int p)
{
  int r = 0, q, l = vec.size(), t;
  map<int,int> mpp1;
  map<int, bool> mpp2;
  set<int> stt;

  for(q = 0;vec[q] <= n && q < l; q++);

  for(int i = 0; i < p && i+q < l; i++){
    for(int j = i; j < p && j+q < l; j++){
      t = vec[i+q] + vec[j+q];
      if(!mpp2[t]){
	mpp2[t] = true;
	mpp1[t] = 1;
	stt.insert(t);
      } else {
	mpp1[t]++;
      }
    }
  }
  t = 0;
  for(set<int>::iterator it = stt.begin(); it != stt.end(); it++){
    t += mpp1[(*it)];
    if(t >= p){
      r = *it;
      break;
    }
  }

  return r;
}

int main()
{
  int n, p;
  bool a[106001];
  vector<int> vec;
  fill(a, a+mx, true);
  a[0] = a[1] = false;

  for(int i = 2; i < mx; i++){
    if(a[i]){
      vec.push_back(i);
      for(int j = i+i; j < mx; j+=i){
	a[j] = false;
      }
    }
  }

  while(cin>>n>>p && (n+p) > -1){
    cout << func(vec, n, p) << endl;
  }

  return 0;
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))

h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]


bad_tenbo_list = [0] * (n)
for a,b in ab:
    if h[a-1] > h[b-1]:
        bad_tenbo_list[b-1]=1
    elif h[a-1] < h[b-1]:
        bad_tenbo_list[a-1]=1
    else:
        bad_tenbo_list[a-1]=1
        bad_tenbo_list[b-1]=1

print(n-sum(bad_tenbo_list))

Measured memory_bytes: 31944
// 貪欲法2

// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

struct State {
    vi last;
    vi ans;
};

int D;
int c[26];
int s[366][26];
State state[26];

ll calc(vi& ans) {
    ll score = 0;
    vi last(26);
    forn1(i, D) {
        int t = ans[i - 1];

        last[t] = i;

        score += s[i][t];
        forn(j, 26) {
            score -= (i - last[j]) * c[j];
        }
    }

    return max(TEN(6) + score, 0LL);
}

int main() {
    fastio();

    cin >> D;
    forn(i, 26) cin >> c[i];
    forn1(i, D) forn(j, 26) cin >> s[i][j];

    forn(i, 26) {
        state[i].last = vi(26, 0);
    }

    forn1(i, D) {

        forn(si, 26) {
            ll v = LLONG_MIN;
            int ans = -1;

            State& st = state[si];
            forn(j, 26) {
                ll x = s[i][j];

                forn(k, 26) {
                    if (k != j) {
                        x -= (i - st.last[k]) * c[k];
                    }
                }

                if (v < x) {
                    v = x;
                    ans = j;
                }
            }

            st.last[ans] = i;
            st.ans.push_back(ans);
        }
    }

    int ansi = 0;
    ll score = -1;
    forn(i, 26) {
        if (score < calc(state[i].ans)) {
            ansi = i;
        }
    }

    for (int x : state[ansi].ans) {
        cout << x + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 266,inf=0x3f3f3f3f;
int n,dis[N][N],col[N],res;
void dfs(int u, int c){
	col[u]=c;
	rep(i,1,n)if(dis[u][i]<inf)
		if(col[i]==-1)dfs(i,c^1);
		else if(col[u]==col[i]){puts("-1");exit(0);}
}
int main() {
	read(n);rep(i,1,n){
		char t[N];scanf("%s",t+1);
		rep(j,1,n)dis[i][j]=t[j]=='1'?1:inf;
	}
	memset(col,-1,sizeof(col));
	dfs(1,0);
	rep(i,1,n)dis[i][i]=0;
	rep(k,1,n)rep(i,1,n)rep(j,1,n)
		umin(dis[i][j],dis[i][k]+dis[k][j]);
	rep(i,1,n)rep(j,1,n)umax(res,dis[i][j]);cout<<res+1;
	return 0;
}


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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	string str1,str2;
	int cnt=0,i;
	cin >> str1 >> str2;
	for(i=0;i<str1.size();i++)
	{
		if(str1[i]!=str2[i])
			cnt++;
	}
	cout << cnt << endl;
}

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	cin >> s;
	map<char, int>mp;
	for (auto c : s)mp[c]++;
	if (mp['x'] < 8){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
  int val,chg,i,sum;

  for(;;){
    sum=0;
    scanf("%d", &val);
    if(val==0) break;

    chg=1000-val;
    if(chg>=500){
      sum++;
      chg=chg-500;
    }
    if(chg>=100){
      for(;chg>=100;){
	sum++;
	chg=chg-100;
      }
    }
    if(chg>=50){
      sum++;
      chg=chg-50;
    }
    if(chg>=10){
      for(;chg>=10;){
	sum++;
	chg=chg-10;
      }
    }
    if(chg>=5){
      sum++;
      chg=chg-5;
    }
    if(chg>=1){
      for(;chg!=0;){
	sum++;
	chg=chg-1;
      }
    }

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

  return 0;
}


Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
long long power(int x, int y){
  int calc = 1;
  rep(i, y) calc *= x;
  return calc;
}

int n;
long long a[301][301];

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

  bool flag = true;

  cin >> n;
  rep(i, n){
    rep(j, n){
      cin >> a[i][j];
    }
  }

  ll len = 0;
  for (int i = 0; i - 1 < n; i++){
    for (int j = i + 1; j < n; j++) {
      ll mini = LLONG_MAX;
      for (int k = 0; k < n; k++){
        if (i == k || j == k) continue;
        mini = min (mini, a[i][k] + a[k][j]);
      }

      if (mini < a[i][j]) {
        flag = false;
        break;
      }
      if (mini > a[i][j]) {// 分枝か連続
        len += a[i][j];
      }
      //if (!flag) break;
    }
    if (!flag) break;
  }

  /*int len = 0;
  rep(i, n) {
    len += a[i][i + 1];
  }*/
  if (flag){
    cout << len << '\n';
  } else {
    cout << -1 << '\n';
  }

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
struct UnionFind{
    vector<int>par,sz;
    UnionFind(int n): par(n),sz(n,1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int i){
        if(i == par[i])return i;
        else return par[i] = find(par[i]);
    }
    void unite(int i,int j){
        i = find(i);
        j = find(j);
        if(i==j)return;
        if(sz[i] < sz[j])swap(i, j);
        sz[i] += sz[j];
        par[j] = i;
    }
    int size(int i){
        return sz[find(i)];
    }
};
int main(){
    int n, k;
    cin >> n >> k;
    int a[3];
    for(auto &&e : a)cin >> e;
    UnionFind uf(n);
    string t;
    cin >> t;
    for(int i = k; i < n; i++){
        if(t[i] == t[i-k]){
            uf.unite(i, i-k);
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(uf.find(i) == i){
            if(t[i] == 'p'){
                t[i]++;
            }
            ans += (uf.size(i) + 1) / 2 * a[(t[i] + 2) % 3];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, n) for(int i = n-1; i >= 0; i--)
#define rep4(i, x, n) for(int i = x; i > n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

ll gcd(ll x, ll y){
    ll a = max(x, y);
    ll b = min(x, y);
    while(b > 0){
        ll s = a%b;
        ll t = b;
        a = t;
        b = s;
    }
    return a;
}

int main(){
    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    ll g = gcd(N, M);
    ll n = N/g;
    ll m = M/g;
    bool able = true;
    rep(i, g){
        if(S[i*n] != T[i*m]) able = false;
    }
    if(able) cout << N*M/g << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
    int n, m = 0;
    std::vector<std::vector<int>> conn;
    std::vector<int> cond;
    cin >> n >> m;
    for(int i = 0; i < m; ++i)
    {
        int k = 0;
        cin >> k;
        conn.push_back({});
        for(int j = 0; j < k; ++j)
        {
            int s = 0;
            cin >> s;
            conn[i].push_back(s);
        }
    }
    for(int i = 0; i < m; ++i)
    {
        int p = 0;
        cin >> p;
        cond.push_back(p);
    }

    vector<vector<int>> patterns;
    int num = pow(2, n);
    for(int i = 0; i < num; ++i)
    {
        int x = i;
        vector<int> pattern;
        for(int j = 0; j < n; ++j)
        {
            if (x&1) 
            {
                pattern.push_back(1);
            }
            else
            {
               pattern.push_back(0);
            }
            x >>= 1;  
        }
        patterns.push_back(pattern);
    }
    int satnum = 0;
    for(vector<int> p : patterns)
    {
        bool unsat = false;
        for(int i = 0; i < m; ++i)
        {
            auto c = conn[i];
            auto sum = 0;
            for(int s : c)
            {
                if(p[s - 1] == 1)
                {
                    ++sum;
                }
            }
            if(cond[i] != (sum % 2))
            {
                unsat = true;
                break;
            }
        }
        if(!unsat)
        {
            ++satnum; 
        }
    }
    cout << satnum;

    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#define ll long long
#define MOD(x) ((x)>=mod?(x)-mod:(x))
using namespace std;
const int maxn=500010, mod=1e9+7;
struct tjm{int too, pre;}e[maxn<<1];
struct poi{int f[3];};
int n, x, ans, tot, tott;
int last[maxn], root[maxn];
vector<poi>q[maxn];
inline void read(int &k)
{
    int f=1; k=0; char c=getchar();
    while(c<'0' || c>'9') c=='-' && (f=-1), c=getchar();
    while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
    k*=f;
}
inline void add(int x, int y){e[++tot]=(tjm){y, last[x]}; last[x]=tot;}
inline int merge(int x, int y)
{
    if(q[x].size()<q[y].size()) swap(x, y);
    int nx=q[x].size()-1, ny=q[y].size()-1;
    for(int i=0;i<=ny;i++) 
    {
        int sum0=0, sum1=0, sum2=0;
        sum0=1ll*q[x][nx-i].f[0]*q[y][ny-i].f[0]%mod;
        sum1=(1ll*q[x][nx-i].f[1]*q[y][ny-i].f[0]+1ll*q[x][nx-i].f[0]*q[y][ny-i].f[1])%mod;
        for(int j=0;j<3;j++)
            for(int k=2;j+k>=2;k--)
                sum2=(1ll*sum2+1ll*q[x][nx-i].f[j]*q[y][ny-i].f[k])%mod;
        q[x][nx-i].f[0]=sum0; q[x][nx-i].f[1]=sum1; q[x][nx-i].f[2]=sum2;
    }
    q[y].clear(); return x;
}
void dfs(int x, int fa)
{
    if(!last[x]) root[x]=++tott; int dep=0;
    for(int i=last[x], too;i;i=e[i].pre)
    if((too=e[i].too)!=fa)
    {
        dfs(too, x);
        if(!root[x]) root[x]=root[too];
        else dep=max(dep, (int)min(q[root[x]].size(), q[root[too]].size())), root[x]=merge(root[x], root[too]);
    }
    int nx=q[root[x]].size()-1; 
    for(int i=0;i<dep;i++) 
        q[root[x]][nx-i].f[0]=MOD(q[root[x]][nx-i].f[0]+q[root[x]][nx-i].f[2]), q[root[x]][nx-i].f[2]=0;
    poi tmp; tmp.f[1]=tmp.f[0]=(mod+1)>>1; tmp.f[2]=0; q[root[x]].push_back(tmp);
}
inline int power(int a, int b)
{
    int ans=1;
    for(;b;b>>=1, a=1ll*a*a%mod)
    if(b&1) ans=1ll*ans*a%mod;
    return ans;
}
int main()
{
    read(n);
    for(int i=1;i<=n;i++) read(x), add(x, i);
    dfs(0, -1); 
    for(int i=0;i<q[root[0]].size();i++) ans=MOD(ans+q[root[0]][i].f[1]);
    printf("%lld\n", 1ll*ans*power(2, n+1)%mod);
}

Measured memory_bytes: 44916
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class SegTree:
    """
    セグメント木
    1.update:  i番目の値をxに更新する
    2.query: 区間[l, r)の値を得る
    """

    def __init__(self, n, func, intv, A=[]):
        """
        :param n: 要素数(0-indexed)
        :param func: 値の操作に使う関数(min, max, add, gcdなど)
        :param intv: 要素の初期値(単位元)
        :param A: 初期化に使うリスト(オプション)
        """
        self.n = n
        self.func = func
        self.intv = intv
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.intv] * (n2 << 1)
        # 初期化の値が決まっている場合
        if A:
            # 1段目(最下段)の初期化
            for i in range(n):
                self.tree[n2+i] = A[i]
            # 2段目以降の初期化
            for i in range(n2-1, -1, -1):
                self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])

    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 0:
            i >>= 1
            self.tree[i] = self.func(self.tree[i*2], self.tree[i*2+1])

    def query(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        l = a + self.n2
        r = b + self.n2
        s = self.intv
        while l < r:
            if r & 1:
                r -= 1
                s = self.func(s, self.tree[r])
            if l & 1:
                s = self.func(s, self.tree[l])
                l += 1
            l >>= 1
            r >>= 1
        return s

    def get(self, i):
        """ 一点取得 """
        return self.tree[i+self.n2]

    def all(self):
        """ 全区間[0, n)の取得 """
        return self.tree[1]

N, M = MAP()
S = input()

dp = SegTree(N+1, min, INF)
dp.update(N, 0)
for i in range(N-1, -1, -1):
    # ゲームオーバーマスには遷移できない
    if S[i] == '1':
        continue
    mn = dp.query(i+1, min(N+1, i+M+1))
    if mn != INF:
        dp.update(i, mn+1)

# 辿り着けない
if dp.get(0) == INF:
    print(-1)
    exit()

cnt = dp.get(0)
cur = 0
prev = -1
ans = []
for i in range(1, N+1):
    if dp.get(i) == INF:
        continue
    # 手数が変わる場所でなるべく手前に飛ぶ
    if dp.get(i) != cnt:
        prev = cur
        cur = i
        ans.append(cur-prev)
        cnt = dp.get(i)
print(*ans)


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define M int(1e9+7)
#define endl '\n'
#define largest(a,b,c) (a>b?(a>c? a:c):(b>c? b:c))
#define smallest(a,b,c) (a<b?(a<c? a:c):(b<c? b:c))

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

struct subset{
	int rank;
	int parent;
	int size;
};

int find(int x, subset s[]){
	if(s[x].parent != x){
		s[x].parent = find(s[x].parent , s);
	}
	return s[x].parent;
}

void Union(int x, int y, subset s[]){
	int xr = find(x,s);
	int yr = find(y,s);
	if(s[xr].rank > s[yr].rank){
		s[yr].parent = xr;
		s[xr].size+=s[yr].size;
		s[yr].size = 0;
	}
	else if(s[xr].rank < s[yr].rank){
		s[xr].parent = yr;
		s[yr].size+=s[xr].size;
		s[xr].size = 0;
 	}
	else{
		s[yr].parent = xr;
		s[xr].rank++;
		s[xr].size+=s[yr].size;
		s[yr].size=0;
 	}
}



int main() {
	fast_io; cout_precision;

	int n,m;	cin >> n >> m;
	subset s[n+1];
	for(int i=1; i<=n; i++){
		s[i].parent = i;
		s[i].rank = 0;
		s[i].size = 1;
	}
	for(int i=0; i<m; i++){
		int a,b;	cin >> a >> b;
		if(find(a,s) != find(b,s))	Union(a,b,s);
	}
	int res = 0;
	for(int i=1; i<=n; i++){
		if(s[i].parent == i)	res = max(res , s[i].size);
	}
	cout << res <<endl;

	return 0;
}


Measured memory_bytes: 5996
const log = console.log;

const parseLines = (s: string) => s.trim().split("\n");

const dictionarySorter = (strA: string, strB: string) =>
  strA.localeCompare(strB);

const dictionarySorterReversed = (strA: string, strB: string) =>
  strB.localeCompare(strA);

const sortCharacters = (
  str: string,
  sorter?: (strA: string, strB: string) => number
) =>
  str
    .split("")
    .sort(sorter || dictionarySorter)
    .join();

// ----

function Main(input: string): void {
  const [s, t] = parseLines(input);

  const sortedS = sortCharacters(s, dictionarySorter);
  const sortedT = sortCharacters(t, dictionarySorterReversed);

  log(sortedS.localeCompare(sortedT) < 0 ? "Yes" : "No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11596
#include<bits/stdc++.h>
#define LL long long

using namespace std;
const int N=5e5+10,M=1e8+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<1],nt[N<<1],dg[N],hd[N],tot=1;
void adde(int x,int y){++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot,++dg[y];}
int n,m,a[N],an[N];
int mi[N<<2];
void psup(int o){mi[o]=min(mi[o<<1],mi[o<<1|1]);}
void modif(int o,int l,int r,int lx,int x)
{
    if(l==r){mi[o]=x;return;}
    int mid=(l+r)>>1;
    if(lx<=mid) modif(o<<1,l,mid,lx,x);
    else modif(o<<1|1,mid+1,r,lx,x);
    psup(o);
}
int quer(int o,int l,int r,int ll,int rr)
{
    if(ll>rr) return n+1;
    if(ll<=l&&r<=rr) return mi[o];
    int an=n+1,mid=(l+r)>>1;
    if(ll<=mid) an=min(an,quer(o<<1,l,mid,ll,rr));
    if(rr>mid) an=min(an,quer(o<<1|1,mid+1,r,ll,rr));
    psup(o);
    return an;
}
void bui(int o,int l,int r)
{
    if(l==r){mi[o]=n+1;return;}
    int mid=(l+r)>>1;
    bui(o<<1,l,mid),bui(o<<1|1,mid+1,r);
    psup(o);
}
struct node
{
    int x;
    bool operator < (const node &bb) const {return a[x]>a[bb.x];}
};
priority_queue<node> q;

int main()
{
    n=rd(),m=rd();
    for(int i=1;i<=n;++i) a[rd()]=i;
    bui(1,1,n);
    for(int i=n;i;--i)
    {
	int n1=quer(1,1,n,max(a[i]-m+1,1),a[i]-1),n2=quer(1,1,n,a[i]+1,min(a[i]+m-1,n));
	if(n1<=n) adde(i,n1);
	if(n2<=n) adde(i,n2);
	modif(1,1,n,a[i],i);
    }
    for(int i=1;i<=n;++i)
	if(!dg[i]) q.push((node){i});
    for(int h=1;h<=n;++h)
    {
	int x=q.top().x;
	q.pop();
	an[a[x]]=h;
	for(int i=hd[x];i;i=nt[i])
	{
	    int y=to[i];
	    --dg[y];
	    if(!dg[y]) q.push((node){y});
	}
    }
    for(int i=1;i<=n;++i) printf("%d\n",an[i]);
    return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll k; cin >> k;
  vector<ll> ans(50);
  rep(i, 50) ans[i] = k/50+i;
  rep(i, k%50) ++ans[49-i];
  cout << 50 << endl;
  line_out(ans);
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(void){
    
    int i,j;
    int n;
    int data1,data2;
    int point1,point2;
    
    while(1){
        point1=0;
        point2=0;
        
    scanf("%d",&n);
        if(n==0)break;
    for(i=0;i<n;i++){
        scanf("%d %d",&data1,&data2);
        if(data1>data2){
            point1+=data1+data2;
        }
        else if(data1<data2){
            point2+=data1+data2;
        }
        else{
            point1+=data1;
            point2+=data2;
        }
    }
    printf("%d %d\n",point1,point2);
    }
    return(0);
}

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

/** Problem0075 : BMI **/
int main()
{
	int stnum, output=0;
	double weight, height;
	char comma;
	
	while (1) {
		cin >> stnum >> comma >> weight >> comma >> height;
		if (cin.eof()) break;
		if (weight / (height*height) >= 25) {
			cout << stnum << endl;
			output=1;
		}
	}
	if (output==0)
		cout << "該当なし" << endl;
	
	return 0;
}

Measured memory_bytes: 1232
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=[0]*(int(1e5)+9)
    s=0
    for i in range(0,n) :
        s+=a[i]
        cnt[a[i]]+=1
    q=int(input())
    for q in range(0,q) :
        b,c=map(int,input().split())
        ct=cnt[b]
        s+=ct*(c-b)
        cnt[b]=0
        cnt[c]+=ct
        print(s)

solve()


Measured memory_bytes: 20888
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();
	 
	int x, y;
	cin >> x >> y;
	if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)){
		cout << "Yes" << endl;
		return 0;
	}
	if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11)){
		cout << "Yes" << endl;
		return 0;
	}
	else
		cout << "No" << endl;
}

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

int main(){
	ll x,y; cin >> x >> y;
	ll ans = 0;
	while(y >= x){
		x *= 2;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    string s, t;
    cin >> s >> t;

    vector< vector<ll> > index_s(26);
    //vector< vector<ll> > index_t(26);

    vector <ll> cnt_s(26);
    for(int i = 0; i < s.size(); i++){
        cnt_s[s[i] - 'a'] ++;
        index_s[s[i] - 'a'].push_back(i);
    }
    for(int i = 0; i < 26; i++){
        sort(all(index_s[i]));
    }

    vector <ll> cnt_t(26);
    for(int i = 0; i < t.size(); i++){
        cnt_t[t[i] - 'a'] ++;
        //index_t[t[i] - 'a'].push_back(i);
    }

    for(int i = 0; i < 26; i++){
        if( ( cnt_t[i] >= 1 && cnt_s[i] == 0) ){
            cout << -1 << endl;
            return 0;
        }
    }


    if(false){
        for(int i = 0; i < 26; i++){
            bool f = false;
            for(int j = 0; j < index_s[i].size(); j++){
                cout << index_s[i][j];
                f = true;
            }
            if(f) cout << ":i "  <<  i   << endl;
        }
    }

    vector< vector<ll> > index_t(t.size());
    ll last = -1; // 前の数字の大きさ
    ll div = 0; // 塊の数
    for(int i = 0; i < t.size(); i++){
        int c = t[i] - 'a';
        bool bFlag = false;
        //cout << "c is " << (char)(c + 'a') << endl;
        auto id = upper_bound(all(index_s[c]), last );
        if(id == index_s[c].end()){
            last = index_s[c][0];
            if(DEBAG){
                cout << "last is " << last + 1<< endl;
                cout << "div ++ " << endl;
            }
            div ++;
        }
        else{
            last = *id;
        }

        /*
        for(int j = 0; j < index_s[c].size(); j++){
            if(index_s[c][j] > last){
                last = index_s[c][j];
                if(DEBAG)cout << "last is " << last + 1 << endl;
                bFlag = true;
                break;
            }
        }
        if(!bFlag){
            last = index_s[c][0];
            if(DEBAG){
                cout << "last is " << last + 1<< endl;
                cout << "div ++ " << endl;
            }
            div ++;
        }
        */
        if(DEBAG)cout << endl;
    }

    //cout << div << endl;
    cout << div * s.size() + last + 1 << endl;


}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	lli n,k;
	cin>>n>>k;

	vector<lli> a(n);

	lli sum=0;
	REP(i,0,n){
		cin>>a[i];
		sum += a[i];
	}

	/*sumの約数が答えの候補*/
	/*約数をでかい順に検討していく*/
	/*約数を割った余りでvectorにつっこんでいき、全部減らしていった後*/
	/*足しまくることでそのあまりにできればOK*/
	vector<lli> yaku;
	for(lli i=1;i*i<=sum;i++){
		if(sum%i==0){
			yaku.push_back(i);
			yaku.push_back(sum/i);
		}
	}
	sort(yaku.rbegin(),yaku.rend());

	REP(i,0,yaku.size()){
		vector<lli> div;
		lli num = yaku.at(i);
		lli divD = 0;
		if(DEBUG)cout<<"yaku="<<num<<endl;

		REP(j,0,n){
			divD += num-(a[j]%num);
			div.push_back(a[j]%num);
		}
		sort(div.begin(),div.end());
		lli divSum=0;

		if(divSum==divD && divSum<=k){
			cout<<num<<endl;
			return 0;
		}
		REP(j,0,n){
			if(DEBUG)cout<<"divSum="<<divSum<<" divD="<<divD<<endl;
			divSum += div[j];
			divD -= (num-div[j]);
			if(divSum==divD && divSum<=k){
				cout<<num<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
  cin>>s;
  int K;
  cin>>K;
  int N=s.size();
  for(int i=0;i<N-1;i++){
  if(s.at(i)!='a' &&26-(s.at(i)-'a')<=K){
  K-=(26-(s.at(i)-'a'));
    s.at(i)='a';
  }
  }s.at(N-1)=char('a'+(s.at(N-1)-'a'+K)%26);
  cout<<s<<endl;
   return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int c4 = 0;
		int codd = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			if (a % 4 == 0)
				c4++;
			else if (a % 2 != 0)
				codd++;
		}
		if (c4 >= codd || c4 + codd == n && codd - c4 == 1)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

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

using namespace std;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int c[3][3];
for (int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    cin>>c[i][j];
    }
}
int a[3]={1};
int b[3]={0};
for(int i=0;i<3;i++){
    b[i]=c[0][i]-a[0];
}
for(int j=1;j<3;j++){
    int tmp1=c[j][0]-b[0];
    int tmp2=c[j][1]-b[1];
    int tmp3=c[j][2]-b[2];
    if(tmp1==tmp2 && tmp2==tmp3){}
    else{
        cout<<"No";
        return 0;
    }
}

cout<<"Yes"<<endl;;

//system("pause");
return 0;
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[][] cnt = new int[n][m];
		char[][] arr = new char[n][m];
	
		
		for(int i = 0; i < n; ++i) {
			char[] tmp = in.next().toCharArray();
			for(int j = 0; j < m; ++j) {
				arr[i][j] = tmp[j];
				
				if(tmp[j] == '#') {
					if(i > 0) ++cnt[i - 1][j];
					if(j > 0) ++ cnt[i][j - 1];
					if(i < n - 1) ++cnt[i + 1][j];
					if(j < m - 1) ++cnt[i][j + 1];
					if(i > 0 && j > 0) ++cnt[i - 1][j - 1];
					if(i > 0 && j < m - 1) ++cnt[i - 1][j + 1];
					if(i < n - 1 && j > 0 ) ++cnt[i + 1][j - 1];
					if(i < n - 1 && j < m - 1) ++cnt[i + 1][j + 1];
				}
			}
		}
		
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < m; ++j) {
				if(arr[i][j] == '#') System.out.print("#");
				else System.out.print(cnt[i][j]);
			} System.out.println();
		}
		
	}
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
const int orzhjw=666;
int main(){
	long long n,T,ghjsb;
	cin>>n>>T;
	if(n>T)
	ghjsb=n-T;     	
	else 
	ghjsb=0;
	cout<<ghjsb<<endl;
	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

mansion = Array.new(4).map { Array.new(3).map { Array.new(10, 0) } }
n = readline.to_i
n.times do
  b, f, r, v = readline.split(' ').map(&:to_i)
  mansion[b - 1][f - 1][r - 1] += v
end
count = 0
mansion.each do |building|
  building.each do |floor|
    puts ' ' + floor.join(' ')
  end
  count += 1
  puts '#' * 20 unless count == 4
end



Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define MAXN 1000002
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod=1e9+7;

int main()
{
  fastio
  int n;
  cin>>n;
  ll sum=0;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=n;j++)
    {
      int ans=__gcd(i,j);
      for(int k=1;k<=n;k++)
      {
        int ans1=__gcd(ans,k);
        sum+=ans1;
      }
    }
  }
  cout<<sum;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
const int maxn=2e5+10;
const double pi=3.1415926535897932384626433832;
using namespace std;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
 
struct node
{
	int l,r;
	int maxi;
	node *ls,*rs;
} *root;
int x1,y1,x2,y2;
int st,xx,yy,cnt;
double ans;
int n,s=1,cntx,cnty;
vector<pii> f;
map<int,int> lsh;
int dp[maxn];
 
void init(node *p,int l,int r)
{
	p->l=l;p->r=r;p->maxi=0;
	if (l==r) return;
	p->ls=new node;
	p->rs=new node;
	
	init(p->ls,l,(l+r)>>1);
	init(p->rs,((l+r)>>1)+1,r);
	return;
}
 
int search(node *p,int l,int r)
{
	if (l>r) return 0;
	if (l<=p->l && p->r<=r) return p->maxi;
	
	int ans=0;
	if (l<=p->ls->r) ans=max(ans,search(p->ls,l,r));
	if (p->rs->l<=r) ans=max(ans,search(p->rs,l,r));
	return ans;
}
 
void add(node *p,int index,int pos)
{
	if (p->l==p->r)
	{
		p->maxi=max(p->maxi,index);
		return;
	}
	
	if (pos<=p->ls->r) add(p->ls,index,pos);
	else add(p->rs,index,pos);
	p->maxi=max(p->ls->maxi,p->rs->maxi);
	return;
}
 
int main()
{
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	scanf("%d",&n);
	st=abs(x2-x1)+abs(y2-y1);
	
	if (x1>x2)
	{
		swap(x1,x2);
		swap(y1,y2);
	}
	
	if(y1>y2)
	{
		s=-1;
		y1*=s;y2*=s;
	}
	
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&xx,&yy);
		yy*=s;
		if (x1<=xx && xx<=x2 && y1<=yy && yy<=y2)
			f.push_back(mp(xx,yy));
	}
	
	if (x1==x2 || y1==y2)
	{
		printf("%.15lf\n",(double)st*100.+(double)f.size()*(10.*pi-20.));
		return 0;
	}
	else if (!f.size())
	{
		printf("%.15lf\n",(double)st*100.);
		return 0;
	}
	
	lsh.clear();
	for(int i=0;i<f.size();i++)
		lsh[f[i].x]=0;
	cntx=0;
	for(map<int,int>::iterator ii=lsh.begin();ii!=lsh.end();ii++)
	{
		cntx++;
		ii->second=cntx;
	}
	for(int i=0;i<f.size();i++)
		f[i].x=lsh[f[i].x];
	
	lsh.clear();
	for(int i=0;i<f.size();i++)
		lsh[f[i].y]=0;
	cnty=0;
	for(map<int,int>::iterator ii=lsh.begin();ii!=lsh.end();ii++)
	{
		cnty++;
		ii->second=cnty;
	}
	for(int i=0;i<f.size();i++)
		f[i].y=lsh[f[i].y];
	
	sort(f.begin(),f.end());
	root=new node;
	init(root,1,f.size());
	for(int i=0;i<f.size();i++)
	{
		dp[i]=search(root,1,f[i].y-1)+1;
		add(root,dp[i],f[i].y);
	}
	
	cnt=0;
	for(int i=0;i<f.size();i++)
		cnt=max(cnt,dp[i]);
	
	ans=(double)st*100.;
	ans-=(20-5.0*pi)*cnt;
    if (cnt==min(x2-x1,y2-y1)+1) ans+=5*pi;
    printf("%.15lf\n",ans);
	return 0;
}

Measured memory_bytes: 30704
#include<iostream>
using namespace std;
#define MOD 1000000007
int pos[50000]={};

long long modpow(int n,int p){
	if(p==0) return 1;
	else{
		if(p%2==0) return modpow(n,p/2)%MOD*modpow(n,p/2)%MOD;
		else return n*(modpow(n,p-1)%MOD)%MOD;
	}
}

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		pos[a/2]++;
	}
	bool flag=true;
	if(n%2==0){
		for(int i=0;i<n/2;i++)
			if(pos[i]!=2) flag=false;
		if(flag) cout << modpow(2,n/2);
		else cout << 0 << endl;
	}
	else{
		if(pos[0]!=1) flag=false;
		for(int i=1;i<n/2;i++)
			if(pos[i]!=2) flag=false;
		if(flag) cout << modpow(2,n/2) << endl;
		else cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int h, w;
    cin >> h >> w;

    ll res = 1e+13;
    for(int i = 1; i < h; ++i){
        vector<ll> S(3);
        int len = h - i;
        if(len > 1){
            S[0] = (ll)i * w;
            S[1] = (ll)len / 2 * w;
            S[2] = (ll)(len - len / 2) * w;
            sort(S.begin(), S.end());
            chmin(res, S[2] - S[0]);
        }

        if(w > 1){
            S[0] = (ll)i * w;
            S[1] = (ll)len * (w / 2);
            S[2] = (ll)len * (w - w / 2);
            sort(S.begin(), S.end());
            chmin(res, S[2] - S[0]);
        }
    }
    for(int i = 1; i < w; ++i){
        vector<ll> S(3);
        int len = w - i;
        if(len > 1){
            S[0] = (ll)i * h;
            S[1] = (ll)len / 2 * h;
            S[2] = (ll)(len - len / 2) * h;
            sort(S.begin(), S.end());
            chmin(res, S[2] - S[0]);
        }

        if(h > 1){
            S[0] = (ll)i * h;
            S[1] = (ll)len * (h / 2);
            S[2] = (ll)len * (h - h / 2);
            sort(S.begin(), S.end());
            chmin(res, S[2] - S[0]);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1005];
int main()
{
	int n;
	scanf("%d", &n);
	double d = 0;
	for(int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		d += 1.0/a[i];
	}
	printf("%.12lf\n", 1.0/d);
	
}

Measured memory_bytes: 256
#include <iostream>
#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
//  int p[100000];
  for(int i = 0; i < N; i++){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end() );
  int mi = 1000000000;
  for(int i = 0; i < N - K+1; i++){
    int dt = p.at(i+K-1) - p.at(i);
    if(mi > dt){
      mi = dt;
    }      
//    cout << p.at(i) << endl;
  }
  cout << mi << endl;
  return 0;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
//cout<<fixed<<setprecision(15)<<

signed main(){
    int n; cin >> n;
    int a=sqrt(n);
    int res=INF;
    FOR(i,1,a+1){
        if(n%i==0) chmin(res,i+n/i-2);
    }
    cout<<res<<endl;
}

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

using namespace std;

const int maxn = 100010;

typedef long long ll;

int n, A[maxn], cur, res = 0;

int gcd(int x, int y) {
	if (!y) return x;
	return gcd(y, x%y);
}

int solve() {
	ll sum = 0;
	int v1 = 0, c[2];
	c[0] = c[1] = 0;
	for (int i = 1; i <= n; i++) {
		sum += A[i];
		if (A[i] == 1) v1 = 1;
		c[A[i] & 1] ++;
	}
	if (v1) {
		res = ((sum - n) & 1);
		return 1;
	} else {
		if ((sum - n) & 1) {
			res = 1;
			return 1;
		}
		if (c[1] == 1) {
			for (int i = 1; i <= n; i++) if (A[i] & 1) A[i] --;
			int d = A[1];
			for (int i = 1; i <= n; i++) d = gcd(d, A[i]);
			for (int i = 1; i <= n; i++) A[i] /= d;
			return 0;
		} else {
			res = 0;
			return 1;
		}
	}
}

int main() {
	if (n == 1) {
		if (n & 1) puts("Second");
		else puts("First");
		return 0;
	}
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
	while (!solve()) cur ^= 1;
	if (res ^ cur) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define p push_back
#define mp make_pair


int main()
{
    ll t;
    t=1;
    while(t--){
        char c;
        cin>>c;
        if(c>='A'&& c<='Z')cout<<"A"<<endl;
        else cout<<"a"<<endl;


    }

}



Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s.find("AB")!=string::npos||s.find("BA")!=string::npos)
        cout<<"Yes";
    else
        cout<<"No";
    cout<<endl;
    return 0;
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    string s1, s2;
    cin >> s1 >> s2;
    map<string, ll> m;
    cin >> m[s1] >> m[s2];
    string s3;
    cin >> s3;
    m[s3]--;
    cout << m[s1] << " " << m[s2] << '\n';
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    
    int size = s.size();
    ll ans = 0;
    ll preA = 0;
    ll aftBC = 0;
    
    
    if(size < 3){
        cout << 0 << "\n";
        return 0;
    }
    
    if(size <= 5){
        for(int i = 0; i < size - 2; i++){
            if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
                s[i] = 'B';
                s[i + 1] = 'C';
                s[i + 2] = 'A';
                ans++;
                i = -1;
            }
        }
        cout << ans << "\n";
        return 0;
    }
    
    for(int i = 0; i < size - 2; i++){
        if(i < 0) i = 0;
        //cout << i << "\n";
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
            int j = i + 3;
            for(; j < size - 1;){
                if(s[j] == 'B' && s[j + 1] == 'C'){
                    aftBC++;
                    j += 2;
                }else{
                    break;
                }
            }
            ans += (preA + 1)*(aftBC + 1);
            i = j-1;
            preA++;
            aftBC = 0;
        }else{
            if(s[i] == 'A')
                preA++;
            else
                preA = 0;
        }
        
    }
    
    cout << ans << "\n";
    return 0;
} 


Measured memory_bytes: 720
while 1:
	n=list(raw_input())
	if n==["0"]*4: break
	elif n[0]==n[1]==n[2]==n[3]:
		print "NA"
		continue
	count=0
	while 1:
		if n==["6","1","7","4"]:
			print count
			break
		l=int("".join(map(str,sorted(n)[::-1])))
		s=int("".join(map(str,sorted(n)[n.count("0"):])))
		n=list(str(l-s))
		n=["0"]*(4-len(n))+n
		count+=1

Measured memory_bytes: 4236
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){
  int N;
cin>>N;
int N_a=N;
//cout << N << endl;
int sum=0;
while(N>0){
  sum+=N%10;
  N/=10;
}
//cout << sum << endl;

//cout<<N_a%sum<< endl;
if(N_a%sum==0) cout << "Yes" << endl;
else cout << "No" << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

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

  ll qc = (N + K - 1) / K, qf = N / K;
  ll r = N % K;
  ll ans = pow(qf, 3);
  if (K % 2 == 0) {
    ans += (r >= K / 2) ? pow(qc, 3) : pow(qf, 3);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1000000007)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  ll n, k, ans=0, nm;
  cin >> n >> k;
  vector<ll> a(n), c(n, 0), r(n, 0);
  rep(i, n) cin >> a.at(i);
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j < n; j++) {
      if(a.at(i) > a.at(j)) c.at(i)++;
    }
    for(int j = 0; j < i; j++) {
      if(a.at(i) > a.at(j)) r.at(i)++;
    }
  }
  nm = (k * (k+1)) / 2;
  for(int i = 0; i < n; i++) {
    ans += (r.at(i) * ((nm-k) % mod)) % mod;
    ans += (c.at(i) * ((nm) % mod)) % mod;
  }
  cout << ans % mod;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:

};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int n = s.length();

    stack<char> stk;
    for (int i = 0; i < n; ++i) {
        if (stk.empty()) {
            stk.push(s[i]);
        } else if (stk.top() != s[i]) {
            stk.pop();
        } else {
            stk.push(s[i]);
        }
    }

    cout << n - stk.size() << "\n";

    return 0;
}

Measured memory_bytes: 512