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

template<typename T1, typename T2> void cmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T1, typename T2> void cmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T> class Dijkstra {
  struct edge {
    int to; T cost;
  };
  vector<vector<edge>> G;
  vector<T> D;
public:
  Dijkstra(int n) : G(n), D(n, numeric_limits<T>::max()) {}
  void add(int from, int to, T cost) {
    G.at(from).push_back((edge) {to, cost});
  }
  vector<T> build(int start) {
    using pit = pair<int, T>;
    priority_queue<pit, vector<pit>, greater<pit>> Q;
    D.at(start) = 0;
    Q.push(pit(start, 0));
    while (Q.size()) {
      auto [now, dist] = Q.top();
      Q.pop();
      if (dist > D.at(now)) continue;
      for (auto [next, cost] : G.at(now)) {
        if (dist + cost < D.at(next)) {
          D.at(next) = dist + cost;
          Q.push(pit(next, D.at(next)));
        }
      }
    }
    return D;
  }
  void reset() {
    fill(D.begin(), D.end(), numeric_limits<T>::max());
  }
};

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

  int H, W;
  cin >> H >> W;
  int sh, sw, gh, gw;
  cin >> sh >> sw >> gh >> gw;
  sh--, sw--, gh--, gw--;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }

  vector<int> mh {-1, 0, 1, 0};
  vector<int> mw {0, 1, 0, -1};
  Dijkstra<int> D(H * W);

  auto id = [&](int i, int j) {
    return W * i + j;
  };

  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      for (int i = 0; i < 4; i++) {
        int nh = h + mh.at(i);
        int nw = w + mw.at(i);
        if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
        if (S.at(nh).at(nw) == '#') continue;
        D.add(id(h, w), id(nh, nw), 0);
      }
      for (int nh = h - 2; nh <= h + 2; nh++) {
        for (int nw = w - 2; nw <= w + 2; nw++) {
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (S.at(nh).at(nw) == '#') continue;
          D.add(id(h, w), id(nh, nw), 1);
        }
      }
    }
  }

  int ans = D.build(id(sh, sw)).at(id(gh, gw));
  if (ans == INT_MAX) ans = -1;
  cout << ans << "\n";
}

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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int c[n-1];
    int s[n-1];
    int f[n-1];
    for(int i = 0; i < n-1; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }

    vector<int> time(n);
    for(int i = 0; i < n-1; i++) {
        time[i]=s[i];
    }
    time[n-1]=0;
    for(int i = 0; i < n-1; i++) {
        for(int j = i; j < n-1; j++) {
            time[i]=max(time[i],s[j]);
            if(time[i]%f[j]!=0) time[i]+=(f[j]-time[i]%f[j]);
            time[i]+=c[j];
        }
    }

    for(int i = 0; i < n; i++) {
        cout << time[i] << "\n";
    }

    return 0;
}

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

int main(){
  int n;
  int r;
  int t;
  vector<int> target;
  vector<int> k;
  vector<vector<int>> result;
  
  cin >> n;
  
  for(int i=0;i<n;++i){
    cin>>r>>t;
    
    //r
    if(r%100==0)
      target.push_back(r/100);
    else{
      target.push_back(r/100);
      target.push_back((r/100)+1);
    }

    //t
    if(t%30==0){
      for(auto& i:target)
	i+=(t/6);
    }
    else{
      for(auto& i:target)
	i+=5*(t/30);
      
      for(auto i:target){
	k.push_back(i+5);
      }
      for(auto i:k)
	target.push_back(i);
    } 
 
    result.push_back(target);
    target.clear();
    k.clear();
  }
  
  for(int i=0;i<n;++i){
    bool flag=false;
    for(auto j:result[i]){
      if(flag==true)
	cout<<" ";
      cout<<j;
      if(flag!=true)
	flag=true;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
signed main() {
    int A,B;cin>>A>>B;
    cout<<A*B<<endl;
}


Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
int main()
{
	int n, left, right;
	string s;
	cin >> n;
	cin >> s;
	left = right = 0;
	rep(i, n) {
		if (s[i] == '(')	left++;
		else {
			if (0 < left)	left--;
			else right++;
		}
	}
	string ans = "";
	rep(i, right)	ans += '(';
	ans += s;
	rep(i, left)	ans += ')';
	cout << ans << endl;
	return 0;
}

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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define pii pair<int,int>

const int N = 1e5 + 10;
vi g[N];
int n,MOD,u,v;

int dp[N][2];
int res[N];

void dfs(int node,int par = -1)
{
    for(auto x : g[node]) if(x != par) dfs(x,node);
    
    for(auto x : g[node]) if(x != par)
    {
        dp[node][0] = (dp[node][0]*dp[x][0])%MOD;
        dp[node][1] = (dp[node][1]*(dp[x][0] + dp[x][1])%MOD)%MOD;
    }   
}

void dfs2(int node,int par = -1)
{
    res[node] = dp[node][1];
    
    vi p1,p2;
    vi s1,s2;
    
    for(auto & x : g[node])
        if(x == par) 
    {
        swap(g[node][0],x);
        break;
    }
    
    for(auto x : g[node]) p1.pb(dp[x][0]),p2.pb((dp[x][0] + dp[x][1])%MOD);
    
    s1 = p1;
    s2 = p2;
    
    int sz = p1.size();
    
    if(sz == 1 && par == -1)
    {
        int x = g[node][0];
        
        dp[node][0] = 1;
        dp[node][1] = 1;
        dp[x][1] = (dp[x][1]*2)%MOD;
        
        dfs2(x,node);
        
        return;
    }
    else if(sz == 1) return;
    
    for(int i=1;i<sz;i++)
    {
        p1[i] = (p1[i-1]*p1[i])%MOD;
        p2[i] = (p2[i-1]*p2[i])%MOD;
    }
    
    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());
    
    for(int i=1;i<sz;i++)
    {
        s1[i] = (s1[i-1]*s1[i])%MOD;
        s2[i] = (s2[i-1]*s2[i])%MOD;
    }
    
    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());
    
    int idd = 1;
    
    if(par == -1) idd--;
    
    for(auto x : g[node]) if(x != par)
    {   
        int save[2];
        f(i,2) save[i] = dp[node][i];
        
        if(idd == 0) dp[node][0] = s1[1],dp[node][1] = s2[1];
        else if(idd == sz-1) dp[node][0] = p1[sz-2],dp[node][1] = p2[sz-2];
        else dp[node][0] = (p1[idd-1]*s1[idd+1])%MOD, dp[node][1] = (p2[idd-1]*s2[idd+1])%MOD;
        
        dp[x][0] = (dp[x][0]*dp[node][0])%MOD;
        dp[x][1] = (dp[x][1]*(dp[node][0] + dp[node][1])%MOD)%MOD;
        
        dfs2(x,node);
        
        f(i,2) dp[node][i] = save[i];
        
        idd++;
    }
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> MOD;
    
    f(i,n-1)
    {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    
    for(int i=1;i<=n;i++) dp[i][0] = dp[i][1] = 1;
    
    dfs(1);
    dfs2(1);
    
    for(int i=1;i<=n;i++) cout << res[i] << '\n';
}

Measured memory_bytes: 35456
n = int(input())
array = list(map(int, input().strip().split()))

alice_total = 0
bob_total = 0

for i in range(len(array)):
    if i % 2 == 0:
        max_value = max(array)
        max_index = array.index(max_value)
        alice_total += array.pop(max_index)
    else:
        max_value = max(array)
        max_index = array.index(max_value)
        bob_total += array.pop(max_index)

print(alice_total - bob_total)


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 1000000007;

const int N = 200000;
long n, k;
int a[N];

void input()
{
	cin >> n >> k;
	rep(i, n)
	{
		cin >> a[i];
	}
}

int last[N];

void solve()
{
	rep(i, N) last[i] = -1;

	int s = 0;
	for (long i = 0; i < k; i++)
	{
		if (last[s] == -1)
		{
			last[s] = i;
		}
		else
		{

			// ここでループ検出できる
			long loopLen = i - last[s];
			long loopCnt = (k - i) / loopLen;
			i += loopCnt * loopLen;
		}

		if (i == k)
		{
			break;
		}

		s = a[s] - 1;
	}
	cout << s + 1 << endl;
}

int main()
{
	input();
	solve();
}

/*
3 3
2 3 1

*/

Measured memory_bytes: 4744
#include<cstdio>
#include<iostream>
#include<deque>
#include<vector>
#include<list>
using namespace std;
int main()
{
	int T,r;
	cin >> r >> T;
	vector<vector<int> >a(r);//二维

	while (T--)
	{
		int choose;
		int b, c;
		cin >> choose;
		switch (choose)
		{
		case 0:
			cin >> b>>c;
			a[b].push_back(c);
			break;
		case 1:
			cin >> b;
			for (int i = 0; i < a[b].size(); i++)
			{
				cout << a[b][i];
				if (i != a[b].size() - 1)cout << " ";
			}
			cout << endl;
			break;
		case 2:
			int b;
			cin >> b;
			a[b].clear();
		}
	}
}



Measured memory_bytes: 5796
import itertools

def input_ints():
    return list(map(int, input().split()))

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    s = input()
    for i in range(3):
        if s[i] == s[i + 1]:
            print('Bad')
            return
    print('Good')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
  int count,i,j,n,y,m,d,M[11]={0,21,20,21,20,21,20,21,20,21,20};

  scanf("%d",&n);

  for(i=0;i<n;i++){
    count=0;
    scanf("%d%d%d",&y,&m,&d);
    
    while(1){
      if(y%3!=0){
	count++;
	d++;
	if(d==M[m]){
	  m++;
	  d=1;
	}
	if(m==11){
	  m=1;
	  y++;
	}
	if(y==1000&&m==1&&d==1){
	  break;
	}
      }else{
	count++;
        d++;
        if(m%2==0){
	  if(d==M[m]+1){
	    m++;
	    d=1;
	  }
	  if(m==11){
	    m=1;
	    y++;
	  }
	  if(y==1000&&m==1&&d==1){
	    break;
	  }
	}else{
	  if(d==M[m]){
	    m++;
	    d=1;
	  }
	  if(m==11){
	    m=1;
	    y++;
	  }
	  if(y==1000&&m==1&&d==1){
	    break;
	  }
	}
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i=0; i < (int)(N); i++)
 
int main() {
  int N;
  int K;
  
  cin >> N >> K;
 
  int ans = 1;
  
  rep(i, N) {
    if(ans <= K) {
      ans += ans;
    }
    else {
      ans += K;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
// std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// int myRand(int R) {
// 	int val=rng() % R;
//       assert(val>=0);
//       return val;
// }
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int32_t MOD=MOD1;


int spf[10000007];
bool prime[10000007];

void init()
{
    int n=1e7+2;
    fill(prime,prime+n,true);
    prime[1]=false;
    rep(i,2,n+1)
    {
          if(!prime[i])continue;
          prime[i]=true;
          spf[i]=i;
          for(int j=2*i;j<=n;j+=i)
          {
                if(!spf[j])spf[j]=i;
                prime[j]=false;
          }
    } 
}

int solve(int n)
{
     int ans=1;
     spf[1]=1;
     rep(i,2,n+1)
     {
            int num=i;
            int prev=spf[num];
            int prod=1;  
            int cnt=1;
            while(1)
            {
                 int cur=spf[num];
                 if(cur==prev)
                 {
                     cnt++;
                     num/=spf[num];
                     continue;
                 }
                 prod*=cnt;
                 cnt=1;
                 prev=spf[num];
                 if(num==1)break;
            }
            ans+=i*prod;
     }
     return ans;
}

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
           int n;
           cin>>n;
           init();
           cout<<solve(n)<<endl;
      }
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

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

using namespace std;

int main() {
  int n, m, l;
  cin >> n >> m >> l;

  long a[101][101], b[101][101];
  long c[101][101] = {0};

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < l; ++j) {
      cin >> b[i][j];
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < l; ++j) {
      for (int k = 0; k < m; ++k) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < l; ++j) {
      if (j > 0) printf(" ");
      printf("%ld", c[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1396
def nCr(n, r):
    mod=10**9+7
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

n,a,b=map(int,input().split())

ans=(power_func(2,n,10**9+7)-1)-nCr(n,a)-nCr(n,b)

if ans<0:
       while ans<0:
              ans+=10**9+7
       print(ans)
else:
       print(ans)

Measured memory_bytes: 38512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	int a[210010];
	int ans[210010];
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> a[i];
		ans[a[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5192
class Heapq
  def initialize
    @heap = []
    @last = 0
  end

  def enqueue(v)
    @last += 1
    @heap[@last] = v
    i = @last
    while i > 1
      if v > @heap[i/2]
        @heap[i] = @heap[i/2]
        @heap[i/2] = v
        i /= 2
      else
        break
      end
    end
  end

  def dequeue
    return nil if empty?
    top = @heap[1]
    v = @heap[@last]
    @heap[@last] = nil
    @heap[1] = v
    @last -= 1
    i = 1
    while i < @last
      l = i*2
      r = i*2 + 1
      if @heap[l] && @heap[l] > v && (@heap[r].nil? || @heap[l] > @heap[r])
        @heap[i] = @heap[l]
        @heap[l] = v
        i = l
      elsif @heap[r] && @heap[r] > v
        @heap[i] = @heap[r]
        @heap[r] = v
        i = r
      else
        break
      end
    end
    top
  end

  def empty?
    @last.zero?
  end

  def length
    @last
  end
end

n, m = gets.split.map(&:to_i)
prices = Hash.new {|h,k| h[k] = []}
n.times do
  a, b = gets.split.map(&:to_i)
  prices[a] << b
end

ans = 0
queue = Heapq.new
(1..m).each do |day|
  prices[day].each do |v|
    queue.enqueue(v)
  end
  unless queue.empty?
    ans += queue.dequeue
  end
end

puts ans


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        cin >> B[i];
    }
    rep(i,N - 1){
        cin >> C[i];
    }
    int happy = 0;
    rep(i,N){
        happy += B[i];
    }
    rep(i,N - 1){
        if (A[i + 1] == A[i] + 1){
            happy += C[A[i] - 1];
        }
    }
    cout << happy << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int inf = 1e8;

int compute_dist(int s, int t, vector<vector<int>>& g)
{
	vector<int> dist(g.size(), inf);
	queue<pair<int,int>> q;

	q.push({s, 0});

	while(!q.empty()) {

		int v = q.front().first;
		int d = q.front().second;
		q.pop();

		if(dist[v] <= d) {
			continue;
		}
		dist[v] = d;

		for(auto w : g[v]) {
			q.push({w, d + 1});
		}
	}

	return dist[t];
}

int main()
{
	int n, m;
	vector<vector<int>> og, g;
	int s, t;

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

	og.resize(n);
	g.resize(3 * n);

	for(int i = 0; i < m; i++) {
		int v, w;
		scanf("%d%d", &v, &w);
		v -= 1;
		w -= 1;
		og[v].push_back(w);
	}

	scanf("%d%d", &s, &t);
	s -= 1;
	t -= 1;

	for(int v = 0; v < n; v++) {
		for(auto w : og[v]) {
			for(int i = 0; i < 3; i++) {
				g[v * 3 + i].push_back(w * 3 + (i + 1) % 3);
			}
		}
	}

	int ans = compute_dist(s * 3, t * 3, g);

	if(ans >= inf) {
		printf("-1\n");
	} else {
		printf("%d\n", ans / 3);
	}

	return 0;
}


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

int main() {
    string S;
    cin >> S;
    bool rev = false;
    int Q;
    deque<char> dq;
    for(int i = 0; i < S.length(); i++) {
        dq.push_back(S[i]);
    }

    cin >> Q;
    for(int i = 0; i < Q; i++) {
        int c;
        cin >> c;
        if(c == 1) rev = !rev;
        else {
            int T;
            char F;
            bool f;
            cin >> T >> F;
            f = T == 1;
            if(f != rev) {
                dq.push_front(F);
            } else {
                dq.push_back(F);
            }
        }
    }

    if(rev == true) {
        for(auto it = dq.rbegin(); it != dq.rend(); it++) {
            cout << *it;
        }
    } else {
        for(auto it = dq.begin(); it != dq.end(); it++) {
            cout << *it;
        }
    }
    cout << endl;
}

Measured memory_bytes: 960
/*
                            Author: Ankit Kaul
*******Code Belongs to Respective Author Only*************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
/*freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}   
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi  
    int n;
    cin>>n;
    int dp[1000001],idp[1000001];
    dp[1]=1;
    idp[1]=1;
    dp[0]=1;
    idp[0]=1;
    for(int i=2;i<1000001;i++)
    {   dp[i]=((dp[i-1]%M) * (i%M))%M;
        idp[i]=((idp[i-1]%M) * (power(i,M-2)%M))%M; 
    }
    if(n==1)
    cout<<0<<endl;
    else
    {   int ans=0;
        for(int i=2;i<=n;i++)
        {   int x=(((dp[n]%M) * (idp[n-i]%M)%M) * (idp[i])%M)%M;
            x=(x*2 * (power(2,i-1)-1LL + M)%M)%M;  
            x=(x* power(8,n-i))%M;
            ans=(ans+x)%M;
        }
        cout<<ans%M<<endl;
    }
}


Measured memory_bytes: 19204
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct node{
  double x,y;
}Point;
void koch(int,Point,Point);

void koch(int n,Point p1,Point p2){
  if(n==0) return;

  Point s,t,u;
  double th=M_PI*60/180;

  s.x=(2*p1.x+1*p2.x)/3;
  s.y=(2*p1.y+1*p2.y)/3;
  t.x=(1*p1.x+2*p2.x)/3;
  t.y=(1*p1.y+2*p2.y)/3;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);
}

int main(){
  Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}

Measured memory_bytes: 2664
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
p = abs(a[0]//2-a[1])
q = a[1]
for i in range(2,n):
    if p >= abs(a[0]//2-a[i]):
        q = a[i]
        p = abs(a[0]/2-a[i])
print(a[0],q)

Measured memory_bytes: 14428
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define ALL(v) v.begin(), v.end()
typedef pair<int, int> P;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}

int A[500001];
int zero[500001];
int pre[1 << 20];
vector<P> v[1 << 20];
ll dp[500001][2];
void solve(int k) {
	for (int i = 0; i <= v[k].size(); i++) dp[i][0] = dp[i][1] = 0;
	dp[1][0] = 1;
	for (int i = 1; i < v[k].size(); i++) {
		dp[i + 1][0] = dp[i][0];
		dp[i + 1][1] = dp[i][1];
		if (v[k][i].first == 0) {
			(dp[i + 1][0] += dp[i][1] * v[k][i].second) %= MOD;
		}
		else {
			(dp[i + 1][1] += dp[i][0] * v[k][i].second) %= MOD;
		}
	}
	return;
}
int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) A[i] ^= A[i - 1];
	memset(pre, -1, sizeof(pre));
	zero[0] = 1;
	for (int i = 1; i <= N; i++) {
		zero[i] = zero[i - 1];
		if (A[i] != 0) {
			int cnt = zero[i];
			if (pre[A[i]] != -1) cnt -= zero[pre[A[i]]];
			if (cnt > 0) v[A[i]].emplace_back(0, cnt);
			v[A[i]].emplace_back(A[i], 1);
			pre[A[i]] = i;
		}
		else {
			zero[i]++;
		}
	}
	for (int i = 1; i < (1 << 20); i++) {
		if (pre[i] == -1) continue;
		int cnt = zero[N];
		cnt -= zero[pre[i]];
		if (cnt > 0) v[i].emplace_back(0, cnt);
	}
	int X = A[N];
	if (X != 0) {
		solve(X);
		cout << dp[v[X].size() - 1][0] << endl;
		return 0;
	}
	ll ans = 0;
	for (int i = 1; i < (1 << 20); i++) {
		if (v[i].empty()) continue;
		solve(i);
		(ans += dp[v[i].size() - 1][1]) %= MOD;
	}
	(ans += mod_pow(2, zero[N] - 2)) %= MOD;
	cout << ans << endl;
}


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

using namespace std;

int main() {
    int n;
    while (cin >> n && n) {
        set<int> taro, hanako;
        for (int i = 0; i < n; ++i) {
            int s;
            cin >> s;
            taro.insert(s);
        }
        for (int i = 1; i <= 2 * n; ++i) {
            if (!taro.count(i)) hanako.insert(i);
        }
        int now = 0, a = 1;
        while (!taro.empty() && !hanako.empty()) {
            if (!now) {
                if (a) {
                    now = *taro.begin();
                    taro.erase(now);
                } else {
                    now = *hanako.begin();
                    hanako.erase(now);
                }
            } else {
                if (a) {
                    auto itr = taro.upper_bound(now);
                    if (itr == taro.end()) {
                        now = 0;
                    } else {
                        now = *itr;
                        taro.erase(now);
                    }
                } else {
                    auto itr = hanako.upper_bound(now);
                    if (itr == hanako.end()) {
                        now = 0;
                    } else {
                        now = *itr;
                        hanako.erase(now);
                    }
                }
            }
            a = 1 - a;
        }
        cout << hanako.size() << '\n';
        cout << taro.size() << '\n';
    }
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
set<string> st;
int n,k;
int flag[10];
string v[10];
void dfs(int maisu,string s){
  if(maisu==k){
    st.insert(s);
    return;
  }
  for(int i=0;i<n;i++){
    if(flag[i]==0){
      flag[i]=1;
      dfs(maisu+1,s+v[i]);
      flag[i]=0;
    }
  }
  return;
}
  
int main(){
  while(1){
    cin>>n>>k;
    if(n==0 && k==0) break;
    for(int i=0;i<n;i++){
      cin>>v[i];
      flag[i]=0;
    }
    
    st.clear();
    dfs(0,"");
    cout<<st.size()<<endl;
  }
}

Measured memory_bytes: 1460
#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
#define MAXN (int)()
#if !testing
#define cerr if(0)cout
#endif

int32_t __attribute__((optimize("Ofast"), target("arch=sandybridge"))) main() 
{
	IAMSPEED
	int X,Y,a,b,c; cin >> X >> Y >> a >> b >> c;
	vector<int> red, green;
	FOR(i,1,a) {
		int x; cin >> x;
		red.pb(x);
	}
	FOR(i,1,b) {
		int x; cin >> x;
		green.pb(x);
	}
	priority_queue<int> white;
	FOR(i,1,c) {
		int x; cin >> x;
		white.push(x);
	}
	sort(all(red),greater<int>());
	sort(all(green),greater<int>());
	while((int)red.size()>X)red.pop_back();
	while((int)green.size()>Y)green.pop_back();
	priority_queue<int,vector<int>,greater<int>>redpq;
	priority_queue<int,vector<int>,greater<int>>greenpq;
	for(auto i: red)redpq.push(i);
	for(auto i: green)greenpq.push(i);
	while(white.size()) {
		int x = white.top();
		if(redpq.size()&&greenpq.size()) {
			if(redpq.top()<greenpq.top()) {
				if(x>redpq.top()) {
					white.pop();
					redpq.pop();
					redpq.push(x);
				} else {
					goto done;
				}
			} else {
				if(x>greenpq.top()) {
					white.pop();
					greenpq.pop();
					greenpq.push(x);
				} else {
					goto done;
				}
			}
		}
		else if(redpq.size()) {
			if(x>redpq.top()){
				redpq.pop();
				white.pop();
				redpq.push(x);
			} else {
				goto done;
			}
		} else if(greenpq.size()) {
			if(x>greenpq.top()) {
				greenpq.pop();
				white.pop();
				greenpq.push(x);
			} else {
				goto done;
			}
		} else {
			goto done;
		}
	}
	done:
	ll ans = 0;
	while(greenpq.size()) {
		ans+=greenpq.top();
		greenpq.pop();
	}
	while(redpq.size()) {
		ans+=redpq.top();
		redpq.pop();
	}
	cout<<ans;
}



Measured memory_bytes: 2552
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class place {
public:
	int vote, rank, cost;
	place() {
		vote = 0;
	}
};
int main() {
	int n, m;
	cin >> n >> m;
	vector<place>P(n);
	for (int i = 0; i < n; i++) {
		cin >> P[i].cost;
		P[i].rank = i + 1;
	}
	for (int j = 0; j < m; j++) {
		int x; cin >> x;
		for (int k = 0; k < n; k++) {
			if (P[k].cost <= x) {
				P[k].vote++;
				break;
			}
		}
	}
	cout << max_element(P.begin(), P.end(), [](const place& x, const place& y) { return x.vote < y.vote; })->rank << endl;
	return 0;
}

Measured memory_bytes: 3092
from math import ceil
import numpy as np
n, a, b = map(int, input().split())
h = np.array(sorted([int(input()) for i in range(n)]))

def enough(T):
    global h
    h2 = h - b * T
    c = sum(np.ceil(h2[h2 > 0]/(a - b)))
    if c <= T: return 1
    else: return 0

def bisearch():
    lo = 0
    hi = ceil(max(h)/b)
    while lo < hi:
        mid = (lo + hi) // 2
        midval = enough(mid)
        if midval < 1: lo = mid + 1
        else: hi = mid
    return lo

print(bisearch())

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

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

  if(a==b){
    result = a*2;
  }else if(a<b){
    result = b*2 - 1;
  }else if(a>b){
    result = a*2 - 1;
  }

  cout << result << endl;
}

Measured memory_bytes: 384
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
	if(a >= b){
	  printf("delicious\n");
	}else if(a + x >= b){
	  printf("safe\n");
	}else{
	  printf("dangerous\n");
	}
	
	Please AC;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string a,b; cin>>a>>b;
	for(int i=0,len = a.length();i<len;i++){
		if(a[i] != b[i]){
			cout<<"No"; return 0;
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 3656
# 0028
array = []
while True:
    try:
        a = input()
        array.append(int(a))
    except EOFError: break
s = set(array)
mx = max(sorted(s, reverse=True), key = array.count)
for a in sorted(s, key = array.count, reverse=True):
    print(a)
    if a == mx: break

Measured memory_bytes: 7620
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;

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

  for(int i=0;i<N;i++){
	cin>>p[i];
	p[i]--;
  }
  int min=0;

  for(int i=0;i<N-1;i++){
	if(p[i]==i){
	  int tmp=p[i];
	  p[i]=p[i+1];
	  p[i+1]=tmp;
	  min++;
	}
  }

  if(p[N-1]==N-1){
	cout << min+1 << endl;
  }else{
	cout << min << endl;
  }

  return 0;
}

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

void lazy_query(int k, vector<int>& node, vector<int>& lazy, int n) {
	if (lazy[k] == INT_MAX)return;
	node[k] = lazy[k];
	if (k < n - 1) {
		lazy[2 * k + 1] = lazy[k];
		lazy[2 * k + 2] = lazy[k];
	}
	lazy[k] = INT_MAX;
}

void update(int a, int b, int x, int k, int l, int r, vector<int>&node, vector<int>& lazy, int n) {
	lazy_query(k, node, lazy, n);
	if (r <= a || b <= l)return;
	if (a <= l && r <= b) {
		lazy[k] = x;
		lazy_query(k, node, lazy, n);
		return;
	}
	else {
		lazy_query(k, node, lazy, n);
		update(a, b, x, 2 * k + 1, l, (l + r) / 2, node, lazy, n);
		update(a, b, x, 2 * k + 2, (l + r) / 2, r, node, lazy, n);
		node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		return;
	}
}

int find(int a, int b, int k, int l, int r, vector<int>&node, vector<int>& lazy, int n) {
	lazy_query(k, node, lazy, n);
	if (r <= a || b <= l)return INT_MAX;
	if (a <= l && r <= b) {
		return node[k];
	}
	else {
		lazy_query(k, node, lazy, n);
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2, node, lazy, n);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r, node, lazy, n);
		//node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		return min(vr, vl);
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n_, q;  cin >> n_ >> q;
	int n = 1;
	while (n < n_) n *= 2;
	vector<int> node(2 * n - 1, INT_MAX);
	vector<int> lazy(2 * n - 1, INT_MAX);

	for (int i = 0; i < q; i++) {
		int com; cin >> com;
		if (com == 0) {
			int s, t, x; cin >> s >> t >> x;
			update(s, t + 1, x, 0, 0, n, node, lazy, n);
		}
		else {
			int s, t; cin >> s >> t;
			cout << find(s, t + 1, 0, 0, n, node, lazy, n) << endl;
		}
	}
}

Measured memory_bytes: 4936
import java.util.*;
class Main{
	public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
		  String s = sc.next();
      String t = sc.next();
      
      int a= sc.nextInt();
      int b= sc.nextInt();

      String z = sc.next();
      
      if(s.indexOf(z)!=-1){
        a--;
      }
      else if (z.indexOf(z)!=-1){
        b--;
      }
      System.out.println(a+" "+b);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define MAX 10000000
#define n_MAX 101
#define c_MAX 11

int main() {

  while( true ) {

    long long int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if ( n == 0 ) break;

    long long int l[n_MAX][n_MAX] = {0};

    for ( long long int i = 0; i < m; i++ ) {

      long long int a, b, f;
      cin >> a >> b >> f;
      l[a][b] = f;
      l[b][a] = f;

    }

    long long int t[c_MAX][n_MAX];
    for ( long long int j = 0; j <= c; j++ ) {
      for ( long long int i = 1; i <= n; i++ ) {
	t[j][i] = MAX;
      }
    }
    t[c][s] = 0;

    for ( long long int j = c; j >= 0; j-- ) {

      priority_queue< pair< int, int >, vector< pair< int, int > >, greater< pair< int, int > > > q;

      for ( long long int i = 1; i <= n; i++ ) {
	if ( t[j][i] < MAX ) {
	  q.push( make_pair( t[j][i], i ) );
	}
      }

      while( q.size() > 0 ) {

	pair< int, int > p;
	p = q.top();
	q.pop();
	long long int next = p.second;
	if ( t[j][next] < p.first ) continue;

	for ( long long int i = 1; i <= n; i++ ) {

	  if ( l[next][i] == 0 ) continue;
	  if ( t[j][i] > t[j][next] + l[next][i] ) {
	    t[j][i] = t[j][next] + l[next][i];
	    q.push( make_pair( t[j][i], i ) );
	  }
	  if ( j > 0 ) {
	    t[j - 1][i] = min( t[j - 1][i], t[j][next] + l[next][i] / 2 );
	  }

	}

      }

    }

    long long int ans = MAX;

    for ( long long int i = 0; i <= c; i++ ) {
      ans = min( ans, t[i][d] );
    }

    cout << ans << endl;

  }

  return 0;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    ll q,h,s,d;
    cin>>q>>h>>s>>d;
    if(q*2<h)h=q*2;
    if(h*2<s)s=h*2;
    if(s*2<d)d=s*2;
    ll n;
    cin>>n;
    cout<<(n/2)*d+(n%2)*s<<endl;
    return 0;
}


Measured memory_bytes: 256
from math import floor
N,K = map(int,input().split())
ans = 0
for b in range(K+1, N+1):
    p,r = N//b,N%b
    ans += p*max(0,b-K)+max(0,r-K+1)
print(ans if K!=0 else ans-max(0,b-K))

Measured memory_bytes: 9064
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

    
  priority_queue<long long> que;
    
  for (int i = 0; i < N; ++i) {
    long long A; cin >> A; que.push(A);  
  }
  
  for (int i = 0; i < M; ++i) {
    long long t = que.top(); que.pop();
    que.push(t/2);
  }
  long long res = 0;
  while (!que.empty()) res += que.top(), que.pop();
    
  cout << res << endl;
}

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

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    int m;
    cin >> m;
    int t[m];
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    
    if (m > n) {
        cout << "NO" << endl;
        return 0;
    }
    sort(d, d + n);
    sort(t, t + m);
    int p;
    for (int i = 0; i < n; i++) {
        if (p == m) break;
        if (t[p] < d[i]) {
            cout << "NO" << endl;
            return 0;
        }
        if (t[p] > d[i]) continue;
        p++;
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();
	int X = sc.nextInt();
	int cnt = 0;
	for(int i = 0; i <= A; i ++) {
	    for(int j = 0; j <= B; j++) {
		int k = (X - i * 500 - j * 100) / 50;
		if(k >= 0 && k <= C) {
		    cnt ++;
		}
	    }
	}
	    
	System.out.println(cnt);
    }
}


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

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

    int cnt = s.size();
    for (int cnt = s.size(); cnt > 0; ) {
        if (cnt >= 5 && s.substr(cnt - 5, 5) == "dream") {
            cnt -= 5;
        }
        else if (cnt >= 7 && s.substr(cnt - 7, 7) == "dreamer") {
            cnt -= 7;
        }
        else if (cnt >= 5 && s.substr(cnt - 5, 5) == "erase") {
            cnt -= 5;
        }
        else if (cnt >= 6 && s.substr(cnt - 6, 6) == "eraser") {
            cnt -= 6;
        }
        else {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	private static class Separate {
		public int a, b;

		public Separate(String[] tokens) {
			a = Integer.parseInt(tokens[0]) - 1;
			b = Integer.parseInt(tokens[1]) - 1;
		}
	}

	int islandNum, bridgeNum;
	boolean[] bridgeState;
	int removeCount;

	public Main(int islandNum, int bridgeNum) {
		this.islandNum = islandNum;
		this.bridgeNum = bridgeNum;
		this.bridgeState = new boolean[bridgeNum];
		Arrays.fill(this.bridgeState, true);
	}

	public void eval(List<Separate> list) {
		for (int i = 0; i < list.size(); ++i) {
			eval(list.get(i));
		}
	}

	private void eval(Separate sep) {
		boolean sepCheck = false;
		for (int i = sep.a; i < sep.b; ++i) {
			if (!bridgeState[i]) {
				sepCheck = true;
				break;
			}
		}
		if (sepCheck) {
			return;
		}
		bridgeState[sep.b - 1] = false;
		removeCount++;
		return;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);
		boolean[] bridges = new boolean[N - 1];
		Arrays.fill(bridges, true);

		List<Separate> list = new ArrayList<>();
		for (int i = 0; i < M; ++i) {
			tokens = in.nextLine().split(" ");
			list.add(new Separate(tokens));
		}
		list.sort(new Comparator<Separate>() {
			@Override
			public int compare(Separate o1, Separate o2) {
				if (o1.b < o2.b) {
					return -1;
				} else if (o1.b > o2.b) {
					return 1;
				} else {
					return 0;
				}
			}
		});
		Main ins = new Main(N, N - 1);
		ins.eval(list);
		System.out.println(ins.removeCount);
		in.close();
	}
}

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

using namespace std;

const int N = 200005;

int n, A[N], dp[N];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &A[i]);
	int cur = n;
	int ans = 0;
	for(int i = 1; i <= n; ++i){
		dp[A[i]] = dp[A[i] - 1] + 1;
	}
	for(int i = 1; i <= n; ++i){
		ans = max(ans, dp[i]);
	}
	printf("%d\n", n - ans);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define DOW(i,b,a) for (int i = (b); i >= (a); i--)
#define pb(a) push_back(a)
#define ALL(a) (a).begin(),(a).end()
#define fi first
#define se second

template<typename T>
void print_array(T* arr, int num) {
   FOR(i, 0, num) cout << arr[i] << ' ';
   cout << endl;
}

template<typename T> 
void print_vector(vector<T> vec) {
   FOR(i,0,vec.size()) cout << vec[i] << ' ';
   cout << endl;
}

string a;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("test.txt", "r", stdin);
    FOR(i,0,3) {
        cin >> a;
        cout << (char) toupper(a[0]);
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;

int n,a[N];

int main()
{
	scanf("%d",&n);int mx=0;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),mx=max(mx,a[i]);
	int s=0;
	for (int i=1;i<=n;i++)
	{
		if (a[i]<mx-1||a[i]>mx) {puts("No");return 0;}
		if (a[i]!=mx) s++;
	}
	if (!s&&mx==n-1) puts("Yes");
	else if (mx<=s||mx>s&&(mx-s)*2>n-s) puts("No");
	else puts("Yes");
	return 0;
	return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> Student(N);
	vector<pair<int, int>> CP(M);
	for (int i = 0; i < N; i++) cin >> Student[i].first >> Student[i].second;
	for (int i = 0; i < M; i++) cin >> CP[i].first >> CP[i].second;
	for (int i = 0; i < N; i++) {
		int MIN = 400000001, ans = -1;
		for (int j = 0; j < M; j++) {
			int dist = abs(Student[i].first - CP[j].first) + abs(Student[i].second - CP[j].second);
			if (dist < MIN) {
				MIN = dist;
				ans = j + 1;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void) {
	int n;
	scanf("%d", &n);
	if (n == 25) {
		puts("Christmas");
	} else if (n == 24) {
		puts("Christmas Eve");
	} else if (n == 23) {
		puts("Christmas Eve Eve");
	} else if (n == 22) {
		puts("Christmas Eve Eve Eve");
	}
	return 0;
}


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

using namespace std;

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

long long int lcm(long long int a, long long int b) {
    return (a*b)/gcd(a, b);
}

int main() {
    long long int A, B;
    int C, D;
    cin >> A >> B >> C >> D;

    long long int lcd = lcm(C, D);
    cout << (B - A + 1) - (- ((B / lcd) - ((A - 1)/lcd)) + ((B / C) - ((A - 1)/C)) + ((B / D) - ((A - 1)/D)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
 
const ll N = 100500, M = 4e9;

struct node{
	int mx;
	node *l, *r;
	node(){
		mx = 0;
		l = NULL;
		r = NULL;
	}
}; 
int n, p[N];
ll l[N], r[N], ans;
bool cmp(int i, int j){
	return r[i] < r[j];
}
void upd(node *&v, ll l, ll r, ll pos, int val){
   	if(v == NULL)
   		v = new node();                                       
   	v -> mx = max(v -> mx, val);
   	if(l == r)
   		return;
	ll m = (l + r) >> 1;
	if(pos <= m)
		upd(v -> l, l, m, pos, val);
	else
		upd(v -> r, m + 1, r, pos, val);
}
ll get(node *&v, ll tl, ll tr, ll l, ll r){
	if(v == NULL || r < tl || tr < l || l > r)
		return 0;
	if(l <= tl && tr <= r)
		return v -> mx;
	ll tm = (tl + tr) >> 1;
	return max(get(v -> l, tl, tm, l, r), get(v -> r, tm + 1, tr, l, r));
}
int main()
{
	scanf("%d", &n);
 	for(int i = 0; i < n; i++){
 		int a, b;
 		scanf("%d%d", &a, &b);
 		l[i] = a - b + 1e9 + 100;
 		r[i] = a + b + 1e9 + 100;
 		p[i] = i;
 	}
 	sort(p, p + n, cmp);
 	node *t = NULL;
 	for(int i = 0; i < n; i++){
 		int ind = p[i];
		ll val = get(t, 0, M, 0, l[ind]) + 1;
 		ans = max(ans, val);
 		upd(t, 0, M, r[ind], val);
 	} 
 	printf("%lld", ans);
}


Measured memory_bytes: 49536
#include <iostream>

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

    int w;

    while (std::cin >> w) {
        for (int i = 0; i < 10; ++i) {
            int num = 1 << i;
            if (w & num) {
                w -= num;
                std::cout << num;

                if (w) {
                    std::cout << " ";
                }
            }
        }
        std::cout << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1188