akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    REP(i, 1, N) {
        string S = to_string(i);
        if (S.length() % 2 == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
int n,k;
  cin>>n>>k;
  if(n+k==5){
    COUT(1);
  }
  else if(n+k==4){
    COUT(2);
  }
  else COUT(3);
}

Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int n,m,k[500],s[500][500],p[500];
int ans ;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

        cin >> n >> m;
        for(int i=1;i<=m;i++){
                cin >> k[i];
                for(int j=1;j<=k[i];j++){
                        cin >> s[i][j];
                        s[i][j]--;
                }
        }

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

        for(int i=0; i < 1<<n ;i++){
                int cnt = 0;
                for(int l = 1;l<=m;l++){
                        int c = 0;
                        for(int j=1;j<=k[l];j++){
                                if( (1<<(s[l][j]))&i   )c++;
                        }
                        if( c%2 == p[l] )cnt++;

                }
                if(cnt==m)ans++;

        }
        cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) _OUTPUT_IMPL_(__VA_ARGS__)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(string, s);
	for (char c : s)
		cout << (c == ',' ? ' ' : c);
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
static unsigned int inf = 1e9+7;
static int bn = 1e5;
int main(){
    string s;
    cin >> s;
    char s1,s2;
    s1 = s[0];
    for(int i = 1; i<s.length(); i++){
        if(s1 != s[i]){
            s2 = s[i];
            break;
        }
    }
    int s1c = 0;
    int s2c = 0;
    int out = 0;
    for(int i = 0;i<s.length();i++){
        if(s1 == s[i]){
            s1c++;
        }else if(s2 == s[i]){
            s2c++;
        }else{
            out = 1;
            break;
        }
        if(s1c > 2 || s2c > 2){
            out = 1;
            break;
        }
    }
    if(s1c == 2 && s2c == 2 && !out){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  string S;
  cin >> S;
  int end = S.size();
  if (S[end-1] == 's')
    S += "es";
  else
    S += 's';
  cout << S << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,s2;
    cin >> s >> s2;
    s2.erase(s.size());
    if(s==s2){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int A, B, M;
	int a[100000];
	int b[100000];
	int x[100000], y[100000], c[100000];
	int mina = 999999, minb = 999999;
	int ans = 999999;
	scanf("%d %d %d", &A, &B, &M);
	for (int i = 0; i < A; i++) {
		scanf("%d", &a[i]);
		mina = min(mina, a[i]);
	}
	for (int i = 0; i < B; i++) {
		scanf("%d", &b[i]);
		minb = min(minb, b[i]);
	}
	ans = min(ans, mina + minb);
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d", &x[i], &y[i], &c[i]);
		ans = min(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]);
	}
	printf("%d\n", ans);
}


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

int main() {
  int x,a,b;
  cin >> x >> a >> b;
  int A, B;
  if (x>a) A=x-a;
  else A=a-x;
  if (x>b) B=x-b;
  else B=b-x;
  if (A>B) cout << 'B' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 256
def larger(x, y):
	if x > y:
		return x
	return y

def openshop(n):
	lst = []
	m = n
	for i in range(0, 10):
		lst.append(m%2)
		m //= 2
	return lst

N = int(input())
F = []
for i in range(0, N):
	F.append(list(map(int, input().split())))
P = []
for i in range(0, N):
	P.append(list(map(int, input().split())))
max = -5000000000000000
for i in range(1, 1024):
	joisino = openshop(i)
	opencounter = []
	for j in range(0, N):
		opencounter.append(0)
	for j in range(0, 10):
		if joisino[j] == 1:
			for k in range(0, N):
				opencounter[k] += F[k][j]
	sum = 0
	for j in range(0, N):
		sum += P[j][opencounter[j]]
	max = larger(max, sum)
print(max)

Measured memory_bytes: 42716
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, M; cin >> N >> M;
	vector<pair<pair<int,int>,int>> edge(M);
	vector<vector<int>> dis(N + 1, vector<int>(N + 1,1e7));
	for (int i = 0; i < M; i++) {
		int a, b, c; cin >> a >> b >> c;
		edge[i].first.first = a, edge[i].first.second = b;
		edge[i].second = c;
		dis[a][b] = c, dis[b][a] = c;
	}

	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = i; j <= N; j++) {
				if (i == j)dis[i][j] = 0;
				else dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
				dis[j][i] = dis[i][j];
			}
		}
	}

	int cnt = 0;
	for (int i = 0; i < M; i++) {
		int a = edge[i].first.first, b = edge[i].first.second, c = edge[i].second;
		if (dis[a][b] != c) cnt++;
	}
	cout << cnt << endl;


}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }
template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

string s;

void read()
{
	cin >> s;
}

void solve()
{
	bool ok = 0;
	for(int i = 0; i < (int)s.size() - 1; i++)
		if(s[i] == 'A' && s[i + 1] == 'C') ok = 1;

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

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FASTIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N = 200005, M = 1000000007, BIG = 0x3f3f3f3f;

double n;

void Process() {
  double ans = (n / 3.) * (n / 3.) * (n / 3.);
  cout << fixed << setprecision(12) << ans << "\n";
}

int main() {
  FASTIO();

  while (cin >> n) {
    Process();

    if (cin.eof())
      break;
  }

  return 0;
}

Measured memory_bytes: 256
//    ŦĦ€Ř€'Ş ŇØŦĦƗŇǤ ĦØŁĐƗ'Ň Μ€ βΔĆҜ ΔŁŴΔ¥Ş ΔŇĐ ₣ØŘ€V€Ř 😈🤩😇😈💪🤜👊🤛🤟😉🤩:

#include<bits/stdc++.h>

#define mod 1000003
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define B(a) a.begin()
#define E(a) a.end()
#define For(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define M_P make_pair
#define P_B push_back
#define endd "\n"

using namespace std;

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

    string s;cin>>s;
    ll sum=0;

    For(i,0,s.length())
    {
        sum=sum+s[i]-'0';
    }

    if(sum%9==0)
        cout<<"Yes";

    else
        cout<<"No";



    return 0;
}


Measured memory_bytes: 3780
package main
import(
    "fmt"
    "sort"
    )
    
func main(){
    var a,b,c int
    fmt.Scanf("%d%d%d",&a,&b,&c)
    nums := []int{a,b,c}
    sort.Ints(nums)
    fmt.Println(nums[0],nums[1],nums[2])
}


Measured memory_bytes: 1136
#include <bits/stdc++.h>
using namespace std;
int main() {
    int k;
    long long ans;
    cin >> k;
    vector<vector<long long>>l(10);
    l[0] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int c = 9;
    int d = 0;
    int count = 0;
    while (c < k) {
        for (int i = 0; i < l[d].size() && c < k; i++) {
            int a = l[d][i]%10;
            if (a == 0) {
                l[d+1].push_back(10*l[d][i] + a);
                l[d+1].push_back(10*l[d][i] + a + 1);
                c += 2;
            }else if (a == 9){
                l[d+1].push_back(10*l[d][i] + a - 1);
                l[d+1].push_back(10*l[d][i] + a);
                c += 2;
            }else {
                l[d+1].push_back(10*l[d][i] + a - 1);
                l[d+1].push_back(10*l[d][i] + a);
                l[d+1].push_back(10*l[d][i] + a + 1);
                c += 3;
            }
        }
        count += l[d].size();
        d++;
        sort(l[d].begin(), l[d].end());
    }
    
    cout << l[d][k - count - 1] << endl;

}


Measured memory_bytes: 4260
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

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

	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		vector< LL > satis( n );
		vector< vector<LL> > ss( n, vector<LL>() ), es( n, vector<LL>() );

		REP( i, 0, n )
		{
			int m, l;
			cin >> m >> l;

			satis[i] = l;

			ss[i].resize( m );
			es[i].resize( m );

			REP( j, 0, m )
			{
				int s, e;
				cin >> s >> e;

				ss[i][j] = s - 6;
				es[i][j] = e - 6;
			}
		}

		vector<LL> dp( 1U << 16, -1 );
		dp[0] = 0;

		REP( i, 0, 1 << 16 )
		{
			if ( dp[i] < 0 )
			{
				continue;
			}

			REP( j, 0, n )
			{
				int next = i;
				bool ok = true;

				REP( k, 0, ss[j].size() )
				{
					REP( l, ss[j][k], es[j][k] )
					{
						if ( ( next >> l ) & 1 )
						{
							ok = false;
							break;
						}

						next |= ( 1 << l );
					}
				}

				if ( !ok )
				{
					continue;
				}

				dp[ next ] = dp[i] + satis[j];
			}
		}

		cout << *max_element( ALL( dp ) ) << endl;
	}

	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  int b=100000;
  cin>>a;
  for(int i=0;i<a;i++){
    b=b*1.05;
    int c=b;
    if(c%1000!=0){
      b=b/1000;
      b=b*1000;
      b=b+1000;
    }
  }
  cout<<b<<"\n";
}



Measured memory_bytes: 3016
#include <iostream>
#include <queue>

using namespace std;

int main()
{
	int n, m, s, t;
	
	while(cin >> n){
		if(n == 0){
			break;
		}
		
		queue<int> que;
		cin >> m;
		for(int i = 1; i <= 2*n; i++){
			que.push(i);
		}
		
		while(m--){
			cin >> t;
			if(t == 0){
				queue<int> q1;
				for(int i = 1; i <= n; i++){
					q1.push(que.front());
					que.pop();
				}
				for(int i = 1; i <= n; i++){
					que.push(q1.front());
					que.push(que.front());
					que.pop();
					q1.pop();
				}
			} else {
				for(int i = 0; i < t; i++){
					que.push(que.front());
					que.pop();
				}
			}
		}
		
		while(!que.empty()){
			cout << que.front() << endl;
			que.pop();
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MAX_N = 100002;
const ll INF   = 1000000000000001;
struct edge {ll to; ll cost;};
vector<edge> G_yen[MAX_N];
vector<edge> G_snu[MAX_N];
ll d_yen[MAX_N];
ll d_snu[MAX_N];
ll d_tot[MAX_N];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, m, s, t;
    ll u, v, a, b;
    edge e;
	  
    cin >> n >> m >> s >>t;
    for (int i = 0; i < m; i++) {
      cin >> u >> v >> a >> b;

      e.to = v; e.cost = a;
      G_yen[u].push_back(e);
      e.to = u; e.cost = a;
      G_yen[v].push_back(e);

      e.to = v; e.cost = b;
      G_snu[u].push_back(e);
      e.to = u; e.cost = b;
      G_snu[v].push_back(e);
    }
    
    fill(d_yen, d_yen + MAX_N, INF);
    fill(d_snu, d_snu + MAX_N, INF);
    fill(d_tot, d_tot + MAX_N, INF);

    priority_queue<P, vector<P>, greater<P> > pque;
    
    // -------------------
    // Dijkstra - Yen

    d_yen[s] = 0;
    pque.push( P(0, s) );
    
    while (!pque.empty()) {
      P p = pque.top();
      pque.pop();

      ll v = p.second;
      if (d_yen[v] < p.first) continue;

      for(ll i = 0; i < G_yen[v].size(); i++) {
	edge e = G_yen[v][i];

	if (d_yen[e.to] > d_yen[v] + e.cost) {
	  d_yen[e.to] = d_yen[v] + e.cost;
	  pque.push( P(d_yen[e.to], e.to) );
	}
      }
    }
    
    // -------------------
    // Dijkstra - Snuke
    
    d_snu[t] = 0;
    pque.push( P(0, t) );
    
    while (!pque.empty()) {
      P p = pque.top();
      pque.pop();

      ll v = p.second;
      if (d_snu[v] < p.first) continue;

      for(ll i = 0; i < G_snu[v].size(); i++) {
	edge e = G_snu[v][i];

	if (d_snu[e.to] > d_snu[v] + e.cost) {
	  d_snu[e.to] = d_snu[v] + e.cost;
	  pque.push( P(d_snu[e.to], e.to) );
	}
      }
    }
    
    //for(ll i = 1; i <= n; i++) cout << d_yen[i] << endl;
    //for(ll i = 1; i <= n; i++) cout << d_snu[i] << endl;


    // -------------------
    // all cost

    priority_queue<P, vector<P>, greater<P> > pque_tot;
    
    for(ll i = 1; i <= n; i++) {
      d_tot[i] = d_yen[i] + d_snu[i];
      pque_tot.push( P(d_tot[i], i) );
    }

    // -------------------
    for(ll i = 0; i < n; i++) {

      P p = pque_tot.top();
      while (i >= p.second) {
	pque_tot.pop();
	p = pque_tot.top();
      }

      ll ans = 1000000000000000 - p.first;
      cout << ans << endl;
    }
    
    return 0;
}


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

#define ll long long int
#define Mod 1000000007

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m; cin>>n>>m;
    vector<pair<ll,ll>>v(n);
    for(int i=0;i<n;i++)
    {
        int a,b; cin>>a>>b;
        v[i].first=a;
        v[i].second=b;
    }
    sort(v.begin(),v.end());
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        if(v[i].second<m)
        {
            m-=v[i].second;
            sum+=v[i].first*v[i].second;
        }
        else
        {
            sum+=v[i].first*m;
            m=0;
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

main()
{
    int q;
    cin>>q;
    multiset<long long> ms;
    auto it=ms.begin();
    long long ans=0;
    while(q--)
    {
        int type;
        cin>>type;
        if(type==2)
        {
            cout<<*it<<' '<<ans<<endl;
            continue;
        }

        long long a,b;
        cin>>a>>b;
        if(ms.empty())
        {
            ms.insert(a);
            it=ms.begin();
            ans=b;
            continue;
        }

        ms.insert(a);
        ans+=abs(a-*it)+b;
        if(ms.size()%2 == 0 && a<*it)--it;
        else if(ms.size()%2 && *it<=a)
        {
            ans+=*it;
            it++;
            ans-=*it;
        }
    }
    return 0;
}

Measured memory_bytes: 9600
# -*- coding: utf-8 -*-

instr = input()
target = int(input())

# 部分文字列の一覧リストを作成
str_list = []
for i in range(len(instr)):

	for j in range(i, len(instr)+1):
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break

		# 候補となる部分文字列の格納
		if i < j:
			str_list.append(instr[i:j])

		j += 1
	i += 1

# 重複削除
str_list = list(set(str_list))
# 昇順ソート
str_list.sort()

print(str_list[target-1])

Measured memory_bytes: 5068
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

#define MAX_M 2048
#define MAX_N 2048

int dp[MAX_M][MAX_N][2];

int main()
{
    int M, N;
    char ch;
    cin >> M >> N;
    vector<int> S(M), T(N);
    for (int i = 0; i < M; i++) {
        cin >> ch;
        S[i] = (ch == 'I' ? 1 : 0);
    }
    for (int i = 0; i < N; i++) {
        cin >> ch;
        T[i] = (ch == 'I' ? 1 : 0);
    }
    
    memset(dp, -1, sizeof(dp));
    
    for (int i = 0; i < M; i++) {
        if (S[i] == 1) {
            for (int j = 0; j < N; j++) {
                dp[i+1][j][1] = 1;
            }
        }
    }
    
    for (int i = 0; i < N; i++) {
        if (T[i] == 1) {
            for (int j = 0; j < M; j++) {
                dp[j][i+1][1] = 1;
            }
        }
    }
    
    for (int i = 0; i <= M; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k < 2; k++) {
                if (dp[i][j][k] == -1) continue;
                if (S[i] == 1-k) {                    
                    dp[i+1][j][1-k] = max(dp[i+1][j][1-k],
                                          dp[i][j][k] + 1);
                }
                if (T[j] == 1-k) {
                    dp[i][j+1][1-k] = max(dp[i][j+1][1-k],
                                          dp[i][j][k] + 1);
                }                
            }
        }
    }
    
    int res = 0;
    for (int i = 0; i <= M; i++) {
        for (int j = 0; j <= N; j++) {
            res = max(res, dp[i][j][1]);   
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 35896
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<bitset>
#define DEBUG
using namespace std;
int main(){
  int n;
  while(cin >> n && n){
    /*
    int a = 'A';
    cout << (char)(a) << endl;
    */
    char c[n];
    for(int i = 0; i < n; i++){
      cin >> c[i];
    }

    int alf[26] = {0};
    int max = 0, fin = -1;

    for(int i = 0; i < n; i++){
      alf[c[i]-'A']++;
      if(alf[max] < alf[c[i]-'A'])max = c[i]-'A';
      for(int j = 0; j < 26; j++){
	if(j != max && alf[j]+(n-i-1) >= alf[max]){
	  break;
	}
	if(j == 25)fin = i+1;;
      }
      if(fin >= 0){
	break;
      }
    }

    if(fin >= 0){
      cout << (char)(max+'A') << " " << fin << endl;
    }else{
      cout << "TIE" << endl;
    }


  }

  return 0;
}



Measured memory_bytes: 2992
#include <stdio.h>
int main(void){
    int N, T, i, c, c1, t;
    scanf("%d %d", &N, &T);
    c1 = 9999;
    for(i=0; i<N; i++) {
        scanf("%d %d", &c, &t);
        if(t <= T)
        {
            if(c <= c1)
            {
                c1 = c;
            }
        }
    }
    if(c1 == 9999)
    {
        printf("TLE");
    }
    else
    {
        printf("%d", c1);
    }
}

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

using namespace std;

typedef tuple<int, int, int, int> mytuple;

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

  vector<mytuple> vec;
  for (int i = 0; i < N; i++) {
    int S, T, X;
    cin >> S;
    cin >> T;
    cin >> X;
    vec.push_back(make_tuple(S - X, 1, X, i));
    vec.push_back(make_tuple(T - X, 2, X, i));
  }

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

  auto it = vec.begin();

  set<tuple<int, int>> s;
  vector<int> ans;

  vector<int> D(Q);
  for (int i = 0; i < Q; i++) {
    cin >> D[i];
  }

  for (int i = 0; i < Q; i++) {
    while (it != vec.end() && get<0>(*it) <= D[i]) {
      int X = get<2>(*it);
      if (get<1>(*it) == 1) {
        s.insert(make_tuple(X, get<3>(*it)));
      } else {
        s.erase(make_tuple(X, get<3>(*it)));
      }
      it++;
    }

    if (s.empty()) {
      ans.push_back(-1);
    } else {
      ans.push_back(get<0>(*s.begin()));
    }
  }

  for (int a : ans) {
    cout << a << endl;
  }

  return 0;
}


Measured memory_bytes: 20968
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	int cnt;
	char c[55][55];
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++)cin >> c[i][j];
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#'&&c[i][j + 1] != '#'&&c[i + 1][j] != '#')cnt++;

		}
	}
	if (cnt == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
//template<class T = ll> T in(){T x; cin >> x; return (x);}

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

  string s;
  cin >> s;
  if(s.size()<4) {cout << "No" << endl;return 0;}

  if(s.substr(0,4) == "YAKI")cout << "Yes" << endl;
  else cout << "No" << endl;

  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

    static long backToOne ( int a, int m ) {
	int no = 1;
	boolean[] visited = new boolean[m];

	long count = 0;
	while ( true ) {
	    visited[no] = true;
	    no = (no * a) % m;
	    count++;
	    if ( visited[no] ) {
		if( no == 1 ) {
		    return count;
		} else {
		    return -1L;
		}
	    }
	}
    }

    static long gcd( long a, long b ) {
	if ( a < b ) {
	    return gcd ( b, a );
	}
	while ( b != 0 ) {
	    final long tmp = a;
	    a = b;
	    b = tmp % a;	    
	}
	return a;
    }

    static long lcm( long a, long b ) {
	return a * b / gcd( a, b );
    }
    
    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( true ) {
	    final int a1 = stdin.nextInt();
	    final int m1 = stdin.nextInt();
	    final int a2 = stdin.nextInt();
	    final int m2 = stdin.nextInt();
	    final int a3 = stdin.nextInt();
	    final int m3 = stdin.nextInt();
	    if ( a1 == 0 && a2 == 0 && a3 == 0 && m1 == 0 && m2 == 0 && m3 == 0) {
		break;
	    }
	    long a = backToOne( a1, m1 );
	    long b = backToOne( a2, m2 );
	    long c = backToOne( a3, m3 );
	    System.out.println( lcm( lcm( a, b ), c ) );
	}
	
    }
    
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;


int main() {
	int N,M;
	cin >> N >> M;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	vector<vector<int>> g(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		bool ok = true;
		for (int j = 0; j < g[i].size(); j++) {
			if (H[i] <= H[g[i][j]]) {
				ok = false;
			}
		}
		if (ok)ans++;
	}

	cout << ans << endl;

	return 0;
}



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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
typedef long long ll;
const ll inf = 100100100100100;
const int mod = 1000000007;


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

    int n; cin >> n;

    int open[n][10];
    rep(i,0,n) rep(j,0,10) cin >> open[i][j];

    int revenue[n][11];
    rep(i,0,n) rep(j,0,11) cin >> revenue[i][j];

    int ans = inf * -1;

    rep(i,1,pow(2,10)){
        int tmp = 0;
        rep(j,0,n){
            int count = 0;
            rep(k,0,10){
                if(i & (1<<k) && open[j][k] == 1){
                    count++;
                }
            } 
            tmp += revenue[j][count];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    vector<string> s(n); rep(i,n) cin>>s[i];
    set<string> st;
    rep(i,n) {
        st.insert(s[i]);
    }
    ct(st.size());
}


Measured memory_bytes: 25108
n = gets.to_i
min_price = gets.to_i
max_profit = nil
(n - 1).times{
    price = gets.to_i
    max_profit = price - min_price if max_profit.nil? || max_profit < price - min_price
    min_price = price if min_price > price
}
puts max_profit
#??\???????§£??¬???????????????????§£???
#http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D

Measured memory_bytes: 8772
#include <bits/stdc++.h>
#define Rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;

//----------------library in this time--------------------------------
template <typename T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <typename T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <typename T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}
//------------------------main function-------------------------------
void Main(){
    u64 n ,m = 0;
    cin >> n;
    vector<u64> height(n);
    Rep(i, n){
        cin >> height[i];
        if(m >=  height[i] + 2){
            cout << "No" << endl;
            return;
        }
        m = max(height[i], m);
    }
    cout << "Yes" << endl;
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

N = int(input())
P = list(map(int, input().split()))

p_sort = sorted(P)

counter = 0
for x, y in zip(P, p_sort):
    if x != y:
        counter += 1

if counter <= 2:
    print('YES')
else:
    print('NO')

# def main():

# if __name__ == '__main__':
#     main()


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

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

    int n, q, l, r, tmp = 0, sum = 0;
    string s;
    cin >> n >> q >> s;
    int length = s.size();
    vector<int> cnt(q), yes(length);

    for (int i = 0; i < length-1; i++) {
        if ((s[i] == 'A') && (s[i+1] == 'C')) {
            yes[i] = sum;
            yes[++i] = ++sum;
        }
        else yes[i] = sum;
    }
    yes[length-1] = sum;

    while (q--) {
        cin >> l >> r;
        cnt[tmp++] = yes[r-1] - yes[l-1];
    }
    for (int i = 0; i < tmp; i++) cout << cnt[i] << endl;
    return 0;
}


Measured memory_bytes: 1872
class Circle
  attr_accessor :x, :y
  def initialize(x=0.0, y=0.0)
    @x, @y = x.to_f, y.to_f
  end

  def distance(c)
    Math::hypot(c.x-@x, c.y-@y)
  end
  def crosspoints(c)
    d = distance(c)
    a = Math::atan2(c.y-@y, c.x-@x)
    # 1 is radius (of each circle)
    dec = Math::acos((d**2 + 1**2 - 1**2)/(2*d*1))
    [dec, -dec].map do |dec|
      [@x + 1*Math::cos(a-dec), @y + 1*Math::sin(a-dec)]
    end
  end
  def cover?(x, y)
    Math::hypot(x-@x, y-@y) <= 1.0
  end
end

while (n = gets.to_i) != 0
  circles = []
  allCrosspoints = []
  answer = 1

  n.times do |t|
    # omajinai
    x, y = gets.chomp.split(",").map{|n| n.to_f}
    circles[t] = Circle.new(x, y)
    # should use circles.push(Circle.new(x, y))
  end

  circles.each do |c1|
    circles.each do |c2|
      next if c1 == c2
      next if c1.distance(c2) > 2.0
      # p c1, c2

      allCrosspoints.push(c1.crosspoints(c2))
      # p debug, allCrosspoints, "- - -"
    end
  end

  allCrosspoints.flatten(1).each do |x, y|
    # p x, y
    covercnt = 0
    circles.each do |c|
      covercnt += 1 if c.cover?(x, y)
    end
    answer = covercnt if covercnt > answer
  end
  puts answer
end

Measured memory_bytes: 6316
// Vicfred
// https://atcoder.jp/contests/abc164/tasks/abc164_c
// set
import std.conv;
import std.stdio;
import std.container.rbtree;
import std.string;

void main() {
    int n = readln.chomp.to!int;

    auto rbt = redBlackTree!string;

    while(n--) {
        string s = readln.chomp;
        rbt.insert(s);
    }

    rbt.length.writeln;
}



Measured memory_bytes: 15896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>p(n);
    REP(i,n)cin >> p[i];
    double total = 0;
    double answer = 0;
    REP(i,k){
        total += (double)(p[i]*(p[i]+1)/2)/p[i];
    }
    answer = total;
    REP(i,n-k){
        total-=(double)(p[i]*(p[i]+1)/2)/p[i];
        total+=(double)(p[i+k]*(p[i+k]+1)/2)/p[i+k];
        answer = max(answer,total);
    }
    printf("%.8f\n",answer);
    return 0;
}

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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair
#define pb push_back

const int MAXN = 2020;

int ans;
int moze[6][MAXN];
int cnt[3][3];

void solve(const vector <string> &v) {
  memset(moze, 0, sizeof moze);
  REP(i, 3) {
    REP(j, 3) {
      if (i == j) continue;
      int t = cnt[i][j];
      const string &a = v[i];
      const string &b = v[j];
      REP(start, (int)a.size()) {
        moze[t][start] = 1;
        REP(k, (int)b.size()) {
          if (start + k >= (int)a.size()) break;
          if (b[k] != a[start + k] && b[k] != '?' && a[start + k] != '?') {
            moze[t][start] = 0;
            break;
          }
        }
      }
    }
  }

  const string &a = v[0];
  const string &b = v[1];
  const string &c = v[2];
  moze[cnt[0][1]][(int)a.size()] = 1;
  REP(i, (int)a.size() + 1) {
    if (!moze[cnt[0][1]][i]) continue;
    int pre = max((int)a.size(), i + (int)b.size());
    ans = min(ans, pre + (int)c.size());
    REP(j, pre) {
      bool ok = 1;
      if (j < (int)a.size() && !moze[cnt[0][2]][j]) ok = 0;
      if (j >= i && !moze[cnt[1][2]][j - i]) ok = 0;
      if (j < i && j + (int)c.size() > i && !moze[cnt[2][1]][i - j]) ok = 0;
      if (ok) {
        ans = min(ans, max(pre, j + (int)c.size()));
      }
    }
  }
}

int main() {
  cnt[0][1] = 0;
  cnt[0][2] = 1;
  cnt[1][0] = 2;
  cnt[1][2] = 3;
  cnt[2][0] = 4;
  cnt[2][1] = 5;
  vector <string> v;
  REP(i, 3) {
    string s;
    cin >> s;
    v.pb(s);
    ans += (int)s.size();
  }

  sort(all(v));

  do {
    solve(v);
  } while (next_permutation(all(v)));

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



Measured memory_bytes: 384
import itertools
N = int(input())
A = [int(_) for _ in input().split()]


class BinaryIndexedTree:
    """
        Parameters
        ----------
        array : list
            to construct BIT from
        f : func
            binary operation of the abelian group
        fi : func
            inverse mapping of f
            i.e. f(a, b) == c <-> fi(c, a) == b
        e : 
            identity element of the abelian group
        size : int
            limit for array size
    """

    def __init__(self, array, f, fi, e, size):
        self.f = f
        self.fi = fi
        self.e = e
        self.size = size
        self.n = len(array)
        self.dat = [e] * (size + 1)
        self.array = [e] * size
        # self.build(array)

    def build(self, array_):
        for i, v in enumerate(array_):
            self.modify(i, v)

    def modify(self, p, v):
        """
        set value at position p (0-indexed)
        """
        self.add(p, self.fi(v, self.array[p]))
    
    def add(self, p, dv):
        """
        add value at position p (0-indexed)
        """
        fi, dat, f, size, array = self.fi, self.dat, self.f, self.size, self.array
        array[p] = f(array[p], dv)
        p += 1
        while p <= size:
            dat[p] = f(dat[p], dv)
            p += p & -p

    def query(self, l, r):
        """
        result on interval [l, r) (0-indexed)
        """
        return self.fi(self._query(r), self._query(l))

    def _query(self, p):
        dat, f, res = self.dat, self.f, self.e
        while p:
            res = f(res, dat[p])
            p -= p & -p
        return res


e = 0
size = 2 * N + 2
f = lambda a, b: a + b
fi = lambda c, a: c - a
offset = N


def check(x):
    cumsum = list(itertools.accumulate([0] + [1 if a <= x else -1 for a in A]))
    # sum([l:r)) = cumsum[r] - cumsum[l] >= 0
    # ⇔ cumsum[l] <= cumsum[r]
    BIT = BinaryIndexedTree([e] * size, f=f, fi=fi, e=e, size=size)
    count = 0
    for c in cumsum:
        c += offset
        count += BIT._query(c + 1)
        BIT.add(c + 1, 1)
    return 2 * count > N * (N + 1) // 2


A_sorted = [0] + sorted(set(A)) + [10**10]
lb = 0
rb = len(A_sorted) - 1
# check(x) == Trueとなる最小のx
while rb - lb > 1:
    mid = (rb + lb) // 2
    if check(A_sorted[mid]):
        rb = mid
    else:
        lb = mid
print(A_sorted[rb])


Measured memory_bytes: 121756
#include<iostream>
#include<string>
using namespace std;
 
int main() {
	string w,t;
	int n=0;
	cin >> w;

	while(1){
		cin >> t;
		if( t == "END_OF_TEXT" ) break;


		for( int i=0; i<w.size(); i++ ){ // size()??§????´???°???????????????
			w[i] = tolower(w[i]); //?°?????????§??????
		}


		for( int i=0; i<t.size(); i++ ){ // size()??§????´???°???????????????
			t[i] = tolower(t[i]); //?°?????????§??????
		}

		if( w==t ) n++;
	}

	cout << n << "\n";
	return 0;
}

Measured memory_bytes: 1192
import math
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n):
    dis=math.sqrt(l[i][0]**2+l[i][1]**2)
    if dis<=d:
        cnt+=1
print(cnt)

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

using namespace std;

typedef long long int ll;
typedef long double ld;

inline void debugMode() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //#ifndef ONLINE_JUDGE
    //freopen("date.in", "r", stdin);
    //freopen("date.out", "w", stdout);
    //#endif // ONLINE_JUDGE
}
inline void PrintYes() { cout << "YES\n"; }
inline void PrintNo() { cout << "NO\n"; }

const double eps = 1e-7;

int main()
{
	debugMode();

    int n, a, b;

    cin >> n >> a >> b;
    int x = n * a;
    cout << min(x, b);

	return 0;
}


Measured memory_bytes: 384
using static System.Math;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var d = int.Parse(Console.ReadLine().Trim());
            if (d == 0) break;
            var n = int.Parse(Console.ReadLine().Trim());
            var m = int.Parse(Console.ReadLine().Trim());
            var a = new int[n + 1];
            for (int i = 0; i < n - 1; i++) a[i] = int.Parse(Console.ReadLine().Trim());
            a[n] = d;
            Array.Sort(a);
            var ans = 0;
            for (int i = 0; i < m; i++)
            {
                var k = int.Parse(Console.ReadLine().Trim());
                ans += getMIN(a, k);
            }
            Console.WriteLine(ans);
        }
    }
    static int getMIN(int[] a, int k)
    {
        var p = LowerBound(a, k);
        if (p == 0) return 0;
        var w1 = Abs(k - a[p]);
        var w2 = Abs(k - a[p - 1]);
        return Min(w1, w2);
    }
    public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
    {
        int low = start;
        int high = end;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (comparer.Compare(arr[mid], value) < 0)
                low = mid + 1;
            else
                high = mid;
        }
        return low;
    }
    public static int LowerBound<T>(T[] arr, T value) where T : IComparable
    {
        return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
    }
}



Measured memory_bytes: 18076
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 5005;


void solve()
{
    int n, m; cin >> n >> m;
    vector<set<int>> vs(n + 1);
    FOR(i, 0, m)
    {
        int u, v; cin >> u >> v;
        if (vs[u].find(v) != vs[u].end() || vs[v].find(u) != vs[v].end()) continue;
        vs[u].insert(v);
        vs[v].insert(u);
    }
    vector<bool> vis(n + 1);
    int mx = 1;
    FOR(i, 1, n + 1)
    {
        if (vis[i]) continue;
        int c = 1;
        queue<int> q;
        set<int> s;
        q.push(i);
        s.insert(i);
        while (!q.empty())
        {
            int num = q.front();
            q.pop();
            if (vis[num]) continue;
            vis[num] = 1;
            trav(j, vs[num])
            {
                if (vis[j] || s.find(j) != s.end()) continue;
                //vis[j] = 1;
                q.push(j);
                s.insert(j);
                c++;
            }
        }
        mx = max(mx, c);
    }
    cout << mx;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    /*int tc;  cin >> tc;
    while (tc--)*/
        solve();
    return 0;
}







Measured memory_bytes: 35740
/**
 *    Created By:  PeekyBlinders
 **/
#include <bits/stdc++.h>

using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
#define endl '\n'

const int INF = (int) 1e18 + 18;

signed main() {
    fio;
    int h , n; cin >> h >> n;
    vector<int> a(n) , b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    vector<int> dp(h + 1 , INF);
    dp[0] = 0;
    for(int i = 1; i <= h; i++) {
        for(int j = 0; j < n; j++) {
            int new_health = max(0LL , i - a[j]);
            dp[i] = min(dp[i] , dp[new_health] + b[j]);
        }
    }
    
    cout << dp[h] << endl;

    return 0;
}



Measured memory_bytes: 384
from math import log, ceil
n = int(input())
x_array = [int(x) for x in input().split()]
ans = float("inf")
for i in range(1, max(x_array)+1):
    tmp = 0
    for x in x_array:
        tmp += (x-i)**2
    ans = min(ans, tmp)
print(ans)




Measured memory_bytes: 3060