akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

map<int, int> dic;
void fact(int m)
{
    for (int i = 2; i * i <= m; i++)
    {
        if (m % i == 0)
        {
            while (m % i == 0)
            {
                dic[i]++;
                m /= i;
            }
        }
    }
    if (m != 1)
    {
        dic[m]++;
        m = 1;
    }
}
int calcComb(int a, int b)
{
    if (b > a - b)
    {
        return calcComb(a, a - b);
    }
    ll ansMul = 1, ansDiv = 1;
    for (int i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
    }
    int ans = ansMul / ansDiv;
    return ans;
}

int main(){
    int n; cin >> n;
    for(int i=2; i<=n; i++) fact(i);
    map<int, int> vec;
    for(P p : dic){
        int x = p.second + 1;
        if(x >= 3) vec[3]++;
        if(x >= 5) vec[5]++;
        if(x >= 15) vec[15]++;
        if(x >= 25) vec[25]++;
        if(x >= 75) vec[75]++;
    }
    int ans = 0;
    if(vec[3]>1 && vec[25]>=1) ans += (vec[3]-1)*vec[25];
    if(vec[5]>1 && vec[15]>=1) ans += (vec[5]-1)*vec[15];
    if(vec[3]>2 && vec[5]>=2) ans += (vec[3]-2)*calcComb(vec[5], 2);
    ans += vec[75];
    OUT(ans);
}

Measured memory_bytes: 256
#include <string.h>
#include<iostream>
#include <algorithm>
#include <sstream>
using namespace std;

int ans = 0;
int m, n;
int mat[10][10000];
int one[10000];

void solve()
{
	ans = 0;
	for (int i = 0; i < (1 << (m + 1)); i++)
	{
		int tmp[10000];
		memcpy(tmp, one, sizeof(one));
		for (int j = 0; j < m; j++)
		{
			if ((i >> j) & 1)
			{
				for (int k = 0; k < n; k++)
					tmp[k] += (mat[j][k] ? -1 : 1);
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++)
			cnt += max(tmp[i], m - tmp[i]);
		ans = max(ans, cnt);
	}
}


int main()
{
	while (cin >> m >> n && m && n)
	{
		memset(one, 0, sizeof(one));
		for (int i = 0; i < m; i++)
			for (int j = 0; j < n; j++)
			{
				cin >> mat[i][j];
				one[j] += mat[i][j];
			}

		solve();
		cout << ans << endl;
	}
}


Measured memory_bytes: 3560
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static List<Ab> getStrings(Scanner sc, int num) {
		List<Ab> stringList = new ArrayList<>();
		while(num>0) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			stringList.add(new Ab(a,b));
			num--;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long d = sc.nextLong();
		List<Ab> array = getStrings(sc, n);
		int result = 0;
		for(Ab ab: array) {
			if (ab.a * ab.a + ab.b * ab.b <= d*d) {
				result++;
			}
		};
		System.out.println(result);

	}

	public static class Ab {
		public long a;
		public long b;

		public Ab(long a, long b) {
			this.a = a;
			this.b = b;
		}

		public long getA() {
			return a;
		}

		public void setA(int a) {
			this.a = a;
		}

		public long getB() {
			return b;
		}

		public void setB(int b) {
			this.b = b;
		}
	}

}


Measured memory_bytes: 67848
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n, T, A;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> T >> A;
    vv<double> h(n);
    rep(i, 0, n) cin >> h[i];
    int ans;
    double tmp = 10000000.0;
    rep(i, 0, n) {
      if (abs((double)T - 0.006 * h[i] - (double)A) < tmp) {
        ans = i + 1;
        tmp = abs((double)T - 0.006 * h[i] - (double)A);
      }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A;
  cin >> A;
  int X = A.size();
  rep2(i, X - 8, X) {
    A.at(i) = ' ';
  }
  cout << A << endl;
}


Measured memory_bytes: 3556
//思维（容斥原理 ）+带权并查集
//这道题卡cin,cout 
#include<bits/stdc++.h>
using namespace std;

int n,m,k;
int fa[100005];//建一个数组
int ans[100005],cnt[100005];//ans记录同和i在friendship且有blockship或者有直接关系,cnt统计i的friendship总数量 
//容斥原理：result=cnt[find(i)]-ans[i]-1; 自己所在的friendship集合的数量减去不符合条件的朋友和自己（关键） 
 
void init(){//初始化数组
	for(int i=1;i<=n;i++){
		fa[i]=i;
		cnt[i]=1;
	}
}

//递归式
int find(int x){
    //x==fa[x]就直接返还了
    if (x != fa[x]) fa[x] = find(fa[x]);
    return fa[x];
}

void join(int x, int y) {
    int fx = find(x),fy = find(y);
    if (fx == fy) return;//相交不合并
    else {
        fa[fx] = y;//规则小看题来规定，没有明示那就随便小 
        cnt[fy]+=cnt[fx];//注意cnt的维护 
    }
}

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	init();
	int x,y;
	for(int i=1;i<=m;i++){//直接关系的不算 
		scanf("%d%d",&x,&y);
		ans[x]++,ans[y]++;
		join(x,y);
	}
	for(int i=1;i<=k;i++){//同一个friendship且同一个blockship不算 
		scanf("%d%d",&x,&y);
		if(find(x)==find(y))ans[x]++,ans[y]++;
	}
	for(int i=1;i<=n;i++){
		printf("%d ",cnt[find(i)]-ans[i]-1);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k;
int a[125252], b[125252];

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d%d",a+i,b+i);
  ll ans = 0;
  while(true){
    ll x = 0;
    REP(i,n)if((a[i]&k)==a[i])x+=b[i];
    CHMAX(ans, x);
    bool ok = false;
    bool zero = false;
    REP(i,30){
      if((k>>i)&1){
        if(zero){
          ok = true;
          k -= 1<<i;
          k |= (1<<i)-1;
          break;
        }
      }else{
        zero = true;
      }
    }
    if(!ok)break;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>

int main(){
	int i;
	char str[1000],*sp;
	fgets(str,1000,stdin);
	while(1){
		sp = strstr(str,"apple");
		if(sp == NULL) break;
		sp[0] = 'p';
		sp[1] = 'p';
		sp[2] = 'p';
		sp[3] = 'p';
		sp[4] = 'p';
	}
	while(1){
		sp = strstr(str,"peach");
		if(sp == NULL) break;
		sp[0] = 'a';
		sp[1] = 'p';
		sp[2] = 'p';
		sp[3] = 'l';
		sp[4] = 'e';
	}
	while(1){
		sp = strstr(str,"ppppp");
		if(sp == NULL) break;
		sp[0] = 'p';
		sp[1] = 'e';
		sp[2] = 'a';
		sp[3] = 'c';
		sp[4] = 'h';
	}
	printf("%s",str);
	return 0;
}

Measured memory_bytes: 520
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;

const int ST_SIZE = (1<<18) -1;
int A[114514];
int N;
int main(){
	int L;
	cin>>L;
	int temp=L,cnt=0,now=1;
	while(temp){
		temp/=2;
		cnt++;
		now*=2;
	}
	N=cnt;
	now/=2;
	int hoge=L-now;
	int cnt2=0;
	//cout<<N<<" "<<hoge<<endl;
	while(hoge){
		cnt2+=(hoge%2);
		hoge/=2;
	}
	//cout<<cnt2<<endl;
	int M=2*(N-1)+cnt2;
	cout<<N<<" "<<M<<endl;
	int hen=1;
	for(int i=N-1;i>=1;i--){
		cout<<i<<" "<<i+1<<" "<<hen<<endl;
		cout<<i<<" "<<i+1<<" "<<0<<endl;
		hen*=2;
	}
	hoge = L-now;
	hen = now;
	int beki=1,sisu=0;
	while(hoge){
		if(hoge%2==1){
			cout<<1<<" "<<N-sisu<<" "<<hen<<endl;
			hen+=beki;
		}
		hoge/=2;
		sisu+=1;
		beki*=2;
	}

}

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

int main() {
  
  int64_t N, K; cin >> N >> K;
  
  int64_t leftside = N % K;
  
  int64_t rightside = abs(leftside - K);
  
  cout << min(leftside, rightside) << endl;
  
}

Measured memory_bytes: 256
def main():
    # 状態がループする
    A, B, C = map(int, input().split())
    flag = False
    for i in range(1, B+1):
        if i * A % B == C:
            flag = True
    if flag:print("YES")
    else:print("NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#TLEの原因は毎回tmpを設定していたこと
#b08はansがとても大きいサンプル
#16:07
n = int(input())
raw = []
for _ in range(n):
  raw.append(list(map(lambda x: int(x)-1, input().split())))
cnt = [0 for _ in range(n)]
now = []
for i in range(n):
  j = raw[i][cnt[i]]
  if i < j and i == raw[j][cnt[j]]:
    now.append(i)
    now.append(j)
ans = 0
while now:
  ans += 1
  last = now
  now = []
  for x in last:
    cnt[x] += 1
    if cnt[x] < n-1:
      y = raw[x][cnt[x]]
      if x == raw[y][cnt[y]]:
        now.append(x)
        now.append(y)
  #print(now)
if cnt == [n-1 for _ in range(n)]:
  print(ans)
else:
  print(-1)

Measured memory_bytes: 53852
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    char S[101];

    if (scanf("%s", S) < 1) return 0;

    int len = strlen(S);

    printf("%c%d%c\n", S[0], len - 2 ,S[len - 1]);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
#define int long long
const int N = 233;
int n, m;
int vis[N][N];
char str[N][N];

signed main(void) {
	read(n); read(m);
	rep (i, n) scanf("%s", str[i] + 1);
	int x = 1, y = 1;
	while (true) {
		if (!str[x][y] == '#') break;
		vis[x][y] = true;
		if (str[x + 1][y] == '#') {
			++x;
		} else if (str[x][y + 1] == '#') {
			++y;
		} else break;
	}
	if (!(x == n && y == m)) {
		cout << "Impossible\n";
		return 0;
	}
	rep (i, n) rep (j, m) if (str[i][j] == '#' && !vis[i][j]) {
		cout << "Impossible\n";
		return 0;
	}
	cout << "Possible\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
    
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i,N) cin >> d[i];

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

    if (d[N / 2 - 1] == d[N / 2]) cout << 0 << endl;
    else cout << abs(d[N / 2 - 1] - d[N / 2]) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N, D, X;
int A[101];

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

  cin >> N >> D >> X;
  rep(i, N) cin >> A[i];

  int cnt = 0;
  rep(i, D){
    rep(j, N){
      if (i%A[j]==0) cnt++;
    }
  }
  cnt += X;

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 2000 + 10, MOD = 1e9 + 7;
int inv[MAXN];

LL pm(LL a, LL n) {
  LL r = 1;
  for (; n; n >>= 1) {
    if (n & 1) r = r * a % MOD;
    a = a * a % MOD;
  }
  return r;
}

LL C(LL n, int m) {
  if (m < 0 || n < 0 || n < m) return 0;
  LL r = 1;
  for (int i = 1; i <= m; ++ i) {
    r = (n - i + 1) % MOD * r % MOD * inv[i] % MOD;
  }
  return r;
}

int main() {
  for (int i = 1; i < MAXN; ++ i) inv[i] = pm(i, MOD - 2);
  LL N, D, X;
  while (scanf("%lld%lld%lld", &N, &D, &X) == 3 && N) {
    LL ret = 0;
    for (int k = 0; X * k <= N && k <= D; ++ k) {
      LL now = C(N + D - 1 - k * X, N - k * X);
      LL coef = C(D, k);
      if (k & 1) ret -= now * coef % MOD;
      else ret += now * coef % MOD;
      ret = (ret + MOD) % MOD;
    }
    printf("%lld\n", ret);  
  }
  return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
long long modpow(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = modpow(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll wa = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        wa += a[i];
    }
    ll res = 0;
    for(int i = 0;i < n;i++){
        ll now = wa - a[i];
        now %= mod;
        res += a[i] * now;
        res %= mod;
    }
    res *= modpow(2,mod-2);
    res %= mod;
    cout << res << endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define endl '\n'
const int INF = (1 << 30);
using namespace std;
typedef long long int ll;

bool solve(){
    int n, smax=0, smin=INF, sum=0, s;
    cin >> n;
    if(!n) return false;
    REP(i,n){
        cin >> s;
        smax = max(s, smax);
        smin = min(s, smin);
        sum += s;
    }
    cout << (sum - smin - smax) / (n-2) << endl;
    return true;
}

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

    while(solve());
}

Measured memory_bytes: 3172
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
	int sum = 0;
	char c;
	bool end = true;
	bool cal = false;
	while(1){
		cal = false;
		while(1){
			scanf("%c", &c);
			if(c == '0' && cal == false) end = false;
			if(c == '\n') break;
			sum += c - '0';
			cal = true;
		}
		if(end == false) break;
		cout << sum << endl;
		sum = 0;
	}
	return 0;
}


Measured memory_bytes: 3220
def determinants(p1, p2, origin=(0, 0)):
    return (p1[0]-origin[0])*(p2[1]-origin[1]) - (p2[0]-origin[0])*(p1[1]-origin[1])


def convex_hull(p):
    h = []
    s = sorted(set(p), key=lambda x: (x[1], x[0]))
    for i in range(len(s)):
        while len(h) > 1 and determinants(h[-2], s[i], h[-1]) > 0:
            h.pop()
        h.append(s[i])
    l = len(h)
    for i in range(len(s) - 2, -1, -1):
        while len(h) > l and determinants(h[-2], s[i], h[-1]) > 0:
            h.pop()
        h.append(s[i])
    return h[:-1]


n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]
result = convex_hull(p)
print(len(result))
for r in result:
    print("{} {}".format(r[0], r[1]))



Measured memory_bytes: 31652
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
//int dx[] = { 1, 0 };
//int dy[] = { 0, 1 };
#define mod7 1e9+7;
#define mod9 1e9+9;

int nextInt(){
	int a;	cin >> a;return a;
}
string next(){
	string s;cin >> s;return s;
}
char nextChar(){
	char c;cin >> c;return c;
}

unsigned long long strtoint(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve(){
	int n = nextInt();
	string s = next();
	int ans = 0;
	int count = 0;
	rep(i,s.length()){
		if(s[i] == 'I'){
			count++;
			ans = max(ans,count);
		}else if(s[i] == 'D'){
			count--;
		}
	}
	P(ans);
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
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;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>k;
    rrrep(i,ohara,1){
        if(a%i==0&&b%i==0)cnt++;
        if(cnt==k){
            Cout(i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,time,x,y;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&time,&x,&y);
		if(x+y>time){
			printf("No\n");
			return 0;
		}
		if((x+y)%2==0&&time%2==1){
			printf("No\n");
			return 0;
		}
		if((x+y)%2==1&&time%2==0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
} 

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

bool isATGC(char c) {
  string t = "ATGC";
  REP(i, SZ(t)) {
    if (c == t[i]) return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  ll n = SZ(s);
  ll ans = 0;
  REP(i, n) {
    ll cnt = 0;
    FOR(j, i, n) {
      if (isATGC(s[j])) {
        cnt++;
        continue;
      }
      break;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int ans = 1;
	for(int i = 2; i * i <= n; i++){
		int t = i;
		for(int j = 2; j < n; j++){
			t *= i;
			if(t > n) break;
			ans = max(ans, t);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				String str1="", str2="";
				int[] s1=new int[10010];
				int[] s2=new int[10010];
				int count;
				for(int i=0; i<n; i++) {
					str1=sc.next();
					str2=sc.next();
					s1[i]=((str1.charAt(0)-'0')*10+(str1.charAt(1)-'0'))*3600;
					s1[i]+=((str1.charAt(3)-'0')*10+(str1.charAt(4)-'0'))*60;
					s1[i]+=((str1.charAt(6)-'0')*10+(str1.charAt(7)-'0'));
					s2[i]=((str2.charAt(0)-'0')*10+(str2.charAt(1)-'0'))*3600;
					s2[i]+=((str2.charAt(3)-'0')*10+(str2.charAt(4)-'0'))*60;
					s2[i]+=((str2.charAt(6)-'0')*10+(str2.charAt(7)-'0'));
				}//s1発車時刻[秒] s2到着時刻[秒]
				int max=0;
				for(int i=0; i<=86400; i++) {
					count=0;
					for(int j=0; j<n; j++) {
						if(s1[j]<=i && i<s2[j]) {
							count++;
						}
					}
					max=Math.max(max, count);
				}
				System.out.println(max);
			}
		}
	}
}


Measured memory_bytes: 64836
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n;
    Team[] t;

    void run(){
	while(true){
	    n = sc.nextInt();
	    if(n==0) break;
	    t = new Team[n];
	    for(int i=0; i<n; i++)
		t[i] = new Team(sc.nextInt());

	    solve();
	}
    }

    void solve(){
	Arrays.sort(t, new Comparator<Team>(){
		public int compare(Team t1, Team t2){
		    int s1 = t1.getTime();
		    int s2 = t2.getTime();
		    return(s1-s2);
		}
	    }
	    );

	//show();

	System.out.println(t[0].getNum());
	System.out.println(t[1].getNum());
	System.out.println(t[n-2].getNum());
    }

    void show(){
	for(int i=0; i<n; i++)
	    System.out.println(t[i].getNum()+" "+t[i].getTime());
    }

    class Team{
	int num, time;
	Team(int n){
	    num = n;
	    int min = 0, sec = 0;
	    for(int i=0; i<4; i++){
		min += sc.nextInt();
		sec += sc.nextInt();
	    }
	    time = min*60 + sec;
	}
	int getTime(){ return time; }
	int getNum(){ return num; }
    }
}
	    
	

Measured memory_bytes: 71800
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1e18;

int A,B,C,D,E,N,M,K,L,R,X;
string s,t;

signed main() {
    IOS();
    cin>>A>>B;
    int ans=0;
    if(A==B)cout<<A+B<<endl;
    else cout<<max(A,B)+max(A,B)-1<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	n, r := readI(), readI()
	if n >= 10 {
		fmt.Println(r)
		return
	}
	fmt.Println(r + (10-n)*100)
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


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

using namespace std;

int main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int k;
  cin >> k;
  int a, b;
  cin >> a >> b;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
      cout << "OK\n";
      return 0;
    }
  }
  cout << "NG\n";
  return 0;
}

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

int main() {
  int x;
  cin >> x;
  int64_t ans = 1;
  bool flag = false;
  for (int i = 1; i < x; i++) {
    // i is a base num
    for (int j = 2; j < x; j++) {
      // j is the power of the base number
      int64_t a = pow(i, j);
      if (a < x) {
        ans = max(ans, a);
      }
      else if (a == x) {
        ans = a;
        flag = true;
        break;
      }
    }
    if (flag) {
      break;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {


    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = 2;
        int b = sc.nextInt();

        System.out.println(lcm(a, b));
    }

    public static int gcd(int a, int b){
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static int lcm(int a, int b){
        return a * b / gcd(a, b);
    }
}

Measured memory_bytes: 21844
# coding: utf-8
from sys import stdin
import sys, fractions
import numpy as np

def main():
    n = int(stdin.readline().rstrip())
    matrix = [stdin.readline().rstrip().split() for _ in range(n)]
    matrix = np.array(matrix, dtype='int32')
    matrix = matrix[np.argsort(matrix[:,-1])]
    task_time = matrix[:,0]
    task_time_sum = np.cumsum(task_time)
    limited_time = matrix[:,-1]
    #print(n, matrix)
    #print(task_time, task_time_sum)
    for x, y in zip(task_time_sum, limited_time):
        if x > y:
            return(0)
    
    return(1)
    
if __name__ == '__main__':
    ans = main()
    print('Yes' if ans==1 else 'No')


    




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

int main(){
  ll n;
  cin >> n;
  ll ans = 100000000; 
  for (ll i=1;i*i<=n;++i){
    if(n%i == 0){
      ans = i + n/i - 2;
      ans = min(ans,i+n/i-2);
    }
  }
  cout << ans << endl;
  return 0;
}
      
      
  


Measured memory_bytes: 256
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 1e4+7;

const int mod = 1e9+7;

int n;
int t;
int mem[N][N];
pair < int , int > dish[N];

int go(int idx , int T){
    if(idx == n+1)
        return 0;
    if(~mem[idx][T])
        return mem[idx][T];
    int best = go(idx + 1 , T);
    if(T <= t)
        best = max(best , go(idx + 1 , T + dish[idx].first) + dish[idx].second);
    return mem[idx][T] = best;
}

int main(){
    scanf("%d%d" , &n , &t);
    t--;
    for(int i = 1; i <= n; i++){
        scanf("%d%d" , &dish[i].first , &dish[i].second);
    }
    sort(dish + 1 , dish + n + 1);
    memset(mem , -1 , sizeof mem);
    printf("%d\n" , go(1 , 0));
}


Measured memory_bytes: 391680
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int N, mx=(1<<30);
int a[200010], u[200010], v[200010], ans[200010], lis[200010];
vector<vector<int>> G;
bool visited[200010]={};

void dfs(int key){
    visited[key]=true;
    int ok=0, ng=N, sbs;
    while(ok+1<ng){
        int mid=(ok+ng)/2;
        if(lis[mid]<a[key]) ok=mid;
        else ng=mid;
    }
    sbs=lis[ng]-a[key];
    lis[ng]=a[key];
    ans[key]=0;
    int ng2=N+1;
    while(ans[key]+1<ng2){
        int mid=(ans[key]+ng2)/2;
        if(lis[mid]<mx) ans[key]=mid;
        else ng2=mid;
    }
    for(int i=0; i<G[key].size(); ++i){
        int p=u[G[key][i]]+v[G[key][i]]-key;
        if(!visited[p]){
            dfs(p);
        }
    }
    lis[ng] += sbs;
}

int main(void){
    cin >> N;
    for(int i=1; i<=N; ++i) cin >> a[i];
    G.resize(N+1);
    for(int i=1; i<N; ++i){
        cin >> u[i] >> v[i];
        G[u[i]].emplace_back(i);
        G[v[i]].emplace_back(i);
    }
    lis[0]=0;
    for(int i=1; i<=N; ++i) lis[i]=mx;
    dfs(1);
    for(int i=1; i<=N; ++i) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 32544
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();

const intt max1 = 11;
const intt max2 = 102;
const intt max3 = 1003;
const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;
const intt lg2 = 7;
const intt lg3 = 10;
const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;
const intt lg7 = 24;
const intt lg8 = 27;
const intt lg9 = 30;
const intt lg18 = 60;
const intt INF = 2LL * 1000000000;
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a, intt b) { while(b) b ^= a ^= b ^= a %= b; return a;}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}
/**************************/

intt arr[3];
int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    cin >> arr[0] >> arr[1] >> arr[2];
    sort (arr, arr + 3);
    cout << arr[0] + arr[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
int ans;
char b[1001];
int main()
{
  string a;
  cin>>a;
  int m=a.size();
  b[0]=a[0];
  b[m-1]=a[m-1];
  cout<<b[0]<<m-2<<b[m-1]<<endl;
}

Measured memory_bytes: 256
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

tmp_ans = A1[0] + sum(A2)
ans = A1[0] + sum(A2)

for i in range(len(A2)-1):
    tmp_ans = tmp_ans - A2[i] + A1[i+1]
    if tmp_ans > ans:
        ans = tmp_ans
print(ans)

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    int N, H;
    cin>>N>>H;
    vector<pair<int, bool>> AB(2*N);
    for (int n = 0; n < N; n++) {
        int a, b;
        cin>>a>>b;
        AB[2*n] = make_pair(a, true);
        AB[2*n+1] = make_pair(b, false);
    }
    sort(begin(AB), end(AB), greater<pair<int, bool>>());
    int count = 0;
    for (auto it = begin(AB); it != end(AB); it++) {
        if (it->second == false) {
            H -= it->first;
            count++;
            if (H <= 0) break;
        } else {
            count += (int)ceil((double)H / it->first);
            break;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	LL a, b, x;
	cin >> a >> b >> x;

	if (a == 0) {
		cout << b / x + 1 << endl;
		return 0;
	}

	
	LL ans = b/x -(a - 1) /x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0&&m==0)break;
    int t[101]={};
    for(int i=0;i<n;i++){
      int a,b;
      cin>>a;
      for(int j=0;j<a;j++){
	cin>>b;
	t[b]++;
      }
    }
    int maxm=-1,ans;
    for(int i=0;i<101;i++){
      if(maxm<t[i]){
	maxm=t[i];
	ans=i;
      }
    }
    if(maxm<m)cout<<0<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
void call(int n);
using namespace std;
int main(){
	int N,m;
	m=0;
	cin>>N;
	int ko[N];
	
	if(N>=10000){
		N=10000;
	}
	for(int i=3;i<N+1;i++){
		
		if(i%3 == 0){
			ko[m]=i;
			m++;
			
		}else if(i%10 == 3){
			ko[m]=i;
			m++;
		}else if((i/10)%10 ==3){
			ko[m]=i;
			m++;
		}else if((i/100)%10 ==3){
			ko[m]=i;
			m++;
		}else if((i/1000)%10 ==3){
			ko[m]=i;
			m++;
		}else if((i/10000)%10 ==3){
			ko[m]=i;
			m++;
		}
	}
	for(int o = 0;o<m;o++){
		
		cout<<' '<<ko[o];
	}
	
	cout<<endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define TEN5 100000 //10^5
#define TEN9 1000000000 //10^9
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int h, w; 
char s[50][50];
void dfs(int i, int j) {
    int tmp = 0;
    for(int x = -1; x <= 1; x++) {
        for (int y = -1; y <= 1; y++) {
            int nx = i + x, ny = j + y;
            if (nx < 0 || nx >= h || ny < 0 || ny >= w)
                continue;
            if (s[nx][ny] == '#')
                tmp++;
        }
    }
    s[i][j] = tmp + '0';
}
int main()
{
    cin >> h >> w;
    rep(i,h) {
        string tmp;
        cin >> tmp;
        rep(j,tmp.length()) {
            s[i][j] = tmp[j];
        }
    }

    rep(i,h) {
        rep(j,w) {
            if (s[i][j] == '.')
                dfs(i, j);
        }
    }

    rep(i,h) {
        rep(j,w) {
            cout << s[i][j];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 5e5 + 5;
int n;
char tmp[maxn];
string s;

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  return true;
}

int prv[maxn], nxt[maxn];
int dp[maxn];

void solve() {
  prv[0] = -1;
  for (int i = 0; i < n; i++) {
    prv[i + 1] = (s[i] == '0' ? i : prv[i]);
  }
  nxt[n] = n;
  for (int i = n - 1; i >= 0; i--) {
    nxt[i] = (s[i] == '0' ? i : nxt[i + 1]);
  }
  for (int i = 0; i <= n; i++) {
    dp[i] = 0;
  }
  {
    int j = nxt[0] + 1;
    if (j < n && s[j] == '1') {
      dp[j + 1] = max(dp[j + 1], j - 1);
    }
  }
  for (int i = 0; i < n; i++) {
    auto &cur = dp[i + 1];
    cur = max(cur, dp[i]);
    {
      int p = prv[i + 1] - 1;
      if (p >= 0 && s[p] == '1') {
        cur = max(cur, dp[p] + i + 1 - p - 2);
      }
    }
    {
      int j = nxt[i + 1] + 1;
      if (j < n && s[j] == '1') {
        dp[j + 1] = max(dp[j + 1], cur + j - i - 2);
      }
    }
  }
  printf("%d\n", dp[n]);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 7040
#include <iostream>
#include <set>
using namespace std;

class Student{
public:
  int score, no;
  Student() : score(0) {}
  bool operator <(const Student &s) const{
    if(score != s.score) return score > s.score;
    return no < s.no;
  }
};

main() {
  while(1) {
    int m;
    set<Student> S;
    cin >> m;
    if(m == 0) break;
    for(int i = 0; i < m; i++) {
      int result[10];
      Student tmp;
      int a, b, c;
      cin >> tmp.no;
      for(int i = 0; i < 9; i++) {
	cin >> a;
	tmp.score += a;
	if(i-1 >= 0 && result[i-1] >= 1) tmp.score += a;
	if(i-2 >= 0 && result[i-2] == 2 && result[i-1] == 2) tmp.score += a;

	if(a == 10) {
	  result[i] = 2;
	  continue;
	}
	cin >> b;
	tmp.score += b;
	if(i-1 >= 0 && result[i-1] == 2) tmp.score += b;
	if(a+b == 10) {
	  result[i] = 1;
	  continue;
	}
	result[i] = 0;
      }

      cin >> a >> b;
      c = 0;
      if(a+b >= 10) {
	cin >> c;
      }
      if(result[8] >= 1) tmp.score += a;
      if(result[7] == 2 && result[8] == 2) tmp.score += a;
      if(result[8] == 2) tmp.score += b;
      tmp.score += a+b+c;

      S.insert(tmp);
    }
    for(set<Student>::iterator it = S.begin();
	it != S.end(); it++) {
      cout << it->no << ' ' << it->score << endl;
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;

int main() {
	long long n, k, ele, ans;
	cin >> n >> k;
	if (n * 2 < k) {
		cout << 0 << endl;
		return(0);
 	}
	ele = n / k;
	ans = ele * ele * ele;
	if (k % 2 == 0) {
		if (n % k >= k / 2) {
			ele = n / k +1;
		}
		else {
			ele = n / k;
		}
		ans += ele*ele*ele;
	}
	
	cout << ans << endl;
	return(0);
}


Measured memory_bytes: 256
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(n,k):
	return min(n%k,abs(n%k - k))
	

N,K = list(map(int, stdin.readline().rstrip().split()))
ans = solve(N,K)
print(ans)


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

int main(int argc, char *argv[]) {
	int32_t A = 0;
	int32_t B = 0;
	int32_t C = 0;

	std::cin >> A;
	std::cin >> B;
	std::cin >> C;

	std::cout << ((A <= C && C <= B) ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    
    cout << min({n*a, b}) << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
 
bool isprime(int N){
	bool ok = true;
	repr(i,2,N){
		if(N % i == 0) ok = false;
	}
	return ok;
}
 

 
int main(){
	int N; cin >> N;
	vector<int> ans;
	repr(i,2,55556){
		if(i % 10 == 1 && isprime(i)) ans.push_back(i);
		if(ans.size() == N) break;
	}
	rep(i,N){
		if(i) cout << " ";
		cout << ans[i];
	}
	cout << endl;
}


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

int p[1111111], q[1111111], r[1111111], s[1111111];
int main() {
    for(int i = 1; i < 1111; i++)
        for(int j = 0; j < 1111111; j += i * i)
            q[j] = i;
    for(int i = 1; i < 1111111; i++)
        r[i] = i, r[i] = r[i / q[i]];
    vector<int> v;
    for(int i = 2; i < 1111111; i++) {
        if(!p[i])
            p[i] = i, v.push_back(i);
        for(int x : v) {
            if(x > p[i] || i * x > 1000000)
                break;
            p[i * x] = x;
        }
    }
    int n, g = 0, f = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        a = r[a];
        g = gcd(g, a);
        if(f)
            continue;
        while(a > 1) {
            int x = p[a];
            if(!x)
                swap(a, x);
            a /= x;
            if(s[x] && s[x] <= i) {
                f = 1;
                break;
            }
            s[x] = i + 1;
        }
    }
    cout << (g > 1 ? "not" : f ? "setwise" : "pairwise") << " coprime" << endl;
    return 0;
}


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

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> A(n+1);
    vector<int64_t> B(n);
    rep(i,n+1){
        cin >> A.at(i);
    }
    rep(i,n){
        cin >> B.at(i);
    }
    int64_t prev,ans;
    ans = 0;
    if (A.at(0) <= B.at(0)){
        ans += A.at(0);
        prev = B.at(0)-A.at(0);
    }
    else{
        ans += B.at(0);
        prev = 0;
    }
    for (int i=1; i<n; i++){
        if (A.at(i) < prev){
                ans += A.at(i);
                prev = B.at(i);
            }
        else{
            ans += prev;
            A.at(i) -= prev;
            if (A.at(i) <= B.at(i)){
                ans += A.at(i);
                prev = B.at(i)-A.at(i);
            }
            else{
                ans += B.at(i);
                prev = 0;
            }
        }
    }
    if (prev){
        ans += min(prev,A.at(n));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll N;
    cin >> N;
    vector<ll>C(N), S(N), F(N);
    for(ll i = 0; i + 1 < N; i++){
        cin >> C[i] >> S[i] >> F[i];
    }
    for(ll i = 0; i < N; i++){
        ll t = 0;
        for(ll j = i; j + 1 < N; j++){
            if(S[j] > t)t = S[j] + C[j];
            else{
                t = C[j] + F[j] * ceil(1.0 * t / F[j]);
            }
        }
        cout << t << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
"use strict";
var INPUT = require('fs').readFileSync('/dev/stdin', 'utf-8');
function isPrime(x) {
    for (var i = Math.floor(x / 2); i >= Math.sqrt(x); i--) {
        if (x % i === 0) {
            return false;
        }
    }
    return true;
}
var X = Number(INPUT.trim());
var x = X;
while (true) {
    if (isPrime(x)) {
        console.log(x);
        break;
    }
    x++;
}


Measured memory_bytes: 7500