akhauriyash/Code-Regression huggingface dataset:
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l.shift() * 1
M = l.shift() * 1 
a = new Array(N)
b = true
for (i=0; i<M; i++) {
  l = inp.shift().split(' ')
  if (a[l[0] - 1] === undefined) {
      a[l[0] - 1] = l[1]
  } else if (a[l[0] - 1] != l[1]) {
      b = false
      break;
  }
}
if (b) {
    for (i=0; i<N; i++) {
        if (i === 0 && a[i] === undefined && N > 1) {
            a[i] = 1
            continue;
        }
        if (a[i] === undefined) {
            a[i] = 0
        }
    }
    ans = a.join("") * 1
    if (a.join("") == ans && N == (ans + "").length) {
        b = true
    } else {
        b = false
    }
}
console.log(b ? ans : -1)

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	int W,H,N;
	cin>>W>>H>>N;
	vector<vector<int>>vec;
	rep(i,H){
		vector<int>t;
		rep(j,W){
			t.push_back(0);
		}
		vec.push_back(t);
	}
	rep(i,N){
		int x,y,a;
		cin>>x>>y>>a;
		if(a==1){
			for(int j=0;j<x;j++){
				for(int k=0;k<H;k++){
					vec[k][j]=1;
				}
			}
		}
		else if(a==2){
			for(int j=x;j<W;j++){
				for(int k=0;k<H;k++){
					vec[k][j]=1;
				}
			}
		}
		else if(a==3){
			for(int j=0;j<W;j++){
				for(int k=0;k<y;k++){
					vec[k][j]=1;
				}
			}
		}
		else{
			for(int j=0;j<W;j++){
				for(int k=y;k<H;k++){
					vec[k][j]=1;
				}
			}
		}
	}
	int ANS=0;
	for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
			if(vec[i][j]==0)ANS++;
		}
	}
	cout<<ANS<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  int a,b,c; cin >> a >> b >> c;
  int k; cin >> k;
  while(k-- > 0) {
    if(a >= b) b *= 2;
    else if(b >= c) c *= 2;
    else break;
  }

  if(a < b && b < c) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  
  return 0;
}


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

ll MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    int color1 = -1;
    int color2 = -1;
    int color3 = -1;
    ll answer = 1;
    for(int i = 0; i < N; i++)
    {
        int A;
        cin >> A;
        int possible = 3;
        if(color1 + 1 != A){
            possible--;
        }
        if(color2 + 1 != A){
            possible--;
        }
        if(color3 + 1 != A){
            possible--;
        }
        answer = (answer * possible) % MOD;
        if(color1 + 1 == A){
            color1++;
        }else if(color2 + 1 == A){
            color2++;
        }else if(color3 + 1 == A){
            color3++;
        }
    }
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 256
def insertion_sort(a, n, g)
  (g...n).each do |i|
    v = a[i]
    j = i - g
    while j >= 0 && a[j] > v do
      a[j+g] = a[j]
      j -= g
      $cnt += 1
    end
    a[j+g] = v
  end
end

def shell_sort(a, n)
  $cnt = 0
  $g = []
  h = 0
  (0...n).each do |i|
    h = 3 * h + 1
    break if n < h
    $g.push(h)
  end
  $g.reverse!
  $m = $g.size
  (0...$m).each do |i|
    insertion_sort(a, n, $g[i])
  end
end

n = gets.to_i
a = Array.new(n)

(0...n).each do |i|
  a[i] = gets.to_i
end

shell_sort(a, n)
puts $m
puts $g.join(" ")
puts $cnt
puts a.join("\n")

Measured memory_bytes: 26172
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	int n,k; cin >> n >> k;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int sorted=0;
	int cnt=0;
	for(int i=0;i<n-1;i++){
		if(a[i]<a[i+1]){
			cnt++;
		}
		else cnt=0;
		if(cnt==k-1)sorted++;
	}
	set<int> s;
	for(int i=0;i<k;i++){
		s.insert(a[i]);
	}
	int ans=1;
	for(int i=0;i<n-k;i++){
		ans++;
		auto it=s.begin();
		auto itt=s.end(); itt--;
		if(a[i]==*it&&a[i+k]>*itt)ans--;
		s.erase(a[i]);
		s.insert(a[i+k]);
	}
	if(sorted)ans-=sorted-1;
	cout << ans << endl;
}

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

typedef long long int ll;
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)

int main() {
	FASTIO;
	string N;
	ll sum = 0;
	cin >> N;
	FOR(i, 0, N.size() - 1) {
		sum += (N[i] - '0');
	}
	if (sum % 9 == 0)
		cout << "Yes";
	else
		cout << "No";


	return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n,l[105],ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	sort(l,l+n);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if(l[k]<l[j]+l[i] && l[k]!=l[j] && l[j]!=l[i]){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 3648
#include <iostream>
#include <stdlib.h>
using namespace std;

#define MAX 100000
#define SENTINEL 2000000000

struct Card { int number; char mark; };

int partition(Card C[], int p, int r) {
    int x = C[r].number;
    int i = p - 1;
    Card tmp;
    for (int j = p; j < r; j++) {
        if (C[j].number <= x) {
            i++;
            tmp = C[i];
            C[i] = C[j];
            C[j] = tmp;
        }
    }
    tmp = C[i+1];
    C[i+1] = C[r];
    C[r] = tmp;
    return i+1;
}

void q_sort(Card C[], int p, int r) {
    if (p < r) {
        int q = partition(C, p, r);
        q_sort(C, p, q-1);
        q_sort(C, q+1, r);
    }
}

Card L[MAX/2+2], R[MAX/2+2];
void merge(Card C[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) {
        L[i] = C[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = C[mid + i];
    }
    L[n1].number = R[n2].number = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i].number <= R[j].number) {
            C[k] = L[i++];
        } else {
            C[k] = R[j++];
        }
    }
}

void merge_sort(Card C[], int left, int right) {
    if (left+1 < right) {
        int mid = (left + right) / 2;
        merge_sort(C, left, mid);
        merge_sort(C, mid, right);
        merge(C, left, mid, right);
    }
}

int main() {
    Card C1[MAX], C2[MAX];
    int n;
    cin >> n;

    int num;
    char mark;
    for (int i = 0; i < n; i++) {
        cin >> mark >> num;
        C1[i].mark = mark;
        C1[i].number = num;
        C2[i] = C1[i];
    }

    q_sort(C1, 0, n-1);
    merge_sort(C2, 0, n);

    bool is_stable = true;
    for (int i = 0; i < n; i++) {
        if (C1[i].number != C2[i].number || C1[i].mark != C2[i].mark) is_stable = false;
    }

    if (is_stable) {
        cout << "Stable";
    } else {
        cout << "Not stable";
    }
    cout << endl;

    for (int i = 0; i < n; i++) {
        cout << C1[i].mark << " " << C1[i].number << endl;
    }

    return 0;
}



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

#define N 100000
#define M 100000
#define INF 0x3f3f3f3f3f3f3f3fLL

int main() {
	static long long ss[N], tt[M];
	int n, m, q, i, j;

	scanf("%d%d%d", &n, &m, &q);
	for (i = 0; i < n; i++)
		scanf("%lld", &ss[i]);
	for (j = 0; j < m; j++)
		scanf("%lld", &tt[j]);
	while (q--) {
		long long x, xs1, xs2, xt1, xt2, d, ans;
		int lower, upper;

		scanf("%lld", &x);
		lower = -1, upper = n;
		while (upper - lower > 1) {
			i = (lower + upper) / 2;
			if (ss[i] < x)
				lower = i;
			else
				upper = i;
		}
		xs1 = lower == -1 ? -1 : ss[lower];
		xs2 = upper == n ? -1 : ss[upper];
		lower = -1, upper = m;
		while (upper - lower > 1) {
			j = (lower + upper) / 2;
			if (tt[j] < x)
				lower = j;
			else
				upper = j;
		}
		xt1 = lower == -1 ? -1 : tt[lower];
		xt2 = upper == m ? -1 : tt[upper];
		ans = INF;
		if (xs1 != -1 && xt1 != -1) {
			d = x - (xs1 < xt1 ? xs1 : xt1);
			if (ans > d)
				ans = d;
		}
		if (xs1 != -1 && xt2 != -1) {
			d = x - xs1 + xt2 - xs1;
			if (ans > d)
				ans = d;
			d = xt2 - x + xt2 - xs1;
			if (ans > d)
				ans = d;
		}
		if (xs2 != -1 && xt1 != -1) {
			d = xs2 - x + xs2 - xt1;
			if (ans > d)
				ans = d;
			d = x - xt1 + xs2 - xt1;
			if (ans > d)
				ans = d;
		}
		if (xs2 != -1 && xt2 != -1) {
			d = (xs2 > xt2 ? xs2 : xt2) - x;
			if (ans > d)
				ans = d;
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2816
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main() {

    string S; cin>>S;

    for (int i = 0; i < S.length(); ++i) {
        cout<<"x";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<long long int>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i = (a); i < (n); i++)
#define fi(i,a,n) for(i = (a); i <= (n); i++)
#define F first
#define S second
int main(){
    string s;
    string t;
    cin>>s>>t;
    ll c = 0;
    for(ll i=0;i<3;i++){
        if(s[i]==t[i]){
            c++;
        }
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val cards = (1..3).map { readLine()!!.map { it - 'a' }.toMutableList() }

    var current = 0
    while (cards.all { it.count() >= 0 }) {
        if(cards[current].isEmpty()) {
            println('A' + current)
            return
        }
        val num = cards[current][0]
        cards[current].removeAt(0)
        current = num
    }
}


Measured memory_bytes: 31900
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,i,j,a[1010][1010],t=-1,k[1010]={};
  bool d[1010],pos=true;
  cin >> n;
  for (i=1;i<=n;i++) for (j=0;j<n-1;j++) cin >> a[i][j];
  while (pos){
    t++;
    pos=false;
    for (i=1;i<=n;i++) d[i]=false;
    for (i=1;i<=n;i++) if (k[i]!=n-1){
      j=a[i][k[i]];
      if (!d[i] && !d[j] && a[j][k[j]]==i){
        pos=true;
        k[i]++;
        k[j]++;
        d[i]=true;
        d[j]=true;
      }
    }
  }
  for (i=1;i<=n;i++) if (k[i]!=n-1) break;
  if (i==n+1) cout << t << endl;
  else cout << -1 << endl;
  return 0;
}


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

int main() {
  int i,n;
  vector<int> a(100);
  int Alice,Bob;
  
  cin >> n;
  for (i=0;i<n;++i)
  {
    cin >> a[i];
  }

  sort(a.begin(),a.end(),greater<int>());//降順ソート
  Alice=Bob=0;
  for (i=0;i<n;++i)
  {
    if (i%2 == 0)
    	Alice += a[i];
    else
      	Bob += a[i];
  }
 
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

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

	int A,B,C;
	cin>>A>>B>>C;
	cout<<max(0,C-(A-B))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define PI 3.14159265358979323846
typedef long long ll;
using namespace std;
ll n,i,j,k,x,y,w,m,Q, start;
pii a[200500];
ll x1,y1,x2,y2,N;
ll t[400500];
map<ll,ll> f;
void modify(int p, int value) {  // set value at position p
  for (t[p += N] = value; p > 1; p >>= 1) t[p>>1] = max(t[p], t[p^1]);
}

ll query(int l, int r) {  // sum on interval [l, r)
  ll res = -(ll)1e+18;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = max(res,t[l++]);
    if (r&1) res = max(res,t[--r]);
  }
  return res;
}
int main() {
    //freopen("input.txt", "r", stdin);
    cin >> x1 >> y1 >> x2 >> y2;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> a[i].X >> a[i].Y;
    }
    sort(a, a+n);
    if (x1 > x2)
    {
        swap(x1, x2);
        swap(y1,y2);
    }
    if (x1 == x2)
    {
        if (y1 > y2)
            swap(y1, y2);
        ll k = 0;
        for (i = 0; i < n; i++)
        {
            if (a[i].X == x1 && a[i].Y >= y1 && a[i].Y <= y2)
                k = 1;
        }
        printf("%.15f\n", 1.*k*(10*PI-20)+(y2-y1)*100);
        return 0;
    }
    if (y1 == y2)
    {
        if (x1 > x2)
            swap(x1, x2);
        ll k = 0;
        for (i = 0; i < n; i++)
        {
            if (a[i].Y == y1 && a[i].X >= x1 && a[i].X <= x2)
                k = 1;
        }
        printf("%.15f\n", 1.*k*(10*PI-20)+(x2-x1)*100);
        return 0;
    }
    if (y1 > y2)
    {
        y1 = 100000000-y1;
        y2 = 100000000-y2;
        for (i = 0; i < n; i++)
        {
            a[i].Y = 100000000-a[i].Y;
        }
        sort(a, a+n);
    }
    ll cur = (y2-y1+x2-x1)*100;
    ll min1 = min(y2-y1, x2-x1);
    for (i = 0; i < n; i++)
    {
        f[a[i].Y] = 0;
    }
    f[y1] = f[y2] = 0;
    i = 0;
    for (auto itr = f.begin(); itr != f.end(); itr++)
    {
        f[(*itr).X] = i++;
    }
    for (i = 0; i < n; i++)
        a[i].Y = f[a[i].Y];
    N = n+2;
    y1 = f[y1], y2 = f[y2];
    for (i = 0; i <= 2*N; i++)
        t[i] = -(ll)1e+18;
    modify(y1, 0);
    for (i = 0; i < n; i++)
    if (a[i].X >= x1 && a[i].X <= x2)
    {
        ll tmp = query(y1, a[i].Y+1);
        ll cur = query(a[i].Y, a[i].Y+1);
        modify(a[i].Y, max(cur,tmp+1));
        //cout << a[i].Y << " " << tmp+1 << endl;
    }
    ll ans = query(y1, y2+1);
    printf("%.15f\n", cur - ans*(20-5*PI)+(ans==min1+1?5*PI:0));
    return 0;
}


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

int main(){
  int n,k,a[100000],sum,maxv;
  
  while(cin >> n >> k,n||k){
    sum = 0;
    for(int i=0;i<k;i++){
      cin >> a[i]; sum += a[i];
    }
    
    maxv = sum;
    for(int i=k;i<n;i++){
      cin >> a[i]; sum += a[i] - a[i-k];
      maxv = std::max(maxv,sum);
    }
    cout << maxv << endl;
  }
}
		   

Measured memory_bytes: 1552
#include <cstdio>

using namespace std;

int dic[30];

int main() {
    char c;
    while (true) {
        if (scanf("%c", &c) == EOF) break;
        if ('A' <= c && c <= 'Z') dic[c - 'A']++;
        else if ('a' <= c && c <= 'z') dic[c - 'a']++;
    }
    for (int i = 0; i < 26; ++i) {
        printf("%c : %d\n", 'a' + i, dic[i]);
    }
    return 0;
}



Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    double x;
    cin >> x; 
    double side = x / 3.;
    double ans = (side * side * side);
    printf("%.10lf\n", ans); 
    return 0;
}



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

typedef long long ll;

using namespace std;

#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, n) for(ll i=n; i>=0; i--)
#define reps(i, s, e) for(ll i=s; i<e; i++)
#define all(x) x.begin(),x.end()

int main(){
	int N;

	cin >> N;

	string S;

	cin >> S;

	int ans = 1;

	rep(i,N-1){
		if(S[i] != S[i+1]){
			ans += 1;
		}
	}

	cout << ans << endl;

	return 0;

}	

Measured memory_bytes: 512
n,m,x= map(int, input().split())

c=[]

for i in range(n):
    a = [int(x) for x in input().split()]
    c.append(a)

for i in range(1,m+1):
    kei=0
    for j in range(n):
        kei+=c[j][i]
    if kei<x:
        print(-1)
        exit()

ans=10**16

for j in range(1,2**n):
    b=format(j,"012b")
    b=b[::-1]
    nedan=0
    skill=[0]*m
    for k in range(n):
        if int(b[k])==1:
            nedan+=c[k][0]
            for l in range(0,m):
                skill[l]+=c[k][l+1]
    if all(goukei>=x for goukei in skill):
        ans=min(ans,nedan)

print(ans)


Measured memory_bytes: 9236
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1000000007;
const int MAX_V = 8;

int n, m, ans = 0;
Graph G(MAX_V, vector<int>(MAX_V));
vector<int> visited(MAX_V);

void dfs(int v) {

    int flag = 1;
    rep(i, n) {
        if(!visited[i]) {
            flag = 0;
        }
    }

    if(flag) {
        ans++;
    }
    
    rep(u, n) {
        if(G[v][u] && !visited[u]) {
            visited[u] = 1;
            dfs(u);
            visited[u] = 0;
        }
    }

}

int main() {

    cin >> n >> m;

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a][b] = G[b][a] = 1;
    }

    visited[0] = 1;    

    dfs(0);

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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

bool j = false;

int main() {

	int x, y;

	cin >> x >> y;

	rep(i, x + 1) {
		int tmp = x - i;

		if (i * 2 + tmp * 4 == y)j = true;

	}

	if (j)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int a[200001];
int b[200001];
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		//printf("%d ",a[n/2-1]);
		if(b[i]>a[n/2-1])
			printf("%d\n",a[n/2-1]);
		else
			printf("%d\n",a[n/2]);
	}
	return 0;
}


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

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    private void solve(){
        int a = in.nextInt();
        int b = in.nextInt();

        if(a == b) {
            out.print("Draw");
            return;
        }
        if(a == 1){
            out.print("Alice");
            return;
        }
        if(b == 1){
            out.print("Bob");
            return;
        }

        if(a>b) out.print("Alice");
        else out.print("Bob");
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 24660
from collections import defaultdict

n, k, l = map(int, input().split())

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

#	def find(self, x):
#		while self.table[x] >= 0:
#			x = self.table[x]
#		return x

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]


	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
		return

road = UnionFind(n)
train = UnionFind(n)

for _ in range(k):
	a, b = map(int, input().split())
	road.union(a - 1, b - 1)

for _ in range(l):
	a, b = map(int, input().split())
	train.union(a - 1, b - 1)

road_root = []
for i in range(n):
	num = road.find(i)
	road_root.append(num)

train_root = []
for i in range(n):
	num = train.find(i)
	train_root.append(num)

count = defaultdict(int)
for i in range(n):
	count[road_root[i] * (10 ** 6) +  train_root[i]] += 1

ans = []
for i in range(n):
	ans.append(count[road_root[i] * (10 ** 6) +  train_root[i]])

print(*ans)


Measured memory_bytes: 46396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=100010;
int N,M,lin[maxn*5],len,cnt;
struct edge{
	int y,next,v;
}e[maxn*12];
inline void insert(int xx,int yy,int vv){
	e[++len].next=lin[xx];
	lin[xx]=len;
	e[len].y=yy;
	e[len].v=vv;
}
inline void ins(int xx,int yy,int vv){
	//printf("%d %d %d\n",xx,yy,vv);
	insert(xx,yy,vv);
	insert(yy,xx,vv);
}
map<pair<int,int>,int>id;
int get_id(int x,int y){
	if(id[make_pair(x,y)])
		return id[make_pair(x,y)];
	return id[make_pair(x,y)]=++cnt;
}
deque<int>q;
int dis[maxn*5];
void bfs(){
	memset(dis,10,sizeof(dis));
	dis[1]=0;
	q.clear();
	q.push_back(1);
	while(!q.empty()){
		int u=q.front();
		q.pop_front();
		for(int i=lin[u];i;i=e[i].next)
			if(dis[e[i].y]>dis[u]+e[i].v){
				dis[e[i].y]=dis[u]+e[i].v;
				if(!e[i].v)
					q.push_front(e[i].y);
				else
					q.push_back(e[i].y);
			}
	}
	if(dis[N]==dis[0])
		puts("-1");
	else
		printf("%d\n",dis[N]/2);
}
int main(){
	//freopen("in","r",stdin);
	cnt=N=read(),M=read();
	for(int i=1;i<=M;i++){
		int x=read(),y=read(),c=read();
		ins(get_id(x,c),get_id(y,c),0);
		ins(get_id(x,c),x,1);
		ins(get_id(y,c),y,1);
	}
	bfs();
	return 0;
}



Measured memory_bytes: 43648
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int ans,a, b;
	cin >> a >> b;
	ans = (a + b) % 24;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}
const ll N=5*1e5+5;
struct tt{
  ll ar[26];
};
tt vii;
// int ar[100005];
string s;
tt tree[4*N];
 
 tt merge (tt a,tt b)
 {
  tt final;
   for(ll i=0;i<26;i++)
    final.ar[i]=a.ar[i]+b.ar[i];
  return final;
 }
 
 
void build(ll node,ll start,ll end)
{
    if(start==end)
    {
        tree[node].ar[s[start]-'a']++;
        return;
    }
   else
   {
     ll mid=(start+end)/2;
     build(2*node,start,mid);
     build(2*node+1,mid+1,end);
 
     tree[node]=merge(tree[2*node],tree[2*node+1]);
 
   }
}
tt query(ll l,ll r,ll start,ll end,ll node)
{
    if(end<l||start>r)   //checking whether range is out of L and R
       {
            return vii;
       }
    else if(l<=start&&end<=r)   // if the range is completely under L and R
        {
            return tree[node];
        }
    else                // if there is partial overlap between range and L and R
       {
           ll mid=(start+end)/2;
           tt p1=query(l,r,start,mid,2*node);      // Checking for answer in left part
           tt p2=query(l,r,mid+1,end,2*node+1);    // Checking for answer in right part
           return merge(p1,p2);
       }
}
void update(ll idx,char c,ll node,ll start,ll end)
{
  ll mid=(start+end)/2;
  if(start==end)
  {
    tree[node].ar[s[start]-'a']--;
    s[start]=c;
    tree[node].ar[s[start]-'a']++;
  }
  else
  {
    if(start<=idx&&idx<=mid)
      update(idx,c,2*node,start,mid);
    else
      update(idx,c,2*node+1,mid+1,end);
    tree[node]=merge(tree[2*node],tree[2*node+1]);
  }
}
int32_t main()
{   
     IOS;
     ll n;
     cin>>n;
     cin>>s;
     build(1,0,n-1);
     ll i,j,k,q;
     cin>>q;
     while(q--)
     {
       ll x;
       cin>>x;
       if(x==1)
       {
         ll id;char ch;
         cin>>id>>ch;
         update(id-1,ch,1,0,n-1); 
       }
       else
       {
         ll ans=0;
          ll l,r;
        cin>>l>>r;
         tt ap=query(l-1,r-1,0,n-1,1);
         for(i=0;i<26;i++) if(ap.ar[i]) ans++;
          cout<<ans<<endl;
       }
     }
     
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 215964
#include<iostream>
#include<cmath>
using namespace std;
int n,a[10000005];
long long sum;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		a[i]=i;
		sum+=a[i];
		if(sum>n) break;
	}
	a[sum-n]=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=0) cout<<a[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

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

int getInt() {
    int s;
    scanf("%d", &s);
    return s;
}

int main(){
    const int n = getInt();
    vector<int> p(n);
    vector<int> q(n);

    REP(i,n) p[i] = getInt() - 1;
    REP(i,n) q[i] = getInt() - 1;

    vector<int> c(n);
    REP(i,n) c[i] = i;

    int a = -1;
    int b = -1;

    int i = 0;
    do {
        if(c == p) a = i;
        if(c == q) b = i;
        i++;
    }while(next_permutation(c.begin(), c.end()));

    printf("%d\n", std::abs(a - b));

    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
A = [0] + list(map(int,readline().split()))

c = 1
while K:
  if K&1:
    c = A[c]
  na = [0] * (N+1)
  for i in range(N+1):
    na[i] = A[A[i]]
  na,A = A,na
  K >>= 1
print(c)

Measured memory_bytes: 168292
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    //freopen("Inp.txt","r", stdin);
    //freopen("Out.txt","w", stdout);

    int n; cin >> n;
    vector<double> dp(n+1,1);
    for (int i = 1; i <= n; i++)
    {
        double p;
        cin >> p;

        for (int j = i; j  >= 1; j--)
            if (j == i)
                dp[j] = (1-p) * dp[j-1];
            else
                dp[j] = (1-p)*dp[j-1] + (p)*dp[j];
        dp[0]*=p;
//        for (int t = 0; t <= i; t++)
//            cout << dp[t] << " ";
//            cout << endl;
    }
    double sum = 0;
    for (int i = 0; i <= (n-1)/2; i++)
        sum+=dp[i];
    cout.precision(10);
    cout << fixed << sum;
    return 0;
}


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

int main() { 
    int n, k;
    double ans = 0.0;
    cin >> n >> k;

    for(int i = 1; i <= n; ++i) {
        int j = i, c = 0;
        while(j < k) {
            j *= 2;
            c++;
        }
        ans += (1.0/n)*pow(0.5, c);
    }

    printf("%.15lf\n", ans);

    return 0;
}


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

def eratosthenes_sieve(n: int):
    """
    エラトステネスの篩を用いてn以下の素数を求める
    """
    table = [0] * (n + 1)
    prime_list = [0, 0]
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(1)
            for j in range(i + i, n + 1, i):
                table[j] = 1
        else:
            prime_list.append(0)
    
    return prime_list

def solve(Q: int, l: "List[int]", r: "List[int]"):
    A = [0] * 100002
    prime_list = eratosthenes_sieve(100001)
    for i, p in enumerate(prime_list):
        if p == 1 and i % 2 == 1 and prime_list[(i+1)//2] == 1:
            A[i] = 1
        else:
            A[i] = 0
    A = list(itertools.accumulate(A))
    for q in range(Q):
        ll = l[q]
        rr = r[q]
        print(A[rr] - A[ll-1])
    return


# Generated by 1.1.5 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()
    Q = int(next(tokens))  # type: int
    l = [int()] * (Q)  # type: "List[int]"
    r = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(Q, l, r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16176
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int mod = 1e9+7;
typedef pair<int,int> P;
#define fi first
#define se second

int dp[302][302][302];
int calc(int k, int n){
	int res = 0;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(k == 0)res += dp[n][i][j];
			if(k == 1)res += dp[i][n][j];
			if(k == 2)res += dp[i][j][n];
			res %= mod;
		}
	}
	return res;
}

signed main(){
	int n, m;
	scanf("%lld%lld", &n, &m);
	vector<vector<P> > v(n+1);
	for(int i = 0;i < m;i++){
		int l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);
		v[r].push_back(P(l, x));
	}
	
	dp[0][0][0] = 1;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++){
			for(int k = 0;k <= n;k++){
				int r = max({i, j, k}), l = min({i, j, k});
				int mid = (i+j+k)-r-l;
				if(l && (mid == l || mid == r || l == r))continue;
				
				for(int p = 0;p < v[r].size();p++){
					P pp = v[r][p];
					if(pp.se == 1){
						if(pp.fi <= mid)dp[i][j][k] = 0;
					}else if(pp.se == 2){
						if(pp.fi <= l)dp[i][j][k] = 0;
						if(pp.fi > mid)dp[i][j][k] = 0;
					}else{
						if(pp.fi > l)dp[i][j][k] = 0;
					}
				}
				
				dp[r+1][j][k] += dp[i][j][k] %= mod;
				dp[i][r+1][k] += dp[i][j][k] %= mod;
				dp[i][j][r+1] += dp[i][j][k] %= mod;
			}
		}
	}
	
	int ans = 0;
	for(int i = 0;i < 3;i++)ans += calc(i, n);
	printf("%lld\n", ans%mod);
	return 0;
}


Measured memory_bytes: 215424
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
            return;
        }
        System.out.println("B");
    }

}


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

#define ll long long
#define N 200010
#define INFLL 0x3f3f3f3f3f3f3f3f
int n, m;
ll d, a[N];
struct Edge
{
    int u, v; ll w;
    Edge() {}
    Edge(int u, int v, ll w) : u(u), v(v), w(w) {}
    bool operator < (const Edge &other) const { return w < other.w; }
}edge[N * 30];

void add(int l, int r)
{
    if (l == r) return;
    int mid = (l + r) >> 1;
    ll Min = INFLL; int pos = -1; 
    for (int i = l; i <= mid; ++i) 
    {
        ll f = a[i] - d * i;
        if (f < Min)
        {
            Min = f;
            pos = i;
        }
    }
    for (int i = mid + 1; i <= r; ++i)
        edge[++m] = Edge(pos, i, a[pos] + a[i] + d * (i - pos));
    Min = INFLL; pos = -1;
    for (int i = mid + 1; i <= r; ++i)
    {
        ll f = a[i] + d * i;
        if (f < Min)
        {
            Min = f;
            pos = i;
        }
    }
    for (int i = l; i <= mid; ++i) 
        edge[++m] = Edge(pos, i, a[pos] + a[i] + d * (pos - i));
    add(l, mid);
    add(mid + 1, r);
}

int pre[N];
int find(int x) { return pre[x] == 0 ? x : pre[x] = find(pre[x]); }
ll Kruskal()
{
    memset(pre, 0, sizeof pre);
    sort(edge + 1, edge + 1 + m);
    int cnt = 1;
    ll res = 0;
    for (int i = 1; i <= m; ++i)
    {
        int u = edge[i].u, v = edge[i].v; ll w = edge[i].w;
        int fu = find(u), fv = find(v);
        if (fu == fv) continue;
        pre[fu] = fv;
        res += w;
        ++cnt;
        if (cnt == n) return res;
    }
    return res;
}

int main()
{
    while (scanf("%d%lld", &n, &d) != EOF)
    {
        m = 0;
        for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
        add(1, n);
        printf("%lld\n", Kruskal());
    }
    return 0;
}

Measured memory_bytes: 59648
while True:
    n = int(raw_input())
    if n==0: break
    l = map(float, raw_input().split())
    avg=sum(l)/len(l)
    naka=0
    for i in l:
        naka+=(i-avg)**2
    hyo2 = naka/n
    print (hyo2)**0.5


Measured memory_bytes: 4772
#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-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int n, i, j;
    cin>>n;
    string s[n];
    int p[n];
    int ans[n];
    string tmp1;
    int tmp2;
    for(i=0; i<n; i++){
        cin>>s[i]>>p[i];
        ans[i] = i+1;
    }
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            if(s[i]>s[j]){
                swap(s[i], s[j]);
                swap(p[i], p[j]);
                swap(ans[i], ans[j]);
            }
            else if(s[i]==s[j]){
                if(p[i]<p[j]){
                    swap(s[i], s[j]);
                    swap(p[i], p[j]);
                    swap(ans[i], ans[j]);
                }
            }
        }
    }

    for(i=0; i<n; i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    if(n % 2 == 0) cout << n << endl;
    else  cout << n*2 << endl;
    
}

Measured memory_bytes: 384
#include <cstdio>

int main(){
	int n, c, d[6], t;
	char s[10];
	while(scanf("%d", &n), n != 0){
		for(int i = 0;i < 6;i++)d[i] = i + 1;
		t = 1;
		for(int i = 0;i < n;i++){
			scanf("%s", s);
			if(s[0] == 'N'){
				c = d[0];
				d[0] = d[1];
				d[1] = d[5];
				d[5] = d[4];
				d[4] = c;
			}
			if(s[0] == 'E'){
				c = d[0];
				d[0] = d[3];
				d[3] = d[5];
				d[5] = d[2];
				d[2] = c;
			}
			if(s[0] == 'W'){
				c = d[0];
				d[0] = d[2];
				d[2] = d[5];
				d[5] = d[3];
				d[3] = c;
			}
			if(s[0] == 'S'){
				c = d[0];
				d[0] = d[4];
				d[4] = d[5];
				d[5] = d[1];
				d[1] = c;
			}
			if(s[0] == 'R'){
				c = d[1];
				d[1] = d[2];
				d[2] = d[4];
				d[4] = d[3];
				d[3] = c;
			}
			if(s[0] == 'L'){
				c = d[1];
				d[1] = d[3];
				d[3] = d[4];
				d[4] = d[2];
				d[2] = c;
			}
			t += d[0];
		}
		printf("%d\n", t);
	}
	return 0;
}

Measured memory_bytes: 2740
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

vii ed;
int addedge(int val1,int val2){
	if(val1*val2==0)
		return 0;
	ed.pb(mp(val1,val2));
}
int main(){
    std::ios::sync_with_stdio(false); cin.tie(NULL);
  	int n;
  	cin>>n;
  	int i;
  	vii vec;
  	if(n==3){
  		cout<<2<<endl;
		cout<<"1 3"<<endl;
		cout<<"2 3"<<endl;
  		return 0;
  	}
  	if(n%2==0){
  		f(i,1,n/2+1){
  			vec.pb(mp(i,n+1-i));
  		}
  		if(n!=4)
  			vec.pb(mp(1,n));
  	}
  	else{
  		n--;
  		f(i,1,n/2+1){
  			vec.pb(mp(i,n+1-i));
  		}
  		vec.pb(mp(n+1,0));
  		vec.pb(mp(1,n));
  	}
  	rep(i,vec.size()-1){
  		addedge(vec[i].ff,vec[i+1].ff);
  		addedge(vec[i].ff,vec[i+1].ss);
  		addedge(vec[i].ss,vec[i+1].ff);
  		addedge(vec[i].ss,vec[i+1].ss);
  	}
  	cout<<ed.size()<<endl;
  	rep(i,ed.size()){
  		cout<<ed[i].ff<<" "<<ed[i].ss<<endl;
  	}
    return 0;   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace  std;
    #define mod 1000000007
    typedef long long ll;
    int main()
    {
        ll n, w;
        cin >> n >> w;
        ll arr[n][2], dp[w+1], sum = 0;
        for(int i = 0; i <= w+1; i++)dp[i] = 0;
        for(int i = 0; i < n; i++)cin >> arr[i][0] >> arr[i][1];
        for(int i = 0; i < n; i++){
            for(int  j = w; j-arr[i][0] >= 0; j--){
                dp[j] = max(dp[j], dp[j-arr[i][0]] + arr[i][1]);
            }
        }
        ll ans = 0;
        for(int i = 0; i <= w; i++)ans = max(ans, dp[i]);
        cout << ans;
    }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

///////////////////////////////////////////////////////////////////////

//////////////
//unionfind

int N, E;
int par[MAX_N];
int ran[MAX_N];

void init(int n) {
	for(int i = 0; i < n; i++) {
		par[i] = i;
		ran[i] = 0;
	}
}

int find(int x) {
	if(par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(ran[x] < ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

//////////////


struct edge { int u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

//int N, E; add this////////////////////////////
edge es[200010];

int kruskal() {
	sort(es, es + E, comp);
	init(N);//init union_find
	int res = 0;
	for(int i = 0; i < E; i++) {
		edge e = es[i];
		if(!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

void add_edge(int s, int t, int cost) {
	es[E++] = edge{s, t, cost};
}

pi X[MAX_N], Y[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		int a, b;
		cin >> a >> b;
		X[i] = pi(a, i);
		Y[i] = pi(b, i);
	}
	sort(X, X + N);
	sort(Y, Y + N);
	rep(i, 0, N - 1) {
		add_edge(X[i].sec, X[i + 1].sec, X[i + 1].fst - X[i].fst);
		add_edge(Y[i].sec, Y[i + 1].sec, Y[i + 1].fst - Y[i].fst);
	}
	cout << kruskal() << "\n";
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define L "\n"
#define S " "
#define ll long long
#define pb push_back
#define mp make_pair
#define vi std::vector<int>
#define si std::set<int>
#define vl std::vector<long long>
#define qi std::queue<int>
#define de(a) cout << #a << "  ------>  " << a << "\n"
#define SIZE 100002
#define INF INT_MAX
#define FOR(i, n) for (i = 1; i <= n; i++)
#define rep(i, n) for (i = 1; i <= n; i++)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;
int n;
int a[SIZE];
double dp[301][301][301];
bool flag[301][301][301];

double f(int one, int two, int three)
{
    if(!one && !two && !three) return 0;
    int divisor = 0;
    double avg1 = 0, avg2 = 0, avg3 = 0;

    flag[one][two][three] = 1;
    int tot = one + two + three;
    double prob = (double)n / tot;


    if (one)
    {
        if (flag[one - 1][two][three])
            avg1 = dp[one - 1][two][three];
        else
            avg1 = f(one - 1, two, three);
        divisor++;
    }

    if (two)
    {
        if (flag[one + 1][two - 1][three])
            avg2 = dp[one + 1][two - 1][three];
        else
            avg2 = f(one + 1, two - 1, three);
        divisor++;
    }

    if (three)
    {
        if (flag[one][two + 1][three - 1])
            avg3 = dp[one][two + 1][three - 1];
        else
            avg3 = f(one, two + 1, three - 1);
        divisor++;
    }

    dp[one][two][three] = prob + ((prob + avg1) * ((double)one / tot) + (prob + avg2) * ((double) two / tot) + (prob + avg3) * ((double)three / tot));

    return dp[one][two][three];
}

void solve()
{
    double res;
    int i, active = 0, c[4] = {0};
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) if (a[i])
    {
        c[a[i]]++;
    }

    res = f(c[1], c[2], c[3]);
    printf("%.10lf\n", res/ 2);

}
int main()
{
    FASTIO;
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
// #endif
    int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 240000
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int taxin(int x, int p) {
	return p*(100 + x) / 100;
}

int taxout(int x, int p) {
	int tax = p * x / (100 + x);
	return p - tax;
}

int main() {
	int x, y, s;
	while (cin >> x >> y >> s, x) {
		int ans = 0;
		FOR(i, 1, s - 1) {
			int a = taxout(x, i), b = taxout(x, s - i);
			if (s != taxin(x, a) + taxin(x, b)) {
				continue;
			}
			else {
				ans = max(ans, taxin(y, a) + taxin(y, b));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1164