akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
#include<cmath>
#include<iterator>
typedef long long ll;
using namespace std;
#define rep(x, y)   for (ll i = x; i <= y; i ++)
#define repi(x, y)  for (ll i = x; i >= y; i --)
priority_queue< ll > cancel;
ll weight[200005];
ll value[200005];
int main()
{
    ll test=1;
    // cin>>test;
    for(ll z=0;z<test;z++)
    {
        ll n,W;
        cin>>n>>W;
        ll siz=0;
        for(ll i=1;i<=n;i++)
        {
            cin>>weight[i];
            cin>>value[i];
            siz+=value[i];
        }
        ll dp[siz+5][n+5];
        for(ll i=0;i<=n;i++)
        {
            dp[0][i]=0;
        }

        for(ll i=0;i<=siz;i++)
        {
            dp[i][0]=99999999999999;
        }
        dp[0][0]=0;
        for(ll i=1;i<=siz;i++)
        {
            for(ll j=1;j<=n;j++)
            {
                if(value[j]>i)
                {
                    dp[i][j]=dp[i][j-1];
                }
                else
                {
                    dp[i][j]=min(dp[i][j-1],dp[i-value[j]][j-1]+weight[j]);
                }  
            }
        }
        ll ans=0;
        // cout<<dp[siz][n]<<endl;
        for(ll i=1;i<=siz;i++)
        {
            if(dp[i][n]<=W)
            {
                ans=i;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 85612
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i) cin >> A[i];
    vector<int> count(1000007, 0);
    for (int x : A) {
        if (count[x] != 0) {
            count[x] = 2;
            continue;
        }
        for (int i = x; i <= 1000007; i += x) count[i]++;
    }
    long long int cnt = 0;
    for (int tmp : A) {
        if (count[tmp] == 1) cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 7932
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int f[N],n;
vector<int> e[N];
bool cmp(int x,int y){
	return f[x]>f[y];
}
void dfs(int x){
	for (int i=0;i<e[x].size();i++) dfs(e[x][i]);
	sort(e[x].begin(),e[x].end(),cmp);
	for (int i=0;i<e[x].size();i++)
		f[x]=max(f[x],f[e[x][i]]+i+1);
}
int main(){
	scanf("%d",&n);
	for (int i=2;i<=n;i++){
		int x;
		scanf("%d",&x);
		e[x].push_back(i);
	}
	dfs(1);
	printf("%d",f[1]);
}

Measured memory_bytes: 10752
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//#define __DEBUG__
#ifdef  __DEBUG__
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#endif

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<tuple<string, int, int>> A(N);
    REP(i, N) {
        string s;
        int rank;
        cin >> s >> rank;
        A[i] = make_tuple(s, -rank, i+1);
    }
    sort(ALL(A));
    REP(i, N) {
        // int id;
        // tie(ignore, ignore, id) = A[i];
        // cout << id << endl;
        cout << get<2>(A[i]) << endl;
    }
    getchar(); getchar();
}

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

const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);

using Point = complex<double>;
using Polygon = vector<Point>;

inline int sgn(const double &a) { return (a < -EPS ? -1 : (a > EPS ? 1 : 0)); }

inline bool eq(const Point &a, const Point &b) { return abs(a - b) < EPS; }

namespace std {
inline bool operator<(const Point &a, const Point &b) {
    if (sgn(a.real() - b.real()))
        return sgn(a.real() - b.real()) < 0;
    return sgn(a.imag() - b.imag()) < 0;
}
} // namespace std

double dot(const Point &a, const Point &b) { return real(conj(a) * b); }

double det(const Point &a, const Point &b) { return imag(conj(a) * b); }

struct Line {
    Point p1, p2;

    Line(Point p1 = Point(), Point p2 = Point()) : p1(p1), p2(p2) {}

    bool operator<(const Line &rhs) const {
        if (eq(p2, rhs.p2))
            return p1 < rhs.p1;
        return p2 < rhs.p2;
    }
    bool operator==(const Line &rhs) const {
        return (eq(p1, rhs.p1) && eq(p2, rhs.p2)) ||
               (eq(p1, rhs.p2) && eq(p2, rhs.p1));
    }
};

inline Point curr(const Polygon &p, const int &i){
    return p[i % p.size()];
}

inline Point next(const Polygon &p, const int &i){
    return p[(i+1) % p.size()];
}

inline Point prev(const Polygon &p, const int &i){
    return p[(i+p.size()-1) % p.size()];
}

enum { OUT, ON, IN };

int contains(const Polygon &poly, const Point &p){
    bool in = false;
    for(int i=0;i<poly.size();i++){
        Point a = curr(poly, i) - p, b = next(poly, i) - p;
        if(sgn(a.imag() - b.imag()) == 1)swap(a, b);
        if(sgn(a.imag()) <= 0 && sgn(b.imag()) > 0)
            if(sgn(det(a, b)) > 0)in = !in;
        if(sgn(det(a, b)) == 0 && sgn(dot(a, b)) <= 0)return ON;
    }
    return in ? IN : OUT;
}

int main(){
    int n;
    cin >> n;
    Polygon pg;
    for(int i=0;i<n;++i){
        double x, y;
        cin >> x >> y;
        Point p = Point(x, y);
        pg.push_back(p);
    }

    int q;
    cin >> q;
    for(int i=0;i<q;++i){
        double x, y;
        cin >> x >> y;
        Point p = Point(x, y);
        cout << contains(pg, p) << endl;
    }

    return 0;
}



Measured memory_bytes: 3228
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<deque>
#include<array>


#define REP(i,a,b) for(int i = (a); i < b; ++i)
#define inf 1e9+10
#define MOD 1000000007

using ll = long long;
using ull = unsigned long long;
using namespace std;

inline ll modpow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

inline ll mod(ll val, ll m) {
	ll res = val % m;
	if (res < 0) res += m;
	return res;
}


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

	vector<pair<int,int>> sc(m);

	REP(i, 0, m) {
		int s, c;
		cin >> s >> c;
		sc[i].first = s;
		sc[i].second = c;
	}

	vector<int> ans(n, -1);

	REP(i, 0, m) {
		if (sc[i].first == 1 && sc[i].second == 0 && n != 1) {
			cout << "-1";
			return 0;
		}
		REP(j, 0, m) {
			if (i != j && sc[i].first == sc[j].first && sc[i].second != sc[j].second) {
				cout << "-1";
				return 0;
			}
			
		}
	}
	REP(i, 0, n) {
		REP(j, 0, m) {
			if (i + 1 == sc[j].first) {
				ans[i] = sc[j].second;
			}
		}
	}
	REP(i, 0, n) {
		if (ans[i] == -1) {
			if (n != 1) {
				if (i == 0) {
					ans[i] = 1;
				}
				else {
					ans[i] = 0;
				}
			}
			else {
				ans[i] = 0;
			}
		}
	}
	REP(i, 0, n) {
		cout << ans[i];
	}
	return 0;
}

Measured memory_bytes: 3612
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t N;
    size_t W[100];
    size_t sum = 0;

    scanf("%zu", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%zu", &(W[i]));
        if (i < N - 1) {
            scanf(" ");
        }

        sum += W[i];
    }

    size_t diffMin = 1000000;
    size_t lCount = 0;

    for (size_t thr = 0; thr < N - 1; thr++) {
        lCount += W[thr];
        const size_t rCount = sum - lCount;
        const size_t abss = ABSS(lCount, rCount);
        if (abss < diffMin) {
            diffMin = abss;
        }
    }

    printf("%zu\n", diffMin);

    return 0;
}


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

int main()
{
        while(true)
        {
                int n,w,h;
                cin>>n;
                if(n==0) break;
                cin>>w>>h;

                int sum[105][105]={0};
                rep(i,n){
                        int x,y;
                        cin>>x>>y;
                        sum[y][x]=1;
                }
                rep(i,h) rep(j,w){
                        sum[i+1][j+1]+=sum[i+1][j]+sum[i][j+1]-sum[i][j];
                }

                int s,t;
                cin>>s>>t;
                int ans=0;
                rep(i,h-t+1) rep(j,w-s+1){
                        ans=max(ans,sum[i+t][j+s]-sum[i+t][j]-sum[i][j+s]+sum[i][j]);
                }
                cout<<ans<<endl;
        }
}

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

int main(void){
	char a[3];
	int i, n;

	for(i = 0; i < 3; i++){
		scanf("%c",&a[i]);
	}
	if(a[0] == a[1] && a[1] == a[2]) printf("No");
	else printf("Yes");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

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

int main(){
	double x,h;
	while(~scanf("%lf",&x)){
		scanf("%lf",&h);

		if(x==h && x==0) break;

		double a = x / 2.0;
		double b = sqrt(a*a + h*h);

		printf("%0.7f\n",x*b*2.0+x*x);
	}
	return 0;
}

Measured memory_bytes: 0
// Problem - Y (indu)

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int A{0};
    long long B{0},N{0};
    double value1{0},value2{0};

    scanf("%d %lli %lli",&A,&B,&N);

    //N--;

    if(N < B){
        value1 =floor( A * N / B );
        value2 =floor( N / B );
        value2 *= A;
        printf("%.0lf\n",value1 - value2);
    }else{
        if(N % B != B - 1){
            N -= (N % B) + 1; 
        }
        value1 =floor( A * N / B );
        value2 =floor( N / B );
        value2 *= A;
        printf("%.0lf\n",value1 - value2);
    }

    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
using namespace std;
int main()
{
	string n ;
	
	while(cin>>n)
	{
		int s = n.size() ,ok=1;
		for(int i=0 ;i<s ;i++)
		{
			if(i&1) 
				if(n[i]=='R'){cout<<"No\n"; ok=0; break;}
			if(i%2==0) 
				if(n[i]=='L'){cout<<"No\n"; ok=0; break;}
		}
		if(ok) cout<<"Yes\n";
	}
} 

Measured memory_bytes: 3036
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<long> p(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> p[i];

    }
    ll sum = accumulate(p.begin(), p.end(), 0);
    decltype(p)::iterator i = max_element(p.begin(), p.end());
    cout << sum - *i + *i / 2 << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int x = scanner.nextInt(); 
    int y = scanner.nextInt();
    int a[] = new int[x];
    int sum = 0;
    int i = 0;
    while(i<x){
      a[i] = scanner.nextInt();
      sum += a[i];
      i++;
    }
    Arrays.sort(a);
    double aa = (double)a[x-y] / (double)sum;
    double bb = (double)1/ (double)(4*y);
    //System.out.println(a[x-y]);
    //System.out.println(aa);
    //System.out.println(bb);
    if(aa >= bb){
      System.out.print("Yes");
    }
    else{
      System.out.print("No");  
    }
  }
}

Measured memory_bytes: 22612
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 int INF = 1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<vector<int>> c(m);
	vector<int> dp((1 << n), INF);
	rep(i,m){
		cin >> a[i] >> b[i];
		c[i].resize(b[i]);
		rep(j,b[i]){
			cin >> c[i][j];
			c[i][j]--;
		}
	}
	dp[0] = 0;
	rep(S,(1 << n)){
		rep(i,m){
			int nextS = S;
			rep(j,b[i]){
				if(!(S >> c[i][j] & 1)) nextS += (1 << c[i][j]);
			}
			chmin(dp[nextS], dp[S] + a[i]);
		}
	}
	int ans = dp[(1 << n)-1];
	if(ans == INF) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
int n,fa[100005];
pair <int,int> px[100005],py[100005];
set <pair<int,pair<int,int> > > st;
int gf(int x){
	if (fa[x]==x) return x; else return fa[x]=gf(fa[x]);
}
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>px[i].first;
		px[i].second=i;
		cin>>py[i].first;
		py[i].second=i;
		fa[i]=i;
	}
	sort(px,px+n);
	sort(py,py+n);
	for (int i=0;i<n-1;i++){
		st.insert(mp(px[i+1].first-px[i].first,mp(px[i+1].second,px[i].second)));
		st.insert(mp(py[i+1].first-py[i].first,mp(py[i+1].second,py[i].second)));  
	}
	long long cnt=0;
	for (set<pair<int,pair<int,int> > >::iterator it=st.begin();it!=st.end();it++){
		if (gf(it->second.first)!=gf(it->second.second)){
			fa[gf(it->second.first)]=fa[gf(it->second.second)];
			cnt+=it->first;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 14720
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;
U_MAP mp;

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

  cin >> n;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  ans = n;
  rep(i, n) {
    if (mp[a[i]] <= 2) continue;
    if (mp[a[i]] % 2 == 1)
      ans -= mp[a[i]] - 1, mp[a[i]] = 1;
    else
      ans -= mp[a[i]] - 2, mp[a[i]] = 2;
  }
  rep(i, n) {
    if (mp[a[i]] != 2) continue;
    cnt++;
    mp[a[i]] = 0;
  }
  ans -= ((cnt + 1) / 2) * 2;
  Cout(ans);
  return 0;
}

Measured memory_bytes: 8000
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 200005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b,n;
	cin>>n;
	a=1000*(n/500);
	b=5*((n%500)/5);
	cout<<(a+b);
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

// ABC094 at 2018/04/14

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solveB();
    }

    private void solveA() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int X = sc.nextInt();
        if ((X - A) < 0) {
            System.out.println("NO");
        } else if (B < (X - A)) {
            System.out.println("NO");
        } else if ((A + B) < X) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }

    private void solveB() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        ArrayList <Integer> list = new ArrayList<>();
        for (int i = 0; i < M; i++) {
            list.add(sc.nextInt());
        }
        int cost1 = 0;
        for (int i = X; i < N + 1; i++) {
            if (list.contains(i)) {
                cost1++;
            }
        }
        int cost2 = 0;
        for (int i = X; 0 < i; i--) {
            if (list.contains(i)) {
                cost2++;
            }
        }
        if (cost1 < cost2) {
            System.out.println(cost1);
        } else {
            System.out.println(cost2);
        }
    }

    private void solveC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveD() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveE() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveF() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

}

Measured memory_bytes: 21588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        try {
            int N = Integer.parseInt(stdin.readLine());
            int[] honest = new int[N];
            int[] unkind = new int[N];
            for (int i = 0; i < N; i++) {
                int A = Integer.parseInt(stdin.readLine());
                for (int j = 0; j < A; j++) {
                    String[] input = stdin.readLine().split(" ");
                    if (Integer.parseInt(input[1]) == 1) {
                        honest[i] |= (1 << (Integer.parseInt(input[0]) - 1));
                    } else {
                        unkind[i] |= (1 << (Integer.parseInt(input[0]) - 1));
                    }
                }
            }
            int max = 0;
            for (int i = 1; i < (1 << N); i++) {
                int honest_sum = 0;
                int unkind_sum = 0;
                int num = 0;
                // System.out.println(String.format("%" + N + "s",
                // Integer.toBinaryString(i)).replace(' ', '0'));
                for (int j = 0; j < N; j++) {

                    if ((i & (1 << j)) != 0) {
                        num++;
                        if (honest[j] != 0)
                            honest_sum |= honest[j];
                        if (unkind[j] != 0)
                            unkind_sum |= unkind[j];
                    }
                }
                // System.out.println("honest_sum:"
                // + String.format("%" + N + "s", Integer.toBinaryString(honest_sum)).replace('
                // ', '0'));
                // System.out.println("unkind_sum:"
                // + String.format("%" + N + "s", Integer.toBinaryString(unkind_sum)).replace('
                // ', '0'));
                if (((honest_sum & unkind_sum) == 0) & ((i & unkind_sum) == 0) & ((~i & honest_sum) == 0)) {
                    // System.out.println("[honest_sum & unkind_sum]:" + (honest_sum & unkind_sum) +
                    // " [i & unkind_sum]:"
                    // + (i & unkind_sum));
                    max = Math.max(max, num);
                }
            }

            System.out.println(max);

            // int N = Integer.parseInt(stdin.readLine());

        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
    }
}

Measured memory_bytes: 32992
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::VecDeque;

fn main() {
	input! {
		n: usize,
		ab: [(usize, usize); n-1],
	}

	let mut v: Vec<Vec<usize>> = vec![vec![]; n];
	for i in 0..n-1 {
		v[ab[i].0-1].push(ab[i].1-1);
		v[ab[i].1-1].push(ab[i].0-1);
	}

	let mut d1 = vec![0usize; n];
	let mut t1 = vec![false; n];
	t1[0] = true;
	let mut q = VecDeque::new();
	for i in 0..v[0].len() {
		q.push_back((v[0][i], 1usize));
	}
	while q.len() > 0 {
		let tmp = q.pop_front().unwrap();
		if t1[tmp.0] {
			continue;
		}
		t1[tmp.0] = true;
		d1[tmp.0] = tmp.1;
		for i in 0..v[tmp.0].len() {
			q.push_back((v[tmp.0][i], tmp.1+1));
		}
	}

	let mut dn = vec![0usize; n];
	let mut tn = vec![false; n];
	tn[n-1] = true;
	let mut q = VecDeque::new();
	for i in 0..v[n-1].len() {
		q.push_back((v[n-1][i], 1usize));
	}
	while q.len() > 0 {
		let tmp = q.pop_front().unwrap();
		if tn[tmp.0] {
			continue;
		}
		tn[tmp.0] = true;
		dn[tmp.0] = tmp.1;
		for i in 0..v[tmp.0].len() {
			q.push_back((v[tmp.0][i], tmp.1+1));
		}
	}

	let mut fe = 0;
	let mut su = 0;
	for i in 0..n {
//		println!("{}: {},{}", i, d1[i], dn[i]);
		if d1[i] <= dn[i] {
			fe += 1;
		}
		else {
			su += 1;
		}
	}
//	println!("{},{}", fe, su);
	if fe > su {
		println!("Fennec");
	}
	else {
		println!("Snuke");
	}
}



Measured memory_bytes: 14216
H,W = list(map(int,input().split()))
V = 10
cost = []
for i in range(V):
    cost.append(list(map(int,input().split())))

INF = float('inf')
for k in range(V):
    for i in range(V):
        for j in range(V):
            if cost[i][k]!=INF and cost[k][j]!=INF:
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

out = 0
for i in range(H):
    A = list(map(int,input().split()))
    for j in range(W):
        if A[j]==-1:
            continue
        else:
            out += cost[A[j]][1]
print(out)

Measured memory_bytes: 73560
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <set>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_b(pair<int, long long> a, pair<int, long long> b) {
    if(a.second != b.second) {
        return a.second > b.second;
    } else {
        return a.first > b.first;
    }
}

int dp[100005][2];
const long long MOD = 1000000007;
int main() {
    string S;
    cin >> S;
    dp[0][0] = 1;
    int n = S.size();
    rep(i, 0, n) {
        if(S[i] == '0') {

            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1];

            dp[i + 1][1] += dp[i][1] * 2 % MOD;
            dp[i + 1][1] %= MOD;
        } else {
            dp[i + 1][1] = (dp[i][0] + dp[i][1]) % MOD;

            dp[i + 1][0] = dp[i][0] * 2 % MOD;
            dp[i + 1][1] += dp[i][1] * 2 % MOD;
            dp[i + 1][1] %= MOD;
        }
    }
    cout << (dp[n][0] + dp[n][1]) % MOD << endl;
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] nyuryoku = line.split("[\\s]+");
		int hikaku_a = Integer.parseInt(nyuryoku[0]);
		int hikaku_b = Integer.parseInt(nyuryoku[1]);

		if(hikaku_a > hikaku_b){
			System.out.println("a > b");
		} else if(hikaku_a < hikaku_b){
			System.out.println( "a < b");
		} else {
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 24492
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

llint L, R;
llint dp[63][2][2][2];

int main(void)
{
	cin >> L >> R;
	
	dp[62][0][0][0] = 1;
	for(int i = 62; i > 0; i--){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				for(int l = 0; l < 2; l++){
					
					//cout << i << " " << j << " " << k << " " << l << " " << dp[i][j][k][l] << endl;
					for(int u = 0; u < 2; u++){
						for(int d = 0; d < 2; d++){
							if(u == 0 && d == 1) continue;
							if(l == 0 && u == 1 && d == 0) continue;
							if(j == 0 && d == 0 && (L&(1LL<<(i-1)))) continue;
							if(k == 0 && u == 1 && (R&(1LL<<(i-1))) == 0) continue;
							int nj = j, nk = k, nl = l;
							if(d == 1 && (L&(1LL<<(i-1))) == 0) nj = 1;
							if(u == 0 && (R&(1LL<<(i-1)))) nk = 1;
							if(u == 1 && d == 1) nl = 1;
							(dp[i-1][nj][nk][nl] += dp[i][j][k][l]) %= mod;
						}
					}
				}
			}
		}
	}
	llint ans = 0;
	for(int j = 0; j < 2; j++){
		for(int k = 0; k < 2; k++){
			for(int l = 0; l < 2; l++){
				ans += dp[0][j][k][l], ans %= mod;
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  string S;
  cin >> S;
//  cout << S << endl;
  
  for (int tmp=0; tmp<(1<<(S.size()-1)); tmp++) {
    bitset<3> bit_tmp(tmp);
//    cout << bit_tmp << endl;

    string s_result = "";
    s_result += S.at(0);
    int result = stoi(s_result);

    for (int cnt=1; cnt<S.size(); cnt++) {
      string S_n = "";
      S_n += S.at(cnt);
//      cout << S_n << endl;
      if( bit_tmp.test(cnt-1) ) {
        result += stoi(S_n);
        s_result += "+";
        s_result += S_n;
      } else {
        result -= stoi(S_n);
        s_result += "-";
        s_result += S_n;
      }
//      cout << result << endl; 
    }
    if (result == 7) {
      cout << s_result << "=7" << endl;
      return 0;
    }
  }

  return 0;
}

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

int a[1000001];
int cmp(const void *s,const void *b){
return (*(int *)b)-(*(int *)s);
}
int main(void){
int n,m,k;
int i,j;
while(scanf("%d",&n),n){
m=0;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
qsort(a,n,sizeof(int),cmp);

for(i=0;i<n;i++){
for(j=i+1;j<n+1;j++){
if(a[i]!=a[j]){
if(m<j-i){
m=j-i;
k=a[i];
}
i=j-1;
break;
}
}
}
if(n/2<m)printf("%d\n",k);
else puts("NO COLOR");
}
return 0;}

Measured memory_bytes: 9932
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=998244353, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

ll fac[300007],finv[300007],inv[300007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<300007;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll com(ll n,ll k){
    if(n<k)return 0;
    if(n<0 || k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll n, a, b, k, ans = 0;
    cin >> n >> a >> b >> k;
    for(ll x = 0; x <= n; x++){
    	if(k >= x * a && (k - x * a) % b == 0){
    		ll y = (k - x * a) / b;
    		(ans += (com(n, x) * com(n, y)) % mod ) %= mod;
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    int a[100001];
    string s,x;
    cin>>s;
   // int len=s.size();
   for(int i=0;i<s.size();i++)
   {
       s[i]='x';

   }
   for(int i=0;i<s.size();i++)
   {
       cout<<s[i];
   }

    cout<<endl;
        return 0;
    }


Measured memory_bytes: 764
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
g3 = [2]

x, y = map(int, input().split())

if x in g1 and y in g1:
  print("Yes")
elif x in g2 and y in g2:
  print("Yes")
elif x in g3 and y in g3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
N, S = map(int, input().split())
A = [int(i) for i in input().split()]

mod = 998244353

dp = [[0] * (S + 1) for _ in range(N + 1)]

ret = 0
for i, a in enumerate(A) :
  if a <= S :
    dp[i + 1][a] += i + 1
    
  for j in range(S, -1, -1) :
    dp[i + 1][j] += dp[i][j]
    if j >= a :
      dp[i + 1][j] += dp[i][j - a]
    dp[i + 1][j] %= mod
        
  ret += (dp[i + 1][S] - dp[i][S]) * (N - i) % mod
  ret %= mod

print(ret)

Measured memory_bytes: 113372
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;

map<ll,ll> ll_counter(vll vec) {
    map<ll,ll> counter;
    for(auto v:vec) counter[v]++;
    return counter;
}

ll func(ll x){
    if(x==0 || x==1) return 0;
    ll res = x * (x-1) / 2;
    return res;
} 

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    
    ll n;cin >> n;
    vll a(n);rep(i,n) cin >> a[i];
    map<ll,ll> counter = ll_counter(a);
    ll total = 0;
    for(auto& c:counter){
        total += func(c.second);
    }
    for(auto& x:a){
        ll val = counter[x];
        ll ans = total - func(val) + func(val-1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 11264
/*天気*/
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		int i;
		int count = 0;

		Scanner sc = new Scanner(System.in);

		String S = sc.nextLine();
		String T = sc.nextLine();

		String[] SArray = S.split("");
		String[] TArray = T.split("");


		for(i = 0; i < 3;i++) {
			if(SArray[i].equals(TArray[i])) count++;
		}
	      System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define int              long long
#define pb               push_back
#define mp               make_pair
#define vi               vector<int>
#define pii              pair<int,int>
#define mii              map<int,int>
#define pqb              priority_queue<int>
#define pqs              priority_queue<int, vi, greater<int>>
#define MOD              1000000007  //10^9+7
#define precision(x,y)   fixed<<setprecision(y)<<x
#define setbits(x)       __builtin_popcountll(x)  // number of 1s
#define zerobits(x)      __builtin_ctzll(x)   //number of zeroes after last 1
#define w(t)             int t; cin>>t; while(t--)
#define mk(arr,n,type)   type *arr=new type[n];
mt19937                  rng(chrono::steady_clock::now().time_since_epoch().count());   
#define shuffle(arr,n)   shuffle(arr, arr+n, rng) 


int32_t main(){ //used int32_t main because int is defined as long long above
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n,res=0;
	cin>>n;
	if(n>2){


	int l[n];
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			for(int k=j+1;k<n;k++){
				if((l[i]!=l[j])&&(l[j]!=l[k])&&(l[i]!=l[k])){
					if((l[i]+l[j]>l[k])&&(l[j]+l[k]>l[i])&&(l[i]+l[k]>l[j])){
						res++;
					}
				}
			}
		}
	}
	}
	cout<<res;
	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

int N, T;
ll ts[200200];

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

    std::cin >> N >> T;

    for(int i=0;i<N;++i){
        std::cin >> ts[i];
    }

    ll res = 0;
    for(int i=0,j=0;i<N;){
        while(j + 1 < N && ts[j + 1] - ts[j] <= T){++j;}

        // std::cout << i << ", " << j << std::endl;
        
        res += ts[j] - ts[i] + T;
        ++j;
        i = j;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 1792
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=1000000000000001;
const ld PI=acos(-1);
 
int main(){
    rapgame
    //freopen("unionday.in", "r", stdin);
    //freopen("unionday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        readll(n);
        vlli a(n);
        bool bits[n][61],ans[n][61]; 
        fr(i,n){
            fr(j,61){
                bits[i][j]=ans[i][j]=0;
            }
        }
        fr(i,n){
            cin >> a[i];
            fr(j,61){
                if(a[i]>=(1ll<<(60-j))){
                    a[i]-=(1ll<<(60-j));
                    bits[i][60-j]=1;
                }
            }
        }
        // 10100 01011 01001 11000 20 11 9 24
        fr(i,61){
            int used=0;
            fr(j,n){
                if(bits[j][i]) used++;
            }
            bool f=(used%2==1);
            fr(j,n) ans[j][i]=bits[j][i]^f;
        }
        fr(i,n){
            lli b=0;
            fr(j,61){
                b+=(1ll<<j)*ans[i][j];
            }
            cout << b << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 28536
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    double ret = 0;
    for (int i = 1; i <= n; i++)
    {
        double tmp = 1.0 / n;
        int now = i;
        while (now < k)
        {
            now *= 2;
            tmp /= 2;
        }
        ret += tmp;
    }
    printf("%.12f\n", ret);
    return 0;
}

Measured memory_bytes: 256
import heapq
import math
#これを加える！！！！
def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

"""
a = [1,7,3,5,4]

#heapify
#配列a = [1,7,3,5,4]をheapにする
heapq._heapify_max(a)
print(a) #[7, 5, 3, 1, 4]

#heappop
#最大値の取り出し
print(_heappop_max(a)) #7
print(a) #[5, 4, 3, 1]

#heappush
#要素(2)の挿入
_heappush_max(a,2)
print(a) #[5, 4, 3, 1, 2]

#最大値の取り出し
print(_heappop_max(a)) #5
"""

N, M = map(int, input().split())
a = [int(i) for i in input().split()]
heapq._heapify_max(a)

for j in range(M):
    _heappush_max(a, _heappop_max(a)//2)
print(sum(a))


Measured memory_bytes: 14436
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int op(int a,int b){ return max(a,b); }

int e(){ return -1; }

int target;

bool f(int v){ return v<target; }

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin>>n>>q;
    vector<int> a(n,0);
    rep(i,n) cin>>a[i];
    segtree<int,op,e> st{a};
    rep(_,q){
        int t; cin>>t;
        if(t==1){
            int x,v; cin>>x>>v;
            st.set(x-1,v);
        }
        if(t==2){
            int l,r; cin>>l>>r;
            printf("%d\n",st.prod(l-1,r));
        }
        if(t==3){
            int x,v; cin>>x>>v;
            target=v;
            printf("%d\n",st.max_right<f>(x-1)+1);
        }
    }
}

Measured memory_bytes: 6140
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(r.readLine());
		String[] ps = r.readLine().split("\\s");
		int[] p = new int[N];
		for (int j = 0; j < N; j++)
			p[j] = Integer.parseInt(ps[j]);
		PrintWriter pw = new PrintWriter(System.out);
		for (int j = 0; j < N; j++) {
			pw.print(1 + (N + 1) * j);
			if (j < N-1)
				pw.print(" ");
		}
		pw.println();
		int[] b = new int[N];
		for (int j = 0; j < N; j++) {
			int il = (N + 1) * (N - p[j] + 1);
			b[p[j] - 1] = il + j - 1;
		}
		for (int j = 0; j < N; j++) {
			pw.print(b[j]);
			if (j < N-1)
				pw.print(" ");
		}
		pw.println();
		pw.close();
		r.close();
	}
	
}


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

int main() {
    int N;
    cin >> N;
    int mi = N + 1, res = 0;
    for (int i = 0; i < N; ++i) {
        int p;
        cin >> p;
        mi = min(mi, p);
        if (mi == p) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 3188
#include<stdio.h>
int main(void) {
  int i, a, b, sum;
  while(scanf("%d%d", &a, &b) != EOF) {
    sum = a + b;
    for(i = 0; sum != 0; i++) {
      sum /= 10;
    }
    printf("%d\n", i);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll C[100005]={};
int n,m;
vector<int> v[100005];
int main() {
	int n[4];
	bool b[4]={};
	cin>>n[0]>>n[1]>>n[2]>>n[3];
	int a[4]={1,7,9,4};
	rep(i,0,4){
		rep(j,0,4){
			if(n[i]==a[j])b[j]=1;
		}
	}
	if(b[0]&&b[1]&&b[2]&&b[3])cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


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

int N,K;
int dp[2005][2005][2];
int solve(string s){
  int INF=1e7;
  for(int i=0;i<2005;i++)
    for(int j=0;j<2005;j++)
      for(int k=0;k<2;k++)
        dp[i][j][k]=-INF;
  

  dp[0][0][0]=0;

  int maxm=0;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<=K;j++){
      for(int k=0;k<2;k++){
        
        if(dp[i][j][k]==-INF)continue;
        int l=(j+2-k)%2;
        //cout<<i<<' '<<j<<' '<<k<<' '<<l<<' '<<dp[i][j][k]<<endl;
        
        if(j<K){
          dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
          
          dp[i][j+1][1-k]=max(dp[i][j+1][1-k],dp[i][j][k]);
        }
      
        int ncost=dp[i][j][k];
        if(k==1){
          if(s[i]=='L')ncost++;
          if(s[i]=='R')ncost--;
        }
        if(l==1){
          if(s[i]=='U')ncost--;
          if(s[i]=='D')ncost++;
        }
        
        dp[i+1][j][k]=max(dp[i+1][j][k], ncost);
        if(i+1==N)maxm=max(maxm,dp[i+1][j][k]);
      }
    }// j
  }// i
  
  int x=0,y=0;
  for(int i=0;i<N;i++){
    if(s[i]=='L')x--;
    if(s[i]=='R')x++;
    if(s[i]=='D')y--;
    if(s[i]=='U')y++;
  }
  
  return x+y+maxm+maxm;
}

int main(){
  string s,t;
  cin>>s>>K;
  N=s.size();
  t=s;
  int ans=0;
  ans=max(ans, solve(t) );

  t=s;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='L')t[i]='R';
    if(s[i]=='R')t[i]='L';
  }
  ans=max(ans, solve(t) );


  t=s;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='L')t[i]='R';
    if(s[i]=='R')t[i]='L';
    if(s[i]=='U')t[i]='D';
    if(s[i]=='D')t[i]='U';
  }
  ans=max(ans, solve(t) );

  t=s;
  for(int i=0;i<(int)s.size();i++){
    if(s[i]=='U')t[i]='D';
    if(s[i]=='D')t[i]='U';
  }
  ans=max(ans, solve(t) );

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

Measured memory_bytes: 34512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


// #define INT_MAX 2147483647
// #define LL_MAX 9223372036854775807

using namespace std;
#define i64  long long

void solve(void)
{
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;

  if((x-r>= 0)&&(y-r>=0)&&(x+r)<=W&&(y+r)<=H)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
  
  return;
}
int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll y = abs(x);
    if(y / d > k) {
        cout << y - k * d << endl;
    } else {
        ll c = y / d;
        ll now = y - c * d;
        if((k - c) % 2 == 0) {
            cout << now << endl;
        } else {
            cout << abs(now - d) << endl;
        }
    }
}

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

const int m=1000005;
int main(){
  int n,a,b;
  cin >> n >>a >>b;
  string s;
  cin >> s;
  rep(i,n){
    if(s[i]=='a' and a+b>0){
      cout << "Yes" << "\n";
      a--;
      continue;
    }
    if(s[i]=='b' and a+b>0 and b>0){
      cout << "Yes" << "\n";
      b--;
      continue;
    }    
    cout << "No" << "\n";
  }
  return 0;
}

Measured memory_bytes: 3784