akhauriyash/Code-Regression huggingface dataset:
//2019.2.19 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline int _abs(const res &x){
    return x>0?x:-x;
}
inline int _max(const res &x,const res &y){
    return x>y?x:y;
}
inline int _min(const res &x,const res &y){
    return x<y?x:y;
}
const int N=3e3+10;
namespace MAIN{
    int n;
    int va[N];
    struct E{
        int next,to;
        E() {}
        E(res next,res to):next(next),to(to) {}
    }edge[N<<1];
    int head[N],cnt;
    inline void addedge(const res &u,const res &v){
        edge[++cnt]=E(head[u],v),head[u]=cnt;
        edge[++cnt]=E(head[v],u),head[v]=cnt;
    }
    bool vis[N];
    void dfs(const res &x,const res &fax){
        vis[x]=0;
        for(res i=head[x];~i;i=edge[i].next){
            res tox=edge[i].to;
            if(tox==fax||va[tox]>=va[x])continue;
            dfs(tox,x);
            if(!vis[tox])vis[x]=1;
        }
    }
    inline void MAIN(){
        memset(head,-1,sizeof(head));
        n=read();
        for(res i=1;i<=n;i++)va[i]=read();
        for(res i=1;i<n;i++){
            res u=read(),v=read();
            addedge(v,u);
        }
        for(res i=1;i<=n;i++){
            dfs(i,0);
            if(vis[i])printf("%d ",i);
        }
    }
}
int main(){
//    freopen("secret.in","r",stdin);
//    freopen("secret.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

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

typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for(size_t i = 0; i < s.size(); ++i)
	{
		if (s[i] != t[i]) ++cnt;
	}	
	cout << cnt;
	return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)

#define BEGIN(n) n / (int)pow(10, floor(log10(n)))
#define END(n) n % 10

int main()
{
    int N, A, B, C = 0;
    cin >> N;

    int M[9][9] = {};
    REP(i, 9)
    {
        REP(j, 9)
        {
            int _i = i + 1;
            int _j = j + 1;
            int l, b, e, count = 0;
            l = (int)floor(log10(N));
            b = BEGIN(N);
            e = END(N);
            REP(k, l + 1)
            {
                if (k == 0)
                {
                    if (_i == _j && _i <= N)
                    {
                        count++;
                    }
                }
                else
                {
                    int diff = N - (_i * (int)pow(10, k) + _j);
                    if (diff >= (int)pow(10, k) - 10)
                    {
                        count += pow(10, k - 1);
                    }
                    else if (diff >= 0)
                    {
                        count += (int)(diff / 10) + 1;
                    }
                }
            }

            M[i][j] = count;
        }
    }

    REP(i, 9)
    {
        REP(j, 9)
        {
            C += M[i][j] * M[j][i];
            // cout << M[i][j] << " ";
        }
        // cout << endl;
    }

    cout << C << endl;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string A;
    cin >> A;
    int N = A.size();

    ll ans = (ll)N * (N + 1) / 2 - N + 1;
    vector<int> cnt(26);
    rep(i, N) {
        if (cnt[A[i] - 'a'] > 0) {
            ans -= cnt[A[i] - 'a'];
        }

        cnt[A[i] - 'a']++;
    }

    write(ans);
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>a(n),b;
  rep(i,n)cin>>a[i];
  map<int,int>ma;
  rep(i,n)ma[a[i]]++;

  for(auto tp:ma)
  {
    b.push_back(tp.second);
  }
  sort(all(b),greater<int>());
  vector<int>res(n+1);
  int s=n;
  int id=1;
  int wei=0;
  rep(i,b.size())
  {
    int nid=s/b[i]+1+wei;
    repi(j,id,nid)
    {
      res[j]=s/(j-wei);
    }
    id=nid;
    s-=b[i];
    wei++;
  }
rep(i,n)  printf("%d\n", res[i+1]);


  return 0;

}


Measured memory_bytes: 17904
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll INF = 1000000009;
ll MOD = 1000000007;


void solve(){

    ll a,b,n;
    cin >>a >> b >> n;

    if(b-1<=n){
        cout << (a*(b-1))/b - a*((b-1)/b) << endl;
    }
    else{
        cout << (a*(n))/b - a*((n)/b) << endl;
    }

    

}

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


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
	vector<int> x(5);
	for(int i=0; i<5; ++i) cin >> x[i];
	for(int i=0; i<5; ++i){
		if(x[i] == 0){
			cout << i+1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define int long long
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);
#define loop(n) for (int i = 0; i < n; i++)
#define double long double
#define mod 998244353
#define pi 3.1415926535897
#define F first
#define S second
#define pb push_back

using namespace std;

string multiply(string num1, string num2)
{
	int len1 = num1.size();
	int len2 = num2.size();
	if (len1 == 0 || len2 == 0)
		return "0";

	// will keep the result number in vector
	// in reverse order
	vector<int> result(len1 + len2, 0);

	// Below two indexes are used to find positions
	// in result.
	int i_n1 = 0;
	int i_n2 = 0;

	// Go from right to left in num1
	for (int i = len1 - 1; i >= 0; i--)
	{
		int carry = 0;
		int n1 = num1[i] - '0';

		// To shift position to left after every
		// multiplication of a digit in num2
		i_n2 = 0;

		// Go from right to left in num2
		for (int j = len2 - 1; j >= 0; j--)
		{
			// Take current digit of second number
			int n2 = num2[j] - '0';

			// Multiply with current digit of first number
			// and add result to previously stored result
			// at current position.
			int sum = n1 * n2 + result[i_n1 + i_n2] + carry;

			// Carry for next iteration
			carry = sum / 10;

			// Store result
			result[i_n1 + i_n2] = sum % 10;

			i_n2++;
		}

		// store carry in next cell
		if (carry > 0)
			result[i_n1 + i_n2] += carry;

		// To shift position to left after every
		// multiplication of a digit in num1.
		i_n1++;
	}

	// ignore '0's from the right
	int i = result.size() - 1;
	while (i >= 0 && result[i] == 0)
		i--;

	// If all were '0's - means either both or
	// one of num1 or num2 were '0'
	if (i == -1)
		return "0";

	// generate the result string
	string s = "";

	while (i >= 0)
		s += std::to_string(result[i--]);

	return s;
}

signed main()
{
	fast;
	int test = 1;
	// cin >> test;
	for (int index = 0; index < test; index++)
	{
		string s1, s2;
		cin >> s1 >> s2;
		string ans = multiply(s1, s2);
		cout << ans << endl;
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll fact(ll x){
	if(x == 0) return 1;
	else return (x*fact(x-1))%mod;
}

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

    ll N;
    string S;
    cin >> N >> S;

    ll res = 1;
    ll tmp = 0;
    REP(i, 2*N){
    	if(tmp < 0){
    		cout << 0 << endl;
    		return 0;
    	}
    	//dump(i)
    	//dump(res)
    	if(S[i] == 'B'){
    		if(tmp%2==0){
    			tmp++;
    		}else{
    			res *= tmp;
    			res %= mod;
    			tmp--;
    		}
    	}else{
    		if(tmp%2==0){
    			res *= tmp;
    			res %= mod;
    			tmp--;
    		}else{
    			tmp++;
    		}
    	}
    	//dump(tmp)
    }

    //dump(fact(N))

    cout << (tmp == 0 ? (res * fact(N)) % mod : 0) << endl;
    return 0;
}

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

struct Combination {
  vector<ModInt<>> _fact, _rfact, _inv;
  Combination(long long nsize = 5000000)
      : _fact(nsize + 1), _rfact(nsize + 1), _inv(nsize + 1) {
    _fact[0] = _rfact[nsize] = _inv[0] = 1;
    for (int i = 1; i <= nsize; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[nsize] /= _fact[nsize];
    for (int i = nsize - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for (int i = 1; i <= nsize; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
  inline ModInt<> fact(int k) const { return _fact[k]; }

  inline ModInt<> rfact(int k) const { return _rfact[k]; }

  inline ModInt<> inv(int k) const { return _inv[k]; }

  ModInt<> P(int n, int r) const {
    if (r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  ModInt<> C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
  // n types,choose r
  ModInt<> H(int n, int r) const {
    if (n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

int n;
Combination com;

ModInt<> solve();

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res, bf = 0;
  for (int i = 1; i < n; ++i) {
    ModInt<> now = com.fact(i) * com.fact(n - 1 - i) * com.C(i - 1, n - i - 1);
    res += (now - bf) * i;
    bf = now;
  }
  return res;
}

Measured memory_bytes: 61624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		int[] a = new int[n];
		int[] b = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		b = a.clone();

		long ans = Long.MAX_VALUE;

		for (int k = 0; k < n; k++) {

			long xk = x * k;
			long sum = 0;

			for (int i = 0; i < n; i++) {
				b[i] = Math.min(b[i], a[(i - k + n) % n]);
				sum += b[i];
			}

			ans = Math.min(ans, sum + xk);

		}

		System.out.println(ans);

	}

}


Measured memory_bytes: 28304
N = int(input())
X = list(map(int,input().split()))
X = [[X[i],i] for i in range(N)]
#print(N,X)

X.sort()
medind = (N-2)//2 
med = X[medind][0]
res = [0]*N

for i in range(N):
    if i <= medind:
        res[X[i][1]] = X[medind+1][0]
    else:
        res[X[i][1]] = med
#print(res)

for i in range(N):
    print(res[i])

Measured memory_bytes: 114004
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DArrangement {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      if (n==2) {
        cout << -1 << endl;
        return;
      }

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

      set<int> st;
      for(int i=1; i<=n; i++) {
        st.insert(i);
      }

      priority_queue<P> que;
      for(int i=1; i<=n; i++) {
        que.emplace(cnt[i], i);
      }

      vector<int> b(n);
      for(int i=0; i<n-3; i++) {
        b[i] = -1;
        while (que.top().first >= n-1-i) {
          if (st.find(que.top().second) == st.end()) {
            // already removed
            que.pop();
            continue;
          } else if (que.top().first != cnt[que.top().second]) {
            // update
            que.pop();
            que.emplace(cnt[que.top().second], que.top().second);
            continue;
          }
          b[i] = que.top().second;
          que.pop();
          break;
        }
        if (b[i] == -1) {
          auto it = st.begin();
          if (i > 0 && a[b[i-1]] == *it) {
            ++it;
          }
          b[i] = *it;
        }
        st.erase(b[i]);
        cnt[a[b[i]]]--;
      }

      // brute-force search
      vector<int> vec;
      for(auto e: st) {
        vec.push_back(e);
      }

      do {
        b[n-3] = vec[0];
        b[n-2] = vec[1];
        b[n-1] = vec[2];
        if (a[b[n-4]] != b[n-3] && a[b[n-3]] != b[n-2] && a[b[n-2]] != b[n-1]) {
          for(auto e: b) {
            cout << e << ' ';
          }
          cout << endl;
          return;
        }
      } while (next_permutation(all(vec)));

      // failed...
      cout << -1 << endl;
    }
};

signed main() {
  DArrangement solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 8308
#include<cstdio>
        #include<string>
        #include<iostream>
        using namespace std;
        int n;
        string w[100];
        int main() {
          scanf("%d", &n);
          bool flag = true;
          cin >> w[0];
          for (int i = 1; i < n; i++) {
            cin >> w[i];
            for (int j = 0; j < i; j++) if (w[i] == w[j]) {
              flag = false;
              break;
            }
            if (w[i][0] != w[i-1][w[i-1].length() - 1]) flag = false;
            if (!flag) break;
          }
          if (flag) printf("Yes\n");
          else printf("No\n");
        }

Measured memory_bytes: 256
res = input().split()
map(int, res)
q = res
cand = []
while len(q) > 0:
    now = q[0]
    q.pop(0)
    b = [x for i, x in enumerate(res) if i != now]
    for i in range(len(b)):
        cand.append(int(now) + int(b[i]))
print(min(cand))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;

  vector<vector<pair<int,int>>> xy(N);

  for(int i = 0;i < N;i++){
    int A;
    cin >> A;
    for(int j = 0;j < A;j++){
      int x,y;
      cin >> x >> y;
      x--;
      xy[i].push_back(make_pair(x,y));
    }
  }

  int ans = 0;
  for(int i = 0;i < (1 << N);i++){
    int now_cnt = 0;
    vector<int> tf(N);
    for(int j = 0;j < N;j++){
      if((i >> j) & 1){
        now_cnt++;
	tf[j] = 1;
      }
      else tf[j] = 0;
    }
   
    bool flag = true;
    for(int j = 0;j < N;j++){
      if(tf[j] == 1){
        for(pair<int,int> P:xy[j]){
          if(tf[P.first] != P.second){
	    flag = false;
	  }
	}
      }
    }
    if(flag)ans = max(ans,now_cnt);
  }

  cout << ans << endl; 

}

Measured memory_bytes: 256
# coding: utf-8
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

dists = [K-A[-1]+A[0]]

for i in range(1,N):
  tmp = A[i] - A[i-1]
  dists.append(tmp)

print(K-max(dists))

Measured memory_bytes: 26060
#include <stdio.h>
#include <limits.h>
#include <string.h>

#define MAX 100001
#define INF INT_MAX

int Partition(int*, char*, int, int);
void Quicksort(int*, char*, int, int);
void merge(int*, char*, int, int, int);
void Mergesort(int*, char*, int, int);

int main(){
  int n, i, arr_q[MAX], arr_m[MAX];
  char mark_q[MAX], mark_m[MAX];

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("\n%c%d" , mark_q+i, arr_q+i);

    arr_m[i] = arr_q[i];
    mark_m[i] = mark_q[i];
  }

  Quicksort(arr_q, mark_q, 0, n-1);
  Mergesort(arr_m, mark_m, 0, n);

  if(memcmp(arr_q, arr_m, n) == 0 &&
     memcmp(mark_q, mark_m, n) == 0){
    puts("Stable");
  }else{
    puts("Not stable");
  }
 
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n" ,mark_q[i], arr_q[i]);
  }

  return 0;
}

int Partition(int arr[], char mark[], int p, int r){
  int x = arr[r], i = p - 1, j, tmp;
  char tmp_mark;

  for(j = p ; j < r ; j++){
    if(arr[j] <= x){
      i++;
      tmp = arr[i];
      arr[i] = arr[j];
      arr[j] = tmp;

      tmp_mark = mark[i];
      mark[i] = mark[j];
      mark[j] = tmp_mark;
    }
  }
  
  tmp = arr[i+1];
  arr[i+1] = arr[r];
  arr[r] = tmp;
  
  tmp_mark = mark[i+1];
  mark[i+1] = mark[r];
  mark[r] = tmp_mark;
  
  return ++i;
}

void Quicksort(int arr[], char mark[], int p, int r){
  int q;

  if(p < r){
    q = Partition(arr, mark, p, r);
    Quicksort(arr, mark, p, q-1);
    Quicksort(arr, mark, q+1, r);
  }
}

void merge(int arr[], char mark[], int left, int mid, int right){
  int n1 = mid - left, n2 = right - mid;
  int L[MAX], R[MAX], i, j, k;
  char Lm[MAX], Rm[MAX];

  for(i = 0 ; i < n1 ; i++){
    L[i] = arr[left + i];
    Lm[i] = mark[left + i];
  }

  for(i = 0 ; i < n2 ; i++){
    R[i] = arr[mid + i];
    Rm[i] = mark[mid + i];
  }

  L[n1] = R[n2] = INF;
  for(i = 0, j = 0, k = left ; k < right ; k++){
    if(L[i] <= R[j]){
      arr[k] = L[i];
      mark[k] = Lm[i++];
    }else{
      arr[k] = R[j];
      mark[k] = Rm[j++];
    }
  }
}

void Mergesort(int arr[], char mark[], int left, int right){
  int mid;

  if(left + 1 < right){
    mid = (left + right) / 2;
    Mergesort(arr, mark, left, mid);
    Mergesort(arr, mark, mid, right);
    merge(arr, mark, left, mid, right);
  }
}

Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
int main(){
  int n; cin>>n;
  long double k,ans=0,memo=0;
  cin>>k;
  
  rep(i,n){
    if(i+1>=k)ans+=2;
    else ans+=pow(0.5,ceil(log2(k/(i+1))-1));
  }
  
  ans/=2*n;
  cout<<fixed<<setprecision(12);
  cout<<ans<<endl;
}


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

int main(){
    long long N;
    long long lst[5];
    cin >> N;
    for(int i=0;i<5;i++){
        cin >> lst[i];
    }
    long long min = lst[0];
    long long idx_min = 0;
    for(int i=1;i<5;i++){
        if(min > lst[i]){
            idx_min = i;
            min = lst[i];
        }
    }
    cout << 4 + (N + (min - 1)) / min; 
    return EXIT_SUCCESS;
}

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

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

    string s = "No";
    for(int i=0;i<26;i++){
        for(int j=0;j<15;j++){
            if(4*i+7*j==n) s = "Yes";
        }
    }

    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cout<<elem;}cerr<<endl;}

const int mod=998244353;

/*二項係数(mod付き)*/
struct Combination{
	const int max=51e4;			//適宜変更する.
	//const int mod=1e9+7;
	vector<llong> fact,inv,finv;//階乗,逆元,逆元の階乗.
	
	Combination():fact(max),inv(max),finv(max){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<max;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){//nが大きい場合に使用.
		llong res=1LL;
		REP(i,k) res=res*(n-i)%mod;
		res=res*finv[k]%mod;
		return res;
	}
};

int main(){
	Combination ob;
	
	int n,m,k;
	cin>>n>>m>>k;
	
	vector<llong> mem(n+1);
	mem[1]=m;
	for(int i=2;i<=n;++i){
		mem[i]=mem[i-1]*(m-1)%mod;
	}
	
	llong ans=0;
	for(int i=0;i<=k;++i){
		//debug(ob.nCk(n-1,i));
		ans=(ans+mem[n-i]*ob.nCk(n-1,i)%mod)%mod;
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 16688
#include <bits/stdc++.h>
using namespace std;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
int n, a[300];
double dp[301][301][301];
bool vis[301][301][301];
double calc(int x, int y, int z) {
	if(x == 0 && y == 0 && z == 0) return 0.0;
	if(vis[x][y][z]) return dp[x][y][z];
	double res = 0.0;
	if(x > 0) res += calc(x - 1, y, z) * ((double)x / n) + (double)x / n;
	if(y > 0) res += calc(x + 1, y - 1, z) * ((double)y / n) + (double)y / n;
	if(z > 0) res += calc(x, y + 1, z - 1) * ((double)z / n) + (double)z / n;
	res += ((double)n - x - y - z) / n;
	res /= (1.0 - ((double)n - x - y - z) / n);
	vis[x][y][z] = 1;
	return dp[x][y][z] = res;
}
int main() {
	R(n);
	int x = 0, y = 0, z = 0;
	for(int i = 0; i < n; i++) {
		R(a[i]);
		if(a[i] == 1) x++;
		if(a[i] == 2) y++;
		if(a[i] == 3) z++;
	}
	memset(vis, 0, sizeof(vis));
	double ans = calc(x, y, z);
	W(ans);
	return 0;
}

Measured memory_bytes: 239872
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 main() {
    input! {
        height: usize,
        width: usize,
        h: usize,
        w: usize
    }
    println!("{}", (height - h) * (width - w));
}


Measured memory_bytes: 4352
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int a,b,c;
  cin>>a>>b>>c;
  if (b-a == c-b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import itertools
import math

N = int(input())

XY = [list(map(int,input().split())) for i in range(N)]

P = list(itertools.permutations(XY,r = N))

D = math.factorial(N)

area = 0

for i in range(0,len(P)):
  p = P[i]
  for j in range(0,N - 1):
    x = (p[j][0] - p[j + 1][0]) ** 2
    y = (p[j][1] - p[j + 1][1]) ** 2
    area += math.sqrt(x + y)
  
print(area / D)

Measured memory_bytes: 7972
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n, k;
	cin >> k >> n;
	vector<ll> arr(n);
	for(auto& el: arr) cin >> el;
	ll ans = k;
	for(int i = 0; i < n; i++) {
		int ne = (i + 1) % n;
		ans = min(ans, k - (k + arr[ne] - arr[i]) % k);
	}
	cout << ans << '\n';
}



Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

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

    if (a%2 != b%2){
        cout << "IMPOSSIBLE";
    }
    else{
        cout << (a + b) /2; 

    }

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n, m,s;
	int i,j;
	while (cin >> n >> m) {
		if (n == 0 && m == 0)break;
		int a[100], b[100];
		int suma = 0; int sumb = 0;
		for (i = 0; i < n; i++) {
			cin >> s; a[i] = s; suma += s;
		}
		for (i = 0; i < m; i++) {
			cin >> s; b[i] = s; sumb += s;
		}
		int mi = (int)MOD;
		for (i = 0; i < n; i++) {
			for (j = 0; j < m; j++) {
				if ((a[i] - b[j]) * 2 == suma - sumb&&a[i]<mi) {
					mi = a[i];
				}
			}
		}
		if (mi == (int)MOD)cout << -1 << endl;
		else cout << mi << " " << mi - (suma - sumb) / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 3008
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
int a[4010];
int b[4010];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt1=0;
	int cnt2=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R'){
			a[cnt1]=i+1;
			cnt1++;
		}
		else if(s[i]=='G'){
			b[cnt2]=i+1;
			cnt2++;
		}
	}
	ll ans=0;
	for(int i=0;i<cnt1;i++) {
		for(int j=0;j<cnt2;j++){
			int cnt=n-cnt1-cnt2;
			if((2*b[j]-a[i])>0&&(2*b[j]-a[i])<=n){
				if(s[2*b[j]-a[i]-1]=='B')
				cnt--;
			}
			if((2*a[i]-b[j])>0&&(2*a[i]-b[j])<=n){
				if(s[2*a[i]-b[j]-1]=='B')
				cnt--;
			}
			if((b[j]+a[i])>0&&(b[j]+a[i])<=2*n){
				if((b[j]+a[i])%2==0){
					int te=(b[j]+a[i])/2;
					if(s[te-1]=='B')
					cnt--;
				}
			}
			ans+=cnt;
		}
	}
	cout<<ans;
	return 0;
} 

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    ll a,b;

ll Binary_Search() {
    ll st=0, ed = 1e18, res = -1;
    while (st <= ed) {
        ll mid = (st + ed)/2;
        ll x = floor(mid*0.08);
        ll y = floor(mid*0.1);
        if (x == a && y == b) {
            res = mid;
            ed = mid-1;
        }
        else if (x > a || y > b)
            ed = mid-1;
        else
            st = st+1;
        ///cout <<x <<" " <<y <<" " <<mid <<n1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>a >>b;
    cout <<Binary_Search();



    return 0;
}


Measured memory_bytes: 256
// AOJ 2601: Evacuation Route
// 2017.11.26 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

#define INF 0x5fffffff
int a[100002];
int b[100002];

char buf[700002], *p;
int getint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int w, i, k, f, close, ans;

	fgets(p=buf, 10, stdin), w = getint();
	fgets(p=buf, sizeof(buf), stdin);
	for (ans = 0, f = 0, i = 1; i <= w; i++) {
		a[i] = k = getint(), p++;
		if (!k) f |= 1;
		else if (k < 0) f |= 2;
		else ans += k;
	}
	if (!ans || !(f & 1)) { puts("0"); return 0; }
	if (!(f & 2)) { printf("%d\n", ans); return 0; }

	for (close = 0, f = 0, i = 1; i <= w; i++) {
		if (!a[i]) close = INF, f = -1;
		else if (a[i] < 0) {
			if (f < 0 || close - (i-f) > -a[i]) close = -a[i], f = i;
		} else {
			if (f < 0) b[i] = INF;
			else {
				k = close - (i-f); if (k < 0) k = 0;
				b[i] = k;
			}
		}
	}

	for (close = 0, f = w, i = w; i >= 1; i--) {
		if (!a[i]) close = INF, f = -1;
		else if (a[i] < 0) {
			if (f < 0 || close - (f-i) > -a[i]) close = -a[i], f = i;
		} else {
			if (f < 0) b[i] = INF;
			else {
				k = close - (f-i); if (k < 0) k = 0;
				if (k > b[i]) b[i] = k;
			}
		}
	}

	for (ans = 0, i = 1; i <= w; i++) {
		if (a[i] > 0) {
			if (b[i] > a[i]) ans += a[i];
			else             ans += b[i];
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main(){
    string s;
    cin>>s;
    int n=0;
    rep(i,4){
        if(s[i]=='+') n++;
        else n--;
    }
    cout<<n<<endl;
    return 0;
}

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


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

    int x = n%10;

    if (x == 3) cout << "bon" << endl;
    else if (x == 0 || x == 1 || x == 6 || x == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define in(a, l, r) (l <= a && a < r)
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

int count(string str) {
    int cnt = 0;
    rep(i, str.size() - 1) {
        if(str[i] == 'A' && str[i + 1] == 'B') cnt++;
    }
    return cnt;
}

int main() {
    int N; cin >> N;
    VS s; s.resize(N); rep(i, N) cin >> s[i];

    int a = 0, b = 0, both = 0;
    int ans = 0;
    for(string str: s) {
        ans += count(str);
        if(str[0] == 'B' && str.back() == 'A') both++;
        else if(str[0] == 'B') b++;
        else if(str.back() == 'A') a++;
    }
    DU(ans) DU(both) DU(a) DU(b)
    if(both == 0) {
        ans += min(a, b);
    } else if (a == 0 && b == 0) {
        ans += both - 1;
    } else {
        ans += both + min(a, b);
    }
    out(ans);
    return 0;
}

Measured memory_bytes: 768
S = input()

eligible_months = set(range(1,13))

first = int(S[:2])
second = int(S[-2:])

if first in eligible_months:

    if second in eligible_months:

        print('AMBIGUOUS')

    else:

        print('MMYY')

else:

    if second in eligible_months:

        print('YYMM')

    else:

        print('NA')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <tuple>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <unordered_map>

using namespace std;
using str = string;

#define rep(a,l,r) for(int a=(l);a<(r);a++)
#define get cin>>
#define put cout<<

void run() {

	int a; int b; get a; get b;

	put a*b-(a+b-1);

}
int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);run();return 0;}


Measured memory_bytes: 256
import sys
n = int(input())
print(0)
sys.stdout.flush()
l = 0
r = n+1
x = input()
if x == "Vacant":
  exit()
prv = 0
while True:
  m = (l+r)//2
  print(m)
  sys.stdout.flush()
  y = input()
  if y == "Vacant":
    break
  if (x == y) ^ (prv%2 == m%2) == 0:
    if prv>m:
      r = m
    else:
      l = m
  else:
    if prv>m:
      l = m
    else:
      r = m
  prv = m
  x = y

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n){
    b[i] = 0;
  }
  rep(i,n-1){
    cin >> a[i+1];
    b[a[i+1]-1]+=1;
  }
  rep(i,n){
    cout << b[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4808
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
	int x[5] = {a, b, c, d, e};
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if(abs(x[i]-x[j])<=k){
				continue;
			}else{
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define min(a,b) (a)<=(b)?(a):(b)
int main()
{   int n,m,x,a[101],i,p;
    scanf("%d%d%d",&n,&m,&x);
    for(i=0;i<m;i++){
        scanf("%d",&a[i]);
        if(a[i]>x){
            p=i;
            break;
        }
    }
    p=min(p,m-p);
    
    printf("%d",p);

    return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import fractions
a,b,c,d = list(map(int,input().split()))

lcm_cd = c*d//fractions.gcd(c,d)

a_div_c = a//c
ac_mod = a%c
bc = b//c

a_div_d = a//d
ad_mod = a%d
bd = b//d

a_div_lcm_cd = a//lcm_cd
alcm_cd_mod = a%lcm_cd
blcm_cd = b//lcm_cd

cnt_c = 0
cnt_d = 0
cnt_lcmcd = 0

cnt_c = (bc-a_div_c)
if not ac_mod:
    cnt_c+=1

cnt_d = (bd-a_div_d)
if not ad_mod:
    cnt_d+=1

cnt_lcmcd = (blcm_cd-a_div_lcm_cd)
if not alcm_cd_mod:
    cnt_lcmcd+=1
print(b-a+1-(cnt_c+cnt_d-cnt_lcmcd))


Measured memory_bytes: 5076
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Maybe
import Data.Function (fix)
import Data.Array (Array, array, (!))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt

data Tree a = Tree (Tree a) a (Tree a)

instance Functor Tree where
    fmap f (Tree l m r) = Tree (fmap f l) (f m) (fmap f r)

index :: Tree a -> Int -> a
index (Tree _ m _) 0 = m
index (Tree l _ r) n = case (n - 1) `divMod` 2 of
    (q,0) -> index l q
    (q,1) -> index r q

nats :: Tree Int
nats = go 0 1
    where go !n !s = Tree (go l s') n (go r s')
            where l = n + s
                  r = l + s
                  s' = s * 2

memo :: (Int -> a) -> (Int -> a)
memo f = index cached
    where cached = fmap f nats

memo2 :: (Int -> Int -> a) -> (Int -> Int -> a)
memo2 f = memo (\x -> memo (f x))

memo3 :: (Int -> Int -> Int -> a) -> (Int -> Int -> Int -> a)
memo3 f = memo (\x -> memo2 (f x))

{- dp example
fibo 0 = 0
fibo 1 = 1
fibo n = mfibo (n-1) + mfibo (n-2)

mfibo = memo fibo
-}

solve :: [Int] -> Int -> Int
solve (x:y:arr) a
    | x+y <= a = solve (y:arr) a
    | otherwise = let k = x + y - a in k + solve (max 0 (y-k):arr) a
solve [x] a = if x > a then x - a else 0

main :: IO ()
main = do
    [n, a] <- getInts
    arr <- getInts
    print $ solve arr a

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

int main() {
  int N,K;
  cin>>N>>K;
  int b=1;
  int i=0;
  for(;b<K&&i<N;i++){
    b*=2;
  }
  for(;i<N;i++){
    b+=K;
  }
  cout<<b<<endl;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;

struct Point
{
    int index;
    double x;
    double y;
};

Point p[100005];
int ans_up[100005];
int ans_down[100005];
char s[1000];

bool cpr(Point a, Point b)
{
    if(a.x<b.x) return 1;
    if(a.x==b.x&&a.y<b.y) return 1;
    return 0;
}

bool ccw(Point a, Point b, Point c)
{
    return (b.x-a.x)*(c.y-b.y)>=(c.x-b.x)*(b.y-a.y);
}

int main()
{
    int i, n, index_up, index_down, minn_y, minn_index;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%lf %lf", &p[i].x, &p[i].y);
        p[i].index=i;
    }
    sort(p, p+n, cpr);
    ans_down[0]=0;
    ans_down[1]=1;
    index_down=2;
    for(i=2;i<n;i++){
        while(index_down>1&&!ccw(p[ans_down[index_down-2]], p[ans_down[index_down-1]], p[i])) index_down--;
        ans_down[index_down]=i;
        index_down++;
    }
    ans_up[0]=n-1;
    ans_up[1]=n-2;
    index_up=2;
    for(i=n-3;i>=0;i--){
        while(index_up>1&&!ccw(p[ans_up[index_up-2]], p[ans_up[index_up-1]], p[i])) index_up--;
        ans_up[index_up]=i;
        index_up++;
    }
    minn_index=0;
    for(i=1;i<index_down;i++){
        if(p[ans_down[i]].y<p[ans_down[minn_index]].y||(p[ans_down[i]].y==p[ans_down[minn_index]].y&&p[ans_down[i]].x<p[ans_down[minn_index]].x)){
            minn_index=i;
        }
    }
    printf("%d\n", index_up+index_down-2);
    for(i=minn_index;i<index_down;i++) printf("%.0f %.0f\n", p[ans_down[i]].x, p[ans_down[i]].y);
    for(i=1;i<index_up-1;i++) printf("%.0f %.0f\n", p[ans_up[i]].x, p[ans_up[i]].y);
    for(i=0;i<minn_index;i++) printf("%.0f %.0f\n", p[ans_down[i]].x, p[ans_down[i]].y);
    /*for(i=0;i<index_down-1;i++) printf("%d %f %f\n", p[ans_down[i]].index, p[ans_down[i]].x, p[ans_down[i]].y);
    for(i=0;i<index_up-1;i++) printf("%d %f %f\n", p[ans_up[i]].index, p[ans_up[i]].x, p[ans_up[i]].y);*/
}

Measured memory_bytes: 3464
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;
typedef long long ll;

using namespace std;

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

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    int g = A[0];
    REP(i, N-1) {
        g = gcd(g, A[i+1]);
    }
    int m = 0;
    REP(i, N) {
        m = max(m, A[i]);
    }
    if (K > m) {
        print("IMPOSSIBLE");
    } else if (g == 1) {
        print("POSSIBLE");
    } else if (K % g == 0) {
        print("POSSIBLE");
    } else {
        print("IMPOSSIBLE");
    }

}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long A,B,C,K;
  cin >> A >> B >> C >> K;
  
  long ans = A;
  if(K<=A){
    ans = K;
  }else if(K>A+B){
    ans = A-(K-(A+B));
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int a, b, c, d, e, k;
    int ans;

    //input
    cin >> a >> b >> c >> d >> e >> k;

    if(k >= e - a){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}


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

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

int main()
{
    int N;
    cin >> N;
    vector<long> A(N), B(N), C(N);
    rep(i, N){
        cin >> A.at(i);
    }
    rep(i, N){
        cin >> B.at(i);
    }
    rep(i, N){
        cin >> C.at(i);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    long long ans = 0;
    rep(i, N){
        auto IterA = lower_bound(A.begin(), A.end(), B.at(i));
        auto IterC = upper_bound(C.begin(), C.end(), B.at(i));
        ans += (IterA - A.begin()) * (C.end() - IterC);
    }

    cout << ans << endl;
}



Measured memory_bytes: 2560
import numpy as np


# read
h, w, K = map(int, input().split())
data = []
for i in range(h):
    data.append(list(input()))
data = np.array(data)

# count
ans = 0
for i in range(2**h):
    h_indexs = []
    for k in range(h):
        if (i >> k) & 1:
            h_indexs.append(k)
    
    for j in range(2**w):
        w_indexs = []
        for k in range(w):
            if (j >> k) & 1:
                w_indexs.append(k)
        d = np.copy(data)
        # coloring
        for h_index in h_indexs:
            d[h_index, :] = 'r'
        for w_index in w_indexs:
            d[:, w_index] = 'r'
        num = (d == '#').sum()
        if num == K:
            ans += 1
        
print(ans)

Measured memory_bytes: 27252
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int gcd(int A, int B){
    if(B == 0){
        return A;
    }
    return gcd(B, A%B);
}

int main(){
    int K;
    cin >> K;
    int sum = 0;
    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                sum += gcd(gcd(i,j), k);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

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

void Main() {
    i32 N, M;
    cin >> N >> M;
    Vec<i32> X(M);
    for (i32 i = 0; i < M; i++) {
        cin >> X[i];
    }
    sort(ALL(X));
    if (N >= M) {
        cout << 0 << endl;
        return;
    }
    priority_queue<i32, Vec<i32>, greater<i32> > pq;
    for (i32 i = 0; i < M - 1; i++) {
        pq.push(abs(X[i + 1] - X[i]));
    }
    i64 ans = 0;
    for (i32 i = 0; i < M - N; i++) {
        i32 dis = pq.top();
        ans += dis;
        pq.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 4184