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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (13 <= a) cout << b;
    else if (6 <= a && a <= 12) cout << (b / 2);
    else cout << 0;
    cout << endl;

    return 0;
}


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

int main(){
  int A,B,C; cin >> A >> B >> C;
  int ans = 0;
  for(int i=0;i<B;i++){
    if(A*i%B == C){
      cout << "YES" << endl;
    ans++; break;}
  }
  if(ans == 0)cout << "NO" << endl;
}
  

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    set<lli> prime;
    prime.insert(2);
    lli x;
    cin >> x;
    if(x==2){
        out(2);
        return 0;
    }
    lli i = 3;
    while (true){
        bool c = false;
        for(lli v:prime){
            if(v*v>i){
                break;
            }
            if(i%v==0){
                c = true;
                break;
            }
        }
        if(c==false){
            if(x<=i){
                out(i);
                return 0;
            }
            else{
                prime.insert(i);
            }
        }
        i++;
    }
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  //sugar
  vector<int> sugar;
  for (int i = 0; i <= 100 ; i++) {
    for (int j = 0; j <= 100; j++) {
      int sums = i * c + j * d;
      if (sums <= f) {
        sugar.push_back(sums);
      }
    }
  }

  //water
  vector<int> water;
  for (int i = 0; i <= 30; i++) {
    for (int j = 0; j <= 30; j++) {
      int sumw = i * a * 100 + j * b * 100;
      if (sumw <= f) {
        water.push_back(sumw);
      }
    }
  }

  double limit = (double)e / (100 + e);
  double n = -1;
  int ans1 = 0, ans2 = 0;
  for (int s : sugar) {
    for (int w : water) {
      int sw = s + w;
      if (sw == 0) continue;
      double x = (double)s / sw;
      if (sw <= f && x <= limit && x > n) {
        n = x;
        ans1 = sw;
        ans2 = s;
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }

    vector<vector<int64_t>> dp(n, vector<int64_t>(2, 0));
    dp.at(1).at(0) = a.at(0);
    dp.at(1).at(1) = a.at(1);
    for (int i = 2; i < n; i++)
    {
        if (i % 2 == 0)
        {
            dp.at(i).at(0) = max(dp.at(i - 1).at(0), dp.at(i - 1).at(1));
            dp.at(i).at(1) = a.at(i) + max(dp.at(i - 2).at(0), dp.at(i - 2).at(1));
        }
        else
        {
            dp.at(i).at(0) = a.at(i - 1) + dp.at(i - 2).at(0);
            dp.at(i).at(1) = a.at(i) + dp.at(i - 1).at(0);
        }
    }
    cout << max(dp.at(n - 1).at(0), dp.at(n - 1).at(1)) << endl;
}

Measured memory_bytes: 14876
//2018-1-19
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define pb push_back
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)

#define N (200+5)
#define LOG (60+5)

const int P = 1e9 + 7;

struct node{
	LL b, c;
	bool operator <(const node &rhs)const{return c < rhs.c;}
}h[N];

struct Seg{
	LL l, r;
	bool operator <(const Seg &rhs)const{return l < rhs.l;}
};

int n, m;
LL a[N], num[N];

struct lnode{
	LL l[N];

	bool operator <(const lnode &rhs)const{
		For(i, 1, n)
			if(l[i] < rhs.l[i]) return true;
			else if(l[i] > rhs.l[i]) return false;
		return false;
	}
};

map<lnode, int> ms;
vector<Seg> seg[N*LOG];

int Calc(LL L, LL R){
	LL tmp;
	int tot = 0;

	--L;
	Forr(i, 60, 0){
		tmp = 1ll<<i;
		if(R & tmp) ++tot;
		if((L&tmp) ^ (R&tmp)) return tot;
	}
	return __builtin_popcount(R);
}

lnode now;
void Put(int p, LL rem){
	For(i, 1, p-1){
		num[i] = h[i].b - 1; if(!h[i].b) return;
	}
	For(i, p, n) num[i] = h[i].b;
	sort(num+1, num+n+1);

	LL tmp = num[1];
	For(i, 1, n) now.l[i] = num[i] - tmp;
	if(!ms.count(now)) ms[now] = ++m;
	
	seg[ms[now]].pb((Seg){tmp-min(rem, tmp), tmp});
}

void Solve(){
	LL ans = 0, nl, nr, tot;

	For(si, 1, m){
		sort(seg[si].begin(), seg[si].end());

		tot = 0;
		nl = seg[si][0].l, nr = seg[si][0].r;

		For(i, 1, seg[si].size()-1){
			if(seg[si][i].l > nr){
				tot += nr - nl + 1;
				nl = seg[si][i].l; nr = seg[si][i].r;
			}else nr = max(nr, seg[si][i].r);
		}
		tot += nr - nl + 1;

		ans = (ans + tot%P) % P;
	}

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

int main(){
	LL s, tmp, rem;

	scanf("%d%lld", &n, &s);
	For(i, 1, n) scanf("%lld", &a[i]);
	
	For(k, 0, 60){
		tmp = 1ll << k;
		For(i, 1, n){
			h[i].b = a[i]/tmp, h[i].c = a[i]-h[i].b*tmp;
		}
		if(s < k) break;

		sort(h+1, h+n+1);
		
		Put(1, s-k);
		For(i, 2, n) if(h[i-1].c+1 <= h[i].c){
			rem = s - k - Calc(h[i-1].c+1, h[i].c);
			if(rem >= 0) Put(i, rem);
		}
	}

	Solve();

	return 0;
}

Measured memory_bytes: 16768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;

int main(){
	int n,m,ans=0;
	scanf("%d%d",&n,&m);
	int num=m/n;
	int v=sqrt(m);
	if(num<=v){
		for(int i=num;i>=1;i--)
			if(!(m%i)){
				ans=i;
				break;
			}
	}
	else{
		for(int i=n;i<=v;i++)
			if(!(m%i)){
				 ans=m/i;
				 break;
			}
		if(!ans){
			for(int i=n;i>=1;i--)
				if(!(m%i)){
					ans=i;
					break;
				}
		}
	}
	cout<<ans;
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    string last;
    set<string> S;
    bool result = true;
    for (int i = 0; i < N; i++) {
        string word;
        cin >> word;
        auto p = S.insert(word);
        if (!p.second || (i != 0 && last[last.size()-1] != word[0])) {
            result = false;
            break;
        }
        last = word;
    }
    cout << (result ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using P = pair<int,int>;

int main() {
    int n; cin >> n;
    vector<P> red(n);
    vector<P> blue(n);
    for(int i=0; i<n; i++){
        cin >> red[i].second;
        cin >> red[i].first;
    }
    for(int i=0; i<n; i++){
        cin >> blue[i].first;
        cin >> blue[i].second;
    }
    //blueはx座標で昇順(blueは(x,y))
    sort(blue.begin(),blue.end(),[](P a,P b){return a.first < b.first;});
    //redはy座標で降順(redは(y,x))
    sort(red.begin(),red.end(),greater<P>());
    //redをカウントしたかメモ
    vector<bool> used(n,false);

    int cnt = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(blue[i].first > red[j].second && blue[i].second > red[j].first && !used[j]){
                used[j] = true;
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
}

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

#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main() {
	sp;

	////////////////To Remove//////////////
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	///////////////////////////////////////

	long long n, m;
	cin>>n>>m;
	long long result = ((n>=2)?(n)*(n-1)/2:0) + ((m>=2)?(m)*(m-1)/2:0);
	cout<<result;
  return 0;
}

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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int n,k;
	cin >> n >> k;
	if(k == 1)cout << 0 << endl;
	else cout << n - k << endl;
	return 0; 
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n;
  cin >> n;
  
  vector<int>rab(n + 1,0);
  for(int i=1;i<=n;i++){
    cin >> rab[i];
  }
  
  int ans = 0;
  
  for(int i=1;i<=n;i++){
    if(rab[rab[i]] == i) ans++;
  }
  
  cout << ans / 2 << endl;
  
  return 0;
}


Measured memory_bytes: 768
import sys

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def all_factors(n):
    """returns a sorted list of all distinct factors of n"""
    small, large = [], []
    for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):
        if not n % i:
            small.append(i)
            large.append(n // i)
    if small[-1] == large[-1]:
        large.pop()
    large.reverse()
    small.extend(large)
    return small

def solve(a,b):
    return (a-1)+(b-1)


n = int(input())
facts = all_factors(n)
length = len(facts)
mini = 10**15 + 7
if length&1:
    for i in range(length//2+1):
        mini = min(mini, solve(facts[i], facts[~i]))
    print(mini)
else:
    for i in range(length//2):
        mini = min(mini, solve(facts[i], facts[~i]))
    print(mini)

Measured memory_bytes: 39408
#coding: utf-8
#ABC043C
import sys

n=int(raw_input())
l=map(int,raw_input().split())
res=float("inf")
cost=0
for i in xrange(-100,101):
 for j in l:
  cost+=(j-i)**2
 if cost<res:
  res=cost
 cost=0

print res


Measured memory_bytes: 2568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		

		if (A == B) {

			System.out.println(C);

		} else if (A == C) {

			System.out.println(B);

		} else if (B == C) {

			System.out.println(A);

		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N;
ll bfs(ll start, vector<vector<ll>>& S)
{
  vector<ll> dist(N, -1);
  dist.at(start) = 1;
  queue<pll> q;
  q.push({start, 1});
  ll res =  -1;
  while (!q.empty())
  {
    pll check = q.front();
    q.pop();
    ll fir = check.first, sec = check.second;
    res = max(res, sec);
    for (ll i = 0; i < S.at(fir).size(); ++i)
    {
      ll next = S.at(fir).at(i);
      if (dist.at(next) == sec - 1 || dist.at(next) == sec + 1)
      {
        continue;
      }
      if (dist.at(next) != -1)
      {
        return -1;
      }
      dist.at(next) = sec + 1;
      q.push({next, sec + 1});
    }
  }
  return res;
}

int main()
{
  cin >> N;
  vector<vector<ll>> S(N);
  for (ll i = 0; i < N; ++i)
  {
    string s;
    cin >> s;
    for (ll j = 0; j < N; ++j)
    {
      if (s[j] == '0')
      {
        continue;
      }
      S.at(i).push_back(j);
    }
  }
  // for (ll i = 0; i < N; ++i)
  // {
  //   for (ll j = 0; j < S.at(i).size(); ++j)
  //   {
  //     cout << S.at(i).at(j) << ' ';
  //   }
  //   cout << endl;
  // }
  ll ans = -1;
  for (ll i = 0; i < N; ++i)
  {
    ans = max(ans, bfs(i, S));
  }
  cout << ans << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const ll MOD = 1e16;
const double EPS = 1e-9;

int n, m;
pair<ll,pair<ll,ll>> dp[1010][1010];
bool visited[1010][1010];
ll ar[3][1010];
int mod;
pair<ll, pair<ll,ll>> anti, ax1;
ll su1, su2;
pair<ll, pair<ll,ll>> f(int pos, int used)
{
	if(used == m) return mp(0, mp(0,0));
	if(pos == n) return anti;
	if(visited[pos][used]) return dp[pos][used];
	visited[pos][used] = 1;
	pair<ll, pair<ll,ll>> ax3 = f(pos + 1,  used), ax2 = f(pos + 1, used + 1);
	ax2.f += ar[0][pos], 
	ax2.s.f += ar[1][pos], 
	ax2.s.s += ar[2][pos];
	su1 = 0, su2 = 0;

	su1 += ((mod & 1)? 1:-1)*ax3.f;
	su1 += ((mod & 2)? 1:-1)*ax3.s.f;
	su1 += ((mod & 4)? 1:-1)*ax3.s.s;

	su2 += ((mod & 1)? 1:-1)*ax2.f;
	su2 += ((mod & 2)? 1:-1)*ax2.s.f;
	su2 += ((mod & 4)? 1:-1)*ax2.s.s;
	//cout<<"   "<<ax1.f<<' '<<ax1.s.f<<' '<<ax1.s.s<<'\n';
	//cout<<"   "<<ax2.f<<' '<<ax2.s.f<<' '<<ax2.s.s<<'\n';
	//cout<<"   "<<pos<<' '<<used<<' '<<su1<<' '<<su2<<'\n';
	if(su1 > su2)
		return dp[pos][used] = ax3;
	else
		return dp[pos][used] = ax2;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	cin>>n>>m;
	fore(i, 0, n) fore(j, 0, 3) cin>>ar[j][i];
	ll res = 0;
	fore(i, 0, 8)
	{
		mem(visited, 0);
		mod = i;
		anti.f = ((mod & 1) ? -MOD:MOD);
		anti.s.f = ((mod & 2) ? -MOD:MOD);
		anti.s.s = ((mod & 4) ? -MOD:MOD);
		ax1 = f(0, 0);
		//cout<<i<<' '<<ax1.f<<' '<<ax1.s.f<<' '<<ax1.s.s<<'\n';
		res = max(res, abs(ax1.f) + abs(ax1.s.f) + abs(ax1.s.s));
	}

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

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

int main(){
    int N;
    cin >> N;
    
    cout << "?";
    for (int i = 1; i <= N; i++) cout << " " << i;
    cout << endl;
    string s;
    cin >> s;
    int l = 1;
    int r = N+1;
    while (r - l > 1) {
        int c = (l+r)/2;
        cout << "?";
        for (int i = c; i <= c+N-1; i++) cout << " " << i;
        cout << endl;
        string t;
        cin >> t;
        if (s == t) l = c;
        else r = c;
    }
    
    vector<char> ans(2*N+1);
    if (s == "Red") {
        ans[l] = 'R';
        ans[l+N] = 'B';
    }else {
        ans[l] = 'B';
        ans[l+N] = 'R';
    }
    
    for (int i = 1; i <= l-1; i++) {
        cout << "?";
        cout << " " << i;
        for (int j = l+1; j <= l+N-1; j++) cout << " " << j;
        cout << endl;
        string t;
        cin >> t;
        if (t == "Red") ans[i] = 'R';
        else ans[i] = 'B';
    }
    
    for (int i = l+N+1; i <= 2*N; i++) {
        cout << "?";
        cout << " " << i;
        for (int j = l+1; j <= l+N-1; j++) cout << " " << j;
        cout << endl;
        string t;
        cin >> t;
        if (t == "Red") ans[i] = 'R';
        else ans[i] = 'B';
    }
    
    for (int i = l+1; i <= l+N-1; i++) {
        cout << "?";
        cout << " " << i;
        for (int j = 1; j <= l-1; j++) cout << " " << j;
        for (int j = l+N+1; j <= 2*N; j++) cout << " " << j;
        cout << endl;
        string t;
        cin >> t;
        if (t == "Red") ans[i] = 'R';
        else ans[i] = 'B';
    }
    
    cout << "! ";
    for (int i = 1; i <= 2*N; i++) cout << ans[i];
    cout << endl;
    return 0;
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define req(i,f,N) for(int i = f; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) { 
        a = b;
        return true; 
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) { 
        a = b; 
        return true; 
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //

string str = "a";
int N;

void dfs() {
    int c = 'a';

    if (str.size() == N) return;

    rep(i, str.size()) {
        chmax(c, str[i]);
    }

    rep(i, c - 'a' + 2) {
        str.push_back(i + 'a');
        if (str.size() == N) {
            cou(str);
        }
        dfs();
        str.pop_back();
    }
}


int main() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    cin >> N;
    if (N == 1) {
        cout << "a" << endl;
        exit(0);
    }
    dfs();

}

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

bool judge(const char s[], const char p[]);

int main(void)
{	
	char s[101] = "\0";
	char p[101] = "\0";
	cin >> s;
	cin >> p;
	
	bool result = judge(s, p);
	if (result) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}

bool judge(const char s[], const char p[]) {
	for (int j = 0; s[j] != '\0'; j++) {
		if (p[0] == s[j]) {
			int k = j;
			int i;
			for (i = 1; p[i] != '\0'; i++) {
				if (s[k+i] == '\0') k = -i;
				if (p[i] != s[k+i]) break;
			}
			if (p[i] == '\0') return true;
		}
	}
	return false;
}

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = 0;
    if (a <= k) {
        ans += a;
        k -= a;
        if (b <= k) {
            k -= b;
            ans -= min(k, c);
        }
    } else {
        ans += k;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

using pll = pair<ll, ll>;

ll solve(vector<ll> &cut, ll H, ll W, ll K, vector<vector<ll>> &S) {
    //print("-----");
    set<ll> ycutset;
    for (ll y = 0; y < H; y++) {
        ycutset.insert(cut[y]);
    }
    ll ycut = ycutset.size() - 1;

    ll xcut = 0;
    //vector<vector<ll>> count(W, vector<ll>(H, 0));
    vector<ll> count(H, 0);
    vector<ll> curcount(H, 0);
    for (ll x = 0; x < W; x++) {
        for (ll y = 0; y < H; y++) {
            ll yu = cut[y];
            curcount[yu] += S[y][x];
        }

        bool cutok = false;
        for (ll y = 0; y < H; y++) {
            if (curcount[y] > K) {
                return INF;
            }
            if (curcount[y] + count[y] > K) {
                cutok = true;
            }
        }
        //        print(ycut, x, cutok);
        if (cutok) {
            xcut++;
            for (ll y = 0; y < H; y++) {
                count[y] = curcount[y];
                curcount[y] = 0;
            }
        } else {
            for (ll y = 0; y < H; y++) {
                count[y] = count[y] + curcount[y];
                curcount[y] = 0;
            }
        }
    }
    return (xcut + ycut);
}

void dfs(ll y, ll H, vector<bool> &use, vector<vector<ll>> &hcut) {
    if (y == H - 1) {
        ll start = 0;
        vector<ll> cut(H);
        for (ll z = 0; z < H - 1; z++) {
            cut[z] = start;
            if (use[z]) {
                start = z + 1;
            }
        }
        cut[H - 1] = start;
        hcut.push_back(cut);
        return;
    }
    use[y] = true;
    dfs(y + 1, H, use, hcut);
    use[y] = false;
    dfs(y + 1, H, use, hcut);
}

int main() {
    ll H, W, K;
    cin >> H >> W >> K;
    vector<vector<ll>> S(H, vector<ll>(W, 0));
    for (ll y = 0; y < H; y++) {
        for (ll x = 0; x < W; x++) {
            char c = '\n';
            while (c != '0' && c != '1') {
                cin >> c;
            }
            S[y][x] = c - '0';
        }
    }

    vector<vector<ll>> hcut;
    vector<bool> use(H, false);
    dfs(0, H, use, hcut);

    ll result = INF;
    for (auto cut : hcut) {
        result = min(result, solve(cut, H, W, K, S));
    }
    print(result);
}


Measured memory_bytes: 3728
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (x, y): (u64, u64) = {
        let mut split = buf.split_whitespace();
        (split.next().unwrap().parse().unwrap(), split.next().unwrap().parse().unwrap())
    };
    writeln!(output, "{}", 64 - (y / x).leading_zeros()).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "3 20
",
            "3\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "25 100
",
            "3\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "314159265 358979323846264338
",
            "31\n",
        );
    }
}

Measured memory_bytes: 4352
import math
import queue
import bisect
import heapq

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a):
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def main():
    n,k = map(int,input().split())
    ans = 0
    h = [x for x in map(int,input().split())]
    for i in h:
        if i>=k:
            ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 12516
using System.IO;
using System;

class Program
{
    static void Main()
    {
        string value = Console.ReadLine();
        string[] v = value.Split();
        var va = int.Parse(v[0]);
        var vb = int.Parse(v[1]);
        
        if(va > vb)
        {
            Console.WriteLine("a > b");
        }
        else if(va < vb)
        {
            Console.WriteLine("a < b");
        }
        else
        {
            Console.WriteLine("a == b");
        }
    }
}


Measured memory_bytes: 8956
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 200010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    init();

    ll ans = 0;
    exrep(j, b, w-1) {
        ans += Comb(h-a-1+j, h-a-1)*Comb(w+a-2-j, a-1);
        ans %= mod;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 4992
#include <iostream>

#define MAX 500000
#define SENTINEL 2000000000
int R[MAX/2+2], L[MAX/2+2];
int cnt;

void merge(int A[],int left ,int mid,int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i++];
            
        } else {
            A[k] = R[j++];
        }
    }
}

void mergesort(int A[],int left,int right) {
    if (left + 1 < right) {
        int mid = (left+right)/2;
        mergesort(A, left, mid);
        mergesort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(void){
    int A[MAX], n;
    cnt = 0;
    std::cin >> n;
    
    for (int i = 0; i < n; i++) {
       std::cin >> A[i];
    }
    
    mergesort(A, 0, n);
    
    for (int i = 0; i < n; i++) {
        if (i != 0) std::cout << " ";
        std::cout << A[i];
    }
    std::cout << "\n";
    
    std::cout << cnt << std::endl;
    
    return 0;
}



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

using namespace std;

int different( double h, double m )
{

	h += m / 12;
	double a = h - m;
	if( a < 0 ) a = -a;
	
	if( 360 - a < a ) a = 360 - a;

	return a;
}

int main(int argc, char const* argv[])
{
	double h,m;
	int n;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		scanf("%lf:%lf",&h,&m);

		h *= 30;
		m *= 6;

		double answer = different( h, m );


		if( answer >= 0 && answer < 30 ) cout << "alert" << endl;
		else if( answer >= 90 && answer <= 180 ) cout << "safe" << endl;
		else cout << "warning" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	string s; cin>>s;
	string x(s.size(),'x');
	cout<<x<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 8 + 10;
int x[N], y[N], a[N];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i];
	iota(a, a + n, 0);
	double ans = 0;
	do
	{
		for (int i = 1; i < n; ++i)
			ans += hypot(x[a[i]] - x[a[i - 1]], y[a[i]] - y[a[i - 1]]);
	}
	while (next_permutation(a, a + n));
	cout << fixed << setprecision(6) << ans / accumulate(a, a + n, 1, [](int x, int y){return x * (y + 1);});
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  int N,T;
  cin >> N >> T;
  vector<int> t(N);
  for(int i=0; i<N; i++){
    cin >> t[i];
  }
  ll ans = 0;
  for(int i=0; i<N-1; i++){
    ans += min(T,t[i+1]-t[i]);
  }
  ans += T;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2005)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)

signed main(){
    int n,x;
    cin >> n >> x;
    int A[MAX];
    REP(i,n) cin >> A[i];
    int mi[MAX][MAX];
    REP(i,n){
        int Mi = INF;
        REP(k,n){
            Mi = min( Mi , A[(i + n - k)%n ]);
            mi[i][k] = Mi;
        }
    }


    int res = INF;
    REP(k,n){
        int tmp = k * x;
        REP(i,n){
            tmp += mi[i][k];
        }
        res = min(res,tmp);


    }
    cout << res << endl;

}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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


int main() {
    cout<<fixed<<setprecision(10);


    string t; cin>>t;

    rep(i,t.size()){
        if(t[i] == '?') t[i] = 'D';
    }

    cout<<t<<endl;

    return 0;

}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	string ans;
	if (s[2] == s[3] && s[4] == s[5]) {
		ans = "Yes";
	}
	else {
		ans = "No";
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::max;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let v = scan.read::<usize>();
    let e = scan.read::<usize>();
    let mut g = vec![vec![];v];
    for _ in 0..e {
        let s = scan.read::<usize>();
        let t = scan.read::<usize>();
        g[s].push(t);
    }
    let mut dag = Dag::new(&g);
    dag.tsort();
    for i in 0..v { println!("{}", dag.vs[i]);}
}

struct Dag {
    g: Vec<Vec<usize>>,
    used: Vec<bool>,
    vs: Vec<usize>,
    n: usize
}

#[allow(dead_code)]
impl Dag {
    fn new(g: &Vec<Vec<usize>>) -> Dag {
        let n = g.len();
        Dag {n: n, g: g.clone(), used: vec![false; n], vs: vec![]}
    }

    fn dfs(&mut self, v: usize) {
        self.used[v] = true;
        for m in self.g[v].clone() {
            if !self.used[m] { self.dfs(m) }
        }
        self.vs.push(v);
    }

    fn tsort(&mut self) {
        for i in 0..self.n { if !self.used[i] { self.dfs(i) } }
        self.vs.reverse();
    }

    fn is_acyclic(&self) -> bool {
        self.vs.len() == self.n
    }

    fn longest_path(&self) -> usize {
        let mut dp = vec![0;self.n];
        for &p in &self.vs {
            for &v in &self.g[p] {
                dp[v] = max(dp[v], dp[p] + 1);
            }
        }
        dp.into_iter().max().unwrap()
    }
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut ret = vec![];
        for _ in 0..n { ret.push(self.read::<T>()) }
        ret
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion


Measured memory_bytes: 5048
#include<cstdio>
#include<cstring>
using namespace std;
int main(void){
	int A,B,len,i;
	char str[1000];

	while(1){
		A=0; B=0;
		fgets(str,sizeof(str),stdin);
		if(str[0]=='0') break;
		len=strlen(str)-1;
		for(i=1;i<len;i++){
			if(str[i]=='A')
				A+=1;
			else if(str[i]=='B')
				B+=1;
		}
		if(A>B)
			printf("%d %d\n",A+1,B);
		else if(B>A)
			printf("%d %d\n",A,B+1);
	}
	return 0;
}

Measured memory_bytes: 2600
#include<stdio.h>
#define MAX 100000
#define NIL -1

struct Node{ int p, l, r;};

struct Node T[MAX];

int n;
int H, D[MAX];

int getDepth(int);
void print(int);



int main(){
  
  int i, j;
  int d, v;
  int c, l;

  
  scanf("%d", &n);

  
  for ( i = 0; i < n; i++ ) {
    
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
    
  }

  for ( i = 0; i < n; i++ ){
    
    scanf("%d %d", &v, &d);

    for ( j = 0; j < d; j++ ){
      
      scanf("%d", &c);
      
      if ( j == 0 ) {
	T[v].l = c;
      }
      else{
	T[l].r = c;
      }
      
      l = c;
      T[c].p = v;
      
    }
  }
  
  H = 0;
  
  for ( i = 0; i < n; i++ ){
    
    D[i] = getDepth(i);
    
    if ( D[i] > H ) {
      H = D[i];
    }
    
  }

  for ( i = 0; i < n; i++ ) {
    print(i);
  }
  
  return 0;
}





int getDepth(int u){
  
  int d = 0;

  for(; T[u].p != NIL ;d++) {
    u = T[u].p;
  }
  
  return d;
}

void print(int u){
  
  int i, c;
  
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].p);
  printf("depth = %d, ", D[u]);

  if ( T[u].p == NIL ) {
    printf("root, ");
  }
  else if ( T[u].l == NIL ) {
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }
  
  printf("[");
  
  for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){

    if (i) printf(", ");

    printf("%d", c);

  }
  
  printf("]\n");
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Grid {
	int h, w;
	vector<vector<int>> c;
	const int di[8] = {1, 1, 0, -1, -1, -1, 0, 1};
	const int dj[8] = {0, 1, 1, 1, 0, -1, -1, -1};

public:
	Grid(int h, int w) : h(h), w(w), c(h, vector<int>(w)) {}
	void input() {
		REP(i, h) {
			REP(j, w) {
				cin >> c[i][j];
			}
		}
	}
	int dfs(int i, int j) {
		if (c[i][j] == 0) return 0;
		c[i][j] = 0;
		REP(k, 8) {
			int u = i + di[k];
			int v = j + dj[k];
			if (u >= 0 && u < h && v >= 0 && v < w) {
				dfs(u, v);
			}
		}
		return 1;
	}
	int ans() {
		int res = 0;
		REP(i, h) {
			REP(j, w) {
				res += dfs(i, j);
			}
		}
		return res;
	}
};

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

	while (true) {
		int h, w;
		cin >> w >> h;
		if (h == 0 && w == 0) break;
		Grid grid(h, w);
		grid.input();
		cout << grid.ans() << endl;
	}

	return 0;
}


Measured memory_bytes: 3236
#include <iostream>

using lli=long long;

int main(){
  int N,M,Q;
  std::cin >> N >> M >> Q;

  lli n_tr[501][501] = {};
  lli r_acc[502][502] = {};

  for(int i = 0; i < M; i++){
    int L,R;
    std::cin >> L >> R;
    n_tr[L][R]++;
  }

  for(int i = 1; i <= N; i++){
    lli tmp = 0;
    for(int j = 1; j <= N; j++){
      tmp += n_tr[i][j];
      r_acc[i][j] = tmp;
    }
  }

  for(int i = 0; i < Q; i++){
    int p,q;
    std::cin >> p >> q;
    lli ans = 0;
    for(int j = p; j <= q; j++){
      ans += r_acc[j][q];
    }
    std::cout << ans << "\n";
  }

  return 0;
}



Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define mod 1000000007
#define MOD 998244353
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
vector <int> adj[N];
int h[N];
signed main()
{
    
    speed
    int n,m;cin>>n>>m;
    rep(i,1,n){
    	cin>>h[i];
    }
    rep(i,1,m){
    	int a,b;cin>>a>>b;
    	adj[a].pb(b);
    	adj[b].pb(a);
    }
    int cnt=0;
    rep(i,1,n){
    	int ma=h[i];
    	if(adj[i].size()==0){
    		cnt+=1;
    		continue;
    	}
    	int flag=0;
    	for(auto it:adj[i]){
    		if(h[it]>=ma){
    			flag=1;
    			break;
    		}
    	}
    	if(flag==0){
    		cnt++;
    	}
    }
    cout<<cnt<<endl;



    

 
    return 0;
}

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

const ll INF = 1e17;
const ll MOD = 1e9+7;


int main() {
    // input, ready
    int N,A;
    cin >> N;
    int AList[N];
    int stone = 1;
    vector<int> ansIndex;
    for (int i=i; i<N; i++)
    {
        cin >> AList[i];
        if (AList[i] == stone)
        {
            ansIndex.push_back(i);
            stone++;
        }
    }

    //resolve
    int ans=0;
    int beforeIndex=0;
    for (int i=0; i< ansIndex.size(); i++)
    {
        ans += (ansIndex[i]-beforeIndex-1);
        beforeIndex = ansIndex[i];
    }
    ans += N-beforeIndex;

    // output
    if (ansIndex.size() == 0) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<string> w(n);
	for (auto &v : w) {
		cin >> v;
	}

	set<string> se;
	for (auto v : w) {
		se.emplace(v);
	}

	if (se.size() != w.size()) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < n - 1; i++) {
		if (w[i][w[i].size() - 1] != w[i + 1][0]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
using namespace std;

int n;
int as[10000];
map<int, int> freq;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    for (int i=0; i<n; i++) {
      scanf("%d", &as[i]);
    }

    int times = 0;
    while (1) {
      freq.clear();
      for (int i=0; i<n; i++) {
        freq[as[i]]++;
      }

      int cnt = 0;
      for (int i=0; i<n; i++) {
        if (as[i] == freq[as[i]]) cnt++;
        as[i] = freq[as[i]];
      }

      if (cnt == n) break;
      times++;
    }

    printf("%d\n", times);
    printf("%d", as[0]);
    for (int i=1; i<n; i++) {
      printf(" %d", as[i]);
    }
    puts("");
  }
}

Measured memory_bytes: 2780
n = int(input())

li = {}
key = []
for _ in range(n):
    tmp = input()
    if tmp in li.keys():
        li[tmp] += 1

    else:
        li[tmp] = 1
        key.append(tmp)

mord = max(li.values())

ans = []
for i in key:
    if li[i] == mord:
        ans.append(i)

ans.sort()

for i in ans:
    print(i)


Measured memory_bytes: 33416
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll a[2010];
int main(){
    int N;
    ll Z, W;
    cin >> N >> Z >> W;
    ll inp;
    REP(i,N){
        cin >> inp;
        a[i] = inp;
    }
    ll ans1, ans2, ans3, ans4;
    ll X,Y;

    if(N == 1){
        cout << abs(a[0] - W) << endl;
        return 0;
    }

    X = a[N-1];
    Y = W;
    ans1 = abs(X - Y);

    X = a[N-1];
    ll ymin = LLONG_MAX;
    int index;
    for(int i = 1; i < N-1; i++){
        ll diff = abs(X - a[i]);
        //cout << diff << endl;
        if(ymin > diff){
            index = i;
            ymin = diff;
        }
    }
    Y = a[index];
    ans2 = abs(X - Y);

    ll xmax = LLONG_MIN;
    Y = a[N-1];
    for(int i = 0; i < N-2; i++){
        ll diff = abs(Y - a[i]);
        if(xmax < diff){
            index = i;
            xmax = diff;
        }
    }
    X = a[index];
    ans3 = abs(X - Y);

    X = a[N-2];
    Y = a[N-1];
    ans4 = abs(X - Y);

    ll ans;
    ans = max(ans1, ans4);

    if(ans >= ans3 && ans >= ans2)
        cout << ans << endl;
    else if(ans2 > ans && ans3 > ans)
        cout << min(ans2, ans3) << endl;
    else 
        cout << ans << endl;

    //printf("1:%lld\t2:%lld\t3:%lld\t4:%lld\n", ans1, ans2, ans3, ans4);
    return 0;
}


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

using namespace std;

int main() {
    int N, Q; cin >> N >> Q;
    string S; cin >> S;
    
    int sum[N+1];
    sum[0] = 0; sum[1] = 0;
    for(int i = 1; i < N; i++) {
        if(S[i] == 'C' && S[i-1] == 'A')  sum[i+1] = sum[i] + 1;
        else sum[i+1] = sum[i];
    }

    for(int i = 0; i < Q; i++) {
        int l, r; cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }

    return 0;
}

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

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

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

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  const ll MAXN = 2*100000+1;
  ll nums[MAXN] = {};
  ll n; cin >> n;
  rep(i, n-1) {
    ll a; cin >> a;
    nums[a]++;
  }
  for (int i = 1; i <= n; i++) {
    outl(nums[i]);
  }
}

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

  solve();
}


Measured memory_bytes: 4732
#include <stdio.h>

int main(void){
	int num=0;
	int input;
	
	while(1){
		scanf("%d", &input);
		if(input == 0){
			return 0;
		}
		num++;
		printf("Case %d: %d\n", num, input);
	}
	
	return 0;
}

Measured memory_bytes: 600