stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <cstdio>

#include <cstring>



const int MaxN = 3000, MaxM = 3000;

const int Mod = 998244353;



int N, M, Ans;

int A[MaxN + 5];

int F[MaxM + 5], Buc[MaxM + 5];



inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }

inline int sub(int x, int y) { return (x -= y) < 0 ? x + Mod : x; }

inline int mul(int x, int y) { return 1LL * x * y % Mod; }

inline void inc(int &x, int y = 1) { x = add(x, y); }



void init() {

  scanf("%d %d", &N, &M);

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

}



void fun(int l, int r) {

  if (l == r) {

    if (A[l] == M) inc(Ans);

    return;

  }

  int m = (l + r) >> 1;

  fun(l, m);

  fun(m + 1, r);

  memset(Buc, 0, sizeof Buc);

  memset(F, 0, sizeof F);

  F[0] = 1;

  for (int i = m; i >= l; --i) {

    for (int j = M; j >= A[i]; --j) inc(F[j], F[j - A[i]]);

    for (int j = 0; j <= M; ++j) inc(Buc[j], F[j]);

  }

  memset(F, 0, sizeof F);

  F[0] = 1;

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

    for (int j = M; j >= A[i]; --j) inc(F[j], F[j - A[i]]);

    for (int j = 0; j <= M; ++j) inc(Ans, mul(F[j], Buc[M - j]));

  }

}



void solve() {

  fun(1, N);

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

}



int main() {

  init();

  solve();

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1804594042437575x):
#include <cstdio>



const int MaxN = 3000;

const int Mod = 998244353;



int N, M;

int A[MaxN + 5];

int F[MaxN + 5][3];



inline int add(int x, int y) { return (x += y) >= Mod ? x - Mod : x; }

inline void inc(int &x, int y = 1) { x = add(x, y); }



void init() {

  scanf("%d %d", &N, &M);

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

}



void solve() {

  F[0][0] = 1;

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

    for (int j = 0; j <= M; ++j) inc(F[j][1], F[j][0]);

    for (int j = M; j >= A[i]; --j) inc(F[j][1], F[j - A[i]][1]);

    for (int j = 0; j <= M; ++j) inc(F[j][2], F[j][1]);

  }

  printf("%d\n", F[M][2]);

}



int main() {

  init();

  solve();

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define ll long long

#define ar array



const int mxN=3e3, M=998244353;

int n, s, a[mxN];

ll dp[mxN+1][mxN+1], ans;



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0);



	cin >> n >> s;

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

		cin >> a[i];

		memcpy(dp[i+1], dp[i], sizeof(dp[0]));

		//start a new sequence

		dp[i+1][a[i]]=(dp[i+1][a[i]]+i+1)%M;

		for(int j=0; j+a[i]<=s; ++j)

			dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%M;

		ans=(dp[i+1][s]+ans)%M;

	}

	cout << ans;

}


// Faster C++ solution for the same problem (measured speedup: 1.4056127714676503x):
#include<bits/stdc++.h>

using namespace std;



const int M = 998244353;



int main(){

    int n,s;

    cin>>n>>s;



    vector<int> arr(n);

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



    vector<int> dp(s+1);



    int res = 0;

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

        for(int j = s - arr[i]; j>=0; j--){

            dp[j+arr[i]]+=dp[j];

            dp[j+arr[i]]%=M;

        }

        if(arr[i]<=s){

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

        }

    

        res += dp[s]%M;

        res%=M;

    }

    cout<<res;

}
// Slower C++ solution:
#include<iostream>

#include<fstream>

#include <cmath>

#include <algorithm>

#include <stack>

#include <vector>

#include <random>

#include <set>

using namespace std;

typedef long long ll;





int main(){

	ll n,s,m=998244353,ans=0;

	cin >> n >> s;

	vector<ll> a(n),dp(3001,0),t,cls(3001,0);

	for(auto &&x:a)cin >> x;

	for(auto &&x:a){

		t = cls;

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

			( t[i] += dp[i] ) %= m;

			if(i+x<=3000)( t[i+x] += dp[i] ) %= m;

		}

		t[0]++;

		t[x]++;

		dp = t;

		( ans += dp[s] ) %= m;

	}

	cout << ans << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1352421867621778x):
#include<iostream>

#include<fstream>

#include <cmath>

#include <algorithm>

#include <stack>

#include <vector>

#include <random>

#include <set>

using namespace std;

typedef long long ll;





int main(){

	ll n,s,m=998244353,ans=0;

	cin >> n >> s;

	vector<ll> a(n),dp(3001,0),t(3001,0);

	for(auto &&x:a)cin >> x;

	for(auto &&x:a){

		fill(t.begin(), t.end(),0LL);

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

			( t[i] += dp[i] ) %= m;

			if(i+x<=3000)( t[i+x] += dp[i] ) %= m;

		}

		t[0]++;

		t[x]++;

		dp = t;

		( ans += dp[s] ) %= m;

	}

	cout << ans << endl;

}
// Slower C++ solution:
#include<iostream>

#include<fstream>

#include <cmath>

#include <algorithm>

#include <stack>

#include <vector>

#include <random>

#include <set>

using namespace std;

typedef long long ll;





int main(){

	ll n,s,m=998244353,ans=0;

	cin >> n >> s;

	vector<ll> a(n),dp(3001,0),t,cls(3001,0);

	for(auto &&x:a)cin >> x;

	for(auto &&x:a){

		t = cls;

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

			( t[i] += dp[i] ) %= m;

			if(i+x<=3000)( t[i+x] += dp[i] ) %= m;

		}

		t[0]++;

		t[x]++;

		dp = t;

		( ans += dp[s] ) %= m;

	}

	cout << ans << endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1849576523410554x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)





/*

https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-03-22abc-159





ans = sum_(i<=j){ f(i,j) }

  

    = f(1,1) +f(1,2) +f(1,3) +...

             +f(2,2) +f(2,3) +...

                     +f(3,3) +...



形式的べき級数で考えると





f(i,j-1) {i<j} について *(x^A[j] + 1) をやることで f(i,j) の分を足す

(x^A[j] + 1)を足すことで f(j,j) を足す



*/





int main(){

  ll ans = 0;

  ll mod = 998244353;

  ll N,S;

  cin >> N >> S;

  vector<ll> coefficient(3003,0);

  FOR(i,0,N){

    ll a;

    cin >> a;

    vector<ll> t = coefficient;

    FOR(j,a,S+1){

      (t[j] += coefficient[j-a]) %= mod;

    }

    t[a]++;

    t[0]++;

    coefficient = t;

    (ans += coefficient[S]) %= mod;

  }

  cout << ans << endl;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

const int mxn =  5e5+5;

const int inf = 0x3f3f3f3f;

typedef long long ll;

const ll mod =998244353; 

int n,m;

ll dp[mxn],v[mxn];

//dp[i] : 装满i容量的物品 的方案数 



int main()

{



	ll ans = 0;

	memset(dp,0,sizeof(dp));

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

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

	

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

	{

		dp[0] ++;

		for(int j = m;j>=v[i];j--)

		{

			dp[j] = ( dp[j]+dp[j-v[i]])%mod;

		}

		ans = (ans + dp[m])%mod;

	}

	printf("%lld",ans);

	

	

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.126460695232958x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 3005;

const int mod = 998244353;

#define pb push_back

#define pii pair<int,int>

#define fi first

#define se second

int t;

int n,m; 

int c[maxn];

int f[maxn];

int add(int a,int b){ a+=b; return a>=mod?a-mod:a;}  



int main()

{

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

	for(int i=1;i<=n;++i) scanf("%d",c+i);

	int ans = 0;

	for(int i=n;i>=1;--i)

	{

		++f[0];

		for(int j=m;j>=c[i];--j)

		{

			f[j] = add(f[j],f[j-c[i]]);

		}

		ans = add(ans,f[m]);

	}

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

}
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;

constexpr long long MOD = 998244353;



int main() {

	int n, s; cin >> n >> s;

	vector<int> a(n);

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



	vector<vector<long long>> dp(3, vector<long long>(s + 3003));

	dp[0][0] = 1;

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

		vector<vector<long long>> next(3, vector<long long>(s + 3003));

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

			(next[0][j] += dp[0][j]) %= MOD;

			(next[1][j] += dp[0][j] + dp[1][j]) %= MOD;

			(next[1][j + a[i]] += dp[0][j] + dp[1][j]) %= MOD;

			(next[2][j] += dp[0][j] + dp[1][j] + dp[2][j]) %= MOD;

			(next[2][j + a[i]] += dp[0][j] + dp[1][j]) %= MOD;

		}

		dp = next;

	}

	cout << dp[2][s];

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 2.5472939226206015x):
#include <iostream>

#include <vector>

using namespace std;

constexpr int MOD = 998244353;



int main() {

	int n, s;

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

	vector<int> a(n);

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



	vector<vector<int>> dp(3, vector<int>(s + 1));

	dp[0][0] = 1;

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

		vector<vector<int>> next(3, vector<int>(s + 1));

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

			(next[0][j] += dp[0][j]) %= MOD;

			(next[1][j] += (dp[0][j] + dp[1][j]) % MOD) %= MOD;

			(next[2][j] += ((dp[0][j] + dp[1][j]) % MOD + dp[2][j]) % MOD) %= MOD;

			if (j + a[i] <= s) {

				(next[1][j + a[i]] += (dp[0][j] + dp[1][j]) % MOD) %= MOD;

				(next[2][j + a[i]] += (dp[0][j] + dp[1][j]) % MOD) %= MOD;

			}

		}

		dp = next;

	}

	printf("%d", dp[2][s]);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

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

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

typedef tuple<ll,ll,ll> T;

const long long INF = 1LL<<60;

const int MOD = 1000000000+7;

#define rev(s) (string((s).rbegin(), (s).rend()))

// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定

// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max

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

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

// int dx[4]={1,0,-1,0};

// int dy[4]={0,1,0,-1};

// ~ は、-1の時だけfalse



int a[3010];

vector<ll> p(3010);



const int mod = 998244353;



int main () {



    int n,s;cin>>n>>s;



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



    ll ans=0;



    rep(i,n) {

        vector<ll> q(3010);

        p[0]++;

        rep(j,s+1) {

            q[j]=(q[j]+p[j])%mod;

            if (j+a[i]<=s) {

                q[j+a[i]]=(q[j+a[i]]+p[j])%mod;

            }

        }

        ans=(ans+q[s])%mod;

        p=q;

    }



    cout<<ans<<endl;





}

// Faster C++ solution for the same problem (measured speedup: 1.2730523080989582x):
#include <bits/stdc++.h>

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

#define chmax(x,y) x = max(x,y)

#define chmin(x,y) x = min(x,y)

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

typedef tuple<ll,ll,ll> T;

const long long INF = 1LL<<60;

const int MOD = 998244353;

#define rev(s) (string((s).rbegin(), (s).rend()))

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

// cout << fixed << setprecision(10) << ans << endl;

// *min_element(c + l, c + r) *max_element(c + l, c + r)

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

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

// int dx[4]={1,0,-1,0};

// int dy[4]={0,1,0,-1};

// struct Edge {

//   int to, id;

//   Edge(int to, int id): to(to), id(id) {}

// };





int main () {

  int N,S;cin>>N>>S;

  vector<int> a(N);

  rep(i,N) cin>>a[i];

  vector<ll> F(S+1,0),pre(S+1,0);

  ll ans = 0;

  rep(i,N) {

    pre[0] += 1;

    F = pre;

    rep(j,S+1) {

      if(j+a[i] <= S){

	F[j+a[i]] += pre[j];

	F[j+a[i]] %= MOD;

      }

    }

    pre = F;

    ans = (ans + F[S]) % MOD;

  }

  cout << ans << endl; 

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

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

#define FOR(i, a, b) for (ll i = a; i < b; i++)

#define is(a, b) a == b

#define len(v) ll(v.size())



//vector書き出し

template <class T>

void cout_vec(const vector<T> &vec1){

  rep(i,len(vec1)){

    cout<<vec1[i]<<' ';

  }

  cout<<'\n';

}



typedef pair<ll,ll> P;

const ll mod=1e9+7;



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    ll x;

    cin>>x;

    vector<ll> sum;

    sum.push_back(1);

    ll cnt=2;

    while(sum.back()<=1e9){

      sum.push_back(cnt+sum.back());

      cnt++;

    }

    cout<<lower_bound(begin(sum),end(sum),x)-begin(sum)+1<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 2.428576080124018x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

typedef pair<ll,ll> P;

typedef pair<int,int> Pi;

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

#define FOR(i,a,b) for(ll i=a;i<b;i++)

#define fi first

#define se second

#define endl "\n"



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

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

template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}

template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}

template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}



const ll mod=1e9+7;

const ll inf=1e17;

const int INF=1e9;

const double PI=acos(-1);

const double EPS=1e-10;



int main(){

	cin.tie(0);ios::sync_with_stdio(false);

	ll x;

	cin>>x;

	ll n;

	rep(i,1e9){

		if(i*(i+1)>=2*x){

			n=i;

			break;

		}

	}

	ll y=n*(n+1)/2-x;

	if(y<=n){

		cout<<n<<endl;

	}else{

		cout<<y<<endl;

	}

}
// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <vector>

#include <string>

#include <map>

#include <algorithm>

#include <tuple>

#include <set>

#include <stack>

#include <queue>

#include <deque>

#include <cstdio>

#include <numeric>

#define REP(i, n) for(LL i = 0;i < n;i++)

#define REPR(i, n) for(LL i = n;i >= 0;i--)

#define FOR(i, m, n) for(LL i = m;i < n;i++)

#define FORR(i, m, n) for(LL i = m;i >= n;i--)

#define SORT(v, n) sort(v, v+n);

#define VSORT(v) sort(v.begin(), v.end());

#define pb(a) push_back(a)

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

#define INF (LL)1e15

#define MOD 1000000007

using namespace std;

typedef long long LL;

typedef pair<int, int> P;

typedef pair<LL, LL> LP;

typedef pair<int, P> PP;

typedef pair<LL, LP> LPP;

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

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



/*************** using variables ***************/

LL x;

vector<LL> ruiseki;

/**********************************************/



int main(){

    cin >> x;

    ruiseki.resize(1000000);

    

    ruiseki[0] = 0;



    LL i = 0;

    while(1){

        ruiseki[i+1] = ruiseki[i] + i+1;

        if(ruiseki[i+1] >= x){

            break;

        }

        i++;

    }

    cout << min(x, i+1) << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 9.333664091543554x):
#include <bits/stdc++.h>

//#define int long long



using namespace std;

using LL = long long;

using P = pair<int, int>;



#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)

#define REP(i, n) FOR(i, 0, n)



#define pb(a) push_back(a)

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



const int INF = (int)1e9;

const LL INFL = (LL)1e15;

const int MOD = 1e9 + 7;



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

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



signed main(){

    cin.tie(0);

    ios::sync_with_stdio(false);



    int x;

    cin >> x;

    int ans = 0, sum = 0;

    for(int i = 1; sum < x; i++){

        sum += i;

        ans++;

    }

    cout << ans << endl;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define mod 1000000007

#define ll long long int

#define ar array

#define mp make_pair

using namespace std;



int main()

{

	ios::sync_with_stdio(false);

	cin.tie(NULL);

	int x;

	cin>>x;

	ll ans = 0, j= 0;

	ll a[int(1e5)];

	memset(a,0x3f,sizeof(a));

	a[0] = x;

	int i = 0;

	for(i = 1;i<x;i++)

	{

		ans = i*(i+1)/2;

		a[i] = i+(x-ans);

		if(ans>x)

		{

			a[i] = i;

			break;

		}

	}

	cout<<*min_element(a,a+int(1e5))<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.8796826834924827x):
#include<bits/stdc++.h>

#define mod 1000000007

#define ll long long int

#define ar array

#define mp make_pair

using namespace std;



int main()

{

	ios::sync_with_stdio(false);

	cin.tie(NULL);

	int x;

	cin>>x;

	for(int i = sqrt(x);i<=x;i++)

	{

		ll ans = i*(i+1)/2;

		if(ans>=x)

		{

			cout<<i<<endl;

			break;

		}

	}

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=311,maxt=200011;

int n,m,t,s[maxn],w[maxn][maxn],a[maxt],b[maxt];

void init(){

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

    for (int i=1;i<=m;++i) scanf("%d",s+i);

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

    for (int i=1;i<=t;++i) scanf("%d%d",a+i,b+i);

}

bool check(int t){

    static int sx[maxn]; memcpy(sx,s,sizeof(s));

    static int wx[maxn][maxn]; memset(wx,0,sizeof(w));

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

        --sx[b[i]]; ++wx[a[i]][b[i]];

    }

    static bool vis[maxn]; memset(vis,0,sizeof(vis));

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

        for (int i=1;i<=n;++i) if (!vis[i]){

			bool flag=1;

			for (int j=1;j<=m;++j) if (wx[i][j]+max(0,sx[j])<w[i][j]){flag=0; break;}

            if (flag){

				vis[i]=1;

				for (int j=1;j<=m;++j) sx[j]+=wx[i][j];

            }

        }

    }

	for (int i=1;i<=n;++i) if (!vis[i]) return true;

	return false;

}

void work(){

    int t=1,w=::t;

    while (t<=w){

		int mid=(t+w)>>1;

		if (check(mid)) w=mid-1;else t=mid+1;

    }

    printf("%d\n",w==::t?-1:w+1);

}

int main(){

	init();

	work();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4796250204445542x):
#include <bits/stdc++.h>

#define fi first

#define se second

#define mp make_pair

using namespace std;



typedef pair <int, int> pii;



int p, r, t;

int l[310], nl[310];

int n[310][310], nn[310][310];

pii a[200010];

int cnt[310];



bool check(int mid){

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

		nl[i] = l[i];

	}

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

		cnt[i] = 0;

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

			nn[i][j] = n[i][j], cnt[i] += n[i][j];

		}

	}

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

		int P = a[i].fi, R = a[i].se;

		nl[R]--, nn[P][R]--, cnt[P]--;

		if (cnt[P] == 0){

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

				nl[j] += n[P][j];

			}

		}

	}

	int pd = 1;

	while (pd){

		pd = 0;

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

			int flag = 1, ppp = 1;

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

				if (nl[j] < nn[i][j]){

					flag = 0;

					break;

				}

				if (nn[i][j]) ppp = 0;

			}

			if (!flag || ppp) continue;

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

				nl[j] += n[i][j] - nn[i][j];

				nn[i][j] = 0;

			}

			pd = 1;

		}

	}

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

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

			if (nn[i][j]) return 1;

		}

	}

	return 0;

}



int main(){

	scanf("%d%d%d", &p, &r, &t);

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

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

	}

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

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

			scanf("%d", &n[i][j]);

		}

	}

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

		scanf("%d%d", &a[i].fi, &a[i].se);

	}

	if (!check(t - 1)){

		printf("-1\n");

		return 0;

	}

	int l = 0, r = t - 1;

	while (l < r){

		int mid = l + r >> 1;

		if (!check(mid)) l = mid + 1;

		else r = mid;

	}

	printf("%d\n", l + 1);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define pi 3.1415926535897932384626

using namespace std;



struct vec

{

    long double x,y;

    bool operator ==(const vec &a) const{

        return x==a.x&&y==a.y;

    }

    bool operator <(const vec &a) const{

        if(a.x!=x) return x<a.x;

        return y<a.y;

    }

    vec operator +(const vec &a) const{

        return {x+a.x,y+a.y};

    }

    vec operator *(const long double &a) const{

        return {x*a,y*a};

    }

    vec operator -(const vec &a) const{

        return {x-a.x,y-a.y};

    }

    vec operator /(const long double &a) const{

        return {x/a,y/a};

    }

    long double len() const{

        return (x*x+y*y);

    }

    long double dot(const vec &a) const{

        return x*a.x+y*a.y;

    }

    long double crs(const vec &a) const{

        return x*a.y-y*a.x;

    }

    vec proj(const vec &a) const{

        return (a/a.len())*(*this).dot(a)/a.len();

    }

};





struct P

{

    int x,y;

    bool operator <(const P &a) const{

        //if(x!=a.x)

         return x>a.x;



    }

};





long long x,y,z,mod=998244353;

//vector<long long> v,v1;

vector<P> v[300110];

//vector<long long> v1;

int i,n,m,k,a,d,b,c,h,dx[10]={1,0,-1,0},dy[10]={0,1,0,-1};

int e;

int l[311111];



int o[311111];



int j[211111];

stack<int> s;

//set<int> s;

queue<int> q,q1;

P u[1],u1[3];

//char r[1],r1[3];

string r,r1;

//2147483647

//'1'==49;

//'A'==65;

//'a'==97;

//unordered_

map<int,int> p;



//v.resize(unique(v.begin(),v.end())-v.begin());



//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//rng();



bool as(P a,P b)

{

    return a.y<b.y;

}





int main()

{

    scanf("%lld %lld %lld",&x,&y,&z);

    if((z-y)%2==0) printf("%lld",(z-y)/2);

        else printf("%lld",min(y+(z-y)/2,x-z+1+(z-y)/2));

}




// Faster C++ solution for the same problem (measured speedup: 9.43980993963635x):
#include<bits/stdc++.h>

#define pi 3.1415926535897932384626

using namespace std;

      

struct P{

  int x,y;

  bool operator < (const P &a )const{

    //if(y!=a.y)

    return y>a.y;

  };

};



int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};

int o[1];

int l[5];

int j[1];



long long x,y,z,mod=1000000007;

//string r;

char r[1];



P u[1];

queue<int> q;



//stack<int> s;

set<int> s;

map<int,int> p;

vector<P> v;



bool as(P a,P b)

{

  if(a.x==b.x)

  return a.y<b.y;

  return a.x<b.x;

}





int main()

{

  scanf("%lld %lld %lld",&z,&y,&x);

  if(x>y) swap(x,y);

  if((x-y)%2==0) printf("%lld",(y-x)/2);

  else

  {

    printf("%lld",min(x-1,z-y)+(y-x+1)/2);

  }

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

using namespace std;

int a[1010],sum1[1010],sum2[1010],sum[1010];long long Sum1=0,Sum2=0,Sum;int cnt2=0,cnt1=0,cnt=0;

int ans[1010],Cnt=0;

int main()

{

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

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

	for(int i=1;i<=n;i+=2)if(a[i]>0)sum1[++cnt1]=i,Sum1+=a[i];

	for(int i=2;i<=n;i+=2)if(a[i]>0)sum2[++cnt2]=i,Sum2+=a[i];

	if(Sum1>Sum2){for(int i=1;i<=cnt1;i++)sum[i]=sum1[i];Sum=Sum1;cnt=cnt1;}

	else {for(int i=1;i<=cnt2;i++)sum[i]=sum2[i];Sum=Sum2;cnt=cnt2;}

	if(Sum==0)

	{

		int Max=-1e9-7,id;

		for(int i=1;i<=n;i++)if(a[i]>Max)Max=a[i],id=i;

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

		for(int i=n;i>id;i--)ans[++Cnt]=i;

		for(int i=1;i<id;i++)ans[++Cnt]=1;

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

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

		return 0; 

	}

	printf("%lld\n",Sum);

	int l=sum[1],r=sum[cnt],K=0;

	for(int i=n;i>r;i--)ans[++Cnt]=i;

	for(int i=1;i<l;i++)ans[++Cnt]=1;

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

	{

		K++;

		int mid=(sum[i]-sum[i-1])>>1;

		for(int j=mid;j>=1;j--)ans[++Cnt]=1+j;

	}

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

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.107728543605883x):
#include<cstdio>

#include<algorithm>

#include<cstring>

#define MN 10005

using namespace std;

typedef long long ll;

int n,fr[MN],maxn=1,ans[MN],res[MN],tt,tans;ll a[MN],f[MN];

int main(){

	scanf("%d",&n);

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

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

		for(int j=1;j<i;j++)if((i-j)%2==0&&f[j]+a[i]>f[i])f[i]=f[j]+a[i],fr[i]=j;

	for(int i=2;i<=n;i++)if(f[i]>f[maxn])maxn=i;printf("%lld\n",f[maxn]);

	for(int i=n;i>maxn;i--)res[++tans]=i;int tmp=maxn;ans[++tt]=maxn;

	while(fr[tmp])ans[++tt]=fr[tmp],tmp=fr[tmp];

	for(int i=1;i<ans[tt];i++)res[++tans]=1;

	for(int i=tt-1;i>=1;i--){

		for(int j=(ans[i]+ans[i+1])/2-ans[i+1]+1;j>1;j--)res[++tans]=j;

	}printf("%d\n",tans);

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

}