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

using namespace std;
const int N=1e5+10;
il int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<1],nt[N<<1],hd[N],dg[N],ddg[N],tot;
void add(int x,int y)
{
    ++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot,++dg[x];
    ++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot,++dg[y];
}
int n,m,ans,s[N],de[N],sx,sy;
bool v[N];
int st[N],tt,sq[N],ts,kk[N];
void findd()
{
    queue<int> q;
	for(int i=1;i<=n;++i) if(dg[i]==1) q.push(i);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=hd[x];i;i=nt[i])
		{
			int y=to[i];
			--dg[y];
			if(dg[y]==1) q.push(y);
		}
	}
	for(int i=1;i<=n;++i)
		if(dg[i]>1)
		{
			int la=0,x=i;
			while(1)
			{
				sq[++ts]=x;
				for(int i=hd[x];i;i=nt[i])
				{
					int y=to[i];
					if(dg[y]<=1||y==la) continue;
					la=x,x=y;break;
				}
				if(x==i) break;
			}
			return;
		}
}
void dfs(int x,int ffa,int ss)
{
	if(x==sx) kk[x]=1;
	else if(x==sy) kk[x]=-1;
	s[x]+=de[x]=ss;
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(y==ffa) continue;
		if(min(x,y)==min(sx,sy)&&max(x,y)==max(sx,sy)) continue;
		dfs(y,x,-ss);
		s[x]+=s[y],kk[x]+=kk[y];
	}
	ans+=abs(s[x]);
}

int main()
{
////
    n=rd(),m=rd();
    for(int i=1;i<=m;++i) add(rd(),rd());
    if(m==n-1)
    {
		dfs(1,0,1);
		printf("%d\n",s[1]?-1:ans);
    }
    else
    {
		findd();
		sx=sq[1],sy=sq[2];
		dfs(1,0,1);
		if(ts&1)
		{
			if(abs(s[1])&1) puts("-1");
			else
			{
				int sht=-(s[1]/2);
				for(int i=1;i<=n;++i) s[i]=0;
				s[sq[1]]=s[sq[2]]=sht;
				ans=0,dfs(1,0,1);
				printf("%d\n",ans+abs(sht));
			}
		}
		else
		{
			if(s[1]) puts("-1");
			else
			{
				ans=0;
				st[tt=1]=0;
				for(int i=1;i<=n;++i)
				{
					if(!kk[i]) ans+=abs(s[i]);
					else st[++tt]=(~kk[i])?-s[i]:s[i];
				}
				sort(st+1,st+tt+1);
				for(int i=1;i<=tt;++i) ans+=abs(st[i]-st[(tt+1)/2]);
				printf("%d\n",ans);
			}
		}
    }
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define int long long
#define ld long double
#define endl '\n'
const int mod= 1e9+7;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define trace(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
#define reset(x,val) memset(x,val,sizeof(x))
#define flush fflush(stdout)
#define sz(a) a.size()
#define pii pair<int,int>
using namespace std;

int dp[100005][102],n,wt;
int v[102],w[102];
void smin(int &x,int y)
{
 x=min(x,y);
}
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>n>>wt;
    for(int i=0;i<100005;i++)
    for(int j=0;j<n;j++)
    dp[i][j]=1e10;
    for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
    
    for(int i=0;i<n;i++)
    dp[0][i]=0;
    
    for(int val=1;val<100005;val++)
    {
     for(int j=0;j<n;j++)
     {
      if(j==0)
      {
       if(v[j]==val)
       dp[val][j]=w[j];
       continue;
       //cout<<val<<' '<<w[j]<<endl;
      }
      if(val<v[j])
      dp[val][j]=dp[val][j-1];
      else
      {
       dp[val][j]=min(w[j]+dp[val-v[j]][j-1] , dp[val][j-1]);
      }
     }
    }
    //trace(dp[30][0]);
    int ans=0;
    for(int i=0;i<100005;i++)
    {
     for(int j=0;j<n;j++)
     if(dp[i][j]<=wt)
     {
     ans=i;
     }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 80000
private fun readInts(): List<Int> = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (N, Q) = readInts()
    val S = readLine()!!
    val lr = (0 until Q).map { readInts().map { index -> index - 1 } } // 0-started

    val left = lr.map { it[0] }
    val right = lr.map { it[1] }

    val sum = Array(N) { 0 }
    for (index in 1 until N) {
        val ac = if (S[index - 1] == 'A' && S[index] == 'C') 1 else 0
        val prev = sum[index - 1]

        sum[index] = ac + prev
    }

    (0 until Q)
        .map { index -> sum[right[index]] - sum[left[index]] }
        .forEach(::println)
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,q;
ll a[100010],x,sum[100010],osum[100010],esum[100010];

void input(){
	cin>>n>>q;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum[i+1]=sum[i]+a[i];
		if(i%2==0)esum[i+1]=esum[i]+a[i],osum[i+1]=osum[i];
		else osum[i+1]=osum[i]+a[i],esum[i+1]=esum[i];
	}
	return;
}

void solve(){
	while(q--){
		cin>>x;
		int l=0,r=(n+1)/2,mid;
		while(r-l>1){
			mid=(r+l)/2;
			if(n-mid*2<0){
				r=mid;
				continue;
			}
			int it2=n-mid-1,it1=n-mid*2-1;
			if(abs(x-a[it2])<abs(x-a[it1]))r=mid;
			else l=mid;
		}
		ll ans=sum[n]-sum[n-r];
		if((n-r*2)%2==0)ans+=osum[n-r*2];
		else ans+=esum[n-r*2];
		cout<<ans<<endl;
	}
	return;
}

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

Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

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

    int t,f;
    char c;
    bool b=false;
    for(int i=0;i<Q;i++){
        cin>>t;
        if(t==1){
            string tmp=S;
            S=R;
            R=tmp;
        }else{
            cin>>f>>c;
            if(f==1){
                R+=c;
            }else{
                S+=c;
            }
        }
    }
    reverse(R.begin(),R.end());
    string ans=R+S;

    cout<<ans;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> num(N,1),pos(N,0);
    pos[0]=1;
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--,y--;
        num[x]--,num[y]++;
        if (pos[y]==1){
            pos[y]=2;
        }
        else if (pos[x]==1){
            pos[x]=0;
            if (num[y]==1){
                pos[y]=1;
            }
            else {
                pos[y]=2;
            }
        }
        else if (pos[x]==2){
            if (num[x]==0){
                pos[x]=0;
            }
            pos[y]=2;
        }
    }
    int ans=0;
    rep(i,N){
        if (pos[i]==1||pos[i]==2){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;

const ll INF = 1000000000;

int main() {FIN
    
    ll i, a, n, mn = INF, mx = -INF, sm = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> a;
        mn = min(mn, a);
        mx = max(mx, a);
        sm += a;
    }
    cout << mn << " " << mx << " " << sm << "\n";
    
    return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = (int)s.size();
  int pcnt = 0;
  for (int i = 0; i < n; ++i) if (s[i] == 'p') pcnt++;

  cout << n / 2 - pcnt << endl;
  return 0;
}



Measured memory_bytes: 512
a,b,c,d,e,f=map(int,open(0).read().split())
a,b,c=sorted((s*s+t*t)**.5for s,t in((a-c,b-d),(c-e,d-f),(e-a,f-b)))
d=a+b+c
s=d/2
s=(s*(s-a)*(s-b)*(s-c))**.5
r=2*s/d
l,h=0,1e5
while h-l>1e-9:
  m=(h+l)/2
  if c*(r-m)/r<2*m:h=m
  else:l=m
print(l)

Measured memory_bytes: 38768
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a>b){
        for(int i=0;i<a;i++){
            printf("%d",b);
        }
    }
    else if(a<b){
        for(int j=0;j<b;j++){
            printf("%d",a);
        }
    }
    else {
        for(int k=0;k<b;k++){
            printf("%d",a);
        }
    }
}

Measured memory_bytes: 128
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ull ba=233;
const db eps=1e-6;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=300000+10,maxn=10000000+10,inf=0x3f3f3f3f;

int main()
{
    int a,b;scanf("%d%d",&a,&b);
    printf("%d\n",(a*3+b)/2);
    return 0;
}
/********************

********************/


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int t[3];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  string s;
  cin >> s;
  R(i,SZ(s)){
    t[s[i] - 'a']++;
  }
  if(max({t[0],t[1],t[2]}) - min({t[0], t[1], t[2]}) > 1){
    cout << "NO\n";
  }else{
    cout << "YES\n";
  }
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int mod = 1e9 + 7;
const int maxN = 2e5 + 7;

inline int pls(int x, int y) {return (x + y) % mod;}
inline int mns(int x, int y) {return pls(x, mod - y);}
inline int mul(int x, int y) {return 1LL * x * y % mod;}
inline void Add(int &x, int y) {x = pls(x, y);}
inline void Mul(int &x, int y) {x = mul(x, y);}
inline void Minus(int &x, int y) {x = mns(x, y);}
inline int pwr(int x, int tms) {
	int res = 1;
	for (; tms > 0; tms >>= 1) {
		if (tms & 1) Mul(res, x);
		Mul(x, x);
	}
	return res;
}
inline int inv(int x) {return pwr(x, mod - 2);}

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m, A, B;
int fac[maxN], ifac[maxN], iv[maxN];

void init() {
	iv[1] = 1; For (i, 2, maxN) iv[i] = mul(mod - mod / i, iv[mod % i]);
	fac[0] = 1; For (i, 1, maxN) fac[i] = mul(fac[i - 1], i);
	ifac[0] = 1; For (i, 1, maxN) ifac[i] = mul(ifac[i - 1], iv[i]);
}

inline int C(int x, int y) {return (y <= x) ? mul(mul(fac[x], ifac[y]), ifac[x - y]) : 0;}

inline int ways(int x, int y) {return C(x + y, x);}

int main() {
	init();

	n = ri(), m = ri(), A = ri(), B = ri();

	n -= A;
	int res = 0;
	rep (j, B+1, m) {
		Add(res, mul(ways(n-1, j-1), ways(A-1, m-j)));
	}
	printf("%d\n", res);

	return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 5e5 + 55;

char c[MAXN];

int dp[MAXN];

void solve(){
	int n;
	scanf("%d%s", &n, &c[1]);
	n += 3;
	c[0] = '0';
	c[n - 1] = '0';
	c[n - 2] = '0';
	int ans = 0;
	REP(i, 1, n){
		dp[i] = max(dp[i], dp[i - 1]);
		if (c[i] == '0' && c[i - 1] == '1' && c[i + 1] == '1'){
			for(int j = i - 1, k = 1; c[j] == '1'; j--, k++){
				dp[i + 2] = max(dp[i + 2], dp[j] + k);
			}
			for(int j = i + 1, k = 1; c[j] == '1'; j++, k++){
				dp[j + 1] = max(dp[j + 1], dp[i - 1] + k);
			}
		}
	}
	
	REPN(i, 0, n){
		ans = max(ans, dp[i]);
		//printf("%d %d\n", i, dp[i]);
	}
	
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 2688
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();

    int[] H = new int[N];
    for (int i = 0; i < N; i++) {
      H[i] = scn.nextInt();
    }

    boolean flg = true;
    H[0]--;
    for (int i = 0; i < N - 1; i++) {
      if (H[i] < H[i + 1]) {
        H[i + 1]--;
      } else if (H[i] > H[i + 1]) {
        flg = false;
        break;

      }
    }

    System.out.println(flg ? "Yes" : "No");
  }
}

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

int main(void){
string str;
getline(cin,str);
for(int i=0;i<str.length();i++){
if('a'<=str[i]&&str[i]<='z')str[i]+='A'-'a';
}
cout<<str<<endl;
return 0;
}

Measured memory_bytes: 3200
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    string a;
    cin >> a;
    bool t = true;
    for(int i = 0; i < 3; i++){
        if(a[i] == a[i+1]){
            cout << "Bad";
            t = false;
            break;
        }
    }
    if(t){
        cout << "Good";
    }
    
    cout << endl;
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

double solve(vector<vector<double>> &dp, vector<vector<bool>> &vis, const vector<double> &v, int h, int t, int n) {
    if(h+t == n) return (h > t);
    if(vis[h][t]) return dp[h][t];
    vis[h][t] = 1;
    dp[h][t] = (solve(dp,vis,v,h+1,t,n)*v[h+t] + solve(dp,vis,v,h,t+1,n)*(1-v[h+t]));
    return dp[h][t];
}


int main() {
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<double>> dp(n,vector<double>(n,0));
    vector<vector<bool>> vis(n,vector<bool>(n,0));
    vector<double> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    cout << fixed << setprecision(9) << solve(dp,vis,v,0,0,n) << endl;
    return 0;
}



Measured memory_bytes: 72192
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
//	ios_base::sync_with_stdio(0); cin.tie(0);
	#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	#endif
	int a,b,c;
	set<int> s;
	cin>>a>>b>>c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout<<s.size()<<'\n';
	return 0;
}	

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


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


    int n, t;
    cin>>n>>t;
    vector<int> a(n);
    for (int i = 0; i<n; i++) cin>>a[i];
    map<int, int> pos;
    for (int i = 0; i<n; i++) pos[a[i]] = i;

    int best = 0;
    int cur = a[0];
    for (int i = 1; i<n; i++)
    {
        best = max(best, a[i]-cur);
        cur = min(cur, a[i]);
    }

    int cnt = 0;


    for (int i = 1; i<n; i++)
    {
        if (pos.find(a[i]-best)!=pos.end() && pos[a[i]-best]<i) cnt++;
    }
    cout<<cnt;

}



Measured memory_bytes: 5376
#include<iostream>
#include<vector>
using namespace std;
bool isPrime(int n){
	if(n<=1||n%2==0&&n!=2)return false;
	for(int i=3;i*i<=n;i+=2){
		if(n%i==0)return false;
	}
	return true;
}

int main(){
	vector<int> p;
	for(int i=2;i<=1120;i++)if(isPrime(i))p.push_back(i);
	//cout<<p.size()<<endl;
	int dp[15][1121]={0};
	dp[0][0]=1;
	for(int i=0;i<p.size();i++){
		for(int j=14;j>0;j--){
			for(int k=0;k+p[i]<=1120;k++){
				dp[j][k+p[i]] += dp[j-1][k];
			}
		}
	}
	int n,k;
	while(cin>>n>>k,n|k){
		cout<<dp[k][n]<<endl;
	}
	return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int n2=n%100;
	int n1=n/100;
	if(n1<=12 && n2<=12 && n1!=0 && n2!=0)
		cout<<"AMBIGUOUS\n";
	else if(n1>12 && n2>12)
		cout<<"NA\n";
	else if(n1<=12 && n1!=0)
		cout<<"MMYY\n";
	else if(n2<=12 && n2!=0)
		cout<<"YYMM\n";
	else{
		cout<<"NA\n";
	}

	return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)


int main()
{	
	int n,x;
	int a;
	int out=0;
	cin>>n>>x;
	
	rep(i,x){
		cin>>a;
		out+=max(0,a-(n-a)-1);
	}
	
	cout<<out<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll a, b, c, k;
/******* define variable end *******/
int solve() {
	cin >> a >> b >> c >> k;
	if(a >= k){
		cout << k << endl;
	}else if(a + b >= k){
		cout << a << endl;
	}else {
		cout << a - (k-a-b) << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main() {
	int n;
	int s[150], d[150];
	int big;
	int m;
	int ans[150] = { 0 };

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> d[i];
	}

	for (int i = 0; i < n; i++) {
		m = s[i];
		while (m != d[i]) {
			for (int j = 35; j >= 0; j--) {
				if (m % (int)pow(2, j) == 0 && m + pow(2, j) <= d[i]) {
					m += pow(2, j);
					ans[i]++;
					break;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
N = int(input())
S = input()
R = set()
G = set()
B = set()
for i in range(N):
    if S[i] == 'R':
        R.add(i)
    elif S[i] == 'G':
        G.add(i)
    else:
        B.add(i)

ans = len(R)*len(G)*len(B)
if ans == 0:
    print(0)
    exit()
for i in R:
    for j in G:
        d = abs(j-i)
        a = min(i, j)-d
        b = (i+j)/2
        c = max(i, j)+d
        s = {a, b, c}
        for k in s:
            if k in B:
                ans -= 1
print(ans)


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int INF = 1000000007;
    vector<string> kurai;
    kurai.push_back("10 ");
    kurai.push_back("50 ");
    kurai.push_back("100 ");
    kurai.push_back("500 ");
    int start = 0;
    while (1) {
        int N;
        cin >> N;
        if (!N) break;
        if (start != 0) {
            cout << endl;
        }
        int JU, GOJU, HYAKU, GOHYAKU;
        cin >> JU >> GOJU >> HYAKU >> GOHYAKU;
        vector<int> cashCoin(4, INF);
        int coinMax = INF;
        for (int i = 0; i <= JU; i++) {
            for (int j = 0; j <= GOJU; j++) {
                for (int k = 0; k <= HYAKU; k++) {
                    for (int l = 0; l <= GOHYAKU; l++) {
                        if (10 * i + 50 * j + 100 * k + 500 * l < N) continue;
                        int oturi = (10 * i + 50 * j + 100 * k + 500 * l) - N;
                        int I = JU - i, J = GOJU - j, K = HYAKU - k, L = GOHYAKU - l;
                        L += oturi / 500;
                        oturi %= 500;
                        K += oturi / 100;
                        oturi %= 100;
                        J += oturi / 50;
                        oturi %= 50;
                        I += oturi / 10;
                        oturi %= 10;
                        // cout << i << " " << j << " " << k << " " << l << endl;
                        if (I + J + K + L < coinMax) {
                            coinMax = I + J + K + L;
                            cashCoin[0] = i;
                            cashCoin[1] = j;
                            cashCoin[2] = k;
                            cashCoin[3] = l;
                        }
                        // cout << coinMax << endl;
                    }
                }
            }
        }
        for (int i = 0; i < cashCoin.size(); i++) {
            if (cashCoin[i] == 0) continue;
            cout << kurai[i] << cashCoin[i] << endl;
        }
        start++;
    }
}


Measured memory_bytes: 3184
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#define ll long long
using namespace std;
struct dog {
	string a;
	int b;
};
int main()
{
	//dog shiba; dog pa;
	//cin >> shiba.a >> pa.a;
	//cin >> shiba.b >> pa.b;
	//string key;
	//cin >> key;
	//if (shiba.a == key)shiba.b -= 1;
	//else if (pa.a == key)pa.b -= 1;
	//cout << shiba.b << " " << pa.b;

	string key;
	cin >> key;
	for (int i = 0; i < key.length(); i++)
	{
		cout << "x";
	}

}



Measured memory_bytes: 3624
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

pair<int, int> proceed(string s, int t, int &hp) {
    string lower = s;
    for(auto &c : lower) if('A' <= c and c <= 'Z') c = (char)(c - 'A' + 'a');

    size_t ptr = 0;
    int success = 0, sum = 0;
    while(ptr < s.size() and hp > 0) {
        printf("? %s\n", s.c_str());
        fflush(stdout);

        char c; scanf(" %c", &c);
        if('A' <= c and c <= 'Z') c = (char)(c - 'A' + 'a');
        if(c == lower[ptr]) {
            s[ptr++] = '_';
            success++; sum++;
        }
        else {
            sum++;
            if(--t < 0) {
                hp--;
                break;
            }
        }
    }
    if(hp == 0) return make_pair(-1, -1);
    else return make_pair(success, sum);
}

int main() {
    int N, H; cin >> N >> H;
    vector<string> S(N); vector<int> T(N);
    for(int i=0; i<N; i++) {
        cin >> S[i] >> T[i];
    }
    
    int success = 0, sum = 0;
    for(int i=0; i<N; i++) {
        auto res = proceed(S[i], T[i], H);
        if(res.first < 0) {
            printf("! Game Over\n");
            fflush(stdout);
            return 0;
        }
        success += res.first, sum += res.second;
    }

    int r = success * 1000 / sum;
    string rate = "";
    for(int i=0; i<4 and (i<=1 or r>0); i++) {
        rate += (char)('0' + r%10);
        r /= 10;
        if(i == 0) rate += ".";
    }
    reverse(rate.begin(), rate.end());
    printf("! Game Clear %s\n", rate.c_str());
    return 0;
}



Measured memory_bytes: 3356
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }

    map<int, int> m;

    rep(i, n) {
        if (m[a[i]] == 0) {
            m[a[i]] = 1;
        } else {
            m[a[i]] += 1;
        }
    }

    int even = 0, odd = 0;
    int ans;

    for (auto iter = m.begin(); iter != m.end(); iter++) {
        if (iter->second % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }

    ans = even + odd - even % 2;
    cout << ans << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 5376
N, X, Y = map(int, input().split())

ans = [0] * N

for i in range(1,N):
    for j in reversed(range(N+1)):
        if i >= j:
            break

        tmp = min(j-i,abs(X-i)+1+abs(Y-j))
        ans[tmp] += 1

for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 3444
var
	N,M,i,u,v,id:Longint;
	Gv,Gp:Array[1..2000]of Longint;
	Gi:Array[1..1000]of Longint;
	cnt:Array[1..1000]of Longint;
	Q:Array[1..1000]of Longint;
	Qs:Longint;
begin
	read(N,M);
	for i:=1 to M do begin
		read(u,v);
		Gv[i]:=v;
		if Gi[u]>0 then begin
			Gp[i]:=Gi[u];
		end;
		Gi[u]:=i;
		inc(cnt[v]);
	end;
	for i:=1 to N do begin
		if cnt[i]=0 then begin
			inc(Qs);
			Q[Qs]:=i;
		end;
	end;
	id:=1;
	while id<=Qs do begin
		u:=Q[id];
		inc(id);
		i:=Gi[u];
		while i<>0 do begin
			dec(cnt[Gv[i]]);
			if cnt[Gv[i]]=0 then begin
				inc(Qs);
				Q[Qs]:=Gv[i];
			end;
			i:=Gp[i];
		end;
	end;
	if Qs<N then writeln(0)else writeln(-1);
end.

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int N;
main(){
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    int n;
    scanf("%d",&n);
    int nd;
    int res1=0,res2=0;
    scanf("%d",&nd);
    for(int j=1;j<n;j++){
      int d;
      scanf("%d",&d);
      if(d>nd){
	res1 = max(res1,d-nd);
      }else{
	res2 = max(res2,nd-d);
      }
      nd = d;
    }
    printf("%d %d\n",res1,res2);
  }
}

Measured memory_bytes: 1188
N = int(input())
a = list(map(int, input().split()))
result = [0] * 8
overColor = 0
count = 0
Max = 0
for i in a:
    if(1 <= i <= 399):
        result[0] += 1
    elif(400 <= i <= 799):
        result[1] += 1
    elif(800 <= i <= 1199):
        result[2] += 1
    elif(1200 <= i <= 1599):
        result[3] += 1
    elif(1600 <= i <= 1999):
        result[4] += 1
    elif(2000 <= i <= 2399):
        result[5] += 1
    elif(2400 <= i <= 2799):
        result[6] += 1
    elif(2800 <= i <= 3199):
        result[7] += 1
    else:
        overColor += 1

for i in result:
    if i != 0:
        count += 1

Max = count + overColor
#全部3200以上だった場合Minは1色にまとまり，MaxはoverColor
if count == 0:
    count = 1
    Max = overColor

print(count, Max)

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

int main() {

 int a;
 int b;
 cin >> a;
 cin >> b;
  
 int i = a * b;
  
  if(i % 2 == 0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define all(v) begin(v),end(v)
#define allr(v) v.rbegin(),v.rend()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define cases int t; cin >> t; while(t--)
#define fast_cin() ios_base::sync_with_stdio(0) 

const int mod = 1e9+7;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main()
{
	fast_cin();
	int N,K;
	cin >> N >> K;		
	int A[N+1];
	for(int i=1;i<=N;i++)
		cin >> A[i];
	int g = A[1];
	for(int i=1;i<=N;i++)
	{
		g = __gcd(A[i], g);
	}
	if(K%g == 0 and K <= *max_element(A+1, A+N+1))
	{
		cout << "POSSIBLE\n";
	}
	else
		cout << "IMPOSSIBLE\n";
	return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int d, n;
  cin >> d >> n;
  if(d == 0 && n == 100) cout << 101 << endl;
  else if(d == 1 && n == 100) cout << 10100 << endl;
  else if(d == 2 && n == 100) cout << 1010000 << endl;
  else cout << to_string(n) + string(2*d, '0') << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

int N;

void solve()
{
	cout << (N+1)/2 << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	solve();
	return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
S = ["#"*(W+2)]
for i in range(H):
    s = input()
    S.append("#"+s+"#")
S.append("#"*(W+2))

white = 0
for i in range(H+2):
    for j in range(W+2):
        if S[i][j] == ".":
            white += 1
flag = 0 
visited = {}
import heapq
#[cost i j]
heap = []
heapq.heappush(heap, [0,1,1])
while heap != []:
    cost, i, j = heapq.heappop(heap)
    #print(cost,i,j)
    visited[(i,j)] = cost
    if i == H and j == W:
        flag = 1
        break
    else:
        for k in range(2):
            d = 2*k - 1
            if S[i+d][j] == ".":
                if (i+d,j) in visited:
                    if visited[(i+d,j)] > cost + 1:
                        visited[(i+d,j)] = cost + 1
                        heapq.heappush(heap, [cost+1,i+d,j])
                else:
                    visited[(i+d,j)] = cost + 1
                    heapq.heappush(heap, [cost+1,i+d,j])
            if S[i][j+d] == ".":
                if (i,j+d) in visited:
                    if visited[(i,j+d)] > cost + 1:
                        visited[(i,j+d)] = cost + 1
                        heapq.heappush(heap, [cost+1,i,j+d])
                else:
                    visited[(i,j+d)] = cost + 1
                    heapq.heappush(heap, [cost+1,i,j+d])

#print(white)
#print(visited)
if flag == 1:
    print(white - cost - 1)
else:
    print(-1)

Measured memory_bytes: 47832
lst = list(input())
cnt = 0
len_lst = []
for i in lst:
    if i == 'A' or\
       i == 'T' or\
       i == 'C' or\
       i == 'G':
        cnt += 1
        len_lst.append(cnt)
    else:
        len_lst.append(cnt)
        cnt = 0
print(max(len_lst))


Measured memory_bytes: 2940
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b;
  int k=0;
  int s=0;
  int i;
  int ke[999]={0};
  while(cin>>a>>b){
  s=a+b;
  while(s>=10){
    s=s/10;
    ke[k]++;
  }
  k++;
}
  for(i=0;i<k;i++){
  cout<<ke[i]+1<<endl;
}
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void)
{
        int n,i;
        long h,s;

        scanf("%ld%d",&h,&n);

        int a[n];

        for(i=0;i<n;i++)
                scanf("%d",&a[i]);

        s=h;

        for(i=0;i<n;i++){
                s=s-a[i];
                if(s<=0) {
                        printf("Yes");
                        return 0;
                }
        }

        printf("No");
        return 0;
}


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

using namespace std;

int gcd(int a, int b);

int main(){
    int N;
    cin >> N;
    
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    if(N == 2){
        cout << max(A[0], A[1]) << endl;
        return 0;
    }
    
    vector<int> L(N + 1, 0);
    vector<int> R(N + 1, 0);
    
    for(int i = 0; i < N; i++){
        L[i] = gcd(L[i - 1], A[i]);
        // cout << L[i] << " ";
    }
    // cout << endl;
    for(int i = N - 1; i >= 0; i--){
        R[i] = gcd(R[i + 1], A[i]);
        // cout << R[i] << " ";
    }
    // cout << endl;
    
    vector<int> cd(N);
    cd[0] = R[1];
    cd[N - 1] = L[N - 2];
    for(int i = 1; i < N - 1; i++){
        cd[i] = gcd(L[i - 1], R[i + 1]);
    }
    // for(int i = 0; i < N; i++){
    //     cout << cd[i] << " ";
    // }
    // cout << endl;
    
    cout << *max_element(cd.begin(), cd.end()) << endl;
}

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

Measured memory_bytes: 1792
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>

using namespace std;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORR(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
//#define int long long
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair

#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1e9 + 7;

const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;

using namespace std;

int main(void)
{
    int N, W;
    cin >> N >> W;
    vector<long long> weights(N);
    vector<long long> values(N);

    for (int i = 0; i < N; i++)
    {
        cin >> weights[i] >> values[i];
    }

    //vector<vector<long long>> dp(N + 1, vector<long long >(W + 1, 0));
    
    vector<long long> dp(W + 1, 0);
    /*for (int i = 1; i <= N; i++)
    {
        for (long long w = 0; w <= W; w++)
        {
            if (i == 0 || w == 0)
            {
                dp[i][w] = 0;
            }
            else if (w - weights[i - 1] < 0)
            {
                dp[i][w] = dp[i - 1][w];
            }
            else
            {
                dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - weights[i - 1]] + values[i - 1]);
            }
        }
    }*/


    for (int item = 0; item < N; item++)
    {
        for (long long w = W; w >= 0; w--)
        {
            if (w - weights[item] >= 0)
                dp[w] = max(dp[w], dp[w - weights[item]] + values[item]);
        }
    }

    cout << dp[W] << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> a(3*n);
    for(int i=0;i<3*n;i++) cin>>a[i];
    sort(a.rbegin(),a.rend());
    long long ans=0;
    for(int i=1;i<n*2;i+=2){
        ans+=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
    int n, minR, maxD;
    int tmp;
    cin >> n;

    cin >> tmp;
    minR = tmp;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    else {
        cin >> tmp;
        maxD = tmp - minR;
        if (tmp < minR) {
            minR = tmp;
        }
    }

    for (int i = 2; i < n; ++i) {
        cin >> tmp;
        if (tmp < minR) {
            minR = tmp;
        } else if (maxD < (tmp - minR)) {
            maxD = tmp - minR;
        }
    }

    cout << maxD << endl;
}



Measured memory_bytes: 3108
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
s=[]
for i in range(n):
    s.append(0)
    for j in range(m):
        s[i] += a[i][j]*b[j]
    s[i] += c

ans=0
for i in range(n):
    if s[i] > 0:
        ans += 1
print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> count(5,0);
  for (int i=0;i<N;i++){
    string S;
    cin >> S;
    char x=S[0];
    if (x=='M'){
      count[0]++;
    }
    if (x=='A'){
      count[1]++;
    }
    if (x=='R'){
      count[2]++;
    }
    if (x=='C'){
      count[3]++;
    }
    if (x=='H'){
      count[4]++;
    }
  }
  long long ans=0;
  for (int i=0;i<3;i++){
    for (int j=i+1;j<4;j++){
      for (int k=j+1;k<5;k++){
        ans+=(long long)count[i]*count[j]*count[k];
      }
    }
  }
  cout << ans << endl;
}

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

int main()
{
  int A, B;
  string op;
  cin >> A >> op >> B;
  
  if ("+" == op)
  {
    cout << A + B << endl;
  }
  else
  {
    cout << A - B << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def solve():
    A, B = list(map(int, input().split()))
    if A < B:
        A, B = B, A
    if (A - B) % 2 != 0:
        return 'IMPOSSIBLE'
    return (A - B) // 2 + B


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int A, B;

void input() { cin >> A >> B; }
int ms[100][100] = {};
void solve() {
  rep(i, 0, 99) {
    rep(j, 0, 99) {
      if (i <= 49) {
        ms[i][j] = 0;
      } else {
        ms[i][j] = 1;
      }
    }
  }

  int cnta = 1;
  int cntb = 1;
  for (int i = 1; i < 49; i += 2) {
    for (int j = 1; j < 99; j += 2) {
      if (cnta < A) {
        ms[i][j] = 1;
        cnta++;
      }
    }
  }
  for (int i = 51; i < 99; i += 2) {
    for (int j = 1; j < 99; j += 2) {
      if (cntb < B) {
        ms[i][j] = 0;
        cntb++;
      }
    }
  }

  cout << "100 100" << endl;
  rep(i, 0, 99) {
    rep(j, 0, 99) { cout << (ms[i][j] == 0 ? "#" : "."); }
    cout << endl;
  }
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    // i: water, j: sugar
    int total=0;
    int sugar=0;
    float mx = 0;
    for(int i=100; i<=F; i=i+100){
        bool fl = false;
        for(int k=0; A*k<=i/100; k++){
            if((i/100-A*k)%B == 0) fl = true;
        }
        if(!fl) continue;

        for(int j=0; j<=F-i; j++){
            if((float)j/i > (float)E/100) continue;
            fl = false;
            for(int k=0; C*k<=j; k++){
                if((j-C*k)%D == 0) fl = true;
            }
            if(!fl) continue;

            float strong = (float)j/(i+j);
            if(strong >= mx){
                mx = strong;
                total = i + j;
                sugar = j;
            }
        }
    }

    cout << total << " " << sugar << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll inf = 1e9+7;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> color(9);
  rep(i, n){
    if     (a[i] >= 1 && a[i] <= 399)     ++color[0];
    else if(a[i] >= 400 && a[i] <= 799)   ++color[1];
    else if(a[i] >= 800 && a[i] <= 1199)  ++color[2];
    else if(a[i] >= 1200 && a[i] <= 1599) ++color[3];
    else if(a[i] >= 1600 && a[i] <= 1999) ++color[4];
    else if(a[i] >= 2000 && a[i] <= 2399) ++color[5];
    else if(a[i] >= 2400 && a[i] <= 2799) ++color[6];
    else if(a[i] >= 2800 && a[i] <= 3199) ++color[7];
    else                                  ++color[8];
  }
  int ans = 0;
  rep(i, 8) if(color[i]) ++ans;
  
  if(ans) cout << ans << " " << ans+color[8] << "\n";
  else cout << ans+1 << " " << ans+color[8] << "\n";
  return 0;
}   

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

int main(){
    int t;cin >> t;
    
    rep(test,t){
        int n; cin >> n;
        vector<ll> a(n);
        rep(i,n)cin >> a[i];
        string s; cin >> s;
        
        vector<ll> dp;//遷移は基底が増えるだけ
        for(int i=n-1; i>=0; i--){
            for(ll b: dp)a[i] = min(a[i], a[i]^b);
            //minを取れば掃き出しが可能
            if(s[i]=='0'){
                dp.push_back(a[i]);//0は何個あってもいい
            }else if(a[i]!=0){
                //1のターンで新しい基底を取れたなら終了
                dp.clear();
                break;
            }
        }
        if(dp.empty())
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3540