akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;

template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int n;
int a[MAXN];
int main()
{
    //~ freopen("file.in", "r", stdin);
    scanf("%d", &n);
	for(int i = 0; i < n; i ++)
		scanf("%d", a + i);
	int l = 0;
	ll cnt = 0, x = 0, p = 0;
	for(int i = 0; i < n; i ++){
		x ^= a[i];
		p += a[i];
		for(;l < n && x != p;)
		{
			x ^= a[l];
			p -= a[l ++];
		}
		cnt += i - l + 1;
		
	}
	cout << cnt;
}




Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a, b;
        a = Double.parseDouble(sc.next());
        b = Double.parseDouble(sc.next());

        int ans = (int)Math.ceil((a + b) / 2);
        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,n){
		int y,m,d,ans=0;
		scanf("%d%d%d",&y,&m,&d);
		if(m%2==1 || y%3==0) ans+=(21-d);
		else ans+=(20-d);
		m++;
		if(m==11) m=1,y++;
		while(m!=1){
			if(m%2==1 || y%3==0) ans+=20;
			else ans+=19;
			m++;
			if(m==11) m=1,y++;
		}
		while(y!=1000){
			if(y%3==0) ans+=200;
			else ans+=195;
			y++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> v(1e5 + 1);
  while (n--) {
    int a, b; cin >> a >> b;
    v[a].push_back(b);
  }

  lint res = 0;
  priority_queue<int> pq;
  for (int t = 1; t <= m; ++t) {
    for (int e : v[t]) {
      pq.push(e);
    }
    if (!pq.empty()) {
      res += pq.top();
      pq.pop();
    }
  }
  cout << res << '\n';
}

Measured memory_bytes: 5632
// Aizu 2049: Headstrong Student
// 2017.9.24 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 1000000
int tbl[MAX+2];

char buf[20], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

int main()
{
	int x, y, k, r;

	while (fgets(p=buf, 20, stdin) && *buf != '0') {
		x = getint(), p++, y = getint();
		k = gcd(x, y);
		x /= k, y /= k;
		memset(tbl, -1, sizeof(tbl));
		tbl[x] = 0;
		for (k = 1; ; k++) {
			x = (x<<3)+(x<<1);
			if ((r = x % y) == 0) {
				printf("%d 0\n", k);
				break;
			}
			if (tbl[r] >= 0) {
				printf("%d %d\n", tbl[r], k - tbl[r]);
				break;
			}
			tbl[r] = k, x = r;
		}
	}
	return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	for(int i=0,val;i<m;i++) {
		cin >> val;
		n -= val;
	}
	if(n < 0)	n = -1;
	cout << n << endl;
	return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, total = 0;
    cin >> n;

    vi a(n);
    rep(i, 0, n) {
        cin >> a[i];
        total += a[i];
    }

    int sum = 0, ans = INT_MAX;
    rep(i, 0, n) {
        sum += a[i];
        ans = min(ans, abs(sum - (total - sum)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//package bigneer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub

		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
//		int t=Integer.parseInt(br.readLine());
//		while(t-->0) {
			int n=Integer.parseInt(br.readLine());
			String q[]=br.readLine().split(" ");
//			int a=Integer.parseInt(q[0]);
//			int b=Integer.parseInt(q[1]);
//			System.out.println(a*b);
			long a[]=new long[n];
			for(int i=0;i<n;i++)
				a[i]=Long.parseLong(q[i]);
//			long p=1;
			int b=0;
			BigInteger p=new BigInteger("1");
			BigInteger p1=new BigInteger("1000000000000000000");
			for(int i=0;i<n;i++) {
				if(a[i]==0) {
					b=0;
					p=new BigInteger("0");
					break;
				}
				if(b!=1) {
				BigInteger w=new BigInteger(Long.toString(a[i]));
				p=p.multiply(w);
				if(p.compareTo(p1)==1)
					{b=1;
//					break;
					}
				}
//				if(p>Math.pow(10, 18)||p<0||p<a[i])
//					{b=1;
//				break;}
					}
//			System.out.println(b);
			if(b==1)
				System.out.println(-1);
			else
				System.out.println(p);
//			System.out.println();
//		}
	}

}


Measured memory_bytes: 54268
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;

char s[N];
int f[26];

int main() {
	scanf("%s", s);
	int n = strlen(s);
	for (int i = 0; i < n; ++i)
		f[s[i] - 'a'] += 1;
	long long sum = 1ll * n * (n + 1) / 2;
	for (int i = 0; i < 26; ++i) {
		sum -= 1ll * f[i] * (f[i] + 1) / 2;
	}
	cout << sum + 1 << endl;
}

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

using namespace std;


int main()
{
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int res = 0;
    for(int i = 0; i < n; i++)
    {
        set<char, greater<char>> ch;
        ch.insert(a[i]);
        ch.insert(b[i]);
        ch.insert(c[i]);
        res += ch.size() - 1;
    }
    cout << res;

    return 0;

}


Measured memory_bytes: 256
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for _ in range(A)] + [INF]
t = [-INF] + [int(input()) for _ in range(B)] + [INF]

for q in range(Q):
    x = int(input())
    y1 = bisect.bisect_right(s, x)
    y2 = bisect.bisect_right(t, x)
    res = INF
    # 最も近い神社の候補２つ
    for sx in [s[y1 - 1], s[y1]]:
        # 最も近い寺の候補２つ
        for tx in [t[y2 - 1], t[y2]]:
            # 神社、寺の順で訪れる場合
            d1 = abs(sx - x) + abs(tx - sx)
            # 寺、神社の順で訪れる場合
            d2 = abs(tx - x) + abs(sx - tx)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 90824
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a,b; cin >> a >> b;
    int ans = 0;
    rep(i,2){
        if(a > b){
            ans += a;
            a--;
        }else{
            ans += b;
            b--;
        }
    }
    ANS;
    
    return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    
    int ans = 0;
    for (int i = 0; i <= min(n, k); i++){
        for (int j = 0; n - j >= i && j + i <= min(n, k); j++){
            int sum = 0, rem = k - (j + i);
            vector<int> s;
            for (int idx = 0; idx < i; idx++){
                s.push_back(v[idx]);
                sum += v[idx];
            }
            
            for (int idx = 0; idx < j; idx++){
                s.push_back(v[n - idx - 1]);
                sum += v[n - idx - 1];
            }

            if (rem){
                sort(s.begin(), s.end());
                for (int idx = 0; idx < min(rem, (int) s.size()); idx++){
                    if (s[idx] < 0)
                        sum -= s[idx];
                    else
                        break;
                }
            }
            
            ans = max(ans, sum);
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll get_val(vector<ll>&ft,ll index)
{
  ll res=0;
  for(;index>=0;index=(index & (index+1))-1)
    res+=ft[index];
  return res;
}

void update(vector<ll>&ft,ll index,ll val)
{
  for(;index<(ll)ft.size();index|=index+1)
    ft[index]+=val;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    
    // Sieve();
   ll tests=1;
 // cin>>tests;
  // ll t=1;
    while(tests--)
    {  
     ll n,m,i,j,k;
     cin>>n>>m>>k;
     vector<ll>a(n),b(m),prea(n+1,0),preb(m+1,0);
     rep(i,0,n-1) cin>>a[i];
     rep(i,0,m-1) cin>>b[i];
     rep(i,1,n) prea[i]=prea[i-1]+a[i-1];
     rep(i,1,m) preb[i]=preb[i-1]+b[i-1];
     i=n;j=0;
     ll ans=0,cur=0;
     while(i>=0)
     {
      if(prea[i]+preb[j]<=k) {cur=i+j;ans=max(ans,cur);}
      while(j<=m && prea[i]+preb[j]<=k) j++;
      // cout<<"-->"<<i<<","<<j<<"\n";
      if(j>m || prea[i]+preb[j]>k) j--;
      if(j<0) j=0;
      if(prea[i]+preb[j]<=k)
      ans=max(ans,i+j);
      i--;
      // cout<<ans<<"\n";
     }
     
     cout<<ans;


    }

    return 0;
   }

Measured memory_bytes: 20360
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000001


int main(){

	string s;
	cin>>s;
	int ans = 0;
	for(int i=0;i<s.size();i++){
		ans += s[i]-'0';
	}
	if(ans%9==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

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

int prime(int a){
    for(int i=2;i<a;i++){
        if(a%i==0){return 0;}
    }
    return 1;
}





int main(void){
int x;
int i;
scanf("%d",&x);
for(i=x;;i++){
    if(prime(i)==0){continue;}
    else{printf("%d\n",i);return 0;}
}
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
    int H, W;
    while(true){
        cin >> H >> W;
            if (H == 0 && W == 0) 
                break;
        for (int now = 1; now < H+1; now++){
            if(now % 2 != 0){//奇数列だったら
                if (W % 2 == 0){//偶数行だったら
                    for (int i = 0; i < W/2; i++){
                       cout << "#" << ".";
                    }
                    cout << endl;
                }
                else if (W % 2 != 0){//奇数行だったら
                    for (int i = 0; i < W/2; i++){
                        cout << "#" << ".";
                    }
                    cout << "#" << endl;
                }
            }
            if(now % 2 == 0){//偶数列だったら
                if (W % 2 == 0){//偶数行だったら
                for (int i = 0; i < W/2; i++){
                       cout << "." << "#";
                    }
                    cout << endl;
                }
                else if (W % 2 != 0){//奇数行だったら
                    for (int i = 0; i < W/2; i++){
                        cout << "." << "#";
                    }
                    cout << "." << endl;
                }
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }

ll solve1(ll perimeter, int n, vector<ll> const & x) {
    ll dist = 0;
    {
        const int start = 0;
        int l = start + 1;
        int r = n;
        dist += x[start];
        while (l != r) {
            dist += x[l - 1] + perimeter - x[r - 1];
            -- r;
            if (l == r) break;
            dist += x[l] + perimeter - x[r];
            ++ l;
        }
    }

    ll answer = dist;
    vector<ll> acc(n + 1);
    partial_sum(ALL(x), acc.begin() + 1);

    REP (start, n - 1) {
        int last = start + (n - start) / 2;
        dist -= x[start];
        dist += x[last] - x[start];
        if ((n - start) % 2 == 0) {
            dist -= perimeter - x[last];
        } else {
            if (last != n - 1) {
                dist -= perimeter - x[last + 1];
            }
        }
        chmax(answer, dist);
    }
    return answer;

/*
    ll answer = 0;
    REP (start, n) {
        int l = start + 1;
        int r = n;
        ll acc = x[start];
        while (l != r) {
            acc += x[l - 1] + perimeter - x[r - 1];
            -- r;
            if (l == r) break;
            acc += x[l] + perimeter - x[r];
            ++ l;
        }
        chmax(answer, acc);
    }
    return answer;
*/
}

ll solve(ll perimeter, int n, vector<ll> const & x) {
    vector<ll> y(n);
    REP (i, n) y[i] = perimeter - x[n - i - 1];
    return max(solve1(perimeter, n, x), solve1(perimeter, n, y));
}

int main() {
    int l, n; cin >> l >> n;
    vector<ll> x(n);
    REP (i, n) cin >> x[i];
    cout << solve(l, n, x) << endl;
    return 0;
}


Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <cassert>
#include <string.h>
#include <cstdio>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-8;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9 + 7;
const LL MAX = 1 << 20;

int n;
int p[MAX];
int pos[MAX];
bool ok[MAX];
VI bad;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	cin >> n;
	FOR(i, 0, n)
	{
		cin >> p[i];
		pos[p[i]] = i;
	}

	FOR(i, 1, n)
		if (pos[i] > pos[i + 1])
		{
			ok[i] = 0;
			bad.push_back(i);
		}
		else
			ok[i] = 1;

	int ans = n - 1;

	FOR(x, 0, n + 1)
	{
		auto b = upper_bound(ALL(bad), x);
		if (b == bad.end())
		{
			ans = min(ans, x);
			continue;
		}

		int t = *b;
		int y = n - t;
		ans = min(ans, x + y);
		//cout << x << " : " << x + y << endl;
	}

	cout << ans << endl;
	cin >> n;
	return 0;
}

Measured memory_bytes: 4344
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  long long mount[n+1],dam[n+1];
  mount[0]=0;
  for(i=0;i<n;i++){
    scanf("%lld",&dam[i]);
    if(i%2==0)
      mount[0]+=dam[i];
    else
      mount[0]-=dam[i];
  }
  printf("%lld ",mount[0]);
  for(i=1;i<n;i++){
    mount[i]=2*dam[i-1]-mount[i-1];
    printf("%lld ",mount[i]);
  }
  return 0;
}


Measured memory_bytes: 2816
N,S=*$<
N=N.to_i
t=[?R,?G,?B].map{|c|S.count c}.inject:*
N.times{|i|(N+1-i>>1).times{|j|S[i]!=S[i+j]&&S[i+j]!=S[i+j*2]&&S[i+j*2]!=S[i]&&t-=1}}
p t

Measured memory_bytes: 14416
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()


abc = readInts()
k = readInt()

def ok(arr):
	return arr[0]<arr[1] and arr[1]<arr[2]

if ok(abc):
	print("Yes")
else:
	ans = 0
	arr = abc
	if 0 in arr:
		print("No")
		exit()

	while not ok(arr):
		if arr[0]>=arr[1]:
			arr[1]*=2
			ans+=1
		elif arr[1]>=arr[2]:
			arr[2]*=2
			ans+=1
	if k>=ans:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 9464
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

string s;
int ans=0;

int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i&&s[i]!=s[i-1]) ans++;
	}
	cout<<ans<<endl;
}

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

inline void f(int &a, int &b, int &c){
  int ta = a, tb = b, tc = c;
  a = (tb + tc)/2;
  b = (ta + tc)/2;
  c = (ta + tb)/2;
}

int main(){
  int a, b, c, ans = 0;
  std::cin >> a >> b >> c;
    if(a == b and b == c and c == a){
      if((a&1) == 0){
        std::cout << -1 << std::endl;
      }else{
        std::cout << ans << std::endl;
      }
      return 0;
    }
  while(((a&1) == 0) and ((b&1) == 0) and ((c&1) == 0)){
    ans++;
    f(a, b, c);
    if(a == b and b == c and c == a){
      if((a&1) == 0){
        std::cout << -1 << std::endl;
      }else{
        std::cout << ans << std::endl;
      }
      return 0;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x1,x2,y1,y2;
  cin>>x1>>y1>>x2>>y2;
  int na=abs(x1-x2),su=abs(y1-y2);
  if(x1<=x2){
      if(y1<=y2){
	  cout<<x2-su<<" "<<y2+na<<" "<<x1-su<<" "<<y1+na<<'\n';
      }
      else{
	  cout<<x2+su<<" "<<y2+na<<" "<<x1+su<<" "<<y1+na<<'\n';
      }
  }
  
  else{
      if(y1<=y2){
	  cout<<x2-su<<" "<<y2-na<<" "<<x1-su<<" "<<y1-na<<'\n';
      }
      else{
	  cout<<x2+su<<" "<<y2-na<<" "<<x1+su<<" "<<y1-na<<'\n';
      }
  }
  
  return 0;
}


Measured memory_bytes: 256
//Tanzim bin nasir
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
int main()
{
    int n,m;
    cin>>n>>m;
    vector<string> v;
    string s,ans;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    ans+=v[i];
    cout<<ans<<endl;
}


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

int dynamic(char X[], char Y[]) {
    int c[1001][1001], i, j, x, y, a;
    a = 0;

    x = strlen(X);
    y = strlen(Y);
    
    for (i = 0; i <= x; ++i) c[i][0] = 0;
    for (j = 0; j <= y; ++j) c[0][j] = 0;
    
    for (i = 1; i <= x; ++i) {
        for (j = 1; j <= y; ++j) {
            if (X[i-1] == Y[j-1]) {
                c[i][j] = c[i-1][j-1] + 1;
            }
            else{
                
                if (c[i-1][j] > c[i][j-1]) {
                    c[i][j] = c[i-1][j];
                }
                else{
                    c[i][j] = c[i][j-1];
                }
            }
            if (a < c[i][j]) a = c[i][j];
        }
    }
    return a;
}


int main() {
    int q, a, k, t[150];
    char X[1000], Y[1000];
    a = 0;
    scanf("%d", &q);
    
    for (k = 0; k < q; ++k) {
        scanf("%s", X);
        scanf("%s", Y);
        t[k] = dynamic(X, Y);
    }
    
    for (k = 0; k < q; ++k) {
        printf("%d\n", t[k]);
    }
    return 0;
}

Measured memory_bytes: 5652
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int v[100005];
int t[100005];
int main(void)
{
	int N, T;
	scanf("%d %d", &N, &T);
	for (int i = 1; i <= N; i++)
		scanf("%d", &v[i]);
	int max = v[N];
	int MAX = 0;
	for (int i = N-1; i >= 1; i--)
	{
		t[i] = max - v[i];
		if (t[i] > MAX)MAX = t[i];
		if (v[i] > max)max = v[i];
	}
	int ans = 0;
	for (int i = 1; i <= N; i++)
		if (t[i] == MAX)
			ans++;
	printf("%d\n", ans);
	return 0;
}

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

class Node{
public:
	int location;
	int p, l, r;
	Node() {}
};

class Point{
public:
	int id, x, y;
	Point() {}
	Point(int id, int x, int y): id(id), x(x), y(y) {}
	bool operator < (const Point &p) const{
		return id < p.id;
	}

	void print(){
		printf("%d\n", id);
	}
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2){return p1.x < p2.x;}
bool lessY(const Point &p1, const Point &p2){return p1.y < p2.y;}

int makekDTree(int l, int r, int depth){
	if(!(l < r)) return NIL;
	int mid = (l + r) / 2;
	int t = np++;
	if(depth % 2 == 0){
		sort(P + l, P + r, lessX);
	}else{
		sort(P + l, P + r, lessY);
	}
	T[t].location = mid;
	T[t].l = makekDTree(l, mid, depth + 1);
	T[t].r = makekDTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans){
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;

	if(sx <= x && x <= tx && sy <= y && y <= ty){
		ans.push_back(P[T[v].location]);
	}

	if(depth % 2 == 0){
		if(T[v].l != NIL){
			if(sx <= x) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if(T[v].r != NIL){
			if(x <= tx) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}else{
		if(T[v].l != NIL){
			if(sy <= y) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if(T[v].r != NIL){
			if(y <= ty) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
}

int main(){
	int x, y;
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d %d", &x, &y);
		P[i] = Point(i, x, y);
		T[i].l = T[i].r = T[i].p = NIL;
	}

	np = 0;

	int root = makekDTree(0, N, 0);

	int q;
	scanf("%d", &q);
	int sx, tx, sy, ty;
	vector<Point> ans;
	for(int i = 0; i < q; i++){
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for(int j = 0; j < ans.size(); j++){
			ans[j].print();
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 15848
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int A ,B;
    cin >> A >> B;
    if (A + B < 10){
        cout << A + B << endl;
    }
    else {
        cout << "error" << endl;
    }
return 0;
}


Measured memory_bytes: 3596
# key not available ""
n, w = [int(i) for i in input().split()]
weights = []
value = []
for _ in range(n):
    x, y = [int(i) for i in input().split()]
    weights.append(x)
    value.append(y)
dp = [[0 for i in range(w+1)] for j in range(n)]
for i in range(n):
    for j in range(1, w+1):
        if weights[i] <= j:
            dp[i][j] = max(value[i] + dp[i-1][j-weights[i]],dp[i-1][j])
        else:
            dp[i][j] = max(dp[i][j-1],dp[i-1][j])
print(dp[-1][-1])

## 0 1 2 3  4  5  6  7  8
#  0 0 0 30 30 30 30 30 30
#  0 0 0 30 50 50 50 80 80
#  0 0 0 30 50 60 60 80 90

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

class UnionFindTree
{
private:
    int n;
    int groupNum;       // グループの数
    vector<int> parent; // 親ノード
    vector<int> rank;   // 木の高さの上限
    vector<int> num;    // グループの要素数
    int find(int i){
        if(parent[i] == i)
            return i;
        else
            return parent[i] = find(parent[i]);
    }
public:
    UnionFindTree(int n){ // コンストラクタ
        this->n = n;
        groupNum = n;
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = i;
        rank.assign(n, 0);
        num.assign(n, 1);
    }
    void unite(int a, int b){ // aとbのグループを併合
        if((a = find(a)) != (b = find(b))){
            if(rank[a] < rank[b]){
                parent[a] = b;
                num[b] += num[a];
            }
            else{
                parent[b] = a;
                if(rank[a] == rank[b])
                    ++ rank[a];
                num[a] += num[b];
            }
            -- groupNum;
        }
    }
    bool same(int a, int b){ // aとbのグループが同じかを調べる
        return find(a) == find(b);
    }
    int getNum(){ // グループの数を返す
        return groupNum;
    }
    int getNum(int a){ // aのグループの要素数を返す
        return num[find(a)];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFindTree uft(n);
    for(int i=0; i<m; ++i){
        int a, b;
        cin >> a >> b;
        -- a;
        -- b;
        uft.unite(a, b);
    }

    int ans = uft.getNum() - 1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4492
n,m=map(int, input().split())
ab=[list(map(int, input().split())) for _ in range(m)]
ab.sort()
a=[ab[i][0] for i in range(m)]
b=[ab[i][1] for i in range(m)]
xy=[[a[0], b[0]]]
for i in range(1,m):
    if a[i]<xy[-1][1]:
        xy[-1][0],xy[-1][1]=a[i],min(xy[-1][1],b[i])
    else:
        xy.append([a[i], b[i]])
print(len(xy))

Measured memory_bytes: 29340
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> V[i];
    }
    for (int i = 0; i < N; ++i)
    {
        cin >> C[i];
    }

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        if (V[i] > C[i])
        {
            ans += V[i] - C[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 100, MAXI = N, D = 10;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 100, flag = 1;
//     cout << tc << "\n";
//     while (tc--)
//     {
    	
//     	int n = rand()%D + 1, m = rand()%D + 1;

//     	n = m = 100;

//     	cout << n << " " << m << "\n";

//     	for(int i=1;i<=n;i++)
//     	{
//     		for(int j=1;j<=m;j++)
//     		{
//     			cout << (char)(rand()%2 + '0');
//     		}
//     		cout << "\n";
//     	}

//      	cout << "~\n";
//     }
 
//     return 0;
// }
 
 
 
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 
 
 
//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long
#define mod (int)(1e9+9)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 100005





// // Driver code to test above functions
int32_t main()
{
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

   	
   	int dp[N];
   	for(int i=1;i<N;i++)
   		dp[i] = MAXI;

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

   	dp[1] = 0;
   	for(int i=1;i<=n;i++){
   		dp[i+1] = min(dp[i+1], dp[i] +  abs(a[i]-a[i+1]));
   		dp[i+2] = min(dp[i+2], dp[i] + abs(a[i]-a[i+2]));
   	}

   	cout << dp[n];
   	
   	
    
    return 0;
 
} 


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define N 100000
int data[N],dp[N];
main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++)cin>>data[i];
  dp[0]=0,dp[1]=abs(data[1]-data[0]);

  for(int i=2;i<n;i++){  
    int minm=1e9;
    for(int j=1;j<=k&&i-j>=0;j++){
      minm=min(minm,dp[i-j]+abs(data[i]-data[i-j]));
    }
    dp[i]=minm;
  }
  cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1792
a = list(map(str,(input())))
b = list(map(str,(input())))
c = list(map(str,(input())))
 
card = a[0]
 
for i in range(len(a) + len(b) + len(c)):
    if card == 'a':
        if a == []:
            print("A")
            break
        else:
            card = a[0]
            a.pop(0)
 
    elif card == 'b':
        if b == []:
            print("B")
            break
        else:
            card = b[0]
            b.pop(0)
 
    else:
        if c == []:
            print("C")
            break
        else:
            card = c[0]
            c.pop(0)

Measured memory_bytes: 9068
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 200 + 7, mod = 998244353, inf = 1e18, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n, m; 
int idd[MAXN];
int cnt[maxn][maxn];   
vector<int> gr[maxn]; 
vector<int> gays[maxn][maxn]; 
int mt[maxn]; 
int used[maxn]; 

bool dfs(int u) {
    if (used[u]) return false;
    used[u] = 1;
    for (auto v : gr[u]) {
        if (gays[u][v].empty()) continue; 
        if (mt[v] == -1 || dfs(mt[v])) {
            mt[v] = u; 
            return true; 
        }
    } 
    return false;
}

vector<int> ans[maxn]; 

void get() {
    for (int i = 0; i < n; ++i) {
        mt[i] = -1; 
    }        
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) used[j] = 0; 
        dfs(i); 
    }
    for (int i = 0; i < n; ++i) {
        ans[mt[i]].pb(gays[mt[i]][i].back());
        gays[mt[i]][i].pop_back();         
    }
}

int lol[maxn][maxn];

void solve() { 
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> cnt[i][j], --cnt[i][j]; 
            idd[i * m + j] = i; 
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            int x = idd[cnt[i][j]];
            gr[i].pb(x);
            gays[i][x].pb(j); 
        }
    }
    for (int i = 0; i < m; ++i) {
        get();               
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cout << cnt[i][ans[i][j]] + 1 << " "; 
            lol[i][j] = cnt[i][ans[i][j]] + 1; 
        }
        cout << '\n'; 
    }
    for (int i = 0; i < m; ++i) {
        vector<int> kek; 
        for (int j = 0; j < n; ++j) {
            kek.pb(lol[j][i]);
        }        
        sort(all(kek)); 
        for (int j = 0; j < n; ++j) {
            lol[j][i] = kek[j]; 
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cout << lol[i][j] << " ";
        }
        cout << '\n'; 
    }
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

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

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

    vector<pair<int, char> > a(S.size());
    for (int i = 0; i < S.size(); i++)
        a[i] = make_pair(i, S[i]);

    int Q;
    cin >> Q;

    int T, F;
    char C;
    int l = -1;
    int r = S.size();
    int dir = 0;
    for (int i = 0; i < Q; i++)
    {
        cin >> T;
        if (T == 1)
            dir = 1 - dir;
        else
        {
            if (T == 2)
                cin >> F >> C;

            if ((dir == 0 && F == 1) || (dir == 1 && F == 2))
            {
                a.push_back(make_pair(l, C));
                l -= 1;
            }
            else
            {
                a.push_back(make_pair(r, C));
                r += 1;
            }
        }
    }

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

    for (int i = 0; i < a.size(); i++)
    {
        int j = dir == 0 ? i : a.size() - i - 1;
        cout << a[j].second;
    }
    cout << endl;
}

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

using ll=long long;

const int MAX = 2200000;
const long long MOD = 1000000007;
long long INF = 90000000001000;


int main() {

    int n;cin >> n;
    int a[20],x[20][20],y[20][20];
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        for (int j = 1; j <= a[i]; ++j)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }
 int mx=0;
 for (int bit = 1; bit <(1 << n) ; ++bit)
    {
       int flag = 1,cnt = 0;
       for (int i = 1; i <= n; ++i)
       {
          if(bit & (1 << (i-1)))
         {
            cnt++;
            for (int j = 1; j <= a[i]; ++j)
            {
                if(y[i][j]^((bit>>(x[i][j]-1))&1)) {cnt=0;flag = 0;}
                if(y[i][j]^((bit>>(x[i][j]-1))&1)) {cnt=0;flag = 0;}
            }

          }
          else continue;
       }
       if(flag) {mx = max(mx,cnt);}


    }   

cout << mx;
return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int ans = 0;
        if (b >= a) {
            ans = b - a <= w ? 0 : b - a - w;
        } else {
            ans = a - b <= w ? 0 : a - b - w;
        }
        System.out.println(ans);
    }
}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 998244353;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());


unordered_map<ll, ll> minvmap;
ll minv(ll a, ll m) {
  auto k = a; auto p = minvmap[a]; if (p != 0) return p;
  ll b = m, u = 1, v = 0;
  while (b) { ll t = a/b; swap(a -= t*b, b); swap(u -= t*v, v); }
  p = (u%m+m)%m; minvmap[k] = p; return p;
}
struct mint {
    ll x;
    mint():x(0){}
    mint(ll x):x((x%mod+mod)%mod){}
    mint& fix() { x = (x%mod+mod)%mod; return *this;}
    mint operator-() const { return mint(0) - *this;}
    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){ (x*=minv(a.x, mod))%=mod; return *this; }
    mint operator+(const mint& a)const{ return mint(*this) += a;}
    mint operator-(const mint& a)const{ return mint(*this) -= a;}
    mint operator*(const mint& a)const{ return mint(*this) *= a;}
    mint operator/(const mint& a)const{ return mint(*this) /= a;}
    bool operator<(const mint& a)const{ return x < a.x;}
    bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

int MAXN = 3000000;
// factorial
vector<mint> fact(MAXN+1);
vector<mint> inv(MAXN+1);
void init() {
  fact[0] = 1;
  for(int i=1; i<=MAXN; i++) fact[i] = fact[i-1]*i;
  inv[MAXN] = mint(1)/fact[MAXN];
  for(int i=MAXN-1; i>=0; i--) inv[i] = inv[i+1]*(i+1);
}

// nCr
mint comb(int n, int r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n]*inv[r]*inv[n-r];
}

signed main() {
  SPEED;
  int n, m; cin >> n >> m;
  init();

  mint all = comb(3*m+n-1, n-1);

  mint ng1 = 0;
  for(int i=m-1; i>=0; i--) {
    mint tmp = comb(i+n-2, n-2);
    ng1 += tmp*n;
  }

  mint ng2 = 0;
  for(int i=m+1; i<=n; i++) {
    if ((3*m-i)%2!=0) continue;
    int r = (3*m-i)/2;
    if (r<0) continue;
    mint tmp = comb(r+n-1, n-1);
    tmp *= comb(n, i);
    ng2 += tmp;
  }
  debug(ng2.x);
  cout << all-ng1-ng2 << endl;

}

Measured memory_bytes: 47104
#include<iostream>

int main(){

    int N;
    std::cin >> N;

    int n = N / 1000; 
    int mod = N % 1000;

    if(mod == 0){
        std::cout << 0 << std::endl; 
    }else{
        std::cout << 1000 - mod << std::endl;
    }

}

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=100010;
int a[N];
inline bool Main(){
	int n=ni,mx=0,mn=N;
	for(int i=1;i<=n;apmax(mx,a[i]=ni),apmin(mn,a[i]),i++);
	if(mx==mn)return mx==n-1||n>=(mx<<1);
	if(mn+1<mx)return false;
	int cnt=0;
	for(int i=1;i<=n;i++){
		cnt+=a[i]==mn;
	}
	return mx>cnt&&n-cnt>=((mx-cnt)<<1);
}
int main(){
	puts(Main()?"Yes":"No");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
   
#define Komachi is retarded
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define bcnt __builtin_popcount
#define clz __builtin_clz
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define LB lower_bound
#define UB upper_bound
#define IN insert
#define rp (p<<1|1)
#define lson l,mid,lp
#define rson mid+1,r,rp
#define LL long long
#define uLL unsigned long long
#define PII pair<int,int>
#define DB double
#define EPS 1e-6
#define INF 0x3f3f3f3f
#define debug(a,p) cerr<<a<<p;
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;i++)
#define DREP(i,a,b) for(int i=(a),i##_end_=(b);i>i##_end_;i--)
  
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0;}
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0;}
 
template<class T>void Rd(T &res){
    char c;res=0;
    while((c=getchar())<48);
    do res=(res<<3)+(res<<1)+(c^48);
    while((c=getchar())>47);
}
 
template<class T>void pf(T res){
    if(res<0)putchar('-'),res=-res;
    else if(!res){putchar('0');return ;}
    static int stk[24],tp;
    for(tp=0;res;res/=10)stk[tp++]=res%10;
    while(tp)putchar(stk[--tp]^48);
}

#define M 50

LL C[M][M],Ans;
int a,b,n,p;
int main(){
    Rd(n);Rd(p);
    REP(i,0,n){
        int x;Rd(x);
        if(x&1) a++;
        else b++;
    }
	
	C[0][0]=C[1][0]=C[1][1]=1LL;
    REP(i,1,M){
        C[i][0]=C[i][i]=1LL;
        REP(j,1,i) C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
    
    Ans=0;
    
    for(int i=p;i<=a;i+=2)Ans+=C[a][i];
    
    Ans*=1ll<<b;
    pf(Ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
const int maxn = 100005;
const int inf = 1e9;

int main(){__
	int x;
	cin >> x;
	if(!x) cout << "1\n";
	else cout << "0\n";
	return 0;
}


Measured memory_bytes: 3604
//解説みた
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}


ll dfs(ll N, ll a, ll b, ll c, vector<ll> l, ll k, ll la, ll lb, ll lc)
{
  if(k == N) {
    ll mp = abs(a - la) + abs(b - lb) + abs(c - lc) - 30;
    if(la * lb * lc == 0) mp = INF;
    return mp;
  }
  ll r0, r1, r2, r3;
  r0 = dfs(N, a, b, c, l, k + 1, la, lb, lc);
  r1 = dfs(N, a, b, c, l, k + 1, la + l[k], lb, lc) + 10;
  r2 = dfs(N, a, b, c, l, k + 1, la, lb + l[k], lc) + 10;
  r3 = dfs(N, a, b, c, l, k + 1, la, lb, lc + l[k]) + 10;
  return min(min(r0, r1), min(r2, r3));
  
}


void solve()
{
  ll N; cin >> N;
  ll a, b, c; cin >> a >> b >> c;
  vector<ll> l(N); rep(i, N) cin >> l[i];
  ll ans = dfs(N, a, b, c, l, 0, 0, 0, 0);
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3712
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            tmp = 500*i+100*j+50*k
            if tmp==x:
                ans+=1

print(ans)

Measured memory_bytes: 9084
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, m, c = MAP()
b = LIST()
ans = 0
for _ in range(n):
    a = LIST()
    tmp = c
    for i in range(m):
        tmp += a[i] * b[i]
    if tmp > 0:
        ans += 1
print(ans)


Measured memory_bytes: 5148
n = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
#a = list(input())
#a = int(input())
r = 0

for i in range(1, len(a)):
    #print("i", i)
    if (a[i] - a[i-1]) == 1:
        #print("b", b[a[i-1]-1])
        r += b[a[i-1]-1]
        #print("c", c[a[i-1]-1])
        r += c[a[i-1]-1]
    else:
        r += b[a[i-1]-1]
       # print("b", b[a[i-1]-1])
    if i == (len(a)-1):
        r += b[a[i]-1]
print(r)

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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

ll f(ll a, ll b, ll x) {
  return floor(a * x / (double) b) - a * floor(x / (double) b);
}

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

  ll a, b, n, mv = 0, v;
  cin >> a >> b >> n;

  if (b <= n)
    cout << f(a, b, b - 1) << endl;
  else
    cout << f(a, b, n) << endl;

  return 0;
}

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

#define int long long 

main()
{
  int N, K;
  int cnt[100005] = {};

  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    cnt[A] += B;
  }
  
  int sum = 0;
  for(int i = 1; i < 100005; i++) {
    sum += cnt[i];
    if(sum >= K) {
      cout << i << endl; break;
    }
  }

  return (0);
}


Measured memory_bytes: 1024
from itertools import product
n=int(input())
m=[]
for i in range(n):
  a=int(input())
  t=[-1]*n
  for j in range(a):
    each=list(map(int,input().split()))
    t[each[0]-1]=each[1]
  m.append(t)

ans = 0
prod=list(product(range(2),repeat=n))
for i in range(len(prod)):
  flag=1
  for j in range(n):
    if prod[i][j] == 1:
      for k in range(n):
        if m[j][k] != -1 and m[j][k] != prod[i][k]:
          flag = 0
          break
      if flag == 0:
        break
  if flag:
    ans = max(ans, sum(prod[i]))
  
print(ans)

Measured memory_bytes: 8892