akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;
typedef unsigned long long ull;



int main(){
    int n,q;
    cin >> n >> q;
    string a;
    a.push_back('.');
    string s;
    cin >> s;
    a=a+s;
    a.push_back('.');
    vector<pair<char,int>> b(q);
    rep(i,q){
        char f,g;
        cin >> f >> g;
        int u=0;
        if (g=='R') u++;
        b[i]=mk(f,u);
    }
    int l=0,r=n+1,ans=0;
    while(true){
        int mid=(l+r)/2;
        int h=mid;
        char y=a[mid];
        rep(i,q){
            // cout << y << endl;
            if (y==b[i].first) {
                if (b[i].second==1) h++;
                else h--;
                y=a[h];
            }
        }
        // cout << h << endl;
        if (l==r){
            if (h==0) l=mid;
        else l=mid-1;
        break;
        }
        if (h==0) l=mid+1;
        else r=mid;
        // cout << l << " " << r << endl;
    }
    // cout << l << endl;
    ans+=l;
    l=0;r=n+1;
    while(true){
        int mid=(l+r)/2;
        int h=mid;
        char y=a[mid];
        rep(i,q){
            if (y==b[i].first) {
                if (b[i].second==1) h++;
                else h--;
                y=a[h];
            }
        }
        if (l==r){
            if (h==n+1) l=mid;
        else l=mid-1;
        break;}
        if (h==n+1) r=mid;
        else l=mid+1;
    }
    ans+=n+1-l;
    cout << n-ans << endl;
}


Measured memory_bytes: 2308
# ALDS1_7_C Tree Walk
import sys


class Node:
    def __init__(self):
        self.left = -1
        self.right = -1
        self.parent = -1


def preorder(A, i, B):
    B.append(i)
    if A[i].left != -1:
        preorder(A, A[i].left, B)
    if A[i].right != -1:
        preorder(A, A[i].right, B)
    return


def inorder(A, i, B):
    if A[i].left != -1:
        inorder(A, A[i].left, B)
    B.append(i)
    if A[i].right != -1:
        inorder(A, A[i].right, B)
    return


def postorder(A, i, B):
    if A[i].left != -1:
        postorder(A, A[i].left, B)
    if A[i].right != -1:
        postorder(A, A[i].right, B)
    B.append(i)
    return


n = int(input())

tree = []
for i in range(n):
    node = Node()
    tree.append(node)

root = [i for i in range(n)]
for i in range(n):
    A = list(map(int, sys.stdin.readline().strip().split()))
    tree[A[0]].left = A[1]
    tree[A[0]].right = A[2]

    if A[1] != -1:
        tree[A[1]].parent = A[0]
        root.remove(A[1])
    if A[2] != -1:
        tree[A[2]].parent = A[0]
        root.remove(A[2])

print('Preorder')
ans = []
preorder(tree, root[0], ans)
print('', ' '.join(map(str, ans)))

print('Inorder')
ans = []
inorder(tree, root[0], ans)
print('', ' '.join(map(str, ans)))

print('Postorder')
ans = []
postorder(tree, root[0], ans)
print('', ' '.join(map(str, ans)))



Measured memory_bytes: 5628
from math import log, ceil

n, k = map(int, input().split())
a = tuple(map(int, input().split()))

A_MAX = 10 ** 9
MAX_BIT_LENGTH = ceil(log(A_MAX * n, 2))

cs = [0]
t = 0
for aa in a:
    t += aa
    cs.append(t)

ps = []
for r in range(1, n + 1):
    for l in range(r):
        ps.append(cs[r] - cs[l])

ans = 0
for b in range(MAX_BIT_LENGTH)[::-1]:
    cnt = 0
    t = ans + (1 << b)
    for p in ps:
        if p & t == t:
            cnt += 1
            if cnt == k:
                ans = t
                break

print(ans)

Measured memory_bytes: 23084
n = gets.to_s.to_i
a = gets.to_s.split.map{ |v| v.to_i }.sort
cs = a.each_with_object([0]) { |v, h| h << h[-1] + v }

ans = 1
(n-2).downto(0) do |i|
  break if cs[i+1] * 2 < a[i+1]
  ans += 1
end

puts ans


Measured memory_bytes: 22996
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポ゚インタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ゚(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量
  int a,j;
  // 地形を読み込み，各水たまりの水量を計算
	for (int i = 0; (c = getchar()) != EOF; i++) {
    		if (c == '\\') {                                 // '\' が出た時の処理
      		// 位置 i を st1 にプッシュ(write your code)
    			push(i,&st1);
    		}
  		else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      		// 水たまりの総水量 sum を更新(write your code)
  			j=pop(&st1);
  			sum=sum+(i-j);
  			// st2_j と st2_a を用いて水たまりの水量を更新 
      			a = i - j;   // 更新する水たまりの水量を a に格納していく
      			while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        		// 水たまりの水量を求めていく (write your code)
      				a=a+pop(&st2_a);
      				pop(&st2_j);
      			}
      			// 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    			push(j,&st2_j);
    			push(a,&st2_a);
    		}
  	}

	printf("%d\n", sum);       // 水たまりの総水量を出力
	printf("%d", st2_a.top);   // 水たまりの個数を出力

	// 各水たまりの水量を断面図の左から出力(スタックの底から出力)
	for(int i = 1; i <= st2_a.top; i++){ 
    		printf(" %d", st2_a.S[i]);  
	}
  	printf("\n");

	return 0;
}


Measured memory_bytes: 2144
module CharMap = Map.Make (struct
  type t = char
  let compare = compare
end)

let () =
  let a = read_line () in
  Array.init (String.length a) (fun i -> a.[i])
  |> Array.fold_left (fun m c ->
      CharMap.add c (1 + try CharMap.find c m with Not_found -> 0) m) CharMap.empty
  |> (fun m -> CharMap.fold (fun _ n acc -> acc + n * (n + 1) / 2) m 0)
  |> (fun n -> 1 + String.length a * (String.length a + 1) / 2 - n)
  |> Printf.printf "%d\n"

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

#define itn int
#define vi vector<int>
#define pb push_back
#define srt sort(v.begin(), v.end())
#define retunr return

//int infiint = std::numeric_limits<int>::max();
//float infiflt = std::numeric_limits<float>::infinity();

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "rt", stdin);

    int k, n;
    cin >> k >> n;
    
    int arr[n];
    for(int i=0; i<n; i++) cin >> arr[i];

    int diff[n];
	for(int i=0; i<n-1; i++) diff[i]=arr[i+1]-arr[i];
	diff[n-1]=k-arr[n-1]+arr[0];
	
	sort(diff, diff+n);

	cout << k-diff[n-1];
	
    return 0;
}

//    0
// 15   5


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
  int x,y;
  bool Ans=true;
  cin>>x>>y;
  for(int i=0;i<=x;i++){
    if(4*i+2*x-i*2==y){
      cout<<"Yes"<<endl;
      Ans=false;
      break;
    }
  }
  if(Ans)
    cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string bus;
  cin>>bus;
  if(bus[0]!=bus[1]||bus[1]!=bus[2]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/******************************************************************************************************/
void file(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/******************************************************************************************************/

const ll nax=2e5+1,mod=1e9+7;



int main(){

    sync
  //  file();
    

    ll n,m,p1;
    cin>>n>>m>>p1;

    pair<ll,pair<ll,ll> > p[m];
    forn(i,m) cin>>p[i].fi>>p[i].se.fi>>p[i].se.se, p[i].se.se = -p[i].se.se+p1;
    vector<ll> dist(n+1,1e15);
    dist[1] = 0;
    forn(i,n-1){
        forn(i,m){
            if(dist[p[i].fi]+p[i].se.se<dist[p[i].se.fi]) 
            {
                dist[p[i].se.fi] = dist[p[i].fi]+p[i].se.se;
            }
        }
    }
        ll ans = dist[n];
        forn(i,n-1){
        forn(i,m){
            if(dist[p[i].fi]+p[i].se.se<dist[p[i].se.fi]) dist[p[i].se.fi] = dist[p[i].fi]+p[i].se.se;
        }
    }
    if(ans!=dist[n]){
        cout<<-1;
    }
    else{
        cout<<max(-ans,0LL);
    }
  return 0;
}


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

#define MEM(var,val) memset(var,(val),sizeof(var))
const int M=1e9+7;
vll a;
ll n,k;
vector<vll>dp;
vll pref;
void dist(ll i)
{
    for(int j=0;j<=k;j++)
    if(j>a[i])
        dp[i][j]=(pref[j]-pref[j-a[i]-1]+M)%M;
    else 
        dp[i][j]=pref[j];
    pref[0]=dp[i][0];
    for(int j=1;j<=k;j++)
        pref[j]=(pref[j-1]+dp[i][j])%M;
    if(i>0)
        dist(i-1);
    return ;
}
int main()
{
  
    cin>>n>>k;
    dp.resize(n+1,vll(k+1,0));
    a.resize(n+1);
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int j=0;j<=a[n-1];j++)
    dp[n-1][j]=1;
    pref.resize(k+1,0);
    pref[0]=1;
    for(int j=1;j<=k;j++)
    pref[j]=pref[j-1]+dp[n-1][j];
    //MEM(dp,-1);
    if(n>=2)
    dist(n-2);
    cout<<dp[0][k]%M;

}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

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

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

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

int main(void){
    int N, Y;
    int x, y, z;
    cin >> N >> Y;
    for (int i = 0; i <= N; ++i)
    {
        for (int j = 0; j <= N; ++j)
        {
            int r = N - i - j;
            //r = r / 1000;
            if (r <= N && r >= 0 && 10000*i + 5000*j + 1000*r == Y)
            {
            cout << i << " " << j << " " << r << endl;
            return 0;
            }
        }
    }
    cout << -1  << " " << -1 << " "  << -1 << endl;
}


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

inline pair <int,int> read() {
	string s;
  cin >> s;
  int n = s.size(), miin = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		sum += (s[i] == '(') ? 1 : -1;
		miin = min(miin, sum);
	}
	return {sum, miin};
}

inline bool comp(const pair<int,int> &a, const pair<int,int> &b) {
  return min(a.second, (a.first + b.second)) > min(b.second, (b.first + a.second));
}
 
int main () {

	int n; scanf ("%d",&n);
	
  vector <pair <int, int>> v;
  for (int i = 0; i < n; i++) v.push_back(read());

	sort(v.begin(),v.end(), comp);
	
  int sum = 0;

	for (int i = 0; i < n; i++) {
		if (sum + v[i].second < 0) return !printf ("No\n");
		sum += v[i].first;
	}

	if (sum == 0) printf ("Yes"); else printf ("No\n");
}

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

using namespace std;

void Main() {
    string S;
    cin >> S;
    set<char> s;
    for (int i = 0; i < S.size(); ++i) {
        s.insert(S[i]);
    }
    cout << (s.size() == S.size() ? "yes" : "no") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int n,v;
int x[200010];
vector<pair<int,int> >tot;
int nl[20][200010],nr[20][200010];
int fl[1<<20],fr[1<<20];
int main()
{
	scanf("%d%d",&n,&v);
	for(int i=1;i<=n;i++)scanf("%d",x+i);
	for(int i=1;i<=n;i++)
	{
		int j=i;
		while(j+1<=n && x[j+1]-x[j]<=v)j++;
		tot.push_back(make_pair(i,j));
		i=j;
	}
	if((int)tot.size()>20)
	{
		for(int i=1;i<=n;i++)puts("Impossible");
		return 0;
	}
	v/=2;
	int k;
	for(k=0;;k++,v/=2)
	{
		for(int i=1;i<=n;i++)
		{
			int j=i;
			while(j+1<=n && x[j+1]-x[j]<=v)j++;
			for(int t=i;t<=j;t++)nl[k][t]=j,nr[k][t]=i;
			i=j;
		}
		if(!v)break;
	}
	k++;
	for(int i=0;i<(1<<k);i++)fr[i]=n+1;
	for(int i=0;i<(1<<k);i++)
	{
		for(int j=0;j<k;j++)
		{
			if(i>>j&1)continue;
			fl[i|(1<<j)]=min(n,max(fl[i|(1<<j)],nl[j][fl[i]+1]));
			fr[i|(1<<j)]=max(1,min(fr[i|(1<<j)],nr[j][fr[i]-1]));
		}
	}
	for(int i=0;i<(int)tot.size();i++)
	{
		bool ok=false;
		for(int j=0;j<(1<<k);j++)
		{
			int a=fl[j],b=fr[((1<<k)-1)^j];
			if((a>=tot[i].first-1 && b<=tot[i].second+1) || a+1>=b)
			{
				ok=true;
				break;
			}
		}
		for(int j=tot[i].first;j<=tot[i].second;j++)puts(ok?"Possible":"Impossible");
	}
	return 0;
}

Measured memory_bytes: 36992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = { -1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1 };
const int dy[] = { -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1 };
const ll integer = pow(2, 32) - 1; // 4294967295
#define N 8010000
#define TC int t;cin>>t;for(int T=1;T<=t;T++)
#define mod 1000000007
#define PI acos(-1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void AIA() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isprime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0)return 0;
	}
	return (n!=1);
}

/*
 _____________              __                ___        ___       ___________________________     ____        ____
|             |            /\ \              |   |      |   |     |                           |    \   \      /   /
|   __________|           / /\ \             |   |      |   |     |      _____      _____     |     \   \    /   /
|  |                     / /  \ \            |   |      |   |     |     |     |    |     |    |      \   \  /   /
|  |                    / /    \ \           |   |      |   |     |     |     |    |     |    |       \   \/   /
|  |______             / /      \ \          |   |______|   |     |     |     |    |     |    |        \      /
|         |           / /        \ \         |              |     |     |     |    |     |    |         \    /
|   ______|          / /          \ \        |    ______    |     |     |     |    |     |    |          |  |
|  |                / /============\ \       |   |      |   |     |     |     |    |     |    |          |  |
|  |               / /==============\ \      |   |      |   |     |     |     |    |     |    |          |  |
|  |              / /                \ \     |   |      |   |     |     |     |    |     |    |          |  |
|  |             / /                  \ \    |   |      |   |     |     |     |    |     |    |          |  |
|__|            /_/                    \_\   |___|      |___|     |_____|     |____|     |____|          |__|

										  <<<<<<<<<<< NEVER GIVE UP !! >>>>>>>>>>>
										<<<<<<<< YOU CAN DO IT IF YOU WANT !! >>>>>>>>
										 <<<<<<<<< BELIEVE IN YOURSELF !! >>>>>>>>>

*/
int main() {
	//cout << fixed << setprecision(9);
	//freopen("stand.in","r",stdin);
	//freopen("stand.out","w",stdout);
	AIA();
	int l,r,d;
	cin>>l>>r>>d;
	int c = 0;
	for(int i = l ; i<= r;i++){
		if(i%d==0){
			c++;
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

template <typename T> inline int size(const T& x) { return x.size(); }

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

    int n;
    while (cin >> n, n) {

        vector<int> prices(n);
        REP(i, n) cin >> prices[i];

        static const int MAX_COIN = 100*500;
        vector<pair<int, int>> dp[2];
        REP(i, 2) dp[i].resize(MAX_COIN);

        dp[0][0] = make_pair(0, 0);
        FOR(i, 1, MAX_COIN) dp[0][i] = make_pair(-10000000, 0);

        REP(i, n) {
            int curr = i % 2;
            int next = (i+1) % 2;

            REP(coin, MAX_COIN) {
                dp[next][coin] = make_pair(-10000000, 0);
            }

            REP(coin, MAX_COIN) {
                auto c = dp[curr][coin];
                int change = (1000 - prices[i]%1000) % 1000;

                if (change >= 500) {
                    // 1000????????§?????£???500?????????????????\?????´???
                    int next_coin = coin + change - 500;
                    if (next_coin < MAX_COIN)
                        dp[next][next_coin] = max(dp[next][next_coin], make_pair(c.first+1, c.second-prices[i]));
                    continue;
                }

                // ??????????????´???
                dp[next][coin] = max(dp[next][coin], c);

                if (change + coin >= 500) {
                    // ????????´?????§????°???????????????°500?????????????????\?????´???
                    int next_coin = coin + change - 500;
                    if (next_coin < MAX_COIN)
                        dp[next][next_coin] = max(dp[next][next_coin], make_pair(c.first+1, c.second-prices[i]));
                } else {
                    // ????????´?????§???500???????????\?????????????????´???
                    int next_coin = coin + change;
                    if (next_coin < MAX_COIN)
                        dp[next][next_coin] = max(dp[next][next_coin], make_pair(c.first, c.second-prices[i]));
                }
            }
        }

        auto ans = make_pair(-10000000, 0);
        REP(coin, MAX_COIN) ans = max(ans, dp[n%2][coin]);

        cout << ans.first << ' ' << -ans.second << endl;
    }
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    map<int, int> m;
    rep(i, n) m[a[i]]++;
    vector<int> v;
    if (m.size() <= k) {
        cout << 0 << endl;
        return 0;
    }
    for (auto u : m) {
        v.push_back(u.second);
    }
    sort(v.begin(), v.end());
    int cnt = 0;
    for (int i = v.size() - 1; i > v.size() - 1 - k; i--) {
        cnt += v[i];
    }
    cout << n - cnt << endl;
}

Measured memory_bytes: 14472
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] A = new long[N];
    long[] B = new long[N];
    long[] C = new long[N];
    long sum = 0;
    long minus = 0;
    int C_minus = 0;

    for(int i=0;i<N;i++){
      long Ai = sc.nextLong();
      A[i] =Ai;
      C[i]=Ai;
    }
    for(int i=0;i<N;i++){
      long Bi = sc.nextLong();
      B[i] =Bi;
      C[i] = C[i]-Bi;
      sum += C[i];
      if(C[i]<0){
         C_minus++;
         minus += C[i];
      }
    }
    if(C_minus==0){
      System.out.println(0);
    }else if(sum<0){
      System.out.println(-1);

    }else{

    //  System.out.println(C_minus);
    //  System.out.println(C[0]);
    //  System.out.println(C[1]);
    //  System.out.println(C[2]);
      int answer = 0;
      Arrays.sort(C);
      for(int i=C.length-1;i>=0;i--){
        minus += C[i];
    //    System.out.println(minus);
        if(minus>0){
          answer =C.length-1-i+1;
          break;
        }
      }
      answer += C_minus;
      System.out.println(answer);
    }
  }
}


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

int main() {
    int n;
	scanf("%d",&n);
	int arr[n];
	for(int i=0;i<n;i++)scanf("%d",&arr[i]);
	int pref=1000000010;
	int ans=0;
	for(int i=0;i<n;i++){
		pref=min(pref,arr[i]);
		if(pref>=arr[i])ans++;
	}
	printf("%d",ans);
}

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

const int MAXN = 1e3 + 5;

int N, M;
vector <int> adj[MAXN];
int dist[MAXN], dad[MAXN];

void load() {
	scanf("%d%d", &N, &M);
	while (M--) {
		int a, b;
		scanf("%d%d", &a, &b);
		adj[a].push_back(b);
	}
}

int bfs(int x, int y) {
	memset(dist, -1, sizeof dist);
	dist[y] = 0;
	queue <int> Q;
	Q.push(y);
	while (!Q.empty()) {
		int curr = Q.front();
		Q.pop();
		for (auto it : adj[curr])
			if (dist[it] == -1) {
				dist[it] = dist[curr] + 1;
				dad[it] = curr;
				Q.push(it);
			}
	}
	return dist[x];
}

void solve() {
	int mini = N, u = 0, v = 0;
	for (int i = 1; i <= N; i++)
		for (auto it : adj[i]) {
			int tmp = bfs(i, it);
			if (tmp != -1 && tmp < mini) {
				 mini = tmp;
				 u = i;
				 v = it;
			}
		}
	
	if (mini == N) {
		puts("-1");
		return;
	}
	
	bfs(u, v);
	
	printf("%d\n%d\n", dist[u] + 1, v);
	for (; u != v; u = dad[u])
		printf("%d\n", u);
}

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

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {


        String s = sc.next();
        char[] arr = s.toCharArray();

        arr[3] = '8';

        StringBuilder sb = new StringBuilder();
        for (int i=0; i<s.length(); i++) sb.append(arr[i]);

        out.print(sb.toString());
        out.flush();



    }

}


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

int main(){
    int H,W,i,j;
    char **s;
    cin >> H >> W;
    s = new char*[H];
    for(i=0;i<H;i++){
        s[i] = new char[W];
    }
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cin >> s[i][j];
        }
    }
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if(s[i][j]=='.'){
                continue;
            }
            if(i!=H-1&&s[i+1][j]=='#'){
                continue;
            }
            if(j!=W-1&&s[i][j+1]=='#'){
                continue;
            }
            if(i!=0&&s[i-1][j]=='#'){
                continue;
            }
            if(j!=0&&s[i][j-1]=='#'){
                continue;
            }
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
def lis(A):
    n = len(A)
    L = [0] * n
    L[0] = A[0]
    length = 1

    for i in xrange(1, n):
        if L[length - 1] < A[i]:
            L[length] = A[i]
            length += 1
        else:
            L[bisect.bisect_left(L[:length], A[i])] = A[i]

    return length

n = int(raw_input())
a = [int(raw_input()) for i in xrange(n)]
print lis(a)

Measured memory_bytes: 8884
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,k;
  cin>>n>>k;
  int r,s,p;
  cin>>r>>s>>p;
  string t;
  cin>>t;
  long long int ans=0;
  char lock='n';
  vector<char> used(n);
  for(int i=0; i<n; i++){
    if(i>=k){
      lock=used.at(i-k);
    }
    if(lock!='r'&&t[i]=='s'){
      ans+=r;
      used.at(i)='r';
    }else if(lock!='s'&&t[i]=='p'){
      ans+=s;
      used.at(i)='s';
    }else if(lock!='p'&&t[i]=='r'){
      ans+=p;
      used.at(i)='p';
    }else{
      if(i>n-k-1){
        used.at(i)='n';
      }else{
        char af=t[i+k];
        set<char> hoge={'r','s','p'};
        if(af=='r'){
          hoge.erase('p');
        }else if(af=='s'){
          hoge.erase('r');
        }else if(af=='p'){
          hoge.erase('s');
        }
        hoge.erase(lock);
        char next=*hoge.begin();
        used.at(i)=next;
      }
    }
    //cout<<used.at(i)<<" "<<ans<<" "<<lock<<endl;
  }
  cout<<ans<<endl;
}

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

int main() {
	int n; cin>>n;
	vector<int> p(n);

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

	int ans=0;
	for (int i=0; i<n; i++) {
		if (i==maxIndex) ans+=p[i]/2;
		else ans+=p[i];
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)

N = int(input())

def shichigosan(n):
    if n != '' and int(n) > N: 
        return 0
    return shichigosan(n+'3') + shichigosan(n+'5') + shichigosan(n+'7') + (1 if len(set(n)) == 3 else 0)

def main():
    print(shichigosan(''))

main()

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

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

bool used[100][100];

void dfs(int x,int y,char c) {
  rep(k,4) {
    int nx = x + dx[k];
    int ny = y + dy[k];
    if( !( 0 <= nx && nx < 100 && 0 <= ny && ny < 100 ) ) continue;
    if( s[ny][nx] == c ) {
      if( used[ny][nx] ) continue;
      used[ny][nx] = true;
      dfs(nx,ny,c);
    }
  }
}

bool veri(int A,int B) {
  int a=0,b=0;
  rep(i,100) {
    rep(j,100) {
      if( !used[i][j] ) {
	used[i][j] = true;
	dfs(j,i,s[i][j]);
	if( s[i][j] == '.' ) ++a;
	else ++b;
      }
    }
  }
  return A == a && B == b;
}

bool check(int x,int y,char c) {
  rep(k,4) {
    int nx = x + dx[k];
    int ny = y + dy[k];
    if( !( 0 <= nx && nx < 100 && 0 <= ny && ny < 100 ) ) continue;
    if( s[ny][nx] == c ) return false;
  }
  return true;
}


void compute(int A,int B) {
  int pA = A, pB = B;
  rep(i,100) {
    if( i < 50 ) {
      s[i] = string(100,'.');
    } else {
      s[i] = string(100,'#');
    }
  }
  --A, --B;
  while( A > 0 ) {
    for(int y=99;y>=50;y-=2) {
      for(int x=99;x>=0;--x) {
	if( check(x,y,'.') ) {
	  s[y][x] = '.';
	  --A;
	  if( A <= 0 ) goto Skip;
	}
      }
    }
  Skip:;
  }
  while( B > 0 ) {
    for(int y=0;y<50;y+=2) {
      rep(x,100){
	if( check(x,y,'#') ) {
	  s[y][x] = '#';
	  --B;
	  if( B <= 0 ) goto Skip2;
	}
      }
    }
  Skip2:;
  }

  
  puts("100 100");
  rep(i,100) cout << s[i] << endl;
  assert( veri(pA,pB) );
}

int main() {
  int A,B;
  cin >> A >> B;
  compute(A,B);
  return 0;
}


Measured memory_bytes: 640
h,w,n=map(int,input().split())
sh,sw=map(int,input().split())
s=input()
t=input()
r='RLDU'
q='LRUD'
p=dict(zip(r,[w-sw+1,sw,h-sh+1,sh]))
ds=dict(zip(r,[0]*4))
dt=dict(zip(r,[0]*4))
for i,j in zip(s,t):
  ds[i]+=1
  for k,l in zip(r,q):
    if ds[k]-dt[l]>=p[k]:
      print('NO')
      exit()
  dt[j]+=1
  for k in r:
    dt[k]=min(dt[k],p[k]+ds[k]-1)
print('YES') 

Measured memory_bytes: 74588
#include <iostream>
#include <algorithm>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

int main(){
    int N;
    cin >> N;
    if (N <= 999){
        cout << "ABC" << endl;
    } else {
        N -= 999;
        cout << "ABD" << endl;
    }
    return 0;
}

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

int main()
{
	int n, k, q;
	scanf("%d%d%d", &n, &k, &q);
	std::vector<std::pair<int, int>> a_sorted(n);
	std::vector<int> a(n);
	for (int i{}; i < n; i++)
	{
		scanf("%d", &a_sorted[i].first);
		a[i] = a_sorted[i].first;
		a_sorted[i].second = i;
	}
	std::sort(a_sorted.begin(), a_sorted.end());
	int min{a_sorted[q - 1].first - a_sorted[0].first};
	std::vector<bool> used(n + 1);
	used[a_sorted[0].second] = used[n] = true;
	for (int i{1}; i < n; i++)
	{
		if (a_sorted[i].first == a_sorted[i - 1].first)
		{
			used[a_sorted[i].second] = true;
			continue;
		}
		int left{};
		std::vector<int> can_use;
		for (int j{}; j <= n; j++)
		{
			if (!used[j]) continue;
			if (j - left < k)
			{
				left = j + 1;
				continue;
			}
			std::vector<int> tmp;
			for (int l{left}; l < j; l++)
				tmp.push_back(a[l]);
			std::sort(tmp.begin(), tmp.end());
			for (int l{}; l < j - left - (k - 1); l++)
				can_use.push_back(tmp[l]);
			left = j + 1;
		}
		if (can_use.size() < q)
			break;
		std::sort(can_use.begin(), can_use.end());
		min = std::min(min, can_use[q - 1] - can_use[0]);
		used[a_sorted[i].second] = true;
	}
	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

string N;
i64 dp[20][300][2];

i64 slv(int idx, bool free, i64 sum)
{
    if (idx >= N.size()) return sum;
    i64 &ret = dp[idx][sum][free];
    if (~ret) return ret;

    ret = 0;
    for (int i = free ? N[idx] - '0' : 9; i >= 0; --i) {
        chmax(ret, slv(idx + 1, free & (i == N[idx] - '0'), sum + i));
    }

    return ret;
}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    memset(dp, -1, sizeof(dp));

    cout << slv(0, true, 0) << endl;

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

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

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


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    string s;
    cin >> s;
    bool flag = false;
    REP(i,0,s.size()-1){
        if(s[i] == 'A' && s[i+1] == 'C') flag = true;
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

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

    int n, m, a, b, ans=0;
    cin >> n >> m;
    int arr[n][2];
    for (int i=0;i<n;i++) {
        cin >> arr[i][0];
        arr[i][1]=0;
    }
    for (int i=0;i<m;i++) {
        cin >> a >> b;
        if (arr[a-1][0]<arr[b-1][0]) {
            arr[a-1][1]+=1;
        }
        else if (arr[a-1][0]>arr[b-1][0])
            arr[b-1][1]+=1;
        else {
            arr[a-1][1]+=1;
            arr[b-1][1]+=1;
        }
    }
    for (int i=0;i<n;i++) {
        if (arr[i][1]==0) {
            ++ans;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4440
#include <iostream>

using namespace std;

int main(){
    int a,b;
    bool f = false;
    while(cin >> a >> b,a+b){
        if(f){
            cout << "" << endl;
        }
        f = true;
        bool flg=true;
        for(int i=a;i<=b;i++){
            if(i%4==0){
                if(i%100==0){
                    if(i%400==0){
                        flg=false;
                        cout << i << endl;
                    }
                }else{
                    flg=false;
                    cout << i << endl;
                }
            }
        }
        if(flg){
            cout << "NA" << endl;
        }

    }
    return 0;
}

Measured memory_bytes: 1160
def check(h):
    flag = True
    for i in range(len(h)-2):
        if h[i+1] - h[i] != h[i+2] - h[i+1]:
            flag = False
            break
    return flag   

while True:
    n = int(input())
    if n == 0:
        break
    
    h = [int(i) for i in input().split()]

    ans = -1 
    for k in range(n+1):
        tmp = h.pop(k)
        if check(h):
            print(tmp)
            break
        h.insert(k, tmp)
    


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

int main() {
	int N, M; cin >> N >> M;
	vector<int>v;
	for (int i = 0; i < M; ++i) {
		int a; cin >> a;
		v.emplace_back(a);
	}
	int ans = 0;
	ans = max(ans, v[0] - 1);
	ans = max(ans, N - v.back());
	for (int i = 0; i < M-1; ++i) {
		ans = max(ans, (v[i + 1] - v[i]) / 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int ans, x;
  ans = 1000;

  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    x = 0;
    while(A % 2 == 0){
      A /= 2;
      x++;
    }
    if(x < ans)
      ans = x;
  }
  
  cout << ans <<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc161c
{
    class Program
    {
        static void Main(string[] args)
        {
            //==========================================================================================================================
            //1) input
            List<decimal> input = Console.ReadLine().Split(' ').Select(decimal.Parse).ToList();
            decimal n = input[0];
            decimal k = input[1];

            decimal tmp = Math.Truncate(n / k);
            decimal start = n - tmp * k;


            decimal n_before = start + 1;
            while (start < n_before)
            {
                n_before = start;
                start = Math.Abs(start - k);
            }




            //==========================================================================================================================
            //2) output
            Console.WriteLine(n_before);
        }
    }
}


Measured memory_bytes: 11348
N,M = map(int,input().split())
mod = 10**9+7

def plmi(k):
    if k%2 == 0:
        return 1
    else:
        return -1

# 1!,2!,3!,...,n! (mod m)
def mod_factorials(n, m):
    mod_factorials = [1] * (n + 1)
    for i in range(1, n+1):
        mod_factorials[i] = mod_factorials[i-1]*i
        mod_factorials[i] %= m
    return mod_factorials

# 1!,2!,3!,...,n! の逆元 (mod m)
def mod_inv_factorials(n, m):
    mod_invs = [1] * (n + 1)
    invs = [1] * (n + 1)
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m

    for i in range(1, n+1):
        mod_invs[i] = invs[i]*mod_invs[i-1]
        mod_invs[i] %= m
    return mod_invs

mod_facts = mod_factorials(M,mod)
mod_inv_facts = mod_inv_factorials(M,mod)

ans = 0

for i in range(0,N+1):
    tmp = 1
    pm = plmi(i)
    tmp *= mod_facts[N]*mod_facts[M-i]
    tmp %= mod
    tmp *= mod_inv_facts[i]*mod_inv_facts[N-i]*mod_inv_facts[M-N]
    tmp %= mod
    tmp *= pm
    ans += tmp
    ans %= mod

ans *= mod_facts[M]*mod_inv_facts[M-N]
ans %= mod

print(ans)









Measured memory_bytes: 96624
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc=new Scanner(System.in);
		
		//コンテストの参加人数
		int N=sc.nextInt();
		//各参加者のレート数配列
		int[] a=new int[N];
		//色を数えるための配列
		int[] colorCount=new int[8];
		int freeColorCount=0;
		
		//合計色のカウント
		int sum=0;
		int max=0;
		int min=0;
		
		//各参加者のレート数と色のカウント
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			if(1<=a[i]&&a[i]<399) {
				//灰色
				colorCount[0]=1;
			}else if(400<=a[i]&&a[i]<=799) {
				//茶色
				colorCount[1]=1;
			}else if(800<=a[i]&&a[i]<=1199) {
				//緑色
				colorCount[2]=1;
			}else if(1200<=a[i]&&a[i]<=1599) {
				//水色
				colorCount[3]=1;
			}else if(1600<=a[i]&&a[i]<=1999) {
				//青色
				colorCount[4]=1;
			}else if(2000<=a[i]&&a[i]<=2399) {
				//黄色
				colorCount[5]=1;
			}else if(2400<=a[i]&&a[i]<=2799) {
				//橙色
				colorCount[6]=1;
			}else if(2800<=a[i]&&a[i]<=3199) {
				//赤色
				colorCount[7]=1;
			}else if(3200<=a[i]) {
				//色自由の人
				freeColorCount++;
			}
			
		}
		
		for(int colorCount1:colorCount) {
			sum+=colorCount1;
		}
	
		
		if(freeColorCount==0) {
			System.out.println(sum+" "+sum);
		}else {
			if(sum==0) {
				min=sum+1;
			}else {
				min=sum;
			}
			
				max=sum+freeColorCount;
			
					
			System.out.println(min+" "+max);
		
		}
		
	}

}

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

//---------- Union-Find -----------------
vector<int> par(100010);

void init(int n){
  for(int i=0; i<n; i++) par[i] = i;
}

int root(int x){
  if (par[x] == x) return x;
  else return par[x] = root(par[x]);
}

void unite(int x, int y){
  x = root(x); y = root(y);
  if (x != y) par[x] = y;
}

bool same(int x, int y){
  return (root(x) == root(y));
}
//----------------------------------------

struct edge {int u, v; Int cost;};

bool comp(edge e1, edge e2){
    return e1.cost < e2.cost;
}

Int kruskal(vector<edge> G, int V){
    sort(G.begin(), G.end(), comp);

    init(V);

    Int res = 0;
    rep(i,G.size()){
        edge e = G[i]; 
        if(!same(e.u, e.v)){
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

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

    vector<tuple<Int,Int,int>> XY, YX;
    rep(i, N){
        Int x, y; cin >> x >> y;
        tuple<Int,Int,int> xy = make_tuple(x, y, i);
        tuple<Int,Int,int> yx = make_tuple(y, x, i);
        XY.push_back(xy); YX.push_back(yx);
    }
    
    sort(XY.begin(), XY.begin()+N);
    sort(YX.begin(), YX.begin()+N);

    vector<edge> G;
    rep(i, N-1){
        Int x1 = get<0>(XY[i]), y1 = get<1>(XY[i]);
        Int x2 = get<0>(XY[i+1]), y2 = get<1>(XY[i+1]);
        Int cost = min(abs(x1-x2), abs(y1-y2));
        
        edge e = {get<2>(XY[i]), get<2>(XY[i+1]), cost};
        G.push_back(e);

        x1 = get<0>(YX[i]); y1 = get<1>(YX[i]);
        x2 = get<0>(YX[i+1]); y2 = get<1>(YX[i+1]);
        cost = min(abs(x1-x2), abs(y1-y2));
        
        e = {get<2>(YX[i]), get<2>(YX[i+1]), cost};
        G.push_back(e);
    }

    Int ans = kruskal(G, N);
    
    cout << ans << endl;
}

Measured memory_bytes: 15136
#include <stdio.h>
#define N 1000
int main(){
  int i, n, key;
  int A[N], j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<n;i++){
    for(key=0;key<n;key++){
      if(key==n-1){
 printf("%d",A[key]);
 continue;
      }
      printf("%d ",A[key]);
    }
    printf("\n");     
    key=A[i];
    j=i-1;
    while(j>=0&&A[j]>key){
      A[j+1]=A[j];
      j--;
      A[j+1]=key;
    }
  }  
  for(key=0;key<n;key++){
    if(key==n-1){
 printf("%d",A[key]);
 continue;
    }
    printf("%d ",A[key]);
  }
   printf("\n");
  return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <set>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  ll h, w, n;
  cin >> h >> w >> n;
  set<Pii> ab;
  for (int i = 0; i < n; i++) {
    Pii buf;
    cin >> buf.first >> buf.second;
    ab.insert(buf);
  }

  vector<set<Pii> > found(10);
  ll base = (h-2) * (w-2);

  for (auto &x: ab) {
    for (int i = x.first - 1; i <= x.first + 1; i++) {
      for (int j = x.second - 1; j <= x.second + 1; j++) {
        bool good = true;
        int count = 0;
        for (int k = i - 1; k <= i + 1; k++) {
          for (int l = j - 1; l <= j + 1; l++) {
            if (k <= 0 || k > h || l <= 0 || l > w) {
              good = false;
              break;
            }
            if (ab.find(Pii(k, l)) != ab.end()) {
              count++;
            }
          }
          if (!good) break;
        }
        if (good) found[count].insert(Pii(i, j));
      }
    }
  }

  vector<ll> ans(10);
  ans[0] = base;
  for (int i = 1; i <= 9; i++) {
    ans[i] = found[i].size();
    ans[0] -= ans[i];
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}


Measured memory_bytes: 47104
#include<bits/stdc++.h>
typedef double db;
typedef long long ll;
using namespace std;
const int N = 1e3+7;
char s[N], t[N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%s%s", s, t);
	int len1 = strlen(s);
	int len2 = strlen(t);
	int ans = len2;
	for(int i = 0; i < len1 - len2 + 1; i++){
		int cnt = 0;
		for(int j = 0; j < len2; j++) 
			if(s[i+j] != t[j]) cnt++;
		ans = min(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

int s_int(string s){
    return atoi(s.c_str());
}

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << max({s_int(a + b) + s_int(c), s_int(a) + s_int(b + c),s_int(a)+s_int(b)+s_int(c)*10}) << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
string ans;

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N = 0;
	string str1, str2;
	cin >> str1;
	cin >> str2;
	AFOR(i, str1.size()) {
		if (str1.at(i) == str2.at(i)) {
			N++;
		}
	}
    if(N == str1.size())
		cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 6776
MOD = 998244353
N,K = map(int,input().split())
lr = []
for i in range(K):
    lr.append(list(map(int,input().split())))
dp = [0] * (10**6)
dp[0] = 1
dpcum = [0] * (10**6)
dpcum[0] = 1
for i in range(1,N+1):
    for j in range(K):
        dp[i] += dpcum[max(-1,i-lr[j][0])] - dpcum[max(-1,i-lr[j][1]-1)]
        dp[i] %= MOD
    dpcum[i] = (dpcum[i-1] + dp[i]) % MOD
#print(dp)
print(dp[N-1])

Measured memory_bytes: 83960