akhauriyash/Code-Regression huggingface dataset:
n, k = gets.split(" ").map(&:to_i)

h = Hash.new(0)

k.times do |i|
  d = gets.to_i
  
  aa = gets.split(" ").map(&:to_i)
  aa.each do |a|
    h[a] += 1
  end
end

ans = 0
(1..n).each do |i|
  ans += 1 if h[i] == 0
end
puts ans

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    string a;
    cin>>a;
    int b[26]={0};
    rep(i,a.size()){
        b[a[i]-'a']++;
    }
    rep(i,26){
        if(b[i]%2!=0){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)


int main()
{
   ll t,n,i,j,k,l,mn=0, mx=0;
   sl(k);
   ll sum=0;
   for(int i=1; i<=1000005; i++)
   {
      sum*=10;
      sum+=7;
      sum%=k;
      if(sum==0)
      {cout<<i; return 0;}
   }
   cout<<-1<<endl;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
vector<int> G[MAX_N];
int D[MAX_N];
int ans = 0;

int loop(int v, int p) {
	vi vp;
	rep(i, 0, sz(G[v])) {
		int n = G[v][i];
		if(n == p) continue;
		vp.pb(loop(n, v));
	}
	if(sz(vp) == 1) {
		return vp[0];
	}
	else if(sz(vp) >= 2) {
		int res = 0;
		rep(i, 0, sz(vp)) {
			res += vp[i] ^ 1;
		}
		ans += max(res - 1, 0);
		return 1;
	}
	else return 0;
}

void solve() {
	cin >> N;
	rep(i, 0, N - 1) {
		int a, b;
		cin >> a >> b;
		G[a].pb(b);
		G[b].pb(a);
		D[a]++; D[b]++;
	}
	int root = -1;
	rep(i, 0, N) {
		if(D[i] >= 3) {
			root = i;
			break;
		}
	}
	if(root == -1) {
		cout << 1 << "\n";
	}
	else {
		loop(root, -1);
		cout << ans << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

a, p = [1], [1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(n, x):
    if n == 0:
        return 1
    if x == 1:
        return 0
    elif 1 < x <= a[n-1] + 1:
        return f(n-1, x-1)
    elif x == a[n-1] + 2:
        return p[n-1] + 1
    elif a[n-1] + 2 < x < 2 * a[n-1] + 2:
        return p[n-1] + 1 + f(n-1, x-a[n-1]-2)
    else:
        return 2 * p[n-1] + 1

print(f(N, X))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  int n, c[9];rep(i,9)c[i] = 0;cin>>n;
  int a;
  rep(i,n){
    cin>>a;
    int b = 0;
    a -= 400;
    while(a >= 0){
      a-=400;b++;
    }
    if(b > 8)b = 8;
    c[b]++;
  }
  int ans = 0;
  rep(i,8)ans += int((bool)c[i]);
  if(ans == 0){
    cout << "1 " << c[8] << endl;
  }else{
    cout << ans << " " << ans + c[8] << endl;
  }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	int n;
	cin>>n;
	set<string> s;
	for (int i=0;i<n;i++){
		string str;
		cin>>str;
		s.insert(str);
	}
	
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 19256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#define INF 1e9+1
using namespace std;
int N;
long long ans;
int A[200001];
int l[100002],r[100002];
long long  merge(int a[],int n,int left,int mid,int right){
  int n1=mid-left,n2=right-mid;
  long long cnt=0;
  for(int i=0;i<n1;i++)l[i]=a[i+left];
  for(int i=0;i<n2;i++)r[i]=a[i+mid];
  
  l[n1]=INF;r[n2]=INF;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    if(l[i]<=r[j]){a[k]=l[i];i++;}
    else {a[k]=r[j];j++;cnt+=(n1-i);}
  }
  return cnt;
}
long long  mergesort(int a[],int n,int left,int right){
  if(left+1>=right)return 0;
  long long v1,v2,v3;
  int mid=(left+right)/2;
  v1=mergesort(a,n,left,mid);
 
  v2=mergesort(a,n,mid,right);
 
  v3=merge(a,n,left,mid,right);
 
  return v1+v2+v3;
}
int main(){
  
  scanf("%d",&N);
  for(int i=0;i<N;i++)scanf("%d",&A[i]);
  ans=mergesort(A,N,0,N);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 1000000007;
// const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;


const int MAX_n = 100000;
int n, p[MAX_n];
bool f[MAX_n];

signed main(){

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


    int ans = 0;

    bool bef = 0;
    for(int i = 0;i < n;i++){
        if(f[i] == 1 && bef == 0){
            ans++;
            bef = 1;
        }else{
            bef = 0;
        }
    }
    cout<< ans<< endl;

    return 0;
}

Measured memory_bytes: 1152
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, P, = map(int, input().split())
# N, = map(int, input().split())
# L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()

# prime = [True] * (int(P ** 0.5) + 1)
# prime[0] = False
# prime[1] = False
# for n in range(2, len(prime)):
#     if prime[n] == False:
#         continue

#     for v in range(n * 2, len(prime), n):
#         prime[v] = False

# p = [v for v in range(len(prime)) if prime[v] == True]

s = defaultdict(int)
for v in range(2, int(P ** 0.5) + 1):
    while P % v == 0:
        P = P // v
        s[v] += 1
if P != 1:
    s[P] += 1

ans = 1
for k, v in s.items():
    if v >= N:
        ans *= k ** (v // N)
print(ans)

Measured memory_bytes: 3444
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
ll mod = 1e9+7;
ll dp[105][10];
ll hoge[105];
int main(){
    int H,W,K;
    cin >> H >> W >> K;
    dp[0][1] = 1;
    hoge[0] = 1;
    hoge[1] = 1;
    for(int i = 2; i<= 104;i++){
        hoge[i] = hoge[i-1] + hoge[i-2];
        hoge[i] %= mod;
    }
    rep(i,H){
        for(int j = 1; j<= W; j++){
            (dp[i+1][j] += dp[i][j]*hoge[j-1]%mod*hoge[W-j]%mod)%=mod;
            if(W-j-1>=0)(dp[i+1][j+1] += dp[i][j]*hoge[j-1]%mod*hoge[W-j-1]%mod)%=mod;
            if(j>=2)(dp[i+1][j-1] += dp[i][j]*hoge[j-2]%mod*hoge[W-j]%mod)%=mod;
        }
    }
    cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist

n, m, q = [ int(v) for v in input().split() ]

train_list = [ [ 0 for i in range(n) ] for i in range(n) ]
for i in range(m):
    a, b = [ int(v)-1 for v in input().split() ]
    train_list[a][b] += 1

train_cumsumx_list = [ cumsum(i) for i in train_list ]
train_cumsumx_list_t = [ [ train_cumsumx_list[i][j] for i in range(n) ] for j in range(n) ]
train_cumsum_list_t = [ cumsum(i) for i in train_cumsumx_list_t ]
train_cumsum_list = [ [0] * n ] + [ [ train_cumsum_list_t[i][j] for i in range(n) ] for j in range(n) ]


for i in range(q):
    c, d = [ int(v)-1 for v in input().split() ]
    print(train_cumsum_list[-1][d] - train_cumsum_list[c][d])

Measured memory_bytes: 65372
import java.util.*;
public class Main{
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();

      if (n < 1000) {
         System.out.println("ABC");
      }
      else {
         System.out.println("ABD");
      }
   }
}

Measured memory_bytes: 21972
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    long A = Long.parseLong(S[1]);
    long B = Long.parseLong(S[2]);
    
    int[] num = new int[N];
    for(int i = 0; i < N; i++){
      num[i] = Integer.parseInt(sc.next());
    }
    
    long[] dis = new long[N-1];
    for(int i = 0; i < N-1; i++){
      dis[i] = (num[i+1] - num[i]) * A;
      if(dis[i] > B){
        dis[i] = B;
      }
    }
    
    long ans = 0;
    for(int i = 0; i < N-1; i++){
      ans += dis[i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 47680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define INF 1000000000000000000
#define all(x) x.begin(), x.end()

int main() {
    string s, t;
    cin >> s >> t;

    int n, m;
    n = s.length();
    m = t.length();
    int dp[n + 1][m + 1];
    memset(dp, 0, sizeof(dp));

    rep(i, s.size()) {
        rep(j, t.size()) {
            if (s[i] == t[j])
                dp[i + 1][j + 1] =
                    max(dp[i][j] + 1, max(dp[i + 1][j], dp[i][j + 1]));
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
        }
    }

    string ans = "";
    int x = n;
    int y = m;
    while (x > 0 && y > 0) {
        if (dp[x][y] == dp[x - 1][y])
            x--;
        else if (dp[x][y] == dp[x][y - 1])
            y--;
        else {
            x--;
            y--;
            ans.push_back(s[x]);
        }
    }

    reverse(all(ans));
    cout << ans << endl;
}

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

int main() {
  int r,D,x;
  cin >> r >> D >> x;
  int A;
  
  for (int i = 0; i < 10; i++) {
    A = r*x - D;
    cout << A << endl;
    x = A;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

ll llpow(ll a,ll b){
  if (b == 0) return 1;
  return a*llpow(a,b-1);
}

int main(){
  ll k;
  cin >> k;
  ll ans = 1;
  int range = k;
  vector<ll> mods(range,1);
  rep(i,range-1){
    mods[i+1] = mods[i]*10;
    mods[i+1] %= k;
  }
  ll mod = 0;
  map<ll,ll> check;
  rep(i,range){
    mod += 7*mods[i];
    mod %= k;
    if(check[mod] > 0){
      cout << -1 << endl;
      return 0;
    }
    check[mod] = 1;
    if(mod == 0){
      cout << ans << endl;
      return 0;
    }
    ans ++;
  }
}


Measured memory_bytes: 73384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	ll a; ld b; scanf("%lld%Lf", &a, &b);
	ll c = b * 100 + 0.1;
	DEBUG("%lld %Lf %lld\n", a, b, c);
	printf("%lld\n", a * c / 100);
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
  using namespace std;
  typedef long long ll;
  int main()
  {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);

      ll n,q,a,b;
      ll sum=0;
      cin>>n;
      vector<ll>v(n),freq(100001,0);
      for(int i=0;i<n;i++)
        {cin>>v[i];
          sum+=v[i];
         freq[v[i]]++;
        }
      cin>>q;

      while(q--)
      {
          cin>>a>>b;
          if(!freq[a])
          {
              cout<<sum<<endl;
              continue;
          }
          ll f=freq[a];
          sum-=a*f;
          freq[a]=0;
          sum+=b*f;
          freq[b]+=f;
          cout<<sum<<endl;
      }


    return 0;
  }


Measured memory_bytes: 4788
#include<bits/stdc++.h>
#define fr(i,j,n)   for(int i=j;i<n;i++)
#define pb          push_back
#define rf(i,j,p)   for(int i=p;i>=j;i--)
#define vi          vector<int>
#define vll         vector<long long>
#define ll          long long
#define hmm         "\n"
#define sp          " "
#define srt(v)      sort(v.begin(), v.end());
#define down        cout<<hmm;
#define faaast      ios_base::sync_with_stdio(0);cin.tie(nullptr);
using namespace std;
int main()
{
 int n ; cin >> n ;
 int a[3*n];
 fr(i,0,3*n)cin>>a[i];
 sort(a,a+3*n);
 int i = 2 ; ll sum = 0, cnt=0 ;
 while(cnt<n)
 {
     sum+=a[3*n-i];
     i+=2;
     cnt++;
     
 }
cout<<sum<<hmm;
 //return main();
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<int> vec;
  rep(i,n){
    ll a;cin >> a;
    vec.push_back(a-(i+1));
  }
  sort(all(vec));
  ll b = vec[(n-1)/2];
  ll ans = 0;
  rep(i,n){
    ans += abs(vec[i]-b);
  }
  cout << ans << endl;

}

Measured memory_bytes: 1400
import math

x = int(input())

flg = False
for i in range(math.floor(x / 4) + 1):
  for j in range(math.floor(x / 7) + 1):
      if x - i * 4 - j * 7 == 0:
        flg = True
        break
if flg:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));

struct mint {
	int x;
	mint(int x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a)const {
		return mint(*this) += a;
	}
	mint operator-(const mint a)const {
		return mint(*this) -= a;
	}
	mint operator*(const mint a)const {
		return mint(*this) *= a;
	}
	mint pow(int t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a)const {
		mint res(*this);
		return res /= a;
	}
};

signed main() {
	int N;
	cin >> N;
	map<int, int>m;
	for (int n = 2; n <= N; n++) {
		int a = n;
		for (int i = 2; i <= a; i++) {
			while (a % i == 0) {
				m[i]++;
				a /= i;
			}
		}
	}
	mint ans = 1;
	for (auto i : m)ans *= i.second + 1;
	cout << ans.x << endl;
}

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

struct MyList{
	int data;
	MyList *next;
};

class MyQueue{
	MyList *head;
	MyList *tail;
public:
	MyQueue();
	~MyQueue();
	void enqueue(int data);
	int dequeue();
	bool isEmpty();
};
MyQueue::MyQueue()
{
	head = NULL;
	tail = NULL;
}
MyQueue::~MyQueue()
{
	while (head)
		dequeue();
}
void MyQueue::enqueue(int data)
{
	if (!head){
		head = new MyList;
		head->data = data;
		head->next = NULL;
		tail = head;
		return;
	}

	tail->next = new MyList;
	tail = tail->next;
	tail->data = data;
	tail->next = NULL;
	return;
}
int MyQueue::dequeue()
{
	int temp;
	MyList *lTemp;

	if (!head){
		cout << "error" << endl;
		return 0;
	}
	if (!head->next){
		temp = head->data;
		delete head;
		head = NULL;
		tail = NULL;
		return temp;
	}
	temp = head->data;
	lTemp = head;
	head = head->next;
	delete lTemp;
	lTemp = NULL;
	return temp;
}
bool MyQueue::isEmpty()
{
	if (!head) return false;
	else return true;
}

int main()
{
	MyQueue *queue1 = new MyQueue;
	MyQueue *queue2 = new MyQueue;
	int x, y;
	int a, b;

	while (true){
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		queue1->enqueue(x);
		queue2->enqueue(y);

	}

	while (queue1->isEmpty()){
		a = queue1->dequeue();
		b = queue2->dequeue();
		if (a < b) cout << a << ' ' << b << endl;
		else cout << b << ' ' << a << endl;
	}
		

	delete queue1;
	delete queue2;

	return 0;
}

Measured memory_bytes: 1316
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n; cin >> n;
  int ar[n];

  for(int i=0;i<n;i++) cin >> ar[i];

  int minn = ar[0];
  int cnt = 1;


  for(int i=1;i<n;i++){
    if(ar[i]<=minn){
      cnt++;
    }
    minn = min(minn,ar[i]);
  }

  cout << cnt;
  

  return 0;
}

Measured memory_bytes: 1792
N = int(input())
H = input().split()
L = [0,abs(int(H[1])-int(H[0]))]
if N != 2:
  for i in range(2,N):
    A = abs(int(H[i])-int(H[i-2]))+L[i-2]
    B = abs(int(H[i])-int(H[i-1]))+L[i-1]
    if A <= B:
      L.append(A)
    else:
      L.append(B)
  print(L[N-1])
else:
  print(abs(int(H[1])-int(H[0])))

Measured memory_bytes: 14024
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
		template <class T> auto operator[](T t) const { (*this)(t); return t; }
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on





auto Main() {
	const int n=Cin[0], k=Cin[0];
	auto A = Cin[vector<ll> (n)];

	FOR(i,0,n) {
		int j = i+k;
		if(j>=n) break;
		if(A[j]>A[i]) Cout("Yes");
		else Cout("No");
	}	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


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

map<pint,int> mp;
map<pint,bool> used;

const int mod = 1e9+7;

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

void normalization(int &A, int &B){
  
  int c = abs(A); int d = abs(B);
  
  if( c == 0 && d == 0 ){ 
    A = 0; B = 0;
    return;
  }//ゼロベクトルは特別扱い
  else if( c == 0 || d == 0 ){ 
    if( c == 0 ){ 
      B = 1;
    }
    else{
      A = 1;
    }
    return;
  }//軸に平行なベクトルは(1,0)か(0,1)として扱う
  
  int g = gcd(c,d);
  
  c /= g; d /= g;
  
  if( ( A > 0 && B > 0 ) || ( A < 0 && B < 0) ){ 
    
    A = c; B = d;
  }
  else{
    
    A = c; B = -d;
    
  }
  //同符号の時は両方とも正に、異符号の時はAを正、Bを負とする
  
  return ;
} 

int p2(int a){ 
  if( a == 0 ){ return 1LL;}
  else if( a == 1 ){ return 2LL;} 
  else{ 
    if( a % 2 == 0 ){ 
      return (p2(a/2)*p2(a/2))%mod;
    }
    else{ 
      return (( (p2((a-1)/2)) * (p2((a-1)/2)) % mod )*2LL)%mod;
    }
  }
}
              
              
  

signed main(void){ 
  
  int N; cin >> N;
  for(int i = 0;  i < N; i++){ 
    int A,B; cin >> A >> B;
    normalization(A,B);
    mp[{A,B}]++;
  }
  
  int ans = 1LL;
  int zero = 0;
  
  for(auto u : mp){ 
    
    auto p = u.first;
    
    if( used[p] ){ continue; } 
    
    int a = p.first; int b = p.second;
    
    if( a == 0 && b == 0 ){ 
      //ゼロベクトルはこれ単体で選ぶことしかできない
      
      zero += u.second;
      
      used[{0,0}] = true;
      
    }
    else{
      
      if( a == 0 || b == 0 ){ 
        // ( 1,0 )　と　(0,1)を組んではならないパターン
        
        int x = mp[{1,0}];
        int y = mp[{0,1}];
        
        ans *= (1+(p2(x)-1)+(p2(y)-1)+mod)%mod;
        ans %= mod;
        used[{1,0}] = used[{0,1}] = true;
      }
      else{
        
        if( ( a > 0 && b > 0 ) || ( a < 0 && b < 0 ) ){ 
          // ( b,-a)と組んではならない
          
          int x = mp[{a,b}];
          int y = mp[{b,-a}];
          
          ans *=(1+(p2(x)-1)+(p2(y)-1)+mod)%mod;
          ans %= mod;
          used[{a,b}] = used[{b,-a}] = true;
        }
        else{
          //(-b,a)と組んではならない
          
          int x = mp[{a,b}];
          int y = mp[{-b,a}];
          
          ans *=(1+(p2(x)-1)+(p2(y)-1)+mod)%mod;
          ans %= mod;
          used[{a,b}] = used[{-b,a}] = true;
          
        }
      }
    }
  }
  
  ans = (ans+zero-1+mod)%mod;
  
  cout << ans << endl;
  
  return 0;
}

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

int para(int a,int b){
  if(a%b==0)return 2*a-b;
	else return a/b*2*b+para(b,a%b);
}



signed main(){
	int n,x;cin>>n>>x;
	int ret=0;
	int y=n-x;
	if(y<x)swap(x,y);
	ret=n+para(y,x);
	cout<<ret<<endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.math.BigInteger;

class Main {
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        BigInteger a, b;
        String sum;
        StringBuilder sb = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            a = new BigInteger(br.readLine());
            b = new BigInteger(br.readLine());
            sum = a.add(b).toString();
            if (sum.length() > 80) {
                sb.append("overflow");
            } else {
                sb.append(sum);
            }
            sb.append('\n');
        }

        System.out.print(sb);
    }
}

Measured memory_bytes: 24408
#include<stdio.h>

int main(void)
{

    int n, a, b, c, i;

    scanf("%d", &n);

    for(i = 0; i < n; i++) {
        scanf("%d %d %d", &a, &b, &c);
        if(a * a + b * b == c * c || a * a + c * c == b * b || c * c + b * b == a * a)
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 580
#include "stdio.h"

int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        int count = 0;
        for (int a = 0; a <= 9; a++)
        {
            for (int b = 0; b <= 9; b++)
            {
                for (int c = 0; c <= 9; c++)
                {
                    for (int d = 0; d <= 9; d++)
                    {
                        if (a + b + c + d == n)
                            count++;
                    }
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 2588
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = 0;
    int max = 0;
    rep(i, n){
        if(max <= h[i]){
            ans++;
            max = h[i];
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  
  int ans;
  int count=0;
  for(int i = min(a, b); i != 0; --i){
    if ((a % i == 0) && (b % i == 0)) count++;
    if (count == k){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

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

    int sum = 0;
    int i=0;
    for(i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            sum = sum + d[i] * d[j];
        }
    }

    printf("%d", sum);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll cnt,sum;
template<typename T>
inline void read(T& x)
{
	x=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
}
int main()
{
	int n,d;ll c;
	read(n);
	while(n--)
	{
		read(d),read(c);
		cnt+=c,sum+=c*d;
	}
	printf("%lld\n",cnt-1+(sum-1)/9);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
	int N = sc.nextInt();
	for(int i = 0; i<N; i++) {
	    int x = sc.nextInt();
	    int c = (map.containsKey(x))? map.get(x):0;
	    map.put(x,c+1);
	    c = (map.containsKey(x-1))? map.get(x-1):0;
            map.put(x-1,c+1);
	    c = (map.containsKey(x+1))? map.get(x+1):0;
            map.put(x+1,c+1);
	}
	int max = 0;
	for(int key: map.keySet()) {
	    max = Math.max(map.get(key),max);
	}
	System.out.println(max);
    }
}

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

int main()
{
  int64_t n,ans;
  cin>>n;
  ans=1;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
    if(a.at(i)==0)
    {
      ans=0;
      break;
    }
  }
  for(int i=0;i<n;i++)
  {
    if(ans==0)
    {
      break;
    }
    else if(1000000000000000000/ans<a.at(i))
    {
      ans=-1;
      break;
    }
    ans*=a.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3972
function main(input){
  let lines = input.split("\n");
  let N = lines[0];
  let A = lines[1].split(" ");
  console.log(lines[1]);
  for(let i = 1; i <= A.length - 1;i++){
    let v = Number(A[i]);
    let j = i - 1;
    while(j >=0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    console.log(A.join(" "))
  }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 16552
#include<cmath>
#include<iostream>

using namespace std;

int main(){
  int n, b, a = 0;

  while (cin >> n >> b) {
    int x, sum = 0;;
    for (int i = 0; i < n; i++) {      
      cin >> x;
      int ax = abs(a - x);
      int bx = abs(b - x);
      
      if (ax < bx) {
	sum += ax * 2;
      } else {
	sum += bx * 2;
      }
    }

    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
 
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
 char C;
 cin >> C;
  for(int i=0;i<26;i++){
  	if(alphabet.at(i)==C){
    	cout << alphabet.at(i+1);
      	return 0;
    }
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>

int n, m, hit, d;
char dan[30][11];

int amida() {
  int i;
  int cur = m;
  for (i = 0; i < d; ++i) {
    // right
    if (cur < n && dan[i][cur - 1] == '1') {
      cur = cur + 1;
    }
    // left
    else if (cur > 1 && dan[i][cur - 2] == '1') {
      cur = cur - 1;
    }
  }
  return cur == hit;
}


void solve() {
  int i, j;
  if (amida()) {
    puts("0");
    return;
  }
  
  for (i = 0; i < d; i++) {
    for (j = 0; j < n - 1; j++) {
      if (dan[i][j] == '0') {
        if (j > 0 && dan[i][j-1] == '1') continue;
        if (j < n - 2 && dan[i][j+1] == '1') continue;
        dan[i][j] = '1';
        if (amida()) {
          printf("%d %d\n", i+1, j+1);
          return;
        }
        dan[i][j] = '0';
      }
    }
  }

  puts("1");
}

int main() {
  int i;
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;

    scanf("%d\n%d\n%d\n", &m, &hit, &d);
    for (i = 0; i < d; i++) {
      scanf("%s\n", dan[i]);
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
S = input()
N = len(S)

a_ = int((N-1)//2)
b_ = int((N+3)//2 -1)
a = S[:a_]
b = S[b_:N+1]

if S == S[::-1] and a == a[::-1] and b == b[::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (w, h, x, y, r) = readLine()!!.split(" ").map(String::toInt)
    when {
        x - r < 0 || y - r < 0 || x + r > w || y + r > h -> println("No")
        else -> println("Yes")
    }
}


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

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

    if((b % a))
    {
        cout << abs(a - b) << endl;
    }
    else
    {
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>

int main() {
	int n, a; std::cin >> n >> a;
	std::vector<int> cards(n); for (auto& c : cards) std::cin >> c;
	std::vector<std::vector<long long int>> pattern(n + 1, std::vector<long long int>(a * n + 1, 0));
	pattern[0][0] = 1;
	for (const auto c : cards) {
		for (int i = pattern.size() - 2; i >= 0; --i) {
			for (auto j = 0; j + c < pattern[i].size(); ++j) if (pattern[i][j] != 0) {
				pattern[i + 1][j + c] += pattern[i][j];
			}
		}
	}
	long long int result{ 0 };
	for (auto i = 1; i < pattern.size(); ++i) {
		result += pattern[i][i * a];
	}
	std::cout << result << '\n';
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define fr(a, b, c) for(int a = b, __ = c; a < __; ++a)
#define dbg(x) cerr << ">>>> " << x << endl;
#define _ << " , " << 

using namespace std;

const int mv = 111111;
typedef long long int ll;

int a[mv];

int main(){
	ios::sync_with_stdio(0);
	int n, x;
	cin >> n >> x;
	fr(i, 0, n)
		cin >> a[i];
	
	ll cnt = 0;
	fr(i, 0, n){
		if(a[i] > x){
			cnt += ll (max(0, a[i] - x));
			a[i] = x;
		}
	}


	fr(i, 0, n-1){
		if(a[i] + a[i+1] > x){
			cnt += ll(a[i] + a[i+1] - x);
			a[i+1] -= a[i] + a[i+1] - x;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;


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

  int a, b;
  cin >> a >> b;
  cout << (a * (a - 1) + b * (b - 1)) / 2 << "\n";
}


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

int main() {
  long long N,M,X,x,y,ans,g;
  cin>>N>>M>>X;
  ans=0;
  x=N%2+M%2+X%2;
  if(x==0){
    g=max(N,max(M,X));
  ans=(g-N)/2+(g-M)/2+(g-X)/2;

  }
  else if(x==1){
    if(N%2==0){
      N++;
    }
        if(M%2==0){
      M++;
    }
        if(X%2==0){
      X++;
    }
       g=max(N,max(M,X));
       ans=(g-N)/2+(g-M)/2+(g-X)/2+1;
  }
    else if(x==2){
    if(N%2==1){
      N++;
    }
        if(M%2==1){
      M++;
    }
        if(X%2==1){
      X++;
    }
       g=max(N,max(M,X));
       ans=(g-N)/2+(g-M)/2+(g-X)/2+1;
  }
  else{
           g=max(N,max(M,X));
       ans=(g-N)/2+(g-M)/2+(g-X)/2;
  }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

int treeSearch(Node u, int k){

  if(u->key == k){
    return 1;
  }
  else if(k<u->key){
    if(u->left != NIL){
      return treeSearch(u->left,  k);
    }
  }
  else {
    if(u->right != NIL){
    return treeSearch(u->right, k);
    }
  }

  return NIL;
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y==NIL){
    root =z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }

}

void inorder(Node u){

  if(u->left!=NIL){
    inorder(u->left);
  }

  printf(" %d", u->key);

  if(u->right!=NIL){
    inorder(u->right);
  }

}
void preorder(Node u){

  printf(" %d", u->key);

  if(u->left!=NIL){
    preorder(u->left);
  }

  if(u->right!=NIL){
    preorder(u->right);
  }

}


int main(){
  int n, i, x, t;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
       t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20496
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int n, m, w[301000], s, M, P[201000], cnt;
vector<int>E[201000];
priority_queue<int>PQ;
int main() {
	int i, b, e, j;
	scanf("%d%d", &n,&m);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &b, &e);
		E[b].push_back(e);
	}
	for (i = 0; i <= m; i++) {
		for (j = 0; j < E[i].size(); j++) {
			PQ.push(-E[i][j]);
		}
		while (PQ.size() > i) {
			P[cnt++] = -PQ.top();
			PQ.pop();
		}
	}
	int s = 0, r = PQ.size(), sz = PQ.size();
	for (i = 0; i < cnt; i++) {
		P[i] = max(P[i], sz + 1);
		w[P[i]]++;
	}
	for (i = m; i > sz; i--) {
		s++;
		r += min(s, w[i]);
		s -= min(s, w[i]);
	}
	printf("%d\n", n - r);
}

Measured memory_bytes: 11132
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outc(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(32);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, int k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
//ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
//Unaccepted
const int maxn = 2e5 + 10;
int a[maxn], cnt[maxn];
//cnt是桶
vector<int> vi;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = n; i >= 1; --i){
        int cur = 0;
        for (int j = 1; j * i <= n; ++j) cur += cnt[j * i];
        if (cur % 2 != a[i]){
            cnt[i] = 1;
            vi.emplace_back(i);
        }
    }
    bool exist = 1;
    for (int i = 1; i <= n; ++i){
        int cur = 0;
        for (int j = 1; j * i <= n; ++j) cur += cnt[j * i];
        if (cur % 2 != a[i]){
            exist = 0;
            break;
        }
    }
    if (!exist){
        cout << "-1" << endl;
        return 0;
    }
    cout << vi.size() << '\n';
    for (int e : vi) cout << e << ' ';
	return 0;
}


Measured memory_bytes: 2936
/*
	*	Created By: 'Present_Sir'
	*	Created On: Sunday 02 August 2020 06:34:51 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;


void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cntR=0,cntW=0,lr=0;
    for(int i=0; i<n; i++){
        if(s[i] == 'R'){
            lr=i;
            cntR++;
        }else{
            cntW++;
        }
    }
    if(min(cntR,cntW) == 0){
        cout<<"0"<<endl;
    }else{
        int j=0,ans=0;
        while(lr>j){
            while(lr>j and s[lr] == 'W')
                --lr;
            if( lr == j)
                continue;
            while(j<lr and s[j]=='R')
                ++j;
            if( lr == j )
                continue;
            swap(s[lr],s[j]);
            lr--;
            ans++;
        }
        cout<<min({ans,cntR,cntW})<<endl;
    }
}

int32_t main(){
    IOS;
    //int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3732
import heapq
from collections import defaultdict
N, M = map(int, input().split())
AB = defaultdict(list)
for _ in range(N):
    a, b = map(int, input().split())
    AB[a].append(b)
# print(AB)
h = []
ans = 0
for i in range(1, M+1):
    if i in AB:
        for x in AB[i]:
            heapq.heappush(h, - x)
    if len(h) > 0:
        ans -= heapq.heappop(h)
print(ans)

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

int main(){
  int t,n;
  for(int i = 0; i < 4;i++){
    int result = 0;
    cin >> t >> n;
    switch (t) {
      case 1:
      result = 6000*n;
      break;
      case 2:
      result = 4000*n;
      break;
      case 3:
      result = 3000*n;
      break;
      case 4:
      result = 2000*n;
      break;
    }
    cout << result << endl;
  }
}

Measured memory_bytes: 1164
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: u64 = sc.read();
    let b: u64 = sc.read();
    let ans = construct(a, b, 1 << n);
    if ans.is_empty() {
        println!("NO");
    } else {
        sc.write("YES\n");
        for (i, ans) in ans.into_iter().enumerate() {
            if i > 0 {
                sc.write(" ");
            }
            sc.write(format!("{}", ans));
        }
        sc.write("\n");
    }
}

fn construct(first: u64, last: u64, n: usize) -> Vec<u64> {
    let diff = first ^ last;
    if diff.count_ones() % 2 == 0 {
        return Vec::new();
    }
    if n == 2 {
        return vec![first, last];
    }
    let diff_pos = (0..).find(|&i| diff & (1 << i) != 0).unwrap();

    let prefix_add = (first >> diff_pos) & 1;
    let suffix_add = (last >> diff_pos) & 1;
    assert_ne!(prefix_add, suffix_add);

    let prefix_first = remove(first, diff_pos);
    let prefix_last = prefix_first ^ 1;
    let suffix_first = prefix_first ^ 1;
    let suffix_last = remove(last, diff_pos);

    let prefix = construct(prefix_first, prefix_last, n / 2);
    let suffix = construct(suffix_first, suffix_last, n / 2);
    if prefix.is_empty() || suffix.is_empty() {
        return Vec::new();
    }

    let mut v = vec![];
    for t in prefix.into_iter() {
        v.push(insert(t, diff_pos, prefix_add));
    }
    for t in suffix.into_iter() {
        v.push(insert(t, diff_pos, suffix_add));
    }

    v
}

fn remove(v: u64, pos: u64) -> u64 {
    let suffix = v & ((1 << pos) - 1);
    let prefix = (v >> (pos + 1)) << pos;
    assert_eq!(prefix & suffix, 0);
    prefix + suffix
}

fn insert(v: u64, pos: u64, add: u64) -> u64 {
    let suffix = v & ((1 << pos) - 1);
    let prefix = (((v >> pos) << 1) + add) << pos;
    assert_eq!(prefix & suffix, 0);
    prefix + suffix
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      --s;
      a[s] |= 1 << i;
    }
  }
  int p = 0;
  rep(i, m) {
    int x;
    cin >> x;
    p |= x << i;
  }

  int ans = 0;
  rep(s, 1 << n) {
    int t = 0;
    rep(i, n) {
      if (s >> i & 1) {
        t ^= a[i];
      }
    }
    if (t == p) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

#define N_MAX 200010

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int N; scanf("%d", &N);
	int a[N_MAX];
	for (int i = 0; i < N; i++){
		scanf("%d", a + i + 1);
	}

	int b[N_MAX], cnt = 0;
	for (int i = N ; i >= 1; i--){
		int sum = 0;
		for (int j = i*2; j <= N; j += i){
			sum += b[j];
		}
		if ((sum % 2) == a[i]){
			b[i] = 0;
		}
		else{
			b[i] = 1;
			cnt++;
		}
	}

	printf("%d\n", cnt);
	for (int i = 1; i <= N; i++){
		if (1 == b[i]){
			printf("%d ", i);
		}
	}

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 2432