akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 2e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll n, m, v, p;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> m >> v >> p;

  ll arr[n + 5];
  for (ll i = 1; i <= n; i++) {
    cin >> arr[i];
  }

  sort(arr + 1, arr + n + 1);

  ll low = 1, high = n;
  while (low <= high) {
    ll mid = (low + high) >> 1;

    bool good = false;
    ll currVal = arr[mid] + m;
    ll rem = v - 1;
    ll arr2[n + 5];
    for (ll i = 1; i <= n; i++) {
      if (i == mid)
        continue;
      if (i > mid)
        arr2[i - 1] = arr[i];
      else
        arr2[i] = arr[i];
    }
    ll n1 = n - 1;
    rem -= (p - 1);

    if (arr2[n1 - (p - 1)] <= currVal) {
      vector<ll> val;
      for (ll i = 1; i <= (n1 - (p - 1)); i++) {
        val.push_back(min(currVal - arr2[i], m));
      }
      sort(val.begin(), val.end(), greater<ll>());
      ll limit = rem * m;
      ll sum1 = 0;
      for (ll i = 0; i < min((ll)val.size(), limit); i++) {
        sum1 += val[i];
      }
      if (sum1 >= limit) {
        good = true;
      }
    }
    if (!good)
      low = mid + 1;
    else
      high = mid - 1;
  }

  cout << (n - low + 1) << en;

  return 0;
}

Measured memory_bytes: 3692
import sys

N,M = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
if N >= M:
    print(ans)
    sys.exit()

X.sort()

L = []
for i in range(1, len(X)):
    L.append(X[i]-X[i-1])

L.sort(reverse=True)
print(X[M-1]-X[0]-sum(L[:N-1]))

Measured memory_bytes: 13960
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    int cur = 1;
    for(auto& e : a){
        if(e == cur){
            cur++;
        }
    }
    int res = -1;
    if(cur > 1){
        res = n - (cur - 1);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 1000010;

int n , d , h , dp[N] , sum[N] , fact[N];

int main(){
	fact[0] = 1;
	scanf("%d%d%d",&n,&h,&d);
	int all = 0;
	for(int i = 1;i <= n;i++){
		fact[i] = (long long)i * fact[i - 1] % mod;
		all += fact[i];
		if(all > mod) all -= mod;
	}
	dp[0] = sum[0] = fact[n];
	for(int i = 1;i < h;i++){
		if(i <= d)
			dp[i] = (long long)sum[i - 1] * all % mod;
		else{
			dp[i] = sum[i - 1] - sum[i - d - 1];
			if(dp[i] >= mod) dp[i] -= mod;
			if(dp[i] < 0) dp[i] += mod;
			dp[i] = (long long)dp[i] * all % mod;
		}
		sum[i] = sum[i - 1] + dp[i];
		if(sum[i] >= mod)
			sum[i] -= mod;
	}
	int ans = 0;
	for(int i = h - 1;i >= h - d;i--){
		ans += dp[i];
		if(ans >= mod)
			ans -= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15344
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < (n); ++i)
#define rem(i, m, n) for (int i = m; i >= (n); --i)
typedef long long ll;

int main(){
  int N;
  string S;
  cin >> N >> S;
  string L = S.substr(0, N);
  string R = S.substr(N, 2 * N);
  reverse(R.begin(), R.end());
  map<pair<string, string>, ll> mp;
  ll ans = 0;
  rep(i, 0, 1 << N) {
    string r = "";
    string b = "";
    rep(j, 0, N) {
      if(i & (1 << j)) r += L[j];
      else b += L[j];
    }
    mp[{r, b}]++;
  }
  rep(i, 0, 1 << N) {
    string r = "";
    string b = "";
    rep(j, 0, N) {
      if(i & (1 << j)) r += R[j];
      else b += R[j];
    }
    ans += mp[{r, b}];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 93952
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))
X1 = sum(A) - 2 * sum(A[1::2])


def g():
    state = X1
    yield X1
    for i in range(N-1):
        state = 2 * A[i] - state
        yield state


print(*list(g()))

Measured memory_bytes: 14528
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, int32_t (*find)(const void*)){
	char (*a)[size] = (char(*)[size])base;
	char (*b)[size] = (char(*)[size])malloc(count*size);
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(0<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(1<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(2<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(find(a[i])>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(find(a[i])>>(3<<3))&0xFF]; memcpy(b[to], a[i], size); }{char(*t)[size]=a; a=b; b=t;}
	free(b);
}

int find(const void *a){
	return *(int*)a;
}

int n;
int a[100001];
int b[100001];
int c[100001];
int d[200001];

void inc(int i){
	i+=100000;
	while(i<=200000){
		d[i]++;
		i+=i&-i;
	}
}

int sum(int i){
	i+=100000;
	int s=0;
	while(i>0){
		s+=d[i];
		i-=i&-i;
	}
	return s;
}

long f(int x){
	for(int i=1; i<=n; i++){
		c[i]=c[i-1]+(a[i]<=x?1:-1);
	}
	memset(d, 0, sizeof(d));
	long ans=0;
	inc(c[0]);
	for(int i=1; i<=n; i++){
		ans+=sum(c[i]-1);
		inc(c[i]);
	}
	return ans;
}

int main(void){
	n=nextint();
	for(int i=1; i<=n; i++){
		a[i]=b[i]=nextint();
	}
	rsorta_d32(b+1, n, sizeof(int), find);
	int kl=1, kr=n;
	long m = (long)n*(n+1)/4+1;
	//printf("%d\n", m);
	while(kl<=kr){
		int km=(kl+kr)/2;
		//printf("%d %d %ld\n", km, b[km], f(b[km]));
		if(f(b[km])>=m) kr=km-1; else kl=km+1;
	}
	//printf("%d %d %ld\n", kl, b[kl], f(b[kl]));
	printf("%d\n", b[kl]);
}


Measured memory_bytes: 3540
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    vi lMax(N,0), rMax(N,0);
    lMax[0] = A[0], rMax[N - 1] = A[N - 1];
    FOR(i,1,N) {
        lMax[i] = max(lMax[i-1], A[i]);
        rMax[N - 1 - i] = max(rMax[N - i], A[N - 1 - i]);
    }

    cout << rMax[1] << endl;
    FOR(i,1,N-1) {
        cout << max(lMax[i - 1], rMax[i + 1]) << endl;
    }
    cout << lMax[N - 2] << endl;

    return 0;
}

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

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

A.sort()

A=A+[0]
B=[]
count=1


for i in range(N):
    if A[i+1]==A[i]:
        count+=1
    else:
        ans=[A[i], count]
        B.append(ans)
        count=1

B.sort(key=lambda x: x[1])
B.reverse()
B=list(B)
B_len=len(B)

sum_count=0
ans=0

for i in range(K,B_len):
    ans+=B[i][1]

print(ans)

Measured memory_bytes: 32996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

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

	int a = 700;
	REP(i, S.length())
	{
		if (S[i] == 'o')a += 100;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
 
if n<105:
    print(0)
elif n>104 and n<135:
    print(1)
elif n>134 and n<165:
    print(2)
elif n>164 and n<189:
    print(3)
elif n>188 and n<195:
    print(4)
else:
    print(5)

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long int lis[100002]={0};
long long int memomemo[100002]={0};
long long int memo[100002]={0};
int N,L;
int func(int a){
    if(memomemo[a]==1)return memo[a];
    memomemo[a]=1;
    if(memo[a]!=0)return memo[a];
    if(a==0){
        if(lis[a]>lis[a+1])memo[a]=L-lis[a];
        else memo[a]=func(a+1)+(L-lis[a]);
        return memo[a];
    }
    else if(a==N-1){
        if(lis[a-1]<lis[a])memo[a]=L-lis[a];
        else memo[a]=func(a-1)+(L-lis[a]);
        return memo[a];
    }
    else{
        if(lis[a-1]<lis[a]&&lis[a]>lis[a+1])memo[a]=L-lis[a];
        else if(lis[a-1]<lis[a])memo[a]=func(a+1)+(L-lis[a]);
        else if(lis[a]>lis[a+1])memo[a]=func(a-1)+(L-lis[a]);
        else memo[a]=max(func(a-1),func(a+1))+(L-lis[a]);
        return memo[a];
    }
}
int main(){
    cin>>N>>L;
    for(int i=0;i<N;i++)cin>>lis[i];
    for(int i=0;i<N;i++)memo[i]=func(i);
    long long int ans=0;
    for(int i=0;i<100000;i++)ans=max(ans,memo[i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3904
use std::io;

fn read() -> String {
  let mut s = String::new();
  io::stdin().read_line(&mut s).unwrap();
  s.trim_right().to_string()
}

fn main() {
  let tmp = read();
  let mut buf = tmp.split_whitespace();
  let a: i32 = buf.next().unwrap().parse().unwrap();
  let b: i32 = buf.next().unwrap().parse().unwrap();
  let t: i32 = buf.next().unwrap().parse().unwrap();
  println!("{}", t / a * b)
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

vector<int> G[100010];

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

    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    vector<int> A(M),B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int ht = H[i - 1];
        bool flag = true;
        for (int j = 0; j < G[i].size(); j++) {
            if (H[G[i][j] - 1] >= ht) {
                flag = false;
            }
        }
        if (flag) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9596
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll max = a*c;
    chmax(max, a*d);
    chmax(max, b*d);
    chmax(max, b*c);
    cout << max << endl;

    return 0;
}

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


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int n,tot,a,b,c;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        tot=0;
        cin>>a>>b>>c;
        a--,b--;
        tot+=a*200-5*(a-a/3);
        if((a+1)%3==0)tot+=20*b;
        else{
            if(b%2==0)tot+=39*(b/2);
            else tot+=39*(b/2)+20;
        }
        tot+=c;
        cout<<196471-tot<<endl;
    }
}



Measured memory_bytes: 3076
import java.util.Scanner;

public class Main{

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

		int n = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());

		int[] a = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
			sum += a[i];
		}
		int left = 0;
		int right = sum;
		int ans;
		while (right - left > 1) {
			ans = (left + right) / 2;
			boolean clear = false;
			clear = isClear(ans, a, x);

			if (clear) {
				right = ans;

			}

			else {
				left = ans;
			}

		}
		System.out.println(right);

	}

	private static boolean isClear(int ans, int[] a, int x) {

		int sum = 0;
		int cnt = 0;
		for (int i = 0; i < x; i++) {
			sum = 0;
			while (true) {
				sum += a[cnt];
				if (sum > ans) {
					break;
				}
				if (cnt == a.length - 1) {
					return true;
				}
				cnt++;
			}
		}

		return false;
	}
}

Measured memory_bytes: 70688
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        int bothmax;
        if (A >= B) {
            bothmax = B;
        } else
            bothmax = A;

        int bothmin;
        if(A+B<=N){
            bothmin=0;
        }
        else if(A+B<2*N) {
            bothmin=(A+B) % N;
        }
        else {
            bothmin=N;
        }

        System.out.printf("%d %d%n",bothmax, bothmin);
    }

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=3e5+20;

int n,b[maxn],a[maxn];

int main()
{
	n=read();
	REP(i,1,n)a[i]=read(),b[i]=a[i]==i;
	REP(i,2,n-1)
	{
		if(!b[i-1] && !b[i] && !b[i+1])puts("No"),exit(0);
	}
	REP(i,1,n)
	{
		if(b[i]==0)
		{
			int j=i;
			while(j<n && b[j]!=b[j+1])++j;
			REP(k,i,j)if(i<=a[k] && a[k]<=j);
			else puts("No"),exit(0);
			int mx1=0,mx2=0;
			REP(k,i,j)
			{
				if(k<a[k])
				{
					if(a[k]<mx1)puts("No"),exit(0);
					mx1=a[k];
				}
				else if(k>a[k])
				{
					if(a[k]<mx2)puts("No"),exit(0);
					mx2=a[k];
				}
			}
			i=j;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int n, i, nearest;
  scanf("%d", &n);
  int a[n], sum = 0;
  double ave, def, nearest_def;

  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
    sum += a[i];
  }
  ave = (double)sum /(double)n;

  def = ave - (double)a[0];
  nearest_def = def * def;
  nearest = 0;

  for(i = 1; i < n; i++){
    def = ave - (double)a[i];
    def *= def;

    if(def < nearest_def){
      nearest_def = def;
      nearest = i;
    }
  }
  printf("%d\n",nearest );

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

struct edge {
    int to;
    ll weight;
};

vector<edge> tree[100010];
ll cost_k[100010];  //kからのコスト

void dfs(int v, int parent, ll dist) {  //parentは親ノード
    cost_k[v] = dist;

    for(int i = 0; i < tree[v].size(); i++) {
        if(tree[v][i].to == parent) {
            continue;
        }

        dfs(tree[v][i].to, v, dist + tree[v][i].weight);  //行き先、今いる頂点、距離
    }
}

int main() {
    int n;
    cin >> n;
    rep(i, n-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        tree[a].push_back({ b, c });
        tree[b].push_back({ a, c });
    }

    int q, k;
    cin >> q >> k;
    k--;

    dfs(k, -1, 0);  //kに親ノードはないので-1とする

    rep(i, q) {
        int x, y;
        cin >> x >> y;
        x--;  y--;
        cout << cost_k[x] + cost_k[y] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 15872
n = gets.to_i
ab = n.times.map{|_| gets.split.map(&:to_i)}.sort_by{|x, y| y}

t = 0
ab.each do |a,b|
  t += a
  if t > b
    print "No\n"
    exit
  end
end
print "Yes\n"

Measured memory_bytes: 34284
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;

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

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    //最小公倍数
    ll l=c*d/gcd(c,d),
    //1からc-1について
    p1=(a-1)/c, q1=(a-1)/d, r1=(a-1)/l,
    //1からdについて
    p2=b/c, q2=b/d, r2=b/l,
    //cからdについて
    p3=p2-p1, q3=q2-q1, r3=r2-r1,
    //cからdの幅
    wid=b-a+1;
    cout<<wid-p3-q3+r3;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		run();
	}

	static void run() {
		new Main().solver();
	}

	long MOD = 1_000_000_009;

	void solver() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			long w = sc.nextLong(), h = sc.nextLong();
			int n = sc.nextInt();
			if (w == 0 && h == 0 && n == 0)
				break;
			long[][] obs = new long[n][2];
			for (int i = 0; i < n; i++) {
				obs[i] = new long[] { sc.nextLong() - 1, sc.nextLong() - 1 };
			}
			Arrays.sort(obs, new Comparator<long[]>() {
				@Override
				public int compare(long[] o1, long[] o2) {
					return Long.compare(o1[1], o2[1]);
				}
			});
			long[][] ans = new long[(int) w][1];
			ans[0][0] = 1;
			long[][] A = new long[(int) w][(int) w];
			for (int i = 0; i < w; i++) {
				if (i < w - 1) {
					A[i][i + 1] = 1;
					A[i + 1][i] = 1;
				}
				A[i][i] = 1;
			}
			long cur_y = 0;
			for (int i = 0; i < n; i++) {

				ans = MtPow(obs[i][1] - cur_y, A, ans);
				// tr(ans);
				cur_y = obs[i][1];
				ans[(int) obs[i][0]][0] = 0;
			}
			ans = MtPow((h - 1) - cur_y, A, ans);
			System.out.println("Case " + (count++) + ": " + ans[(int) w - 1][0]);
		}
	}

	int count = 1;

	long[][] MtPow(long n, long[][] A, long[][] v) {
		for (; n > 0; n = n >> 1) {
			if ((n & 1) == 1)
				v = MtPrd(A, v);
			A = MtPrd(A, A);
		}
		return v;
	}

	long[][] MtPrd(long[][] A, long[][] B) {
		long[][] C = new long[A.length][B[0].length];
		for (int i = 0; i < A.length; i++) {
			for (int j = 0; j < B[0].length; j++) {
				for (int k = 0; k < A[0].length; k++) {
					C[i][j] += A[i][k] * B[k][j] % MOD;
					C[i][j] %= MOD;
				}
			}
		}
		return C;
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 60264
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    vi vec;
    char prev = s.at(0);
    rep(i, s.size()){
        if(prev != s.at(i)){
            prev = s.at(i);
            vec.push_back(cnt);
            cnt = 0;
        }
        cnt++;
    }
    vec.push_back(cnt);
    if(vec.size() <= 2){
        sort(vec.begin(), vec.end(), greater<int>());
        cout << vec[0] << endl;
    }else{
        int cnt = 0;
        int half;
        if(s.size() % 2 == 1){
            half = s.size() / 2 + 1;
        }else{
            half = s.size() / 2;
        }
        int tmp = 0;
        rep(i, vec.size()){
            cnt += vec[i];
            if(cnt >= half) break;
        }
        swap(tmp, cnt);
        for(int i = vec.size() - 1;i >= 0;--i){
            cnt += vec[i];
            if(cnt >= half) break;
        }
        if(tmp < cnt){
            swap(tmp, cnt);
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N, K; cin >> N >> K;
  
  vector<double> p(N);
  rep(i, N) cin >> p[i];
  vector<double> e(N);
  rep(i, N) e[i] = (p[i]+1)/2;
  //rep(i, N) cout << e[i] << endl;
  
  double k = 0;
  rep(i, K) k += e[i];
  
  double ans = k;
  for(int i=K; i<N; i++) {
    k += e[i];
    k -= e[i-K];
    ans = max(ans, k);
    //cout << ans << endl;
  }
  cout << fixed << setprecision(10) << ans << endl;

}

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

int main(){
    int A, B, C, X;
    int ans = 0;
    cin >> A >> B >> C >> X;
    for(int a = 0; a <= A; a++){
        for(int b = 0; b <= B; b++){
            for(int c = 0; c <= C; c++){
                int total = 500*a + 100*b + 50*c;
                if(total == X) ans++;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef double db;
 
const int N = 200005;
int n, x, ans[N], vis[N], tmp[N], tn;
 
int main(){
	scanf("%d%d", &n, &x);
	if (x == 1 || x == 2 * n - 1) printf("No\n");
	else {
		ans[n] = x;
		int l = n, r = n;
		int cnt = min(x - 1, 2 * n - 1 - x);
		vis[x] = 1;
		for (int i = 1; i <= cnt; i++) {
			vis[i] = vis[2 * n - 1 - i + 1] = 1;
			ans[--l] = i; ans[++r] = 2 * n - 1 - i + 1;
		}
		for (int i = 1; i <= 2 * n - 1; i++) 
			if (vis[i] == 0) tmp[tn++] = i;
		for (int i = 0; i < tn / 2; i++) ans[--l] = tmp[i];
		for (int i = tn / 2; i < tn; i++) ans[++r] = tmp[i];
	printf("Yes\n");
	for (int i = 1; i <= 2 * n - 1; i++) printf("%d\n", ans[i]);
	}

	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<functional>
#include<list>
#include<unordered_map>
#define int long long
using namespace std;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	int e; cin >> e;
	int sum = 0;
	for (int d = 1; d < a; d++) {
		int f; scanf("%lld", &f);
		sum += min(c,b*(f-e));
		e = f;
	}
	cout << sum << endl;
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(std::string s) {
  for (char c : s) {
    if (c == ',') {
      cout << " ";
    } else {
      cout << c;
    }
  }
  cout << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 3624
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b=INTM()
    print(a*b-(a+b-1))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

// int main(){
//     int L;
//     cin >> L;
//     double l = L/3.l;
//     printf("%.12f\n.",pow(l,3));
//     return 0;
// }

int main() {
    int L;
    cin >> L;
 
    double d = L / 3.l;
    // double ans = );
 
    printf("%.12f", pow(d,3));
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const double inf = 1e9;
const int MAX = 5005;

//mod(1e9+7)
const int mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x = 0) : x(x % mod){}
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

int main() {
    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];
    vint mat(3,0);
    mint sum = 1;
    REP(i,n+1) {
        int ct = 0;
        rep(j,3) if (a[i-1] == mat[j]) ct++;
        rep(j,3) if (a[i-1] == mat[j]) {mat[j]++; break;}
        sum *= ct;
    }
    cout << sum.x << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

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

    int N;
    int W;
    cin >> N >> W;

    long long w[N], v[N];
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    long long dp[N + 1][W + 1];
    for (int i = 0; i < N + 1; i++) {
        for (int j = 0; j < W + 1; j++) {
            dp[i][j] = 0;
        }
    }

    // 縦軸に品物の個数，横軸に重さをとる二次元の表を全部埋める感じ
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            // i 番目の品物を選ぶ場合
            if (j - w[i] >= 0) {
                change_max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
            }
            // i 番目の品物を選ばない場合
            change_max(dp[i + 1][j], dp[i][j]);
        }
    }

    cout << dp[N][W] << '\n';
    return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<bool> f(n, false);
  std::vector<int64_t> l(n, 0);
  std::vector<std::map<int64_t, int64_t>> no(n);

  for (int64_t i = 0; i < n - 1; i++) {
    int64_t u, v, w;
    std::cin >> u >> v >> w;
    u--;
    v--;
    no[u].insert({v, w});
    no[v].insert({u, w});
  }

  f[0] = true;
  l[0] = 0;

  std::set<std::pair<int64_t, int64_t>> q;
  for (const auto &i : no[0]) {
    if (!f[i.first]) {
      q.insert({l[0] + i.second, i.first});
    }
  }

  while (!q.empty()) {
    const auto cost = q.cbegin()->first;
    const auto node = q.cbegin()->second;
    if (!f[node]) {
      f[node] = true;
      l[node] = cost;

      for (const auto &i : no[node]) {
        if (!f[i.first]) {
          q.insert({cost + i.second, i.first});
        }
      }
    }
    q.erase(q.begin());
  }

  for (const auto i : l) {
    if (i % 2 == 0) {
      std::cout << 0 << std::endl;
    } else {
      std::cout << 1 << std::endl;
    }
  }

  return 0;
}

Measured memory_bytes: 18560
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

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

	int n, t, s;
	cin >> n >> t >> s;

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

	vector<int> dp(t + 1, -1);
	dp[0] = 0;
	for(int i = 0; i < n; ++i) {
		for(int x = t - b[i]; x >= 0; --x) {
			if(dp[x] == -1) continue;
			if(x < s && s < x + b[i]) {
				if(s + b[i] <= t) chmax(dp[s + b[i]], dp[x] + a[i]);
			}
			else {
				chmax(dp[x + b[i]], dp[x] + a[i]);
			}
		}
	}

	cout << *max_element(dp.begin(), dp.end()) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1240
#include <iostream>

using namespace std;

bool judge ( int x1, int y1, int x2, int y2, int t )
{
  int sum = (x2-x1)+(y2-y1);

  if ( sum > t ) return false;
  if ( (t-sum)%2 == 0 ) return true;
  else return false;
}

int main()
{
  int x1, y1, x2, y2;
  int N,t1, t2;
  bool f = true;

  x1 = y1 = 0;
  t1 = 0;

  cin >> N;

  while ( N-- ) {
    scanf("%d%d%d", &t2, &x2, &y2);
    if ( !judge(x1, y1, x2, y2, t2-t1) ) f = false;
    x1 = x2; y1 = y2; t1 = t2;
  }

  if ( f ) cout << "Yes\n";
  else cout << "No\n";
}


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

using namespace std;

int main() {
    int length_of_strings;
    string input, output = "No";

    cin >> length_of_strings >> input;

    if(length_of_strings % 2 == 0) {
        string half_input = input.substr(0, length_of_strings/2);
        if(input == half_input + half_input) {
            output = "Yes";
        }
    }
    cout << output << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int ans=0;
string x;
cin>>x;
for(int i=0;i<x.length()-1;i++)
{
    if(x[i]!=x[i+1])
    {
        ans++;
    }
}
cout<<ans<<endl;
}

Measured memory_bytes: 512
N, Y = map(int, input().split())
ichiman_num = -1
gosen_num = -1
sen_num = -1
for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if 10000*i + 5000*j + 1000*k == Y and k >=0:
            ichiman_num = i
            gosen_num = j
            sen_num = k
            print(ichiman_num, gosen_num, sen_num)
            exit()
print(ichiman_num, gosen_num, sen_num)

Measured memory_bytes: 3060
/* ****mittal21**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
#define N  100005
void solve()
{
   ll n;
   cin>>n;
   ll a[n+3],b[n+3];
   ll lol[n+3],hol[n+3];
   memset(lol,0,sizeof(lol));
   memset(hol,0,sizeof(hol));
   for(int i=1;i<=n;i++)
   	{
   		cin>>a[i];
   		hol[a[i]]++;
   	}
   for(int i=1;i<=n;i++)
   	{
   		 cin>>b[i];
   		 lol[b[i]]++;
   	}
   	ll fl=0;
   	for(int i=1;i<=n;i++)
   	{
   		  if(lol[a[i]]==0)
   		  {
   		  	  continue;
   		  }
   		  if(lol[a[i]]>n-hol[a[i]])
   		  	fl=1;
   	}
   	if(fl)
   	{
   		  cout<<"No";
   		  return;
   	}
   	priority_queue<pair<ll,ll>>pq;
   	for(int i=1;i<=n;i++)
   	{
   		 if(hol[i]>0&&lol[i]>0)
   		 {
   		 	pq.push({lol[i],i});
   		 	//cout<<lol[i]<<" "<<i<<endl;
   		 }
   	}
   	ll c[n+3];
   	memset(c,-1,sizeof(c));
   	for(int i=1;i<=n;i++)
   	{
       if(pq.size()==0)
        break;
       pair<ll,ll>temp=pq.top();
       pq.pop();
       if(temp.S==a[i])
       {
       	  if(pq.size()==0)
       	  {
       	  	 pq.push(temp);
       	  	 continue;
       	  }
       	  pair<ll,ll>temp1=pq.top();
       	  pq.pop();
       	  c[i]=temp1.S;
       	  pq.push(temp);
       	  if(temp1.F!=1)
       	  {
       	  	pq.push({temp1.F-1,temp1.S});
       	  }
       }
       else
       {
       	  c[i]=temp.S;
       	  if(temp.F!=1)
       	  {
       	  	pq.push({temp.F-1,temp.S});
       	  }
       }

   	}
   	ll cnt=1;
    std::vector<ll> vv;
   	for(int i=1;i<=n;i++)
   	{
   		  if(lol[i]>0&&hol[i]==0)
   		  {
   		  	 for(int j=0;j<lol[i];j++)
            vv.pb(i);
   		  }
   	}
     cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(c[i]==-1)
        {
            if(cnt>=vv.size())
              break;
            c[i]=vv[cnt];
            cnt++;
        }
    }
    ll w=0;
    for(int i=1;i<=n;i++)
    {
        if(c[i]==-1)
        {
            for(int j=1;j<=n;j++)
            {
                if(i!=j&&a[i]!=a[j]&&c[j]!=a[i])
                {
                    c[i]=c[j];
                    c[j]=a[i];
                    w=1;
                    break;
                }
            }
        }
        
    }
   	cout<<"Yes"<<endl;
   	for(int i=1;i<=n;i++)
   	{
   		cout<<c[i]<<" ";
   	}
   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 14336
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    p.sort()
    y = 0

    for i in range(n):
        if p[i] <= x:
            y = i
            if i != n-1 and x < p[i+1]:
                break 

    i = 0
    while 1 == 1:
        if y - i < 0:
            print(p[0] - 1)
            break
        elif x - i != p[y - i]:
            print(x - i)
            break
        if n <= y + i:
            print(p[n - 1] + 1)
            break
        elif x + i != p[y + i]:
            print(x + i)
            break
        i = i + 1

Measured memory_bytes: 9232
import java.util.Scanner;

class Main{

	//static long[] a;



	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int N =sc.nextInt();
		int D =sc.nextInt();
		int X =sc.nextInt();
		int[] A =new int[N];
		
		for(int i = 0;i < N;i++){
			A[i] =sc.nextInt();
		}
		
		int ans = 0;
		for(int i =0 ;i < N;i++){
			int day = 1;
			
			for(int j = 0;day <= D;j++){
				day += A[i];
				ans ++;

			}

		}
		System.out.println(ans + X);
	}
}




Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
char a[110],t[110];
int main(){
	scanf("%s%s",&a,&t);
	int len = strlen(a);
	int len1 = len;
	if(strcmp(t,a) == 0){
		printf("Yes\n");
		return 0;
	}
	while(len1){
		char ch = t[len - 1];
		for(int i = len - 1;i >= 1;i--){
			t[i] = t[i - 1];
		}
		t[0] = ch;
		if(strcmp(t,a) == 0){
			printf("Yes\n");
			return 0;
		}
		len1--;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
def echo(n, s):
    # nが奇数
    if  n % 2 != 0:
        return "No"
    # nが偶数
    else:
        s_first, s_last = s[:int(n/2)], s[int(n/2):]
        if s_first == s_last:
            return "Yes"
        else:
            return "No"

if __name__ == "__main__":
    n = int(input())
    s = input()
    print(echo(n, s))

Measured memory_bytes: 3064
using System;

namespace Sample101
{
    class Program
    {
        static int SumOfDigits(int n)
        {
            int sum = 0;
            while (n > 0)
            {
                sum += n % 10;
                n /= 10;
            }
            return sum;
        }
        static void Main(string[] args)
        {
            string result = "No";
            int N = int.Parse(Console.ReadLine());
            // Nはハーシャッド数か
            // 各桁の数字の和
            // Nが和で割り切れるならハーシャッド数
            int sum = SumOfDigits(N);
            if (N % sum == 0)
            {
                result = "Yes";
            }

            Console.WriteLine(result);
        }
    }
}

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

int main(){
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int count[3] = {0, 0, 0};
    char ans[3] = {'A', 'B', 'C'};
    int person = 0;
    while(true){
        if(count[person] == s[person].length()){
            break;
        }
        switch (s[person][count[person]]){
            case 'a':
                count[person]++;
                person = 0;
                break;
            case 'b':
                count[person]++;
                person = 1;
                break;
            case 'c':
                count[person]++;
                person = 2;
                break;
        }
    }
    cout << ans[person] << endl;

}

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

using namespace std;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int A,B,M;
    cin>>A>>B>>M;

    vector<int> as;
    for (size_t i = 0; i < A; i++)
    {
        int a;cin>>a;as.push_back(a);
    }

    vector<int> bs;
    for (size_t i = 0; i < B; i++)
    {
        int b;cin>>b;bs.push_back(b);
    }

    int best = *min_element(as.begin(),as.end()) + *min_element(bs.begin(),bs.end());

    for (size_t i = 0; i < M; i++)
    {
        int x,y,c;cin>>x>>y>>c;
        x--;y--;
        best=min(best, as[x] + bs[y] - c);
    }
    
    cout << best <<"\n";
    

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
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();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    //int f=0;
    //string st,tt,nt;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    cin>>a>>b;
    if(a>8||b>8)printa(":(");
    else printa("Yay!");
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut v = Vec::new();
    for i in 1..=n {
        let s:String = read();
        let p:i64 = read::<i64>() * -1;
        v.push((s, p, i));
    }
    v.sort();
    for i in v {
        println!("{}", i.2);
    }
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> c(M);
  vector<int> s(M);
  for(int i; i < M; i++){
    cin >> s[i] >> c[i];
  }
  
  vector<int> r(N);
  for(int i; i < N ;i++){
   r[i]=-1;
  }
  
  int f=1;
  for(int i; i < M ;i++){
    if( (r[s[i]-1] ==-1 || r[s[i]-1] == c[i]) && !(s[i] == 1 && c[i] == 0)){
      r[s[i]-1]=c[i];
    }else if( (s[i] == 1 && c[i] == 0) && N == 1){
      r[s[i]-1]=c[i];
    }else{
      cout << -1;
      f=-1;
      break;
    }
  }

  if(f == 1){
    for(int i; i < N ;i++){
      if(r[i] == -1){
        r[i]=0;
        if(i == 0 && N !=1){
          r[i]=1;
        }
      }
    }
  
    for(int x:r){
      cout << x;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int N, K; cin >> N >> K;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int h; cin >> h;
    if (h >= K) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256