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

#include <algorithm>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */



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

	int A,B,C,D;

	while(cin>>A>>B>>C>>D)

	{

		int ta=max(A,C),tc=min(B,D);

		if(tc-ta<0)

			ta=0;

		else

			ta=tc-ta;

		cout<<ta<<endl;

	}

	

	return 0;

}

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

#include<math.h>



int main()

{

    int a,b,c,d;

    int i,j,k,l,m,n;

    while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)

    {

        if(b<=c||d<=a)

        {

            printf("0\n");

        }

        else

        {

            i=a<c?a:c;

            j=a+c-i;

            k=b<d?b:d;

            l=b+d-k;

            printf("%d\n",k-j);

        }

    }

    return 0;

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

#include <algorithm>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */



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

	int A,B,C,D;

	while(cin>>A>>B>>C>>D)

	{

		int ta=max(A,C),tc=min(B,D);

		if(tc-ta<0)

			ta=0;

		else

			ta=tc-ta;

		cout<<ta<<endl;

	}

	

	return 0;

}

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

using namespace std;

int main()

{

	int A1,A2,B1,B2,a=0;

	scanf("%d%d%d%d",&A1,&A2,&B1,&B2);

	if(A2<=B1||B2<=A1)

    	a=0;

	else if(A1>=B1)

	{

		a=B2-A1;

		if(A2<B2)

			a=A2-A1;

	}

	else if(B1>=A1)

	{

		a=A2-B1;

		if(B2<A2)

			a=B2-B1;

	}

	printf("%d",a);

	return 0;

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

#include <algorithm>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */



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

	int A,B,C,D;

	while(cin>>A>>B>>C>>D)

	{

		int ta=max(A,C),tc=min(B,D);

		if(tc-ta<0)

			ta=0;

		else

			ta=tc-ta;

		cout<<ta<<endl;

	}

	

	return 0;

}

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



int main()

{

    int a, b, c, d;

    int s, e, t;

    while(scanf("%d%d%d%d", &a, &b, &c, &d) != EOF)

    {

        if(b <= c || d <= a)

            t = 0;

        else

        {

            s = (a > c) ? a : c;

            e = (b < d) ? b : d;

            t = e - s;

        }

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

    }

    return 0;

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

#include<vector>

#include<cmath>

#include<algorithm>

using namespace std;

int main()

{

	int a[4];

	cin>>a[0]>>a[1]>>a[2]>>a[3];

	if((a[1]<=a[2])||(a[3]<=a[0]))

        cout<<'0';

    else

    {

    	sort(a,a+4);

    	cout<<a[2]-a[1];

	}

}

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



int main()

{

    int a, b, c, d;

    int s, e, t;

    while(scanf("%d%d%d%d", &a, &b, &c, &d) != EOF)

    {

        if(b <= c || d <= a)

            t = 0;

        else

        {

            s = (a > c) ? a : c;

            e = (b < d) ? b : d;

            t = e - s;

        }

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

    }

    return 0;

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

#include<cmath>

using namespace std;



int main()

{

	int a_s,a_r,b_s,b_r,min,max;

	cin>>a_s>>a_r>>b_s>>b_r;

	min=a_r>b_r?b_r:a_r;

	max=a_s>b_s?a_s:b_s;

	if(min-max>0)

		cout<<min-max;

	else

		cout<<0;

	return 0;

 }

  

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

#include<algorithm>

int main()

{

	int a,b,c,d;

	scanf("%d%d%d%d",&a,&b,&c,&d);

	printf("%d\n",std::max(0,std::min(b,d)-std::max(a,c)));

	return 0;

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

using namespace std;

int main(){

int a,b,c,d,cnt=0;

cin>>a>>b>>c>>d;

//for(int i=0;i<100;i++)

for( int i=100;i>0;i--)

if(a<i && b>=i && c<i && d>=i){

    cnt++;

}

cout<<cnt<<"\n";

}

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

#include<algorithm>

int main()

{

	int a,b,c,d;

	scanf("%d%d%d%d",&a,&b,&c,&d);

	printf("%d\n",std::max(0,std::min(b,d)-std::max(a,c)));

	return 0;

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

using namespace std;

int main(){

	int a,b,c,d;

	cin>>a>>b>>c>>d;

if(b>c&&d>a)

cout<<abs(min(b,d)-max(a,c));

else

cout<<0;

	}

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

#include<algorithm>

int main()

{

	int a,b,c,d;

	scanf("%d%d%d%d",&a,&b,&c,&d);

	printf("%d\n",std::max(0,std::min(b,d)-std::max(a,c)));

	return 0;

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

#include<cmath>

using namespace std;



int main()

{

	int a_s,a_r,b_s,b_r,min,max;

	cin>>a_s>>a_r>>b_s>>b_r;

	min=a_r>b_r?b_r:a_r;

	max=a_s>b_s?a_s:b_s;

	if(min-max>0)

		cout<<min-max;

	else

		cout<<0;

	return 0;

 }

  

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

#include<string.h>



int main ()

{

    int a,b,c,d,x,y;

    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(a>c) x=a;

    else x=c;

    if(b>d) y=d;

    else y=b;

    if(x>y) printf("0");

    else printf("%d",y-x);

    return 0;

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

using namespace std;

int main(){

int a,b,c,d,cnt=0;

cin>>a>>b>>c>>d;

//for(int i=0;i<100;i++)

for( int i=100;i>0;i--)

if(a<i && b>=i && c<i && d>=i){

    cnt++;

}

cout<<cnt<<"\n";

}

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

#include<string.h>



int main ()

{

    int a,b,c,d,x,y;

    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(a>c) x=a;

    else x=c;

    if(b>d) y=d;

    else y=b;

    if(x>y) printf("0");

    else printf("%d",y-x);

    return 0;

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

using namespace std;

int main(){

	int a,b,c,d;

	cin>>a>>b>>c>>d;

if(b>c&&d>a)

cout<<abs(min(b,d)-max(a,c));

else

cout<<0;

	}

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

#include<string.h>



int main ()

{

    int a,b,c,d,x,y;

    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(a>c) x=a;

    else x=c;

    if(b>d) y=d;

    else y=b;

    if(x>y) printf("0");

    else printf("%d",y-x);

    return 0;

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

using namespace std;

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

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

#define REPR(i, k, n) for(int i=k; i>=n; --i)

#define MAX 2001

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define r return

typedef long long ll;

typedef long long int lli;

typedef unsigned long long ull;

typedef unsigned int long long uill;

int main(){



	ios::sync_with_stdio(0);

	cin.tie(0);

	set<char> s1;

	vector<int> v;

	int cnt=0;

	int flag=1;

    int a,b,c,d;



    cin>>a>>b>>c>>d;



     int ma = max(a,c);

     int mi = min(b,d);



    

    cout << max(0, mi-ma) << "\n";



   //50 55 25 40







  // ----------50------55----

  // ---25-40------



    return 0;





}

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

#include<string.h>



int main ()

{

    int a,b,c,d,x,y;

    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(a>c) x=a;

    else x=c;

    if(b>d) y=d;

    else y=b;

    if(x>y) printf("0");

    else printf("%d",y-x);

    return 0;

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

#include<string.h>



using namespace std;



int main()

{

    int a,b,c,d;

    cin>>a>>b>>c>>d;

    if(a<=c)

    {

        if(b<=c)

        {

            cout<<"0";

        }

        else

        {

            if(b>=d)

            {

                cout<<(d-c);

            }

            else

            {

                cout<<(b-c);

            }

        }

    }

    else if(a>=d)

    {

        cout<<"0";

    }

    else

    {

        if(b<=d)

        {

            cout<<(b-a);

        }

        else

        {

            cout<<(d-a);

        }

    }

    return 0;

}




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

#include<string.h>



int main ()

{

    int a,b,c,d,x,y;

    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(a>c) x=a;

    else x=c;

    if(b>d) y=d;

    else y=b;

    if(x>y) printf("0");

    else printf("%d",y-x);

    return 0;

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

using namespace std;

int main()

{

    long long int a,b,m,mn,i;

    while(scanf("%lld %lld",&a,&b)!=EOF)

    {

        m=max(a,b);

      if(m==a)

      {

          mn=b;



      }

      else

        mn=a;

       //  printf("max= %lld min=%lld\n",m,mn);

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

      {

          if((m*i)%mn==0)

          {

              printf("%lld\n",m*i);

              break;

          }

      }

    }

    return 0;

}


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

int main()

{

    long long int a,b,t,gcd,lcm,x,y;

    while(scanf("%lld %lld",&a,&b)!=EOF)

    {

        x=a;

        y=b;

    if(a==0)

    gcd=a;

    else if(b==0)

        gcd=b;

    else

    {

    while(b!=0)

    {

        t=b;

        b=a%b;

        a=t;

    }

    gcd=a;

    }

    lcm=(x*y)/gcd;

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

    }

    return 0;

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

#include<vector>

#include<algorithm>

using namespace std;



int main(){

  vector<int> v,s(10001);

  int a,b,n,o=0;

  while(cin>>b){

    fill(s.begin(),s.end(),0);

    o =0;

    if(b==0) break;

    else{

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

      cin>>a;

      v.push_back(a);

    }

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

      int sum = 0;

      for(int j = i; j < b; j++){

	sum += v[j];

	s.push_back(sum);

      }

    } 





  int d = *max_element(s.begin(),s.end());

  cout<<d<<endl;

    }

    s.clear(),v.clear();

  }

}

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

#include <map>

#include <set>

#include <stack>

#include <queue>

#include <algorithm>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <string>

#include <cstring>

#include <complex>

#include <ctime>

#include <cstdlib>



using namespace std;



inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}

template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}



typedef long long ll;



int main()

{

	int n, T[5001], dp[5001];

	while(cin >> n, n)

	{

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

		{

			cin >> T[i];

		}



		memset(dp, -1, sizeof(dp));



		dp[0] = T[0];



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

		{

			dp[i] = max(dp[i-1] + T[i], T[i]);

		}



		int res = -10000000;

		

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

		{

			res = max(res, dp[i]);

		}



		cout << res << endl;

	}

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

#include<algorithm>

using namespace std;



int main(){

  int n;

  int a[5000];

  int tmp;

  int ans;



  while(1){

    cin >> n;

    if(!n)break;



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

      cin >> a[i];

    }



    ans = a[0];

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

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

	if(i==j)tmp = a[i];

	else tmp += a[j];

	ans = max(tmp,ans);

      }

    }



    cout << ans << endl;

  }

}

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

#include<algorithm>

using namespace std;



int main(){

  int n,tmp,ans;

  int a[5000];



  while(scanf("%d",&n) && n){

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

    

    ans = a[0];

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

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

	if(i==j)tmp = a[i];

	else tmp += a[j];

	ans = max(tmp,ans);

      }

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

  }

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

#define ll long long

using namespace std;

 

const ll mol = 1e9 + 7;

const int maxn = 2e5;

 

int a[maxn + 11],b[maxn + 11];

 

int main() {

	int k,n;

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

	int ca = 0 , cb = 0;

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

		int x;

		scanf("%d",&x);

		if (x >= 0) a[++ca] = x;

		else b[++cb] = -x;

	}

	sort(a + 1 , a + 1 + ca , [&](int x,int y) { return x > y; });

	sort(b + 1 , b + 1 + cb , [&](int x,int y) { return x > y; });

	if (ca == 0) {

		ll ans = 1;

		if (k % 2 == 1) {

			for (int i = cb; i >= cb - k + 1; i--)

				ans = ans * b[i] % mol;

			ans = mol - ans;

		}

		else {

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

				ans = ans * b[i] % mol;

		}

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

		return 0;

	}

	if (n == k) {

		ll ans = 1;

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

			ans = ans * a[i] % mol;

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

			ans = ans * b[i] % mol;

		if (cb & 1) ans = mol - ans;

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

		return 0;

	}

	int u,d;

	if (ca >= k) { u = k; d = 0; }

	else if ((k - ca) % 2 == 0) {

		u = ca; d = k - ca;

	}

	else {

		u = ca - 1; d = k - ca + 1;

	}

	while (1) {

		if (u < 2 || d + 2 > cb) break;

		if (1ll * a[u] * a[u - 1] > 1ll * b[d + 1] * b[d + 2]) break;

		u -= 2; d += 2;

	} 

	ll ans = 1;

	for (int i = 1; i <= u; i++) ans = ans * a[i] % mol;

	for (int i = 1; i <= d; i++) ans = ans * b[i] % mol;

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

} 

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

#include <cstdio>

using namespace std;

int n, k;

long long int a[200005], s[200005], ps = 0;

const long long MOD = 1e9 + 7;

int main() {

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

  long long res = 1;

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

    scanf("%lld", &a[i]);

  }

  sort(a, a + n);



  if (k % 2) {

    res = a[n - 1];

    int w = res > 0 ? 1 : -1;

    int l = 0, r = n - 2, cnt = 1;

    while (cnt < k && l < r) {

      if (w * a[l] * a[l + 1] > w * a[r] * a[r - 1]) {

        s[ps++] = a[l++];

        s[ps++] = a[l++];

        cnt += 2;

      } else {

        s[ps++] = a[r--];

        s[ps++] = a[r--];

        cnt += 2;

      }

    }

  } else {

    res = 1;

    int l = 0, r = n - 1, cnt = 0;

    while (cnt < k && l < r) {

      if (a[l] * a[l + 1] > a[r] * a[r - 1]) {

        s[ps++] = a[l++];

        s[ps++] = a[l++];

        cnt += 2;

      } else {

        s[ps++] = a[r--];

        s[ps++] = a[r--];

        cnt += 2;

      }

    }

  }

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

    res = (1l * (s[i] % MOD) * (res % MOD) + MOD) % MOD;

  }

  res = (res % MOD + MOD) % MOD;

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

  return 0;

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

using namespace std;

typedef long long ll;

const int N=2e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;

#define mst(a) memset(a,0,sizeof a)

#define lx x<<1

#define rx x<<1|1

#define reg register

#define PII pair<int,int>

#define fi first 

#define se second

ll a[N];

int main(){

	int n,k;

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

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

	sort(a,a+n);

	int l=0,r=n-1,w=1; 

	ll ans=1;

	if(k&1) ans=a[r--],k--,w=(ans<0?-1:1);

	while(k){

		ll x=a[l]*a[l+1],y=a[r]*a[r-1];

		if(x*w>y*w) ans=(ans*(x%mod))%mod,l+=2;

		else ans=(ans*(y%mod))%mod,r-=2;

		k-=2;

	}

	printf("%lld\n",(ans%mod+mod)%mod);

	return 0;

}


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

#include <cstdio>

using namespace std;

int n, k;

long long int a[200005], s[200005], ps = 0;

const long long MOD = 1e9 + 7;

int main() {

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

  long long res = 1;

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

    scanf("%lld", &a[i]);

  }

  sort(a, a + n);



  if (k % 2) {

    res = a[n - 1];

    int w = res > 0 ? 1 : -1;

    int l = 0, r = n - 2, cnt = 1;

    while (cnt < k && l < r) {

      if (w * a[l] * a[l + 1] > w * a[r] * a[r - 1]) {

        s[ps++] = a[l++];

        s[ps++] = a[l++];

        cnt += 2;

      } else {

        s[ps++] = a[r--];

        s[ps++] = a[r--];

        cnt += 2;

      }

    }

  } else {

    res = 1;

    int l = 0, r = n - 1, cnt = 0;

    while (cnt < k && l < r) {

      if (a[l] * a[l + 1] > a[r] * a[r - 1]) {

        s[ps++] = a[l++];

        s[ps++] = a[l++];

        cnt += 2;

      } else {

        s[ps++] = a[r--];

        s[ps++] = a[r--];

        cnt += 2;

      }

    }

  }

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

    res = (1l * (s[i] % MOD) * res) % MOD;

  }

  res = (res % MOD + MOD) % MOD;

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

  return 0;

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

using namespace std;

typedef long long ll;

const int N=2e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;

#define mst(a) memset(a,0,sizeof a)

#define lx x<<1

#define rx x<<1|1

#define reg register

#define PII pair<int,int>

#define fi first 

#define se second

ll a[N];

int main(){

	int n,k;

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

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

	sort(a,a+n);

	int l=0,r=n-1,w=1; 

	ll ans=1;

	if(k&1) ans=a[r--],k--,w=(ans<0?-1:1);

	while(k){

		ll x=a[l]*a[l+1],y=a[r]*a[r-1];

		if(x*w>y*w) ans=(ans*(x%mod))%mod,l+=2;

		else ans=(ans*(y%mod))%mod,r-=2;

		k-=2;

	}

	printf("%lld\n",(ans%mod+mod)%mod);

	return 0;

}


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

#include <cstdio>

using namespace std;

int n, k;

long long int a[200005], s[200005], ps = 0;

const long long MOD = 1e9 + 7;

int main() {

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

  long long res = 1;

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

    scanf("%lld", &a[i]);

  }

  sort(a, a + n);



  if (k % 2) {

    res = a[n - 1];

    int w = res > 0 ? 1 : -1;

    int l = 0, r = n - 2, cnt = 1;

    while (cnt < k && l < r) {

      if (w * a[l] * a[l + 1] > w * a[r] * a[r - 1]) {

        s[ps++] = a[l++];

        s[ps++] = a[l++];

        cnt += 2;

      } else {

        s[ps++] = a[r--];

        s[ps++] = a[r--];

        cnt += 2;

      }

    }

  } else {

    res = 1;

    int l = 0, r = n - 1, cnt = 0;

    while (cnt < k && l < r) {

      if (a[l] * a[l + 1] > a[r] * a[r - 1]) {

        s[ps++] = a[l++];

        s[ps++] = a[l++];

        cnt += 2;

      } else {

        s[ps++] = a[r--];

        s[ps++] = a[r--];

        cnt += 2;

      }

    }

  }

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

    res = (1l * (s[i] % MOD) * (res % MOD) + MOD) % MOD;

  }

  res = (res % MOD + MOD) % MOD;

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

  return 0;

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

#include <cmath>

using namespace std;



int main()

{

    int n,x=0,y=0;

    string s;

    cin>>n;

    cin>>s;

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

    {

        if(s[i]=='I') {x+=1; y=max(y,x);}

        else          {x-=1; y=max(y,x);}

    }

    cout << y << endl;

    return 0;

}


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



int main(){



	int n,x=0;

	int max = 0;

	scanf("%d",&n);

	char arr[n];

	

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

		scanf("%c",&arr[i]);

		if(arr[i] == 'I'){

			x++;

		}

		else if(arr[i] == 'D'){

			x--;

		}

		

		

		if(x >= max){

			max = x;

		}

	}



printf("%d",max);



	return 0;

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

#include <bits/stdc++.h>

#include <string>

#include <cmath>



using namespace std;





int main()

{

   int x=0;

   int mx=0;

   int n;

   char a;

   cin>>n;

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

   {

       cin>>a;

       if(a=='I') x+=1;

       else if(a=='D') x-=1;

    if(x>mx)

        mx=x;

   }

   cout<<mx;

     return 0;

}


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



int main(){



	int n,x=0;

	int max = 0;

	scanf("%d",&n);

	char arr[n];

	

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

		scanf("%c",&arr[i]);

		if(arr[i] == 'I'){

			x++;

		}

		else if(arr[i] == 'D'){

			x--;

		}

		

		

		if(x >= max){

			max = x;

		}

	}



printf("%d",max);



	return 0;

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



using namespace std;



int main() {

    long long len,x=0,maxx=0;

    string s;

    cin >> len>>s;

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

        if(s[i]=='I') x++;

        else if(s[i]=='D') x--;

        if(x>maxx){

            maxx=x;

        }

    }

    cout << maxx;

    return 0;

}

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



int main(){



	int n,x=0;

	int max = 0;

	scanf("%d",&n);

	char arr[n];

	

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

		scanf("%c",&arr[i]);

		if(arr[i] == 'I'){

			x++;

		}

		else if(arr[i] == 'D'){

			x--;

		}

		

		

		if(x >= max){

			max = x;

		}

	}



printf("%d",max);



	return 0;

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

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<algorithm>

//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector

//#include<bits/stdc++.h>

#define ll long long

using namespace std;





int main() {

	ios::sync_with_stdio(false);

	ll a,b,c,d;

	cin>>a;

	string s;

	cin>>s;

	ll sum=0;

	ll max1=0;

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

		if(s[i]=='I') {

			sum++;

		} else {

			sum--;

		}

		max1=max(sum,max1);

	}

	cout<<max1<<endl;

	return 0;

}

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



int main(){



	int n,x=0;

	int max = 0;

	scanf("%d",&n);

	char arr[n];

	

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

		scanf("%c",&arr[i]);

		if(arr[i] == 'I'){

			x++;

		}

		else if(arr[i] == 'D'){

			x--;

		}

		

		

		if(x >= max){

			max = x;

		}

	}



printf("%d",max);



	return 0;

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

using namespace std;

int main(){

	int n ,x=0 ,max=0;

	scanf("%d",&n);

	char s[n];

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

	 cin>>s[i];

	 if(s[i]=='I') {

	 	++x;

	 	++i;

	 	

	 }

	 else if(s[i] =='D'){

	 	--x;

     	++i;

	 }

	 if(x>max)

	 max=x;

	}

	printf("%d",max);

}

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



int main(){



	int n,x=0;

	int max = 0;

	scanf("%d",&n);

	char arr[n];

	

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

		scanf("%c",&arr[i]);

		if(arr[i] == 'I'){

			x++;

		}

		else if(arr[i] == 'D'){

			x--;

		}

		

		

		if(x >= max){

			max = x;

		}

	}



printf("%d",max);



	return 0;

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

#include <cstdio>

#include <algorithm>

#include <cmath>



using namespace std;

typedef long long ll;



const int INF = 0x7fffffff;

const int _INF = 0x7fffffff + 1;



int main()

{

    char s[1002];

    int n;

    cin>>n;getchar();

    cin>>s;



    int ans = 0;

    int x = 0;

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

    {

        if(s[i] == 'I')

            x++;

        else if(s[i] == 'D')

            x--;

        if(x >= ans)

            ans = x;

    }

    printf("%d", ans);

    return 0;

}


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



int main(){



	int n,x=0;

	int max = 0;

	scanf("%d",&n);

	char arr[n];

	

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

		scanf("%c",&arr[i]);

		if(arr[i] == 'I'){

			x++;

		}

		else if(arr[i] == 'D'){

			x--;

		}

		

		

		if(x >= max){

			max = x;

		}

	}



printf("%d",max);



	return 0;

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

#include <cmath>

using namespace std;



int main()

{

    int n,x=0,y=0;

    string s;

    cin>>n;

    cin>>s;

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

    {

        if(s[i]=='I') {x+=1; y=max(y,x);}

        else          {x-=1; y=max(y,x);}

    }

    cout << y << endl;

    return 0;

}


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



int main(){

	int n;

	scanf("%d", &n);

	char id[n];

	

	int x = 0;

	int max = 0;

	

	scanf("%s", id);

	for(int i = 0; id[i] != '\0'; i++){

		if(id[i] == 'I'){

			x++;

			if(max < x){

				max = x;

			}

		}

		else if(id[i] == 'D'){

			x--;

		}

	}

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

	return 0;

}