akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=2e5+5;
int he[N],ver[N*2],nex[N*2],tot;
void addedge(int,int);
int d[N],c[N],col[N];
int st[N],top;
int last[N],siz[N],vis[N],sz[N];
void dfs0(int,int);
void dfs(int,int);
int S[N];
ll ans[N];

void init();
void work();
int ca=1;
int main(){
//    freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
//    init();
//    int T;cin>>T;
//    while(T--)
    work();
    return 0;
}
void work(){
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>c[i];
    int u,v;tot=1;
    for(int i=1;i<n;i++){
        cin>>u>>v;
        addedge(u,v);
        addedge(v,u);
    }
    dfs0(1,0);
//    cout<<"siz: ";
//    for(int i=1;i<=n;i++) cout<<siz[i]<<' ';
//    cout<<endl;
    dfs(1,0);
    for(int i=2;i<=n;i++)if(col[i]){
        int t=col[i];
//        cout<<"siz: "<<i<<' '<<siz[i]<<endl;
        ans[t]+=1LL*siz[i]*(siz[i]+1)/2;
    }
    for(int i=1;i<=n;i++){
        S[i]=n-S[i];
//        cout<<"S: "<<i<<' '<<S[i]<<endl;
        ans[i]+=1LL*S[i]*(S[i]+1)/2;
    }
    ll t=1LL*n*(n+1)/2;
    for(int i=1;i<=n;i++) cout<<t-ans[i]<<'\n';
}
void dfs(int u,int fa){
    st[++top]=u;
    int tmp=last[c[u]];
    if(tmp){
//        cout<<"st: "<<st[tmp]<<' '<<st[tmp+1]<<' '<<u<<endl;
        if(st[tmp+1]!=u) siz[st[tmp+1]]-=sz[u],col[st[tmp+1]]=c[u];
        vis[st[tmp]]=1;
    }else S[c[u]]+=sz[u];
    last[c[u]]=top;
    for(int i=he[u];i;i=nex[i]){
        int v=ver[i];
        if(v==fa)continue;
        vis[u]=0;
        dfs(v,u);
        if(!vis[u]){
            ans[c[u]]+=1LL*sz[v]*(sz[v]+1)/2;
        }
    }
    last[c[u]]=tmp;
    top--;
}
void dfs0(int u,int fa){
    siz[u]=1;
    for(int i=he[u];i;i=nex[i]){
        int v=ver[i];
        if(v==fa) continue;
        dfs0(v,u);
        siz[u]+=siz[v];
    }
    sz[u]=siz[u];
}
void addedge(int u,int v){
    ver[tot]=v;nex[tot]=he[u];he[u]=tot++;
}


Measured memory_bytes: 30832
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, K;
	cin >> N >> K;
	
	vector<int> A(N);
	REP(i, N) scanf("%d", &A[i]);
	
	int l = 0, r = INF;
	while (r - l > 1) {
		int m = (l + r) / 2;
		bool ok = [&](int x) -> bool {
			ll cnt = 0;
			REP(i, N) cnt += (A[i] - 1) / x;
			return cnt <= K;
		}(m);
		if (ok) r = m;
		else l = m;
	}
	printf("%d\n", r);
	return 0;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
int h,w,k;
string s[10];
vector<vector<int>>RR,CC;
void solve1(int i,vector<int>row){
    if(i>h){
        RR.push_back(row);
        return;
    }
    solve1(i+1,row);
    row.push_back(i);
    solve1(i+1,row);
}
void solve2(int i,vector<int>col){
    if(i>w){
        CC.push_back(col);
        return;
    }
    solve2(i+1,col);
    col.push_back(i);
    solve2(i+1,col);
}
bool ok(vector<int>r,vector<int>c){
    string sp[10];
    for(int i=1;i<=h;i++)sp[i]=s[i];

    for(int x:r){
        for(int i=1;i<=w;i++){
                sp[x][i]='R';
        }
    }
    for(int x:c){
        for(int i=1;i<=h;i++){
                sp[i][x]='R';
        }
    }
    int ret=0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(sp[i][j]=='#')ret++;
        }
    }
    return ret==k;
}
int main (){

    cin >> h >> w >> k;

    for(int i=1;i<=h;i++){
        cin >> s[i];
        s[i] = "R" + s[i];
    }
    solve1(1,{});
    solve2(1,{});
    int res=0;
    /*cout<<"row: ";
    for(int i=0;i<RR.size();i++){
        for(int x:RR[i])cout<<x<<" ";
        cout<<endl;
    }
    cout<<"col: ";
    for(int i=0;i<CC.size();i++){
        for(int x:CC[i])cout<<x<<" ";
        cout<<endl;
    }*/
    for(int i=0;i<RR.size();i++){
        for(int j=0;j<CC.size();j++){
                if(ok(RR[i],CC[j]))res++;

        }
    }
    cout<<res<<endl;
    return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;

  vector<ll> h(n);
  for (ll i = 0; i < n; i++) cin >> h[i];
  
  vector<ll> dp(n, __INT_MAX__);
  dp[0] = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = 1; j <= k; j++) {
      ll dest = min(i + j, n - 1);
      dp[dest] = min(dp[dest], dp[i] + abs(h[i] - h[dest]));
    }
  }

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


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int count = 0;
        for(int i = a ; i <= b ; i++)
        {
            if(c % i == 0)
                count++;
        }
        System.out.println(count);
    }
}


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n;
  cin>>n;
  double sum;
  REP(i,n){
    double d;
    cin>>d;
    sum+=1/d;
  }
  sum=1/sum;
  cout<<fixed<<setprecision(6)<<sum<<endl;
}


Measured memory_bytes: 256
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	if(c^'-')k=1,x=c&15;else k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (100010)
int n,f[N],ans[N];
char s[N]; 
signed main(){
	cin>>s+1,n=strlen(s+1);
	Frn1(i,2,n)if(s[i]=='L')f[i]=s[i-1]=='L'?f[i-1]:i-1;
	Frn_(i,n-1,1)if(s[i]=='R')f[i]=s[i+1]=='R'?f[i+1]:i+1;
	Frn1(i,1,n)++ans[s[i]=='L'?f[i]+((i-f[i])&1):f[i]-((f[i]-i)&1)];
	Frn1(i,1,n)wr(ans[i]),Ps;
	exit(0);
}

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

int main() {
  string S;
  cin >> S;
  int longest = 0;
  for (int i = 0; i < S.size(); i++) {
    int length = 0;
    for (int j = i; j < S.size(); j++) {
      if (S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T') {
        length++;
      } else {break;}
    }
    if (length > longest) {
      longest = length;
    }
  }
  cout << longest << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;


int main(){
    int h, w;   cin >> h >> w;
    vector<vector<ll>> c(10, vector<ll>(10, 1e+15));
    
    for(int i=0; i<10; i++)
        for(int j=0; j<10; j++)  cin >> c.at(i).at(j);

    for(int k=0; k<10; k++)
        for(int i=0; i<10; i++)
            for(int j=0; j<10; j++)
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
    
    ll res=0;
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            int x;  cin >> x;
            if(x==-1) continue;
            res += c[x][1];
        }
    }
    cout << res << endl;

}



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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){


	int N; cin >> N;
	vector<int> V(N);
	vector<int> C(N);

	REP(i,N) cin >> V[i];
	REP(i,N) cin >> C[i];

	int ans = 0;
	REP(i,N){
		if(V[i] > C[i]) ans += (V[i]-C[i]);
	}

	cout << ans << endl;



	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long s,n;
	while(cin>>n,n){
		s=1;
		loop(i,2,sqrt(n))if(n%i==0){s+=i;s+=(n/i);}
		if(n==1)cout<<"deficient number"<<endl;
		else if(n>s)cout<<"deficient number"<<endl;
		else if(n<s)cout<<"abundant number"<<endl;
		else cout<<"perfect number"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();

        if(a % x != 0)
        	a = a + (x - a % x);

        if(b % x != 0)
        	b = b - (b % x);
        if(a > b)
        	System.out.println(0);
        else
        	System.out.println((b - a) / x + 1);
    }
}


Measured memory_bytes: 24020
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int W,a,b;
  cin >> W >> a >> b;

  int ans;
  if(b+W < a) ans = a - b - W;
  if(b+W >= a && b <= a+W) ans = 0;
  if(a+W < b) ans = b - a - W;

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


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

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
const int N=3005;

int mod=998244353;

int cache[N][N];
int n;
int a[N];

int dp(int idx,int s){
    if(s==0) return n-idx+1;
    if(s<0) return 0;

    int &ans=cache[idx][s];
    if(idx>n-1) return 0;
    if(ans!=-1) return ans;

    ans=dp(idx+1,s)+dp(idx+1,s-a[idx]);
    ans%=mod;
    return ans;
}

int32_t main() {
    int s;
    cin>>n>>s;
    memset(cache,-1, sizeof(cache));
//    int a[n];
    rep(i,0,n) cin>>a[i];

    int ans=0;

    for(int i=0;i<n;i++){
        ans+=dp(i,s);
//        cout<<ans<<endl;
        ans%=mod;
    }

    cout<<ans<<endl;
}

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

using namespace std;

const int MaxN = 1e5 + 15;
int a[MaxN];

long long st[MaxN];

long double sum(long long a)
{
    int res = 0;
    while(a)
    {
        res += a % 10;
        a /= 10;
    }
    return res;
}

bool good(long double x)
{
    for(long double i = x + 1; i <= x + 10000; ++i)
        if(x / sum(x) > i / sum(i))
            return false;
    return true;
}

bool better(long double x, long double y)
{
    return x / sum(x) <= y / sum(y);
}

int myLen(long long x)
{
    int res = 0;
    while(x)
    {
        res++;
        x /= 10;
    }
    return res;
}

long long toi(string s)
{
    long long res = 0;
    for(int i = 0; i < s.size(); ++i)
    {
        res = res * 10;
        res += s[i] - '0';
    }
    return res;
}

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

    st[0] = 1;
    for(int i = 1; i < 100; ++i)
        st[i] = st[i - 1] * 10ll;

    vector <long long> v;
    for(int i = 1; i <= 9; ++i)
        v.push_back(i);

    for(int len = 2; len <= 15; ++len)
    {
        string s;
        for(int i = 0; i < len; ++i)
            s.push_back('9');
        v.push_back(toi(s));

        long long y = toi(s);

        while(true)
        {
            bool OK = false;
            for(int pref = s.size(); pref > 0; --pref)
            {
                long long nextY = y - st[s.size() - pref];
                if(myLen(nextY) == myLen(y) && better(nextY, y))
                {
                    y = nextY;
                    v.push_back(y);
                    OK = true;
                    break;
                }
            }
            if(!OK)
                break;
        }
    }

    sort(v.begin(), v.end());

    int k;
    cin >> k;

    for(int i = 0; i < k; ++i)
        cout << v[i] << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {

	//ツ　0093 Leap Year
	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//		String data = "1\n"+
//		BufferedReader reader = new BufferedReader(new StringReader(data));

		
		
		for(int loop = 0;;loop++) {
			String s = reader.readLine();
			String[] sp = s.split(" ");
			int y1 = Integer.parseInt(sp[0]);
			int y2 = Integer.parseInt(sp[1]);
			if (y1 == 0 && y2 == 0)
				break;
			if (loop != 0)
				System.out.printf("\n");
			
			int cnt = 0;
			for(int y = y1; y <= y2; y++) {
				if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
					System.out.printf("%d\n", y);
					cnt++;
				}
			}
			if (cnt == 0)
				System.out.printf("NA\n");
			
		}
		
		reader.close();
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
#include<vector>

using namespace std;

enum Diceface {
	DICETOP,
	DICEFRONT,
	DICERIGHT,
	DICELEFT,
	DICEBACK,
	DICEBOTTOM,
	DICENUM
};

class Dice {
private:
	int *face;
public:
	Dice( ) { face = new int[DICENUM]; }
	Dice( int top, int front, int right, int left, int back, int bottom ) {
		face = new int[DICENUM];
		
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	}
	~Dice( ) {
		delete [ ] face;
	}
	void setFace( int top, int front, int right, int left, int back, int bottom ) {
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	
		return;
	}
	void roll( char cmd ) {
		int t;
		if( 'E' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICELEFT];
			face[DICELEFT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICERIGHT];
			face[DICERIGHT] = t;
		} else if( 'N' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICEFRONT];
			face[DICEFRONT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICEBACK];
			face[DICEBACK] = t;
		} else if( 'S' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICEBACK];
			face[DICEBACK] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICEFRONT];
			face[DICEFRONT] = t;
		} else if( 'W' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICERIGHT];
			face[DICERIGHT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICELEFT];
			face[DICELEFT] = t;
		} else if( 'M' == cmd ) {
			t = face[DICEBACK];
			face[DICEBACK] = face[DICERIGHT];
			face[DICERIGHT] = face[DICEFRONT];
			face[DICEFRONT] = face[DICELEFT];
			face[DICELEFT] = t;
		}
		return;
	}
	int getFace( int diceface ) {
		return face[ diceface ];
	}

	bool isDiff( Dice &dice ) {
		int cnt;
		string cmd = "MMMMNMMMMWMMMMWMMMMWMMMMNMMMM";

		for( int i=0; i<cmd.length(); i++ ) {		
			if( dice.getFace( DICETOP ) == face[ DICETOP ] ) {
				for( cnt=0; cnt<DICENUM; cnt++ ) {
					if( dice.getFace( cnt ) != face[ cnt ] ) { break; }
				}
				if( DICENUM == cnt ) { break; }
			}
			dice.roll( cmd[i] );
		}
		
		if( DICENUM == cnt ) {
			return false;
		} else {
			return true;
		}
	}

};

int main( )
{
	int t, f, r, l, ba, bo;
	int n;
	
	cin>>n;
	Dice *dice = new Dice[n];
	if( NULL == dice ) { return 0; }
	
	int cnt = 0;
	while( cnt < n ) {
		cin>>t>>f>>r>>l>>ba>>bo;
		dice[ cnt++ ].setFace( t, f, r, l, ba, bo );
	}
	
	bool isDiff = false;
	for( int i=0; i<n-1; i++ ) {
		for( int j=i+1; j<n; j++ ) {
			if( !( isDiff = dice[i].isDiff( dice[j] ) ) ) { break; }
		}
		if( !isDiff ) { break; }
	}
	if( isDiff ) {
		cout<<"Yes"<<endl;		
	} else {
		cout<<"No"<<endl;
	}

	delete [ ] dice; 
	
	return 0;
}

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

int main(){ 
    int n; cin>>n;
    int ans=1;
    vector<int>d(n);
    for(int i=0;i<n;i++){   
        cin>>d.at(i);
        }
    sort(d.begin(),d.end());
    for(int i=0;i<n-1;i++){
        if(d.at(i)!=d.at(i+1)){
            ans++;
            }
        }
    cout<<ans<<endl;
    }


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

typedef long long ll;
int x,y,a,b,c;
ll Now;

struct node{
	int kd,val;
}Apple[300005];

bool CMP(const node &a,const node &b){
	return a.val > b.val;
}

int main(){
	//these IN 
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	for(int i = 1; i <= a; i++) scanf("%lld",&Apple[i].val), Apple[i].kd = 1;
	for(int i = a + 1; i <= a + b; i++) scanf("%lld",&Apple[i].val), Apple[i].kd = 2;
	for(int i = a + b + 1; i <= a + b + c; i++) scanf("%lld",&Apple[i].val), Apple[i].kd =3;
	
	sort(Apple + 1, Apple + 1 + a + b + c, CMP);
	//for(int i = 1; i <= a + b + c; i++) printf("Apple[%d].val:%d\n",i,Apple[i].val);
	ll ans = 0;
	int nx = 0, ny = 0, cnt = 0;
	for(int i = 1 ; i <= a + b + c; i++){
		if(Apple[i].kd == 1){
			if(nx == x) continue;
			nx++;
		}
		else if(Apple[i].kd == 2){
			if(ny == y) continue;
			ny++;
		}
		cnt++;
		ans += Apple[i].val;
		if(cnt == x + y) break;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long
using namespace std;

   
int32_t main() {
    int n;
    string s;
    cin>>n>>s;
    if(n&1)cout<<"No\n";
    else
    {
        int flag=1;
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[i+n/2]){flag=0;break;}
        }
        if(flag)cout<<"Yes\n";
        else cout<<"No\n";
    }
    
    return 0;
}


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

#define endl '\n'
#define rep(n)      for (int i = 0 ; i < n ; i++)
#define all(a)      a.begin(),a.end()
#define NumofDigits(n)    ((long long)log10(n)+1)
#define Unique(n)         (n).erase(unique(all(n)), (n).end())

void quick ()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}

void readFromText ()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
}

const double Pi = acos(-1.0);

int main()
{
    quick();
//    readFromText();
    int n , k ; cin >> n >> k ;
    set<int>st ;
    while (k--){
        int n , x ; cin >> n ; rep(n){cin >> x ; st.insert(x) ;}
    }
    cout << n-st.size();
    return 0;
}

unsigned long long pow(long long base, long long power){
    if(power==0)
        return 1;
    if(power==1)
        return base;
    unsigned long long ans = pow(base, power/2);
    ans *= ans;

    if(power&1)
        return ans*base;
    return ans;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    set<pair<int,int>> st;
    int N,h,m;
    cin >> N;
    for(int i = 0 ; i < N ; i++){
	cin >> h >> m;
	st.insert(make_pair(h,m));
    }
    cin >> N;
    for(int i = 0 ; i < N ; i++){
	cin >> h >> m;
	st.insert(make_pair(h,m));
    }
    bool blank = false;
    for(auto x : st){
	if(blank){ cout << " "; }
	blank = true;
	printf("%d:%02d",x.first,x.second);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3252
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n;
cin >> n;
vector<vector<vector<int>>> bfrv(4, vector<vector<int>>(3, vector<int>(10)));
for (int i=0;i<n;i++)
{
int b,f,r,v;
cin >> b >> f>> r >> v;
bfrv.at(b-1).at(f-1).at(r-1)+=v;
}
for(int i=0;i<4;i++)
{
for(int j=0;j<3;j++)
{
for(int k=0;k<10;k++)
{
cout << " " << bfrv.at(i).at(j).at(k);
}
cout <<endl;
}
if(i!=3)cout << "####################" << endl;
}
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Debug_array(a,n) for (int i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (int i=(s); i<=(e); i++)
#define Fod(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	
	ll n;cin>>n;
	string a[n];
	For(i,0,n) cin>>a[i];

	bool flag1 = true;
	For(i,1,n){
		if(a[i][0]!=a[i-1][a[i-1].size()-1]) flag1=false;
	}
	bool flag2=true;
	For(i,0,n){
		For(j,i+1,n){
			if(a[i]==a[j]) flag2=false;
		}
	}
	if(flag1&&flag2) cout<<"Yes";
	else cout<<"No";
}

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

int main(){

    string S; cin >> S;
    bool ans = 0;
    for(int i = 0; i < S.length()-1; i+=2){
        if(S[i] == 'h' && S[i+1] == 'i'){ans = 1;}
        else{ans = 0; break;}
    }

    if(S.length()%2 == 1){ans = 0;}

    if(ans){cout << "Yes" << endl;}else{cout << "No" << endl;}
}

Measured memory_bytes: 256
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut line = String::new();
    std::io::stdin().read_to_string(&mut line);
    let input: Vec<i64> = line.split_whitespace().map(|a| a.parse().unwrap()).collect();
    let (k, n) = (input[0],input[1]);
    let mut m = 0;
    let s = &input[2..];

    for i in 0..s.len() {
        m = max(m, (k + s[(i + 1) % s.len()] - s[i]) % k);
    }
    println!("{}", k - m);
}


Measured memory_bytes: 10492
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	//入力
	int N, A, B, C, D;
	string S;
	cin >> N >> A >> B >> C >> D;
	cin >> S;

	//A<B<C<DorA<C<B<DつまりC<Dなら、AC間とBD間に#2連がなければYes
	//AC間
	string S_AC = S.substr(A - 1, C - A + 1);//入力が1始まりなので、A-1で0始まりにfix
	//BD間
	string S_BD = S.substr(B - 1, D - B + 1);
	if (C < D) {
		if (S_AC.find("##") == string::npos && S_BD.find("##") == string::npos) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}

	/*
	A<B<D<Cなら、AC間とBD間に#2連がないことと、
	AがBを追い越せること、すなわち
	B-1~D+1の間に.3連があることがYes条件
	*/
	//B-1,D+1間
	string S_BD_2 = S.substr(B - 2, D - B + 3);
	if (D < C) {
		if (S_AC.find("##") == string::npos && S_BD.find("##") == string::npos && S_BD_2.find("...") != string::npos) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, x;
  cin >> k >> x;

  string result = "";

  for (int i = x - k + 1; i <= x + k - 1; i++) {
    result.append(to_string(i) + " ");
  }

  cout << result.substr(0, result.size() - 1);
}

Measured memory_bytes: 256
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in= new Scanner(System.in);
        int r = in.nextInt();
        int D= in.nextInt();
        long x = in.nextLong();

        for(int i=0;i<10;i++){
            x = r*x-D;
            System.out.println(x);
        }
    }
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
// #define int ll
 
bool test = 1;

//............................
#define MAX 300000
signed main(){
  int i,j,k,l;
  int n;
  while(1) {
	cin >> n;
	if(n == 0) break; 
	int cnt = 0;
	REP(i,1,n) {
	  int sum = 0;
	  REP(j,i,n) {
		sum += j;
		if(sum >= n) break;
	  }
	  if(sum == n) ++cnt;
	}
	cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a > b) {
			System.out.println("a > b");
		}else if (a == b) {
			System.out.println("a == b");
		}else {
			System.out.println("a < b");
		}
	}
}


Measured memory_bytes: 26112
import heapq
N = int(input())
A = []

for _ in range(N):
    A.append((-1)*(int(input())))

B = A.copy()

heapq.heapify(B)
max_1 = 0 - heapq.heappop(B)
max_2 = 0 - heapq.heappop(B)

if max_1 == max_2:
    for _ in range(N):
        print(max_1)
        
else:
    index = A.index(-max_1)
    
    for i in range(index):
        print(max_1)

    print(max_2)

    for i in range(N - index - 1):
        print(max_1)

    


Measured memory_bytes: 14088
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define pii pair<int,int>
#define fr(i, a, b) for(int i = a; i < b; i++)
#define frb(i, a, b) for(int i = a; i > b; i--)
#define sz(s) (int)s.size()
#define all(v) (v).begin(), (v).end()
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
#define iset tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define oset tree < pair<int, int> ,  null_type ,  less<pair<int, int> > ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define ll long long
using namespace std; 
using namespace __gnu_pbds; 

int  prg()
{
    long double a,b;
    cin>>a>>b;
    cout<<floor(a*b);
    return 0;
}
void multi()
{
    int t;
    cin>>t;
    for(int i=0;i<t;++i)
    {
       prg();
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    prg();
    return 0;
}

Measured memory_bytes: 3796
#include <iostream>
using namespace std;
int fact(int z) {
  int r = 1;
  int i = z;
  while (i) {
    r *= i;
    i--;
  }
  return r;
}
int main() {
  int n,m, a = 0, b = 0;
  int p[8] = { };
  int q[8] = { };
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    p[i] = m;
  }
  for (int i = 0; i < n; i++) {
    cin >> m;
    q[i] = m;
  }
  for (int i = 1; i <= n; i++) {
    a += (p[i - 1] - 1) * fact(n - i);
    b += (q[i - 1] - 1) * fact(n - i);
    for (int j = i; j < n; j++) {
      if(p[i-1] < p[j]) p[j]--;
      if(q[i-1] < q[j]) q[j]--;
    }
  }
  cout << abs(a - b);
  return 0;
}

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

string S;

void solve(){
	bool flg=true;
	FOR(i,1,(int)S.length()-1){
		if (S[i-1]!=S[i+1]) flg=false;
	}
	if (flg){
		cout<<"Second"<<endl;
		return;
	}
	if (S.front()!=S.back()){
		if (S.length()%2==1){
			cout<<"First"<<endl;
		}else{
			cout<<"Second"<<endl;
		}
	}else{
		if (S.length()%2==0){
			cout<<"First"<<endl;
		}else{
			cout<<"Second"<<endl;
		}
	}
}

int main(){
	cin>>S;
	solve();
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

 
     signed main(){
     int n,c;
     cin>>n>>c;
     int a[n],b[n];
     for(int i=0;i<n;i++)cin>>a[i];
     for(int i=0;i<n;i++)cin>>b[i];
     int dp[n][c+1];for(int i=0;i<n;i++)fill(dp[i],dp[i]+c+1,0);
     for(int i=0;i<n;i++){
          for(int j=a[i];j<=b[i];j++){
               int t=1;
               for(int k=0;k<c+1;k++){
                    dp[i][k]=(dp[i][k]+t)%MOD;
                    t=(t*j)%MOD;
               }
          }
     }
     for(int i=1;i<n;i++){
          for(int j=c;j>=0;j--){
               dp[i][j]=(dp[i][j]*dp[i-1][0])%MOD;
               for(int k=1;k<=j;k++){
                    dp[i][j]=(dp[i][j]+dp[i-1][k]*dp[i][j-k])%MOD;
               }
          }
     }
     cout<<dp[n-1][c]<<endl;

     
     

   

      }

        

Measured memory_bytes: 1536
H,W = map(int,input().split())
src = [input() for i in range(H)]
cols = list(zip(*src))
for row in src:
    if all([c=='.' for c in row]): continue
    out = ''
    for i,c in enumerate(row):
        if all([c=='.' for c in cols[i]]): continue
        out += c
    print(out)

Measured memory_bytes: 3064
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))

one = np.zeros(40, dtype=int)
for i in range(40):
    one[i] = np.count_nonzero(a % 2)
    a >>= 1
zero = n-one

bk = bin(k)[2:].zfill(40)
bk = bk[::-1]
answer = 0
tmp = 0
for i in range(40 - 1, -1, -1):
    if bk[i] == "0":
        tmp += one[i] * (2 ** i)
    else:
        ans = tmp + one[i] * (2 ** i)
        for j in range(i - 1, -1, -1):
            ans += max(one[j], zero[j]) * (2 ** j)
        answer = max(answer, ans)
        tmp += zero[i] * (2 ** i)
else:
    answer = max(answer, tmp)

print(answer)


Measured memory_bytes: 23652
#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) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const ll INF = 1000000000000000000LL;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Edge{
  int src, dst, t, m, v;
  Edge(int s, int d, int t, int m, int v) : 
    src(s), dst(d), t(t), m(m), v(v) {}
};
typedef vector<Edge> Node;
typedef vector<Node> Graph;

Graph G;
ll t[1000], m[1000], vl[1000];
int prev[1000];
int last[1000];
void dfs(int v, int p, int& k){
  prev[k] = (last[v] >= 0) ? last[v] : k;
  last[v] = k;
  k++;
  FORIT(e, G[v]){
    if(e->dst != p){
      t[k] = e->t;
      m[k] = e->m;
      vl[k] = e->v;

      dfs(e->dst, e->src, k);

      prev[k] = (last[v] >= 0) ? last[v] : k;
      last[v] = k;
      k++;
    }
  }
}
void update(ll& x, ll y){
  if(x < y) x = y;
}

int main(){
  ll N, T;
  while(cin >> N >> T){
    G = Graph(N);
    REP(i, N - 1){
      int a, b, t, m, v;
      cin >> a >> b >> t >> m >> v;
      a--; b--;
      G[a].push_back(Edge(a, b, t, m, v));
      G[b].push_back(Edge(b, a, t, m, v));
    }
    int K = 0;
    memset(last, -1, sizeof(last));
    memset(t, 0, sizeof(t));
    memset(m, 0, sizeof(m));
    memset(vl, 0, sizeof(vl));
    dfs(0, -1, K);
    static ll dp[610][10010] = {};
    REP(i, K) REP(j, T + 1) dp[i][j] = -INF;
    dp[0][0] = 0;
    for(int i = 1; i < K; i++){
      if(m[i] >= 2){
        for(ll u = 2 * t[i]; u <= T; u++) update(dp[i][u], dp[i - 1][u - 2 * t[i]] + 2 * vl[i]);
        ll rest = m[i] - 2;
        if(rest % 2 == 1) rest--;
        for(ll c = 2; rest >= 2; c <<= 1){
          ll mul = min(rest, c);
          for(ll u = T; u >= mul * t[i]; u--) update(dp[i][u], dp[i][u - mul * t[i]] + mul * vl[i]);
          rest -= mul;
        }
      }
      if(m[i] % 2 == 1){
        for(ll u = (m[i] + 1) * t[i]; u <= T; u++) update(dp[i][u], dp[i - 1][u - (m[i] + 1) * t[i]] + m[i] * vl[i]);
      }
      if(m[i] == 0){
        for(ll u = 2 * t[i]; u <= T; u++) update(dp[i][u], dp[i - 1][u - 2 * t[i]]);
      }
      for(ll u = 0; u <= T; u++) update(dp[i][u], dp[prev[i]][u]); 
    }
    ll ans = 0;
    for(ll i = 0; i <= T; i++) update(ans, dp[K - 1][i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 48324
#include <stdio.h>

int main() {

  int m, f, r;
  int x;
  while(1) {

    scanf("%d %d %d", &m , &f , &r);
    x = m + f;
    if(m == -1 && f ==-1 && r == -1) {
      break;
    }

    if(m == -1 || f == -1) {
      printf("F\n");
    } else if(x >= 80) {
      printf("A\n");
    } else if (x >= 65) {
      printf("B\n");
    } else if(x >= 50) {
      printf("C\n");
    } else if ( x >=30) {
      if(r >= 50) {
	printf("C\n");
      } else {
	printf("D\n");
      }
    } else if (x < 30) {
      printf("F\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2700
require "bigdecimal"
require "bigdecimal/util"

def gi() gets.to_i end
def gs() gets.chomp end
def gim() gets.split.map(&:to_i) end
def gsm() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end

#####
x = gi
res = (x/500.0).floor * 1000
x = x % 500
res += (x/5.0).floor * 5
puts res

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
int INF = 2000000000;
vector<vector<int>> child(vector<vector<int>> E, int r){
	int N = E.size();
	vector<vector<int>> c(N);
	queue<int> Q;
	Q.push(r);
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (int w : E[v]){
			if (c[w].empty()){
				c[v].push_back(w);
				Q.push(w);
			}
		}
	}
	return c;
}
void dfs(vector<vector<int>> &c, vector<pair<string, int>> &Q, vector<int> &a, int v){
  Q.push_back(make_pair("insert", a[v]));
  Q.push_back(make_pair("output", v));
  for (int w : c[v]){
    dfs(c, Q, a	, w);
  }
  Q.push_back(make_pair("pop", -1));
  return;
}
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  vector<vector<int>> c = child(E, 0);
  vector<pair<string, int>> Q;
  dfs(c, Q, a, 0);
  int M = Q.size();
  /*
  for (int i = 0; i < M; i++){
    if (Q[i].second == -1){
      cout << Q[i].first << endl;
    } else {
      cout << Q[i].first << ' ' << Q[i].second << endl;
    }
  }
  */
  vector<int> dp(N, INF);
  vector<int> res(N, -1);
  stack<pair<int, int>> op;
  for (int i = 0; i < M; i++){
    string S = Q[i].first;
    if (S == "insert"){
      int x = Q[i].second;
      auto itr = lower_bound(dp.begin(), dp.end(), x);
      int pos = itr - dp.begin();
      //スタックに位置と元の数を積む
      op.push(make_pair(pos, *itr));
      //変更をする
      *itr = x;
    }
    if (S == "output"){
      int x = Q[i].second;
      //結果を記録
      res[x] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    }
    if (S == "pop"){
      //スタックの最も上の逆操作を行う
      dp[op.top().first] = op.top().second;
      op.pop();
    }
  }
  for (int i = 0; i < N; i++){
    cout << res[i] << endl;
  }
}

Measured memory_bytes: 95876
import Data.Bool
import Data.List

main :: IO ()
main = do
  { [n,a,b] <- readLineInputs
  ; s <- getLine
  ; mapM_ putStrLn $ solve a b s
  }


{- |
>>> solve 2 3 "abccabaabb"
["Yes","Yes","No","No","Yes","Yes","Yes","No","No","No"]
>>> solve 5 2 "cabbabaacaba"
["No","Yes","Yes","Yes","Yes","No","Yes","Yes","No","Yes","No","No"]
>>> solve 2 2 "ccccc"
["No","No","No","No","No"]
-}
solve :: Int -> Int -> String -> [String]
solve a b s = unfoldr psi (0, 0, s)
  where
    psi (x,y,"") = Nothing
    psi (x,y,z:zs) = case z of
      'a' -> Just $ bool ("Yes", (succ x, y, zs)) ("No", (x, y, zs)) (a+b <= x+y)
      'b' -> Just $ bool ("Yes", (x, succ y, zs)) ("No", (x, y, zs)) (a+b <= x+y || b <= y)
      'c' -> Just ("No", (x, y, zs))

readLineInputs :: Read a => IO [a]
readLineInputs = map read . words <$> getLine


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

using namespace std;

int N, M, a[51], b[51];
bool g[51][51];
bool vis[51];

void dfs(int cur){
  for(int i = 0; i < N; i++){
    if(g[cur][i] == true && vis[i] == false){
      vis[i] = true;
      dfs(i);
    }
  }
}

int main(){
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = true;
  }

  int ans=0;
  for(int i = 0; i < M; i++ ){
    g[a[i]][b[i]] = g[b[i]][a[i]] = false;

    for(int j = 0; j < N; j++) vis[j] = false;
    vis[0] = true;

    dfs(0);
    //for(int j = 0; j < N; j++) cout << vis[j] << " " ;
    //cout << endl;
    for(int j = 1; j < N; j++){
      if(vis[j] == false){
        ans++;
        break;
      }
    }
    //cout << ans << endl;
    g[a[i]][b[i]] = g[b[i]][a[i]] = true;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int sum1 = A + B;
  int sum2 = C + D;

  if (sum1 > sum2) {
    cout << "Left" << endl;
  } else if (sum1 < sum2){
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt" , "r" , stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	ll n,c=0,c1=0,c2=0,c3=0;
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		for(ll i=0;i<s.length()-1;i++)
		{
			if(s[i]=='A'&&s[i+1]=='B')
				c++;
		}
		if(s[0]=='B'&&s[s.length()-1]=='A')
			c1++;
		else if(s[0]=='B')
			c2++;
		else if(s[s.length()-1]=='A')
			c3++;
	}
	c=c+min(c2,c3);
	if(c1>0)
	{
	  c2-=min(c2,c3);
	  c3-=min(c2,c3);
	  if(c2||c3)
	  c+=c1;
	  else
	  	c+=c1-1;
	}
	cout<<c<<endl;


	
	
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 305;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int32_t main() {
	FAST;

	int n, c0 = 0;
	cin >> n;
	vector<int> a(n);
	string s;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {c0++; a[i] = 0;}
		else a[i] = 1;
	}

	int t = 0;
	for (int i = 0; i < c0; i++) {
		if (!a[i]) t++;
	}

	cout << min({c0 - t, c0, n - c0});
}

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

N = int(input())
S = input()
if len(S) % 2 == 0:
    char1 = S[0:N // 2]
    char2 = S[N // 2: N + 1]
    if char1 == char2:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++)
        cnt += (s[i] == 'x');
    if (cnt > 7)
        cout << "NO\n";
    else
        cout << "YES\n";

    return 0;
}


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

int n, m, k;
int a[305][305], vis[305], been[305];

bool check(int x) {
    memset(been, 0, sizeof(been));
    for (int i = 1; i <= n; i++) a[i][0] = 1;
    while (1) {
        memset(vis, 0, sizeof(vis));
        bool flag = true;
        for (int i = 1; i <= n; i++) {
            while (a[i][0] <= m && been[a[i][a[i][0]]]) a[i][0]++;
            if (++vis[a[i][a[i][0]]] > x) {
                been[a[i][a[i][0]]] = 1;
                flag = false;
            }
            if (a[i][0] > m) return false;
        }
        if (flag) return true;
    }
    return false;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        a[i][0] = 1;
        for (int j = 1; j <= m; j++)
            scanf("%d", &a[i][j]);
    }
    int l = 1, r = n;
    while (l < r) {
        int mid = (l + r) >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 640
#include <fstream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <bitset>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <set>
#include <complex>
#include <cstring>

using namespace std;

const int SIZE = 1 << 10;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

const int MAXN = 100000;

char s[1 + MAXN];

struct Trie {
    Trie *son[2];

    Trie() {
        son[0] = son[1] = NULL;
    }
};

Trie *root;

void Insert() {
    int n = strlen(s + 1);
    Trie *node = root;
    for (int i = 1; i <= n; i++) {
        if (!node->son[s[i] - '0'])
            node->son[s[i] - '0'] = new Trie();
        node = node->son[s[i] - '0'];
    }
}

long long l, xorSum = 0;

long long SG(long long x) {
    return x & -x;
}

void Solve(Trie *node, int depth) {
    for (int i = 0; i < 2; i++)
        if (!node->son[i])
            xorSum ^= SG(l - depth);
        else
            Solve(node->son[i], depth + 1);
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    root = new Trie();
    int n;
    scanf("%d%lld\n", &n, &l);
    for (int i = 1; i <= n; i++) {
        scanf("%s\n", s + 1);
        Insert();
    }
    Solve(root, 0);
    if (xorSum)
        printf("Alice\n");
    else
        printf("Bob\n");
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <cmath>
#include <bitset>
#include <queue>
#include <set>
#include <numeric>
#include <unordered_set>
#include <iomanip>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

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

	ll n, d, a;
	cin >> n >> d >> a;
	vector<pair<ll, ll>> v(n);
	for (auto &x : v)
	{
		cin >> x.first >> x.second;
		x.second = (x.second + a - 1) / a;
	}
	sort(v.begin(), v.end());

	vector<int> bit(n + 1);
	auto update = [&](ll idx, ll val) {
		for (++idx; idx <= n; idx += idx & -idx)
		{
			bit[idx] += val;
		}
	};
	auto range_update = [&](ll l, ll r, ll val) {
		update(l, val);
		update(r + 1, -val);
	};
	auto query = [&](ll idx) {
		ll res = 0;
		for (++idx; idx > 0; idx -= idx & -idx)
		{
			res += bit[idx];
		}
		return res;
	};
	
	for (ll i = 0;i<n;++i){
		range_update(i, i, v[i].second);
	}

	ll tot = 0;
	for (ll i = 0; i < n; ++i)
	{
		ll h = query(i);
		if (h <= 0)
			continue;
		ll lo = 0, hi = n - 1, ans = -1;
		while (lo <= hi)
		{
			ll mid = lo + (hi - lo) / 2;
			if (v[mid].first <= v[i].first + 2 * d)
			{
				ans = mid;
				lo = mid + 1;
			}
			else
			{
				hi = mid - 1;
			}
		}
		range_update(i, ans, -h);
		tot += h;
	}
	cout << tot;
}

Measured memory_bytes: 4224
S = str(input())
for i in range(1, len(S), 2):
    if S[i] == "L" or S[i] == "U" or S[i] == "D":
        continue
    else:
        print("No")
        exit()
for i in range(0, len(S), 2):
    if S[i] == "R" or S[i] == "U" or S[i] == "D":
        continue
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, k;
  cin >> n >> k;
  int res = 0;
  while(n--){
    int x;
    cin >> x;
    if(x >= k){
      res++;
    }
  }
  cout << res;
}

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

int main() {
	int N, K, X, Y;
	cin >> N;
	cin >> K;
	cin >> X;
	cin >> Y;
	if (N > K) {
		cout << (K * X) + ((N - K) * Y) << endl;
	} else {
		cout << (N * X) << endl;
	}
}

Measured memory_bytes: 256
import itertools
n=int(input())
l={i for i in range(1,n+1)}
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

#def factor(x):
  #y=1
  #if x==0 or x==1:
    #return 1
  #else:
    #for i in range(1,x+1):
      #y*=i
    #return y
#jp=0
#jq=0
#for i in range(n):
  #jp+=(p[i]-1)*factor(n-i-1)
  #jq+=(q[i-1])*factor(n-i-1)
#print(jp,jq)
per=list(itertools.permutations(l))

for i in range(len(per)):
  #print(per[i],p)
  if per[i]==p:
    a=i
  if per[i]==q:
    b=i
print(abs(a-b))



Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color [MAX];

void dfs(int r, int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;
  while ( !S.empty() ) {
    int u = S.top(); S.pop();
    for ( int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if ( color[v] == NIL ) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  int id = 1;
  for (int i = 0; i < n; i++) color[i] = NIL;
  for (int u = 0; u < n; u++) {
    if (color[u] == NIL) dfs(u, id++);
  }
}

int main() {
  int s, t, m, q;

  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 8972