akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,a[110],r[110];
string s[110];
bool cmp(int x,int y){
	if(s[x]!=s[y]) return (s[x]<s[y]);
    else return (a[x]>a[y]);
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i]>>a[i];
		r[i]=i;
	}
	sort(r+1,r+n+1,cmp);
	for(int i=1;i<=n;i++) cout<<r[i]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<int, int, int> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;

const int INF = 1e9;
const ll INFLL = 1e16;
const int MOD = 1000000007;
const int MAXN = 3e5;
//const ld eps = 1e-6;
const ld eps2 = 1e-9;
const int MOD2 = 998244353;
const int dosz = 5e5;
const int SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("substrcmp.in", "r", stdin);
       // freopen("substrcmp.out", "w", stdout);
#endif
}

vi g[1000000];

int keklol[2000+228][2000+228];

void solve(){
    int n;
    cin >> n;
    int x, y;
    cin >> x >> y;
    x--, y--;
    for(int i=0; i<n-1; i++){
        g[i].pb(i+1);
        g[i+1].pb(i);
    }
    g[x].pb(y);
    g[y].pb(x);

    for(int i=0; i<n; i++){
        vb used(n, false);
        vi distance(n, INF);
        distance[i] = 1;
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int v = q.front(); q.pop();
            if(used[v])
                continue;
            used[v] = true;
            for(int i:g[v]){
                if(distance[i]>distance[v]+1){
                    distance[i] = distance[v]+1;
                    q.push(i);
                }
            }
        }
        for(int j=0; j<n; j++){
            keklol[i][j] = distance[j];
        }
    }
    vi ans(n-1, 0);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(keklol[i][j])
                ans[keklol[i][j]-2]++;
        }
    }
    for(int i:ans)
        cout << i << endl;

}

signed main() {
    fast_io();
    int q = 1;
    // cout << fixed << setprecision(6);
    // cin >> q;
    // cout << 1 << endl;
    while(q--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 62592
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll n;
    cin>>n;
    ll s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    int cnt=1;
    ll a=s[0];
    for(int i=1;i<n;i++){
        if(a*2>=s[i]){
            cnt++;
            a+=s[i];
        }
        else{
            cnt=1;
            a+=s[i];
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 1024
N, P = map(int, input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = 1
for sosuu, cnt in factorization(P):
  ans *= (sosuu ** (cnt//N))
  
print(ans)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define F first
#define S second

const int MAXN = 1e4 + 10;

ll n, a[MAXN], b[MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	ll sm = 0;
	for (int i = 0; i < n; i++)
		if (b[i] < a[i]){
			sm += a[i] - b[i];
			b[i] = a[i];
		}
	for (int i = 0; i < n; i++)
		if (a[i] < b[i] && b[i]%2 != a[i]%2) {
			b[i]++;
			a[i]+=2;
		}
	for (int i = 0; i < n; i++)
		if (a[i] < b[i]) {
			ll g = min(sm, (b[i]-a[i])/2);
			a[i] += g * 2;
			sm -= g;
		}
	for (int i = 0; i < n; i++)
		if (a[i] > b[i]){
			cout << "No\n";
			return 0;
		}
	if (sm != 0)
		cout << "No\n";
	else
		cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 384
S = list(input())
a_count = 0
b_count = 0
c_count = 0
for c in S:
    if c == "a":
        a_count += 1
    elif c == "b":
        b_count += 1
    elif c == "c":
        c_count +=1
        
if max(a_count, b_count, c_count) - min(a_count, b_count, c_count) <= 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=200005,LIM=524288,mod=924844033,G=5;
int n,tot;
int h[N],ne[N<<1],to[N<<1],sz[N],p[LIM],tmp[LIM],rev[LIM],fac[N],ni[N];
int qm(int x) {return x>=mod?x-mod:x;}
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
void pre_dfs(int x,int las) {
	sz[x]=1;p[n]=qm(p[n]+1);
	for(RI i=h[x];i;i=ne[i]) {
		if(to[i]==las) continue;
		pre_dfs(to[i],x),sz[x]+=sz[to[i]];
		p[sz[to[i]]]=qm(p[sz[to[i]]]-1+mod);
	}
	if(n-sz[x]) p[n-sz[x]]=qm(p[n-sz[x]]-1+mod);
}
int ksm(int x,int y) {
	int re=1;
	for(;y;y>>=1,x=1LL*x*x%mod) if(y&1) re=1LL*re*x%mod;
	return re;
}
void NTT(int *a,int n,int x) {
	for(RI i=0;i<n;++i) if(rev[i]>i) swap(a[i],a[rev[i]]);
	for(RI i=1;i<n;i<<=1) {
		int gn=ksm(G,(mod-1)/(i<<1));
		for(RI j=0;j<n;j+=(i<<1)) {
			int t1,t2,g=1;
			for(RI k=0;k<i;++k,g=1LL*g*gn%mod) {
				t1=a[j+k],t2=1LL*g*a[j+i+k]%mod;
				a[j+k]=qm(t1+t2),a[j+i+k]=qm(t1-t2+mod);
			}
		}
	}
	if(x==1) return;
	int inv=ksm(n,mod-2);reverse(a+1,a+n);
	for(RI i=0;i<n;++i) a[i]=1LL*a[i]*inv%mod;
}
int main()
{
	int x,y,kn=1,len=0;
	n=read();
	for(RI i=1;i<n;++i) x=read(),y=read(),add(x,y),add(y,x);
	pre_dfs(1,0);fac[0]=1;
	for(RI i=1;i<=n;++i)
		fac[i]=1LL*fac[i-1]*i%mod,p[i]=1LL*p[i]*fac[i]%mod;
	ni[n]=ksm(fac[n],mod-2);
	for(RI i=n-1;i>=0;--i) ni[i]=1LL*(i+1)*ni[i+1]%mod;
	for(RI i=0;i<=n;++i) tmp[n-i]=ni[i];
	while(kn<=n+n) kn<<=1,++len;
	for(RI i=1;i<kn;++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<(len-1));
	NTT(p,kn,1),NTT(tmp,kn,1);
	for(RI i=0;i<kn;++i) tmp[i]=1LL*tmp[i]*p[i]%mod;
	NTT(tmp,kn,-1);
	for(RI i=1;i<=n;++i) printf("%lld\n",1LL*tmp[n+i]*ni[i]%mod);
	return 0;
}

Measured memory_bytes: 22528
#include <cstdio>
#include <algorithm>
using namespace std;

const int MOD = 1000000007;
int n;
int x[100003];

void proc() {
	scanf("%d", &n);
	int ans = 1, cnt = 1;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &x[i]);
		ans = (long long)ans * cnt % MOD;
		if (x[i] >= 2 * (cnt - 1) + 1) {
			++cnt;
		}
	}
	printf("%d\n", ans);
}

int main() {
	proc();
	return 0;
}

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> d){
  ll ans=0;
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      ans += d[i]*d[j];
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> d(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&d[i]);
  }
  solve(N, std::move(d));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;

int main(){
  long long l, r;
  long long m = 999999999999999999;
  cin >> l >> r;
  for(long long i = l; i < min(r, l+2019); i++){
    for(long long j = l + 1; j <= min(r, l+4038); j++){
      m = min(m, ((i%2019) * (j%2019))%2019);
    }
  }
  cout << m << endl;
  return 0;
} 


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;


int main(){
    long long X,N;
    cin >> X;
    double XX, NN;

    XX= (double) X;
    NN= (-1.0 +  sqrt(8.0*XX + 1 ) )/2.0;

    N= (long long) ceil(NN);

    cout << N << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int N,a[111],ans=0,i;
	scanf("%d",&N);
	for(i=0; i<N; i++){
		scanf("%d",&a[i]);
	}
	for(i=0; i<N-1; i++){
		// printf("%d\n",a[i]);
		// printf("%d\n",a[i]);
		if(a[i]==a[i+1]){
			a[i+1]=0;
			ans++;
		}
	}
	
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    int ans = 0;
    for (int i = 0; i < k; i++) {
        int dpr0 = 0;
        int dps0 = 0;
        int dpp0 = 0;
        for (int j = i; j < n; j += k) {
            int dpr1 = (t[j] == 's' ? r : 0) + max(dps0, dpp0);
            int dps1 = (t[j] == 'p' ? s : 0) + max(dpp0, dpr0);
            int dpp1 = (t[j] == 'r' ? p : 0) + max(dpr0, dps0);
            dpr0 = dpr1;
            dps0 = dps1;
            dpp0 = dpp1;
        }
        ans += max({dpr0, dps0, dpp0});
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
const int MAX = 3000000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


long long modpow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = (ret * x) % MOD;  
        x = (x * x) % MOD;
        n >>= 1;  
    }
    return ret;
}

int main(){
    COMinit();
    string s;
    ll k;
    cin >> k >> s;
    ll n = (ll)(s.size());
    ll ans = 0;
    for(ll i=k;i>=0;i--){
        ll res = ((modpow(26,i) * modpow(25,k-i))%MOD * COM(n+k-i-1,n-1))%MOD;
        ans = (ans + res)%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 75544
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  int a, b, c, X, Y;
  int D, G;
  char s[101][101]={};
  char sv[101]={};
  char ss[101]={};
//  char s_temp[101]={};
  char t[101]={};
//  char s[10000000000000000001]={};
//  char s[101]={};
  int len=0;
  int N, M;
  int A[20000]={};
  int B[20000]={};
  int C[20000]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int min=101;
  int cnt=0;
  int max=0;
  int ans=0;
  int str_len=0;

//  long cnt =0;
  long long A_temp;
//    int k=0;

  scanf("%d", &a, &b);
//  printf("%d %d\n",D,G);
  scanf("%s", s[0]);
  str_len=strlen(s[0]);
  for(i=1;i<a;i++){
    scanf("%s", s[i]);
 //   printf("%s\n",s[i]);
//    printf("%c %c\n",s[i-1][str_len-1],s[i][0]);
//    printf("%d\n",strncmp(&s[i-1][str_len-1],&s[i][0],1));
//    if(s[i-1][str_len] != s[i][0]){
    if(strncmp(&s[i-1][str_len-1],&s[i][0],1) != 0){
//      printf("%dlen No\n",i);
      printf("No\n");
      flag=1;
      break;
    }
    for(j=0;j<i;j++){
      if(0==strcmp(s[j],s[i])){
//      printf("cmp No\n");
      printf("No\n");
      flag=1;
      break;
      }
    str_len=strlen(s[i]);

    }
  if(flag==1) break;
  }

 if(flag==0)       printf("Yes\n");;
   
//   printf("%d\n",a-b+1);
  
return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;



int main(){
    INIT;
    int a, b; cin >> a >> b;
    if((a*b)%2 == 0) cout << "Even";
    else cout << "Odd";
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll a,b;char op;
    cin>>a>>op>>b;
    if(op=='+')
        cout<<a+b<<endl;
    else
        cout<<a-b<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

b_low=-1*(10**12)
b_high=10**12
b_low_d=sum([abs(a[i]-(b_low+2+i)) for i in range(n)])-sum([abs(a[i]-(b_low+1+i)) for i in range(n)])
b_high_d=sum([abs(a[i]-(b_high+2+i)) for i in range(n)])-sum([abs(a[i]-(b_high+1+i)) for i in range(n)])

while b_high-b_low>10:
  b_tmp=(b_low+b_high)//2
  b_tmp_d=sum([abs(a[i]-(b_tmp+2+i)) for i in range(n)])-sum([abs(a[i]-(b_tmp+1+i)) for i in range(n)])
  if b_tmp_d>0:
    b_high=b_tmp
  else:
    b_low=b_tmp

ans=10**20
for j in range(b_low,b_high):
  ans=min(ans,sum([abs(a[i]-(j+2+i)) for i in range(n)]))

print(ans)

Measured memory_bytes: 136916
from heapq import heappush, heappop

line = input()
v, e = list(map(int, line.split()))
edge = {}
edge[0] = [[0, 0]]
for _ in range(0, e):
    line = input()
    s, t, w = list(map(int, line.split()))
    if s not in edge:
        edge[s]  = [[t, w]]
    else:
        edge[s] += [[t, w]]
    if t not in edge:
        edge[t]  = [[s, w]]
    else:
        edge[t] += [[s, w]]

def solve(v, edge):
    q = []
    vtx = set([i for i in range(0, v)])
    for t, w in edge[0]:
        heappush(q, (w, 0, t))
    vn = set([0])
    en = []
    cost = 0
    while len(vn) < v:
        w = s = t = 0
        qq = []
        while q:
            w, s, t = heappop(q)
            if s in vn and t not in vn:
                s, t = t, s
                break
            if s not in vn and t in vn:
                break
        vn.add(s)
        en += [(s, t)]
        cost += w
        for t, w in edge[s]:
            heappush(q, (w, s, t))
    return cost
        
print(solve(v, edge))


Measured memory_bytes: 49112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=1145141919810364364;

#define SHEEP 1
#define WOLF -1

int main(){
	int n; cin>>n;
	string s; cin>>s;
	int a[n]={};
	for(int i=0;i<(1<<2);i++){
		rep(j,2){
			if(i>>j&1) a[j]=SHEEP;
			else a[j]=WOLF;
		}
		for(int j=1;j<=n-2;j++){
			if(s[j]=='o'){
				if(a[j]==SHEEP) a[j+1]=a[j-1];
				else a[j+1]=-a[j-1];
			}else{
				if(a[j]==SHEEP) a[j+1]=-a[j-1];
				else a[j+1]=a[j-1];
			}
		}
		bool flg1=0;
		if((s[n-1]=='o'&&a[n-1]==SHEEP)||(s[n-1]=='x'&&a[n-1]==WOLF)){
			if(a[0]*a[n-2]==1) flg1=1;
		}else{
			if(a[0]*a[n-2]==-1) flg1=1;
		}
		bool flg2=0;
		if(flg1){
			if((s[0]=='o'&&a[0]==SHEEP)||(s[0]=='x'&&a[0]==WOLF)){
				if(a[1]*a[n-1]==1) flg2=1;
			}else{
				if(a[1]*a[n-1]==-1) flg2=1;
			}
		}
		if(flg2){
			for(auto i:a){
				if(i==SHEEP) cout<<'S';
				else cout<<'W';
			}
			cout<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int sz=(1<<16)+5;
int dp[sz];
vector<int>vec[sz];
int a[17][17];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(0);   
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

  int n;
  cin>>n;

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>a[i][j];
  int lim=(1<<n)-1;
  for(int i=0;i<=lim;i++)
    for(int j=0;j<n;j++)
      for(int k=j+1;k<n;k++)
        if(((1<<j)&i)&&(i&(1<<k)))
          dp[i]+=a[j][k];

  for(int mask=0;mask<=lim;mask++)
  {
    for(int j=mask;j>0;j=((j-1)&mask))
    {
      vec[mask].push_back(j);
    }
  }

  for(int mask=0;mask<=lim;mask++)
  {
    for(auto j:vec[mask])
    {
      dp[mask]=max(dp[mask],dp[j]+dp[j^mask]);
    }
  }
  cout<<dp[lim];

// -------------------------------------Code ends here------------------------------------------------------------------
    clock_t clk;
  clk = clock();

    clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
  return 0;
}


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

int main(){
    int a, b, c, ans;
    cin >> a >> b >> c;
    vector<int> lis{a, b, c};
    sort(lis.begin(), lis.end());
    for(int i = 0; i < 3; i++){
        if (i == 0) continue;
        ans += abs(lis[i] - lis[i - 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

using namespace std;

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

	if (X >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3584
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=1e5+10;
char s[N];
void main() {
    R(s);
    int l=0,r=strlen(s)-1,ans=0;
    while ( l<r ) {
        if ( s[l]==s[r] ) {
            l++;
            r--;
        } else if ( s[l]=='x' ) {
            l++;
            ans++;
        } else if ( s[r]=='x' ) {
            r--;
            ans++;
        } else {
            W(-1);
            return;
        }
    }
    W(ans);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 384
// =====================================================================================
// 
//       Filename:  B.cpp
//        Created:  2017년 09월 08일 04시 31분 22초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  bsj0206@naver.com
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
int cnt[26];
int main(){
	string str;
	cin>>str;
	long long ans=1;
	for(int i=0;i<str.size();i++){
		ans+=i-cnt[str[i]-'a'];
		cnt[str[i]-'a']++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 640
import java.util.*;
 
public class Main {
  private static long ans = Long.MIN_VALUE;
  private static Integer[] open = new Integer[10];

  private static int N;
  private static int[][] F;
  private static int[][] P;

	public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    F = new int[N][10];
    P = new int[N][11];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
        F[i][j] = sc.nextInt();
      }
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 11; j++) {
        P[i][j] = sc.nextInt();
      }
    }

    dfs(0);
    System.out.println(ans);
  }

  private static void dfs(int i) {
    if (i == 10) {
      calc();
      return;
    }

    open[i] = 0;
    dfs(i + 1);
    open[i] = 1;
    dfs(i + 1);
  }

  private static void calc() {
    if (!Arrays.asList(open).contains(1)) return;
    long kouho = 0;
    for (int i = 0; i < N; i++) {
      int c = 0;
      for (int j = 0; j < 10; j++) {
        if (open[j] == 1 && open[j] == F[i][j]) c++; 
      }
      kouho += P[i][c];
    }
    ans = Math.max(ans, kouho);
  }

  //指定した値以上の先頭のインデックスを返す
  private static final int lowerBound(final int[] arr, final int value) {
    int low = 0;
    int high = arr.length;
    int mid;
    while (low < high) {
      mid = ((high - low) >>> 1) + low;   //(low+high)/2のオーバーフロー対策
      if (arr[mid] < value) {
        low = mid + 1;
      } else {
        high = mid;
      }
    }
    return low;
  }
 
  //指定した値より大きい先頭のインデックスを返す
  private static final int upperBound(final int[] arr, final int value) {
    int low = 0;
    int high = arr.length;
    int mid;
    while (low < high) {
      mid = ((high - low) >>> 1) + low;   //(low+high)/2のオーバーフロー対策
      if (arr[mid] <= value) {
        low = mid + 1;
      } else {
        high = mid;
      }
    }
    return low;
  }
}

Measured memory_bytes: 26672
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
///////////////////////////////////////

int main() {
	ll N, Q; cin >> N >> Q;
	vector<ll>S(N), T(N), X(N), D(Q);
	for (int i = 0; i < N; ++i) {
		cin >> S[i] >> T[i] >> X[i];
	}
	for (int i = 0; i < Q; ++i) {
		cin >> D[i];
	}
	set<pair<pair<ll, ll>, ll>>events;
	set<ll>running;
	for (int i = 0; i < N; ++i) {
		events.insert(make_pair(make_pair(S[i] - X[i], X[i]), 1));
		events.insert(make_pair(make_pair(T[i] - X[i], X[i]), 0));
	}
	for (int i = 0; i < Q; ++i) {
		if (!events.empty()) {
			while ((*events.begin()).first.first <= D[i]) {
				if ((*events.begin()).second == 1) {
					running.insert((*events.begin()).first.second);
				}
				else {
					running.erase(running.find((*events.begin()).first.second));
				}
				events.erase(events.begin());
				if (events.empty())break;
			}
		}
		ll ans;
		if (running.empty()) {
			ans = -1;
		}
		else {
			ans = *running.begin();
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 33152
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll k,t,ans=0;
    scanf("%lld%lld",&k,&t);
    ll a[t];
    rep(i,0,t){
        scanf("%lld",&a[i]);
    }
    ll ma=maxn(t,a);
    if(ma>k/2){
        ans = ( ma-(k-ma) ) -1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(100001)

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
visited = [False] * n
for _ in range(m):
    a, b = map(int, input().split())
    la = len(edges[a - 1])
    lb = len(edges[b - 1])
    edges[a - 1].append([b - 1, lb])
    edges[b - 1].append([a - 1, la])

def dfs(p, v):
    visited[v] = True
    for (i, r) in edges[v]:
        if not visited[i] and r != -1 and i != p:
            dfs(v, i)
    odd = False
    pr = -1
    for (i, r) in edges[v]:
        if i != p:
            if r != -1:
                edges[i][r][1] = -1
                odd = not odd
        else:
            pr = r
    if odd:
        edges[p][pr][1] = -1

if m % 2 == 1:
    print(-1)
else:
    dfs(-1, 0)
    for v in range(n):
        for (i, r) in edges[v]:
            if r >= 0:
                print(v + 1, i + 1)


Measured memory_bytes: 214304
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int q,max=101010;
    cin >> q ;
    vector<int> a(max,1);
    a[0] = 0, a[1] = 0;
    for (int i = 2; i < max; i++){
        if(a[i]==1){
            for (int j = i * 2; j < max; j+=i)
                a[j] = 0;
        }
    }
    vector<int> b(max, 0);
    for (int i = 0; i < max; i++){
        if(i%2==1){
            if(a[i]&&a[(i+1)/2])
                b[i] = 1;
        }
    }

    vector<int> s(max, 0);
    for(int i=0; i<max; i++)
        s[i + 1] = s[i] + b[i];
    int l, r;
    for (int i = 0; i < q;i++){
        cin >> l >> r;
        cout << s[r+1] - s[l] << endl;
    }
}

Measured memory_bytes: 4556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int sum=0;
	
	if(a!=0)
	{
		if(a>=k)
		{
			sum+=k;
			k=0;
			
		}
		else
		{
			k=k-a;
			sum+=a;
		}
	}
	if(b!=0)
	{
		if(k!=0)
		{
			if(b>=k)
			{
				k=0;
			}
			else
			{
				k-=b;
			}
		}
	}
	sum-=k;
	cout<<sum<<endl;
	
	
	return 0;	
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    ll N,M;
    cin >> N >> M;
    ll ans = 0;
    if(N*2 <= M) ans+=N,M-=N*2;
    else ans += M/2, M-=ans*2;
    
    ans += M/4;
    cout << ans << endl;

    
    
    
    

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int A, P;
    cin >> A >> P;
    int sum = A*3 + P;
    printf("%lld\n", sum / 2);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<utility>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<cinttypes>
#include<stack>
#include<ctgmath>
using namespace std;

typedef long long ll;


#define ceil(a,b)  ( !(a%b) ? a/b : a/b+1 )
#define all(a)  (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define endl '\n' 
#define debug(a) cin>>#a>>a;
//vector<ll> primes{ }

int gcd( int a, int b ) { return !a ? b : gcd( b%a, a); }
int lcm( int a, int b ) { return (a*b)/gcd(a,b); } 

int main(){
    ll n{0},d{0};
    cin>>n>>d;
    int count{0};
    while(n--){
        ll a{0},b{0};
        cin>>a>>b;
        ll result = (a)*(a) + (b)*(b);
        //cout<<"result: "<<result<<endl;
        if (result <= d*d) {
            count++;
        }
    } 
    cout<<count<<endl;
}


Measured memory_bytes: 3628
abcd = str(input())

for i in range(1<<3):
    temp = int(abcd[0])
    ans = '{}'.format(abcd[0])

    for j in range(1, 4):
        if i >> (j-1) & 1:
            temp += int(abcd[j])
            ans += '+{}'.format(abcd[j])
        else:
            temp -= int(abcd[j])
            ans += '-{}'.format(abcd[j])
    if temp ==7:
        print(ans + "=7")
        break


Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		//エラトステネスのふるい
		int MAX = 101010;
		int[] isPrime = new int[MAX];
		Arrays.fill(isPrime, 1);
		isPrime[0] = 0; isPrime[1] = 0;
		for (int i = 2; i < MAX; i++) {
			if (isPrime[i] == 0) continue;
			for (int j = i * 2; j < MAX; j += i) {
				isPrime[j] = 0;
			}
		}

		//2017likeを探す
		int[] a = new int[MAX];
		Arrays.fill(a, 0);
		for (int i = 0; i < MAX; i++) {
			if (isPrime[i] != 0 && isPrime[(i + 1) / 2] != 0) {
				a[i] = 1;
			}
		}

		//累積和
		int[] sum = new int[MAX + 1];
		sum[0] = 0;
		for (int i = 1; i < sum.length; i++) {
			sum[i] = a[i - 1] + sum[i - 1];
		}

		//クエリの処理
		int Q = sc.nextInt();
		for (int q = 0; q < Q; q++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			int ans = sum[r + 1] - sum[l];
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 65188
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
    int n, k;
    int i;
    int ans = 1;
    
    cin >> n >> k;
    
    for(i = 0; i < n; i++){
        if(i == 0)      ans *= k;
        else            ans *= k - 1;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//例31115 → 31　→ 13を算出 
int calculate(int data)
{
  int ret;
  ret = data / 1000;
  ret = (ret / 10) + (ret % 10) * 10;
  return ret;
}

int main(){
  int A, B, answer;
  cin >> A >> B;
  //100で割ったものを引いて、基本値を出す。
  //例 31415 92653→611
  answer = B/100 - A/100 - 1;
  //例 31315→31の逆13が範囲に入るか確認
  if((A % 100) <= calculate(A))
  {
    answer++;
  }
  if((B % 100) >= calculate(B))
  {
    answer++;
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238462
typedef long long ll;
typedef long double db;
ll a[200005],b[200005];
int main(){
    ll n,m,k,mx=0;cin>>n>>m>>k;
    a[0]=0;b[0]=0;
    for(ll i=1;i<=n;i++){
        cin>>a[i];a[i]+=a[i-1];
    }
    for(ll i=1;i<=m;i++){
        cin>>b[i];b[i]+=b[i-1];
    }
    ll x=n;
    for(ll i=0;i<=n;i++){
        if(a[i]>k){x=i-1;break;}
    }
    for(ll i=0;i<=m;i++){
        ll v=b[i];
        while(x>=0&&a[x]>k-v) x--;
        if(x==-1) break;
        mx=max(mx,i+x);
    }
    cout<<mx<<endl;
}
    
     

Measured memory_bytes: 6744
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  int sta  [100] = {};
  char input;
  int i=1;

  while((scanf("%s",&input)) != EOF){
    if(input >= '0' && input <= '9'){
      sta[i] = atoi(&input);
      i++;
    }
    else{
      if(input == '+'){
	sta[i-2] = (sta[i-2]) + (sta[i-1]);
      }
      else if(input == '-'){
	sta[i-2] = (sta[i-2]) - (sta[i-1]);
      }
      else if(input == '*'){
	sta[i-2] = (sta[i-2]) * (sta[i-1]);
      }
      else if(input == '\0'){
	break;
      }
      else{
	i++;
      }
      i--;
    }
  }
  
  printf("%d\n",sta[1]);
  
  return(0);
}

Measured memory_bytes: 548
n=int(input())
a=[list(map(int,input().split()))for i in range(n)]
b=[list(map(int,input().split()))for i in range(n)]
b.sort()
a=sorted(a,key=lambda x:-x[1])
d=0
for i in range(n):
    for j in range(len(a)):
        if b[i][0]>a[j][0] and b[i][1]>a[j][1]:
            d+=1
            del a[j]
            break
print(d)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main() {
  vector<int> v(3);
  int k;
  cin >> v[0] >> v[1] >> v[2];
  cin >> k;
  sort(v.begin(), v.end());
  long long ans = v[2]*pow(2, k) + v[1] + v[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int a[210];

int main(){
    cin>>n;
    for (int i=0;i<n;++i)cin>>a[i];
    
int count=0;
while (true){
    bool exist_odd=false;
    for(int i=0;i<n;++i){
        if(a[i]%2!=0)exist_odd=true;
    }
    if(exist_odd)break;

    for(int i=0;i<n;++i){
        a[i]/=2;
    }
     ++count;
}
    cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int n,x,y,i,j;
        long s;

        scanf("%d",&n);

        int d[n];

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

        s=0;
        for(i=0;i<n-1;i++){
                for(j=i+1;j<n;j++){
                        s=s+d[i]*d[j];
                }
        }

        printf("%ld",s);
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a, a + n);
    sort(b, b + n);
    ll ans = 0;
    if (n % 2 == 1) {
        ll le = a[n / 2];
        ll ri = b[n / 2];
        ans = ri - le + 1;
    } else {
        ll le = a[n / 2 - 1] + a[n / 2];
        ll ri = b[n / 2 - 1] + b[n / 2];
        ans = ri - le + 1;
    }
    cout << ans << endl;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<ll> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

int n;
double mm[310][310][310];

double f(int a, int b, int c){
	double& rt = mm[a][b][c];
	if(rt >-0.5) return rt;
	int abc = a+b+c;
	if( abc ==0) return 0;
	rt = 1.0 * n / abc;
	if(a) rt += f(a-1,b  ,c) * a / abc;
	if(b) rt += f(a+1,b-1,c) * b / abc;
	if(c) rt += f(a,b+1,c-1) * c / abc;
	return rt;
}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	cin >>n;
	memset(mm, -1, sizeof mm);
	int idt[4]={};
	rep(i,n){
		int a; cin >>a;
		idt[a-1]++;
	}
	printf("%.15f\n", f(idt[0], idt[1], idt[2]));
	return 0;
}


Measured memory_bytes: 233088
n=int(input())
xy=[map(int,input().split()) for i in range(n)]
x,y=[list(v) for v in zip(*xy)]
cnt=0
for i in range(n):
  if x[i]==y[i]:
    cnt+=1
  else:
    cnt=0
  if cnt==3:
    print('Yes')
    break
if cnt!=3:
  print('No')

Measured memory_bytes: 9212
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0

for i in range(N):
    ans += B[A[i] - 1]
    if i < N - 1:
        if A[i + 1] == A[i] + 1:
            ans += C[A[i] - 1]

print(ans)


Measured memory_bytes: 3060
//
//  main.cpp
//

// https://atcoder.jp/contests/abc117/tasks/abc117_d

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

ll N, K;
vector<ll> Ais;

ll f(ll x) {
    ll ret = 0;
    for (ll ai : Ais) {
        ret += ai ^ x;
    }
    return ret;
}

int main() {
    cin >> N >> K;
    for (int n = 0; n < N; n++) {
        ll ai;
        cin >> ai;
        Ais.push_back(ai);
    }
    int cnt[64]; // cnt[i] = Aiたちのうち第ibitが1であるものの個数
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < 64; i++) {
        for (ll ai : Ais) {
            if ((ai & ((ull)1 << i)) != 0) {
                cnt[i] += 1;
            }
        }
    }
    vector<ll> fs(64, 0);
    // fs[i] = 第(i+1)ビット以降はKと同じ、第iビットはKより小さい、第(i-1)ビット以前は任意、という条件を満たす数xに対するf(x)の最大値
    // ただしそのような数xの集合が空集合であるときは-1とする
    for (int i = 0; i < 64; i++) {
        if (((ull)K & ((ull)1 << i)) == 0) { // Kの第iビットが0のとき
            fs[i] = -1;
            continue;
        }
        ll x = 0;
        if (i < 63) {
            x += ((ull)K) & (((ull)-1) << (i+1));
        }
        // ここまで：第(i+1)ビット以降はKと同じ、第iビットはKより小さい（0）
        for (int j = i-1; j >= 0; j--) {
            // 第jビットについて
            if (2 * cnt[j] < N) { // ビットが0のものが過半数のとき
                x += (ull)1 << j;
            }
        }
        fs[i] = f(x);
    }
    ll max_fs = f(K);
    for (ll f : fs) {
        max_fs = max(max_fs, f);
    }
    cout << max_fs << endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i).first >> a.at(i).second;}
  double g;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < i;j++){
      double x;
      x = sqrt((a.at(i).first-a.at(j).first)*(a.at(i).first-a.at(j).first)+(a.at(i).second-a.at(j).second)*(a.at(i).second-a.at(j).second));
        g += x;}
  }

g = g /(n*(n-1)/2)*(n-1);
cout << fixed << setprecision(15)<<g << endl;
    
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

S = ['3', '5', '7']
n = II()
cnt = 0

def dfs(ns, cnt):
    for s in S:
        news = ''.join([ns, s])
        # print(news)
        if eval(news) > n:
            continue
        elif len(set(list(news))) != 3:
            # 3, 5, 7がそろっていない
            cnt = dfs(news, cnt)
        else:
            cnt += 1
            # print('yes', news, cnt)
            cnt = dfs(news, cnt)
    return cnt


def solve():

    ans = dfs('', 0)
    print(ans)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 3188
/**
 * Created by hiramekun at 01:18 on 2020-05-12.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */


void solve() {
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) {
        cin >> s[i];
    }

    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') continue;
            vector<vector<ll>> d(h, vector<ll>(w, ll_inf));
            d[i][j] = 0;

            ll tmp = 0;
            auto rec = [&](auto &&f, vector<P> &nxt) -> void {
                vector<P> nxt2;
                while (!nxt.empty()) {
                    ll x = nxt.back().first, y = nxt.back().second;
                    nxt.pop_back();
                    rep(k, 4) {
                        ll nx = x + dx[k], ny = y + dy[k];
                        if (nx < 0 || h - 1 < nx || ny < 0 || w - 1 < ny) continue;
                        if (s[nx][ny] == '#' || d[nx][ny] < ll_inf) continue;
                        d[nx][ny] = d[x][y] + 1;
                        tmp = max(tmp, d[nx][ny]);
                        nxt2.emplace_back(make_pair(nx, ny));
                    }
                }
                if (!nxt2.empty()) f(f, nxt2);
            };
            vector<P> now{make_pair(i, j)};
            rec(rec, now);
            ans = max(ans, tmp);
        }
    }

    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll n,k,r,s,p;
  string t;
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
  ll ans = 0;
  char pre[k];
  for(int i=0;i<k;i++) pre[i] = '*';
  for(int i=0;i<n;i++){
    ll m = i%k;
    if(pre[m] == t[i]){
      pre[m] = '*';
      continue;
    }
    else{
      pre[m] = t[i];
      if(pre[m] == 'r') ans += p;
      else if(pre[m] == 's') ans += r;
      else ans += s;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512