akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  string a,s,c;cin>>a>>s>>c;
  string ans="A"+s.substr(0,1)+"C";
  cout(ans);
  return 0;
}

Measured memory_bytes: 125696
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll Max = 10000000;
ll divs[Max + 66];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	for (int i=1; i<=Max; i++) {
		for (int j=i; j<=Max; j+=i) {
			divs[j] += 1;
		}
	}
	ll n, ans = 0;
	cin >> n;
	for (int i=1; i<=n; i++) ans += (divs[i]*i);
	cout << ans;
	return 0;
}

Measured memory_bytes: 81748
/*"Nothing is true."*/
#include<bits/stdc++.h>
using namespace std;
inline int min(int _a, int _b) {return _a < _b ? _a : _b;}
inline int max(int _a, int _b) {return _a > _b ? _a : _b;}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

template <class _T> inline void rd(_T &_a) {
	int _f=0,_ch=getchar();_a=0;
	while(_ch<'0' || _ch>'9'){if(_ch=='-')_f=1;_ch=getchar();}
	while(_ch>='0' && _ch<='9')_a=(_a<<1)+(_a<<3)+_ch-'0',_ch=getchar();
	if(_f)_a=-_a;
}

int main() {
	//freopen("AtCoder_020_A.in","r",stdin);
	//freopen("AtCoder_020_A.out","w",stdout);
	int n, a, b;
	rd(n); rd(a); rd(b);
	if((b - a) & 1 == 1) puts("Borys");
	else puts("Alice");
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int N;
    int x[110000],y[110000],t[110000];
    x[0]=y[0]=t[0]=0;
    cin>>N;
    for(int i=0;i<N;i++)cin>>t[i+1]>>x[i+1]>>y[i+1];

    bool can=true;
    for(int i=0;i<N;i++){
        int dt=t[i+1]-t[i];
        int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if(dt<dist)can=false;
        if(dt%2!=dist%2)can=false;
    }

    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 1408
H, W = map(int, input().split())
a = list(input() for _ in range(H))
h = []
w = []
w_list = []

for i in range(H):
  if a[i] == "." * W:
    h.append(i)
  for j in range(W):
    if a[i][j] == ".":
      w.append(j)

w_set = list(set(w))
for x in range(len(w_set)):
  if w.count(w_set[x]) == H:
    w_list.append(w_set[x])

for i in range(H):
  A = ""
  if a[i] != "." * W:
    for j in range(W):
      if not j in w_list:
        A += a[i][j]
    print(A)

Measured memory_bytes: 3188
N, = map(int, input().split())
R = [0] * (N**2+1)
V = [0] * (N**2+1)
X = list(map(int, input().split()))
for ai in range(N**2):
    i, j = divmod(ai, N)
    R[ai+1] = min([i, N-i-1, j, N-j-1])

r = 0
for a in X:
    r += R[a]
    V[a] = 1
    stack=[a]
    while stack:
        v = stack.pop()
        ccs = []
        if v>N:
            ccs.append(v-N)
        if v<N**2+1-N:
            ccs.append(v+N)
        if v%N:
            ccs.append(v+1)
        if v%N!=1:
            ccs.append(v-1)
        for u in ccs:
            if R[v]>=R[u] or ((1-V[v]) and R[v]+1 >= R[u]):
                continue
            R[u] -= 1
            stack.append(u)
print(r)


Measured memory_bytes: 169568
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define fi first
#define se second
#define ll long long
int main(){
	ll n, m, k;
	scanf("%lld %lld %lld", &n, &m, &k);
	pair<ll, ll> a[n];
	for (ll i = 0; i < n; i++) scanf("%lld %lld", &a[i].fi, &a[i].se);
	sort(a, a + n);
	m = m * 2;
	vector<pair<ll, ll> > v;
	v.emplace_back(-2147483648ll, 0ll);
	for (ll i = 0; i < n; i++){
		pair<ll, ll> p = *(lower_bound(v.begin(), v.end(), make_pair(a[i].fi - m, -2147483648ll)) - 1);
		ll t = v[v.size() - 1].se - p.se, t2 = 0ll;
		if (t * k < a[i].se){
			t2 = (a[i].se - t * k) / k + 1;
			if ((a[i].se - t * k) % k == 0) t2--;
		}
		v.emplace_back(a[i].fi, v[v.size() - 1].se + t2);
	}
	printf("%lld\n", v[v.size() - 1].se);
}

Measured memory_bytes: 9456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin>>n>>m;
    vector<P> ab;
    rep(i, n){
        int a,b; cin>>a>>b;
        ab.emplace_back(a,b);
    }
    sort(ab.begin(), ab.end());
    ll ans = 0;
    int cnt = 0;
    for(P p : ab){
        while(p.second!=0) {
            ans += p.first;
            cnt++;
            p.second--;
            if(cnt==m) break;
        }
        if(cnt==m) break;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 1400
import queue
k = int(input())
q = queue.Queue()
for i in range(1,10):
    q.put(i)
cnt = 0
runrun = 0
while cnt < k:
    runrun = q.get()
    cnt += 1
    x = runrun % 10
    if x != 0:
        q.put(10 * runrun + x - 1)
    q.put(10 * runrun + x)
    if runrun % 10 != 9:
        q.put(10 * runrun + x + 1)
print(runrun)

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

int main() {
    int h,n;
    cin >> h >> n;
    int atk=0;
    for(int i = 0; i < n; i++){
        int buf;
        cin >> buf;
        atk += buf;
    }
    cout << ((atk >= h)?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
int gcd(int _a, int _b) {
  unsigned int a = abs(_a), b = abs(_b);
  if(a == 0) return b;
  if(b == 0) return a;
  int shift = __builtin_ctzll(a | b);
  a >>= __builtin_ctzll(a);
  do {
    b >>= __builtin_ctzll(b);
    if(a > b) std::swap(a, b);
    b -= a;
  }while(b);
  return (a << shift);
}

int cnt[1000001];
int main(){
  int n;scanf("%d", &n);
  for(int i=0;i<n;i++) {
    int num;scanf("%d", &num);
    cnt[num]++;
  }
  int max_S = 0;
  for(int i=2;i<=1000000;i++){
    int S = 0;
    for(int j=i;j<=1000000;j+=i) S += cnt[j];
    max_S = std::max(max_S, S);
  }
  if(max_S<2) printf("pairwise coprime\n");
  else if(max_S != n) printf("setwise coprime\n");
  else printf("not coprime\n");
}


Measured memory_bytes: 7580
N = int(input())

a_max = N // 4
b_max = N // 7

match = False
for i in range(a_max+1):
    for j in range(b_max+1):
        if i*4 + j*7 == N:
            match = True

if match:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;

int main() {


    int N;
    cin >> N;

    int m = 0;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        m = max(m, p);
        sum += p;
    }

    sum -= (m / 2);

    cout << sum << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  map<ll,ll> mp;
  int cnt=0;
  vector<ll> u;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    if(mp.find(a)!=mp.end()){
      mp[a]++;
    }
    else{
      cnt++;
      mp[a]=1;
      u.push_back(a);
    }
  }
  if(n%3!=0){
    if(u[0]==0&cnt==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  if(cnt>3){
    cout<<"No"<<endl;
    return 0;
  }
  if(cnt==1){
    if(u[0]==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  if(cnt==2){
    int id=0;
    if(mp[u[0]]<mp[u[1]]) id=1;
    if(u[(id+1)%2]==0&&mp[u[id]]==mp[u[(id+1)%2]]*2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }
  else if(cnt==3){
  //  cout<<"SSSS"<<(u[0]^u[1])<<" "<<u[2]<<endl;
    if((u[0]^u[1])==u[2]&&mp[u[0]]==mp[u[1]]&&mp[u[1]]==mp[u[2]]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
  }

}


Measured memory_bytes: 7416
// ABC075-D
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))

int N, K;
ll x[60], y[60];

int main() {
   cin >> N >> K;
   rep (i, 0, N) cin >> x[i] >> y[i];

   ll area = 1LL << 62;
   rep (xi, 0, N) {
      rep (xj, 0, N) {
         rep (yi, 0, N) {
            rep (yj, 0, N) {
               if (x[xi] <= x[xj] && y[yi] <= y[yj]) {
                  int cnt = 0;
                  rep (p, 0, N) {
                     if (x[p] >= x[xi] && x[p] <= x[xj] && y[p] >= y[yi] && y[p] <= y [yj]) {
                        cnt++;
                     }
                  }
                  if (cnt >= K) {
                     area = min(area, (x[xj]-x[xi]) * (y[yj]-y[yi]));
                  }
               }
            }
         }
      }
   }
   cout << area << endl;

   return 0;
}

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

int main(){
    int n;
    int a[10000];
    int count=0;
    int sum=0;
    while(true){
        cin >>n;
        if(n==0)
        break;
        for(int i=0;i<n;i++){
            cin >> a[i];
            sum+=a[i];
        }
        for(int i=0;i<n;i++){
            if(a[i]<=sum/n)
            count++;
        }
        cout << count << endl;
        count=0;
        sum=0;
    }
    return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

string str;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    cin>>str;

    int Min = 1e8, cnt = 0, flag = 0;
    int len = str.size();

    for(int i = 0; i < len; i++){
        if(!flag){
            if(str[i] == '1')
                cnt++;
            flag = 1;
        }
        else{
            if(str[i] == '0')
                cnt++;
            flag = 0;
        }
    }

    Min = min(Min, cnt);
    cnt = 0, flag = 1;

    for(int i = 0; i < len; i++){
        if(!flag){
            if(str[i] == '1')
                cnt++;
            flag = 1;
        }
        else{
            if(str[i] == '0')
                cnt++;
            flag = 0;
        }
    }
    Min = min(Min, cnt);

    cout<<Min<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll n, m, i, fact[100010];
  fact[0] = 1;
  for(i = 1; i < 100010; ++i) fact[i] = (fact[i - 1] * i) % mod;
  scanf("%lld%lld", &n, &m);
  if(n - 1 <= m && m <= n + 1) printf("%lld", (fact[n] * fact[m] * (n == m ? 2 : 1)) % mod);
  else printf("0");
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <list>
#include <stack>
#include <set>
#include <cctype>
#include <cmath>

using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

#define ll long long
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)


int main() {

	char b;
	cin >> b;

	if (b == 'A') {
		cout << 'T' << endl;
	} else if (b == 'T') {
		cout << 'A' << endl;
	}else if (b == 'G') {
		cout << 'C' << endl;
	}else if (b == 'C') {
		cout << 'G' << endl;
	}


}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int N;
    scanf("%d",&N);

    char Map[2][N+1];
    scanf("%s",Map[0]);
    scanf("%s",Map[1]);

    long ans=1;
    for(int i=0;i<N;i++){
        //縦置きのとき
        if(Map[0][i]==Map[1][i]){
            if(i==0) ans=(ans*3)%MOD;
            else{
                //一個前も縦置きなら
                if(Map[0][i-1]==Map[1][i-1]) ans=(ans*2)%MOD;
            }
        }
        //横置きのとき
        else{
            if(i==0) ans=6;
            else{
                //一個前も縦置きなら
                if(Map[0][i-1]==Map[1][i-1]) ans=(ans*2)%MOD;
                else{
                    if(Map[0][i]!=Map[0][i-1]) ans=(ans*3)%MOD;
                }
            }
        }
    }
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <fstream>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


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


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=2e5+5;
ll mod=1e9+7;
ll mul (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll add (ll a, ll b)
{
    a%=mod;
    b%=mod;
    return (a+b+mod)%mod;
}
ll fastpow(ll b, ll p)
{
    if(p==0)
        return 1;
    ll ans=fastpow(b,p/2);
    ans=mul(ans,ans);
    if(p%2)ans=mul(ans,b);
    return ans;
}


int main()
{
    FIO
    ll a,b,x,y;
    cin>>a>>b>>x>>y;
    ld ans=(ld)(a*b)/2.0;
    bool good=((((a)/2)==x)&&((b)/2==y)&&(a%2==0)&&(b%2==0));
    cout<<fixed<<setprecision(12)<<ans<<" ";
    cout<<good<<endl;
    return 0;
}

Measured memory_bytes: 3720
A = []
for i in range(3):
    a = list(map(int,input().split()))
    A.extend(a)
n = int(input())
B = [0]*9
for i in range(n):
    b = int(input())
    for i in range(9):
        if A[i] == b:
            B[i] = 1
ans = 0
for i in range(3):
    if B[i*3] == B[i*3+1] == B[i*3+2] == 1:
        ans = 1
    if B[i] == B[i+3] == B[i+6] == 1:
        ans = 1
    if B[0] == B[4] == B[8] == 1:
        ans = 1
    if B[2] == B[4] == B[6] == 1:
        ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define all(c)	(c).begin(),(c).end()
#define rall(c)	(c).rbegin(),(c).rend()
#define rep(i,N)	for(int i=0;i<N;++i)
#define pb	push_back
#define eb	emplace_back

using ll = long long;

constexpr ll INF = 0x1fffffffffffffff;
constexpr int inf = 0x1fffffff;
constexpr double inf_l = 1e18;
constexpr ll MOD = 1000000007LL;
constexpr int mod = 1000000007;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N; cin >> N;
	vector<int> A(N + 1, 0);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += A[i] / 2;
		if ((A[i] & 1) && A[i + 1]>0) {
			++ans;
			--A[i + 1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<map>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<stack>
#include<vector>
#include<cmath>
using namespace std;

char s[1000];

int main(){
	cin >> s + 1;
	int len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		if(s[i] == 'A' && s[i + 1] == 'C'){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

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

int main() {
    
    int ci, ro;
    cin >> ci >> ro;
    
    vector<int> counter(ci);
    
    for (int r = 0; r < ro; r++){
        int c1, c2;
        cin >> c1 >> c2;
        counter.at(c1 - 1) += 1;
        counter.at(c2 - 1) += 1;
    }
    
    for (int i = 0; i < ci; i++){
        cout << counter.at(i) << endl;
    }
}

Measured memory_bytes: 256
//#include <GOD>

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define si size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define E end()
#define B begin()
#define pi pair<int, int>
#define en cout << endl
#define cn const
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

cn int maxn = 1e3 + 10;
cn int mod = 1e9 + 7;
string a[maxn];
ll dp[maxn][maxn];

int main(){
	fast_io;
	int h, w;
	cin >> h >> w;
	for(int i = 0; i < h; i ++){
		cin >> a[i];
	}
	dp[0][0] = 1;
	for(int i = 0; i < h; i ++){
		for(int j = 0; j < w; j ++){
			if(a[i][j] != '#'){
				if(i > 0){
					dp[i][j] += dp[i - 1][j] % mod;
				}
				dp[i][j] %= mod;
				if(j > 0){
					dp[i][j] += dp[i][j - 1] % mod;
				}
				dp[i][j] %= mod;
			}
		}
	}
//	
//	for(int i = 0; i < h; i ++){
//		for(int j = 0; j < w; j ++){
//			cout << dp[i][j] << " ";
//		}
//		en;
//	}
	
	cout << dp[h - 1][w - 1] % mod;
	
	return 0;
}



Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);


ll power(ll x, ll pw, ll mod) {
    ll res = 1;
    x = x % mod;  // if it x >= p
    while (pw > 0) {
        if (pw & 1)
            res = (res*x) % mod;
        pw /= 2;
        x = (x*x) % mod;
    }
    return res;
}
ll modInverse(ll n, ll p) {
    return power(n, p-2, p) % p; // Fermat's little theorem
}
ll nCr(ll n, ll m, ll mod=1e9+7) {
    m = min(m, n-m);
    if (m == 0) return 1;
    ll num = 1, dem = 1;
    for(ll i = 1; i <= m; i++) {
        num = (num*(n+1-i)) % mod;
        dem = (dem*(i)) % mod;
    }
    return (num * modInverse(dem, mod)) % mod;
}

int main() {
    ll n, a, b, mod = 1e9+7;
    cin >> n >> a >> b;
    // formula 2^n-1 - nCr(n, a) - nCr(n, b)
    ll ans = power(2, n, mod) - 1;
    ans -= nCr(n, a, mod);
    ans -= nCr(n, b, mod);
    ans = (ans + mod*5) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, M=map(int, input().split())
A = [int(input()) for i in range(M)]

def fib(x):
    a = 1
    b = 1
    if x == 0:
        return 0
    elif x == 1:
        return a
    elif x == 2:
        return b
    else:
        for i in range(x-2):
            c = a + b
            a = b
            b = c
        return b 

before_a=1
output=1
if M>=1:
    output = fib(A[0])
    for i in range(M-1):
        output *= fib(A[i+1]-A[i]-1)
    output *= fib(N-A[M-1])
else:
    output *= fib(N+1)
print(output%1000000007)

Measured memory_bytes: 7080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, k;
ll arr[200005];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	REP(i, 0, n){
		cin >> arr[i];
	}
	ll mini = 0;
	ll maxi = 1000000000;
	while (mini + 1 != maxi){
		ll middle = (mini + maxi + 1)/2;
		ll cutneed = 0;
		REP(i, 0, n){
			if (arr[i] <= middle) continue;
			cutneed += (arr[i]/middle);
		}
		if (cutneed > k){
			mini = middle;
		} else {
			maxi = middle;
		}
	}
	cout << maxi << endl;
}

//cout.flush()

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

int main() {
  int H, W;
  cin>>H>>W;
  for (int i=0; i<H+2; i++){
    vector<char> vec(W+2);
    for (int j=0; j<vec.size(); j++){
      if (i==0 || i==H+1 || j==0 || j==W+1)
        vec.at(j)='#';
      else
        cin>>vec.at(j);
      cout<<vec.at(j);
    }
    cout<<endl;
  }
}


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

ll powmod(int x, int y) {
    ll res = 1;

    rep(i,y) {
        res = res * x % mod;
    }
    return res;
}

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

    ll ans = powmod(10, n) - 2*powmod(9, n) + powmod(8, n);
    ans %= mod;
    ans = (ans+mod) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

template <class... Args>
struct tuple_input_impl;
template <std::size_t i, std::size_t... tail>
struct tuple_input_impl<std::index_sequence<i, tail...>>
{
    template <class... Args>
    static void f(std::tuple<Args...>& x)
    {
        std::cin >> std::get<i>(x);
        tuple_input_impl<std::index_sequence<tail...>>::f(x);
    }
};
template <>
struct tuple_input_impl<std::index_sequence<>>
{
    static void f(...) {}
};

template <class... Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& x)
{
    tuple_input_impl<std::index_sequence_for<Args...>>::f(x);
    return in;
}

template <class T>
T read()
{
    T res;
    std::cin >> res;
    return res;
}
template <class T>
std::vector<T> read(std::size_t n)
{
    std::vector<T> res(n);
    for (std::size_t i = 0; i < n; ++i) std::cin >> res[i];
    return res;
}

template <class T, class... Args>
void out_impl(T&& v, Args&&... args)
{
    std::cout << std::forward<T>(v) << ' ';
    impl(std::forward<Args>(args)...);
}
template <class T>
void out_impl(T&& v) { std::cout << std::forward<T>(v); }
template <class... Args>
void out(Args&&... args)
{
    out_impl(std::forward<Args>(args)...);
    std::cout << '\n';
}
template <class... Args>
void out_noreturn(Args&&... args) { out_impl(std::forward<Args>(args)...); }

template <class T>
void print(const T& container)
{
    bool first = true;
    for (auto&& x : container) {
        if (!first) std::cout << ' ';
        std::cout << x;
        first = false;
    }
    std::cout << '\n';
}

void prog()
{
    int H, W, h, w;
    std::cin >> H >> W >> h >> w;
    out((H - h) * (W - w));
}

int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    prog();
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    int n, m;
    cin >> n >> m;
    vint p(m);
    vector<string> s(m);
    rep(i, m) {
        cin >> p[i] >> s[i];
    }
    set<int> st;
    map<int, int> mp;
    int ok = 0, pe = 0;
    for (int i = 0; i < m; i++) {
        bool check = true;
        auto itr = st.find(p[i]);
        if (itr != st.end()) {
            check = false;
        }
        if (s[i] == "WA") {
            mp[p[i]]++;
        } else if (s[i] == "AC" && check == true) {
            ok++;
            pe += mp[p[i]];
            st.insert(p[i]);
        }
    }

    cout << ok << " " << pe << endl;
    return 0;
}

Measured memory_bytes: 15488
s= input().strip()
f="Yes"
if (s.count('N')!=s.count('S') and s.count('N')*s.count('S')==0):
    f="No"
elif(s.count('E')*s.count('W')==0 and s.count('E')!=s.count('W')):
    f="No"
print(f)

Measured memory_bytes: 9024
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{
    int n,m,x;cin>>n>>m;
    n==m?x=1:x=0;
    TF(x);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
int main(){
    int s;
    cin>>s;
    int cnt=1;
    int next=s;
    if(s==2 || s==1){
        cout<<"4"<<endl;
        return 0;
    }

    while(next!=4){
        if(next%2==0){
            next=next/2;
        }
        else{
            next=3*next+1;
        }
        cnt++;
    }
    cnt+=3;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
long long nowm;
long long ans;
long long u;
int main(){
	cin>>n;
	while(n--){
		cin>>u;
		nowm=max(nowm,u);
		ans+=nowm-u;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3628
from sys import stdin
n,y = [int(x) for x in stdin.readline().rstrip().split()]
flag = False

for p in reversed(range(n+1)):
   if p * 10000 > y:
      continue
   else:
      for q in reversed(range(n-p+1)):
         if 10000*p + 5000*q + 1000*(n-p-q) == y:
            print(p,q,n-p-q)
            flag = True
            break
      if flag == True:
         break
   if flag == True:
      break
if flag == False:
   print(-1,-1,-1)

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

int main() {
	int n,m;
	cin>>n>>m;
	int target[m],tp[n],score[n]={0};
	
	for(int i=0;i<m;i++)cin>>target[i];
	
	for(int i=0;i<m;i++){
		int cnt=0;
		
		for(int j=0;j<n;j++)cin>>tp[j];
		
		for(int j=0;j<n;j++){
			if(tp[j]==target[i]){
				score[j]++;
			}else{
				cnt++;
			}
		}
		
		score[target[i]-1]+=cnt;
			
		//for(int j=0;j<n;j++)cout<<" "<<score[j];
		//cout<<endl;
	}
	for(int i=0;i<n;i++)cout<<score[i]<<endl;
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
using ll = long long;
int main()
{
	ll n;
	constexpr ll max = 1e5 * 2 + 1;
	ll a[max] = { 0 };

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

	ll sum = 0;
	for (int i = 0; i < n; i++)
		sum ^= a[i];

	for (int i = 0; i < n; i++)
		cout << static_cast<ll>(sum ^ a[i]) << " ";

	return 0;
}

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

int main(){
    
    int N;cin>>N;
    vector<int> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        int cnt=0;
        for(int j=i+1;j<N;j++){
            if(S[i]==S[j]) cnt++;
            else{
                i=j-1;
                break;
        }
            if(j==N-1) i=N;
    }
        ans+=(cnt+1)/2;
}
    cout<<ans<<endl;
}


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

#define int long long

const int INF = (1e9 * 300 * 3000);
int g[301][301], dp[301][301], ans, p[301][301];

main()
{
	int n;
	//scanf("%lld", &n);
	cin >> n;///////////////////////////////////////////////////////////
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			//scanf("%lld", &g[i][j]);
			cin >> g[i][j];///////////////////////////////////////////////////////////
			if(i < j)
				ans += g[i][j];
		}
	}
	
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			dp[i][j] = INF;
	
	for(int k = 1; k <= n; k++)
	{
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				if( g[i][k] + g[k][j] < dp[i][j] || ( dp[i][j] == g[i][k] + g[k][j] && (i != k && j != k && i != j) ) )
				{
					dp[i][j] = g[i][k] + g[k][j];
					p[i][j] = (i != k && j != k && i != j);
				}
			}
		}
	}
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = i + 1; j <= n; j++)
		{
			if(g[i][j] != dp[i][j])
				//return printf("%d", -1), 0;///////////////////////////////////////////////////////////
				return cout << -1, 0;
			
			if(p[i][j] == 1)
				ans -= g[i][j];
		}
	}
	
	//printf("%lld", ans);
	cout << ans;///////////////////////////////////////////////////////////
}


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

using namespace std;

int main(int qtd, char* nome[])
{
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    if (n % 2 == 0){
        cout << n;
    }else
    cout << n*2;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ss, ee) for (int i = (ss); i < (ee); ++i)

void solve() {
  int x, ans;
  rep(i, 0, 5) {
    cin >> x;
    if (x == 0) ans = i + 1;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3584
using System;

class Program
{
    public static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);

        if (a * b % 2 == 0)
            Console.WriteLine("Even");
        else
            Console.WriteLine("Odd");
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
double a;
int main(){
	cin >> a;
	int f=0;
	for(int i=1;i<=9;i++){
		int y=a/i;
		if((y<10)&&(y>0)&&(y*i==a)){
			f=1;
			break;
		}
	}
	if(f==1) cout << "Yes" <<endl;
	else cout << "No" <<endl;
	return 0;
}


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


int  main()
{


#ifndef ONLINE_JUDGE
freopen("i.txt", "r", stdin);
freopen("o.txt", "w", stdout);
#else
// online submission

#endif
  ll t;
  cin>>t;
cout<<!t<<endl;



    }








Measured memory_bytes: 3528
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(x: usize, y: usize)->usize{
    if y == 0{
        return x
    }
    gcd(y, x % y)
}

fn main() {
    input! {
        s: chars,
    }
    let mut c0 = 0;
    let mut c1 = 0;
    for i in s{
        if i == '0'{
            c0 += 1;
        }else{
            c1 += 1;
        }
    }
    let ans = 2 * min(c0, c1);
    println!("{}", ans);
}


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

#define ll long long

using namespace std;


int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    
    ll a, b, c;
    cin >> a >> b >> c;
    if (b > c) return 0 * printf("0");
    cout << max(0ll, ((a - 2) * (c - b) + 1));

    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int C=sc.nextInt();
		int s[] = new int[N];
		int t[] = new int[N];
		int c[] = new int[N];

		int maxt = 0;
		for(int i=0; i<N; i++) {
			s[i]=sc.nextInt();
			t[i]=sc.nextInt();
			maxt = Math.max(maxt, t[i]);
			c[i]=sc.nextInt();
		}

		int sumt[] = new int[2*maxt+1];
		for(int i=1; i<=C; i++) {
			int tt[] = new int[2*maxt+1];
			for(int j=0; j<N; j++) {
				if(c[j]==i) {
					tt[2*s[j]-1]++;
					tt[2*t[j]]--;
				}
			}
			for(int j=1; j<=2*maxt; j++) {
				tt[j] += tt[j-1];
			}

			for(int j=0; j<=2*maxt; j++) {
				if(tt[j]>0)	sumt[j]++;
			}
		}
		long ans = 0;
		for(int i=0; i<=2*maxt; i++) {
			ans = Math.max(ans, sumt[i]);
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 61896
#include<stdio.h>
#include<string.h>
int main(){
char a[110][40],d[40];
int b[110],i,c,count=0,j;
for(i=0;i<105;i++){
b[i]=0;
}
while(scanf("%s %d\n",d,&c)!=EOF){
strcpy(a[count],d);
b[count]=c;
count++;
}
for(i=0;i<count;i++){
for(j=i;j<count;j++){
if((strcmp(a[i],a[j])>0) ||(strcmp(a[i],a[j])==0 && b[i]>b[j])){
strcpy(d,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],d);
c=b[i];
b[i]=b[j];
b[j]=c;
}
else if(strcmp(a[i],a[j])==0 && a[i]<a[j]){
strcpy(d,a[i+1]);
strcpy(a[i+1],a[j]);
strcpy(a[j],d);
c=b[i+1];
b[i+1]=b[j];
b[j]=c;
}
}
}
printf("%s\n%d",a[0],b[0]);
for(i=1;i<count;i++){
if(strcmp(a[i-1],a[i])==0){
printf(" %d",b[i]);
}
else{
printf("\n%s\n%d",a[i],b[i]);
}
}
printf("\n");
return 0;
}


Measured memory_bytes: 2052
n = int(input())
dic = {}
push = [True] * n
for i in range(1, n+1):
  a = int(input())
  dic[i] = a
i = 1
cnt = 1
push[0] = False
while True:
  if dic[i] == 2:
    break
  else:
    k = dic[i]
    if push[k-1]:
      i = k
      cnt += 1
      push[k-1] = False
    else:
      cnt = -1
      break
print(cnt)
    

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

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

  for (int i = 0; i < n; i++)
  {
    cout << (al^a[i]) << " ";
  }
  cout << endl;  
}

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

vector<int> h;

int mizuyari(int be, int en){ //beからenまでの水やり回数
    if(be>en) return 0;
    int min = 1000, minidx;
    for(int i = be; i <= en; i++){
        if(!h[i]) return mizuyari(be, i-1) + mizuyari(i+1, en);
        if(h[i]<min){
            min = h[i]; minidx = i;
        }
    }
    for(int i = be; i <= en; i++) h[i] -= min;
    return min + mizuyari(be, en);
}

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int hi; cin >> hi;
        h.push_back(hi);
    }
    cout << mizuyari(0, n-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 1500001;

int a[N], b[N];

int main() {
    int n, m;
    while (cin >> n >> m && n){
        VI h(n), w(m);
        REP(i,n) scanf("%d", &h[i]);
        REP(i,m) scanf("%d", &w[i]);
        REP(i,N) a[i] = b[i] = 0;
        REP(i,n){
            int x = 0;
            FOR(j,i,n-1){
                x += h[j];
                a[x]++;
            }
        }
        REP(i,m){
            int x = 0;
            FOR(j,i,m-1){
                x += w[j];
                b[x]++;
            }
        }
        ll ans = 0;
        REP(i,N) ans += a[i]*b[i];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 14928
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    vector<ll> a(N);
    REP(i, 0, N)
    cin >> a[i];
    sort(a.rbegin(), a.rend());

    if (N == 2)
    {
        cout << a[0] << endl;
        return 0;
    }

    ll ans = a[0] + a[1];
    priority_queue<tuple<ll, ll, ll>> pq;
    pq.emplace(a[1], a[0], a[1]);
    pq.emplace(a[2], a[0], a[2]);
    pq.emplace(a[2], a[1], a[2]);

    REP(i, 3, N)
    {
        auto [v, l, r] = pq.top();
        pq.pop();
        ans += v;
        pq.emplace(a[i], l, a[i]);
        pq.emplace(a[i], r, a[i]);
    }

    cerr << pq.size() << endl;
    cout << ans << endl;
}


Measured memory_bytes: 11084
import scala.io.StdIn.{readLine, readInt}

object Main extends App {
  val n = readInt
  val A = readLine.split(" ").map(_.toInt)
  var ans = new Array[Int](n)

  for (i <- 0 until n) {
    ans(A(i) - 1) = i + 1
  }

  println(ans.mkString(" "))
}

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

using namespace std;

int main() {
	int ans = 0;
	int a, b, c;
	cin >> a >> b >> c;
	int x; cin >> x;
	for(int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if((i*500 + j*100 + k *50) == x) ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(ll i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
 
    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
 
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
 
    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
 
    ll size(ll x) {
        return -par[root(x)];
    }
};
 
template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<int, T> > > & G){
   const T INF = numeric_limits<T>::max();
   using P = pair<T, int>;
   int n=G.size();
   vector<T> d(n,INF);
   vector<int> b(n,-1);
   priority_queue<P,vector<P>,greater<P> > q;
   d[s]=0;
   q.emplace(d[s],s);
   while(!q.empty()){
     P p=q.top();q.pop();
     int v=p.second;
     if(d[v]<p.first) continue;
     for(auto& e:G[v]){
       int u=e.first;
       T c=e.second;
       if(d[u]>d[v]+c){
         d[u]=d[v]+c;
         b[u]=v;
         q.emplace(d[u],u);
       }
     }
   }
   return d;
}
 
int main(){
    ll a, b, c;
  	cin >> a >> b >> c;
    if(a == b && b == c) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define INF 1000000000

using P = pair<int, int>;
#define fi first
#define se second

int d[1010][1010] = {{0}};
bool visited[1010][1010] = {{0}};

bool in_range(P p, int h, int w) {
    return (0 <= p.fi && p.fi < h && 0 <= p.se && p.se < w);
}

int main() {
    int h, w;
    P start, goal;
    cin >> h >> w >> start.fi >> start.se >> goal.fi >> goal.se;
    start.fi--; start.se--;
    goal.fi--; goal.se--;
    for (int i=0; i<h; i++) {
        string s; cin >> s;
        for (int j=0; j<w; j++) {
            d[i][j] = INF;
            visited[i][j] = (s[j] == '#');
        }
    }
    deque<P> dq;
    dq.push_back(start);
    d[start.fi][start.se] = 0;
    while (!dq.empty()) {
        P f = dq.front(); dq.pop_front();
        if (visited[f.fi][f.se]) continue;
        visited[f.fi][f.se] = true;
        for (int i=f.fi-1; i<=f.fi+1; i++) {
            for (int j=f.se-1; j<=f.se+1; j++) {
                if (i != f.fi && j != f.se) continue;
                if (in_range(P{i, j}, h, w) && !visited[i][j] && d[i][j] > d[f.fi][f.se]) {
                    dq.push_front(P{i, j});
                    d[i][j] = d[f.fi][f.se];
                }
            }
        }
        for (int i=f.fi-2; i<=f.fi+2; i++) {
            for (int j=f.se-2; j<=f.se+2; j++) {
                if (in_range(P{i, j}, h, w) && !visited[i][j] && d[i][j] > d[f.fi][f.se] + 1) {
                    dq.push_back(P{i, j});
                    d[i][j] = d[f.fi][f.se] + 1;
                }
            }
        }
    }
    cout << (d[goal.fi][goal.se] < INF ? d[goal.fi][goal.se] : -1) << '\n';
    return 0;
}

Measured memory_bytes: 8596
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
inline int inc(int x, int y) {x += y; return x >= mod ? x - mod : x;}
inline int mul(int x, int y) {return (ll)x * y % mod;}
inline int qpow(int x, int y)
{
	int res = 1;
	for (; y; y >>= 1, x = (ll)x * x % mod)
		if (y & 1) res = (ll)res * x % mod;
	return res;
}
const int MAXN = 2e5 + 10;
int n, f[MAXN], a[MAXN], lst[MAXN];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
	f[1] = lst[a[1]] = 1;
	for (int i = 2; i <= n; i ++)
	{
		f[i] = f[i - 1];
		if (a[i] != a[i - 1])
			f[i] = inc(f[i], lst[a[i]]), lst[a[i]] = f[i];
	}
	printf("%d\n", f[n]);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  int M = N - K;
  int ans = 1 + (M+K-2)/(K-1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
n = int(input())
h_list = list(map(int, input().split()))

ans = 0
tmp_ans = 0
current = h_list[0]
for h in h_list[1:]:
    if h <= current:
        tmp_ans += 1
    else:
        ans = max(tmp_ans, ans)
        tmp_ans = 0
    current = h

ans = max(tmp_ans, ans)
print(ans)


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

int main(){
    int N;
    int H_list[100];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> H_list[i];   
    }
    long long cnt = 0;
    for(int i=0;i<N;i++){
        bool flg = true;
        for(int j=0;j<=i-1;j++){
            if(H_list[j] > H_list[i]){
                flg = false;
                break;
            }
        }
        if(flg){
            cnt++;
        }
    }
    cout << cnt;
    return EXIT_SUCCESS;
}

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

def divisor(n):
    cd = []
    i = 1
    while i*i <= n:
        if n%i==0:
            cd.append(i)
            if i != n//i:
                cd.append(n//i)
        i += 1
    return cd

def solve(X):
    fac = divisor(X)
    for f in fac:
        for i in range(1,10**4):
            A = i
            B = i-f
            p = i**5-B**5
            if p==X:
                break
        else:
            continue
        break
    ans = [A,B]
    return ans
print(*solve(X),sep=' ')

Measured memory_bytes: 9204