akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ABC_060_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int A = word[0].Length;
            int B = word[1].Length;
            char A1 = word[0].ToCharArray()[A - 1];
            char B1 = word[1].ToCharArray()[0];
            char B2 = word[1].ToCharArray()[B - 1];
            char C1 = word[2].ToCharArray()[0];
            if (A1 == B1 && B2 == C1)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	ll s;
    cin>>s;
    ll cnt=0;
    COMinit();

    // 計算例
    //cout << COM(100000, 50000) << endl;    
    for(ll i=1;i*3<=s;i++){
    	ll zan=s-i*3;
    	cnt+=COM(i-1+zan,zan);
    	//cout <<cnt<<endl;
    	cnt%=inf;
    }
    cout <<cnt;
	// your code goes here
	return 0;
}

Measured memory_bytes: 15592
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int,int>;
const int INF = 1e18;
const int MOD = 1e9+7;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

int gcd(int N, int M){ return M?gcd(M,N%M):N; }

signed main(){
    int N;
    cin >> N;
    int ans;
    cin >> ans;
    for(int i=0;i<N-1;i++){
        int a;
        cin >> a;
        ans = gcd(ans,a);
    }

    cout << ans << endl;
}


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

int main(void){
    
    int N,sum=0;
    cin >> N;
    
    int l,r;
    for(int i=0;i<N;i++){
        cin >> l >> r;
        sum += (r - l + 1);
    }
    cout << sum <<endl;
}

Measured memory_bytes: 3652
#include <stdio.h>
#define MAX1 100000
#define MAX2 50000

int main(void)
{
    int a[MAX1];
    int b[MAX2];
    int left;
    int right;
    int mid;
    int n,q,i;
    int count=0;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
     scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<q;i++){
    left=0;
    right=n;
    while(1){
        mid=(left+right)/2;
        if(left==right) break;
        if(a[mid]==b[i]){
            count++;
            break;
        } 
        else if(a[mid]<b[i]){
            left=mid+1;
        } 
        else{
            right=mid;
        } 
      }
    }
    
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2300
#include<regex>
#include<iostream>
#include<string>
#include<cinttypes>

using ui = std::uint32_t;
using ul = std::uint64_t;

int main(){


	std::string raw;
	std::cin >> raw;

	auto s = std::regex_replace( raw, std::regex{ "BC" }, "X" );



	ui ac{};
	ul ans{};
	for( const auto&c : s )
		if( c == 'A' )
			++ac;
		else if( c == 'X' )
			ans += ac;
		else
			ac = 0;

	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    ll d;
    cin >> n >> d;
    int ans = 0;
    for(int i = 1;i <= n;i++){
        ll x , y;
        cin >> x >> y;
        if(x * x + y * y <= d* d) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define pb push_back
#define INF 1'000'000'007
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n,W;
	cin>>n>>W;
	ll w[n],v[n];
	rep(i,0,n){
		cin>>w[i]>>v[i];
	}
	ll dp[n+1][W+1];
	rep(i,0,n+1){
		rep(j,0,W+1){
			if(i==0||j==0){
				dp[i][j]=0;
				continue;
			}
			if(w[i-1]<=j){
				dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
			}
			else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	cout<<dp[n][W];
	
	
	
	return 0;
}

Measured memory_bytes: 82364
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;

int main(){
  while(true){
    int input[10];
    int a[10];
    REP(i, 10) cin>>input[i];
    if(input[0] == -1) break;
    for(int i = 1; i <= 10; i++) a[i - 1] = i;
    int ans = 0;
    do{
      bool ok = true;
      REP(i, 10)if(input[i] != 0 && input[i] != a[i]) ok = false;
      if(!ok) continue;
      int MOD = a[9];
      int v[8][3] = {
        {0,1,2},
        {3,4,5},
        {6,7,8},
        {0,3,6},
        {1,4,7},
        {2,5,8},
        {0,4,8},
        {2,4,6}
      };
      set<int> cnt;
      REP(i, 8){
        int sum = 0;
        REP(j, 3) sum += a[v[i][j]];
        cnt.insert(sum % MOD);
      }
      if(cnt.size() == 1) ans ++;
    }while(next_permutation(a, a + 10));
    cout<<ans<<endl;
  }
  return 0;
}

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

int c = 0;

void bubblesort(int *a, int n); 

int main(){
  int a[100] = {0};
  int n;
  cin >> n;
  for ( int i = 0; i < n; i++ ) cin >> a[i];
  bubblesort(a, n);
  for ( int i = 0; i < n; i++ ) {
    cout << a[i];
    if (i != n - 1) cout << " ";
  }
  cout << endl;
  cout << c << endl;
  
  return 0;
}

void bubblesort(int *a, int n){
  bool flag = 1;
  int tmp;
  
  while(flag){
    flag = 0;
    for ( int i = n - 1; i > 0; i-- ) { //i--だぞ
      if (a[i] < a[i - 1]) {
        tmp = a[i]; a[i] = a[i - 1]; a[i - 1] = tmp;
        flag = 1;
        c++;
      }
    }
  }
}


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

int dp[50];

int fibonacci(int n) {
	if ( n == 0 || n== 1) return dp[n]=1;
	if ( dp[n] != -1 ) return dp[n];
	return dp[n] = fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
	int n;
	cin >> n;
	for( int i = 0; i < 50; ++i ) dp[i] = -1;
	cout << fibonacci(n) << endl;

}


Measured memory_bytes: 3100
def main():
    N, Q = map(int, input().split())
    s = input()
    command = [None] * Q
    for i in range(Q):
        t, d = input().split()
        command[i] = (t, d)
    left = -1
    right = N
    for c in list(reversed(command)):
        t, d = c
        if d == "L":
            if left < N-1 and t == s[left+1]:
                left += 1
            if right < N and t == s[right]:
                right += 1
        if d == "R":
            if right > 0 and t == s[right-1]:
                right -= 1
            if left >= 0 and t == s[left]:
                left -= 1
    print(max((right-1) - (left+1)+1, 0))


if __name__ == "__main__":
    main()


Measured memory_bytes: 80716
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int s,t,a,b,c,d,max_;
  cin >>a>>b>>c>>d;
  s=a+b+c+d;
  cin >>a>>b>>c>>d;
  t=a+b+c+d;
  max_=max(s,t);
  cout<<max_<<endl;
  return 0;
}

Measured memory_bytes: 1160
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define multitest
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
inline ll add(ll a, ll b, ll m)
{
	return (((a % m + b % m) % m + m) % m);
}
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes" << ln;
	else
		cout << "No" << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
class pa{
    public:
    int num;
    int count;
    pa(int a,int b){
        num=a;
        count=b;
    };
};

bool operator< (const pa &p1,const pa &p2) {
    return (p1.num >  p2.num);
}
 
int main(){
    ll n,k,a,b;
    priority_queue<pa> q;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        q.push(pa(a,b));
    }
    ll count=0;
    for(int i=0;i<n;i++){
        pa p=q.top();
        count+=p.count;
        if(count>=k){
            cout<<p.num<<endl;
            break;
        }
        q.pop();
    }
    return 0;
}

Measured memory_bytes: 1400
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
ans = 1001
for i in range(1<<d):
    count, score, left = 0, 0, 0
    for j in range(d):
        if (i >> j) & 1:
            score += (j+1)*100*pc[j][0] + pc[j][1]
            count += pc[j][0]
        else: left = j
    add = min(-(-max(g-score, 0)//((left+1)*100)),pc[left][0])
    count += add
    score += (left+1)*100*add
    if score >= g: ans = min(ans, count)
print(ans)

Measured memory_bytes: 3064
from operator import itemgetter

def sm(lis):
    return (lis[0]*2 + lis[1]**2)**0.5


def main():
    n = int(input())
    XY = [list(map(int,input().split())) for _ in range(n)]
    ans = 0
    a = [0,0]
    b = [0,0]
    c = [0,0]
    d = [0,0]
    y1 = 0
    y2 = 0
    x1 = 0
    x2 = 0
    for x,y in XY:
        if x >= x1:
            x1 = x
        if x <= x2:
            x2 = x
        if y >= y1:
            y1 = y
        if y <= y2:
            y2 = y
    a = [x1,y1]
    b = [x2,y1]
    c = [x2,y2]
    d = [x1,y2]
    Ans = []

            


    XY.sort(key = lambda xy:abs(xy[0] - a[0]) + abs(xy[1] - a[1]))
    Ans.append(XY[-1])
    Ans.append(XY[-2])
    XY.sort(key = lambda xy:abs(xy[0] - b[0]) + abs(xy[1] - b[1]))
    Ans.append(XY[-1])
    Ans.append(XY[-2])

    XY.sort(key = lambda xy:abs(xy[0] - c[0]) + abs(xy[1] - c[1]))
    Ans.append(XY[-1])
    Ans.append(XY[-2])

    XY.sort(key = lambda xy:abs(xy[0] - d[0]) + abs(xy[1] - d[1]))
    Ans.append(XY[-1])
    Ans.append(XY[-2])

    for x,y in Ans:
        for xx,yy in Ans:
            ans  = max(abs(x - xx) + abs(y - yy),ans)
    print(ans)
    return

if __name__ == "__main__":
    main()

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

int main()
{
	int n, key, a[255];
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= n; i++)
	{
		if(i == 1)
			cout << "node " << i << ": key = "<< a[i] << ", left key = " << a[2*i] << ", right key = " << a[2*i+1] << ", " << endl;
		else if(2*i < n)
				cout << "node " << i << ": key = "<< a[i] << ", parent key = " << a[i/2] <<", left key = " << a[2*i] << ", right key = " << a[2*i+1] << ", "<< endl;
		else if(2*i == n)		
				cout << "node " << i << ": key = "<< a[i] << ", parent key = " << a[i/2] <<", left key = " << a[2*i] << ", "<< endl;
		else if(2*i > n)		
				cout << "node " << i << ": key = "<< a[i] << ", parent key = " << a[i/2] << ", "<< endl;
	}
	
	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=2e5+10;
const int N=2e5+10;
using namespace std;
int id(int l,int r){return l+r|l!=r;}
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
int n,m,k,t,v,x[maxn],d[20],ret[maxn],l[20][maxn],r[20][maxn],dpl[1<<20],dpr[1<<20],tot;
int main()
{
    int i,j;
    scanf("%d%d",&n,&v);
    rep(i,1,n)scanf("%d",&x[i]);
    while(v)
    {
        d[tot++]=v;
        v/=2;
    }
    d[tot++]=0;
    rep(i,0,tot-1)
    {
        rep(j,1,n)
        {
            if(j>1&&x[j]-x[j-1]<=d[i])l[i][j]=l[i][j-1];
            else l[i][j]=j;
        }
        for(j=n;j>=1;j--)
        {
            if(j<n&&x[j+1]-x[j]<=d[i])r[i][j]=r[i][j+1];
            else r[i][j]=j;
        }
    }
    rep(i,0,(1<<tot)-1)dpr[i]=n+1;
    rep(i,0,(1<<tot)-1)
    {
        rep(j,0,tot-1)
        {
            if(~i&(1<<j))
            {
                if(dpl[i]+1<=n)dpl[i^(1<<j)]=max(dpl[i^(1<<j)],r[j][dpl[i]+1]);
                if(dpr[i]-1>=1)dpr[i^(1<<j)]=min(dpr[i^(1<<j)],l[j][dpr[i]-1]);
            }
        }
    }
    rep(i,0,(1<<tot)-1)
    {
        if(i&1)continue;
        if(dpl[i]>=dpr[(i^((1<<tot)-1))-1])
        {
            ret[1]++;
            ret[n+1]--;
        }
        else
        {
            if(r[0][dpl[i]+1]>=dpr[(i^((1<<tot)-1))-1]-1)
            {
                int x=dpl[i]+1;
                ret[l[0][x]]++;
                ret[r[0][x]+1]--;
            }
        }
    }
    rep(i,1,n)
    {
        ret[i]+=ret[i-1];
        puts(ret[i]?"Possible":"Impossible");
    }
    return 0;
}


Measured memory_bytes: 43392
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let n = read::<usize>();
    let mut a = vec![0; n];
    let mut ans :i64 = 0;
    let mut h = HashMap::new();

    for i in 0..n {
        a[i] = read::<i64>();

        *h.entry(a[i]).or_insert(0) += 1;
    }

    for (k, v) in h {
        if k <= v {
            ans += v - k;
        } else {
            ans += v;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 12540
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;

vector<vector<LL>>  comb(4000, vector<LL>(4000, 0));
int main(){
    int N, K;
    cin >> N >> K;
    LL mod = 1e9+7;
    for(int i = 0;i < 2010;i++){
        for(int j = 0;j < 2010;j++){
            if(i == j || i == 0 || j == 0)    comb[i][j] = 1;
            else if(i < j)  comb[i][j] = 0;
            else    comb[i][j] = (comb[i-1][j]+comb[i-1][j-1])%mod;
        }
    }
    for(int i = 1;i <= K;i++){
        LL ans = comb[K-1][K-i]*comb[N-K+1][i];
        ans %= mod;
        cout << ans << endl;
    }
}

Measured memory_bytes: 125440
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;


long long int N,M,K,res,sum=0,X,Y;
string str;
vector<long long int>vec;


int main()
{
    cout << fixed << setprecision(18);
    cin>>X>>Y;
    
    if(abs(X-Y)<=1){cout<<"Brown"<<endl;}
    else{cout<<"Alice"<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  ll n, m, c; cin >> n >> m >> c;
  vector <ll> b(m);
  rep(i, m) cin >> b.at(i);
  ll res = 0;
  rep(i, n) {
    ll tmp = c;
    rep(j, m) {
      ll a; cin >> a;
      tmp += a*b.at(j);
    }
    if (tmp > 0) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
	int n, a[2000001] = {}, b[2000001] = {}, c[10001] = {}, m = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		c[a[i]]++;
		m = max(m, a[i]);
	}
	for (int i = 1; i <= m; i++) {
		c[i] += c[i - 1];
	}
	for (int i = n - 1; i >= 0;i--) {
		b[c[a[i]]] = a[i];
		c[a[i]]--;
	}
	for (int i = 1; i <= n; i++) {
		if (i-1) cout << " ";
		cout << b[i];
	}
	cout << endl;
}


Measured memory_bytes: 18764
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;
const int MAX=100005;

int main()
{
    int n,a[MAX],b[MAX],ans,t,sum;
    scanf("%d",&n);
    a[0]=0;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
        sum=0;
    for(int i=1;i<=n;i++)
    {
        b[i]=a[i]-a[i-1];
        if(b[i]<0) b[i]=-b[i];
        sum+=b[i];
    }

    for(int i=1;i<n;i++)
    {
        ans=sum;
        ans-=(b[i]+b[i+1]);
        t=a[i+1]-a[i-1];
        if(t<0) t=-t;
        ans+=t;
        t=a[n];
        if(t<0) t=-t;
        ans+=t;
        printf("%d\n",ans);
    }
    t=a[n-1];
    if(t<0) t=-t;
    ans=sum-b[n]+t;
    printf("%d\n",ans);

    return 0;
}


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

class UnionFind{
public:
    vector<int> par;
    vector<int> rank;
    UnionFind(int n){
        init(n);
    }
    void init(int n){
        par.resize(n);
        for(int i=0;i<n;i++){
            par[i] = i;
        }
        rank.assign(n, 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(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

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

    UnionFind ufk(N), ufl(N);

    for(int i=0;i<K;i++){
        int p, q;
        cin >> p >> q;
        ufk.unite(p-1, q-1);
    }
    for(int i=0;i<L;i++){
        int p, q;
        cin >> p >> q;
        ufl.unite(p-1, q-1);
    }

    map<pair<int, int>, int> count;
    for(int i=0;i<N;i++){
        count[make_pair(ufk.find(i), ufl.find(i))]++;
    }
    for(int i=0;i<N;i++){
        if(i != 0) cout << " ";
        cout << count[make_pair(ufk.find(i), ufl.find(i))];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 15104
N = int(input())
v = list(map(int,input().split()))

while True:
    v.sort()
    tmp = (v[0] + v[1])/2
    v.append(tmp)
    v.pop(0)
    v.pop(0)

    if len(v) == 1:
        print(v[0])
        exit() 

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n + 1); rank.resize(n + 1); diff_weight.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int N, M;

void solve() {
    UnionFind<int> uni(N);
    while(M--) {
        char query;
        cin >> query;
        if(query == '!') {
            int a, b, w;
            cin >> a >> b >> w;
            uni.merge(a, b, w);
        } else {
            int a, b;
            cin >> a >> b;
            if(uni.issame(a, b)) {
                cout << uni.diff(a, b) << endl;
            } else {
                cout << "UNKNOWN" << endl;
            }
        }
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3976
import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

H, N = map(int,input().split())
A = list(map(int,input().split()))

if H <= sum(A):
  print('Yes')
else:
  print('No')




Measured memory_bytes: 24228
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[,]A = new int[M,2];
		int[]C = new int[N];
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i,0] = int.Parse(str2[0]);
			A[i,1] = int.Parse(str2[1]);
			C[A[i,0]-1]++;
			C[A[i,1]-1]++;
		}
		var listN = new List<int>[N];
		for(var i=0;i<N;i++){
			listN[i] = new List<int>();
		}
		for(var i=0;i<M;i++){
			listN[A[i,0]-1].Add(A[i,1]);
			listN[A[i,1]-1].Add(A[i,0]);
		}
		string ans = "Yes";
			int ct = 0;
			int ct6 = 0;
			int ct4 = 0;
			int ct4a = -1;
			int ct4b = -1;
			for(var i=0;i<N;i++){
				if(C[i]%2==1){
					ct++;
				}
				if(C[i]>=6){
					ct6++;
				}
				if(C[i]>=4){
					ct4++;
					if(ct4a==-1){
						ct4a = i;
					} else if(ct4b==-1){
						ct4b = i;
					}
				}
			}
			if(ct>=1){
				ans = "No";
			} else {
				if(ct6>=1 || ct4>=3){
					ans = "Yes";
				} else if(ct4<=1){
					ans = "No";
				} else {
					var list = new List<int>();
					int bct = 0;
					for(var i=0;i<N;i++){
						if(A[i,0] == ct4a+1){
							if(A[i,1]==ct4b+1){
								bct++;
							} else {
								list.Add(A[i,1]);
							}
                          listN[A[i,0]-1].Remove(A[i,1]);
							listN[A[i,1]-1].Remove(A[i,0]);
							A[i,0] = -1;
							A[i,1] = -1;

						}
						if(A[i,1] == ct4a+1){
							if(A[i,0]==ct4b+1){
								bct++;
							} else {
								list.Add(A[i,0]);
							}	
                          listN[A[i,0]-1].Remove(A[i,1]);
							listN[A[i,1]-1].Remove(A[i,0]);
							A[i,0] = -1;
							A[i,1] = -1;
						}
					}
					while(true){
						var list2 = new List<int>();
						for(var j=0;j<list.Count;j++){
							for(var k=0;k<listN[list[j]-1].Count;k++){
								if(listN[list[j]-1][k]==ct4b+1){
									bct++;
								} else if(listN[list[j]-1][k]!=ct4a+1){
									list2.Add(listN[list[j]-1][k]);
								}
								listN[listN[list[j]-1][k]-1].Remove(list[j]);
								listN[list[j]-1].RemoveAt(k);
								k--;
							}
						}
						list = new List<int>(list2);
						if(list.Count==0){
							if(bct!=2){
								ans = "No";
							}
							break;
						}
					}
				}
			}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 28172
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.Final_Examination", "r", stdin );
	int n;
	while (scanf ("%d", &n ) && n ){
		vector<int> sum(n, 0 );
		rep (i, n ){
			rep (j, 5 ){
				int in;
				scanf ("%d", &in );
				sum[i] += in;
			} // end rep
		} // end rep
		sort (ALL (sum ) );
		printf ("%d %d\n", sum[n-1], sum[0] );
	} // end while

	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll a[n], b[n], ans=0;
	for(int i=0; i<n+1; i++){
		cin >> a[i];
		ans+=a[i];
	}
	for(int i=0; i<n; i++) cin >> b[i];
	for(int i=0; i<n; i++){
		ll t=min(a[i], b[i]);
		a[i]-=t;
		b[i]-=t;
		a[i+1]-=min(a[i+1], b[i]);
	}
	for(int i=0; i<n+1; i++) ans-=a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec  

#include<bits/stdc++.h>
#define ll                    long long int
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define MOD                   1000000007
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define eb                    emplace_back
#define ull                   unsigned long long
#define bug(x)				  cout<<"  [ "#x<<" = "<<x<<" ]"<<endl;
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
void solve()
{
	int n,cnt=0,cnt1=0;
	string s;
	cin>>n>>s;
	for(auto i: s)
	{
		if(i=='R')
			cnt++;
	}
	for(int i=0;i<cnt;i++)
	{
		if(s[i]=='R')
			cnt1++;
	}
	cout<<cnt-cnt1<<endl;
}
int main()
{
    KAMEHAMEHA
	int t=1;
	//cin>>t;
	for(int cn=1;cn<=t;cn++)
	{
		solve();
	}
    return 0;
}



Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int N = 100005;
int n;
vector<ii> adjlist[N];
int p[N], d[N], sz[N];
int furthest;
int root;
ll sum = 0;
void init(int x){
    memset(p,-1,sizeof(p));
    memset(d,0,sizeof(d));
    root = x;
    p[root] = root;
    furthest = root;
    sum = 0;
}
bool iscentroid(int u){
    for (auto v : adjlist[u]){
        int x = (v.first == p[u]) ? (n-sz[u]) : sz[v.first];
        if (x > n/2) return false;
    }
    return true;
}
void dfs(int u){
    sz[u] = 1;
    for (auto v : adjlist[u]){
        if (p[v.first] == -1){
            p[v.first] = u;
            d[v.first] = d[u]+1;
            if (d[furthest] < d[v.first]) furthest = v.first;
            dfs(v.first);
            sum += 2ll*v.second*min(sz[v.first], n-sz[v.first]);
            sz[u] += sz[v.first];
        }
    }
}
ll solve(){
    init(1);
    dfs(root);
    int tominus = 100000001;
    vector<int> v;
    for (int i = 1; i <= n; i++){
        if (iscentroid(i)){
            v.push_back(i);
        }
    }
    if (v.size() == 1){
        for (auto x : adjlist[v[0]]){
            tominus = min(tominus,x.second);
        }
    }
    else if (v.size() == 2){
        for (auto x : adjlist[v[0]]){
            if (x.first == v[1]){
                tominus = x.second;
            }
        }
    }
    return sum-tominus;
}
int main(){
    scanf("%d",&n);
    for (int i = 1; i < n; i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        adjlist[a].push_back({b,c});
        adjlist[b].push_back({a,c});
    }
    printf("%lld ",solve());


}


Measured memory_bytes: 12288
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){

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

  for(int i=0; i<n-8; i++){
    cout << s[i];
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int main() {
  int N,M;
  cin >> N >> M;
  UnionFind Uni(N);
  int mx = 0;
  for (int i = 0; i < M; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    Uni.unite(a,b);
  }
  for (int i = 0; i < N; i++) {
    int c = Uni.size(i);
    mx = max(mx,c);
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 4836
A, B = map(int, input().split())

tax1 = 0.08
tax2 = 0.1
ans = -1
for i in range(1, 1001):
    if A <= i * tax1 and i * tax1 < A + 1:
        if B <= i * tax2 and i * tax2 < B + 1:
            ans = i
            break

print(ans)

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_094
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] array = ReadLongs();
            Array.Sort(array);
            long ai = array[n - 1];
            long aj = array[0];
            long ajComp = Math.Min(ai - array[0], array[0]);
            for (int i = 1; i < n; i++)
            {
                long temp = Math.Min(ai - array[i], array[i]);
                if (ajComp < temp)
                {
                    aj = array[i];
                    ajComp = temp;
                }
            }
            Console.WriteLine(ai + " " + aj);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 20192
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> P(N);
    rep(i,N){
        cin >> P[i];
    }
    vector<Pll> v(N);
    rep(i,N){
        v[i] = Pll(P[i], i+1);
    } 
    sort(v.begin(), v.end());
    ll cur = 0;
    ll M = 0;
    ll cnt = 0;
    rep(i,N){
        if(cur < v[i].se){
            cnt++;
            cmax(M,cnt);
        }else{
            cmax(M,cnt);
            cnt = 1;
        }
        cur = v[i].se;
    }
    cout << N - M << endl;
}

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

using namespace std;

#define ll             long long
#define vi             vector<int>
#define FOR(x, l, r)   for (int x = l; x <= r; ++x)
#define RFOR(x, l, r)   for (int x = l; x >= r; --x)

const int N = (int) 2e5 + 5;
const int INF = (int) 1e9 + 7;
int ini(){
    int x;
    scanf("%d",&x);
    return x;
}
long long inl(){
    long long x;
    scanf("%lld",&x);
    return x;
}
int main()
{
    int a,b;
    a=ini();
    b=ini();
    if(a%2 && b%2)
        printf("Odd\n");
    else
        printf("Even");

    return 0;
}



Measured memory_bytes: 256
n = gets.chomp.to_i
arr = n.times.map{gets.chomp.split(" ").map(&:to_i)}

t = 0
arr.sort_by{|(a, b)| [b, -a]}.each do |(a, b)|
  t += a
  if t > b then
    puts "No"
    exit
  end
end

puts "Yes"


Measured memory_bytes: 26744
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }
int main() {
	int n,res=0;
	string str,s;
	cin>>str>>n;
	while(n--){
		int i,j;
		cin>>s;
		for(i=0;i<s.size();i++){
			for(j=0;j<str.size();j++){
				if(s[(i+j)%s.size()]!=str[j])break;
			}
//cout<<i<<" "<<j<<" "<<str<<" "<<s<<endl;
			if(j==str.size())break;
		}
		if(i<s.size())res++;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

lint max_recatngle(vector<int> &h){
    int n = h.size();
    int L[n], R[n];
    stack<int> st;
    
    rep(i, n){
        while(!st.empty() && h[st.top()] >= h[i]) st.pop();
        L[i] = st.empty() ? 0 : (st.top()+1);
        st.push(i);
    }
    while(!st.empty()) st.pop();
    
    rrep(i, n){
        while(!st.empty() && h[st.top()] >= h[i]) st.pop();
        R[i] = st.empty() ? n : st.top();
        st.push(i);
    }
    
    lint ret = 0;
    rep(i, n) ret = max(ret, 1LL * (h[i]+1) * (R[i]-L[i]+1));
    return ret;
}

int main(){
    int h, w;
    scanf("%d%d", &h, &w);
    string s[h];
    rep(i, h) cin >> s[i];
    vector<vector<int>> a = vector<vector<int>>(h-1, vector<int>(w-1, 0));
    rep(i, h-1)rep(j, w-1){
        a[i][j] = (s[i][j]=='#') ^ (s[i][j+1]=='#') ^ (s[i+1][j]=='#') ^ (s[i+1][j+1]=='#');
    }
    
    vector<int> v(w-1, 0);
    lint ans = max(h, w);
    rep(i, h-1){
        rep(j, w-1){
            if(a[i][j]) v[j] = 0;
            else ++v[j];
        }
        ans = max(ans, max_recatngle(v));
    }
    
    printf("%lld\n", ans);
}

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

deque<long long int> store;

int main() {
    int N;
    cin >> N;
    deque<long long int> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<long long int>());
    // look for first length
    long long int sum = 0;
    while (!A.empty()) {
        store.push_back(A[0]);
        A.pop_front();
        if (A[0] == store[0]) {
            sum = A[0]; // first length found!
            A.pop_front();
            store.pop_back();
            break;
        } else {
            store.pop_back(); // discard the length and try again
        }

    }
    while (!A.empty()) {
        store.push_back(A[0]);
        A.pop_front();
        if (A[0] == store[0]) {
            sum *= A[0]; // second length found!
            A.pop_front();
            store.pop_back();
            break;
        } else {
            store.pop_back(); // discard the length and try again
        }
    }
    cout << sum << '\n';
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 1e3;
bool vis[nsz * (nsz - 1) / 2 + 5][nsz + 5];
int n, cnt, ans;
queue<int> dat[nsz + 5];

int inline read() {
    int res = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar());
    for (; isdigit(c); res *= 10, res += c ^ 48, c = getchar());
    return res;
}

void inline writeln(int a) {
    if (a < 0) {
        putchar(45);
        a = -a;
    }
    int s = 0, d[10] = {0};
    for (; a; d[s++] = a % 10, a /= 10);
    for (s = s ? s : 1; s; putchar(d[--s] + 48));
    putchar(ln);
}

int main() {
    n = read();
    cont (i, n) {
        cont (j, n - 1) {
            dat[i].push(read());
        }
    }
    queue<pair<int, int>> q[2];
    int pre = 0, cur = 1;
    cont (i, n) {
        if (vis[0][i])  continue;
        int j = dat[i].front();
        if (dat[j].front() == i && !vis[0][j]) {
            q[pre].push(make_pair(i, j));
            dat[i].pop();
            dat[j].pop();
            vis[0][i] = vis[0][j] = 1;
        }
    }
    for (; q[pre].size();) {
        ++ans;
        for (; q[pre].size();) {
            int i = q[pre].front().first, j = q[pre].front().second;
            q[pre].pop();
            if (dat[i].size() && !vis[ans][i]) {
                int nj = dat[i].front();
                if (dat[nj].size() && dat[nj].front() == i && !vis[ans][nj]) {
                    q[cur].push(make_pair(i, nj));
                    dat[i].pop();
                    dat[nj].pop();
                    vis[ans][i] = vis[ans][nj] = 1;
                }
            }
            if (dat[j].size() && !vis[ans][j]) {
                int ni = dat[j].front();
                if (dat[ni].size() && dat[ni].front() == j && !vis[ans][ni]) {
                    q[cur].push(make_pair(ni, j));
                    dat[ni].pop();
                    dat[j].pop();
                    vis[ans][ni] = vis[ans][j] = 1;
                }
            }
        }
        swap(pre, cur);
    }
    cont (i, n) {
        if (dat[i].size()) {
            ans = -1;
            break;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 494848
n = int(input())
lr = []
for i in range(n):
    x,l=input().split()
    x=int(x)
    l=int(l)
    lr.append([x-l,x+l])

lr.sort(key=lambda x:x[1])

l = -2000000000
ans=0
for i in range(n):
    if l<=lr[i][0]:
        l=lr[i][1]
        ans+=1

print(ans)

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

using namespace std;
typedef long long ll;

const long long int MOD = 1000000007;
int s(ll n){
  int res = 0;
  while(n){
    res += n % 10;
    n /= 10;
  }
  return res;
}
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);

  vector<ll> nums({1, 2, 3, 4, 5, 6, 7, 8});
  for(int i = 1;i < 17;i++){
    ll init = 1;
    ll power = 1;
    for(int j = 0;j < i;j++)init *= 10;
    power = init;
    init--;


    for(int j = 0;;j++){
      if(j % 10 == 9)continue;
      ll num = power * j + init;

      if( num > power * s(num))break;
      nums.push_back(num);
    }
  }

  sort(nums.begin(), nums.end());
  for(int i = 1;i < nums.size();i++)
    assert(nums[i] != nums[i - 1]);
  int k;
  cin >> k;
  for(int i = 0;i < k;i++)
    cout << nums[i] << endl;


  return 0;
//  int n, l;
  vector<pair<double, int>> ss;
  for(int i = 1;i < 100000000;i++){
//    cout << i << ' ' << 1.0 * i / s(i) << endl;
    ss.push_back({1.0 * i / s(i), i});
  }
//  cout << 1.0 * 409999 / s(409999) << endl;
  sort(ss.begin(), ss.end());
  int mx = 0;
  for(auto el : ss){
    if(el.second > mx){
      cout << el.second << ' ' << el.first << endl;
      mx = el.second;
    }
  }
}



Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if(a>0&&b>0)puts("Positive");
	else if(max(a,b)>=0&&min(a,b)<=0)puts("Zero");
	else if((abs(max(a,b))-abs(min(a,b)))%2==0)puts("Negative");
	else puts("Positive");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN = 500000 + 10;
int pre[MAXN];
int dp[MAXN];
int main() {
//    freopen("test.txt", "r", stdin);
    int n, j, tmp;
    cin >> n;
    string s;
    cin >> s;
    if (s[0] != '0') pre[0] = -1;
    for (int i = 1; i < n; i++) {
        if (s[i] == '0') pre[i] = i;
        else pre[i] = pre[i-1];
    }
    for (int i = 2; i < n; i++) {
        dp[i] = dp[i-1];
        if (s[i] == '1') {
            if (s[i-1]=='0' && s[i-2]=='1') {
                j = pre[i-2];
                tmp = i-2-j;
                if (j >= 0) tmp += dp[j];
                dp[i] = max(dp[i], tmp);
                if (i-2 > j+1) {
                    tmp = i-2 - (j+1) + dp[j+1];
                    dp[i] = max(dp[i], tmp);
                }
            }
            j = pre[i];
            if (j > 0 && s[j-1]=='1') {
                tmp = i - j;
                if (j-2 >= 0) tmp += dp[j-2];
                dp[i] = max(dp[i], tmp);
            }

        }
    }
    cout << dp[n-1] << endl;


}

Measured memory_bytes: 4740
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	string S;
	cin >> S;

	map<char, int> alphabet;
	for (int i = 0; i < S.size(); i++) {
		alphabet[S[i]]++;
	}

	for (auto &kv:alphabet) {
		if (kv.second >= 2) {
			cout << "no" << endl;
			return 0;
		}
	}

	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
C.count(0)>1 and S.each {|s|
  26.times {|i| if C[i]==0 && i!=(z||=i); s[z]<s[i] ? (s[z]=0; z=i) : (s[i]=0) end }
}
L,M,N = [-1]*27,8,3
def calc(d,n)
  s = S[d]
  t = (0..25).map {s[_1] > 0 ? C[_1]*(d-L[_1])+s[_1] : 0}
  i = (0..25).max_by(M){t[_1]}.max_by {|i|
    next t[i]  if n == 0 || d+1 >= D || t[i] == 0
    l,L[i] = L[i],d
    calc(d+1,n-1)[1].tap {L[i]=l}
  }
  [i, t[i]]
end
D.times { p 1 + i=calc(_1,N)[0]; L[i]=_1 }

Measured memory_bytes: 14988