akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
signed main(){
	int h,w;cin >> h >> w;
	int sx,sy,gx,gy;cin >> sx >> sy >> gx >> gy;
	sx--;sy--;gx--;gy--;
	vector<string> f(h);
	rep(i,h)cin >> f[i];

	priority_queue<P,vector<P>,greater<P>>pq;
	auto toid = [&](int x,int y){
		return x*w + y;
	};
	vector<int> dist(h*w,INF);
	auto push = [&](int x,int y,int cost){
		if(x < 0 || y < 0 || x > h-1 || y > w-1)return;
		if(dist[toid(x,y)] <= cost)return;
		if(dist[toid(x,y)] == -1)return;
		if(f[x][y] == '#')return;
		dist[toid(x,y)] = cost;
		pq.emplace(cost,toid(x,y));
		
	};
	push(sx,sy,0);
	while(pq.size()){
		auto now = pq.top();pq.pop();
		if(dist[now.second] != now.first)continue;
		int x = now.second/w,y = now.second%w;
		rep(i,4){
			int nx = x + dx[i],ny = y + dy[i];
			push(nx,ny,now.first);
		}
		for(int nx = x-2;nx <= x+2;nx++)for(int ny = y-2;ny <= y+2;ny++){
			push(nx,ny,now.first+1);
		}
	}
	int ret = dist[toid(gx,gy)];
	if(ret == INF)ret = -1;
	cout <<ret << endl;
	return 0;
}

Measured memory_bytes: 13332
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	string str;
	int s,i,j;
	cin >> str;
	s=str.size();
	for(i=0; i<s; i++)
		if(str[i]=='A')
			break;
	for(j=s-1; j>=0; j--)
		if(str[j]=='Z')
			break;	
	cout << j-i+1;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void)
{
	int n,m,X,Y,x[101],y[101],i,max,mini;
	scanf("%d%d%d%d",&n,&m,&X,&Y);
	max=X;
	mini=Y;
	for(i=0; i<n; i++){
		scanf("%d",&x[i]);
		if(max<x[i]){
			max=x[i];
		}
	}
	for(i=0; i<m; i++){
		scanf("%d",&y[i]);
		if(mini>y[i]){
			mini=y[i];
		}
	}
	if(max<mini){
		puts("No War");
	}else{
		puts("War");
	}
	return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n, a[maxn];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  cin>>n;
  for (int i=1; i<=n; i++) cin>>a[i];

  int ans=0;
  for (int i=1; i<=n; i++) {
    if (a[i] == i) {
      ans++;
      if (i+1<=n) {
	swap(a[i],a[i+1]);
      } else {
	assert(i-1>=1);
	swap(a[i],a[i-1]);
      }
    }

    // watch(i);
    // for (int j=1; j<=n; j++) {
    //   cout<<a[j]<<" ";
    // }
    // cout<<endl;
  }
  out(ans);  

  return 0;
}


Measured memory_bytes: 768
x,y,a,b,c = map(int,input().split())
arra = list(map(int, input().split()))
arrb = list(map(int, input().split()))
arrc = list(map(int, input().split()))

arra.sort()
arrb.sort()
arrc.sort()

temp = arra[a-x:]+arrb[b-y:]
#print(temp)

if x+y<c:
  	temp +=arrc[c-x-y:]
else:
  	temp +=arrc
    
#print(temp)
temp.sort()

arr = temp[len(temp)-x-y:]
#print(arr)
print(sum(arr))

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

signed main() {
	int n;
	cin >> n;

	map<char, int> cnt;
	cnt['M'] = 0;
	cnt['A'] = 0;
	cnt['R'] = 0;
	cnt['C'] = 0;
	cnt['H'] = 0;

	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		cnt[s[0]]++;
	}
	
	int ans = 0;

	/*
	do {
		ans += cnt[march[0]] * cnt[march[1]] * cnt[march[2]];
		cout << cnt[march[0]] * cnt[march[1]] * cnt[march[2]];
	} while (next_permutation(march.begin(), march.end()));

	int num = bool(cnt[march[0]]) * bool(cnt[march[1]]) * bool(cnt[march[2]]) * bool(cnt[march[3]]) * bool(cnt[march[4]])
	*/

	ans += cnt['M'] * cnt['A'] * cnt['R'];
	ans += cnt['M'] * cnt['A'] * cnt['C'];
	ans += cnt['M'] * cnt['A'] * cnt['H'];
	ans += cnt['M'] * cnt['R'] * cnt['C'];
	ans += cnt['M'] * cnt['R'] * cnt['H'];
	ans += cnt['M'] * cnt['C'] * cnt['H'];
	ans += cnt['A'] * cnt['R'] * cnt['C'];
	ans += cnt['A'] * cnt['R'] * cnt['H'];
	ans += cnt['A'] * cnt['C'] * cnt['H'];
	ans += cnt['R'] * cnt['C'] * cnt['H'];

	cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
        String A = scan.next();
        String B = scan.next();
        String C = scan.next();
        
        if(A.equals("5") && B.equals("5")) {
        	System.out.println("YES");
        }else if(B.equals("5") && C.equals("5")){
        	System.out.println("YES");
        }else if(A.equals("5") && C.equals("5")){
        	System.out.println("YES");
        }else {
        	System.out.println("NO");
        }
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, d;
    while(cin >> w >> d, w | d)
    {
        vector<int> h1(50, 0), h2(50, 0);
        for(int i = 0; i < w; i++) cin >> h1[i];
        for(int i = 0; i < d; i++) cin >> h2[i];
        bool used[50] = {};
        int ans = 0;
        for(int i = 0; i < w; i++)
        {
            bool flag = false;
            for(int j = 0; j < d; j++)
            {
                if(used[j]) continue;
                if(h1[i] == h2[j])
                {
                    used[j] = true;
                    ans += h1[i];
                    flag = true;
                    break;
                }
            }
            if(flag == false)
            {
                ans += h1[i];
            }
        }
        for(int i = 0; i < d; i++)
        {
            if(used[i] == false) ans += h2[i];
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3088
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vll V(N),C(N);
    for(ll i=0;i<N;i++)cin>>V[i];
    for(ll i=0;i<N;i++)cin>>C[i];
    
    ll ans=0;
    for(ll i=0;i<N;i++){
        if(V[i]>C[i])ans+=V[i]-C[i];
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())

    if N <= K:
        ans = X * N
    else:
        ans = X * K + Y * (N - K)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int a,b,c;
int main(){
cin>>a>>b>>c;
int time=0,time2=0;
int ans=-1;
for(int i=0;i<10000;i++){

	int now;
	if((i+1)%2)now=a;
	else now=b;

		for(int j=0;j<now;j++){
			time++;
			time2++;
			if(time==60)time=0;
			if((i+1)%2&&time==c){
				cout<<time2<<endl;
				return 0;
			}
		}
	}


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


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

	ll n, k;
	cin >> n >> k;

	vector<int> arr(n);
	for (int &x : arr)
		cin >> x, --x;

	vector<int> p;
	set<int> seen;

	int s = 0;
	int cycle = -1;
	while (true)
	{
		seen.insert(s);
		s = arr[s];
		if (seen.count(s))
		{
			cycle = s;
			break;
		}
	}
	s = 0;
	while (s != cycle)
	{
		s = arr[s];
		k--;
		if (k == 0)
		{
			break;
		}
	}
	if (k == 0)
	{
		cout << s + 1 << endl;
	}
	else
	{
		p.push_back(s);
		s = arr[s];

		while (s != cycle)
		{
			p.push_back(s);
			s = arr[s];
		}

		ll len = p.size();
		cout << p[k % (len)] + 1 << endl;
	}
}

Measured memory_bytes: 13108
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>
#include <queue>
#include <bits/stl_numeric.h>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;


int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,X;
    cin >> K >> X;
    string res;

    if(K * 500 >= X)
    {
        res = "Yes";
    }
    else res = "No";


    cout << res << endl;

    return 0;
}


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

int n;
string w, lst;
map<string, bool> vis;

int main() {
	scanf("%d", &n); --n; cin >> lst; vis[lst] = 1;
	while (n--) {
		cin >> w;
		if (vis[w] || w[0] != lst[lst.size() - 1]) {
			puts("No");
			return 0;
		}
		vis[w] = 1; lst = w;
	}
	puts("Yes");
	return 0;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n; cin >> n;
  map<string,int> mp;
  int ans = 0;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    sort(s.begin(),s.end());
    ans += mp[s]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int n;
cin >> n;
string s;
cin >> s;
int k;
cin >> k;
k--;
for(int i=0;i<s.size();i++){
    if(s.at(i)!=s.at(k))cout<<"*";
    else cout<<s.at(i);
}
cout<<endl;
}
 


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

int main(void){
    int count = 0, max = 0, len, i;
    char s[11];

    scanf("%s", s);
    len = strlen(s);

    for(i = 0;i <= len;i++){
        switch(s[i]){
            case 'A':
            case 'T':
            case 'G':
            case 'C':
                    count++;
                    break;
            default:
                if(max < count){
                    max = count;
                }
                count = 0;
                break;
        }
    }
    printf("%d\n", max);
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vint a(A), b(B), x(M), y(M), c(M);
    rep(i, A)
    {
        cin >> a[i];
    }
    int aMin = *min_element(all(a));
    rep(i, B)
    {
        cin >> b[i];
    }
    int bMin = *min_element(all(b));
    int Min = aMin + bMin;
    rep(i, M)
    {
        cin >> x[i] >> y[i] >> c[i];
        x[i]--;
        y[i]--;
        Min = min(Min, a[x[i]] + b[y[i]] - c[i]);
    }
    cout << Min;
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 9007199254740997;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

const int w=7;
const int k=600;
const int n=26;
int ww;
int d;

VI c(n);
VVI s(365,VI(n));

struct st{
	VI a;
	ll score;
	bool operator<(const st &another) const {return score < another.score;};
};

vector<st> f(st p){
	VI a=p.a; ll score=p.score;
	int now=a.size()+1;
	VI last(n,0);
	REP(i,a.size())
		last[a[i]]=i+1;
	VI down(n); ll downsum=0;
	REP(i,n){
		down[i]=c[i]*(now-last[i]);
		downsum+=down[i];
	}
	a.push_back(-1);
	vector<st> tmp;
	REP(i,n){
		a[now-1]=i;
		tmp.push_back({a,score-downsum+down[i]+s[now-1][i]});
	}
	sort(ALL(tmp));
	vector<st> ret;
	REP(i,ww)
		ret.push_back(tmp[n-1-i]);
	return ret;
}

int main(){
	cin >> d;
	REP(i,n) cin >> c[i];
	REP(i,d)REP(j,n) cin >> s[i][j];
	priority_queue<st> q;
	VI a(0);
	q.push({a,0});
	REP(i,d){
		priority_queue<st> next;
		ww=w;
		REP(j,k){
			if(j%100==0)
			ww--;
			if(q.empty())
				break;
			for(auto nx:f(q.top()))
				next.push(nx);
			q.pop();
		}
		q=next;
	}
	REP(i,d)
		cout << q.top().a[i]+1 << endl;
	//cout << q.top().score << endl;
	return 0;
}

Measured memory_bytes: 18256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int unx(){int x=0,n=0; char c=getchar(); for(;!isdigit(c);c=getchar()) n=(c=='-'); for(;isdigit(c);c=getchar())x=x*10+c-'0'; return (n)?-x:x;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){}
#define in unx()
#define fasty ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define forinc(a,b,c) for(int a=b, _c=c; a<=_c; ++a)
#define fordec(a,b,c) for(int a=b, _c=c; a>=_c; --a)
#define forv(a,b) for(auto &a:b)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define mt make_tuple
#define bit(x,i) (x>>(i-1)&1ll)
#define onbit(x,i) (x|(1ll<<(i-1)))
#define offbit(x,i) (x&~(1ll<<(i-1)))

const int N=2e5+5;
map<int,int> mp;
int n;
ii a[N];
int dd[N];

main(){
  fasty;
  int ans=0;
  forinc(i,1,n=in) a[i] ={in,i};
  forinc(i,1,n){
    int u=a[i].fi-a[i].se;
    u=-u;
    ans+=mp[u];
    mp[a[i].fi+i]++;
  }
  cout<<ans<<'\n';
}



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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	for(int i = min(s.size(), t.size()); i >= 0; i--){
		if(s.substr(s.size()-i,i) == t.substr(0,i)){
			ANS(s.size() + t.size() - i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 2019
int main()
{
    string s;
    cin >> s;
    if (s.empty()) return 0;
    long long ans = 0;
    vector<long long> dp(mod + 1);
    dp[0] = 1;
    long long d = 1, x = 0;
    for (int i=s.size()-1;i>=0;i--) 
    {
        x = (x + d * (s[i] - '0')) % mod;
        ans += dp[x];
        dp[x] += 1;
        d = (d * 10) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD 998244353
typedef long long int lli;

int main(){
    int n;
    cin >> n;
    vector<lli> d(n);
    vector<lli> d_memo(n);
    lli d_max = 0;
    for(int i = 0; i < n; ++i){
        cin >> d[i];
        d_max = max(d_max, d[i]);
        d_memo[d[i]]++;
    }

    if(d[0] != 0 || d_memo[0] != 1){
        puts("0");
        return 0;
    }

    lli ans = 1;
    for(int i = 1; i <= d_max; ++i){
        for(int l = 0; l < d_memo[i]; ++l){
            ans = (ans % MOD) * (d_memo[i - 1] % MOD) % MOD;
        }
    }

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

Measured memory_bytes: 2296
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<"::"<<x<<endl;
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
void solve()
{
	int h,w;
	cin>>h>>w;
	vector<string>v(h);
	for(int i=0;i<h;i++)
	{
		cin>>v[i];
	}	
	vector<vector<int> >dp(h,vector<int>(w,0));
	dp[0][0]=1;
	for(int i=1;i<h;i++)
	{
		if(v[i][0]=='.')
		{
			dp[i][0]=dp[i-1][0];
		}
	}
	for(int j=1;j<w;j++)
	{
		if(v[0][j]=='.')
		{
			dp[0][j]=dp[0][j-1];
		}
	}
	for(int i=1;i<h;i++)
	{
		for(int j=1;j<w;j++)
		{
			if(v[i][j]=='.')
			{
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
			}
		}
	}
	cout<<dp[h-1][w-1]<<'\n';
}

int main()
{
	int t;
	t=1;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 5248
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=100100,P=1e9+7;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int n,a[N];
bool check(int x){
	ll nw=a[x],i;
	for(i=1;i<=n;i++)
	if(i!=x){
		if(a[i]>nw+nw)return 0;
		nw+=a[i];
	}return 1;
}
int main(){
	int i,l,r;
	n=read();
	for(i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	l=0;r=n;while(l<r-1)
	check((l+r)>>1)?r=(l+r)>>1:l=(l+r)>>1;
	printf("%d\n",n-l);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>

using namespace std;

class Edge{
public:
	int p, q, cost;
	Edge(int p, int q, int cost) : p(p), q(q), cost(cost) {}
	bool operator < (const Edge &e) const { return cost > e.cost; }
};

int main(){
	int n, s, t; 
	while(cin >> n >> s >> t, n){
		s--; t--;
		int cst[100][100];
		int sign[100], out[100];
		for(int i=0;i<n;i++) cin >> sign[i];
		vector< vector<Edge> > graph(n);
		memset(out,0,sizeof(out));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin >> cst[i][j];
				if(cst[i][j]){ out[i]++; graph[i].push_back(Edge(i,j,cst[i][j])); }
			}
		}
		vector<int> dist(n,-1);
		priority_queue<Edge> qu; qu.push(Edge(-2,t,0));
		while(!qu.empty()){
			Edge e = qu.top(); qu.pop();
			int pos = e.q, ccost = e.cost;
			if(!(dist[pos]<0)) continue;
			dist[pos] = ccost;
			for(int i=0;i<graph[pos].size();i++)
				qu.push(Edge(pos,graph[pos][i].q,ccost+cst[pos][graph[pos][i].q]));
		}
		if(dist[s]==-1) { puts("impossible"); return 0; }
		double a[100][100], b[100];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) a[i][j] = 0;
			b[i] = 0;
		}
		for(int i=0;i<n;i++){
			if(i==t){
				a[i][i] = 1.0; 
			} else if(sign[i]){
				a[i][i] = 1;
				int cnt = 0;
				for(int j=0;j<n;j++){
					if(cst[i][j]!=0&&dist[i]>-1&&dist[j]>-1&&dist[i]==dist[j]+cst[i][j]) cnt++;
				}
				for(int j=0;j<n;j++){
					if(cst[i][j]!=0&&dist[i]>-1&&dist[j]>-1&&dist[i]==dist[j]+cst[i][j]){
						a[i][j] -= 1.0/cnt;
						b[i] += (double)cst[i][j]/cnt;
					}
				}	
			} else {
				a[i][i] = 1;
				for(int j=0;j<n;j++){
					if(cst[i][j]){
						a[i][j] -= 1.0/out[i];
						b[i] += (double)cst[i][j]/out[i];
					}
				}
			}
		}
		for(int i=0;i<n;i++){
			int pivot = i;
			for(int j=i+1;j<n;j++)
				if(abs(a[j][i])>abs(a[pivot][i])) pivot = j;
			for(int j=0;j<n;j++) swap(a[i][j],a[pivot][j]);
			swap(b[i], b[pivot]);
			double div = a[i][i];
			for(int j=0;j<n;j++) a[i][j] /= div; b[i] /= div;
			for(int j=i+1;j<n;j++){
				double mul = a[j][i];
				for(int k=0;k<n;k++)
					a[j][k] -= a[i][k]*mul;
				b[j] -= b[i]*mul;
			}
		}
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<i;j++){
				b[j] -= a[j][i]*b[i];
			}
		}
		double ans = 0.0;
		int cnt = 0;
		for(int i=0;i<n;i++){
			if(dist[i]!=-1){
				cnt++;
				ans += b[i];
			}
		}
		printf("%.9lf\n", b[s]);
	}
}

Measured memory_bytes: 0
/*
	  Chase
	   Your
	  Legend

	英雄志逐传奇
*/

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	int X, D;
	cin >> X >> D;

	vector<vector<int>> vec(X, vector<int>(D));
	rep(i, X) {
		rep(j, D) {
			cin >> vec[i][j];
		}
	}

	vector<double>qvec(X);
	int ans = 0;

	for (int i = 0; i < X; i++) {
		for (int j = i + 1; j < X; j++) {

			int Z = 0;

			for (int k = 0; k < D; k++) {
				int def = abs(vec[i][k] - vec[j][k]);
				Z = Z + def * def;
			}

			for (int m = 0; m <= Z; m++) {
				if (m * m == Z) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const int MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
struct Combination {

	vector<llong> fact, rfact;

	Combination(llong sz) : fact(sz + 1), rfact(sz + 1) {

		fact[0] = 1;
		for (llong i = 1; i < fact.size(); i++) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		//逆元
		rfact[sz] = inv(fact[sz]);
		for (llong i = sz - 1; i >= 0; i--) {
			rfact[i] = rfact[i + 1] * (i + 1) % MOD;
		}
	}

	llong inv(llong x) {
		return pow(x, MOD - 2);
	}
	llong pow(llong x, llong n) {
		llong ret = 1;
		while (n > 0) {
			if (n & 1) (ret *= x) %= MOD;
			(x *= x) %= MOD;
			n >>= 1;
		}
		return (ret);
	}
	llong P(llong n, llong r) {
		if (r < 0 || n < r) return (0);
		return (fact[n] * rfact[n - r] % MOD);
	}

	llong C(llong p, llong q) {
		if (q < 0 || p < q) return (0);
		return (fact[p] * rfact[q] % MOD * rfact[p - q] % MOD);
	}

	llong H(llong n, llong r) {
		if (n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};

int main() {
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	int n = (2 * x - y) / 3;
	int m = (2 * y - x) / 3;
	if (n < 0 || m < 0) {
		cout << 0 << endl;
		return 0;
	}
	Combination com(n+m);
	llong ans = com.C(m + n, n);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 10624
#include<stdio.h>

int main()

{
    int height[15],i,j,temp;

    for(i=0;i<10;i++)
        scanf("%d",& height[i]);
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
            if(height[i]>height[j]){

                temp=height[j];
                 height[j]=height[i];
                 height[i]=temp;

            }
        }
    }
      for(i=9;i>6;i--)
      {
          printf("%d\n",height[i]);

      }
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <iterator>
#include <unordered_map>

int main()
{
  int N;
  std::unordered_map<int, bool> m;
  int ans = 0;

  std::cin >> N;
  for (int i=0; i<N; i++) {
    int x;
    std::cin >> x;
    auto search = m.find(x);
    if (search == m.end()) m.emplace(x, true);
    else search->second = !search->second;
  }
  for (auto iter=m.begin(); iter!=m.end(); iter++) {
    if (iter->second) ans++;
  }

  std::cout << ans;

  return 0;
}


Measured memory_bytes: 4388
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN;

  std::cin >> NN;

  ll L[NN];
  for (size_t i = 0; i < NN; i++) {
    std::cin >> L[i];
  }

  ll sum=0, max=0;

  for (size_t i = 0; i < NN; i++) {
    if (max < L[i]) {
      max = L[i];
    }
    sum+= L[i];
  }

  if (max >= sum - max) {
    std::cout << "No" << '\n';
  }else{
    std::cout << "Yes" << '\n';
  }


  return 0;
}


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

#define int long long

using namespace std;

const int MAXN = 2e5 + 100;

vector<int> L[MAXN];

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

    int N;
    cin >> N;

    for(int i = 0 ; i < N-1 ; i++)
    {
    	int a, b;
    	cin >> a >> b;
    	L[a].push_back(b);
    	L[b].push_back(a);
    }

    int sum = 0, comp = 0, res = 0;

    for(int i = 1 ; i <= N ; i++)
    {
    	comp++;
    	for(auto v : L[i])
    	{
    		if(v < i)
    		{
    			comp--;
    			sum -= N-i+1;
    		}
    		else
    		{
    			sum += N-v+1;
    		}
    	}

    	res += sum - comp*(N-2*i);
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 15824
#include<iostream>
using namespace std;
int n; 
int main(){
	cin>>n;
	n=n%10;
	if(n==2 || n==4 || n==5 || n==7 || n==9){
		cout<<"hon"<<endl; return 0; 
	}
	if(n==1 || n==0 || n==6 || n==8){
		cout<<"pon"<<endl; return 0; 
	}
	cout<<"bon"<<endl;
}

Measured memory_bytes: 3592
import math
n = int(input())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([x,y])
dist = []
for i in range(len(c)):
    for j in range(len(c)):
        dist.append(math.sqrt(pow(c[i][0]-c[j][0],2)+pow(c[i][1]-c[j][1],2)))
print(sum(dist)/n)

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <climits>
#include <utility>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#define REP(i,n) for(int (i)=0;i<(int)(n);++(i))
#define REPIT(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define PB push_back
#define FT first
#define SD second
#define ZERO(x) memset(x,0,sizeof(x))
#define NEG(x) memset(x,-1,sizeof(x))
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define OIII(x,y,z) printf("%d %d %d\n",(x),(y),(z))
#define OII(x,y) printf("%d %d\n",(x),(y))
#define OI(x) printf("%d\n",(x))
#define OL(x) cout<<(x)<<endl
#define OLL(x,y) cout<<(x)<<" "<<(y)<<endl
#define OLLL(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define RS(s) scanf("%s",(s))
#define MP(x,y) make_pair((x),(y))
#define SZ(x) ((int)(x).size())
#define FIN(f) freopen(f,"r",stdin)
#define FOUT(f) freopen(f,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<int,int> PII;
const int MOD = 1e9+7;
const int maxn = 222222;
string s;
int a[4];
int main(int argc, char const *argv[])
{
    cin>>s;
    REP(i,SZ(s)) {
        if(s[i] == 'N')a[0]++;
        else if(s[i] == 'S')a[1]++;
        else if(s[i] == 'W')a[2]++;
        else if(s[i] == 'E')a[3]++;
    }
    if(a[0] > 0 && a[1] == 0)puts("No");
    else if(a[0] == 0 && a[1] > 0)puts("No");
    else if(a[2] == 0 && a[3] > 0)puts("No");
    else if(a[3] == 0 && a[2] > 0)puts("No");
    else puts("Yes");
    return 0;
}

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

btn_list = {i:int(input()) for i in range(1,n+1)}

count = 1
right = btn_list[1]

while True:
    if right == 2:
        print(count)
        break
    elif count == n:
        print(-1)
        break
    else:
        count += 1
        right = btn_list[right]

Measured memory_bytes: 55640
def main():
    # input
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    # 訪れた頂点のメモ
    s = []
    # sの中のインデックスに対応, 訪れていない点は−１に対応
    order = [-1]*(n+1)
    c = 1 # 周期
    v = 1 # vertex, 1から始める
    while order[v] == -1:
        order[v] = len(s) 
        s.append(v) # 訪れた頂点の記録
        v = a[v-1] # 次の頂点へ


    l = order[v] # 例外部分の長さ
    c = len(s) - l
    if k < l :
        print(s[k])
    else:
        k -= l
        k %= c
        print(s[l+k])

if __name__ == "__main__":
    main()

Measured memory_bytes: 32316
#include <cstdio>
#include <algorithm>
#include <cmath>
#define Rint register int
#define LL long long
#define F(x,y,z) for(Rint x=y;x<=z;++x)
#define D(x,y,z) for(Rint x=y;x>=z;--x)
using namespace std;
LL Min(LL x,LL y){return x<y?x:y;}
LL Max(LL x,LL y){return x>y?x:y;}
inline LL R(){
    char c='!';LL x=0,z=1;
    for( ; c>'9'||c<'0';c=getchar()) if(c=='-')z=-1;
    for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
    return x*z;
}
int n,m,ans;
int a[10010];
int main(){
	n=R();
	F(i,1,n) a[i]=R();
	F(i,1,n)
		if (a[i]==a[i-1]){
			++ans;
			a[i]=-1;
		}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target("avx")
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[100001][3];

int main(void){
    cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vvl a(n,vl(3));
	rep(i,n) rep(j,3){
	    cin>>a[i][j];
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	rep(i,n-1){
	    ll one = max(dp[i][1],dp[i][2]);
	    dp[i+1][0] = max(dp[i+1][0],one+a[i+1][0]);
	    one = max(dp[i][0],dp[i][2]);
	    dp[i+1][1] = max(dp[i+1][1],one+a[i+1][1]);
	    one = max(dp[i][0],dp[i][1]);
	    dp[i+1][2] = max(dp[i+1][2],one+a[i+1][2]);
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 8064
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())
a = []

for _ in range(n):
    var = int(input())
    a.append(var)

first = int(max(a))
if 1<a.count(first):
    second = int(first)
else:
    second = sorted(set(a))[-2]

for _ in a[:]:
    if _ == first:
        print(second)
    else:
        print(first)

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

 int main() {
   int N;
   cin >> N;
   int a = N;
   int b = 0;
   while(a > 0){
     b += a%10;
     a /= 10; 
   }
  if(N%b == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
 }

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

using namespace std;

using ll = long long;

ll a[100000], b[100000];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  ll ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    if ((a[i] + ans) % b[i] == 0)
      continue;
    ans += b[i] - (a[i] + ans) % b[i];
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

int main(){
    string s;
    cin >> s;
    bool flag = true;
    for (int i = 0; i < 4; i++) {
        if(stringcount(s, s[i]) != 2){
            flag = false;
        }
    }
    Yes(flag);
    return 0;
}

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

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

    vector<int> parent(N + 1, 0);

    int A;
    for (int i = 2; i <= N; i++)
    {
        cin >> A;
        parent[i] = A;
    }

    vector<int> ans(N + 1, 0);
    vector<bool> visited(N + 1, false);
    for (int i = N; i > 0; i--)
    {
        int n = i;
        while (n != 0 && !visited[n])
        {
            visited[n] = true;
            n = parent[n];
            ans[n]++;
        }
    }
    for (int i = 1; i <= N; i++)
    {
        cout << ans[i] << endl;
    }
}


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

using namespace std;

typedef vector<int> vi;

const int maxn = 100;

vi V[maxn];
int n, k;

int main()
{
  cin >> n >> k;
  if (k > (n - 1) * (n - 2) / 2)
    cout << -1, exit(0);

  int cnt = (n - 1) * (n - 2) / 2, m = 0;
  for (int i = 1; i < n; ++i)
    V[0].push_back(i), ++m;

  for (int i = 1; i < n && k < cnt; ++i)
    for (int j = i + 1; j < n && k < cnt; ++j)
      V[i].push_back(j), --cnt, ++m;

  cout << m << '\n';
  for (int i = 0; i < n; ++i)
    for (int j : V[i])
      cout << i + 1 << ' ' << j + 1 << '\n';
}



Measured memory_bytes: 256
#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)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

pii p[100000];

int main() {
  int n,m;
  while(input(n,m)) {
    REP(i,n) input(p[i].first, p[i].second);
    sort(p,p+n);
    priority_queue<int> Q;
    int j=0;
    int ans = 0;
    REPR(i,m) {
      while(j<n&&p[j].first<=m-i) {
        Q.push(p[j].second);
        j++;
      }
      if (!Q.empty()) {
        ans += Q.top();
        Q.pop();
      }
    }
    cout << ans << endl;
  }
}


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

int main()
{
    double v, t, y, n;

    while( cin >> v )
    {
        t = v / 9.8;                 //t秒間に
        y = 4.9 * t * t;             //yだけ落下

        n = ( y + 5 ) / 5;           //n階
        if( n - (int)n > 0 )         //nが少数で出たら、切り上げ。
            n = (int)( n + 1 );
        cout << n << endl;
    }
    return 0;
}


Measured memory_bytes: 3300
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final BigInteger MOD = BigInteger.valueOf((long) 1e9 + 7);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int k = in.nextInt();

        for (int i=1; i <= k; i++) {
            out.println(n-k-i+1 < 0 ? 0 : combination(n-k+1, i).mod(MOD).multiply(combination(k-1, i-1)).mod(MOD));
        }
    }

    /**
     * Returns Combination(a, b) = aCb
     * @param a Integer
     * @param b Integer
     * @return Combination
     */

    private static BigInteger combination(int a, int b) {
        BigInteger ret = BigInteger.ONE;
        for (int i=a; i > a-b; i--) {
            ret = ret.multiply(BigInteger.valueOf(i)).mod(MOD);
        }
        for (int i=1; i <= b; i++) {
            ret = ret.multiply(BigInteger.valueOf(i).modInverse(MOD)).mod(MOD);
        }
        return ret;
    }


}


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

#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const int MAXN = 5e5+5;
const int MOD= 998244353;
int main(){
    ll h,w;
    while(cin>>h>>w){
        if(h==1||w==1){
            cout<<1<<endl;
            continue;
        }
        ll ans;
        if(h%2==0){
            ans=h/2*w;
        }
        else{
            ans=h;
            if(w%2==0){
                ans*=(w/2);
            }
            else{
                ans*=(w/2);
                ans+=h/2+1;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int a[15][15];
signed main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        REP(j,m){
            cin >> a[i][j];
        }
    }
    int minn = INF;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        vector<int> v(m, 0);
        int cnt = 0;
        for (int i = 0; i < n; i++)
        {
            if((1<<i) & bit ){
                cnt += c[i];
                REP(j, m)
                {
                    v[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for (int i = 0; i < m; i++)
        {
            if(v[i]<x){
                ok = false;
                break;
            }
        }
        if(ok){
            chmin(minn, cnt);
        }
    }
    if(minn!=INF)cout << minn << endl;
    else{
        cout << -1 << endl;
    }
    return 0;
}

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

int main(){
  int n; cin>>n;
  bool x[10000],y[10000];
  string s[10000];
  long long b=0,a=0,c=0,ans1=0,ans2=0;
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<s[i].size()-1;j++){
    if(s[i][j]=='A'&&s[i][j+1]=='B'){
      ans1++;
     }
    }
  }
  for(int i=0;i<n;i++){
      if(s[i][0]=='B'&&s[i][s[i].length()-1]=='A'){
        c++;
      }
      else if(s[i][s[i].length()-1]=='A'){
        a++;
      }
     else if(s[i][0]=='B'){
        b++;
    }
  }
  if(a==0&&b==0&&c!=0){
    ans2=c-1;
  }
  else{
    ans2=min(a,b)+c;
  }
  cout<<ans2+ans1<<endl;
  return 0;
}

Measured memory_bytes: 768
// https://arc103.contest.atcoder.jp/tasks/arc103_c
#ifndef _GLIBCXX_DEBUG
#define NDEBUG
#endif
#include<cassert>
#include<iostream>
#include<string>
auto&I=std::cin;auto&O=std::cout;
int main(){
	std::ios::sync_with_stdio(false);I.tie(nullptr);
	std::string s;I>>s;
	int nNode=s.size();
	s='0'+s;
	for(char& c:s)c-='0';

	for(int i=0;i*2<=nNode;++i)
		if(s[i]!=s[nNode-i]){
			O<<"-1\n";
			return 0;
		}
	if(not s[1]){ // it's always possible to split an edge adj to a leaf to create a connected
		// component with size 1
		O<<"-1\n";
		return 0;
	}

	int root=1,lastUsedNode=1;
	int nNodeInRoot=1;
	while(true){
		assert(s[nNodeInRoot]);
		assert(nNodeInRoot<nNode);
		O<<root<<' '<<++lastUsedNode<<'\n';
		root=lastUsedNode;
		++nNodeInRoot;
		if(nNodeInRoot==nNode)
			return 0;

		while(not s[nNodeInRoot]){
			O<<root<<' '<<++lastUsedNode<<'\n';
			++nNodeInRoot;
			if(nNodeInRoot==nNode)
				return 0;
			else{
				assert(nNode+1u==s.size());
				assert(nNodeInRoot<=nNode);
			}
		}
	}

}


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  for(int i = 0; i < n; ++i){
    cin >> l[i];
  }
  int c = 1;
  int res = 0;
  for(int i = 0; i < n; ++i){
    res += l[i];
    if(res <= x){
      c += 1;
    }else{
      break;
    }
  }
  cout << c;
}

Measured memory_bytes: 3572
from collections import Counter, deque, defaultdict
def inpl(): return list(map(int, input().split()))

MOD = 10**9 + 7
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
size = 2*10**5 + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD


N = int(input())
A = inpl()
C = Counter(A)
for k, v in C.items():
    if v == 2:
        break
l = A.index(k)
r = N - A[::-1].index(k)

d = r - l - 1

print(N)
print((1 + N-1 + d + cmb(N-1, 2, MOD))%MOD)
for k in range(3, N+2):
    X = cmb(N-1, k-1, MOD)
    Y = cmb(N-1-d, k-1, MOD)
    Z = X - Y
    tmp = cmb(N-1, k, MOD) + Y + 2*Z + cmb(N-1, k-2, MOD)
    print(tmp%MOD)

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

using namespace std;

#define int long long int
#define pi pair<int,int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 5005;

pi a[N];
int dp[N][N];

bool cmp(pi &a, pi &b){
	return a.fi+a.se < b.fi+b.se;
}

signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
	#endif
	IOS;
	int n;	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i].fi >> a[i].se;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			dp[i][j] = 1e18;
	sort(a+1, a+n+1, cmp);
	dp[1][1] = a[1].se;
	for(int i = 2; i <= n; i++){
		for(int j = 1; j <= i; j++){
			dp[i][j] = dp[i-1][j];
			if(a[i].fi >= dp[i-1][j-1])
				dp[i][j] = min(dp[i][j], dp[i-1][j-1] + a[i].se);
		}
	}
	for(int i = n; i >= 1; i--)
		if(dp[n][i] != 1e18)
			return cout << i, 0;
	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<P> D(n);
  rep(i,n) cin >> D[i].first >> D[i].second;
  int cnt = 0;
  
  rep(i,n){
    if(D[i].first == D[i].second) cnt++;
    else cnt = 0;
    
    if(cnt >= 3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            int[] H = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int ans = 0;
            while (H.Any(x => x > 0))
            {
                int last = 0;
                for (int i = 0; i < H.Length; i++)
                {
                    if (last == 0 && H[i] > 0)
                    {
                        ans++;
                    }

                    last = H[i];
                    if (H[i] > 0)
                    {
                        H[i]--;
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;
public class Main{
	public static void main(String args[]){
    	Scanner sc= new Scanner(System.in);
    	int A=sc.nextInt();
    	int P=sc.nextInt();
     	int N;
    	N=(3*A+P)/2;
    	System.out.println(N);
    }
}


Measured memory_bytes: 21844