akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N;
  cin >> N;
  string result = "";
  while(N >= 1){
    int k = N % 26;
    if(k == 1){
     result = "a" + result; 
    }
    if(k == 2){
     result = "b" + result; 
    }
    if(k == 3){
     result = "c" + result; 
    }
    if(k == 4){
     result = "d" + result; 
    }
    if(k == 5){
     result = "e" + result; 
    }
    if(k == 6){
     result = "f" + result; 
    }
    if(k == 7){
     result = "g" + result; 
    }
    if(k == 8){
     result = "h" + result; 
    }
    if(k == 9){
     result = "i" + result; 
    }
    if(k == 10){
     result = "j" + result; 
    }
    if(k == 11){
     result = "k" + result; 
    }
    if(k == 12){
     result = "l" + result; 
    }
    if(k == 13){
     result = "m" + result; 
    }
    if(k == 14){
     result = "n" + result; 
    }
    if(k == 15){
     result = "o" + result; 
    }
    if(k == 16){
     result = "p" + result; 
    }
    if(k == 17){
     result = "q" + result; 
    }
    if(k == 18){
     result = "r" + result; 
    }
    if(k == 19){
     result = "s" + result; 
    }
    if(k == 20){
     result = "t" + result; 
    }
    if(k == 21){
     result = "u" + result; 
    }
    if(k == 22){
     result = "v" + result; 
    }
    if(k == 23){
     result = "w" + result; 
    }
    if(k == 24){
     result = "x" + result; 
    }
    if(k == 25){
     result = "y" + result; 
    }
    if(k == 0){
     result = "z" + result; 
    }
    if(N % 26 == 0){
     N = (N - 26) / 26; 
    }else{
     N /= 26; 
    }
    
  }
  
  cout << result << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> y(n);
  vector<int> m(n);
  vector<int> d(n);
  vector<int> ans(n);
  for(int i=0;i<n;i++){
    cin >> y[i] >> m[i] >> d[i];
    for(int j=y[i]+1;j<=999;j++){
      if(j%3 == 0){
	ans[i]+=200;
      }
      else{
	ans[i]+=195;
      }
    }
    for(int k = m[i]+1;k<=10;k++){
      if(y[i]%3==0){
	ans[i]+=20;
	  }else if(k%2 ==0){
	ans[i] += 19;
      }else if(k%2 == 1){
	ans[i] += 20;
      }
    }
    int flag;
    if(y[i]%3 == 0) flag = 20;
    else if(m[i]%2 == 0) flag = 19;
    else if(m[i]%2 == 1) flag = 20;
    for(int l = d[i];l<flag;l++){
      ans[i]++;
    }
    ans[i]=ans[i]+1;
  }
  y.pop_back();
    m.pop_back();
      d.pop_back();
  for(int o=0;o<n;o++){
    cout << ans[o] << endl;
  }
  ans.pop_back();
  return 0; 
}
  



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

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

int n,c;
int t[10][10],used[10][10];
bool zeroFlg;

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

int dfs(int x,int y,int number){
	int res = 1;
	used[y][x] = 1;

	rep(i,6){
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(ny>=0 && ny<n && nx>=0 && nx<=ny){
			if(t[ny][nx]==0) zeroFlg = true;
			if(t[ny][nx]==number && !used[ny][nx]){
				int tmp = dfs(nx,ny,number);
				res += tmp;
			}
		}
	}
	return res;
}

int solve(void){
	memset(used,0,sizeof(used));
	int res = 0;
	rep(i,n) rep(j,i+1){
		if(t[i][j]>0 && !used[i][j]){
			zeroFlg = false;
			int tmp = dfs(j,i,t[i][j]);
			if(zeroFlg) continue;
			if(t[i][j] == c){
				res -= tmp;
			} else{
				res += tmp;
			}
		}
	}
	return res;
}

int main(void){
	while(cin>>n>>c,c||c){
		rep(i,n) rep(j,i+1) cin>>t[i][j];

		int ans = -1000;
		rep(i,n) rep(j,i+1) if(t[i][j]==0){

			t[i][j] = c;
			ans = max(ans,solve());
			t[i][j] = 0;
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
S = input()
T = input()
flag = True
traslateT = [0] * 26
traslateS = [0] * 26
use = [False] * 26
for i in range(len(S)):
    si = ord(S[i]) - ord('a')
    ti = ord(T[i]) - ord('a')
    if(traslateS[si] != 0 and traslateS[si] != ti):
        flag = False
    if(traslateT[ti] != 0 and traslateT[ti] != si):
        flag = False
    traslateS[si] = ti
    traslateT[ti] = si

if(flag):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3760
#!/usr/bin/perl
#753 - AtCoder Beginner Contest 114

use strict;
use warnings;
 
# データ取得
my ($age);
    {
        $age = <STDIN>;
        chomp($age);
    }

    {
        if (   ($age == 7)
            || ($age == 5)
            || ($age == 3) ){
            print("YES\n");
        }else{
        	print("NO\n");
        }
    }
 
exit(0);


Measured memory_bytes: 640
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

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

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

vector<vector<bool>> stage;
vvecllong memo;
llong H, W;

llong search(llong h, llong w) {
    if(h == H and w == W) {
        return 1;
    }
    if(memo[h][w] >= 0) {
        return memo[h][w] % MOD;
    }

    llong ret = 0;
    if(stage[h + 1][w]) ret += search(h + 1, w);
    if(stage[h][w + 1]) ret += search(h, w + 1);
    memo[h][w] = ret % MOD;
    return memo[h][w];
};

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

    cin >> H >> W;

    stage = vector<vector<bool>>(H + 2, vector<bool>(W + 2, false));
    memo = vvecllong(H + 1, vecllong(W + 1, -1));

    FORS(h, 1, H + 1) {
        FORS(w, 1, W + 1) {
            char c;
            cin >> c;
            if(c == '.') {
                stage[h][w] = true;
            }
        }
    }

    llong ans = search(1, 1) % MOD;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
const int Q = 55;
int n, m, q;
int a[Q], b[Q], c[Q], d[Q];
int A[11], ans = 0;
void dfs(int i, int t)
{
    if (i == n + 1) {
        int s = 0;
        for (int j = 0; j < q; ++j)
            if (A[b[j]] - A[a[j]] == c[j])
                s += d[j];
        ans = max(ans, s);
        return;
    }
    for (A[i] = t; A[i] <= m; ++A[i])
        dfs(i + 1, A[i]);
}
int main()
{
    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(1, 1);
    cout << ans << endl;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
int M;
bool used[1600];
int par[1600];
int size[1600];
int elem[1600];
bool conned[800][800];
bool psum[800][800];
vector<PII> ps;

int Root(int u) {
  if (par[u] == u) return u;
  return par[u] = Root(par[u]);
}

bool Same(int u, int v) {
  return Root(u) == Root(v);
}

void Unite(int u, int v) {
  u = Root(u);
  v = Root(v);
  if (u == v) return;

  if (size[u] < size[v]) {
    par[u] = v;
  } else {
    par[v] = u;
  }
  size[u] = size[v] = size[u] + size[v];
  elem[u] = elem[v] = elem[u] + elem[v];
}

bool Join(int u, int v) {
  Unite(u, v+N);
  Unite(u+N, v);
  return Same(u, v);
}

int main(){
  scanf("%d%d", &N, &M);
  rep(i, N*2) {
    size[i] = 1;
    par[i] = i;
    elem[i] = i < N;
  }

  rep(i, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    conned[a][b] = true;
    conned[b][a] = true;
  }

  rep(u, N) {
    reps(v, u+1, N) {
      if (!conned[u][v]) {
        if (Join(u, v)) {
          puts("-1");
          return 0;
        }
      }
    }
  }

  rep(v, N) {
    int r = Root(v);
    if (used[r]) continue;
    
    int nr = r - N;
    if (r < N) nr = r + N;
    
    ps.emplace_back(PII(elem[r], elem[nr]));
    used[r] = used[nr] = true;
  }

  int g = ps.size();
  psum[0][0] = true;
  rep(i, g) {
    int a, b;
    tie(a, b) = ps[i];
    rep(j, N+1) {
      if (!psum[i][j]) continue;
      if (j+a <= N) psum[i+1][j+a] = true;
      if (j+b <= N) psum[i+1][j+b] = true;
    }
  }

  int ans = M;
  rep(i, N+1) {
    if (psum[g][i]) {
      int j = N-i;
      int a = i*(i-1)/2;
      int b = j*(j-1)/2;
      ans = min(ans, a+b);
    }
  }
  printf("%d\n", ans);
  
  return 0;
}


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

bool warshall_floyd(const int n,
                    vector<vector<int64_t>>& cost) {
    // 辺が存在しない場合は(1LL << 60)で初期化する
    for (auto i = 0; i < n; i++) cost[i][i] = 0;

    for (auto k = 0; k < n; k++) {
        for (auto i = 0; i < n; i++) {
            for (auto j = 0; j < n; j++) {
                // 直接行く場合とkを経由する場合でより小さい距離を採用する
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }

    bool isNegativeCycle = false;
    for (auto i = 0; i < n; i++) {
        // 自身へのコストが0以下なら負の閉路がある
        if (cost[i][i] < 0) isNegativeCycle = true;
    }

    return isNegativeCycle;
}

int main(){
    int h, w;
    cin >> h >> w;

    const int COUNT = 10;

    vector<vector<int64_t>> magic(COUNT, vector<int64_t>(COUNT, 0));
    for (auto i = 0; i < COUNT; i++) {
        for (auto j = 0; j < COUNT; j++) cin >> magic[i][j];
    }

    map<int, int> number;
    for (auto i = 0; i < h; i++) {
        for (auto j = 0; j < w; j++) {
            int tmp; cin >> tmp;
            if(tmp >= 0) number[tmp]++;
        }
    }

    warshall_floyd(COUNT, magic);
    int64_t ans = 0;
    for (auto& elm : number) ans += magic[elm.first][1] * elm.second;

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

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

int main(){
    string moji;
    int back;
    cin >> moji;
    
    back = moji.size();

    if(moji.at(back -1) == 's'){
        moji += "es";
    }
    else{
        moji += "s";
    }

    cout << moji;
    
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)

int main(void) {
	ll n, x, ans = 0;
	cin >> n >> x;
	vector<ll>a(n + 1);
	for (ll i = 1;i <= n;i++)cin >> a[i];
	for (ll i = 2;i <= n;i++) {
		if (i == 2) {
			if (a[1] + a[2] > x) {
				if (a[1] > x) {
					ans += a[1] + a[2] - x;
					a[1] = x;
					a[2] = 0;
				}
				else {
					ans += a[1] + a[2] - x;
					a[2] = a[2] - (a[1] + a[2] - x);
				}
			}
		}
		else {
			if (a[i] + a[i - 1] > x) {
				ans += a[i] + a[i - 1] - x;
				a[i] = a[i] - (a[i - 1] + a[i] - x);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
const int maxn = 1e4;
int main()
{
	int n;
	string s;

	cin >> n >> s;
	
	for (int i = 0; i < s.length(); i++)
	{
		if(s[i] + n > 'Z') {
			cout << char(s[i] + n - 'Z' + 'A' - 1);
		}
		else {
			cout << char(s[i] + n);
		}
		
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,k=1,ans=0,i=10;
	cin>>n;
	if(n<10){
		cout<<n;
		return 0;
	}
	for(;i<=n;i*=100){
		ans+=i*0.9;
	}
	if(n/(i/100)>9)ans+=n-i/10+1;
	cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O 
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc    
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAX_N = 100005, MAX_M = 200010;
// code
#define int long long
vector<pii> g[MAX_M];
int dist[MAX_M], n, m;
void dfs(int u){
    //cout << u << ' ';
    for (auto v:g[u]){
        if (dist[v.F] != INT_MIN){
            if (dist[v.F] != dist[u] + v.S){
                cout << "No";
                exit(0);
            }
        }else{
            dist[v.F] = dist[u] + v.S;
            dfs(v.F);
        }
    }
}
void Solve() {
    cin >> n >> m;
    //cout << n << ' ' << m;
    for (int i = 1; i <= n; i++){
        dist[i] = INT_MIN;
        //cout << "?";
    }
    for (int j = 1; j <= m; j++){
        int u, v, d;
        cin >> u >> v >> d;
        g[u].eb(v, d);
        g[v].eb(u, -d);
    }
    
    for (int i = 1; i <= n; i++){
        //cout << "? ";
        if (dist[i] == INT_MIN){
            dist[i] = 0;
            dfs(i);
        }
        //cout << dist[i] << ' ';
    }
    
    cout << "Yes";
}

signed main(){
    FAST_IO;
    int TC = 1; 
	//cin >> TC;
    while(TC--) Solve();
    return 0;
}

Measured memory_bytes: 22012
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<ll> v;
    ll cnt = 0;
    ll now = 1;
    rep(i,N){
        if(S[i] - '0' == now){
            cnt++;
        }else{
            v.push_back(cnt);
            cnt = 0;
            now = (now==0?1:0);
            i--;
        }
    }
    v.push_back(cnt);
    if(now==0){
        v.push_back(0);
    }
    //PR(v,v.size());
    ll M = v.size();
    ll ans = 0;
    ll tmp = 0;// v[0];
    ll r = 0;
    rep(l,M){
        if(l > r) r = l;
        while(r < M && r-l < K*2+1 ){
            tmp += v[r];
            r++;
            if(r < M && r-l < K*2+1){
                tmp += v[r];
                r++;
            }
        }
        //cout << tmp << endl;
        cmax(ans, tmp);
        if(l<r){
            tmp -= v[l];
        }
        l++;
        if(l<r){
            tmp -= v[l];
        }
        //tmp -= v[l];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4396
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();
		int Y = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		long[] aa = new long[A];
		long[] bb = new long[B];
		long[] P = new long[X+Y+C];
		int count = 0;
		for( int i=0; i<A; i++ ){
			aa[i] = sc.nextLong();
		}
		for( int i=0; i<B; i++ ){
			bb[i] = sc.nextLong();
		}
		for( int i=0; i<C; i++ ){
			long cc = sc.nextLong();
			P[count] = cc;
			count++;
		}
		Arrays.sort(aa);
		Arrays.sort(bb);
		for( int i=A-1; i>A-1-X; i-- ){
			P[count] = aa[i];
			count++;	
		}
		for( int i=B-1; i>B-1-Y; i-- ){
			P[count] = bb[i];
			count++;
		}
		Arrays.sort(P);
		long ans = 0;
		for( int i=C; i<X+Y+C; i++ ){
			ans += P[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 98108
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <cassert>
#include <functional>
#include <numeric>
#include <chrono>
#include <random>
#include <optional>

using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  map<ll, ll> odd, even;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (i & 1) odd[a]++;
    else even[a]++;
  }

  vector<pair<ll, ll>> impar;
  for (auto p: odd) {
    ll tot = n / 2;
    ll dif = tot - p.second;
    impar.push_back({dif, p.first});
  }

  vector<pair<ll, ll>> par;
  for (auto p: even) {
    ll tot = n / 2;
    ll dif = tot - p.second;
    par.push_back({dif, p.first});
  }

  sort(impar.begin(), impar.end());
  sort(par.begin(), par.end());
  ll res = 1e9;
  for (int i = 0; i < min(2, (int)impar.size()); i++) {
    for (int j = 0; j < min(2, (int)par.size()); j++) {
      ll val = impar[i].first + par[j].first;
      if (impar[i].second == par[j].second) {
        val = min(impar[i].first, par[j].first) + n/2;
      }
      res = min(res, val);
    }
  }
  cout << res << endl;
  return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    vector<int> used(200005);
    int n, m; cin >> n >> m;
    vector<int> v(m);
    rep(i, 0, m) cin >> v[i];
    reverse(all(v));
    vector<int> ans; ans.reserve(n);
    rep(i, 0, m) {
        if (!used[v[i]]) {
            ans.push_back(v[i]);
            used[v[i]] = true;
        }
    }
    rep(i, 1, n + 1) if (!used[i]) ans.push_back(i);
    rep(i, 0, n) cout << ans[i] << endl;
}


Measured memory_bytes: 4648
import math
h,w = map(int,input().split())
g = [list(input()) for _ in range(h)]
dp = [[float('inf')]*w for _ in range(h)]
if g[0][0] == '.':
    dp[0][0] = 0
else:
    dp[0][0] = 1

for i in range(h):
    for j in range(w):
        for di, dj in zip((0,1), (1, 0)):
            ni, nj = i+di, j+dj
            if ni>=h or nj>=w:
                continue
            if g[ni][nj]!=g[i][j]:
                dp[ni][nj] = min(dp[ni][nj], dp[i][j]+1)
            else:
                dp[ni][nj] = min(dp[ni][nj], dp[i][j])
print(math.ceil(dp[h-1][w-1]/2))

Measured memory_bytes: 42224
#include <bits/stdc++.h>
#define N 1000500
using namespace std;

vector<int> E[N];
int sg[N],n;
inline int rd() {int r;scanf("%d",&r);return r;}
void dfs(int u,int f) {
	sg[u] = 0;
	for (int i=0;i<(int)E[u].size();i++) {
		int v = E[u][i]; if (v == f) continue;
		dfs(v,u); sg[u] ^= sg[v]+1;
	}
}

int main() {
	n = rd();
	for (int i=1;i<n;i++) {
		int a = rd(), b = rd();
		E[a].push_back(b);
		E[b].push_back(a);	
	}
	dfs(1,1);
	puts(sg[1] ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 36864
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())
    R, S, P = map(int, readline().split())
    T = readline().strip()

    T = [int(c) for c in T.translate(str.maketrans('rsp', '012'))]
    H = [R, S, P]

    dp = [[0] * 3 for _ in range(N + 1)]

    for i in range(N):
        com = T[i]
        for h in range(3):
            if i > K - 1:
                dp[i + 1][h] = max(dp[i + 1 - K][(h + 1) % 3], dp[i + 1 - K][(h + 2) % 3])
            if (h + 1) % 3 == com:
                dp[i + 1][h] += H[h]

    print(sum(max(p) for p in dp[-K:]))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 85460
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main() {
    int n, m;
    stringstream ss;
    string line;

    getline(cin, line);
    ss << line;
    ss >> n >> m;
    bool * passed = new bool[n];
    int * penalties = new int[n];
    int ok = 0;
    for (int i = 0; i < m; i++) {
        int question;
        string score;
        stringstream ss1;
        getline(cin, line);
        ss1 << line;
        ss1 >> question >> score;
        if (score == "AC") {
            if (passed[question -1] == false) {
                ok += 1;
            }
            passed[question - 1] = true;
        } else if (passed[question - 1] == false) {
            if (penalties[question-1]) {
                penalties[question - 1] += 1;
            } else {
                penalties[question -1] = 1;
            }
        }
    }
    int totalPen = 0;
    for (int i = 0; i < n; i++) {
        if (passed[i]) {
            totalPen += penalties[i];
        }
    }
    cout << ok << " " << totalPen;

}


Measured memory_bytes: 768
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//scan.useDelimiter("\n");
		int a[] = new int [200];
		int b[] = new int [200];
		int count[] = new int [200];
		int i = 0;
		while(scan.hasNextInt()){
			//scan.useDelimiter(" ");
			a[i] = scan.nextInt();
			b[i] = scan.nextInt();
			//scan.useDelimiter("\n");
			a[i] = a[i]+b[i];
			while(a[i]!=0){
				a[i]=a[i]/10;
				count[i]++;
			}
			i++;
		}
		int N = i;
		for(i=0;i<N;i++){
			System.out.println(count[i]);
		}
	}

}

Measured memory_bytes: 20440
function main(input) {
    const s = input;
    var res = 0;

    for (var i = 0; i < 3; i++) {
        if (s[i] === '1') {
            res++;
        }
    }
    console.log(res);
}

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

Measured memory_bytes: 7372
def solve(P):
    A, B, C, D = P
    if A<B or D<B:
        return False
    if C >= B-1:
        return True
    g = gcd(B,D)
    return A%g + ((B-A%g-1)//g)*g <= C

from math import gcd

T = int(input())
for _ in range(T):
    P = map(int, input().split())
    print("Yes" if solve(P) else "No")

Measured memory_bytes: 66888
#include<stdio.h>
int main()
{
	int a[101][101]={0};
	int i,j,r,c;
	scanf("%d%d",&r,&c);
	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			scanf("%d",&a[i][j]);

		}
	}
	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			a[i][c]+=a[i][j];

		}
	}
	for(i=0;i<c;i++)
	{
		for(j=0;j<r;j++)
		{
			a[r][i]+=a[j][i];
			
		}
	}
	for(j=0;j<c;j++)
	{
		a[r][c]+=a[r][j];
	}
	for(i=0;i<r+1;i++)
	{
		for(j=0;j<c;j++)
		{
			printf("%d ",a[i][j]);

		}
		printf("%d\n",a[i][c]);
	}
return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int p[8];
	string str="1212141412121414";
	while(1){
		rep(i,0,8) cin>>p[i];
		if(cin.eof()) break;
		string tmp;
		int MIN=1e7;
		string ans;
		rep(i,0,8){
			tmp=str.substr(i,8);
			int dif=0;
			rep(j,0,8){
				if(p[j]>(int)(tmp[j]-'0')){
					dif+=p[j]-(int)(tmp[j]-'0');
				}
			}
			if(dif<MIN){
				MIN=dif;
				ans=tmp;
			}else if(dif==MIN){
				if(ans>tmp) ans=tmp;
			}
		}
		rep(i,0,8){
			if(i!=0) cout<<" ";
			cout<<ans[i];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1204
#include<stdio.h>

int main(){
  int H, W, i, j;
  char c;
  scanf("%d %d %c", &W, &H, &c);

  for ( i = 0; i < H; i++ ){
    for ( j = 0; j < W; j++ ){
      if ( i == 0 && j == 0 ||
                      i == 0 && j == W-1 ||
                      i == H-1 && j == 0 ||
           i == H-1 && j == W-1 ){
        printf("+");
      } else if ( i == 0 || i == H-1 ){
        printf("-");
      } else if ( j == 0 || j == W-1 ){
        printf("|");
      } else if ( i == H/2 && j == W/2 ){
        printf("%c", c);
      } else {
        printf(".");
      }
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	int Q=0,team=0;
	scanf("%d",&Q);
	int c[Q]={0},a[Q]={0},n[Q]={0};
	for(int i=0;i<Q;i++)
	{
		scanf("%d %d %d",&c[i],&a[i],&n[i]);
	}
	for(int i=0;i<Q;i++)
	{
		if(c[i]>0&&a[i]>0&&n[i]>0)
		{
			while(c[i]!=0&&a[i]!=0&&n[i]!=0)
			{
				c[i]=c[i]-1;a[i]=a[i]-1;n[i]=n[i]-1;
				team=team+1;
			}
		}
		if(c[i]>1&&a>0)
		{
			while(c[i]>=2&&a[i]!=0)
			{
				c[i]=c[i]-2;a[i]=a[i]-1;
				team=team+1;
			}
		}
		if(c[i]>2)
		{
			while(c[i]>=3)
			{
				c[i]=c[i]-3;
				team=team+1;
			}
		}
		printf("%d\n",team);
		team=0;
	}
}	


Measured memory_bytes: 3196
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] arr = reader.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int R = Integer.parseInt(arr[1]);
        System.out.println(10 <= N ? R : R + 100 * (10 - N));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
  if(s.at(1) == s.at(2) && s.at(0) == s.at(1)) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            double n = sc.nextDouble();
            if(n==-1.0) break;

            n = n * 2 * 2 * 2 * 2;
            if(n%1.0!=0){
                System.out.println("NA");
                continue;
            }

            String s = Integer.toBinaryString((int)n);
            if(s.length()>12){
                System.out.println("NA");
                continue;
            }
            String seisu = s.substring(0, s.length()-4);
            String syousu = s.substring(s.length()-4, s.length());
            while(seisu.length()!=8) seisu = "0" + seisu;
            System.out.println(seisu+"."+syousu);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 27908
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
inline int  in(){int n;scanf("%lld",&n);return n;}
inline void out(int n){printf("%lld\n",n);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;


signed main(){
    io();

    n = in();
    if(n < 1000){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }


    return 0;
}


Measured memory_bytes: 888
H, W = map(int, input().split())
S = [input() for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      bk = sum([t[j].count("#") for t in S[max(0,i-1):min(H,i+2)]])
      bk += S[i][max(0,j-1):min(W,j+2)].count("#")-1
      if bk == 1:
        print("No")
        exit()

print("Yes")


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int res = 0;
    for (int i = 0; i < 10; ++i) {
        int iid = s.find(to_string(i));
        if (iid == string::npos) continue;

        for (int j = 0; j < 10; ++j) {
            string sj = s.substr(iid + 1);
            int jid = sj.find(to_string(j));
            if (jid == sj.length() - 1) continue;
            if (jid == string::npos) continue;

            for (int k = 0; k < 10; ++k) {
                string sk = sj.substr(jid + 1);
                int kid = sk.find(to_string(k));
                if (kid != string::npos){
                    res++;
                }
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3744
/*
正在播放《フリージア》
1:21  ━━━━━━●─────   5:35
   ⇆   ◁   ❚❚   ▷   ↻
```````'`...```````''`````````````'````````````````'`.`''
```````''..`';;'```''```'''''''''''''`````````````````'':
.````''''':;;!!:````'````'''''''''''``````````````````'':
``''''''':;;;;;'```'``````''```````````____________```'':
`````````:;;!;'```````````'```````'```|   所以说   |'``'':
```````'|$&$%:````````````'```````````|不要停下来啊|''''':
````'''!$&&&|'```````````'''::''::''''/ （指AC）  |':'':::
````'':|&&&$!'`````'''''''::.....`;!;'/_________|''``'::
  ....'|&&@$!'........```:!;'....`:;:```````````````````'
..````;$&&&$!:''``````'':|%%!::;|%$$!::::::::''::::::::::
``````!&&@&&|:'````````':|$$$$$$$$$|:':::::::::::::::::::
`````:%&@@@@@@@@&&&@@@@&&&&@@@@@@@&&&|::::::::':::::::::;
`````.```':|$@@@@@@@@@@@@@@@@@@@@@@@@###@@&&$|;:::'::::::
````````````';|$&@@@@@@@@@###@@@@@@########@@@@$!''''::::
`````````..````:|%$@@@@@#########@#########@@@@&!''''::::
`````````````````:|&########################@@@$;::::::::
``````````````````:!$@########################@%;:::'::::
``````````..``````':|&#######################@@&!''''''::
''''::'''`.`''''''':|@#######################@@&|:'`.`';!
:::::::::``'''''';%@######################@@##@@&!::'';;;
::;::::::`.''''';%@@@@####################$%@##@@%;:'':;!
:;;;;::::``':;%@@@#########################&%&##@@|:'';;!
;;!;;;;;;'`::;%@#############################@@##@$!'';!!
;;;;;;;;:``':::::;|$@############################@$!'`;!!
::;;;;;;:'`'::::::;!$@#######################&&@$$$;``:;;
`````````..````````'|@#####################$;!$$$&@@|''':
'''''''''''''':'''''|@#########@&@##########@@####@@&%|!!
''''''''':'''::'':''!&########&!|&@##########&&####&%|!||
:::::'''::::::::::::!&########|:;|$@#########@&###&%||||!
:::::::'''''':::::::!&#######@!:;!!$@########@$&##@%||||!

                    だからよ...止まるじゃねえぞ
 */
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<double, int> PII;
const int N = 1000000 + 5;
const double eps = 1e-9;


int main() {
    string s;
    cin >> s;
    ll ans = 0;
    for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] > '5') {
            ans += '9' - s[i] + 1;
            if (i == 0)
                ans += 1;
            else if (s[i - 1] == '9') {
                int j = i - 1;
                while (j >= 0) {
                    if (s[j] == '9') {
                        s[j] = '0';
                        j--;
                    } else {
                        s[j] += 1;
                        break;
                    }
                }
                if (j < 0)
                    ans += 1;
            } else
                s[i - 1] += 1;
        } else if (s[i] == '5') {
            ans += '9' - s[i] + 1;
            if (i != 0 && s[i - 1] >= '5')
                s[i - 1] += 1;
        } else
            ans += s[i] - '0';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;





int main()
{
   
   
    int n, w;
    cin >> n >> w;
    vector<ll>p(w + 109);
    vector<int>a(n), b(n);
    for (int i = 1; i <= w; i++) {
        p[i] = -99999999999999;
        
    }
    p[0] = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        for (int j = w - x; j >= 0; j--) {
            p[j+x] = max(p[j+x], p[j] + y);
            ans = max(ans, p[j + x]);
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3964
h, w = map(int, input().split())

s = []*(h+2)
for i in range(h+2):
    s.append(['#']*(w+2))

for i in range(h):
    c = input()
    s[i+1][1:w+1] = c

for j in range(h+2):
    print(''.join(s[j]))

Measured memory_bytes: 3060
//
// Created on 2018-12-08.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<(n);++i)
#define RFOR(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


ll ans = INF;


//void callback(vl comb) {
//    ll max_el = *max_element(ALL(comb));
//    ll min_el = *min_element(ALL(comb));
//    ans = min(ans, abs(max_el-min_el));
//}
//
//void combination(const vector<ll>& seed, unsigned long target_size) {
//    vector<int> indices(target_size);
//    const unsigned long seed_size = seed.size();
//    int start_index = 0;
//    int size = 0;
//
//    while (size >= 0) {
//        for (int i = start_index; i < seed_size; ++i) {
//            indices[size++] = i;
//            if (size == target_size) {
//                vector<ll> comb(target_size);
//                for (int x = 0; x < target_size; ++x) {
//                    comb[x] = seed[indices[x]];
//                }
//                callback(comb);
//                break;
//            }
//        }
//        --size;
//        if (size < 0) break;
//        start_index = indices[size] + 1;
//    }
//}

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

    unsigned long N, K;
    cin >> N >> K;

    vl v;
    ll t;
    REP(_, N){cin >> t; v.emplace_back(t);}

    //combination(v, K);

    sort(ALL(v));

    REP(i,N-K+1){
        ans = min(ans,v[i+K-1]-v[i]);
    }


    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 1400
#include <iostream>

using namespace std;

int n, x, a;

int main(void)
{
	cin >> n >> x;
	int sum = 0;
	for(int i = 1; i <= n; i++){
		cin >> a;
		sum += a;
		if(sum > x){
			cout << i << endl;
			return 0;
		}
	}
	cout << n+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	cout << (n + k - 3) / (k - 1) << endl;

	return 0;
}

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

using namespace std;

int main() {

	long a,b;
	cin >> a >> b;

	long c,d;
	c = min(a, b);
	d = max(a, b);

	for (long i = 0; i < d; i++) {
		cout << c;
	}

	cout  << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		String bs=str.toUpperCase();
		String ss=str.toLowerCase();
		if(str.equals(bs))
		{
			System.out.println("A");
		}
		else if(str.equals(ss))
		{
			System.out.println("a");
		}
		sc.close();
	}
}


Measured memory_bytes: 35780
#include <stdio.h>


int main() {
	int H[50] = {};
	int W[50] = {};
	int n = 0;
	bool q=true;
	for (;;) {
		scanf("%d %d", &H[n], &W[n]);
		if (H[n] == 0)break;
		n++;
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < H[k]; i++) {
			for (int j = 0; j < W[k]; j++) {
				if (q) {
					printf("#");
					q = false;
				}
				else {
					printf(".");
					q = true;
				}
			}
			printf("\n");
			if (i%2==0)q = false;
			else q = true;
		}
		printf("\n");
		q = true;
	}

	return 0;
}

Measured memory_bytes: 2588
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  let height_list = [0];
  let current_height = 0;
  line.forEach(function(e, i){
      if (e == '\\') current_height -= 1
      else if (e == '_') current_height += 0
      else current_height += 1
      height_list.push(current_height);
  });

  // console.log(height_list.join(','));
  let sum = 0;
  let holes = [];
  for (;height_list.length > 1;) {
    let h = makeHole(height_list);
    if (h > 0) {
      sum += h;
      holes.push(h);
      // console.log(h, height_list.join(','));
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    if (begin <= list.reduce((a, b) => Math.max(a, b), -100000)) {
      area = 0;
      while (true) {
      if (list.length == 0 || begin <= list[0]) break;
        area += begin - list.shift();
      }
      return area;
    } else {
      return 0;
    }
}



Measured memory_bytes: 21052
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  if (a.at(n-1) - a.at(0) >= 2) {
    cout << "No" << endl;
    return 0;
  }
  if (a.at(n-1) - a.at(0) == 1) {
    int r = distance(a.begin(), lower_bound(a.begin(), a.end(), a.at(n-1)));
    int k = a.at(0);
    if (r <= k && k <= (n-r)/2 + r - 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }

  int k = a.at(0);
  if ((1 <= k && k <= n/2) || k == n-1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

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

int main(){
    int n;
    cin >> n;
    
    vector<int> a;
    for(int i = 0; i < n; i++){
        int z;
        cin >> z;
        z--;
        a.push_back(z);
    }
    
    int now = 0, c = 0;
    while(true){
        if(now == 1){
            cout << c;
            break;
        }
        if(c >= n){
            cout << -1;
            break;
        }
        c++;
        now = a[now];
    }
}


Measured memory_bytes: 892
#include <stdio.h>

void swap(int *a, int *b)
{
	int t = *a;
	*a = *b;
	*b = t;
}

int main(void)
{
	int a[128];
	int i, j;
	int n, c;

	while (scanf("%d", &n), n){
		for (i = 0; i < n; i++){
			scanf("%d", a + i);
		}

		c = 0;
		for (i = n - 1; i > 0; i--){
			for (j = 0; j < i; j++){
				if (a[j] > a[j + 1]) swap(a + j, a + j + 1), c++;
			}
		}
		printf("%d\n", c);
	}

	return (0);
}

Measured memory_bytes: 600
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := scanInt(), scanInt()
	type number struct{ a, b int }
	nums := make([]number, n)
	for i := range nums {
		nums[i].a, nums[i].b = scanInt(), scanInt()
	}

	sort.Slice(nums, func(i, j int) bool { return nums[i].a < nums[j].a })
	cnt := 0
	for _, num := range nums {
		if cnt+num.b >= k {
			fmt.Println(num.a)
			return
		}
		cnt += num.b
	}
}


Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//#define fr(i,j,k) for(int i=j;i<k;i++)
//#define f(n) fr(i,0,n)
//#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e11 + 7;
const int maxn = 2e5+5;
#include<atcoder/all>
using namespace atcoder;
void solve() {
    int n, m;
    cin >> n >> m;
    fenwick_tree<ll>b(n);
    for(int i = 0 ; i < n ; i++) {
        ll x;
        cin >> x;
        b.add(i,x);
    }
    while (m--) {
        int op;
        cin >> op;
        if (!op) {
            int p, x;
            cin >> p >> x;
            b.add(p,x);
        }
        else {
            int l, r;
            cin >> l >> r;
            cout << b.sum(l, r) << '\n';
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


Measured memory_bytes: 8252
#include <stdio.h>

#pragma GCC optimize ("Ofast", "unroll-loops")
#pragma GCC target ("arch=ivybridge")

int main() {
  
  	const int nmax = 204800, block = 2048, unrl = 16;
  	int a[nmax], b[nmax];
	int N, i, j, k, ans = 0;
  
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);

	for (i = 0; i + unrl <= N; i += unrl) {
		for (j = 0; j + block <= N; j += block) {
			for (k = j; k < block + j; k++) {

				ans ^= (a[i + 0] + b[k]) ^ (a[i + 1] + b[k]);
				ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
				ans ^= (a[i + 4] + b[k]) ^ (a[i + 5] + b[k]);
				ans ^= (a[i + 6] + b[k]) ^ (a[i + 7] + b[k]);
              	ans ^= (a[i + 8] + b[k]) ^ (a[i + 9] + b[k]);
				ans ^= (a[i + 10] + b[k]) ^ (a[i + 11] + b[k]);
				ans ^= (a[i + 12] + b[k]) ^ (a[i + 13] + b[k]);
				ans ^= (a[i + 14] + b[k]) ^ (a[i + 15] + b[k]);

			}
		}
	}

	for (i = 0; i < N / unrl * unrl; i++) {
		for (j = N / block * block; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}	
	for (; i < N; i++) {
		for (j = 0; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}

	printf("%d\n", ans);

	return 0;
}


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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define gofor(n) for(int i=0; i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD (int)10e9+7

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;
int a[200001];



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

    cin >> n;

    gofor(n)
        cin >> a[i];

    int curr = 1;
    gofor(n)
        curr=a[i]==curr?curr+1:curr;


    if(curr==1)
        cout << -1 << endl;
    else
        cout << n-curr+1 << endl;

    return 0;

}


Measured memory_bytes: 1024
if __name__ == '__main__':

    n = int(input())
    fs = []
    for i in range(n):
        vs = list(map(int, input().split()))
        fs.append(vs)
    ps = []
    for i in range(n):
        vs = list(map(int, input().split()))
        ps.append(vs)

    from itertools import product

    ans = -10 ** 10
    for decision in product([0, 1], repeat=10):
        if not any(decision):
            continue
        tans = 0
        for fv, pv in zip(fs, ps):
            c = 0
            for f, d in zip(fv, decision):
                c += f * d
            tans += pv[c]
        ans = max(ans, tans)
    print(ans)


Measured memory_bytes: 43356
package main
 
import (
	"fmt"
)
 
func main() {
	var n int
	fmt.Scan(&n)
 
	pay := 0
	mx := 0
	for i := 0; i < n; i++ {
		var p int
		fmt.Scan(&p)
 
		pay += p
		if p > mx {
			mx = p
		}
	}
	pay -= mx / 2
	fmt.Println(pay)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;





int main()
{
int n ;
cin>>n;
int ans = 0;
while(n--)
{
    int l ,r;
    cin>>l>>r;

    ans+=r-l+1;
}
cout<<ans<<endl;

 return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int m=max(max(a, b), max(a, c));
  int d=3*m-a-b-c;
  if(d%2==0)cout << d/2;
  else cout << (d+3)/2;
  return 0;
}

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


long long int f(long long int n) {
    long long int t = 0;
    while (n) {
        t++;
        n/=10;
    }
    return t;
}



int main() {
    ios::sync_with_stdio(false);
    long long int n;
    cin >> n;
    
    long long int digits = f(n);
    long long int first = n / (long long int)pow(10,digits-1);
    long long int num = (first+1)*(long long int)pow(10,digits-1);
    if ((num - 1) == n)
        cout << first + 9*(digits-1) << endl;
    else
        cout << first + 9*(digits-1) - 1 << endl;
    return 0;
}


Measured memory_bytes: 256