akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <functional>
#include <deque>
#include <stdexcept>
#include <algorithm>


template<typename T, typename Container = ::std::vector<T>, typename Compare = ::std::greater<typename Container::value_type>>
class sliding_window {
    using iterator_type = typename Container::const_iterator;
    using value_compare = Compare;
    using value_type = T;
    using const_reference = const value_type &;

    iterator_type right_bound, left_bound, end;
    value_compare comp;
    size_t length;
    ::std::deque<value_type> val;

public:
    void push() {
        if (left_bound == end) {
            throw ::std::runtime_error("already reached to the end");
        }
        const auto &tmp = *left_bound;
        //while (!val.empty() && comp(val.back(), tmp))val.pop_back();
        val.resize(val.rend() - ::std::lower_bound(val.rbegin(), val.rend(), tmp, comp));
        val.push_back(tmp);
        ++left_bound;
        ++length;
    }

    void pop() {
        if (right_bound == left_bound) {
            throw ::std::runtime_error("interval is empty");
        }
        const auto &tmp = *right_bound;
        if (tmp == val.front())val.pop_front();
        ++right_bound;
        --length;
    }

    sliding_window(iterator_type _begin, iterator_type _end, const Compare &_comp = Compare()) : length(0),
                                                                                                 right_bound(_begin),
                                                                                                 left_bound(_begin),
                                                                                                 end(_end), comp(_comp),
                                                                                                 val({}) {}

    const size_t size() const {
        return length;
    }

    const_reference top() const {
        return val.front();
    }

    void resize(size_t n) {
        if (n < length) {
            while (n != length) {
                pop();
            }
        } else {
            while (n != length) {
                push();
            }
        }
    }

    void forward() {
        if (left_bound != end)push();
        pop();
    }

};

#include <iostream>

int main() {
    unsigned long long N, M, K;
    scanf("%llu%llu%llu", &N, &M, &K);

    std::vector<unsigned long long> A(N), dp1(N), dp2(N);
    for (auto &i : A)scanf("%llu", &i);

    std::copy(A.begin(), A.end(), dp1.begin());

    for (unsigned long long i = 1; i != K; ++i) {
        sliding_window<unsigned long long, std::vector<unsigned long long>, std::less<>> slidingWindow(
                dp1.begin() + i - 1, dp1.end());
        std::transform(A.begin() + i, A.end(), dp2.begin() + i, [&i](auto a) { return a * (i + 1); });

        slidingWindow.push();

        for (unsigned long long j = i; j != N; ++j) {
            dp2[j] += slidingWindow.top();
            if (slidingWindow.size() == M)slidingWindow.pop();
            slidingWindow.push();
        }

        std::swap(dp1, dp2);
    }

    std::cout << *std::max_element(dp1.begin(), dp1.end()) << std::endl;

    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;

int N;
int K;
char hito[200000];
int renzoku[200000];
int kotae;
int kotae2;

int main(){
  cin >> N >> K;
  for(int i=0; i<N;i++){
    cin >> hito[i];
  }
  for(int i=0; i<N;i++){
    if(hito[i]=='1') hito[i]='0';
    else break;
  }
  for(int i=N-1; i>=0;i--){
    if(hito[i]=='1') hito[i]='0';
    else break;
  }

  char now = '0';
  int now_num=0;
  int now_idx=0;
  for(int i=0;i<N;i++){
    if(hito[i]==now){
      now_num ++;
    }
    else{
      renzoku[now_idx]=now_num;
      now_num=1;
      now_idx ++;
      if(now=='0') now='1';
      else now='0';
    }
  }
  renzoku[now_idx]=now_num;
  if(now_idx< 2*K-1 ){
    cout << N << endl;
    return 0;
  }
  else{
    kotae = 0;
    for(int i=0;i<2*K;i++){
      kotae += renzoku[i];
      kotae2 = max(kotae2,kotae);
    }
    for(int i=2*K;i<=now_idx;i=i+2){
      if(i==2*K){
        kotae += renzoku[i];
        kotae += renzoku[i+1];
        kotae -= renzoku[i-2*K];
        kotae2 = max(kotae2,kotae);
      }
      else if(i==now_idx){
        kotae += renzoku[i];
        kotae -= renzoku[i-2*K];
        kotae -= renzoku[i-2*K-1];
        kotae2 = max(kotae2,kotae);
      }
      else{
      kotae += renzoku[i];
      kotae += renzoku[i+1];
      kotae -= renzoku[i-2*K];
      kotae -= renzoku[i-2*K-1];
      kotae2 = max(kotae2,kotae);
    }
    }
  }
  cout<<kotae2 << endl;
  return 0;
}


Measured memory_bytes: 768
fun main(args: Array<String>){
    val N = nextInt()
    val P = listOfInt()
    var count = 0
    for (n in 0 until N) {
        if (P[n] != n + 1) count++
    }
    println(if (count == 0 || count <= 2) "YES" else "NO")
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }


Measured memory_bytes: 36028
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int x = 1;
    for(int i=0; i<n; ++i){
        if(a[i] == x)
            ++ x;
    }
    if(x == 1)
        cout << -1 << endl;
    else
        cout << (n + 1 - x) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector> 
#include <math.h>
#include <stdio.h>
using namespace std;

double r(double x1,double y1,double x2,double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	
	}

int main() {
	// your code goes here
int n;
int a[110]={0};
while(cin>>n){
	a[n]=a[n]+1;

}
int ma=-1;
vector<int> ve;
for(int j=0;j<101;j++){
	if(a[j]==ma){
		ve.push_back(j);
	}
	else if(a[j]>ma){
		ve.clear();
        ve.push_back(j);
        ma=a[j];
	}
		
		
	}
	
	int y=ve.size();
	for(int u=0;u<y;u++){
		cout<<ve[u]<<endl;
		
	}
	


	
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>       // std::numeric_limits

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin >> n;
	int a[n], dp[n];
	for(int i=0;i<=n;++i)
		dp[i] = std::numeric_limits<int>::max();
	for(int i=0;i < n; ++i)
		cin>>a[i];
	dp[0] = 0;
	for (int i=0;i<n;++i) {
		if (i+1 < n) dp[i+1] = min(dp[i+1], dp[i] + abs(a[i] - a[i+1]));
		if (i+2 < n) dp[i+2] = min(dp[i+2], dp[i] + abs(a[i] - a[i+2]));
	}

	cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 1024
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    rep(i, N) cin >> L.at(i);

    vector<int> D(N + 1);
    D.at(0) = 0;
    int ans = 1;
    for (int i = 1; i <= N; i++) {
        D.at(i) = D.at(i - 1) + L.at(i - 1);
        if (D.at(i) <= X) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define LL long long
#define pa pair<int,int>
using namespace std;
const int inf = 2147483647;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

bool v[101];
int hh[101][101];
int a[101], b[101];

int main() {
	int n = read();
	if(n % 4 == 0) {
		int c = n / 4;
		printf("%d\n", (n / 2) * (n / 2));
		for(int i = 1; i <= c; i++) a[i] = i;
		for(int i = n - c + 1; i <= n; i++) a[i - 2 * c] = i;
		for(int i = c + 1; i <= n - c; i++) b[i - c] = i;
		for(int i = 1; i <= n / 2; i++) {
			for(int j = 1; j <= n / 2; j++) {
				printf("%d %d\n", a[i], b[j]);
			}
		}
	} else if((n + 1) % 4 == 0) {
		int c = n * (n + 1) / 4;
		int u1 = 0, u2 = 0;
		for(int i = n; i >= 1; i--) if(c >= i) a[++u1] = i, c -= i, v[i] = 1;
		for(int i = 1; i <= n; i++) if(!v[i]) b[++u2] = i;
		printf("%d\n", u1 * u2);
		for(int i = 1; i <= u1; i++) {
			for(int j = 1; j <= u2; j++) {
				printf("%d %d\n", a[i], b[j]);
			}
		}
	} else {
		int c = n * (n + 1) / 2, q;
		for(int i = 2; i <= sqrt(c); i++) if(c % i == 0) {q = i; break;}
		int u = n, ans = 0;
		for(int i = 1; i <= q; i++) {
			int s = c / q;
			for(int j = n; j >= 1; j--) if(!v[j] && s >= j) hh[i][++hh[i][0]] = j, v[j] = 1, s -= j;
			ans += (u - hh[i][0]) * hh[i][0];
			u -= hh[i][0];
		} printf("%d\n", ans);
		for(int i = 1; i < q; i++) {
			for(int j = i + 1; j <= q; j++) {
				for(int k = 1; k <= hh[i][0]; k++) {
					for(int h = 1; h <= hh[j][0]; h++) {
						printf("%d %d\n", hh[i][k], hh[j][h]);
					}
				}
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;

long long costmin;
long long costmax;
long long n,a,b;

int main() {
  cin >> n >> a >> b;
  if(a > b || (n == 1 && a != b)) {
    cout << "0" << endl;
    return 0;
  }
  if(n == 1 && a == b) {
    cout << "1" << endl;
    return 0;
  }
  costmin = (n-1)*a + b;
  costmax = (n-1)*b + a;
  cout << costmax - costmin + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int h = std.nextInt();
        int w = std.nextInt();
        int[][] table = new int[h][w];
        for (int i = 0; i < h; i++) {
            String s = std.next();
            for (int j = 0; j < s.length(); j++) {
                char c = s.charAt(j);
                table[i][j] = (c == '#') ? 1:0;
            }
        }

        int[][] ldp = new int[h][w];
        int[][] rdp = new int[h][w];
        int[][] tdp = new int[h][w];
        int[][] bdp = new int[h][w];

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (table[i][j] == 1) {
                    ldp[i][j] = 0;
                    tdp[i][j] = 0;
                    continue;
                }

                if (j == 0) {
                    ldp[i][j] = 1;
                } else {
                    ldp[i][j] = ldp[i][j - 1] + 1;
                }

                if (i == 0) {
                    tdp[i][j] = 1;
                } else {
                    tdp[i][j] = tdp[i - 1][j] + 1;
                }
            }
        }

        for (int i = h - 1; i >= 0; i--) {
            for (int j = w - 1; j >= 0; j--) {
                if (table[i][j] == 1) {
                    rdp[i][j] = 0;
                    bdp[i][j] = 0;
                    continue;
                }

                if (j == w - 1) {
                    rdp[i][j] = 1;
                } else {
                    rdp[i][j] = rdp[i][j + 1] + 1;
                }

                if (i == h - 1) {
                    bdp[i][j] = 1;
                } else {
                    bdp[i][j] = bdp[i + 1][j] + 1;
                }
            }
        }

        long ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                long value = ldp[i][j] + rdp[i][j] + tdp[i][j] + bdp[i][j] - 3;
                ans = Math.max(ans, value);
            }
        }

        System.out.println(ans);
    }
}


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

int main(){
    ll x,y;
    cin >> x >> y;
    ll cnt = 0;
    while(x <= y){
        x *= 2;
        cnt++;
    }
    cout << cnt << endl;
}

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

int n, A[200005], B[200005], ans = 1e18;

signed main(){
  
  cin>>n;
  
  int S = 0;
  
  int a = 0, b = 0, c = 0;
  
  for(int i=0;i<n;i++){
    cin>>A[i];
    A[i] -= i + 1;
    S += abs( A[i] );
    if( A[i] > 0 ) a++;
    if( A[i] == 0 ) b++;
    if( A[i] < 0 ) c++;
    B[i] = A[i];
  }
  
  if( a + b > c ){
    for(int i=0;i<n;i++){
      if( A[i] != 0 ) A[i] *= -1;
      B[i] = A[i];
    }
  }
  
  sort( A, A + n, greater<int>() );
  
  sort( B, B + n );
  
  ans = min( ans, S );

  int p = 0;
  
  for(int i=0;i<n;i++){
    
    if( p != A[i] && A[i] < 0 ){
      
      int cnt2 = lower_bound( B, B + n, A[i] + 1 ) - B;

      int cnt1 = n - cnt2;
      
      if( cnt1 - cnt2 < 0 ){
	ans += ( cnt1 - cnt2 ) * abs( A[i] - p );
      }
      
      p = A[i];
      
    }
    
  }

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


Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll n,m,f[100005],w,v;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&w,&v);
		for(int j=m;j>=w;j--)
		  f[j]=max(f[j],f[j-w]+v);
	}
	ll ans=0;
	for(int j=1;j<=m;j++)
	  ans=max(ans,f[j]);
	printf("%lld\n",f[m]);
	return 0;
}

Measured memory_bytes: 896
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  double n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vd X(n);
  Vs U(n);
  REP(i,n){
    IN2(X[i],U[i]);
    if(U[i] == "JPY") z += X[i];
    else z += X[i] * 380000.0;
  }
  OUT(z);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int D, G;
int p[10];
int c[10];


int main () {
  cin >> D >> G;
  for(int i = 0; i < D; ++i){
    cin >> p[i] >> c[i];
  }
  
  
  int ans = 10000;
  
  for(int bit = 0; bit < (1<<D); ++bit) {
    int cnt = 0;
    int sum = 0;
    for(int i = 0; i < D; ++i) {
      if(bit & (1<<i)) {
        cnt += p[i];
        sum += 100 * p[i] * (i+1) + c[i];
      }
    }
    if(sum >= G) ans = min(ans, cnt);
    else {
      for(int i = D-1; i >= 0; --i) {
        if(bit & (1<<i)) continue;
        for(int j = 0; j < p[i]; ++j) {
          if(sum >= G) break;
          sum += 100 * (i+1);
          ++cnt;
        }
      }
      ans = min(ans, cnt);
    }
  
  }
cout << ans << endl;
}

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

int main(){
  string str;
  int ab[26]={};
  int i;
  int j;

  while(getline(cin,str))
    {
      for(i=0;i < str.size();i++)
	{
	  if(str[i] >= 'a' && str[i] <= 'z') ab[str[i]-'a']++;
	  else if(str[i] >= 'A' && str[i] <= 'Z') ab[str[i]-'A']++;
	}
    }
  for(j=0;j < 26;j++)
    {
      cout << (char)('a'+j) << " : " << ab[j] << endl;
    }
  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; string s; cin >> n >> s;
    // 先頭2種類を固定して矛盾が無いか試す
    for(ll i=0; i<4; i++){
        // 1文字余分に確保
        string tmp = "SS" + string(n-1, '-');
        if(i&(1LL<<0)) tmp[0] = 'W';
        if(i&(1LL<<1)) tmp[1] = 'W';
        for(ll i=1; i<n; i++){
            if(tmp[i] == 'S'){
                // 羊の場合
                if(s[i] == 'o'){
                    tmp[i+1] = tmp[i-1];
                }
                else{
                    tmp[i+1] = (tmp[i-1] == 'S' ? 'W' : 'S');
                }
            }
            else{
                // 狼の場合
                if(s[i] == 'o'){
                    tmp[i+1] = (tmp[i-1] == 'S' ? 'W' : 'S');
                }
                else{
                    tmp[i+1] = tmp[i-1];
                }
            }
        }
        if(tmp[0] == tmp[n]){
            if(tmp[0] == 'S'){
                if((s[0] == 'o' && tmp[1] != tmp[n-1]) || (s[0] == 'x' && tmp[1] == tmp[n-1])) continue; 
            }
            else{
                if((s[0] == 'o' && tmp[1] == tmp[n-1]) || (s[0] == 'x' && tmp[1] != tmp[n-1])) continue; 
            }
            cout << tmp.substr(0, n) << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3764
import numpy as np


D = int(input())
c = np.array(list( map(int,input().split())))
S = np.zeros((D,26))
for i in range(D):
    S[i] = np.array(list( map(int,input().split())))

T = np.array([])
for i in range(D):
    T = np.append(T,int(input()))

"""
D = 365
c = np.random.randint(0,100,size=(26))
S = np.random.randint(0,20000,size=(D,26))
"""

def calc_score(T,D,c,S):
    last = np.ones(26) * (-1)
    scores = []
    score = 0
    for d in range(D):
        i = int(T[d])-1
        score += S[d,i]
        last[i] = d
        score -= np.sum(c*(d-last))
        scores.append(score)
    score = max([10**6+score,0])
    return score,scores

_,ans = calc_score(T,D,c,S)
for a in ans:
    print(int(a))

Measured memory_bytes: 27140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a)
#define ld long double
const ll mod=1e9+7;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    swap(a,c);
    swap(b,c);
    cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 256
n, k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
h = Hash.new(0)
ans = 0

a.each do |e|
    h[e] += 1
end

if h.size <= k then
    puts "0"
    exit
end

hashToArray = h.sort_by{|key, value| value}

(h.size-k).times do |i|
    ans += hashToArray[i][1]
end

puts ans

Measured memory_bytes: 42240
#include<stdio.h>
int main()
{
    int k,a,b,i;
    scanf("%d%d%d",&k,&a,&b);
    for(i=a;i<=b;i++){
        if(i%k==0){
            printf("OK\n");
            break;
        }
        if(i==b&&i%k!=0){
            printf("NG\n");
        }

    }
}


Measured memory_bytes: 1656
import numpy as np
N,W = map(int,input().split())
l = []
for i in range(N):
  y,x =  map(int,input().split())
  l.append((x,y))
V = sum([x[0] for x in l])
dp = np.full((N+1,V+1), np.inf)
dp[0][0]=0
for i in range(N):
  v = l[i][0]
  w = l[i][1]
  dp[i+1]=dp[i]
  dp[i+1][v:] = np.minimum(dp[i][v:],dp[i][:V-v+1]+w)
i = V
while True:
    if dp[N][i] <= W:
      print(i)
      break
    i -= 1

Measured memory_bytes: 92928
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// input
int N;
long long W, weight[MAX_N], value[MAX_N];

// DP table
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // initialize
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // initial condition
    dp[0][0] = 0;

    // DP loop
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
            
            // choose ith goods
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // not choose ith goods
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // output optimal value
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 86272
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
ll k,n;
ll r[1000005];
int main(){
    cin>>k>>n;
    rep(i,0,n){
        cin>>r[i];
    }
    sort(r,r+n);
    ll maxi=0;
    rep(i,0,n-1){
        maxi=max(maxi,r[i+1]-r[i]);
    }
    //puts(r[0]+k-r[n-1]);
    maxi=max(maxi,r[0]+k-r[n-1]);
    puts(k-maxi);
}

Measured memory_bytes: 1792
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-07 23:17:58
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  string s; cin >> s;
  if (all_of(all(s), [](char c ){return c == 'A';}) || all_of(all(s), [](char c ){return c == 'B';})) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    map<int, int> a;
    rep(i, n) {
        int t; cin >> t;
        if(a[t] > 0) a[t]--;
        else a[t]++;
    }
    int ans = 0;
    rfor(p, a) if(p.second > 0) ans++;
    print(ans);

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
    int N;
    string S;
    cin>>N>>S;
    ll ans = 1;
    ll K =  0;
    for(auto c: S){
        if((c == 'W') == (K%2 == 0)){
            K %= MOD;
            ans *= K;
            ans %= MOD;
            if((--K)<0)break;
        }
        else{
            K++;
            K %= MOD;
        }
    }
    if(K!=0){
        cout<<0<<endl;
        return 0;
    }
    rep1(i,N+1){
        ans *= i;
        ans %= MOD;
    }
    cout<<ans<<endl;

}

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

map<ll,ll> mp;

void prime(ll n){
  for(ll a=2;a*a<=n;++a){
    if(n%a!=0)continue;
    ll ex=0;
    while(n%a==0){
      ++ex;
      n/=a;
    }
    mp[a]=ex;
  }
  if(n!=1) mp[n]++;
  return;
}


int main(){
  ll n;
  cin >> n;
  ll res=n;
  prime(n);
  for(auto p : mp){
    res*=(p.first-1);
    res/=p.first;
  }
  cout << res << endl;
  return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

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

  vector<string> TELS ={"AC", "WA", "TLE", "RE"};
  vector<int> ans(4);
  string tmp;
  rep(i, N){
    cin >> tmp;
    rep(j,4){
      if(tmp == TELS.at(j)){
        ans.at(j)++;
      }
    }
  }
  rep(i,4){
    cout << TELS.at(i) << " x " << ans.at(i) << endl;
  }
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
class Sharyou {
	Sharyou *prev, *back;
public:
	char ch;
	Sharyou(const char &c = ' ') :prev{ nullptr }, back{ nullptr }, ch{ c } {};
	void set_prev(Sharyou &p) {
		prev = &p;
	}
	void set_back(Sharyou &b) {
		back = &b;
	}
	std::string to_s() const {
		auto front = top();
		return front.to_string();
	}
private:
	Sharyou top() const {
		if (prev) {
			return prev->top();
		}
		else {
			return (*this);
		}
	}
	std::string to_string(std::string res = "") const {
		res.push_back(ch);
		if (back) {
			return back->to_string(res);
		}
		else {
			return res;
		}
	}
};
std::vector<Sharyou> init() {
	std::vector<Sharyou> vector(26);
	char ch = 'a';
	for (auto i = 0; i < 26; ++i, ++ch) {
		vector.at(i).ch = ch;
	}
	return vector;
}
int main() {
	int n;
	std::cin >> n;
	for (; n > 0; --n) {
		std::string str;
		std::cin >> str;
		std::vector<Sharyou> vector = init();
		for (auto i = 3; i < str.size(); i += 3) {
			switch (str.at(i - 1)) {
			case '>':
				vector.at(str.at(i) - 'a').set_prev(vector.at(str.at(i - 3) - 'a'));
				vector.at(str.at(i - 3) - 'a').set_back(vector.at(str.at(i) - 'a'));
				break;
			case '-':
				vector.at(str.at(i) - 'a').set_back(vector.at(str.at(i - 3) - 'a'));
				vector.at(str.at(i - 3) - 'a').set_prev(vector.at(str.at(i) - 'a'));
			}
		}

		std::cout << vector.at(str.at(0) - 'a').to_s() << '\n';
	}
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1e18;
const ll mod=1e9+7;
const ll maxn=1e5;
bool srts(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    //if(a.second==b.second)return a.first>b.first;
    if(a.first==b.first)return a.second>b.second;
    return (a.first > b.first); 
}
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    ll a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b});
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define lowbit(x) x&(-x)
#define PA pair<int, int>
#define MK make_pair
#define inf 0x3f3f3f3f
#define fi first
#define se second
using namespace std;
typedef long long LL;
inline LL read()
{
	LL l = 0, f = 1;
	char a = getchar();
	for (; a < '0' || a > '9'; a = getchar())
		if (a == '-') f = -1;
	for (; a >= '0' && a <= '9'; a = getchar())
		l = l*10+a-48;
	return l*f;
}
const LL N = 100005;
LL n, ans, a[N];
int main(int argc, char const *argv[])
{
	n = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	a[++n] = 0;
	for (int i = 1; i <= n; ++i) ans += abs(a[i]-a[i-1]);
	for (int i = 1; i < n; ++i)
	{
		LL tmp = ans;
		tmp -= abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
		tmp += abs(a[i+1]-a[i-1]);
		printf("%lld\n", tmp);
	}
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
using namespace std;
int main(){
  string str;
  int n;
  cin >> n;
  cin.ignore();
  while(n--){
  getline(cin,str);

    for(int pos = str.find("Hoshino") ; pos != string::npos ;
	pos = str.find("Hoshino",7 + pos ))
      {
	str.replace(pos,7,"Hoshina");
      }
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N, vector<int>(N));
    rep(i,N) G[i][i] = 1;
    rep(i,M) {
        int u,v; cin >> u >> v;
        --u; --v;
        G[u][v] = G[v][u] = 1;
    }

    vector<int> dist(N,1e9);
    vector<bool> seen(N);
    vector<int> A;
    rep(i,N) {
        if (seen[i]) continue;
        queue<int> que;
        que.emplace(i);
        vector<int> check;
        seen[i] = 1;
        dist[i] = 0;
        check.emplace_back(i);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            rep(j,N) {
                if (!G[v][j]) {
                    if (seen[j]) {
                        if (dist[j]%2 != (dist[v]+1)%2) {
                            cout << -1 << ln;
                            return 0;
                        }
                        continue;
                    }
                    dist[j] = dist[v]+1;
                    seen[j] = true;
                    que.emplace(j);
                    check.emplace_back(j);
                }
            }
        }

        int even = 0, odd = 0;
        for (auto i : check) {
            if (dist[i]&1) odd++;
            else even++;
        }
        A.emplace_back(abs(odd-even));
    }

    int L = A.size();
    vector<bitset<1500>> dp(L+1);
    dp[0][750] = 1;
    rep(i,L) {
        dp[i+1] |= (dp[i]<<A[i]);
        dp[i+1] |= (dp[i]>>A[i]);
    }
    int d;
    rep(i,700) {
        if (dp[L][750+i]) {
            d = i;
            break;
        }
    }
    int o = (N+d)/2;
    int e = (N-d)/2;
    cout << o*(o-1)/2 + e*(e-1)/2 << ln;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    string s; cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
Ws = np.array(list(map(int,input().split())))

ret = []
for i in range(N):
  s1 = Ws[:i+1].sum()
  s2 = Ws[i+1:].sum()
  ret.append(abs(s1-s2))
  
print(min(ret))


Measured memory_bytes: 12452
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;
int main() {

    int number_of_cities,number_of_roads,i,j,k;
    map<int,int> road_to_city;

    cin >> number_of_cities >> number_of_roads;

    for(i = 0 ; i< number_of_cities; i++) {
        road_to_city[i] = 0;
    }

    for(i = 0; i < number_of_roads;i++) {
        cin >> j >> k;
        road_to_city[j-1]++;
        road_to_city[k-1]++;
    }

    for(i = 0; i<number_of_cities;i++){
        cout << road_to_city[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

int getSibling(int);
void print(int);
  
struct Node
{
  int p,l,r;
};

struct Node T[MAX];
int n;
int D[MAX],H[MAX];

int getDepth(int u)
{
  int d = 0;
  while(1)
    {
      u=T[u].p;
      if(u==NIL) break;
      d++;
    }
  return d;
}

main ()
{
  int i,v,l,r;
  scanf("%d",&n);

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

  for(i=0;i<n;i++)
    {
      scanf("%d %d %d",&v,&l,&r);
      T[v].l=l;
      T[v].r=r;
      if(l != NIL) T[l].p=v;
      if(r != NIL) T[r].p=v;
    }

  for(i=0;i<n;i++)
    {
      D[i]=getDepth(i);
      H[i]=0;
    }

  for(i=0;i<n;i++)
    {
      if(T[i].l==NIL && T[i].r==NIL)
	{
	  H[i]=0;
	  int p = T[i].p;
	  int c = 1;
	  while(1)
	    {
	      if(p==NIL) break;
	      if(H[p] < c) H[p]=c;
	      c++;
	      p=T[p].p;
	    }
	}
    }

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

}

int getSibling(int u)
{
  if(T[u].p==NIL) return NIL;
  if(T[T[u].p].l != u && T[T[u].p].l !=NIL) return T[T[u].p].l;
  if(T[T[u].p].r != u && T[T[u].p].r !=NIL) return T[T[u].p].r;
  return NIL;
}

void print(int u)
{
  printf("node %d: ",u);

  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].l !=NIL) deg++;
  if(T[u].r !=NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].p==NIL)
    {
      printf("root\n");
    }
  else if(T[u].l==NIL && T[u].r==NIL)
    {
      printf("leaf\n");
    }
  else
    {
      printf("internal node\n");
    }
}



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

int main(){
    int n;
    cin >> n;
    vector<int> a(n-1);
    vector<int> b(n,0);
    rep(i,n-1) cin >> a[i];
    sort(a.begin(),a.end());
    int i=1, j=0;
    while(i < n){
        if(i==a[j]){
            ++b[i-1];
            ++j;
            continue;
        }else if(i!=a[j]){
            ++i;
            continue;
        }
    } 
    rep(i,n) cout << b.at(i) << "\n";
    return 0;
}

Measured memory_bytes: 4840
//
// author  : Abhishek
//
#include <bits/stdc++.h>

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}


ll power(ll x, ll n, ll m) {
    if (x == 0) {
        return 0;
    }
    if (n == 0) {
        return 1;
    }
    ll ans;
    if (isEven(n)) {
        ll smallAns = power(x, n / 2, m);
        ans = (smallAns * smallAns) % m;
    } else {
        ll smallAns = power(x, n - 1, m);
        ans = x;
        ans = (ans * smallAns) % m;
    }
    // for negative values also
    return (ans + m) % m;

}

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;

    cin >> n;
    vector<ll> arr(n);
    arr = read(n);

    ll ans = 0;

    fo(i, 61) {
        x = 0;
        fo(j, n) {
//            deb(j);
            if (arr[j] != 0 && (arr[j] & 1))
                x++;
            arr[j] >>= 1;
        }
//        deb(i);
//        deb(x);

        ans += ((x * (n - x)) % mod * power(2, i, mod)) % mod;
        ans %= mod;
//        deb(ans);
    }

    cout << ans;

    return 0;
}




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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

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

  int n;
  cin >> n;

  vector<string> a(n);
  trav(i, a) cin >> i;

  using state = tuple<int, int, int, int>; // left close, right open, total diff, len
  vector<state> b(n);
  rep(i, 0, n) {
    int cnt = 0, lc = 0, ro = 0;
    trav(c, a[i])
      lc = max(lc, cnt += (c == ')') ? 1 : -1);
    reverse(all(a[i])); cnt = 0;
    trav(c, a[i])
      ro = max(ro, cnt += (c == ')') ? -1 : 1);
    b[i] = {lc, ro, ro - lc, sz(a[i])};
  }

  
  
  sort(all(b), [&](state s1, state s2) {
		 auto [lc1, ro1, delta1, len1] = s1;
		 auto [lc2, ro2, delta2, len2] = s2;
		 if (delta1 > 0 and delta2 <= 0) {
		   return true;
		 } else if (delta1 <= 0 and delta2 > 0) {
		   return false;
		 } else if (delta1 <= 0 and delta2 <= 0){
		   return tie(ro2, delta1) < tie(ro1, delta2);
		 } else if (delta1 > 0 and delta2 > 0) {
		   return tie(lc1, delta2) < tie(lc2, delta1);
		 } else assert(false);
	       });
  bool good = true;
  int have = 0;
  for (const auto& [lc, ro, diff, len]: b) {
    if (lc > have) {
      good = false;
      break;
    }
    have += diff;
  }
  if (have != 0) good = false;
  cout << (good ? "Yes" : "No") << '\n';
}


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

using namespace std;

int n;
double ans;
double x;
char s[10];
double y = 380000.0;

int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%lf%s",&x,s);
		if(s[0] == 'J') ans += x;
		else ans += x * y;	
	}
	printf("%.6lf",ans);
	return 0;
}


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

int rpow(int n, int m, int o){
    if (m == 0) return 1;
    else {
        int res = rpow(n,m/2,o);
        if (m % 2 == 0) return (res * res) % o;
        else return (((res * res) % o) *n) % o;
    } 
}

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int m, n; cin >> m >> n;
    cout << rpow(m, n, 1000000007) << endl;
    return 0;
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;
  int ans = min(n, m/2);
  m -= ans*2;
  cout << ans + m/4 << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int left = -1, right = n + 1;
  while (right - left > 1) {
    long long mid = (left + right) >> 1;
    if (a[mid] + m < a[n - p]) {
      left = mid;
      continue;
    }
    long long cur = 0;
    for (int i = 0; i < mid; i++) {
      cur += m;
    }
    for (int i = mid + 1; i <= n - p; i++) {
      cur += min(a[mid] + m - a[i], m);
    }
    for (int i = n - p + 1; i < n; i++) {
      cur += m;
    }
    if (cur >= m * (v - 1)) right = mid;
    else left = mid;
  }
  cout << n - left - 1 << '\n';
  return 0;
}

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

int main() {
    int n, x=0, m=0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'I') x++;
        else if (s[i] == 'D') x--;
        if (m < x) m = x;
    }
    cout << m << endl;
}

Measured memory_bytes: 256
n,a=map(int,input().split())
X=list(map(int,input().split()))
dp=[[0]*2501 for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
    x=X[i]
    for j in range(n,0,-1):
    	for k in range(2501-x):
        	dp[j][k+x]+=dp[j-1][k]
ans=0
for i in range(n):
    ans+=dp[i+1][(i+1)*a]
print(ans)

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

const int MAX = 1e5+10;

int N, A, B, C;
string S[MAX];

bool dfs(vector<char> &res, int i) {
    if (i == N) return true;
    int &P = (S[i] == "AB") ? A : ((S[i] == "BC") ? B : C);
    int &Q = (S[i] == "AB") ? B : ((S[i] == "BC") ? C : A);
    int &R = (S[i] == "AB") ? C : ((S[i] == "BC") ? A : B);
    bool p;

    if (P == 0 && Q == 0) return false;
    if (P == 0) p = true;
    else if (Q == 0) p = false;

    else if (i == N-1) p = true;

    else if (S[i] == S[i+1]) {
        if (P > Q) p = false;
        else p = true;
    }

    else if (S[i][0] == S[i+1][1]) p = true;
    else p = false;

    if (p) {
        P++;
        Q--;
        res.push_back(S[i][0]);
    } else {
        P--;
        Q++;
        res.push_back(S[i][1]);
    }
    return dfs(res, i+1);
}

void solve() {
    REP (i, N) if (S[i] == "AC") S[i] = "CA";
    vector<char> res;
    if (dfs(res, 0)) {
        cout << "Yes" << endl;
        FORE (r, res) cout << r << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cin >> N >> A >> B >> C;
    REP (i, N) cin >> S[i];
    solve();
}

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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if (x1 == 0)
    cout << '1' << endl;
  else if (x2 == 0)
    cout << '2' << endl;
  else if (x3 == 0)
    cout << '3' << endl;
  else if (x4 == 0)
    cout << '4' << endl;
  else if (x5 == 0)
    cout << '5' << endl;
}


Measured memory_bytes: 3600