akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define TRUE 1
#define FALSE 0
#define MAX 100005

typedef struct{
  char name[100];
  int time;
}P;


int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

int head=0,tail=0,n;
P Q[MAX+1];

int main()
{
  int elaps = 0,c;
  int i,q;
  P u;

  scanf("%d %d",&n,&q);

  for(i = 0 ; i < n ; i++ )
    {
      scanf("%s",u.name);
      scanf("%d",&u.time);
      if(u.time < 1 || u.time > 50000 || strlen(u.name) < 1 || strlen(u.name) > 10) return 0;
      
      enqueue(u);
    }

  
  while(n > 0)
    {
      u = dequeue();

      c = u.time - q;

      if(c <= 0)
	{
	  elaps += u.time;
	  n--;
	  printf("%s %d\n",u.name,elaps);
	}
      else
	{
	  u.time -= q;
	  elaps += q;
	  enqueue(u);
	}
    }

  

  return 0;
}

int isEmpty()
{
  if(head == tail) return TRUE;
  else return FALSE;
}

int isFull()
{
  if(head == (tail + 1) % MAX) return TRUE;
  else return FALSE;
}

void enqueue(P x)
{
  if(isFull()) exit(1);

  Q[tail] = x;

  if(tail + 1 == MAX) tail = 0;
  else tail++;
}

P dequeue()
{
  P x;
  if(isEmpty()) exit(2);

  x = Q[head];

  if(head + 1 == MAX) head = 0;
  else head++;

  return x;
}



Measured memory_bytes: 11868
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int N, Q;
    string S;
    cin >> N >> S >> Q;

    vector<set<int>> A(26);
    for (int i = 0; i < N; i++) {
        A[S[i] - 'a'].insert(i);
    }

    while (Q--) {
        int op;
        cin >> op;

        if (op == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;

            for (auto&& a : A) {
                a.erase(i);
            }
            A[c - 'a'].insert(i);

        } else {
            int l, r;
            cin >> l >> r;
            l--, r--;

            int res = 0;
            for (auto&& a : A) {
                if (a.lower_bound(l) != a.upper_bound(r)) {
                    res++;
                }
            }

            cout << res << '\n';
        }
    }
}

Measured memory_bytes: 26244
#include <stdio.h>
#include <stdlib.h>
int main() {
  int A, B ,C;
  scanf("%d %d", &A, &B);
  if(A > B){
      C = A;
  }else{
      C = B;
  }
  for(int i = 0; i < C; i++){
      if(abs(A - i) == abs(B - i)){
          printf("%d", i);
          return 0;
      }
  }
    printf("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
const int maxn = 2e5 + 500;
int main(int argc, char const *argv[])
{
	ll n;
	scanf("%lld",&n);
	vector<ll> a,b;
	for(ll i = 2;i * i <= n; ++i)
	{
		if(n % i == 0)
		{
			a.push_back(i);
			if(n != i * i)
			{
				a.push_back(n / i);
			}
		}
	}
	a.push_back(n);
	ll m = n;
	--n;
	for(ll i = 2;i * i <= n; ++i)
	{
		if(n % i == 0)
		{
			b.push_back(i);
			if(n != i * i)
			{
				b.push_back(n / i);
			}
		}
	}
	b.push_back(n);
	n = m;
	ll cnt = 0;
	for(int i = 0;i < b.size(); ++i)
	{
		if(n % b[i] != 0)
		{
			++cnt;
		}
	}
	for(int i = 0;i < a.size(); ++i)
	{
		ll tmp = n;
		while(tmp % a[i] == 0)
		{
			tmp /= a[i];
		}
		if(tmp % a[i] == 1)
		{
			++cnt;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#define UnL unsigned long long
using namespace std;
UnL a[101],n;
UnL gcd(UnL a,UnL b){
	UnL c=1,r;
	while(a&&b){
		while(a&1^1&&b&1^1) a>>=1,b>>=1,c<<=1;
		while(a&1^1) a>>=1;
		while(b&1^1) b>>=1;
		if(a<b) swap(a,b);
		r=a;a=b;b=r-b;
	}
	return c*(a+b);
}
UnL Lcm(UnL a,UnL b){
	return a/gcd(a,b)*b;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	UnL ans=a[0];
 	for(int i=1;i<n;i++)
		ans=Lcm(ans,a[i]);
	cout<<ans;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



char c;
void solve(){
	int a = 0;
	for(int i = 0; i < 4; i++){
		cin >> c;
		if(c == '+') a++;
		else a--;
	}
	
	cout << a << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int n,m;
#define maxn 311
int a[maxn][maxn];
int tmp[maxn],cnt[maxn];
int que[maxn],tail;
bool no[maxn];
bool judge(int x)
{
	memset(tmp,0,sizeof(tmp));
	memset(cnt,0,sizeof(cnt));
	memset(no,0,sizeof(no));
	tail=0;
	for (int i=1;i<=n;i++)
		que[++tail]=i;
	while (tail)
	{
		for (int i=1;i<=tail;i++)
		{
			const int now=que[i];
			while (tmp[now]<=m && no[a[now][tmp[now]]]) tmp[now]++;
			if (tmp[now]>m) return 0;
			cnt[a[now][tmp[now]]]++;
			if (cnt[a[now][tmp[now]]]>x) no[a[now][tmp[now]]]=1;
		}
		tail=0;
		for (int i=1;i<=n;i++)
			if (no[a[i][tmp[i]]])
			{
				cnt[a[i][tmp[i]]]--;
				que[++tail]=i;
			}
	}
	return 1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	int L=1,R=n;
	while (L<R)
	{
		int mid=(L+R)>>1;
		if (judge(mid)) R=mid;
		else L=mid+1;
	}
	printf("%d\n",L);
	return 0;
}

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

int main(){
	int lx,ly,rx,ry;
	int w,h,n;
	cin >> w >> h >> n;
	lx=0; ly=0;
	rx = w; ry = h;
	rep(i,n){
		int a,b,c;
		cin >> a >> b >> c;
		if(c==1) lx = max(lx,a);
		if(c==2) rx = min(rx,a);
		if(c==3) ly = max(ly,b);
		if(c==4) ry = min(ry,b);
	}
	if((rx-lx)<=0||(ry-ly)<=0){
		cout << 0 << endl;
		return 0;
	}
	cout << max(0,(rx-lx)*(ry-ly)) << endl;
	return 0;
}


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

int N, K, A[109];

bool dp[100009];

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

    for(int i = 0; i <= K; i++)
        for(int j = 1; j <= N; j++)
            if(i >= A[j]) dp[i] |= !dp[i - A[j]];

    cout << (dp[K] ? "First" : "Second") << endl;

    return 0;
}

Measured memory_bytes: 384
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
# ans = [[0]*w for _ in range(h)]

import copy

dir = [(i, j) for i in range(-1, 2) for j in range(-1, 2)]
ans = copy.deepcopy(s)
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            cnt = 0
            for y, x in dir:
                iy, jx = i+y, j+x
                if 0 <= iy < h and 0 <= jx < w:
                    if s[iy][jx] == '#':
                        cnt += 1
            ans[i][j] = cnt




for i in range(h):
    moji = map(str,ans[i])
    print("".join(moji))

Measured memory_bytes: 9412
using System;

namespace abc165_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            string[] abArray = Console.ReadLine().Split(" ");
            int a = int.Parse(abArray[0]);
            int b = int.Parse(abArray[1]);

            for(int i = a; i <= b; i++)
            {
                int kamari = i % k;
                if (kamari == 0)
                {
                    Console.WriteLine("OK");
                    return;
                }
            }
            Console.WriteLine("NG");
            return;

        }
    }
}


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


int main()
{
	int mod = 1e9 + 7;
	int n; cin >> n;
	vector<int> A(n);
	vector<ll> B(n+1, 0);
	for (int i = 0; i < n; ++i)
	{
		cin >> A[i];
		B[i+1] = B[i] + A[i];
	}
	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ll sum = (B[n] - B[i+1]) % mod;
		ans += A[i] * sum;
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 5604
#include<iostream>
#include<vector>
using namespace std;
vector<int>G[1<<17];
int n,K,a[1<<17];
int cnt;
int dfs(int u,int p)
{
	int d=0;
	for(int i=0;i<G[u].size();i++)
	{
		d=max(d,dfs(G[u][i],u));
	}
	if(d==K-1&&p!=0)cnt++,d=-1;
	return d+1;
}
main()
{
	cin>>n>>K;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]--;
		if(i)G[a[i]].push_back(i);
	}
	dfs(0,0);
	cout<<cnt+!!a[0]<<endl;
}

Measured memory_bytes: 13056
N,C,K=map(int,input().split())
T=[]

for i in range(N):
    T.append(int(input()))

T.sort()
ans=1
mem=1
s=T[0]

for i in range(N):
    if T[i]>s+K or mem>=C:
        ans+=1
        s=T[i]
        mem=1
    else:
        mem+=1
print(min(ans,N))

Measured memory_bytes: 7384
#include<iostream>
using namespace std;
void moveE(int dice[6])
{
	int tmp = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = tmp;
}
void moveN(int dice[6])
{
	int tmp = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = dice[4];
	dice[4] = tmp;
}
void moveS(int dice[6])
{
	int tmp = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = tmp;
}
void moveW(int dice[6])
{
	int tmp = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = dice[3];
	dice[3] = tmp;
}
int main()
{
	int dice[6] = { 0 };
	cin >> dice[0] >> dice[1] >> dice[2] >> dice[3] >> dice[4] >> dice[5];
	int q;
	cin >> q;
	for(int i = 0;i < q;i++)
	{
		int top, front;
		cin >> top >> front;
		for(int j = 0;j < 6;j++)
		{
			if(dice[j] == top)
			{
				switch(j)
				{
				case 1:
					moveN(dice);
					break;
				case 2:
					moveE(dice);
					break;
				case 3:
					moveW(dice);
					break;
				case 4:
					moveN(dice);
					break;
				case 5:
					moveN(dice);
					moveN(dice);
					break;
				}
			}
		}
		for(int j = 0;j < 6;j++)
		{
			if(dice[j] == front)
			{
				switch (j)
				{
				case 1:
					cout << dice[2] << endl;
					break;
				case 2:
					cout << dice[4] << endl;
					break;
				case 3:
					cout << dice[1] << endl;
					break;
				case 4:
					cout << dice[3] << endl;
					break;
				}
			}
		}
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

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

	int a, b;
	cin >> a >> b;

	cout << max(a - 2 * b, 0) << endl;

}


Measured memory_bytes: 256
B = (1 << 10).times.map{|v| 10.times.count{|i| v[i] > 0 }}

N = gets.to_i
F = N.times.map{ gets.chomp.tr(' ','').to_i(2) }
P = N.times.map{ gets.split.map(&:to_i) }

revenue = lambda do |state|
  N.times.inject(0) do |s, i|
    s + P[i][B[F[i] & state]]
  end
end

puts (1 ... 1 << 10).map(&revenue).max


Measured memory_bytes: 2044
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
int main() {
    int n; cin >> n;
    int f[n][10]; rep(i, n) rep(j, 10) cin >> f[i][j];
    int p[n][11]; rep(i, n) rep(j, 11) cin >> p[i][j];
    int mmax = -1e9;
    rep(i, (1 << 10)) {
        if (i == 0) continue;
        int check[n];
        rep(j, n) check[j] = 0;
        rep(j, 10) if (i & (1 << j)) {
            rep(k, n) if (f[k][j] == 1) check[k]++;
        }
        int tmp = 0;
        rep(j, n) tmp += p[j][check[j]];
        mmax = max(mmax, tmp);
    }
    cout << mmax << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
		int n = Integer.parseInt(br.readLine());
		int a = Integer.parseInt(br.readLine());
		
		System.out.println(n*n - a);
	}

}


Measured memory_bytes: 22996
n = int(input())
a = [int(i) for i in input().split()]

b = a[n::-2]+a[::2] if n%2 == 0 else a[n::-2]+a[1::2]
for i in range(n):
    if i < n-1:
        print(b[i],end=" ")
    else:
        print(b[i])

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

#define ll long long
#define MAX 100100

const ll INF = 1LL << 60;

int N, K;
ll h[MAX];
ll dp[MAX];

int main() {
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        cin >> h[i];
    }

    for(int i = 0; i < MAX; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 1; j <= K; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    printf("%lld\n", dp[N - 1]);
}

Measured memory_bytes: 1792
import sys
readline = sys.stdin.readline

N, X = map(int,readline().split())

T = [0] * (N + 1) # レベルiバーガーの厚さ
P = [0] * (N + 1) # レベルiバーガーのパティの数

T[0] = 1
P[0] = 1

for i in range(1, N + 1):
  T[i] = T[i - 1] * 2 + 3
  P[i] = P[i - 1] * 2 + 1

# Nバーガー,X枚目
stack = [[N,X]]
ans = 0

while stack:
  n, x = stack.pop()
  if x <= 0:
    continue
  if x >= T[n]:
    ans += P[n]
    continue
  if n == 0:
    ans += P[n]
    continue
  stack.append([n - 1,x - 1])
  ans += (x >= T[n - 1] + 2) * 1
  stack.append([n - 1, x - (T[n - 1] + 2)])

print(ans)


Measured memory_bytes: 3188
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<algorithm>
typedef signed long long int int64;
inline unsigned getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register unsigned x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
const int64 inf=0x7ffffffffffffff;
const int N=200001;
int n;
class FenwickTree {
	private:
		int64 val[N];
		int lowbit(const int &x) const {
			return x&-x;
		}
	public:
		FenwickTree() {
			std::fill(&val[0],&val[N],inf);
		}
		void modify(int p,const int64 &x) {
			while(p<=n) {
				val[p]=std::min(val[p],x);
				p+=lowbit(p);
			}
		}
		int64 query(int p) const {
			int64 ret=inf;
			while(p) {
				ret=std::min(ret,val[p]);
				p-=lowbit(p);
			}
			return ret;
		}
};
FenwickTree ta;
class RevFenwickTree {
	private:
		int64 val[N];
		int lowbit(const int &x) const {
			return x&-x;
		}
	public:
		RevFenwickTree() {
			std::fill(&val[0],&val[N],inf);
		}
		void modify(int p,const int64 &x) {
			while(p) {
				val[p]=std::min(val[p],x);
				p-=lowbit(p);
			}
		}
		int64 query(int p) const {
			int64 ret=inf;
			while(p<=n) {
				ret=std::min(ret,val[p]);
				p+=lowbit(p);
			}
			return ret;
		}
};
RevFenwickTree tb;
int64 f[N];
inline void modify(const int &p,const int64 x) {
	if(x<f[p]) {
		f[p]=x;
		ta.modify(p,x-p);
		tb.modify(p,x+p);
	}
}
int main() {
	n=getint();
	int q=getint(),a=getint(),b=getint();
	std::fill(&f[0],&f[N],inf);
	modify(a,0);
	int64 sum=0;
	while(q--) {
		a=b;
		b=getint();
		sum+=abs(a-b);
		int64 t1=ta.query(b)+b,t2=tb.query(b)-b;
		modify(a,std::min(t1,t2)-abs(a-b));
	}
	int64 tmp=inf;
	for(register int i=1;i<=n;i++) {
		tmp=std::min(tmp,f[i]);
	}
	printf("%lld\n",tmp+sum);
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e5;
int x, y, a, b, c;
V<P<int, int>> v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> x >> y >> a >> b >> c;
  FOR(_, 0, a){
    int d;
    cin >> d;
    v.pb(mp(d, 0));
  }
  FOR(_, 0, b){
    int d;
    cin >> d;
    v.pb(mp(d, 1));
  }
  FOR(_, 0, c){
    int d;
    cin >> d;
    v.pb(mp(d, 2));
  }
  sort(all(v), greater<P<int, int>>());
  ll ans=0;
  int ca=0, cb=0, cc=0;
  for(auto p:v){
    if(ca+cb+cc == x+y) break;
    switch(p.se){
      case 0:
        if(ca==x) break;
        ca++;
        ans += p.fi;
        break;
      case 1:
        if(cb==y) break;
        cb++;
        ans += p.fi;
        break;
      case 2:
        cc++;
        ans += p.fi;
        break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6128
using System;
using System.Linq;

namespace _0258
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                n++;
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int i = 0; i < n; i++)
                {
                    int[] now = new int[n - 1];
                    for (int j = 0; j < i; j++)
                    {
                        now[j] = x[j];
                    }
                    for (int j = i + 1; j < n; j++)
                    {
                        now[j - 1] = x[j];
                    }
                    int sa = now[1] - now[0];
                    bool ret = true;
                    for (int j = 1; j < n - 2; j++)
                    {
                        if (now[j + 1] - now[j] != sa)
                        {
                            ret = false;
                        }
                    }
                    if (ret)
                    {
                        Console.WriteLine(x[i]);
                        break;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 9836
#include <iostream>

using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    int A[1000];
    for (int i=0; i<N; i++) cin >> A[i];

    int allvote = 0;
    for (int i=0; i<N; i++) allvote += A[i];

    int threshold = allvote / (4 * M);
    if (allvote % (4 * M) == 0) threshold -= 1;

    int ans = 0;
    for (int i=0; i<N; i++) {
       if (A[i] > threshold) ans++;
    }

    if (ans >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int par[200020];
int co[200020] = { 0 };
int root(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = root(par[x]);
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		int x = root(a);
		int y = root(b);
		if (x != y) {
			par[x] = y;
		}
	}
	for (int i = 1; i <= n; i++) {
		co[root(i)]++;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (ans < co[i]) {
			ans = co[i];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 10652
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin >> s;
  string h = "2019/04/30";
  if (s > h) {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    public class Person
    {
        public string firstName;
        public string lastName;
        public void Introduce()
        {
            Console.WriteLine("My name is " + firstName + " " + lastName);
        }
        public Person(string a = "HAHAa", string b =  "VCCAVA")
        {
            this.firstName = a;
            this.lastName = b;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int N, K;
            var a = Console.ReadLine().Split(' ');
            Int32.TryParse(a[0], out N);
            Int32.TryParse(a[1], out K);
            //Console.WriteLine("N : {0}, K: {1}", N, K);
            if (K == 10)
            {
                Console.WriteLine(a[0].Length);
            }
            else
            {
                int cnt = 0;
                while (N >= 1)
                {
                    N /= K;
                    cnt++;
                }
                Console.WriteLine(cnt);
            }
        }
    }
}


Measured memory_bytes: 11092
from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1 for _ in range(n)]
 
    def same(self, x, y):
        return self.root(x)==self.root(y)
 
    def root(self, x):
        if self.par[x]<0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
 
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
 
        if self.par[x] > self.par[y]:
            x, y = y, x
 
        self.par[x] += self.par[y]
        self.par[y] = x
        
N, K, L = map(int, input().split())

uf = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf.unite(p - 1, q - 1)
    
uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.unite(r - 1, s - 1)

d = defaultdict(int)
for i in range(N):
    n = uf.root(i)
    m = uf2.root(i)
    d[(n, m)] += 1

ans = []
for i in range(N):
    n = uf.root(i)
    m = uf2.root(i)
    ans.append(d[(n, m)])

print(* ans)

Measured memory_bytes: 41716
// ABC175-B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


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

    string s;
    cin>>s;
    int total=0;
    rep(i,s.size()){
        total+=(s[i]-'0');
    }
    if(total%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3744
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int h;

void del(vector<vector<int>> &v){
    rep(i,h){
        rep(j,5){
            
            int base = v[i][j];
            if(base==0)continue;
            int num = 0;
            rep(k,5){
                if(j+k>5)break;
                if(base==v[i][j+k])num++;
                else break;
            }
            if(num<3)continue;
            rep(k,5){
                if(j+k>5)break;
                if(base==v[i][j+k]){
                    v[i][j+k]=0;
                }else break;
            }
            
        }
    }
}

bool fall(vector<vector<int>> &v){
    bool ret = false;
    for(int i=h-2;i>=0;i--){
        rep(j,5){
            if(v[i+1][j]==0 && v[i][j]!=0){
                ret|=true;
                swap(v[i+1][j],v[i][j]);
            }
        }
    }
    return ret;
}


int main(){
    while(cin>>h&&h){
        int sum = 0;
        vector<vector<int>> fie(h,vector<int>(5));
        rep(i,h){
            rep(j,5){
                cin>>fie[i][j];
                sum+=fie[i][j];
            }
        }
        
        while(1){
            del(fie);
            
            bool res = false;
            rep(i,h)res |= fall(fie);
            if(res==false)break;
        }
        int t = 0;
        rep(i,h){
            rep(j,5){
                t+=fie[i][j];
            }
        }
    
        cout<<sum-t<<endl;
    }
}

Measured memory_bytes: 3124
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		
		if((x + r <= W) && (y + r <= H) && (x - r >= 0) && (y - r >= 0)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

int n;

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    int y_odd = 0;
    bool flag = false;
    if(n < 0) flag = true, n = -n;
    for(int i = 0; i < 35; ++i) {
        if((i & 1LL) && !flag) {
            if((1LL << i) & n) {
                y_odd |= (1LL << i);
                n += (1LL << i);
            }
        } else if(!(i & 1LL) && flag) {
            if((1LL << i) & n) {
                y_odd |= (1LL << i);
                n += (1LL << i);
            }
        }
    }
    int ans = n | y_odd;
    auto hp = [](int j)->int {
        int ret = 1;
        for(int msk = 1; msk <= (1LL << 50); msk <<= 1) {
            if(msk & j) ret = msk;
        }
        return ret;
    };
    for(int i = hp(ans); i >= 1LL; i >>= 1LL) {
        cout << ((i & ans) ? 1 : 0);
    }
    cout << endl;

}

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

using namespace std;

#define first ff
#define second ss

int main() {
#ifdef LOCAL
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#else
    // freopen("levenshtein.in", "r", stdin);
    // freopen("levenshtein.out", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;
    int ans = 0;
    while (n != 0) {
        ans++;
        n /= k;
    }
    cout << ans;

    return 0;
}


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

using namespace std;

int main() {
  long n,d;
  cin>>n>>d;
  d=d*d;
  int ans=0;
  long x,y,d1;
  for(int i=0;i<n;i++){
  	cin>>x>>y;
    d1 = x*x + y*y;
    // cout<<d1;
    if(d1<=d)
      ans++;
  }
    cout<<ans;
  return 0;
}


Measured memory_bytes: 3644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.AbstractCollection;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author teiwa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int N = in.nextInt();
            int M = in.nextInt();
            ArrayList<Integer>[] l = new ArrayList[M];
            for (int i = 0; i < M; i++) {
                l[i] = new ArrayList<Integer>();
            }
            for (int i = 0; i < N; i++) {
                int A = in.nextInt();
                int B = in.nextInt();
                if (M - A >= 0) {
                    l[M - A].add(B);
                }
            }
            int ans = 0;
            PriorityQueue<Integer> q = new PriorityQueue<Integer>(Comparator.reverseOrder());
            for (int i = M - 1; i >= 0; i--) {
                for (int b : l[i]) {
                    q.add(b);
                }
                if (!q.isEmpty()) {
                    ans += q.poll();
                }
            }
            out.println(ans);

        }

    }
}



Measured memory_bytes: 100024
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,K = inpl()
K -= 1
S = list(input())

if S[K] == 'A':
    S[K] = 'a'
    print(''.join(S))
elif S[K] == 'B':
    S[K] = 'b'
    print(''.join(S))
elif S[K] == 'C':
    S[K] = 'c'
    print(''.join(S))


Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    ll n,k;
    cin >> n >> k;
    vector<vector<ll>> cost(n);
    vector<ll> p(n),c(n), sum(n,0);
    for(ll i = 0; i < n; i++) cin >> p[i], p[i]--;
    for(ll i = 0; i < n; i++) cin >> c[i];
    
    for(ll i = 0; i < n; i++){
        ll now = i;
        while(true){
            now = p[now];
            cost[i].push_back(c[now]);
            sum[i] += c[now];
            if(now == i) break;
        }
    }

    auto calc = [&](ll i,ll n,bool z){
        ll mx = cost[i][0];
        ll tmp = 0;
        if(z) mx = max(0ll,mx);
        for(ll j = 0; j < n; j++){
            tmp += cost[i][j%cost[i].size()];
            mx = max(mx,tmp);
        }  
        return mx;
    };

    ll ans = -mod*mod;

    for(ll i = 0; i < n; i++){
        ll cs = cost[i].size();
        ll fir = calc(i,min(cs,k),false);
        ans = max(ans,fir);
        if(sum[i] <= 0) continue;
        ll can;
        if(cs <= k && k <= 2*cs){
            can = calc(i,k,false);
        } else {
            can = sum[i]*((k/cs)-1);
            int m = k%cs+cs;
            can += calc(i,m,true);
        }
        ans = max(can,ans);
    }

    cout << ans << endl;


    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    Vl A(N);
    unordered_map<ll, ll> invmp;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        invmp[A[i]] = i;
    }
    sort(A.begin(), A.end());
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
        ll d = abs(i - invmp[A[i]]);
        if (d % 2 == 1) ++cnt;
    }
    cout << cnt / 2 << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

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

    if (N == 1) {
        cout << 0 << endl;
        return 0;        
    }

    vector<vector<pair<int, ll>>> edges(N + 1);
    for (int i = 0; i < N - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        edges[u].push_back({v, w});
        edges[v].push_back({u, w});
    }
    vector<int> ans(N + 1, -1);
    int start;
    for (int i = 1; i <= N; ++i) {
        if (edges[i].size() == 1) {
            start = i;
            break;
        }
    }
    queue<int> que;
    que.push(start);
    ans[start] = 0;
    while (que.size()) {
        int u = que.front();
        que.pop();        
        int c = ans[u];
        for (int i = 0; i < (int)edges[u].size(); ++i) {
            int v = edges[u][i].first;
            int w = edges[u][i].second;
            if (ans[v] != -1) {
                continue;
            }
            if (w & 1) {
                ans[v] = 1 - c;
            } else {
                ans[v] = c;
            }
            que.push(v);
        }
    }
    for (int i = 1; i <= N; ++i) {
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8320
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    map<str, int> mp;
    for(int q=0; q<a; q++){
        str t; cin>>t;
        mp[t]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void EducationalDP_F()
{
	string s, t;
	cin >> s;
	cin >> t;
	int N = s.length();
	int M = t.length();
	vvi dp(N + 1, vi(M + 1));
	string str;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			dp[i + 1][j + 1] = max(dp[i][j + 1], max(dp[i + 1][j], dp[i][j] + (s[i] == t[j] ? 1 : 0)));
		}
	}


	int i = s.length();
	int j = t.length();
	while (i > 0 && j > 0)
	{
		if (dp[i][j] == dp[i - 1][j])
		{
			--i;
		}
		else if (dp[i][j] == dp[i][j - 1])
		{
			--j;
		}
		else
		{
			--i;
			--j;
			str = s[i] + str;
		}
	}


	cout << str << endl;
}
int main()
{
	EducationalDP_F();
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;

struct str {
	int a = 0, b = 0;
	string s;
};

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // LOCAL
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	str a[n];

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


	for (int i = 0; i < n; ++i) {
		int x = 0;

		for (int j = 0; j < a[i].s.size(); ++j) {
			if (a[i].s[j] == '(')
				x++;
			else {
				if (x == 0)
					a[i].a++;
				else
					x--;
			}
		}
		a[i].b = x;

		// cout << a[i].a << " " << a[i].b << endl;
	}

	sort(a, a + n, [](str &a, str &b) {
					   return a.a < b.a;
				   });

	int x = 0;
	multiset<pair<int, string>> s;

	int j = 0;
	string ss;
	while (true) {
		while (j < n && a[j].a <= x)
			s.insert({-a[j].a + a[j].b, a[j].s}), j++;

		if (s.empty())
			break;

		x += s.rbegin()->first;
		ss += s.rbegin()->second;
		// cout << x << endl;
		if (x < 0) {
			cout << "No";
			return 0;
		}
		auto it = s.end();
		it--;
		s.erase(it);
	}

	bool f1 = j == n && x == 0;

	for (int i = 0; i < n; ++i) {
		swap(a[i].a, a[i].b);
	}
	sort(a, a + n, [](str &a, str &b) {
					   return a.a < b.a;
				   });

	x = 0;
	s.clear();
	j = 0;
	while (true) {
		while (j < n && a[j].a <= x)
			s.insert({-a[j].a + a[j].b, a[j].s}), j++;

		if (s.empty())
			break;

		x += s.rbegin()->first;
		ss += s.rbegin()->second;
		// cout << x << endl;
		if (x < 0) {
			cout << "No";
			return 0;
		}
		auto it = s.end();
		it--;
		s.erase(it);
	}

	// x = 0;
	// for (int i = 0; i < ss.size(); ++i) {
	// 	if (ss[i] == '(')
	// 		x++;
	// 	else {
	// 		if (x == 0) {
	// 			cout << "No";
	// 			return 0;
	// 		} else {
	// 			x--;
	// 		}
	// 	}
	// }

	// cout << ss;
	if (f1 && j == n && x == 0) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 122032
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll n, a, b;
ll p[100005] = {};
ll ans = 0;

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

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

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int i;
    vector <int> p(n);
    vector <int> q(n);
    for(i = 0;i < n;++i){
        cin >> p.at(i);
    }
    for(i = 0;i < n;++i){
        cin >> q.at(i);
    }
    vector<int> v;
    for(i = 0;i < n;++i){
        v.push_back(i+1);
    }
    int p_n,q_n;
    int ans = 0;
    do{
        bool p_f = true,q_f = true;
        for(i = 0;i < n;++i){
            if(v.at(i) != p.at(i)){
                p_f = false;
            }
            if(v.at(i) != q.at(i)){
                q_f = false;
            }
        }
        if(p_f){
                p_n = ans;
            }
            if(q_f){
                q_n = ans;
            }
        ++ans;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(p_n - q_n) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = 10 ** 18
for z in range(2):
    if z == 0:
        sign = 1
    else:
        sign = -1
    c = 0
    cost = 0
    for x in a:
        c += x
        if c * sign <= 0:
            cost += 1 - c * sign
            c = sign
        sign *= -1
    ans = min(ans, cost)
print(ans)

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


int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto &v:a) cin>>v;
  vector<int> cnt(9,0);
  for(int i=0;i<n;i++){
    for(int j=0;j<9;j++){
      if(j==8){
	cnt[8]++;
      }
      else if(a[i]<(j+1)*400){
	cnt[j]=true;
	break;
      }
    }
  }
  cout<<max(1,accumulate(cnt.begin(),cnt.begin()+8,0))<<" "<<accumulate(cnt.begin(),cnt.begin()+8,0)+cnt[8]<<endl;
  return 0;

}


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

int main()
{
    long double  a, b, c, diff;
    long double ab;
    cin >> a >> b >> c;

    if (c < a + b) {
        cout << "No" << endl;
        return 0;
    }
    
    diff = c - a - b;
    ab = sqrt(a * b);
    // cout << ab << endl;
    if (diff > 2 * ab) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    // if (((diff / 2) * (diff / 2)) > (a * b)) {
    //     cout << "Yes" << endl;
    // } else {
    //     cout << "No" << endl;
    // }

    return 0;
}



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

int main() {
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> A(N);
    rep(i, Q){
        int a; cin >> a;
        a--;
        A[a]++;
    }
    rep(i, N){
        if(K - Q + A[i] > 0){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include <unistd.h>
#include <cstdio>
#include <x86intrin.h>

typedef long long ll;
int mat[3000][3000]; 
ll dp0[3000] __attribute((aligned(32)));

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx2"))), apply_to=function)
int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    for (int y = 0; y < rr; y++) {
        ll work0 = 0, work1 = 0, work2 = 0, work3 = 0;
        for (int x = 0; x < cc; x++) {
            if (dp0[x] > work0) work0 = dp0[x];
            int v = mat[y][x];

            if (work3 < work2 + v) work3 = work2 + v;
            if (work2 < work1 + v) work2 = work1 + v;
            if (work1 < work0 + v) work1 = work0 + v;

            ll worka = work3 > work2 ? work3 : work2;
            ll workb = work1 > work0 ? work1 : work0;
            if (workb > worka) worka = workb;

            dp0[x] = worka;
        }
    }
    std::printf("%lld\n", dp0[cc - 1]);
    return 0;
}
#pragma clang attribute pop

Measured memory_bytes: 39316
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    ll n,m;
    cin>>n>>m;
    if(m/2<=n){
        cout<<(m/2LL)<<endl;
    }
    else{
        ll ans = n;
        m-=2*n;
        ans+=m/4;
        cout<<ans<<endl;
    }

}


Measured memory_bytes: 3596
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] s = S.split("");
        long ans = 0;
        for(int i=0; i<s.length; i++) {
            ans += Integer.parseInt(s[i]);
        }
        S = String.valueOf(ans);
        s = S.split("");
        long count = 0;
        for(int i=0; i<s.length; i++) {
            count += Integer.parseInt(s[i]);
        }
        if(count % 9 == 0) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 65368
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int inplace=0,ans=0;
	for (int i = 0; i < n; ++i)
	{
		int p;
		cin >> p;
		if (p==i+1) ++inplace;
		else {
			ans += (inplace+1)/2;
			inplace = 0;
		}
	}
	ans += (inplace+1)/2;
	cout << ans << endl;
	return 0;
}


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

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int main(){
    string s="CODEFESTIVAL2016";
    string S;
    cin>>S;
    int cnt=0;
    REP(i,SZ(S))if(s[i]!=S[i])cnt++;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	int a, b, c; scanf("%d%d%d", &a, &b, &c);
	int m = min(min(a, b), c);
	int M = max(max(a, b), c);
	printf("%d %d %d\n", m, (a + b + c) - (m + M), M);
}


Measured memory_bytes: 3184
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int min=1000;
    int res;
    for(int i=1;i<N;i++){
        int A=i;
        int B=N-i;
        int sum_A=0;
        int sum_B=0;
        for(int j=0;j<6;j++){
            sum_A+=A%10;
            A=A/10;
            sum_B+=B%10;
            B=B/10;
        }
        if(min>sum_A+sum_B){
            min=sum_A+sum_B;
        }
    }
    cout<<min<<endl;
  return 0;
}

Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


S = input()

ans = 0
g = 0
p = 0
for s in S:
    if g == p:
        g += 1
        if s == "g":
            pass
        elif s == "p":
            ans -= 1
    else:
        p += 1
        if s == "g":
            ans += 1
        elif s == "p":
            pass
print(ans)


Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
int h,w,coun;
int f_x[5]={1,0,-1,0};
int f_y[5]={0,1,0,-1};
char map[105][105]; 
void dfs(int x,int y,char c)
{
	map[x][y]='0';
	for (int i=0;i<4;i++){
		int nextx=x+f_x[i],nexty=y+f_y[i];
		if (nextx>=0&&nextx<h&&nexty>=0&&nexty<w&&map[nextx][nexty]==c){
			dfs(nextx,nexty,c);
		}
	}
}
int main()
{
	int i,j;
	while (~scanf("%d%d",&h,&w),h+w)
	{
		coun=0;
		for (i=0;i<h;i++)
			scanf("%s",map[i]);
		for (i=0;i<h;i++)
			for (j=0;j<w;j++)
				if (map[i][j]!='0')
					{dfs(i,j,map[i][j]);coun++;}
		printf("%d\n",coun);
	}
	return 0;
}

Measured memory_bytes: 1668