akhauriyash/Code-Regression huggingface dataset:
// ref: https://drken1215.hatenablog.com/entry/2019/03/03/224600

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

class unionFind_size{
 private:
    vector<int> par; // parent
 public:
    unionFind_size(uint size): par(size, -1) {}
    ~unionFind_size(){}
    
    int root(int rhs){
        if( par[rhs] < 0 ){ return rhs;
        }       else      { return par[rhs] = root(par[rhs]); }
    }
    
    bool unite(int lhs, int rhs){
        int rL = root(lhs);
        int rR = root(rhs);
        if(rL==rR){ return false; }
//        if(par[rL]>par[rR]){ swap(rL, rR); }
        par[rL] += par[rR];
        par[rR] = rL;
        return true;
    }
    
    bool same(int lhs, int rhs){
        return root(lhs)==root(rhs);
    }
    
    int size(int rhs){
        return -par[root(rhs)];
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int64 N, M; cin >> N >> M;
    vector<int> vA(M), vB(M);
    for(int i=M-1; i>=0; --i){ cin >> vA[i] >> vB[i]; --vA[i]; --vB[i]; }
    
    unionFind_size uf(N);
    vector<int64> vAns(M);
    int64 cur = N*(N-1)/2;
    for(int i=0; i<M; ++i){
        vAns[i] = cur;
        
        if(uf.same(vA[i], vB[i])){ continue; }
        
        int a = uf.size(vA[i]);
        int b = uf.size(vB[i]);
        cur -= a * b;
        
        uf.unite(vA[i], vB[i]);
    }
    
    for(int i=M-1; i>=0; --i){ cout << vAns[i] << endl; }
    return 0;
}

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

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

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

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

ll L[300];

int main()
{
    int N;
    cin >> N;
    REP(i, 2 * N)
    {
        cin >> L[i];
    }
    sort(L, L + 2 * N);
    ll sum = 0;
    REP(i, N)
    {
        sum += L[2 * i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	int n;
	cin >> n;
	int a[n+5];
	int cnt = 0;
	rep(i,n){
		cin >> a[i];
		if((i+1)%2 == 1 && a[i]%2 == 1){
			cnt++;
		}
	}	
	cout << cnt << endl;
	return 0;
}


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

using namespace std;

bool isBig(string s1, string s2);

int main(int argc, char const *argv[]) {
  int N, L;
  cin >> N >> L;
  vector<string> s(100);
  for (size_t i = 0; i < N; i++) {
    cin >> s[i];
  }

  string temp;
  for (size_t i = N; i > 0; i--) {
    for (size_t j = 0; j < i-1; j++) {
      if (isBig(s[j+1], s[j])) {
        temp = s[j];
        s[j] = s[j+1];
        s[j+1] = temp;
      }
    }
  }

  for (size_t i = 0; i < N; i++) {
    cout << s[i];
  }
  cout << endl;

  return 0;
}

bool isBig(string s1, string s2) {
  int n = min(s1.length(), s2.length());
  for (size_t i = 0; i < n; i++) {
    if (s1[i] < s2[i]) {
      return true;
    } else if (s1[i] > s2[i]) {
      return false;
    }
  }
  return s1.length() < s2.length() ? true : false;
}

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

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const int INF = INT_MAX / 2;

vector<int> X;

int solve(const int N) {
    int ans = INF;

    for (int i = 0; i <= 100; i++) {
        int acc = 0;
        for (int j = 0; j < N; j++) {
            acc += (X[j] - i) * (X[j] - i);
        }
        chmin(ans, acc);
    }

    return ans;
}

int main(void) {
    int N;
    cin >> N;

    X.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }

    cout << solve(N) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll l, r, d;
  cin >> l >> r >> d;

  ll ans = r / d - (l - 1) / d;

  cout << ans << ln;

  return 0;
}

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

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

const long long MOD = 1000000007;

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int ans=min(n*a,b);
  cout << ans << endl;
}


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	for (char c : s) {
		int tmp = c - 'A';
		tmp += n;
		tmp %= 26;
		cout << char(tmp + 'A');
	}
	cout << '\n';
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    string s;
    string t;
    cin>>s;
    cin>>t;
    bool ok=true;
    if(s.size()+1!=t.size()){
        ok=false;
    }
    rep(i,s.size()){
        if(s[i]!=t[i])ok=false;
    }
    if(ok){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;

}
/*


*/


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define ld double
#define pb push_back
#define EPS 1e-9
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

struct Train {
    int l, r, cs;
    Train(int l = 0, int r = 0, int cs = 0) : l(r), r(r), cs(cs) {}
} a[200010], b[200010];

bool operator< (Train a, Train b)
{
    if (a.r == b.r) return a.l < b.l;
    return a.r < b.r;
}

int n, m, q, res[200010], f[510];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n >> m >> q;
    FOR(i,1,m) cin >> a[i].l >> a[i].r;
    FOR(i,1,q) {
        cin >> b[i].l >> b[i].r;
        b[i].cs = i;
    }
    sort(b+1, b+q+1);
    sort(a+1, a+m+1);
    int now = 1;
    FOR(i,1,q) {
        int r = b[i].r;
        while (now <= m) {
            if (a[now].r > r) break;
            f[a[now].l]++;
            now++;
        }
        int so = now-1;
        FORE(j,b[i].l-1,1) {
            res[b[i].cs] += f[j];
        }
        res[b[i].cs] = so - res[b[i].cs];
    }
    FOR(i,1,q) cout << res[i] << "\n";
    return 0;
}


Measured memory_bytes: 6016
'use strict'

function main(input) {
  const nums = input.split('\n')[1].split(' ').map(n => parseInt(n, 10))
  const sortNums = nums.sort(compareNumbers)

  let A = 0
  let B = 0
  
  for (let i = 0; i < sortNums.length; i ++) {
    if (i % 2 === 0) {
      A += sortNums[i]
    } else {
      B += sortNums[i]
    }
  }

  console.log(A - B)

}

function compareNumbers(a, b) {
  return b - a
}

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


Measured memory_bytes: 21064
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let n: usize = sc.read();
    let k: usize = sc.read();
    if n % k == 0 {
        println!("0");
    } else {
        println!("1");
    }
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


Measured memory_bytes: 4352
A=gets.chomp
N=A.length
ret = 0

h=Hash.new(0)
A.each_char do |c|
  h[c]+=1
end

target=0
h.each do|k,v|
  target += (v-1)*v/2
end
count = (N-1)*N/2+1
ret = count - target
puts ret


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int A,B,M; cin>>A>>B>>M;
  vi C(A),D(B);
  int memo;
  cin>>C[0];
  memo=C[0];
  rep(i,1,A){
    cin>>C[i];
    memo=min(memo,C[i]);
  }
  int ans=memo;
  cin>>D[0];
  memo=D[0];
  rep(i,1,B){
    cin>>D[i];
    memo=min(memo,D[i]);
  }
  ans+=memo;
  rep(i,0,M){
    int E,F,G; cin>>E>>F>>G;
    ans=min(ans,C[E-1]+D[F-1]-G);
  }
  cout<<ans<<endl;
  }


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

ll MOD = 1000000007;

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<ll>> dp(n+1, vector<ll>(2, 0));
  
  dp[0][0] = 1;
  rep(i, n) rep(j, 2) rep(d, 3)
  {
    int c = s[i]-'0';
    int ni = i+1, nj = j;
    if(j == 0 && d && c == 0) break;
    if(j == 0 && d == 0 && c) nj++;
    dp[ni][nj] = (dp[ni][nj] + dp[i][j]) % MOD;
  }
  cout << (dp[n][0] + dp[n][1]) % MOD << endl;

  return 0;
}

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

int main(void) {
	int a, b, c; cin >> a >> b >> c;
	int res = a * 100 + b * 10 + c;
	cout << (res % 4 == 0 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Maxn 4007
using namespace std;
int n,m;
int last[Maxn],pre[Maxn],other[Maxn],cnt=1;
int a[Maxn],b[Maxn];
vector<int> p[Maxn],cover[Maxn];
bool flag[Maxn],vis[Maxn];
int tot[Maxn];
void insert(int u,int v)
{
	other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
}
bool dfs(int u,int fa,int g,int s)
{
	if (u==g) return true;
	for (int q=last[u];q;q=pre[q])
	{
		int v=other[q];
		if (v!=fa)
		{
			if (dfs(v,u,g,s))
			{
				p[s].push_back(q);
				return true;
			}
		}
	}
	return false;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		insert(u,v),insert(v,u);
	}
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		dfs(a[i],-1,b[i],i);
		for (int j=0;j<(int)p[i].size();j++)
		{
			++tot[p[i][j]/2];
			cover[p[i][j]/2].push_back(i);
		}
	}
	int ans=0;
	for (int i=1;i<n;i++)
		ans+=min(tot[i],2);
	while (true)
	{
		int pos=0;
		for (int i=1;i<n;i++)
			if (tot[i]==1&&(flag[i*2]^flag[i*2+1]))
			{
				if (flag[i*2]) pos=i*2+1; else pos=i*2;
				break;
			}
		if (pos==0)
		{
			for (int i=1;i<n;i++)
				if (tot[i]>0) pos=i*2;
		}
		if (pos==0) break;
		while (vis[cover[pos/2].back()]) cover[pos/2].pop_back();
		int now=cover[pos/2].back();
		vis[now]=true;
		bool check=false;
		for (int j=0;j<(int)p[now].size();j++)
			if (p[now][j]/2==pos/2)
			{
				if (p[now][j]^pos) 
				{
					check=true;
					break;
				}
			}
		if (check)
		{
			swap(a[now],b[now]);
			for (int j=0;j<(int)p[now].size();j++)
				p[now][j]^=1;
		}
		for (int j=0;j<(int)p[now].size();j++)
			flag[p[now][j]]=true,--tot[p[now][j]/2];
	}
	printf("%d\n",ans);
	for (int i=1;i<=m;i++)
		printf("%d %d\n",a[i],b[i]);
	return 0;
}


Measured memory_bytes: 13952
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		if(A<6)
			System.out.println(0);
		if(6<=A&&A<=12)
			System.out.println(B/2);
		if(13<=A)
			System.out.println(B);
	}
}

Measured memory_bytes: 23764
# Educational DP Contest C-Vacation

def solve():
    n = int(input())
    dpa = [0] * n
    dpb = [0] * n
    dpc = [0] * n
    
    a, b, c = list(map(int, input().split()))
    dpa[0] = a
    dpb[0] = b
    dpc[0] = c
    for i in range(1, n):
        a, b, c = list(map(int, input().split()))
        dpa[i] = max(dpb[i-1] + a, dpc[i-1] + a)
        dpb[i] = max(dpa[i-1] + b, dpc[i-1] + b)
        dpc[i] = max(dpb[i-1] + c, dpa[i-1] + c)
    return(max(dpa[-1], dpb[-1], dpc[-1]))

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 50904
N=int(input())
A=list(map(int,input().split()))

ans=[0]*(N+1)

for i in range(N,0,-1):
    cnt=0
    for j in range(i*2,N+1,i):
        cnt+=ans[j]
    ans[i]=cnt&1^A[i-1]

print(sum(ans))
for i in range(1,N+1):
    if ans[i]:
        print(i,end=' ')

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

#define EPS 1e-10
#define EQ(a, b) (fabs(a - b) < EPS)
 
int main(void)
{
    const long double radius = 6378.1;
    const long double pi = acos(-1);
    long double x[2], y[2];
    long double dx;
    long double d;
     
    while (1){
        int i;
        
		bool f = true;
		
        for (i = 0; i < 2; i++){
            cin >> y[i] >> x[i];
            if (y[i] != -1 || x[i] != -1) f = false;
			 
            x[i] = x[i] * pi / 180;
            y[i] = y[i] * pi / 180;
        }
		
		if (f) return 0;
         
        dx = x[1] - x[0];
         
        d = radius * acos( sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx) );
         
        cout << round(d) << endl;
    }
     
    return 0;
}

Measured memory_bytes: 1304
/*राधे कृष्णा*//*राधे कृष्णा*//*राधे कृष्णा*//*राधे कृष्णा*/
#include <iostream>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
#include <cstdio> 
#include <string> 
#include <vector> 
#include<bits/stdc++.h>
#include<queue>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//#define test ll t;cin >> t;while(t--)
#define ll long long int
#define  sll stack<ll>
#define  qll queue<ll>
#define  pll pair<ll,ll>
#define  vll vector<ll>
#define  vpi vector<pair<int,int>>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ln "\n"
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define fab(i,a,b) for(i=a;i<b;i++)
//typical dp problem
void solve() {
	ll n,i,j;
	cin >> n;
	ll h[n+1];
	for(i=1;i<=n;i++) cin >> h[i];
	ll dp[n+1];
	dp[0]=0; dp[1]=0; dp[2]= abs(h[2]-h[1]);
	for(i=3;i<=n;i++){
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[n];
}
int main(){
	fastio
	/*ll t;
	cin >> t;
	while(t--){*/
		solve();
	//}
	return 0;
}

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

using namespace std;


int main()
{
    int a[5], mh = 10;
    for (int i = 0; i < 5;i++)
    {
        int t;
        cin >> t;
        if(t % 10 != 0)
        {
            mh = min(mh, t % 10);
        }
        if (t % 10 != 0)
        {
            a[i] = ((int)t / 10) * 10 + 10;
        }
        else
        {
            a[i] = t;
        }
    }
    sort(a, a + 5);
    int ans = a[0] + a[1] + a[2] + a[3] + a[4];
    if(mh != 10)
    {
        ans = ans - 10 + mh;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    cin >> p;
    sort(p.begin(), p.end());
    int sum = 0;
    rep(i, k) sum += p[i];
    cout << sum << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll ;
using namespace std;
int main() {
    ll x,k,d;
    cin>>x>>k>>d;
    ll cnt=abs(x)/d;
    if(k<cnt){
        cout<<abs(x)-d*k;
    }else {
        ll now = abs(x) - cnt * d;
        k -= cnt;
        k %= 2;
        if (k == 0) cout << now;
        else cout << d - now;
    }
    return 0;
}

Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import product
from copy import deepcopy
def resolve():
    n,ma,mb=map(int,input().split())
    ABC=[tuple(map(int,input().split())) for _ in range(n)]
    M=400

    dp=[[INF]*(M+1) for _ in range(M+1)]
    dp[0][0]=0

    for a,b,c in ABC:
        ndp=deepcopy(dp)
        for x,y in product(range(M+1),repeat=2):
            if(x+a<=M and y+b<=M):
                ndp[x+a][y+b]=min(ndp[x+a][y+b],dp[x][y]+c)
        dp=ndp

    ans=INF
    for x,y in product(range(1,M+1),repeat=2):
        if(x*mb==y*ma): ans=min(ans,dp[x][y])
    if(ans==INF): ans=-1
    print(ans)
resolve()

Measured memory_bytes: 121564
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize
    }

    println!("{}", n * (n - 1) / 2);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 8572
def resolve():
	n = int(input())
	if n == 0:
		print("0")
		return
	out = []
	while n != 0:
		n, rem = divmod(n, -2)
		if rem < 0:
			n += 1
			rem -= -2
		out.append(rem)
	print("".join(map(str, out[::-1])))
resolve()

Measured memory_bytes: 38256
#!/usr/bin/env python3
import sys

YES = "POSSIBLE"  # type: str
NO = "IMPOSSIBLE"  # type: str

def solve(N: int, M: int, a: "List[int]", b: "List[int]"):
    conn = [[] for _ in range(N)]
    for i in range(M):
        conn[a[i] - 1].append(b[i] - 1)
        conn[b[i] - 1].append(a[i] - 1)
    ret = NO
    for n in conn[0]:
        if N - 1 in conn[n]:
            ret = YES
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]" 
    b = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, M, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 54220
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
// #include <bits/stdc++.h>
#include <vector>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
#include <random>
#include <queue>
#include <algorithm>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <cstring>
#include <deque>

 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<cd> vcd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vl> vvl;


#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = b; i > a; i--)
#define F0Rd(i,a) for (int i = a; i > -1; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define que queue
#define pa pair
#define ex(m,i) m.find(i)!=m.end()
#define nex(m,i) m.find(i)==m.end()


#define uniq(x) x.resize(unique(all(x))-x.begin())
 
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
const double epsilon = 1e-12;
const int ds[4][2] = {
    {-1,0},
    {1,0},
    {0,-1},
    {0,1}
};
 

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

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    
    int d, t, s1; cin >> d >> t >> s1;

    double temp = d * 1.0 / s1;
    if(temp + epsilon < t || abs(temp-t)<epsilon){
        printf("Yes\n");
    } 
    else{
        printf("No\n");
    }

    return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3132
from collections import defaultdict, deque

n, m = map(int, input().split())
es = [[int(x) for x in input().split()] for _ in range(m)]

outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1 - 1].append(v2 - 1)
    ins[v2 - 1] += 1

# 入次数がゼロのノードから始める
q = deque(v1 for v1 in range(n) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
            
LP = {v:0 for v in res}
for v0 in res:
    for v1 in outs[v0]:
        LP[v1] = max(LP[v1], LP[v0] + 1)
print(max(LP.values()))

Measured memory_bytes: 67320
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

    string s;
    cin >> s;
    int n = s.size();
    bool f = 0;
    rep(i, n - 1) {
        if(s[i] == s[i+1]) f = 1;
    }
    if(f) puts("Bad");
    else puts("Good");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int N;
  cin >> N;
  int x[N], y[N];
  for(int i=0;i<N;i++){
    cin >> x[i];
    cin >> y[i];
  }
  long double sum=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      sum += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  cout <<setprecision(15)<< sum * 2.0 / N;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<math.h>
using namespace std;

int main()
{
    int a, b;
    int i = 0, x, judge, p;
    
    cin >> a >> b;
    
    x = b;

    do {
        x = x / 10;
        i++;
    } while(x != 0);
    
    judge = pow(10, i) * a + b;
    
    p = sqrt(judge);
    
    if(p*p == judge) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 512
w = gets.to_i
n = gets.to_i
arr = Array.new
n.times{arr << gets}

a = (1..w).to_a
arr.each do |i|
   h = i.split(",")
   h.map!{|j| j.to_i}
   a[h[0] - 1], a[h[1] - 1] = a[h[1] - 1], a[h[0] - 1]
end
puts a.join("\n")

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

using namespace std; 

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mmp make_pair
#define st first
#define nd second
#define rd third
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define itr pair <int, pii>
#define PQ priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define Rep(i, n) for (int (i) = 0; (i) <= (int)(n); i++)
#define For(i, a, n) for (int (i) = (a); (i) <= (int)(n); i++)
#define Forn(i, a, n) for (int (i) = (a); (i) >= (int)(n); i--)
#define rep(i, n) for (int (i) = 1; (i) <= (int)(n); i++)
#define EACH(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define DEBUG(x) cout << #x << " = " << (x) << endl; 
#define PR(a, n) {cout << #a << " = "; FOR(_, 1, n) cout << a[_] << ' '; puts(""); }
#define PRO(a, n) { cout << #a << " = "; REP(_, n) cout << a[_] << ' '; puts(""); }
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

const int INF = 1e9; 
const int N = 1005; 
const int dx[] = {-1, 0, 1, 0}; 
const int dy[] = {0, 1, 0, -1}; 

inline ll read()
{
	ll x = 0; int f = 1, c = getchar(); 
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; 
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); 
	return x * f; 
}

int n; 
vector <int> a; 

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin); 
		freopen("output.txt", "w", stdout); 
	#endif
	
	n = read(); 
	
	REP(i, n + 1)
	{
		int x = read(); 
		a.pb(x); 
	}
	
	ll ans = 0; 
	REP(i, n)
	{
		int x = read(); 
		ans += x; 
		if (x < a[i]) a[i] -= x; 
		else if (x < a[i] + a[i + 1]) a[i + 1] -= x - a[i], a[i] = 0; 
		else
		{
			ans += a[i] + a[i + 1] - x; 
			a[i] = 0; 
			a[i + 1] = 0; 
		}
//		PRO(a, a.size()); 
//		DEBUG(ans); 
	}
	
	printf("%lld", ans); 
	
	return 0; 
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;

int n;
int get(int x) {
  return x == 3 ? 3 : x == 2 ? x+n : x%2 ? x+n : x;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  if (__builtin_popcount(n) == 1) {
    puts("No");
    return 0;
  }
  cout << "Yes\n";
  for (int i = 1; i < 3; i++) {
    cout << i << " " << i+1 << nl;
  }
  cout << 3 << " " << n+1 << nl;
  for (int i = 1; i < 3; i++) {
    cout << n+i << " " << n+i+1 << nl;
  }
  for (int i = 4; i < n; i += 2) {
    cout << n+1 << " " << i << nl
         << i << " " << i+1 << nl;
    cout << n+1 << " " << n+i+1 << nl
         << n+i+1 << " " << n+i << nl;
  }
  if (n%2 == 0) {
    int need1 = n ^ (1 << (31 - __builtin_clz(n))) ^ 1, need2 = 1 << (31 - __builtin_clz(n));
    assert(need1 < n && need2 < n);
    cout << get(need1) << " " << n << nl;
    cout << get(need2) << " " << n+n << nl;
  }
  return 0;
}


Measured memory_bytes: 2816
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize
    }
    let mut res = 1;
    for i in 1..n + 1 {
        res = (res * i) % 1000000007;
    }
    println!("{}", res);
}

// fn main() {
//     input! {
//         h: usize,
//         w: usize,
//         s: [chars; h]
//     }
//     let xy = [
//         // [-1i32, 1i32],
//         [0i32, 1i32],
//         // [1i32, 1i32],
//         [-1i32, 0i32],
//         [1i32, 0i32],
//         // [-1i32, -1i32],
//         [0i32, -1i32],
//         // [1i32, -1i32],
//     ];
//     let mut s = s;
//     for y in 0..h {
//         for x in 0..w {
//             if s[y][x] == '.' {
//                 continue;
//             }
//             let mut b = false;
//             for i in 0..4 {
//                 let xx = x as i32 + xy[i][0] as i32;
//                 let yy = y as i32 + xy[i][1] as i32;
//                 if xx < 0 || w as i32 <= xx {
//                     continue;
//                 }
//                 if yy < 0 || h as i32 <= yy {
//                     continue;
//                 }
//                 if s[yy as usize][xx as usize] == '#' {
//                     b = true;
//                 }
//             }
//             if !b {
//                 println!("No");
//                 return;
//             }
//         }
//     }
//     println!("Yes")
// }


Measured memory_bytes: 4352
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    print(N ** 3)


if __name__ == '__main__':
    main()


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

using namespace std;

int f(int n){
    return int(n*1.08);
}

int main(){
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i){
        if(f(i) == n){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;

    return 0;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int h, w;
    const i64 mod = 1000000007;
    std::cin >> h >> w;
    std::vector<std::string> b(h);
    for (int i = 0; i < h; i++) {
        std::cin >> b[i];
    }

    std::vector<std::vector<i64>> c(h + 1, std::vector<i64>(w + 1));
    c[1][1] = 1;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (i * j == 1) continue;
            if (b[i - 1][j - 1] == '#') continue;
            c[i][j] = (c[i - 1][j] + c[i][j - 1]) % mod;
        }
    }

    std::cout << c.back().back() << std::endl;

    return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000000000005
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 1000005
#define sz(x) (ll)x.size()
#define ins insert
#define mp make_pair
#define int  long long
typedef  long long ll;
typedef long double ld;
using namespace std;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

signed  main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
	ll n;
	cin>>n;
	if(n>=30) cout<<"Yes\n";
	else cout<<"No\n";
}
   

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  vector<bool> A(100001,true);
  A[0]=false,A[1]=false;
  for(int i=2;i<=320;i++){
    if(!A[i])
      continue;
    for(int j=2;i*j<=100001;j++)
      A[i*j]=false;
  }
  vector<int> B(100002,0);
  for(int i=3;i<100002;i+=2){
    B[i+1]=B[i-1];
    if(A[i] && A[(i+1)/2])
      B[i+1]++;
  }
  int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    cout<<B[r+1]-B[l-1]<<endl;
  }
}

Measured memory_bytes: 3852
#include<stdio.h>
int main()
{
int p[4][3][10];
int n, r, g, f,v;

for(int i=0;i<4;i++)
for(int j=0;j<3;j++)
for(int k=0;k<10;k++)
p[i][j][k]=0;

scanf("%d",&n);
for(int ii=0;ii<n;ii++)
{
scanf("%d",&r);scanf("%d",&g);scanf("%d",&f);scanf("%d",&v);
p[r-1][g-1][f-1]+=v;
}
for(int iii=0;iii<4;iii++)
{
for(int jj=0;jj<3;jj++)
{
for(int kk=0;kk<10;kk++)

{
printf(" %d",p[iii][jj][kk]);
}
printf("\n");
}
if(iii<3)printf("####################\n");

}
return 0;
}

Measured memory_bytes: 1040
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a,n;
  int sm,mx,mn;
  while(cin>>n&&n){
    sm=0;
    mx=0;
    mn=1000;
    for(i=0;i<n;i++){
      cin>>a;
      sm+=a;
      if(mx<a)
	mx=a;
      if(mn>a)
	mn=a;
    }
    cout<<(sm-mn-mx)/(n-2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import sys
readline = sys.stdin.readline
writelines = sys.stdout.writelines
N = int(readline())
depth = [0]*N
PR = [-1]*N
G = [None]*N
for i in range(N):
    i, _, *cs, = map(int, readline().split())
    G[i] = cs
    for v in G[i]:
        PR[v] = i
def dfs(v, d):
    depth[v] = d
    for w in G[v]:
        dfs(w, d+1)
dfs(PR.index(-1), 0)
writelines(["node %d: parent = %d, depth = %d, %s, %s\n" % (i, PR[i], depth[i], ('root' if PR[i] == -1 else 'leaf' if len(G[i]) == 0 else 'internal node'), G[i]) for i in range(N)])



Measured memory_bytes: 33440
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return input()
def n():
    return int(input())
def d():
    return float(input())

def ls():
    return input().split()
def ln():
    return map(int, input().split())
def ld():
    return map(float, input().split())

def fs():
    return [input() for i in range(input())]
def fn():
    return [int(input()) for i in range(input())]
def fd():
    return [float(input()) for i in range(input())]

N,i = ln()



print(N-i+1)


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

int main() {
  int num, k;
  double kekka = 0;
  double tmp,tmp2;
  double Max = 0;
  int MaxCnt = 0;
  
  cin >> num >> k;
  
  vector<int> vec(num);
  vector<double> vecWa(num,0);
  vector<double> vecInt(num,0);
  for(int i = 0; i < num; i++) cin >> vec.at(i);
  
  for(int i = 0; i < num; i++){
    if(i == 0){
      vecWa.at(i) = vec.at(i);
      continue;
    }
    if(i < k){
      vecWa.at(i) = vec.at(i) + vecWa.at(i-1);
      continue;
    }
    
    vecWa.at(i) = vec.at(i) + vecWa.at(i-1) - vec.at(i - k);
    if(Max < vecWa.at(i)){
      Max = vecWa.at(i);
      MaxCnt = i-k+1;
    }
  }
  
  for(int i = 0; i < k; i++){
    tmp = (vec.at(i+MaxCnt) * (vec.at(i+MaxCnt) +1)) / 2;
    tmp /= vec.at(i+MaxCnt);
    kekka += tmp;
  }
  
  cout << setprecision(10) << kekka;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,d[2],sqr[200005];
struct judge{
	vector < pii > dpos;
	int col[605][605];
	bool in(int x,int y){
		return x>=0 && x<2*n && y>=0 && y<2*n;
	}
	void dfs(int x,int y,int c){
		int i,j,k;
		if(col[x][y]!=-1){
			assert(col[x][y]==c);
			return;
		}
		col[x][y]=c;
		for(i=0;i<(int)dpos.size();++i){
			for(j=0;j<2;++j){
				dpos[i].first=-dpos[i].first;
				for(k=0;k<2;++k){
					dpos[i].second=-dpos[i].second;
					if(in(x+(int)dpos[i].first,y+(int)dpos[i].second)){
						dfs(x+(int)dpos[i].first,y+(int)dpos[i].second,1-col[x][y]);
					}
				}
			}
		}
	}
	void init(int val){
		int i,j;
		for(i=0;i<n*2 && i*i<=val;++i){
			if(sqr[val-i*i]>=i){
				dpos.push_back(mpr(i,sqr[val-i*i]));
				dpos.push_back(mpr(sqr[val-i*i],i));
			}
		}
		memset(col,-1,sizeof(col));
		for(i=0;i<n*2;++i){
			for(j=0;j<n*2;++j){
				if(col[i][j]==-1){
					dfs(i,j,0);
				}
			}
		}
	}
}judges[2];
vector < pii > res[4];
void init(){
	int i;
	memset(sqr,-1,sizeof(sqr));
	for(i=0;i*i<=d[0] || i*i<=d[1];++i) sqr[i*i]=i;
	judges[0].init(d[0]);
	judges[1].init(d[1]);
}
bool cmp(vector < pii > A,vector < pii > B){return A.size()>B.size();}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    scanf("%d%d%d",&n,d,d+1);
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    int i,j;
	init();
	for(i=0;i<n*2;++i){
		for(j=0;j<n*2;++j){
			res[judges[0].col[i][j]*2+judges[1].col[i][j]].push_back(mpr(i,j));
		}
	}
	sort(res,res+4,cmp);
	assert((int)res[0].size()>=n*n);
	for(i=0;i<n*n;++i){
		printf("%d %d\n",res[0][i].first,res[0][i].second);
	}
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

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

int main(){
    long N;
    long m=0;
    long a=0;
    long r=0;
    long c=0;
    long h=0;
    //unsigned long long int ans=0;
    string name;

    cin >> N;
    for(int i=0;i<N;i++){
        cin >> name;
        switch(name[0]){
            case 'M':
                m++;
                break;
            case 'A':
                a++;
                break;
            case 'R':
                r++;
                break;
            case 'C':
                c++;
                break;
            case 'H':
                h++;
                break;
            default:
                break;
        }
    }
    cout << m*a*r + m*a*c + m*a*h + m*r*c + m*r*h 
          + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h << endl;


    return 0;
}

Measured memory_bytes: 256
from collections import deque

K = int(input())

q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
counter = 0

while q:
  e = q.popleft()
  counter += 1 
  
  if counter >= K:
    print(e)
    break
  
  for i in [-1, 0, 1]:
    d = e % 10 + i
    if 0 <= d <= 9:
      q.append(e * 10 + d)
      

Measured memory_bytes: 47400
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500+j*100+k*50==X:
                ans+=1
print(ans)
            


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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

bool isSquare(ll x){
	long double sq = sqrt(x*1.0);
	return (sq - floor(sq))==0;
}

int main(){
	IO;
	ll n;
	cin>>n;
	ll a[n],ans[n];
	ans[0]=0;ans[1]=0;
	forn(i,n){
		cin>>a[i];
		(i%2==0)?ans[0]+=a[i]:ans[0]-=a[i];
	}
	forn(i,n){
		(i%2==0 && i>1)?ans[1]-=a[i]:ans[1]+=a[i];
	}
	for(ll i = 2; i<n; i++){
		ans[i] = ans[i-2] + 2*a[i-1] - 2*a[i-2];
	}
	forn(i,n){
		cout<<ans[i];
		(i==n-1)?cout<<"\n":cout<<" ";
	}
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}


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

int main() {
    string s;
    std::cin >> s;
    ll n = s.length();
    for (int i = 0; i < n/2; i++) {
        if(s[i]==s[(n-1)/2-1-i]&&s[i]==s[(n+3)/2-1+i]&&s[i]==s[n-1-i]){
            
        }else{
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
}



Measured memory_bytes: 256