akhauriyash/Code-Regression huggingface dataset:
using System;

namespace B___Picture_Frame
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var h = int.Parse (input[0]);
            var w = int.Parse (input[1]);
            var a = new string[h];
            for (var i = 0; i < h; i++)
            {
                a[i] = Console.ReadLine ();
            }
            for (var i = 0; i < w + 2; i++)
            {
                Console.Write ("#");
            }
            Console.WriteLine ();
            for (var i = 0; i < h; i++)
            {
                Console.WriteLine ($"#{a[i]}#");
            }
            for (var i = 0; i < w + 2; i++)
            {
                Console.Write ("#");
            }
            Console.WriteLine ();
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

typedef unsigned int U;

const U R = 1000000;
bool isp[R];
vector<U> primes;

void elatos(){
  memset(isp , 1 , sizeof(isp));
  U n = 0;
  for(U i=2; i < R; i++)
    if(isp[i])
      for(U j=2*i; j < R; j+=i) isp[j] = 0;
  for(U i=2; i<R; i++) if(isp[i]) primes.push_back(i);
}

int main(){
  elatos();
  int n;
  while(cin >> n){
    vector<U>::iterator it = upper_bound(primes.begin(), primes.end() , n);
    cout << it - primes.begin() << endl;
  }
  return 0;
}

Measured memory_bytes: 2568
#!/usr/bin/env python3
def main():
    from collections import deque
    import numpy as np

    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    move = ((0, 1), (0, -1), (1, 0), (-1, 0))
    seen = [[False] * W for _ in range(H)]
    ans = 0
    for sh in range(H):
        for sw in range(W):
            if S[sh][sw] == '#' or seen[sh][sw]:
                continue
            seen[sh][sw] = True
            queue = deque([(sh, sw)])
            # distance = np.zeros((H, W), dtype=np.int16)
            distance = np.full((H, W), -1, dtype=np.int16)
            distance[sh, sw] = 0
            while queue:
                h, w = queue.popleft()
                for dh, dw in move:
                    nh = h + dh
                    nw = w + dw
                    if (1
                            and 0 <= nh < H
                            and 0 <= nw < W
                            and S[nh][nw] == '.'
                            and distance[nh][nw] == -1):
                        distance[nh][nw] = distance[h][w] + 1
                        queue.append((nh, nw))
            ans = max(ans, distance.max())
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27332
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String t = sc.next();

    sc.close();

    String[] S = s.split("");
    String[] T = t.split("");

    HashMap<String, Integer> mapS = new HashMap<String, Integer>();
    HashMap<String, Integer> mapT = new HashMap<String, Integer>();

    for (int i = 0; i < S.length; i++) {
      if (mapS.containsKey(S[i])) {
        int v = mapS.get(S[i]);
        mapS.put(S[i],v+1);
      } else {
        mapS.put(S[i],1);
      }
    }

    for (int i = 0; i < T.length; i++) {
      if (mapT.containsKey(T[i])) {
        int v = mapT.get(T[i]);
        mapT.put(T[i],v+1);
      } else {
        mapT.put(T[i],1);
      }
    }

    int[] arrS = new int[200000];
    int[] arrT = new int[200000];

    for (Integer val : mapS.values()) {
      arrS[val]++;
    }

    for (Integer val : mapT.values()) {
      arrT[val]++;
    }

    String result = "Yes";

    for (int i = 0; i < 200000; i++) {
      if (arrS[i] != arrT[i]){
        result = "No";
        break;
      }
    }

    System.out.println(result);

  }

}

Measured memory_bytes: 68300
#include <bits/stdc++.h>
#define ll long long
#define ar array
using namespace std;

const int mod = 1e9+7;
void add_self(int &a, int b) {a+=b; if(a>=mod) a-=mod;}
void sub_self(int &a, int b) {a-=b; if(a<0) a+=mod;}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
 
  // dp[i] : no. of ways s.t. we used i candies
  vector<int> dp(k+1);
  dp[0] = 1;
  for(int j=0; j<n; j++) {
    int upto;
    cin >> upto;
    vector<int> fake(k+1);
    for(int used=k; used>=0; used--) {
      int L = used + 1;
      int R = used + min(upto, k-used);
      if(L <= R) {
        add_self(fake[L], dp[used]);
        if(R+1 <= k) {
          sub_self(fake[R+1], dp[used]);
        }
      }
    }
    int prefix_sum = 0;
    for(int i=0; i<=k; i++) {
      add_self(prefix_sum, fake[i]);
      add_self(dp[i],  prefix_sum);
    }
  }
  cout << dp[k] << '\n';

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(){

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

	if(x == 1 || x == 2 * n - 1){
		cout << "No" << endl;
		return 0;
	}else{
		cout << "Yes" << endl;
    int ans[200010] = {0};
    bool used[200010] = {false};

		if(x > n){
			ans[n+1] = x + 1; ans[n+2] = x - 2; ans[n] = x;	ans[n-1] = x - 1;
			used[x+1] = true; used[x-2] = true; used[x-1] = true; used[x] = true;
		}else{
			ans[n+1] = x - 1; ans[n+2] = x + 2; ans[n] = x; ans[n-1] = x + 1;
			used[x-1] = 1; used[x+2] = 1; used[x+1] = 1; used[x] = true;
		}

		int cnt = 1;
		for(int i = 1; i < 2 * n; i++){
			if(ans[i] == 0){
				while(used[cnt]){
					cnt++;
				}
				ans[i] = cnt;
				cnt++;
			}
		}

		for(int i = 1; i < 2 * n; i++){
			cout << ans[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

struct stu{
    ll a,b,c,d;
};

vector <stu> condition;
ll ans = 0;
ll n,m,q;

void func(vector <ll> arr){
    if (arr.size() == n){
        ll temp = 0;
        for (int z=0;z<q;z++){
            ll a,b,c,d;
            a = condition[z].a;
            b = condition[z].b;
            c = condition[z].c;
            d = condition[z].d;
            if (arr[b-1]-arr[a-1] == c) temp += d;
        }
        ans = max(ans,temp);
        return;
    }
    if (arr.size() == 0){
        for (int z=1;z<=m;z++){
            arr.push_back(z);
            func(arr);
            arr.pop_back();
        }
    }
    else {
        ll k = arr[arr.size()-1];
        for (int z=k;z<=m;z++){
            arr.push_back(z);
            func(arr);
            arr.pop_back();
        }
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> m >> q;
    condition.resize(q);
    for (int z=0;z<q;z++){
        cin >> condition[z].a >> condition[z].b >> condition[z].c >> condition[z].d;
    }
    vector <ll> arr;
    func(arr);
    cout << ans << endl;
} 

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> a(m);
    for(int i = 0; i < m; i++){
        cin >> a[i].second >> a[i].first;//first = b, second = a
    }

    sort(a.begin(), a.end());
    int x = a[0].first-1;
    int ans = 1;
    for(int i = 0; i < m; i++){
        if(x + 1 <= a[i].second){
            ans++;
            x = a[i].first-1;
        }
    }
    cout << ans << endl;
}

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



int main()
{
    int a,b,c,m;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b)
        m=c;
    else if(b==c)
        m=a;
    else
        m=b;
    printf("%d",m);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

int main() {
    std::string s;
    std::map< char, int > mp;
    bool flag = true;

    std::cin >> s;
    for (char x : s) ++mp[x];
    if (mp.size() != 2) flag = false;
    for (auto m : mp) {
        if (m.second != 2) flag = false;
    }
    std::cout << (flag ? "Yes" : "No") << std::endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll Q,H,S,D;
  cin>>Q>>H>>S>>D;
  ll N;
  cin>>N;
  if(N%2==0)
  cout<<N/2*min(min(D,8*Q),min(4*H,2*S))<<endl;
  else
  cout<<N/2*min(min(D,8*Q),min(4*H,2*S))+min(4*Q,min(2*H,S))<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    cin >> n;
    string s;
    cin >> s;

    bool ans = true;

    rep(i, n/2){
        if(s[i] != s[n/2 + i]){
            ans = false;
            break;
        }
    }

    cout << (ans && n % 2 == 0 ? "Yes": "No") << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = 0
prev = 0
for _ in range(n):
    a = int(input())
    tmp_ans = (a + prev) // 2
    ans += tmp_ans
    if tmp_ans == 0:
        prev = a % 2
    else:
        prev = (a + prev) % 2
print(ans)



Measured memory_bytes: 9060
from heapq import heappush, heappop

N, K = map(int, input().split())
sushi = [[] for _ in range(N+1)]
for _ in range(N):
    t, d = map(int, input().split())
    sushi[t].append(d)
for li in sushi:
    li.sort()

first = [(li[-1], i) for i, li in enumerate(sushi) if li]
first.sort(reverse = True)

kind = 0
v_first = 0
second = []
second_sum = 0
second_cnt = 0

ans = 0
for v, i in first:
    kind += 1
    if kind > K:
        break
    v_first += v
    for d in sushi[i][:-1]:
        heappush(second, d)
        second_sum += d
        second_cnt += 1
    while second_cnt > (K-kind):
        d = heappop(second)
        second_cnt -= 1
        second_sum -= d
    value = kind*kind + v_first + second_sum
    if ans < value:
        ans = value

print(ans)

Measured memory_bytes: 73120
mod = 10**9+7

n, m = gets.to_s.split.map{|t|t.to_i}

# if n == 1
#   puts 1
#   exit
# end

stairs = Array.new(n+1){ 1 }

m.times do
  stairs[gets.to_s.to_i] = 0
end

2.upto(n) do |i|
  next if stairs[i] == 0
  stairs[i] = stairs[i-1] + stairs[i-2]
  stairs[i] %= mod if stairs[i] >= mod 
end

puts stairs[-1] % (10**9+7)


Measured memory_bytes: 2812
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll cnt[10000010];
int main()
{
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) cnt[i] = 1;
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		int j = 2;
		while (i * j <= N) {
			cnt[i * j]++;
			j++;
		}
		ans += cnt[i] * i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 81724
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=200000+10;
char s[maxn],h[maxn];
int i,j,k,l,t,n,m,cnt,num;
int main(){
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	fo(i,1,n)
		if (s[i]=='A') s[i]='1';else s[i]='0';
	i=1;
	fo(l,1,2*n+10){
		t=s[i]-'0';
		if (t^cnt) s[i]=(1-t)+'0';
		else{
			cnt^=1;
			num^=1;
			i++;
		}
		if (l==k){
			fo(j,i,n){
				t=s[j]-'0';
				if (t^cnt) printf("A");else printf("B");
			}
			fo(j,1,i-1){
				if (num) printf("A");else printf("B");
				num^=1;
			}
		}
		if (i>n) break;
	}
	if (l<k){
		if (!num){
			fo(i,1,n)
				if (i%2==1) printf("B");else printf("A");
			return 0;
		}
		fo(i,1,n){
			if (num) h[i]='A';else h[i]='B';
			num^=1;
		}
		if (l%2!=k%2){
			if (h[1]=='A') h[1]='B';else h[1]='A';
		}
		fo(i,1,n) printf("%c",h[i]);
		return 0;
	}
}

Measured memory_bytes: 768
v[]={0,4,2,5,0,5,2,4,0,3,2,1,0,1,2,3,4,3,5,1,1,5,3,4};main(n,c,i,j,s){while(scanf("%d",&n)&&n){int d[]={1,3,6,4,2,5};for(s=1;n--&&scanf(" %s",&c);){c&=255;i=c-78?c-83?c-69?c-87?c-76?20:16:12:8:4:0;c=d[v[i]];for(j=0;j<3;++j)d[v[i+j]]=d[v[i+j+1]];d[v[i+3]]=c;s+=*d;}printf("%d\n",s);}}

Measured memory_bytes: 0
h,w,x=map(int,input().split())
c=[input() for _ in [0]*h]
print(sum(x==sum(i>>k&1 and j>>l&1 and c[k][l]=='#' for k in range(h) for l in range(w)) for i in range(2**h) for j in range(2**w)))

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N;
int A[100000];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    vint vec;
    int cur=0;
    while(cur<N){
        int next=cur+1;
        while(next<N&&A[next]!=A[next-1])next++;
        vec.pb(next-cur);
        cur=next;
    }
    int ans=0;
    if(vec.size()<3)ans=accumulate(all(vec),0ll);
    else rep(i,vec.size()-2)chmax(ans,vec[i]+vec[i+1]+vec[i+2]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2452
#include<bits/stdc++.h>
#define N 100005
#define LL long long
using namespace std;

LL read(){
	char c=getchar();
	LL t=0,f=1;
	while(c>'9'||c<'0') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') t=t*10+c-'0',c=getchar();
	return t*f;
}

int n,op[N],st;
LL sum[N],absum[N]; 
char ch[2];

int main(){
	n=read(),sum[1]=absum[1]=read(),st=op[1]=1;
	for(int i=2,x;i<=n;i++){
		scanf("%s",ch),op[i]=(ch[0]=='-')?-1:1;
		x=read(),sum[i]=sum[i-1]+x*op[i],absum[i]=absum[i-1]+x;
	}
	LL ans=sum[n];
	while(op[st]>0) st++;
	for(int i=st,j=st+1;i<=n;i=j,j++){
		LL tmp=sum[i-1];
		while(op[j]>0&&j<=n) j++;
		tmp+=(absum[n]-absum[j-1])-(absum[j-1]-absum[i-1]);
		ans=max(ans,tmp);
	}
	printf("%lld\n",ans);
}
/*
3
5 - 1 - 3
5
1 - 20 - 13 + 14 - 5
6
3 - 5 + 1 + 6 - 11 - 13
*/

Measured memory_bytes: 2176
#include <stdio.h>

int n;
int a[100000];
unsigned long int sum = 0;

int abs(int a) { if(a > 0) return a; return (-1)*a; }

int main(void)
{
	int i, min = 1000000000, cnt = 0;
	scanf("%d%*c", &n);
	for(i=0;i<n;i++) {
		scanf("%d%*c", &a[i]);
		if(a[i] <= 0) cnt++;
		int tmp = abs(a[i]);
		if(min > tmp) min = tmp;
		sum += tmp;
	}

	if(cnt%2 == 0) printf("%ld", sum);
	else printf("%ld", sum - min*2);
	
	return 0;
}


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

int main(){
	char S[100000];
	int len;
	int count=0;
	scanf("%s",S);
	len = strlen(S);

	if(S[0] == '1'){
		for(int i=0;i<len;i++){
			if(i%2==0 && S[i] != '1'){
				count++;
			}else if(i%2==1 && S[i] != '0'){
				count++;
			}
		}
	}else if(S[0] == '0'){
		for(int i=0;i<len;i++){
			if(i%2==0 && S[i] != '0'){
				count++;
			}else if(i%2==1 && S[i] != '1'){
				count++;
			}
		}

	}

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

Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from itertools import product

h, w = map(int, input().split())
s = np.full((h, w), 'x', dtype='U1')
for i in range(h):
    s[i] = list(input())

d = np.identity(h * w, dtype='i1')
for i, k in product(range(h), range(w)):
    if s[i, k] == '#':
        continue
    for dy, dx in ((-1, 0), (0, -1), (0, 1), (1, 0)):
        y, x = i + dy, k + dx
        if y < 0 or h <= y or x < 0 or w <= x or s[y, x] == '#':
            continue
        d[i*w+k, y*w+x] = 1
        d[y*w+x, i*w+k] = 1

print(floyd_warshall(d).astype('i8').max())


Measured memory_bytes: 20516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.*;
public class Main {
	static int n;
	static int k;
	static int[] arr;
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.valueOf(br.readLine());
		HashMap<String,Integer> map=new HashMap<>();
		map.put("AC",0);
		map.put("WA",0);
		map.put("TLE",0);
		map.put("RE",0);
		for(int i=0;i<n;i++)
		{
			String s=br.readLine();
			if(map.containsKey(s))
				map.replace(s,map.get(s)+1);
		}
		System.out.println("AC x "+map.get("AC"));
		System.out.println("WA x "+map.get("WA"));
		System.out.println("TLE x "+map.get("TLE"));
		System.out.println("RE x "+map.get("RE"));
	}

}


Measured memory_bytes: 44712
package main

import "fmt"

func countPair(S string) (pair int) {
	for i := 0; i+1 < len(S); i++ {
		if S[i] == S[i+1] {
			pair++
			i++
		}
	}
	return pair
}

func main() {
	var s1, s2 string
	var k, ans int
	fmt.Scan(&s1, &k)
	m := make(map[byte]int, 0)
	for i := 0; i < len(s1); i++ {
		m[s1[i]]++
	}
	p1 := countPair(s1)
	s2 = s1 + s1
	p2 := countPair(s2)
	if len(m) == 1 {
		ans = len(s1) * k / 2
	} else if p1*2 == p2 {
		ans = p1 * k
	} else {
		d := p2 - p1*2
		ans = p1*k + (k-1)*d
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
let rec take n l =
  match l with
  | [] -> []
  | x :: xs ->
     if n = 0 then []
     else x :: take (n-1) xs
let () =
  let n, m = Scanf.scanf "%d %d" (fun x y -> x, y) in
  let xyzs = Array.to_list @@ Array.init n (fun _ ->
      Scanf.scanf " %d %d %d"
        (fun x y z -> x, y, z)) in
  List.fold_left (fun (s1,s2,s3,s4,s5,s6,s7,s8) (x, y, z) ->
      ((x+y+z)::s1,
      (x+y-z)::s2,
      (x-y+z)::s3,
      (x-y-z)::s4,
      (-x+y+z)::s5,
      (-x+y-z)::s6,
      (-x-y+z)::s7,
      (-x-y-z)::s8)
    ) ([],[],[],[],[],[],[],[]) xyzs
  |> (fun (s1,s2,s3,s4,s5,s6,s7,s8) ->
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s1) ::
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s2) ::
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s3) ::
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s4) ::
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s5) ::
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s6) ::
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s7) ::
    (List.fold_left (+) 0 @@ take  m @@ List.rev @@ List.sort compare s8) :: [])
|> List.fold_left max 0  
|>  Printf.printf "%d\n"


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define md 1000000007
#define ll long long
int main(){
  int n;
  int dd[1001]={};
  int div = 2;
  ll ans = 1;
  cin>>n;
  for(int i=2;i<=n;i++){
    dd[i] = i;
  }
  for(int i=2;i<=1000;i++){
    if(dd[i] == 0) break;
    if(dd[i] != 1){
      int cnt = 1;
      for(int j=i+1;j<=1000;j++){
        if(dd[j] == 0) break;
        while(dd[j]%i == 0){
          dd[j] /= i;
          cnt++;
        }
      }
      dd[i] = cnt;
    }else dd[i]=0;
  }

  for(int i=2;i<1000;i++){
    ans = (ans*(dd[i]+1))%md;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) max_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

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

    int N; cin >> N;
    vei d(N); rep(i,N) cin >> d[i];
    sort(all(d));

    cout << d[(N/2)] - d[(N/2) - 1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<climits>
using namespace std;

class RMQ{
    //0-index
    public:
    long long  n=1,*data;

    RMQ(long long n_){
        while(n<n_)n*=2;//要素数nを2の冪乗に
        data=new long long [n*2-1];
        for(long long i=0;i<n*2-1;i++)data[i]=100000000000000000;//木を最大値で初期化
    }
    
    void updata(long long k,long long a){//k番目の要素をaに更新
        k+=n-1;//k番目の葉のインデックス
        data[k]=a;//葉を更新
        while(k>0){//頂点に達するまで親を更新
            k=(k-1)/2;
            data[k]=min(data[k*2+1],data[k*2+2]);
        }
    }

    //[a,b)の最小値を返す
    //k 接点番号　[l,r)に対応
    long long query(long long a,long long b,long long k,long long l,long long r){
        if(r<=a||b<=l)return 100000000000000000;//完全に範囲外
        if(a<=l&&r<=b)return data[k];//完全に範囲内
        long long mid=(l+r)/2;
        return min(query(a,b,k*2+1,l,mid),query(a,b,k*2+2,mid,r));
    }
    //query(a,b,0,0,n)を呼ぶ
    long long query(long long a,long long b){return query(a,b,0,0,n);}
};



int main(){
    long long n,m,l,r,c,mi;
    cin>>n>>m;
    RMQ rmq(n);
    rmq.updata(0,0);
    
    vector<tuple<long long,long long,long long>>e(m);
    for(long long i=0;i<m;i++){cin>>l>>r>>c;e[i]=make_tuple(r,l,c);}
    sort(e.begin(),e.end());

    for(long long i=0;i<m;i++){
        l=get<1>(e[i]),r=get<0>(e[i]),c=get<2>(e[i]);
        //cin>>l>>r>>c;
        l--,r--;
        mi=rmq.query(l,r);
        rmq.updata(r,min(mi+c,rmq.query(r,r+1)));
        //e[i]=make_tuple(l,r,c);
    }
    cout<<(rmq.query(n-1,n)==100000000000000000?-1:rmq.query(n-1,n))<<endl;
    return 0;
}

Measured memory_bytes: 4608
if __name__ == '__main__':
    k, s = map(int, input().split())
    ans = 0
    for i in range(k+1):
        if i > s:
            break
        for j in range(k+1):
            z = s - i - j
            if i + j > s:
                break
            elif 0 <= z and z <= k:
                ans += 1
    print(ans)

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

#define MAX_C 30
#define INF 10000000000001
long long d[MAX_C][MAX_C];
long long N;
long long C;

// void warshall_floyd() {
// 	for (int k = 0; k < C; k++) 
// 		for (int i = 0; i < C; i++) 
// 			for (int j = 0; j < C; j++) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
// }

int main(){	
	for(int i = 0 ; i <= MAX_C-1 ; i++){
		for(int j = 0 ; j <= MAX_C-1 ; j++){
			if (i == j) d[i][j] = 0; else d[i][j] = INF;
		}
	}
	scanf("%lld",&N);
	vector< vector<long long> > c(N-1+1,vector<long long>(N-1+1));
	scanf("%lld",&C);
	vector< vector<long long> > D(C-1+1,vector<long long>(C-1+1));
	for(int i = 0 ; i <= C-1 ; i++){
		for(int j = 0 ; j <= C-1 ; j++){
			scanf("%lld",&D[i][j]);
			d[i][j] = D[i][j];
		}
	}
	// warshall_floyd();
	map<long long, long long> m[3];
	for(int i = 0 ; i <= N-1 ; i++){
		for(int j = 0 ; j <= N-1 ; j++){
			scanf("%lld",&c[i][j]);
			m[(i+j)%3][c[i][j]-1]++;
		}
	}

	long long res = INF;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			for (int k = 0; k < C; k++) {
				if (i == j || j == k || k == i) continue;
				long long now = 0;
				for (int l = 0; l < C; l++) {
					now += d[l][i]*m[0][l]+d[l][j]*m[1][l]+d[l][k]*m[2][l];
				}
				res = min(res, now);
			}
		}
	}
	cout << res << endl;

	return 0;
}



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

int uruu(int i){
  if(i%4!=0)return 0;
  else if(i%400==0)return 1;
  else if(i%100==0)return 0;
  return 1;
}

int main(){
  int a,b,k=11111;
  while(1){
    cin>>a>>b;
    if(a==0)break;
    if(k!=11111)cout<<endl;
    k=0;
    for(int i=a;i<=b;i++){
      if(uruu(i)){k++;cout<<i<<endl;}
      
    }
    if(k==0)cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;

#define DEBUG false

int main() {
	
	ll n, m, l, k, a, h;
	//a:テゥツヲツ姪ゥツδス
	//h:テァツ崢ョテァツ堋?・ツ慊ー
	while(cin >> n >> m >> l >> k >> a >> h){
		if(n == 0 && m == 0 && l == 0 && k == 0 && a == 0 && h == 0) break;
	
		vector<bool> cold(n);
		vector<vector<ii>> g(n);
		rep(i, l){
			int tmp;
			cin >> tmp;
			cold[tmp] = true;
		}
		rep(i, k) {
			ll x, y, k;
			cin >> x >> y >> k;
			g[x].push_back(make_pair(y, k));
			g[y].push_back(make_pair(x, k));
		}
		
		vector<vector<bool>> used(n, vector<bool>(m+1, false));
		priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>> > qu;//cost, now, rest
		qu.push(make_pair(0, make_pair(a, m)));
		bool flag = false;
		while(!qu.empty()){
			auto tmp = qu.top();
			qu.pop();
			ll cost = tmp.first;
			ll pos = tmp.second.first;
			ll rest = tmp.second.second;
			if(used[pos][rest]) continue;
			used[pos][rest] = true;
			if(DEBUG) cout << cost << "\t" << pos << endl;
			if(pos == h){
				flag = true;
				cout << cost << endl;
				break;
			}
			
			if(cold[pos] && rest < m) qu.push(make_pair(cost+1, make_pair(pos, rest+1)));
			rep(i, g[pos].size()){
				ll weight = g[pos][i].second;
				if(DEBUG) cout << g[pos][i].first << "\t" << rest << "\t" << weight << endl;
				if(rest - weight >= 0) qu.push(make_pair(cost + weight, make_pair(g[pos][i].first, rest-weight)));
			}
			
		}
		
		if(!flag) cout << "Help!" << endl;
		
	}
	
	
	return 0;
}

Measured memory_bytes: 5324
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}
		System.out.println(set.size());
	}
}

Measured memory_bytes: 21972
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
 
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, k;
  int A[N+1];
  scanf("%d", &n);
  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  trace(A, n);

  for(j = 2;j <= n;j++){
    k = A[j];
    i = j -1;
    while(i > 0 && A[i] > k){
      A[i + 1] = A[i];
      i = i - 1;
      A[i + 1] = k;
    }
    trace(A,n);

  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef unsigned long long ull;

const int inf = 1e9 + 5;
const long double PI = 3.141592653589793;


void solve(){
  char x;
  cin>>x;
  if(x >= 'A' && x <= 'Z'){
    cout << "A" << endl;
  }
  else{
    cout << "a" <<endl;
  }
}  
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 3580
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d;
	cin >> s;
	a--;
	b--;
	c--;
	d--;
	bool ok1, ok2;
	ok1 = true;
	ok2 = true;
	for (int i = a; i < c; i++) {
		if (s[i + 1] == '#' && s[i + 2] == '#') {
			ok1 = false;
		} else if (s[i + 1] == '#' && s[i + 2] == '.') {
			i++;
		}
	}
	for (int i = b; i < d; i++) {
		if (s[i + 1] == '#' && s[i + 2] == '#') {
			ok2 = false;
		} else if (s[i + 1] == '#' && s[i + 2] == '.') {
			i++;
		}
	}
	if (c < d) {
		dump(ok1 && ok2
				 ? "Yes"
				 : "No");
		return 0;
	}
	bool ok = false;
	for (int i = b - 1; i <= d - 1; i++) {
		if (s.substr(i, 3) == "...") ok = true;
	}
	dump(ok1 && ok2 && ok
			 ? "Yes"
			 : "No");

	return 0;
}

Measured memory_bytes: 592
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0; i<n; i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        boolean check = true;
        for(int i = 0; i<n-1; i++){
            if(a[i] == a[i+1]){
                check = false;
                out.println("NO");
                break;
            }
        }
        if(check){
            out.println("YES");
        }
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 56004
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int h,a,cnt=0;cin>>h>>a;
    while(h>0)
    {
        h-=a;
        cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c = inpl()
if a <= c <= a+b:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 5080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s, ans;
  cin >> s;
  
  for (char x : s){
    if (x == '0') ans += "0";
    if (x == '1') ans += "1";
    if (x == 'B' && !ans.empty()) ans.pop_back();
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3568
#dp[i][j]...i番で作れるjの通り数
#出力はdp[n][m]

n = int(input())
A = list(map(int,input().split()))
m = A.pop()
maxN = min(sum(A), 20)
dp = [[0 for i in range(maxN + 1)] for _ in A]
for i in range(len(A)):
  for j in range(maxN + 1):
    if i == 0:
      dp[0][A[i]] = 1
    else:
      if j - A[i] >= 0:
        dp[i][j] += dp[i - 1][j - A[i]]
      if j + A[i] <= maxN:
        dp[i][j] += dp[i - 1][j + A[i]]

print(dp[len(A) - 1][m])



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

using namespace std;

typedef long long ll;

const int maxn = 3010;
const int mod = 1e9+7;

int A[maxn], f[maxn][maxn];

int n, q;

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			f[i][j] = (A[i] < A[j]);
		}
	}
	for (int i = 1; i <= q; i++) {
		int x, y; scanf("%d%d", &x, &y);
		int inv = (mod + 1) / 2;
		for (int j = 1; j <= n; j++) {
			if (j != x && j != y) {
				int s = 1LL * (f[j][x] + f[j][y]) * inv % mod;
				f[j][x] = f[j][y] = s;
			}
		}
		for (int j = 1; j <= n; j++) {
			if (j != x && j != y) {
				int s = 1LL * (f[x][j] + f[y][j]) * inv % mod;
				f[x][j] = f[y][j] = s;
			}
		}
		int s = 1LL * (f[x][y] + f[y][x]) * inv % mod;
		f[x][y] = f[y][x] = s;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < i; j++) {
			ans = (ans + f[i][j]) % mod;
		}
	}
	for (int i = 1; i <= q; i++) ans = 1LL * ans * 2 % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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 ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r=0,w=0;
  rep(i,n) if(s[i]=='R')++r;
  int ans = r;
  rep(i,n){
    if(s[i]=='R') --r;
    else ++w;
    int now = max(r,w);
    ans = min (ans,now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3756
(defun calc (l)
  (+ (abs (- (nth 1 l) (nth 0 l))) (abs (- (nth 2 l) (nth 1 l)))))

(defun perm (now next)
  (let ((minimum 1000000000) (tmp nil))
    (if (equal now nil)
      (calc next)
      (dotimes (i (length now) minimum)
               (setq tmp (perm (append (subseq now 0 i) (nthcdr (+ i 1) now)) (append next (list (nth i now)))))
               (when (> minimum tmp) (setq minimum tmp))))))

(format t "~a~%" (perm (list (read) (read) (read)) '()))

Measured memory_bytes: 12388
import java.io.*;
import  java.util.*;
import static java.lang.System.in;

public class Main{
    static int n,m;
    static long[] head,pos;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int n = sc.nextInt(), Q = sc.nextInt();
        String src = " "+sc.next();
        char[] s = src.toCharArray();
        int[] dp = new int[n+1];
        for(int i=2;i<=n;i++){
            if(s[i]=='C'&&s[i-1]=='A') dp[i] = dp[i-2]+1;
            else dp[i] = dp[i-1];
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=0;i<Q;i++){
            int le = sc.nextInt(), ri = sc.nextInt();
            int ans = dp[ri]-dp[le-1];
            if(le>1&&s[le]=='C'&&s[le-1]=='A') ans--;
            out.println(ans);
        }
        out.flush();
    }
}


Measured memory_bytes: 71772
<?php
/**
 * 標準出力　1行
 */
// 標準入力からの入力値を変数に代入します
$single_line_input = fgets(STDIN);
// 取得した入力値を半角スペースで分解します
$array = explode(" ", $single_line_input );
// 単一行の入力の場合はこれだけで各入力値が配列の要素として使えます

$hitpoint_taka = $array[0];
$attack_taka = $array[1];
$hitpoint_aoki = $array[2];
$attack_aoki = $array[3];


//勝者の名前
$name_victory = '';

while(true){
    //高橋のターン
    $hitpoint_aoki = $hitpoint_aoki - $attack_taka;

    if($hitpoint_aoki <= 0){
        $name_victory = 'taka';
        break;
    }

    //青木のターン
    $hitpoint_taka = $hitpoint_taka - $attack_aoki;

    if($hitpoint_taka <= 0){
        $name_victory = 'aoki';
        break;
    }
}

if($name_victory == 'taka') {
    print('Yes');
}else{
    print('No');
}


Measured memory_bytes: 16084
#include<iostream>
#include<climits>
#include<algorithm>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
	int n, i, j, *a, coun=0;
	cin >> n;
	a = new int(n);
	r(i, n)cin >> a[i];


	r(i, n-1)
	{
		j = i + 1;
		r(j, n-1)
			if (a[j] > a[j+1])
			{
				swap(a[j], a[j+1]);
				coun++;
			}
	}
	r(i, n)
	{
		if (i)cout << " ";
		cout << a[i];
	}
	
	cout << endl <<  coun << endl;
	return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> d){
    sort(ALL(d));
    cout << (d[N/2] - d[N/2-1]) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&d[i]);
    }
    solve(N, std::move(d));
    return 0;
}


Measured memory_bytes: 1024
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VVI ct(10, VI(10, 0));
  REP2(int, i, 1, n+1)
  {

    int a = i, b = i%10;
    while(a >= 10) a /= 10;
    if (a == 0 || b == 0) continue;
    ++ct[a][b];
  }
  int ans = 0;
  REP2(int, i, 1, 10) REP2(int, j, 1, 10) ans += ct[i][j] * ct[j][i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
import java.util.Stack;

public class Main {
    private Stack<Character> stack = new Stack<>();
    private Stack<Integer> stackInt = new Stack<>();
    private void solve(String s){
        for (int i = 0; i < s.length(); ){
            int a, b = 0;
            char c = s.charAt(i);
            if (c == '+'){
                a = stackInt.pop();
                b = stackInt.pop();
                stackInt.push(a + b);
            }
            else if (c == '-'){
                b = stackInt.pop();
                a = stackInt.pop();
                stackInt.push(a - b);
            }
            else if (c == '*'){
                a = stackInt.pop();
                b = stackInt.pop();
                stackInt.push(a * b);
            }
            else if (c != ' '){
                int j = 0;
                a = 0;
                for (c = s.charAt(i); c != ' ';){
                    stack.push(c);
                    c = s.charAt(++i);
                }
                while (!stack.isEmpty()){
                    a += (stack.pop() - '0') * Math.pow(10, j);
                    j++;
                }
                stackInt.push(a);
            }
            i++;
        }
        System.out.println(stackInt.pop());
    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        Main stack = new Main();
        String s = scanner.nextLine();
        stack.solve(s);
    }
}



Measured memory_bytes: 26284
n = int(input())
A = [int(input()) for i in range(n)]

INF = int(1e15)
DP = [[INF] * (n+1) for i in range(5)]
for i in range(4):
    DP[i][0] = 0

for i in range(n):
    DP[0][i+1] = DP[0][i] + A[i]
    DP[1][i+1] = min(DP[0][i], DP[1][i]) + (A[i] % 2 if A[i] != 0 else 2)
    DP[2][i+1] = min(DP[0][i], DP[1][i], DP[2][i]) + (A[i] + 1) % 2
    DP[3][i+1] = min(DP[0][i], DP[2][i], DP[3][i]) + (A[i] % 2 if A[i] != 0 else 2)
    DP[4][i+1] = min(DP[2][i], DP[3][i], DP[4][i]) + A[i]

print(min(DP[i][n] for i in range(1, 5)))

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

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    string r;
    for (int i = 0; i < n; i++) {
        r += s[i];
        r += t[i];
    }
    cout << r << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char str[100001];
  scanf("%s", str);
  int flag;
  char test = 'a';
  int i;
  for(i=0;i<26;i++) {
    flag = 0;
    int j;
    for(j=0;j<100001;j++) {
      char chr = str[j];
      if(chr == 0x00) break;
      //printf("0x%02X ", str[j] & 0x000000ff);
      if(chr == test) {
	flag = 1;
      }
    }
    if(flag == 0) {
      putchar(test);
      break;
    }
    test++;
  }
  if(flag != 0) printf("None");
  return 0;
}


Measured memory_bytes: 256
from sys import stdin

def main():
    n, k = map(int, stdin.readline().rstrip().split())
    a = [int(x)-1 for x in stdin.readline().rstrip().split()]
    n = a[0]
    his = [-1, n]
    f = his.append
    s = set()
    while True:
        n = a[n]
        if n in s:
            f(n)
            break
        f(n)
        s.add(n)
    idx = his.index(his[-1])
    loop = len(his[his.index(his[-1]):-1])
    if len(his) > k:
        print(his[k]+1)
    else:
        t = (k - idx) % loop
        g = his[idx:-1]
        print(g[t]+1)
main()

Measured memory_bytes: 124832
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {

	int N;
	cin >> N;
	string s;
	int a = 0, b = 0, ab = 0;
	bool AllAB = true;

	for (int i = 0; i < N; i++) {
		cin >> s;
		int p = 0;
		while ((p = s.find("AB", p)) != string::npos) {
			ab++; p++;
		}

		if (s.front() == 'B') {
			b++;
			if (s.back() != 'A') AllAB = false;
		}

		if (s.back() == 'A') {
			a++;
			if (s.front() != 'B') AllAB = false;
		}


	}

	if(AllAB && a > 0) cout << ab + a - 1 << endl;
	else cout << ab + min(a, b) << endl;
	//cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
 
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;
 
 
 
int main(){
	int N;
	cin>>N;
	int H[21];
	rep1(i,N)cin>>H[i];
	
	int ans=1;
	for(int i=2;i<=N;i++){
		bool ok=true;
		rep1(j,i-1)if(H[j]>H[i])ok=false;
		if(ok)ans++;
	}
	cout<<ans<<endl;
}

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

int main()
{

        string str;

        cin >> str;

        if (str.find('a') == std::string::npos) {
                cout << "No" << endl;
                return 0;
        }
        if (str.find('b') == std::string::npos) {
                cout << "No" << endl;
                return 0;
        }
        if (str.find('c') == std::string::npos) {
                cout << "No" << endl;
                return 0;
        }
        cout << "Yes" << endl;

}


Measured memory_bytes: 256