akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwert=b; x<qwert; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;

const int N=2e5+1;
int cnt[N], n, k;

int main(){
	cin >> n >> k;
	fore(x,0,n){int tmp; cin >> tmp; cnt[tmp]++;}
	sort(cnt,cnt+n+1,greater<int>());
	int total=0;
	fore(x,0,k)total+=cnt[x];
	cout << n - total << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


ll a[110];

int main() {
    ll N, x;
    cin >> N >> x;

    rep(i, N)cin >> a[i];
    sort(a, a + N);

    ll cou = 0;
    for (int i = 0; i < N; i++) {


        x -= a[i];
        if (x < 0) {
            break;
        }
        if (x > 0 && i == N - 1) {
            break;
        }
        cou++;
    }
    cout << cou << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
int n,L,a[maxn];

int main()
{
	scanf("%d%d",&n,&L);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int j=1;
	for(int i=2;i<n;i++)
		if(a[i]+a[i+1]>a[j]+a[j+1]) j=i;
	if(a[j]+a[j+1]<L) printf("Impossible\n");
	else {
		printf("Possible\n");
		for(int i=n-1;i>j;i--) printf("%d\n",i);
		for(int i=1;i<=j;i++) printf("%d\n",i);
	}
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a, b) make_pair((a), (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


void smain() {

    ll n, a, b;
    cin >> n >> a >> b;
    if ((a & 1) == (b & 1)) {
        cout << abs(a - b) / 2;
    } else {
        if (a > b)
            swap(a, b);
        ll ret = (b - a - 1) / 2 + a;
        a = n - a + 1;
        b = n - b + 1;
        swap(a, b);
        inmin(ret, (b - a - 1) / 2 + a);
        cout << ret;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, k;
int x[105];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, n) cin >> x[i];
    int ans = 0;
    rep(i, n) {
        if (abs(x[i] - k) <= x[i]) ans += 2 * abs(x[i] - k);
        else ans += 2 * x[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
char t[100001];
int main()
{
    while(scanf("%s",t)!=EOF)
    {
    int y=strlen(t);
    int max1=y;
    int h=0;
    for(int i=0;i<y;i++)
    {
        if(t[i]!=t[i+1])
        {
            int u;
            if(y-i-1>i+1)
                u=y-i-1;
            else
                u=i+1;
            if(max1>u)
                max1=u;
        }
    }
    cout<<max1<<endl;
    }
    return 0;
}


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

	int fs(int W){
      for (int i=1;i<=W+2;i++){
        cout <<"#";
      }
      cout <<endl;
      return 0;
    }
	int main(){
      int H,W;
      string S;
      cin >> H >> W;
      fs(W);
      for (int i=0;i<H;i++){
        cin >> S;
        cout << "#" << S << "#" << endl;
      }
      fs(W);
    }

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

typedef long long ll;

const int MOD = 1e9 + 7;

ll cn[26];
int n;
string s;

int main() {
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		cn[s[i] - 'a']++;
	}
	ll ans = 1;
	for (int i = 0; i < 26; i++) {
		ans = ans * (cn[i] + 1) % MOD;
	}
	ans = (ans - 1) % MOD + MOD;
	cout << ans % MOD << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<map>

using namespace std;

int main(){
        int a,b,c;
        cin >> a >> b >> c;
        if(a == b+c || b == a + c || c == a + b){
                cout << "Yes\n";
        }else{
                cout << "No\n";
        }

        return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
//using Graph = vector<vector<int>>;
//#define pi 3.1415926535

int main()
{
  int n;
  cin >> n;

  for(int i = 0; i < n; i++){
    cout << "ACL";
  }
  
  cout << endl;
  return 0; 
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    int N, M;
    cin >> N >> M;
    vint X(M);
    int ans = 0;
    rep(i, M)
    {
        cin >> X[i];
    }
    sort(all(X));
    vint L(M);
    rep(i, M)
    {
        if (i == 0)
            L[i] = 0;
        else
        {
            L[i] = X[i] - X[i - 1];
        }
    }
    sort(all(L), greater<int>());
    rep(i, min(N-1, M))
    {
        ans += L[i];
    }
    cout << X[M - 1] - X[0] - ans;
    return 0;
}

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

struct Edge { int from, to, cost; };
vector<Edge> edges;

int mincost[11][101];

int main() {
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c) {
        edges.clear();
        int a, b, f;
        for (int i=0; i<m; ++i) {
            cin >> a >> b >> f;
            edges.push_back((Edge){ a, b, f });
            edges.push_back((Edge){ b, a, f });
        }
        for (int i=0; i<11; ++i) {
            for (int j=0; j<101; ++j) {
                mincost[i][j] = 10000000;
            }
        }
        mincost[0][s] = 0;
        for (int k=0; k<n; ++k) {
            for (int i=0; i<(int)edges.size(); ++i) {
                Edge &e = edges[i];
                for (int j=0; j<=c; ++j) {
                    mincost[j][e.to] = min(mincost[j][e.to], mincost[j][e.from] + e.cost);
                    if (j < c) {
                        mincost[j+1][e.to] = min(mincost[j+1][e.to], mincost[j][e.from] + e.cost / 2);
                    }
                }
            }
        }
        int res = 10000000;
        for (int i=0; i<10; ++i) {
            res = min(res, mincost[i][d]);
        }
        cout << res << endl;
    }
    return 0;
}

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    ll N, K;
    cin >> N >> K;
    priority_queue<ll> HP;
    for(ll i=0; i < N; i++){
        ll H;
        cin >> H;
        HP.push(H);
    }
    for(ll i=0; (i < K && HP.size() > 0); i++){
        HP.pop();
    }
    ll ans = 0;
    while(HP.size() > 0){
        ans += HP.top();
        HP.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a; long long b,n; cin >>a >>b >>n;
  int x=floor(a*(b-1)*1.0/b);
  int y=floor(a*n*1.0/b);
  if(n<b) cout <<y;
  else cout <<x;
return 0;}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

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

	int64_t sum = 1;
	vector<int64_t> A(N);
	rep(i, N){
		cin >> A.at(i);
	}
	sort(A.begin(), A.end());
	rep(i, N){
		// int64_t copy = sum;
		if (sum != 0 && !(A.at(i) < LONG_MAX / sum)){
			sum = -1;
			break ;
		}
		sum *= A.at(i);
		if (sum > 1000000000000000000L){
			sum = -1;
			break ;
		}
		// if (sum != 0 && sum / copy != A.at(i)) {
		// 	sum = -1;
		// 	break ;
		// }
	}
	// if (sum > 1000000000000000000) sum = -1;
	cout << sum << endl;
}

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

#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define gsize(x) (int)((x).size())

using namespace std;

const char nl = '\n';

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
 
const ll inf = 1e9;
const ll inf2 = 1e18 + 99LL;
const ld inf3 = 1e14;
const ll mod = 1e9 + 7;
const ld eps = 1e-6;
 
const int logn = 19, maxn = 2e3+5, maxm = 1e5 + 5;

int dp[2001][2001];

int main() {
	FAST;
	int s;
	cin >> s;
	dp[0][0] = 1;
	for (int i = 1; i <= s; i++) {
		vector<ll> p(s + 3);
		for (int j = 0; j < s + 1; j++) {
			p[j + 1] = (p[j] + dp[i - 1][j]) % mod;
		}
		for (int ts = s; ts >= 3; ts--) {
			dp[i][ts] = p[ts - 2];
		}
	}
	ll ans = 0;
	for (int i = 0; i <= s; i++) {
		ans = (ans + dp[i][s]) % mod;
	}
	cout << ans;
}

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

int main() {
    int N;
    cin >> N;
    
    int f = 0, n = N;
    while (n/10 != 0){
        f += n%10;
        n = n/10;
    }
    f += n%10;
    if (N%f == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main(){
  string s[3];
  while(cin >> s[0], s[0] != "0"){
    cin >> s[1] >> s[2];
    for(int x=0;x<3;x++){
      int a=0, b=0;
      for(int i=1;i<(int)s[x].size();i++){
        if(s[x][i] == 'A')a++;
        else b++;
      }
      if(a>b)a++;
      else b++;
      cout << a << " " << b << endl;
    }
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double d,x;
    int n;
    cin >> n >> d >>x;
    double ans=(double)n,a=(n+1.0)/6.0;
    REPN(i,1,n-1){
        ans+=a;
        a=a*(i+1.0)*(i+1.0)/((i+3.0)*i);
    }

    cout << fixed <<setprecision(13) <<ans*(d+(2.0*n-1.0)*x/2.0) << endl;

    return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for _ in range(N):
    a = list(map(int, input().split()))
    A.append(a)
    
count = 0
for i in range(N):
    ans = C
    for j in range(M):
        ans += A[i][j]*B[j]
    if ans > 0:
        count += 1
        
print(count)

Measured memory_bytes: 3064
eval'H,W,A,B='+`tr ' ' ,`
f=r=1,*(1..H+W).map{r=r*_1%M=10**9+7}
p (A...H).sum{|i|(f[h=W+~B]*f[i]*f[B-1]*f[H+~i]).pow(M-2,M)*f[h+i]*f[B+H-i-2]}%M

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 1000000

int main()
{
  int h,w;cin>>h>>w;
  vector<vector<char>> s(h,vector<char>(w));
  int i,j;
  rep(i,h)rep(j,w)cin>>s[i][j];
  vector<vector<int>> dp_modoki(h,vector<int>(w,INF));
  dp_modoki[0][0]=0;
  if(s[0][0]=='#')dp_modoki[0][0]=1;
  rep(i,h)
  {
    rep(j,w)
    {
      if(i==0&&j==0)continue;
      if(i==0)
      {
        if(s[i][j-1]=='.'&&s[i][j]=='#')
        {
          dp_modoki[i][j]=dp_modoki[i][j-1]+1;
        }
        else dp_modoki[i][j]=dp_modoki[i][j-1];
      }
      else if(j==0)
      {
        if(s[i-1][j]=='.'&&s[i][j]=='#')
        {
          dp_modoki[i][j]=dp_modoki[i-1][j]+1;
        }
        else dp_modoki[i][j]=dp_modoki[i-1][j];
      }
      else
      {
        int down=dp_modoki[i-1][j];
        int right=dp_modoki[i][j-1];
        if(s[i-1][j]=='.'&&s[i][j]=='#')down++;
        if(s[i][j-1]=='.'&&s[i][j]=='#')right++;
        dp_modoki[i][j]=min(down,right);
      }
    }
  }
  cout<<dp_modoki[h-1][w-1]<<endl;
} 


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n;cin>>n;
    vs s(n);
    rep(i,n)cin>>s[i];
    map<char,ll> mp;
    rep(i,n){
        char c = s[i][0];
        mp[c]++;
    }
    ll res = 0;
    ll a[5] = {mp['M'],mp['A'],mp['R'],mp['C'],mp['H']};
    rep(i,5) exrep(j,i+1,5) exrep(k,j+1,5) res += a[i]*a[j]*a[k];
    out(res);
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

struct UnionFind {
	const int V;
	// par[x] := xのroot
	vector<int> par;
	// sz[x] := xを含む集合のサイズ
	vector<int> sz;
	UnionFind(const int V) :
		V(V),
		par(vector<int>(V)),
		sz(vector<int>(V, 1))
		{
			for(int i = 0; i < V; ++i) par[i] = i;
		}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(same(x, y)) return false;
		if(y < x) swap(x, y);
		par[y] = x;
		sz[x] += sz[y];
		return true;
	}
	int root(int x) {
		if(par[x] == x) return x;
		return (par[x] = root(par[x]));
	}
	bool same(int x, int y) {
		return (root(x) == root(y));
	}
	int size(int x) {
		return sz[root(x)];
	}
};

int main() {
	int n, m; cin >> n >> m;
	UnionFind uf(n);
	rep(i,m) {
		int a, b; cin >> a >> b;
		--a, --b;
		uf.unite(a, b);
	}
	int ans = 0;
	rep(i,n) {
		ans = max(ans, uf.size(i));
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4848
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#define fi first
#define sec second
using namespace std;
typedef pair<int,int> P;

int n, m, p, q, r;
int ans;
vector<P> v;
vector<P>::iterator it;

void solve(){
	ans = 0;
	v.clear();
	v.push_back(P(1,n));
	scanf("%d%d%d%d", &m, &p, &q, &r);
	int pst;
	for(int i = 0; i < m; i++){
		int x, y; scanf("%d%d", &x, &y);
		pst = 0;
		int cnt = 0;
		for(it = v.begin(); it != v.end(); it++){
			cnt++;
			pst += (*it).sec-(*it).fi+1;
			if(pst < x) continue;
			if(pst == x){
				x = cnt-1;
				break;
			}
			int in = (*it).sec;
			(*it).sec = (*it).sec-(pst-x);
			v.insert(it+1,P((*it).sec+1,in));
			x = cnt-1;
			break;
		}
		pst = 0;
		cnt = 0;
		/*
		for(int j = 0; j < v.size(); j++){
			printf(" %d %d\n", v[j].fi, v[j].sec);
		}
		*/
		for(it = v.begin(); it != v.end(); it++){
			cnt++;
			pst += (*it).sec-(*it).fi+1;
			if(pst < y) continue;
			if(pst == y){
				y = cnt-1;
				break;
			}
			int in = (*it).sec;
			(*it).sec = (*it).sec-(pst-y);
			v.insert(it+1,P((*it).sec+1,in));
			y = cnt-1;
			break;
		}
		vector<P> tmp;
		for(int j = y+1; j < v.size(); j++) tmp.push_back(v[j]);
		for(int j = x+1; j <= y; j++) tmp.push_back(v[j]);
		for(int j = 0; j <= x; j++) tmp.push_back(v[j]);
		v = tmp;
		/*
		printf("\n");
		for(int j = 0; j < v.size(); j++){
			printf("%d %d\n", v[j].fi, v[j].sec);
		}
		*/
	}
	/*
	for(int j = 0; j < v.size(); j++){
			printf("%d %d\n", v[j].fi, v[j].sec);
		}*/
	pst = 0;
	for(int i = 0; i < v.size(); i++){
		pst += v[i].sec-v[i].fi+1;
		int s = pst-(v[i].sec-v[i].fi), dif = 0;
		if(v[i].fi > r) continue;
		if(pst < p) continue;
		if(s > q) continue;
		if(s < p) dif = p-s;
		if(pst <= q){
			if(r >= v[i].sec) ans += v[i].sec-v[i].fi+1-dif;
			else ans += r-v[i].fi+1-dif;
		} else{
			if(r >= v[i].fi+q-s) ans += q-s+1-dif;
			else ans += r-v[i].fi+1-dif;
		}
		//printf("%d\n", ans);
	}
	printf("%d\n", ans);
}

int main(){
	while(scanf("%d", &n),n) solve();
}

Measured memory_bytes: 1160
a=[int(input()) for _ in range(5)]
k=int(input())
flag=False
for i in range(5):
	for j in range(i+1,5):
		tmp=abs(a[i]-a[j])
		if tmp > k:
			flag=True
			break
	if flag:
		break
if flag:
	print(":(")
else:
	print("Yay!")

Measured memory_bytes: 9116
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll MAXN = 2e5 + 228;
ll n, k;
vl a;

void ans(ll x) {
    vl b;
    for (ll i = n - x; i < n; ++i) {
        b.pb(a[i]);
        // cout << a[i] << " ";
    }
    if (true) {
        n = sz(b);

        vl last(MAXN * 2, n);
        vl next_same(MAXN * 2);

        for (ll i = n - 1; i >= 0; --i) {
            next_same[i] = last[b[i]];
            last[b[i]] = i;
        }

        ll i = 0;
        while (true) {
            while (i < n && next_same[i] < n) {
                i = next_same[i] + 1;
            }
            if (i >= n) break;
            cout << b[i++] << " ";
        }
    }

    cout << endl;
    exit(0);
}


int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> k;

    vl last(MAXN * 2, n);
    vl next_same(MAXN * 2);

    a = vl(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (ll i = 0; i < n; ++i) {
        a.pb(a[i]);
    }

    for (ll i = 2 * n - 1; i >= 0; --i) {
        next_same[i] = last[a[i]];
        last[a[i]] = i;
    }

    ll l = 0;
    ll i = 0;
    vl kek;
    vl cnt(MAXN);
    while (true) {
        ++l;
        while (i < n && next_same[i] < n) {
            i = next_same[i] + 1;
        }
        if (++cnt[n - i] >= 2) break;
        kek.pb(n - i);
        if (l == k) { ans(n - i); break; }

        i = next_same[i] + 1 - n;

    }

    ll kk = sz(kek);
    ans(kek[(k + kk - 1) % kk]);

    return 0;
}


Measured memory_bytes: 23268
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

i64 safe_sum(const i64& x, const i64& y) {
  if (x == std::numeric_limits<i64>::max()) return x;
  if (y == std::numeric_limits<i64>::max()) return y;
  return x + y;
}

int main() {
  i64 H, W;
  std::cin >> H >> W;
  std::vector<std::string> S;
  tools::read(S, H);

  std::vector<std::vector<std::vector<std::vector<i64>>>> graph(
    H,
    std::vector<std::vector<std::vector<i64>>>(
      W,
      std::vector<std::vector<i64>>(
        H,
        std::vector<i64>(
          W,
          std::numeric_limits<i64>::max()
        )
      )
    )
  );
  for (i64 y = 0; y < H; ++y) {
    for (i64 x = 0; x < W; ++x) {
      graph[y][x][y][x] = 0;
    }
  }
  for (i64 y = 0; y < H; ++y) {
    for (i64 x = 0; x < W; ++x) {
      if (y + 1 < H && S[y][x] == '.' && S[y + 1][x] == '.') {
        graph[y][x][y + 1][x] = 1;
        graph[y + 1][x][y][x] = 1;
      }
      if (x + 1 < W && S[y][x] == '.' && S[y][x + 1] == '.') {
        graph[y][x][y][x + 1] = 1;
        graph[y][x + 1][y][x] = 1;
      }
    }
  }

  for (i64 y3 = 0; y3 < H; ++y3) {
    for (i64 x3 = 0; x3 < W; ++x3) {
      for (i64 y1 = 0; y1 < H; ++y1) {
        for (i64 x1 = 0; x1 < W; ++x1) {
          for (i64 y2 = 0; y2 < H; ++y2) {
            for (i64 x2 = 0; x2 < W; ++x2) {
              graph[y1][x1][y2][x2] = std::min(graph[y1][x1][y2][x2], safe_sum(graph[y1][x1][y3][x3], graph[y3][x3][y2][x2]));
            }
          }
        }
      }
    }
  }

  i64 answer = std::numeric_limits<i64>::min();
  for (i64 y1 = 0; y1 < H; ++y1) {
    for (i64 x1 = 0; x1 < W; ++x1) {
      for (i64 y2 = 0; y2 < H; ++y2) {
        for (i64 x2 = 0; x2 < W; ++x2) {
          if (S[y1][x1] == '.' && S[y2][x2] == '.') {
            answer = std::max(answer, graph[y1][x1][y2][x2]);
          }
        }
      }
    }
  }
  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
int main(void){
 long long int x,i,j,a,b;
  a=100;
  b=0;
  scanf("%lld",&x);
  for(i=1;i<3770;i++){
    a=(long long int)(a*1.01);
    b+=1;
    if(a>=x){
      printf("%lld\n",b);
      break;
    }
  }
  return 0;
}


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

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

#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

template<typename T>
void swap(T*,T*);


int main()
{
    string s;
    cin >> s;
    int N = s.size();
    int count = 0;
    rep(i,N/2)
    {
        if(s[i] != s[N - i - 1])
        {
            count++;
        }
    }
    cout << count <<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define rep(i, n) for(int i=0;i<(int)(n);i++)

int main(void){
	int n;
	char s[200], t[200];
	scanf("%d%s%s",&n ,s ,t);
	rep(i,n){
		printf("%c%c",s[i],t[i]);
	}
	printf("\n");
    return 0; 
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<int> L(N);
  for(int i=0;i<N;++i) cin>>L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  int index;
  for(int i=0;i<N;++i) {
    for(int j=i+1;j<N;++j) {
      index = lower_bound(L.begin()+j, L.end(), L[i]+L[j])-L.begin()-1;
      ans += index-j;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3640
using System;
using System.Linq;

namespace AtCoder20190601
{
	class ProgramB
	{
		static void Main(string[] args)
		{
			string S = Console.ReadLine().Trim();
			B(S);
		}
		static void B(string S)
		{
			int wins = S.ToCharArray().Where(c => c == 'o').Count();
			int maxwins = wins + 15 - S.Length;
			bool good = maxwins >= 8;
			Console.WriteLine(good ? "YES" : "NO");
		}
	}
}

Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

int p[51][51];
int dp[51][51][51];

struct P {
  int a,b,c;
  P(int a, int b, int c) :
    a(a),b(b),c(c) {}
  P() {}
} pre[51][51][51];

int main() {
  int n,d;
  while(cin>>n>>d) {
    REP(i,n) {
      REP(j,d) {
        cin >> p[i][j];
      }
    }
    memset(dp,0x3f,sizeof(dp));
    REP(i,n) {
      dp[d-1][0][i] = p[i][d-1];
      pre[d-1][0][i].a = -1;
    }
    for (int i=d-2; i>=0; --i) {
      REP(j,d+1) {
        REP(k,n) {        
          REP(l,n) {
            if (k==l) {
              if (chmin(dp[i][j][k], dp[i+1][j][l] + p[k][i])) {
                pre[i][j][k] = P(i+1,j,l);
              }
            } else {
              if (j && chmin(dp[i][j][k], dp[i+1][j-1][l] + p[k][i])) {
                pre[i][j][k] = P(i+1,j-1,l);
              } 
            }
          }
        }
      }
    }
    int ans = INF;
    P preini;
    vector<int> ansv;
    REP(j,d+1) {
      REP(k,n) {
        if (chmin(ans,dp[0][j][k]))
          preini = P(d,j,k);
      }
    }
    cout << ans << " " << preini.b << endl;

    REP(j,d+1) {
      REP(k,n) {
        if (ans == dp[0][j][k] && preini.b == j) {
          P cur = P(0,j,k);
          vector<int> v;
          while(cur.a != -1) {
            v.push_back(cur.c);
            cur = pre[cur.a][cur.b][cur.c];
          }
          if (ansv.size() == 0 || v < ansv) {
            ansv = v;
          }
        }
      }
    }
    
    REP(i,ansv.size()) {
      cout << ansv[i]+1 << endl;
    }
  }
}

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

namespace ABC053
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            n = int.Parse(Console.ReadLine());
            if (n < 1200)
                Console.WriteLine("ABC");
            else
                Console.WriteLine("ARC");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

int solve(int n, int x)
{
    int ret = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                if (i + j + k == x) {
                    ret += 1;
                }
            }
        }
    }

    return ret;
}

int main()
{
    while (true) {
        int n, x;
        cin >> n >> x;

        if (!n && !x)
            break;

        cout << solve(n, x) << endl;
    }
}



Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int c=300000;
  char s[c];
  scanf("%s",s);

  int all=0;

  for(int i=0;i<c;i++){
    if(s[i]=='\0'){
      break;
    }
    
    int now=s[i]-'0';
    all+=now;
  }

  if(all%9==0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

void include3(int x, int i) {
    while (x>0) {
        if (x%10==3) {
            cout<<" "<<i;
            return;
        }
        x/=10;
    }
    return;
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    for (int i = 1; i <= n; ++i) {
        int j=i;
        if (j%3==0) {
            cout<<" "<<i;
            continue;
        }
        include3(j,i);
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;

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

    vector<vector<int>> F(110,vector<int>(12));
    vector<vector<int>> P(110,vector<int>(12));

    for(int i=0;i<N;i++){
        for(int j=0;j<10;j++){
            cin >> F[i][j];
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<11;j++){
            cin >> P[i][j];
        }
    }
    int ma=-(1<<30);
    int ct,c;

    for(int i=1;i<(1<<10);i++){
        ct=0;
        for(int j=0;j<N;j++){
            c=0;
            for(int k=0;k<10;k++){
                c+=((i>>k)&1 & (F[j][k]));
            }
            ct+=P[j][c];
        }
        ma=max(ct,ma);
    }
    cout << ma << endl;
}

Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
ll f[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll d, a, n;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> v(n);
    vector<ll> x(n);
    for (ll i = 0; i < n; i++)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());
    for (ll i = 0; i < n; i++)
        x[i] = v[i].first;
    ll s = 0;
    for (ll i = 0; i < n; i++)
    {
        if (i)
            f[i] += f[i - 1];
        v[i].second -= f[i] * a;
        if (v[i].second > 0)
        {
            ll c = (v[i].second - 1) / a + 1;
            s += c;
            f[i] += c;
            ll u = upper_bound(x.begin(), x.end(), x[i] + 2 * d) - x.begin();
            f[u] -= c;
        }
    }
    cout << s;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,H;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>A;
	cout<<(H+A-1)/A<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;


bool prime(int);

int main(){
	int n,k,c=0;
	cin >> n;
	while(n--){
		cin >> k;
		if(prime(k)) c++;
	}
	cout << c << endl;
	return 0;
}

bool prime(int a){
		for(int i=2;i<(int)(sqrt((double)a))+1;i++){
			if(a%i==0) return false;
		}
		return true;
}

Measured memory_bytes: 1164
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007
#define BOX 200000

typedef long long ll;

#define rep(i, s, e) for(unsigned int i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j
#define fix(i) fixed << setprecision(i)
#define so(a) sort(begin(a), end(a))
#define soR(a) sort(begin(a), end(a), greater<ll>())
#define uni(a) a.erase(unique(begin(a), end(a)), end(a))
#define sum(a) accumulate(begin(a), end(a), 0)


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 main() {
    ll R;
    cin >> R;
    cout << R * 2 * M_PI << endl;
    return 0;

}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ub upper_bound
    #define int long long
    #define vbe(sdk) sdk.begin(),sdk.end()
    #define pb push_back
    #define loop(i,a,b) for(int i=a;i<b;++i)
    #define rloop(i,a,b) for(int i=a;i>=b;--i)
    #define mp make_pair
    #define mod 1000000007
    #define endl '\n'
    #define vvll vector<vector<int> >
    #define vll vector<int>
    #define mint map<int,int> 
    #define sz(x) (int)x.size()
    #define sll set<int>
    #define pll pair<int,int>
    #define F first
    #define S second
    #define pi 3.14159265358979323846
    using namespace std;

  double maxvolume(double s) 
{ 
    // finding length 
    double length = s / 3; 
  
    s -= length; 
  
    // finding breadth 
    double breadth = s / 2; 
  
    // finding height 
    double height = s - breadth; 
  
    return length * breadth * height; 
} 
  
    signed main()
    {
        double s;
        cin>>s;
        cout<<fixed<<setprecision(10)<<maxvolume(s)<<"\n";
        return 0;
    }
 
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
#define fil(x) memset(x, 0, sizeof(x))
#define fillb(x) memset(x,false,sizeof(x))
#define fillm(x) memset(x, -1, sizeof(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<n;i++)
#define fof(i,a,b) for(int i=a;i<=b;i++)

int dp[100005];
int a[100005];
int n,k;

int func(int ind)
{
    if(ind==n) return 0;
    int mn = INT_MAX;
    if(dp[ind]!=-1)return dp[ind];
    for(int i=ind+1; i<= min(ind+k, n); i++)
    {
        mn = min(mn, abs(a[ind]-a[i])+func(i));
    }
    return dp[ind] = mn;
}

int main()
{
    fillm(dp);
    cin>>n>>k;
    fof(i,1,n)cin>>a[i];
    cout<<func(1);
    return 0;
}

///Alhamdulillah


Measured memory_bytes: 10536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int Ans = 0;

        if( A + B >= C ) {
            Ans = B + C;
        } else {
            Ans = A + B + 1 + B;
        }

        System.out.println(Ans);
        scan.close();
    }
}

Measured memory_bytes: 25044
#include "bits/stdc++.h"
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        int N = 2 * n - 1;
        vector<int> a(N);
        for (int i = 0; i < N; i ++) scanf("%d", &a[i]);
        int lb = 1, ub = N;
        while (ub - lb > 1) {
                int mid = (lb + ub) / 2;
                vector<int> b(N);
                for (int i = 0; i < N; i ++) b[i] = a[i] >= mid;
                int m = N / 2;
                if (b[m] == b[m + 1] || b[m] == b[m - 1]) {
                        (b[m] ? lb : ub) = mid;
                } else {
                        int left = m, right = m;
                        while (left > 0 && (b[left] ^ b[left - 1]) == 1) left --;
                        while (right < N && (b[right] ^ b[right + 1]) == 1) right ++;
                        if (m - left < right - m) (b[left] ? lb : ub) = mid;
                        else                      (b[right] ? lb : ub) = mid;
                }
        }
        printf("%d\n", lb);
        return 0;
}


Measured memory_bytes: 1808
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n)]
    for i in range(len(s)):
        pt[s[i]-1].append(t[i]-1)
        if not directed:
            pt[t[i]-1].append(s[i]-1)
    return pt

N,M = LI()
H = LI()
A,B = LIR(M,2)

pt = edges_to_pt(A,B,N)

ans = 0
used = [False]*N
for i in range(N):
    flag = True
    if not used[i]:
        for j in pt[i]:
            if H[j] > H[i]:
                used[i] = True
                flag = False
                break
            elif H[j] == H[i]:
                flag = False
                used[j] = True
            else:
                used[j] = True
    if used[i]:
        flag = False
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 111092
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; string s;
    cin >> n >> s;
    map<char, ll> cnt;
    rep(i, n) cnt[s[i]]++;
    ll total = cnt['R'] * cnt['G'] * cnt['B'];

    // 条件に合わない個数を数える
    for(ll i=0; i<n; i++){
        for(ll j=i+1; j<n; j++){
            ll k = 2*j-i;
            if(k > n-1) break;
            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) total--;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define INF 1000000000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {

    int N,M;
    cin >> N>>M;
   /*vector<int>A(N);
    for (int i = 0; i < N; i++) { cin >> A[i]; }*/
    if(N%M==0)cout<<N/M<<endl;
  else cout<<(N/M)+1<<endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define MAX 100000

int partition(int[],int,int);

int A[MAX];

int main(){
  int n,i,j,q;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  q=partition(A,0,n-1);

  for(i=0;i<n-1;i++){
    if(q==i){
      printf("[%d] ",A[i]);
    }
    else printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);

  return 0;
}


int partition(int A[],int p,int r){

  int i,j,x,t;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

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

int main(){
	
	int n; cin>>n;
	vector<int> a(n),pl(n);
	vector<pair<int,int>>mi(n);
	for(int i=0; i<n; i++){
		cin >> a.at(i);
		pl.at(i) = i + a.at(i);
		mi.at(i) = {i - a.at(i),i}; 
	}
	ll sum{};
	
	sort(mi.begin(),mi.end());
	for(int i=0; i<n; i++){
		auto it1 = lower_bound(mi.begin(),mi.end(),make_pair(pl.at(i),i+1));
		auto it2 = lower_bound(mi.begin(),mi.end(),make_pair(pl.at(i)+1,0));
		sum += it2 - it1;
	}
	cout << sum << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N; cin >> N;
	double jpy = 0, btc = 0;

	rep(i, N) {
		double x; cin >> x;
		string u; cin >> u;
		if (u == "JPY") jpy += x;
		else btc += x;
	}

	cout << jpy + 380000 * btc << endl;
}


Measured memory_bytes: 384
def printAns(ans):
    for i in range(len(ans)):
        if i == 0:
            print(ans[i], end="")
        else:
            print(" ", end="")
            print(ans[i], end="")
    print("")

N = int(input())

for l in range(N):
    a,b = [int(i) for i in input().split()]

    ans = []
    if a < b:
        for i in range(a, b+1):
            ans.append(i)
    else: # a > b
        if a <= 5:
            for i in range(a, b-1, -1):
                ans.append(i)
        else:
            if b <= 5:
                for i in range(a, 10):
                    ans.append(i)
                for i in range(5, b-1, -1):
                    ans.append(i)
            else:
                for i in range(a, 10):
                    ans.append(i)
                for i in range(5, 0, -1):
                    ans.append(i)
                for i in range(b+1):
                    ans.append(i)

    printAns(ans)



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

typedef long long int ll;

std::vector<ll> a, p;
  
ll f(int x, ll y) {
  if(x==0) {
    return (y<=0?0:1);
  }
  else if (y <= (1 + a.at(x-1))) {
    return f(x-1, y-1);
  } else {
    return (p.at(x-1)+1+f(x-1, (y-2-a.at(x-1))));
  }
}

int main() {
  int n = 0;
  ll x = 0;
  std::cin >> n >> x;
  
  a.push_back(1);
  p.push_back(1);
  
  for (int i = 0; i < n; i++) {
    a.push_back(3 + 2 * a.at(i));
    p.push_back(1 + 2 * p.at(i));
  }

  std::cout << f(n, x) << std::endl;
  return 0;
}


Measured memory_bytes: 256