akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
struct jb
{
	int a,b;
	friend bool operator <(jb x,jb y)
	{
		return x.a>y.a;
	};
}g[100010];
int n,m,k,l,ans=0,f[100010];
set<int> s;
_Rb_tree_const_iterator<int> p;
int mx(int x,int y)
{
	return x>y?x:y;
}
int mn(int x,int y)
{
	return x<y?x:y;
}
void read(int &x)
{
	char c;
	x=0;
	while(c>'9' || c<'0') c=getchar();
	while(c>='0' && c<='9')
	{
		x=x*10+c-'0';
		 c=getchar();
	}
}
int main()
{
	//freopen("ted.in","r",stdin);
	read(n);
	read(m);
	for(int i=0;i<n;i++)
	{
		read(g[i].b);
		read(g[i].a);
	}
	sort(g,g+n);
	for(int i=0;i<=m;i++) s.insert(i);
	for(int i=0;i<n;i++)
	{
		g[i].b=m-g[i].b;
		p=s.lower_bound(g[i].b);
		if(p!=s.begin() && (*p)>g[i].b) p--;
		if((*p)<=g[i].b)
		{
			ans+=g[i].a;
			s.erase(*p);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=LONG_LONG_MAX;
const int inf=(1<<30)-1;


int main(){
      ll n,x;
      cin>>n>>x;
      ll b[n],l[n],u[n];
      rep0(i,n){
            cin>>b[i]>>l[i]>>u[i];
      }
      ll aoki=0;
      rep0(i,n){
            aoki+=b[i]*l[i];
      }
      vector<P> toribun(n);
      rep0(i,n){
            ll hogee=max({x*u[i]-b[i]*(u[i]-l[i]),x*l[i]});
            toribun[i]={hogee,i};
      }
      sort(toribun.begin(),toribun.end());
      reverse(toribun.begin(),toribun.end());
      ll accumtoribun[n+1];
      fill(accumtoribun,accumtoribun+n+1,0);
      ll mantenNoKosuu=0;
      bool v=false;
      rep0(i,n){
            accumtoribun[i+1]=accumtoribun[i]+toribun[i].first;
            if(accumtoribun[i+1]>=aoki&&!v){
                  mantenNoKosuu=i;
                  v=true;
            }
      }
      //cout<<mantenNoKosuu<<endl;
      ll benkyouzikan=longinf;
      rep0(hanpa,n){
            if(hanpa>=mantenNoKosuu){
                  ll postokuten=accumtoribun[mantenNoKosuu];
                  ll posbenkyouzikan=mantenNoKosuu*x;
                  ll j=toribun[hanpa].second;
                  ll nokori=(aoki-postokuten+b[j]*(u[j]-l[j])+u[j]-1)/u[j];
                  ll nokori2=(aoki-postokuten+l[j]-1)/l[j];
                  nokori=min(nokori,nokori2);
                  //cout<<nokori<<endl;
                  posbenkyouzikan+=nokori;
                  benkyouzikan=min(posbenkyouzikan,benkyouzikan);
            }
            else{
                  ll postokuten=accumtoribun[mantenNoKosuu+1]-toribun[hanpa].first;
                  ll posbenkyouzikan=mantenNoKosuu*x;
                  ll j=toribun[hanpa].second;
                  ll nokori=(aoki-postokuten+b[j]*(u[j]-l[j])+u[j]-1)/u[j];
                  ll nokori2=(aoki-postokuten+l[j]-1)/l[j];
                  nokori=min(nokori,nokori2);
                  posbenkyouzikan+=nokori;
                  //cout<<nokori<<endl;
                  benkyouzikan=min(posbenkyouzikan,benkyouzikan);
            }
      }
      cout<<benkyouzikan<<endl;
      return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value )
      A[k] = L[i++];
    else
      A[k] = R[j++];
  }
}

void mergeSort(struct Card A[], int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ )
    if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, 0, n);
  quickSort(B, 0, n - 1);

  for ( i = 0; i < n; i++ )
    // マージソートとクイックソートの結果を比べる
    if ( A[i].suit != B[i].suit ) stable = 0;

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ )
    printf("%c %d\n", B[i].suit, B[i].value);

  return 0;
}


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

using namespace std;

#define ll       long long

#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)

#define  pfi(x)   printf("%d", x)
#define  pfl(x)   printf("%lld", x)
#define  pfd(x)   printf("%lf", x)
#define  pfc(x)   printf("Case %d: ", x++)
#define  ps       printf(" ")
#define  pn       printf("\n")

#define  pb       push_back
#define  ppb      pop_back
#define  pf       push_front
#define  ppf      pop_front
#define  In       insert
#define  All(a)   a.begin(), a.end()

ll dp[100005][105];
int w[100], v[100];

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n, W, ans = 0;
    sci(n), sci(W);

    int i, j;

    for(i = 1; i <= 100; i++)
    {
    	sci(w[i]), sci(v[i]);
    }

    for(i = 0; i <= 100001; i++)
    	for(j = 0; j <= n; j++)
    		dp[i][j] = INT_MAX * (i? 1: 0);

    for(i = 0; i <= 100001; i++)
    {
    	for(j = 1; j <= n; j++)
    	{
    		if(i - v[j] < 0)
    			dp[i][j] = min(dp[i][j], dp[i][j - 1]);

    		else
    			dp[i][j] = min(dp[i - v[j]][j - 1] + w[j], dp[i][j - 1]);
    		
    		if(dp[i][j] <= W)
    			ans = i;
    	}
    }

    cout << ans;

    return 0;
}

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

long long int henkan(char*);

int main(){
	long long int s,c;
	char* str;
	char* data;
	int i = 0;
	int j = 0;

	data = (char*)calloc(100,sizeof(char));
	str = (char*)calloc(100,sizeof(char));
	fgets(str,100,stdin);

	while( str[i] != ' ' ){
		data[i] = str[i];
		i++;
	}
	data[i] = '\0';
	s = henkan(data);

	i++;
	while( str[i] != '\0' && str[i] != '\n' ){
		data[j] = str[i];
		i++;
		j++;
	}
	data[j] = '\0';
	c = henkan(data);

	c /= 2;

	if( s >= c ){
		printf("%lld\n",c);
	}else{
		c -= s;
		c /= 2;
		printf("%lld\n",s+c);
	}

	return 0;
}

long long int henkan( char* str ){
	int i;
	long long int data = 0;
	long long int keta = 1;
	char* tmp;

	tmp = (char*)calloc(2,sizeof(char));
	tmp[1] = '\0';

	i = strlen(str) - 1;

	while( i >= 0 ){
		tmp[0] = str[i];
		data += (long long int)atoi(tmp)*keta;
		keta *= 10;
		i--;
	}

	return data;
}

Measured memory_bytes: 128
N,M = map(int,input().split())
a = {i:0 for i in range(1,N + 1)}
for i in range(M):
    x,y = map(int,input().split())
    a[x] += 1
    a[y] += 1

ans = list(a.values())
for i in ans:
    print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
int main(){
IOS;
int n,i,count=0;
cin>>n;
for(i=1;i<=n;i++){
    if(((int)log10(i)+1)%2)
        count++;
}
cout<<count<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define pi pair<ll,ll>
#define fr freopen("in.txt","r",stdin)
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define frep(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define f first
#define s second
#define maxn 50
int p[200011];
int N;
vector<int>g[200011];
struct F
{   
    ll A;
    ll count;
    F(){}
    F(ll  _A,ll _count) {
        A = _A;
        count = _count;
    }
    void print() {
        cout << A << " " << count << "\n";
    }
};
ll pw[200011];
deque<pair<int,F> >Q[200011];
const ll mod = 1e9+7;
F operator*(F a, F b) {
    return F(((ll)a.A*(ll)b.A)%mod,(a.count+b.count)%(mod-1));
}
F operator+(F a, F b) {
    F c;
    c.count = max(a.count,b.count);
    a.A*=pw[c.count-a.count];
    a.A%=mod;

    b.A*=pw[c.count-b.count];
    b.A%=mod;
    c.A = a.A+b.A;
    c.A%=mod;

    return c;
}
void combine(int r1,int r2,int node) {
    stack<pair<int,F> >S;
    pair<int,F>c0,c1,c2,d0,d1,d2,e0,e1,e2;

    while(Q[r2].size()) {
        c0 = Q[r2].front();
        Q[r2].pop_front();

        c1 = Q[r2].front();
        Q[r2].pop_front();

        c2 = Q[r2].front();
        Q[r2].pop_front();

        d0 = Q[r1].front();
        Q[r1].pop_front();

        d1 = Q[r1].front();
        Q[r1].pop_front();
        
        d2 = Q[r1].front();
        Q[r1].pop_front();

        if(c2.f!=node) {
            c0.s = c0.s+c2.s;
            c2 = {node,F(0,0)};
        }
        if(d2.f!=node) {
            d0.s = d0.s+d2.s;
            d2 = {node,F(0,0)};
        }

        e0.s = d0.s*c0.s;
        e1.s = c0.s*d1.s + c1.s*d0.s;

        e2.s = (c1.s+c2.s) * (d1.s+d2.s) + c2.s*d0.s+d2.s*c0.s ;

        e0.f = e1.f = e2.f = node;

        S.push(e0);
        S.push(e1); 
        S.push(e2);
    }
    while(!S.empty()) {
        Q[r1].push_front(S.top());
        S.pop();
    }
}
int dfs(int v) {
    int root = v;
    vector<int>childQ;
    for(auto x:g[v]) {
        int r1 = dfs(x);
        childQ.pb(r1);
        if(Q[r1].size() > Q[root].size()) {
            root = r1;
        }
    }
    for(auto x:childQ) {
        if(x!=root) {
            combine(root,x,v);
        }
    }
    Q[root].push_front({v,F(1,1)});
    Q[root].push_front({v,F(1,1)});
    Q[root].push_front({v,F(0,0)});
    return root;
}
ll bpow(ll x,ll n) {
    ll ans =1;
    while(n>0){
        if(n&1) ans*=x;
        x*=x;
        ans%=mod;
        x%=mod;
        n/=2;
    }
    return ans;
}
int main() {
    pw[0] = 1;
    for(int i=1;i<=200000;i++) {
        pw[i] = 2*pw[i-1];
        pw[i] %= mod;
    }
    ll inv2 = bpow(2,mod-2);
    cin >> N;
    for(int i=1;i<=N;i++) {
        cin >> p[i];
        g[p[i]].pb(i);
    }
    int r = dfs(0);
    F sum(0,0);
    while(Q[r].size()) {
        Q[r].pop_front();
        sum=sum+Q[r].front().s;
        Q[r].pop_front();
        Q[r].pop_front();
    }
    ll ans = sum.A * pw[N+1-sum.count];
    ans%=mod;
    cout << ans;
}


Measured memory_bytes: 240116
N = int(input())
A = list(map(int, input().split()))

d = [0]*N
ans = 0
for i in range(N):
    a = A[i]
    l,r = i+a, i-a
    if 0 <= l < N:
        d[l] += 1
    if 0 <= r < N:
        ans += d[r]

print(ans)


Measured memory_bytes: 92808
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)2e5+20
#define INF 2e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
#define int LL
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin>>n; n=24-n+24; cout<<n;
	return cout<<endl,0;
}

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

int main(void) {
	
	string S;
	cin >> S;

	S = S.replace(0, 4, "2018");
	
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 t, a, b, s, c, d;
    std::cin >> t >> s >> a >> b >> c >> d;

    i64 d1 = t * (a - c),
        d2 = t * a + s * b - t * c - s * d,
        dd = llabs(d2 - d1);
    if (d2) {
        if ((d1 < 0 && d2 > 0) || (d1 > 0 && d2 < 0)) {
            d1 = d1 < 0 ? -d1 : d1;
            d2 = d2 < 0 ? -d2 : d2;
            i64 q = (d1 + d2) / d2, r = q * d2 - dd;
            std::cout << 2 * q - 3 + (r == 0 ? 1 : r < 0 ? 2 : 0) << std::endl;
        } else {
            std::cout << 0 << std::endl;
        }
    } else {
        std::cout << "infinity" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N; cin >> N;
  ll max_a = 0;
  ll min_b = 1e18;
  REP(i,N){
    ll a,b; cin >> a >> b;
    if(a>max_a){
      max_a = a;
      min_b = b;
    }
  }
  cout << max_a + min_b << endl;
}

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

class GModInt {
public:
	static int Mod;	int x; GModInt() : x(0) { }GModInt(signed sig) { if ((x = sig % Mod + Mod) >= Mod) x -= Mod; }GModInt(signed long long sig) { if ((x = sig % Mod + Mod) >= Mod) x -= Mod; }int get() const { return x; }	GModInt &operator+=(GModInt that) { if ((x += that.x) >= Mod) x -= Mod; return *this; }	GModInt &operator-=(GModInt that) { if ((x += Mod - that.x) >= Mod) x -= Mod; return *this; }GModInt &operator*=(GModInt that) { x = (unsigned long long)x * that.x % Mod; return *this; }GModInt &operator/=(GModInt that) { return *this *= that.inverse(); }GModInt operator+(GModInt that) const { return GModInt(*this) += that; }GModInt operator-(GModInt that) const { return GModInt(*this) -= that; }GModInt operator*(GModInt that) const { return GModInt(*this) *= that; }GModInt operator/(GModInt that) const { return GModInt(*this) /= that; }GModInt inverse() const { long long a = x, b = Mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }return GModInt(u); }bool operator==(GModInt that) const { return x == that.x; }bool operator!=(GModInt that) const { return x != that.x; }GModInt operator-() const { GModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
int GModInt::Mod = 0;
typedef GModInt mint;
mint operator^(mint a, unsigned long long k) {
	mint r = 1;
	while (k) {
		if (k & 1) r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}


#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)

vector<mint> interpolate(const vector<pair<mint, mint> > &points) {
	int n = points.size();
	vector<mint> dp(n + 1);
	dp[0] = 1;
	FOR(i, 0, n) for (int j = i; j >= 0; j--) {
		dp[j + 1] += dp[j];
		dp[j] *= -points[i].first;
	}
	vector<mint>coef(n);
	FOR(i, 0, n) {
		mint den = 1;
		FOR(j, 0, n) if (i != j)
			den *= points[i].first - points[j].first;
		mint iden = (mint)1 / den, minus = 0;
		for (int j = n - 1; j >= 0; j--) {
			minus = dp[j + 1] + minus * points[i].first;
			coef[j] += minus * iden * points[i].second;
		}
	}
	return coef;
}

int main() {
	{
		int P; cin >> P;
		GModInt::Mod = P;
		vector<int>a(P); {
			FOR(i, 0, P) {
				cin >> a[i];
			}
		}
		vector<pair<mint, mint>>input(P); {
			FOR(i, 0, P) {
				input[i] = { i,a[i] };
			}
		}
		vector<mint> poly = interpolate(input);
		FOR(i, 0, P) {
			cout << poly[i].get() << " \n"[i + 1 == P];
		}

	}
}


Measured memory_bytes: 384
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

using ll = long long;

ll H, W;

int main()
{
  scanf( "%lld%lld", &H, &W );

  if( H == 1 || W == 1 )
    printf( "%lld\n", 1 );
  else
    printf( "%lld\n", (H*W+1)/2 );

  return 0;
}

Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define setpr(xval) cout<<fixed<<setprecision(12)<<xval<<endl;
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,k;
double ans;
void solve()
{
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        double d;string s;
        cin>>d>>s;
        if(s[0]=='J')
            ans+=d;
        else
            ans+=d*380000.0;
    }
    setpr(ans);
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)

	ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	ll n;
	ll a[100100];
	cin>>n>>a[0];
	rep(i,1,n+1)cin>>a[i];
	//if(n==1){
 //		cout<<a[1]-a[0]<<endl;
	//	return 0;
	//}
	sort(a,a+n+1);
	ll b[100010];
	rep(i,0,n){
		b[i]=a[i+1]-a[i];
	}
	ll x=b[0];
	rep(i,1,n){
		x=gcd(x,b[i]);
	}
	cout<<x<<endl;


}

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

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

    int N, M;
    cin >> N;
    int arr[N];
    for(int i=0; i< N; i++){
        cin >> arr[i];
    }

    cin >> M;

    vector<pair<int,int>> vc;
    while(M--){
        int p, x;
        cin >> p >> x;
        vc.push_back(pair<int,int>(p, x));
    }

    for(auto p=vc.begin();p!=vc.end();++p){
        int total = 0;
        for(int i = 0;i<N;i++){
            if(i+1 == p->first){
                total += p->second;
            }else{
                total += arr[i];
            }
        }
        cout << total << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
const ll INF = 1000000007;

int main() {
	int n, k;
	cin >> n >> k;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		double ansi;
		ansi = 1 / (double)n;
		int a = i;
		while (a < k) {
			ansi /= 2;
			a *= 2;
		}
		ans += ansi;
	}
	printf("%.12f\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <cstdio>
#include <set>
using namespace std;
int b[10];
bool good(int n)
{
	while(n)
 	{
		if(b[n%10])
  			return false;
		n/=10;
	}
	return true;
}
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		int val;
		cin>>val;
		b[val]=1;
	}
	while(!good(n))	n++;
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int H,W,K;
    cin >> H >> W >> K;
    vector<string> S(H);
    vector<vector<int>> A(H, vector<int>(W));
    REP(i,H)cin >> S[i];
    string zero = "";
    REP(i,W)zero += ".";
    int last = 1;
    REP(i,H){
        int before = 0;
        REP(j,W){
            if(S[i][j] == '#'){
                for(int l = before;l<=j;l++)A[i][l] = last;
                before = j + 1;
                last++;
            }
        }
        if(before != 0 && before != W){
            for(int l = before;l<=W-1;l++)A[i][l] = last - 1;
        }
    }
    bool ok = 0;
    while(ok == 0){
        ok = 1;
        REP(i,H){
            if(A[i][0] == 0){
                ok = 0;
                if(i != 0&&i != H-1){
                    if(A[i+1][0] != 0){
                        REP(l,W)A[i][l] = A[i+1][l];
                    }
                    if(A[i-1][0] != 0){
                        REP(l,W)A[i][l] = A[i-1][l];
                    }
                }
                if(i == 0){
                    if(A[i+1][0] != 0){
                        REP(l,W)A[i][l] = A[i+1][l];
                    }
                }
                if(i == H-1){
                    if(A[i-1][0] != 0){
                        REP(l,W)A[i][l] = A[i-1][l];
                    }
                }
            }
        }
    }
    REP(i,H)REP(l,W)cout <<A[i][l]<< "\n";
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define mp make_pair
 
const int N = 1e5 + 5;
const int mod = 998244353;
const ll INF = (ll)4e18 + 5;

inline int mul(int a, int b){
    return ((ll)a * b) % mod;
}

inline int add(int a, int b){
    int ans = a + b;
    if(ans >= mod) ans -= mod;
    return ans; 
}

// credits : codeforces :https://codeforces.com/blog/entry/54396
bool isprime(ll n){
    if(n<2) return false;
    for(ll i=2;i*i*i<=n;++i) if(n%i==0) return false;
    for(int it=0;it<1e2;++it){
        ll i = rand()%(n-1)+1;
        if(__gcd(i,n)!=1) return false;
        // if(mpow(i,n-1,n)!=1) return false;
    }
    return true;
}

ll fast_pow(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b){
        if(b&1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return ans;
}

vector<pii> v;
int mx;

int check(int cnt){
    int l1 = v[0].F, r1 = v[0].S, l2 = -1, r2 = 1e9+7;
    for(int j = 1; j < (int)v.size(); j++){
        if(cnt == 0 && j == mx){
            l2 = v[j].F, r2 = v[j].S;
            continue;
        }
        int l_ = max(l1, v[j].F), r_ = min(r1, v[j].S);
        int new_cnt = r_ - l_ + 1;
        if(new_cnt >= cnt) l1 = l_, r1 = r_;
        else l2 = max(l2, v[j].F), r2 = min(r2, v[j].S);
    }
    return (max(0, r1-l1+1) + max(0, r2-l2+1));
}

int foo(int l, int r){
    if(l == r) return check(l);
    int m = (l+r) >> 1;
    int x1 = check(m), x2 = check(m+1);
    if(x1 <= x2) return foo(m+1, r);
    return foo(l, m);
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin >> s;
    int n = s.length();
    ll ans = 0;
    vector<int> suff(n+5, 0), pre(n+5, 0);
    for(int j = n-1; j >= 0; j--){
        if(s[j] == '>') suff[j] = 1 + suff[j+1];
        else suff[j] = 0;
    }
    for(int j = 1; j <= n; j++){
        char ch = s[j-1];
        if(ch == '<') pre[j] = pre[j-1] + 1;
        else pre[j] = 0;
    }
    for(int j = 0; j <= n; j++){
        // cout << j << " : " << pre[j] << " " << suff[j] << endl;
        ans += max(pre[j], suff[j]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4764
#include <stdio.h>
#include <assert.h>
int e,i,n,q,a,v,aa,vv,f[1000000],prev[100000],next[100000],aaa[100000],vvv[100000],head=0;
int main(void){
	scanf("%d %d",&n,&q);
	for(i=0;i<n;i++)f[i]=0; prev[0]=-1;

	for(e=0;e<q;e++){
		scanf("%d %d",&a,&v);a--;
		f[a]+=v;
		prev[e+1]=e;
		next[e]=e+1;
		aaa[e]=a;
		vvv[e]=f[a];

		if(v>0){if(f[a]>vv || (f[a]==vv && a<aa)){vv=f[a];aa=a;}}
		else if(a==aa){
			i=head;aa=0;vv=0;
			while(i<=e){
				if(vvv[i]!=f[aaa[i]]){
					if(prev[i]<0)head=next[i]; else next[prev[i]]=next[i];
					prev[next[i]]=prev[i];
				}
				else{
					if(vvv[i]>vv || (vvv[i]==vv && aaa[i]<aa)){vv=vvv[i];aa=aaa[i];}
				}
				i=next[i];
			}
		}
		printf("%d %d\n",aa+1,vv);
	}
	return 0;
}

Measured memory_bytes: 6064
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int n,m;
inline int read()
{
	char c;
	int res,flag=0;
	while((c=getchar())>'9'||c<'0') if(c=='-')flag=1;
	res=c-'0';
	while((c=getchar())>='0'&&c<='9') res=(res<<3)+(res<<1)+c-'0';
	return flag?-res:res;
}
const int N=280000;
struct cc
{
	ll a,b;
	friend inline bool operator <(const cc &a,const cc &b)
	{
		return a.a<b.a||a.a==b.a&&a.b>b.b;
	}
}p[N];
vector<cc> q[N];
cc b[N];
int tot,bn;
int fir[N],go[N],nex[N],val[N];
inline void add(int x,int y,int z)
{
	nex[++tot]=fir[x];fir[x]=tot;go[tot]=y;val[tot]=z;
	nex[++tot]=fir[y];fir[y]=tot;go[tot]=x;val[tot]=z;
}
ll L,R,Mid,bmin;
bool flag;
inline void dfs(int u,int father,int top)
{
	q[u].clear();
	if(!nex[fir[u]]&&go[fir[u]]==father)
	{
		q[u].push_back((cc){top,top});
		return;
	}
	int e,v,v1=0,v2;
	for(e=fir[u];v=go[e],e;e=nex[e])
	if(v!=father)
	{
		dfs(v,u,val[e]);
		if(!v1) v1=v;
		else v2=v;
	}
	if(q[v1].size()>q[v2].size()) swap(v1,v2);
	vector<cc>::iterator it;
	bn=0;
	ll l,r,mid,p;
	for(it=q[v1].begin();it!=q[v1].end();++it)
	{//ar<=mid-bl 
		l=0;
		r=q[v2].size()-1;
		while(l+1<r)
		{
			mid=l+r>>1;
			if(q[v2][mid].a<=Mid-(*it).b) l=mid;
			else r=mid;
		}
		p=-1;
		if(q[v2][r].a<=Mid-(*it).b) p=r;
		else if(q[v2][l].a<=Mid-(*it).b) p=l;
		if(p==-1) continue;
		++bn;
		b[bn].a=(*it).a;
		b[bn].b=q[v2][p].b;
	}
	for(int i=1;i<=bn;++i)
	{
		b[bn+i].a=b[i].b;
		b[bn+i].b=b[i].a;
	}
	bn<<=1;
	sort(b+1,b+1+bn);
	bmin=(ll)4e10;
	int qn=0;
	for(int i=1;i<=bn;++i)
	if(b[i].b<bmin)
	{
		bmin=b[i].b;
		++qn;
		q[u].push_back((cc){b[i].a+top,b[i].b+top});
	}
}
inline bool check()
{
	dfs(1,1,0);
	return q[1].size();
}
int main()
{
//	freopen("E.in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	int y,z;
	for(int i=2;i<=n;++i)
	{
		y=read();
		z=read();
		add(i,y,z);
	}
	L=0;
	R=(ll)4e10;
	while(L+1<R)
	{
		Mid=L+R>>1;
		if(check()) R=Mid;
		else L=Mid;
	}
	Mid=L;
	if(check()) printf("%lld",L);
	else printf("%lld",R);
//	Mid=15;
//	printf("%d",check());
}


Measured memory_bytes: 36472
N = int(input())
H = list(map(int, input().split()))
count = 0
H.append(0)
for lv in range(1, 101):
    flag = False
    for h in H:
        if flag and h < lv:
            count += 1
            flag = False
        elif not flag and h >= lv:
            flag = True
print(count)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;
    int ans1=0,ans2=0;
    for(int i=0; i<(int)S.length(); i++){
        if(i%2){
            if(S[i]=='0'){
                ans1++;
            }else{
                ans2++;
            }
        }else{
            if(S[i]=='1'){
                ans1++;
            }else{
                ans2++;
            }
        }
    }
    cout << min(ans1,ans2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){

    int n;
    cin >> n;

    cout << n*n*n;

    return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;

  bool b = false;
  int s_begin;

  if (S.size() < T.size()) {
	  cout << "UNRESTORABLE" << endl;
	  return 0;
  }

  for (int i = 0; i < S.size() - T.size() + 1; i++) {
	  if (S.at(i) == T.at(0) || S.at(i) == '?') {
		  for (int j = 0; j < T.size(); j++) {
			if (S.at(i + j) == T.at(j) || S.at(i + j) == '?') {
				if (j == T.size() - 1) {
					b = true;
					s_begin = i;
				} else {
					continue;
				}
			} else {
				break;
			}
	  	  }
  	  } else {
		  continue;
	  }
  }

  string s_out = S;

  if (!b) {
	  s_out = "UNRESTORABLE";
  }
  else {
	  for (int i = 0; i < S.size(); i++) {
		  if (S.at(i) == '?') {
		  	if (i >= s_begin && i < s_begin + T.size()) {
			  	s_out.at(i) = T.at(i - s_begin);
		  	} else {
				s_out.at(i) = 'a';
			}
		  } else {
		  	continue;
	          }		
	  }
  }

  cout << s_out << endl;

  return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,p,sum,aum,z;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&p);
	sum=p*a;
	if(p<c){
		aum=b;
	}
	else{
		aum=b+((p-c)*d);
	}
	if(sum<aum){
		printf("%d\n",sum);
	}
	else{
		printf("%d\n",aum);
	}
	return 0;
}



Measured memory_bytes: 2100
// #include <bits/stdc++.h>
#include <iostream> // cin, cout, string
#include <algorithm> // sort, min, max
#include <vector>
#include <utility> // pair, swap
#include <functional>
#include <iomanip> // setprecision
#include <map>
#include <set> // multiset
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <stack>
#include <queue> // priority_queue
#include <deque>
#include <bitset>
#include <complex>

using namespace std;

// #define int long long

using ll = long long;
using ld = long double;

// template<class T1, class T2> using P = pair<T1, T2>;
template<class T> using vec = vector<T>;
template<typename T> using func = function<T>;

using pii = pair<int, int>;
using ppi = pair<pii, int>;
using pip = pair<int, pii>;
using ppp = pair<pii, pii>;

using vi = vec<int>;
using vvi = vec<vi>; // Graph
using vp = vec<pii>;

constexpr int IINF =  0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
// constexpr int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
constexpr ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define mp make_pair
#define mt make_tuple
// eb(*,*) = pb(mp(*,*))
#define eb emplace_back
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))
// #define sum(...) accumulate(range(__VA_ARGS__), 0LL)

#define endl '\n'
#define dec(n) fixed << setprecision(n)
#define zfl(n)  setfill(‘0’) << setw(n)
#define debug(x) cerr << #x << ": " << (x) << endl

template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

template<typename T> istream &operator>>(istream &is, vector<T> &v) { for(auto&& x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for(int i=0; i<(int)v.size(); ++i) cout << v[i] << ( i+1 != (int)v.size() ? " " : "" ); return os; }

template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << p.first << " " << p.second; return os; }

const int limit = 100007;

int N, M;
int L[limit], R[limit];
int lb, rb;

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

  cin >> N >> M;
  lb = 1;
  rb = N;
  rep(i, M) {
    cin >> L[i] >> R[i];
    chmax(lb, L[i]);
    chmin(rb, R[i]);
  }

  if(rb>=lb) cout << (rb-lb+1) << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 1024
var s:string;
n,i:longint;
f:boolean;
begin 
	readln(s);
	n:=length(s);
	if s[1]<>'A' then begin write('WA');exit;end;
	if  (s[2]<'a') or  (s[n]<'a')  then begin write('WA');exit;end;
	f:=true;
	for i:=3 to n-1 do 
	if (s[i]='C') and (f=false) or (s[i]<'a') and (s[i]<>'C') then begin write('WA');exit;end
	else if s[i]='C' then f:=false;
	if f=true then begin write('WA');exit;end;
	write('AC');
end.

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	input := scanIntNum()
	s := scanString()
	fmt.Println(check(input, s))
}

// example
func check(n int, s string) int {
	var count int
	for i := 0; i < len(s)-2; i++ {
		if s[i] == byte('A') && s[i+1] == byte('B') && s[i+2] == byte('C') {
			count++
		}
	}
	return count
}

func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func scanString() (s string) {
	sc.Scan()
	return sc.Text()
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        a: usize,
        b: usize
    };

    let mut set = vec![1, 2, 3].into_iter().collect::<HashSet<_>>();
    set.remove(&a);
    set.remove(&b);
    let res = set.into_iter().next().unwrap();
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x[N], y[M];
  for (int i = 0; i < N; i++) cin >> x[i];
  for (int i = 0; i < M; i++) cin >> y[i];
  
  sort(x, x + N);
  sort(y, y + M);

  if(!(X < y[0] && y[0] <= Y)) {
    cout << "War" << endl;
    return 0;
  }
  
  for (int i : x) {
    if (i >= y[0]) {
      cout << "War" << endl;
      return 0;
    }
  }
  for (int i : y) {
    if (y[0] > i) {
      cout << "War" << endl;
      return 0;
    }
  }
  cout << "No War" << endl;
}

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

#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x

int a[100000] = {0};
int main(void){
	int N;
	cin >> N;
	rep(i, N) cin >> a[i];

	int ans = 0;
	int cur = 0;
	rep(i, N + 1){
		if(cur == 1){
			printf("%d\n", ans);
			return 0;
		}
		cur = a[cur] - 1;
		ans++;
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 640
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> x(N);
    for(int i=0; i<N; i++) cin >> x[i];

    int ans = INF;
    for(int i=0; i<2010; i++) {
        int cand = 0;
        for(int j=0; j<N; j++) {
            int d = abs(i - x[j]);
            chmax(cand, d);
        }
        chmin(ans, cand);
    }
    cout << ans << endl;
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 2e5+10;

int N, M;
int A[MAX], B[MAX], L[MAX], R[MAX];
vii line, edge[MAX];
bool visited[MAX];
vi ans;

int dnf(int n) {
    visited[n] = true;
    int ret = line[n].second;
    FORE (e, edge[n]) {
        int next = e.first;
        if (visited[next]) continue;
        int c = dnf(next);
        ret ^= c;
        if (c) ans.push_back(e.second);
    }
    return ret;
}

bool solve() {
    REP (i, N) line.push_back(ii(A[i], B[i]));
    line.push_back(ii(1e18, 0)); // 無限遠にoffのスイッチがある
    sort(ALL(line));
    REPR (i, N) line[i+1].second ^= line[i].second;

    REP (i, M) {
        int l = lower_bound(ALL(line), ii(L[i], 0)) - line.begin();
        int r = upper_bound(ALL(line), ii(R[i], 1)) - line.begin();
        if (l == r) continue;
        edge[l].push_back(ii(r, i+1));
        edge[r].push_back(ii(l, i+1));
    }

    REP (i, N) if (!visited[i]) {
        if (dnf(i)) return false;
    }

    sort(ALL(ans));
    return true;
}

int main() {
    cin >> N >> M;
    REP (i, N) cin >> A[i] >> B[i];
    REP (i, M) cin >> L[i] >> R[i];
    if (solve()) {
        cout << ans.size() << endl;
        FORE(x, ans) cout << x << " ";
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 23024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

typedef pair<int, int> P;//firstは最短距離、secondは頂点の番号

//revは逆辺
struct edge { int to, cap, cost, rev; };

int V; //頂点数
vector<edge> G[101010];
int h[101010];//ポテンシャル
int dist[101010];//最短距離
int prevv[101010], preve[101010];//直前の頂点と辺

void add_edge(int from, int to, int cap, int cost) {
	G[from].emplace_back(edge{ to,cap,cost,(int)G[to].size() });
	G[to].emplace_back(edge{ from,0,-cost,(int)G[from].size() - 1 });
}

//最小費用流、流せない場合は-1

int min_cost_flow(int s, int t, int f) {
	int res = 0;
	REP(i,V)h[i]=0;//初期化
	while (f > 0) {
		//ダイクストラ法を用いてhを更新
		priority_queue<P, vector<P>, greater<P>> que;
		REP(i, V)dist[i] = INF;
		dist[s] = 0;
		que.push(P(0, s));
		while (que.size()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (dist[v] < p.first)continue;
			for (int i = 0; i < G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF) {
			return -1;
			//これ以上流せない
		}
		for (int v = 0; v < V; v++)h[v] += dist[v];

		//s-t間最短路に沿ってめいっぱい流す
		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d*h[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}
int  e, f;
int main() {
	cin >> V >> e >> f;
	int s = 0, t = V - 1;
	REP(i, e) {
		int u, v, c, d;
		cin >> u >> v >> c >> d;
		add_edge(u, v, c, d);
	}
	cout << min_cost_flow(s, t, f) << endl;
}


Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main()
{
    string S, T;
    cin >> S >> T;

    const int NOT_FOUND = -1;
    int match_location = NOT_FOUND;

    for(int i = 0; i + T.size() - 1 < S.size(); i++)
    {
        int match_made = true;
        for(int j = 0; j < T.size(); j++)
        {
            if(S[i + j] != T[j] && S[i + j] != '?')
            {
                match_made = false;
            }
        }

        if(match_made)
            match_location = i;
    }

    for(int i = 0; i < S.size(); i++)
        if(S[i] == '?')
            S[i] = 'a';

    for(int i = 0; i < T.size(); i++)
        S[match_location + i] = T[i];

    if(match_location == NOT_FOUND)
        cout << "UNRESTORABLE\n";
    else
        cout << S;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#define _USE_MATH_DEFINENS
#include <cmath>
using namespace std;

#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n, k;
    cin >> n >> k;

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

    sort(a, a + n, greater<int>());

    int total = 0;
    for(int i = 0; i < k; i++){
        total += a[i];
    }

    cout << total << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, c; cin >> n >> c;
  V<> v(n), w(n); for (int i = 0; i < n; i++) cin >> v[i] >> w[i];
  V<> dp(c + 1);
  for (int i = 0; i < n; i++) {
    for (int j = w[i]; j <= c; j++) dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
  }
  cout << dp[c] << '\n';
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

string S;
int idx;
int N, M;
string alphas;
int curr;

bool try_consume(char c) {
  if(S[idx] != c) return false;
  idx ++;
  return true;
}

int E();

int convert(string const& b) {
  int n = b.size();
  int ret = 0;
  for(int i=0; i<n; i++) {
    ret *= 2;
    assert(isdigit(b[i]));
    ret += b[i] - '0';
  }
  return ret;
}

string B() {
  string ret;
  while(1) {
    if(S[idx] == '0') ret += '0';
    else if(S[idx] == '1') ret += '1';
    else break;
    idx++;
  }
  return ret;
}

int Nu() {
  if(try_consume('0')) return 0;
  if(!try_consume('1')) return -inf;
  return convert("1" + B());
}

int F() {
  if(try_consume('-')) {
    int f = F();
    if(f == -inf) return -inf;
    return -f;
  }
  else if(try_consume('(')) {
    int r = E();
    if(!try_consume(')')) return -inf;
    return r;
  }
  else {
    return Nu();
  }
}

int T() {
  int num1 = F();
  if(num1 == -inf) return -inf;
  while(try_consume('*')) {
    int num2 = F();
    if(num2 == -inf) return -inf;
    num1 *= num2;
  }
  return num1;
}

int E() {
  int term1 = T();
  if(term1 == -inf) return -inf;
  while(1) {
    bool cont = 0;
    while(try_consume('+')) {
      cont = 1;
      int term2 = T();
      if(term2 == -inf) return -inf;
      term1 += term2;
    }
    while(try_consume('-')) {
      cont = 1;
      int term2 = T();
      if(term2 == -inf) return -inf;
      term1 -= term2;
    }
    if(!cont) break;
  }
  return term1;
}

bool Q() {
  int expr1 = E();
  if(expr1 == -inf) return false;
  if(!try_consume('=')) return false;
  int expr2 = E();
  if(expr2 == -inf) return false;
  return expr1 == expr2 && idx == N;
}

int main() {

  string T = "01+-*()=";
  sort(T.begin(), T.end());
  string RS; cin >> RS;
  N = RS.size();
  for(auto c: RS) if(isalpha(c)) alphas.push_back(c);
  sort(alphas.begin(), alphas.end());
  alphas.erase(unique(alphas.begin(), alphas.end()), alphas.end());
  M = alphas.size();

  if(M > T.size()) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 0;
  set<string> st;
  do {
    S = RS;
    rep(i, N) {
      if(isalpha(S[i])) S[i] = T[alphas.find(S[i])];
    }
    if(!st.count(S)) {
      st.insert(S);
      idx = curr = 0;
      ans += Q();
    }
  } while(next_permutation(T.begin(), T.end()));
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7588
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = INT_MAX, rs = 0, ws = 0, ano = 0;
    for (auto &i: s)
        if (i=='R') rs++;
        else ws++;
    ans = min(rs, ws);
    for (int i=0; i<rs; i++)
        if (s[i]!='R')
            ano++;
    ans = min(ans, ano);
    cout << ans <<"\n";
}

Measured memory_bytes: 3744
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    map<string, int> m;
    rep(i,n) {
        string s; cin >> s;
        m[s]++;
    }
    typedef pair<int, string> P;
    vector<P> vec;
    for (auto v : m) {
        vec.emplace_back(v.second, v.first);
    }
    sort(vec.begin(), vec.end());
    int num = vec[vec.size()-1].first;
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i].first == num) {
            cout << vec[i].second << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 30316
N,M=map(int,input().split())
ab=[]
for i in range(N):
  ab.append(list(map(int,input().split())))
cd=[]
for i in range(M):
  cd.append(list(map(int,input().split())))
for i in ab:
  l=[]
  for j in cd:
    l.append(abs(i[0]-j[0])+abs(i[1]-j[1])) 
  print(l.index(min(l))+1)  

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>
#include <cassert>
#include <exception>
#include <stdexcept>
#include <iterator>
#include <sstream>

using namespace std;

typedef long long i64;

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

    i64 x, y;
    cin >> x >> y;

    int cnt = 0;
    for (i64 w = x; w <= y; w *= 2)
        cnt++;

    cout << cnt;    
}

Measured memory_bytes: 256