akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=1e17;
const ll ms=(1e5)+5;

ll ar[ms]={0};
ll dp[ms][2]={0};


int main()
{
    idfc;

    int n;
    cin>>n;
    int i;
    for(i=1;i<=n;i++)cin>>ar[i];


    dp[2][0]=ar[1]+ar[2];
    dp[2][1]=-(ar[1]+ar[2]);
    dp[1][0]=ar[1];
    dp[1][1]=ar[1];
    int x;

  for(i=3;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][0],dp[i-1][1])+ar[i];
        
        dp[i][1]=max(dp[i-1][0]-ar[i-1]-(ar[i-1]+ar[i]),dp[i-1][1]+ar[i-1]+ar[i-1]-ar[i]);
    }
    cout<<max(dp[n][0],dp[n][1]);
    return 0;
}

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

int main (void){
long long  int x = 0,y = 0,z = 0;

  cin >> x;
  y = 100;
  while(y < x){
    y = y + y*0.01;
    z++;
  }
  cout << z << endl;
  return 0;
}


Measured memory_bytes: 3624
def reconstruct(preorder_values, inorder_values, postorder_values, left, right)
  return unless left < right

  root = preorder_values.shift

  mid = inorder_values.find_index(root)

  reconstruct(preorder_values, inorder_values, postorder_values, left, mid)
  reconstruct(preorder_values, inorder_values, postorder_values, mid + 1, right)

  postorder_values << root
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  preorder_values = gets.chomp.split.map(&:to_i)
  inorder_values = gets.chomp.split.map(&:to_i)
  postorder_values = []

  reconstruct(preorder_values, inorder_values, postorder_values, 0, n)

  puts postorder_values.join(' ')
end

Measured memory_bytes: 8656
#pragma once
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
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;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}
int search(int x) {

	int k = 0;
	int p = 1;
	while (p * 2 <= max_n)
	{
		p *= 2;
	}
	for (int i = p; i > 0; i /= 2)
	{
		if (i + k < max_n && bit[i + k] < x) {
			x -= bit[i + k];
			k += i;
		}
	}
	return k + 1;
}
void solv() {

	int n;
	cin >> n;
	double x[105], y[105];
	for (size_t i = 0; i < n; i++)
	{
		cin >> x[i];
	}

	for (size_t i = 0; i < n; i++)
	{
		cin >> y[i];
	}

	double d1 = 0;
	for (size_t i = 0; i < n; i++)
	{
		d1 += abs(x[i] - y[i]);
	}

	double d2 = 0;
	for (size_t i = 0; i < n; i++)
	{
		d2 += (x[i] - y[i]) * (x[i] - y[i]);
	}
	d2 = sqrt(d2);

	double d3 = 0;
	for (size_t i = 0; i < n; i++)
	{
		d3 += abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
		
	}
	d3 = cbrt(d3);
	double di = 0;
	for (size_t i = 0; i < n; i++)
	{
		di = max(abs(x[i] - y[i]),di);
	}
	cout << fixed << setprecision(10);
	cout << d1 << endl;
	cout << d2 << endl;
	cout << d3 << endl;
	cout << di << endl;;
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 3460
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ggr getchar();getchar();return 0;
#define rep(i,q)for(int i=0;i<q;i++)
using namespace std;
signed main() {
	int x, cnt = 0, ans = 0;
	cin >> x;
	for (int i = 1; i <= 1000000000; i++) {
		cnt += i;
		if (cnt >= x)break;
		ans = i;
	}
	cout << ans+1 << endl;
	ggr
}

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

bool comp(string a,string b){
  if(a.size()!=b.size()){
    return a.size()>b.size();
  }
  for(int i=0;i<a.size();i++){
    if(a.at(i)!=b.at(i)){
      return a.at(i)>b.at(i);
    }
  }
}

int main(){
  string A,B;
  cin >> A >> B;
  if(A==B){
    cout << "EQUAL" << endl;
  }else if(comp(A,B)){
    cout << "GREATER" << endl;
  }else{
    cout << "LESS" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int MAXN=500005;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    ll ret=0;
    cin>>n;
    int a[2*n];
    for(int i=0;i<2*n;i++)cin>>a[i];
    sort(a,a+2*n);
    for(int i=0;i<2*n;i+=2)ret+=a[i];
    cout<<ret<<'\n';
    return 0;
}

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


int main() {
 int n;
 cin>>n;
 vector<int> vec(n) ;
 for (int i = 0; i < n; i++)
 {
   cin>>vec[i];
 }
 vector<int> ren(n);
 for(int i=0;i<n;i++)ren[vec[i]-1]=i+1;
 for(int i=0;i<n;i++)cout << ren[i] <<endl;

}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    long long n,k;
    cin>>n>>k;
    long long v[n];
   
    for(long long i=0;i<n;i++){
        cin>>v[i];
    }
    long long ans=0;


    for(long long i=0;i<=k;i++){
        for(long long j=0;j<=k-i;j++){
            for(int t=0;t<=k-i-j;t++){
            if(n<j+t) continue;
            if(i>=t+j) continue;
            vector<long long> a;
            long long ret=0;
            for(long long h=0;h<j;h++){
                a.push_back(v[h]);
                ret+=v[h];
            }
            
            for(long long h=0;h<t;h++){
                a.push_back(v[n-1-h]);
                ret+=v[n-1-h];
            }
            sort(a.begin(),a.end());
            for(long long h=0;h<i;h++){
                ret-=a[h];
            }
            ans=max(ans,ret);
            //cerr<<ans<<" "<<ret<<" "<<i<<" "<<j<<" "<<endl; 
            }
        }
    }
    cout<<ans<<endl;
    
    
    
}


Measured memory_bytes: 384
#include<cstdio>
    #include<queue>
    #define put(x,y) make_pair(x,y)
    using namespace std;
    const int SIZE=1e6;
    deque< pair<int,int> > p;
    bool vis[SIZE];
    int k;
    void bfs() {
        while(p.size()) {
            pair<int,int> now=p.front(); p.pop_front();
            if(vis[now.first]) continue;
            vis[now.first]=true;
            if(!now.first) {
                printf("%d\n",now.second);
                return;
            }
            p.push_front(put(now.first*10%k,now.second));
            p.push_back(put((now.first+1)%k,now.second+1));
        }
    }
    int main() {
        scanf("%d",&k);
        p.push_front(put(1,1));
        bfs();
        return 0;
    }

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> S(H+1);
    REP(i,0,W+1) S[0] += ".";
    REP(i,1,H+1) {
        cin >> S[i];
        S[i] = "." + S[i];
    }

    mat dp(H+1, vec(W+1, INF));
    dp[0][1] = 0;
    dp[1][0] = 0;
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            ll a = dp[i-1][j], b = dp[i][j-1], m;
            if(S[i-1][j] == '.' && S[i][j] == '#') ++a;
            if(S[i][j-1] == '.' && S[i][j] == '#') ++b;;
            dp[i][j] = MIN(a,b); 
        }
    }
    PR(dp[H][W]);

    return 0;
}

/*



*/

Measured memory_bytes: 3680
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main()
{
  int i,j,k;
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;
    int v[500][500];
    rep(i,n)rep(j,n)
      if(i==j)v[i][j]=0;
      else v[i][j]=INF;
    rep(i,m){
      int a,b;
      cin>>a>>b;
      a--;b--;
      v[a][b]=1;
      v[b][a]=1;
    }
    rep(k,n)rep(i,n)rep(j,n)
      v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    int ans=0;
    rep(i,n)
      if(v[0][i]==1 || v[0][i]==2)ans++;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define pb push_back
#define ff first
#define ss second
#define ii insert
#define ld long double
#define ppb pop_back
#define nuenxfiu ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define TT int testcases;cin>>testcases;while(testcases--)
#define mk make_pair
#define MAX ((int)2e9+17)
#define N 200005
#define mod ((int)1e9+7)
#define MOD 1000003
//int fact[1000007]={0};
int fpow(int n, int k, int p = mod) {int r = 1; while(k > 0) {if (k & 1) r = r * n%p; n = n * n%p; k = k >> 1;} return r;}
int expo(int x,int y){ int res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
int sub(int a, int b) {return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b) {return ((a%mod)*(b%mod) + mod)%mod;}
int inv(int x) {return expo(x, mod-2);}
using namespace std;





void solve()
{
	int n;
	cin>>n;
	
	int a[n];
	int x=0;
	
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		x^=a[i];
	}
	
	for(int i=0;i<n;i++)
	cout<<(x^a[i])<<" ";
	cout<<endl;
	
}
signed main()
{
    
	nuenxfiu
	//TT
	solve();
     return 0;
}

Measured memory_bytes: 5220
#include <algorithm>
#include <iostream>
#include <vector>

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

using namespace std;

#define ALL(v) (v).begin(),(v).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define SORT(x) sort(begin(x),end(x))
#define SELECT_SORT(x, n) sort(begin(x),begin(x)+n)
#define SWAP(type, a, b) do {type tmp = a; a = b; b = tmp;} while (0)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

#define INF 2000000000000
#define MAX 10

#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


int main()
{
	int m,money,y,n;
	int a,c;
	long double risi;
	cin >> m;
	while(m)
	{
		cin >> money;
		cin >> y;
		cin >> n;

		int ans=0;

		int moneytmp = money;
		rep(i,n){
			cin >> a >> risi >> c;
			int tmpRisi=0;
			int anstmp=0;

			moneytmp = money;   
			if(!a){
				rep(i,y)
				{
					tmpRisi += moneytmp*risi;
					moneytmp -= c;  
				}
				anstmp = moneytmp + tmpRisi;
			}else{
				rep(i,y)
				{
					moneytmp +=moneytmp*risi-c;
				}
				anstmp=moneytmp;
			}
			ans = max(ans, anstmp);
		}
		cout << ans << endl;
		m--;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#define MAX_N 100000
#define MAX_M 200000
#define INF ( 1 << 29 )

using namespace std;

typedef pair<int, int> P;

vector<int> G[MAX_N + 1];
int d[MAX_N + 1];
int m[MAX_N + 1];

int dijkstra( int s, int t, int N )
{
    priority_queue<P> que;
    for ( int v = 1; v <= N; v++ )
    {
        d[v] = ( v == s ) ? 0 : INF;
        que.push( P( -d[v], v ) );
    }

    while ( !que.empty() )
    {
        int u = que.top().second;
        que.pop();

        for ( auto v : G[u] )
        {
            int alt = d[u] + 1;
            if ( d[v] > alt )
            {
                d[v] = alt;
                m[v] = u;
                que.push( P( -d[v], v ) );
            }
        }
    }

    return d[t] >= INF ? -1 : d[t];
}

int main( int argc, char **argv )
{
    int N, M;
    cin >> N >> M;

    for ( auto i = 0; i < M; i++ )
    {
        int A, B;
        cin >> A >> B;
        G[A].push_back( B );
        G[B].push_back( A );
    }

    dijkstra( 1, 1, N );

    cout << "Yes" << endl;
    for ( auto i = 2; i <= N; i++ ) { cout << m[i] << endl; }

    return 0;
}


Measured memory_bytes: 12000
#include <stdio.h> 
 #include <ctype.h> 
 
 
 int main(){ 
     int count[26]={0}; 
     char ch; 
     int i, num; 

     while(scanf("%c", &ch)!=EOF){ 
         if(islower(ch)){ 
             num=ch-'a'; 
         }else if(isupper(ch)){ 
             num=ch-'A'; 
         }else{ 
             continue; 
         } 
         count[num]++; 
     } 
     for(i=0;i<26;i++){ 
         printf("%c : %d\n", 'a'+i, count[i]); 
     } 
 
 
     return 0; 
 } 



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

int main()
{
	int m, f, r;
	
	while(1){
		cin >> m >> f >> r;
		if(m==-1&&f==-1&&r==-1)
			break;
		
		if(m==-1||f==-1)
			cout << 'F' << endl;
		else if(m+f>=80)
			cout << 'A' << endl;
		else if(m+f>=65&&m+f<80)
			cout << 'B' << endl;
		else if(m+f>=50&&m+f<65)
			cout << 'C' << endl;
		else if(m+f>=30&&m+f<50){
			if(r>=50)
				cout << 'C' << endl;
			else
				cout << 'D' << endl;
		}
		else if(m+f<30)
			cout << 'F' << endl;
	}
	
	return 0;
}

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

using namespace std;

int main(void)
{
    int K;
    int A, B;
    cin >> K;
    cin >> A >> B;
    if(A%K==0 || B % K == 0){
        cout << "OK" <<endl;
    }else if(A/K == B/K){
        cout << "NG" << endl;
    }else{
        cout << "OK" << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b)cout<<c<<endl;
  else if(b==c)cout<<a<<endl;
  else cout<<b<<endl;
  return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> h(n);
  string ans = "Yes";
  rep(i,n) {
    cin >> h[i];
  }
  int t = -1;
  rep(i,n-1) {
    int d = h[i] - h[i+1];
    if (d <= 1) {
     if (h[i] > t) h[i]--;
    }
    if (h[i] > h[i+1]) {ans = "No"; break;}
    t = max(t,h[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2 + y1 - y2;
    int y3 = y2 - x1 + x2;
    int x4 = x3 + x1 - x2;
    int y4 = y3 + y1 - y2;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

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

static const int N = 100;

int main(){
  int n,p[N+1],m[N+1][N+1];
  cin>>n;

  for(int i = 1;i<=n;i++){
    cin>>p[i-1]>>p[i];
  }

  for(int i = 1; i<=n;i++) m[i][i] = 0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j = i+l-1;
      m[i][j] = (1<<21);
      for(int k = i; k <=j-1;k++){
	m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout << m[1][n]<<endl;
  return 0;
}





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

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        vector<int> d(M);
        for (auto& i : d) cin >> i;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                int x; cin >> x;
                d[j] -= x;
            }
        }
        bool ans = true;
        for (auto i : d) {
            if (i < 0) ans = false;
        }
        cout << (ans ? "Yes" : "No") << endl;
    }

    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  string S;
  cin >> S;

  if(S == "Sunny"){
   cout << "Cloudy"; 
  }
  if(S == "Cloudy"){
    cout << "Rainy";
  }
  if(S == "Rainy"){
    cout << "Sunny";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100003;
ll i,n,b,l,r;
ll a[N];
bool pos = 1;
vi x;
set<ll> ans;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n) cin>>a[i];
    rep(i,0,n){
        cin>>b;
        x.pb({a[i] - b,i});
    }
    sort(all(x));
    l = 0; r = n - 1;
    while(l <= r){
        if(x[l].f >= 0) break;
        if(x[r].f <= 0){
            pos = 0;
            break;
        }
        ans.insert(x[l].se);
        ans.insert(x[r].se);
        if(x[l].f + x[r].f == 0){
            l += 1;
            r -= 1;
        }
        else{
            if(x[l].f + x[r].f > 0){
                x[r].f += x[l].f;
                l += 1;
            }
            else{
                x[l].f += x[r].f;
                r -= 1;
            }
        }
    }
    if(!pos) cout<<-1;
    else
        cout<<ans.size();
    return 0;
}

Measured memory_bytes: 6896
#include<stdio.h>
int main(void)
{
	int n,i,a[10000];
	long long sum=0,max=-1000000,min=1000000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]>=max){
			max=a[i];
		}
		if(a[i]<=min){
			min=a[i];
		}
		sum=sum+a[i];
	}
	printf("%lld %lld %lld\n",min,max,sum);
	
	return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
ll ans=llINF;
ll mo;
int kouka[4];
int ansko[4];
void dfs(int d,int s,int j,int g,int h,int gh){
  if(d==4){
    int mi=0;
    s-=mo;
    if(s<0)return;
    mi+=s/500;
    s%=500;
    mi+=s/100;
    s%=100;
    mi+=s/50;
    s%=50;
    mi+=s/10;
    mi+=kouka[0]-j;mi+=kouka[1]-g;mi+=kouka[2]-h;mi+=kouka[3]-gh;
    if(mi<ans){
      ans=mi;
      ansko[0]=j;
      ansko[1]=g;
      ansko[2]=h;
      ansko[3]=gh;
    }
    return;
  }
  int ko=0;
  if(d==1)ko=50;
  else if(d==2)ko=100;
  else ko=500;
  for(int i=0;i<=kouka[d];i++){
    if(d==1)
      dfs(d+1,s+i*ko,j,g+i,h,gh);
    else if(d==2)
      dfs(d+1,s+i*ko,j,g,h+i,gh);
    else
      dfs(d+1,s+i*ko,j,g,h,gh+i);
  }
}
int main(){
  int point=0;
  while(cin>>mo,mo){
    if(point)cout<<endl;
    ans=llINF;
    for(int i=0;i<4;i++)ansko[i]=0;
    cin>>kouka[0]>>kouka[1]>>kouka[2]>>kouka[3];
    for(int i=0;i<=kouka[0];i++){
      dfs(1,i*10,i,0,0,0);
    }
    for(int i=0;i<4;i++){
      if(ansko[i]){
	if(i==0){
	  cout<<10<<" "<<ansko[i]<<endl;
	}else if(i==1){
	  cout<<50<<" "<<ansko[i]<<endl;
	}else if(i==2){
	  cout<<100<<" "<<ansko[i]<<endl;
	}else{
	  cout<<500<<" "<<ansko[i]<<endl;
	}
      }
    }
    point++;
  }
  return 0;
}



Measured memory_bytes: 2976
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;

const int INF = 1e10;
const int ZERO = 0;

int N,A,B,C;
int ka[10];
int dfs(int cnt,int a,int b,int c) {
	if(cnt == N) {
		if(a == 0 || b == 0 || c == 0) {
			return INF;
		}
		return abs(a - A) + abs(b - B) + abs(c - C);
	}
	
	int res = INF;
	res = min(res,dfs(cnt + 1,a,b,c));
	res = min(res,dfs(cnt + 1,a + ka[cnt],b,c) + (a ? 10 : 0));
	res = min(res,dfs(cnt + 1,a,b + ka[cnt],c) + (b ? 10 : 0));
	res = min(res,dfs(cnt + 1,a,b,c + ka[cnt]) + (c ? 10 : 0));
	return res;
}
signed main() {
	cin >> N >> A >> B >> C;
	for(int i = 0;i < N;i++) {
		cin >> ka[i];
	}
	cout << dfs(0,0,0,0) << endl;
}

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

int main() {
    int N;
    cin >> N;
    set<string> str;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        str.insert(s);
    }
    cout << str.size() << endl;
}

Measured memory_bytes: 19224
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       ll n,f=0;
       cin>>n;
       vector <pair<ll,ll>> v(n);
       for(auto &u:v)
        cin>>u.ff>>u.ss;
       for(ll i=0;i<n-2;i++)
        if(v[i].ff==v[i].ss&&v[i+1].ff==v[i+1].ss&&v[i+2].ff==v[i+2].ss)
        {
            f=1;
            break;
        } 
       cout<<(f?"Yes":"No"); 
   }
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

//int a,b,c;
vector<int> a(3);
int main() {
    //cin >> a >> b >> c;
    REP(i,3){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int res = a[0]+a[1]+a[2]*10;
    put(res);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static void Main()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            var v = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToDecimal);
            Array.Sort(v);
            decimal kq = (v[0]+v[1])/2;
            for (int i = 2; i < n; i++)
                kq = (kq + v[i]) / 2;
            Console.WriteLine("{0:0.00000}", kq);


        }


    }
}


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

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

  int ans = 0;
  if(S[0] == T[0]) ans++;
  if(S[1] == T[1]) ans++;
  if(S[2] == T[2]) ans++;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>>a(h,vector<char>(w));
    vector<vector<char>>ans(h,vector<char>(w));
    vector<int> dx{1,1, 1,0,0, -1,-1,-1};
    vector<int> dy{1,-1,0,1,-1,-1,0, 1};
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> a[i][j];
        }
    }
    
    int cnt=0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(a[i][j]=='#'){
                ans[i][j]='#';
                continue;
            }else{
                for(int x=0; x<8; x++){
                    i += dx[x];
                    j += dy[x];
                    if(i>=0 && i<h && j<w && j>=0 && a[i][j]=='#') cnt++;
                    i -= dx[x];
                    j -= dy[x];
                }
            }
            
            ans[i][j] = cnt+48;
            cnt = 0;
        }
    }
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
def main():

    N, L = map(int, input().split())
    total = N * L + int(N * (N + 1) / 2) - N
    mylst = []
    for i in range(1, N + 1):
        taste = L + i - 1
        mylst.append(taste)
        mylst.sort()
        if taste == 0:
            print(total)
            exit()
    if mylst[0] < 0:
        mn = max(mylst)
        print(total - mn)
    else:
        mn = min(mylst)
        print(total - mn)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++)
	{
		s[i]+=n;
		if(s[i]>'Z') s[i]-=26;
	}
	cout<<s<<endl;
	return 0;
}


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

vector<string> BubbleSort(vector<string> s) {
	for (int i = 0; i < s.size(); ++i) {
		for (int k = s.size() - 1; k > i; --k) {
			if ((s[k])[1] < (s[k - 1])[1])		swap(s[k], s[k - 1]);
		}
	}
	return s;
}

vector<string> SelectionSort(vector<string> s) {
	int mink;
	for (int i = 0; i < s.size(); ++i) {
		mink = i;
		for (int k = i; k < s.size(); ++k)
			if ((s[k])[1] < (s[mink])[1])		mink = k;
		swap(s[i], s[mink]);
	}
	return s;
}

void DrawArray(const vector<string> s) {
	for (int i = 0; i < s.size(); ++i) {
		cout << s[i];
		if (i != s.size() - 1)
			cout << " ";
	}
	cout << endl;
}

int main() {
	int N;
	vector<string> s, s2, s3;

	cin >> N;
	s.resize(N);

	for (int i = 0; i < s.size(); ++i) {
		cin >> s[i];
	}

	s2 = BubbleSort(s);
	s3 = SelectionSort(s);

	DrawArray(s2);
	cout << "Stable" << endl;
	DrawArray(s3);

	for (int i = 0; i < N; ++i) {
		if (s3[i] != s2[i]) {
			cout << "Not stable" << endl;
			return 0;
		}
	}

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


Measured memory_bytes: 3168
ans = 0
n = int(input())
c = input()
#print(c)
check  = c[0]
count = 0
flag=0
for i in c:
    if(i=="R"):
        count+=1
for i,k in enumerate(c):
#    print(check,k)
    if check=="W" and k=="R":
        ans+=1
        check = "W"
        if i<count:
            flag+=1
    else:
        check  = k
print(ans-flag)
    

Measured memory_bytes: 9388
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  int i=0;
  int j=0;
  int n=0;
  int a[1000000]={};
  int sum=0;

  while(scanf("%d",&n)!=EOF)
    {
      for(i=0;i<1000000;i++)
        a[i]=1;
      sum=0;

      for(i=2;i<=n;i++)
        {
          if(a[i-1]==0)
            continue;
	  for(j=2;j<=n/i;j++)
            a[i*j-1]=0;
	}

      for(i=1;i<n;i++)
	sum+=a[i];

      cout<<sum<<endl;

    }


  return 0;

}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    int t[20005];
    for(int i=0;i<n+m;++i)
      cin>>t[i];
    sort(t,t+n+m);
    int ans=t[0];
    for(int i=1;i<n+m;++i){
      ans=max(ans,t[i]-t[i-1]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3220
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  int n, k;
  cin >> n >> k;
  vl a(n, 0);
  rep(i, n) cin >> a[i];
  vs result;
  for(int i = k; i < n; i++) {
    if (a[i] > a[i - k]) {
      result.push_back("Yes");
    }else{
      result.push_back("No");
    }
  }
  for (auto e : result) cout << e << endl;
}


Measured memory_bytes: 13216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long Int;


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

    vector<Int> a(26, 0);
    map<vector<Int>,Int> m;

    while(N-->0) {
        string S;
        cin >> S;
        rep(i,26) a[i] = 0;
        rep(j,10) {
            a[S[j] - 'a']++;
        }
        m[a]++;
    }

    Int ans = 0;

    for (auto ite = m.begin(); ite != m.end(); ++ite) {
        ans += ite->second * (ite->second - 1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 29952
#include <iostream>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  long long int ans = 0;
  for(int i = K+1; i <= N; ++i){
    ans += N/i*(i - K) + max(0, N%i - K + 1);
    if(K == 0) --ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = [input() for _ in range(H)]

N = W * H
E = [[0] * N  for _ in range(N)]
for i, e in enumerate(E):
    e[i] = 1

dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            for di, dj in dij:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == ".":
                    E[W * i + j][W * ni + nj] = 1

from scipy.sparse.csgraph import floyd_warshall

INF = float("inf")

A = floyd_warshall(E)
print(int(max(max(a if a != INF else 0 for a in a) for a in A)))


Measured memory_bytes: 28304
#include <stdio.h>
 
int main(void)
{
	long long int A=0,B=0,Ans=0;
	char rom;
 
	scanf("%lld %c %lld",&A,&rom,&B);
 
	if(rom == '+')
	{
		Ans=A+B;
	}
	else
	{
		Ans=A-B;
	}
 
	printf("%lld",Ans);
	return 0;
 
}

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

struct Node{
	int id,p=-1,d;
	vector<int> children;
	string toString(){
		string str="node "+to_string(id);
		str+=": parent = "+to_string(p);
		str+=", depth = "+to_string(d);
		str+=", ";
		if(p==-1) str+="root";
		else if(children.size()==0){
			str+="leaf";
		} else {
			str+="internal node";
		}
		str+=", [";
		for(int i=0;i<children.size();i++){
			if(i!=0) str+=", ";
			str+=to_string(children[i]);
		}
		str+="]";
		return str;
	}
};

void setDepth(Node nodes[],int id, int depth){
	nodes[id].d=depth;
	int s=nodes[id].children.size();
	for(int i=0;i<s;i++){
		int c=nodes[id].children[i];
		setDepth(nodes,c,depth+1);
	}
}

int main(){
	int n,k,id;
	cin >> n;
	Node nodes[n];
	for(int i=0;i<n;i++){
		cin >> id;
		nodes[id].id=id;
		cin >> k;
		for(int j=0;j<k;j++){
			int c;
			cin >> c;
			nodes[id].children.push_back(c);
			nodes[c].p=id;
		}
	}
	
	int rootId;
	for(int i=0;i<n;i++){
		if(nodes[i].p==-1){
			rootId=nodes[i].id;
			break;
		}
	}
	
	setDepth(nodes,rootId,0);
	
	for(int i=0;i<n;i++){
		cout << nodes[i].toString() << endl;
	}
	return 0;
}



Measured memory_bytes: 8292
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=int(1e4+5);
int n,k;
char Max,Min,Ans[MAXN],s[MAXN];
void Check(char *s,int k) {
    char t[MAXN];
    int nw=n,len=0;
    while(nw>=1&&s[nw]==Min)
        nw--,len++;
    while(k!=0&&len<n)
        len*=2,k--;
    if(len>=n) {
        for(int i=1;i<=n;i++)
            Ans[i]=Min;
        printf("%s\n",Ans+1);
        exit(0);
    }
    for(int i=1;i<=len;i++)
        t[i]=Min;
    for(int i=len+1;i<=n;i++)
        t[i]=s[nw--];
    for(int i=1;i<=n;i++) {
        if(t[i]<Ans[i]) {
            for(int j=1;j<=n;j++)
                Ans[j]=t[j];
            return;
        }
        else
            if(t[i]>Ans[i])
                return;
    }
}
int main()
{
    scanf("%d%d%s",&n,&k,s+1);
    Min='z',Max='a';
    for(int i=1;i<=n;i++) {
        Min=min(Min,s[i]);
        Max=max(Max,s[i]);
        s[2*n-i+1]=s[i];
        Ans[i]='z';
    }
    if(Min==Max) {
        printf("%s\n",s+1);
        return 0;
    }
    if(s[n]==Min)
        Check(s,k);
    for(int i=n;i<=2*n;i++)
        if(s[i]==Min)
            Check(s+i-n,k-1);
    printf("%s\n",Ans+1);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1e9+7,dp[1001][1001]={0};
int main(){
    int h,w;
    char C[1000][1000];
    cin>>h>>w;
    rep(i,h)rep(j,w) cin>>C[i][j];
    dp[0][0]=1;
    rep(i,h)rep(j,w){
        if(i&&C[i-1][j]=='.') (dp[i][j]+=dp[i-1][j])%=mod;
        if(j&&C[i][j-1]=='.') (dp[i][j]+=dp[i][j-1])%=mod;
    }
    cout<<dp[h-1][w-1]<<"\n";
}

Measured memory_bytes: 9088
Answer = []

while True:
    inp = input().split()
    n = int(inp[0])
    m = int(inp[1])
    c = n**2 + m**2
    if c == 0:
        break

    T = []
    for t in range(n):
        inp = int(input())
        T.append(inp)

    H = []
    for h in range(m):
        inp = int(input())
        H.append(inp)

    Temp = []
    for i in range(n):
        for j in range(m):
            if sum(T)-2*T[i] == sum(H)-2*H[j]:
                TTemp = [T[i],H[j]]
                Temp.append(TTemp)
    if len(Temp) == 0:
        Answer.append(-1)
    else:
        S = sum(Temp[0])
        flg = 0
        for k in range(len(Temp)):
            if sum(Temp[k]) < S:
                flg = k
            S = min(S,sum(Temp[k]))
        Answer.append(str(Temp[flg][0])+" "+str(Temp[flg][1]))

for l in range(len(Answer)):
    print(Answer[l])

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int main(void)
{
    const int N_MAX = 100;
    int N;
    int a[N_MAX];
    int b[N_MAX];
    int c[N_MAX];
    int d[N_MAX];
    pii p[N_MAX];
    pii q[N_MAX];
    bool usedp[N_MAX];
    bool usedq[N_MAX];
    cin >> N;
    REP(i, N) {
        cin >> a[i] >> b[i];
        p[i] = pii(-b[i], a[i]);
    }
    REP(i, N) {
        cin >> c[i] >> d[i];
        q[i] = pii(c[i], d[i]);
    }
    sort(p, p + N);
    sort(q, q + N);
    REP(i, N) {
        usedp[i] = false;
        usedq[i] = false;
    }
    int result = 0;
    REP(j, N) {
        REP(i, N) {
            if (!usedp[i] && p[i].second < q[j].first && -p[i].first < q[j].second) {
                usedp[i] = true;
                usedq[j] = true;
                ++result;
                break;
            }
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

def inc(x):
  if x == "No":
    return "No"
  elif x == "Any":
    return "Any"
  else:
    (a, b, p) = x
    return (a-1, b+1, (p+1)%2)

def imin(x, y):
  if x == "No" or y == "No":
    return "No"
  elif y == "Any":
    return x
  elif x == "Any":
    return y
  else:
    (a1, b1, p1) = x
    (a2, b2, p2) = y
    if p1 != p2 or b1 < a2 or b2 < a1:
      return "No"
    else:
      return (max(a1, a2), min(b1, b2), p1)

setrecursionlimit(1000000)

N = read()

edges = [[] for i in range(N)]

for i in range(N-1):
  (A, B) = reads()
  (A, B) = (A-1, B-1)
  edges[A].append(B)
  edges[B].append(A)

K = read()
d = ["Any"] * N

for i in range(K):
  (V, P) = reads()
  V = V - 1
  d[V] = (P, P, P%2)

children = [[] for i in range(N)]
parent = [0] * N

parent[0] = None
def walk(n):
  children[n] = list(edges[n])
  if n != 0:
    children[n].remove(parent[n])
  for i in children[n]:
    parent[i] = n
    walk(i)
    # print("i = {0}, d[i] = {1} ".format(i, d[i]))
  d[n] = reduce(imin, (inc(d[i]) for i in children[n]), d[n])

walk(0)

f = [0] * N
def walk2(n, k = None):
  if d[n] == "No":
    print("No"); exit()
  elif d[n] == "Any":
    f[n] = k+1
  else:
    (a, b, p) = d[n]
    if k == None:
      if a % 2 == p:
        f[n] = a
      else:
        f[n] = a + 1
    else:
      if a <= k-1 <= b:
        f[n] = k-1
      elif a <= k+1 <= b:
        f[n] = k+1
      else:
        print("No"); exit()
  for i in children[n]:
    walk2(i, f[n])

walk2(0)

print("Yes")
for i in range(N):
  print(f[i])


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

int main()
{
	char a[3];

	for (int i = 0; i < 2; i++)
	{
		cin >> a[i];
	}
	scanf("%c", &a[2]);

	if (a[2] == '\n')
	{
		for (int i = 0; i < 2; i++)
		{
			cout << a[i];
		}
	}

	else
	{
		for (int i = 2; i >= 0; i--)
		{
			cout << a[i];
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<string,int> mp;
  for(int i=0;i<n;i++)
  {
    string s;
    cin>>s;
    mp[s]=1;
  }
  cout<<mp.size();
  return 0;
}

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

int main()  {
    int n,k,x,y,cost=0;
    cin>>n>>k>>x>>y;
    for(int i=1;i<=n;i++)
    {
        if(i<=k)
            cost+=x;
        else
            cost+=y;
    }
    cout<<cost;
    return 0;
}


Measured memory_bytes: 3568
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        Scanner ss=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=a+b;
        if(c%2==0){
        System.out.println((a+b)/2);}
        if(c%2==1){
            System.out.println(c/2+1);
        }
        
    }
    }



Measured memory_bytes: 21844
;/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
using namespace std;

int main(){
    long long A, B, C;

    cin >> A >> B >> C;
    bool poi = false;
    long long count = 0;
    while(1){
        if(poi){
            if(B > 0){
                B--;
                count++;
                poi = false;
            }
            else if(A > 0){
                A--;
                poi = false;
            }
            else {
                break;
            }
        }
        else{
            if(C > 0){
                C--;
                count++;
                poi = true;
            }
            else {
                if(B > 0){
                    B--;
                    count++;
                }
                else {
                    break;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,h=100,w=50,i,j,k;
  vector<string> s(100);
  cin>>a>>b;
  cout<<h<<' '<<w<<endl;
  for(j=0;j<w;j++) s.at(0)+='.';
  for(i=1;i<h/2;i++) s.at(i)=s.at(0);
  for(j=0;j<w;j++) s.at(h/2)+='#';
  for(i=h/2+1;i<h;i++) s.at(i)=s.at(h/2);
  for(k=0;k<b-1;k++) s.at(1+k/(w/2)*2).at(k%(w/2)*2)='#';
  for(k=0;k<a-1;k++) s.at(h/2+1+k/(w/2)*2).at(k%(w/2)*2)='.';
  for(i=0;i<h;i++) cout<<s.at(i)<<endl;
}

Measured memory_bytes: 3632
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > cond;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        cond.PB(MP(x - 1, y));
    }
    for(int i = 0; i <= 999; i++){
        function<bool(int)> check = [&](int x){
            vector<int> res;
            if(x == 0) res.PB(0);
            while(x > 0){
                res.PB(x % 10);
                x /= 10;
            }
            reverse(ALL(res));
            bool ok = SZ(res) == n;
            for(auto &x : cond){
                ok &= (res[x.F] == x.S);   
            }
            return ok;
        };
        if(check(i)){
            cout << i;
            return 0;
        }
    }
    cout << -1;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int P[200000];
int main(){
  int i;
  int res = 0;
  int mn = 1073709056;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(P[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    if(mn > P[i]){
      mn = P[i];
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, P[2d5];
// {
//   int res = 0, mn = int_inf;
//   rd(N,P(N));
//   rep(i,N){
//     if(mn > P[i]) mn = P[i], res++;
//   }
//   wt(res);
// }


Measured memory_bytes: 1024
N = int(input())
S = [input() for _ in range(N)]
B_A = 0
notB_A = 0
B_notA = 0
ans = 0
for s in S:
    if s[0] == "B" and s[-1] == "A":
        B_A += 1
    elif s[0] == "B":
        B_notA += 1
    elif s[-1] == "A":
        notB_A += 1
    for i in range(len(s) - 1):
        if s[i : i + 2] == "AB":
            ans += 1

if B_A:
    ans += B_A - 1
    if notB_A > 0:
        ans += 1
        notB_A -= 1
    if B_notA > 0:
        ans += 1
        B_notA -= 1

print(ans + min(notB_A, B_notA))


Measured memory_bytes: 3700