akhauriyash/Code-Regression huggingface dataset:
mod = 10**9 + 7

fact_range = 2010
facts = [1] * (fact_range + 1)
for i in range(0, fact_range):
    facts[i+1] = facts[i] * (i + 1) % mod

ifacts = [1] * (fact_range + 1)
ifacts[fact_range] = pow(facts[fact_range], mod - 2, mod)
for i in range(fact_range, 0, -1):
    ifacts[i-1] = ifacts[i] * i % mod

def comb(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return facts[n] * ifacts[n-k] % mod * ifacts[k] % mod

n, k = map(int, input().split())
m = n - k
for i in range(1, k + 1):
    print(comb(k - 1, i - 1) * comb(m + 1, i) % mod)



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

int main(void)
{
  int a,b,c,k,n;
  cin >> a >> b >> c;
  n=0;
  for(k=a;k<=b;k++){
    if(c%k == 0)
      n=n+1;
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3092
s = input()
n = len(s)
ans = 0
# print(len(s))

for i in range(n):
	if i % 2 == int(s[i]):
		# # print(s[i])
		# if s[i] == '0':
		ans += 1
			# print('a')
	# else:
	# 	if s[i] == '1':
	# 		ans += 1
# print(ans)

print(min(ans,n-ans))

Measured memory_bytes: 3188
require 'prime'

def calcComb(a, b)
  a - b < b ? calcComb(a, a - b) : (a - b + 1..a).to_a.inject(1, &:*) / (1..b).to_a.inject(1, &:*)
end

mod = 10**9 + 7
n, m = gets.split.map(&:to_i)
puts n == 1 ? 1 : m.prime_division.map(&:last).inject(1) { |s, v| (s * calcComb(n - 1 + v, v)) % mod }


Measured memory_bytes: 1916
//I used a #1336508 code by s146028 as a reference
#include <iostream>
#include <string>
#include <stack>
#include <utility>
#include <queue>
using namespace std;

int main(){
    string str;
    getline(cin, str);
    typedef pair<char, int> bslash;
    typedef pair<int, int> lake;
    stack<bslash> bslashes;
    stack<lake> lakes;
    int A=0;
    int sum=0;
    for(int n=0; n<str.length(); ++n){
        if (str[n] == '\\'){
            bslashes.push(bslash('\\', n));
        }else if (str[n] == '/'){
            if (!bslashes.empty()){
                A += n - bslashes.top().second;
                if (!lakes.empty()){
                    while(!lakes.empty() && bslashes.top().second < lakes.top().second){
                        sum += lakes.top().first;
                        lakes.pop();
                    }
                }
                lakes.push(lake(sum+n-bslashes.top().second, n));
                sum = 0;
                bslashes.pop();
            }
        }
    }
    
    cout << A << endl;
    cout << lakes.size();
    stack<int> st;
    
    while(!lakes.empty()){
        st.push(lakes.top().first);
        lakes.pop(); 
    }
    while(!st.empty()){
        cout << ' ' << st.top();
        st.pop();
    }
    cout << endl;
}

Measured memory_bytes: 1372
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)  
#define rep(i,n) for(long long int (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long int (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
const unsigned int mod = 1e9+7;
const int maxInt = 2147483647;
const int mx=1000005;
char s[1005];
ll dp[1005][1005];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll h,w;
    cin >> h >> w;
    dp[0][0]=1;
    rep(i,h){
    	cin >> s;
    	rep(j,w){
    		if(s[j]=='.'){
    			if(i)dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
    			if(j)dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
    		}
    	}
    }
    cout <<(dp[h-1][w-1])%mod << endl;
    return 0;
}






























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

int mny[200010];

int main(void){
    int H, W, N;
    cin >> H >> W >> N;
    for(int i=1; i<=H; ++i) mny[i]=W+1;
    for(int i=0; i<N; ++i){
        int X, Y;
        cin >> X >> Y;
        mny[X]=min(mny[X], Y);
    }
    int ans=1, now=1;
    while(ans<H){
        if(mny[ans+1]<=now) break;
        if(mny[ans+1]>now+1) ++now;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

int count(int n, int x){
    int cnt=0;
    for (int i=1; i<=n-2; i++){
        for (int j=i+1; j<=n-1; j++){
            for (int k=j+1; k<=n; k++){
                if(i+j+k==x) cnt=cnt+1;
            }
        }
    }
    return cnt;
}
int main(){
    int n,x;
    
    while(1){
        cin >> n>> x;
        if (n==0 && x==0) break;
        cout << count(n,x) << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M, Q;
int L[200010], R[200010];
int cum[510][510];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
    cum[L[i]][R[i]]++;
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j+1 <= N; j++) {
      cum[i][j+1] += cum[i][j];
    }
  }
  for (int j = 0; j <= N; j++) {
    for (int i = 0; i+1 <= N; i++) {
      cum[i+1][j] += cum[i][j];
    }
  }
  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    int ans = 0;
    ans += cum[q][q];
    ans += cum[p-1][p-1];
    ans -= cum[q][p-1];
    ans -= cum[p-1][q];
    cout << ans << endl;
  }

  return 0;
}

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

int n, ca, cb, cntr = 0;
string a, b, s;
char c;

int main(){
   
	a = b = s = "";
	ca = cb = 0;
	
	cin >> n;
	for(int i = 1 ; i <= n ; ++i)	s+= (char)(i+'0');
	for(int i = 0 ; i < n ; ++i) {cin >> c; a += c;}
	for(int i = 0 ; i < n ; ++i) {cin >> c; b += c;}
	
	while(next_permutation(s.begin(), s.end())){
		cntr++;
		if(s == a)	ca = cntr;
		if(s == b)	cb = cntr;
		
		if(ca && cb)	break;
	}
	cout << abs(ca - cb);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

// Most important thing in CP - Have Fun :)



void solve(){
	//write here
    string s,t;
    cin>>s>>t;
    int x = sz(t);
    int mxval = 0 ;
    for (int i = 0 ; i + x<=sz(s) ; i++){
        int ans = 0;
        //cout<<s[i]<<endl;
        for (int j = 0 ; j<x ; j++){
            if (s[i+j]==t[j])ans++;
        }
        mxval = max(ans,mxval);
    }
    cout<<x - mxval<<endl;
	return;
}

int main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
	
		solve();
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, C;

    //全てのチャンネルにおいて、0~100000までの時間のうち、
    //放送している時間を1,放送していない時間を0で表す
    vvi tv(35, vi(100050, 0));
    cin >> N >> C;
    rep(i, N) {
        int s, t, c;
        cin >> s >> t >> c;
        FOR(j, s, t+1) tv[c][j] = 1;
    }

    int res = 0;
    //0~100000までの時間全てにおいて、放送しているチャンネルの個数を数える
    FOR(i, 0, 100001) {
        int temp = 0;
        rep(j, C+1) temp += tv[j][i];
        res = max(res, temp);
    }
    
    cout << res << endl;
    return 0;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

LL N, A, B;
VI xs;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	cin >> N >> A >> B;
	rep (i, N) {
		int x;
		cin >> x;
		xs.pb(x);
	}
	LL ans = 0;
	rep (i, xs.size() - 1) {
		ans += min((xs[i + 1] - xs[i]) * A, B);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 892
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int a, b;
  cin >> a >> b;
  
  //白列を除いてvを作成
  vector<string> v;
  for(int i=0; i<a; i++) {
    string s;
    cin >> s;
    for(int j=0; j<b; j++) {
      if(s[j] == '#') {
        v.push_back(s);
        break;
      }
    }
  }
  
  //vの縦横を入れ替えたwを作成
  int c = v.size();
  vector<string> w(b);
  for(int i=0; i<c; i++) {
    string s;
    s = v[i];
    for(int j=0; j<b; j++) {
      w[j] += s[j];
    }
  }
  
  //白列をwから削除
  for(int i=0; i<w.size(); i++) {
    string s;
    s = w[i];
    for(int j=0; j<c; j++) {
      if(s[j] == '#') break;
      if(j == c-1 && s[j] == '.') {
        w.erase(w.begin()+i);
        i--;
      }
    }
  }

  //wの縦横を入れ替えたxを作成
  int d = w.size();
  vector<string> x(c);
  for(int i=0; i<d; i++) {
    for(int j=0; j<c; j++) {
      string s;
      s = w[i];
      x[j] += s[j];
    }
  }
  
  //出力
  for(int i=0; i<c; i++) {
    cout << x[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








      

 
  int main() {
   
    int MAX = 101010;
    
    vector <int> is_prime(MAX,1);
    is_prime[0] = 0,is_prime[1] = 0;
    for (int i = 2;i < MAX;i++){
      if (!is_prime[i]) continue;
      for (int j = i*2;j < MAX;j += i) is_prime[j]=0;
    }
    vector <int> a(MAX,0);
    for (int i = 0;i < MAX;i++){
      if (i % 2 == 0) continue;
      if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    vector <int> s(MAX+1,0);
    for (int i = 0;i < MAX;i++) s[i+1]=s[i]+a[i];






    int n;
    cin >> n;
    int l[n+1],r[n+1];
    rep (i,n){
      cin >> l[i] >> r[i];
      ++r[i];
    }
    rep (i,n){
      cout << s[r[i]] - s[l[i]] << endl;
    }

    
}




Measured memory_bytes: 5020
S = input()
ans = 'None'
l = len(S)
if not l % 2 == 0:
    ans = 'No'
else:
    for j in range(l//2):
        if not (S[2*j] == 'h' and S[2*j+1] == 'i'):
            ans = 'No'
            break
        if j == (l//2)-1:
            ans = 'Yes'
print(ans)

Measured memory_bytes: 3060
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n,m;
 
   cin >> n >> m;
  
   if(n<10&&m<10){
     cout << n*m << endl;
   }else{
     cout << -1 << endl;
   }
  
   
   
  return 0;
}


Measured memory_bytes: 256
S = list(input())
N = len(S)
left = [0] * N
right = [0] * N

if S[0] == 'B':
    left[0] = 1
for i in range(1, N):
    if S[i] == 'B':
        left[i] = left[i - 1] + 1
    else:
        left[i] = left[i - 1]

# if S[N -1] == 'W':
#     right[N - 1] = 1
# for i in range(N - 2, -1, -1):
#     if S[i] == 'W':
#         pass

ans = 0
for i in range(N):
    if S[i] == 'W':
        ans += left[i]

print (ans)

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

int main() {
  int n,a;
  cin >> n;
  a = n % 1000;
  if(a == 0){
    cout << 0 << endl;
  }else{
  	cout << 1000 - a << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
n, m, l = map(int, input().split())
a_list = []
b_list = []
for i in range(n):
	a_list.append(list(map(int, input().split())))
for i in range(m):
	b_list.append(list(map(int, input().split())))
c_list = [[0 for i in range(l)] for i in range(n)]
for i in range(n):
	for j in range(l):
		for k in range(m):
			c_list[i][j] += a_list[i][k] * b_list[k][j]
for c in c_list:
	print(' '.join(list(map(str, c))))


Measured memory_bytes: 6892
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Linq.Enumerable;

namespace AtCoderCSharp
{
    static class Program
    {
        const long MaxValue = 1000000000;
        const int MaxPrime = 100000;

        static bool Check(int N, long[] poly, long p)
        {
            var mp = (MaxValue / p + 1) * p;
            if ((mp + poly[N]) % p != 0)
            {
                return false;
            }
            for (var i = 1L; i <= Math.Min(p - 1, N); ++i)
            {
                var v = 0L;
                for (var k = i; k <= N; k += p - 1)
                {
                    v += mp + poly[N - k];
                    v %= p;
                }
                if (v != 0)
                {
                    return false;
                }
            }
            return true;
        }

        static IEnumerable<long> Primes(int N, long val)
        {
            var sieve = new bool[MaxPrime + 1];
            for (var p = 2; p <= MaxPrime; ++p)
            {
                if (sieve[p])
                {
                    continue;
                }
                if (p <= N || val % p == 0)
                {
                    yield return p;
                    while (val % p == 0)
                    {
                        val /= p;
                    }
                }
                for (var k = p; k <= MaxPrime; k += p)
                {
                    sieve[k] = true;
                }
            }
            if (val != 1)
            {
                yield return val;
            }
        }

        static void Main(string[] args)
        {
            var N = int.Parse(ReadLine());
            var poly = Range(0, N + 1).Select(v => long.Parse(ReadLine())).ToArray();
            foreach (var p in Primes(N, Math.Abs(poly[0])).Where(p => Check(N, poly, p))) 
            {
                WriteLine(p);
            }
        }
    }
}


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

using namespace std;

int N, M, C[21];
int dp[21][50001];
int main(){
  for(int i = 0; i < 21; i++){
    for(int k = 0; k < 50001; k++){
      dp[i][k] = 30000;
    }
  }
  for(int i = 0; i < 21; i++){
    dp[i][0] = 0;
  }
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> C[i+1];
  }

  for(int i = 1; i <= M; i++){
    for(int k = 1; k <= N; k++){
      if(k >= C[i]){
	dp[i][k] = min(dp[i][k], dp[i-1][k - C[i]] + 1);
	dp[i][k] = min(dp[i][k], dp[i][k-C[i]] + 1);
      }
      dp[i][k] = min(dp[i][k], dp[i-1][k]);
    }
  }
  cout << dp[M][N] << endl;
  

}

Measured memory_bytes: 7172
n = int(input())
x = 0
y = 0
for i in range(n):
    t,a = map(int,input().split())
    if x%t == 0:
        la = x//t
        if la == 0:
            la = 1
    else:
        la = x//t + 1

    if y % a == 0:
        lb = y//a
        if lb == 0:
            lb = 1
    else:
        lb = y//a +1

    l = max(la,lb)
    x = t*l
    y = a*l

print(x+y)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define rep(i,n) FOR(i,0,n)

int main(){
	int N;
	long long K;
	cin >> N >> K;
	vector<pair<int,int>> ab;
	int a,b;
	rep(i,N){
		cin >> a >> b;
		ab.emplace_back(make_pair(a,b));
	}
	sort(ab.begin(),ab.end());
	long long cntr = 0;
	rep(i,N){
		cntr += ab[i].second;
		if(cntr>=K){
			cout << ab[i].first << endl;
			break;
		}
	}
}

Measured memory_bytes: 1400
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)


int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    
    //jが大きい/iが大きいの2パターン
    ll l[2000000];
    ll sum = 0;
    REP(i, n) {
        // ペア候補として登録
        if(i+a[i] < n) l[i+a[i]]++;
        //ペアがあったら答えに追加
        if(i-a[i] > 0) sum += l[i-a[i]];
    }
    cout << sum << endl;
    

    return 0;
}

Measured memory_bytes: 6424
#include<stdio.h>
int main(){
	int i,n;
	int a[10001],b[10001],c[10001],d[10001],e[10001];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i/10000==3 || i/1000==3 || i/100==3 || i/10==3 || i%10000==3 || i%10000/1000==3 || i%10000%1000/100==3 || i%10000%1000%100/10==3 || i%10000%1000%100%10==3){
			printf(" %d",i);
		}
		else if(i%3==0)printf(" %d",i);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2016
n=int(input())
a=list(map(str,input().split()))
b,c=[],[]
if n%2==0:
    for i in range(n):
        if i%2==0:
            b.append(a[i])
        else:
            c.append(a[i])
    c.reverse()
else:
    for i in range(n):
        if i%2==1:
            b.append(a[i])
        else:
            c.append(a[i])
    c.reverse()
print(" ".join(c+b))

Measured memory_bytes: 30776
#include <iostream>
using namespace std;
#define mod 1000000007
#define ll long long
long long solve(int n)
{ll sum=0;ll ans=0;
for(ll i=1;i<=n;i++){
   ll x;cin>>x;
   sum+=x;
   ans=(ans+(i*x-sum))%mod;
   
}
return ans;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	long long x=solve(n),y=solve(m);
	printf("%lld",(x*y)%mod);
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define eb emplace_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int n = 0;
    cin >> n;
    vi ar(n);

    rep(i,0,n) cin >> ar[i];

    sort(all(ar));
    cout << ar[n/2]-ar[n/2-1] << "\n";

    return;
}

int main(){

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

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/


Measured memory_bytes: 640
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll x;
    cin >> x;
    cout << lcm(x, 360) / x << endl;
}


Measured memory_bytes: 3640
//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define RANDOM srand(94385)
#define all(a) a.begin(), a.end()
#define shuffle(a) \
    for (int i = 0; i < sz(a); ++i) \
        swap(a[i], a[rand() % sz(a)]);
#define enter putchar('\n')
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
using namespace std;

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

void debug_out() { cerr << '\n'; }
template<typename T, typename ...R>void debug_out(const T &f, const R &...r) {cerr << f << " ";debug_out(r...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__);
inline ll read() {ll x = 0;int f = 0;char ch = getchar();while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar();while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();return x = f ? -x : x;}
inline void write(ll x) {if (x == 0) {putchar('0');return;}if (x < 0) {putchar('-');x = -x;}static char s[23];int l = 0;while (x != 0)s[l++] = x % 10 + 48, x /= 10;while (l)putchar(s[--l]);}
int lowbit(int x) { return x & (-x); }
template<class T>T big(const T &a1, const T &a2) { return a1 > a2 ? a1 : a2; }
template<typename T, typename ...R>T big(const T &f, const R &...r) { return big(f, big(r...)); }
template<class T>T sml(const T &a1, const T &a2) { return a1 < a2 ? a1 : a2; }
template<typename T, typename ...R>T sml(const T &f, const R &...r) { return sml(f, sml(r...)); }
template<class T, class U>inline void checkMin(T &x, U y) { if (y < x) x = y; }
template<class T, class U>inline void checkMax(T &x, U y) { if (y > x) x = y; }
template<class T, class U>inline bool ifMax(T &x, U y) {if (y > x) return x = y, true;return false;}
template<class T, class U>inline bool ifMin(T &x, U y) {if (y < x) return x = y, true;return false;}

const int maxn = 212345;// 2e5+5
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000000007;// 1e9+7

// HAVE FREE OPEN IN MAIN FUNCTION
struct node{
    int st,num;
    node(int st=0,int num=0){
        this->st=st;
        this->num=num;
    }
};
vector<node>v;
char s[maxn];
int main() {

    int n,k,tmp,ans;
    scanf("%d%d%s",&n,&k,s+1);
    s[n+1]='p';
    tmp=1;
    for(int i=2;i<=n+1;i++){
        if(s[i]!=s[tmp])
        {
            v.push_back(node(tmp,i-tmp));
            tmp=i;
            if(i==n+1)
                break;
        }
    }
    tmp=v.size();
    if(tmp==1){
        write(n-1),enter;
        return 0;
    }
    int sss=1;
    for(int i=1;i<=v.size()-1;i++)
    {
        sss++;
        if(!k) break;
        if(i%2){
            tmp-=2;
            if(i==v.size()-1)
                tmp++;
            k--;
        }
    }
    if(sss<-1)write(-1),enter;
    else
        
    write(n-tmp),enter;
    return 0;

}


Measured memory_bytes: 1528
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, d; cin >> h >> w >> d;
    vvll a(h, vll(w));
    V< P<int, int> > xy(h * w + 1);
    for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++) {
        cin >> a[i][j];
        xy[a[i][j]] = make_pair(i, j);
    }

    vll accd(h * w + 1, 0);
    for (ll i = d + 1; i < h * w + 1; i++) {
        accd[i] = accd[i - d] + abs(xy[i].first - xy[i - d].first) + abs(xy[i].second - xy[i - d].second);
    }

    ll q; cin >> q;
    while (q-->0) {
        ll l, r; cin >> l >> r;
        cout << accd[r] - accd[l] << '\n';
    }
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
typedef pair<int, P> PP;
const long long inf = 1ll << 61;
const int mod = 10000000000007;
int modpow(int x, int n, int md) {
	if (!n)return 1;
	int res = modpow(x*x%md, n / 2, md);
	if (n & 1)res = res*x%md;
	return res;
}
int dgtsum(int a) {
	if (!a)return 0;
	return a % 10 + dgtsum(a / 10);
}
signed main() {
	int a, n, m; cin >> a >> n >> m;
	int ans = 0;
	vector<int>V;
	for (int x = 1; x < inf; x++) {
		int l = modpow(x, n, mod);
		if (l > m)break;
		V.push_back(l);
	}
	rep(i,V.size()) {
		int x = V[i];
		if (x == modpow(dgtsum(x) + a, n, mod))ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 3164
scnum = list(map(int,input().split()))
score = [0]*scnum[0]
answer = 13*(10**5)
nowsum = 0
scosum = [0]*scnum[1]
gacchi = 0

for i in range(scnum[0]):
    score[i] = list(map(int,input().split()))
    
for j in range(2**scnum[0]):
    if j != 0:
        for h in range(scnum[0]):
            if (j>>h) & 1:
                nowsum += score[h][0]
                for k in range(scnum[1]):
                    scosum[k] += score[h][k+1]
        for l in range(scnum[1]):
            if scosum[l] >= scnum[2]:
                gacchi += 1
        if gacchi == scnum[1] and nowsum < answer:
            answer = nowsum
        nowsum = 0
        gacchi = 0
        scosum = [0]*scnum[1]

if answer == 13*(10**5):
    print(-1)
else:
    print(answer)

Measured memory_bytes: 92664
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 1e5+4;
int n,m,q,ans;
int a[55],b[55],c[55],d[55];
vector<int>v;

void calc(int x,int j){
		if(j==n-1){
			int res=0;
			rep(i,q){
				if(v[b[i]]-v[a[i]]==c[i])res+=d[i];
			}
			umax(ans,res);
			return;
		}
		for(int i=x;i<=m;i++){
			v.pb(i);
			calc(i,j+1);
			v.pop_back();
		}
}

void solve(){
	cin>>n>>m>>q;
	rep(i,q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		--a[i],--b[i];
	}
	for(int i=1;i<=m;++i){
		v.pb(i);
		calc(i,0);
		v.pop_back();
	}
	cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 3664
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
struct Edge{
    int d,z,nxt;
} edge[1000005];
int t[500005],sm=0,n,ks,wb,ans,d[500005];
void add(int x,int y,int z){
    sm++;
    edge[sm]=(Edge){y,z,t[x]};
    t[x]=sm;
}
struct Node
{
    int x, d;
    bool operator <(const Node &b)const
    {
        return d > b.d;
    }
}cyc;
priority_queue<Node> q;
void bfs(){
    for(int i=0;i<=n;i++){
        d[i]=2147483647;
    }
    d[0]=0;
    q.push((Node){0,0});
    while(!q.empty()){
        Node a=q.top();
        q.pop();
        int b=a.x;
        if(a.d!=d[a.x])continue;
        for(int i=t[b];i;i=edge[i].nxt){
            int c=edge[i].d;
            if(d[c]>d[b]+edge[i].z){
                d[c]=d[b]+edge[i].z;
                q.push((Node){c,d[c]});
            }
        }
    }
}
int main(int argc, const char * argv[]) {
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=9;j++){
            add(i,((i-1)*10+j)%n+1,j);
        }
    }
    for(int i=1;i<=9;i++)
        add(0,i+1,i);
    bfs();
    cout<<d[1];
    return 0;
}


Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
const int INF=1001001001;
int main() {
    int a,b;
    cin>>a>>b;
    for(int n=0;n<10000;n++){
        int za=n*8/100;
        int zb=n*10/100;
        if(a==za&&b==zb){
            cout<<n<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	while (cin >> N >> M >> K >> L >> T, N) {
		vector<vector<int>>edge(N, vector<int>(N, MOD));
		for (int i = 0; i < M; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			a--, b--;
			edge[a][b] = c;
			edge[b][a] = c;
		}
		for (int i = 0; i < N; i++)edge[i][i] = 0;
		vector<int>node(K);
		vector<int>cost(K);
		for (int i = 0; i < K; i++) {
			cin >> node[i] >> cost[i];
			node[i]--;
		}
		L--;
		node.push_back(L);
		cost.push_back(0);
		K++;
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
				}
			}
		}
		vector<vector<int>>dp(1 << K, vector<int>(K, MOD));
		dp[0][K - 1] = 0;
		dp[1 << (K - 1)][K - 1] = 0;
		for (int i = 0; i < 1 << K; i++) {
			for (int j = 0; j < K; j++) {
				for (int k = 0; k < K; k++) {
					if ((i >> k) & 1)continue;
					dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + edge[node[j]][node[k]] + cost[k]);
				}
			}
		}
		//for (int i = 0; i < 1 << K; i++) {
		//	for (int j = 0; j < K; j++) {
		//		cout << i << " " << j << " " << dp[i][j] << endl;
		//	}
		//}
		int ans = 0;
		for (int i = 1 << (K - 1); i < 1 << K; i++) {
		//	cout << dp[i][K - 1] << endl;
			if (dp[i][K - 1] <= T) {
				int box = i;
				int num = 0;
				while (box) {
					num += box & 1;
					box >>= 1;
				}
				ans = max(ans, num - 1);
			}
		}
		cout << ans << endl;
	}
}


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

eachbit=[0]*32
for i in range(N):
    bin_str = format(A[i],'032b')
#    print(bin_str)
    for j in range(1,33):
        if bin_str[-j] == '1':
            eachbit[j-1] += 1

#print(eachbit)
even = True
for e in eachbit:
    if e % 2 != 0:
        even = False

if even:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14116
X,Y=map(int,input().split())
ans=0
if X==1:
  ans+=300000
if X==2:
  ans+=200000
if X==3:
  ans+=100000
if Y==1:
  ans+=300000
if Y==2:
  ans+=200000
if Y==3:
  ans+=100000
if X==1 and Y==1:
  ans+=400000
print(ans)
  
  
    
  

Measured memory_bytes: 3060
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut xy: Vec<(i64, i64)> = (0..n)
        .map(|_| {
            let x: i64 = sc.read();
            let y: i64 = sc.read();
            (x, y)
        })
        .collect();
    xy.sort_by(|&(x1, y1), &(x2, y2)| {
        let t1 = (y1 as f64).atan2(x1 as f64);
        let t2 = (y2 as f64).atan2(x2 as f64);
        t1.partial_cmp(&t2).unwrap()
    });
    let tmp = xy.clone();
    xy.extend(tmp);
    let mut ans = 0;
    for head in 0..n {
        for tail in head..(head + n) {
            let mut cur = (0, 0);
            for i in head..(tail + 1) {
                cur.0 += xy[i].0;
                cur.1 += xy[i].1;
            }
            let (x, y) = cur;
            ans = std::cmp::max(ans, x * x + y * y);
        }
    }
    println!("{}", (ans as f64).sqrt());
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int H, W, D;

	cin >> H >> W >> D;
	vector<pair<int,int>> map(H*W + 1);

	for  (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			int tmp;
			cin >> tmp;
			map[tmp].first = i + 1;
			map[tmp].second = j + 1;
		}
	}
	

	vector<int> sum(H*W + 1,0);

	for (int i = D + 1; i <=H*W; i++) {
		sum[i] = sum[i - D] + abs(map[i].first - map[i - D].first) + abs(map[i].second - map[i - D].second);
	}

	vector<int> ans;
	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int l, r;

		cin >> l >> r;

		ans.push_back(sum[r] - sum[l]);
	}

	for (int i = 0; i < Q; i++)
	{
		cout << ans[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 2680
#include <stdio.h>
int main(void)
{
    int i,x;
    for(i=1;i<=10000;i++)
    {
        scanf("%d",&x);
        if(x>0&&x<=10000)
        {
        if(x==0)
        {
            break;
        }
        printf("Case %d: %d\n",i,x);
        }
        else break;
    }
    return 0;
}



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

int main(){
  int n;
  cin >>n;
  string s,t,u;
  cin >>s >>t >>u;
  int cnt = 0;
  rep(i,n){
    if(s[i]!=t[i] && t[i]!=u[i] && u[i]!=s[i]) cnt += 2;
    else if(s[i]!=t[i] || t[i]!=u[i] || u[i]!=s[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main() {
  int a, b, c;
  int k;

  cin >> a >> b >> c;
  cin >> k;

  int res;

  int max_n = a;
  int max_i = 1;
  if (max_n < b) {
    max_n = b;
    max_i = 2;
  }
  if (max_n < c) {
    max_n = c;
    max_i = 3;
  }

  switch (max_i) {
    case 1:
      a *= pow(2, k);
      break;
    case 2:
      b *= pow(2, k);
      break;
    case 3:
      c *= pow(2, k);
      break;
  }

  res = a + b + c;

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    ll r,d,x;
    cin >> r >> d >> x;
    rep(i,10) {
        x = x*r-d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
const ll num = 1e18;
int main() {
    ll n;
	cin>>n;
	ll a[n];
	bool check = false;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		if(a[i] == 0) 
		check = true;
	}
	if(check){
		cout<<0;
		return 0;
	}
	ll p = 1;
	for(int i = 0; i < n; i++){
		
		if(num/p < a[i]){
			
			cout<<-1;
			return 0;
		}
		p*= a[i];
	}
	cout<<p;
	
}

Measured memory_bytes: 4420
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define MOD 998244853
int main()
{
    ll n;
    cin>>n;
    ll arr[n],i,dp[n];
    for(i=0;i<n;i++)
    cin>>arr[i];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(i=2;i<n;i++)
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    cout<<dp[n-1];
}

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

int main() {
	int x,N;
  	cin>>x>>N;
  	int p[N];
  	rep(i,N) cin>>p[i];
  	sort(p,p+N);
  	int j=0;
  	int d=150;
  	bool a=false;
  	rep(i,105){
     	if(p[j]==i){
          j++;
          continue;
        }
      	else d=min(d,abs(x-i));
      
    }

  	rep(i,N){
     	if(p[i]==x-d) {
          cout<<x+d<<endl;
          a=true;
        }
    }
  	if(!a) cout<<x-d<<endl;
  	
}

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    LL K; cin >> K;
    set<LL> se;

    LL now = 7 % K;
    LL ans = 1;

    while(1){

        if(now == 0){
            cout << ans << endl;
            return 0;
        }

        if(se.find(now) != se.end()){
            cout << -1 << endl;
            return 0;
        }else{
            ans++;
            se.insert(now);
            now = (now*10 + 7) % K;
        }
        
    }



}

Measured memory_bytes: 50524
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	/** 白チョコを表す文字 */
	private static final char WHITE = '1';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			int k = scanner.nextInt();
			boolean[][] s = new boolean[h][w];
			IntStream.range(0, h).forEach(i -> {
				char[] cs = scanner.next().toCharArray();
				IntStream.range(0, cs.length).forEach(j -> s[i][j] = (cs[j] == WHITE));
			});
			System.out.println(IntStream.range(0, (1 << (h - 1))).map(i -> {
				// 白チョコの数を格納する配列
				int[] counts = new int[Integer.bitCount(i) + 1];
				int result = Integer.bitCount(i);
				for (int j = 0; j < w; j++) {
					int[] now = calcNow(i, h, s, j);
					if (!check(now, k)) {
						return Integer.MAX_VALUE;
					}
					calcSum(counts, now);
					if (!check(counts, k)) {
						counts = now;
						result++;
					}
				}
				return result;
			}).min().getAsInt());
		}
	}

	/**
	 * チョコのj列目の白チョコの個数の配列を計算
	 * 
	 * @param plan チョコを横に分割するプラン
	 * @param h    チョコの高さ
	 * @param s    チョコの配列
	 * @param j    チョコのj列目に対して計算
	 * @return チョコのj列目の白チョコの個数の配列
	 */
	private static int[] calcNow(final int plan, int h, boolean[][] s, int j) {
		int[] result = new int[Integer.bitCount(plan) + 1];
		Arrays.fill(result, 0);
		int index = 0;
		for (int i = 0; i < h; i++) {
			result[index] += (s[i][j]) ? 1 : 0;
			if (0 != ((1 << i) & plan)) {
				index++;
			}
		}
		return result;
	}

	/**
	 * 配列に最大値を超えたものが含まれないかを計算
	 * 
	 * @param array 配列
	 * @param k     チョコの最大値
	 * @return 配列に最大値を超えたものが含まれないか
	 */
	private static boolean check(int[] array, int k) {
		for (int a : array) {
			if (a > k) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 現在のチョコ数配列を合計用チョコ数配列に加算する
	 * 
	 * @param counts 合計用チョコ数配列
	 * @param now    現在のチョコ数配列
	 */
	private static void calcSum(int[] counts, int[] now) {
		for (int i = 0; i < Math.min(counts.length, now.length); i++) {
			counts[i] += now[i];
		}
	}
}


Measured memory_bytes: 43388
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        s: String
    }
    let ans = match &*s {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => 0,
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
import collections

N = int(input())
A = collections.Counter(sorted(list(map(int, input().split()))))

card = [0, 0]
for x in list(A.keys()):
    if A[x] % 2 != 0:
        card[0] += 1
    else:
        card[1] += 1

print(card[0] + card[1] - card[1] % 2)

Measured memory_bytes: 18632
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		int n = sc.nextInt();
		int m = sc.nextInt();
		int count=0;
		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			count=count+a;
			list.add(a);
		}
		//double saite = count/(4*m);
		int ko = 0;
		for(int i=0;n>i;i++) {
			if(list.get(i)*4*m>=count)
				ko++;
		}
		if(ko>=m)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 22996