stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

pair<long long, long long> a[101010];

main()

{

    int n;

    int x, y;

    long long o;

	cin >>n;

    for(int i = 0; i < n; i ++)

        cin >>a[i].first >>a[i].second;

    for(int k = o = 0; k < 100000; k ++)

    {

        random_shuffle(a, a + n);

        x = 0;

        y = 0;

        for(int i = 0; i < n; i ++)

        {

        	

            if((long long)(x + a[i].first) * (x + a[i].first) + (long long)(y + a[i].second) * (y + a[i].second) > (long long)x * x + (long long)y * y)

            {

                x += a[i].first ;

                y += a[i].second;

            }

        }

        o = max(o, (long long)x * x + (long long)y * y);

    }

    cout <<fixed <<setprecision(20) <<(sqrt(o));

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



#ifdef NeverBeRed

#include "debug.h"

#else

#define debug(...) 9715

#endif

typedef long long ll;

typedef long double ld;

typedef complex<ll> point;

#define F first

#define S second



ll cross(point a, point b) { return imag(conj(a) * b); }



int qua(point x)

{

	if (x.real() > 0 && x.imag() >= 0) return 0;

	if (x.real() <= 0 && x.imag() > 0) return 1;

	if (x.real() < 0 && x.imag() <= 0) return 2;

	return 3;

}



int main()

{

	#ifdef TurnRed

		//freopen("a.in", "r", stdin);

		//freopen("a.out", "w", stdout);

	#endif



	ios_base::sync_with_stdio(0), cin.tie(0);



	int n;

	cin >> n;

	vector<point> v(n);

	for (int i = 0, x, y; i < n; ++i)

	{

		cin >> x >> y;

		v[i] = { x, y };

	}



	ll ans = 0;

//	if (n <= 20)

//	{

//		for (int i = 1; i < 1<<n; ++i)

//		{

//			point p = { 0, 0 };

//			for (int j = 0; j < n; ++j)

//				if (i >> j & 1)

//					p += v[j];

//			ans = max(ans, norm(p));

//		}

//	}

//	else

	{

		sort(v.begin(), v.end(), [](const point &x, const point &y)

		{

			int qx = qua(x);

			int qy = qua(y);

			if (qx != qy) return qx < qy;

			if (cross(x, y) == 0) return norm(x) < norm(y);

			return cross(x, y) > 0;

		});



		for (int i = 0; i < n; ++i)

		{

			point p = { 0, 0 };

			for (int j = i, k = n; k--; j = (j+1) % n)

			{

				p += v[j];

				ans = max(ans, norm(p));

			}

		}

	}

	ld ans2 = sqrtl(ans);

//	ld l = 0, r = ans;

//	for (int it = 500; it--; )

//	{

//		ld m = (l + r) / 2.0;

//		if (m * m < ans)

//			l = m;

//		else

//			r = m;

//	}

//	ans2 = r;

	cout << setprecision(20) << fixed << ans2/*sqrtl(ans)*/ << "\n";



	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main() {



    int n;

    cin >> n;



    pair<int, int> data[n];



    for(int i = 0; i < n; i++) {

        cin >> data[i].first >> data[i].second;

    }

    



    double sol = 0;

    for(int r = 0; r < 100000; r++) {

        random_shuffle(data, data + n);

        double x = data[0].first, y = data[0].second, c = sqrt(pow(x, 2) + pow(y, 2));

        for(int j = 1; j < n; j++) {

            x += data[j].first;

            y += data[j].second;

            double length = sqrt(pow(x, 2) + pow(y, 2));

            if(length > c) c = length;

            else {

                x -= data[j].first;

                y -= data[j].second;

            }

        }

        sol = max(c, sol);

    }



    cout << fixed << setprecision(20) << sol << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



int main() {



    int n;

    cin >> n;



    pair<int, int> data[n];



    for(int i = 0; i < n; i++) {

        cin >> data[i].first >> data[i].second;

    }

    



    double sol = 0;

    for(int r = 0; r < 100; r++) {

        random_shuffle(data, data + n);

        for(int i = 0; i < n; i++) {

            double x = data[i].first, y = data[i].second, c = sqrt(pow(x, 2) + pow(y, 2));

            for(int j = 0; j < n; j++) {

                if(i == j) continue;

                x += data[j].first;

                y += data[j].second;

                double length = sqrt(pow(x, 2) + pow(y, 2));

                if(length > c) c = length;

                else {

                    x -= data[j].first;

                    y -= data[j].second;

                }

            }

            sol = max(c, sol);

        }

    }



    cout << fixed << setprecision(20) << sol << endl;



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

const double PI = acos(-1);



typedef complex<double> Point;

typedef vector<Point> VP;



int main(void){

    int n;

    cin >> n;

    VP ps(n);

    rep(i,n){

        double x,y;

        cin >> x >> y;

        ps[i] = Point(x,y);

    }

    double M = 10000;

    double res = 0;

    rep(i,M){

        Point inf = polar(1e9, 2.0*PI*(i/M));

        VP used;

        Point p(0,0);

        rep(j,n){

            if (abs(ps[j]-inf) < 1e9) {

                p += ps[j];

            }

        }

        res = max(res, abs(p));

    }

    printf("%.20f\n", res);

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

const double PI = acos(-1);



typedef complex<double> Point;

typedef vector<Point> VP;



int main(void){

    int n;

    cin >> n;

    VP ps(n);

    rep(i,n){

        double x,y;

        cin >> x >> y;

        ps[i] = Point(x,y);

    }

    double M = 1000;

    double res = 0;

    rep(i,M){

        Point inf = polar(1e9, 2.0*PI*(i/M));

        VP used;

        Point p(0,0);

        rep(j,n){

            if (abs(ps[j]-inf) < 1e9) {

                p += ps[j];

            }

        }

        res = max(res, abs(p));

    }

    printf("%.20f\n", res);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
// 解説後

#include <algorithm>

#include <iostream>

#include <iomanip>

#include <vector>

#include <cmath>



template <typename T>

struct Vector2 {

  Vector2& operator+=(const Vector2& other) noexcept {

    x += other.x;

    y += other.y;

    return *this;

  }



  friend Vector2 operator+(Vector2 lhs, Vector2 rhs) noexcept {

    return Vector2(lhs) += rhs;

  }



  template<typename U>

  auto dot(Vector2<U> rhs) const noexcept {

    return x * rhs.x + y * rhs.y;

  }



  auto norm2() const noexcept { return dot(*this); }



  auto norm() const noexcept { return sqrt(norm2()); }



  T x, y;

};



// L^2ノルムを最大化したいので、方向が同じベクトルを集める

int solve_F() {

  size_t N;

  std::cin >> N;



  std::vector<Vector2<double>> directions(36000);

  for (size_t i = 0; i < directions.size(); ++i) {

    const double angle = 3.14159265358979 * 2 * i / directions.size();

    directions[i].x = cos(angle);

    directions[i].y = sin(angle);

  }





  std::vector<Vector2<int64_t>> summations(directions.size());

  for (size_t i = 0; i < N; ++i) {

    Vector2<int64_t> v;

    std::cin >> v.x >> v.y;



    for (size_t j = 0; j < directions.size(); ++j) {

      if (directions[j].dot(v) >= 0.0) {

        summations[j] += v;

      }

    }

  }



  double result = 0.0;

  for (const auto& v : summations) {

    result = std::max(result, v.norm());

  }



  std::cout << std::setprecision(20) << result;

  return 0;

}



int main() { return solve_F(); }


// Optimized solution to the same problem (faster):
// 解説後

#include <algorithm>

#include <iostream>

#include <iomanip>

#include <vector>

#include <cmath>



template <typename T>

struct Vector2 {

  Vector2& operator+=(const Vector2& other) noexcept {

    x += other.x;

    y += other.y;

    return *this;

  }



  friend Vector2 operator+(Vector2 lhs, Vector2 rhs) noexcept {

    return Vector2(lhs) += rhs;

  }



  template<typename U>

  auto dot(Vector2<U> rhs) const noexcept {

    return x * rhs.x + y * rhs.y;

  }



  auto norm2() const noexcept { return dot(*this); }



  auto norm() const noexcept { return sqrt(norm2()); }



  T x, y;

};



// L^2ノルムを最大化したいので、方向が同じベクトルを集める

int solve_F() {

  size_t N;

  std::cin >> N;



  std::vector<Vector2<double>> directions(360);

  for (size_t i = 0; i < directions.size(); ++i) {

    const double angle = 3.14159265358979 * 2 * i / directions.size();

    directions[i].x = cos(angle);

    directions[i].y = sin(angle);

  }





  std::vector<Vector2<int64_t>> summations(directions.size());

  for (size_t i = 0; i < N; ++i) {

    Vector2<int64_t> v;

    std::cin >> v.x >> v.y;



    for (size_t j = 0; j < directions.size(); ++j) {

      if (directions[j].dot(v) >= 0.0) {

        summations[j] += v;

      }

    }

  }



  double result = 0.0;

  for (const auto& v : summations) {

    result = std::max(result, v.norm());

  }



  std::cout << std::setprecision(20) << result;

  return 0;

}



int main() { return solve_F(); }


// Fastest known solution for this problem:
// Original C++ solution (slower):
// F.



#include <iostream>

#include <sstream>

#include <algorithm>

#include <vector>

#include <cmath>



using namespace std;



typedef long long LL;

typedef long double LD;



int n;

vector<LD> x, y;

vector<LD> angle;



double calc(LD r) {

	LD xs = 0, ys = 0;

	for (int i = 0; i < n; ++i) {

		if (r - M_PI/2 <= angle[i] && angle[i] <= r + M_PI/2) {

			xs += x[i], ys += y[i];

		}

	}

	return sqrt(xs * xs + ys * ys);

}





int main(int argc, char* argv[]) {

	cout.precision(12);



	cin >> n;

	x.resize(n);

	y.resize(n);

	angle.resize(n);

	for (int i = 0; i < n; ++i) {

		cin >> x[i] >> y[i];

		angle[i] = atan2(y[i], x[i]);

		if (angle[i] < 0) {

			angle[i] += 2 * M_PI;

		}

	}

	LD left = 0, right = 2 * M_PI;



	for (int t = 0; t < 1000; ++t) {

		if (calc((left * 2 + right) / 3) > calc((left + right * 2) / 3)) {

			right = (left + right * 2) / 3;

		} else {

			left = (left * 2 + right) / 3;

		}

	}

	LD ans = calc(left);



	for (int i = 0; i < n; ++i) {

		angle[i] = atan2(x[i], y[i]);

		if (angle[i] < 0) {

			angle[i] += 2 * M_PI;

		}

	}

	left = 0, right = 2 * M_PI;



	for (int t = 0; t < 1000; ++t) {

		if (calc((left * 2 + right) / 3) > calc((left + right * 2) / 3)) {

			right = (left + right * 2) / 3;

		} else {

			left = (left * 2 + right) / 3;

		}

	}

	LD ans2 = calc(left);

	if (ans2 > ans) {

		ans = ans2;

	}



	cout << ans << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
// F.



#include <iostream>

#include <sstream>

#include <algorithm>

#include <vector>

#include <cmath>



using namespace std;



typedef long double LD;



int main(int argc, char* argv[]) {

	cout.precision(12);

	while (true) {

		int n = -1;

		cin >> n;

		if (n <= 0) break;

		vector<LD> x(n), y(n);

		vector<pair<LD, int>> v(n);

		for (int i = 0; i < n; ++i) {

			cin >> x[i] >> y[i];

			v[i] = {atan2(y[i], x[i]), i};

		}

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

		LD ans = 0;

		for (int i = 0; i < n; ++i) {

			LD xs = 0, ys = 0;

			for (int j = 0; j < n; ++j) {

				int k = v[(i + j) % n].second;

				xs += x[k], ys += y[k];

				ans = max(ans, sqrt(xs * xs + ys * ys));

			}

		}

		cout << ans << endl;

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <iomanip>

#include <cmath>

#include <random>

using namespace std;

random_device rd;

mt19937 mt(rd());



int n;

double x[111], y[111];



int main() {

  cin >> n;

  for(int i = 0; i < n; ++i) cin >> x[i] >> y[i];



  double ans = 0.0;

  uniform_real_distribution<> rand(-1.0, 1.0);

  for(int a = 0; a < 10000; ++a) {

    x[n] = rand(mt), y[n] = rand(mt);



    double px = 0.0, py = 0.0;

    for(int i = 0; i < n; ++i) {

      if(x[i]*x[n] + y[i]*y[n] >= 0) px += x[i], py += y[i];

    }

    ans = max(ans, px*px + py*py);

  }

  cout << fixed << setprecision(15) << sqrt(ans);

  return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <algorithm>

#include <iomanip>

#include <cmath>

using namespace std;



int n;

pair<double, double> ps[222];



int main() {

  cin >> n;

  for(int i = 0; i < n; ++i) cin >> ps[i].first >> ps[i].second;

  sort(ps, ps + n, [](auto a, auto b) {

      return atan2(a.first, a.second) < atan2(b.first, b.second);

  });

  for(int i = 0; i < n; ++i) ps[i + n] = ps[i];



  double ans = 0.0;

  for(int L = 0; L < n; ++L) {

    for(int R = L; R < L + n; ++R) {

      double x = 0.0, y = 0.0;

      for(int i = L; i <= R; ++i) x += ps[i].first, y += ps[i].second;

      ans = max(ans, x*x + y*y);

    }

  }

  cout << fixed << setprecision(15) << sqrt(ans);

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define LL long long

#define pii pair<int,int>

#define SZ(x)  (int)x.size()

#define all(x) x.begin(),x.end()



using namespace std;



LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}

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

LL powmod(LL a, LL b, LL MOD) {LL ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}

const int N = 2e5 + 11;

int n;

struct uzi

{

	int a, b;

	bool operator <(const uzi & t)const {

		return 	atan2(a, b) < atan2(t.a, t.b);

	}

} p[N];

double get(LL l, LL r) {

	return sqrt(l * l + r * r);

}

int main() {

	ios::sync_with_stdio(false);

	cin >> n;

	for (int i = 1; i <= n; i++)cin >> p[i].a >> p[i].b;

	sort(p + 1, p + 1 + n);

	double ans = 0;

	for (int i = 1; i <= n; i++) {

		LL x = 0, y = 0;

		for (int j = 0; j < n; j++) {

			x += p[((i + j) % n) == 0 ? n : ((i + j) % n)].a;

			y += p[((i + j) % n) == 0 ? n : ((i + j) % n)].b;

			ans = max(ans, get(x, y));

		}

	}

	cout << fixed << setprecision(20) << ans << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cmath>

#include <cstdio>

#include <algorithm>

using namespace std;

typedef long long ll;

const double pi = acos(-1);

struct data

{

	ll x , y;

	double ang;

	bool operator<(const data &a)const {return ang < a.ang;}

} a[400010];

int main()

{

	int n , i , p;

	ll sx = 0 , sy = 0 , ans = 0;

	scanf("%d" , &n);

	for (i = 1 ; i <= n ; i ++ ) scanf("%lld%lld" , &a[i].x , &a[i].y) , a[i].ang = atan2(a[i].y , a[i].x);

	sort(a + 1 , a + n + 1);

	for (p = i = 1 ; i <= n ; i ++ )

	{

		while (p < i + n && a[p].ang - a[i].ang < pi) sx += a[p].x , sy += a[p ++ ].y , ans = max(ans , sx * sx + sy * sy);

		sx -= a[i].x , sy -= a[i].y , ans = max(ans , sx * sx + sy * sy);;

		a[i + n].x = a[i].x , a[i + n].y = a[i].y , a[i + n].ang = a[i].ang + 2 * pi;

	}

	printf("%.18f\n" , sqrt(1.0 * ans));

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int blk;

struct node{

    int left,right;

    int index;

};

static bool compare(node& p1,node& p2){

    if(p1.left/blk==p2.left/blk)

    return p1.right<p2.right;

    return p1.left<p2.left;

}

int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int n,m;

    cin>>n>>m;

    blk=sqrt(n);

    vector<int> a(n,0);

    for(int i=0;i<n;i++)

    cin>>a[i];

    vector<node> q;

    q.resize(m);

    for(int i=0;i<m;i++){

        int l,r;

        cin>>l>>r;

        node p;

        p.left=l,p.right=r,p.index=i;

        q[i]=p;

    }

    sort(q.begin(),q.end(),compare);

    vector<int> freq(500001,0);

    vector<int> ans(m,0);

    int ml=0,mr=-1,count=0;

    for(int i=0;i<m;i++){

        int l=q[i].left-1,r=q[i].right-1;

        int ind=q[i].index;

        while(ml>l)

        if(++freq[a[--ml]]==1)

        count++;

        while(mr<r)

        if(++freq[a[++mr]]==1)

        count++;

        while(ml<l)

        if(--freq[a[ml++]]==0)

        count--;

        while(mr>r)

        if(--freq[a[mr--]]==0)

        count--;

        ans[ind]=count;

    }

    for(auto &i:ans)

    cout<<i<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define REP(i,n) for (int i = 1; i <= n; i++)

#define mod 1000000007

#define pb push_back

#define ff first

#define ss second

#define ii pair<int,int>

#define vi vector<int>

#define vii vector<ii>

#define lli long long int

#define INF 1000000000

#define endl '\n'

#define BLOCK 710

const double PI = 3.141592653589793238460;

typedef std::complex<double> Complex;

typedef std::valarray<Complex> CArray;

 

using namespace std;

struct query{

	int l;

	int r;

	int i;

};

query Q[500001];

int ar[500001] , ans[500001];

int fre[500001];

int cnt = 0;

 

bool comp(query a , query b)

{

	if(a.l / BLOCK != b.l/BLOCK)

	return a.l/BLOCK < b.l/BLOCK;

	

	return a.r < b.r;

}

 

void add(int pos)

{

	fre[ar[pos]]++;

	if(fre[ar[pos]] == 1)

	cnt++;

}

 

void remove(int pos)

{

	fre[ar[pos]]--;

	if(fre[ar[pos]] == 0)

	cnt--;

}

 

int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	

	int n , q;

	cin>>n>>q;

	for(int i=0;i<n;i++)

	cin>>ar[i];

	

	for(int i=0;i<q;i++){

		cin>>Q[i].l>>Q[i].r;

		Q[i].i = i , Q[i].l-- , Q[i].r--;

	}

	

	sort(Q , Q+q , comp);

	

	//why ML = 0 , and MR = -1?

	int ML = 0 , MR = -1;

	for(int i=0;i<q;i++)

	{

		int L = Q[i].l;

		int R = Q[i].r;

		

		while(ML > L)

		ML-- , add(ML);

		

		while(MR < R)

		MR++ , add(MR);

		

		while(ML < L)

		remove(ML) , ML++;

		

		while(MR > R)

		remove(MR) , MR--;

		

		ans[Q[i].i] = cnt;

	}

	

	for(int i=0;i<q;i++)

	cout<<ans[i]<<'\n';

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma GCC optimize(3,"Ofast","inline")

#include<bits/stdc++.h>

using namespace std;

const int N=1e6+10;

int bl,t,n,m;

int res,a[N],cnt[N],ans[N];

int curR,curL;

struct node

{

  int l,r,p;

  bool operator <(const node &W)const

  {

    return l<W.l;

  }

}e[N];

bool cmp(const node &a,const node &b)

{

  return (a.l/bl)==(b.l/bl) ?  a.r<b.r : a.l>b.l;

}

void remove(int i)

{

  if((--cnt[a[i]])==0) res--;

}

void add(int i)

{

  if((++cnt[a[i]])==1) res++;

}

int main()

{



     memset(ans,0,sizeof(ans));

     memset(cnt,0,sizeof(cnt));

     scanf("%d %d",&n,&m);

     for(int i=1;i<=n;i++) scanf("%d",&a[i]);



     bl=sqrt(n);

     for(int i=1;i<=m;i++)

     {

       scanf("%d %d",&e[i].l,&e[i].r);

       e[i].p=i;

     }

     sort(e+1,e+1+m,cmp);

     res=0;

     curL=1;curR=0;

     for(int i=1;i<=m;i++)

     {

       int L=e[i].l,R=e[i].r;

       while(curL<L) remove(curL++);

       while(curL>L) add(--curL);

       while(curR<R) add(++curR);

       while(curR>R) remove(curR--);

       ans[e[i].p]=res;

     }

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



}




// Optimized solution to the same problem (faster):
#pragma GCC optimize(3,"Ofast","inline")

#include<bits/stdc++.h>

using namespace std;

const int N=5e5+10;

int cnt[N],ans[N],a[N];

int n,q,bl;

int res;

struct node

{

    int l,r,p;



}e[N];

bool cmp(const node &a,const node &b)

{

    return (a.l/bl)==(b.l/bl) ? a.r<b.r :a.l<b.l;

}

void remove(int x)

{

    if((--cnt[a[x]])==0) res--;

}

void add(int x)

{

    if((++cnt[a[x]])==1) res++;

}

int main()

{

    scanf("%d %d",&n,&q);

    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

     bl=sqrt(n);

    for(int i=1,l,r;i<=q;i++)

    {

        scanf("%d %d",&l,&r);

        e[i]={l,r,i};

    }

  //  cout<<"--------------"<<endl;



    sort(e+1,e+1+q,cmp);

   // cout<<"*****"<<endl;

    res=0;

    int curL=1,curR=0;

    for(int i=1;i<=q;i++)

    {

        //cout<<i<<endl;

        int L=e[i].l,R=e[i].r;

        while(curL<L) remove(curL++);

        while(curL>L) add(--curL);

        while(curR<R) add(++curR);

        while(curR>R) remove(curR--);

        ans[e[i].p]=res;

    }

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



}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)

#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)

#define EREP(i,u) for(int i=start[u];i;i=e[i].next)

#define fi first

#define se second

#define mkr(a,b) make_pair(a,b)

#define SZ(A) ((int)A.size())

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

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

inline int read()

{

	int s=0,f=1; char ch=getchar();

	while(!isdigit(ch) && ch!='-')ch=getchar();

	if(ch=='-')ch=getchar(),f=-1;

	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();

	return ~f?s:-s;

}



const int maxn=5e3+20;



int n,mod;

int dp[maxn];



inline void init()

{

	n=read();mod=read();

}



inline void pls(int &a,int b){ a+=b; a-=a>=mod?mod:0;}



int f[maxn][maxn];



inline void doing()

{

	int len=n-1>>1;

	dp[0]=1;

	REP(i,1,len+(~n&1))

	{

		int w=i;

		for(int j=w;j<=n;j++)

			pls(dp[j],dp[j-w]);

	}

	f[0][0]=1;

	REP(i,1,n)

	{

		REP(j,0,n)f[i][j]=f[i-1][j];

		REP(j,i,n)pls(f[i][j],f[i][j-i]);

	}

	DREP(i,n,1)

	{

		int s=0;

		REP(j,0,n)

		{

			pls(s,f[i-1][j]);

			int nj=j+len+1;

			if(nj<=n)pls(f[i][nj],mod-s);

		}

	}

	int ans=0;

	REP(x,1,n)

	{

		int a=x-1,mx=n-x;

		int suf=0;

		DREP(j,a,0)

		{

			suf=(suf+dp[a-j])%mod;

			ans=(ans+(ll)suf*f[mx][j])%mod;

		}

	}

	printf("%d\n",ans);

}



int main()

{

	init();

	doing();

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

int f[5007];

int min(int a,int b){return a<b? a:b;}

int main()

{

    int n,p,ans=0;

    scanf("%d%d",&n,&p),f[0]=1;

    for(int i=1;i<n;++i) for(int k=min(i,n-i+1),j=k;j<n;++j) (f[j]+=f[j-k])%=p;

    for(int i=0;i<n;++i) (ans+=1ll*(n-i)*f[i]%p)%=p;

    printf("%d",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<algorithm>

using namespace std;

int D[5010][5010], n, Mod, C[5010];

void Make(int t) {

	int i, j;

	for (i = 0; i <= n / (t+1); i++) {

		for (j = t * i; j <= n-t; j++) {

			D[i + 1][j + t] = (D[i + 1][j + t] + D[i][j]) % Mod;

		}

	}

}

int main() {

	int i, j;

	scanf("%d%d", &n, &Mod);

	D[0][0] = 1;

	for (i = 2; i <= n; i++) {

		C[min(i - 2, n + 1 - i)]++;

	}

	for (i = n / 2; i >= 0; i--) {

		for (j = 0; j < C[i]; j++) {

			Make(i);

		}

	}

	int res = 0;

	for (i = 0; i < n; i++) {

		for (j = 0; j <= n; j++) {

			res = (res + (long long)max(n - i - j, 0) * D[i][j]) % Mod;

		}

	}

	printf("%d\n", res);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

using namespace std;

int D[5010], n, Mod, C[5010];

void Make(int t) {

	int i;

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

		D[i+t] = (D[i+t] + D[i]) % Mod;

	}

}

int main() {

	int i;

	scanf("%d%d", &n, &Mod);

	D[0] = 1;

	for (i = 2; i <= n; i++) {

		Make(min(i - 1, n + 2 - i));

	}

	int res = 0;

	for (i = 0; i < n; i++) {

		res = (res + 1ll * (n - i)*D[i]) % Mod;

	}

	printf("%d\n", res);

}

// Fastest known solution for this problem: