akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vvl A(2, vl(N));
  rep(i, 2){
    rep(j, N) cin >> A[i][j];
  }

  vl C(N, 0), D(N, 0);
  C[0] = A[0][0];
  D[N - 1] = A[1][N - 1];
  
  rep2(j, 1, N){
    C[j] += C[j - 1] + A[0][j];
  }
  rep_inv(j, N - 2, -1){
    D[j] += D[j + 1] + A[1][j];
  }
  rep(j, N) C[j] += D[j];

  stable_sort(C.begin(), C.end());

  cout << C[N - 1] << endl;
  
  return 0;
}


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

#define fastIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
#define asc(s) sort(s.begin(), s.end())
#define des(s) sort(s.rbegin(), s.rend())
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define rev(v) reverse(v.begin(), v.end())
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define precision(x, p) fixed << setprecision(p) << x
#define set_bits(n) __builtin_popcount(n);
#define mod 1000000007
#define PI 3.14159265358979
typedef long long ll;

#ifndef ONLINE_JUDGE
#define debug(x) cout << x << endl;
#else
#define debug(x)
#endif

template <class T>
T gcd(T a, T b)
{
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) { return a * b / gcd(a, b); };

vector<string> split(string s)
{
    istringstream buf(s);
    istream_iterator<string> beg(buf), end;
    vector<string> list(beg, end);
    return list;
}

bool isvowel(char c)
{
    string s = "aeiou";
    if (find(s.begin(), s.end(), c) != s.end())
        return true;
    return false;
}

bool cmp(pair<int, int> &a, pair<int, int> &b)
{
    return a.second > b.second || (a.second == b.second && a.first > b.first);
}

bool isprime(ll n)
{
    for (int i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;

    return true && (n != 1);
}

void solve()
{
    int n, m, a, b;
    cin >> n >> m;

    vector<vector<int>> v(1e5 + 1);

    for (int i = 0; i < n; i++)
    {
        cin >> a >> b;
        v[a].pb(b);
    }

    ll ans = 0;
    priority_queue<int> pq;

    for (int i = 1; i <= m; i++)
    {
        for (auto x : v[i])
            pq.push(x);

        if (!pq.empty())
        {
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans;
}

int main()
{
    fastIO

        int t = 1;
    // cin>>t;

    for (int test_case = 1; test_case <= t; test_case++)
    {
        solve();
    }
    return 0;
}

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	ll a,b;cin >> a >> b;
    ll s=0;
    ll fa = 0, fb = 0;
	//f(a-1)
	if(a%2==0){
		fa = (ll)(a/2)%2;
	}else{
		fa = (a-1) ^ (ll)((a-1)/2)%2;
	}
	if((b+1)%2==0){
		fb = (ll)((b+1)/2)%2;
	}else{
		fb = (b) ^ (ll)((b)/2)%2;
	}
	cout << (fa ^ fb) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back             
#define se second                
#define fi first  
#define be begin()
#define en end()
#define all(v) v.be, v.en
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
template<typename... T> void po(T... args) { ((cout << args << " "), ...); cout<<""; }

 vector<int> pr;
 bool isPrimeNumber(int n){
   if (n <= 1)
      return false;
   if (n <= 3)
      return true;
   if (n % 2 == 0 || n % 3 == 0)
      return false;
   for (int i = 5; i * i <= n; i = i + 6)
      if (n % i == 0 || n % (i + 2) == 0)
         return false;
   return true;
}
void printPrime(int n){
   for (int i = 2; i <= n; i++) {
      if (isPrimeNumber(i))
        //  cout<<i<<" ";
        pr.pb(i);
      }
   }



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
     int test=1;
     //cin>>test;
     for(int tt=1; tt<=test; tt++){
       ll n;
       cin>>n;
       ll a[n];
       map<ll,ll>mp;
       printPrime(1005);
       ll prs = pr.size();
    //    pp(prs);
       ll prc[prs]={0};
       map<ll,ll> mpp;
       for(ll i=0; i<n; i++){
           cin>>a[i];
           mp[a[i]]++;
       }
       ll gcd = a[0];
       ll ma = a[0];
       for(ll i=1; i<n; i++){
           gcd = __gcd(a[i],gcd);
           ma = max(ma,a[i]);
       }
       if(gcd!=1){
           pp("not coprime");
           return 0;
       }
       ll ans=0;
       
           for(ll j=0; j<n; j++){
               ll k = a[j],ch=0;
               while (k % 2 == 0)  
                {  
                    // cout << 2 << " ";  
                    ch = 1;
                    k = k/2;  
                }  
                if(ch)mpp[2]++;
                if(mpp[2]>1){
                    pp("setwise coprime");
                    return 0;
                }
                // k must be odd at this point. So we can skip  
                // one element (Note i = i +2)  
                for (int i = 3; i <= sqrt(k); i = i + 2)  
                {  
                    // While i divides k, print i and divide k  
                    ch = 0;
                    while (k % i == 0)  
                    {  
                        // cout << i << " ";  
                       ch = 1;
                        k = k/i;  
                    }  
                    if(ch)mpp[i]++;
                    if(mpp[i]>1){
                        pp("setwise coprime");
                        return 0;
                    }
                }  
            
                // This condition is to handle the case when k  
                // is a prime number greater than 2  
                if (k > 2)mpp[k]++;
                if(mpp[k]>1){
                        pp("setwise coprime");
                        return 0;
                    }
                    // cout << n << " "; 

           }
       
       
         pp("pairwise coprime");
       
       
     //cout<<"Case #"<<tt<<": ";  
     }
 
    return 0;
}

Measured memory_bytes: 73932
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, A, B, C, D;
  string S;
  cin >> N >> A >> B >> C >> D >> S;

  S = "#" + S + "#";

  auto can_reach = [&](int s, int e) {
                     for (int i = s; i+1 <= e; ++i) {
                       if (S[i] == '#' && S[i+1] == '#') {
                         return false;
                       }
                     }
                     return true;
                   };

  if (!can_reach(A, C) || !can_reach(B, D)) {
    cout << "No" << endl;
    return 0;
  }

  if (C > D) {
    bool snuke_can_over = false;
    for (int i = B; i <= D; ++i) {
      if (S[i-1] == '.' && S[i] == '.' && S[i+1] == '.') snuke_can_over = true;
    }

    if (!snuke_can_over) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 772
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

s=0
ac=0
bc=0
max=0

for i in range(n):
  s=s+a[i]
  ac=ac+1
  if s > k:
    s=s-a[i]
    ac=ac-1
    break
for i in range(m):
  s=s+b[i]
  bc=bc+1
  if s > k:
    s=s-b[i]
    bc=bc-1
    break

max=ac+bc

flag=0
while flag==0 and ac!=0:
  ac=ac-1
  s=s-a[ac]
  while s <= k:
    bc=bc+1
    if bc > m:
      flag=1
      break
    s=s+b[bc-1]
  bc=bc-1
  if flag==0:
    s=s-b[bc]
  
  if max < ac+bc:
    max=ac+bc
    
print(max)


Measured memory_bytes: 42216
#include<bits/stdc++.h>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=2e6+7;
const int INF=1e9;
int a,b;

int main()
{ 
   cin>>a>>b;
   int u=a+b;
   int v=a-b;
   int w=a*b;
   cout<<max(max(a+b,a-b),a*b);
    return 0;
}

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

typedef long long ll;
int N,K;
ll A[100010] = {0},S[100010] = {0},T[100010] = {0};

int main(){
	cin >> N >> K;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		S[i] = S[i-1] + A[i];
		T[i] = T[i-1] + max(A[i]-A[i],A[i]);
	}
	ll ans = 0;
	for(int i=1;i<=N-K+1;i++){
		ans = max(ans,max(T[i-1] + S[i+K-1]-S[i-1] + T[N]-T[i+K-1],
			T[i-1] + T[N]-T[i+K-1]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, K, D;
    cin >> X >> K >> D;
    {
        ll cnt = min(abs(X) / D, K);
        if (X < 0) {
            X += D * cnt;
        } else {
            X -= D * cnt;
        }
        K -= cnt;
    }
    if (K % 2) {
        if (X < 0) {
            X += D;
        } else {
            X -= D;
        }
    }
    cout << abs(X) << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    double x=0;
    REP(i,n){
        double a;
        cin>>a;
        x+=1.0/a;
    }
    printf("%.10f\n",1.0/x);
    return 0;
}


Measured memory_bytes: 384
s=input()
t=input()
a=-1
n=len(s)
k=len(t)
if k>n:
  print('UNRESTORABLE')
else:
  ans=str()
  for i in range(n):
    ok=True
    if n-i>=k:
      for j in range(k):
        if t[j]!=s[i+j] and s[i+j]!='?':
          ok=False
      if ok:
        a=i
  if a==-1:
    print('UNRESTORABLE')
  else:
    for i in range(n):
      if a<=i<=a+k-1:
        ans+=t[i-a]
      else:
        if s[i]=='?':
          ans+='a'
        else:
          ans+=s[i]
    print(ans)

Measured memory_bytes: 3064
s = gets.chomp.split("")
A = 'dream'.split("")
B = 'dreamer'.split("")
C = 'erase'.split("")
D = 'eraser'.split("")
answer = 'YES'
counter = 0
#main
(0 .. s.length - 1).each do |i|
    if i != 0 && i <= counter then
        next
    else
        if s[(s.length - 1) - i] == 'r' then
            if s[(s.length - 1) - i - 2] == 'm' then
                (0 .. 6).each do |j|
                    if B[6 - j] != s[(s.length - 1) - i - j] then
                        answer ='NO'
                        print ("#{answer}\n")
                        exit
                    end
                    # counter += 1
                end
                counter = i + 6
            else
                (0 .. 5).each do |j|
                    if D[5 - j] != s[(s.length - 1) - i - j] then
                        answer ='NO'
                        print ("#{answer}\n")
                        exit
                    end
                    # counter += 1
                end
                counter = i + 5
            end
        else
            if s[(s.length - 1) - i] == 'm' then
                (0 .. 4).each do |j|
                    if A[4 - j] != s[(s.length - 1) - i - j] then
                        answer ='NO'
                        print ("#{answer}\n")
                        exit
                    end
                    # counter += 1
                end
                counter = i + 4
            else
                (0 .. 4).each do |j|
                    if C[4 - j] != s[(s.length - 1) - (i + j)] then
                        answer ='NO'
                        print ("#{answer}\n")
                        exit
                    end
                    # counter += 1
                end
                counter = i + 4
            end
        end
    end
end
print ("#{answer}\n")

Measured memory_bytes: 8316
N, M, K = map(int,input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

cumA = [0] * (N+1)
cumB = [0] * (M+1)

for i in range(N):
    cumA[i+1] = cumA[i] + A[i]
for i in range(M):
    cumB[i+1] = cumB[i] + B[i]

def check(X):
    res = 1e9+1
    for i in range(N+1):
        j = X - i
        if j < 0 or M < j: continue
        if(cumA[i] + cumB[j] < res):
            res = cumA[i] + cumB[j]
    return res <= K

ok = 0
ng = N + M + 1

while ng - ok > 1:
    mid = (ok + ng) // 2
    if(check(mid)): ok = mid
    else: ng = mid

print(ok)

Measured memory_bytes: 47376
n, k, *a = map(int, open(0).read().split())

for _ in range(k):
    b = [0] * -~n
    for i in range(len(a)):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    for i in range(n):
        b[i + 1] += b[i]

    if all(x == n for x in b[:n]):
        print(' '.join(map(str, b[:n])))
        exit()
    a = b
print(' '.join(map(str, a[:n])))


Measured memory_bytes: 226552
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;



int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;

    ll ans = 0;
    
    auto f = [&](ll a) {
        if (a == 1) {
            return 300000;
        };
        if (a == 2) {
            return 200000;
        }
        if(a == 3) {
            return 100000;
        }
        return 0;
    };

    ans += f(x);
    ans += f(y);
    if (x == 1 && y == 1) {
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(LL i = (a); i < (LL)(n); ++i)
#define REM(i,a,n) for(LL i = ((n) - 1); i >= (a); --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const string INFSTR = "\x7f";
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template<class T>
T Compare(T left, T right) { return left > right ? 1 : (left < right ? -1 : 0); }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }
// all_of
// partial_sum, adjacent_difference

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#include "Geometry.h"
#include "Matrix.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

#if 1234567891
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N;
int A[100000];
int main() {
	cin >> N;
	REP(i, 0, N) {
		cin >> A[i];
	}
	YESNO(accumulate(A, A + N, 0LL) % 2 == 0);
	return 0;
}

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

int n;
int a[2010];
vector<int> e[2010],next[2010];
bool vis[2010];
priority_queue<int> f;

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}

void ins(int x,int y){
	e[x].push_back(y);e[y].push_back(x);
}

void dfs(int x){
	vis[x]=true;
	for(int i=0;i<e[x].size();i++)
		if(!vis[e[x][i]]) next[x].push_back(e[x][i]),dfs(e[x][i]);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++) if(gcd(a[i],a[j])!=1) ins(i,j);
	for(int i=1;i<=n;i++) if(!vis[i]) dfs(i),f.push(i);
	while(!f.empty()){
		int x=f.top();f.pop();
		printf("%d ",a[x]);
		for(int i=0;i<next[x].size();i++) f.push(next[x][i]);
	}
}

Measured memory_bytes: 17792
#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;}

ll h[100000];

int main() {
  int n, A, B;
  while (input(n, A, B)) {
    inputs(h, n);
    ll low = 0, high = 1LL<<31;
    ll alpha = A - B;
    while (low + 1 < high) {
      ll mid = (low + high) >> 1;
      ll base = mid * B;
      ll cnt = 0;
      REP(i, n) {
        cnt += (max(0LL, h[i] - base) + alpha - 1) / alpha;
      }
      if (cnt > mid) {
        low = mid;
      } else {
        high = mid;
      }
    }
    cout << high << endl;
  }
}


Measured memory_bytes: 1024
int main(){
	int x;
	scanf("%d",&x);
	for(long long a=0;a<200;a++)for(long long b=-200;b<a;b++){
		if(a*a*a*a*a-b*b*b*b*b==x){
			printf("%lld %lld",a,b);
			return 0;
		}
	}
}

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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0) return cout << "Zero" << endl, 0;
	if (b < 0 && (b - a + 1) % 2) return cout << "Negative" << endl, 0;
	cout << "Positive" << endl;
	return 0;
}

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

template <typename T>
struct node {
	T val, add;
	node *l, *r;
	void init(T v, T a, node *left, node *right) {
		val = v;
		add = a;
		l = left;
		r = right;
	}
};

node<ll> pool[PMAX];

template <typename T>
class SaikyoSegmentTree {
	const ll n;
	const T id;
	int it;
	vector<node<T>*> root;
	T getval(node<T> *x) {
		return x == nullptr ? id : x->val;
	}
	T getadd(node<T> *x) {
		return x == nullptr ? id : x->add;
	}
	node<T>* getl(node<T> *x) {
		return x == nullptr ? nullptr : x->l;
	}
	node<T>* getr(node<T> *x) {
		return x == nullptr ? nullptr : x->r;
	}
	ll size(ll n) {
		assert(n < (1ll << 62ll));
		ll res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	node<T> *new_node(T val, T add, node<T> *l = nullptr, node<T> *r = nullptr) {
		pool[it].init(val, add, l, r);
		return &pool[it++];
	}
	node<T> *fix(node<T> *x, ll l, ll r, T val, ll lb, ll ub) {
		if (r <= lb || ub <= l) return x;
		if (l <= lb && ub <= r) return new_node(getval(x), getadd(x) + val, getl(x), getr(x));
		ll c = (lb + ub) / 2;
		auto nl = fix(getl(x), l, r, val, lb, c);
		auto nr = fix(getr(x), l, r, val, c, ub);
		return new_node(getval(x) + val * (min(r, ub) - max(l, lb)), getadd(x), nl, nr);
	}
	T sub(node<T> *x, ll l, ll r, ll lb, ll ub) {
		if (x == nullptr) return id;
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return x->val + x->add * (ub - lb);
		ll c = (lb + ub) / 2;
		return sub(getl(x), l, r, lb, c) + sub(getr(x), l, r, c, ub) + x->add * (min(r, ub) - max(l, lb));
	}
public:
	SaikyoSegmentTree(ll n_, T id_) : n(size(n_)), id(id_), it(0) {
		root.push_back(nullptr);
	}
	void add(ll l, ll r, T val, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		root.push_back(fix(root[rt], l, r + 1, val, 0, n));
	}
	T find(ll l, ll r, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		return sub(root[rt], l, r + 1, 0, n);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll N, M, Q;
	cin >> N >> M >> Q;
	vector<tuple<int, int, int>> vab(M);
	for (int i = 0; i < M; i++) {
		cin >> get<1>(vab[i]) >> get<2>(vab[i]) >> get<0>(vab[i]); get<1>(vab[i])--; get<2>(vab[i])--;
	}
	sort(vab.begin(), vab.end());
	SaikyoSegmentTree<ll> sst(N, 0);
	for (int i = 0; i < M; i++) {
		sst.add(get<1>(vab[i]), get<2>(vab[i]), 1);
	}
	ll x, y, j;
	while (Q--) {
		cin >> x >> y >> j; x--; y--;
		ll l = 0, r = M;
		while(l + 1 < r) {
			ll c = (l + r) / 2;
			if (sst.find(x, y, c) >= j) {
				r = c;
			}
			else {
				l = c;
			}
		}
		printf("%d\n", get<0>(vab[r - 1]));
	}
	return 0;
}

Measured memory_bytes: 266636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(std::vector<T>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

bool check (string S, string T, int k)
{
   corner(T.size() + k > S.size(),"Out of Size");
   bool check = 1;
   for (int i = 0; i < T.size(); i++)
   {
    if((S[k+i] == T[i] || S[k+i] == '?')^(true)) check = 0;
   }

   return check;
}

string fill(string S,string T,int k)
{
  string filled = S;
  for (int i = 0; i < T.size(); i++)
  {
    filled[k+i] = T[i];
  }
  for (int i = 0; i < S.size(); i++)
  {
    if(filled[i] == '?')filled[i] = 'a';
  }
  
  return filled;
}
void solve(void)
{   
  char A,B;
  cin>>A>>B;
  if(A>B)
  {
    cout<<">"<<endl;
  }
  else if(A < B)
  {
    cout<<"<"<<endl;
  }
  else
  {
    cout<<"="<<endl;
  }
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
//  problem
//  Created by 聂小楠 on 2017/8/12.
//  All rights reserved.

#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define MAX_N 1000
#define Mem(a,b) memset(a,b,sizeof(a))
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
#define INF  2147483647
using namespace std;
const ll mod =1e9+7;
int a[105];
int ans[105][105];
int main()
{
    std::ios::sync_with_stdio(false);
    char str[100];
    cin>>str;
    int len=strlen(str);
    int flag=1;
    for(int i=0;i<len/2;i++)
    {
        if(str[i]!=str[len-1-i])
            flag=0;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;
const ll maxn=1e6+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
void io(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int main()
{
	io();
	ll n;
	cin>>n;
	double m;
	m=(double)n/3;
	printf("%.12lf\n",m*m*m); 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	string s;
	cin>>s;
	bool c=true;
	if(a%2==1)
	cout<<"No";
	else
	{
		for(int i=0;i<a/2;i++)
		{
			if(s[i]!=s[a/2+i])
			{
				c=false;
			}
		}
		if(c)
		cout<<"Yes";
		else
		cout<<"No";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
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);

int main() {
    int r, c;
    cin >> r >> c;
    string s(c+2, '#');
    cout << s << endl;
    for(int i = 0; i < r; i++) {
        string s2 = s;
        string s3;
        cin >> s3;
        for(int i = 0; i < c; i++)
            s2[i+1] = s3[i];
        cout << s2 << endl;
    }
    cout << s << endl;
    return 0;
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    int n,m; cin >> n >> m;
    int h[n], f[n] = {};
    rep(i,0,n) cin >> h[i];
    ll ans = 0;
    rep(i,0,m){
        int ai,bi; cin >> ai >> bi;
        f[ai-1] = max(f[ai-1], h[bi-1]);
        f[bi-1] = max(f[bi-1], h[ai-1]);
    }
    rep(i,0,n){
        if(h[i] >f[i]) ans++;
    }
    cout << ans << "\n";
} 

Measured memory_bytes: 4416
#include<stdio.h>

static int N=100;

int main(){
  int M[N][N];
  int n,u,k,v,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j>0) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2100
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int count = 1;
		int sum = 1;
		while(X > sum) {
			count++;
			sum += count;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23380
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cassert>
#include <numeric>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef long long ll;
typedef double lf;
typedef long double llf;
typedef pair<int,int> pii;
typedef vector<int> vec;
#define fi first
#define se second
/* */
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define forEach(i, s) for(auto i=begin(s);i!=end(s);i++)
#define for_each_n(i, s, n) for(auto i=begin(s),_5=next(i,n);i!=_5;i++)
#define pb push_back
#define mp make_pair

/* special */
#define Mem(x) memset(x,0,sizeof(x))
#define GET_MACRO(_0,_1,_2,_3,_NAME,...) _NAME
/* */
#define rep(...)  GET_MACRO(_0,##__VA_ARGS__,rep3,rep2,rep1,rep0)(__VA_ARGS__)
	#define rep3(i,a,b) for(int i=(a);i<(b);++i)
	#define rep2(i,a) for(int i=0;i<(a);++i)
	#define rep1(a) rep2(_,a)
	#define rep0()	while(1)
#define callOnce if([]{static int i=-1;i++;return !i;}())


/* input */
namespace my{
	#define out(x) cout<<(x)<<endl
	inline int in(int &x) {return scanf("%d",&x);}
	inline int in(double &x) {return scanf("%lf",&x);}
	inline int in(ll &x) {return scanf("%lld",&x);}
	inline int in(int &x,int &y) {return scanf("%d %d",&x,&y);}
	inline int in(int &x,int &y,int &z) {return scanf("%d %d %d",&x,&y,&z);}
	inline int in(char s[]) {return scanf("%s",s);}
	inline int in(char &c) {return scanf("%c",&c);}
}

using namespace my;

/* debug */
#ifndef ONLINE_JUDGE
	#define D0()
	#define D1(x) {cout<<" ";cout.width(5);cout<<(x);}
	#define D2(x,y) {D1(x)D1(y)}
	#define D3(x,y,z) {D2(x,y)D1(z)}
	#define Dset(...) for(auto i : __VA_ARGS__ ) D1(i) //std::size()
	#define Darr1(x,fir) for(auto _7 = begin(x),_6=next(begin(x),fir);_7!=_6;++_7) D1(*_7)
	#define Darr2(x,fir,sec) for(auto _8=begin(x),_9=next(begin(x),fir);_8!=_9;++_8){ Darr1((*_8),sec)D()}
	#define D(...) {cout<<#__VA_ARGS__<<" ";GET_MACRO(_0,##__VA_ARGS__,D3,D2,D1,D0)(__VA_ARGS__);cout<<endl;}
	#define Da(...)  {cout<<#__VA_ARGS__;D()GET_MACRO(""##__VA_ARGS__,UNUSED,Darr2,Darr1,Dset)(__VA_ARGS__)D()}
#endif // ONLINE_JUDGE

// template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
#define pow2(X) (1<<(X))
#define gcd __gcd
#define lcm(a,b) ((a)/gcd(a,b)*(b))
ll mod=1e9+7;
inline ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x3f3f3f3f;//0x3f
const int NINF=0xcfcfcfcf;//0xcf
const int maxn=1e9+10;
int n,t,T,x,i,p,y,v;

int main(){

	in(n,i);
	out(n-i+1);

}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N)]
def C(x):
    count = [0]*M
    index = [0]*N
    flag = [False]*M
    for i in range(N):
        count[A[i][0]]+=1
    m = max(count)
    while m>x:
        tmp = [0]*M
        for i in range(N):
            j = index[i]
            if count[A[i][j]]>x:
                flag[A[i][j]] = True
        for i in range(N):
            j = index[i]
            while flag[A[i][j]]:
                index[i]+=1
                j+=1
                if j == M:
                    return False
            tmp[A[i][j]]+=1
        count = [t for t in tmp]
        m = max(count)
    return True

ng = 0
ok = N
while ok-ng>1:
    mid = (ok+ng)//2
    if C(mid):ok = mid
    else:ng = mid
print(ok)


Measured memory_bytes: 47708
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 1000005
using namespace std;
typedef long long ll;

template <typename T> void read(T &t)
{
	t=0;int f=0;char c=getchar();
	while(!isdigit(c)){f|=c=='-';c=getchar();}
	while(isdigit(c)){t=t*10+c-'0';c=getchar();}
	if(f)t=-t;
}

ll n,m;
ll ans;

struct stos
{
	ll a,b;
}s[maxn];

bool cmp(const stos &x,const stos &y)
{
	return x.a<y.a;
}

int main()
{
	read(n),read(m);
	for(register ll i=1;i<=n;++i)
		scanf("%lld%lld",&s[i].a,&s[i].b);
	sort(s+1,s+n+1,cmp);
	for(register ll i=1;i<=n;++i)
	{
		if(m==0)break;
		ll x=min(s[i].b,m);
		ans+=x*s[i].a;
		m-=x;
	}
	printf("%lld",ans);
	return 0;
}


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

signed main()
{
  int n;
  int max_ = -2000000000;
  static int a[200010];

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

  int min_ = a[0];
  for (int i = 1; i < n; i++) {
    max_ = max(max_, a[i] - min_);
    min_ = min(min_, a[i]);
  }

  cout << max_ << endl;

  return (0);
}

Measured memory_bytes: 3880
while True:
  card = str(input())
  if card == "-":
    break;
  else:
    num = int(input())
    for i in range(num):
      kazu = int(input())
      nextcard = ""
      nextcard += card[kazu:]
      nextcard += card[:kazu]
      card = nextcard
    print(card)
    


Measured memory_bytes: 5596
#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main(int argc, char **argv) {
    int R, G, B, N;
    scanf("%d%d%d%d", &R, &G, &B, &N);
    int triples = 0;
    for (int r = 0; r * R <= N; ++r)
        for (int g = 0; g * G <= N; ++g) {
            int b = N - (r * R + g * G);
            if (b >= 0 && b % B == 0)
                ++triples;
        }
    printf("%d\n", triples);
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;


int main(void) {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	


	int n;
	vector<int> v;
	set<int> s;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		v.push_back(x);
		s.insert(x);

	}
	if (s.size() == v.size()) {
		cout << "YES";
	}
	else {
		cout << "NO" << endl;
	}



	return 0;
}



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


int main(){
	string s;
	cin >> s;
	int g = 0;
	int ans = 0;
	for(auto c : s ){
		if( c == 'p' ){
			if(g)g--;
			else g++, ans--;
		}else{
			if(g)g--, ans++;
			else g++;
		}
	}
	cout << ans << endl;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;

    bool ans = false;
    for (int i = 0; i <= N/4; i++) {
        for (int j = 0; j <= N/7; j++) {
            int value = 4*i + 7*j;
            if (value == N) {
                ans = true;
            }
        }
    }
    if (ans) {
        print("Yes");
    } else {
        print("No");
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}



const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
	int sum = -1, sugar = 0;
	for (int i = 0; 100 * i <= f; i += a) {
		for (int j = 0; 100 * (i + j) <= f; j += b) {
			for (int k = 0; 100 * (i + j) + k <= f; k += c) {
				for (int l = 0; 100 * (i + j) + k + l <= f; l += d) {
					int tmp = k + l;
					int t = 100 * (i + j) + tmp;
					if (tmp <= (i + j)*e&&t > 0 && (sum < 0 || sugar * t < tmp*sum)) {
						sum = t; sugar = tmp;
					}
				}
			}
		}
	}
	cout << sum << " " << sugar << endl;
	return 0;
}

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

using namespace std;

int main() {
  int N; cin>>N;
  vector<int> A(N+1);
  vector<int> B(N);
  for (int i = 0; i < N+1; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];


  long count = 0;
  for (int i = N-1; i >= 0; i--) {
    if (A[i+1] >= B[i]) {
      count += B[i];
      A[i+1] -= B[i];
      B[i] = 0;
    } else {
      count += A[i+1];
      B[i] -= A[i+1];
      A[i+1] = 0;
    }

    if (A[i] >= B[i]) {
      count += B[i];
      A[i] -= B[i];
      B[i] = 0;
    } else {
      count += A[i];
      B[i] -= A[i];
      A[i] = 0;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1024
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::iter::once;
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

////////////////////////////////////////////////////////////////////////////////

fn main() {
    let n = read!(usize);
    let p = read!([i64]);

    let ans = p
        .windows(3)
        .filter(|&a| {
            debug!(a);
            a[0] < a[1] && a[1] < a[2] && a[0] < a[2] || a[0] > a[1] && a[1] > a[2] && a[0] > a[2]
        })
        .count();

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[][] a = new int[2][m];
		for(int j = 0 ; j < m ; j++){
			for(int i = 0 ; i < 2 ; i++) a[i][j] = Integer.parseInt(sc.next()) - 1;
		}
		sc.close();
		boolean[] q = new boolean[n];
		boolean[] p = new boolean[n];
		Arrays.fill(q , false);
		Arrays.fill(p , false);
		for(int i = 0 ; i < m ; i++){
			if(a[0][i] == 0) q[a[1][i]] = true;
			if(a[1][i] == 0) q[a[0][i]] = true;
			if(a[0][i] == n - 1) p[a[1][i]] = true;
			if(a[1][i] == n - 1) p[a[0][i]] = true;
		}
		boolean che = false;
		for(int i = 0 ; !che && i < n ; i++) if(p[i] && q[i]) che = true;
		if(che) ou.println("POSSIBLE");
		else ou.println("IMPOSSIBLE");
		ou.flush();
	}
}

Measured memory_bytes: 61140
#include <stdio.h>

int main(void){
	int x, n;	

	for(n = 1; ; n++){
		scanf("%d", &x);
		if(x != 0){
			printf("Case %d: %d\n", n, x);
		} else{
			break;
		}
	}
	
	return 0;
}

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

int main() {
    int n, k;
	cin >> n >> k;
    
	vector<long long> num(k, 0);
	
    for (int i = 1; i <= n; ++i){
		num[i%k]++;
	}
	
    long long res = 0;
    for (int a = 0; a < k; a++) {
        int b = (k-a) % k;
        int c = (k-a) % k;
        if ((b+c) % k != 0){
			continue;
		}
        res += num[a] * num[b] * num[c];
    }
    cout << res << endl;
}

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

using namespace std;

const int maxn = 1e5 + 5;
const long long MOD = 1e9 + 7;

struct mi {
      long long v;
      explicit operator long long() const { return v; }
      mi() { v = 0; }
      mi(long long _v) { v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; if (v < 0) { v += MOD; } }

      friend bool operator == (const mi& a, const mi& b) { return a.v == b.v; }
      friend bool operator != (const mi& a, const mi& b) { return !(a == b); }
      friend bool operator < (const mi& a, const mi& b) { return a.v < b.v; }

      mi& operator += (const mi& m) { if ((v += m.v) >= MOD) { v -= MOD; } return *this; }
      mi& operator -= (const mi& m) { if ((v -= m.v) < 0) { v += MOD; } return *this; }
      mi& operator *= (const mi& m) { v = v * m.v % MOD; return *this; }
      mi& operator /= (const mi& m) { return (*this) *= inv(m); }

      friend mi pow(mi a, long long p) { mi ans = 1; assert(p >= 0); for (; p; p /= 2, a *= a) { if (p & 1) { ans *= a; } } return ans; }
      friend mi inv(const mi& a)       { assert(a.v != 0); return pow(a, MOD - 2); }

      mi operator - () const { return mi(-v); }
      mi& operator ++ () { return *this += 1; }
      mi& operator -- () { return *this -= 1; }
      mi operator ++ (int) { mi temp; temp.v = v++; return temp; }
      mi operator -- (int) { mi temp; temp.v = v--; return temp; }

      friend mi operator + (mi a, const mi& b) { return a += b; }
      friend mi operator - (mi a, const mi& b) { return a -= b; }
      friend mi operator * (mi a, const mi& b) { return a *= b; }
      friend mi operator / (mi a, const mi& b) { return a /= b; }

      friend ostream& operator << (ostream& os, const mi& m) { os << m.v; return os; }
      friend istream& operator >> (istream& is, mi& m) { long long x; is >> x; m.v = x; return is; }
};

mi fact[maxn];
mi ifact[maxn];

void calc() {
      fact[0] = ifact[0] = 1;
      for (int i = 1; i < maxn; i++) {
            fact[i] = i * fact[i - 1];
            ifact[i] = inv(fact[i]);
      }
}

mi nCr(int n, int r) {
      if (n < r or n < 0 or r < 0) {
            return 0;
      }
      return fact[n] * ifact[r] * ifact[n - r];
}

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

      bool FILEIO = 0;
      if (FILEIO and fopen("in.txt", "r")) {
            freopen("in.txt", "r", stdin);
      }

      calc();

      int n, k;
      cin >> n >> k;
      vector <int> vec(n);
      for (int &x : vec) {
            cin >> x;
      }
      sort(vec.begin(), vec.end());
      mi maxsum = 0;
      mi minsum = 0;
      for (int i = k - 1; i < n; i++) {
            mi choose = nCr(i, k - 1);
            maxsum += choose * vec[i];
      }
      reverse(vec.begin(), vec.end());
      for (int i = k - 1; i < n; i++) {
            mi choose = nCr(i, k - 1);
            minsum += choose * vec[i];
      }
      mi ans = maxsum - minsum;
      cout << ans << endl;
}


Measured memory_bytes: 5240
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int i, N, M, a, b, ans=0; cin >> N >> M; vector<int> ar(N-1);
map<pair<int, int>, bool> C;
REP(i, M){ cin >> a >> b; a--; b--; C[make_pair(a, b)]=true; C[make_pair(b, a)]=true; }
REP(i, N-1){ ar[i]=i; }
do {
  bool f=true;
  REP(i, N-1){ 
    if(i==0){ if(C[make_pair(0, ar[i]+1)]==false){ f=false; break; } }
    else{ if(C[make_pair(ar[i-1]+1, ar[i]+1)]==false){ f=false; break; } }
  }
  if(f){ ans++; }
} while(next_permutation(ar.begin(), ar.end()));
cout << ans << "\n";
}

Measured memory_bytes: 3604