akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-9;
long double pi = acos(-1);

ll mod = 1e9+7;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,a,b;
    cin>>n>>a>>b;
    if(a<b)swap(a,b);
    ll s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    if(n==3){
        int ans = 0;
        for(int bit=0;bit<(1<<n);bit++){
            vector<int> va,vb;
            for(int i=0;i<n;i++){
                if((1<<i) & bit)va.push_back(i);
                else vb.push_back(i);
            }
            bool pos = true;
            if(va.size()>1){
                for(int i=1;i<va.size();i++){
                    if(s[va[i]]-s[va[i-1]]<a)pos=false;
                }
            }
            if(vb.size() > 1){
                for(int i=1;i<vb.size();i++){
                    if(s[vb[i]] - s[vb[i-1]] < b)pos=false;
                }
            }
            ans+=pos;
        }
        cout << ans << endl;
        return 0;
    }
    ll dp[n+1][2]={};
    int dif[n+1]={};
    int dif_A[n+1]={};
    dif_A[0] = 1;
    dif[0] = 1;
    for(int i=1;i<n;i++){
        dif_A[i] = dif_A[i-1] + (s[i] - s[i-1] >= a);
        dif[i] = dif[i-1] + (s[i]-s[i-1]>=b);
    }
    int pre_A[n+1]={};
    int pre_B[n+1]={};
    int now = 0;
    for(int i=0;i<n;i++){
        while(now<n && s[now]-s[i]<a){
            pre_A[now] = i;
            now++;
        }
    }
    now = 0;
    for(int i=0;i<n;i++){
        while(now<n && s[now]-s[i]<b){
            pre_B[now] = i;
            now++;
        }
    }
    dp[0][1] = 1;
    //dp[0][0] = 1;
    dp[1][0]=1;
    dp[1][1]=1;
    for(int i=1;i<n;i++){
        // B
        if(i && s[i]-s[i-1]>=b) add(dp[i+1][0],dp[i][0]);
        // if(s[i]-s[pre_B[i]-1]>=b) add(dp[i+1][0],dp[pre_B[i]][0]);
        // add(dp[i+1][0],dp[i][1]);
        // pre_B[i] made all A
        bool okB = (i==pre_B[i] || ((dif_A[i-1] - dif_A[pre_B[i]]) == i-pre_B[i]-1));
        if(okB) add(dp[i+1][0],dp[i][1]);

        // A
        // pre_A[i] ~ i -> all B
        bool ok = 0;
        ok=((dif[i-1] - dif[pre_A[i]]) == i-pre_A[i]-1); 
        if(ok) add(dp[i+1][1],dp[pre_A[i]][1]);
        //cerr << i << " " << okB << " " << pre_B[i] << " " << dif_A[i-1] << " " << dif_A[pre_B[i]] << " " << dp[i+1][1] << " " << dp[i+1][0]<< endl;
        //cerr << i << " " << ok << " " << okB << " " << pre_A[i] << " " << pre_B[i] << " " << dp[i+1][1] << " " << dp[i+1][0] << endl;
        if(pre_A[i]==0)continue;

        bool dist = dif[pre_A[i]] - dif[pre_A[i]-1];
        if(ok && dist) add(dp[i+1][1],dp[pre_A[i]][0]);
        // cerr << dist << " " << dp[i+1][1] << endl;

    }
    ll ans = (dp[n][0]+dp[n][1])%mod;
    cout << ans << endl;
}

Measured memory_bytes: 7516
#include<iostream>
#include<cstdlib>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

const int N = 8;
char m[8][9];
char op[]={'o','x'};
enum{MAMI=0,CHA=1};
int dx[]={0,0,1,-1,1,1,-1,-1};
int dy[]={1,-1,0,0,1,-1,1,-1};

void output(){
  rep(i,8)cout << m[i] << endl;
  cout <<"output end " << endl;
}

bool ok(int who,int y,int x,int i,int j){
  if (who == MAMI){
    if (y != i)return i < y;//ue
    return j < x;//hidari
  }else {
    if (y != i)return i > y;//sita
    return j > x;//migi
  }
  return false;
}

int configure(int me,int you,int y,int x,bool isCount){
  int cnt=0;
  rep(i,8){
    int nex=x+dx[i],ney=y+dy[i];
    int tmp=0;
    bool isok=false;
    while(nex != -1 && ney != -1 && nex != N && ney != N){
      if (m[ney][nex] == op[me]){isok=true;break;}
      else if(m[ney][nex] == op[you])tmp++;
      else break;
      nex+=dx[i];
      ney+=dy[i];
    }
    if (isok)cnt+=tmp;
    if (!isok)continue;
    if (isCount)continue;
    nex=x+dx[i];
    ney=y+dy[i];
    while(nex != -1 && ney != -1 && nex != N && ney != N){
      if (m[ney][nex] == op[me]){break;}
      else if(m[ney][nex] == op[you])m[ney][nex]=op[me];
      else break;
      nex+=dx[i];
      ney+=dy[i];
    }
  }
  return cnt;
}

bool canput(int who){
  int get=0,y=-1,x=-1;
  rep(i,8){
    rep(j,8){
      if (m[i][j] != '.')continue;
      int cnt=configure(who,1-who,i,j,true);
      if (cnt == 0)continue;
      if (cnt > get){
        y=i;
        x=j;
        get=cnt;
      }else if (cnt == get && ok(who,y,x,i,j)){
        y=i;
        x=j;
        get=cnt;
      }
    }
  }
  //output();
  if (get != 0)configure(who,1-who,y,x,false),m[y][x]=op[who];
  //cout << y <<" " << x <<" " << get << endl;
  //output();
  //exit(1);
  return get != 0;
}

main(){
  while(cin>>m[0]){
    REP(i,1,8)cin>>m[i];
    int now=0,fail=0;;
    while(fail < 2){
      //output();
      if (!canput(now))fail++;
      else fail=0;
      now=(now+1)%2;
      //cout << now <<" " << fail << endl;
    }
    rep(i,8)cout << m[i]<<endl;
    
#ifdef DEBUG
    cout <<"end" << endl;
#endif
  }
  return false;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(((abs(a-b) <= d) && (abs(b-c) <= d)) || abs(a-c) <= d) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
bool isPerfectSquare(long double x) {   
    long double sr = sqrt(x); 
    return ((sr - floor(sr)) == 0); 
} 
int32_t main(){
    SPEED;
    int n, k;
    cin >> n >> k;
    int arr[n];
    read(arr);
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int cal = min((2 * arr[i]), 2 * (k - arr[i]));
        ans += cal;
    }
    cout << ans ;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 5e5 + 5;
const int M = 1e9 + 7;
#define multi_case
#undef multi_case
int n,Q,r[N],c[N];
int t[N];
struct query{
    int l,r,i,a;
} q[N];
inline int lowbit(int x){return x & -x;}
void add(int x,int v) {
    while(x <= n) {
        t[x] += v;
        x += lowbit(x);
    }
}
int sum(int x) {
    int ans = 0;
    while(x) {
        ans += t[x];
        x -= lowbit(x);
    }
    return ans;
}

void pre() {
}
void solve(int _case) {
    cin >> n >> Q;
    for(int i = 1; i <= n; i++) cin >> c[i];
    for(int i = 1; i <= Q; i++) {
        int l,r;
        cin >> l >> r;
        q[i] = {l,r,i,0};
    }
    sort(q+1, q+Q+1, [](query l, query r) {return l.r < r.r;});
    int rl = 0;
    for(int i = 1; i <= Q; i++) {
        while(rl < q[i].r) {
            rl++;
            if(r[c[rl]]) add(r[c[rl]],-1);
            r[c[rl]] = rl;
            add(rl,1);
        }
        q[i].a = sum(rl) - sum(q[i].l-1);
    }
    sort(q+1, q+Q+1, [](query l, query r) {return l.i < r.i;});
    for(int i = 1; i <= Q; i++) {
        printf("%d\n", q[i].a);
    }
}
int main() {
    //freopen("data.in","r",stdin);
//    freopen("data.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    pre();
#ifdef multi_case
    cin >> t;
#else
    t = 1;
#endif
    for (int i = 1; i <= t; i++) {
//        printf("Case #%d: ",i);
        solve(i);
    }
    return 0;
}

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

int main() {
    int N;
    long Y;
    cin >> N >> Y;

    int x, y, z;
    for(x=0; x<=N; x++){
        for(y=0; y<=N; y++){
            z = (Y - x*10000 - y*5000) / 1000;
            if(0<= z and z == (N-x-y)){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 3600
abc = list(map(int, input().rstrip("\n").split()))
parities = [n % 2 for n in abc]
i = (parities.count(0) < parities.count(1))
new_abc = list()

ans = 0

if len(set(parities)) == 2:
    for num, parity in zip(abc, parities):
        if parity == i:
            num += 1
        new_abc.append(num)
    ans += 1
else:
    new_abc = abc

max_ = max(new_abc)
new_abc.remove(max_)

for num in new_abc:
    ans += (max_ - num) // 2

print(ans)


Measured memory_bytes: 38384
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int a,b;
cin>>a>>b;
int ans = -1;
FOR(i,1,100001) {
    if(i*8/100 == a && i/10 == b) {
        ans = i;
        break;
    }
}
cout<<ans;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 2000
#define INF 1000000000
vector<int> G[MAXN+5];
int u,v,n,k,ex,ans;
int dfs(int x,int fa,int deep)
{
	int sum=0;
	for(int i=0;i<G[x].size();i++)
	{
		int to=G[x][i];
		if(to==fa)continue;
		sum+=dfs(to,x,deep-1);
	}
	if(deep<=0)sum++;
	return sum;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	ans=INF;
	for(int rt=1;rt<=n;rt++)
	{
		ex=0;
		int sum=0;
		for(int i=0;i<G[rt].size();i++)
		{
			int to=G[rt][i];
			int val=dfs(to,rt,k/2);
			sum+=val;
			if(k%2)ex=max(ex,val-dfs(to,rt,k/2+1));
		}
		sum-=ex;
		ans=min(sum,ans);//
	}
	printf("%d",ans);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod=998244353;
#define mem(a,b) memset(a,b,sizeof(a))
int max(int a,int b) {return a>b?a:b;}

int main()
{
    int n,a[200],A,B;
    scanf("%d",&n);
    scanf("%d%d",&A,&B);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    int x1=0,x2=0,x3=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=A) x1++;
        else if(a[i]>B) x3++;
        else x2++;
    }
    printf("%d\n",min(x1,min(x2,x3)));
    return 0;
}



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

using namespace std;

int main() {
    //forItachi
    int n;
    cin>>n;
    vector<int> v1;
    vector<int> v2;
    vector<int> v;
    for( int i = 0 ; i < n ; i++){
        int x;
        cin>>x;
        v1.push_back(x);
    }
    for( int i = 0 ; i < n ; i++){
        int x;
        cin>>x;
        v2.push_back(x);
    }
    v.assign(v1.begin() , v1.end());
    sort(v.begin(),v.end());
    int status = 0,count1 = 0,count2 = 0 ,status1 = 0 ,status2 = 0;
    while( status != 2){
        if( status1 == 0){
        if( v == v1){
            status++;
            status1++;
        }
        else{
            count1++;
        }
        }
        if(status2 == 0){
        if( v == v2){
            status++;
            status2++;
        }
        else{
            count2++;
        }
        }
        next_permutation(v.begin(),v.end());
        
    }
    cout<<abs(count1 - count2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str, T: str, A: int, B: int, U: str):
    numA = A
    numB = B
    if U == S:
        numA -= 1
    else:  # U == T
        numB -= 1

    print(numA, numB)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    U = next(tokens)  # type: str
    solve(S, T, A, B, U)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b=parseMap(split(readline()))
    if a>8 || b>8
        println(":(")
    else
        println("Yay!")
    end
end
main()

Measured memory_bytes: 109544
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
 ll N=S.size();
  vector<ll> vec(N);
  ll k=1;
  for(ll i=0;i<N;i++) {
    vec[i]=(S[N-1-i]-'0')*k%2019;
    k*=10;
    k%=2019;
  }
  
  vector<ll> R(N);
  ll sum=0;
  for(ll i=0;i<N;i++) {
    sum+=vec[i];
    sum%=2019;
    R[i]=sum;
  }
  
 
  
  map<ll,ll> W;
  for(ll i=0;i<N;i++) {
W[R[i]]++;
  }
  ll ans=0;
  for(auto x:W) {
    ans+=x.second*(x.second-1)/2;
    if(x.first==0) {
ans+=x.second;
    }
  }
  
  cout<<ans<<endl;
}

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

  


Measured memory_bytes: 6828
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define len(x)           x.length()
#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define M                 1000000007
#define MM                998244353
#define ff                first
#define ss                second
#define pii               pair<int,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define mem0(x)           memset(x, 0, sizeof (x))
#define mem1(x)           memset(x, -1, sizeof (x))
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

//coded by Avijit Mandal 

int main(){
   IOS;
   ll t,i,j,k,n;
   string a,b,res;
   cin>>a>>b;
   ll dp[len(a)+1][len(b)+1];
   for(i=0;i<=len(a);i++){
      for(j=0;j<=len(b);j++){
         if(i==0||j==0)dp[i][j]=0;
         else
         {
            if(a[i-1]==b[j-1]) dp[i][j]=1+dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
         }
         
      }
   }
   //cout<<dp[len(a)][len(b)]<<endl;
   i=len(a);
   j=len(b);
   while(i>0 && j>0){
      if(a[i-1]==b[j-1])res+=a[i-1],i--,j--;
      else if(dp[i-1][j]>dp[i][j-1])i--;
      else j--;
   }
   reverse(res.begin(),res.end());
   cout<<res<<endl;
}


Measured memory_bytes: 70656
#include <stdio.h>

int main() {

  int a[4];
  int b[4];
    int A =0;
  int B = 0;

    int i,j,k,l;

    for(i=0;i<4;i++){
      scanf("%d",&a[i]);
      A = A + a[i];
    }
    for(i=0;i<4;i++){
      scanf("%d",&b[i]);
      B = B + b[i];
    }

    if(A > B) {
      printf("%d\n",A);
    } else if(A < B) {
      printf("%d\n", B);
    } else if(A == B) {
      printf("%d\n",A);
    }

    return 0;
}

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

#pragma GCC optimize(2)

#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
using namespace std;

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

int gi() {
	int f = 1, x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 1) + (x << 3) + ch - '0';
		ch = getchar();
	}
	return f * x;
}

ll qpow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res; 
}
const int N = 55; 
int n, cov[N], qu[N], qv[N], f[N][N], d[N];
vector <int> g[N];

void dfs(int u, int pre) {
	f[u][0] = pre;
	d[u] = d[pre] + 1;
	for (auto v: g[u]) {
		if (v != pre) dfs(v, u); 
	}
}

int lca(int u, int v) {
	if (d[u] < d[v]) swap(u, v);
	per (i, 6, 0)
		if (d[u] - (1 << i) >= d[v]) u = f[u][i];
	if (u == v) return u;
	per (i, 6, 0)
		if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
	return f[u][0]; 
}
int left_edges; 
void dfs2(int u, int pre) {
	for (auto v: g[u]) {
		if (v != pre) {
			dfs2(v, u);
			cov[u] += cov[v];
		}
	}
//	cout << u << ":" << cov[u] << endl; 
	if (cov[u]) --left_edges; 
}
int main() {
	n = gi();
	rep (i, 1, n-1) {
		int u = gi(), v = gi();
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 0); 
	rep (j, 1, 6)
		rep (i, 1, n)
			if (f[i][j - 1]) f[i][j] = f[f[i][j - 1]][j - 1];
	int m = gi();
	rep (i, 1, m) qu[i] = gi(), qv[i] = gi();
	ll answer = qpow(2, n - 1); 
	for (int i = 1; i < (1 << m); i++) {
		left_edges = n - 1; 
		rep (j, 1, n) cov[j] = 0; 
		int flag = qpow(-1, __builtin_popcount(i));
		for (int j = 1; j <= m; j++) {
			if (i & (1 << (j - 1))) ++cov[qu[j]], ++cov[qv[j]], cov[lca(qu[j], qv[j])] -= 2;
		}
		dfs2(1, 0); 
		answer += flag * qpow(2, left_edges);
	}
	cout << answer << endl; 
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    set<char>st;
    for (int i=0;i<s.length();i++){
        st.insert(s[i]);
    }
    cout<<(st.size()==s.length()?"yes":"no");
    return 0;
}


Measured memory_bytes: 256
S = list(input())
T = input()
ls = []

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != "?":
            break
    else:
        ls.append(i)

if ls:
    for j in range(len(T)):
        S[ls[-1]+j] = T[j]
    print("".join(S).replace("?", "a"))
else:
    print("UNRESTORABLE")        


Measured memory_bytes: 3064
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1

#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <random>
#include <ctime>

#define MOD 1000000007

const long long INF = 10000000000000000;

using namespace std;

int main(){
	int A,B;
	cin>>A>>B;
	if(A==1) A=14;
	if(B==1) B=14;

	if(A>B){
		cout<<"Alice"<<endl;
	} else if(A<B){
		cout<<"Bob"<<endl;
	}else{
		cout<<"Draw"<<endl;
	}

	return 0;
}


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

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( true ) {
	    final String[] input = stdin.nextLine().split( " " );
	    final int height = Integer.parseInt( input[0] );
	    final int width = Integer.parseInt( input[1] );
	    
	    if ( height == 0 && width == 0 ) {
		break;
	    }

	    final char[][] map = new char[height][];
	    
	    for ( int i = 0; i < height; i++ ) {
		map[i] = stdin.nextLine().toCharArray(); 
	    }

	    final int[][] acCol = new int[height][width];
	    for ( int r = 0; r < width; r++ ) {
		acCol[0][r] = ( map[0][r] == '.' ) ? 1 : 0;
		for ( int c = 1; c < height; c++ ) {
		    if ( map[c][r] == '.' ) {
			acCol[c][r] = acCol[c - 1][r] + 1;
		    } else {
			acCol[c][r] = 0;	
		    }
		}
	    }

	    final int[][] acRow = new int[height][width];
	    for ( int c = 0; c < height; c++ ) {
		acRow[c][0] = ( map[c][0] == '.' ) ? 1 : 0;
		for ( int r = 1; r < width; r++ ) {
		    if ( map[c][r] == '.' ) {
			acRow[c][r] = acRow[c][r - 1] + 1;
		    } else {
			acRow[c][r] = 0;	
		    }
		}
	    }

	    int maxArea = 0;
	    
	    for ( int c = 0; c < height; c++ ) {
		for ( int r = 0; r < width; r++ ) {

		    int minHeight = Integer.MAX_VALUE;
		    for ( int ri = 0; ri < acRow[c][r]; ri++) {
			final int cr = r - ri;
			minHeight = Math.min( minHeight, acCol[c][cr] );
			final int area = ( r - cr + 1 ) * minHeight;
			maxArea = Math.max( maxArea, area );
		    }
		    
		}
	    }

	    System.out.println( maxArea );
	}
    }

    static void printArray( int[][] array ) {
	for ( int[] ar : array ) {
	    System.err.println( Arrays.toString( ar ) );
	}	
    }

    static void printArray( char[][] array ) {
	for ( char[] ar : array ) {
	    System.err.println( Arrays.toString( ar ) );
	}	
    }
    
}

Measured memory_bytes: 34220
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

int cnt = 0;

template<typename T>
void print(vector<T> v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void merge(vi &A, int left, int mid, int right) {
  auto n1 = mid -left;
  auto n2 = right - mid;
  vi L(n1 + 1), R(n2 + 1);
  REP(i, n1) L[i] = A[left + i];
  REP(i, n2) R[i] = A[mid + i];
  L[n1] = INF;
  R[n2] = INF;
  int i= 0, j=0;
  FOR(k, left, right) {
    ++cnt;
    A[k] = (L[i] <= R[j] ) ? L[i++] : R[j++];
  }
}

void merge_sort(vi &A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right ) / 2;
    merge_sort(A, left, mid);
    merge_sort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n;
  cin >> n;
  vi S(n);
  REP(i, n) cin >> S[i];
  merge_sort(S, 0, n);
  print(S);
  cout << cnt << endl;
}



Measured memory_bytes: 6800
#!/usr/bin/env ruby
n, k = STDIN.readline.strip.split(' ').map(&:to_i)
h = STDIN.read().split("\n").map(&:to_i)
h = h.sort
min = 10**9+1
for i in (k-1)..(n-1) do
  min = h[i] - h[i-(k-1)] if min > h[i] - h[i-(k-1)]
end
puts min


Measured memory_bytes: 10104
import sys, re
from collections import deque, defaultdict, Counter
from math import floor, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B = MAP()
N = gcd(A, B)

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

x = factorization(N)
if x == [[1, 1]]:
	print(1)
else:
	print(1+len(x))


Measured memory_bytes: 5328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int a,b;

    cin >> a >>  b;

    if(b%a==0)cout << a+b << endl;
    else cout << b-a << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	//given n times, and R, an array of currencies/rates
	  public static int compute_maxprofit(int n, Integer[] R) {
	      int max_profit = -100000;
	      for(int i = 0; i < n - 1; i ++) {
	    	  for(int j = i + 1; j < n; j ++){
	    		  if(R[j] - R[i] > max_profit) {
	    			  max_profit = R[j] - R[i];
	    		  }	  
	    	  }
	      }
	      return max_profit;
	  }
	  
	  public static int fastCompute_Maxprofit(int n, Integer[] R) {
		  int max_profit = Integer.MIN_VALUE;
		  int min_prior=Integer.MAX_VALUE;
		  
		  for(int i=0; i<n; i++) {
			  int c=R[i];
			  
			  if((c-min_prior)>max_profit) {
				  max_profit=c-min_prior;
			  }
			  if(c<min_prior) {
				  min_prior=c;
			  }
		  }
		  
		  return max_profit;
	  }
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int duration = sc.nextInt();
		
		Integer[] R = new Integer[duration];
		
		for(int i = 0; i<duration; i++) {
			R[i]=sc.nextInt();
		}
		
		System.out.println(fastCompute_Maxprofit(duration,R));
		
	}

}


Measured memory_bytes: 105456
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int n;cin>>n;
    vi v(n);cin>>v;
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=v[i]*v[j];
        }
    }
    cout<<ans;
}

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

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

    bool ok = false;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (N == i * j) ok = true;
        }
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

/* Name of the class has to be "Main" only if the class is public. */
class Main {
    private static long inversions = 0;

    public static void main(String[] args) throws java.lang.Exception {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int arraySize = s.nextInt();
        int[] A = new int[arraySize];
        for (int i = 0; i < arraySize; i++) {
            A[i] = s.nextInt();
        }

        mergeSort(A, 0, A.length);
        System.out.println(inversions);
    }

    public static void mergeSort(int[] A, int left, int right) {
        if (left + 1 >= right) {
            return;
        }
        int mid = (right + left) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }

    public static void merge(int[] A, int left, int mid, int right) {

        int n1 = mid - left;
        int n2 = right - mid;

        int[] L = new int[n1];
        int[] R = new int[n2];

        for (int i = 0; i < n1; i++) {
            L[i] = A[left + i];
        }
        for (int i = 0; i < n2; i++) {
            R[i] = A[mid + i];
        }

        int i = 0;
        int j = 0;

        for (int k = left; k < right; k++) {
            if (j >= n2) {
                A[k] = L[i];
                i = i + 1;
                continue;
            }
            if (i >= n1) {
                A[k] = R[j];
                inversions += L.length - i;
                j = j + 1;
                continue;
            }
            if (L[i] <= R[j]) {
                A[k] = L[i];
                i = i + 1;
            } else {
                A[k] = R[j];
                inversions += L.length - i;
                j = j + 1;
            }
        }
    }
}



Measured memory_bytes: 101336
#include <cstdio>
using namespace std;
int ys[4] = {0, 0, -2, -2};
int xs[4] = {0, 1, 1, 0};
int fib[3];

void fibCalc() {
    fib[0] = fib[1];
    fib[1] = fib[2];
    fib[2] = fib[0]+fib[1];
}

bool check(const int &y, const int &x) {
    if (y <= ys[0] && y >= ys[3] && x >= xs[0] && x <= xs[1]) return true;
    return false;
}

void change(const int &idx) {
    if (idx == 3) xs[0]-=fib[2], xs[3]-=fib[2];
    else if (idx == 0) ys[0]+=fib[2], ys[1]+=fib[2];
    else if (idx == 1) xs[1]+=fib[2], xs[2]+=fib[2];
    else if (idx == 2) ys[2]-=fib[2], ys[3]-=fib[2];
}


int main()
{

    int x, y, idx, num; //y: height val, x: width val
    scanf("%d %d", &x, &y);
    y*= -1;
    num = 3;
    idx = 3;
    fib[0] = 1, fib[1] = 2, fib[2] = 3;
    if (x == 0 && y == 0) printf("%d\n", 1);
    else if (x == 1 && y == 0) printf("%d\n", 2);
    else {
        for (;;) {
            if (check(y, x)) { printf("%d\n", num); break; }
            else {
                change(idx);
                idx = (idx+1) % 4;
                fibCalc();
                num = (num + 1 > 3) ? 1 : num+1;
            }
        }

    }
    return 0;
}



Measured memory_bytes: 2736
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N; cin >> N;
    vector<int> H(N+1);
    H[0] = 0;
    for(int i=1; i<N+1; i++){
        int h; cin >> h;
        H[i] = h;
        if(H[i-1] < H[i]) H[i]--;
    }
    
    for(int i=1; i<N; i++){
        if(H[i]>H[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

class UnionFind
{
private:
  lint size;
  vector< lint > group;
public:
  UnionFind(lint size) : size(size), group(size, -1) {}
  void add(lint x, lint y) {
    while (group[x] != -1) x = group[x];
    while (group[y] != -1) y = group[y];
    if (x < y) group[y] = x;
    else if (x > y) group[x] = y;
  }
  bool isConnect(lint x, lint y) {
    while (group[x] != -1) x = group[x];
    while (group[y] != -1) y = group[y];
    return x==y;
  }
  lint gid(lint idx) {
    while (group[idx] != -1) idx = group[idx];
    return idx;
  }
};

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n, k, l;
  cin >> n >> k >> l;
  UnionFind uf_road(n), uf_rail(n);
  for (lint i=0; i<k; ++i) {
    lint x, y;
    cin >> x >> y;
    x--; y--;
    uf_road.add(x, y);
  }
  for (lint i=0; i<l; ++i) {
    lint x, y;
    cin >> x >> y;
    x--; y--;
    uf_rail.add(x, y);
  }
  unordered_map< lint, lint > m;
  for (lint i=0; i<n; ++i) {
    lint key = uf_road.gid(i) * n + uf_rail.gid(i);
    if (m.count(key) > 0) m[key] += 1;
    else m[key] = 1;
  }
  for (lint i=0; i<n; ++i) {
    lint key = uf_road.gid(i) * n + uf_rail.gid(i);
    cout << m[key] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 11336
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

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

	int n, z, w;
	cin >> n >> z >> w;

	int *arr = new int[n];

	for (int i = 0; i < n; ++i)
		cin >> arr[i];

	if (n == 1) {
		cout << abs(arr[0] - w);
		return 0;
	}

	cout << max(abs(arr[n - 1] - w), abs(arr[n - 1] - arr[n - 2]));

	delete arr;

	//system("pause");

	return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    s = input()
    ss = s[::-1]
    if n <= m:
        print(n)
    else:
        cnt = 0
        for i in range(n + 1):
            if s[i] == "1":
                cnt += 1
            else:
                cnt = 0
            if cnt >= m:
                print(-1)
                exit()
        pos = 0
        res = []
        while n != pos:
            for i in reversed(range(m + 1)):
                if pos + i > n:
                    continue
                if ss[pos + i] != "1":
                    pos += i
                    res.append(i)
                    break
        print(*res[::-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 51056
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll l,A[200200],N,sum,ans;

int main(){
    cin>>N;
    rep(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    rep(i,N){
        if((l+A[i])*2>=sum){
            out(min((sum-l)-l,(l+A[i])-(sum-(l+A[i]))));
            return 0;
        }
        l+=A[i];
    }
    
    
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int H,W; cin>>H>>W;
    char a[H][W]; REP(i,H) REP(j,W) cin>>a[i][j];
    vector<int> h,w;
    REP(i,H) {
        bool flag = true;
        REP(j,W) {
            if (a[i][j]=='#') {
                flag = false;
                break;
            }
        }
        if (flag) h.push_back(i);
    }
    REP(i,W) {
        bool flag = true;
        REP(j,H) {
            if (a[j][i]=='#') {
                flag = false;
                break;
            }
        }
        if (flag) w.push_back(i);
    }
    REP(i,h.size()) cerr<<h[i]<<" ";
    cerr<<endl;
    REP(i,w.size()) cerr<<w[i]<<" ";
    cerr<<endl;
    REP(i,H) {
        bool flag = true;
        REP(k,h.size()) {
            if (i==h[k]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            REP(j,W) {
                flag = true;
                REP(l,w.size()) {
                    if (j==w[l]) {
                        flag = false;
                        break;
                    }
                }
                if (flag) cout<<a[i][j];
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#define f first
#define s second
 
using namespace std;
const int N=500009;
pair <int, pair <int, int> > q[N];
int n, m, a[N], ans[N];
int st[5*N], used[5*N];
int cmp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b)
{
    if (a.s.f != b.s.f)
        return a.s.f < b.s.f;
    return a.f < b.f;
}
void update(int v, int l, int r, int x, int d)
{
    if (l == r)
    {
        st[v] = d;
        return;
    }
    int mid = (l + r) / 2;
    if (x <= mid)
        update(v * 2, l, mid, x, d);
    else
        update(v * 2 + 1, mid + 1, r, x, d);
    st[v] = st[v * 2] + st[v * 2 + 1];
}
int Find(int v, int A, int B, int l, int r)
{
    if (l > B || r < A)
        return 0;
    if (A == l && B == r)
        return st[v];
    int mid = (A + B) / 2;
    return Find(v * 2, A, mid, l, min(mid, r)) + Find(v * 2 + 1, mid + 1, B, max(mid + 1, l), r);
}
 
int main()
{
    scanf("%d", &n);
    scanf("%d", &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    
    for (int i = 1; i <= m; i++)
        scanf("%d %d", &q[i].f, &q[i].s.f), q[i].s.s = i;
    sort(q + 1, q + m + 1, cmp);
    int j = 1;
    for (int i = 1; i <= m; i++)
    {
        while(j <= q[i].s.f)
        {
            if (!used[a[j]])
            {
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            else
            {
                update(1, 1, n, used[a[j]], 0);
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            j++;
        }
        ans[q[i].s.s] = Find(1, 1, n, q[i].f, q[i].s.f);
    }
    for (int i = 1; i <= m; i++)
        printf("%d\n", ans[i]);
 
    return 0;
}


Measured memory_bytes: 19608
#include<iostream>
#include<map>
using namespace std;
int N,X,Y,M;
int main(){
    cin>>N;
    int x[N],y[N];
    for(int i=0;i<N;i++)cin>>x[i]>>y[i];
    map<pair<int,int>,int>m;
    for(int i=0;i<N-1;i++)for(int j=i+1;j<N;j++){
        X=x[i]-x[j],Y=y[i]-y[j];
        if(Y==0)X=abs(X);
        if(Y<0)X=-X,Y=-Y;
        M=max(M,++m[make_pair(X,Y)]);
    }
    cout<<N-M<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using ll = long long;
using namespace std;        
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define ar array

const int N=1e5+5;
vector<int> g[N];
bool used[N];

void dfs(int u){
	used[u]=true;
	for(auto x:g[u]){
		if(used[x]) continue;
		dfs(x);
	}
}
void solve(){
         int n,m;	
         cin>>n>>m;
         for(int i=0;i<m;i++){
         	int a,b;
         	cin>>a>>b;
            	a--;
            	b--;
            	g[a].pb(b);
            	g[b].pb(a);	
         }
         int roads=0;
         for(int i=0;i<n;i++){
              if(!used[i]){
              	roads++;
              	dfs(i);
              }
         }
         cout<<roads-1<<endl;

}

int main(){
	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
//	freopen("input.txt",r,"stdin");
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}





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

int main() {
    double ans = 0;
    int N;
    cin >> N;
    multiset<double> v;
    for(int i = 0; i < N; i++) {
        double x;
        cin >> x;
        v.insert(x);
    }
    for(int i = 0; i < N - 1; i++) {
        double x = *v.begin();
        v.erase(v.begin());
        x /= double(2);
        double y = *v.begin();
        v.erase(v.begin());
        y /= double(2);
        v.insert(x + y);
    }
    ans = *v.begin();
    cout << fixed << setprecision(6) << ans << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << min(c, a+b+1) + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int word[26];

int main() {
    std::string w;
    bool flag = true;
    std::cin >> w;
    for (int i=0; i<w.size(); ++i) ++word[ w[i] - 'a' ];
    for (int i=0; i<26; ++i) {
        if ( word[i] % 2 ) flag = false;
    }
    std::cout << ( flag ? "Yes" : "No" ) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int num[10];
	int c;
	int i;
	int j;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &num[i]);
	}
	
	for (i = 0; i < 9; i++){
		for (j = 0; j < 9; j++){
			if (num[j] > num[j + 1]){
				c = num[j + 1];
				num[j + 1] = num[j];
				num[j] = c;
			}
		}
	}
	
	printf("%d\n%d\n%d\n", num[9], num[8], num[7]);
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
#define ll long long int
#define endl '\n'
#define mp make_pair
#define pb push_back
#define mod 1000000007

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a;
	string s;
	cin>>a>>s;
	if(a<3200)
	{
		cout<<"red";	
	}
	else
	  cout<<s<<endl;
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define INF 9223372036854775801

#define MAX 1000005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
void solve(lli the)
{
//	char ch;
//	long db aa,bb,cc;
//	string s1,s2,s3,str;
//    lli i,j,k,a,b,c,d,n,m,l,r,x,y,low,high,mid,sum=0,ans=0,temp,t;
	lli i,n;
	cin >> n;
	lli arr[n];
	rep(i,0,n-1)	cin >> arr[i];
	lli freq[n+1];
	rep(i,0,n+1)	freq[i]=0;
	for(i=0;i<n-1;i++){
		freq[arr[i]]++;
	}
	for(i=1;i<=n;i++){
		cout<<freq[i]<<endl;
	}
	
    
}














int main()
{
	long long int t=1,c=1;
	//scanf("%lld",&t);
	while(t--){
		solve(c);
		c++;
	}
	return 0;
}
/* UJJWAL KESHRI */

Measured memory_bytes: 6756
/**


２点 P1(x1, y1), P2(x2, y2) の距離を求めるプログラムを作成せよ。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);
		// 4つの数字を受け取る
		double dbX1 = sc.nextDouble();
		double dbY1 = sc.nextDouble();
		double dbX2 = sc.nextDouble();
		double dbY2 = sc.nextDouble();
		//計算する
		double dbKekka = Math.sqrt(Math.pow(dbX2 - dbX1,2)  + Math.pow(dbY2 - dbY1,2));

		//結果表示
		System.out.println(dbKekka);
	}
}

Measured memory_bytes: 18300
# coding: utf-8
# Your code here!

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

#print("S =",S)
#print("T =",T)

ans=0
for s in S:
    count = S.count(s)-T.count(s)
    if ans<count:
        ans=count
    
print(ans)


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


typedef struct{
  int p, l, r;
}node;

node *data;

int dep(int n){
  int d=0;

  for(n=data[n].p;n!=-1;n=data[n].p) d++;

  return d;
}

int hei(int n){
  int a=0, b=0;

  if(data[n].l!=-1) a=hei(data[n].l)+1;
  if(data[n].r!=-1) b=hei(data[n].r)+1;

  if(a>b) return a;
  else return b;
}

int main(){
  int i, a, c, n;
  
  scanf("%d",&n);
  
  data=(node *)malloc(sizeof(node)*n);
  
  for(i=0;i<n;i++) data[i].p=-1;
  
  for(i=0;i<n;i++){
    
    scanf("%d",&a);
    
    scanf(" %d %d",&data[a].l,&data[a].r);
    
    data[data[a].l].p=a;
    
    data[data[a].r].p=a;
  }


  for(i=0;i<n;i++){
    c=0;
    
    printf("node %d: parent = %d, sibling = ",i,data[i].p);
    
    if(data[i].p==-1) printf("-1, ");
    
    else if(data[data[i].p].l!=i) printf("%d, ",data[data[i].p].l);
    
    else printf("%d, ",data[data[i].p].r);

    
    if(data[i].l!=-1) c++;
    
    if(data[i].r!=-1) c++;
    
    printf("degree = %d, depth = %d, height = %d, ",c,dep(i),hei(i));

    
    if(data[i].p==-1) printf("root\n");
    
    else if(c == 0) printf("leaf\n");
    
    else printf("internal node\n");
  }

 
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
#define print(a) cout << a << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,A,B,C;cin>>n>>A>>B>>C;
  string s;
  vector<char> V(n);
  vector<string> Q(n);
  bool isok=true;
  rep(i,n) cin>>Q[i];
  rep(i,n) {
    s=Q[i];
    if(isok) {
      if(i!=n-1&&s=="AB"&&A==1&&B==1&&C==0&&s!=Q[i+1]) {
        if(Q[i+1]=="AC") {A++;B--;V[i]='A';isok=(B>-1);}
        else {A--;B++;V[i]='B';isok=(A>-1);}
      }
      else if(i!=n-1&&s=="BC"&&A==0&&B==1&&C==1&&s!=Q[i+1]) {
        if(Q[i+1]=="AC") {C++;B--;V[i]='C';isok=(B>-1);}
        else {C--;B++;V[i]='B';isok=(C>-1);}
      }
      else if(i!=n-1&&s=="AC"&&A==1&&B==0&&C==1&&s!=Q[i+1]){
        if(Q[i+1]=="AB") {A++;C--;V[i]='A';isok=(C>-1);}
        else {A--;C++;V[i]='C';isok=(A>-1);}
      }
      else {
        if(s=="AB") {
          if(A<B) {A++;B--;V[i]='A';isok=(B>-1);}
          else {A--;B++;V[i]='B';isok=(A>-1);}
        }
        else if(s=="BC") {
          if(C<B) {C++;B--;V[i]='C';isok=(B>-1);}
          else {C--;B++;V[i]='B';isok=(C>-1);}
        }
        else {
          if(A<C) {A++;C--;V[i]='A';isok=(C>-1);}
          else {A--;C++;V[i]='C';isok=(A>-1);}
        }
      }
    }
  }
  if(!isok) puts("No");
  else {
    print("Yes");
    for(char c:V) print(c);
  } 
  return 0;
}

Measured memory_bytes: 6380
// AtCoder Regular Contest 069
// E - Frequency

#include <cstdio>
#include <cstring>
#include <queue>
#define MAX_N 100000
using namespace std;
typedef long long int ll;
typedef pair<ll, int> PLI;


int N;
priority_queue<PLI> q;
ll ans[MAX_N];

int main() {

  PLI p;
  ll a, cnt;
  int min_i;

  scanf("%d", &N);
  q.push(PLI(0, -1));
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a);
    q.push(PLI(a, i));
  }
  memset(ans, 0, sizeof(ans));

  min_i = N;
  cnt = 0;
  while (q.size() > 1) {
    p = q.top(); q.pop();
    min_i = min(min_i, p.second);
    ans[min_i] += (p.first - q.top().first) * (cnt + 1);
    cnt++;
  }

  for (int i = 0; i < N; i++) {
    printf("%lld\n", ans[i]);
  }

  return 0;

}




Measured memory_bytes: 3568