akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
int main(){
        int n,r;
        while(~getII(n,r)){
                if(n>=10) printf("%d\n",r);
                else printf("%d\n",r+100*(10-n));
        }
}

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


const int maxn = 1e5 + 7;

typedef pair<int, long long> Point;

Point o[maxn];
int main() {
	int n, start_point;
	scanf("%d%d", &n, &start_point);
	o[0] = Point(start_point, (long long)1e17);
	for (int i = 1; i <= n; i++) {
		scanf("%d%lld", &o[i].first, &o[i].second);
	}
	sort(o, o + n + 1);

	int last = -1;
	int s = 0, t = n;
	long long ans = o[n].first - o[0].first;
	if (o[s].second < o[t].second) {
		o[t].second += o[s].second;
		last = 1;
		s++;
	}
	else {
		o[s].second += o[t].second;
		last = 0;
		t--;
	}
	while (s < t) {
		if (o[s].second < o[t].second) {
			if (last == 0) ans += o[t].first - o[s].first;
			last = 1;
			o[t].second += o[s].second;
			s++;
		}
		else {
			if (last == 1) ans += o[t].first - o[s].first;
			last = 0;
			o[s].second += o[t].second;
			t--;
		}
		// cout << s << ' ' << t << ' ' << last << ' ' << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int>a(N);
  vector<int>b(N);
  for (int i=0;i<N;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(b.begin(),b.end());
  for(int i=0;i<N;i++){
    if(a[i]==b[N-1]){
      cout<<b[N-2];
    }
    else cout<<b[N-1];
    cout<<endl;
  }
  return 0;
}

  

Measured memory_bytes: 3200
#include <cstdio>
long long n, a[100010], k, i, cnt, x, tmp, check;
int main(){
	for(scanf("%lld", &n); i<n; i++){
		scanf("%lld", a+i);
		k+=a[i];
		cnt+=i+1;
	}
	if(k%cnt!=0)	return 0*printf("NO");
	k/=cnt;
	cnt=0;
	for(i=0; i<n; i++){
		tmp=a[i]-a[(i+1)%n];
		if((tmp+k)%n!=0||tmp+k<0)	return 0*printf("NO");
		x=(tmp+k)/n;
		cnt+=x;
		check+=x*(n-i);
	}
	if(cnt!=k||check!=a[0])	return 0*printf("NO");
	puts("YES");
	return 0;
}

Measured memory_bytes: 896
N = int(input())
S = [input() for i in range(N)]
#print(S)
a_cnt = 0
b_cnt = 0
ab_cnt = 0
b_a_cnt = 0
for i,s in enumerate(S):
    ab_cnt += s.count("AB")
    if s[-1] == "A":
        a_cnt += 1
    if s[0] == "B":
        b_cnt += 1
    if s[0] == "B" and s[-1] == "A":
        b_a_cnt += 1
if a_cnt == b_cnt == b_a_cnt and b_a_cnt != 0:
    ab_cnt += min(a_cnt, b_cnt) - 1
else:
    ab_cnt += min(a_cnt, b_cnt)

print(ab_cnt)

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

ll data[17][17];
ll dp[(1 << 17) + 1] = {};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n && n){
    rep(i,n){
      rep(j,n+1){
        cin >> data[i][j];
      }
    }
    rep(j,(1 << 17) + 1){
      dp[j] = 0;
    }
    bitset<17> b,nb;
    /* dp[0][0] = 0; */
    REP(st,1,1 << (n+1)){
      b = bitset<17>(st);
      nb = bitset<17>(st);
      ll tmpcost = inf;
      rep(i,n){
        if(!b[i]) continue;
        ll mint = data[i][0];
        ll tmp = st & ~(1 << i);
        /* nb[i] = 0; */
        /* cout << b << ' ' << i << ' ' << bitset<17>(tmp) << ' ' << nb << endl; */
        rep(j,n){
          if(tmp >> j & 1) {
            mint = min(mint,data[i][j+1]);
          }
        }
        tmpcost = min(tmpcost,dp[tmp] + mint);
      }
      dp[st] = tmpcost;
    }
    /* ll ans = inf;           */
    /* rep(j,1 << n){          */
    /*   cout << dp[j] << ' '; */
    /* }                       */
    /* cout << endl; */
    std::cout << dp[(1 << n) - 1] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 4116
#include<iostream>
using namespace std;
#define int long long
signed main(){int n;cin>>n;int n1=n/11;int n2=n%11;int cl;if(n2>6)cl=2;else if(n2==0)cl=0;else cl=1;int key=n1*2+cl;cout<<key<<endl;return 0;
}

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

const int INF = 1e9;


int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i=0; i<N; i++) cin >> h[i];
  vector<int> dp(N, INF);
  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  for (int i=2; i<N; i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[N-1] << endl;
}


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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int K, A, B; cin >> K >> A >> B;
    for(int i = A; i <= B; i++)
    {
        if(i % K == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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

int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    
    if(((b-a) <= k) && ((c-b) <= k) && ((d-c) <= k) && ((e-d) <= k) && ((c-a) <= k) && ((d-a) <= k) && ((d-b) <= k) && ((e-b) <= k) && ((e-c) <= k)&& ((e-a) <= k)){
        cout << "Yay!" << endl; 
    }else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int n, k, A[2000000], C[10001];

int main(void) {

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
        if (A[i] > k) {
            k = A[i];
        }
        ++C[A[i]];
    }

    for (int i = 0, f = 0; i <= k; ++i) {
        for (int j = 0; j < C[i]; ++j) {
            if (f) {
                printf(" %d", i);
            }
            else {
                f = 1;
                printf("%d", i);
            }
        }
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
#include <bits/stdint-intn.h>

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

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int64_t> a(n);
  rep(i, n) { std::cin >> a[i]; }
  std::map<int64_t, int64_t> map;

  rep(i, n) { map[a[i]]++; }

  sort(a.begin(), a.end(), greater<int64_t>());
  a.erase(unique(a.begin(), a.end()), a.end());

  int64_t maxv = 0;
  int64_t num = 0;
  int64_t ans = 1;
  rep(i, n) {
    if (num == 2) {
      break;
    }
    if (map[a[i]] >= 4) {
      maxv = max(maxv, a[i] * a[i]);
    }
    if (map[a[i]] >= 2) {
      ans *= a[i];
      num++;
    }
  }

  if (num < 2) {
    std::cout << 0 << std::endl;
    return 0;
  }

  std::cout << max(maxv, ans) << std::endl;

  return 0;
}


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

public class Main{

	public static void main(String[] args){
		Scanner sc =  new Scanner(System.in);

		int N = sc.nextInt();
		int L = sc.nextInt();
		String S[] = new String[N];

		for(int i = 0;i< N;i++){
			S[i] = sc.next();
		}

		Arrays.sort(S);
		String A = "";
		for(int i = 0;i<N ;i++){
			A += S[i];
		}
		System.out.println(A);
	}
}

Measured memory_bytes: 13652
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

double pow2(double x);

int main()
{
    int n;
    cin >> n;
    while (n--) {
        double x1, y1, x2, y2, x3, y3;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

        double xx1 = pow2(x1);
        double yy1 = pow2(y1);
        double xx2 = pow2(x2);
        double yy2 = pow2(y2);
        double xx3 = pow2(x3);
        double yy3 = pow2(y3);

        double a1 = 2 * (x2 - x1);
        double b1 = 2 * (y2 - y1);
        double c1 = xx1 - xx2 + yy1 - yy2;
        double a2 = 2 * (x3 - x1);
        double b2 = 2 * (y3 - y1);
        double c2 = xx1 - xx3 + yy1 - yy3;

        double xp = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
        double yp = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
        double r = sqrt(pow2(xp - x1) + pow2(yp - y1));

        cout << fixed << setprecision(3)
             << xp << " " << yp << " " << r << endl;
    }

    return 0;
}

double pow2(double x)
{
    return (x * x);
}

Measured memory_bytes: 1292
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int count,i;
            int a[];
            a = new int[100000];
            Scanner n = new Scanner(System.in);
            count = n.nextInt();
            for(i=0;i<count;i++){
                a[i] = n.nextInt();
            }
            for(i=count-1;i>=0;i--){
                if(i==0){
                    System.out.printf("%d",a[i]);
                }else{
                    System.out.printf("%d ",a[i]);
                }
            }
            System.out.printf("\n");
    }
}


Measured memory_bytes: 26828
##B - Go to Jail
N = int(input())
D = list(list(map(int,input().split())) for i in range(N))
ans = 0
for j in range(N):
    if D[j][0] == D[j][1]:
        ans += 1
        if ans == 3:
            break
    else:
        ans *= 0
if ans == 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9180
n_ = input()
n = int(n_)
k = int(input())

#kが小さい
#100桁から2か所,1~9二回選択
#ちょうどk個

ans = 0
l = len(n_) 
ans += int(n_[0])+9*(l-1)
if k==1:
    print(ans)
    exit()
ans = 0
ans += 9*9*(l-2)*(l-1)//2
ans += (int(n_[0])-1)*9*(l-1)
tmp = int(n_[0])*10**(l-1)
for j in range(1,10):
    for i in range(len(n_)):
        if n>=tmp+j*10**i:
            ans += 1
if k==2:
    print(ans)
    exit()
    
ans = 0

ans += 9*9*9*(l-2)*(l-1)*(l-3)//6
ans += (int(n_[0])-1)*9*9*(l-1)*(l-2)//2
tmp = int(n_[0])*10**(l-1)
for j in range(1,10):
    for k in range(1,10):
        for i in range(len(n_)):
            for h in range(i):
                if n>=tmp+j*10**i+k*10**h:
                    ans += 1
print(ans)
    




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

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

signed main()
{
    int h, w;
    while(cin>>w>>h, w) {
        char field[h+1][w+1];
        int sx, sy;
        for(int i=0; i<h; ++i) {
            for(int j=0; j<w; ++j) {
                char c;
                cin >> c;
                if(c=='@') {
                    sx = i;
                    sy = j;
                }
                field[i][j] = c;
            }
        }

        queue<pair<int, int> > q;
        q.push(make_pair(sx, sy));
        int ans = 0;
        while(!q.empty()) {
            ans++;
            pair<int, int> p = q.front();
            q.pop();
            int x = p.first;
            int y = p.second;
            for(int i=0; i<4; ++i) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if(nx>=0&&nx<h&&ny>=0&&ny<w&&field[nx][ny]=='.') {
                    q.push(make_pair(nx, ny));
                    field[nx][ny] = '#';
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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


    

int main() {
  int N;
  cin >> N;
  long long a=1,b=1,c=1,ans=0;
  long long mod=0;
  mod=1000000007;
  for(int i=0; i<N; i++){
    a=a*2%mod*5%mod;
  }
   for(int j=0; j<N; j++){
    b=b*3%mod*3%mod;
  }
   for(int k=0; k<N; k++){
    c=c*2%mod*2%mod*2%mod;
  }
  ans=a-2*b%mod+c;
  if(ans<0){
    ans=ans+1000000007;
  }
    cout << ans <<endl;
    
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
int main(){
int h,w,i,j,k,l,a[101][101],n,b[10001];
scanf("%d%d",&h,&w);
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",&b[i]);
k=1;
for(i=1;i<=h;i++){
	if(i%2){
	for(j=1;j<=w;j++){
		a[i][j]=k;
		b[k]--;
		if(b[k]==0)k++;
	}
	}
	else{for(j=w;j>=1;j--){
		a[i][j]=k;
		b[k]--;
		if(b[k]==0)k++;
	}
		
	}
}
for(i=1;i<=h;i++)
{
	for(j=1;j<=w;j++)printf("%d ",a[i][j]);
	printf("\n");
	}
return 0;
}



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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'

int n, k, c= 0;
int a[50000];

signed main()
{
	IOS;
	cin >> n >> k;
	for (int i = 0; i < n; i++) 
	{
		int e;
		cin >> e;
		if (e >= k) c++;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,m,cnt;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		if (i%2==0) continue;
		int t=0;
		for (int j=1;j<=i;++j){
			if (i%j==0) ++t;
		}
		if (t==8) ++cnt;
	}
	printf("%d",cnt);
	return 0;
}

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

typedef long long ll;
static const int MOD = 1e9+7;
static const ll INF = 1ll<<60;

int main(){
    int X,N;
    cin>>X>>N;
    set<int> p;
    for(int i=0; i<N; i++){
        int a;
        cin>>a;
        p.insert(a);
    }

    int ans = -10000;
    int cnt = 0;

    while(ans == -10000){
        int l,r;
        l = X - cnt;
        r = X + cnt;

        if(!p.count(l)){
            ans = l;
            break;
        }

        if(!p.count(r)){
            ans = r;
            break;
        }

        cnt++;
    }

    cout<<ans<<endl;
}

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

typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;

int h, w, k;

int main() {
    cin >> h >> w >> k;
    k--;
    vector<vector<ll>> cur_count(h, vector<ll>(w, 0));
    cur_count[0][0] = 0;
    for (int i = 0; i < 1 << (w - 1); i++) {
        bool valid = true;
        for (int k = 0; k < w - 2; k++) {
            if ((i >> k & 1) && (i >> (k + 1) & 1)) {
                valid = false;
                break;
            }
        }
        if (!valid)
            continue;
        if (i & 1) {
            cur_count[0][1]++;
        } else {
            cur_count[0][0]++;
        }
    }
    for (int l = 1; l < h; l++) {
        for (int m = 0; m < w; m++) {
            for (int i = 0; i < 1 << (w - 1); i++) {
                bool valid = true;
                for (int k = 0; k < w - 2; k++) {
                    if ((i >> k & 1) && (i >> (k + 1) & 1)) {
                        valid = false;
                        break;
                    }
                }
                if (!valid)
                    continue;
                if (m > 0 && (i >> (m - 1) & 1)) {
                    cur_count[l][m] += cur_count[l - 1][m - 1] % MOD;
                } else if (m < w - 1 && (i >> m & 1)) {
                    cur_count[l][m] += cur_count[l - 1][m + 1] % MOD;
                } else {
                    cur_count[l][m] += cur_count[l - 1][m] % MOD;
                }
            }
        }
    }
    cout << cur_count[h - 1][k] % MOD;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  double N,M;
  cin >> N >> M;
  vector<int> A(N);
  double sum = 0;
  rep(i,N) cin >> A[i];
  rep(i,N) sum += A[i];
  sort(RALL(A));
  if(A[M-1]>=sum/(4*M))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int i,n,m,min,best=-1000000000;
    cin>>n>>min;
    for(i=0;i<n-1;i++){
        cin>>m;
        if(m-min>best)best=m-min;
        if(m<min)min=m;        
    }
    cout<<best<<endl;
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
int di[4] = {1,0,-1,0};
int dj[4] = {0,1,0,-1};


int main() {
    int h,w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    //各スタートに対しての最長距離を見ていけばよい（ゴールはいちいち考えない）
    int ans = 0;
    rep(si,h)rep(sj,w) { //スタート位置全探索
        if (s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w,INF));
        dist[si][sj] = 0;
        queue<P> que;
        que.push(P(si,sj));
        while (!que.empty()) {
            int i = que.front().first;
            int j = que.front().second; que.pop();
            rep(dir,4) {
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if (ni<0 || ni>=h || nj<0 || nj>=w) continue;
                if (s[ni][nj] == '#') continue;
                if (dist[ni][nj] != INF) continue;
                que.push(P(ni,nj));
                dist[ni][nj] = dist[i][j] + 1;
            }
        }
        rep(i,h)rep(j,w) {
            if (dist[i][j] == INF) continue;
            chmax(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<double, double> pdd;
/*
bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < pri_max; i++)
	{
		if (memo[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l < pri_max; l += i)
			{
				memo[l] = true;
			}
		}
	}
}*/
int main()
{
	int a, b, c;
	while (cin >> a >> b >> c)
	{
		int x[11] = {};
		x[a] = x[b] = x[c] = 1;
		int c = 0;
		for (int i = 1; i <= 10; i++)
		{
			if (x[i] == 0 && i + a + b <= 20)
			{
				c++;
			}
		}
		cout << (c >= 4 ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, k;
int main() {
	cin >> n >> k;
	vector<ll> s(n);
	REP(i, n)cin >> s[i];
	sort(ALL(s));
	ll ans = 0;
	REP(i, max(0ll, n - k)) {
		ans += s[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3

import math


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()

    ans = 100
    for a in range(1, int(math.sqrt(N)) + 1):
        if N % a != 0:
            continue

        b = N // a
        f = max(len(str(a)), len(str(b)))
        ans = min(ans, f)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
s = int(input())
an = [s]
for n in range(2, 1000):
    if an[n-2]%2 == 0:
        a = an[n-2]//2
        #print(a)
        if a in an:
            print(n)
            exit()
        else:
            an.append(a)
    else:
        a = 1 + 3*an[n-2]
        if a in an:
            print(n)
            exit()
        else:
            an.append(a)

Measured memory_bytes: 9088
loop do
    n = gets.to_i
    break if n == 0
    y = gets.to_i
    a = (1..n).map { gets.split.map(&:to_i) }
    p a.max_by {|_, r, t| t == 1 ? 1 + y * r / 100.0 : (1 + r / 100.0) ** y}[0]
end


Measured memory_bytes: 6948
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int main() 
{
	int n,i; cin>>n;
	if(n%1000==0) return cout<<0, 0;
	for(i=1;i<=10;i++)
	{
	    if(1000*i>n)
	    return cout<<1000*i-n , 0;
	}
	return 0;
}


Measured memory_bytes: 3628
n, m = map(int, input().split())
ships = [list(map(int, input().split())) for _ in range(m)]
starts = list(map(lambda x:x[1], list(filter(lambda x:x[0]==1, ships))))
goals = list(map(lambda x:x[0], list(filter(lambda x:x[1]==n, ships))))
if len(set(starts+goals)) != len(starts+goals):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 64776
#include<stdio.h>

int main(){
    int a,b,c,tmp;
    scanf("%d%d%d",&a,&b,&c);
    if(b<a) tmp=a,a=b,b=tmp;
    if(c<b) tmp=c,c=b,b=tmp;
    if(b<a) tmp=a,a=b,b=tmp;
    printf("%d %d %d\n",a,b,c);
    
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    set<int> a, b;
    forn(i, n) {
        if (s[i] == 'R') a.insert(i);
        else b.insert(i);
    }
    if (b.empty() || a.empty()) {
        cout << "0\n";
        return 0;
    }
    int cnt = 0;
    while (*a.rbegin() > *b.begin()) {
        cnt++;
        int x = *a.rbegin(), y = *b.begin();
        a.erase(x), b.erase(y);
        a.insert(y), b.insert(x);
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 13020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;


typedef long long lint, ll;
typedef long double ldouble, ld;

#ifdef LOCAL
	#define dbg(expr) cerr << "[" << __LINE__ << "] " << #expr << " = " << (expr) << '\n';
#else
	#define dbg(expr) (void) 0;
#endif


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

    int n;
    cin >> n;
    vector<lint> l(n);
    for (int i = 0; i < n; i++)
        cin >> l[i];
    sort(l.begin(), l.end());
    vector<lint> possible;
    for (int i = n - 1; i >= 0; i--) {
        if (i > 0 && l[i] == l[i - 1]) {
            possible.push_back(l[i]);
            i--;
        }
    }
    if ((int)possible.size() < 2) {
        cout << 0 << endl;
        return 0;
    }
    cout << possible[0] * possible[1] << endl;
}

Measured memory_bytes: 1660
_,a=open(0)
*a,=map(int,a.split())
m=max(a)
c=[0]*-~m
for i in a:c[i]+=1
print(sum(c[:-~m//2])<1and~m%-2+2==c[-~m//2]and all(c[i+1]>1for i in range(m//2,m))and'Possible'or'Impossible')

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

int main()
{
    unsigned long n,a,b;
    scanf("%lu %lu %lu",&n,&a,&b);
    unsigned long c,d;
    c=n/(a+b);
    d=n%(a+b);
    if(d>a)
    {
        printf("%lu\n",c*a+a);
    }
    else
    {
        printf("%lu\n",c*a+d);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;
int main(){
  ll n; cin >>n; ll sum=0;
  if(n==1){cout <<0; return 0;}
  for(int i=2; i<=sqrt(n); i++){
    int tem=i;
    while(n%i==0){
      if(n%tem==0){n/=tem; tem*=i; sum++;}
      else n/=i;
    }
  }
  if(n-1) sum++;
  cout <<sum;
return 0;}

Measured memory_bytes: 3680
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    long long ans = 0;
    for(int i=1; i<n; ++i){
        int b = max(0, a[i-1] + a[i] - x);
        ans += b;
        if(b <= a[i]){
            a[i] -= b;
        }
        else{
            a[i-1] -= b - a[i];
            a[i] = 0;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
using namespace std;
const int64_t MOD = 1e9 + 7;

#define M 1046527
#define L 14

vector<string> H(M);

int getChar(char ch) {
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

int getKey(string S) {
	int sum = 0, p = 1;
	for (int i = 0; i < S.size(); i++) {
		sum += p * getChar(S.at(i));
		p *= 5;
	}

	return sum;
}

int h1(int key) {
	return key % M;
}

int h2(int key) {
	return 1 + (key % (M - 1));
}

int find(string S) {
	int key, h;
	key = getKey(S);
	for (int i = 0;; i++) {
		h = (h1(key) + i * h2(key)) % M;
		if (H.at(h) == S) return 1;
		else if (H.at(h).size() == 0) return 0;
	}
}

int insert(string S) {
	int key, h;
	key = getKey(S);
	for (int i = 0;; i++) {
		h = (h1(key) + i * h2(key)) % M;
		if (H.at(h) == S) return 1;
		else if (H.at(h).size() == 0) {
			H.at(h) = S;
			return 0;
		}
	}

	return 0;
}

int main() {
	int n, h;
	string S, com;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> com >> S;
		if (com.at(0) == 'i') {
			insert(S);
		}
		else {
			if (find(S)) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}
	}
}


Measured memory_bytes: 27364
use std::io::Read;

fn input() -> (i32,i32) {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let a:i32 = iter.next().unwrap().parse().unwrap();
    let b:i32 = iter.next().unwrap().parse().unwrap();
    (a,b)
}

fn main() {
    let (a,b) = input();
    println!("{}",a*b);
}



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

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

ll a[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	ll k; cin>>k;
	ll gd=-1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i==0) gd=a[0];
		else gd=__gcd(a[i],gd);
	}
	sort(a,a+n);
	if(k%gd==0&&k<=a[n-1]) cout<<"POSSIBLE\n";
	else cout<<"IMPOSSIBLE\n";
	
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<numeric>
#include<functional>
#include<algorithm>
#include<queue>
#include<map>


#define FOR(i, a, b) for(int i=a; i<b; i++)
#define COUT(a) cout << a << endl;

using namespace std;
using Int = long long;
using P = pair<Int, Int>;

Int H, W;

int main(){
    Int N;
    vector<char> balls;

    cin >> N;
    FOR(i, 0, N){
        char ball;
        cin >> ball;
        balls.push_back(ball);
    }

    sort(balls.begin(), balls.end());
    balls.erase(unique(balls.begin(), balls.end()), balls.end());

    if (balls.size() == 3){
        COUT("Three");
        return 0;
    }

    COUT("Four");
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
input=sys.stdin.readline
N,K,Q=map(int,input().split())
scores=[K-Q]*N
for _ in range(Q):
    scores[int(input())-1]+=1
for score in scores:
    print('Yes' if score>0 else 'No')

Measured memory_bytes: 11612
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;

int main()
{
   int n; cin>>n;
   if(n%1000==0) {
       cout << 0 << endl;
       return 0;
   }
   cout<<1000-(n%1000)<<endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
  long X;
  cin >> X;
  long a,b;
  a = X / 500;
  X = X - a * 500;
  b = X / 5;
  cout << a * 1000 + b * 5 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int m = sc.nextInt();
        if(m>=1){
            System.out.println(24-m+24);
        }else{
            System.out.println(24-m+24);
        }
    }
}

Measured memory_bytes: 21716
def slove():
    import sys
    import heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    l = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    r = []
    heapq.heapify(l)
    heapq.heapify(r)
    t = 0
    for i in range(m + 1):
        while True:
            if len(l) != 0:
                a, b = heapq.heappop(l)
                if a <= i:
                    heapq.heappush(r, -b)
                else:
                    heapq.heappush(l, [a, b])
                    break
            else:
                break
        if len(r) != 0:
            t += -heapq.heappop(r)
    print(t)


if __name__ == '__main__':
    slove()


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

int main(){

  double n,t,x,h;
  cin >> n >> t;

  double res = 0;
  for(int i = 0; i < n; i++){
    cin >> x >> h;
    res = max(h/x,res);
  }
  printf("%f\n",res*t);

	return 0;
}



Measured memory_bytes: 3212
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        int K = int.Parse(words[0]);
        int A = int.Parse(words[1]);
        int B = int.Parse(words[2]);
        bool bis = false;
        if (B - A > 2) bis = true;

        long BiscuitsCount = 1;
        bool en = false;
        for (int i = 0; i < K; i++)
        {
            if (bis)
            {
                if (en)
                {
                    BiscuitsCount += B;
                    en = false;
                }
                else
                {
                    //ラスト1枚は円に交換させない
                    if (BiscuitsCount >= A && i < K - 1)
                    {
                        BiscuitsCount -= A;
                        en = true;
                    }
                    else
                    {
                        BiscuitsCount++;
                    }
                }
            }
            else
            {
                BiscuitsCount++;
            }
        }
        Console.WriteLine(BiscuitsCount);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



signed main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n)cin>>v[i];
  sort(v.begin(),v.end(),greater<int>());
  vector<int> use;
  rep(i,n-1){
    if(v[i]==v[i+1]){
      use.pb(v[i]);
      i++;
    }
  }
  cout<<(use.size()>=2?use[0]*use[1]:0)<<endl;
  return 0;
}


Measured memory_bytes: 1660
H,W=map(x->parse(Int,x),split(readline()))
S=readlines()
for i=1:H,j=1:W
	if S[i][j]!='#'
		continue
	end
	flag=false;
	for (x,y)=zip([i,i-1,i,i+1],[j-1,j,j+1,j])
		if 1<=x<=H&&1<=y<=W&&S[x][y]=='#'
			flag=true
			break
		end
	end
	if !flag
		println("No")
		exit()
	end
end
println("Yes")


Measured memory_bytes: 117788
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

    int N;
    cin >> N;

    int acc = 0;

    for(int i=1; i<=N; i++){
        if(i%3==0 || i%5==0){
            continue;
        }
        acc += i;
    }

    cout << acc << endl;

    return 0;
}


Measured memory_bytes: 3560
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		string s = Console.ReadLine();
        bool a = false;
        bool b = false;
        bool c = false;
        foreach(char d in s){
            if (d == 'a') a = true;
            if (d == 'b') b = true;
            if (d == 'c') c = true;
        }
        Console.WriteLine(a&&b&&c==true?"Yes":"No");
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main(void){

  int X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> p(A),q(B),r(C);
  for(int i=0;i<A;i++) cin >> p[i];
  for(int i=0;i<B;i++) cin >> q[i];
  for(int i=0;i<C;i++) cin >> r[i];

  sort(p.rbegin(),p.rend());
  sort(q.rbegin(),q.rend());

  for(int i=0;i<X;i++){
    r.push_back(p[i]);
  }
  for(int i=0;i<Y;i++){
    r.push_back(q[i]);
  }

  sort(r.rbegin(),r.rend());
  int ans_sum=0;
  for(int i=0;i<X+Y;++i){
    ans_sum+=r[i];
  }

  cout << ans_sum << "\n";

  return 0;
}

Measured memory_bytes: 6384
#include <cstdio>
#include <algorithm>
using namespace std;


int t[100000 + 100];
int a[100000 + 100];
int n;


bool t_is_right(int id) {
	if (id == 0) return true;

	if (id > 0 && t[id-1] < t[id])  return true;
	return false;
}


bool a_is_right(int id) {
	if (id == n-1) return true;

	if (id < n-1 && a[id] > a[id+1])  return true;
	return false;
}

const long long mod = 1e9+7 + 0.5;
int main() {
	// freopen("c.in", "r", stdin);
	
	while (scanf("%d", &n) != EOF) {
		for (int i = 0; i < n; i++) {
			scanf("%d", &t[i]);
		}
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		
		bool hasAnswer = true;
		for (int i = 0; i < n; i++) {
			if (t_is_right(i) || a_is_right(i)) {
				int haha = t[i];
				int hehe = a[i];
				if (!t_is_right(i)) {
					int heihei = haha;
					haha = hehe;
					hehe = heihei;
				}

				if (haha > hehe) {
					hasAnswer = false;
				}
			}
		}

		if (!hasAnswer) {
			puts("0");
		} else {
			long long ans = 1;
			for (int i = 0; i < n; i++) {
				if (!t_is_right(i) && !a_is_right(i)) {
					int min_height = min(a[i], t[i]);
					ans = (ans * min_height) % mod;
				}
			}
			printf("%d\n", (int)ans);
		}

	}
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    auto judge = [&](int i) {
        if(n-i <= p) return true;
        ll now = a[i]+m;
        if(now < a[n-p]) return false;
        ll sum = 0;
        rep(j,n) {
            if(j <= i || j >= n-p+1) sum += m;
            else sum += now-a[j];
        }
        return sum >= m*v;
    };
    int l = -1,r = n;
    while(true) {
        if(r-l == 1) break;
        int mid = (l+r)/2;
        if(judge(mid)) r = mid;
        else l = mid;
    }
    cout << n-r << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<climits>
#include<vector>
#define INFTY 2000000000
using namespace std;

int cnt;

void merge(std::vector<int>& v, int left,int mid, int right){
	int n1 = mid - left, n2 = right - mid;
	std::vector<int> L,R;
	for(int i=0;i<n1;i++){
		L.push_back(v[left+i]);
	}
	for(int i=0;i<n2;i++){
		R.push_back(v[mid+i]);
	}
	L.push_back(INFTY);
	R.push_back(INFTY);
	int i=0,j=0;
	for(int k=left; k<right;k++){
		cnt++;
		if(L[i] <= R[j]){
			v[k] = L[i];
			i++;
		} else {
			v[k] = R[j];
			j++;
		}
	}
}

void mergeSort(std::vector<int>& v, int left, int right){
	if(left+1 < right){
		int mid = (left+right)/2;
		mergeSort(v,left,mid);
		mergeSort(v,mid,right);
		merge(v,left,mid,right);
	}
}

int main(){
	int n,in;
	std::vector<int> v;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> in;
		v.push_back(in);
	}
	mergeSort(v,0,n);

	for(int i=0;i<n;i++){
		if(i>0) cout <<" ";
		cout << v[i];
	}
	cout << endl;
	cout << cnt << endl;
	return 0;
}

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

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

	int b[n]={0} ;
	int c[m]={0} ;

	char a[n][m] ;

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

	for(int i=0;i<n;i++)
	{
		int flag=0 ;
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='#')
				flag=1 ;
		}

		if(flag==0)
		{
			b[i]=1 ;
		}
	}

	for(int i=0;i<m;i++)
	{
		int flag=0 ;
		for(int j=0;j<n;j++)
		{
			if(a[j][i]=='#')
				flag=1 ;
		}

		if(flag==0)
		{
			c[i]=1 ;
		}
	}

	for(int i=0;i<n;i++)
	{
		if(b[i]==1)
		{
			continue ;
		}

		for(int j=0;j<m;j++)
		{
			if((b[i]==1)||(c[j]==1))
			{
				continue ;
			}

			else
			{
				cout << a[i][j] ;
			}
		}

		cout << endl ;
	}

	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;

using namespace std;
// n^(exponent) を mod で割った余りを計算 O(logN)
ll mod_pow(ll n, ll exponent, ll mod) {
    ll pow = 1;
    while(exponent > 0) {
        if((exponent & 1) == 1) {
            pow *= n;
            pow %= mod;
        }
        n *= n;
        n %= mod;
        
        // 桁をずらす
        exponent >>= 1;
    }
    return pow;
}

// n! を mod で割った余りを計算　O(N)
ll mod_factorial(ll n, ll mod) {
    ll factorial = 1;
    for(ll i = 1; i <= n; i++) {
        factorial *= i;
        factorial %= mod;
    }
    return factorial;
}

// xCn を　mod で割った余りを計算
ll mod_conbination(ll x, ll n, ll mod) {
    ll conb = mod_factorial(x, mod);
    
    // 逆元を求める(フェールマーの小定理を参照)
    ll reverse_n = mod_pow(mod_factorial(n, mod), mod - 2, mod);
    ll reverse_difference = mod_pow(mod_factorial(x - n, mod), mod - 2, mod);
    
    return (((conb * reverse_n) % mod) * reverse_difference) % mod;
}

int main() {
    int x, y;
    cin >> x >> y;
    
    if(y > 2 * x || x > 2 * y || ((x + y) % 3) != 0) {
        cout << 0 << endl;
    }
    else {
        ll k = (x + y) / 3;
        ll num = 2 * k - max(x, y);
        ll ans = mod_conbination(k, num, MOD);
        cout << ans << endl;
    }
    
    return 0;
}



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

long long gcd(long long m,long long n){
	if(m==0||n==0) return 0;
	while(m!=n){
		if(m>n) m=m-n;
		else n=n-m;
	}
	return m;
}

int main(void){
	long long a,b;

	while(cin >> a >>b){
		cout << gcd(a,b) << " " << a/gcd(a,b)*b << endl;
	}
	return 0;
}

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

int main(){
    int a,b;
    char op;
    while (true)
    {
        cin >> a >> op >> b;
        if(op == '?') break;
        switch (op)
        {
        case '+':
            cout << a + b << endl;
            break;
        case '-':
            cout << a - b << endl;
            break;
        case '*':
            cout << a * b << endl;
            break;
        case '/':
            cout << a / b << endl;
            break;
        }
    }
}


Measured memory_bytes: 3100
#include <stdio.h>

int stack[50], cp;

void push(int n)
{
	stack[cp] = n;
	cp++;
}

int pop(void)
{
	cp--;
	return stack[cp];
}

int main(void)
{
	int n;
	cp = 0;
	
	while (scanf("%d", &n) != EOF) {
		if (n != 0)   push(n);
		else if (cp != 0)printf("%d\n", pop());
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<algorithm>
char s[10];
int main()
{
    scanf("%s",s);
    for(int i=0;i<(int)strlen(s);i++)
    {
        if(s[i]=='1')
        {
            s[i]='9';
            continue;
        }
        if(s[i]=='9') s[i]='1';
    }
    printf("%s",s);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long ans=0,n,m;
struct node{
	long long mon,time;
}a[100005];
bool cmp(const node &a,const node &b) {
	return a.mon<b.mon;
}
int main() {
	cin>>n>>m;
	for (long long i=1;i<=n;i++) 
		cin>>a[i].mon>>a[i].time;
	sort(a+1,a+n+1,cmp);
	for (long long i=1;i<=n;i++) {
		if (m>a[i].time) {
			m-=a[i].time;
			ans+=a[i].time*a[i].mon;
		}
		else {
			ans+=m*a[i].mon;
			cout<<ans<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())
 
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const ll MOD = (ll)1000000007;//10^9+7
const ll INF2 = (ll)100000000000000000;//10^18


int main() {
    int N,K,X,Y;
    cin>>N>>K>>X>>Y;
    int sum=0;
    if(N>K){
        sum = K*X+(N-K)*Y;
    }else{
        sum = N*X;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
x,n=map(int,input().split(" "))
if n==0:
  print(x)
else:
  line=list(map(int,input().split(" ")))
  a=0
  b=0
  while a==0:
    if x-b not in line:
      min=x-b
      a=1
    elif x+b not in line:
      min=x+b
      a=1
    else:
      b=b+1
  print(min)




Measured memory_bytes: 9188
i = list(map(int, input().split())) 
N = i[0]
M = i[1]
A =list(map(int, input().split())) 

A_S = sorted(A, reverse=True)
ashi = sum(A) * (1/(4*M))

if A_S[M-1] >= ashi:
    print("Yes")
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n,m;
vector<int> G[N];
int vis[N];
queue<int> q;
int p[N];
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 0; i < m; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memset(p,-1,sizeof(p));
    p[1] = 0;
    q.push(1);
    while(q.size()){
        int u = q.front(); q.pop();
        for (auto v: G[u]){
            if (p[v] == -1){
                p[v] = u;
                q.push(v);
            }
        }
    }
    printf("Yes\n");
    for (int i = 2; i <= n; i++){
        printf("%d\n",p[i]);
    }


}


Measured memory_bytes: 13396