akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  tourist
 *    created: 29.12.2018 16:47:13       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  if (k == 1) { cout << "1\n1\n"; return 0; }
  if (k == 5) { cout << "5\n1 2 3 4 5\n1 2 3 4 5\n1 2 3 4 5\n1 2 3 4 5\n1 2 3 4 5\n"; return 0; }
  int n = 2;
  while (2 * n < k) {
    n += 2;
  }
  vector<vector<int>> a(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = j + 1;
      if ((i + j) % 2 == 0) {
        a[i][j] += n;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    rotate(a[i].begin(), a[i].end() - (i / 2 * 2), a[i].end());
  }
  int x = 2 * n;
  int have = 2 * n;
  while (have > k) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (a[i][j] >= x) a[i][j]--;
    x -= 2;
    have--;
  }
  cout << n << '\n';
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j > 0) cout << " ";
      cout << a[i][j];
    }
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

int main(void){
  int N, i, j;
  int tmp = 0;
  int temp = 0;
  scanf("%d", &N);
  int a[N];
  for(i = 0; i < N; i++){
    scanf("%d", &a[i]);
  }
  for(i = 0; i < N - 1; i++){
    for(j = N - 1; j > i; j--){
      if(a[j - 1] < a[j]){
        tmp = a[j];
        a[j] = a[j - 1];
        a[j - 1] = tmp;
      }
    }
  }
  for(i = 0; i < N; i++){
    if(i % 2 == 0)
    temp += a[i];
    else
    temp -= a[i];
  }
  printf("%d", temp);

}

Measured memory_bytes: 128
import * as fs from 'fs';

//in
// 3
// 3 1 2
//out
// 11
const main = (inp: string) => {
    const n: number = parseInt(inp.split('\n')[0]);
    const d: number[] = inp.split('\n')[1].split(' ').map(a => parseInt(a));

    let cur: number = 1;
    let ans: number = 0;
    for (let i: number = 0; i < n; i++) {
        for (let j: number = cur; j < n; j++) {
            ans += d[i] * d[j];
        }
        cur++;
    }
    console.log(ans);
};

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


Measured memory_bytes: 7372
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    H,W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))
    res = []
    for i in range(N):
        for _ in range(a[i]):
            res.append(i+1)
    for i in range(H):
        if  i%2==0:
            b = res[i*W:(i+1)*W]
            print(' '.join(map(str, b)))
        else:
            b = res[i*W:(i+1)*W]
            b = b[::-1]
            print(' '.join(map(str, b)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>

int main(){
    int N,sum=0;
    std::cin >> N;
    int L[N*2];
    for(int i=0; i<N*2; ++i) std::cin >> L[i];
    std::sort(L,L+N*2);
    for(int i=0; i<N*2; i+=2) sum += L[i];
    std::cout << sum;
}

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

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
ll mod = 1e9 + 7;
ll binpow(ll u, ll p){
        if (p == 0) return 1;
        if (p == 1) return u % mod;
        ll t = binpow(u, p / 2) % mod;
        if (p & 1) return t * t % mod * u % mod;
        return t * t % mod;
}
map<pair<ll, ll>, pair<ll, ll>> mem;
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("BONUS.INP", "r")){
                freopen("BONUS.INP", "r", stdin);
                freopen("BONUS.OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        ll add = 0, ans = 1;
        for (int i = 1; i <= n; i++){
                ll a, b;
                cin >> a >> b;
                if (!a && !b) {
                        add++;
                        continue;
                }
                ll gcd = __gcd(a, b);
                gcd = abs(gcd);
                a = a / gcd;
                b = b / gcd;
                if (b < 0) a = -a, b = -b;
                if (a <= 0){
                        mem[{b, -a}].first++;
                } else {
                        mem[{a, b}].second++;
                }
        }
        for (auto j : mem) ans = ans * (binpow(2ll, j.second.second) + binpow(2ll, j.second.first) - 1 + mod) % mod;
        cout << (ans + add - 1 + mod) % mod;
}


Measured memory_bytes: 19252
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int x, y, z;
	int s, ans;
	scanf("%d", &x);
	ans = (x - 1) / 2;
	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	ll n,k,c;
  cin >> n >>k;
  vector<pair<ll,ll>> p(n);
  ll a[n],b[n];
  for(long long int i=0;i<n;i++){
    cin >>a[i] >> b[i];
    p[i]=make_pair(a[i],b[i]);
  }
  
  sort(p.begin(),p.end());
  
  for(long long int i=0;i<n;i++){
    
    if(k<=p[i].second){
      c += k*p[i].first;
      
      cout << c << endl;
      return 0;
    }
     else{
       k-=p[i].second;
       c+= p[i].first*p[i].second;
    }
  }
}


Measured memory_bytes: 3328
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
  
int main(){
  int N,a,b,c,d;
  cin>>N;
a=N/1000;
b=(N/100)%10;
c=(N/10)%10;
d=N%10;
if(a==b&&b==c){
    cout<<"Yes"<<endl;
    
}
else if(b==c&&c==d){
    cout<<"Yes"<<endl;
    
}
else{
    cout<<"No"<<endl;
}

}

Measured memory_bytes: 256
s=input()

if s=='SUN':
    print(7)
elif s=='MON':
    print(6)
elif s=='TUE':
    print(5)
elif s=='WED':
    print(4)
elif s=='THU':
    print(3)
elif s=='FRI':
    print(2)
elif s=='SAT':
    print(1)


Measured memory_bytes: 2940
N = int(input())
S = input()

# 白→黒　が許容される状態

ans = N + 1

# 所与→全黒
ans = S.count(".")
prev = ans

for i in range(N):
	if S[i] == "#":
		now = prev + 1
	else:
		now = prev - 1


	if now < ans:
		ans = now
	prev = now

print(ans)


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int x;

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

	cin >> x;
	cout << 360/__gcd(360, x) << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include<string>
using namespace std;
int main(){

    string a;
    cin>>a;
    int aa;
    int h,hlen,hh;
    h=a[0]-'0';
    aa=stoi(a);
    
    hlen=a.length();
    hh=0;
    
    for(int i=0;i<hlen;i++){
        hh+=h*pow(10,i);
    }
    
    
   
    if(aa<=hh){
        cout<<hh<<endl;
    }else{
        hh=0;
        h=h+1;
        for(int i=0;i<hlen;i++){
            hh+=h*pow(10,i);
        }
        cout<<hh<<endl;
    }
    
        return 0;
    }

Measured memory_bytes: 384
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) x.begin(),x.end()
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
vector<ll> vi;
/*--------------------template--------------------*/

int main() {
	cin >> s;
	REP(i, s.size()) {
		char t = s[i];
		vc.push_back(t);
	}
	sort(ALL(vc));
	REP(i, s.size()-1) {
		if (vc[i] != vc[i + 1]) {
			sum++;
		}
		i++;
	}
	if (s.size() % 2 == 1) {
		sum++;
	}
	if (sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 384
#include<stdio.h>
#define N 100001
typedef struct{
  int f;
  int p;
  int d;
  int k;

} NODE;
int Cnt(NODE *,int,int);
int main(){
  int n,id,k,c[N][11],i,j;
  NODE T[N];
  for(i=0;i<N;i++){
    T[i].f=0;
    T[i].p=-1;

      }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&id);
    T[id].f=1;
    scanf("%d",&T[id].k);
    if(T[id].k>0)
      T[id].f=2;
    for(j=0;j<T[id].k;j++){
      scanf("%d",&c[id][j]);
      T[c[id][j]].p=id;
	}
  }
  for(i=0;i<N;i++){
    if(T[i].f==0)
      continue;
     T[i].d=Cnt(T,i,0);
    if(T[i].p==-1)
      T[i].f=3;
  }
  for(i=0;i<N;i++){
    if(T[i].f==0)
      continue;
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,T[i].d);
    if(T[i].f==1)
      printf("leaf, [");
    else if(T[i].f==2)
      printf("internal node, [");
    else
      printf("root, [");
    for(j=0;j<T[i].k;j++){
      if(j!=0) printf(" ");
      printf("%d",c[i][j]);
      if(j!=T[i].k-1)
	printf(",");
	}
    printf("]\n");
  }
    



}
int Cnt(NODE T[],int i,int cnt){
  if(T[i].p==-1)
    return cnt;
  else
    return Cnt(T,T[i].p,cnt+1);

}



Measured memory_bytes: 3724
//created by missever

#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
typedef long long LL;


int main(){
    int n,k,i,x;
    scanf("%d%d",&n,&k);
    int g = 0;
    int m = 0;
    for(i = 0;i < n; i++) {
        scanf("%d",&x);
        g = __gcd(x,g);
        m = max(m,x);
    }
    if(m >= k && (m - k) % g == 0) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
	return 0;
}


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

int main(){
	int N; cin >> N;
	vector<pair<int, int>> c(N);
	for(int i=0; i<N; i++){
		cin >> c[i].first;
	}
	for(int i=0; i<N; i++){
		cin >> c[i].second;
	}
	int m = 1e9;
	for(int i=0; i<(1<<N); i++){
		vector<pair<int, int>> arr0, arr1;
		int e[N];
		for(int j=0; j<N; j++){
			if(i & (1<<j)){
				e[j] = 1-(j%2);
				if(e[j] == 1) arr1.push_back({c[j].second, j});
				else arr0.push_back({c[j].second, j});
			}else{
				e[j] = j%2;
				if(e[j] == 1) arr1.push_back({c[j].first, j});
				else arr0.push_back({c[j].first, j});
			}
		}
		if(((N+1)/2) == arr0.size()){
			sort(arr0.begin(), arr0.end());
			sort(arr1.begin(), arr1.end());
			vector<pair<int, int>> x;
			for(int j=0; j<N; j++){
				if(j%2==0) x.push_back({arr0[j/2].first, arr0[j/2].second});
				else x.push_back({arr1[j/2].first, arr1[j/2].second});
			}
			int f = 0;
			for(int j=0; j<N-1; j++){
				if(x[j].first > x[j+1].first) f = 1;
			}
			int ans = 0;
			if(!f){
				for(int j=0; j<N; j++){
					for(int k=j+1; k<N; k++){
						if(x[j].second > x[k].second) ans++;
					}
				}
				if(m > ans) m = ans;
			}
		}
	}
	if(m==1e9) cout << -1 << endl;
	else cout << m << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()

    println(problem136_a(a, b, c))
}

fun problem136_a(a: Int, b: Int, c: Int): Int {

    val capa = a - b
    return if (c - capa > 0) {
        c - capa
    } else {
        0
    }
}

Measured memory_bytes: 29604
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
const long long mod=1000000007;
typedef long long ll;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<max(b+c-a,0)<<endl;
}


Measured memory_bytes: 256
/*
    author:@bhaskar_8998
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;  
typedef long long i64;
typedef vector<int> vi;
typedef vector<long> vl;
typedef pair<int,int>pii;
#define all(A) (A).begin(),(A).end()
#define pb push_back
#define MOD 1000000007
#define fastio() {ios_base::sync_with_stdio(false);cin.tie(NULL);}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    fastio();
    i64 ss[31];
    for(int i=1,ts=2;i<=30;i++){
        ss[i]=ts;
        ts*=2;
    }
    clock_t beg=clock();
    int t=1;
    // cin>>t;
    while(t--){
        string s;
        cin>>s;
        if(s=="ABC")cout<<"ARC";
        else cout<<"ABC";
    }
    clock_t end=clock(); 
    fprintf(stderr, "\n%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}


    

Measured memory_bytes: 3816
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);


int main(){
  int A, B, C; cin >> A >> B >> C;
  if (A <= C && C <= B){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    int N, M; cin >> N >> M;
    vector<bool> A(N*N), B(M*M);
    REP(i, N) REP(j, N) {
        char c; cin >> c;
        A[i*N+j] = c == '#';
    }
    REP(i, M) REP(j, M) {
        char c; cin >> c;
        B[i*M+j] = c == '#';
    }
    REP(i, N-M+1) REP(j, N-M+1) {
        REP(k, M) REP(l, M) {
            if (A[(i+k)*N+(j+l)] != B[k*M+l]) {
                goto NEXT;
            }
        }
        cout << "Yes" << endl;
        return 0;
NEXT:
        ;
    }
    cout << "No" << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int ans = (n + 1) / 2;
    cout << ans << endl;
}

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

#define EPS 1e-8

using LLI = long long int;

int N;
int Q;
LLI L[114];
double X[114];
double Y[114];
double Z[114];
double R[114];

int main() {
  scanf("%d%d", &N, &Q);
  for (int i=0; i<N; i++) {
    scanf("%lf%lf%lf%lf%lld", &X[i], &Y[i], &Z[i], &R[i], &L[i]);
  }

  while (Q--) {
    double sx, sy, sz;
    double dx, dy, dz;
    scanf("%lf%lf%lf%lf%lf%lf", &sx, &sy, &sz, &dx, &dy, &dz);
    LLI ans = 0;
    for (int j=0; j<N; j++) {
      double low = 0;
      double high = 1;
      for (int i=0; i<60; i++) {
        double midl = (low*2+high)/3;
        double midr = (low+high*2)/3;
        double xl = sx*midl + dx*(1-midl);
        double yl = sy*midl + dy*(1-midl);
        double zl = sz*midl + dz*(1-midl);
        double dl = (X[j]-xl)*(X[j]-xl) + (Y[j]-yl)*(Y[j]-yl) + (Z[j]-zl)*(Z[j]-zl);
        double xr = sx*midr + dx*(1-midr);
        double yr = sy*midr + dy*(1-midr);
        double zr = sz*midr + dz*(1-midr);
        double dr = (X[j]-xr)*(X[j]-xr) + (Y[j]-yr)*(Y[j]-yr) + (Z[j]-zr)*(Z[j]-zr);
        if (dl > dr) low = midl;
        else high = midr;
      }

      double mid = low;
      double x = sx*mid + dx*(1-mid);
      double y = sy*mid + dy*(1-mid);
      double z = sz*mid + dz*(1-mid);
      double d = (X[j]-x)*(X[j]-x) + (Y[j]-y)*(Y[j]-y) + (Z[j]-z)*(Z[j]-z);
      if (-EPS <= R[j]*R[j]-d) ans += L[j];
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 3224
def main():
    # 下、右、上、左
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    dot = "." * (W + 2)
    s = [dot]
    s += ["." + input() + "." for i in range(H)]
    s.append(dot)
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "#" and\
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()


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

#define forn(i,n) for(int i=0;i <int(n);++i)
#define forsn(i,s,n) for(int i=s;i <int(n);++i)

int gcd(int a, int b){
	return b ? gcd(b, a%b) : a;
}

struct vec {
	int x, y;
	int operator ^ (vec const& o) const {
		return x*o.y - y*o.x;
	}
	int operator * (vec const& o) const {
		return x*o.x + y*o.y;
	}
	vec operator - (vec const& o) const {
		vec res = *this;
		res.x -= o.x; res.y -= o.y;
		return res;
	}
	int n2 () const {
		return *this * *this;
	}
};

bool bad (vec const& a, vec const& b, vec const& c){
	vec d1 = b-c;
	vec d2 = a-c;

	int cross = d1 ^ d2;
	int dot   = d1 * d2;

	return cross != 0 ? cross > 0 : dot < 0;
}

int main () {
	int n;
	cin >> n;
	vector<vec> ps(n);
	forn(i,n)
		cin >> ps[i].x >> ps[i].y;

	auto it = min_element(ps.begin(), ps.end(), [](vec &l, vec &r) {
		// bottommost, break tie by taking leftmost
		return l.y != r.y ? l.y < r.y : l.x < r.x;
	});

	swap(ps[0], *it);

	sort(ps.begin()+1, ps.end(), [&](vec& l, vec& r){
		vec d1 = l-ps[0];
		vec d2 = r-ps[0];
		int cross = d1 ^ d2;
		// could be closest just as well, we just need to pick one.
		bool farthest = d2.n2() < d1.n2();
		return cross != 0 ? cross > 0 : farthest;
	});

	{
		// fix up colinear points
		int i = 1;
		vec d1 = ps[1] - ps[0];
		while(1){
			if(i >= n) break;
			vec di = ps[i] - ps[0];
			if((di^d1) != 0) break;
			i++;
		}
		reverse(ps.begin()+1, ps.begin()+i);
	}

#ifdef DEBUG
	for(auto v : ps){
		cerr << v.x << ' ' << v.y << '\n';
	}
#endif

	ps.push_back(ps[0]);
	vector<vec> ch;
	ch.push_back(ps[0]);
	forsn(i,1,n+1){
		ch.push_back(ps[i]);
		while(ch.size() >= 3 && bad(ch[ch.size()-3], ch[ch.size()-2], ch[ch.size()-1])){
			ch.pop_back();
			ch.back() = ps[i];
		}
	}
	ch.pop_back();

#ifndef DEBUG
	cout << ch.size() << '\n';
#endif
	for(auto v : ch){
		cout << v.x << ' ' << v.y << '\n';
	}

}


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N;i++)
        cin >> A.at(i);
    sort(A.begin(), A.end());
    int x, y;
    x = 0, y = 0;
    for (int i = 0; i < N; i++){
        if (i % 2 == 0){
            x += A.at(N - i - 1);
        }
        else {
            y += A.at(N - i - 1);
        }
    }
    cout << x - y << endl;
}

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

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int mi = 1e9, ma = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mi = min(mi, a[i]);
    ma = max(ma, a[i]);
  }
  if (ma - mi >= 2) {
    cout << "No" << endl;
  } else if (ma - mi == 0) {
    if (n == a[0] + 1) {
      cout << "Yes" << endl;
    } else if (a[0] * 2 <= n) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else if (ma - mi == 1) {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] == mi)
        ans++;
    }
    if (ans > mi) {
      cout << "No" << endl;
    } else if ((mi + 1 - ans) * 2 <= n - ans) {
      if (n - ans == 1)
        cout << "No" << endl;
      else
        cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


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

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

Measured memory_bytes: 256
package main
import (
  "fmt"
)
func main() {
  var s string
  fmt.Scan(&s)
  result := "Yes"
  for i, char := range s {
    if i%2 == 0 && char == 'L' {
      result = "No"
      break
    }
    if i%2 == 1 && char == 'R' {
      result = "No"
      break
    }
  }
  fmt.Println(result)
}

Measured memory_bytes: 512
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a = input()
b = input()

if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
	print("YES")
else:
	print("NO")


Measured memory_bytes: 5400
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

struct edge{
    ll from, to, cost;
    edge(ll s, ll d, ll w) : from(s), to(d), cost(w){}
    
    bool operator < (const edge& x) const {
        return cost < x.cost;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, H, W;
    cin >> N >> H >> W;
    vector<edge> x,y;

    UnionFind uf(H + W + 10);

    REP(i,N){
        ll R, C, A;
        cin >> R >> C >> A;
        x.emplace_back(R, C+H, -A);
    }

    sort(x.begin(), x.end());
    
    ll ans = 0;

    REP(i,N){
        if(!uf.issame(x[i].from, x[i].to)){
            ans += x[i].cost;
            uf.unite(x[i].from, x[i].to);
        }
        else{
            if(!uf.issame(x[i].from, 0)){
                ans += x[i].cost;
                uf.unite(x[i].from,0);
            }
        }
    }
    cout << ans * (-1) << endl;
}


Measured memory_bytes: 5748
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N;
vi vec;

int main(){
    cin >> N;

    vec.resize(N,0);

    rep(i, N) cin >> vec[i];

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

    cout << vec.back() - vec.front() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const int MAX_NM = 1000000;

ll factorial[MAX_NM];

void init_fact()
{
    factorial[0] = factorial[1] = 1;
    rep(i, 2, MAX_NM)
        factorial[i] = ((ll)i * factorial[i - 1]) % MOD;
}

ll power_mod(int x, int y)
{
    ll base = x;
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        y >>= 1;
    }
    return res;
}

map<ll, ll> inv_mod_map;
ll inv_mod(int x)
{
    if (inv_mod_map.count(x)) return inv_mod_map[x];
    else
        return inv_mod_map[x] = power_mod(x, MOD - 2);
}

ll comb(int n, int m)
{
    if (m == 0) return 1;
    if (n < m) return 0; 
    ll res = 1;
    res = (res * factorial[n]) % MOD;
    res = (res * inv_mod(factorial[m])) % MOD;
    res = (res * inv_mod(factorial[n - m])) % MOD;
    return res;
}

int main()
{
    init_fact();
    // cout << comb(4, 4) << endl;
    // cout << comb(4, 3) << endl;
    // cout << comb(4, 2) << endl;
    // cout << comb(4, 1) << endl;
    // cout << power_mod(2, 1) << endl;
    // cout << power_mod(2, 2) << endl;
    // cout << power_mod(2, 3) << endl;
    // cout << power_mod(2, 4) << endl;
    // cout << power_mod(2, 5) << endl;
    // cout << power_mod(2, 6) << endl;
    // cout << power_mod(2, 10) << endl;

    ll n, m, k;
    cin >> n >> m >> k;

    ll ans = 0;
    rep(i, 0, n)
        ans = (ans + m * m * i * (n - i)) % MOD;
    rep(i, 0, m)
        ans = (ans + n * n * i * (m - i)) % MOD;

    ans = (ans * comb(n * m - 2, k - 2)) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
ll z[21000];
int main()
{
	ll X;
	cin>>X;
	for(int i=0;i<=10000;i++)
	 z[i]=pow(i,5);
	for(int i=10001;i<=20500;i++)
     z[i]=pow(-1*(i-10000),5);	
	//cout<<f[1]<<endl;
	for(int i=0;i<=20500;i++)
	 for(int j=0;j<=20500;j++)
	  {
	  	ll tmp=z[i]-z[j];
	  	if(tmp==X)
	  	{
	  		int ans1=i,ans2=j;
	  		if(ans1>=10001) ans1=-1*(ans1-10000);
	  		if(ans2>=10001) ans2=-1*(ans2-10000);
	  		cout<<ans1<<" "<<ans2<<endl;
	  		return 0;
		}
	  }
}

Measured memory_bytes: 4404
#include<stdio.h>

int main(){
  int i, n, min, max;
  int R[200000];

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d", &R[i]);
  }
  min = R[0];
  max = R[1] - R[0];
  for(i = 1; i < n; i++){
    if(max < R[i]-min) max = R[i] - min;
    if(min > R[i]) min = R[i];
  }
  printf("%d\n", max);

  return 0;
}



Measured memory_bytes: 2636
<?php
    $S = str_split(trim(fgets(STDIN)));
    $T = str_split(trim(fgets(STDIN)));
    $total = 0;
    
    for($i = 0; $i < count($S); $i++){
        if($S[$i] != $T[$i]){
            $total++;
        }
    }
    
    echo $total;
?>

Measured memory_bytes: 41252
h,w = sorted(list(map(int,input().split())))
if h % 3 == 0 or w % 3 == 0:
  ans = 0
else:
  c1 = ((w//3+1)*h)-((w-1-w//3)*(h//2))
  c2 = ((w-w//3)*(h-h//2))-(w//3*h)
  c3 = h
  c4 = ((h//3+1)*w)-((h-1-h//3)*(w//2))
  c5 = ((h-h//3)*(w-w//2))-(h//3*w)
  ans = min(c1,c2,c3,c4,c5)
print(ans)


Measured memory_bytes: 3064
n = int(input())
dp = [0]
for i in range(1, n+1):
    now = []
    k = 1
    while i >= k:
        now.append(dp[i-k]+1)
        k *= 6
    k = 1
    while i >= k:
        now.append(dp[i-k]+1)
        k *= 9
    dp.append(min(now))
print(dp[-1])

Measured memory_bytes: 3860
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] a) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
		String str = "";
		int num[] = new int[10];
		int top[] = new int[3];
		for (int i = 0; i < 10; i++) {
			str = br.readLine();
			num[i] = Integer.parseInt(str);
			if (top[0] < num[i]) {
				top[2] = top[1];
				top[1] = top[0];
				top[0] = num[i];
			} else if (top[1] < num[i]) {
				top[2] = top[1];
				top[1] = num[i];
			} else if (top[2] < num[i]) {
				top[2] = num[i];
			}
		}
		System.out.println(top[0]);
		System.out.println(top[1]);
		System.out.println(top[2]);
	}
}

Measured memory_bytes: 17016
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];
ll a[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>x>>y>>n;
    swap(x,y);
    swap(x,n);
    cout<<x<<" "<<y<<" "<<n;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;

// auto mod int
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { 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 pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}c(200005);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  mint ans = 0;
  mint col = m;
  for(int i = n - 1; i >= 0; --i) {
    mint now = col;
    now *= c(n - 1, i);
    if(i <= k) ans += now;
    col *= m - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6236
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll sum = 0;
  ll n = s.length() - 1;
  FOR(i,0,1<<n) {
    ll tmp = 0;
    ll tmptmp = ll(s[0] - '0');
    FOR(j,0,n) {
      // +
      if (i & (1 << j)) {
        tmp += tmptmp;
        tmptmp = ll(s[j+1] - '0');;
      } else {
        tmptmp *= 10;
        tmptmp += ll(s[j+1] - '0');
      }
    }
    tmp += tmptmp;
    sum += tmp;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int tyuukan = scan.nextInt();
        int kimatu = scan.nextInt();
        int saisiken = scan.nextInt();
        while (tyuukan != -1 || kimatu != -1 || saisiken != -1) {
            int y;
            y = tyuukan + kimatu;
            if (tyuukan == -1 || kimatu == -1) {
                System.out.println("F");
            } else if (y >= 80) {
                System.out.println("A");
            } else if (y >= 65 && y < 80) {
                System.out.println("B");
            } else if (y >= 50 && y < 65) {
                System.out.println("C");
            } else if (y >= 30 && y < 50) {
                if (saisiken >= 50) {
                    System.out.println("C");
                } else {
                    System.out.println("D");
                }
            } else {
                System.out.println("F");
            }
            tyuukan = scan.nextInt();
            kimatu = scan.nextInt();
            saisiken = scan.nextInt();
        }
    }
}



Measured memory_bytes: 26340
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[0]+a[1] << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>
#define MAX_N 100000

int w[MAX_N];
int n, k;

bool
cond(int p)
{
	int v;
	int i, j;

	j = 0;
	for (i = 0; i < k; ++i)
	{
		v = 0;
		while (v + w[j] <= p)
		{
			v += w[j];
			j++;
			if (j >= n)
				return false;
		}
	}

	return j < n;
}

int
main(int argc, char** argv)
{
	int i;

	scanf("%d %d", &n, &k);
	int sum;
	for (i = 0; i < n; ++i)
	{
		scanf("%d", &w[i]);
		sum += w[i];
	}

	int lb = 0, ub = sum;
	while (ub - lb > 1)
	{
		int mid = (lb + ub) / 2;
		if (cond(mid))
			lb = mid;
		else
			ub = mid;
	}

	printf("%d\n", ub);
	return 0;
}

Measured memory_bytes: 984
fn main() {
    const MOD: usize = 1_000_000_007;

    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut c: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };
    c.sort();

    let pow = |mut a, mut n| {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 {
                res = res * a % MOD;
            }
            a = a * a % MOD;
            n >>= 1;
        }
        res
    };

    let mut ans = 0;
    for i in 0..n {
        ans = (ans + (c[i] * (n - i + 1)) % MOD) % MOD;
    }
    ans = ans * pow(4, n - 1) % MOD;
    println!("{}", ans);
}

Measured memory_bytes: 5828
#include<bits/stdc++.h>
 
using namespace std;
 
#define lli long long
lli M=1e9;
 
#define MAXN  10000001 
 
int main()
{
    lli q=1;
    // cin>>q;
    time_t start, end;
    time(&start);
    for(lli tc=1;tc<=q;tc++)
    {
        lli n;
        cin>>n;
        n--;
        string s="";
        while(n>=0)
        {
            s=(char)('a'+n%26)+s;
            n/=26;
            n--;
        }

        cout<<s<<endl;
    }
    
    time(&end);
    // cout<<fixed<<double(end - start)<<setprecision(10)<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

 
int main() {

    int a,b,c,d;
    cin >> a >> b >> c >> d;

    rep(i,100000) {
        if(i%2==0) {
            c-=b;
            if(c<=0) {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        else {
            a-=d;
            if(a<=0) {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }

 return 0;
}

Measured memory_bytes: 3640
import sys
read = lambda: sys.stdin.readline().rstrip()

def counting_tree(N, D):
    import collections
    tot = 1

    cnt = collections.Counter(D)
    """
    cnt = [0]*N
    for i in D:
        cnt[i]+=1
    """

    for i in D[1:]:
        tot = tot * cnt[i-1]%998244353

    return tot if D[0]==0 else 0

def main():
    
    N0 = int(read())
    D0 = tuple(map(int, read().split()))

    res = counting_tree(N0, D0)

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 18932
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)






void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




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

    ll x;
    cin>>x;
    ll ans = (x/500)*1000+((x%500)/5)*5;
    cout<<ans;

    return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (K, T) = readInputLine().split(" ").map { it.toInt() }
    val aList = readInputLine().split(" ").map { it.toInt() }.sortedDescending()

    println(Math.max(0, aList.first() - 1 - (K - aList.first())))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37564
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  vector<int> a(3);
  cin>>a[0]>>a[1]>>a[2];
  asort(a);
  if(a[0]==5&&a[1]==5&&a[2]==7) cout<<"YES";
  else cout<<"NO";
  cout<<endl;

      
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP2_3_D
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] a = ReadIntAr();
            int m = ReadInt();
            int[] b = ReadIntAr();

            for (int i = 0 ; i < Math.Min(n,m) ; i++)
            {
                if (a[i] > b[i])
                {
                    Console.WriteLine(0);
                    return;
                }
                else if (a[i] < b[i])
                {
                    Console.WriteLine(1);
                    return;
                }
            }

            if (m > n)
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(0);
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 19952
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  string str;
  string x,y;
  vector<string> alf(26);
  
alf = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    
  cin >> n >> str;
  a = str.size();
  for ( int i = 0;i<str.size();++i){
   for (int j = 0;j<26;++j){
     x = str.at(i);
     y = alf.at(j);
          
    if (x == y){
      if (j+n>25){
        b = j+n-26;
      }
      else {
        b = j+n;
      }
    
      str.replace(i,1,alf.at(b));
      break;      
   }
  }

}
   cout << str << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  string S;
  cin >> N >> S;
  if(N % 2) cout << "No" << endl;
  else {
    rep(i, N/2) {
      if(S[i] != S[N/2+i]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def gcd(a, b)
  return a if (b == 0)
  gcd(b, a % b)
end

N, X = STDIN.gets.split(" ").map(&:to_i)
x = STDIN.gets.split(" ").map(&:to_i)
x.push(X)
x = x.sort
x = x.map.with_index(0) do |x_i, i|
  i == x.length - 1 ? nil : x[i+1] - x[i]
end
x.pop
d = x[0]
for i in 1..(x.length-1) do
  d = gcd(x[i], d)
end
puts d

Measured memory_bytes: 10104
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>

using namespace std;


int main() {

    string s;
    cin >> s;

    vector<int> vector(s.size());

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T') {
            vector[i] = 1;
        }
    }

    std::vector<int> as;
    as.push_back(0);

    for (int i = 0; i < s.size(); i++) {

        if (vector[i] == 1) {
            as.push_back(as[i] + vector[i]);
        } else {
            as.push_back(0);
        }
    }

    int result = 0;

    for (int i = 0; i <= as.size(); i++) {
        result = std::max(result, as[i]);
    }
    cout << result << "\n";

    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int x;cin>>x;

  ll ans = (x / 500)*1000;
  x = x % 500;
  ans += (x / 5)*5;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import queue
N=int(input())
M=[input().split()[2:]for _ in[0]*N]
q=queue.Queue();q.put(0)
d=[-1]*N;d[0]=0
while q.qsize()>0:
 u=q.get()
 for v in M[u]:
  v=int(v)-1
  if d[v]<0:d[v]=d[u]+1;q.put(v)
for i in range(N):print(i+1,d[i])


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

int main()
{
	string digits = "";
	string temp = "";
	
	for (int i = 0; i < 3; i++)
	{
		cin >> temp;
		digits += temp;
	}
	
	int num = atoi(digits.c_str());
	
	if (num % 4 == 0)
		cout << "YES";
	else
		cout << "NO";
	
	return 0;
}

Measured memory_bytes: 256