akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;


int main()
{
    long long a,b,c,k;
    cin >> a >> b >> c >> k;
    long long ans = 0;
    ans += min(a,k);
    k -= a;
    k -= b;
    if(k>0)
        ans -=min(c,k);
    cout << ans;
    return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
  string S;
  cin >> S;
  bool ans = true;
  while(1){
    int len = S.length();
    if(len == 0) break;
    else if(len < 5){
      ans = false;
      break;
    }
    if(S.substr(len-5,5) == "dream" || S.substr(len-5,5) == "erase"){
      S = S.substr(0,len-5);
    }
    else if(len >= 6 && S.substr(len-6,6) == "eraser"){
      S = S.substr(0,len-6);
    }
    else if(len >= 7 && S.substr(len-7,7) == "dreamer"){
      S = S.substr(0,len-7);
    }
    else{
      ans = false;
      break;
    }
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int N;
    cin >> N;
    lint A[N],B[N];
    rep(i,N) cin >> A[i] >> B[i];
    lint ans=0;
    rep(i,N) ans-=B[i];
    lint C[N];
    rep(i,N) C[i]=A[i]+B[i];
    sort(C,C+N,greater<lint>());
    for(int i=0;i<N;i+=2) ans+=C[i];
    cout << ans << endl;
}

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

int main()
{
  int n, k;
  scanf("%d%d", &n, &k);
  long long ans = k;
  if(n < 10)
  {
    ans += 100 * (10 - n);
  }
  printf("%lld\n", ans);
  return 0;
}

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

int main()
{
	double x1,y1,x2,y2,x3,y3,xp,yp;
	double m,n;

	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp)
	{
		m = ((xp - x1) * (y3 - y1) - (yp - y1) * (x3 - x1)) /
                ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1));
 
        n = ((xp - x1) * (y2 - y1) - (yp - y1) * (x2 - x1)) /
                ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1));
 
        if(m > 0 && n > 0 && m + n < 1) cout << "YES" << endl;
        else cout << "NO" << endl;
	}

	return 0;
}

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

int main(){
    string s;
    cin >> s;

    vector<int> children(s.length(),0);
    int counter = 1;
    int record = 0;

    for(int i=0; i<s.length()-1; i++){
        if(s[i] == 'R' && s[i+1] == 'L'){
            children[i] += (counter + 1) / 2;
            children[i+1] += counter / 2;
            record = i;
            /*
            for(int i=0; i<s.length(); i++){
                cout << children[i] << " ";
            }
            cout << " " << counter << endl;
            */
            counter = 1;
        }
        else if(s[i] == 'L' && s[i+1] == 'R'){
            children[record + 1] += (counter + 1) / 2;
            children[record] += counter / 2;
            /*
            for(int i=0; i<s.length(); i++){
                cout << children[i] << " ";
            }
            cout << " " << counter << endl;
            */
            counter = 1;
        }else{
            counter += 1;
        }
    }
    if(record != s.length() - 1){
        children[record + 1] += (counter + 1) / 2;
        children[record] += counter / 2;
    }
    
    for(int i=0; i<s.length(); i++){
        cout << children[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Y = sc.nextInt();

		int x;
		for (int z = 0; z <= N; z++) {
			for (int y = 0; y <= N; y++) {
				x = N - y - z;
				if (x >= 0 && 10000 * x + 5000 * y + 1000 * z == Y) {
					System.out.println(x + " " + y + " " + z);
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

ll N, P, res;
ll cnt;

ll pw(int x, int n) {
	ll y = 1;
	ll p = x;
	while (n != 0) {
		if (n % 2) {
			y = y*p;
		}
		p = p*p;
		n = n / 2;
	}
	return y;
}

int main() {
	res = 1;
	cin >> N >> P;
	if (N == 1) {
		cout << P << endl;
		return 0;
	}
	for (ll i = 2; i*i <= P; ++i) {
		cnt = 0;
		while (P%i == 0) {
			P /= i;
			++cnt;
		}
		res *= pw(i, cnt / N);
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 50 + 10;
ll K; ll N;
ll A[MAXN];

int main() {
	register int i;
	scanf("%lld", &K);
	N = 50;
	for(i = 0; i < N; ++i)
		A[i] = (K / N) - (K % N) + (N - 1) + (i < K % N ? N + 1 : 0);
	printf("%lld\n", N);
	for(i = 0; i < N; ++i)
		printf("%lld\n", A[i]);
	return 0;
}

Measured memory_bytes: 128
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


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


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	Int a, b, c; cin >> a >> b >> c;
	if (a*b*c % 2 == 0)print(0);
	else {
		Int minq = a * b;
		minq = min(minq, b*c); minq = min(minq, c*a);
		print(minq);
	}


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct card{
	char c;
	int in;
	int number;
};
int partition(card A[], int p, int r){
	int memo=A[r].in;
	int i=p-1;
	for(int j=p; j<r; j++){
		int k=A[j].in;
		if(k<=memo){
			i++;
			card s=A[i];
			A[i]=A[j];
			A[j]=s;
		}
	}
	card m=A[i+1];
	A[i+1]=A[r];
	A[r]=m;
	return i+1;
}
void quickSort(card A[], int p, int r){
	if(p<r){
		int q=partition(A, p, r);
		quickSort(A, p, q-1);
		quickSort(A, q+1, r);
	}
}
int main(){
	bool flag=true;
	int n;
	cin>>n;
	card c[n];
	for(int i=0; i<n; i++){
		cin>>c[i].c>>c[i].in;
		c[i].number=i;
	}
	quickSort(c, 0, n-1);
	for(int i=0; i<n-1; i++){
		if(c[i].in==c[i+1].in && c[i].number>c[i+1].number){
			flag=false;
			break;
		}
	}
	if(flag==true)
		cout<<"Stable"<<endl;
	else
		cout<<"Not stable"<<endl;
	for(int i=0; i<n; i++)
		cout<<c[i].c<<" "<<c[i].in<<endl;
	return 0;
}



Measured memory_bytes: 4272
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  string s; cin >> s;
  int cnt = 0;
  for (int i = 0; i + 3 <= n; ++i) {
    if (s.substr(i, 3) == "ABC") ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  if(n[0]==n[1] && n[0]==n[2] || n[1]==n[2]&&n[2]==n[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define INF 2000000000
using namespace std;
int main(){
  int v,n;
  cin>>v>>n;
  long long a[v][v];
  r(i,v)r(j,v)a[i][j]=i==j?0:INF;
  r(i,n){int x,y,w;
    cin>>x>>y>>w;
    a[x][y]=w;
  }
  r(k,v)r(i,v)r(j,v)if(a[i][k]!=INF&&a[k][j]!=INF)a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
  r(i,v)if(a[i][i]<0){cout<<"NEGATIVE CYCLE"<<endl;return 0;}
  r(i,v){r(j,v){
      if(j)cout<<' ';
      if(a[i][j]>=INF) cout<<"INF";
      else cout<<a[i][j];
    }
    cout<<endl;
  }
}



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

typedef long long int ll;
using ii= pair<ll,ll>;
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001
#define mod 1000000007

class prioritize{
    public: bool operator() (ii &p1,ii &p2){
        return p1.F<p2.F;
    }
};

ll powerm(ll a,ll b,ll m){
    if(b==0) return (1+m)%m;
    ll t= powerm(a,b/2,mod);
    t= (t*t+m)%m;
    if(b%2!=0) t= (t*a+m)%m;
    return t;
}



int main()
{
    
    #ifndef ONLINE_JUDGE
        freopen("input1.txt","r", stdin);
        freopen("output1.txt","w",stdout);
        auto start= high_resolution_clock::now();
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    
    ll n;     //2511445
    cin>>n;
    
    if(n==1) cout<<0<<"\n";
    else if(n==2) cout<<2<<"\n";
    else{

        ll tot= powerm(10,n,mod);
        ll np_z_n= (2*(powerm(9,n,mod)%mod)%mod);
        ll inters= powerm(8,n,mod);
        ll ans= (tot- np_z_n+ inters+ mod)%mod;
        cout<<ans<<"\n";
        //cout<<tot<<" "<<np_z_n<<" "<<inters<<"\n";
    }





    
    #ifndef ONLINE_JUDGE
        auto stop= high_resolution_clock::now();
        auto duration= duration_cast<milliseconds>(stop-start);
        cout<<"run time: "<<duration.count()<<" ms"<<"\n";
    #endif
}

Measured memory_bytes: 3628
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! { a:i32, b:i32 };
    println!("{}", if (a*b)%2==0 { "No" } else { "Yes" } );
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
     int i,j,k,n,m;
     int a,b,c,d;
     char s[10];
     scanf("%s",s);
     a=s[0]-'0';
     b=s[1]-'0';
     c=s[2]-'0';
     d=s[3]-'0';
     if(a+b+c+d==7)
     {
          printf("%d+%d+%d+%d=7\n",a,b,c,d);
          return 0;
     }
     if(a+b+c-d==7)
     {
          printf("%d+%d+%d-%d=7\n",a,b,c,d);
          return 0;
     }
     if(a+b-c+d==7)
     {
          printf("%d+%d-%d+%d=7\n",a,b,c,d);
          return 0;
     }
     if(a-b+c+d==7)
     {
          printf("%d-%d+%d+%d=7\n",a,b,c,d);
          return 0;
     }
     if(a+b-c-d==7)
     {
          printf("%d+%d-%d-%d=7\n",a,b,c,d);
          return 0;
     }
     if(a-b+c-d==7)
     {
          printf("%d-%d+%d-%d=7\n",a,b,c,d);
          return 0;
     }
     if(a-b-c+d==7)
     {
          printf("%d-%d-%d+%d=7\n",a,b,c,d);
          return 0;
     }
     if(a-b-c-d==7)
     {
          printf("%d-%d-%d-%d=7\n",a,b,c,d);
          return 0;
     }
     return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
ans = [0]*(n+1)

for i in range(n,0,-1):
    
    k = 1
    count = 0
    while k*i <= n:
        count += ans[k*i]
        k += 1
    if count%2 != l[i-1]:
        ans[i] = 1
print(sum(ans))
if sum(ans) > 0:
    for i in range(n+1):
        if ans[i] == 1:
            print(i,end=" ")


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

using ll = long long;

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};

int main() {
  int n;
  cin >> n;
  map<string,int> m;
  int mx=0;
  rep(i,n){
    string s;
    cin >> s;
    m[s]++;
    mx=max(mx,m[s]);
  }
  for(auto p:m){
    string s=p.first;
    int x=p.second;
    if(x==mx) cout << s << endl;
  }
  
}


Measured memory_bytes: 19140
def bubble_sort(A, n):
	flag = 1
	i = 0
	count = 0

	while flag:
		flag = 0
		for j in range(n-1, i, -1):
			if A[j] < A[j-1]:
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1
				count += 1

		i += 1
	
	print(' '.join(map(str, A)))
	print(count)


if __name__ == '__main__':
	n = int(input())
	A = list(map(int, input().split()))

	bubble_sort(A, n)

Measured memory_bytes: 7708
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

        
    
int main(){
  string s; cin >> s; int n = s.size();
  if(s[n-1]=='s'){
    cout << s << "es" << endl;
  }
  else cout << s << 's' << endl;
}

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  cout <<max(max(A,B),C)-(A+B+C-min(min(A,B),C)-max(max(A,B),C))+((A+B+C-min(min(A,B),C)-max(max(A,B),C))-min(min(A,B),C))<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  ll a = 1000000000, b = -1;
  for(ll i=0;i<s.size();i++){
    if(s[i]=='A') a = min(a, i);
    if(s[i]=='Z') b = max(b, i);
  }
  std::cout << b - a + 1 << '\n';
  return 0;
}


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

using namespace std;

typedef long long LL;
const int N = 60;

bool mat[N][N];
int n, m, s;
LL mod;

LL pow_mod(LL x, int p){
    LL s = 1;
    while(p){
		if(p & 1) 	s = s * x % mod;
		x = x * x % mod;
		p >>= 1;
    }
    return s;
}

int query(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c, d);
    fflush(stdout);
    int ret;
    scanf("%d", &ret);
    return ret;
}

void solve(int x1, int x2, int y1, int y2, int sum, int div){
    int area = (x2 - x1 + 1) * (y2 - y1 + 1);
    if(sum == 0 || x1 > x2 || y1 > y2)	return;
    if(area == sum){
		for(int i=x1; i<=x2; i++){
			for(int j=y1; j<=y2; j++){
				mat[i][j] = 1;
			}
		}
		return;
    }

    if(div){
		if(y1 == y2){
			div ^= 1;
		}
    } else {
		if(x1 == x2){
			div ^= 1;
		}
    }

    if(div){
		int mid = y1 + y2 >> 1;
		int g = query(x1, y1, x2, mid);
		solve(x1, x2, y1, mid, g, div^1);
		solve(x1, x2, mid+1, y2, sum - g, div^1);
	} else {
		int mid = x1 + x2 >> 1;
		int g = query(x1, y1, mid, y2);
        solve(x1, mid, y1, y2, g, div^1);
        solve(mid+1, x2, y1, y2, sum - g, div^1);
    }
}

int main(){
    while(~scanf("%d %d %d %lld", &n, &m, &s, &mod)){
        memset(mat, 0, sizeof(mat));

        int a = query(0, 0, n/2-1, m/2-1);
        int b = query(0, m/2, n/2-1, m-1);
        int c = query(n/2, 0, n-1, m/2-1);
        int d = s - a - b - c;

        solve(0, n/2-1, 0, m/2-1, a, 0);
        solve(0, n/2-1, m/2, m-1, b, 0);
        solve(n/2, n-1, 0, m/2-1, c, 0);
        solve(n/2, n-1, m/2, m-1, d, 0);

        LL ans = 0;
        for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				if(mat[i][j]){
					ans = ans + pow_mod(2, i * m + j) % mod;
					ans %= mod;
				}
			}
        }
        printf("! %lld\n", ans);
        fflush(stdout);
    }
	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

bool ok(string s)
{
        rep(i, 0, len(s)) {
                char x = s[0];
                if (s[i] != x) return false;
        }
        return true;
}

int main()
{
        string S;
        cin >> S;
        ll N = len(S);

        map<char, ll> mp;
        rep(i, 0, N) mp[S[i]]++;
        vector<pair<ll, char> > rank;
        for (auto x : mp) {
                rank.emplace_back(pair<ll, char>{x.second, x.first});
        }
        sort(rank.rbegin(), rank.rend());

        ll ans = 0;
        ll ansans = inf;

        if (ok(S)) {
                cout << 0 << endl;
                return 0;
        }
        for (char alph = 'a'; alph <= 'z'; ++alph) {
                ans = 0;
                string prev(S);
                rep(i, 0, N) {
                        string s;

                        rep(j, 0, N-i-1) {
                                if (prev[j] == alph) s.push_back(prev[j]);
                                else if (prev[j+1] == alph) s.push_back(prev[j+1]);
                                else s.push_back(prev[j]);
                        } 
                        
                        ++ans;
                        if (ok(s)) break;
                        prev.clear();
                        rep(j, 0, len(s)) prev[j] = s[j];
                }
                chmin(ansans, ans);
        }

        cout << ansans << endl;
}

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

int main()
{
    int A,i,something;vector<int> vec;
    for(i=0;i<3;i++){cin>>A;vec.push_back(A);}
    sort(vec.begin(),vec.end());
    vector<int>::iterator vec_iter = vec.begin();
    cout<<(*vec_iter)+(*(++vec_iter))<<endl;
    return 0;
}


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

signed main(){
  
  string s;
  cin>>s;
  
  set<int> S;
  
  for(int i=0;i<s.size();i++) S.insert((int)s[i]);
  
  if(S.size()!=2) cout<<"No"<<endl;
  else{
    
    int cnt = 0;
    
    for(int i=0;i<s.size();i++){
      if(s[i] == s[0]) cnt++;
    }
    
    if( cnt==2 ) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define MOD 1000000007
template <typename Type>
istream &operator>>(istream &in, vector<Type> &vec) {
    ll n = vec.size();
    for (ll i = 0; i < n; i++)
        in >> vec[i];
    return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &vec) {
    for (auto val : vec)
        out << val << " ";
    return out;
}
#define PI 3.14159265

int main()
{
   ll n;
   cin>>n;
   vector<ll>a(n);
   cin>>a;
   ll dp[n];
   dp[0] = 0;
   dp[1] = abs(a[1]-a[0]);
   for(ll i=2;i<n;i++)
   {
       dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
   }
   cout<<dp[n-1]<<endl;

   
   return 0;
}
    


Measured memory_bytes: 1792
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func main() {
	sc := NewScanner()
	A, B := sc.nextInt(), sc.nextInt()
	if A > 9 || B > 9 {
		fmt.Println("-1")
		return
	}
	fmt.Println(A * B)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)
        cin >> A[i];
    vector<int> B = A;
    sort(B.begin(), B.end());
    int mx = B[N-1];
    int mx2 = B[N-2];
    int id = max_element(A.begin(), A.end()) - A.begin();
    for(int i=0; i<N; i++)
        cout << ((i != id) ? mx : mx2) << endl;

    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;

int main()
{ 
	ll n,k,x;
	cin>>n>>k;

	ll dp[k+5];
	memset(dp,0,sizeof(dp));
	dp[0]=1;

	for(ll i=0;i<n;i++)
	{
		cin>>x;

		vector<ll> diff(k+5,0);

		for(ll j=k-1;j>-1;j--)
		{
			ll val=dp[j];

			ll l=j+1,r=min(k,j+x);

		diff[l]=(diff[l]+val)%mod;
	    diff[r+1]=(mod +diff[r+1]-val)%mod;
		}

		ll pre=0;

		for(ll i=0;i<=k;i++)
		{
			pre=(pre+mod+diff[i])%mod;
			dp[i]=(dp[i]+pre+mod)%mod;
		}
		
	}
	cout<<dp[k]<<endl;
}


Measured memory_bytes: 1792
s = int(input())

aa = [s]
i = 1

while True:
    if aa[i-1] % 2 == 0:
        fn = aa[i-1] // 2
    else:
        fn = 3 * aa[i-1] + 1
    i += 1
    if fn in aa:
        print(i)
        break
    else:
        aa.append(fn)


Measured memory_bytes: 2940
import math
def A():
    N, M = map(int, input().split())
    if N == 1 == M:
        print(0)
        return
    ans = 0
    if N > 1:
        ans += math.factorial(N)//(2*(math.factorial(N-2)))
    if M > 1:
        ans += math.factorial(M)//(2*(math.factorial(M-2)))
    print(ans)

def B():
    S = input()
    if not S:
        print('No')
        return
    # for i in range(len(S)//4):
    #     # print(S[i], S[len(S)//2-i-1], S[len(S)//2+i+1], S[-i-1])
    #     if not (S[i] == S[(len(S)-1)//2-i-1] == S[(len(S)+3)//2+i-1] == S[-i-1]):
    #         print('No')
    #         return
    for i in range(len(S)):
        if not S[i] == S[len(S)-i-1]:
            print('No')
            return
    for i in range((len(S)-1)//2):
        if not S[i] == S[(len(S)-1)//2-i-1]:
            print('No')
            return
        if not S[(len(S)+3)//2+i-1] == S[len(S)-i-1]:
            print('No')
            return
    print('Yes')

import math
def C():
    L = int(input())
    print(math.pow((L/3), 3))

from collections import Counter
def D():
    N = int(input())
    A = [int(i) for i in input().split()]
    counts = Counter(A)
    combi = 0
    for a in counts:
        if counts[a] > 1:
            combi += math.factorial(counts[a])//(2*(math.factorial(counts[a]-2)))
    for k in range(N):
        print(max(0, combi-(counts[A[k]]-1)))
D()

Measured memory_bytes: 26900
#include<stdio.h>

int main(void){
    int a,b,add,sub,kake,max;

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

    add=a+b;
    sub=a-b;
    kake=a*b;

    max=add;
    if(max<sub){
        max=sub;
    }

    if(max<kake){
        max=kake;
    }

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

    return 0;
}

Measured memory_bytes: 128
import numpy as np
N = int(input())
h = list(map(int, input().split()))


memo = np.full(N, 10**4)
memo[0] = 0
memo[1] = abs(h[0] - h[1])
for i in range(2, N):
    memo[i] = min([memo[i-1] + abs(h[i-1] - h[i]), memo[i-2] + abs(h[i-2] - h[i])])
print(memo[N-1])

Measured memory_bytes: 38864
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 305;
const int INF = (LL)1e9 + 5;
const int MOD = 998244353;

int N, M, C[MAXN][MAXN], pw[MAXN];
vector<bitset<MAXN>> a;

void gaussian(vector<bitset<MAXN>> &a) {
	int pos = 0;
	for (int j = 0; j < M && pos < N; j++) {
		bool go = false;
		for (int i = pos; i < N; i++) {
			if (a[i][j]) {
				swap(a[i], a[pos]);
				go = true;
				break;
			}
		}
		if (!go) continue;
		for (int i = pos + 1; i < N; i++) {
			if (a[i][j]) {
				a[i] ^= a[pos];
			}
		}
		pos++;
	}
}

int qpow(int a, int pw) {
	int res = 1;
	while (pw) {
		if (pw & 1) res = (LL) res * a % MOD;
		pw >>= 1;
		a = (LL) a * a % MOD;
	}
	return res;
}

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

	for (int n = 1; n < MAXN; n++) {
		C[n][0] = C[n][n] = 1;
		for (int k = 1; k < n; k++) {
			C[n][k] = C[n - 1][k] + C[n - 1][k - 1];
			C[n][k] %= MOD;
		}
	}

	cin >> N >> M;
	a.resize(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			int x;
			cin >> x;
			a[i][j] = x;
		}
 	}

	int r = 0;
	gaussian(a);
	for (int i = 0; i < N; i++) {
		if (a[i].any()) {
			r++;
		}
	}

	int ans = 0;
	assert(r <= N && r <= M);
	for (int i = 1; i <= r; i += 2) {
		int add = (LL) C[r][i] * qpow(3, r - i) % MOD * qpow(2, N + M - r - r) % MOD;
		ans = (ans + add) % MOD;
	}
	
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
const int limit = 50;

int n,m;
int a[limit],b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
  visited[v] = true;
  for(int v2=0;v2<n;v2++){
    if(graph[v][v2] == false)
    continue;
    if(visited[v2] == true)
    continue;

    dfs(v2);
  }
}

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

for(int i=0;i<m;i++){
  cin >> a[i] >> b[i];
  a[i]--;
  b[i]--;
  graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
}

int ans = 0;

for(int i=0;i<m;i++){
  graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

  for(int j=0;j<n;j++){
    visited[j] = false;
  }

  dfs(0);

  bool bridge = false;
  for(int j=0;j<n;j++){
    if(visited[j] == false)
    bridge = true;
  }
    if(bridge)
    ans++;

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>

int main() {
  std::vector<std::pair<int, char>> a;
  for (int i = 0; i < 3; ++i) {
    int x;
    scanf("%d", &x);
    a.emplace_back(x, 'A'+i);
  }

  std::sort(a.rbegin(), a.rend());
  printf("%c\n", a[0].second);
}



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

int main() {
  int N ; 
  cin >> N ; 
  vector<int> P(N+1) ; 
  
  for(int i = 1 ; i <= N ; i++ ) {
    cin >> P.at(i) ; 
  }
  
  int min = P.at(1); 
  int cnt = 0 ; 
  
  for(int i = 1 ; i <= N ; i++){
    

    
    if(min >= P.at(i) ){
      min = P.at(i) ;
            cnt++ ; 
    }
    else{

    }
    
     //   cout << i << " " <<  min << endl ; 
  }
  cout << cnt << endl ; 
  
}

Measured memory_bytes: 4056
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
                int l = sc.nextInt();
	        int[] A = new int[N];
      for(int i=0; i<N; i++){
A[i] = sc.nextInt();
}

System.out.println((N-1+l-2)/(l-1));
	}

}


Measured memory_bytes: 48392
#include <stdio.h>
#include <vector>
#include <algorithm>

#define MAX_SIZE 1500000

using namespace std;

int main(){
	int dansu,kansu,shelf[20],book[100],min_size,left,right,m,dansu_index,max_length;

	while(true){
		scanf("%d %d",&dansu,&kansu);
		if(dansu == 0 && kansu == 0)break;

		max_length = 0;

		for(int i = 0; i < kansu; i++){
			scanf("%d",&book[i]);
			max_length = max(max_length,book[i]);
		}

		min_size = MAX_SIZE;
		left = max_length,right = MAX_SIZE;
		m = (left+right)/2;

		while(left < right){

			for(int i = 0; i < dansu; i++)shelf[i] = m;
			dansu_index = 0;
			for(int i = 0; i < kansu && dansu_index < dansu;){
				if(shelf[dansu_index] >= book[i]){
					shelf[dansu_index] -= book[i];
					i++;
				}else{
					dansu_index++;
				}
			}

			if(dansu_index == dansu){
				left = m + 1;
				m = (left + right)/2;
			}else{
				min_size = min(min_size,m);
				right = right - 1;
				m = (left + right)/2;
			}
		}

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

	}

    return 0;
}

Measured memory_bytes: 2708
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int K, T;
    cin >> K >> T;
    vi a(T);
    rep(i, T) cin >> a[i];

    int pre_id = -1;
    while (true) {
        int ma = -1;
        int ma_id = -1;
        rep(i, T) {
            if (i != pre_id && ma < a[i]) {
                ma = a[i];
                ma_id = i;
            }
        }
        if (ma <= 0) {
            cout << a[pre_id] << endl;
            return 0;
        }
        a[ma_id]--;
        pre_id = ma_id;
        if (*max_element(all(a)) == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;

int main() {
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = []
for _ in range(N):
    S.append(input())
word_dict = {}
for word in S:
    if word in word_dict:
        word_dict[word] += 1
    else:
        word_dict[word] = 1

max_v = max(word_dict.values())

for key in sorted(word_dict):
    if word_dict[key] == max_v:
        print(key)

Measured memory_bytes: 35212
import sys
from typing import List


class Dice:

    def __init__(self, values: List[int]):
        self.face_value = values

    def get_value(self, face_num) -> int:
        return self.face_value[face_num]

    def get_all_values(self) -> str:
        return ' '.join(map(str, self.face_value))

    def get_upper_value(self) -> int:
        return self.get_value(0)

    def invoke_method(self, mkey: str) -> None:
        if mkey == 'S':
            self.S()
        elif mkey == 'N':
            self.N()
        elif mkey == 'E':
            self.E()
        elif mkey == 'W':
            self.W()
        else:
            raise ValueError(f'This method does not exist. : {mkey}')

    def set_value(self, s0, s1, s2, s3, s4, s5) -> None:
        self.face_value[0] = s0
        self.face_value[1] = s1
        self.face_value[2] = s2
        self.face_value[3] = s3
        self.face_value[4] = s4
        self.face_value[5] = s5

    def S(self) -> None:
        self.set_value(self.face_value[4], self.face_value[0],
                       self.face_value[2], self.face_value[3],
                       self.face_value[5], self.face_value[1])

    def N(self) -> None:
        self.set_value(self.face_value[1], self.face_value[5],
                       self.face_value[2], self.face_value[3],
                       self.face_value[0], self.face_value[4])

    def E(self) -> None:
        self.set_value(self.face_value[3], self.face_value[1],
                       self.face_value[0], self.face_value[5],
                       self.face_value[4], self.face_value[2])

    def W(self) -> None:
        self.set_value(self.face_value[2], self.face_value[1],
                       self.face_value[5], self.face_value[0],
                       self.face_value[4], self.face_value[3])

    def R(self) -> None:
        """横回転."""
        self.set_value(self.face_value[0], self.face_value[2],
                       self.face_value[4], self.face_value[1],
                       self.face_value[3], self.face_value[5])


def check_R(dice1, dice2) -> bool:
    """横回転をチェックする."""
    for _i in range(4):
        dice1.R()
        if dice1.get_all_values() == dice2.get_all_values():
            return True
    return False


# 提出用
data1 = [int(i) for i in input().split()]
data2 = [int(i) for i in input().split()]

# # 動作確認用1
# with open('input_itp1_11_c_2.txt', mode='r', encoding='utf8') as fin:
#     data1 = [int(i) for i in next(fin).split()]
#     data2 = [int(i) for i in next(fin).split()]

dice1 = Dice(data1)
dice2 = Dice(data2)


for _i in range(4):
    dice1.S()
    if dice1.get_upper_value() == dice2.get_upper_value():
        if check_R(dice1, dice2):
            print('Yes')
            sys.exit()

for _i in range(4):
    dice1.E()
    if dice1.get_upper_value() == dice2.get_upper_value():
        if check_R(dice1, dice2):
            print('Yes')
            sys.exit()

print('No')


Measured memory_bytes: 7192
#include"bits/stdc++.h"
using namespace std;

char in[120];
pair<pair<string,int>,int> p[110];
int main(){
     int N;
     cin >> N;
     for(int i=0;i<N;i++){
        int t;
        scanf("%s%d",in,&t);
        string tmp=in;
        p[i]=make_pair(make_pair(in,-t),i);
    }
    sort(p,p+N);
    for(int i=0;i<N;i++)printf("%d\n",p[i].second+1);
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int N, K;
ll res;

int main() {
	cin >> N >> K;
	if (K) {
		for (int i = K + 1; i != N + 1; ++i) {
			res += (N / i)*(i - K) + max(0, N%i - K + 1);
		}
	}
	else {
		res = (ll)N * N;
	}
	cout << res << endl;
	return 0;
}

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

int main(){
    int a1,a2,b;
    while(cin>>a1>>a2>>b){
        int cmax=min(10,20-(a1+a2));
        int cmin=1;
        int n=cmax-cmin+1;
        if(cmin<=a1 && a1<=cmax) n--;
        if(cmin<=a2 && a2<=cmax) n--;
        if(cmin<=b  &&  b<=cmax) n--;
        cout<<((double)n/7>=0.5 ? "YES" : "NO")<<endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;

int main(){
	ll N,K;
	cin>>N>>K;
	int ans = 0;
	for(int i = K; i<=N+1; ++i){
		int nax = i*(2LL*N-i+1LL)/2LL %MOD;
		int nin = i*(0+(i-1LL))/2LL %MOD;
		// cout<<nin<<' '<<nax<<endl;
		ans += nax-nin+1LL;
		ans %= MOD;
	}
	if(ans<0)ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#define K 3000008
#define M 524288
#define N 200001
#define p 924844033
#define ll long long
inline int mod(int x){return x>=p?x-p:x;}
inline int mul(int x,int y){return(ll)x*y%p;}
inline int calc(int x,int y)
{
	int z=1;
	for(;y;x=1ll*x*x%p,y>>=1)if(y&1)z=1ll*z*x%p;
	return z;
}
char G[K],*H=G;
inline int read()
{
	int x=0;
	while(*H<48||57<*H)H++;
	while(47<*H&&*H<58)x=(x<<1)+(x<<3)+(*H++^48);
	return x; 
}
int S[10],T;
inline void print(int x)
{
	int y;
	do y=x/10,S[++T]=x-y*10,x=y;while(x);
	while(T)*H++=S[T--]^48;
}
int a[N],b[N<<1],c[N<<1],d[N],e[N],f[M],l[M],m,n,r[M],s[N],t,w[M|1],x,y;
void dfs(int u,int v){for(int i=a[u];i;i=b[i])if(c[i]!=v)dfs(c[i],u),s[u]+=s[c[i]],l[n-s[c[i]]]++,l[s[c[i]]]++;}
int I,J,v;
inline void NTT(int*o,int u)
{
	for(int i=0;i<m;i++)if(f[i]>i)t=o[f[i]],o[f[i]]=o[i],o[i]=t;
	for(int i=1;i<m;i<<=1)for(I=0,J=i,u>>=1;J<m;I+=i,J+=i)for(v=m&u;J&i;v+=u)x=o[I],y=mul(w[v],o[J]),o[I++]=mod(x+y),o[J++]=mod(p+x-y);
}
int main()
{
	fread(G,1,K,stdin),s[n=read()]=1;
	for(int i=1,u,v;i<n;i++)s[i]=1,b[++t]=a[u=read()],c[a[u]=t]=v=read(),b[++t]=a[v],c[a[v]=t]=u;
	dfs(m=1,0),t=0;
	while(m<=n<<1)m<<=1,t++;
	w[*d=d[1]=*e=e[1]=*w=w[m]=1]=calc(5,p>>t--),f[1]=1<<t;
	for(int i=2;i<m;i++)f[i]=f[i>>1]>>1|(i&1)<<t,w[i]=mul(w[i-1],w[1]);
	for(int i=2;i<=n;i++)d[i]=mul(d[i-1],i),e[i]=mul(p-p/i,e[p%i]);
	for(int i=2;i<=n;i++)e[i]=mul(e[i],e[i-1]);
	for(int i=0;i<=n;i++)l[i]=mul(l[i],d[i]),r[i]=e[n-i];
	NTT(l,m),NTT(r,m),H=G;
	for(int i=0;i<m;i++)l[i]=mul(l[i],r[i]);
	NTT(l,-m),t=calc(m,p-2);
	for(int i=1;i<=n;i++)print(mod(p+mul(mul(mul(d[n],e[n-i]),e[i]),n)-mul(mul(l[n+i],t),e[i]))),*H++='\n';
	fwrite(G,1,H-G,stdout);
	return 0;
}

Measured memory_bytes: 27008
//codeforces 1337C
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ps(x,y) fixed<<setprecision(y)<<x
#define all(x) x.begin(),x.end()
#define endl "\n"
#define io ios_base::sync_with_stdio(false); cin.tie(0)
int const mod = 1000000000+7;
int32_t main() {
    io;
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
  int n,m,a,sum = 0;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    cin >> a;
    sum += a;
  }
  if(sum <= n)
    cout << n - sum << endl;
  else
    cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3612
import statistics
import math
N = int( input())
temp = list(map(int,input().split(" ")))
for i in range(len(temp)):
    temp[i] = (temp[i] - (i+1))

m = statistics.median(temp)
nums = list(map(lambda x:abs(x-m),temp))
ans = sum(nums)
ans = int(ans)
print(ans)

Measured memory_bytes: 27236
N,W = map(int,input().split())
value = [0]
weight = [0]
for i in range(N):
    v,w = map(int,input().split())
    value.append(v)
    weight.append(w)

dp = [[0]*(W+3) for _ in range(N+3)]
for w in range(1,W+1):
    for k in range(1,N+1):
        if weight[k] > w:
            dp[k][w] = dp[k-1][w]
        else:
            #print(dp[k-1][w])
            dp[k][w] = max(dp[k-1][w], value[k] + dp[k-1][w-weight[k]])
print(dp[N][W])



Measured memory_bytes: 25664
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int64 {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return int64(n)
}

func binarySearch(x, n int64, arr []int64) bool {

	var reSearch func(b, e int64) bool

	reSearch = func(b, e int64) bool {
		if b >= e {
			return false
		}
		m := (b + e) / 2
		if arr[m] == x {
			return true
		}
		if arr[m] < x {
			return reSearch(m+1, e)
		}
		return reSearch(b, m)
	}

	return reSearch(0, n)
}

func parseArrInt(l int64, strArr []string) []int64 {
	var intArr []int64

	for i := 0; i < len(strArr); i++ {
		n, _ := strconv.Atoi(strArr[i])
		intArr = append(intArr, int64(n))

	}
	return intArr
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	sarr := make([]int64, n)
	for i, _ := range sarr {
		sarr[i] = nextInt()
	}

	q := nextInt()
	tarr := make([]int64, q)
	for i, _ := range tarr {
		tarr[i] = nextInt()
	}

	count := 0
	for _, t := range tarr {
		if binarySearch(t, n, sarr) {
			count++
		}
	}

	fmt.Println(count)

}



Measured memory_bytes: 3120
N, M = map(int, input().split())
H = list(map(int, input().split()))

route = [[H[i]] for i in range(N)]

for i in range(M):
    A, B = map(int, input().split())
    A = A - 1
    B = B - 1
    route[A].append(H[B])
    route[B].append(H[A])

ans = 0
for i in range(len(route)):
    if route[i].count(H[i]) != 1:
        continue
    if H[i] == max(route[i]):
        ans += 1
print(ans)

Measured memory_bytes: 95800
# coding: utf-8
import functools
n = int(input())
A = list(map(int, input().split(" ")))

res = 0
hist = []
for i in range(n-1):
    if A[i] > A[i+1]:
        sa = A[i] - A[i+1]
        res += sa
        A[i+1] += sa

print(res)


Measured memory_bytes: 33692
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll solve(ll N, ll K, vector<pair<ll, ll>>& d_and_ts) {
    // おいしさの大きい順に、単にとっていく
    ll base = 0;
    set<ll> seen;
    priority_queue<ll, vector<ll>, greater<ll> > deletable;
    ll kind = 0;
    REP(k, K) {
        auto d = -d_and_ts[k].first;
        auto t = d_and_ts[k].second;
        // cout << "d, t = " << d << "," << t << endl;
        base += d;
        if (seen.count(t)) {
            deletable.push(d);
        } else {
            ++kind;
        }
        seen.insert(t);
    }
    ll bonus = kind * kind;
    ll score = base + bonus;
    ll ans = score;
    // cout << "base " << base << " + bonus " << bonus << " = score " << score << endl;

    // deletableから1個減らし、代わりに新しい種類を加える
    FOR(k, K, N) {
        if (deletable.empty()) break;

        auto d = -d_and_ts[k].first;
        auto t = d_and_ts[k].second;
        if (!seen.count(t)) {
            seen.insert(t);
            ++kind;
            auto dele = deletable.top();
            deletable.pop();
            base -= dele;
            base += d;
            ll bonus = kind * kind;
            ll score = base + bonus;
            ans = max(ans, score);
            // cout << "base " << base << " + bonus " << bonus << " = score " << score << endl;
        }
    }
    return ans;
}



int main(void)
{
    cin.sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;

    vector<pair<ll, ll>> d_and_ts;
    map<ll, vector<ll>> t_to_ds;
    REP(n, N) {
        ll t, d;
        cin >> t >> d;
        t_to_ds[t].pb(d);
        d_and_ts.pb({-d, t});
    }
    sort(ALL(d_and_ts));

    auto mine = solve(N, K, d_and_ts);
    cout << mine << endl;

    // vector<ll> bests;
    // vector<ll> remains;
    // for(auto kv: t_to_ds) {
    //     auto ds = kv.second;
    //     sort(ALL(ds));
    //     reverse(ALL(ds));
    //     REP(i, SIZE(ds)) {
    //         if (i == 0) bests.pb(ds[i]);
    //         else remains.pb(ds[i]);
    //     }
    // }

    // auto mx_kind = SIZE(t_to_ds);
    // FOR(i, 1, mx_kind + 1) {
        
    // }


    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;    
using pll = pair<ll, ll> ;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define ar array
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) ((long long)x.size())


template<typename T> void umin(T& a,T b){a = min(a,b);}
template<typename T> void umax(T& a,T b){a = max(a,b);}

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){


}

void solve(){    

    int n;
    cin >> n;
    long long a[n+1];
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    long long ans=0;
    for(int i=1;i<n;i++){
        if(a[i] > a[i+1]){
            ans += a[i] - a[i+1];
            a[i+1] = a[i];
        }
    }
    cout << ans;


}

int32_t main(){
    #ifndef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;
    //cin >> T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 5176
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

void solveA()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << "\n";
}

void solveB()
{
	int N;
	string S;
	cin >> N;
	cin >> S;
	int cur = 0;
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'I') cur++;
		else cur--;

		ans = max(ans, cur);
	}
	cout << ans << "\n";
}

int main()
{
	solveB();
}

Measured memory_bytes: 384