akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

long long mon(long long in) {

	if (in != 1) {
		in /= 2;
		return mon(in) * 2 + 1;
	}
	else {
		return 1;
	}
}

int main() {
	long long h;
	cin >> h;

	long long ans = mon(h);
	cout << ans << endl;

	return 0;
}

//CCCCCCCCCCCC
//int main() {
//	int n, k;
//	cin >> n >> k;
//
//	vector<int> h(n);
//	for (int i = 0;i < n;i++) {
//		cin >> h[i];
//	}
//
//	sort(h.rbegin(), h.rend());
//	long long ans = 0;
//	for (int i = k;i < n;i++) {
//		ans += h[i];
//	}
//
//	cout << ans << endl;
//	return 0;
//}

//BBBBBBBBBBBBBB
//int main() {
//	int h, n;
//	cin >> h >> n;
//	vector<int> a(n);
//	for (int i = 0;i < n;i++) {
//		cin >> a[i];
//	}
//
//	for (int i = 0;i < n;i++) {
//		h -= a[i];
//		if (h <= 0) {
//			cout << "Yes" << endl;
//			return 0;
//		}
//	}
//
//	cout << "No" << endl;
//
//	return 0;
//}

//AAAAAAAAAAAAA
//int main() {
//	int h,a;
//	cin >> h >> a;
//
//	if (h % a != 0)
//		cout << h / a + 1 << endl;
//	else cout << h / a << endl;
//	
//	return 0;
//}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

inline ll sum(ll n, ll b){
	ll ret = 0;
	while(n){
		ret += n%b;
		n /= b;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll n, s;
	cin>>n>>s;
	if(s > n){
		cout<<-1<<'\n';
		exit(0);
	}
	if(n == s){
		cout<<n + 1<<'\n';
		exit(0);
	}
	for(ll b = 2; b*b - 1 < n; b++){
		if(sum(n, b) == s){
			cout<<b<<'\n';
			exit(0);
		}
	}
	ll diff = n - s;
	ll ans = -1;
	for(ll f = 1; f*f <= diff; f++){
		if(sum(n, f + 1) == s){
			cout<<f + 1<<'\n';
			exit(0);
		}
		if(sum(n, diff/f + 1) == s)ans = diff/f + 1;
	}
	cout<<ans<<'\n';

	return 0;
}

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

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

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            B = [A[i], A[j], A[k]]
            if len(set(B)) == 3 and (max(B) < sum(B) - max(B)):
                total += 1

print(total)

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


int main() {
  int n;
  cin >> n;
  vector<long>a(n);
  long ans=1;
  rep(i,n){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  rep(i,n){
    if(a.at(i)==0){
      ans=0;
      break;
    }
    else{
  if(ans<=1000000000000000000/a.at(i)){
    ans*=a.at(i);
  }
   else{
      ans=-1;
     break;
   }
    }
  }
  
    cout<<ans<<endl;
  
  
  
}







Measured memory_bytes: 4048
#include<stdio.h>

int main(){
  int a, b, c, k, max, val;
  val = scanf("%d%d%d%d", &a, &b, &c, &k);
  if(val == 0) return 1;
  max = (a < b) ? ((b < c) ? c : b) : ((a < c) ? c : a);
  val = max;
  while(k > 0){
    k--;
    val *= 2;
  }
  printf("%d", val - max + a + b + c);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  long long N;
  int X = 0;
  scanf("%lld",&N);

  long long m = N;
  while(m > 0){
    X += m%10;
    m /= 10;
  }

  if(N%X == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}

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

const int MOD = 1000000007;
const int INF = 1000000000;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

// a = max(a, b), a = min(a, b)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

int main(){
    int N;
    cin >> N;
    map<string, int>S;
    REP(i, N){
        string A;
        cin >> A;
        S[A]++;
    }
    int cnt = 0;
    for(auto x : S){
        chmax(cnt, x.second);
    }
    vector<string>ans;
    for(auto x : S){
        if(cnt == x.second) ans.push_back(x.first);
    }
    sort(all(ans));
    REP(i, ans.size()){
        print(ans.at(i));
    }

}


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

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

  for (int i = 0; i < (int)T.size(); i++) {
    if(T[i]=='?') {
      T[i]='D';
    }
  }

  cout << T << endl;
  return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, A[201010], AA[201010], B[201010];
//---------------------------------------------------------------------------------------------------
int check(int x) {
    rep(i, 0, 2 * N - 1) {
        if (A[i] < x) AA[i] = 0;
        else AA[i] = 1;
    }
    rep(i, 0, 2 * N - 1) B[i] = 0;
    rep(i, 0, 2 * N - 1) {
        if (i) if (AA[i - 1] == AA[i]) B[i] = 1;
        if (i + 1 < 2 * N - 1) if (AA[i] == AA[i + 1]) B[i] = 1;
    }

    int f = 0;
    rep(i, 0, 2 * N - 1) if (B[i]) f = 1;
    if (f == 0) {
        // 01010101...
        if (N % 2 == 0) return 1 - AA[N - 1];
        else return AA[N - 1];
    } else {
        int x = N - 1, y = N - 1;
        while (B[x] == 0 and B[y] == 0) { x--; y++; }
        if (B[x]) return AA[x];
        return AA[y];
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N * 2 - 1) cin >> A[i];

    check(5);
    
    int ok = 1, ng = 2 * N;
    while (ok + 1 != ng) {
        int md = (ok + ng) / 2;
        if (check(md)) ok = md;
        else ng = md;
    }

    cout << ok << endl;
}

Measured memory_bytes: 2560
H,W = map(int,input().split())

a = []

for _ in range(H):
    a.append(list(map(int,input().split())))

n_order = 0
order = []
for i in range(H):
    for j in range(W):
        if j != W-1:
            if a[i][j]%2 == 1:
                a[i][j+1] += 1
                a[i][j] -= 1
                n_order += 1
                order.append([i+1,j+1,i+1,j+2])
        else:
            if a[i][j]%2 == 1:
                try:
                    a[i][j] -= 1
                    a[i+1][j] += 1
                    n_order += 1
                    order.append([i+1,j+1,i+2,j+1])
                except:
                    pass

print(n_order)
for i in order:
    print(*i)

Measured memory_bytes: 30264
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
ans = 0
cnt = 0

for i in range(1,m+1):
    for j in a:
        if i in j[1:]:
            cnt += 1
    if cnt == n:
        ans += 1
    cnt = 0

print(ans)

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vi v(m);
	REP(i, m)cin >> v[i];
	sort(ALL(v));
	if (n >= m) {
		cout << 0 << endl;
	}
	else {
		vi t(m - 1);
		REP(i, m - 1)t[i] = v[i + 1] - v[i];
		sort(ALL(t));
		int ans = v.back()-v.front();
		REP(i, n - 1)ans -= t[m - 2 - i];
		cout << ans << endl;
	}
	
}

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#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()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

template<class T>
class BIT
{
public:
  int n;
  vector<T> bit;

  BIT(){}

  BIT(int n_)
  {
    init(n_);
  }

  void init(int n_)
  {
    n = n_;
    bit.resize(n+1);
    clear();
  }

  T sum(int i)
  {
    T s = 0;
    while(i > 0){
      s += bit[i];
      s %= mod;
      i -= i&-i;
    }
    return s;
  }

  void add(int i, T x)
  {
    while(i <= n){
      bit[i] += x;
      bit[i] %= mod;
      i += i&-i;
    }
  }

  void clear()
  {
    for(int i = 0; i < n; i++){
      bit[i] = 0;
    }
  }
};

/*
  dp[i][j]
    i個めのアメをj番目の子供に挙げる
    BITを使う

  dp[i][j] = dp[i-1][j] + dp[i-1][j-1] ...
              + dp[i-1][max(0, j-a[i])]
*/

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

  vi a(n);
  rep(i, n) cin >> a[i];

  BIT<ll> bit[n+1];
  rep(i, n+1) bit[i].init(k+2);

  bit[0].add(1, 1);
  rep(i, n) repi(j, 1, k+2){
    bit[i+1].add(j, (bit[i].sum(j)-bit[i].sum(max(0, j-a[i]-1)))%mod);
  }

  cout << (bit[n].sum(k+1)-bit[n].sum(k)+mod)%mod << endl;

/*
  rep(i, n+1){
    repi(j, 1, k+2){
      cout << bit[i].sum(j)-bit[i].sum(j-1) << " ";
    }
    cout << endl;
  }
*/

  return 0;
}


Measured memory_bytes: 79488
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long int
int main(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    priority_queue<ll, vector<ll>, less<ll> >q_a, q_b, q_c;
    for(ll i = 0; i < a; ++i){
        ll num;
        cin >> num;
        q_a.push(num);
    }
    for(ll i = 0; i < b; ++i){
        ll num;
        cin >> num;
        q_b.push(num);
    }
    for(ll i = 0; i < c; ++i){
        ll num;
        cin >> num;
        q_c.push(num);
    }

    ll ans = 0;

    for(ll i = 0; i < x; ++i){
        if(q_c.size() == 0){
            ans += q_a.top();
            q_a.pop();
            continue;
        }
        if(q_a.top() >= q_c.top()){
            ans += q_a.top();
            q_a.pop();
        }
        else{
            ans += q_c.top();
            q_c.pop();
        }
    }

    for(ll i = 0; i < y; ++i){
        ll y_num = q_b.top();
        if(q_c.size() == 0){
            if(a - q_a.size() >= x){
                ans += y_num;
                q_b.pop();
            }
            else{
                if(q_a.top() > y_num){
                    ans += q_a.top();
                    q_a.pop();
                }
                else{
                    ans += y_num;
                    q_b.pop();
                }
            }
        }
        else{
            if(y_num >= q_c.top()){
                if(a - q_a.size() >= x){
                    ans += y_num;
                    q_b.pop();
                }
                else{
                    if(y_num <= q_a.top()){
                        ans += q_a.top();
                        q_a.pop();
                    }
                    else{
                        ans += y_num;
                        q_b.pop();
                    }
                }
            }
            else{
                if(a - q_a.size() >= x){
                    ans += q_c.top();
                    q_c.pop();
                }
                else{
                    if(q_c.top() > q_a.top()){
                        ans += q_c.top();
                        q_c.pop();
                    }
                    else{
                        ans += q_a.top();
                        q_a.pop();
                    }
                }
            }
        }
    }

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

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    if (b - a <= 2) {
        cout << 1 + k << endl;
        exit(0);
    }

    //2回消費してb-a増やせる 事前にa枚必要
    //1回消費して1増やせる

    if (1 + k < a) {
        cout << 1 + k << endl;
        exit(0);
    }

    ll r = a;
    k -= a - 1;

    ll l = k / 2;
    k -= l * 2;

    r += l * (b - a);
    r += k;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <stdio.h>
#include <queue>
#include <stack>
#include <deque>
#include <math.h>
#include <sstream>
#include <stdlib.h>
#include <functional>
#include <deque>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,a,n) for(int i = a; i < n; i++)
#define INF (1<<29)
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define fi first
#define se second 
#define pb push_back
#define PI 3.14159265358979323846
#define all(o) (o).begin(), (o).end()
#define rall(x) x.rbegin(),x.rend()
 
 
typedef double ld;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector < vc > vvc;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long int ulli;
typedef vector<ll> vl;
 
const int dx[] = { 1, 0, -1, 0 };
const int dy[] = { 0, 1, 0, -1 };
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const ld eps = 1e-10, pi = acos(-1.0);
 
#define MAX_N 100001
 
 
// Union-Find木
int par[MAX_N], rnk[MAX_N], unionSize[MAX_N];
// はじめは全ての頂点が根
void UnionFindTreeInit(int n) {
	rep(i, n) {
		par[i] = i;
		rnk[i] = 0;
		unionSize[i] = 1;
	}
}
//木の根元を求める
int root(int x) {
	if (par[x] == x) return x; // 根を返す
	else return par[x] = root(par[x]);
}
// 連結成分の大きさを取得
int componentSize(int x) {
	return unionSize[root(x)];
}
// xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return root(x) == root(y);
}
// xとyの属する集合を併合
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	if (rnk[x] < rnk[y]) {
		par[x] = y;
		unionSize[y] += unionSize[x];
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y]) rnk[x]++;
		unionSize[x] += unionSize[y];
	}
}
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
    ll n,m;
    cin >> n >> m;
    vector < vl > graph(n);
    rep(i, m) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    deque<ll> dq;
    vector<bool> visited(n);
    dq.push_back(0);
    visited[0] = true;
    ll p = 0;
    ll i;
    while(1) {
        for (i = 0;graph[p].size() > i; i++) {
            if (visited[graph[p][i]] == false) {
                break;
            }
        }
        if (i != graph[p].size()) {
            dq.push_back(graph[p][i]);
            visited[graph[p][i]] = true;
            p = graph[p][i];
        } else {
            break;
        }
    }    
    p = 0;
    while(1) {
        for (i = 0;graph[p].size() > i; i++) {
            if (visited[graph[p][i]] == false) {
                break;
            }
        }
        if (i != graph[p].size()) {
            dq.push_front(graph[p][i]);
            visited[graph[p][i]] = true;
            p = graph[p][i];
        } else {
            break;
        }
    }
    cout << dq.size() << endl;
    rep(i,dq.size()) {
        cout << dq[i] + 1 << endl;
    }

	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <string>

using namespace std;

int main() {
    size_t n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    size_t num_qualifier = 0;
    size_t num_foreigner = 0;
    for (size_t i = 0; i < n; ++i) {
        if (s[i] == 'a') {
            if (num_qualifier < (a + b)) {
                cout << "Yes" << endl;
                ++num_qualifier;
            }
            else {
                cout << "No" << endl;
            }
        }
        else if (s[i] == 'b') {
            if (num_qualifier < (a + b) && num_foreigner < b) {
                cout << "Yes" << endl;
                ++num_qualifier;
                ++num_foreigner;
            }
            else {
                cout << "No" << endl;
            }
        }
        else {
            cout << "No" << endl;
        }
    }
    return EXIT_SUCCESS;
}

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

int main(){
    int x[3], ans = 0;

    cin >> x[0] >> x[1] >> x[2];

    sort(x, x+3);

    if((x[2] - x[0]) % 2 == 0 && (x[2] - x[1]) % 2 == 1){
        ++x[2]; ++x[0];
        ++ans;
    }
    else if((x[2] - x[0]) % 2 == 1 && (x[2] - x[1]) % 2 == 0){
        ++x[2]; ++x[1];
        ++ans;
    }
    else if((x[2] - x[0]) % 2 == 1 && (x[2] - x[1]) % 2 == 1){
        ++x[1]; ++x[0];
        ++ans;
    }

    cout << (x[2] - x[0]) / 2 + (x[2] - x[1]) / 2  + ans << endl;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
S = [input().rstrip() for _ in range(H)]
visited = [[False] * W for _ in range(H)]
dq = deque([(0, Ch, Cw)])
while dq:
    d, i, j = dq.popleft()
    if (i, j) == (Dh, Dw):
        print(d)
        exit()
    if visited[i][j]:
        continue
    visited[i][j] = True
    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == '.':
            dq.appendleft((d, ni, nj))
    for di in range(-2, 3):
        for dj in range(-2, 3):
            if di == dj == 0:
                continue
            ni, nj = i + di, j + dj
            if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == '.' and not visited[ni][nj]:
                dq.append((d + 1, ni, nj))
print(-1)

Measured memory_bytes: 235808
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import bisect


def main():
    X = int(input())
    result = []
    for i in range(1, 33):
        result += [i ** j for j in range(2, 10)]
    result.sort()
    index = bisect.bisect_right(result, X)

    print(result[index - 1])


if __name__ == "__main__":
    main()


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

int a, b, c;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> a >> b >> c;
	cout << max({a, b, c}) * 10 + a + b + c - max({a, b, c}) << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)

//your code here!

int main(void){
    ll N, ans[100100], i=0;
	scanf("%lld", &N);
	if(0==N) {
      printf("0");
      return 0;
    }
	while(N){
		ans[i++] = abs(N%(-2));
		if(N<0) N--;
		N /= -2;

	}
	while(i>0) printf("%lld", ans[--i]);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<" | "<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<" | "<<#y<<":"<<y<<" | "<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
bool compare(pi a, pi b){
	if(a.first==b.first)return a.second<b.second;
	return a.first<b.first;
}

 int main(){
 	fast_io;
 	vi a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
 	int k;
 	cin>>k;
 	cout<<a[k-1];
 }

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

int main()
{
    long long int N,i,j,k,l,sum=0;
    scanf("%lld",&N);
    i=N;
    while(i>0)
    {
        sum=sum+i%10;
        i=i/10;
    }
    if(N%sum==0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
#define MODD 998244353
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	string s;
	cin >> n >> s;
	int a[7] = {0};
	a[0] = n;
	long long ans = 1;
	
	for (int i = 0; i < 3 * n; i++) {
		if (s[i] == 'R') {
			if (a[6] > 0) {
				ans = (ans * a[6]) % MODD;
				a[6]--;
				a[7]++;
			} else {
				if (a[2] > 0) {
					ans = (ans * a[2]) % MODD;
					a[2]--;
					a[4]++;
				} else {
					if (a[3] > 0) {
						ans = (ans * a[3]) % MODD;
						a[3]--;
						a[5]++;
					} else {
						ans = (ans * a[0]) % MODD; 
						a[0]--;
						a[1]++;
					}
				}
			}
		} else {
			if (s[i] == 'G') {
				if (a[5] > 0) {
					ans = (ans * a[5]) % MODD;
					a[5]--;
					a[7]++;
				} else {
					if (a[1] > 0) {
						ans = (ans * a[1]) % MODD;
						a[1]--;
						a[4]++;
					} else {
						if (a[3] > 0) {
							ans = (ans * a[3]) % MODD;
							a[3]--;
							a[6]++;
						} else {
							ans = (ans * a[0]) % MODD;
							a[0]--;
							a[2]++;
						}
					}
				}
			} else {
				if (a[4] > 0) {
					ans = (ans * a[4]) % MODD;
					a[4]--;
					a[7]++;
				} else {
					if (a[1] > 0) {
						ans = (ans * a[1]) % MODD;
						a[1]--;
						a[5]++;
					} else {
						if (a[2] > 0) {
							ans = (ans * a[2]) % MODD;
							a[2]--;
							a[6]++;
						} else {
							ans = (ans * a[0]) % MODD;
							a[0]--;
							a[3]++;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    double L;
    cin >> L;
    cout << fixed << setprecision(10);
    cout << (L / 3) * (L / 3) * (L / 3);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
double ara[1000007];
int main()
{
	int size1;
	double sum = 0;
	cin >> size1;
	for (int i = 0;i < size1;i++)
	{
		cin >> ara[i];
		ara[i] = (1 / ara[i]);
		sum += ara[i];
	}
	cout << setprecision(17) << 1 / sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    int total = 0;
    int res = 0;
    string ans = "No";
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        total += A[i];
    }

    for (int i = 0; i < n; i++)
    {
        if (A[i] * 4 * m >= total)
        {
            res++;
        }
    }
    if (res >= m)
        ans = "Yes";

    cout << ans << endl;
}


Measured memory_bytes: 3560
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXNB=50;
const int MAXNA=2*MAXNB-1;
const int MOD=1000000007;

int na,nb;
int a[MAXNA];

int mem[MAXNB+1][MAXNA+1][MAXNA+1];
int go(int preflen,int suffoptused,int curidx) {
	int &ret=mem[preflen][suffoptused][curidx];
	if(ret==-1) {
		if(preflen==nb) return ret=1;
		ret=0;
		int nsuffopt=a[na-preflen]-a[preflen-1]+1;
		bool rembotopt=a[preflen-1]!=a[preflen];
		bool remtopopt=a[na-preflen]!=a[na-preflen-1];
		REPE(usedrembot,rembotopt?1:0) REPE(usedremtop,remtopopt?1:0) FORE(delta,-2,+2) {
			int nsuffoptused=suffoptused-usedrembot-usedremtop+(abs(delta)==1?1:0),nxtidx=curidx-usedrembot-(delta==-2?1:0)+(delta>=+1?1:0);
			if(nxtidx<0||nxtidx>=nsuffoptused||nsuffoptused+(rembotopt?1:0)+(remtopopt?1:0)>nsuffopt) continue;
			ret=(ret+go(preflen+1,nsuffoptused,nxtidx))%MOD;
			//printf("\t(%d,%d,%d)->(%d,%d,%d) [%d,%d,%d]\n",preflen,suffoptused,curidx,preflen+1,nsuffoptused,nxtidx,usedrembot,usedremtop,delta);
		}
		//printf("%d %d %d = %d [%d,%d,%d]\n",preflen,suffoptused,curidx,ret,nsuffopt,rembotopt?1:0,remtopopt?1:0);
	}
	return ret;
}


void run() {
	scanf("%d",&nb); na=2*nb-1;
	REP(i,na) scanf("%d",&a[i]); sort(a,a+na); for(int at=0,to=at;at<na;at=to) { while(to<na&&a[to]==a[at]) ++to; FOR(i,at,to) a[i]=at==0?0:a[at-1]+1; }
	memset(mem,-1,sizeof(mem));
	int ret=go(1,1,0);
	printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 2304
import sys, random
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
    inf = 10 ** 20

#    t = int(input())
    # t, a, b = map(int, input().split())
    t = 1
    
    
    for _ in range(1, t+1):
        # print("Case #{}: ".format(_), end = '')
        
        a, b, c, k = map(int, input().split())
        ans = 0
        if(k):
            ans += min(k, a)
            k -= min(k, a)
        if(k):
            k -= min(k, b)
        if(k):
            ans -= k
        
        print(ans)
        
main()

Measured memory_bytes: 76952
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{

  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  ll w, h;
  cin >> w >> h;
  ll p[100010], q[100010];
  smaller_queue<pll> que;
  rep(i, w)
  {
    cin >> p[i];
    que.push(MP(p[i], 0));
  }
  rep(i, h)
  {
    cin >> q[i];
    que.push(MP(q[i], 1));
  }

  ll ans = 0;
  ll used_cnt[2] = {};
  while (!que.empty())
  {
    ll cost = que.top().first;
    int type = que.top().second;
    que.pop();
    if (type == 0)
    {
      ans += cost * (h + 1 - used_cnt[1]);
      //cerr << cost << " " << (w + 1 - used_cnt[1]) << endl;
      used_cnt[0]++;
    }
    else
    {
      ans += cost * (w + 1 - used_cnt[0]);
      //cerr << cost << " " << (h + 1 - used_cnt[0]) << endl;
      used_cnt[1]++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7408
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 400000;

ll ans(ll L, ll R) {
	if (L / 2019 != R / 2019) { return 0; }
	L %= 2019;
	R %= 2019;

	ll min = 2019;

	for (ll i = L; i < R; i++) {
		for (ll j = L + 1; j <= R; j++) {
			ll val = i * j % 2019;
			if (val < min) { min = val; }
		}
	}

	return min;
}


int main() {
	ll L, R;
	cin >> L >> R;

	cout << ans(L, R);

	system("PAUSE");

}

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

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

	vector dp(700,vector(tar+1,mint(0)));
	dp[0][0]=1;
	rep(i,699){
		dp[i+1][0]=dp[i][0];
		rep(j,tar) dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1];
	}

	mint ans=0;
	rep(k,tar/3+1){
		ans+=dp[k][tar-3*k];
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 8800
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	vi a(3*n);
	rep(i, 3*n) cin >> a[i];
	ll sum = 0LL;
	sort(all(a));
	for(int i = n; i < 3*n; i+=2) sum += a[i];
	cout << sum << endl;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;

	cin >> a >> b >> c;

	if (a < b) {
		if (b < c) cout << a << " " << b << " " << c << endl;
		else {
			if (a < c) cout << a << " " << c << " " << b << endl;
			else cout << c << " " << a << " " << b << endl;
		}
	} else {
		if (a < c) cout << b << " " << a << " " << c << endl;
		else {
			if (b < c) cout << b << " " << c << " " << a << endl;
			else cout << c << " " << b << " " << a << endl;
		}
	}
}

Measured memory_bytes: 1164
main :: IO ()
main = do
  s <- getLine
  putStrLn . show . solve $ s


solve :: String -> Int
solve = solve' . str2Bool

str2Bool :: String -> [Bool]
str2Bool s = map f s
  where
    f :: Char -> Bool
    f c
      | c == 'o'  = True
      | otherwise = False

solve' :: [Bool] -> Int
solve' [] = 700
solve' (x:xs) = (if x then 100 else 0) + solve' xs


Measured memory_bytes: 380
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))
#define all(v) v.begin(),v.end()

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}


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

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//***************************************************************************************************************************//

vector <int> g[N];
bool vis[N];
ll dp[N][2];
ll mod = 1e9 + 7;

void solve(int v)
{
    vis[v] = true;
    dp[v][1] = 1;
    dp[v][0] = 1;
    for(auto x : g[v])
    {
        if(!vis[x])
        {
            solve(x);
            dp[v][0] = (dp[v][0]*((dp[x][0] + dp[x][1])%mod))%mod;
            dp[v][1] = (dp[v][1]*((dp[x][0])%mod))%mod;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int n;
    cin >> n;
    mem(vis,false);
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    solve(1);
    //for(int i=1;i<=n;i++)
    //    cout << dp[i][0] << " " << dp[i][1] << "\n";
    cout << (dp[1][0] + dp[1][1])%mod;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  ll A, B; cin >> A >> B;
  if (A==B) { cout << 1 << endl; return 0;}
  ll diga = 0; while((1ull<<diga)<=A) diga++;
  ll digb = 0; while((1ull<<digb)<=B) digb++;
  if (diga==digb) {
    while((A&(1ull<<diga))==(B&(1ull<<digb))&&(digb>=0)) {
      A -= A&(1ull<<diga); B -= B&(1ull<<digb);
      diga--; digb--;
    }
  }
 
  while (!(B&(1ull<<digb))&&(digb>=0)) digb--;
  int maxdig = digb; B -= (1ull<<digb);
  while (!(B&(1ull<<digb))&&(digb>=0)) digb--;
  B = (1ull<<(digb+1))-1;
  // cout << diga << " " << digb << " " << maxdig << endl;
  // cout << A << " " << B << endl;

  ll result = 0;
  result += (1ull<<maxdig)-A;
  result += min((1ull<<maxdig), (1ull<<maxdig)-A+B+1);
  cout << result << endl;
  return 0;
}

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

using namespace std;

const int MAX = 1e5 + 5 ;
int arr[MAX] ;

int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0) ;
    int n , m ;
    cin>>n>>m ;
    for(int i = 0 ; i < m ; ++i)
    {
        int l , r ;
        cin>>l>>r ;
        arr[l]++ , arr[r+1]-- ;
    }
    int ans = 0 ;
    for(int i = 1 ; i <= n ; ++i)
    {
        arr[i] += arr[i-1] ;
        if(arr[i] == m)
            ans++ ;
    }
    return cout<<ans<<"\n" , 0 ;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

// template<class T> void chmin(T& a, T b) {
//     if (a > b) {
//         a = b;
//     }
// }

// template<class T> void chmax(T& a, T b) {
//     if (a < b) {
//         a = b;
//     }
// }

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

    vector<int> x(m);
    vector<int> diff(m-1);
    for(int im=0;im<m;im++) {
        cin >> x.at(im);
    }
    sort(x.begin(), x.end());

    for(int im=0;im<m-1;im++) {
        diff.at(im) = x.at(im+1) - x.at(im);
    }
    sort(diff.begin(), diff.end());

    int ans=0;
    for(int i=0;i<m-n;i++) {
        ans += diff.at(i);
    }

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


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;
const char sp = ' ';

ll N, M;
static ll A[100003], B[100003], su[100003];
static vector<ll> raw;
ll ans, ansnum;

bool can_clear(ll index){
    ans=0, ansnum=0;
    ll count=0;
    for(ll j=100001; j>=0; j--){
        if(index-j>100001) break;
        ll thiscount=A[j]*B[max(index-j, (ll)0)];
        count+=thiscount;
        ll thisansnum=thiscount-A[j]*A[max(index-j, (ll)0)];
        ansnum+=thisansnum;
        ans+=thisansnum*j;
        if(thisansnum==0) continue;
        ans+=su[N-thisansnum/A[j]]*A[j];
        
        /*if(index==113){
            cout<<thisansnum<<sp<<
            thiscount<<sp<<ansnum<<sp<<su[N-thisansnum]+thisansnum*j<<sp<<thisansnum<<endl;
        }*/
    }
    
    /*cout<<ansnum<<sp<<ans<<endl;
    cout<<index<<endl;
    cout<<endl;*/
    
    if(count>=M) return true;
    else return false;
}

//条件に合致する最大indexを二分探索 O(logN)
//-2...全indexがみたす -1...条件に合致するものがない
ll nibutan_max(ll min, ll max){
  //評価関数bool can_clear(ll　value) を指定すること
  ll left=min, right=max;
  ll ans;
  while(true){
      //cout<<left<<" " <<right<<endl; //debug用
      if(left+1==right){
        if(can_clear(right)){
          if(right==max) return -2;
          else return right;
        }
        else{
          if(can_clear(left)) return left;
          else return -1;
        }
        break;
      }
      ll nibutan=(left+right)/2;
      bool can_do_it=can_clear(nibutan);
      if(can_do_it) left = nibutan;
      else right = nibutan;
  }
}


int main(void){
    cin>>N>>M;
    ll val;
    MEMSET(A, 0);
    MEMSET(B, 0);
    MEMSET(su, 0);
    rep(i, N) cin>>val, A[val]++, raw.push_back(val);
    sort(all(raw));
    for(ll i=N-1; i>=0; i--) su[i]=su[i+1]+raw[i];
    for(ll i=100001; i>=0; i--) B[i]=B[i+1]+A[i];
    ll minim=nibutan_max(1, 200002);
    //cout<<minim<<endl;
    ans+=minim*(M-ansnum);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3704
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
s = []
for i in range(1,N+1):
    for j in range(a[i-1]):
        s.append(i)
##print(s)
num = 0
for i in range(H):
    tmp = []
    for j in range(W):
        tmp.append(s[num])
        num += 1
    
    if i%2 == 1:
        tmp.reverse()
    print(*tmp)


Measured memory_bytes: 3916
n = int(input())
a, b = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

# print(n)
# print(a, b)
# print(sorted(p))

q_a = 0
q_b = 0
q_c = 0

for i in p:
    if i <= a:
        q_a += 1
    elif a < i <= b:
        q_b += 1
    else:
        q_c += 1

print(min([q_a, q_b, q_c]))


Measured memory_bytes: 3060
from itertools import combinations
n,x,y = map(int,input().split())
cnt = [0]*n
for i,j in combinations(range(1,n+1),r=2):
    k = min(j-i,abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))
    cnt[k]+=1
for i in range(1,n):
    print(cnt[i])    

Measured memory_bytes: 48220
h, w, k = map(int, input().split())
# 横に分けてから縦に切る
s = [list(input()) for _ in range(h)]
ans = 1
a = [[0]*w for _ in range(h)]
a_0 = [0]*w  # 行にイチゴがないときよう
for i in range(h):
    s_count = s[i].count("#")
    if s_count == 1:
        for j in range(w):
            a[i][j] = ans
            a_0[j] = ans
    elif s_count != 0:
        count = 0  # これは#の今現在数えた数
        for j in range(w):
            a[i][j] = ans
            a_0[j] = ans
            if s[i][j] == "#" and j+1 != w and s_count != count + 1:  # 最後のイチゴと端のイチゴの条件
                ans += 1
                count += 1
    else:
        for j in range(w):
            a[i][j] = a_0[j]

        ans -= 1
    ans += 1
for i in range(h):
    if max(a[i]) == 0:
        for j in range(h):
            if max(a[j]) != 0:
                a[i] = a[j]
                break

for i in a:
    print(*i)


Measured memory_bytes: 78836
ans=[0,0,0,0]

n=int(input())

for i in range(n):
    x=input()
    if x=="AC":
        ans[0]+=1
    elif x=="WA":
        ans[1]+=1
    elif x=="TLE":
        ans[2]+=1
    elif x=="RE":
        ans[3]+=1
        
print("AC x ",end="")
print(ans[0])
print("WA x ",end="")
print(ans[1])
print("TLE x ",end="")
print(ans[2])
print("RE x ",end="")
print(ans[3])

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


void findNumberOfDigits(long n, int base) 
{  
	int dig = (int)(floor( log(n) / 
						log(base)) + 1); 
	
	// printing output 
	cout <<dig; 
} 

// Driver method 
int main() 
{ 
	// taking inputs 
	long n;
	int base;
  cin>>n>>base;
	
	// calling the method 
	findNumberOfDigits(n, base); 
	return 0; 
} 

// This code is contributed by Manish Shaw 
// (manishshaw1) 


Measured memory_bytes: 640
# 各桁の数値の総和を計算する.
def calc_digit_sum(num):
    sums = 0
    while num > 0:
        sums += num % 10
        num //= 10
    return sums


s = input()
contains = set(["A", "C", "G", "T"])

answer = cnt = 0
for ch in s:
    if ch not in contains:
        cnt = 0
    else:
        cnt += 1
    answer = max(answer, cnt)

print(answer)

Measured memory_bytes: 61852
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
    int a,i=1,sum=0;
    cin >> a;
    
    while(a>=i){
        sum+=a%(10*i)/i;
        i=i*10;
    }
    if(a%sum==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vp=vector<pair<ll,ll>>;
int main() {
    int N;cin>>N;
    ll D,A;cin>>D>>A;
    vp enemy(N);
    for (int i = 0; i < N; i++){
        int X,H;cin>>X>>H;
        enemy[i].first=X;
        enemy[i].second=H;
    }
    sort(enemy.begin(),enemy.end());
    vector<ll> bomb_num(N,0);
    ll damage=0;
    ll ans=0;
    for (int i = 0; i < N; i++){
        ll X=enemy[i].first;
        ll H=enemy[i].second;
        damage-=A*bomb_num[i];
        H-=damage;
        H=max(H,(ll)0);
        ll n=(H+A-1)/A;
        ans+=n;
        damage+=n*A;
        auto iter=upper_bound(enemy.begin(),enemy.end(),pair<ll,ll>(X+2*D+1,0));
        int idx=distance(enemy.begin(),iter);
        if(idx!=N)bomb_num[idx]+=n;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7940
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    n = int(input())
    to = [[] for _ in range(n)]
    cost = [[] for _ in range(n)]

    for i in range(n - 1):
        ui, vi, wi = map(int, input().split())
        ui -= 1
        vi -= 1
        to[ui].append(vi)
        to[vi].append(ui)
        cost[ui].append(wi)
        cost[vi].append(wi)

    ans = [-1 for _ in range(n)]
    q = deque()
    ans[0] = 0
    q.append(0)

    while q:
        vj = q.popleft()

        for j in range(len(to[vj])):
            uj = to[vj][j]
            wj = cost[vj][j]

            if ans[uj] != -1:
                continue

            ans[uj] = (ans[vj] + wj) % 2
            q.append(uj)

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 80288
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int i,n,j,S=0;
        double avr,O=0,s;
        for(i=0; ;i++){
            n=sc.nextInt();
            int array[]=new int[n];
            if(n==0){
                break;
            }else{
                for(j=1;j<=n;j++){
                    array[j-1]=sc.nextInt();
                    S+=array[j-1];
                }
                avr=S/(double)n;
                for(j=1;j<=n;j++){
                    O+=(avr-array[j-1])*(avr-array[j-1]);                    
                }
                s=Math.sqrt(O/n);
                System.out.println(s);
            }
            S=0;
            O=0;
        }
    }
} 


Measured memory_bytes: 31436
#include<bits/stdc++.h>
using namespace std;
int a[100000005];
int main(){
    int n;
    long long ans=0;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]%=10;
        ans+=a[i];
        ans%=10;
    }
    if (ans%2==0) cout<<"YES";
    else cout<<"NO";
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

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

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,cmp,data,m,h,w,x,y,xcmp,ycmp,sum=0;

string s;

vector<int> z;

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

       cin >> a >> b >> c;
       Yes(a+b==c || a+c==b || b+c==a);
return 0;
}


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

int main(){
	ll n,d;
	cin>>n>>d;
	ll x,y,count=0;
	ll val;

	for(int i=0;i<n;i++){
		cin>>x>>y;
		val=ceil((sqrt(x*x+y*y)));
		if(d>=val) count++;
	}
	cout<<count<<endl;

	return 0;
}

Measured memory_bytes: 3744