akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll N,M;
int main() {
    cin>>N>>M;


    ll ans = 0;
    if(2*N > M) ans = M / 2;
    else{
      ans = N;
      M -= 2*N;
      ans += M / 4;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

using ll = long long;

//各種nil
template <class T>
constexpr T nil = static_cast<T>(-1);

constexpr int nil_i = nil<int>;
constexpr int nil_ll = nil<ll>;
constexpr double nil_d = nil<double>;

//vector
template <class T>
using vec = std::vector<T>;

struct Vec2D
{
    int x, y;
};

struct TimePos
{
    int time;
    Vec2D pos;
};

int ManhattanDistance(Vec2D v1, Vec2D v2)
{
    using namespace std;
    return abs(v1.x - v2.x) + abs(v1.y - v2.y);
}

void solve()
{
    using namespace std;
    int r, g, b;
    cin >> r >> g >> b;
    
    if ((r * 100 + g * 10 + b) % 4 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;


}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod = 1e9 + 7;

long long bigMod(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1) {
            res = (res * a) % mod;
        }
        b >>= 1;
        a = (a * a) % mod;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);    
    long long n;
    cin >> n;
    long long a = bigMod(10, n);
    long long b = (bigMod(9, n) * 2) % mod;
    long long c = bigMod(8, n);
    if (b - c < 0) {
        b += mod;
    }
    if (a - b + c < 0) {
        a += mod;
    }
    cout << (a - b + c) % mod << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x, y, b, a;
   cin>> x >> y;
   b = (y/2)-x;
   a = (2*x)-(y/2);
   if(b>=0 && a>=0 && y%2==0){
    printf("Yes\n");
   }
   else{
    printf("No\n");
   }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
void setIO(string name) {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const int MAX=2005;
int a[MAX];
int32_t main()
{
  BOOST;
  int n,x,y;
  cin>>n>>x>>y;
  for (int i=1;i<=n;i++)cin>>a[i];
  int ans=0;
  ans=max(ans,abs(a[n]-y));
  if (n>=2)ans=max(ans,abs(a[n-1]-a[n]));
  cout<<ans;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    bool ok=false;
    vector<vector<int>> c(3,vector<int>(3));
    int a1,a2,a3,b1,b2,b3;
    rep(i,3){
        rep(j,3){
            cin >> c[i][j];
        }
    }
    a1 = 0; 
    b1 = c[0][0];
    b2 = c[0][1];
    b3 = c[0][2];
    a2 = c[1][0] - b1;
    a3 = c[2][0] - b1;
    
    if(a2+ b2 == c[1][1] && a2+b3 == c[1][2]  && a3+b2 == c[2][1] && a3+b3 == c[2][2]) ok = true;
    
    if(ok) cout << "Yes" <<endl;
    else cout << "No" << endl;
} 

Measured memory_bytes: 256
from itertools import permutations
import math
n=int(input())
xy=[list((map(int,input().split()))) for j in range(n)]

sum=0
for i in permutations(xy,2):
  sum+=math.sqrt((abs(i[0][0] - i[1][0]))**2 + (abs(i[0][1] - i[1][1]))**2 )
print(sum/n)


Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <list>
#include <math.h>
#include <map>
using namespace std;
#define REP(i, k, n) for(int i = k;i < n; i++)
#define rep(i, n) REP(i,0,n)
#define ll long long int
int dx[4] = {0,-1,1,0};
int dy[4] = {-1,0,0,1};
#define eps 10e-6
int cnt[51][26];
int main(void){
	int n;
	cin >> n;

	rep(i,n){
		string s;
		cin >> s;
		rep(j,s.size()){
			cnt[i][s[j]-'a']++;
		}
	}
	int ans = 0;
	rep(i,26){
		int mini = 10000000;
		rep(j,n){
			mini = min(mini, cnt[j][i]);
		}
		char c = 'a';
		rep(j,mini){
			printf("%c",c+i);
		}
	}
	cout << endl;
}


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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
    int a,b,k;
    cin>>a>>b>>k;
    if(b-a+1>2*k){
        REP(i,k){
            cout<<a+i<<endl;
        }
        REP(i,k){
            cout<<b-k+i+1<<endl;
        }
    }else{
        REP(i,b-a+1){
            cout<<a+i<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main(void){
  int heaps[250]={0};
  int heap_size=0;
  scanf("%d",&heap_size);
  int i=0;
  for(i=0;i<heap_size;i++){
    scanf("%d",&(heaps[i]));
  }

  for(i=0;i<heap_size;i++){
    printf("node\x0020%d:\x0020",i+1);
    printf("key\x0020=\x0020%d,\x0020",heaps[i]);
    if(i!=0){
      printf("parent\x0020key\x0020=\x0020%d,\x0020",heaps[(i+1)/2-1]);
    }
    if(2*(i+1)<=heap_size){
      printf("left\x0020key\x0020=\x0020%d,\x0020",heaps[(i+1)*2-1]);
      if(2*(i+1)+1<=heap_size){
	printf("right\x0020key\x0020=\x0020%d,\x0020",heaps[(i+1)*2]);
      }
    }
    printf("\n");
  }
  return 0;
}

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

int main(){
  ll n,a,b;
  cin >> n;
  for(ll i = sqrt(n); i>=1;i--){
    if(n/i*i==n){
      a=i; b=n/i;
      break;
    }
  }
  cout << a+b-2<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  int l = s.size();
  if(l<=k)
    cout << s << endl;
  else{
    for(int i=0; i<k; i++)
      cout << s[i];
    cout << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SQR(x) (x) * (x)
#define itn int

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> A_(N);
  REP(i, N) {
    cin >> A[i];
    A_[i] = A[i];
  }
  sort(ALL(A_));
  double ans = 0;
  REP(i, N) {
    auto iter = lower_bound(ALL(A_), A[i]);
    int ind   = distance(A_.begin(), iter);
    if ((i - ind) % 2)
      ans += 0.5;
  }
  cout << (int)ans << endl;
}


Measured memory_bytes: 1920
n,k = gets.chomp.split.map(&:to_i)
array = Array.new
hash = Hash.new
n.times do |i|
  a,b = gets.split.map(&:to_i)
  array << a
  #puts "a=#{a} b=#{b}"
  hash[a] = hash[a].to_i + b
end

array.sort!
array.uniq!
cnt = 0
array.size.times do |j|
  cnt += hash[array[j]]
  if cnt >= k then
    puts array[j]
   # p array
    #puts "hash #{hash[100000]}"
    exit
  end
end

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
//

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    cout<<n*n*n<<"\n";
  return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

vector<long double> r;
vector<int> w;

int main(int argc, char* argv[]) {
  int N, W;
  cin >> N >> W;

  int v[N];
  w.resize(N);
  for (int i = 0; i < N; ++i)
    cin >> v[i] >> w[i];

  long long dp[N + 1][W + 1];
  memset(dp, 0, sizeof(int) * (N + 1) * (W + 1));

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= W; ++j) {
      if (w[i] > j)
        dp[i + 1][j] = dp[i][j];
      else {
        dp[i + 1][j] = max(max(v[i] + dp[i][j - w[i]], dp[i][j]), dp[i + 1][j - w[i]] + v[i]);
      }
    }
  }

  cout << dp[N][W] << endl;

  return 0;
}


Measured memory_bytes: 10980
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		Long[] a = new Long[N];

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);

		long ans = 0;

		for (int i = 0; i < N - K; i++) {
			ans += a[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 55852
#include <bits/stdc++.h>
using namespace std;
typedef long long lol;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    //lol n; cin >> n;
    //int k; cin >> k;
    int n{0};
    
    string ch;
    cin >> ch;
    REP(i, 15)
    {
        if(ch[i] == 'x')
            n++;
    }
    if(n > 7)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    
    
    

    //cout << result << endl;
    return 0;
}

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

using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,cnt[200000],tot;
int main()
{
	n=read(); for(int i=1;i<=n;i++)
	{
		int k=read(); if(cnt[k]) tot++;
		else cnt[k]=1;
	}
	if(tot&1) cout << n-tot-1 << endl;
	else cout << n-tot << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>

using namespace std;

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

typedef long long ll;

int main() {
  int N;
  cin >> N;
  int A[N];
  rep(i,N) cin >> A[i];
  
  map<int, ll> B, C;
  rep(i,N) {
    B[i+1 + A[i]]++;
    C[i+1 - A[i]]++;
  }
  
  ll r = 0;
  for(auto [x,y]: B) {
    r += y * C[x];
  }
  
  cout << r << endl;
  return 0;
}

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


int main() {
  int N, M, X;
  cin >> N >> M >> X;

  int C[N];
  int A[N][M];
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int minCost = -1;
  // Loop for all the 2^N patterns
  for (int bit = 0; bit < (1<<N); ++bit) {
    int cost = 0;
    int levels[M];
    for (int j = 0; j < M; j++) levels[j] = 0;

    for (int i = 0; i < N; i++) {
      if (bit & (1<<i)) {  // when i'th bit is 1 -> buy i'th book
        cost += C[i];
        for (int j = 0; j < M; j++) levels[j] += A[i][j];
      }
    }

    bool accomplished = true;
    for (int j = 0; j < M; j++) {
      if (levels[j] < X) accomplished = false;
    }

    if (accomplished && (cost < minCost || minCost == -1)) minCost = cost;
  }

  cout << minCost << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
 
int main() {
    string str;
    getline(cin, str);
 
    for (string::iterator it = str.begin(); it != str.end(); ++it) {
        if (0x41 <= *it && *it <= 0x5a) {
            cout << char(*it + 0x20);
            continue;
        }
        if (0x61 <= *it && *it <= 0x7a) {
            cout << char(*it - 0x20);
            continue;
        }
        cout << *it;
    }
    cout << endl;
 
    return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2147483647;
using namespace std;

const int sqrtN = 512;

class sqdiv{
    public:
        int N, K;
        vector<int> data;
        vector<bool> lazy_flag;
        vector<int> lazy_update;
        sqdiv(int n){ //?????±???????????????????????´
            N = n;
            K = (N + sqrtN - 1) / sqrtN;
            data.assign(K * sqrtN, INF);
            lazy_flag.assign(K, false);
            lazy_update.assign(K, 0);
        }
        void eval(int k){
            if(lazy_flag[k]){
                lazy_flag[k] = false;
                for(int i = k * sqrtN; i < (k + 1) * sqrtN; i++){
                    data[i] = lazy_update[k];
                }
            }
        }
        void update(int x, int y, int a){
            rep(k,K){
                int l = k * sqrtN, r = (k + 1) * sqrtN;
                if(r <= x || y <= l) continue;
                if(x <= l && r <= y){
                    lazy_flag[k] = true;
                    lazy_update[k] = a;
                }else{
                    eval(k);
                    for(int i = max(x, l); i < min(y, r); i++){
                        data[i] = a;
                    }
                }
            }
        }
        int find(int a){
            int k = a / sqrtN;
            eval(k);
            return data[a];
        }
};

int main(){
    int n,q;
    cin >> n >> q;
    sqdiv ob(n);
    rep(i,q){
        bool com;
        int a, b, c;
        cin >> com;
        if(com){
            cin >> a;
            cout << ob.find(a) << endl;
        }else{
            cin >> a >> b >> c;
            ob.update(a,b + 1,c);
        }
    }
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double N, A, S; 
  cin >> N;
  A = 0;
  for(int i = 1;i <= N;i++){
  if(i % 2 == 1) A++;
  }
  S = A / N;
  cout << std::fixed << std::setprecision(10) << S << endl;  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;


int main()
{
	int n, k, x, y;
	scanf("%d%d%d%d", &n, &k, &x, &y);
	printf("%d\n", x*min(n, k)+max(n-k, 0)*y);
	return 0;
}

Measured memory_bytes: 256
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc125_a.cpp
 * time   : Fri May  1 16:41:40 2020
 * quest  : A - Biscuit Generator
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, t;
  cin >> a >> b >> t;
  cout << (t / a * b) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//コピペするとこ



//-------------------------------------------------


int main()
{
  int x ;
  cin >> x ;
  for(int i=1;i<=1000;i++){
    if(100*i<=x && x<=105*i){
      cout << 1 <<endl ;
      return 0 ;
    }
  }
  
  cout << 0 <<endl ;
  return 0 ;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int p[100][100];
int main(){
	int n,m[100];
	int k,l[100];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++){
		cin>>m[i];
		for(int j=0;j<m[i];j++){
			cin>>p[i][j];
		}
	}
	cin>>k;
	for(int i=0;i<k;i++)
		cin>>l[i];
	int count=0,set;
	for(int i=0;i<n;i++){
		bool t=true;
		for(int j=0;j<k;j++){
			bool f=false;
			for(int o=0;o<m[i];o++){
				if(l[j]==p[i][o])
					f=true;
			}
			if(f==false)
				t=false;
		}
		if(t==true){
			if(count==0){
				set=i;
			}
			count++;
		}
	}
	if(count==1)
		cout<<set+1<<endl;
	else
		cout<<"-1"<<endl;
	}
	return 0;
}

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

int main(){
    int x, y;
    while (1){
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x > y) {cout << y << " "<< x << endl;}
        else {
            cout << x << " " << y << endl;
        }
    }
    return 0;
}


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

int main() {
	long mod = 1e9+7;
	long n, k;
	cin>>n>>k;
	if(n<=k+1){
		long ue = 1, shita = 1;
		for(long i=1;i<=2*n-1;++i){
			ue *= i;
			ue %= mod;
		}
		for(long i=1;i<=n;++i){
			shita *= i;
			shita %= mod;
		}
		for(long i=1;i<=n-1;++i){
			shita *= i;
			shita %= mod;
		}
		long tmp = mod - 2;
		long shita1 = 1;
		long shita2;
		while(tmp > 0){
			shita2 = shita;
			long two = 1;
			while(true){
				two *= 2;
				if(two > tmp){
					two /= 2;
					tmp -= two;
					shita1 *= shita2;
					shita1 %= mod;
					break;
				}
				shita2 *= shita2 % mod;
				shita2 %= mod;
			}
		}
		cout<<ue*shita1%mod<<endl;
	}
	else{
		long DPue[n+1], DPshita[n+1];
		DPue[0] = 1;
		DPshita[0] = 1;
		for(long i=1;i<=n;++i){
			DPue[i] = DPue[i-1] * i;
			DPue[i] %= mod;
			DPshita[i] = DPue[i];
		}
		/**
		for(int i=0;i<=n;++i){
			cout<<i<<" "<<DP[i]<<endl;
		}
		**/
		long tmp;
		long shita1, shita2;
		for(long i=0;i<=n;++i){
			tmp = mod - 2;
			shita1 = 1;
			while(tmp > 0){
				shita2 = DPshita[i];
				long two = 1;
				while(true){
					two *= 2;
					if(two > tmp){
						two /= 2;
						tmp -= two;
						shita1 *= shita2;
						shita1 %= mod;
						break;
					}
					shita2 *= shita2 % mod;
					shita2 %= mod;
				}
			}
			DPshita[i] = shita1 % mod;
		}
		long ans = 0;
		long tmpans;
		for(int i=0;i<=k;++i){
			tmpans = 1;
			tmpans *= (DPue[n]*DPshita[i]%mod)*DPshita[n-i]%mod;
			tmpans %= mod;
			tmpans *= (DPue[n-1]*DPshita[i]%mod)*DPshita[n-1-i]%mod;
			ans += tmpans%mod;
			ans %= mod;
		}
		while(ans<0){
			ans += mod;
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int a;
bool y,m;
int main()
{
	cin>>a;
	if(a%100<=12&&a%100>=1) y=1;
	if(a/100<=12&&a/100>=1) m=1;
	if(y==1&&m==1)
	{
		cout<<"AMBIGUOUS";
		return 0;
	}
	if(y==1) cout<<"YYMM";
	else if(m==1) cout<<"MMYY";
	else cout<<"NA";
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        if 1 <= a + i <= H - 2:
            for j in tmplst:
                if 1 <= b + j <= W - 2:
                    lst_append((a + i, b + j))

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Measured memory_bytes: 127988
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef vector<int> Array;
typedef vector<Array> Matrix;

void PrintMatrix(const Matrix &lhs) {
  const int n = lhs.size();
  REP(y, n) {
    REP(x, n) {
      printf("%d ", lhs[y][x]);
    }
    puts("");
  }
}


Matrix mul(const Matrix &lhs, const Matrix &rhs) {
  const int n = lhs.size();
  Matrix ret(n, Array(n, 0));
  REP(i, n) REP(k, n) REP(j, n) {
    ret[i][k] = max(ret[i][k], lhs[i][j] * rhs[j][k]);
  }
  return ret;
}

Matrix powmat(Matrix base, ll power) {
  const int n = base.size();
  Matrix ret(n, Array(n, 0));
  REP(i, n) { ret[i][i] = 1; }
  while (power > 0) {
    if (power & 1) { ret = mul(ret, base); }
    base = mul(base, base);
    power >>= 1;
  }
  return ret;
}

int n, m, z;
inline int LEFT(int x) { return x; }
inline int RIGHT(int x) { return x + m; }
inline int SOURCE() { return m + m; }
inline int DEST() { return m + m + 1; }
inline int SIZE() { return m + m + 2; }
int f[100];
int t[100];
int main() {
  while (scanf("%d %d %d", &n, &m, &z), n|m|z) {
    Matrix mat(m * 2 + 2, Array(m * 2 + 2, 0));
    REP(i, m) {
      scanf("%d %d", &f[i], &t[i]);
      if (f[i] > t[i]) { swap(f[i], t[i]); }
      f[i]--; t[i]--;
    }
    REP(i, m) {
      if (f[i] == 0) {
        mat[SOURCE()][RIGHT(i)] = 1;
      }
      if (f[i] == 0 && t[i] == n - 1) {
        mat[SOURCE()][DEST()] = 1;
      }
      REP(j, m) {
        if (i == j) { continue; }
        if (f[i] == f[j] && t[i] == t[j]) { continue; }
        if (f[i] == f[j]) {
          mat[LEFT(i)][RIGHT(j)] = 1;
          if (t[j] == n - 1) {
            mat[LEFT(i)][DEST()] = 1;
          }
        }
        if (f[i] == t[j]) {
          mat[LEFT(i)][LEFT(j)] = 1;
        }
        if (t[i] == f[j]) {
          mat[RIGHT(i)][RIGHT(j)] = 1;
          if (t[j] == n - 1) {
            mat[RIGHT(i)][DEST()] = 1;
          }
        }
        if (t[i] == t[j]) {
          mat[RIGHT(i)][LEFT(j)] = 1;
        }
      }
    }
    Matrix ans = powmat(mat, z);
    //PrintMatrix(mat);
    //puts("");
    //PrintMatrix(ans);
    if (ans[SOURCE()][DEST()]) {
      puts("yes");
    } else {
      puts("no");
    }
  }
}

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

int main(void)
{
	char rome[128];
	int arabia;
	int i, p;
	
	while (scanf("%s", rome) != EOF){
		p = strlen(rome) - 1;
		arabia = 0;
		i = 0;
		while (p >= 0){
			switch (rome[p]){
			case 'I':
				if (i == 0){
					arabia += 1;
				}
				else {
					arabia -= 1;
				}
				break;
			
			case 'V':
				if (i <= 1){
					arabia += 5;
					i = 1;
				}
				else {
					arabia -= 5;
				}
				break;
				
			case 'X':
				if (i <= 2){
					arabia += 10;
					i = 2;
				}
				else {
					arabia -= 10;
				}
				break;
				
			case 'L':
				if (i <= 3){
					arabia += 50;
					i = 3;
				}
				else {
					arabia -= 50;
				}
				break;
				
			case 'C':
				if (i <= 4){
					arabia += 100;
					i = 4;
				}
				else {
					arabia -= 100;
				}
				break;
				
			case 'D':
				if (i <= 5){
					arabia += 500;
					i = 6;
				}
				else {
					arabia -= 500;
				}
				break;
				
			case 'M':
				arabia += 1000;
				i = 7;
				break;
			}
			
			p--;
		}
		
		printf("%d\n", arabia);
		
	}
	
	return (0);
}

Measured memory_bytes: 536
#include <stdio.h>
int main(void){
    
   int i,a,num;
   int x=0;
   
   scanf("%d",&a);
   
   num=a;
   while(num!=0){
    num = num / 10;
    x++;
   }
   
   for(i=1;i<=a;i++){
   if(i%3==0 || i%10==3 || i/10==3)
    printf(" %d",i);
   else if(i%100/10==3 || i/100==3)
    printf(" %d",i);
    else if(i/1000==3 || i%1000/100==3 || i%1000%100/10==3)
    printf(" %d",i);
   }
   printf("\n");
   return 0;

   }



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

using namespace std;

int N, M, K;
int Parent[100001], Rank[100001];
int ClubNumber[100001];

int findRoot(int num) {
	if (Parent[num] == num) {
		return num;
	}
	return (Parent[num] = findRoot(Parent[num]));
}

bool Disjoint(int a, int b) {
	int rootA, rootB, clubA, clubB;

	rootA = findRoot(a);
	rootB = findRoot(b);
	clubA = ClubNumber[rootA];
	clubB = ClubNumber[rootB];
	if (clubA == 0 && clubB != 0) {
		ClubNumber[rootA] = clubB;
	}
	else if(clubA != 0 && clubB == 0) {
		ClubNumber[rootB] = clubA;
	}
	else if (clubA != 0 && clubB != 0) {
		if (clubA != clubB) {
			return false;
		}
	}
	if (rootA == rootB) {
		return true;
	}

	if (Rank[rootA] > Rank[rootB]) {
		Parent[rootB] = rootA;
	}else {
		Parent[rootA] = rootB;
		if (Rank[rootA] == Rank[rootB]) {
			++Rank[rootA];
		}
	}
	return true;
}

bool judge(int c, int x) {
	int curRoot;

	curRoot = findRoot(c);
	if (ClubNumber[curRoot] == 0) {
		ClubNumber[curRoot] = x;
		return false;
	}
	if (ClubNumber[curRoot] == x) {
		return false;
	}
	return true;
}

int main() {
	int type, num1, num2;

	memset(Rank, 0, sizeof(Rank));
	memset(ClubNumber, 0, sizeof(ClubNumber));
	cin >> N >> M >> K;
	for (int i = 1; i <= N; ++i) {
		Parent[i] = i;
	}
	for (int i = 0; i < K; ++i) {
		cin >> type >> num1 >> num2;
		if (type == 1) {
			if (!Disjoint(num1, num2)) {
				cout << i + 1 << endl;
				return 0;
			}
		}
		else if (type == 2) {
			if (judge(num1,num2)) {
				cout << i+1 << endl;
				return 0;
			}
		}
	}
	cout << "0" << endl;

	return 0;
}



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

int main() {
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<s.size(); i++){
    if((int)s.at(i) + n > 90){
      cout << (char)((((int)s.at(i) + n)-90)+64);
    }
    else{
      cout << (char)((int)s.at(i) + n);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
string S;
  cin>>N>>S;
  for(int i=0;i<S.size();i++){
  S.at(i)=(S.at(i)-'A'+N)%26 +'A';
  }
  cout<<S<<endl;
}

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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

ll N, K;

int main(void)
{
    cin >> N >> K;
    vecll A(N);
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }

    ll diff_cnt = 0;
    ll i = A[0];
    vecll LA;
    LA.push_back(0);
    set<ll> found;
    found.insert(0);
    while (true) {
        LA.push_back(i);
        diff_cnt++;
        if (found.find(i) != found.end()) {
            break;
        }
        else {
            found.insert(i);
        }

        i = A[i];
    };

    // ループ開始地点のindex
    int dist = distance(LA.begin(), find(ALLOF(LA), i));
    int loop_cnt = diff_cnt - dist;

    if (K < dist) {
        cout << LA[K] + 1 << endl;
        return 0;
    }

    ll k = (K - dist);
    k %= loop_cnt;

    cout << LA[dist + k] + 1 << endl;


    return 0;
}

Measured memory_bytes: 15376
#include <iostream>
#include <vector>

using namespace std;
int n;
vector <int> h(100000);
vector <int> cost(100000);

int ans(int n)
{
    if (cost.at(n) != -1)
        return cost.at(n);
    cost.at(n) = min(ans(n-1) + abs(h.at(n) - h.at(n-1)),
                     ans(n-2) + abs(h.at(n) - h.at(n-2)));
    return cost.at(n);
}

int main()
{
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> h.at(i);
        cost.at(i) = -1;
    }
    cost.at(0) = 0;
    cost.at(1) = abs(h.at(1) - h.at(0));
    cout << ans(n-1) << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
using namespace std;
ll a,b,c,d,n,ans;
int main(){
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&n);a*=8;b*=4;c*=2;
	if (a<b&&a<c&&a<d) return cout<<n*a/2,0;
	if (b<a&&b<c&&b<d) return cout<<n*b/2,0;
	if (c<a&&c<b&&c<d) return cout<<n*c/2,0;
	ans=n/2*d;
	if (n&1) ans+=min(min(a/2,b/2),c/2);
	cout<<ans;
	return 0;
}

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

int main() {
        int H, W;
        vector<string> M;
        cin >> H >> W;
        vector<bool> is_del(W, true);
        for(int i = 0; i < H; i++) {
                string str;
                cin >> str;
                for(int j = 0; j < W; j++) if(str[j] == '#') is_del[j] = false;
                for(int j = 0; j < str.size(); j++) if(str[j] == '#') {
                        M.push_back(str);
                        break;
                }
        }

        for(int i = 0; i < M.size(); i++) {
                for(int j = 0; j < W; j++) if(is_del[j] == false) cout << M[i][j];
                cout << endl;
        }
        return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

cnt_list =[0]*9

cnt_sum=0
num_min=0
num_max=0


for i in a:
    j=int(i/400)
    if j<8:cnt_list[j]=1
    else:cnt_list[8]+=1

      
cnt_sum = sum(cnt_list)-cnt_list[8]
if cnt_list[8]>0:
    if cnt_sum==0:
        num_min=1
    else:num_min=cnt_sum
    num_max=cnt_sum+cnt_list[8]
else:
    num_min=cnt_sum
    num_max=cnt_sum

print(num_min, num_max)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();
        long res = 0;
        for (int i = 1; i <= n; i++)
        {
            res += (n / i) * Math.Max(i - k, 0) + Math.Max(n - n / i * i - k + 1, 0) - (0 % i >= k ? 1 : 0);
        }
        Console.WriteLine(res);
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
using namespace std;

typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second


int main(){
  int n,x;cin>>n>>x;
  std::vector<ll> a(n);

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

  sort(all(a));
  ll ans=0;
  rep(i,n){
    x-=a[i];
    if(x>=0){
      ans++;
    }else{
      break;
    }
  }

  if(x>0){
    ans--;
  }
  cout<<max(ans,0ll)<<endl;

}
















Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
using ll = long long;

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

    int D,N;
    cin >> D >> N;

    if (N == 100) N++;

    for (int i = 0; i < D; i++) {
        N *= 100;
    }
    cout << N << endl;
    return 0;
}

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

int main(void) {
  string a, b ,c ;
  cin >> a >> b >> c;
  
  transform(a.begin(), a.end(), a.begin(), ::toupper);
  transform(b.begin(), b.end(), b.begin(), ::toupper);
  transform(c.begin(), c.end(), c.begin(), ::toupper);
  
  string ans;
  cout << a.at(0) <<  b.at(0) << c.at(0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
#define hash hush
typedef long long ll;
typedef long double ld;
int n, a[8];
signed  main() {
	int n;
	string s;
	int a = 0, b = 0, c = 0, d = 0;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == '(')
			a++;
		else
			b++;
		if (s[i] == ')'&&a==b-1) {
			c++;
			a++;
		}
	}
	if (b < a)
		d += (a - b);
	for (int i = 0; i < c; i++)
		s = '(' + s;
	for (int i = 0; i < d; i++)
		s = s + ')';
	cout << s << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c,d,e,k;
  scanf("%d%d%d%d%d%d",&a, &b, &c, &d, &e, &k);
  if( (e-a > k) || (e-b > k) || (e-c > k) || (e-d > k) ){ printf(":(\n");   }
  else													{ printf("Yay!\n"); }
  return 0;
}

Measured memory_bytes: 1648
#include <stdio.h>


int main(int argc, char *argv[]){

  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  if(a == 7 && b == 5 && c == 5){
    printf("YES\n");
  }else if(a == 5 && b == 7 && c == 5){
    printf("YES\n");
  }else if(a == 5 && b == 5 && c == 7){
    printf("YES\n");
  }else{
    printf("NO\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    cout << (n < 1000 ? "ABC" : "ABD") << endl;
    return 0;
}


Measured memory_bytes: 256
#!python3

def LI():
    return list(map(int, input().split()))

# input
N = int(input())
A = LI()


def main():
    d = {}
    for a in A:
        d[a] = d[a] + 1 if a in d else 1
    
    l = []
    for k, v in d.items():
        if v >= 2:
            l.append(k)
    
    l.sort(reverse=True)
    if len(l) < 2:
        ans = 0
    elif d[l[0]] >= 4:
        ans = l[0] ** 2
    else:
        ans = l[0] * l[1]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 17960
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : usize = 1000000007;

#[fastout]
fn main() {
  input! {
    a : usize,
  };

  println!("{}", a + a * a + a * a * a);
}


Measured memory_bytes: 2180
#C - Average Length
import math
import itertools
N = int(input())
town = []
for i in range(N):
    x,y = map(int,input().split())
    town.append((x,y))

def dist(A,B):
    return math.sqrt((A[0]-B[0])**2 + (A[1]-B[1])**2)
route = list(itertools.permutations(town))
tot = 0
for i in route:
    for j in range(len(i)-1):
        tot += dist(i[j],i[j+1])
ave = tot/len(route)
print(ave)

Measured memory_bytes: 13884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;
	string ans = "No";
	sort(all(S));
	if(S[0] == S[1]&&S[1]!=S[2]&&S[2] == S[3])
	{
		ans = "Yes";
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double x = sc.nextDouble();
        double S = x/a;
        double h = (a*b-S)*2/a;
        double w = S*2/b;

        if(S>=a*b/2) System.out.println(Math.toDegrees(Math.atan(h/a)));
        else System.out.println(Math.toDegrees(Math.atan(b/w)));
    }
}


Measured memory_bytes: 25044
#include <iostream>
#include <set>
#include <map>
using namespace std;

int M,N;
map<pair<set<int>,set<int>>,int> m;
char F[129][12];

int dfs(set<int> ob,set<int> fe){
    if(ob.size()<=1) return (M-(int) fe.size());
    if(m.count({ob,fe})) return m[{ob,fe}];
    int res = 1e9;
    set<int> fe2 = fe;
    for(auto x:fe){
        set<int> ob0,ob1;
        for(auto y:ob){
            if(F[y][x]=='0') ob0.insert(y);
            else ob1.insert(y);
        }
        fe2.erase(x);
        res = min(res,max(dfs(ob0,fe2),dfs(ob1,fe2)));
        fe2.insert(x);
    }
    return m[{ob,fe}] = res;
}

int main(){
    while(cin >> M >> N && N>0){
        m.clear();
        for(int i=0;i<N;i++) for(int j=0;j<M;j++) cin >> F[i][j];
        set<int> ob,fe;
        for(int i=0;i<N;i++) ob.insert(i);
        for(int j=0;j<M;j++) fe.insert(j);
        cout << dfs(ob,fe) << endl;
    }
}


Measured memory_bytes: 32392
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;


void calc() {

	Int N, M; std::cin >> N >> M;
	Int sum = 0;
	std::vector<Int> A(N); 
	rep(i, N) {
		std::cin >> A[i];
		sum += A[i];
	}
	std::sort(A.rbegin(), A.rend());
	double val = (double)sum / (double)(4 * M);
	if (A[M - 1] >= std::ceil(val))std::cout << "Yes";
	else std::cout << "No";

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.trim().split(' ')
	const a = parseInt(args[0], 10)
	const b = parseInt(args[1], 10)
	const c = parseInt(args[2], 10)
	if (a === b + c) console.log('Yes')
	else if (a + b === c) console.log('Yes')
	else if (a + c === b) console.log('Yes')
	else console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	vector<int> a(3);
	rep(i,3) cin>>a[i];
	sort(begin(a),end(a));
	int ans=0;
	int x=(a[2]-a[0])/2,y=(a[2]-a[1])/2;
	ans+=x+y;
	a[0]+=x*2;
	a[1]+=y*2;
	sort(begin(a),end(a));
	if(a[0]==a[2]){
		cout<<ans<<endl;
	}else{
		if(a[1]==a[2]){
			cout<<ans+2<<endl;
		}else{
			cout<<ans+1<<endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  cin >> n;
  V<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(a.begin(), a.end());

  if (a.size() == 1) {
    cout << a[0] << endl;
    return 0;
  }

  int half = a.size() / 2;

  if (a.size() % 2 == 0) {
    ll sm = 0, la = 0;
    for (int i = 0; i < half; i++) sm += a[i] * 2;
    sm -= a[half - 1];
    for (int i = a.size() / 2; i < n; i++) la += a[i] * 2;
    la -= a[half];

    ll ans = la - sm;
    cout << ans << endl;
    return 0;
  }

  ll ans = 0;

  ll sm = 0, la = 0;
  for (int i = 0; i < half; i++) sm += a[i] * 2;
  for (int i = half; i < n; i++) la += a[i] * 2;
  la -= a[half] + a[half + 1];
  ans = max(ans, la - sm);

  sm = 0;
  la = 0;
  for (int i = 0; i < half + 1; i++) sm += a[i] * 2;
  for (int i = half + 1; i < n; i++) la += a[i] * 2;
  sm -= a[half] + a[half - 1];
  ans = max(ans, la - sm);

  cout << ans << endl;
}


Measured memory_bytes: 3996
import sys
import math
import numpy as np
from fractions import gcd

import heapq

# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N,M = map(int, sys.stdin.readline().split())
list_A = list(map(int, sys.stdin.readline().split()))
# list_A.sort(reverse=True)

# list_A_np = np.array(list_A)

# hq = heapq.heapify(list_A)
for i in range(N):
    list_A[i] = -list_A[i]

heapq.heapify(list_A)
# print(list_A)
# print(int(-4.34))

for i in range(M):
    tmp = heapq.heappop(list_A)
    heapq.heappush(list_A, int(tmp/2))

# for i in range(M):
    # list_A.sort(reverse=True)
    # idx_max = list_A.index(max(list_A))
    # list_A[idx_max] = int(list_A[idx_max]/2)

    # if(list_A[0] > list_A[1]):
    #     list_A[0] = int(list_A[0]/2)
    # else:
    #     list_A.sort(reverse=True)
    #     list_A[0] = int(list_A[0]/2)


    # if(list_A_np[0] > list_A_np[1]):
    #     list_A_np[0] = int(list_A_np[0]/2)
    # else:
    #     # idx_max = list_A_np.argmax()
    #     # list_A_np[idx_max] = int(list_A_np[idx_max]/2)
    #     list_A_np = np.sort(list_A_np)[::-1]
    #     list_A_np[0] = int(list_A_np[0]/2)

    # idx_max = list_A_np.argmax()
    # list_A_np[idx_max] = int(list_A_np[idx_max]/2)

ans = 0

for i in range(N):
    # ans += list_A[i]
    # ans += list_A_np[i]
    # ans += hq.pop
    ans += heapq.heappop(list_A)

print(-ans)


Measured memory_bytes: 24980
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int sum(int a) {
  map<int, int> mp;
  while (a > 1) {
    bool b = false;
    for (int i = 2; i * i <= a; i++) {
      if (a % i == 0) {
        mp[i]++;
        a /= i;
        b = true;
        break;
      }
    }
    if (!b) {
      mp[a]++;
      break;
    }
  }
  int ret = 1;
  for (auto it = mp.begin(); it != mp.end(); it++)
    ret *= it->second + 1;
  return ret;
}

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i += 2) {
    if (sum(i) == 8) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include "vector"
#include "queue"
#include "map"
#include "math.h"
#include "algorithm"
using namespace std;
typedef long long ll ;
typedef vector<ll> ve ;
typedef pair <int , int> pr ;
#define F first
#define S second
#define pb push_back
#define MP make_pair
#define MAX INT_MAX
#define MIN (-1 * INT_MAX)
#define rep(i,a,b) for(int i = a ; i< b ; ++i)
#define loop(i , arr)  for(auto i : arr)
#define endll '\n'
ve    vec2  , vec3  , vec4;
int t , n , k , sum , cnt;
priority_queue<ll> pq ;
int arr[100001] ;
map<char , ll> mp ;
const int mod = 1e9+7 ;
int gcd (int a  , int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
bool isPrime(int n){
    for(int i = 2; i <= sqrt(n); i++){
        if(n%i == 0)
            return false;
    }
    return true;
}
int main () {
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
  int n , k ;
  cin >>n >> k ;
  vec2.resize(n) ;
  rep(i , 0 , n ) cin >>vec2[i] ;
  sort(vec2.begin() , vec2.end()) ;
  rep(i , 0 , k ) sum+=vec2[i] ;
  cout << sum ;
 return 0 ;
}











Measured memory_bytes: 3208
n,*ps=$<.read.split.map(&:to_i)

ret = ps.map.with_index {|n,i| n == i+1}.
  slice_when{|a,b| a != b}.
  select{|a|a[0]}.
  map{|a|(a.length+1)/2}.
  inject(&:+) || 0
p ret


Measured memory_bytes: 15356