akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================
class Node {
public:
	int location;
	int p, l, r;
	Node() {}
};

class Point {
public:
	int id, x, y;
	Point() {}
	Point(int id, int x, int y) : id(id), x(x), y(y) {}
	bool operator < (const Point &p)const {
		return id < p.id;
	}

	void print() {
		printf("%d\n", id);
	}
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) {
	return p1.x < p2.x;
}

bool lessY(const Point &p1, const Point &p2) {
	return p1.y < p2.y;
}

int makeKDTree(int l, int r, int depth) {
	if (!(l < r))return NIL;
	int mid = (l + r) / 2;
	int t = np++;
	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX);
	} else {
		sort(P + l, P + r, lessY);
	}
	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, depth + 1);
	T[t].r = makeKDTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <= ty) {
		ans.push_back(P[T[v].location]);
	}

	if (depth % 2 == 0) {
		if (T[v].l != NIL) {
			if (sx <= x) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if (T[v].r != NIL) {
			if (x <= tx) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	} else {
		if (T[v].l != NIL) {
			if (sy <= y) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if (T[v].r != NIL) {
			if (y <= ty) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
}

int main() {
	/*
	ios::sync_with_stdio(false);
	cin.tie(0);
	*/
	int x, y;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &x, &y);
		P[i] = Point(i, x, y);
		T[i].l = T[i].r = T[i].p = NIL;
	}

	np = 0;

	int root = makeKDTree(0, N, 0);

	int q;
	scanf("%d", &q);
	int sx, tx, sy, ty;
	vector<Point> ans;
	for (int i = 0; i < q; i++) {
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int j = 0; j < ans.size(); j++) {
			ans[j].print();
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 16368
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define MOD 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h=0,w=0,x=0,y=0;
    cin>>h>>w;
    char v[h][w];
    for(int i=0;i<h;++i)
        for(int j=0;j<w;++j)
            cin>>v[i][j];
    int dp[h][w];
    for(int i=0;i<h;++i)
        for(int j=0;j<w;++j)
            dp[i][j]=INT_MAX;
    if(v[0][0]=='.')
        dp[0][0]=0;
    else
        dp[0][0]=1;
    for(int i=0;i<h;++i)
        for(int j=0;j<w;++j)
        {
            x=i+1;y=j;
            if(x<h&&y<w)
            {
                if(v[i][j]=='.'&&v[x][y]=='#')
                    dp[x][y]=min(dp[x][y],dp[i][j]+1);
                else
                    dp[x][y]=min(dp[x][y],dp[i][j]);
            }
            x=i;y=j+1;
            if(x<h&&y<w)
            {
                if(v[i][j]=='.'&&v[x][y]=='#')
                    dp[x][y]=min(dp[x][y],dp[i][j]+1);
                else
                    dp[x][y]=min(dp[x][y],dp[i][j]);
            }
        }
    cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int lli;

using namespace std;

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
	int t=1;
	//cin>>t;
	while(t--){
		//logic_start
        int n,m;
        cin>>n>>m;
        vector<int> arr(n);
        int tsum=0,mm=4*m,cnt=0;
        for(int i=0;i<n;i++){
            cin>>arr[i];
            tsum+=arr[i];
        }
        for(int i=0;i<n;i++){
            if((double)arr[i]>=((double)tsum/(double)mm))
                cnt++;
        }
        if(cnt>=m)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
		//logic_end

	} 
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector <int> A(N);
    vector <int> B(N);
    vector <int> C(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));
    
    ll sum = 0;
    for(int i=0; i<N; i++){
        auto a_itr = lower_bound(ALL(A), B[i]);
        auto c_itr = upper_bound(ALL(C), B[i]);
        sum += (a_itr - A.begin()) * (C.end() - c_itr);
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1408
import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())

    ans = len(str(n))
    i = 1
    while i * i <= n:
        if n % i == 0:
            a = i
            b = n // i
            ans = min(ans, max(len(str(a)), len(str(b))))

        i += 1

    print(ans)

if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    cin >> n;
    int ans = INT_MAX;
    for(int i = 1; i < n / 2 + 1; i++){
        int a = i;
        int b = n - i;
        int da = 0, db = 0;
        while(a>0){
            da += (a % 10);
            a /= 10;
        }
        while(b>0){
            db += (b % 10);
            b /= 10;
        }
        ans = min(ans,(da+db));
    }
    cout << ans;
}

Measured memory_bytes: 256
/* https://www.youtube.com/watch?v=dQw4w9WgXcQ hello. -bedirhan */
#include <iostream>
using namespace std;
int main()
{
  int x;
  cin >> x;
  int ans{};
  ans = (x/500)*1000+(x%500)/5*5;
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

long long xorsum(long long val){
  if (val%4==0){
    return val;
  } else if (val%4==1){
    return 1;
  } else if (val%4==2){
    return val+1;
  } else if (val%4==3){
    return 0;
  }
}

int main(){
  long long A, B;
  scanf("%lld",&A);
  scanf("%lld",&B);
  long long ans = 0;
  long long multiple = 1;
  long long sumA = xorsum(A-1);
  long long sumB = xorsum(B);
  while(sumA>0 || sumB>0){
    //printf("sumA=%lld\n",sumA);
    //printf("sumB=%lld\n",sumB);
    if ((sumA%2+sumB%2)%2==1){
      ans += multiple*1;
    }
    sumA = sumA/2;
    sumB = sumB/2;
    multiple *= 2;
  }
  printf("%lld\n",ans);
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

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

    int res = 0;
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'L' && i >= 1 && s[i] == s[i-1]) res++;
        if(s[i] == 'R' && i < n - 1 && s[i+1] == s[i]) res++;
    }
    cout << min(res + 2*k, n - 1) << endl;
}

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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main()
{
    int N,M,i,max=0;
    int X[200001];
    int sa[200000];

    scanf("%d%d",&N,&M);
    for(i=0;i<M;i++){
        scanf("%d",&X[i]);
    }

    qsort(X,M,sizeof(int),asc);
    

    for(i=0;i<M-1;i++){
        sa[i] = X[i+1] - X[i]; 
    }

    qsort(sa,M-1,sizeof(int),asc);

    for(i=0;i<M-N;i++){
        max += sa[i];
    }

    printf("%d",max);

    return 0;
}



Measured memory_bytes: 1396
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define mx 1000010

int main(){
	IOS;
	ll n,k;cin>>n>>k;
	ll h[n];rep(i,0,n)cin>>h[i];
	ll dp[n];
	rep(i,0,n)dp[i]=99999999999;
	dp[0]=0;
	for(ll i=1;i<n;++i){
		for(ll j=1;j<=min(k,i);++j){
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}



Measured memory_bytes: 1792
from itertools import product

n, m = map(int, input().split())
sp = [list(map(int, input().split())) for _ in range(m + 1)]
print(sum(all(sum(i[a - 1] for a in s[1:]) % 2 == p for s, p in zip(sp[:m], sp[-1])) for i in product((0, 1), repeat=n)))

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

int main()
{
  int r,D,x200[11];
  cin >> r >> D >> x200[0];
  for(int i = 1;i <= 10;++i){
    x200[i] = r * x200[i-1] - D;
    cout << x200[i] << endl;
  }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
	int tcase;
   
	cin >> tcase;
  	while(tcase--) {
    	string A, B, C = "";
   		cin >> A >> B;
     
    	unsigned sz = max(A.size(), B.size());
    	while(A.size()<sz) A = '0' + A;
    	while(B.size()<sz) B = '0' + B;
 
    	int c = 0;
    	for(int i=sz-1; i>=0; i--) {
      	//answer
      	C += (( (A[i]-'0') + (B[i]-'0') + c ) % 10 + '0');
      	//carry
      	c = ( (A[i]-'0') + (B[i]-'0') + c ) / 10;
    	}
    	if(c>0) C += (c + '0');
     
    	reverse(C.begin(), C.end());
    	if(C.size() > 80) cout << "overflow" << endl;
    	else cout << C << endl;
  	}
  	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl  "\n"
typedef long long ll;
 
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

vector<ll> mnp(1e5+1 ,1e15 ) ;
map< pair<int ,int>, int > mp ; 

void dfs( int u  , int p, vector< vector<int> > &df,vector<int > vis, ll cost  ){
       // cout<<u<<endl;
        vis[u] = 1 ;
        mnp[u] = min( mnp[u], cost )     ;
        for( auto i  : df[u] ){
                if( vis[i] == 0  ) dfs( i, u , df, vis, cost+ mp[ {u, i} ]   );
            }
    }   
 

 int  main(){
            int  n ,x  ,t ; cin>>n >>x >> t; 
            cout<<(int)( ceil( (float)n/x ) )*t ; 
        }

Measured memory_bytes: 3856
#include <iostream>
#include <string>
#include <map>
using namespace std;

int getValue(string v, int &ptr) {
    int ret = 0;
    while(isdigit(v[ptr])) {
        ret *= 10;
        ret += v[ptr++] - '0';
    }
    return ret;
}

int main() {

    int N;
    cin >> N;
    map< char, int > rel;
    rel['m'] = 1000, rel['c'] = 100, rel['x'] = 10, rel['i'] = 1;
    while(N--) {
        string s1, s2; cin >> s1 >> s2;
        int sum1 = 0, sum2 = 0;

        s1 = "a" + s1, s2 = "a" + s2;

        for(int i = 1; i <= s1.size(); i++) {
            if(isdigit(s1[i])) {
                sum1 += getValue(s1, i) * rel[s1[i]];
            } else if(!isdigit(s1[i - 1])) {
                sum1 += rel[s1[i]];
            }
        }
        for(int i = 1; i <= s2.size(); i++) {
            if(isdigit(s2[i])) {
                sum2 += getValue(s2, i) * rel[s2[i]];
            } else if(!isdigit(s2[i - 1])) {
                sum2 += rel[s2[i]];
            }
        }
        sum1 += sum2;

        if(sum1 / 1000 >= 1) {
            if(sum1 / 1000 > 1) cout << sum1 / 1000;
            cout << 'm';
        }
        sum1 %= 1000;
        if(sum1 / 100 >= 1) {
            if(sum1 / 100 > 1)cout << sum1 / 100;
            cout << 'c';
        }
        sum1 %= 100;
        if(sum1 / 10 >= 1) {
            if(sum1 / 10 > 1)cout << sum1 / 10;
            cout << 'x';
        }
        sum1 %= 10;
        if(sum1 >= 1) {
            if(sum1 > 1) cout << sum1;
            cout << 'i';
        }
        cout << endl;
    }
}

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());

    int max = Math.max(A, Math.max(B, C));
    int sum = A + B + C - max;
    sum += max * Math.pow(2, K);

    System.out.println(sum);

  }
}

Measured memory_bytes: 21844
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

A,B,K = map(int, input().split())

if K<=A:
    A-=K
    K=0
else:
    K-=A
    A=0
    
if K!= 0:
    if K<=B:
        B-=K
        K=0
    else:
        K-=B
        B=0
    


print(str(A)+" "+str(B))

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

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

    int cnt_4 = 0, cnt_2 = 0, odd = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a % 4 == 0)
            cnt_4++;
        else if (a % 2 == 0)
            cnt_2++;
        else
            odd++;
    }

    bool ok;
    if (cnt_2 == 0)
        ok = (odd <= cnt_4 + 1);
    else
        ok = (odd <= cnt_4);

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int n, m;
vector<int> a;
int main() {
  while (cin >> n >> m) {
    a.resize(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      --a[i];
    }

    long long def = 0;
    for (int i = 0; i < n-1; ++i) {
      if (a[i] < a[i+1]) def += a[i+1] - a[i];
      else def += (a[i+1] + m) - a[i];
    }

    vector<long long> sum(m*2+5, 0);
    for (int i = 0; i < n-1; ++i) {
      if (a[i] < a[i+1]) {
        sum[a[i]+m+2]++;
        sum[a[i+1]+m+2] += (a[i+1] - a[i] - 1);
        sum[a[i+1]+m+1] -= (a[i+1] - a[i]);
      }
      else {
        sum[a[i]+2]++;
        sum[a[i+1]+m+2] += (a[i+1]+m - a[i] - 1);
        sum[a[i+1]+m+1] -= (a[i+1]+m - a[i]);
        sum[a[i]+m+2]++;
      }
    }
    for (int iter = 0; iter <= 2; ++iter) {
      //for (int i = 0; i <= m * 2 + 1; ++i) cout << i << ": " << sum[i] << endl;
      
      if (iter == 2) break;
      for (int i = 0; i <= m*2+1; ++i) {
        sum[i+1] += sum[i];
      }
    }

    long long res = 0;
    int pres = -1;
    for (int i = m; i < m*2; ++i) {
      if (chmax(res, sum[i])) {
        pres = i-m;
      }
    }

    //COUT(def); COUT(res); COUT(pres);

    cout << def - res << endl;
    
  }
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
	string str;

	cin >> str;

	int ok = 0;
	if (str == "KIHBR")
		ok = 1;
	if (str == "KIHBRA")
		ok = 1;
	if (str == "KIHBAR")
		ok = 1;
	if (str == "KIHBARA")
		ok = 1;
	if (str == "KIHABR")
		ok = 1;
	if (str == "KIHABRA")
		ok = 1;
	if (str == "KIHABAR")
		ok = 1;
	if (str == "KIHABARA")
		ok = 1;
	if (str == "AKIHBR")
		ok = 1;
	if (str == "AKIHBRA")
		ok = 1;
	if (str == "AKIHBAR")
		ok = 1;
	if (str == "AKIHBARA")
		ok = 1;
	if (str == "AKIHABR")
		ok = 1;
	if (str == "AKIHABRA")
		ok = 1;
	if (str == "AKIHABAR")
		ok = 1;
	if (str == "AKIHABARA")
		ok = 1;

	if (ok){
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld double
#define pb push_back
#define mod 1000000007
#define p1 4312312
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
ll binpow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
main()
{
    IO
    ll n;
    cin>>n;
    string s;
    cin>>s;
    map<char,ll> ae;
    for(int x=0;x<n;x++)
    {
       ++ae[s[x]];
    }
    ll e=0;
    ll ans=1e18;
    for(int x=-1;x<n;x++)
    {    if(x>=0)
        if(s[x]=='R')
            ++e;
        ll j=x+1-e;
        if(ae['R']>x+1)
           j+=(ae['R']-x-1);
        ans=min(ans,j);
    }
    cout<<ans;
}


Measured memory_bytes: 3744
import java.util.Scanner;

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

		sc.close();

		if(a==1&&b!=1){
			System.out.print("Alice");
		}else if(b==1&&a!=1){
			System.out.print("Bob");
		}else if(b==1&&a==1){
			System.out.print("Draw");
		}else if(b!=1&&a!=1){
			if(a>b){
				System.out.print("Alice");
			}else if(a<b){
				System.out.print("Bob");
			}else{
				System.out.print("Draw");
			}
		}
	}
}

Measured memory_bytes: 21204
#include <cstdio>
int main(int argc, char** argv)
{
	(void)argc;
	(void)argv;
	int A,B,C,D;
	scanf("%d%d%d%d",&A,&B,&C,&D);

	char buf[101] = {};
	for(int i=A,iMax=B;i<iMax;i++){
		buf[i] |= 1;
	}
	for(int i=C,iMax=D;i<iMax;i++){
		buf[i] |= 2;
	}

	int cnt=0;
	for(int i=0;i<=100;i++)
	{
		if (buf[i]==3){cnt++;}
	}

	printf("%d\n",cnt);

	return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**6)

n = int(input())
es = [[] for _ in range(n)]

for i in range(n-1):
  a,b = map(int,input().split())
  if a > b:
    a,b = b,a
  es[a-1].append((b-1,i))

ans = [0] * (n-1) 

def coloring(vi,prev_color):
  color = 1    
  for to,i in es[vi] :
    if color == prev_color:
      color += 1        
    ans[i] = color     
    coloring(to,color)
    color += 1
    
coloring(0,0)

print(max(ans))
print(*ans,sep='\n')

Measured memory_bytes: 69144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i<0;i<(ll)n;i++)


int main()
{
    string S, ans;
    cin >>S;

    if (S[2]==S[3]&&S[4]==S[5]) ans = "Yes";
    else ans = "No";

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,m,x[100000],y[100000],ans=0,i;
    cin >> n >> m;
    for(i=0;i<m;i++) cin >> x[i];
    sort(x,x+m);
    for(i=0;i<m-1;i++) y[i] = x[i+1]-x[i];
    sort(y,y+m-1);
    for(i=0;i<m-n;i++) ans+=y[i];
    cout << ans;
}

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

struct state{
  int lx, ly, rx, ry, step;
};
int w, h;
char rmap[51][51], lmap[51][51];
queue<state> quu;
int lx, ly, rx, ry;
int d[51][51][51][51];
int xmj[4] = {0, 0, 1, -1}, ymj[4] = {1, -1, 0, 0};
int a[2], b[2];

void lmove(int *x, int *y, int i){

  int lnx = *x - xmj[i], lny = *y + ymj[i];

  if(lnx < 0 || lnx >= w || lny < 0 || lny >= h) return;

  if(lmap[lny][lnx] == '#') return;

  *x = lnx;
  *y = lny;


}

void rmove(int *x, int *y, int i){

  int rnx = *x + xmj[i], rny = *y + ymj[i];

  if(rnx < 0 || rnx >= w || rny < 0 || rny >= h) return;

  if(rmap[rny][rnx] == '#') return;

  *x = rnx;
  *y = rny;


}

void wide(int lx, int ly, int rx, int ry){

  memset(d,0,sizeof(d));
  quu.push((state){lx,ly,rx,ry,1});
  d[ly][lx][ry][ry] = 1;
  while(!quu.empty()){

    state st;
    st = quu.front();
    quu.pop();
    // cout << st.lx << " " << st.ly << " " << st.rx << " " << st.ry << endl;
    for(int i = 0; i < 4; i++){
      int lnx = st.lx, lny = st.ly;
      int rnx = st.rx, rny = st.ry;

      lmove(&lnx,&lny,i);
      rmove(&rnx,&rny,i);

      if(rmap[rny][rnx] == '%' && lmap[lny][lnx] != '%') continue;
      if(rmap[rny][rnx] != '%' && lmap[lny][lnx] == '%') continue;

      if( d[lny][lnx][rny][rnx] == 0){
	quu.push((state){lnx,lny,rnx,rny,st.step+1});
	d[lny][lnx][rny][rnx] = 1;
      }
      
    }
   
  }
  
  if(d[a[0]][a[1]][b[0]][b[1]]) cout << "Yes" << endl;
  else cout << "No" << endl;



}

int main(){


  while(cin >> w >> h && (w || h)){

    for(int i = 0; i < h*2; i++){
      if(i % 2 == 0){
	for(int j = 0; j < w; j++){
	  cin >> lmap[i/2][j];	  
	  if(lmap[i/2][j] == 'L'){
	    lx = j;
	    ly = i/2;
	  }
	  if(lmap[i/2][j] == '%'){
	    a[0] = i/2;
	    a[1] = j;
	    //   cout << a[1] << " " << a[0] << endl; 
	  }
	}
      }else {
	for(int j = 0; j < w; j++){
	  cin >> rmap[(i-1)/2][j];
	  if(rmap[(i-1)/2][j] == 'R'){
	    rx = j;
	    ry = (i-1)/2;
	  }
	  if(rmap[(i-1)/2][j] == '%'){
	    b[0] = (i-1)/2;
	    b[1] = j;
	    //      cout << b[1] << " " << b[0] << endl; 
	  }
	  //  cout << rx << " " << ry << endl;
	  
	  // cout << i;
	}
      }
    }
    wide(lx,ly,rx,ry);
     
  }
    
  
}

Measured memory_bytes: 28788
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, a, b;
  cin >> n >> a >> b;
  if (n == 1)
  {
    cout << (a == b) << endl;
    return 0;
  }
  if (a > b)
  {
    cout << 0 << endl;
    return 0;
  }
  n -= 2;
  cout << b * n - a * n + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int x,i,j,m;
    cin>>x;
    for(i=x;;i++)
    {
        int prime=1;
        for(j=2;j<=i/2;j++)
        {
            if(i%j==0)
            {
                prime=0;
                break;
            }
        }
        if(prime==1)
        {
          m=i;
          break;
        }
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 3612
def resolve():
    n = int(input())
    happy = [[0]*3 for i in range(n)]
    for i in range(n):
        a, b, c = map(int, input().split())
        if i == 0:
            happy[0][0] = a
            happy[0][1] = b
            happy[0][2] = c
        else:
            happy[i][0] = a + max(happy[i-1][1], happy[i-1][2])
            happy[i][1] = b + max(happy[i - 1][0], happy[i - 1][2])
            happy[i][2] = c + max(happy[i - 1][0], happy[i - 1][1])
    print(max(happy[n-1]))
resolve()

Measured memory_bytes: 22772
import java.util.Scanner;
     
    class Main{
    	public static void main(String arg[]) {
    		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();
    		int[] a = new int[N+1];
    		
;    		for(int i = 1; i <= N; i++) {
				a[i] = sc.nextInt();
			}
    		sc.close();
    		int count = 0;
    		
    		int i = 1;
    		boolean[] isON = new boolean[N+1];
    		while(true) {
    			if(a[i] == 2 ) {
    				count++;
    				break;
    			}
    			if(isON[i] == true) {
    				count = -1;
    				break;
    			}
    			count++;
    			isON[i] = true;
    			i = a[i];
    		}
    		System.out.println(count);
    	}
    }

Measured memory_bytes: 53964
N,M = map(int,input().split())
root1 = set()
root2 = set()
for i in range(M):
    ai,bi = map(int,input().split())
    if ai==1:
        root1.add(bi)
    if bi==N:
        root2.add(ai)
if set(root1) & set(root2):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 25928
//https://atcoder.jp/contests/abc141/tasks/abc141_c
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N, K, Q; cin>>N>>K>>Q;    
    vector<ll> point(N+1);
    vector<ll> aq(Q);
    for(auto&& a:aq){
        cin>>a;
        point.at(a)++;
    }
    for(auto&& p:point){
        p=K+p-Q;
    }
    FOR(i,1,point.size()){
        if(point[i]<=0){
            cout<<"No"<<endl;
        }else {
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(b>=a)printf("%d",a);
  else printf("%d",a-1);
}

Measured memory_bytes: 256
N = gets.chomp.to_i

items = []
N.times do
  items << gets.chomp.to_i
end

sum = 0
max_item = 0
items.each do |item|
  sum += item
  if item > max_item
    max_item = item
  end
end

puts sum - (max_item / 2) 


Measured memory_bytes: 1916
/*#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}

int main()
{
    fast_cin;
      string s,t;
      cin>>s>>t;
      int n=s.length();
      int m=t.length();
      unsigned int dp[n+1][m+1];
      string ans;
      for(int i=0;i<=n;i++)
      {
          for(int j=0;j<=m;j++)
          {
              if(i==0||j==0)
                dp[i][j]=0;
              else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
              else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
              /*if(ans.length()<dp[i][j])
                ans+=s[i];
          }
      }
      cout<<dp[n][m]<<endl;
      //cout<<ans<<endl;
    return 0;
}*/
#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}
void binary(int n)
{
    // array to store binary number
    int binaryNum[32];

    // counter for binary array
    int i = 0;
    while (n > 0) {

        // storing remainder in binary array
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }

    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}
int main()
{
    fast_cin;
    ll n;
    cin>>n;
    ll ans=0,prev=0;
    while(n--)
    {
        ll u;
        cin>>u;
        if(u<prev)
        {
            ans+=prev-u;
        }
        else
            prev=u;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3900
// AtCoder ABC084 D - 2017-like Number
// 2020.1.23 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

#define MAX  100000
#define SQRT 316
char prime[MAX+3] = { 0,0,1,1,0 };
void sieve()
{
	int i, j;
	memset(prime, 1, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (i = 4; i <= MAX; i+=2) prime[i] = 0;
	for (i = 3; i <= SQRT; i += 2) if (prime[i]) {
		for (j = i*i; j <= MAX; j += i) prime[j] = 0;
	}
}

char f[MAX+3];
int a[MAX+3];

int main()
{
	int i, l, r, Q;
	
	sieve();
	for (i = 1; i <= MAX; i+=2) {
		if (prime[i] && prime[(i+1)>>1]) f[i] = 1;
	}
	for (i = 1; i <= MAX; i++) a[i] = a[i-1]+f[i];
	Q = in();
	while (Q--) {
		l = in(), r = in();
		out(a[r]-a[l-1]);
	}
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pub push_back
#define ll long long
					  
using namespace std;

int n;
vector<pair<int, int> > g[100007];
int up[18][100007];
ll path[100007];
int tin[100007], tout[100007];

int tt = 0;
void dfs(int v, int pred, ll len){
	tin[v] = tt++;
	path[v] = len;
	up[0][v] = pred;
	for (int i = 1; i < 18; i++) up[i][v] = up[i - 1][up[i - 1][v]];
	for (auto to : g[v]) if (to.x != pred) dfs(to.x, v, len + to.y);
	tout[v] = tt++;
}

bool isPred(int a, int b){
	return tin[a] <= tin[b] && tout[b] <= tout[a];
}

int getLca(int a, int b){
	if (isPred(a, b)) return a;
	if (isPred(b, a)) return b;
	for (int i = 17; i >= 0; i--) if (!isPred(up[i][a], b)) a = up[i][a];
	return up[0][a]; 
}

ll getPathLen(int a, int b){
	int c = getLca(a, b);
	return path[a] + path[b] - 2 * path[c];
}

int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("seating.in", "r", stdin);
	//freopen("seating.out", "w", stdout);
	cin >> n;
	for (int i = 0; i < n - 1; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].pub(mp(b, c));
		g[b].pub(mp(a, c));
	}
	dfs(0, 0, 0);
	int m, k;
	cin >> m >> k; k--;
	while(m--){
		int a, b;
		cin >> a >> b;
		a--; b--;
		cout << getPathLen(a, k) + getPathLen(k, b) << "\n";
	}
}

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

long long MOD = 1000000007;

long long modPlus(long long a, long long b) {
    return (a + b) % MOD;
}

int main(void)
{
    int n;
    int m;
    cin >> n >> m;
    vector<long long> p(n+1);
    vector<bool> a(n+1, true);
    for (int i = 1; i < m+1; i++) {
        int x;
        cin >> x;
        a[x] = false;
    }
    p[0] = 1;
    if (a[1] == true) p[1] = 1;
    else p[1] = 0;
    for (int i = 2; i < n+1; i++) {
        if (a[i] == false) {
            p[i] = 0;
            continue;
        }
        p[i] = modPlus(p[i-1], p[i-2]);
    }
    cout << p[n] << endl;

    return 0;
}



Measured memory_bytes: 1024
//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define si(x) scanf("%d",&x)
#define sii(a,b) scanf("%d%d",&a,&b)
#define siii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define siiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sl(x) scanf("%lld",&x)
#define sll(a,b) scanf("%lld%lld",&a,&b)
#define slll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sllll(a,b,c,d) scanf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define ss(x) scanf("%s",x+1)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define piiii(a,b,c,d) printf("%d %d %d %d",a,b,c,d)
#define Pi(x) printf("%d\n",x)
#define Pii(x,y) printf("%d %d\n",x,y)
#define Piii(a,b,c) printf("%d %d %d\n",a,b,c)
#define Piiii(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(a,b,c) printf("%lld %lld %lld",a,b,c)
#define pllll(a,b,c,d) printf("%lld %lld %lld %lld",a,b,c,d)
#define Pl(x) printf("%lld\n",x)
#define Pll(x,y) printf("%lld %lld\n",x,y)
#define Plll(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define Pllll(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define ps(x) printf("%s",x+1)
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;typedef long long LL;typedef long double LD;const LL pp=1e9+7;const LD eps=1e-8;
inline LL ksm(LL x,LL y=pp-2){x=(x%pp+pp)%pp;LL ans=1;while (y){if (y&1) ans=ans*x%pp;x=x*x%pp;y>>=1;}return ans;}
inline LL gcd(LL x,LL y){return y?gcd(y,x%y):x;}
inline void reads(char s[],int &n){n=0;char ch=getchar();while (ch==' ' || ch=='\n' || ch=='\r') ch=getchar();
while (ch!=' ' && ch!='\n' && ch!='\r' && ch!=EOF) s[++n]=ch,ch=getchar();}
//========================    C    ========================    N    ==================================
int n,tot,u,p;
int len[200009],ch[1000009][29],c[1000009][29],k[29];
LL ans=0;
char str[1000009];
#include <vector>
vector<int>S[200009];
void count(int u)
{
	for (int i=1;i<=26;i++)
		ans+=1ll*c[u][i]*((k[i])?1:0);
}
int main()
{
	//freopen("r.txt","r",stdin);
	//freopen("w1.txt","w",stdout);
	tot=1;
	si(n);
	for (int i=1;i<=n;i++)
	{
		reads(str,len[i]);
		S[i].push_back(0);
		for (int j=1;j<=len[i];j++)
			S[i].push_back(str[j]-'a'+1);
		u=1;p=len[i];
		while (ch[u][S[i][p]] && p>=2)
			u=ch[u][S[i][p]],p--;
		while (p>=2)
			ch[u][S[i][p]]=++tot,u=tot,p--;
		c[u][S[i][1]]++;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=26;j++)
			k[j]=0;
		for (int j=1;j<=len[i];j++)
			k[S[i][j]]++;
		u=1;p=len[i];
		count(u);
		while (ch[u][S[i][p]] && p>=1)
		{
			u=ch[u][S[i][p]];
			k[S[i][p]]--;
			p--;
			count(u);
		}
	}
	Pl(ans-1ll*n);
	return 0;
}

Measured memory_bytes: 175120
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define int long long
signed main() {
	int N;
	cin >> N;
	vector<int> u(N,-1000000), d(N,-1000000),o(N,-1000000),w(N,0);
	vector<vector<int> > to(N);
	int A,B;
	for (int i = 0; i < N-1; i++) {
		cin >> A>>B;
		A--;
		B--;
		to[A].push_back(B);
		to[B].push_back(A);
	}
	int K;
	cin>>K;
	int V,P;
	int n;
	queue<int> qu;
	for (int i = 0; i < K; i++) {
		cin>>V>>P;
		V--;
		n=V;
		u[V]=P;
		d[V]=P;
		o[V]=P%2;
		w[V]=-1;
		qu.push(V);
	}
	
	
	bool f;
	int k;
	while (qu.size() > 0) {
		k = qu.front();
		
		for (int i = 0; i < to[k].size(); i++) {
			f=false;
			if (u[to[k][i]]==-1000000){
				o[to[k][i]]=((o[k]+1)%2);
				u[to[k][i]]=u[k]+1;
				d[to[k][i]]=d[k]-1;
				qu.push(to[k][i]);
			}else{

				if(o[to[k][i]]!=((o[k]+1)%2)){
					cout<<"No"<<endl;
					return 0;
				}
				if(u[to[k][i]]>u[k]+1){
					u[to[k][i]]=u[k]+1;
					f=true;
				}
				if(d[to[k][i]]<d[k]-1){
					d[to[k][i]]=d[k]-1;
					f=true;
				}
				if(d[to[k][i]]>u[to[k][i]]){
					cout<<"No"<<endl;
					return 0;
				}
				if(f){
					qu.push(to[k][i]);
				}
			}
		}
		qu.pop();
	}
	
	cout << "Yes" << endl;
	for(int i=0;i<N;i++){
		cout << u[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,S;cin>>N;
  vector<int>B(N-1);
  cin>>B.at(0);S=B.at(0);
  for(int i=1;i<N-1;i++){
    cin>>B.at(i);
    S+=min(B.at(i),B.at(i-1));
  }
  cout<<S+B.at(N-2)<<endl;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

typedef double D;
typedef complex<D> P;

#define X real()
#define Y imag()

const D eps=1e-9;
const D inf=1e12;
const D PI=acos(-1);

bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
bool cmp_y(const P& a,const P& b){ return a.Y==b.Y?a.X<b.X:a.Y<b.Y; }
bool cmp_a(const P& a,const P& b){ return arg(a)==arg(b)?norm(a)<norm(b):arg(a)<arg(b); }
D cross(P a,P b){ return (conj(a)*b).Y; }
D dot(P a,P b){ return (conj(a)*b).X; }
D toRag(D deg){ return deg*PI/180.0; }
P rot(P base,P a,D theta){ return base+polar(abs(a-base),arg(a-base)+theta); }

struct C{
  P p; D r;
  C(const P& p,D r):p(p),r(r){}
};

void crosspointCC(const C& c1,const C& c2,P& p1,P& p2){
  D x1=c2.p.X-c1.p.X,y1=c2.p.Y-c1.p.Y;
  D r1=c1.r,r2=c2.r;
  D a=(x1*x1+y1*y1+r1*r1-r2*r2)/2.0;
  p1=P(((a*x1+y1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.X,((a*y1-x1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.Y);
  p2=P(((a*x1-y1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.X,((a*y1+x1*sqrt((x1*x1+y1*y1)*r1*r1-a*a))/(x1*x1+y1*y1))+c1.p.Y);
}

int N;
int X0[50010],R[50010];
double l[50010],r[50010];
double crtl[50010],crtr[50010];

bool ok(double H){
  rep(i,N){
    if((double)R[i]<H){
      crtl[i]=-inf; crtr[i]=-inf;
      continue;
    }
    crtl[i]=max(l[i],X0[i]-sqrt(pow((double)R[i],2)-pow(H,2)));
    crtr[i]=min(r[i],X0[i]+sqrt(pow((double)R[i],2)-pow(H,2)));
    if(crtl[i]>crtr[i]){
      crtl[i]=-inf; crtr[i]=-inf;
    }
  }
  double mx=0,crt=0;
  rep(i,N){
    if(abs(l[i]-crtl[i])>eps){
      crt=0;
    }
    crt+=crtr[i]-crtl[i];
    maxch(mx,crt);
    if(abs(r[i]-crtr[i])>eps){
      crt=0;
    }
  }
  return mx>H*2-eps;
}

int main(){
  while(1){
    scanf("%d",&N);
    if(N==0)break;
    vector<C> cs;
    rep(i,N){
      scanf("%d%d",X0+i,R+i);
      cs.push_back(C(P(X0[i],0),R[i]));
    }
    l[0]=X0[0]-R[0];
    rep(i,N-1){
      P p1,p2;
      crosspointCC(cs[i],cs[i+1],p1,p2);
      r[i]=p1.X; l[i+1]=p1.X;
    }
    r[N-1]=X0[N-1]+R[N-1];

    double lb=0,ub=5e5;
    rep(_,50){
      double mid=(lb+ub)/2.0;
      if(ok(mid))lb=mid;
      else ub=mid;
    }
    printf("%.10f\n", 2.0*lb);
  }
  return 0;
}



Measured memory_bytes: 7456
from itertools import permutations
from math import factorial, hypot

n = int(input())
p = [list(map(int, input().split())) for i in range(n)]

ans = 0
for ps in permutations(p, n):
    x1, y1 = ps[0]
    for i in range(n):
        x2, y2 = ps[i]
        ans += hypot(x1-x2, y1-y2)
        x1, y1 = x2, y2
ans /= factorial(n)
print(ans)


Measured memory_bytes: 41196
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<iomanip>

#define ll long long

using namespace std;

int main(){
    double N,K;
    cin >> N >> K;
    int k;
    double l;
    double keep=0.000;
    double j;
    for(int i=1;i<=N;i++){
        j=1.0;
        l=1.0;
        k=0;
        while(K-(i*j)>0){
            j*=2.0;
            k++;
        }
        for(int p=0;p<k;p++){
            l/=2.0;
        }
        keep+=l/N;
        //printf("%0.10lf\n",l/N);
    }
    cout << setprecision(12) << keep << endl;
    return 0;
}


Measured memory_bytes: 256
/*
  dp[i][j] = iばんめまでで
  greedy?
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
using ll = long long;

int main(){
    int T;
    cin >> T;
    rep(it, T){
        int n,d;
        cin >> n >> d;
        int ans = 0;
        ans += (n&1) ? d : d^127;
        ans += 127*(n-1);
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
import heapq
import collections
def main():

    N, M = map(int, input().split())
    graph = collections.defaultdict(dict)
    for i in range(N-1):
        graph[i+1][i] = 0

    for _ in range(M):
        L, R, C = map(int, input().split())
        if L-1 in graph and R-1 in graph[L-1]:
            graph[L-1][R-1] = min(graph[L-1][R-1], C)
        else:
            graph[L-1][R-1] = C

    dist = [float('inf') for _ in range(N)]
    dist[0] = 0
    v = []
    heapq.heappush(v, [0, 0])

    while len(v) > 0:
        d, u = heapq.heappop(v)
        if d > dist[u]: continue
        for w in graph[u]:
            if dist[w] > d + graph[u][w]:
                dist[w] = d + graph[u][w]
                heapq.heappush(v, [dist[w], w])

    if dist[N-1] == float('inf'): return -1

    return dist[N-1]

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

Measured memory_bytes: 61804
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    int q;
    cin >> q;
    vector<int> m(q);
    vector<int>ans(n);
    rep(i,q) cin >> m[i];
    for(int bit = 0; bit < (1<<n);bit++) {
        int sum = 0;
        for(int i = 0; i < n;i++) {
            if(bit & (1<<i)) {
                sum += a[i];
            }
        }
        ans.push_back(sum);
    }
    for(int i = 0;i<q;i++) {
        bool exist = false;
        for(int j = 0;j<ans.size();j++) {
            if(m[i] == ans[j]) {
                exist = true;
                cout << "yes" << endl;
                break;
            }
        }
        if(!exist) cout << "no" << endl;
    }
}



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

using namespace std;

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

int main() {
    while (true) {
        int n, l, r;
        cin >> n >> l >> r;
        if (n == 0 && l == 0 && r == 0)
            break;
        vector<int> v[2];
        FOR(i,l,r+1)
            v[0].PB(i);

        int res = 0;
        REP(i, n) {
            int a;
            cin >> a;
            v[1-i%2].erase(v[1-i%2].begin(), v[1-i%2].end());
            int count = 0;
            for (const auto & e : v[i%2]) {
                if (e % a == 0)  {
                    ++count;
                }
                else
                    v[1-i%2].PB(e);
            }
            if (i % 2 == 0)
                res += count;
        }
        if (n % 2 == 0)
            res += v[0].size();
        cout << res << endl;
    }
}


Measured memory_bytes: 3216
// WA 2019.06.14
#include<bits/stdc++.h>
using namespace std;
double avg_temp(double t, double x){
    double tmp=0;
    tmp = x*0.006;

    return t-(x*0.006);
}
int main(){
    int n;
    double t, a;
    double h;
    double avgt;
    double dis;
    pair<int, double> p1;
    p1 = std::make_pair(1, 100000);
    cin >> n;
    cin >> t >> a;
    for(int i=1; i<=n; ++i){
        cin >> h;
        avgt = avg_temp(t,h);
        dis = abs(a-avgt);
        if(dis < p1.second) {
            p1 = make_pair(i, dis);
        }else{
        }
        //cout << p1.first << ":" << p1.second << endl;
    }
    cout << p1.first << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define len(val) static_cast<long long>(val.size())
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
typedef pair<int, int> P;


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

    string s;
    cin >> s;
    ll N = len(s);
    ll ans = 0;
    ll r = 0;
    ll l = N-1;
    while(true){
      if(r >= l){
        cout << ans << endl;
        return 0;
      }else if(s[r] ==  s[l]){
        r++; l--;
      }else if(s[l] == 'x'){
        ans++;
        l--;
      }else if(s[r] == 'x'){
        ans++;
        r++;
      }else{
        cout << -1 << endl;
        return 0;
      }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512