akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
 
import static java.util.Comparator.*;
 
public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    //================================================================================
    final int RR = 1, SS = 2, PP = 3;
    int N, K, R, S, P;
    char[] C;
    int[][] CK;
    int[][] dp;
    int calc(int s, int d) {
    	if(s == RR && d == SS)		return R;
    	else if(s == SS && d == PP)	return S;
    	else if(s == PP && d == RR)	return P;
    	else						return 0;
    }
    public void solve() {
    	N = Integer.parseInt(sc.next());
    	K = Integer.parseInt(sc.next());
    	R = Integer.parseInt(sc.next());
    	S = Integer.parseInt(sc.next());
    	P = Integer.parseInt(sc.next());
    	C = sc.next().toCharArray();
    	// mod K で分割する
    	int max = N / K + 1;
    	CK = new int[K][max];
    	for (int i = 0; i < N; i++) {
    		int wk = 0;
    		if(C[i] == 'r')			wk = RR;
    		else if(C[i] == 's')	wk = SS;
    		else					wk = PP;
			CK[i % K][i / K] = wk;
		}
    	long ans = 0;
    	dp = new int[max+3][4];
    	for (int i = 0; i < K; i++) {
			for (int j = 0; j < dp.length; j++) {
				for (int j2 = 0; j2 < 4; j2++) {
					dp[j][j2] = 0;
				}
			}
			for (int j = 0; j < max; j++) {
				for (int j2 = 1; j2 < 4; j2++) {
					if(j2 == RR) {
						dp[j+1][RR] = Math.max(dp[j+1][RR], dp[j][SS] + calc(RR, CK[i][j]));
						dp[j+1][RR] = Math.max(dp[j+1][RR], dp[j][PP] + calc(RR, CK[i][j]));
					} else if(j2 == SS) {
						dp[j+1][SS] = Math.max(dp[j+1][SS], dp[j][RR] + calc(SS, CK[i][j]));
						dp[j+1][SS] = Math.max(dp[j+1][SS], dp[j][PP] + calc(SS, CK[i][j]));
					} else if(j2 == PP) {
						dp[j+1][PP] = Math.max(dp[j+1][PP], dp[j][RR] + calc(PP, CK[i][j]));
						dp[j+1][PP] = Math.max(dp[j+1][PP], dp[j][SS] + calc(PP, CK[i][j]));
					}
				}
			}
			ans += (Math.max(dp[max][RR], Math.max(dp[max][SS], dp[max][PP])));
		}
    	out.println(ans);
    }
}

Measured memory_bytes: 30264
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl
#define MOD 1000000007
#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long n;
long long a[100005];
long long k[100005];
long long ans;
long long t;
long long d;
long long bef,af;
long long ni[100006];
long long di[100006];
int main()
{
	bef=-1;
	cin>>n;
	n++;
	rep(i,n)
	{
		cin>>a[i];
		k[a[i]]++;
		if(k[a[i]]==2)t=a[i];
	}
	vector<long long> inv(n+1);
	inv[1]=1;
	for(long long i=2;i<=n;++i)
	{
		inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
	}
	rep(i,n)
	{
		if(a[i]==t)
		{
			if(bef==-1)
			{
				bef=i;
			}
			else af=i;
		}
	}
	d=af-bef+1;
	if(n==2)
	{
	  cout<<1<<endl<<1<<endl;
		return 0;
	}
	/*rep2(now,1,n+1)
	{
		
	}*/
	rep(i,n-1)
	{
		if(i==0)ni[0]=1;
		else 
		{
			ni[i]=(ni[i-1]*(n-2-i+1))%MOD;
			ni[i]*=inv[i];
			ni[i]%=MOD;
		}
	}
	/*cout<<"ni"<<endl;
	rep(i,n-1)
	{
		cout<<ni[i]<<endl;
	}*/
	//cout<<"di"<<endl;
	rep(i,n-d+1)
	{
		if(i==0)di[0]=1;
		else 
		{
			di[i]=(di[i-1]*(n-d-i+1))%MOD;
			di[i]*=inv[i];
			di[i]%=MOD;
		}
	}
	/*rep(i,n-d+1)
	{
		cout<<di[i]<<endl;
	}*/
	//cout<<"ams"<<endl;
	for(long long k=1;k<=n;k++)
	{
		ans=0;
		if(n-2>=k)
		{
			ans+=ni[k];
		}
		if(k>=2&&n>=k)
		{
			ans+=ni[k-2];
		}
		if(k>=1&&n-d>=k-1)
		{
			ans-=di[k-1];
		}
		if(k>=1&&n-2>=k-1)
		{
			ans+=2*ni[k-1];
		}
		if(ans>0)cout<<ans%MOD<<endl;
		else
		  {
		    while(ans<0)ans+=MOD;
		    cout<<ans<<endl;
		  }
	}
	/*cout<<"aa"<<endl;
	rep(i,n+1)
	{
		cout<<inv[i]<<endl;
	}*/
	return 0;
}


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

int main(){
    long long a,b,x,ans;
    cin >> a >> b;
    
    x = a*b;
    if(a<b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    long long r = a% b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    ans= x/b;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A,B;
	
	
	scanf("%d",&A); 
	scanf("%d",&B);
	
	if((A+B)%3 == 0){
		printf("Possible\n");
		}
	
	else if(A%3 == 0||B%3 == 0){
		printf("Possible\n");
	}
	
	else{
		printf("Impossible\n");
	}
	
	return 0;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll a[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> a[i];

    return true;
}

ll f(int sign) {
    ll sum = 0, res = 0;

    forn (i, n) {
        ll p = sum + a[i];

        if (sign == -1 && p <= 0) {
            res += 1 - p;
            p = 1;
        }

        if (sign == 1 && p >= 0) {
            res += p + 1;
            p = -1;
        }

        sign = -sign;
        sum = p;
    }

    return res;
}

void solve() {
    cout << min(f(1), f(-1)) << endl;
}

int32_t main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

ll f(ll x)
{
    ll ret;
    double b = 1e15;
    string s = to_string(x);
    int n = s.size();
    ll d = 1;
    RFOR(i,n-1,0){
        ll t = x/(d*10)*(d*10) + d-1;
        int c = s[i]-'0';
        FOR(j,c,9){
            ll cand = t+d*c;
            string cs = to_string(cand);
            int sum=0;
            rep(k,cs.size()) sum+=cs[k]-'0';
            if (b>(double)cand/sum){
                b = (double)cand/sum;
                ret = cand;
            }
        }
        d*=10;
    }
    return ret;
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin>>k;
    ll n=0;
    while(k--){
        cout<<(n=f(n+1))<<"\n";
    }
    return 0;
}


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

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

   for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
         if(i * j == N) {
            cout << "Yes" <<endl;
            return 0;
         }
      }
   }
   cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, m, p;
	while (cin >> n >> m >> p && (n || m || p)) {
		int sum = 0;
		vector<int> x(n);
		for (int i = 0; i < n; ++i) {
			cin >> x[i];
			sum += x[i] * 100;
		}
		if (x[m - 1]) {
			sum = sum * (100 - p) / 100;
			sum /= x[m - 1];
			cout << sum << endl;
		} else cout << 0 << endl;
	}

	return 0;
}


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

int main(){ 
  string S;
  cin >> S;
  if (S.at(0) == '7' || S.at(1) == '7' || S.at(2) == '7'){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }  
}
      

Measured memory_bytes: 3584
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))
    h = list(map(int, readline().split()))

    good = [True] * n

    for _ in range(m):
        a, b = list(map(int, readline().split()))
        a, b = a - 1, b - 1
        ha, hb = h[a], h[b]

        if ha <= hb:
            good[a] = False
        if ha >= hb:
            good[b] = False

    print(good.count(True))

if __name__ == '__main__':
    main()


Measured memory_bytes: 85904
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a; cin >> a;
	cout << (a[0] == '9' || a[1] == '9' ? "Yes": "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
long long a[500005],q[500005],h[500005],j[500005];
int main(void)
{
    int n;
    while(~scanf("%d",&n))
    {
        long long sum=0;
        int i;
        for(i=0;i<n;i++)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
        }
        long long suma=sum;
        for(i=0;i<n;i++)
        {
            sum-=a[i];
            q[i]=suma-sum;
            h[i]=suma-q[i];
        }
        for(i=0;i<n-1;i++)
            j[i]=fabs(q[i]-h[i]);
        sort(j,j+n-1);
        printf("%lld\n",j[0]);
    }
    return 0;
}


Measured memory_bytes: 13952
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
#define M_PI 3.14159265358979323846


#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

void setup() {
	ios::sync_with_stdio(0);
	cin.tie(0);
}


int main() {
	setup();
	int n, m,i,a;
	cin >> n >> m;
	REP(i, m)
	{
		cin >> a;
		n-=a;
	}
	if (n < 0)
	{
		cout << -1 << endl;
	}
	else {
		cout << n << endl;

	}

}

Measured memory_bytes: 3176
#include <stdio.h>

int main(void) {
	int i, j;
	char s[11];
	int len;
	long long sum;

	scanf("%s%n", s, &len);

	sum = 0;
	for (i = 1 << len - 1; i < 1 << len; i++) {
		long long cur = 0;
		for (j = 0; j < len; j++) {
			cur = cur * 10 + s[j] - '0';
			if (i >> j & 1) {
				sum += cur;
				cur = 0;
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>

#define MAX(X,Y) ((X)>(Y)?(X):(Y))
using namespace std;

int main(void){
  long long a,b,m;
  int k;
  
  scanf("%lld%lld", &a, &b);
  scanf("%d", &k);
  
  for (int i=a; i<=a+k-1 && i<= b; i++){
    printf("%d\n", m = i);
  }
  
  for (int i=MAX(m+1, b-k+1); i<=b; i++){
    printf("%d\n", i);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {

int a,b;
cin>>a>>b;
if(a==b) cout<<0<<endl;
else if((a+b)%2==0&&(b-(a+b)/2)<=0&&((a-(a+b)/2)>=0)) cout<<(a+b)/2;
else if((a+b)%2==0&&(b-(a+b)/2)>=0&&((a-(a+b)/2)<=0)) cout<<(a+b)/2;

else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define INF 1000000007
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b,c;cin>>a>>b>>c;
  cout<<min(c,b/a)<<endl;
}
  

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    long long a,b,c,delta=0;
    cin>>a>>b>>c;
    if(b>=a){
        cout<<1<<endl;
        goto endapp;
    }
    if(c>=b){
        cout<<-1<<endl;
        goto endapp;
    }
    if ((a-b)%(b-c)>=1)
        delta=1;
    cout<<((a-b)/(b-c)+delta)*2+1<<endl;
endapp:
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <string>
#include <vector>
using namespace std;
using P = pair<int, int>;

const int di[] = {0,-1,0,1};
const int dj[] = {-1,0,1,0};

int main(){
    int h, w;
    cin >> h >> w;
    int ch, cw;
    cin >> ch >> cw;
    int dh, dw;
    cin >> dh >> dw;
    --ch; --cw; --dh; --dw;
    vector<string> s(h);
    for(int i = 0; i < h; i++){
        cin >> s[i];
    }
    const int INF = 1e18;
    vector<vector<int> > dist(h, vector<int>(w, INF));
    dist[ch][cw] = 0;
    deque<P> q;
    q.emplace_front(ch,cw);
    while(!q.empty()){
        int i = q.front().first;
        int j = q.front().second;
        q.pop_front();
        int d = dist[i][j];
        for(int k = 0; k < 4; k++){
            int ni = i + di[k];
            int nj = j + dj[k];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(s[ni][nj] == '#') continue;
            if(dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni,nj);
        }
        for(int a = -2; a <= 2; a++){
            for(int b = -2; b <= 2; b++){
                int ni = i + a;
                int nj = j + b;
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(s[ni][nj] == '#') continue;
                if(dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni,nj);
            }
        }
    }
    int ans;
    if(dist[dh][dw] == INF){
        ans = -1;
    }else{
        ans = dist[dh][dw];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9464
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in a:
  if ((i+n)%2 == 0) and (i != 0):
    print(0)
    exit()
  if i in d:
    d[i] += 1
    if (d[i] == 3) or (i == 0):
      print(0)
      exit()
  else:
    d[i] = 1
ans = 1
for i in list(d.values()):
  ans *= i
print(ans%1000000007)

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

int main()
{
	string s;
	int k;
	cin>>s>>k;
	vector<string> v;
	int temp,temp2;
	for(temp=0;temp<s.size();temp++)
	{
		string s1;
		for(temp2=temp;temp2<min((int)s.size(),temp+5);temp2++)
		{
			s1+=s[temp2];
			v.push_back(s1);
		}
	}
	sort(v.begin(),v.end());
	auto it=unique(v.begin(),v.end()); v.erase(it,v.end());
	//for(auto lol : v)	cout<<lol<<"\n";
	cout<<v[k-1]<<"\n";
}

Measured memory_bytes: 1660
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1142&lang=jp

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

string reverse_str(string train)
{	
	int n = train.size();
	rep(i,n/2)
	{
		swap(train[i],train[(n-1)-i]);
	}

	return train;
}

bool check(vector<string> &train_list, string train)
{
	bool flag=false;

	rep(i,train_list.size())
	{
		if(train_list[i]  == train){ flag=true; }
	}

	return flag;
}

void train_list_pop(vector<string> &train_list, string split1, string split2)
{
	string tmp = split1 + split2;
	if(!check(train_list, tmp)){ train_list.push_back(tmp); }

	tmp = split1 + reverse_str(split2);
	if(!check(train_list, tmp)){ train_list.push_back(tmp); }

	tmp = reverse_str(split1) + split2;
	if(!check(train_list, tmp)){ train_list.push_back(tmp); }

	tmp = reverse_str(split1) + reverse_str(split2);
	if(!check(train_list, tmp)){ train_list.push_back(tmp); }
}

int main() {
	int M;

	cin >> M;
	string train;
	vector<string> train_list;

	rep(i,M)
	{
		cin >> train;
		
		train_list.clear();
		int n = train.size();
		REP(j,1,n)
		{
			string split1 = train.substr(0,j);
			string split2 = train.substr(j);
		
			train_list_pop(train_list, split1, split2);
			train_list_pop(train_list, split2, split1);

		}
		cout << train_list.size() << endl;

	}
	return 0;
}

Measured memory_bytes: 1276
n,a,b=map(int,input().split())
s=str(input())
o=0
e=0
for i in range(n):
  if s[i]=='a':
    if o<a+b:
      o+=1
      print('Yes')
    else:
      print('No')
  elif s[i]=='b':
    if o<a+b and e<b:
      o+=1
      e+=1
      print('Yes')
    else:
      print('No')
  else:
    print('No')


Measured memory_bytes: 75888
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,m = map(int, input().split())
    SCs = [list(map(int, input().split())) for _ in range(m)]
    for i in range(0, 10**(n)):
        istr = str(i)
        # print(istr)
        tf = True
        if len(istr) == n:
            for j in range(m):
                if istr[SCs[j][0]-1] != str(SCs[j][1]):
                    tf = False
            if tf:
                print(i)
                return
    print('-1')
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5480
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<char, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[2010];

int solve() {
    int s = 0;
    for (int i = 0; i < n; i++) {
        s += a[i];
    }
    bitset<4000100> b;
    b[0] = 1;
    for (int i = 0; i < n; i++) {
        b |= (b<<a[i]);
    }
    int t = (s+1) / 2;
    while (true) {
        if (b.test(t)) {
            return t;
        }
        t++;
    }
    return -1;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

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


Measured memory_bytes: 5100
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        int N = sc.nextInt();
        String S = sc.next();
        int R[] = new int[N];
        int G[] = new int[N];
        int B[] = new int[N];

        for (int i = N-2; i >= 0; i--) {
            R[i] = R[i+1] + (S.charAt(i+1) == 'R' ? 1 : 0);
            G[i] = G[i+1] + (S.charAt(i+1) == 'G' ? 1 : 0);
            B[i] = B[i+1] + (S.charAt(i+1) == 'B' ? 1 : 0);
        }

        long ans = 0;
        for(int i = 0; i < N; i++) {
            for(int j = i+1; j < N; j++) {
                char firstC = S.charAt(i);
                char secondC = S.charAt(j);
                if(firstC == secondC) continue;

                if((firstC == 'R' && secondC == 'B') || firstC == 'B' && secondC == 'R') {
                    ans += G[j];
                    if(2*j-i < N && S.charAt(2*j-i) == 'G')
                        ans--;
                }
                if((firstC == 'R' && secondC == 'G') || firstC == 'G' && secondC == 'R') {
                    ans += B[j];
                    if(2*j-i < N && S.charAt(2*j-i) == 'B')
                        ans--;
                }
                if((firstC == 'G' && secondC == 'B') || firstC == 'B' && secondC == 'G') {
                    ans += R[j];
                    if(2*j-i < N && S.charAt(2*j-i) == 'R')
                        ans--;
                }
            }
        }

        os.println(ans);

    }
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int x;
    cin >> x;
    cout << 8 - (x - 400) / 200 << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
const int maxn = 111, mod = 998244353;
int mul(long long a, long long b){
	return a * b % mod;
}
map<vector<bool>, int> f;
vector<bool> cut(vector<bool> &v, int l, int r){
	vector<bool> nxt;
	for(int i = l; i <= r; i++) nxt.push_back(v[i]);
	return nxt;
}
int solve(vector<bool> v){
	if(v.empty()) return 1;
	auto it = f.find(v);
	if(it != f.end()) return it->second;
	int ans = 0;
	ans += mul(1 + v[0], solve(cut(v, 1, v.size() - 1)));
	for(int i = 1; i <= v.size(); i++){
		for(int k = 2; k * i <= v.size(); k++){
			vector<bool> folded(i, true);
			for(int j = 0; j < k; j++)
				for(int l = 0; l < i; l++)
					folded[l] = folded[l] & v[j * i + l];
			ans += mul(solve(folded), solve(cut(v, k * i, v.size() - 1)));
			if(ans >= mod) ans -= mod;
		}
	}
	return f[v] = ans;
}
int main(){
	string s; cin >> s;
	int len = s.size();
	vector<bool> v(len);
	for(int i = 0; i < len; i++) if(s[i] == '1') v[i] = true;
	cout << solve(v) << endl;
	return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int n, m;
string s[100];
int si, sj, fi, fj;
int ans;
int sz;
vector<int> graph[500];
int c[22000];
int f[22000];
int v[22000];
int u[22000];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (s[i][j] == 'S') si = i, sj = j;
            if (s[i][j] == 'T') fi = i, fj = j;
        }
    }
    if (si == fi || sj == fj) cout << -1, exit(0);
    if (s[si][fj] == 'o') ans++, s[si][fj] = '.';
    if (s[fi][sj] == 'o') ans++, s[fi][sj] = '.';
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (s[i][j] != 'o') continue;
            v[sz] = i;
            u[sz] = j + n;
            c[sz] = (j != sj && i != fi);
            graph[i].push_back(sz);
            sz++;
            v[sz] = i;
            u[sz] = j + n;
            c[sz] = (i != si && j != fj);
            graph[j + n].push_back(sz);
            sz++;
        }
    }
    while (1)
    {
        vector<int> prv(200, -1);
        vector<int> vec;
        vec.push_back(si);
        vec.push_back(sj + n);
        prv[si] = -2, prv[sj + n] = -2;
        for (int i = 0; i < vec.size(); i++)
        {
            int vert = vec[i];
            for (int j = 0; j < graph[vert].size(); j++)
            {
                int id = graph[vert][j];
                int coct = v[id] + u[id] - vert;
                if (f[id] < c[id] && prv[coct] == -1)
                {
                    vec.push_back(coct);
                    prv[coct] = id;
                }
            }
        }
        if (prv[fi] == -1 && prv[fj + n] == -1)
        {
            cout << ans;
            return 0;
        }
        ans++;
        if (prv[fi] != -1)
        {
            int we = fi;
            while (1)
            {
                int id = prv[we];
                f[id]++;
                f[id ^ 1]--;
                we = u[id] + v[id] - we;
                if (prv[we] == -2) break;
            }
        }
        else
        {
            int we = fj + n;
            while (1)
            {
                int id = prv[we];
                f[id]++;
                f[id ^ 1]--;
                we = u[id] + v[id] - we;
                if (prv[we] == -2) break;
            }
        }
    }
}


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

int main() {
  int N;
  string S;
  string T;
  cin >> N;
  cin >> S;
  cin >> T;
  for (int i=0; i<N; i++) {
    cout << S.at(i) << T.at(i); 
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;

#define MAXN 200010

int n;
ll bi[2*MAXN];
ll C[MAXN];

void initBI( ll MOD ){
	bi[0] = 1;
	for( int i = 1; i < 2*MAXN; ++i )
		bi[i] = ( 2 * bi[i-1] ) % MOD;
}

bool cmp_reverse( ll a, ll b ){
	return a > b;
}


ll mismatch( ll k, ll MOD ){
	// In fact, k here = k in main() - 1
	if( k == 0 )
		return 1;
	return (k+2) * bi[2*k-1] % MOD;
}


int main(){
	

	ll const MOD = 1000000007L;
	initBI( MOD );

	std::cin >> n;

	for( int i = 1; i <= n; i++ )
		std::cin >> C[i];

	/*	思路：
	 *	假設，A[k] <- 長度為k的兩個序列對(p1,p2)，滿足(p1 != p2)的序列對數量
	 *	已知，A[k] = 2^k * (2^k - 1)
	 *	用遞推法也可得，對最後的一個bit(位置為k)進行討論的話，有四種情況
	 *	00: A[k-1]
	 *	01: (2^(k-1))^2
	 *	10: (2^(k-1))^2
	 *	11: A[k-1]
	 *
	 *	對C進行逆序排序，原因是我們希望權重比較大的位先進行反轉
	 *  假設dp[k-1]是長度為k-1的序列對的結果
	 *  則，00和11直接就等於這個dp[k-1]
	 *	01和10還需要考慮 sum( 長度k-1序列中的錯位值 * C[k] ) 對所有(2^(k-1))^2個序列對求和
	 *	等價於考慮： sum( 長度k序列對中錯位值為i的數量 * i * C[k] ) 對所有i = 1 to k
	 *	最後我們會得到：
		k = 1, c[0] = 2 c[1] = 2
		k = 2, c[0] = 4 c[1] = 8 c[2] = 4
		k = 3, c[0] = 8 c[1] = 24 c[2] = 24 c[3] = 8
		k = 4, c[0] = 16 c[1] = 64 c[2] = 96 c[3] = 64 c[4] = 16
		k = 5, c[0] = 32 c[1] = 160 c[2] = 320 c[3] = 320 c[4] = 160 c[5] = 32
		剩餘等式自己推導
		sigma( i * iCk )的求和公式可參考維基百科
		https://bit.ly/314EqQ9
	 */

	std::sort( C+1, C+1+n, cmp_reverse);
	ll res = 0;
	for( int k = 1; k <= n; k++ ){
		res = res * 4 % MOD;
		res = (res + C[k] * mismatch(k-1,MOD) % MOD * 2 % MOD) % MOD;
	}

	std::cout << res << std::endl;

}


Measured memory_bytes: 4992
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]
t = []
last = [[-1] for i in range(26)]

# max index greedy search
for i in range(D):
    op = 0
    mx = 0
    for j in range(26):
        if s[i][j]*c[j] > mx:
            mx = s[i][j]*c[j]
            op = j
    t.append(op+1)
    last[op].append(i)
    # ans += s[i][op]
    # last[op]=i
    # for j in range(26):
    #     ans -= c[j]*(i-last[j])
    # for j in range(26):
    #     ans -= c[j]*(i-last[j][-1])

# update
from bisect import *
import random
m = 2000000
def suminc(a,b):
    return b*(b-1)//2-a*(a-1)//2
while m:
    m-=1
    update = 0
    d = random.randint(1,D)
    q = random.randint(1,26)
    d-=1
    q-=1
    oq = t[d]-1
    update += s[d][q]-s[d][oq]
    idx = bisect_left(last[oq],d)
    if idx == len(last[oq])-1:
        cnt = D - last[oq][idx]
    else:
        cnt = last[oq][idx+1] - last[oq][idx]
    update += c[oq]*suminc(0,cnt)
    cntprv = last[oq][idx] - last[oq][idx-1]
    update -= c[oq]*suminc(cntprv,cntprv+cnt)

    idx2 = bisect_left(last[q],d)-1
    if idx2 == len(last[q])-1:
        cnt = D - d
    else:
        cnt = last[q][idx2+1] - d
    if idx2 == len(last[q])-1:
        cntprv = D - last[q][idx2] - cnt
    else:
        cntprv = last[q][idx2+1] - last[q][idx2] - cnt
    update += c[q]*suminc(cntprv,cntprv+cnt)
    update -= c[q]*suminc(0,cnt)

    if update > 0:
    # ans += update
        del last[oq][idx]
        last[q].insert(idx2+1,d)
        # print(ans)
        t[d] = q+1

# with open('ramdom.out', 'w') as f:
#     for i in range(D):
#         print(t[i],file=f)

for i in range(D):
    print(t[i])


Measured memory_bytes: 89344
using System;
using System.Collections.Generic;
using System.Linq;
namespace Codes
{
    class Program
    {
        static void Main(string[] args)
        {
            string answer = "hoge";
            int n = -1;

            var aList = new List<List<int>>();
            var bList = new List<int>();
            while(true){
                var a = Console.ReadLine().Split(' ').Select(l => int.Parse(l));
                if(a.Count() == 1){
                    n = a.First();
                    break;
                }
                aList.Add(a.ToList());
            }
            


            for(int i = 0;i<n;i++){
                bList.Add(int.Parse(Console.ReadLine()));
            }
            foreach(var b in bList){
                foreach(var a in aList){
                    for(var i = 0;i<aList.Count();i++){
                        if(a[i] == b){
                            a[i] = 0;
                        }
                    }
                }
            }

            if(aList[0][0] + aList[0][1] + aList[0][2] == 0 ||
               aList[1][0] + aList[1][1] + aList[1][2] == 0 ||
               aList[2][0] + aList[2][1] + aList[2][2] == 0 ||
               aList[0][0] + aList[1][0] + aList[2][0] == 0 ||
               aList[0][1] + aList[1][1] + aList[2][1] == 0 ||
               aList[0][2] + aList[1][2] + aList[2][2] == 0 ||
               aList[0][0] + aList[1][1] + aList[2][2] == 0 ||
               aList[0][2] + aList[1][1] + aList[2][0] == 0){
                   answer = "Yes";
               }
               else{
                   answer = "No";
               }




            Console.WriteLine(answer);


        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int ans = 0;
  while (n) {
    ans++;
    n /= k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby

N = gets.chomp.to_i
P = gets.chomp.split(" ").map(&:to_i)
Q = gets.chomp.split(" ").map(&:to_i)

n = Array(1..N).permutation.to_a


p = 0
q = 0

1.upto(n.size){|i|
  if n[i-1] == P
    p = i
  end

  if n[i-1] == Q
    q = i
  end

  break if p != 0 and q != 0
}

puts (p-q).abs


Measured memory_bytes: 6780
fun main(args:Array<String>) {
    val (n,k,q) = readLine()!!.split(" ").map { it.toLong() }
    val log = (1..q).map { readLine()!!.toInt()-1 }
    val ans = (1..n).map { k - q }.toMutableList()
    for(i in log) {
        ans[i] = ans[i] + 1
    }
    for(i in ans) {
        println(if(i>0) "Yes" else "No")
    }
}


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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 10001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define int long long
const double PI = acos(-1);
typedef pair<int, int> P;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void)
{
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i)
        {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}
vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i - 1);
            if (i * i != n)
            {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main()
{
	int a,b,c;
    cin >> a >> b >> c;
    if(b - a == c - b){
    	cout << "YES" << endl;
    }else{
    	cout << "NO" << endl;
    }
}


Measured memory_bytes: 3608
# coding: utf-8
# Your code here!
n = int(input())
s = list(map(int,input().split()))
ans = {}
#各番号がいくつずつあるのかを整理
#keyに番号、valueにその番号が書かれてあるボールの数
for i in range(n):
    if not s[i] in ans.keys():
        ans[s[i]] = 1
    else:
        ans[s[i]] += 1
#iC2の総和
answer = 0
for i,j in ans.items():
    answer += j*(j-1)//2
#answer-nC2+(n-1)C2 = answer-n+1
#nはans[s[i]],よって以下の出力で求められる
for i in range(n):
    print(answer-ans[s[i]]+1)


Measured memory_bytes: 26140
n=int(input())
arr=[int(i) for i in input().split()]
q=int(input())
q_arr=[]
for i in range(q):
    q_arr.append([int(j) for j in input().split()])
from collections import defaultdict
cnt=defaultdict(lambda :0)
sum_=sum(arr)
for i in arr:
    cnt[i]+=1
#print(cnt)
for j in q_arr:
    if cnt[j[0]]:
        sum_+=(j[1]-j[0])*(cnt[j[0]])
        cnt[j[1]]+=cnt[j[0]]
        cnt[j[0]]=0
    print(sum_)


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

int main() {
  string a, b;
  cin >> a >> b;
  int x = stoi(a+b);
  for (int i = 2; i * i <= x; i++) {
    if (x / i == i && x % i == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
public class Main {

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    protected static String calc(String input) {
        final int[] ints = split(input);

        int a = ints[0];
        int b = ints[1];
        int c = ints[2];

        if (a < b && b < c) {
            return "Yes";
        }

        return "No";
    }

    private static int[] split(String s) {
        final String[] s0 = s.split(" ");
        int[] ints = new int[s0.length];

        for (int i = 0; i < s0.length; i++) {
            ints[i] = Integer.parseInt(s0[i]);
        }

        return ints;
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
}

Measured memory_bytes: 17288
S = input()
K = int(input())
V = []
for e in S:
    V.append(ord(e)-97)
for i in range(len(S)):
    if S[i] == 'a':
        continue
    if K < 26-V[i]:
        pass
    else:
        K -= 26-V[i]
        V[i] = 0
V[-1] += K
V[-1] %= 26
V = [chr(e+97) for e in V]
print("".join(V))


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380
int digit(LLI val, int n) { return (int)(val / pow(10, 1)) % 10; }

int m[10][10];

int f(int l) {
    while(9 < l) {
        l /= 10;
    }
    return l;
}

int main() {
    cout << fixed << setprecision(10);
    int n;
    cin >> n;

    for(int a = 1; a <= n; a++) {
        int at = a % 10;
        int al = f(a);
        m[at][al]++;
    }

    int c = 0;
    for(int a = 1; a <= n; a++) {
        int at = a % 10;
        int al = f(a);
        // 末尾がatで最上位がal
        c += m[al][at];
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;

typedef vector<ull> vull;
typedef vector<ll> vll;
typedef vector<ui> vui;
typedef vector<long> vl;
typedef vector<int> vi;

typedef pair<ull, ull> pull;
typedef pair<ll, ll> pll;
typedef pair<ui, ui> pui;
typedef pair<long, long> pl;
typedef pair<int, int> pi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

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

    int x = 0, maxi = 0;
    for (char c: s) {
        if (c == 'I') ++x;
        if (c == 'D') --x;
        maxi = max(maxi, x);
    }

    cout << max(maxi, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        vector<pair<int, int>> v;
        rep(i,n){
            int a, b;
            cin >> a >> b;
            v.emplace_back(a,b);
        }

        int dp[1005] = {0};
        dp[0] = 1;
        rep(i,n){
            for(int j = 1000; j >= 0; j--){
                range(k,1,v[i].second + 1){
                    if(j - v[i].first * k < 0) continue;
                    dp[j] += dp[j - v[i].first * k];
                }
            }
        }

        int g;
        cin >> g;
        rep(i,g){
            int k;
            cin >> k;
            cout << dp[k] << endl;
        }
    }
}

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

using namespace std;

int main() {
  int m, d;
  scanf("2019/%d/%d", &m, &d);

  int date = 100 * m + d;
  if (date <= 430) {
    cout << "Heisei\n";
  } else {
    cout << "TBD\n";
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  set<char> acgt; int l=0;
  acgt.insert('A'); acgt.insert('C'); acgt.insert('G'); acgt.insert('T');
  for(int i=0;i<s.size();i++){
    for(int j=1;j<=s.size()-i;j++){
      string  tmp = s.substr(i,j);
      bool flag = true;
      for(int k=0;k<tmp.size();k++) if(!acgt.count(tmp.at(k))) flag = false;
      if(flag) l = max(l,(int)tmp.size());
    }
  }
  cout << l << endl;
        
      
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 8
#define exsit -1
#define nexsit 1
#define true 1
#define false 0

int row[N],col[N],lslan[2*N-1],rslan[2*N-1],a[N][N];

//初期化
void initialize(){
  int i;
  
  for(i=0;i<N;i++){
    row[i]=col[i]=exsit;
  }

  for(i=0;i<2*N-1;i++){
    lslan[i]=rslan[i]=exsit;
  }
}

void print(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(a[i][j] && row[i]!=j) return;   //指定されたところにクイーンがない場合、やり直し
    }
  }

  for(i=0;i<N;i++){             //指定されたところにクイーンがある場合、表示
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void position(int i){
  int j;
  
  if(i==N){
    print();
    return; 
  }

  //クイーンが他のクイーンい襲撃されている場合は無視する
  for(j=0;j<N;j++){
    if(col[j]==nexsit || lslan[i+j]==nexsit || rslan[i-j+N-1]==nexsit ) continue;
    
    
    //クイーンを配置する
    row[i]=j;
    col[j]=lslan[i+j]=rslan[i-j+N-1]=nexsit;
    
    //次の行に配置する
    position(i+1);
    
    //失敗した場合クイーンを取り除く
    row[i]=col[j]=lslan[i+j]=rslan[i-j+N-1]=exsit;
  }  
}

int main(){
  int i,j,n,r,c;
  
  initialize();

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      a[i][j]=false;
    }
  }

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    a[r][c]=true;
  }

  position(0);

  return 0;
}




Measured memory_bytes: 2108
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n = inp()
a = inlist()
a = sorted(a)
res = 1
for i in a:
    res *= i
    if res > 10**18:
        res = -1
        break
print(res)


Measured memory_bytes: 22628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    string ans = "No";
    if(abs(a-b)<=d && abs(b-c)<=d){
        ans = "Yes";
    }
    if(abs(a-c)<=d){
        ans = "Yes";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from datetime import datetime, timedelta
h1, m1, h2, m2, k = [int(i) for i in input().split()]

t1 = datetime(year=1, month=1, day=1, hour=h1, minute=m1)
t2 = datetime(year=1, month=1, day=1, hour=h2, minute=m2)
if h2 > h1:
    print((t2-t1-timedelta(minutes=k)).seconds//60)
elif h1 == h2 and m2 > m1:
    print((t2-t1-timedelta(minutes=k)).seconds//60)
else:
    t2 = t2.replace(day=2)
    print((t2-t1-timedelta(minutes=k)).seconds//60)


Measured memory_bytes: 9312
#include <bits/stdc++.h>
#define fi first 
#define se second
using namespace std;
typedef long long i64;
typedef pair<int, int> pii;
const int N = 2e5+5;
int n, a[N], b[N]; i64 ans; priority_queue<pii> q;
int get(int x) { return !x?n:x==n+1?1:x; }
int main()
{ 
    scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", a+i);
    for(int i = 1; i <= n; ++i) scanf("%d", b+i);
    for(int i = 1; i <= n; ++i) 
        if(a[i] > b[i]) return puts("-1"), 0;
        else if(a[i] < b[i]) q.push(pii(b[i], i));
    while(q.size())
    {
        pii u = q.top(); q.pop();
        int i = u.se, d = b[i]-a[i], w = b[get(i-1)]+b[get(i+1)];
        if(d/w == 0&&a[i] != b[i]) return puts("-1"), 0;
        ans += d/w, b[i] -= d/w*w;
        if(a[i] < b[i]) q.push(pii(b[i], i));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6844
#include <iostream>
#include <map>
#include <vector>
#include <stack>
using namespace std;

int main(){
  long N,Q;
  cin>>N>>Q;
  
  map<long,std::vector<long long>> tree;
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a-=1;
    b-=1;
    if(tree.count(a)==0){
      vector<long long> vec;
      tree[a]=vec;
    }
    if(tree.count(b)==0){
      std:vector<long long> vec;
      tree[b]=vec;
    }
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  long long points[N];
  for(int i=0;i<N;i++){
    points[i]=0;
  }
  for(int i=0;i<Q;i++){
    long long p,x;
    cin>>p>>x;
    p-=1;
    points[p]=points[p]+x;
  }
  
  stack<vector<long long>> s;
  s.push({0,0,-1});
  long long ans[N];
  for(int i=0;i<N;i++){
    ans[i]=0;
  }
  while(s.size()>0){
    vector<long long> v;
    v=s.top();
    s.pop();
    
    long long node = v[0];
    long long point = v[1];
    long long parent = v[2];
    
    long long curpoints=point+points[node];
    ans[node]=curpoints;
    vector<long long> vec = tree[node];
    for(int i=0;i<vec.size();i++){
      long long nex = vec[i];
      if(nex==parent){
        continue;
      }
      s.push({nex,curpoints,node});
    }
  }
  for(int i=0;i<N;i++){
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 40916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

ll a[2000010], f[2000010];
ll n, k;
ll c = 0;

int main() {
  cin >> n >> k;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (ll i = 0; i < n; i++) {
    cin >> f[i];
  }
  sort(a, a + n);
  sort(f, f + n);
  ll r = -1, l = a[n - 1] * f[n - 1];
  while (l - r > 1) {
    ll mid = (l + r) / 2;
    ll res = 0;
    for (ll i = 0; i < n; i++) {
      res += max(c, a[i] - mid / f[n - i - 1]);
    }
    if (res <= k) {
      l = mid;
    } else {
      r = mid;
    }
  }
  cout << l << endl;
}


Measured memory_bytes: 6016