akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;

int GCD(int a, int b)
{
    return b ? GCD(b, a % b) : a;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    ll res = A[0];
    for (int i = 0; i < N; ++i)
        res = GCD(res, A[i]);
    cout << res << endl;
}

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

struct Card {
  char suit;
  int num;
};

const int N = 36;

void bubble_sort(int n, Card A[]) {
  int flag = 1, sorted = 0;

  while (flag) {
    flag = 0;
    for (int i = n-1; i > sorted; i--) {
      if (A[i-1].num > A[i].num) {
        flag = 1;
        Card tmp = A[i];
        A[i] = A[i-1];
        A[i-1] = tmp;        
      }
    }
  }  
}

void selection_sort(int n, Card A[]) {
  for (int i = 0; i < n; i++) {
    int min_j = i;
    for (int j = i+1; j < n; j++) {
      if (A[j].num < A[min_j].num) min_j = j;
    }
    Card tmp = A[i];
    A[i] = A[min_j];
    A[min_j] = tmp;
  }    
}

void print(int n, Card A[]) {
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << A[i].suit << A[i].num;
  }
  cout << endl;
}

int main() {
  int n, num;
  char suit;  
  Card A1[N], A2[N];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> suit >> num;
    A1[i].suit = A2[i].suit = suit;
    A1[i].num = A2[i].num = num;
  }

  bubble_sort(n, A1);
  selection_sort(n, A2);

  print(n, A1);
  cout << "Stable" << endl;

  print(n, A2);
  int is_same = 1;
  for (int i = 0; i < n; i++) {
    if (A1[i].suit != A2[i].suit || A1[i].num != A2[i].num) is_same = 0;
  }
  if (is_same) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  
  return 0;
}



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


using namespace std;
typedef long long ll;

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

    return (a*b)/gcd(a, b); 
}
int main(){
	ll a,b;
	cin >> a >> b;
	cout << lcm(a,b) << endl;
	
}




Measured memory_bytes: 256
//q062.cpp
//Sat Aug 29 18:58:10 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 1e8
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int d[10][10];

void warshall_floyd(){
	for (int k=0;k<10;k++){
		for (int i=0;i<10;i++){
			for (int j=0;j<10;j++){
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
}

int main(){
	int h,w;
	cin >> h >> w;

	rep(i,10)rep(j,10) cin >> d[i][j];

	warshall_floyd();

	int ans = 0;
	rep(i,h)rep(j,w){
		int x;
		cin >> x;
		if(x==-1)continue;
		ans += d[x][1];
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3620
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1<<60);
int k, x, m, n, h, t, w,y,d = 0; ll sum = 0; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main() {
    cin >> n >> t; vector<int> a(n);
    rep(i, n) cin >> a[i];
    int mi = a[0],mb = 0;
    req(i, n - 1) {
        if (mi > a[i]) mi = a[i];
        else if (mi < a[i]) mb = max(mb, a[i] - mi);
    }mi = a[0];
    req(i, n - 1) {
        if (mi > a[i]) mi = a[i];
        else if (a[i] - mi == mb) sum++;
    }cout << sum << endl;
}

Measured memory_bytes: 640
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};


#define lim 2005

ll dp[lim],a[lim],n,s,ans;

/*
ll F(ll now){
    if(now<0) return 0;
    if(now==0) return 1;
    ll &ret = dp[now];
    if ( ~ret ) return ret;
    ret = 0;
    for(ll i=1;i<=n;i++){
        ret = (ret+F(now-a[i]))%mod;
    }
    return ret;
}
*/
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    sfl(s);
    n = s-2;
    for(ll i=1,j=3;i<=n;i++,j++){
        a[i] = j;
    }
    dp[0] = 1; 
    for(ll i=3;i<=s;i++){
        for(ll j=1;j<=n;j++){
            if( i-a[j]>=0 ){
                dp[i] += dp[i-a[j]];
                dp[i] %= mod;
            }
        }
    }
    pfl(dp[s]);
    return 0;
}

Measured memory_bytes: 3824
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
int dp[1001][1 << 12];
int a[1000], b[1000], c[1000];
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		for (int j = 0; j < b[i]; j++) {
			int k;
			cin >> k;
			c[i] |= (1 << (k - 1));
		}
	}
	fill((int*)dp, (int*)(dp + 1001), 1 << 30);
	dp[0][0] = 0;
	for (int i = 0; i < M; i++) {
		for (int bit = 0; bit < (1 << N); bit++) {
			dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit]);
			dp[i + 1][bit | c[i]] = min(dp[i + 1][bit | c[i]], dp[i][bit] + a[i]);
		}
	}
	if (dp[M][(1 << N) - 1] == 1 << 30) cout << -1 << endl;
	else cout << dp[M][(1 << N) - 1] << endl;
}

Measured memory_bytes: 16256
#include<bits/stdc++.h>
#define int long long
#define PI 3.14159265
int mod = 1000000009;
#define fi(i,start,end) for(int i=0; i<n; i++)
#define pb(x) push_back(x)
#define int long long
#define PI 3.14159265
#define all(v) v.begin(), v.end()
#define endl cout<<"\n" 
#define ll long long
#define dbg(x) cout<<#x<<" "<<x;endl;
#define bye endl;return
using namespace std;
template<typename T>



void debug(vector<T> x){
    for(auto e:x){
        cout<<e<<" ";
    }
    cout<<"\n";
}
/*
1
8 6
1 2 4 1 2 4 1 2

*/

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    int ans = 0;
    for(int i=1; i<n; i++){
        if(v[i] < v[i-1]){
            ans += (v[i-1] - v[i]);
            v[i] = v[i-1];
        }
    }
    cout<<ans;bye;
    

}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //




// --------- library end - //


int main(){

  string A = is();
  ll len = A.size();

  // a~zが何回ずつ出てくるか
  vector<ll> buckets(26, 0);

  for (char c : A){
    buckets[c-'a']++;
  }

  ll ans = 0;
  rep(i, 26){
    ans += buckets[i] * (len - buckets[i]);
  }

  // (ai, aj) (aj, ai) <-をダブルカウントしているので/2する
  ans /= 2;

  // 何も反転しない場合
  ans++;

  cout << ans << endl;

}

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

struct Edge {
	int start;
	int target;
	int weight;
};

class UnionFind {
	std::vector<int> m_nodes;

public:
	UnionFind(size_t size) : m_nodes(size) {
		for (size_t i = 0; i < size; i++)
			m_nodes[i] = i;
	}

	int find(int index) {
		int ret = m_nodes[index];
		if (ret == index) return ret;

		ret = find(ret);
		m_nodes[index] = ret;
		return ret;
	}

	void merge(int x, int y) {
		x = find(x);
		y = find(y);
		m_nodes[x] = y;
	}
};

int main()
{
	int v, e;
	std::cin >> v >> e;

	std::vector<Edge> edges;
	edges.reserve(e);

	for (int i = 0; i < e; i++) {
		Edge edge;
		std::cin >> edge.start >> edge.target >> edge.weight;
		edges.push_back(edge);
	}

	std::sort(edges.begin(), edges.end(), [](Edge& x, Edge& y) { return x.weight < y.weight; });

	UnionFind uf(v);
	uint_least64_t weight = 0;

	for (Edge& edge : edges) {
		int s = uf.find(edge.start);
		int t = uf.find(edge.target);

		if (s != t) {
			uf.merge(s, t);
			weight += edge.weight;
		}
	}

	std::cout << weight << std::endl;

	return 0;
}

Measured memory_bytes: 4072
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>

using namespace std;

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

int main()
{
    int N;
    cin >> N;
    vector<P> th(N);
    vector<int> A(N),B(N);
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());

    if(N%2!=0){
        int min=A[N/2];
        int max=B[N/2];
        cout << max-min+1 << endl;
    }else{
        int min=(A[(N-1)/2]+A[(N/2)]);
        int max=(B[(N-1)/2]+B[(N/2)]);
        cout << max-min+1 << endl;
    }


    return 0;
}

Measured memory_bytes: 6332
import heapq
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
cnt=0
for i in range(m):
    ma=heapq.heappop(a)
    heapq.heappush(a,(-1)*(-ma//2))
print((-1)*sum(a))

Measured memory_bytes: 14276
#include <iostream>
#include <iomanip>

double dp[3003][3003];

int main(){
    int n;
    std::cin >> n;
    dp[0][0] = 1.0;
    for(int i = 1; i <= n; i++){
        double p;
        std::cin >> p;
        for(int j = 0; j <= i; j++){
            dp[i][j] = p*dp[i-1][j-1] + (1.0-p)*dp[i-1][j];
        }
    }
    double ans = 0.0;
    for(int j = (n/2+1); j <= n; j++){
        ans += dp[n][j];
    }
    std::cout << std::setprecision(10) << ans << std::endl;
}


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

string reserve( const string& s ){
	string rs;
	for ( int i = s.size()-1; i >= 0; --i ){
		rs += s[ i ];
	}
	return rs;
}

int main(){
	int cnt = 0;
	string s;

	while ( cin >> s ){
		if ( s == reserve( s ) ) ++cnt;
	}

	cout << cnt << endl;
	return 0;
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

// 分解

// dp[i][j] := i番目までのコインを投げて，表がちょうどj枚になる確率
double dp[3030][3030];

// dp[i][j] = dp[i-1][j-1] * p[j] + dp[i-1][j] * (1-p[j])
// 排反
// i枚目に表が出る確率 dp[i-1][j-1] * p[j]
// i枚目に裏が出る確率 dp[i-1][j] * (1 - p[j])

int main() {
    int N;
    cin >> N;
    vector<double> p(N+1);
    rep(i, N) cin >> p[i+1];

    dp[0][0] = 1.0;
    for (int i=1; i<=N; ++i) {
        for (int j=0; j<=i; ++j) {
            if (j-1 >= 0) dp[i][j] += dp[i-1][j-1] * p[i];
            dp[i][j] += dp[i-1][j] * (1-p[i]);
        }
    }
    double ans = 0;
    for (int i = 0; i <= N; ++i) {
        if (i > N-i) ans += dp[N][i];
    }
    printf("%.15lf\n", ans);
}


Measured memory_bytes: 70272
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	ll x, flag=0,y;
	cin >> x >> y;
	ll a[7] = { 1,3,5,7,8,10,12 };
	ll b[4] = { 4,6,9,11 };
	ll c[1] = {2};
	for (ll i = 0; i < 7; i++) {
		if (a[i] == x) {
			flag = 1;
		}
		else if (flag == 1 && a[i] == y) {
			cout << "Yes" << endl;
			exit(0);
		}
	}
	for (ll i = 0; i < 4; i++) {
		if (b[i] == x) {
			flag = 1;
		}
		else if (flag == 1 && b[i] == y) {
			cout << "Yes" << endl;
			exit(0);
		}
	}
	cout << "No" << endl;
	


}

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


using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define endl        '\n'
#define ll          long long int
#define pb          push_back
#define sz(x)       (int)(x).size()
const ll mod = 1e9 + 7;

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

ll powm(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * 1LL * a) % mod;
b >>= 1LL;
a = (a * 1LL * a) % mod;
}
return res;
}

//--------------------------------------------------------------------------------------------------------------------------//



int main() {
	fast
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
 
int n;cin>>n;
ll w;cin>>w;
ll wa[n+1];
ll va[n+1];
for(int i=1;i<=n;i++)
{cin>>wa[i]>>va[i];}
ll dp[n+1][w+1];
for(int i=0;i<=n;i++)dp[i][0]=0;
for(int i=0;i<=w;i++)dp[0][i]=0;

for(int i=1;i<=n;i++)
{
	for(int j=1;j<=w;j++)
	{
		dp[i][j]=dp[i-1][j];
		if(j-wa[i]>=0)
		{
			dp[i][j]=max(dp[i][j],dp[i-1][j-wa[i]]+va[i]);
		}
	}
}	

cout<<dp[n][w];



	return 0;
}



Measured memory_bytes: 82548
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  rep(i,n){
    string x = s.substr(0,i), y = s.substr(i);
    set<char> st1,st2;
    rep(j,x.size()) st1.insert(x[j]);
    rep(j,y.size()) st2.insert(y[j]);

    int cnt = 0;
    for(auto a : st1) if(st2.count(a)) cnt++;
    chmax(ans,cnt);
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  for(i=2;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    trace(A,n);
  }

  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H, N;
  cin >> H >> N;
  int s = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    s += A[i];
  }
  cout << (s >= H ? "Yes" : "No");
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

class UnionFind {
    vector<int> parent;

    public:
        UnionFind(int size) {
            parent = vector<int>(size, -1);
        }

        int find(int x) {
            if (parent[x] < 0) {
                // parent itself
                return x;
            } else {
                return parent[x] = find(parent[x]);
            }
        }

        bool unite(int x, int y) {
            int rX, rY;
            if ((rX = find(x)) == (rY = find(y))) {
                // already united
                return false;
            }
            if (size(rX) < size(rY)) {
                int tmp = rX;
                rX = rY;
                rY = tmp;
            }
            parent[rX] += parent[rY];
            parent[rY] = rX;
            return true;
        }

        int size(int x) {
            return -parent[find(x)];
        }

        bool is_same(int x, int y) {
            return find(x) == find(y);
        }

        // CAUTION!! : This method is heavy due to scanning linearly.
        int component_count() {
            int c = 0;
            for (const int x : parent) {
                if (x < 0) {
                    c++;
                }
            }
            return c;
        }
};

void solve() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int a, b;
    REP(i, m) {
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    int ans = 0;
    REP(i, n) chmax(ans, uf.size(i));
    cout << ans << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using Pl = pair<ll, int>;

int ave(int x, int y){
    return (x+y)/2;    
}

void Main() {
    int a, b, c;
	cin >> a >> b >> c;

    if(a == b && b == c && c == a){
        if(a%2 == 0) cout << -1 << endl;
        else cout << 0 << endl;
        return;
    }
    
    int cnt = 0;
    while(a%2 == 0 && b%2 == 0 && c%2 == 0){
        int A, B, C;    
        A = ave(b,c);
        B = ave(c,a);
        C = ave(a,b);
        a = A;
        b = B; 
        c = C;
        cnt++;
    }
    
    cout << cnt << endl;
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import copy
import itertools


def solve(h, w, k, stage):
    res = 0
    is_sel_rs = itertools.product((False, True), repeat=h)
    is_sel_cs = itertools.product((False, True), repeat=w)
    for irs, ics in itertools.product(is_sel_rs, is_sel_cs):
        st = copy.deepcopy(stage)
        for r0, ir in enumerate(irs):
            if ir:
                for c in range(w):
                    st[r0][c] = "*"
        for c0, ic in enumerate(ics):
            if ic:
                for r in range(h):
                    st[r][c0] = "*"
        num_blacks = 0
        for r, c in itertools.product(range(h), range(w)):
            if st[r][c] == "#":
                num_blacks += 1
        if num_blacks == k:
            res += 1
    return res


def main():
    h, w, k = (int(z) for z in input().split())
    stage = [list(input()) for _ in range(h)]
    res = solve(h, w, k, stage)
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9352
#include<bits/stdc++.h> // includes INT_MIN
// #include<iostream>


using namespace std;

int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	int dp[n][3];
	for(int i = 0;i < n ;i++)
		cin>>a[i]>>b[i]>>c[i]; // happiness points available on each day 
	// for(int i = 0;i<n;i++)
	// 	cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<'\n';
	for(int i = 0;i < n;i++)
	{
		for(int j = 0;j < 3;j++)
		{
          	dp[i][j] = INT_MIN;
			if(i == 0)		//base case
			{
				if(j == 0)
					dp[i][j] = a[i];
				else if(j == 1)
					dp[i][j] = b[i];
				else 
					dp[i][j] = c[i];
			}
			else
			{
				for(int k = 0;k < 3;k++)		//k means previous activity and j is present activity
				{
					if(j == k) 
						continue;
					else if(j == 0)
						dp[i][j] = max(dp[i][j] , dp[i-1][k] + a[i]);
					else if(j == 1)
						dp[i][j] = max(dp[i][j] , dp[i-1][k] + b[i]);
					else if(j == 2) 
						dp[i][j] = max(dp[i][j] , dp[i-1][k] + c[i]);
				}
			}
		}
	}
	cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]))<<'\n';
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int>V(N);
    rep(i,0,N)cin >> V[i];
    sort(V.rbegin(), V.rend());
    ll sum = 0;
    rep(i,1,N)sum += V[i];
    rep(i,0,N-1){
        if(sum * 2 < V[i]){
            cout << i + 1 << endl;
            return 0;
        }
        //cout << sum << endl;
        sum -= V[i+1];
    }
    cout << N << endl;
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main (String[] args) throws java.lang.Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    long n = Long.parseLong(br.readLine());
	    while(n!=0){
	        ArrayList<Long> syain = new ArrayList<Long>();
	        HashMap<Long,Long> syainMap = new HashMap<Long,Long>();
	        for(int i=0;i<n;i++){
	            String[] lines = br.readLine().split(" ");
	            long syainno = Long.parseLong(lines[0]);
	            long price   = Long.parseLong(lines[1]) * Long.parseLong(lines[2]);
	            if(syainMap.containsKey(syainno)){
	                syainMap.put(syainno,price + syainMap.get(syainno));
	            }else{
	                syain.add(syainno);
	                syainMap.put(syainno,price);
	            }
	        }
	        boolean ans = false;
	        for(long s:syain){
	            if(syainMap.get(s)>=1000000){
	                System.out.println(s);
	                ans = true;
	            }
	        }
	        if(!ans){
	            System.out.println("NA");
	        }
	        n = Long.parseLong(br.readLine());
	    }
	}
}

Measured memory_bytes: 26168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;
pair<ll,ll> p[maxn];
int fa[maxn];
ll num[maxn];
ll ans[maxn];

int find(int i)
{
	return i==fa[i]?i:fa[i]=find(fa[i]);
}
int main()
{
	int n,m;

	cin>>n>>m;
	for (int q=1;q<=n;q++){
		fa[q]=q;
		num[q]=1;
	}

	for (int q=1;q<=m;q++)
	cin>>p[q].first>>p[q].second;


	int f1,f2;
	ll s=1ll*n*(n-1)/2;
	
	for (int q=m;q>=1;q--)
	{
		f1=find(p[q].first);
		f2=find(p[q].second);
		ans[q]=s;
		if (f1!=f2)
		{
			fa[f2]=f1;
			s-=num[f1]*num[f2];
			num[f1]+=num[f2];
			num[f2]=0;
		}	
	}

	for (int q=1;q<=m;q++)
	printf("%lld\n",ans[q]);

	

	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n;cin >> n;
	vector<int> hv;
	for(int i = 0; i < n; i++){
		int h; cin >> h;
		hv.push_back(h);
	}
	int ans = 0;
	int cnt = 0;
	for(int i = 0; i < n-1; i++){
		//cout << hv[i] << "(" << cnt  << ") ";
		if(hv[i] >= hv[i+1]){
			cnt++;
		}else{
			ans = max(cnt, ans);
			cnt = 0;
		}
	}
	cout << max(cnt,ans) << endl;

}

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

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

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

int H, W, K;
vector<vector<char>> masu;

void input()
{
	cin >> H >> W >> K;
    masu = vector<vector<char>> (H, vector<char>(W));
	for (int i=0; i<H; i++)
	{
		string str;
		cin >> str;
		for (int j=0; j<W; j++) 
        {
            masu[i][j] = str[j];
        }
	}
}


void solve()
{
	int row_bits = pow(2, H);
	int col_bits = pow(2, W);
	// 行と列の選び方 <= 2^12
	// それぞれに対して黒マスの数え上げが36マス
	// O(2^12 * 36) 4048*36
	// ビットが立ってなければ赤に塗り潰し
	int ans = 0;
	for (int i=0; i<=row_bits; i++)
	{
		for (int j=0; j<=col_bits; j++)
		{
            // 塗り潰しのパターンに対して黒マスの数え上げ
			int kuro=0;
			for (int k=0; k<H; k++)
			{
				if (i & (1<<k))
					for (int l=0; l<W; l++)
					{
						if ((j & (1<<l)) && masu[k][l]=='#') kuro++; 
					}
			}
            if (kuro==K) ans++;
            //if (kuro==K) cout << i << " " << j << endl;
		}
	}
	cout << ans << endl;
}

int main()
{
	input();
	solve();
}


Measured memory_bytes: 4108
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

const i32 mod = 1000000007;

#define POS(i, j, k) ((((i) & 1) * (n + 1) + (j)) * (n + 1) + (k))

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  i32 *dp = (i32 *) calloc (2 * (n + 1) * (n + 1), sizeof (i32));
  dp[POS(0, n, 0)] = 1;
  for (i32 i = 1; i <= m; ++i) {
    for (i32 j = 1; j <= n; ++j) {
      for (i32 k = 0; k <= n - j; ++k) {
        i64 local = (i64) j * dp[POS(i - 1, j + k, 0)];
        if (k > 0) local += (i64) k * dp[POS(i - 1, j, k)];
        if (n - j - k > 0) local += (i64) (n - j - k) * dp[POS(i - 1, j, k + 1)];
        dp[POS(i, j, k)] = local % mod;
      }
    }
  }
  printf ("%" PRIi32 "\n", dp[POS(m, 1, 0)]);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 896
'use strict'

const main = arg => {
 const time = parseInt(arg.trim().split("\n")[0], 10);
 const h = Math.floor(time / (60 * 60));
 const m = Math.floor(time % (60 * 60) / 60);
 const s = time % 60;

 console.log("%d:%d:%d", h, m, s);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 15344
a,b,c,x,y = map(int, input().split())

if 2*c < a+b:
    if x < y:
        ans = 2*c * x + min(2*c, b) * (y - x)
    else:
        ans = 2*c * y + min(2*c, a) * (x - y)
else:
    ans = a * x + b * y
print(ans)

Measured memory_bytes: 9056
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<assert.h>
#include<cstring>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define mp make_pair
#define pb push_back

////////////////////

int const N = 1e5 +41;
char s[N];
vector<int> q;
int can[N], n;

string str[4] = {"dream", "dreamer", "erase", "eraser"};

void read(){
	scanf("%s",&s);
}

bool canPos(string a, int p){
	if(sz(a) + p > n){
		return false;
	}
	fi(0, sz(a)){
		if(a[i] != s[i+p]){
			return false;
		}
	}
	return true;
}

void solve(){
	n = strlen(s);
	q.pb(0);
	can[0] = 1;
	while(sz(q)){
		int pos = q.back();
		if(pos == n){
				printf("YES\n");
				exit(0);
		}
		q.pop_back();
		fi(0, 4){
			if(canPos(str[i], pos) && !can[pos+sz(str[i])]){
				q.pb(pos + sz(str[i]));
				can[pos + sz(str[i])] = 1;
			}
		}
	}
	
	if(can[n]){
		assert(false);
	}else{
		printf("NO\n");
	}
}

void prepare(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}

int main(){
	prepare();
	read();
	solve();





	return 0;
}

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

using namespace std;

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

    vector<int> candidate;
    bool flag = false;

    for (int k = 0; k*(k-1)/2 <= 100000; k++) {
        candidate.push_back(k*(k-1)/2);
    }

    for (int k = 2; k < candidate.size(); k++) {
        if (N == candidate[k]) {
            flag = true;

            vector<vector<int>> S(k, vector<int>{});
            int num = 1;

            for (int i = 0; i < k-1; i++) {
                for (int j = i+1; j < k; j++) {
                    S[i].push_back(num);
                    S[j].push_back(num);
                    num++;
                }
            }

            cout << "Yes" << endl;
            cout << k << endl;
            for (int i = 0; i < k; i++) {
                cout << S[i].size();

                for (auto j : S[i]) {
                    cout << " " << j;
                }
                cout << endl;
            }
        }
    }

    if (flag == false) {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4512
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	ll K, N;
    cin >> K >> N;
    VL A;
    ll max = 0;
    ll b = 0;
    rep(i,N){
        ll a;
        cin >> a;
        A.PB(a);
        chmax(max,a-b);
        b = a;
    }

    chmax(max,K+A[0]-A[N-1]);
    ll ans = K- max;

    cout << ans << endl; 

    return 0;
}


Measured memory_bytes: 2420
n,k=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
aa.sort()
bb.sort(reverse=True)

low=0
high=max([aa[i]*bb[i] for i in range(n)])
while low<high and abs(high-low)>=2:
    mid=(low+high)//2
    tot=0
    for i in range(n):
        a=mid//bb[i]
        ans=max(aa[i]-a,0)
        tot+=ans
    #print(mid,tot)
    if tot<=k:
        high=mid
    else:
        low=mid+1

for i in range(low,high+1):
    tot=0
    for ii in range(n):
        a=i//bb[ii]
        ans=max(aa[ii]-a,0)
        tot+=ans
   # print(i,tot)
    if tot<=k:
        ans=i
        break
print(ans)


Measured memory_bytes: 119884
#include <cstdio>
#include <cstring>

int k;
double r,l,p,e,t;
double res=0;

void dfs(int v,double x,double y,double per){
	//printf("%d %f %f %f\n",v,x,y,per);
	if(y<t-e || t+e<x)return;
	if(t-e<=x && y<=t+e){
		res+=per;
		return;
	}
	if(v==k){
		double tt=(x+y)/2;
		if(t-e<=tt && tt<=t+e){
			res+=per;
		}
		return;
	}
	double h=(x+y)/2.0;
	if(h>=t){
		dfs(v+1,h,y,per*(p));
		dfs(v+1,x,h,per*(1.0-p));
	}else{
		dfs(v+1,h,y,per*(1.0-p));
		dfs(v+1,x,h,per*(p));
	}
}

int main(void){
	scanf("%d %lf %lf",&k,&r,&l);
	scanf("%lf",&p);
	scanf("%lf",&e);
	scanf("%lf",&t);

	dfs(0,r,l,1.0);
	printf("%.9f\n",res);
	return 0;
}

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

int main(int argc, char *argv[]){
	int count['z' - 'a' + 1];
	for(char c = 'a'; c <= 'z'; c++){
		count[c - 'a'] = 0;
	}
	while(!cin.eof()){
		char c = cin.get();
		if ('A' <= c && c <= 'Z'){
			count[c - 'A']++;
		} else if ('a' <= c && c <= 'z'){
			count[c - 'a']++;
		} 
	}
	for(char c = 'a';c <= 'z'; c++){
		cout << c << " : " << count[c - 'a'] << endl;
	}
}

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

namespace _200523
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            (new Solve())._E();
        }

        string n;
        int len;
        int k;
        long ans = 0;
        void _E()
        {
            n = Ex.Read;
            len = n.Length;
            k = Ex.ReadInt;

            dfs(0, 0, 1, true);

            ans.Cw();
        }

        void dfs(int i, int now_k, long cou, bool b)
        {
            if (now_k > k)
            {
                return;
            }
            if (i >= len)
            {
                if (now_k == k)
                {
                    ans += cou;
                }
                return;
            }

            // 0
            dfs(i + 1, now_k, cou, b && n[i] == '0');

            // 1-9
            if (b)
            {

                int max = n[i] - '0';
                if (max - 1 > 0)
                    dfs(i + 1, now_k + 1, cou * (max - 1), false);
                if (max > 0)
                    dfs(i + 1, now_k + 1, cou, true);
            }
            else
            {
                dfs(i + 1, now_k + 1, cou * 9, false);
            }
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }


        static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); }
        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13140
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		int a,b;
		scanf("%d%d",&a,&b);
		if (a>9 || b>9)
		{
			printf("-1");
			return 0;
		}
		else printf("%lld",(ll)a*b);
		return 0;
}  


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

const int dMax = 100'100;

void solve()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(all(d));
    int left = n / 2 - 1;
    int right = n / 2;
    int ans = 0;
    for (int i = d[left] + 1; i <= d[right]; i++)
        ans++;
    cout << ans << endl;
}

int main()
{
    // srand((unsigned)time(NULL));
    // int t = clock();
    solve();
    // double et = 1.0 * (clock() - t) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int a, b;
  vector< vector<int> > ab(N);
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    ab[i] = {a, b};
  }
  vector<int> ans(N), d(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    for (int j = 0; j < N; j++) {
      int x = abs(ab[j][0] - a) + abs(ab[j][1] - b);
      if (d[j] == -1 || x < d[j]) {
        ans[j] = i + 1;
        d[j] = x;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }
}

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

int main(){
	bool vis=true;
	char ch[300];
	int flag=0;
	cin>>ch;
	int n=strlen(ch);
	for(int i=0;i<n;i++){
		if(ch[i]=='C'&&vis){
			flag=i;
			vis=false;
		}
		if(ch[i]=='F'&&!vis&&flag<i){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
} 

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

string dp[50][500];

struct edge {
	int to;
	string s;
};

struct S {
	int v;
	string s;

	bool operator <(const S& x) const {
		return s > x.s;
	}
};

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

	int n, a, s, g;
	while(cin >> n >> a >> s >> g, n) {
		vector<edge> G[50];
		for(int i = 0; i < a; i++) {
			int x, y;
			string str;
			cin >> x >> y >> str;
			G[x].push_back({ y, str });
		}

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

		priority_queue<S> q;
		q.push({ s, "" });
		dp[s][0] = "";
		while(q.size()) {
			int v = q.top().v;
			string str = q.top().s;
			q.pop();
			if(dp[v][str.size()] < str) continue;

			//cerr << "v : " << v << ", t : " << t << ", str : " << str << endl;
			if(str.size() >= 400) continue;

			for(auto e : G[v]) {
				string ns = str + e.s;
				if(ns.size() >= 400) continue;
				if(dp[e.to][ns.size()] > ns) {
					dp[e.to][ns.size()] = ns;
					q.push({ e.to, ns });
				}
			}
		}

		string ans = "{";
		for(int i = 1; i < 300; i++) {
			if(dp[g][i] == "{") continue;

			bool flag = true;
			for(int j = i + 1; j < 400; j++) {
				if(dp[g][i] > dp[g][j]) {
					flag = false;
					break;
				}
			}
			if(flag) {
				ans = dp[g][i];
				break;
			}
		}
		if(ans == "{") cout << "NO" << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 21832
#include<bits/stdc++.h>
using namespace std;
 
#define w cout
#define e '\n'
#define int long long
#define sz(x) (int)x.size()
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
 
const int N = 2e5 + 10 , mod = 998244353;

signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int k , n; cin >> k >> n;
	int minn = -1e18;
	vector<int> v(n);  cin >> v;
	for(int i = 1 ; i < n ;i ++) {
		minn = max(minn , abs(v[i] - v[i - 1]));
	}
	minn = max(minn , k - v[n - 1] + v[0]);
	w << k - minn; 
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
res = 1

for i in a:
    b[i] += 1

if n % 2 == 1:
    if b[0] != 1:
        print(0)
        exit(0)
    else:
        for i in range(2, n, 2):
            if b[i] != 2:
                print(0)
                exit(0)
            #print(res)
            res = res * 2 % (10**9 + 7)
else:
    for i in range(1, n, 2):
        if b[i] != 2:
            print(0)
            exit(0)
        res = res * 2 % (10 ** 9 + 7)
print(res)

Measured memory_bytes: 14008
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;
typedef unsigned long long ull;

inline int scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
using namespace std;
ll LLsqrt(ll x){
    ll L=0,R=1e9,mid,ans=-1;
    while (L<=R){
        mid=(L+R)>>1;
        if (mid*mid<=x)
            L=mid+1,ans=mid;
        else
            R=mid-1;
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        ll a, b;
        cin >> a >> b;
        if(a == 1 && b == 1)
        {
            cout << 0 << endl;
            continue;
        }
        if(a > b)swap(a, b);
        ll sum = a*b-1;
        ll zong = LLsqrt(sum);
        ll ans = zong*2;
        if(sum/zong == zong)ans--;
        if(a != b)ans--;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int N_MAX = 200000;
int main()
{
  int n,i;
  int a[N_MAX];
  cin >> n;
  for(i=0;i<n;i++)
    cin >> a[i];
  for(i=n-1;i>=0;i-=2)
    cout << a[i] << " ";
  for(i=n%2;i<n-1;i+=2)
    cout << a[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int a[26];

int main()
{
    string w;
    cin >> w;
    rep(i, w.size()) a[w[i] - 'a']++;
    string ans = "Yes";
    rep(i, 26) {
        if(a[i] % 2 == 1) ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class A {
    static void Main(string[] args) {
        string[] Shiri = Console.ReadLine().Split(' ');

        Console.WriteLine(Shiri[0][Shiri[0].Length - 1] == Shiri[1][0] 
                       && Shiri[1][Shiri[1].Length - 1] == Shiri[2][0] ? "YES" : "NO");
    }
}

  

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
	stack<int> s;

    char c[5];
    while(cin >> c){
        int a,b;
        switch(c[0]){
            case '+':
                a = s.top();
                s.pop();
                b = s.top();
                s.pop();
                s.push(a+b);
                break;
            case '-':
                a = s.top();
                s.pop();
                b = s.top();
                s.pop();
                s.push(b-a);
                break;
            case '*':
                a = s.top();
                s.pop();
                b = s.top();
                s.pop();
                s.push(a*b);
                break;
            default:
                int n = stoi(c);
                s.push(n);
                break;
        }
    }
    cout << s.top() << endl;
}


Measured memory_bytes: 3224
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ld = long double;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;

  if (N <= 599) {
    cout << 8 << endl;
  } else if (N <= 799) {
    cout << 7 << endl;
  } else if (N <= 999) {
    cout << 6 << endl;
  } else if (N <= 1199) {
    cout << 5 << endl;
  } else if (N <= 1399) {
    cout << 4 << endl;
  } else if (N <= 1599) {
    cout << 3 << endl;
  } else if (N <= 1799) {
    cout << 2 << endl;
  } else if (N <= 1999) {
    cout << 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3648