akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int X, N, ans;
  cin >> X >> N;
  ans = 0;
  int p[N+1];
  for (int i = 0; i < N; ++i) {
    cin >> p[i];
  }
  for (int i = -200; i <= 200; ++i) {
    int tmp = abs(X - i);
    int count = 0;
    for (int j = 0; j < N; ++j) {
      if (p[j] == i) {
        break;
      }
      ++count;
    }
    if (count == N && tmp < X-ans) {
      ans = i;
    }
  }
  if (N == 0) {
    ans = X;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int ans = (n * a > b) ? b : (n * a);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    string S = "", T = "";
    int cnt = 0;
    cin >> S >> T;

    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) != T.at(i)) {
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3932
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
long long a[5005],sum;
int main(){
	ios_base::sync_with_stdio(false);
	long long i,j,n,x,t,ans=0;
	cin>>n>>x;
	for(i=0;i<n;i++) cin>>a[i],sum+=a[i];
	if(sum<x){
		cout<<n<<endl;
		return 0;
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(i=0;i<n;i++){
		t=x;
		for(j=0;j<n;j++){
			if(i!=j){
				if(t>a[j]) t-=a[j];
			}
		}
		if(t>a[i]) ans++;
	} 
	cout<<ans<<endl;
	return 0;
}


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

#define MAX 2000001
#define SCORE 10001


int n,nums; 
int counter[SCORE+1], maxi;
int list[MAX+1], sortedList[MAX+1];


void CountingSort() {
  memset(counter,0,sizeof counter);
  int i;
  for(i=0;i<n;++i) ++counter[list[i]];
  for(i=1;i<=maxi;++i) counter[i] += counter[i-1];
  for(i=n-1;i>=0;--i) {
    sortedList[--counter[list[i]]] = list[i];
  }
}

int main() {
  int i, id;
  while( scanf("%d",&n) != EOF ) {
    maxi = 0;
    for(i=0;i<n;++i) {
      scanf("%d",&nums);
      list[i] = nums;
      if( maxi < nums ) maxi = nums;
    }
    CountingSort();
    for(i=0;i<n;++i) {
      if( i ) printf(" ");
      printf("%d",sortedList[i]);
    } puts("");
  }
  return 0;
}



Measured memory_bytes: 17468
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    // input
    int n, m;
    cin >> n >> m;
    //スイッチごとにどの電球に繋がってるかbitで管理
    vector<int> sw(n, 0);
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int s;
            cin >> s;
            s--;
            sw[s] |= (1 << i);
        }
    }
    //点灯条件をbitで管理
    int p = 0;
    for (int i = 0; i < m; i++) {
        int temp;
        cin >> temp;
        p |= (1 << i) * temp;
    }
    // input終わり

    // bit全探索
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        int state = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                state ^= sw[j];
            }
        }
        if (state == p) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<stdio.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int integerlist[n];
    for(int i = 0; i < n; i++){
        cin >> integerlist[i];
    }
    for(int j = 0; j < n; j++){
        if (j != n-1){
            cout << integerlist[n-1-j] << " ";
        } else{
            cout << integerlist[n-1-j] << endl;

        }

    }
}


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

int main()
{
   long A1,A2,A3;
   std::cin >> A1 >> A2 >> A3;
   if(A1+A2+A3>=22){
       std::cout << "bust" << std::endl;
   }else{
       std::cout << "win" << std::endl;
   }
    return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> c(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c.at(i).at(j);
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c.at(i).at(j) = min(c.at(i).at(j), c.at(i).at(k) + c.at(k).at(j));
      }
    }
  }
  int s = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int a;
      cin >> a;
      if (a == -1) continue;
      s += c.at(a).at(1);
    }
  }
  cout << s << endl;
}


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    int cnt = 0;
    repeat(i, 1, n - 1) {
        if (a[i - 1] < a[i] and a[i] < a[i + 1])
            cnt++;
        if (a[i - 1] > a[i] and a[i] > a[i + 1])
            cnt++;
    }
    out(cnt);
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
l=[False]*8+[0]
for i in a:
    if i<400:
        l[0]=True
    elif i<800:
        l[1]=True
    elif i<1200:
        l[2]=True
    elif i<1600:
        l[3]=True
    elif i<2000:
        l[4]=True
    elif i<2400:
        l[5]=True
    elif i<2800:
        l[6]=True
    elif i<3200:
        l[7]=True
    else:
        l[8]+=1
print(max(sum(l[:8]),1),sum(l[:8])+l[8])#https://yukicoder.me/run/08454c2883ca1

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>

#define loop while(1)
#define SZ(x) ((int)(x).size())
#define tep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pushb push_back
#define popb pop_back

#define i64 long long int
#define veci vector<int> 
#define vveci vector<VI>
#define veci64 vector<i64>


using namespace std;

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(begin(a), end(a));
	int score = 0;
	score += a[2] * 10 + a[0] + a[1];
	cout << score << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <sstream>
using namespace std;

struct sort_pred {
	bool operator() (const pair<string, int> &a, const pair<string, int> &b) {
		return a.second > b.second;
	}
};

int main() {
	int n;
	string s;
	while (cin >> n, n) {
		getchar();
		map<char, map<string, int> > table;
		while (n--) {
			getline(cin, s);
			istringstream is(s);
			string t;
			while (is >> t) {
				table[t[0]][t]++;
			}
		}
		char c; cin >> c;
		vector< pair<string, int> > words;
		for (map<string, int>::iterator mi = table[c].begin(); mi != table[c].end(); mi++) {
			words.push_back(*mi);
		}
		sort(words.begin(), words.end(), sort_pred());
		if (words.empty()) {
			cout << "NA" << endl;
			continue;
		}
		cout << words[0].first;
		for (int i = 1; i < min((int)words.size(), 5); i++) {
			cout << ' ' << words[i].first;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 944
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#define rep(i,rept) for(long long i = 0; i <(long long)rept;i++)
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami, mado[50];
	bool gg = false;
	int manji, nk[26] = { false };
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		cin >> mado[i];
	}
	/*rep(j,b)*/for (int j = 0; j < a;j++) {
		for (int k = 0; k < b; k++) {
			if (mado[j][k] != '#') {
				mado[j][k] = '0';
				if (k > 0 && mado[j][k - 1] == '#') {
					mado[j][k]++;
				}
				if (k < b - 1 && mado[j][k + 1] == '#') {
					mado[j][k]++;
				}
				if (j > 0 && mado[j - 1][k] == '#') {
					mado[j][k]++;
				}
				if (j < a - 1 && mado[j + 1][k] == '#') {
					mado[j][k]++;
				}
				if (j > 0 && k > 0 && mado[j - 1][k - 1] == '#') {
					mado[j][k]++;
				}
				if (j < a - 1 && k>0 && mado[j + 1][k - 1] == '#') {
					mado[j][k]++;
				}
				if (j > 0 && k < b - 1 && mado[j - 1][k + 1] == '#') {
					mado[j][k]++;
				}
				if (j < a - 1 && k < b - 1 && mado[j + 1][k + 1] == '#') {
					mado[j][k]++;
				}
				
			}
			cout << mado[j][k];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int m=-1,n=-1,i;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='C'&&m==-1)
		{
			m=i;
		}
		if(s[i]=='F')
		{
			n=i;
		}
	}
	if(m!=-1&&n!=-1&&m<n)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl; 
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    ll N,K;cin >> N >> K;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    vector<ll> bkt(N);
    rep(i,N){
        bkt[A[i]]++;
    }
    sort(All(bkt));
    reverse(All(bkt));
    ll large = 0;
    rep(i,K){
        large += bkt[i];
    }
    cout << N - large << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <tuple>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> max(2, 0);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] > max[0]) {
            max[0] = A[i];
        } else if (A[i] > max[1]) {
            max[1] = A[i];
        }
    }

    for (int i = 0; i < N; i++) {
        if (max[0] == A[i]) {
            cout << max[1] << endl;
        } else {
            cout << max[0] << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	ll x,k,d; cin>>x>>k>>d; x=abs(x);
	
	ll am=x/d;
	if(k<am){
		cout<<x-k*d<<"\n";
		return 0;
	}
	x%=d; k-=am;
	ll ans=x;
	if(k&1) ans-=d;
	cout<<abs(ans)<<"\n";
	
}

Measured memory_bytes: 3648
def sum_degit(n):
    length = len(n)
    n = int(n)
    s_degit = 0
    for _ in range(length):
        s_degit+=n%10
        n = int(n/10)
    return s_degit

N = input()
sum_degit = sum_degit(N)
int_N = int(N)
if int_N%sum_degit == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#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>;

int main(){
    string s, t, u;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    if(s==u){
        --a;
    } else if(t==u){
        --b;
    }
    cout << a << " " << b << "\n";
    return 0;
}

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

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

long lcm(long a, long b) {
  return (a*b) / gcd(a,b);
}

int cycle(int a, int b) {
  int cnt = 1;
  int n = a%b;
  while(n != 1) {
    n = (n*a) % b;
    cnt++;
  }
  return cnt;
}

int main() {
  int a[3], m[3];
  while(cin >> a[0] >> m[0], a[0]+m[0]) {
    for(int i = 1; i < 3; i++) {
      cin >> a[i] >> m[i];
    }

    cout << lcm(lcm(cycle(a[0],m[0]),cycle(a[1],m[1])), cycle(a[2],m[2])) << endl;
  }
}

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

int main() {
	
	int n, a;
	cin >> n >> a;
	if((n%500) > a) puts("No");
	else puts("Yes");
	
	return 0;
}

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

class Main {

	private static int[] color;
	private static int b = 0, w = 0;
	private static List<Integer>[] g;

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		color = new int[N];
		g = new List[N];
		for (int i = 0; i < N; i++) {
			g[i] = new ArrayList<>();
		}

		for (int i = 0; i < M; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			g[a].add(b);
			g[b].add(a);
		}

		if (dfs(0, 1)) {
			System.out.println((long) N * (N - 1) / 2 - M);
		} else {
			System.out.println((long) b * w - M);
		}
	}

	static private boolean dfs(int v, int c) {
		if (color[v] != 0) {
			if (color[v] != c) return true;
			return false;
		}
		color[v] = c;
		int nc = 0;
		if (c == 1) {
			nc = 2;
			w++;
		} else {
			nc = 1;
			b++;
		}
		for (int next : g[v]) {
			if (dfs(next, nc)) return true;
		}
		return false;
	}
}


Measured memory_bytes: 103692
from itertools import combinations

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

items = []
calced = []

min_cost = float('inf')

for _ in range(N):
    items.append(list(map(int, input().split())))

for i in range(N):
    for combo in combinations(items, i+1):
        cost = 0
        exp = [0] * M
        mastered = True
        for c in combo:
            cost += c[0]
            for m in range(0,M):
                exp[m] += c[m+1]
        for m in range(M):
            if exp[m] < X:
                mastered = False
        if mastered:
            min_cost = min(min_cost, cost)


if min_cost == float('inf'):
    print(-1)
else:
    print(min_cost)



Measured memory_bytes: 9216
import itertools

roads = [list(map(int, input().split(" "))) for i in range(3)]

len_route = 4
routes = list(itertools.permutations(range(1, len_route+1)))

flag = False
for route in routes:
    success = True
    for road in roads:
        cond = sum([set(road) ==  set(route[i:i+2]) for i in range(len_route - 1)])
        #print(route, road, cond)
        if cond != 1:
            success = False
            break
    if success:
        flag = True
        #print(route)
        break

out_txt = "YES" if flag else "NO"
print(out_txt)

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 400010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll fs[MAX], inv[MAX];

ll mod_pow(ll a, ll n)
{
    ll res = 1, base = a;

    while (n)
    {
        if (n & 1)
            res = (res * base) % MOD;

        base = (base * base) % MOD;
        n >>= 1;
    }

    return res;
}

void precomp()
{
    fs[0] = 1;

    for (ll i = 1; i < MAX; ++i)
        fs[i] = (fs[i - 1] * i) % MOD;

    inv[0] = 1;

    for (ll i = 1; i < MAX; ++i)
        inv[i] = mod_pow(fs[i], MOD - 2);
}

ll mod(ll a)
{
    return (((a % MOD) + MOD) % MOD);
}

ll binom(ll n, ll m)
{
    ll res = mod(fs[n] * inv[m]);
    res = mod(res * inv[n - m]);

    return res;
}

ll solve(ll N, ll K)
{
    if (K >= N - 1)
        return binom(2*N - 1, N - 1);

    ll ans = 0;

    for (int k = 0; k <= K; ++k)
    {
        ll x = mod(binom(N - 1, k)*binom(N, k));
        ans = mod(ans + x);
    }

    return ans;                
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    ll N, K;
    cin >> N >> K;

    auto ans = solve(N, K);

    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 6528
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = list(map(int, input().split()))
u = UnionFind(N)
for _ in range(M):
    a, b = list(map(int, input().split()))
    u.union(a-1,b-1)
ans = []
for i in range(N):
    ans.append(u.find(i))
from collections import Counter
c=Counter(ans)
print(max(c.values()))

Measured memory_bytes: 102396
import sys
input = sys.stdin.readline
N = int(input())
A = [int(i) for i in input().split()]
count0 = [0 for i in range(60)]
count1 = [0 for i in range(60)]
for a in A:
    a_tmp = bin(a).replace("0b","")
    a_tmp = a_tmp.zfill(60)
    for i,b in enumerate(a_tmp):
        if b == "1":
            count1[i] += 1
        else:
            count0[i] += 1
cnt = 0
ans = 0
for c0,c1 in zip(count0[::-1],count1[::-1]):
    ans += c0*c1*(2**cnt)
    cnt += 1
print(ans%(10**9+7))


Measured memory_bytes: 123132
<?php
list($N, $M) = explode(" ", trim(fgets(STDIN)));

$s = [];
for ($i = 1; $i <= $N; $i++) {
    $tmp = explode(" ", trim(fgets(STDIN)));
    unset($tmp[0]);
    if ($i == 1) {
        $s = $tmp;
    } else {
        $s = array_intersect($s, $tmp);
    }

}

echo count($s) . "\n";

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

int main() {
  int n, x;
  cin >> n >> x;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a, a+n);
  int ans=0;
  for(int i=0; i<n; i++) {
    if(x-a[i]<0) break;
    x-=a[i];
    ans++;
  }
  if(ans==n&&x!=0)ans--;
  cout << ans << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll a,b,x;cin >>a>>b>>x;
    ll ans=a?b/x-(a-1)/x:b/x+1;
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 3596
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	int f=0,t=0,o=0;
	while(n--) {
		int val;
		cin>>val;
		if(val%4==0)f++;
		else if(val%2==0)t++;
		else o++;
	}
	if(t>0) {
		if(o<=f)cout<<"Yes";
		else cout<<"No";
	} else {
		if(f>=o-1)cout<<"Yes";
		else cout<<"No";
	}
	
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

using namespace std;

int main() {
  int a, b;
  char op;
  cin >> a >> op >> b;
  if (op == '+') {
    cout << a + b << endl;
  } else if (op == '-') {
    cout << a - b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
x, n = input().split()
x = int(x)
n = int(n)
m = list(map(int,input().split()))
sa = 999
ans = 0

if m.count(x) == 0 :
    print(x)
    exit()
elif len(m) == 0:
    print(x)
    exit()

for k in range(1,200):
    if m.count((x - k)) == 0 and x - (x - k) < sa:
        sa =  x - (x - k)
        ans = x - k

for l in range(1,200):
    if m.count((x + l)) == 0 and (x+l) - x < sa:
        sa = (x+l) - x
        ans = x + l

print(ans)

Measured memory_bytes: 62612
a, b, c = list(map(int, input().split()))
ans = 0
if a%2==b%2==c%2:
  pass
elif a%2==b%2:
  a, b = a+1, b+1
  ans += 1
elif a%2==c%2:
  a, c = a+1, c+1
  ans += 1
else:
  b, c = b+1, c+1
  ans += 1

t = max(a, b, c)
ans += abs(t-a)//2+abs(t-b)//2+abs(t-c)//2
print(ans)

Measured memory_bytes: 3064
#include <iostream>

int main() {
    long long n, a, min, max, sum;
    std::cin >> n >> a;
    min = max = sum = a;
    for (int i=1;i<n;i++) {
        std::cin >> a;
        if (min > a) min = a;
        if (max < a) max = a;
        sum += a;
    }
    std::cout << min << " " << max << " " << sum << std::endl;
    
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <queue>


int main(void){
  int K,N;
  std::queue<double> v;
  std::cin >> N;
  std::cin >> K;
  
  double max = 0.0;
  double temp = 0.0;
  int tmp;
  for(int i=0;i<K;i++){
    std::cin >> tmp;
    temp = temp + ((double)(tmp+1.0))/2.0;
    v.push(((double)(tmp+1.0))/2.0);
  }
  max = temp;
  for(int i=1;i<N-K+1;i++){
    //v[0](先頭)の成分を引く
    temp = temp - v.front();
    v.pop();
    //i+K-1の成分を足す
    std::cin >> tmp;
    temp = temp + ((double)(tmp+1.0))/2.0;
    v.push(((double)(tmp+1.0))/2.0);
    
    if(temp > max){
      max = temp;
    }
  }
  printf("%0.7f\n",max);
  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

class UnionFind{ //連結判定
private:
    std::vector<int> parent; //parent[i] = parent of node i
    std::vector<int> rank;
    std::vector<int> size;
public:
    //constructor
    UnionFind(int N){
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    //initialize
    void init(int N){
        parent.clear();
        rank.clear();
        size.clear();
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    int root(int a){
        if(parent[a] == a) return a;
        return parent[a] = root(parent[a]); //親が自分自身になるまで再帰を呼び出す & 経路圧縮 
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA == rootB) return; //ノードa, bがすでに連結しているとき
        //次数の大きい方を親として連結
        if(rank[rootA] < rank[rootB]){
            size[rootB] += size[rootA];
            parent[rootA] = rootB;
        }
        else{
            size[rootA] += size[rootB];
            parent[rootB] = rootA;
            if(rank[rootA] == rank[rootB]) rank[rootA]++;
        }
    }
    bool same(int a, int b){
        return root(a) == root(b); //ノードa, bが同じ木に属するかどうか
    }
    int get_size(int a){
        return size[root(a)];
    }
};

int main()
{
    using P = std::pair<int, int>;

    int N, K, L;
    std::cin >> N >> K >> L;
    std::vector<P> route(K), rail(L);
    for(int i=0; i<K; i++){
        scanf(" %d %d", &(route[i].first), &(route[i].second));
        route[i].first--; route[i].second--;
    }
    for(int i=0; i<L; i++){
        scanf(" %d %d", &(rail[i].first), &(rail[i].second));
        rail[i].first--; rail[i].second--;
    }

    UnionFind uf_route(N), uf_rail(N);
    for(int i=0; i<K; i++){
        int u = route[i].first, v = route[i].second;
        uf_route.unite(u, v);
    }
    for(int i=0; i<L; i++){
        int u = rail[i].first, v = rail[i].second;
        uf_rail.unite(u, v);
    }

    std::vector<std::pair<P, int> > root;
    for(int i=0; i<N; i++){
        int a = uf_route.root(i), b = uf_rail.root(i);
        root.push_back(std::pair<P, int>(P(a, b), i));
    }
    std::sort(root.begin(), root.end());
    std::vector<int> tmp, count(N);
    for(int i=0; i<N; i++){
        tmp.push_back(root[i].second);
        if(i == N-1 || (i != N-1 && root[i].first != root[i+1].first)){
            int M = tmp.size();
            while(!tmp.empty()){
                count[tmp.back()] = M;
                tmp.pop_back();
            }
        }
    }
    
    for(int i=0; i<N; i++){
        printf("%d ", count[i]);
    }
    printf("\n");
}

Measured memory_bytes: 11504
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vi a (n);
  F0R (i, n) cin >> a[i];
  i64 tot = 0;
  FOR (i, 1, n) {
    int extra = a[i] + a[i - 1] - k;
    if (extra >= 0) {
      if (a[i] >= extra) {
        a[i] -= extra;
        tot += extra;
      } else {
        tot += a[i];
        extra -= a[i];
        a[i] = 0;
        a[i - 1] -= extra;
        tot += extra;
      }
    }
  }
  cout << tot << '\n';
  return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#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;
typedef pair<int,int> P;
const int MOD = 1e9+7;

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

    int n,m,x;
    cin >> n >> m >> x;

    int a[n][m],c[n];
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }

    int ans = 1001001001;
    rep(i,1<<n){
        int rikai[m], temp = 0;
        rep(j,m) rikai[j] = 0;
        rep(j,n){
            if(i>>j&1){
                temp += c[j];
                rep(k,m) rikai[k] += a[j][k];
            }
        }
        bool ok = true;
        rep(j,m) if(rikai[j] < x) ok = false;
        if(ok) ans = min(ans,temp);
    }

    if(ans == 1001001001) ans = -1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long int lli;
#define repeat(i, n) for(int (i)=0; (i)<(n); (i)++)


int main(){
	vector<int> input(3);
	repeat(i, 3) cin >> input[i];
	sort(input.begin(), input.end());
	int ans = 0;
	
	int diff = input[2] -input[1];
	ans += diff;
	input[0] += diff;
	input[1] += diff;
	
	diff = input[1] -input[0];
	if(diff%2 == 0){
		ans += diff/2;
	}else{
		ans += (diff+1)/2 + 1;
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(3e2 + 5);
const int MAX_M = (int)(3e2 + 5);

int n, m;
int a[MAX_N][MAX_M];

bool check(int x) {
  vector<queue<int>> qs(MAX_N);

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      qs[i].push(a[i][j]);
    }
  }

  bool remain[MAX_M];

  for (int i = 1; i <= m; ++i) remain[i] = true;

  while (true) {
    unordered_map<int, int> cnt;
    for (int i = 1; i <= n; ++i) cnt[qs[i].front()] += 1;

    vector<int> ng;
    for (auto& e : cnt)
      if (e.second > x) ng.push_back(e.first);

    if (ng.empty()) return true;

    for (auto& e : ng) remain[e] = false;

    for (int i = 1; i <= n; ++i) {
      while (!qs[i].empty() && !remain[qs[i].front()]) qs[i].pop();
      if (qs[i].empty()) return false;
    }
  }
}

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &(a[i][j]));
    }
  }

  int ok = MAX_M;
  int ng = 0;

  while (abs(ok - ng) > 1) {
    int next = (ok + ng) / 2;

    if (check(next)) {
      ok = next;
    } else {
      ng = next;
    }
  }

  int ans = ok;

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

  return 0;
}


Measured memory_bytes: 1152
w = int(input())
n = int(input())
l = list(range(1, w+1))
for i in range(n):
  a, b = map(int, input().split(','))
  a -= 1
  b -= 1
  l[a], l[b] = l[b], l[a]
for i in l:
  print(i)


Measured memory_bytes: 5592
N, M = map(int, input().split())
H = [int(h) for h in input().split()]
AB = []
AB = [[int(x) for x in input().split()] for m in range(M)]
Observatory=[[] for n in range(N+1)]
for a, b in AB:
  Observatory[a].append(b)
  Observatory[b].append(a)
#print(Observatory)

ans=0
for i, o in enumerate(Observatory):
  # rule2
  if not len(o):
    ans+=0
  
  # rule1
  for ab in o:
    if H[i-1]<=H[ab-1]:
      break
  else:
    ans+=1

print(ans-1) # decrease Observatroy index 0

Measured memory_bytes: 39680
X=input()
a, b, c= map(str, X.split())
a ,b ,c=int(a), int(b), int(c)
test1=a+b
test2=a+c
test3=b+c
list=[]
list.append(test1)
list.append(test2)
list.append(test3)
print(min(list))

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

using namespace std;
const int N = 200010;
int _w;

int ct, cs;
char s[N];

int main() {
	cin >> s;
	for( char *p = s; *p; ++p )
		if( *p == 'T' ) {
			if( cs ) --cs;
			else ++ct;
		} else {
			++cs;
		}
	cout << ct+cs << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
  
  int n, m;
  cin >> n >> m;
  vector<long long> h(n + 1);
  REP(i, n) {
    cin >> h.at(i + 1);
  }
  vector<vector<int>> data(n + 1);
  int a, b;
  REP(i, m) {
    cin >> a >> b;
    data.at(a).push_back(b);
    data.at(b).push_back(a);
  }
  bool OK;
  int count = 0;
  int d;
  for (int i = 1; i <= n; i++) {
    d = data.at(i).size();
    if (data.at(i).size() == 0) {
      count++;
      continue;
    }
    OK = true;
    for (int j = 0; j < d; j++) {
      if (h.at(data.at(i).at(j)) >= h.at(i)) {
        OK = false;
      }
    }
    if (OK) {
      count++;
    }
  }
  cout << count << endl;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    sort(all(a));
    vector<bool> dp(k+1);
    for(i = 0;i < a.front();++i){
        dp.at(i) = false;
    }
    for(i = i;i <= k;++i){
        bool flag = false;
        rep(j,n){
            if(i < a.at(j)) continue;
            ll tmp = i - a.at(j);
            if(!dp.at(tmp)) flag = true;
        }
        if(flag) dp.at(i) = true;
        else dp.at(i) = false;
    }
    if(dp.at(k)) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll mod = 1e9 + 7;


void solve()
{
    int n;
    cin>>n;
    int height[n]={0};
    for (int i = 0; i < n; i++)
    {
        cin>>height[i];
    }
    int jump[n];
    jump[0]=0;
    jump[1]=abs(height[1]-height[0]);
  
    for (int i = 2; i < n; i++)
    {
        jump[i]=min(abs(height[i]-height[i-2])+jump[i-2],abs(height[i]-height[i-1])+jump[i-1]);
        
    }
    cout<<jump[n-1]<<endl;
    
}

int main()
{
  
        solve();
     

    return 0;
}

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

using namespace std;

int m,n;
int d[251];

bool dfs(int x,bool *p){
  x=max(0,x);
  if(x>n)return true;
  if(p[x]++)return false;
  bool f=false;
  for(int i=1;i<=m;i++){
    int nx=x+i;
    f|=nx>n||dfs(nx+d[nx],p);
  }
  return f;
}

int main(){
  while(cin>>m>>n,m){
    bool r[251]={};
    for(int i=1;i<=n;i++){
      cin>>d[i];
    }
    dfs(0,r);
    bool f=false;
    for(int i=0;i<=n;i++){
      bool p[251]={};
      f|=r[i]&&!dfs(i,p);
    }
    cout<<(!f?"OK":"NG")<<endl;
  }
}

Measured memory_bytes: 1156
package main

import "fmt"
import "bufio"
import "os"
import "strconv"
import "sort"
import "container/heap"

var _sw = bufio.NewScanner(os.Stdin)

func main() {
	N := NextInt()
	M := NextInt()
	// A := NextInts(N)

	h := &IntHeap{}
	heap.Init(h)
	for i := 0; i < N; i++ {
		a := NextInt()
		heap.Push(h, -a)
	}

	for i := 0; i < M; i++ {
		n := -1 * (heap.Pop(h).(int))
		n = n / 2
		heap.Push(h, -n)
	}

	sum := 0
	for _, n := range *h {
		sum += n
	}
	fmt.Println(-sum)
}

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

func NextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func NextInts(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = NextInt()
	}
	return a
}

func NextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func Bounded(lower, n, upper int) int {
	return Min(upper, Max(lower, n))
}

func SortInts(xs []int) {
	sort.Sort(sort.IntSlice(xs))
}

func ReverseSortInts(xs []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(xs)))
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 7552
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    string s, t;
    cin >> s >> t;
   
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if (s < t) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;  cin >> a >> b;
    int ans;
    if (a == 1 || b == 1) {
      if (a == b) {
        ans = 1;
      }  else if (a != 1) {
        ans = 2;
      } else {
        ans = 0;
      }
    } else {
      if (a > b) {
        ans = 0;
      } else if (a < b) {
        ans = 2;
      } else {
        ans = 1;
      }
    }

    switch (ans) {
      case 0: cout << "Alice" << endl; break;
      case 1: cout << "Draw" << endl; break;
      case 2: cout << "Bob" << endl; break;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
ll mod=1e9+7;
int main()
{
	ll n,m;
	cin>>n>>m;
	if(n*2>=m)
	{
		cout<<m/2;
	}
	else
	{
		cout<<n+(m-n*2)/4;
	}
	return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

vector<pair<int, int>> g[maxn];

void dijkstra(int src, vector<int> &dist) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> st;
    dist[src] = 0;
    st.push({0, src});
    while (!st.empty()) {
        auto top = st.top();
        st.pop();

        int node_dist = top.first;
        int node = top.second;

        if (node_dist != dist[node])continue;

        for (auto x : g[node]) {
            auto dest = x.first;
            if (dist[dest] > node_dist + x.second) {
                dist[dest] = node_dist + x.second;
                st.push({dist[dest], dest});
            }
        }
    }
}

void solve() {
    int n;
    cin >> n;

    for (int i = 0; i < n - 1; i++) {
        int a, b, w;
        cin >> a >> b >> w;

        g[a].push_back({b, w});
        g[b].push_back({a, w});
    }
    int q, k;
    cin >> q >> k;
    vector<int> dist(n + 1, 1e15);
    dijkstra(k, dist);
    for(int i = 0; i < q;i++){
        int a, b;
        cin >> a >> b;
        cout << dist[a] + dist[b] << endl;
    }
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 11120
#include <stdio.h>

int main(void)
{
    int first, last, divided;
    scanf("%d %d %d", &first, &last, &divided);

    int divisor;
    int cnt = 0;
    for (divisor = first; divisor <= last; divisor++){
        if (divided % divisor == 0){
            cnt++;
        }
    }
    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 596
N = int(input())
a = list(map(int, input().split()))

rating = [0 for i in range(9)]
for aa in a:
    if aa <= 3199:
        rating[aa // 400] += 1
    else:
        rating[8] += 1

ans_min = 0
for i in range(8):
    if rating[i] > 0:
        ans_min += 1

ans_max = ans_min + rating[8]

ans_min = max(ans_min, 1)

print(ans_min, ans_max)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int N = cin.ReadInt;
			int nMax = 0;
			int nMin = 1000;
			for(int i = 0; i < N; i++)
			{
				int a = cin.ReadInt;
				if (a < nMin) nMin = a;
				if (nMax < a) nMax = a;
			}
			WriteLine(nMax - nMin);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>

using namespace std;
int main(){
  int n;
  cin >> n;
  int a;
  int b[n] = {0};
  for(int i = 1; i < n; i++) {
    cin >> a;
    b[a-1]++;
  }

  for(int i = 0; i < n; i++) {
    cout << b[i] << endl;
  }
  return 0;
}


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

int main( void )
{
    int a,b;
    cin >> a >> b;
    
    int sum = a + b;
    if ( sum > 9 )
        cout << "error" << endl;
    else
        cout << sum << endl;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var Ti = Sarray();
            var Vi = Sarray();
            Vi = Vi.Concat(new long[] { 0 }).ToArray();
            for (var i = N - 1; 0 <= i; --i)
                Vi[i] = Min(Vi[i], Vi[i + 1] + Ti[i]);

            double Vl = 0, Vr = 0, sum = 0;
            for (var i = 0; i < N; ++i)
            {
                double men = 0;
                var t = Ti[i];
                if (Vi[i] + 0.1 < Vl) throw new Exception();
                if (Vi[i] <= Vi[i + 1])
                {
                    Vr = Min(Vl + t, Vi[i]);
                    var Adt = Vr - Vl;
                    var Cst = t - Adt;
                    men = (Vl + Vr) * Adt / 2.0 + Cst * Vr;
                }
                else
                {
                    Vr = Min(Vi[i + 1], Vl + t);
                    double Vm = Vi[i];
                    double Adt = Vm - Vl;
                    double Dst = Vm - Vr;
                    if (t < Adt + Dst)
                    {
                        Adt = (t + Vr - Vl) / 2.0;//Vl+Adt'=Dst'+Vr,Adt'+Dst'=t
                        Dst = t - Adt;
                        Vm = Vl + Adt;
                    }
                    men = (Vl + Vm) * Adt / 2.0 + Vm * (t - Adt - Dst) + (Vm + Vr) * Dst / 2.0;
                }
                Vl = Vr;
                sum += men;
            }
            WriteLine($"{sum:f5}");
        }
    }
}

Measured memory_bytes: 28400
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int p[13],tr[1594323][3],Tr[1594323],rt[3],num[1594323],ans[531441],n,i,j,k,l,len,Len;
char st[200001];

void New(int t,int x) {tr[t][x]=++len;}
void mt(int T,int t,int s)
{
	if (T==n) {num[t]=s; return;}
	New(t,0);mt(T+1,tr[t][0],s);
	New(t,1);mt(T+1,tr[t][1],s+p[T]);
	New(t,2);mt(T+1,tr[t][2],s+p[T]*2);
}

void swap(int &x,int &y) {int z=x;x=y;y=z;}
void down(int t)
{
	if (Tr[t])
	{
		swap(tr[t][1],tr[t][2]);
		if (tr[t][0])
		Tr[tr[t][0]]^=1,Tr[tr[t][1]]^=1,Tr[tr[t][2]]^=1;
		Tr[t]=0;
	}
}
void change(int t)
{
	down(t);
	if (!tr[t][0]) return;
	
	int x=tr[t][2];
	tr[t][2]=tr[t][1];tr[t][1]=tr[t][0];tr[t][0]=x;
	change(x);
}
void find(int T,int t,int s)
{
	down(t);
	if (T==n) {ans[num[t]]=s;return;}
	find(T+1,tr[t][0],s);find(T+1,tr[t][1],s+p[T]);find(T+1,tr[t][2],s+p[T]*2);
}

int main()
{
	#ifdef file
	freopen("c.in","r",stdin);
	#endif
	
	scanf("%d",&n);
	scanf("%s",st);Len=strlen(st);
	
	p[0]=1;fo(i,1,12) p[i]=p[i-1]*3;
	mt(0,0,0);
	
	fo(i,0,Len-1)
	if (st[i]=='S') Tr[0]^=1; else change(0);
	find(0,0,0);
	fo(i,0,p[n]-1) printf("%d ",ans[i]);printf("\n");
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    int cnt = 0;
    ll min_num = INF;
    ll ans = 0;
    rep(i, N) {
        if (A[i] < 0) {
            cnt++;
        }
        min_num = min(min_num, abs(A[i]));
        ans += abs(A[i]);
    }
    if (cnt % 2 == 0) {
        cout << ans << '\n';
    } else {
        cout << ans - 2 * min_num << '\n';
    }
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(){
  int n;
  long double s;
  vector<long double> x,y;

  cin >>n;
  for(int i=0; i<n; i++){
    cin >>s;
    x.push_back(s);
  }
  for(int i=0; i<n; i++){
    cin >>s;
    y.push_back(s);
  }

  //マンハッタン距離
  long double m=0;
  for(int i=0; i<n; i++){
    m+=fabs(x[i]-y[i]);
  }
  printf("%.6Lf\n", m);

  //ユークリット距離
  long double u=0;
  for(int i=0; i<n; i++){
    u+=(x[i]-y[i])*(x[i]-y[i]);
  }
  printf("%.6Lf\n", sqrt(u));

  //p=3
  long double p3=0;
  //再利用する
  s=0;
  for(int i=0; i<n; i++){
    s=fabs(x[i]-y[i]);
    p3+=s*s*s;
  }
  printf("%.6Lf\n", pow(p3,1.0/3.0));

  //チェビシェフ距離
  long double c=0;
  s=0;
  for(int i=0; i<n; i++){
    s=fabs(x[i]-y[i]);
    c=max(c,s);
  }
  printf("%.6Lf\n", c);
  
  
  return 0;
}



Measured memory_bytes: 3488