akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];

    map<char, int> mp;
    REP(i, h) REP(j, w) mp[s[i][j]]++;
    vector<int> a;
    for(auto x : mp) a.pb(x.second);
    sort(all(a), greater<int>());
    
    // abczcba
    // defzfed
    // ghiwihg
    // defzfed
    // abczcba

    if(h >= 2 && w >= 2){
        if(h % 2 == 0 && w % 2 == 0){
            for(auto x : a) if(x % 4 != 0){cout << "No" << endl; return 0;}
        }else if(h % 2 == 0 || w % 2 == 0){
            REP(i, (h/2) * (w/2)){
                if(a[0] < 4){cout << "No" << endl; return 0;}
                a[0] -= 4;
                sort(all(a), greater<int>());
            }
            for(auto x : a) if(x % 2 != 0){cout << "No" << endl; return 0;}
        }else{
            REP(i, (h/2) * (w/2)){
                if(a[0] < 4){cout << "No" << endl; return 0;}
                a[0] -= 4;
                sort(all(a), greater<int>());
            }
            REP(i, h/2){
                if(a[0] < 2){cout << "No" << endl; return 0;}
                a[0] -= 2;
                sort(all(a), greater<int>());
            }
            REP(i, w/2){
                if(a[0] < 2){cout << "No" << endl; return 0;}
                a[0] -= 2;
                sort(all(a), greater<int>());
            }
        }
    }else{
        REP(i, max(w, h)/2){
            if(a[0] < 2){cout << "No" << endl; return 0;}
            a[0] -= 2;
            sort(all(a), greater<int>());
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char n[3];
  for (int i=0; i < 3; i++) {
    scanf("%c", &n[i]);
  }
  if (n[0] == n[1] && n[0] == n[2]) {
    printf("No");
  } else {
    printf("Yes");
  }
    
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int H,heap[2000001];
void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;

  //左の子、自分、右の子で値が最大のものを選択

  if(l<=H&&heap[l]>heap[i]) largest=l;
  else largest=i;
  if(r<=H&&heap[r]>heap[largest]) largest=r;

  if(largest!=i){
    swap(heap[i],heap[largest]);
    maxHeapify(largest);
  }
}
int main(){
  scanf("%d",&H);
  for(int i=1;i<=H;++i) scanf("%d",&heap[i]);
  for(int i=H/2;i>=1;--i) maxHeapify(i);
  for(int i=1;i<=H;++i) printf(" %d",heap[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 5164
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

import numpy as np

n = int(input())
a = np.array([list(map(int, input().split())) for _ in range(n)])

g = csr_matrix(a)
dist = floyd_warshall(g)

if (dist == a).all():
    sm = dist.sum()

    INF = 10 ** 18 + 1
    for i in range(n):
        dist[i, i] = INF

    for u in range(n):
        for v in range(n):
            if u == v:
                continue

            mn = np.min(dist[u] + dist[v])
            if mn == dist[u, v]:
                sm -= dist[u, v]

    ans = int(sm) // 2
    print(ans)

else:
    print(-1)


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

ll temp1,temp2,temp;
char tempc;

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

#define N 1000000007
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

ll binpow(ll a, ll b)
{
    a%=N;b=b%(N-1);
    ll res=1;
    while(b>0)
    {
        if(b&1) res=res*a%N;
        a=a*a%N;
        b>>=1;
    }
    return res%N;
}

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

// struct DSU {
//     vector<int> sz;
//     vector<int> parent;
 
//     void make_set(int v) {
//         parent[v] = v;
//         sz[v] = 1;
//     }
 
//     int find_set(int v) {
//         if (v == parent[v])
//             return v;
//         return parent[v] = find_set(parent[v]);
//     }
 
//     void union_sets(int a, int b) {
//         a = find_set(a);
//         b = find_set(b);
//         if (a != b) {
//             if (sz[a] < sz[b])
//                 swap(a, b);
//             parent[b] = a;
//             sz[a] += sz[b];
//         }
//     }
 
//     DSU(int n) {
//         sz.resize(n+1);
//         parent.resize(n+1);
//         for (int i = 1; i <= n; i++) make_set(i);
//     }
// };

int val(int n)
{
    int count=0;
    while(n)
    {
        n/=2;
        count++;

    }
    return count-1;
}

signed main()
{
    fast;
    int n; cin >> n;
    set <string> si;
    forn(i,n)
    {
        string str; cin >> str;
        si.insert(str);
    }
    cout << si.size() << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N), X(110000);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
    X[a.at(i)]++;
    X[a.at(i)+1]++;
    if(a.at(i)!=0){
      X[a.at(i)-1]++;
    }
  }
  int ans=0;
  for(int i: X){
    ans=max(ans,i);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3920
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <iomanip>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int ans[225816];

int main(void){
	int n,i,a;
	std::cin >> n;
	for(i=1; i<n; ++i){
		std::cin >> a;
		++ans[--a];
	}
	for(i=0; i<n; ++i){
		std::cout << ans[i] << std::endl;
	}
	return 0;
}


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

int main() {
  int a;
  cin>>a;
  int p,q;
  p=0;
  
  for(int i=0;i<a;i++){
    cin>>q;
    if(q!=i+1){
      p++;
    }
  }
  
  if(p==0||p==2){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; ++i) {
		int sum = 0;
		for (int j = i; j > 0; j /= 10) {
			sum += j % 10;
		}
		if (sum >= a && sum <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

from collections import defaultdict
from heapq import heappush, heappop
import sys
import numpy as np
import itertools
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x, file=sys.stderr)


def solve(H, W, K, data):
    "void()"
    data = (data == 35)
    ret = 0
    for x in itertools.product((0, 1), repeat=W):
        dX = data * x
        for y in itertools.product((0, 1), repeat=H):
            s = (dX.T * y).sum()
            if s == K:
                ret += 1
    return ret


def main():
    H, W, K = map(int, input().split())
    data = np.array([list(input().strip()) for i in range(H)])
    print(solve(H, W, K, data))


T1 = """
2 3 2
..#
###
"""


T2 = """
2 3 4
..#
###
"""

T3 = """
2 2 3
##
##
"""

T4 = """
6 6 8
..##..
.#..#.
#....#
######
#....#
#....#
"""


def test_T4():
    """
    >>> as_input(T4)
    >>> main()
    208
    """


def test_T3():
    """
    >>> as_input(T3)
    >>> main()
    0
    """


def test_T2():
    """
    >>> as_input(T2)
    >>> main()
    1
    """


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    5
    """


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())

    def input():
        return bytes(f.readline(), "ascii")

    def read():
        return bytes(f.read(), "ascii")


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 27324
N = int(input())
H = list(map(int, input().split()))
# print(H)
count = 0
while sum(H) > 0:
    flag = 0
    for i, h in enumerate(H):
        if h > 0 and flag == 0:
            H[i] -= 1
            flag = 1
        elif h == 0 and flag == 1:
            break
        elif h == 0 and flag == 0:
            continue
        else:
            H[i] -= 1
    count += 1
    # print(H)
print(count)

Measured memory_bytes: 41196
#include <bits/stdc++.h>
#define dbgi(x) cout << #x << " = " << (x) << "\n";
#define dbgvi(x) cout << #x << " = "; for(int i = 0; i < (x.size()); ++i) cout << x[i] << " ";
#define mrk() cout << "HERE\n"
#define int long long
#define vi vector < int >
#define vii vector < vi >
#define viii vector < vii >
#define viiii vector < viii >
#define pii pair < int, int >
#define vpii vector < pii >
#define foru(i, a, b) for(int i = a; i < b; ++i)
#define ford(i, b, a) for(int i = b; i > a; --i)
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ld long double
using namespace std;

set < int > bad;

bool check(int a){
    while(a){
        if(bad.count(a % 10))return false;
        a /= 10;
    }
    return true;
}



signed main(){
    int n, k;
    cin >> n >> k;
    foru(i, 0, k){
        int t;
        cin >> t;
        bad.insert(t);
    }
    foru(i, n, 1000 * 1000 + 100){
        if(check(i)){
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

int arr[25];

int main() {
	fastio;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int mx = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (arr[i] >= mx) {
			ans++;
			mx = arr[i];
		}
	}
	cout << ans << endl;
	return 0;
}
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    const int mod = 1000000007;
    const int range = 2000000000;
    #define ll long long
    #define rep(i,n) for(int i=0 ; (n) >i; i++)

        int main(){
            int n; cin >> n; 
            std::vector<int> ans(n);
            rep(i,n) cin >> ans[i];

            int res = 0;

            while(true){
                bool check = false;
                for(int j=0 ; j<n ;j++){
                  if(ans[j]%2 == 1) check = true;  
                }

                if(check) break;

                for(int j=0 ; j<n ; j++){
                    ans[j] /=2;
                }
                res++;
            }

            cout << res << endl;

            return 0;
        }




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

char grid0[110][110];
char grid1[110][110];
char grid2[110][110];

int main(){
  int h,w;
  cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>grid0[i][j];
  }
  int H=0;
  rep(hi,h){
    bool flag=0;
    rep(wi,w){
      if(grid0[hi][wi]=='#')flag=1;
    }
    if(flag){
      rep(wi,w){
        grid1[H][wi]=grid0[hi][wi];
      }
      H++;
    }
  }
  int W=0;
  rep(wi,w){
    bool flag=0;
    rep(hi,H){
      if(grid1[hi][wi]=='#')flag=1;
    }
    if(flag){
      rep(hi,H){
        grid2[hi][W]=grid1[hi][wi];
      }
      W++;
    }
  }
  rep(i,H){
    rep(j,W){
      cout<<grid2[i][j];
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int N, L;
  cin >> N >> L;
  vector<string> V(N,string());
  for(int i = 0; i < N; i++) cin >> V[i];
  sort(V.begin(), V.end());
  for(int i = 0; i < N; i++) cout << V[i];
}

Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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 pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
long long GCD(long long a,long long b){
    if(b==0)return a;
    return GCD(b,a%b);
}
long long LCM(long long a,long long b){
    return a*b/GCD(a,b);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,w;
    cin>>n>>w;
    VV dp(n+2,V(1e6,INF));
    VP vec(n);
    dp[0][0]=0;
    rep(i,n){
        cin>>vec[i].F>>vec[i].S;
    }
    rep(i,n){
        rep(j,1e6){
            chmin(dp[i+1][j],dp[i][j]);
            if(j>=vec[i].S){
                chmin(dp[i+1][j],dp[i][j-vec[i].S]+vec[i].F);
            }
        }
    }
    for(int i=1e6-1;i>=0;i--){
        if(dp[n][i]<=w){
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 805248
#include<bits/stdtr1c++.h>
#include<list>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if (abs(x-a) <= abs(x-b)){
        cout << "A" << endl;
    }
    else{
        cout << "B" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll c[20001];
int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=0;
	for(ll i=0;i<n;i++){
		cin>>c[i];
	}
	ans=max(ans,abs(b-c[n-1]));
	if(n!=1){
	ans=max(ans,abs(c[n-1]-c[n-2]));
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

using ll = long long;

int main(){

  int n;
  cin >> n;
  ll ans = 0;

  priority_queue<int> que;
  ll a;
  for(int i=0;i<n;i++){
    cin >> a;
    que.push(a);
  }

  queue<int> points;
  a=que.top();
  que.pop();
  points.push(a);
  while(!que.empty()){
    a=que.top();
    que.pop();
    points.push(a);
    points.push(a);
    ans+=points.front();
    points.pop();
    //cout << ans << endl;
  }

  cout << ans << endl;
}

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

using namespace std;
using ll =long long;
using db = double;

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; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;

ll ans;
//ここから書き始める
int main()
{
	cout << setprecision(10);
	int A , B;
	cin >> A >> B;//Aが白 B が黒
	vector<vector<char>> grid(100,vector<char> (100));
	rep(i,100){
		rep(j,100){
			if(j<50){
				grid[i][j]='.';
			}else{
				grid[i][j]='#';
			}
		}
	}
//	rep(i,100){
//		rep(j,100){
//			cout<<grid[i][j];
//		}
//		cout << endl;
//	}
	int white = 1;//Aにする
	int black = 1;//Bにする
	//blackから考えるか
	int i = 0, j =0;
	while(black<B){
		grid[i][j]='#';
		j+=2;
		black ++;
		if(j>=49){
			j = 0;
			i += 2;
		}
	}
	i = 0, j = 51;
	while(white<A){
		grid[i][j]='.';
		white ++;
		j += 2 ;
		if(j>=99){
			j = 51;
			i+=2;
		}
	}
	cout << 100<<" "<<100<<endl;
	rep(i,100){
		rep(j,100){
			cout<<grid[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2165

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

#define EPS 1e-10

double entropy(int s, int a, int c, vector<int> I)
{
	const int mod = 256;
	int n = I.size();

	//R(0)を除いて、n個必要である
	vector<int> R(n+1);
	R[0] = s;
	rep(i,n){ R[i+1] = (a*R[i]+c) % mod; }

	//R(1)からn個回して、O(n)を作成する
	vector<int> O(n);
	rep(i,n){ O[i] = (I[i] + R[i+1]) % mod; }

	//数字の出現回数を記録する
	vector<int> freq(256,0);
	rep(i,n){ freq[O[i]]++; }

	//エントロピーを求める
	double h=0;
	rep(i,256)
	{ 
		if(!freq[i]){ continue; }
		h -= ((double)freq[i]/n) * log((double)freq[i]/n);
	}
	
	return h;
}

int main()
{
	int N;

	while(cin >> N && N)
	{
		vector<int> I(N);
		rep(i,N){ cin >> I[i]; }

		double ans_h = 1e10; //大きい数で初期化
		int ans_s, ans_a, ans_c;
		rep(s,16){
			rep(a,16){
				rep(c,16)
				{
					double h = entropy(s,a,c,I);
					if(h+EPS<ans_h) //誤差予防にEPSが必要
					{
						ans_h = h;
						ans_s = s;
						ans_a = a;
						ans_c = c;
					}
				}
			}
		}

		cout << ans_s << " " << ans_a << " " << ans_c << endl;
	}

	return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  string S;
  cin>>S;
  if(S=="Sunny") cout<<"Cloudy"<<endl;
  else if(S=="Cloudy") cout<<"Rainy"<<endl;
  else if(S=="Rainy") cout<<"Sunny"<<endl;
  return 0;
}


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

int main()
{
	int i,ans=0,n,now=0;
	char a;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a;
		if(a=='I')
		{
			now++;
			ans=max(now,ans);
		}
		else	now--;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	ll n;
	cin >> n;
	ll r = 600;
	ll k = 8;
	while (true) {
		if (n < r) {
			cout << k << endl;
			return 0;
		}
		r += 200;
		--k;
	}
}


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

int main() {
    int A[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) cin >> A[i][j];
    }
    bool card[3][3] = {false};
    int N;
    cin >> N;
    int b[N];
    for (int i = 0; i < N; i++) {
        cin >> b[i];
        }       
     for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < N; k++){
            if (b[k] == A[i][j]) card[i][j] = true;
            }
        }
        
    }
    string ans = "No";
    for (int i = 0; i < 3; i++) {
        if (card[i][0] && card[i][1] && card[i][2]) ans = "Yes";
        if (card[0][i] && card[1][i] && card[2][i]) ans = "Yes";
    }
    if (card[0][0] && card[1][1] && card[2][2]) ans = "Yes";
    if (card[0][2] && card[1][1] && card[2][0]) ans = "Yes";
    cout << ans << 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;
int main() {
  ll n; cin>>n;
  vector<ll> a(n);
  ll sm=0;
  rep(i, n) {
    cin>>a.at(i);
    sm+=a.at(i);
  }
  ll av1=(sm+n-1)/n;
  ll av2=sm/n;
  ll hp1=0;
  ll hp2=0;
  rep(i, n) hp1+=(a.at(i)-av1)*(a.at(i)-av1);
  rep(i, n) hp2+=(a.at(i)-av2)*(a.at(i)-av2);
  cout << min(hp1, hp2) << endl;
}

Measured memory_bytes: 256
/*-- ILSH  --*/

// Multipoll evaluation + Divide and Conquer
// Time ( Iterative ) < Time ( Recursive )

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double ld;

#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll > 
#define len length 
#define fi first
#define se second
#define dt cout<<"HEre\n";
#define sz(x) (ll)x.size()
const ll inf=1e18+1e17;
const ll mod = 1e9+7;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
const int N=(1<<18);
ll fac[N],faci[N];
inline ll add ( ll a, ll b){
	if ( a+b>mod)
		return a+b-mod;
	return a+b;
}
void init(){
	fac[0]=1;faci[0]=1;
	for ( int i=1;i<N;i++){
		fac[i]=(fac[i-1]*i)%mod;
		faci[i]=modInverse(fac[i],mod);
	}
}
void solve(){
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	int x=w-b;
	ll res=0;
	for ( int i=1;i<=h-a;i++){
		ll val1=(fac[i+b-2]*faci[i-1])%mod;
		val1=(val1*faci[b-1])%mod;
		int x1=h-i,x2=w-b-1;
//		cout<<x1<<' '<<x2<<'\n';
		ll val2=(fac[x1+x2]*faci[x1])%mod;
		val2=(val2*faci[x2])%mod;
		res=add(res,(val1*val2)%mod);
	}
	cout<<res<<'\n';
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
	//cin>>t;
	init();
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
    //	cout << clock() / double(CLOCKS_PER_SEC) << endl;
}


Measured memory_bytes: 7760
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}

//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
signed main() {
	int n, k;
	cin >> n >> k;
	COMinit();
	for (int i = 1; i <= k; i++)cout << COMB(k - 1, i - 1) * COMB(n - k + 1, i) % mod << endl;
	ggr
}

Measured memory_bytes: 7936
import java.util.Scanner;

class Card {
  char suit;
  int value;
}


public class Main {
  static void bubbleSort(Card[] a, int n) {
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j].value < a[j-1].value) {
          Card t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
        }
      }
    }
  }

  static void selectionSort(Card[] a, int n) {
    for (int i = 0; i < n; i++) {
      int minj = i;
      for (int j = i; j < n; j++) 
        if (a[j].value < a[minj].value) 
          minj = j;
      Card t = a[i];
      a[i] = a[minj];
      a[minj] = t;
    }
  }

  static boolean isStable(Card[] c1, Card[] c2, int n) {
    for (int i = 0; i < n; i++) 
      if (c1[i].suit != c2[i].suit) return false;
    return true;
  }

  static void print(Card[] a, int n) {
    for (int i = 0; i < n; i++) {
      System.out.print(a[i].suit);
      System.out.print(a[i].value);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
  }
  
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    Card[] c1 = new Card[n];
    Card[] c2 = new Card[n];
    String[] s = new String[n];
    for (int i = 0; i < n; i++) {
      c1[i] = new Card();
      c2[i] = new Card();
      s[i] = stdIn.next();
      c1[i].suit = s[i].charAt(0);
      c1[i].value = Integer.parseInt(s[i].substring(1,2));
      c2[i] = c1[i];
    }
  bubbleSort(c1, n);
  selectionSort(c2, n);
  print(c1, n);
  System.out.println("Stable");
  print(c2, n);
  if (isStable(c1, c2, n)) System.out.println("Stable");
  else System.out.println("Not stable");
  }
}

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

int main(){
    int N,K;
    scanf("%d %d", &N, &K);
    multiset<int> s;
    for(int i=0;i<N;i++){
        int x;
        scanf("%d", &x);
        s.insert(x);
    }
    int ans = 0;
    auto itr = s.begin();
    for(int i=0;i<K;i++){
        ans += *itr;
        itr++;
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 3764
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

#[allow(non_snake_case)]
fn main() {
    input! {
        N:usize,
        M:usize,
        H:[usize;N],
        v:[(usize,usize);M]
    }
    let mut ok = vec![true; N];
    for i in 0..M {
        let (mut a, mut b) = v[i];
        a -= 1;
        b -= 1;
        if H[a] >= H[b] {
            ok[b] = false;
        }
        if H[a] <= H[b] {
            ok[a] = false;
        }
    }
    let mut ans = 0;
    for i in 0..N {
        if ok[i] == true {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4436
import itertools

N, M = map(int, input().split())
L = list(map(str, input().split()))
tmp = [0 for _ in range(10)]
seq = []

for i in range(10 ** 5):
    tmp = str(i)
    flag = True
    for j in range(len(tmp)):
        if tmp[j] in L:
            flag = False
        
    if i >= N and flag == True:
        res = i
        break

        
print(res)

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N, M;
    cin >> N >> M;

    vector<ll> A(N);
    vector<pair<ll,ll>> BC(M);

    rep(i,N){
        cin >> A[i];
    }

    rep(i,M){
        cin >> BC[i].second;
        cin >> BC[i].first;
    }

    sort(A.begin(),A.end());
    sort(BC.rbegin(),BC.rend());

    int index = 0;
    rep(i,N){
        if(BC[index].second == 0){
            index++;
        }

        if(M <= index){
            break;
        }

        if(BC[index].first <= A[i]){
            break;
        }else{
            A[i] = BC[index].first;
            BC[index].second--;
        }
    }

    ll sum = 0;
    rep(i,N){
        sum += A[i];
    }

    cout << sum << endl;

}

Measured memory_bytes: 2560
#include<stdio.h>
#define MAX 100
#define INF 999999
#define NIL -1
#define WHITE 0
#define BLACK 2

int prim();

int n, G[MAX][MAX], sum=0;

int main()
{
  int i, j;

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      for(j=0; j<n; j++)
	{
	  scanf("%d", &G[i][j]);
	}
    }
  
  printf("%d\n", prim());
  
  return 0;
}

int prim()
{
  int u, i, v, mincost, d[n], pi[n], color[n];

  for(u=0; u<n; u++)
    {
      d[u] = INF;
      pi[u] = NIL;
      color[u] = WHITE;
    }

  d[0] = 0;
  while(1)
    {
      mincost = INF;

      for(i=0; i<n; i++)
	{
	  if(color[i] != BLACK && d[i] < mincost)
	    {
	      mincost = d[i];
	      u = i;
	    }
	}
      
      if(mincost == INF) break;
      
      color[u] = BLACK;
      
      for(v=0; v<n; v++)
	{
	  if(color[v] != BLACK && G[u][v] < d[v] && G[u][v] != -1)
	    {
	      pi[v] = u;
	      d[v] = G[u][v];
	    }
	}
    }

  for(i=0; i<n; i++)
    {
      if(G[i][pi[i]] != -1) sum += G[i][pi[i]];
    }

  return sum;
}

Measured memory_bytes: 636
N = int(input())

if N == 1:
    print(0)
else:
    a = (10**N) % (10**9+7)
    b = (2*(9**N)) % (10**9+7)
    c = (8**N) % (10**9+7)
    print((a-b+c)%(10**9+7))

Measured memory_bytes: 10804
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<numeric>

using namespace std;

int N;
vector<int> A, B, C;

int input(){
  cin >> N;
  A.resize(N);
  B.resize(N);
  C.resize(N);
  for( int i = 0; i < N; i++ ){ cin >> A[i]; }
  for( int i = 0; i < N; i++ ){ cin >> B[i]; }
  for( int i = 0; i < N; i++ ){ cin >> C[i]; }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  return 0;
}

int main(){
  input();
  // B_iを用いてBとCで構築できる個数．
  vector<long> nBC(N);
  int i = 0, j = 0, li = 0;
  while( i < N && j < N ){
    if( B[i] < C[j] ){
      i++;
    }else if( B[i] >= C[j] ){
      for( int ii = li; ii < i; ii++ ){ nBC[ii] = N-j; }
      j++;
      li = i;
    }
  }
  for( int ii = li; ii < N; ii++ ){ nBC[ii] = N-j; }

  long n = 0;
  i = N-1, j = N-1, li = 0;
  while( i >= 0 && j >= 0 ){
    if( A[i] < B[j] ){
      n += nBC[j]*(i+1);
      j--;
    }else if( A[i] >= B[j] ){
      i--;
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
	char c;
	int n;
	for(;;)
	{
		n=0;
		for(;~(c=getchar())&&c!=10;c>30?n+=(c-'0'):0);
		if(n==0)return 0;
		printf("%d\n",n);
	}
}



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

int main(){
    int a,b;
    cin >> a >> b;
    if(a>b){
        cout << "a" << " " << ">" << " " << "b" << endl;
    }
    else if(a<b){
        cout << "a" << " " << "<" << " " << "b" << endl;
    }
    else{
        cout << "a" << " " << "==" << " " << "b" << endl;
    }
}


Measured memory_bytes: 3096
from collections import deque

N = int(input())
A = list(map(int, input().split()))

d = deque()

if N % 2 == 0:
	for i in range(N):
		if (i + 1) % 2 == 1:
			d.append(A[i])
		else:
			d.appendleft(A[i])
else:
	for i in range(N):
		if (i + 1) % 2 == 1:
			d.appendleft(A[i])
		else:
			d.append(A[i])
			
print(*d)

Measured memory_bytes: 98872
n,m=map(int, input().split())
xy=[list(map(int, input().split())) for _ in range(m)]

ball=[1]*n
red=[False]*n
red[0]=True
for i in range(m):
    x=xy[i][0]-1
    y=xy[i][1]-1
    if red[x]:
        red[y]=True
        if ball[x]==1:
            red[x]=False
    ball[y]+=1
    ball[x]-=1
print(red.count(True))


Measured memory_bytes: 28656
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#define ll long long
using namespace std;
const int maxn=1e5+10;
const ll mod=1e9+7;
ll fac[maxn],inv[maxn],a[maxn];
ll pow_mod(ll d,ll k){
    ll f=1;
    while(k){
        if(k&1) f=f*d%mod;
        d=d*d%mod;
        k>>=1;
    }
    return f;
}
void kb(){
    fac[0]=1;
    for(ll i=1;i<=1e5+2;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=pow_mod(i,mod-2);
        inv[i]=(inv[i]+inv[i-1])%mod;
    }
}
int main(){
    ll n;
    cin>>n;
    kb();
    for(ll i=1;i<=n;i++)cin>>a[i];
    ll sum=0;
    for(int i=1;i<=n;i++){
        sum=(sum+a[i]*(inv[i]+inv[n-i+1]-1)%mod)%mod;
    }
    cout<<sum*fac[n]%mod<<endl;
}


Measured memory_bytes: 5900
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long

using namespace std;

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int dp[N];

int32_t main() {
    speed;
    int n;
    cin >> n;
    dp[0] = 1;
    for ( int i = 0; i <= n; i++ ) {
        for ( int j = i + 3; j <= n; j++ ) {
            dp[j] += dp[i];
            dp[j] %= mod;
        }
    }
    cout << dp[n];
}


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  int val;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    val = 0;
    for (int j = 0; j < M; j++) {
      val += A.at(i).at(j) * B.at(j);
    }
    if (val + C > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long x = min(n, m), y = max(n, m);
    //long long ans = n * m;
    long long ans;
    if (x==1 && y == 1)
    {
        ans = 1;
    }
    else if (x == 1 && y!= 1)
    {
        ans = y-2;
    }
    else
    {
        ans = (x-2)*(y-2);
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> w(n);
    map<int, size_t> m;
    int minw=1e8;
    for (size_t i=0; i<n; ++i) {
        scanf("%d", &w[i]);
        m[w[i]] = 0;
        if (minw > w[i])
            minw = w[i];
    }

    {
        size_t k=0;
        for (pair<const int, size_t> &p: m)
            p.second = k++;
    }

    int res=0;
    vector<bool> done(n);
    for (size_t i=0; i<n; ++i) {
        if (done[i]) continue;

        int count_=0, minc=1e8, sum=0;
        size_t cur=i;
        for (count_=0; ; ++count_) {
            if (done[cur]) break;

            done[cur] = true;
            if (minc > w[cur])
                minc = w[cur];

            sum += w[cur];
            cur = m[w[cur]];
        }

        res += sum + min((count_-2)*minc, minc+minw*(count_+1));
    }

    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 2884
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int[] ary = new int[3];
    	for(int i = 0; i < 3; i++){
    		ary[i] = sc.nextInt();
		}
    	sc.close();
    	Arrays.sort(ary);
    	System.out.println(ary[0] * ary[1] / 2);
    }

}


Measured memory_bytes: 23764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

sm=0
n=I()
mx=0
s=input().rstrip()
for i in range(n):
    if s[i]=="I":
        sm+=1
    else:
        sm-=1
    if sm>mx:
        mx=sm
print(mx)

Measured memory_bytes: 3444
while num = gets.split(" ").map(&:to_i) do
  if(num[0] == 0 && num[1] == 0) then
    exit
  end
  num[1].times do
    printf "#"
  end
  printf "\n";
  (num[0]-2).times  do
    printf "#"
    (num[1]-2).times do
      printf "."
    end
    printf "#\n"
  end
  num[1].times do
    printf "#"
  end
  printf "\n\n";
end

Measured memory_bytes: 8688
/**
*    author:  yuya1234
*    created: 26.06.2020 13:06:46
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
int digit(int n)
{
    int d=0;
    while(n>0)
    {
        n/=10;
        d++;
    }
    return d;
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    ll n;
    cin>>n;
    ll ans=100000000000;

    for(ll i=1;i<=sqrt(n);i++)
    {
        if(i*(ll)(n/i)==n)
        {
            ans = min(ans,max((ll)i,(ll)(n/i)));
        }
    }

    cout<<digit(ans)<<endl;

    return 0;
}

Measured memory_bytes: 3644
import java.util.*
import kotlin.math.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    val (x, n) = readInts()
    if (n == 0) {
        println(x)
        return
    }
    val p = readInts().toSet()
    if (!p.contains(x)) {
        println(x)
        return
    }
    var d = 1
    while (true) {
        if (!p.contains(x - d)) {
            println(x - d)
            return
        }
        if (!p.contains(x + d)) {
            println(x + d)
            return
        }
        d++
    }
}


Measured memory_bytes: 36756
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)


//union-find
#define UFLIMIT (1<<17)
int unicnt[UFLIMIT+10];//正ならcnt、非正なら根のindex
void ufinit(int n){rep(i,0,n)unicnt[i]=1;}
int root(int x){return unicnt[x]<=0?-(unicnt[x]=-root(-unicnt[x])):x;}
int same(int x,int y){return root(x)==root(y);}
void uni(int x,int y){if((x=root(x))==(y=root(y)))return;if(unicnt[x]<unicnt[y]){int t=x;x=y;y=t;}unicnt[x]+=unicnt[y];unicnt[y]=-x;}
#undef UFLIMIT

ll n,m;
int main(){
	scanf("%lld%lld",&n,&m);
	ll ans=n;
	ufinit(n);
	rep(i,0,m){
		ll x,y;
		scanf("%lld%lld%*lld",&x,&y);
		x--,y--;
		if(!same(x,y)){
			uni(x,y);
			ans--;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 512
//2018.9.20 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register LL
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline LL read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline LL _abs(const res &x){
    return x>0?x:-x;
}
inline LL _max(const res &x,const res &y){
    return x>y?x:y;
}
const LL kcz=1e9+7;
const LL N=2e6+10,P=2e3+10;
namespace MAIN{
    LL inv[N],fac[N];
    inline void pre(){
        inv[0]=inv[1]=fac[0]=fac[1]=1;
        for(res i=2;i<=N-10;i++)fac[i]=(LL)fac[i-1]*i%kcz,inv[i]=(LL)inv[kcz%i]*(kcz-kcz/i)%kcz;
        for(res i=2;i<=N-10;i++)inv[i]=(LL)inv[i]*inv[i-1]%kcz;
    }
    inline LL C(const res &x,const res &y){
        return (LL)fac[x]*inv[y]%kcz*inv[x-y]%kcz;
    }
    LL n;
    LL dp[P*2+1000][P*2+1000];
    LL a[N],b[N],ans;
    inline void add(res &x,const res &y){
        x+=y;
        x=(x%kcz+kcz)%kcz;
    }
    inline LL qpow(res x,res y){
        res ans=1;
        while(y){
            if(y&1)ans=(LL)ans*x%kcz;
            y>>=1,x=(LL)x*x%kcz;
        }
        return ans%kcz;
    }
    inline void MAIN(){
        pre();
        n=read();
        for(res i=1;i<=n;i++)a[i]=read(),b[i]=read(),dp[P-a[i]][P-b[i]]++;
        for(res i=1;i<=2*P;i++)
            for(res j=1;j<=2*P;j++)
                add(dp[i][j],dp[i-1][j]+dp[i][j-1]);
        for(res i=1;i<=n;i++)add(ans,dp[P+a[i]][P+b[i]]),add(ans,kcz-C((a[i]+b[i])*2,a[i]*2));
        printf("%lld\n",ans*qpow(2,kcz-2)%kcz);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 197760
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n-1,-1,-1):
    ans += min(a[i]+a[i+1],b[i])
    a[i] = max(a[i]-max(b[i]-a[i+1],0),0)
print(ans)


Measured memory_bytes: 24232
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		while(true){
			String[] line = br.readLine().split(" ");
			int h = Integer.parseInt(line[0]);
			int w = Integer.parseInt(line[1]);
			if( h==0 && w==0 ) break;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if( i == 0 || i == h-1 || j == 0 || j == w-1 ) sb.append("#");
					else sb.append(".");
				}
				sb.append("\n");
			}
			sb.append("\n");
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 25388
#include <stdio.h>
 
int main(void) {
   int mountain_cnt, keep_H;
   scanf("%d", &mountain_cnt);
  
   int see_cnt = 0;
   int max_Hi = 0;
   for(int i = 0; i < mountain_cnt; i++) {
      scanf("%d", &keep_H);
      if(max_Hi <= keep_H) {
         max_Hi = keep_H;
         see_cnt++;
      }
   }

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

   return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double sum = 0;
    for (int i = 0; i < N; i++) {
      int a = sc.nextInt();
      sum += (double)1/a;
    }
    System.out.println(1/sum);
  }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N,K;cin>>N>>K;
  char D[K];
  rep(i,K)cin>>D[i];
  ll ans;
  for(int i=N;i<1000000;++i){
    string s = to_string(i);
    bool flag=true;
    rep(j,K){
      if(s.find(D[j]) != string::npos){
        flag = false;
        break;
      }
    }
    if(flag){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
X = []
Y = []
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append((x, y))

X = sorted(X)
Y = sorted(Y)
mi = 1<<200
for i in range(N):
    for j in range(i+1, N):
        for k in range(N):
            for l in range(k+1, N):
                s = 0
                for x, y in XY:
                    if X[i] <= x <= X[j] and Y[k] <= y <= Y[l]:
                        s += 1
                if s >= K:
                    mi = min(mi, (X[j] - X[i]) * (Y[l] - Y[k]))

print(mi)


Measured memory_bytes: 47324