akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const ll MAX_N = 1E+12;

ll N, M;

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

    cin >> N >> M;

    ll ans = 0;

    if (N < M / 2) {
        ll res = M - 2 * N;
        res /= 4;
        ans += N + res;
    } else {
        ans = M / 2;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	ll n,q;cin >> n >> q;
	
	REP(i,q)
	{
		ll a,b;cin >> a >> b;
		if(n == 1)
		{
			cout << min(a,b) << endl;
		}
		else
		{
			while(1)
			{
				if(a > b)
				{
					a = (a + n - 2) / n;
				}
				
				if(b > a)
				{
					b = (b + n - 2) / n;
				}
				
				if(a == b)
				{
					cout << a << endl;
					break;
				}
			}
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 1280
class Book
  attr_accessor :price, :values
  def initialize(price, values)
    @price = price
    @values = values
  end
end
n, m, x = gets.chomp.split(' ').map(&:to_i)
books = []
n.times do
  line = gets.chomp.split(' ').map(&:to_i)
  books << Book.new(line[0], line[1, line.length - 1])
end
min_price = Float::INFINITY
(0...(1 << n)).each do |i|
  values = Array.new(m, 0)
  price = 0
  (0...n).each do |j|
    next if (i >> j) & 1 != 1
    book = books[j]
    price += book.price
    values = values.map.with_index { |v, k| v + book.values[k] }
  end
  min_price = [price, min_price].min if values.inject(true) { |acc, value| acc && value >= x }
end
puts min_price != Float::INFINITY ? min_price : '-1'

Measured memory_bytes: 14396
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
#define vll			vector<ll>
#define sll			set<ll>
const ll inf = 1000000000000000;
ll in = 1000000000000000000;
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

int main()
{
	FastIO;
	ll t, a, i, j, k, q, c, d, b, r,n;
	cin >> n;
	vll v, u;
	f(i, n+1)
	{
		cin >> a;
		v.push_back(a);
	}
	f(i, n)
	{
		cin >> a;
		u.push_back(a);
	}
	ll sum = 0;
	f(i, n)
	{
		if (v[i] >= u[i])
		{
			sum += u[i];
			v[i] -= u[i];
		}
		else
		{
			sum += v[i];
			u[i] -= v[i];
			if (v[i + 1] <= u[i])
			{
				sum += v[i + 1];
				v[i + 1] = 0;
			}
			else
			{
				sum += u[i];
				v[i + 1] -= u[i];
			}
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 5568
#include <stdio.h>

int main(void) {
  int decimal_number,remainder;
  int stack[20];
  int i,j;
	
	while (1) {
		scanf("%d", &decimal_number);
		if (decimal_number == -1)break;
		i=0;
		while (1) {
		  remainder = decimal_number % 4;  
		  stack[i++] = remainder;          
		  if(decimal_number < 4) break;
		  decimal_number = decimal_number / 4; 
		}
		for(j=i-1; j>=0; j--)
		  printf("%d",stack[j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=13;
int NN_MAX=4096;
int INF=1e9;
int main()
{
  int n,m,a,b,t,i,j,k;
  int c[N_MAX],d[NN_MAX],s[NN_MAX][N_MAX],po[N_MAX];
  cin >> n >> m;
  po[0]=1;
  for(i=1;i<=n;i++)
    po[i]=po[i-1]*2;
  for(i=0;i<po[n];i++){
    t=i;
    for(j=0;j<n;j++){
      s[i][j]=t%2;
      t/=2;
    }
    d[i]=INF;
  }
  d[0]=0;
  for(k=0;k<m;k++){
    cin >> a >> b;
    for(i=0;i<b;i++){
      cin >> c[i];
      c[i]--;
    }
    for(i=0;i<po[n];i++){
      t=i;
      for(j=0;j<b;j++)
        if(s[i][c[j]]==0)
          t+=po[c[j]];
      d[t]=min(d[t],d[i]+a);
    }
  }
  if(d[po[n]-1]==INF)
    cout << "-1" << endl;
  else
    cout << d[po[n]-1] << endl;
  return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;


class UnionFind {
public:
    vector <int> par; // 各元の親を表す配列
    vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(int sz_): par(sz_), siz(sz_, 1) {
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);  // resize だとなぜか初期化されなかった
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    int root(int x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n,k,l;
  cin >> n >> k >> l;
  UnionFind road(n), rail(n);
  while(k--){
    int p,q;
    cin >> p >> q;
    p--;
    q--;
    road.merge(p,q);   
  }
  while(l--){
    int r,s;
    cin >> r >> s;
    r--;
    s--;
    rail.merge(r,s);
  }
  
  map<pair<int,int>,int>mp;
  rep(i,n){
    mp[make_pair(road.root(i),rail.root(i))]++;
  }
  rep(i,n){
    cout << mp[make_pair(road.root(i),rail.root(i))]<< " ";
  }
  return 0;
}


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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

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 <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (k <= a)
	{
		cout << k << en;
		return;
	}
	ans += a;
	k -= a;
	if (k && k <= b)
	{
		cout << ans << en;
		return;
	}
	cout << ans - (k - b) << en;
}

int main()
{
	fast;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
        while(a[i]==a[i+1])++i;
        if(a[i]<a[i+1]){
            while(a[i]<=a[i+1])i++;
        }
        else if(a[i]>a[i+1]){
            while(a[i]>=a[i+1])i++;
        }
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, b, c;
  cin >> n >> b >> c;
  if (c % __gcd(n,b) == 0) cout << "YES" << '\n';
  else cout << "NO" << '\n';
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    cout << "x";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n,m; cin >> n >> m;
  vi p(m),y(m);
  vvi ans(n);
  rep(i, m){
    cin >> p[i] >> y[i];
    p[i]--;
    ans[p[i]].push_back(y[i]);
  }
  rep(i, n) sort(all(ans[i]));
  rep(i,m){
      cout<< setfill('0') << setw(6) << p[i]+1;
      //"lower_bound(all(配列), key) - 配列.begin()" でkeyの先頭からの距離（0-index）
      //"lower_bound(all(配列), key)" はkey以上の要素の値（型はイテレータ）を返す
      int num = lower_bound(all(ans[p[i]]),y[i]) - ans[p[i]].begin();
      cout<< setfill('0') << setw(6) << num+1 <<endl;
    }
  }


Measured memory_bytes: 7808
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner tc=new Scanner(System.in);
		
		int a=tc.nextInt(), b=tc.nextInt(), c=0;
		if(a%b==0 || b%a==0) {c=a+b;}
		else {c=b-a;}
		System.out.println(c);
	
 
		
		// TODO Auto-generated method stub

	}

}


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

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  vector<bool> point_x(H,false);
  vector<bool> point_y(H,false);

  for(int i=0; i<H; i++){
    cin >> a[i];
  }

  
  for(int h_i=0; h_i<H; h_i++){
      for(int w_i=0; w_i<W; w_i++){
        if(a[h_i][w_i]=='#'){
          point_x[h_i]=true;
          point_y[w_i]=true;
        }
      }
  }

  for(int x=0; x<H; x++){
    if(point_x[x]){
       for(int y=0; y<W; y++){
         if(point_y[y]){
           cout<<a[x][y];
         }
       }
    
    cout <<endl;
    }
    	
    }
  return 0;
}

Measured memory_bytes: 256
let () =
  let n, (a, b) = Scanf.scanf "%d %d %d\n" (fun n a b -> (n, (a, b))) in
  let sum = a + b in
  let p = n / sum and q = n mod sum in
  if p >= 1 && q >= a then print_int ((a * p) + a)
  else if p >= 1 && q < a then print_int ((a * p) + q)
  else if q >= a then print_int a
  else print_int q


Measured memory_bytes: 384
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'

int n;
int aa[300000];
int bb[300000];
int q;
int no,w;
vector<int> cc;
int dp[512][100001];
int kk;
int ans=0;
void brute(int ind ,int su=0,int val=0){
	if(ind==cc.size()){
		if(su<=w){
			ans=max(ans,dp[kk][w-su]+val);
			//cout<<dp[kk][w-su]+val<<endl;
		}
	}
	else{
		brute(ind+1,su+bb[cc[ind]-1],val+aa[cc[ind]-1]);
		brute(ind+1,su,val);
	}
}
void calc(int no){
	if(no>511 or no>n){
		return;
	}
	if(no>1){
		for(int i=0;i<=100000;i++){
			dp[no][i]=dp[no/2][i];
		}
	}
	for(int i=100000;i>=bb[no-1];i--){
		dp[no][i]=max(dp[no][i],dp[no][i-bb[no-1]]+aa[no-1]);
	}
	calc(no*2+1);
	calc(no*2);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>aa[i]>>bb[i];
	}
	cin>>q;
	calc(1);
	while(q--){
		cin>>no>>w;

		if(no<=511){
			cout<<dp[no][w]<<endl;
			continue;
		}

		while(no>511){
			cc.pb(no);
			no/=2;
		}
		kk=no;
		ans=0;
		brute(0);
		cc.clear();
		cout<<ans<<endl;
		
	}






	return 0;
}

Measured memory_bytes: 205240
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, m; std::cin >> n >> m;
    std::vector<long long> x(m);
    for (int i = 0; i < m; i++) std::cin >> x[i];
    std::sort(x.begin(), x.end());
    std::vector<long long> d(m - 1);
    for (int i = 0; i < m - 1; i++) d[i] = x[i + 1] - x[i];
    std::sort(d.rbegin(), d.rend());
    std::cout << std::accumulate(d.begin(), d.end(), 0LL) -
        std::accumulate(d.begin(), d.begin() + std::min(n - 1, m - 1), 0LL)
        << std::endl;
    return 0;
}


Measured memory_bytes: 1792
using System;

namespace ABC_20190810_A0137_p_x_Cs
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            int k = int.Parse(line[0]);
            int x = int.Parse(line[1]);

            int ans0 = x-k +1;
            int ansn = k*2 -1;
            for(int i=0; i<ansn; i++) Console.Write(ans0+i + " ");
            Console.WriteLine();
        }
    }
}


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

void solve(int n){
    ll a=1,b=1,c=1;
    for(ll i=0;i<n;i++){
        a = (a * 10) % mod ;
        b = (b * 9) % mod;
        c = (c * 8) % mod;
    }
    b = (2 * b) % mod;
    int ans = (a -b+c) % mod;
    if(ans >= 0) cout << ans << endl;
    else cout << mod + ans << endl;
}

int main(){
    ll n;
    cin >> n;
    solve(n);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc() {
	ll n, h;
	ll ans = 0;

	cin >> n >> h;

	vector<P> a(n), b(n);
	V ob(n);
	ll ta, tb, ti;
	rep(i, n) {
		cin >> ta >> tb;
		a[i] = make_pair(ta, i);
		b[i] = make_pair(tb, i);
		ob[i] = tb;
	}

	sort(ALL(a));
	reverse(ALL(a));
	sort(ALL(b));
	reverse(ALL(b));

	ta = a[0].first;
	ti = a[0].second;
	tb = ob[ti];
	bool is_ab = false;
	ll now = 0;
	rep(i, n) {
		if (b[i].first > ta) {
			//武器iのaより強いbが存在するので使う
			if (b[i].second != ti) {
				h -= b[i].first;
				ans++;
				if (h <= 0) {
					break;
				}
			}
			else {
				h -= b[i].first;
				ans++;
				is_ab = true;
				if (h <= 0) {
					break;
				}
			}
		}
		else {
			break;
		}
	}

	ll val;
	if (h > 0) {
		val = h / ta;
		ans += val;
		if (h - ta * val > 0) {
			ans++;
		}
	}

	cout << ans << "\n";
}

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

	solve_abc();

	return 0;
}

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

int main(){
  int n,l;
  cin>>n>>l;
  int wa=0;
  bool zero=false;
  int saishou=INT_MAX;
  int saidai=-1*INT_MAX;
  for(int i=l;i<l+n;i++){
    if(i==0)zero=true;
    if(i<0)saidai=max(saidai,i);
    if(i>0)saishou=min(saishou,i);
    wa+=i;
  }
  if(zero==true){
    cout<<wa<<endl;
    return 0;
  }
  if (l+n-1<0)cout<<wa-saidai<<endl;
  else cout<<wa-saishou<<endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector <vector <pair<int, int> > > ar(n);
	for (int i = 0; i < m; ++i) {
		int l, r, d;
		cin >> l >> r >> d;
		l--;
		r--;
		ar[l].push_back({r, d});
		ar[r].push_back({l, -d});
	}
	vector <bool> used(n, false);
	vector <int> pos(n, 0);
	vector <int> q(n);
	for (int i = 0; i < n; ++i) {
		used[i] = true;
		q[0] = i;
		int beg = 0;
		int end = 1;
		while (beg < end) {
			int cur = q[beg++];
			int p = pos[cur];
			for (int i = 0; i < ar[cur].size(); ++i) {
				int to = ar[cur][i].first;
				int d = ar[cur][i].second;
				if (used[to]) {
					if (p + d != pos[to]) {
						cout << "No" << endl;
						return 0;
					}
					continue;
				}
				pos[to] = p + d;
				used[to] = true;
				q[end++] = to;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 9600
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var NMaMb = Console.ReadLine().SplittedStringToInt32List();
        var N = NMaMb[0];
        var Ma = NMaMb[1];
        var Mb = NMaMb[2];
        var ls = new List<ABC>();
        for (int i = 0; i < N; i++)
        {
            var abc = Console.ReadLine().SplittedStringToInt32List();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];
            var abc2 = new ABC() { A = a, B = b, C = c };
            ls.Add(abc2);
        }
        var dp = new int[50, 500, 500];
        for (int i = 0; i < 50; i++)
        {
            for (int j = 0;j < 500; j++)
            {
                for (int k = 0; k < 500; k++)
                {
                    dp[i, j, k] = INF;
                }
            }
        }
        dp[0, 0, 0] = 0;
        for (int i = 0; i < N; i++)
        {
            var item = ls[i];
            for (int ma = 0; ma < 500; ma++)
            {
                for (int mb = 0; mb < 500; mb++)
                {
                    if (ma - item.A < 0 || mb - item.B < 0)
                    {
                        dp[i + 1, ma, mb] = dp[i, ma, mb];
                    }
                    else
                    {
                        dp[i + 1, ma, mb] = Math.Min(dp[i, ma, mb],dp[i,ma - item.A,mb - item.B] + item.C);
                    }
                }
            }
        }
        var numsss = 500 / Math.Max(Ma, Mb);
        var mins = INF;
        for (int i = 1; i <= numsss; i++)
        {
            try
            {
                var num = dp[N, Ma * i, Mb * i];
                mins = Math.Min(mins, num);
            }
            catch
            {
                break;
            }

        }
        Console.WriteLine(mins == INF ? -1 : mins);

        Console.ReadLine();
    }

    class ABC
    {
        public int A;
        public int B;
        public int C;
    }


    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();

    public const int INF = int.MaxValue / 2;
    #endregion
}


Measured memory_bytes: 59872
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

ll N, A, B, H[100000];

bool check(int n) {
    ll rest = n;
    REP(i, N) {
        if (H[i] - (B * n) > 0)
            rest -= (H[i] - (B * n) + A - B - 1) / (A - B);
    }
    return rest >= 0;
}

int main() {
    cin >> N >> A >> B;
    REP(i, N) cin >> H[i];

    int ng = 0, ok = 1e9;
    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        if (check(mid)) ok = mid;
        else            ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    string T;//PD?D??P PDPDPDP
    cin >> T;
    ll s = T.size();
    for (int i = 0; i < s; i++) {
        if(T[i] == '?')T[i] = 'D';
    }
    cout << T << endl;
}

Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
using System.Linq;

static class SumOfIntegers
{
    static void Main()
    {
        Console.In.ReadToEnd()
            .Split( 
                new[] { '\r', '\n' },
                StringSplitOptions.RemoveEmptyEntries )
            .TakeWhile( x => x != "0 0" )
            .Select( x => Array.ConvertAll( x.Split(), int.Parse ) )
            .Select( x => Count( Enumerable.Range( 0, 10 ), x[0], x[1] ) )
            .ToList()
            .ForEach( Console.WriteLine );
    }

    static int Count
    (IEnumerable<int> c, int n, int s)
    {
        return n > 0
            ? n > 1
                ? c.Sum( x => Count( c.SkipWhile( y => y <= x ), n - 1, s - x ) )
                : c.Any( x => x == s ) ? 1 : 0
            : 0;
    }
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n;
    cin >> n;
    vs s(n);
    char c[5] = {'M','A','R','C','H'};

    vll a(5,0);

    rep(i,n){
        cin >> s[i];
        rep(j,5){
            if(s[i][0] == c[j]){
                a[j]++;
                break;
            }
        }
    }

    ll sum = 0;
    rep(i,3){
        REP(j,i+1,4){
            REP(k,j+1,5){
                sum += a[i] * a[j] * a[k];
                //cout << i << " " << j << " " << k  << " " << sum << endl;
            }
        }
    }

    cout << sum << endl;

    //rep(i,5)cout << a[i] << " ";
    //cout << endl;

    return 0;
}

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

#define N 101
#define M 100001

long long ans[N][M];

int main() {
	int n, m;

	cin >> n >> m;

	int w[n], p[n];

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

	for (int i = 0;i <= m;i++) ans[0][i] = 0;

	for (int j = 0;j <= n;j++) ans[j][0] = 0;

	for (int i = 1;i <= n;i++) {

		//cerr << "i: " << i << endl;

		for (int j = 1;j <= m;j++) {
			if (j >= w[i]) {
				ans[i][j] = max(ans[i - 1][j], (ans[i - 1][j - w[i]] + p[i]));
			} else {
				ans[i][j] = ans[i - 1][j];
			}
		} 
	}

	long long out = 0;

	/*for (int i = 0;i <= n;i++) {
		cout << "i: " << i << "      ";
		for (int j = 0;j <= m;j++) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}*/

	for (int i = 1;i <= n;i++) {
		if (ans[i][m] > out) out = ans[i][m];
	}

	cout << out;
}

Measured memory_bytes: 79104
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
 
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <numeric>
#include <time.h>
#include <stack>
#include <bitset>

#define prev asasddlsa
#define rank aljds

#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i++)
 
using namespace std;
 
typedef long long ll;
typedef double dbl;
 
template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}
 
template<class T>   
void print(const T* s, int n){
    for (int i = 0; i < n; i++)
        cout << s[i] << ' ';
    cout << endl;
}

template<class T>
void print(vector<vector<T>> s){
    for (int i = 0; i < s.size(); i++)
        print(s[i]);
}

ll f(ll x, ll n){
    // cout << n % x << ' ' << x << ' ' << (2 * (n / x - 1) + 1) << endl;
    // cout << x << ' ' << n << endl;
    if (n % x == 0)
        return x * (2 * (n / x - 1) + 1);
    return 2 * x * (n / x) + f(n % x, x);
}

int solve(){
    ll n, x;
    cin >> n >> x;
    cout << n + f(x, n - x) << endl;
    return 0;
}

int main(){
    srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed; 
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


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

using namespace std;

inline bool update(int &a, int v) {
    if(a > v) return false;
    a = v;
    return true;
}

// dp[using_upto_g][sale_books]
int dp[10][2001];
int main() {
    int N, K;
    cin >> N >> K;
    vector<vector<int> > books_of(10);
    for(int i = 0; i < N; ++i) {
        int c, g;
        cin >> c >> g;
        --g;
        books_of[g].push_back(c);
    }
    vector<vector<int> > values_of(10);
    for(int i = 0; i < 10; ++i) {
        vector<int> &books = books_of[i];
        vector<int> &values = values_of[i];
        values.push_back(0);
        sort(books.begin(), books.end());
        reverse(books.begin(), books.end());
        const int BN = books.size();
        int acc = 0;
        for(int j = 0; j < BN; ++j) {
            acc += books[j];
            int v = acc;
            if(j > 0) v += j*(j+1);
            values.push_back(v);
        }
    }
    for(int sale = 0; sale < (int)values_of[0].size(); ++sale) {
        dp[0][sale] = values_of[0][sale];
    }
    for(int g = 1; g < 10; ++g) {
        const vector<int> &values = values_of[g];
        const int VN = (int)values.size();
        for(int sale = 0; sale <= K; ++sale) {
            update(dp[g][sale], dp[g-1][sale]);
            for(int prev = 0; prev < sale; ++prev) {
                if(sale-prev < VN) update(dp[g][sale], dp[g-1][prev] + values[sale-prev]);
            }
        }
    }
    cout << dp[9][K] << endl;
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
  int sum = 0;
  int N;
  scanf("%d", &N);
  
  int T[N];
  int i;
  for( i = 0; i < N; i++ ){
    scanf("%d", (T+i) );
  }
  
  int M;
  scanf("%d", &M );
  int P[M];
  int X[M];

  for( i = 0; i < M; i++ ){
    scanf("%d %d", (P+i), (X+i) );
  }
  
  int ans;
  
  for( i = 0; i < N; i++ ){
    sum += T[i];
  }
  
  for( i = 0; i < M; i++ ){
    ans = sum  - T[P[i]-1] + X[i];
    printf("%d\n", ans );
  } 
    
  return 0;
  
}       
        


Measured memory_bytes: 128
def bubble_sort(N ,num1, suit1): # バブルソート(常に安定)
   # print('\nnum1 & suit1 adress')
   # print(id(num1), id(suit1))
   for i in range(N): # 未ソート部分列は一つずつ減っていく
      for j in range(N-1, i, -1): # 一番後ろ(配列的にはN-1番目)から未ソート部分列の先頭(i+1)まで
         if num1[j] < num1[j-1]: # 後ろより前の方が大きかったら交換
            num1[j], num1[j-1] = num1[j-1], num1[j]
            suit1[j], suit1[j-1] = suit1[j-1], suit1[j]
   return join_trump(N, num1, suit1)

def selection_sort(N, num2, suit2): # 選択ソート(常に安定ではない)
   for i in range(N):
      minj = i # とりあえず未ソート部分列の先頭A[i]を一番小さいことにしておく(indexを記憶)
      for j in range(i+1, N): # 未ソート部分列の次から最後まで，より小さいものを探す
         if num2[j] < num2[minj]: # もし小さいのがあれば
            minj = j # 最小値のindexを変更
      if num2[minj] < num2[i]: # 未ソート部分列中の最小値と未ソート部分列の先頭を比較
         num2[i], num2[minj] = num2[minj], num2[i] # 先頭の方が大きければ入れ替える
         suit2[i], suit2[minj] = suit2[minj], suit2[i]
   return join_trump(N, num2, suit2)

def join_trump(N, num3, suit3):
   trump = [''] * N
   for i in range(N):
      trump[i] = suit3[i] + str(num3[i])
   return trump

# Selection Sortが安定かどうかを調べる
def is_stable(x, y, N): # x: bubble_ans, y: selec_ans
   for i in range(N):
      if x[i]!=y[i]:
         print('Not stable')
         return 0
   print('Stable')

N = int(input()) # カード枚数の入力
# card = list(map(int, input().split())) # 「1 2 3…」のような配列入力
trump = input().split() # 今回は文字列入力なのでこれだけでよい
suit1 = [''] * N # トランプの絵札だけ用配列
num1 = [0] * N   # トランプの数字だけ用配列
for i in range(N):           # トランプの絵札を数字を別々にする
   suit1[i] = trump[i][0]     # 絵札だけ
   num1[i] = int(trump[i][1]) # 数字だけ
suit2, num2 = suit1[:], num1[:]
# print('\nnum & suit adress')
# print(id(num1), id(suit1))
# print(id(num2), id(suit2))

# # Bubble Sortによる出力(常に安定)
bubble_ans = bubble_sort(N, num1, suit1)
print(*bubble_ans)
print('Stable')

# # Selection Sortによる出力(安定とは限らない)
selec_ans = selection_sort(N, num2, suit2)
print(*selec_ans)
is_stable(bubble_ans, selec_ans, N)


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

int main() {
    long long N, A, B, goal = 10000000000000;
    cin >> N;
    A = 1;
    while (A * A <= N) {
        if (N % A == 0) {
            B = N / A;
            if (goal > A + B) {
                goal = A + B;
            }
        }
        A++;
    }
    cout << goal - 2 << endl;
}

Measured memory_bytes: 256
# coding: utf-8
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[1])
time = 0
for i in range(N):
    time += L[i][0]
    if time > L[i][1]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 53600
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

N = int(input())
list_A = list(map(int, input().split()))
student = list(range(N))

student.sort(key=lambda i: list_A[i])

ans = ""
for i in range(N):
    ans += str(student[i]+1) + " "
    # print(ans)
ans = ans.strip()

print(ans)


Measured memory_bytes: 20496
N = int(input())
cards = {}
for i in range(N):
  si = input()
  if si in cards:
    cards[si] += 1
  else:
    cards[si] = 1
M = int(input())
for i in range(M):
  ti = input()
  if ti in cards:
    cards[ti] -= 1
  else:
    cards[ti] = -1

answer = 0
for word in cards:
  if answer < cards[word]:
    answer = cards[word]
# print(cards)
print(0 if answer < 0 else answer)


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n,a,b; cin >> n >> a >> b;
  if(a > b || (n == 1 && a != b)) cout << 0 << endl;
  else cout << b*(n-2)-a*(n-2) + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
LL readint(){
	char c=getchar();
	LL ret=0ll;
	bool neg=0;
	while(!(c>='0' && c<='9')){
		if(c=='-') neg=1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		ret=ret*10ll+(LL)(c-'0');
		c=getchar();
	}
	return neg?-ret:ret;
}
void putint(LL v){
	if(v<0){
		putchar('-');
		v=-v;
	}
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10ll) putint(v/10ll);
	putchar('0'+(v%10ll));
}
char readch(){
	char c=getchar();
	while(!(c!=' '&&c!='\n'&&c!='\r')) c=getchar();
	return c;
}
namespace flows{
	struct edge{
		int v,r,f;
		LL c;
		edge(int _v,int _r,int _f,LL _c){
			v=_v;r=_r;f=_f;c=_c;
		}
	};
	vector < edge > adj[10005];
	void adde(int u,int v,int f,LL c){
		adj[u].push_back(edge(v,(int)adj[v].size(),f,c));
		adj[v].push_back(edge(u,(int)adj[u].size()-1,0,-c));
	}
	LL cost,flow,dist[10005];
	int N,prevv[10005],preve[10005];
	bool inq[10005];
	void init(){
		int i;
		N=2505;
		for(i=0;i<=N;++i) adj[i].clear();
		cost=flow=0;
	}
	void spfa(int S){
		queue < int > Q;
		int i;
		Q.push(S);
		memset(inq,0,sizeof(bool)*N);
		inq[S]=1;
		fill(dist,dist+N,(LL)8e18);
		dist[S]=0;
		while(!Q.empty()){
			int cv=Q.front();
			inq[cv]=0;
			Q.pop();
			for(i=0;i<(int)adj[cv].size();++i){
				edge E=adj[cv][i];
				if(E.f && dist[cv]+E.c<dist[E.v]){
					dist[E.v]=dist[cv]+E.c;
					prevv[E.v]=cv;
					preve[E.v]=i;
					if(!inq[E.v]){
						inq[E.v]=1;
						Q.push(E.v);
					}
				}
			}
		}
	}
	void calc(int S,int T,int THR){
		while(flow<THR){
			spfa(S);
			if(dist[T]>(LL)7e18) break;
			++flow;
			int i;
			for(i=T;i!=S;i=prevv[i]){
				int pr=prevv[i],pv=preve[i];
				edge &E=adj[pr][pv];
				cost+=E.c;
				--E.f;
				++(adj[i][E.r].f);
			}
		}
	}
}
int n,m,pct;
char g[55][55];
int main(){
	int i,j,k,l;
	n=readint();m=readint();
	for(i=0;i<n;++i)
		for(j=0;j<m;++j)
			g[i][j]=readch();
	flows::init();
	for(i=0;i<n;++i){
		for(j=0;j<m;++j){
			if(g[i][j]=='o') flows::adde(n*m,i*m+j,1,i+j),++pct;
			if(g[i][j]!='#'){
				flows::adde(i*m+j,n*m+1,1,-i-j);
				if(i+1<n && g[i+1][j]!='#')
					flows::adde(i*m+j,(i+1)*m+j,100,0);
				if(j+1<m && g[i][j+1]!='#')
					flows::adde(i*m+j,i*m+(j+1),100,0);
			}
		}
	}
	flows::calc(n*m,n*m+1,pct);
	printf("%lld\n",-flows::cost);
	return 0;
}


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
#define maxn 200010
#define LL long long 
#define INF 0x3f3f3f3f

int n,m;
string s;
vector<int> G[maxn];
int x[maxn],y[maxn];
bool A[maxn],pei[maxn];
int sam[maxn],dif[maxn];
int u,v;
bool use[maxn];
queue<int> q;

void spfa(){
	while(!q.empty()){
		u=q.front();q.pop();
		for(unsigned int i=0;i<G[u].size();i++){
			v=G[u][i];
			if(use[v]==false) continue;
			if(A[u]==A[v]) sam[v]--;
			else dif[v]--;
			if(sam[v]==false||dif[v]==false){
				use[v]=false;
				q.push(v);
			}
		}
	}
}

int main(){
	//freopen("test.in","r",stdin);
	
	scanf("%d%d",&n,&m);
	cin>>s;
	for(int i=0;i<n;i++)
		if(s[i]=='A') A[i+1]=true;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		if(A[u]==A[v]) sam[u]++,sam[v]++;
		else dif[u]++,dif[v]++;
		x[i]=u;y[i]=v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(sam[i]&&dif[i]) use[i]=true;
		else q.push(i);
	spfa();
	
	for(int i=1;i<=m;i++){
		if(use[x[i]]&&use[y[i]]&&A[x[i]]!=A[y[i]]){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}
// 3 7 8 10 13

Measured memory_bytes: 14340
import math

def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
    
def Koch(n,x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    Koch(n-1, x1,y1, sx,sy)
    Koch(n-1, sx,sy, ux,uy)
    Koch(n-1, ux,uy, tx,ty)
    Koch(n-1, tx,ty, x2,y2)

n=int(input())
Koch(n,0,0,100,0)
plot(100,0)


Measured memory_bytes: 5752
from collections import deque
from copy import deepcopy

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, input().split())
UF = UnionFind(N+1)
direct_connect = [0]*(N+1)
for _ in range(M):
  a, b = map(int, input().split())
  UF.union(a, b)
  direct_connect[a] += 1
  direct_connect[b] += 1
for _ in range(K):
  a, b = map(int, input().split())
  if UF.same(a, b):
    direct_connect[a] += 1
    direct_connect[b] += 1
ans = ""
for i in range(1, N+1):
  ans += "%d "%(UF.size(i)-direct_connect[i]-1)
print(ans)

Measured memory_bytes: 10140
#include <stdio.h>


int main(void){
  
    int w, h, x, y;
    scanf("%d",&w); 
    scanf("%d",&h); 
    scanf("%d",&x); 
    scanf("%d",&y); 
  
	if (y== 1){
		printf("1");
	} 
	else{
		printf("0");
	}
return 0;

}

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

// main.cpp

int main() {
  std::int_fast64_t n;
  std::cin >> n;

  std::vector<std::int_fast64_t> l({2, 1});
  l.reserve(n + 1);
  for (std::int_fast64_t i = 2; i <= n; ++i) {
    l.push_back(l[i - 1] + l[i - 2]);
  }

  std::cout << l[n] << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            
            int n;
            cin >> n;
            int a[n];
            int ans = 0;
            for(int i = 0; i < n; i++)
            {
                cin >> a[i];
                if(i > 0)
                {
                    if(a[i] < a[i-1])
                    {
                        ans += a[i-1] - a[i];
                        a[i] = a[i-1];
                    }
                }
            }
            cout << ans << endl;




           return 0;
        }
          

Measured memory_bytes: 5216
N = int(input())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))

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

time = 0
over_flag = False
for i in range(N):
    A, B = AB[i]
    time += A
    if time > B:
        over_flag = True
        break
if over_flag:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 90456
#include <stdio.h>

int main(void) {
	int a,b,c,i;
	int count;
	scanf("%d %d %d\n", &a, &b, &c);
	for(i=a,count=0;i<=b;i++) {
		if(c%i==0) count ++;
	}
	printf("%d\n", count);
	
	return 0;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t a,b;
  int64_t n;
  cin >> a >> b >> n;
  
  int64_t value = 0;
  int64_t max = 0;

  int64_t x = min(b-1,n);
  max = (int64_t)(a*x/(double)b) - a*(int64_t)(x/(double)b);
  cout << max << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int MAXN = 1e5+7;
#define lop(i,a,b) for(register int i = (a); i <= (b); ++i)
#define dlop(i,a,b) for(register int i = (a); i >= (b); --i)
#define read2(a, b) (read(a), read(b))
#define read3(a, b, c)  (read(a), read(b), read(c))
template<class T> void chmax(T &a, T b) {if (a < b) a = b;}
template<class T> void chmin(T &a, T b) {if (a > b) a = b;}
inline void update(int &x, int y) {x += y; if (x >= mod) x -= mod;}

template<class T> void read(T & x) {
  register int c = getchar(), f = 1; x = 0;
  while(!isdigit(c)) (c=='-')&&(f=-f), c = getchar();
  while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
char goal[105][105], mat[105][105];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int n, m;
int main(void) {
  cin >> n >> m;
  for(int i = 1; i <= n; ++i) scanf("%s", goal[i] + 1);
  for(int i = 1; i <= n; ++i) 
    for(int j = 1; j <= m; ++j)
      if (goal[i][j] == '#') {
        bool flag = 0;
        for(int k = 0; k < 4; ++k) {
          int xx = i + dx[k], yy = j + dy[k];
          if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && goal[xx][yy] == '#') flag = 1;
        }
        if (!flag) return puts("No"), 0;
      }
  return puts("Yes"), 0;
}

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

char s[200010];
stack<int> st;

int main(){
	scanf("%s", s);
	for(int i = 0; s[i]; i++){
		if(s[i] == 'S'){ st.push(1); }
		else{
			if(st.empty() || st.top() != 1) st.push(0); 
			else st.pop();
		}
	}
	printf("%d\n", st.size());
}

Measured memory_bytes: 1280
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc =new Scanner(System.in);
		
		int n=sc.nextInt();
		String s[]=new String[n];
		
		for(int i=0;i<n;i++) {
			s[i]=sc.next();
			char[] c =s[i].toCharArray();
			Arrays.sort(c);
			s[i]=new String(c);
		}
		
		Arrays.sort(s);
		
		long ans =0;
		long count=1;
		
		for(int i=1;i<n;i++){
			if(s[i].equals(s[i-1])) {
				count++;
			}
			else {
				ans+=count*(count-1)/2;
				count=1;
			}
			
		}
		ans+=count*(count-1)/2;
		
        System.out.println(ans);
	}
	
}

	class Data{
		  private int a;
		    private int b;
		    public Data(int a, int b) {
		        this.a = a;
		        this.b = b;
		    }
		    public int getA() {
		        return a;
		    }
		    public int getB() {
		        return b;
		    }
}

	class MyComparator implements Comparator {
		 
	    public int compare(Object obj1, Object obj2) {
	         
	        int num1 = (int)obj1;
	        int num2 = (int)obj2;
	         
	        if(num1 < num2) {
	            return 1;
	        } else if(num1 > num2) {
	            return -1;
	        } else{
	            return 0;
	        }
	    }
	}




Measured memory_bytes: 51612