akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
  int w,h,a,b,c,i,j,k,l,n,y,x,ans,max;
  char e[3][3],f[1003][1003]={0};
  char s[5]=" JOI";
  scanf("%d %d",&h,&w);
  for(i=ans=0;i<h;i++)scanf("%s",f[i+1]+1);
  for(i=max=0;i<2;i++)scanf("%s",e[i]);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      c=f[i][j];//printf("%c:",c);
      for(k=0;k<4;k++){
	if(k)f[i][j]=s[k];
	for(l=a=0;l<4;l++){
	  for(n=0;n<4;n++){
	    y=n/2-l/2;
	    x=n%2-l%2;//printf("%c %c  ",f[i+y][j+x],e[n/2][n%2]);
	    if(f[i+y][j+x]-e[n/2][n%2])break;
	  }//printf("\n");
	  if(n==4)a++;
	}
	if(k==0)b=a;
	if(max<a-b)max=a-b;
      }
      ans+=b;//printf("%d\n",ans);
      f[i][j]=c;
    }
  }//printf("\n");
  printf("%d\n",ans/4+max);
  return 0;
}
 

Measured memory_bytes: 1592
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
c = []
d = 1
m = 10**9+7
for i in range(n):
    if a[i] < 0:
        c.append(a[i])
    else:
        b.append(a[i])
b.sort()
c.sort(reverse=True)
if len(b) == 0 and k%2 == 1:
    for i in range(k):
        d = d*c[i]%m
else:
    while k > 0:
        if len(b) > 1 and len(c) > 1:
            if b[-1]*b[-2] < c[-1]*c[-2] and k > 1:
                d = d*c.pop()%m
                d = d*c.pop()%m
                k -= 2
            else:
                d = d*b.pop()%m
                k -= 1
        elif len(b) == 1 and len(c) > 1:
            if k > 1:
                d = d*c.pop()%m
                d = d*c.pop()%m
                k -= 2
            else:
                d = d*b.pop()%m
                k -= 1
        elif len(b) >= 1 and len(c) <= 1:
            d = d*b.pop()%m
            k -= 1
        else:
            d = d*c.pop()%m
            k -= 1
print(d)

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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair<int, int> pii;

#define F(i, l, r) for(int i = (l); i < (r); i++)
#define E(i, l, r) for(int i = (l); i <= (r); i++)
#define DF(i, l, r) for(int i = (l); i >= (r); i--)
#define I(x, a) for(auto x : (a))
#define mp make_pair
#define X first
#define Y second
#define clean(x) memset((x), 0, sizeof(x))
#define ret return
#define cont continue
#define brk break
#define ins insert
#define all(x) (x).begin(),(x).end()
#define sync ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define y1 fjfg

map<ll, int> cnt;
int n;

int main(){
	sync;
	cnt[0] = 1;
	ll ans = 0;
	cin >> n;
	ll sum = 0;
	F(i, 0, n){
		int a;
		cin >> a;
		sum += a;
		ans += cnt[sum];
		cnt[sum]++;
	}
	cout << ans;
}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

template<typename T>
struct SegmentTree{
    int n;
    T e; //単位元
    vector<T> v;
    function<T(T,T)> operation;
    function<T(T,T)> update;
    //区間[a,b)に対してのクエリ 今は[l,r)を見ている
    T _query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return e;
        if(a<=l && r<=b) return v[k];
        else{
            T c1=_query(a,b,2*k+1,l,(l+r)/2);
            T c2=_query(a,b,2*k+2,(l+r)/2,r);
            return operation(c1,c2);
        }
    }
public:
    SegmentTree(size_t _n,T _e,function<T(T,T)> _operation,function<T(T,T)> _update):e(_e),operation(_operation),update(_update){
        n=1;
        while(n<_n){
            n*=2;
        }
        v=vector<T>(2*n-1,e);
    }
    void change(int i,T x){
        i+=n-1;
        v[i]=update(v[i],x);
        while(i>0){
            i=(i-1)/2;
            v[i]=operation(v[i*2+1],v[i*2+2]);
        }
    }
    T query(int a,int b){
        return _query(a,b,0,0,n);
    }
    T operator[](int i){
        return v[i+n-1];
    }
};
//veryfi
int main(){
    int n,q; cin >> n >> q;
    SegmentTree<ll> st(n,(1ull<<31)-1,[](ll a,ll b){return min(a,b);},[](ll a,ll b){return b;});
    rep(i,q){
        bool x; cin >> x;
        int a1,a2; cin >> a1 >> a2;
        if(x){
            cout << st.query(a1,a2+1)<<endl;
        }else{
            st.change(a1,a2);
        }
    }
    //加算ならうupdateに渡すラムダ式は[](int a,b){return a+b;}とする（？）
}



Measured memory_bytes: 4972
#include <stdio.h>

int main(){

  int m,n,p,i,sum=0,ans=0;
  int x[100]={};
  for(;;){
    
    scanf("%d %d %d",&n,&m,&p);

    if(n==0&&m==0&&p==0){
      break;
    }
    for(i=1;i<=n;i++){
      scanf("%d",&x[i]);
      sum+=x[i];
    }

    if(x[m]!=0){
      ans=((double)100*sum/x[m])*((100-p)*0.01);
    }

    if(x[m]==0){
      printf("0\n");
    }
    else{
      printf("%d\n",ans);
    }
      ans=0;
      sum=0;
      for(i=1;i<=n;i++){
	x[i]=0;
      }
    }  
    return 0;
  }

Measured memory_bytes: 1040
// Vivek Rai
// Blazer_007

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define fastio 		ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define ppi			pair<ll,pii>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define bit(x, y)   (((x)>>(y))&1)
#define bpt(x)      (__builtin_popcount(x))
#define bptl(x)     (__builtin_popcountll(x))
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)

using namespace std;
using namespace __gnu_pbds;

typedef priority_queue<int> maxHeap;
typedef priority_queue<int, vector<int>, greater<int> > minHeap;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(index) -> value at given index or Kth smallest element in set
// order_of_key(X) -> number of elements strictly less than X
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cout << name << " : " << arg1 << endl;
    //use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

template <typename T>
istream &operator>>(istream &in, vector<T> &arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
        cin >> arr[i];
    return in;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
        cout << arr[i] << " ";
    cout << endl;
    return os;
}

void solution()
{
	string s, t;
	cin >> s >> t;
	int n1 = sz(s);
	int n2 = sz(t);
	int ans = INT_MAX;
	// trace(n1,n2,n1-n2);
	loop(i,0,n1-n2+1)
	{
		int cur = 0;
		loop(j,0,n2)
		{
			if (s[i+j] != t[j])
				cur++;
		}
		ans = min(ans,cur);
	}
	cout << ans << endl;
}

signed main()
{
    fastio

    ll t = 1;
    // cin >> t;
    loop(i, 1, t + 1)
    {
        //cout<<"Case #"<<i<<": ";
        solution();
    }
}


	

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
int main() {
    string S;
    cin >> S;

    ll red = 0;
    ll blue = 0;
    for (size_t i = 0; i < S.size(); i++)
    {
        if (S[i] == '0') {
            red += 1;
        } else {
            blue += 1;
        }
    }
    cout << min(red, blue) * 2 << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N); 
    for (int i = 0; i < N; ++i) cin >> A[i];

    // 操作回数
    int counter = 0;

    // 操作が行えなくなるまで操作を行う
    while (true) {
        // 操作が行えるかどうかを判定する
        bool can_do = true;
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 == 1) can_do = false;
        }

        // 操作を行えないならば、ループを打ち切る
        if (!can_do) break;

        // 操作を行えるならば、操作を行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2; // 2 で割る
        }

        // 操作回数をカウントする
        ++counter;
    }
    cout << counter << endl;
}

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

int main()
{
    ll n;
    cin >> n;
    vector<P> p;
    rep(i, n)
    {
        ll a, b;
        cin >> a >> b;
        p.push_back(P(b, a));
    }
    sort(p.begin(), p.end(), greater<>());
    ll t = p[0].first;
    for (auto v : p)
    {
        // cout << v.first << " " << v.second << endl;
        t = min(t, v.first);
        t -= v.second;
        // cout << t << endl;
    }
    if (t >= 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> t(n+1), x(n+1), y(n+1);
    t[0] = 0, x[0] = 0, y[0] = 0;
    for(int i=1; i<=n; i++) cin >> t[i] >> x[i] >> y[i];

    bool flag = true;
    for(int i=0; i<n; i++){
        int T = t[i+1] - t[i];
        int d = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if(T-d < 0 || (T-d)%2 == 1) flag = false;
        }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 110;
int dp[N][N * N], p[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    dp[n + 1][0] = 1;
    int ans = 0;
    p[0] = 1;
    for (int i = 1; i <= n; i++) p[i] = p[i - 1] * (k + 1) % mod;
    for (int i = n; i >= 1; i--){
        for (int j = 0; j <= k * n; j++){
            for (int l = 0; l <= k; l++){
                int x = (l + j) / i;
                if (l > i) x = 0;
                ans = (ans + x * dp[i + 1][j] % mod * p[i - 1]) % mod;
                dp[i][j + x] = (dp[i][j + x] + dp[i + 1][j]) % mod;
            }
        }
    }
    int x = k * (k + 1) / 2;
    for (int i = 1; i < n; i++) x = x * (k + 1) % mod;
    cout << (n * x - ans + mod) % mod;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define ll long long
#define MAXN 10
using namespace std;

double p[MAXN][2], fact;
int n;

double dist(int a, int b){
    return sqrt(pow(p[a][0] - p[b][0],2) + pow(p[a][1] - p[b][1],2));
}

double fac(int n){
    if(n == 0) return 1.0;
    return n*fac(n-1);
}

int main(){

    cin>>n;

    fact = fac(n);
    int vet[n];

    for(int i=0; i<n; i++){
        vet[i]=i;
        cin>>p[i][0]>>p[i][1];
    }

    double res = 0;

    do{
        double d=0;
        for(int i=1; i<n; i++){
            d += dist(vet[i],vet[i-1]);
        }

        res += d/fact;

    }while(next_permutation(vet,vet+n));

    printf("%.10lf\n",res);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,ans;
char s;
scanf("%d\n",&ans);
while(1){
scanf("%c\n",&s);
if(s=='+'){
scanf("%d\n",&a);
ans=ans+a;
}
else if(s=='-'){
scanf("%d\n",&a);
ans=ans-a;
}
else if(s=='*'){
scanf("%d\n",&a);
ans=ans*a;
}
else if(s=='/'){
scanf("%d\n",&a);
ans=ans/a;
}
else if(s=='='){
break;
}
}
printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 2028
n=int(input())
T=[]
for _ in range(n):
    t = int(input())
    T.append(t)

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

ans = T[0]
for i in range(1,n):
    ans=lcm(ans, T[i])

print(ans)


Measured memory_bytes: 38384
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int x, a1 = 0, a2 = 0, a3 = 0, a4 = 0;
	for (int i = 0; i < 6; i++) {
		cin >> x;
		if (x == 1)a1++;
		if (x == 2)a2++;
		if (x == 3)a3++;
		if (x == 4)a4++;
	}
	x = 0;
	if (a1 == 3)x = 1;
	if (a2 == 3)x = 1;
	if (a3 == 3)x = 1;
	if (a4 == 3)x = 1;

	if (x == 0)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
typedef long long ll;
struct point {
    ll x, y;
};

ll n;
struct point red[105];
struct point blue[105];
bool is_pair_red[105];
bool is_pair_blue[105];

ll ans = 0;

int main()
{
    scanf("%lld", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld", &red[i].x, &red[i].y);
    }
    for (int i = 0; i < n; i++) {
        scanf("%lld %lld", &blue[i].x, &blue[i].y);
    }
    
    blue[n].x = blue[n].y = 1000;
    red[n].x = red[n].y = -1;

    // 1.x座標の一番大きい赤い点を選ぶ
    // 2.1.の点とペアになれる点のなかで1番yの小さいものを選ぶ
    // 3. 1.にもどる！

    for (int i = 0; i < n; i++) {
        int red_pos = n;
        int blue_pos = n;
        
        for (int j = 0; j < n; j++) {
            if (red[j].x > red[red_pos].x && !is_pair_red[j]) {
                red_pos = j;
            }
        }

        for (int j = 0; j < n; j++) {
            if (red[red_pos].x < blue[j].x &&
                red[red_pos].y < blue[j].y &&
                !is_pair_blue[j] &&
                blue[blue_pos].y > blue[j].y) {
                
                blue_pos = j;
            }
        }

        if (blue_pos < n) {
            ans++;
            is_pair_blue[blue_pos] = true;
        }
        
        is_pair_red[red_pos] = true;
    }

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

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
    int N,W;
    cin>>N>>W;
    vector<int> v(N);
    vector<int> w(N);
    for(int i=0;i<N;i++){
	cin>>v[i]>>w[i];
    }
    vector<vector<int> > dp(2,vector<int>(W+1,-inf) );
    dp[0][0] = 0;
    for(int i=0;i<N;i++){
	for(int j=0;j<=W;j++){
	    if( w[i] <= j){
		dp[(i+1)%2][j] = max(dp[i%2][j],dp[i%2][j-w[i]] + v[i]);
	    }else{
		dp[(i+1)%2][j] = dp[i%2][j];
	    }
	}
    }
    int res = 0;
    for(int i=0;i<=W;i++)res = max(res,dp[N%2][i]);
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <string>

using namespace std;

int main() {

    int N;
    cin >> N;
    string S;
    cin >> S;

    for(auto & s : S) {
        s += N;
        s %= 'Z' + 1;
        if(s < 'A') s += 'A';
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in)) {
            long resultNum = 0;
            String resultStr = "";

            // int n = sc.nextInt();

            char[] c = sc.next().toCharArray();

            return Character.isUpperCase(c[0]) ? "A" : "a";
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenBitUtil {
    static int popCount(int bit) {
        return Integer.bitCount(bit);
    }

    static boolean isFlag(int bit, int i) {
        return 0 != (bit & (1 << i));
    }

    static int setTrue(int bit, int i) {
        return bit |= (1 << i);
    }

    static int setFalse(int bit, int i) {
        return bit &= ~(1 << i);
    }

    static int setReverse(int bit, int i) {
        return isFlag(bit, i) ? setFalse(bit, i) : setTrue(bit, i);
    }

    static int reverseAll(int bit) {
        return ~bit;
    }
}

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

int main(){
    string s;

    cin >> s;

    int length = s.length();

    vector<int> v(length);
    for(int i = 0; i < length; i++){
        v[i] = s[i] - '0';
    }

    /*
    for(int i = 0; i < length; i++){
        printf("%d", v[i]);
    }*/

    //printf("\n");

    //char plus[length - 1];

    long long sum = 0;

    for(int i = 0; i < (1 << (length-1)); i++){
        long long now = v[0];
        long long ans = 0;
        for(int j = 0; j < length-1; j++){
            if(i & (1 << j)){//ない場合
                now = 10*now + v[j+1];
               //printf("count %d\n", count);
            }
            else{//プラスの挙動
                ans = now + ans;
                now = v[j+1];
                //printf("count %d\n", count);
            }
        }
        ans = ans + now;
        sum = sum + ans;
        //printf("count %d\n", ans);
    }

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

    return 0;

}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> botan(N);
 
  for (int i = 0; i < N; i++) {
    cin >> botan.at(i);
  }
  
  int current = 0;
  int res = -1;
  
  for (int i = 0; i < N; i++) {
    if (current == 1) {
      res = i;
      break;
    }
    current = botan.at(current)-1;
  }
  cout << res << endl;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<pair<int,int>>v(5);
    f(i,0,5){
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(all(v));
    cout << v[0].second+1;
    return 0;
}
 

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

#define dump(...) DUMPOUT<<"  ";DUMPOUT<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<std::endl;DUMPOUT<<"    ";dump_func(__VA_ARGS__)
#define PI 3.14159265358979323846
#define EPS 1e-10
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(j) (j).begin(), (j).end()
#define SZ(j) ((int)(j).size())

int D = 365;
const int T = 26;

vector<int> c(T);
vector<vector<int>> s(D, vector<int>(T)); 

long long eval(vector<int> out, int k) {
    long long score = 0;
    vector<int> last(T, 0);
    REP(d, (int)out.size()) {
        last[out[d]-1] = d+1;
        REP(i, T) {
            score -= (long long)(d+1 - last[i]) * c[i];
        }
        score += s[d][out[d]-1];
    }
    FOR(d, (int)out.size(), min(D, (int)out.size()+k)) {
        REP(i, T) {
            score -= (long long)(d+1 - last[i]) * c[i];
        }
    }

    return score;
}

long long compute_score(vector<int> out) {
    long long score = 0;
    vector<int> last(T, 0);
    REP(d, (int)out.size()) {
        last[out[d]-1] = d+1;
        REP(i, T) {
            score -= (long long)(d+1 - last[i]) * c[i];
        }
        score += s[d][out[d]-1];

        // cout << score << endl;
    }

    return score;
}

vector<int> solve(int k=13) {
    vector<int> out;
    REP(_, D) {
        int best_i = 1;
        long long max_score = -(1e18);
        FOR(i, 1, T+1) {
            out.emplace_back(i);
            long long score = eval(out, k);
            if (max_score < score) {
                max_score = score;
                best_i = i;
            }

            out.pop_back(); 
        }
        out.emplace_back(best_i);
    }

    return out;
}

void test_score() {
    vector<int> t(D);
    REP(i, D) cin >> t[i];
    compute_score(t);
}

int main(int argc, char const *argv[])
{
    int d_;
    cin >> d_;
    D = d_;
    
    REP(i, T) cin >> c[i];
    REP(i, D) REP(j, T) cin >> s[i][j];

    vector<int> out = solve();
    assert(out.size() == D);
    for (int t : solve()) {
        cout << t << endl;
    }

    return 0;
}


Measured memory_bytes: 3720
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

const int MaxSum = 330;
const int MaxN = 10;
int table[MaxN+1][MaxSum+1];
int mask = (1 << MaxN) - 1;

void recur(int n, int depth, int sum)
{
	if (depth == n)
	{
		++table[n][sum];
	}
	else
	{
		for (int i = 0; i < MaxN; ++i)
		{
			int f = 1 << i;
			if (mask & f)
			{
				mask ^= f;
				recur(n, depth+1, sum + (depth+1)*i);
				mask ^= f;
			}
		}
	}
}

int main()
{
	for (int i = 1; i <= MaxN; ++i)
		recur(i, 0, 0);

	int n, s;
	while (scanf("%d %d", &n, &s) != EOF)
	{
		if (s <= MaxSum)
			printf("%d\n", table[n][s]);
		else
			puts("0");
	}

	return 0;
}

Measured memory_bytes: 760
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/

void build(){

}
char c[ 1021 ];
void init(){
  cin >> c;
}
void solve(){
  int len = strlen( c );
  for( int i = 0 ; i < len - 8 ; i ++ )
    putchar( c[ i ] );
  puts( "" );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int A,B,C,d[3] = {};
    REP(i,N){
        cin >> A >> B >> C;
        int a = d[0],b = d[1],c = d[2];
        d[0] = A + max(b,c);
        d[1] = B + max(a,c);
        d[2] = C + max(a,b);
    }
    cout << max({d[0],d[1],d[2]}) << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

h, n = na()
ab = [na() for i in range(n)]
max_a = max([ab[i][0] for i in range(n)])
dp = [inf] * (h + max_a)
dp[0] = 0

for i in range(n):
    for j in range(h):
        a, b = ab[i]
        m = min(j + a, h)
        dp[m] = min(dp[m], dp[j] + b)

print(dp[h])

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005;
vector<vector<bool>> C(50,vector<bool>(MAX*(MAX+1)/2,0));

int main(){
    
    ll N,K;cin>>N>>K;
    vector<ll> A(N),sum(N+1),T;
    
    for(int i=0;i<N*(N+1)/2;i++){
        C[0][i]=1;
    }
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum[i+1]=sum[i]+A[i];
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N+1;j++){
            T.push_back(sum[j]-sum[i]);
        }
    }
    
    ll ans=0;
    bool check=true;
    for(int i=0;i<=45;i++){
        if(check){
            int cnt=0;
            for(int j=0;j<N*(N+1)/2;j++){
                if(C[i][j]&&(T[j]&(1LL<<(45-i)))){
                    cnt++;
                    C[i+1][j]=1;
                }
            }
            if(cnt>=K) ans=ans|1LL<<(45-i);
            else check=false;
        }
        if(!check){
            for(int j=0;j<N*(N+1)/2;j++){
                C[i+1][j]=C[i][j];
            }
            check=true;
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll a,b;
  cin>>a>>b;
  cout<<b+b-a;
}


Measured memory_bytes: 3628
n, k = gets.split.map(&:to_i)
xn = gets.split.map(&:to_i)
ans = (10**8) * (10**5)

(n-k+1).times do |i|
  w = xn[i...(k+i)]
  # left
  score = w.first.abs + (w.last - w.first).abs
  ans = score if ans > score
  # right
  score = w.last.abs + (w.last - w.first).abs
  ans = score if ans > score
end

puts ans

Measured memory_bytes: 11012
#include <ctype.h>
#include <iostream>
#include <string>
using namespace std;

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

    int s1 = stoi(S.substr(0, 2));
    //string s1 = S.substr(0, 2);
    //string s2 = S.substr(2, 3);

    int s2 = stoi(S.substr(2, 3));

    string result;

    bool s1result = false;
    bool s2result = false;

    if (s1 < 13 && s1 > 0) {
        s1result = true;
    }

    if (s2 < 13 && s2 > 0) {
        s2result = true;
    }

    if (s1result && s2result) {
        result = "AMBIGUOUS";
    } else if (s1result) {
        result = "MMYY";
    } else if (s2result) {
        result = "YYMM";
    } else {
        result = "NA";
    }

    cout << result << endl;

	return 0;
}



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

void b_increment_decrement(void) {
	int x = 0;
	int n;
	string s;
	cin >> n>>s;
	int max=0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'I')x++;
		else            x--;

		if (x > max)max = x;
	}
	cout << max << endl;
}

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

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;
bool mysort(pair<string,pair<int,int>> a,pair<string,pair<int,int>> b){
    if(a.first!=b.first){
        return a.first<b.first;
    }else{
        pair<int,int> a1=a.second;
        pair<int,int> b1=b.second;
        return a1.first>b1.first;
    }
}

void solve(){
    int N;
    cin>>N;
    vector<pair<string,pair<int,int>>> A(N);
    F0R(i,N){
        string s;
        int a;
        cin>>s>>a;
        A[i]=make_pair(s,make_pair(a,i+1));
    }
    sort(all(A),mysort);
    for(int i=0;i<N;i++){
        pair<int,int> temp=A[i].second;
        cout<<temp.second<<endl;
    }

}

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

template<class T> inline T sqr(T x) {return x*x;}

constexpr int MOD = 1000000000 + 7;

long long power(long long x, long long n, long long mod = MOD) {
    if (n == 0) return 1;
    if (n % 2 == 0) return power(x * x % mod, n/2, mod);
    else return x * power(x, n-1, mod) % mod;
}

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    VVI ru(4, VI(n));
    REP(i,0,n) {
        if (s[i] == '?') ru[3][i]++;
        else ru[s[i] - 'A'][i]++;
    }
    REP(i,1,n) {
        REP(j,0,4) ru[j][i] += ru[j][i-1];
    }
    
    LL ans = 0;
    REP(i,1,n-1) {
        if (s[i] == 'B' || s[i] == '?') {
            int ac = ru[0][i-1], cc = ru[2][n-1] - ru[2][i];
            int qb = ru[3][i-1], qa = ru[3][n-1] - ru[3][i];

            LL a = (power(3,qb) * (LL)ac) % MOD;
            if (qb > 0) a = (a + power(3,qb-1) * (LL)qb) % MOD;

            LL c = (power(3,qa) * (LL)cc) % MOD;
            if (qa > 0) c = (c + power(3,qa-1) * (LL)qa) % MOD;

            ans = (ans + (a * c)) % MOD;
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 2432
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
//https://blog.csdn.net/keshuai19940722/article/details/49688065
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 1000000;
long long daan[maxn+5];
long long dp[maxn + 5];
int fac[maxn + 5], inv[maxn + 5];

int pow_mod(ll x, long long n) {
    ll ret = 1;
    while (n) {
        if (n&1) ret = ret * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return ret;
}

void presolve() {
    fac[0] = 1;
    for (int i = 1; i <= maxn; i++)
        fac[i] = 1LL * i * fac[i-1] % mod;
    inv[maxn] = pow_mod(fac[maxn], mod-2);
    for (int i = maxn-1; i >= 0; i--)
        inv[i] = 1LL * (i+1) * inv[i+1] % mod;
}

int N, ans, sz[maxn + 5];
vector<int> G[maxn + 5];


ll C(int n, int k) {
    if (k > n || k < 0 || n < 0) return 0;
    return 1LL * fac[n] * inv[k] % mod * inv[n-k] % mod;
}

ll dfs (int u, int f) {
    ll& ret = dp[u];
    ret = 1;
    sz[u] = 0;
    for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (v == f) continue;
        ret = ret * dfs(v, u) % mod;
        sz[u] += sz[v];
    }

    int s = sz[u];
    for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (v == f) continue;
        ret = ret * C(s, sz[v]) % mod;
        s -= sz[v];
    }
    sz[u]++;
    return ret;
}

void dfs(int u, int f, ll k) {
    ll ret = k;
    k = (k * dp[u]) % mod;

    int s = N-1;
    for (int i = 0; i < G[u].size(); i++) {
        int v = G[u][i];
        if (v == f) continue;
        ll iv = k * pow_mod(dp[v] * C(sz[u]-1, sz[v]) % mod, mod-2) % mod;
        dfs(v, u, iv * C(N-sz[v]-1, sz[u]-sz[v]-1) % mod);
        ret = ret * C(s, sz[v]) % mod * dp[v] % mod;
        s -= sz[v];
    }
    daan[u]+=ret;
    daan[u]%=mod;
}

int main () {
        presolve();
        memset(dp,0,sizeof(daan));
        scanf("%d", &N);
        int u, v;
        for (int i = 1; i <= N; i++) G[i].clear();
        for (int i = 1; i < N; i++) {
            scanf("%d%d", &u, &v);
            G[u].push_back(v);
            G[v].push_back(u);
        }

        ans = 0;
        dfs(1, 0);
        dfs(1, 0, 1);
        for(int i=1;i<=N;i++)
        printf("%lld\n",daan[i]);
    return 0;
}


Measured memory_bytes: 52212
#include <cstdio>
using namespace std;
int N, a[200001], b[200001], cnt;
int main() {
  scanf("%d", &N);
  for(int i = 1; i <= N; ++i) scanf("%d", &a[i]);
  for(int i = 1; i <= N; ++i) {
    for(int j = N/i; j > N/(i+1); --j) {
      int bsum = 0;
      for(int k = 2; j*k <= N; ++k) bsum += b[j*k];
      if((a[j]+bsum)%2 == 1) b[j] = 1, ++cnt;
    }
  }
  printf("%d\n", cnt);
  for(int i = 1; i <= N; ++i) {
    if(b[i] > 0) printf("%d ", i);
  }
}

Measured memory_bytes: 2304
#include <stdio.h>

#define w_MAX 30
#define n_MAX 30

void amida(int*, int*, int*, int);

int
main()
{
  
  int i;
  int w, n;
  int tatesen[w_MAX] = {};
  int a[n_MAX], b[n_MAX];
  
  scanf("%d\n", &w);
    
  for(i = 0; i < w; i++)
    {
      tatesen[i] = i + 1;
    }
  
  scanf("%d\n", &n);
  
  for(i = 0; i < n; i++)
    {
      scanf("%d,%d\n", (a + i), (b + i));
    }
  
  for(i = 0; i < n; i++)
    {
      amida(tatesen, a, b, i);
    }
  
  for(i = 0; i < w; i++)
    {
      printf ("%d\n", tatesen[i]);
    }
  
  return 0;
}

void
amida(int *tatesen, int *a, int *b, int i)
{
  int temp;
  temp = tatesen[a[i] - 1];
  tatesen[a[i] - 1] = tatesen [b[i] - 1];
  tatesen[b[i] - 1] = temp;
}



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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;  

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i = 0 ; i < N; i++){
        cin >> a[i];
    }
    int i = 0;
    while( a[i] % 2 == 1 || (a[i] % 2 == 0 && a[i] % 3 == 0 || a[i] % 5 == 0)){
        i++;
        if(i >= N) break;
    }
    if( i == N) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}



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

using namespace std;
int main()

{
     char a,b;
    cin>>a>>b;
    if(a>b){
        cout<<">"<<endl;
    }
    else if(a<b){
        cout<<"<"<<endl;
    }else{
        cout<<"="<<endl;
    }
  return 0;
}

Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
#include <utility>

namespace n91 {

void main_() {
  const auto n = scan<usize>();
  std::vector<u32> a;
  a.reserve(n);
  std::copy_n(std::istream_iterator<u32>(std::cin), n, std::back_inserter(a));

  std::multiset<u32> s;
  for (const auto e : a) {
    if (!s.empty() && *s.begin() < e) {
      const auto itr = std::prev(s.lower_bound(e));
      s.erase(itr);
    }
    s.insert(e);
  }

  std::cout << s.size() << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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


int main() {

    int64_t n,a,b;
    cin>>n>>a>>b;

    int64_t sum_all=0;
    for(int i=1;i<=n;i++){
        string swk = to_string(i);
        int64_t sum=0;
        for(int j=0;j<swk.size();j++){
            char cwk = swk.at(j);
            sum+=(cwk-'0');
        }
        if(sum>=a&&sum<=b)
            sum_all+=i;
    }

    cout<<sum_all<<endl;

	return 0;
}

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

int main() {
  int N;
  string S;
  int ans = 0;
  cin >> N >> S;
  for (int i = 2; i < N; i++) {
    if (S.at(i) == 'C' && S.at(i - 1) == 'B' && S.at(i - 2) == 'A') {
      ans++;
    }
  }
  cout << ans << endl;
       
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n; cin >> n;
  string s; cin >> s;
  int x = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      x++;
      ans = max(ans, x);
    } else {
      x--;
    }
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main(){
  int64_t A, B, N, ans;
  cin >>A >> B >> N;
  ans = 0;
if(N < B){
  ans = A*N/B;
}
else{
ans =A*((N/B*B)-1)/B- A*(((N/B*B)-1)/B);
}
  cout << ans << endl;

}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  lint N;
  cin>>N;
  string ans="";
  while(N>0){
    N--;
    ans+='a'+N%26;
    N/=26;
  }
  reverse(ALL(ans));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;

using ll = long long;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

bool contain(ll mask, ll pos){
  return (mask & (1LL << pos)) != 0LL; 
}

int main(){
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  vector<ll> pos(100, 0);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    ll bit = 0;
    while((1LL << bit) <= A[i]){
      if(contain(A[i], bit)) pos[bit]++;
      bit++;
    }
  }
  
  ll ans_bit = 0;
  for(int i = 40; i >= 0; i--){
    if(K < ans_bit + (1LL << i)) continue;
    if(pos[i] <  N - pos[i]) ans_bit += (1LL << i);
  }

  ll ans = 0;
  for(int i = 0 ; i< N; i++){
    ans += (ans_bit xor A[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
from bisect import bisect

N = int(input())
inputs = sorted([int(i) for i in input().split()])

ans = 0
for i in range(inputs[-1] + 1):
    index = bisect(inputs, i)
    if index == (N // 2):
        ans += 1
    elif index > (N // 2):
        break
print(ans)


Measured memory_bytes: 14324
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/26/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int H,W; cin>>H>>W;
  vector<pair<int, int>> os;
  int grid[H][W];
  for (int h = 0; h < H; h++) for (int w = 0; w < W; w++) {
    cin>>grid[h][w];
  }
  vector<tuple<int,int,int,int>> ans;
  int x = 0, y = 0;
  bool en = false;
  while (true) {
    en ^= grid[x][y]%2==1;
    auto tx = x;
    auto ty = y;
    if (x%2==0) {
      if (y < W-1) {
        ty++;
      } else {
        if (tx == H-1)
          break;
        tx++;
      }
    } else {
      if (y > 0)
        ty--;
      else {
        if (tx == H-1)
          break;
        tx++;
      }
    }
    if (en)
      ans.emplace_back(x,y,tx,ty);
    x=tx;
    y=ty;
  }

  cout << ans.size() << endl;
  for (auto a : ans) {
    cout << get<0>(a)+1 << " " << get<1>(a)+1 << " " <<get<2>(a)+1 << " " <<get<3>(a)+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
const ll mod = 1e9 + 7;
const int intmax = 0x7fffffff, intmin = ~intmax;
const ll llmax = 0x7fffffffffffffffll, llmin = ~llmax;

int a[200000];
int main() {
  int n, m = intmin, m2 = intmin;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > m) {
      m2 = m;
      m = a[i];
    } else if (a[i] > m2) {
      m2 = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    cout << (m2 == intmin ? m : a[i] == m ? m2 : m) << endl;
  }
}


Measured memory_bytes: 2432
def resolve():
	from collections import Counter

	def prime_factorize(n):
	    a = []
	    while n % 2 == 0:
	        a.append(2)
	        n //= 2
	    f = 3
	    while f * f <= n:
	        if n % f == 0:
	            a.append(f)
	            n //= f
	        else:
	            f += 2
	    if n != 1:
	        a.append(n)
	    return a

	def cnt(x):
	    ans = 0
	    i = 1
	    while True:
	        ans += i
	        if ans > x:
	            return i-1
	        i += 1
	        
	n = int(input())
	ans = 0

	a = Counter(prime_factorize(n))
	for i in a.values():
	    ans += cnt(i)

	print(ans)
	
resolve()

Measured memory_bytes: 9456
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <algorithm>
 
using ii = std::pair<int, int>;
 
int main()
{
	long long int q, h, s, d, n;
 
	scanf("%lld %lld %lld %lld %lld", &q, &h, &s, &d, &n);
 
	s = std::min({ q * 4, h * 2, s });
 
	long long int total = 0;
 
	if (s * 2 > d)
	{
		if (n % 2 == 0)
			total = n / 2 * d;
		else
			total = n / 2 * d + s;
	}
	else
	{
		total = n * s;
	}
 
	printf("%lld", total);
 
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

//dijkstraではグラフは隣接リストの形で持つ
//頂点toへのコストcostの辺
struct edge {
    ll to; ll cost;
};

ll const inf = 1e10;

//V頂点数
ll N;
//辺
vector<edge> G[100000];
//最短距離
ll d[100000];

void Dijkstra(ll s){
    //min_dist, number
    priority_queue<P, vector<P>, greater<P> > que;
    //初期化
    fill(d,d+N,inf);
    //スタート
    d[s]=0;
    que.push(P(0,s));
    //更新する点がなくなるまでwhileループ
    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        //入れた時より現在の方が更新されていたらスルー
        if (d[v] < p.first) continue;
        //vに隣接する辺についてループ
        REP(i,0,G[v].size()){
            edge e = G[v][i];
            //より短いルートが見つかったら更新してqueへ入れる
            if (d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i,0,N-1){
        ll from, to, cost;
        cin >> from >> to >> cost;
        //0スタートにする
        --from; --to;
        edge e;
        e.to = to; e.cost = cost%2;
        G[from].push_back(e);
        //無向グラフの場合には反対方向に辺を引く
        e.to = from;
        G[to].push_back(e);
    }
    Dijkstra(0);
    REP(i,0,N){
        if (d[i]%2 == 0) CO('0');
        else CO('1');
    }
    return 0;
}


Measured memory_bytes: 8704