akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

vector<int> bfs(
    int p,
    const vector<vector<int>> graph)
{
    queue<int> Q;
    vector<bool> status(graph.size());
    vector<int> distance(graph.size());
    Q.push(p);
    status[p] = true;
    while (!Q.empty())
    {  
        int k = Q.front();
        Q.pop();
        for (const auto& q : graph[k]) {
            if (!status[q]) {
                Q.push(q);
                status[q] = true;
                distance[q] = distance[k]+1;
            }
        }
    }
    for (int i = 0; i < status.size(); ++i) {
        if (status[i] == 0) {
            distance[i] = -1;
        }
    }
    return distance;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    for (auto&& g : graph) {
        int id;
        cin >> id;
        int size;
        cin >> size;
        g.reserve(size);
        for (int j = 0; j < size; ++j) {
            int k; 
            cin >> k;
            g.push_back(k-1);
        }
    }
    auto result = bfs(0, graph);
    for (int i = 0; i < result.size(); ++i) {
        cout << i+1 << " " << result[i] << endl;
    }
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll> a(n+1),limit(n);
  rep(i, n+1)cin>>a[i];

  if(n==0){
    if(a[0]==1)cout<<1<<endl;
    else cout<<-1<<endl;
    return 0;
  }

  limit[n-1]=a[n]+a[n-1];
  rrep(i, n-1){
//cout<<limit[i+1]<<' '<<a[i]<<endl;
    limit[i] = limit[i+1]+a[i];
  }
  limit.push_back(a.back());

//  for(auto c:limit)cout<<c<<' ';cout<<endl;

  ll result = 1;
  ll l=1;

  if(a[0]==1 && n>0) { cout<<-1<<endl; return 0; }

  rep(i, n){
    ll c=(ll)a[i];

    ll nl = min<ll>((l-c)*2LL, limit[i+1]);
    if(l-c<0 || nl-a[i+1]<0) { 
//cout<<nl<<'-'<<a[i+1]<<endl;
cout<<-1<<endl; return 0;}
    if(l==0 && a[i]>0) { cout<<-1<<endl; return 0;}

    if(i<n-1)result += nl;
//cout<<l<<' '<<c<<' '<<l-c<<' '<<nl<<' '<<result<<endl;
    swap(l, nl);
  }
//cout<<l<<endl;
  if(a.back()>limit.back() || a.back()>l) { cout<<-1<<endl; return 0; }

  cout<<result+a.back()<<endl;

  return 0;
}

Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int SIZE = 1e5 + 333;
const int MOD = 1e9 + 7;

vector <int> graf[SIZE];
bool vis[SIZE];
int dp[SIZE][2];

int n, a, b;

    void input(){
        cin >> n;
        for(int i = 1; i < n; i++){
            cin >> a >> b;
            graf[a].push_back(b);
            graf[b].push_back(a);
        }
    }

    void dfs(int start){
        vis[start] = true;
        for(auto it : graf[start])
            if(!vis[it]){
                dfs(it);
                dp[start][0] *= dp[it][0] + dp[it][1];
                dp[start][1] *= dp[it][0];
                dp[start][0] %= MOD;
                dp[start][1] %= MOD;
            }
    }
signed main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    input();

    for(int i = 0; i <= n; i++){
            dp[i][0] = 1;
            dp[i][1] = 1;
        }

    dfs(1);

    cout << (dp[1][0] + dp[1][1]) % MOD;
    return 0;

}

Measured memory_bytes: 11520
n,m = map(int,input().split())
a = list(map(int,input().split()))
m_count = 0
a_sum = sum(a)
for i in a:
  if i >= (a_sum/(4*m)):
    m_count += 1
  else:
    continue
    
if m_count >= m:
  print("Yes")
else:
  print("No")

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];

    repa(i,k,n){
        if(a[i]>a[i-k])cout<<"Yes\n";
        else cout<<"No\n";
    }

    return 0;

}

Measured memory_bytes: 4044
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
struct edge{int to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
int two[114514];
void multi(){
    two[0]=1;
    rep(i,0,114510)two[i+1]=two[i]*2%inf;
}
signed main(){
    int n,m;cin>>n>>m;
    int a[114514],b[114514];
    multi();
    int suma[114514],sumb[114514];
    rep(i,0,n){
        cin>>a[i];
        if(i)suma[i]=(a[i]+suma[i-1])%inf;
        else suma[i]=a[i];
    }rep(i,0,m){
       cin>>b[i];
        if(i)sumb[i]=(b[i]+sumb[i-1])%inf;
        else sumb[i]=b[i];
    }
    int ansh=0,answ=0;
    rep(i,1,n)ansh=((i*a[i]%inf)-suma[i-1]+inf+ansh)%inf;
    rep(i,1,m)answ=((i*b[i]%inf)-sumb[i-1]+inf+answ)%inf;
    cout<<ansh*answ%inf<<endl;
    return 0;
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a[] = new int[n];

		for(int i = 0; i < n; i++){
			a[sc.nextInt()]++;
		}

		int count = 0;

		int start = 1;
		if(n % 2 == 1){
			start = 2;

			if(a[0] != 1){
				System.out.println(0);
				return;
			}

			count++;
		}

		for(int i = start; i < n; i += 2){
			if(a[i] != 2){
				System.out.println(0);
				return;
			}

			count += a[i];
		}

		if(count != n){
			System.out.println(0);
			return;
		}

		else {
			long result = 1;
			for(int i = 0; i < n/2; i++){
				result *= 2;
				result %= 1_000_000_007;
			}

			System.out.println(result);
		}

	}

}


Measured memory_bytes: 50508
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(){
  int n,x,t;
  cin >> n >> x >> t;
  int tmp = n%x;
  if(tmp == 0) cout << (n/x) *t;
  else cout << (n/x +1) *t;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 101000
#define LL long long

int x, y, z, n;
LL sum, ans;//已选元素A / B和，已选元素C和，前缀C和，后缀C和,前后缀C和是在不同顺序的意义下的
LL f[AC], g[AC];

struct node{
	LL a, b, c, v;
}s[AC];

struct cmp_min{
	bool operator () (int a, int b){
		return s[a].v > s[b].v;
	}
};

priority_queue<int, vector<int>, cmp_min> q;//小根堆，维护已选元素的min
inline bool cmp1(node a, node b){return a.a - a.b > b.a - b.b;}//按ai - bi从大到小排序
inline void upmax(LL &a, LL b){ if(b > a) a = b;}

inline int read()
{
	int x = 0;char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

void pre()
{
	x = read(), y = read(), z = read(), n = x + y + z;
	for(R i = 1; i <= n; i ++) //先默认全都选C，然后根据改成选A的增量来判断哪些选A
		s[i].a = read(), s[i].b = read(), s[i].c = read();		
	sort(s + 1, s + n + 1, cmp1);
	//for(R i = 1; i <= n; i ++) printf("%lld %lld %lld\n", s[i].a, s[i].b, s[i].c);		
	for(R i = 1; i <= n; i ++) 
		s[i].a -= s[i].c, s[i].b -= s[i].c, ans += s[i].c;
//	for(R i = 1; i <= n; i ++) printf("%lld %lld\n", s[i].a, s[i].b);
}

void work1()
{
	for(R i = 1; i <= n; i ++) s[i].v = s[i].a;
	for(int i = 1; i <= x; i ++) 
	{
		q.push(i), sum += s[i].a;//先把前x个取走
		if(i != x) f[i] = -1e18;//不合法状态一定要初始化
	}
	f[x] = sum;
	int tmp = n - y;
	for(int i = x + 1; i <= tmp; i ++)
	{
		int now = q.top();
		if(s[now].v < s[i].v) //只需要维护一个堆，因为如果现在不能替换掉堆内元素，以后就更不可能了
		{	
			q.pop(), sum -= s[now].a; 
			q.push(i), sum += s[i].a;
		}
		f[i] = sum;
	}
	for(R i = tmp + 1; i <= n; i ++) f[i] = -1e18;
	//for(R i = 1; i <= n; i ++) printf("%lld ", f[i]);
	//printf("\n");
}

void work2()
{
	q = priority_queue<int, vector<int>, cmp_min> ();
	int tmp = n - y;
	sum = 0;
	for(R i = 1; i <= n; i ++) s[i].v = s[i].b;//修改要在入队之前！！！	
	for(int i = n; i > tmp; i --) 
	{
		q.push(i), sum += s[i].b;
		if(i != tmp + 1) g[i] = -1e18;//不合法状态一定要初始化
	}
	g[tmp + 1] = sum;
	for(int i = tmp; i > x; i --) 
	{
		int now = q.top();
		if(s[now].v < s[i].v)
		{
			q.pop(), sum -= s[now].b;
			q.push(i), sum += s[i].b; 
		}
		g[i] = sum;
	}
	for(R i = 1; i <= x; i ++) g[i] = -1e18;
	//for(R i = 1; i <= n; i ++) printf("%lld ", g[i]);
	//printf("\n");
	LL maxn = -1e18;//f和g数组完全可能是负数啊，a，c又不一定大于c...
	for(R i = 1; i <= n; i ++) upmax(maxn, f[i] + g[i + 1]);
	//printf("%lld\n", maxn);
	printf("%lld\n", ans + maxn);
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work1();
	work2();
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 5628
import math
A, B, H, M = map(int, input().split())
sd = H*30 + M*0.5
ld = M*6

c1 = ld - sd
ans = A**2 + B**2 - 2*A*B*math.cos(math.radians(c1))

print(f"{math.sqrt(ans):.10f}")

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

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;

	int cnt = 0;
	for(int i = 0; i <= a; i++) {
		for(int j = 0; j <= b; j++) {
			for(int k = 0; k <= c; k++) {
				if((i * 500 + j * 100 + k * 50) == x) cnt++;
			}
		}
	}

	cout << cnt <<endl;

 	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int d;
vector<int> c(26,0),last(26,0);
vector<vector<int>> s;

void score(vector<int> &t){
    int ans=0;
    rep(i,d){
        ans+=s[i][t[i]-1];
        last[t[i]-1]=i+1;
        rep(j,26) ans-=c[j]*(i+1-last[j]);
        cout<<ans<<endl;
    }
}

int main(){
    cin>>d;
    vector<int> t(d,0);
    rep(i,26) cin>>c[i];
    s.assign(d,vector<int>(26,0));
    rep(i,d)rep(j,26){
        cin>>s[i][j];
    }
    rep(i,d) cin>>t[i];
    score(t);
}


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

using LL =unsigned long long;
using namespace std;

int main()
{
    int N;cin >> N;
    vector<int> T,X,Y;
    T.push_back(0);
    X.push_back(0);
    Y.push_back(0);
    for(int a = 0;a < N;a++){
        int b,c,d;cin >> b >> c >> d;
        T.push_back(b);
        X.push_back(c);
        Y.push_back(d);
    }
    bool result = true;
    for(int a = 1;a < N+1;a++){
        //cout<<T.at(a)-T.at(a-1)<<" "<<X.at(a)+Y.at(a)<<endl;
        int rec= T.at(a)-T.at(a-1);
        int kyo = abs(X.at(a)-X.at(a-1))+abs(Y.at(a)-Y.at(a-1));
        if(rec < kyo){
            result = false;
           //cout<<"L"<<endl;
        }else{
            if(rec%2!=kyo%2){
                    result = false;
             //       cout<<"M"<<endl;
                }
        }
        }
    cout<<(result?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 1644
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b = iim()

if a*b <= 0:
    print('Zero')
elif a > 0:
    print('Positive')
else:
    if abs(a-b)%2 == 0:
        print('Negative')
    else:
        print('Positive')

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

int main(){
  int64_t A;
  string B;
  cin >> A >> B;
  int64_t X, Y, Z;
  X=B.at(0)-'0';
  Y=B.at(2)-'0';
  Z=B.at(3)-'0';
  int64_t Ans=0;
  Ans+=X*A;
  int64_t subAns=0;
  subAns+=Y*A*10;
  subAns+=Z*A;
  Ans+=subAns/100;
  cout << Ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	char b;
	cin >> b;

	if (b == 'A')
		cout << 'T' << endl;
	else if (b == 'T')
		cout << 'A' << endl;
	else if (b == 'C')
		cout << 'G' << endl;
	else
		cout << 'C' << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define all(container) container.begin(), container.end()
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;

struct Score {
  int a;
  int b;
  int sum;
};

int main() {
  long long n, scoreT, scoreA;
  cin >> n;
  vector<Score> score(n);
  rep(i, 0, n) {
    cin >> score[i].a >> score[i].b;
    score[i].sum = score[i].a + score[i].b;
  }
  sort(all(score), [](const Score &x, const Score &y) {
    return x.sum > y.sum;
  });
  int idx;
  scoreT = 0;
  scoreA = 0;
  rep(i, 0, n) {
    if (i % 2 == 0) {
      scoreT += score[i].a;
    } else {
      scoreA += score[i].b;
    }
  }

  cout << scoreT - scoreA << endl;

  return 0;
}


Measured memory_bytes: 1408
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.B
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int w = cin.NextInt();
			int h = cin.NextInt();
			int n = cin.NextInt();
			int xmin = 0;
			int xmax = w;
			int ymin = 0;
			int ymax = h;
            for (int i = 0; i < n; i++)
            {
				var x = cin.NextInt();
				var y = cin.NextInt();
				var a = cin.NextInt();
                switch (a)
                {
					case 1:
						xmin = Math.Max(xmin, x);
						break;
					case 2:
						xmax = Math.Min(xmax, x);
						break;
					case 3:
						ymin = Math.Max(ymin, y);
						break;
					case 4:
						ymax = Math.Min(ymax, y);
						break;
					default:
                        break;
                }
            }
			Console.WriteLine(Math.Max(0, xmax - xmin) * Math.Max(0, ymax - ymin));

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    string s;
    cin >> s;
    Int len = (Int)s.length();
    if (len % 2 == 1) {
        cout << "No" << endl;
    } else {
        bool result = true;
        for (Int i = 0; i < len; i += 2) {
            if (s[i] == 'h' && s[i + 1] == 'i') {
            } else {
                result = false;
            }
        }
        if (result) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

const ll MAX = 510000;
// const ll MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

// 二項係数計算
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll a[101];
ll solve()
{
    ll n;
    cin >> n;
    for(int i=0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 1e9;
    for(ll i=-100; i < 101; i++){
        ll t = 0;
        for(int j=0; j <n ; j++){
            t += abs(a[j] - i)*abs(a[j] - i);
        }
        ans = min(ans, t);
    }
    cout << ans << endl;

    return 0;
}

int main()
{
    //cout.precision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B, C, D;
	cin >> A >> B >> C >> D;
	A += B;
	C += D;
	if (A == C)
	{
		cout << "Balanced" << endl;
	}
	else if (A > C)
	{
		cout << "Left" << endl;
	}
	else
	{
		cout << "Right" << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)
lcm=(c*d)//gcd(c,d)
dba=(a//c-int(a%c==0))+(a//d-int(a%d==0))-(a//lcm-int(a%lcm==0))
dbb=(b//c)+(b//d)-(b//lcm)
dbb-=dba
ans-=dbb
print(ans)
        
        

Measured memory_bytes: 65004
import sys


def alg_combination_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    for i in range(k):
        if k -1 >= i and n - k + 1 >= i + 1:
            print((alg_combination_mod(k-1, i, mod) * alg_combination_mod(n - k + 1, i + 1, mod)) % mod)
        else:
            print(0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 42224
import sys
input=sys.stdin.readline
from bisect import bisect_left

class SegmentTree():
    def __init__(self,param,default,func):
        if isinstance(param,list):
            n=len(param)
        else:
            n=param
        self.d=default
        self.leaf=1<<(n-1).bit_length()
        if isinstance(param,list):
            self.tree=[default]*(self.leaf-1)+param+[default]*(self.leaf-n)
            for i in range(self.leaf-2,-1,-1):
                self.tree[i]=func(self.tree[i*2+1],self.tree[i*2+2])
        else:
            self.tree=[default]*(self.leaf*2-1)
        self.f=func
    def find(self,i):
        return self.tree[i+self.leaf-1]
    def update(self,idx,a):
        idx+=self.leaf-1
        self.tree[idx]=a
        while idx:
            idx=(idx-1)>>1
            self.tree[idx]=self.merge(self.tree[idx*2+1],self.tree[idx*2+2])
    def merge(self,a,b):
        return self.f(a,b)
    def get_top(self):
        return self.tree[0]
    def query(self,a,b): #[a,b)
        T=self.tree
        l,r=a+self.leaf-1,b+self.leaf-1
        res=self.d
        while l<r:
            if not l%2:
                res=self.merge(res,T[l])
                l+=1
            if not r%2:
                r-=1
                res=self.merge(res,T[r])
            l>>=1; r>>=1
        return res

def main():
    mod=998244353
    n=int(input())
    XD=[list(map(int,input().split())) for _ in range(n)]
    XD.sort()
    X=[x for x,d in XD]
    seg=SegmentTree(n,-1,max)
    DP=[0]*(n+1)
    DP[-1]=1
    for i in reversed(range(n)):
        x,d=XD[i]
        j=bisect_left(X,x+d)
        r=max(i,seg.query(i+1,j))
        seg.update(i,r)
        DP[i]=(DP[i+1]+DP[r+1])%mod
    print(DP[0])
    
if __name__=='__main__':
    main()

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

int n;
string s;
string solve()
{
	stack<char> opened;
	VB paired(n, false);
	 REP(i, 0, n)
	 {
		 if(s[i] == '(') opened.push(i);
		 else {
			if(opened.empty() == false)
				paired[i] = true, paired[opened.top()] = true, opened.pop();
		 }
	 }
	
	string ans = s;
	for(int i = 0; i < n; ++i)
	{
		if(paired[i] == false) {
			if(s[i] == '(') {
				ans.push_back(')');
			}
			else { // ')'
				ans.insert(ans.begin(), '(');
			}
		}
	}
	//sort(ALL(ans));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> s;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if (A > B)
    {
        cout << (A + A - 1) << endl;
    }
    else if (A == B)
    {
        cout << (2 * A) << endl;
    }
    else
    {
        cout << (B + B - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;

using std::string;

int abs(int a) { return a < 0 ? -a : a; }

int main() {
    string s;
    cin >> s;

    int a, b, c;
    a = b = c = 0;
    for (char i : s) {
        if (i == 'a') {
            a++;
        } else if (i == 'b') {
            b++;
        } else if (i == 'c') {
            c++;
        }
    }

    while (a >= 3 && b >= 3 && c >= 3) {
        a -= 3;
        b -= 3;
        c -= 3;
    }

    bool ans = a <= 3 && b <= 3 && c <= 3 && abs(a - b) <= 1 && abs(b - c) <= 1 &&
               abs(c - a) <= 1;
    cout << (ans ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 888
import Control.Applicative
import Control.Monad
import Data.List
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  [a, b, c] <- readInts
  print $ solve a b c

solve :: Int -> Int -> Int -> Int
solve a b c = length [ d | d <- divisors c, a <= d, d <= b ]

divisors :: Int -> [Int]
divisors n = [ d | d <- [1..n], n `rem` d == 0 ]



Measured memory_bytes: 4132
/////////////////////////////////////////Info/////////////////////////////////////////////////
//Problem:
//Date:
//Skill:
//Bug:
/////////////////////////////////////////Definations/////////////////////////////////////////////////
//循环控制
#define CLR(a) memset((a),0,sizeof(a))
#define F(i,a,b) for(int i=a;i<=int(b);++i)
#define F2(i,a,b) for(int i=a;i>=int(b);--i)
#define RE(i,n)  for(int i=0;i<int(n);i++)
#define RE2(i,n) for(int i=1;i<=int(n);i++)
//简化敲击
#define PII pair<int,int>
#define PLL pari<long long ,long long>
#define PB push_back
#define ENDL '\n'
#define x first
#define y second
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
////////////////////////////////////////Options//////////////////////////////////////////////////////
#define stdcpph
#define CPP_IO

#ifdef stdcpph
#include<bits/stdc++.h>
#else
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#ifdef CPP_IO
#include<iostream>
#include<iomanip>
#include<string>
#else
#include<stdio.h>
#endif
#endif
////////////////////////////////////////Basic Functions//////////////////////////////////////////////
template<typename INint> inline void IN(INint &x)
{
	x = 0; int f = 1; char c; cin.get(c);
	while (c<'0' || c>'9') { if (c == '-')f = -1; cin.get(c); }
	while (c >= '0'&&c <= '9') { x = x * 10 + c - '0'; cin.get(c); }
	x *= f;
}
template<typename INint> inline void OUT(INint x)
{
	if (x > 9)OUT(x / 10); cout.put(x % 10 + '0');
}
////////////////////////////////////////Added Functions//////////////////////////////////////////////
const int maxn = int(20);
int n;
string s;
int  ans(0);
int cnt[4];
////////////////////////////////////////////Code/////////////////////////////////////////////////////
int main()
{
	//freopen("C:\\Users\\VULCAN\\Desktop\\data.in", "r", stdin);
	int T(1), times(0);
#ifdef CPP_IO// CPP_IO
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//cin >> T;
#else
	//IN(T);
#endif 
	/////////////////////////////////////////////////////////////////////////////////////////////////
	while (++times, T--)
	{
		cin >> n;
		RE2(i, n)
		{
			cin >> s;
			RE(i, s.size() - 1)
			{
				if (s[i] == 'A'&&s[i + 1] == 'B')++ans;
			}
			int st = 0;
			if (*s.begin() == 'B')st += 2;
			if (s.back() == 'A')st += 1;
			cnt[st]++;
		}
		int st = 0;
		while (1)
		{
			if (st == 0)
			{
				if (cnt[1])
				{
					--cnt[1]; st = 1;
				}
				else if(cnt[3])
				{
					--cnt[3]; st = 1;
				}
				else break;
			}
			else
			{
				if (cnt[3])
				{
					--cnt[3]; ++ans;
				}
				else if (cnt[2])
				{
					--cnt[2]; ++ans; st = 0;
				}
				else break;
			}
		}
		cout << ans << endl;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////////
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
int a[100000], x[100000], y[100000], z[100000], n, m, cnt;

int f(int x) {
  if(x == a[x])
    return x;
  return a[x] = f(a[x]);
}

void con(int p, int t) {
  if(f(p) == f(t))
    return;
  --cnt;
  a[f(p)] = f(t);
}

int main() {
  cin >> n >> m;
  cnt = n;
  for(int i = 0; i < m; ++i)
    cin >> x[i] >> y[i] >> z[i], (--x[i], --y[i]);
  iota(a, a + n, 0);
  for(int i = 0; i < m; ++i)
    con(x[i], y[i]);
  cout << cnt << endl;
}

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

int a, b, c, x, cnt = 0;

int main() {
  int i, j, k;
  cin >> a >> b >> c >> x;
  for(i = 0; i <= a; ++i)
    for(j = 0; j <= b; ++j)
      for(k = 0; k <= c; ++k)
        if(i * 500 + j * 100 + k * 50 == x) ++cnt;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
/* ****AWARE**** */
#include<bits/stdc++.h>
#include <limits.h> 
#define cut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define pb          push_back
#define endl        '\n'
#define pii         pair< ll, ll>
#define vi          vector< ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(  ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp13       make_pair
using namespace std; 
#define MAX  3000
#define MODULO 2
using namespace std;   
#define hell 1000000007 
#define hell1 30000000000000000
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define mysizeof(i) (char*)(&i+1)-(char *)(&i);
ll T;
//double dp[MAX][MAX];
vector<double>v;

void solve()
{    ll i,j,k,n,m,x=0,y=0,z=0;
     cin>>n;
     double a,b,c,d;
     for(i=0;i<n;i++)
     { cin>>a,v.pb(a);
     	
     	if(a==1)
     		x++;
     	else if(a==2)
     		y++;
     	else if(a==3)
     		z++;

     }
double dp[n+1][n+1][n+1];
for(k=0;k<=z;k++)
{
	for(j=0;j<=min(n,y+z-k) ;j++)
	{
		for(i=0;i<=min(n,x+y+z-k-j);i++)
		{   if(i==0 && j==0 && k==0)
			{
			   dp[i][j][k]=0;	
			   continue;
			}
			a=(((n-i-j-k)*(1.0))/n);
			if(a<0)
			continue;
			b=((i*(1.0))/n);
            c=((j*(1.0))/n);
            d=((k*(1.0))/n);
            dp[i][j][k]=1;
            if(b!=0)
            dp[i][j][k]+=b*dp[i-1][j][k];
           if(c!=0)
           	dp[i][j][k]+=c*dp[i+1][j-1][k];
           if(d!=0)
           	dp[i][j][k]+=d*dp[i][j+1][k-1];
            dp[i][j][k]=((dp[i][j][k])*(1.0))/(1-a);

		}
	}
}

cout<<fixed<<setprecision(11)<<dp[x][y][z]<<"\n";
  
}
           
int main(){ 
cut; 
ll t; 
//cin>>t;
//T=t;
 t=1;
while(t--)
solve();
return 0;
}
     


Measured memory_bytes: 111168
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int MOD=1e9+7;
//ll a[N];
//ll sum;
//ll ans[N];
char ans[505][505];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    ll a,b;
    cin >>a>>b;
    for(int i=1;i<=50;i++)
        for(int j=1;j<=100;j++) ans[i][j]='.';
    for(int i=51;i<=100;i++)
        for(int j=1;j<=100;j++) ans[i][j]='#';
    a--,b--;
    if(a){
        for(int i=52;i<=100&&a;i+=2)
            for(int j=1;j<=100&&a;j+=2)    a--,ans[i][j]='.';
    }
    if(b){
        for(int i=1;i<=48&&b;i+=2)
            for(int j=1;j<=100&&b;j+=2)    b--,ans[i][j]='#';
    }
    cout << 100 <<" "<< 100 <<endl;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++) cout << ans[i][j];
        cout <<"\n";
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<vector<int>> v(100001);

  REP(i, n) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
  }

  priority_queue<int> que;

  int sum = 0;
  FOR(i, 1, m + 1) {
    REP(j, v[i].size()) {
      que.push(v[i][j]);
    }

    if(!que.empty()) {
      sum += que.top();
      que.pop();
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 5632
N = int(input())
a = [0] + list(map(int, input().split()))
box = [0] * (N + 1)
ans = []

# ex. 3の倍数は 3*1, 3*2, ..., 3*(N//3 - 1), 3*(N//3)

# 箱Nから確定させていく (箱番号が大きいものほど、考慮すべき箱の数が少ない)

# 箱iについて
for i in range(N, 0, -1):
    cnt = 0
    # 2*i, 3*i, ..., N//i * i について、現在のボールの総和
    for j in range(N // i, 1, -1):
        cnt += box[i * j]
    # 既に偶奇が満たされている場合
    if cnt % 2 == a[i]:
        box[i] = 0
    # 偶奇が満たされていない場合
    else:
        box[i] = 1
        ans.append(i)

ans = ans[::-1]
print(len(ans))
if len(ans) > 0:
    print(*ans)


Measured memory_bytes: 92272
#include<iostream>
#include<math.h>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include <cstdint>

typedef unsigned long long ll;

using namespace std;

int main() {
	char b;
	cin >> b;
	if (b == 'A') {
		cout << 'T';
	}
	if (b == 'C') {
		cout << 'G';
	}
	if (b == 'G') {
		cout << 'C';
	}
	if (b == 'T') {
		cout << 'A';
	}
}



Measured memory_bytes: 256
A, B = [int(num) for num in input().split()]
max = A * B

bigger = None
smaller = None
if A > B:
    bigger = A
    smaller = B
else:
    bigger = B
    smaller = A

for i in range(1, smaller + 1):
    num = bigger * i

    if not num % smaller:
        print(num)
        break

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

int main(void){
    int n, t[105], m, p, x, tsum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
        tsum += t[i];
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        cin >> p >> x;
        cout << tsum - t[p] + x << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    static int n;
    static int m;
    static long x;
    static long[] cost;
    static long[][] exp;
    static long min;
    static List<Long> now;

    static void dfs(int i, long c, List<Long> list){
        if(overX(list)){
            if(min == -1 || min > c){
                min = c;
            }
            return;
        }
        if(i >= n){
            return;
        }
        List<Long> newList = new ArrayList<>();
        newList.addAll(now);
        dfs(i + 1, c, list);
        newList = new ArrayList<>();
        for(int j=0; j<m; j++){
            newList.add(list.get(j) + exp[i][j]);
        }
        dfs(i + 1, c + cost[i], newList);
    }
    
    static boolean overX(List<Long> list){
        boolean flag = true;
        for(int i=0; i<m; i++){
            if(list.get(i) < x){
                flag = false;
                break;
            }
        }
        return flag;
    }

    public static void main(String[] args) throws Exception{

        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        m = sc.nextInt();
        x = sc.nextLong();

        cost = new long[n];
        exp = new long[n][m];
        now = new ArrayList<>();
        for(int i=0; i<m; i++){
            now.add(0L);
        }
        min = -1;

        for(int i=0; i<n; i++){
            cost[i] = sc.nextLong();
            for(int j=0; j<m; j++){
                exp[i][j] = sc.nextLong();
            }
        }

        dfs(0, 0, now);
        System.out.println(min);
    }
}

Measured memory_bytes: 40496
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  int n;
  ll ans = 1;
  cin >> n;
  vector<ll> a;
  rep(i, n)
  {
    ll x;
    cin >> x;
    a.push_back(x);
    if (x == 0)
    {
      cout << 0 << endl;
      return 0;
    }
  }

  for (auto ai : a)
  {
    if (ans > 1000000000000000000 / ai)
    {
      cout << -1 << endl;
      return 0;
    }
    ans *= ai;
  }

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


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

int main() {
  int n;
  cin >> n;
  vector<char> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
    if (s.at(i) == 'Y') {
      cout << "Four";
      return 0;
    }
  }
  cout << "Three";

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b;
  if((a+b)==4)
    cout<<2<<endl;;
  if((a+b)==5)
    cout<<1<<endl;
  if((a+b)==3)
    cout<<3<<endl;
  return 0;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	char b; cin>>b;
	if (b=='A') cout << "T\n";
	else if (b=='T') cout << "A\n";
	else if (b=='C') cout << "G\n"; 
	else cout << "C\n" << endl;;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<string> str{"dream","dreamer", "erase", "eraser" };
string S;

void deleate(int index,string search){
  if(equal(search.begin(),search.end(),S.begin()+index)){
    index += search.size();
    if(S.begin() + index == S.end()){
      cout << "YES" << endl;
      exit(0);
    }else{
      for(int i =0;i < str.size(); i++){
        deleate(index,str[i]);
      }
    }
  }  
}

int main(){
  //string S;
  cin >> S;
  
  for(int i =0;i < str.size(); i++){
    deleate(0,str[i]);
  }
  
  cout << "NO" <<endl;
}

Measured memory_bytes: 2560
loop do
  n, m = gets.split.map(&:to_i)
  
  break if n == 0
  
  arr1, arr2, cur = n.times.map{ gets.to_i }, m.times.map{ gets.to_i }, 0
  
  m.times do |i|
    cur += arr2[i]
    
    if cur >= n - 1
      puts i + 1
      break
    end
    
    cur += arr1[cur]
    
    if cur >= n - 1
      puts i + 1
      break
    end
  end
end

Measured memory_bytes: 8908
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
    vector<string> b(m);
    for(int i=0;i<m;i++){
        cin>>a.at(i)>>b.at(i);
    }
    vector<vector<int>> c(n,vector<int>(0));
    
    vector<bool> clear(n,false);
    int cans=0,wans=0;
    for(int i=0;i<m;i++){
        if(clear.at(a.at(i)-1)){
            continue;
        }
        if(b.at(i)=="AC"){
            cans+=1;
            wans+=c.at(a.at(i)-1).size();
            clear.at(a.at(i)-1)=true;
        }else{
            c.at(a.at(i)-1).push_back(0);
        }
    }
    cout<<cans<<" "<<wans;
}

Measured memory_bytes: 10368
def gcd(a,b):
  while a%b != 0:
    a,b = b,a%b
  return b

N,K = map(int, input().split())
A = list(map(int, input().split()))
m = max(A)
if K > m:
  print('IMPOSSIBLE')
  exit()

if K in A:
  print('POSSIBLE')
  exit()

g = A[0]
for i in A[1:]:
  g = gcd(g,i)

if K % g == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	string s;
	cin>>s;
	sort(all(s));
	if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int calc(int a,int b,int c,int x)
{
	int res=0;
	for(int t:{a,b,c}){
		if(t>x)
			res+=t-x;
		else{
			int d=x-t;
			res+=d/2+(d%2)*2;
		}
	}
	return res;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int a,b,c;cin>>a>>b>>c;){
		// 1減らす or 2増やす を繰り返してxにする
		int res=INF;
		for(int x=-100;x<=100;x++)
			chmin(res,calc(a,b,c,x));
		cout<<res<<endl;
	}
}


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

int main() {
  ll n, k, i = 0, c = 0;
  cin >> n >> k;

  vector<pair<ll, ll> > p(n);
  for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;

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

  while (c < k) {
    c += p[i].second;
    i++;
  }
  cout << p[i - 1].first << endl;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    vector<int64_t> probsum(N+1);
    for(int i=1; i<=N; i++){
        probsum[i] = (inv_mod(i+1) + probsum[i-1]) % MOD;
    }
    int64_t ans = 0;
    for(int i=0; i<N; i++){
        int64_t res = (1 + probsum[i] + probsum[N-1-i]) % MOD;
        add(ans, res * A[i] % MOD);
    }
    for(int i=1; i<=N; i++) mul(ans, i);
    cout << ans << endl;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

int main() {
	int M, N; cin >> M >> N;
	vector<string> C(M);
	for (int y = 0; y < M; y++)
		cin >> C[y];
	int cnt = 0;
	for (;;) {
		bool flag = false;
		for (int y = 0; y < M; y++)
			for (int x = 0; x < N; x++) {
				if (C[y][x] != '.') continue;
				vector<int> a(26);
				for (int k = 0; k < 4; k++)
					for (int _x = x, _y = y; _x >= 0 && _x < N && _y >= 0 && _y < M; _x += dx[k], _y += dy[k]) {
						char c = C[_y][_x];
						if (c != '.') {
							a[c - 'A']++;
							break;
						}
					}
				for (char c = 'A'; c <= 'Z'; c++) {
					if (a[c - 'A'] < 2) continue;
					cnt += 2;
					flag = true;
					for (int y = 0; y < M; y++)
						for (int x = 0; x < N; x++)
							if (C[y][x] == c)
								C[y][x] = '.';
				}
			}
		if (!flag) break;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1344
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

struct UnionFind {
    vector<int> d;
    UnionFind(int n = 0): d(n, -1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
    int count(int x) { return d[x];}
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        --x; --y;
        uf.unite(x, y);
    }
    int ans = 0;
    rep(i, n) {
        if(uf.count(i) < 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3728