akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

    // shops[i] = {value, stocks}
    vector<pair<int, int>> shops(n);
    for (int i = 0; i < n; i++) {
        shops[i] = {a[i], b[i]};
    }

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

    int drinks_you_buy = m;
    int money = 0;
    for (int i = 0; i < n; i++) {
        if (drinks_you_buy > shops[i].second) {
            drinks_you_buy -= shops[i].second;
            money += shops[i].first * shops[i].second;
        } else {
            money += shops[i].first * drinks_you_buy;
            drinks_you_buy = 0;
            break;
        }
    }

    cout << money << endl;
}


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

long calc(string s) {
  long ret = 0;
  string tmp = "";
  char op = '+';
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+' || s[i] == '-') {
      if (op == '+') {
        ret += atol(tmp.c_str());
      } else {
        ret -= atol(tmp.c_str());
      }
      op = s[i];
      tmp = "";
    } else {
      tmp += s[i];
    }
  }
  
  if (op == '+') {
    ret += atol(tmp.c_str());
  } else {
    ret -= atol(tmp.c_str());
  }

  return ret;
}

int main() {
  string S;
  cin >> S;
  
  int gapNum = S.size() - 1;

  for (int i = 0; i < (1 << gapNum); i++) { // ビット検索
    string s = S;
    int offset = 0;
    for (int j = 0; j < gapNum; j++) {
      if (i & (1 << j)) { // +
        s.insert(j + 1 + (offset++), "+");
      } else { // -
        s.insert(j + 1 + (offset++), "-");
      }
    }
    if (7 == calc(s)) {
      cout << s << "=7" << endl;
      break;
    }
  }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int powint(int x, int y){
    int res = 1;
    while(y>0){
        if(y&1>0){
            res *= x;
        }
        x *= x;
        y >>= 1;
    }
    return res;
}

int main(){
    int N, M;
    cin >> N >> M;
    int A = 1900*M + 100*(N-M);
    cout << A * powint(2, M) << endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define RV reverse
#define UQ(v) v.erase(unique(ALL(v)), v.end())

LL n;
vector<LL> a;
map<LL, LL> s;

int main() {
	cin >> n;
	inc(i, n) {
		LL x;
		cin >> x;
		a.PB(x);
	}
	
	inc(i, n) { s[a[i]]++; }
	sort(ALL(a));
	UQ(a);
	
	vector<LL> v;
	inc(i, a.size()) {
		if(s[a[i]] >= 2) { v.PB(a[i]); }
		if(s[a[i]] >= 4) { v.PB(a[i]); }
	}
	sort(ALL(v));
	RV(ALL(v));
	
	LL ans = 0;
	if(v.size() >= 2) {
		ans = v[0] * v[1];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7284
#include <stdio.h>
int main(void){
  double l,s,t,diff;
  int n,h,m;
  scanf("%d",&n);
  while(n--){
    scanf("%d:%d",&h,&m);
    l=h*30+m*0.5;
    s=m*6;
    if(l<s){
      t=s;
      s=l;
      l=t;
    }
    diff=l-s;
    if(diff>180)diff=360-diff;
    if(diff<30)puts("alert");
    else if(90<=diff&&diff<=180)puts("safe");
    else puts("warning");
  }
  return 0;
}

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


int main(){

    string b;
    cin >> b;

    if(b =="A"){
        cout << "T" << endl;
    } else if(b=="C"){
        cout << "G" << endl;
    } else if(b=="G"){
        cout << "C" << endl;
    } else if(b=="T"){
        cout << "A" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  var in = readLine().split(" ").map(i => i.toInt)
  var b = 0
  in(1) -= 1
  while (in(1) > 0) {
    in(1) += 1
  	in(1) -= in(0)
    b += 1
  }
  println(b)
}

Measured memory_bytes: 26936
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;cin>>a>>b;
  cout<<max(0LL,a-2*b)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

int main() {

	int N, M;
	std::cin >> N;
	std::vector<std::string> blue(N);
	for (int i = 0; i < N; i++)std::cin >> blue[i];
	std::cin >> M;
	std::vector<std::string> red(M);
	for (int i = 0; i < M; i++)std::cin >> red[i];

	int ans = 0;

	for (int i = 0; i < N; i++) {
		int A = 0;
		int B = 0;//青の中に含まれる最大ダブり個数
		int res = 0;
        
		//青の中に何個のb[i]が含まれるか
		for (int j = i; j < N; j++) {

			if (blue[i] == blue[j])res++;
		}
		if (res >= B)B = res;

		res = 0;
		for (int j = 0; j < M; j++) {
			if (blue[i] == red[j])res++;
		}
		if (res >= A)A = res;

		if (B - A >= ans)ans = B - A;
	}


	std::cout << ans << std::endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string s;
  ull k;
  cin >> s >> k;

  char last = '1';
  rep(i, k) {
    if (s[i] != '1') {
      last = s[i];
      break;
    }
  }

  cout << last;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 8
#define FREE  -1
#define NOT_FREE  1
#define TRUE 2

int row[N],col[N],dpos[N*2-1],dneg[N*2-1];
int X[N][N];

void putQueen(int);
void printBoard(void);

void putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE) continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}

void printBoard(){
  int i,j;
  for(i = 0;i<N;i++) {
    for(j = 0;j<N;j++) {
      if(X[i][j]==TRUE) {
        if(row[i] != j) return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
  return;
}

int main(){
  int i,n,a,b;
  
  for(i=0;i<N;i++){
    row[i]=col[i]=FREE;
  }
  for(i=0;i<N*2-1;i++){
    dpos[i]=dneg[i]=FREE;
  }
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    X[a][b]=TRUE;
  }
  putQueen(0);

  return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===


int dp[3030][3030];


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

	string s, t;
	cin >> s >> t;

	memset(dp, 0, sizeof(dp));

	int ls = (int)s.size(), lt = (int)t.size();

	for (int i = 1; i <= ls; ++i) {
		for (int j = 1; j <= lt; ++j) {
			if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}

	string ans;
	int row = ls, col = lt;
	while (row > 0 && col > 0) {
		if (s[row - 1] == t[col - 1]) {
			ans += s[row - 1];
			--row; --col;
		}
		else {
			if (dp[row][col] == dp[row - 1][col]) {
				--row;
			}
			else {
				--col;
			}
		}
	}

	reverse(ans.begin(), ans.end());

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 36096
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	nn := n

	s := 0
	for {
		if n == 0 {
			break
		}
		tmp := n % 10
		s += tmp
		n /= 10
	}
//	fmt.Printf("%+v\n", s) // output for debug

	if nn%s == 0 {
		fmt.Printf("Yes\n") // output for debug
	} else {
		fmt.Printf("No\n") // output for debug
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#!/usr/local/bin/ruby
n=gets.to_i
n.times{
xa,ya,ra,xb,yb,rb=gets.split.map(&:to_f)
d=Math.sqrt((xb-xa)**2+(yb-ya)**2)
  if d < ra-rb
    puts "2"
  elsif d < rb-ra
    puts"-2"
  elsif d > ra +rb
  puts"0"
  else
    puts "1"
  end
}

Measured memory_bytes: 6136
#include<stdio.h>
int main(void){
    int a=0,b=0,c=0;
    int capa=0;

    scanf("%d %d %d",&a,&b,&c);

    capa=a-b;
    if(capa<=c){
        printf("%d",c-capa);
    }else{
        printf("0");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示


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

	ll n;
	cin >> n;
	ll k;
	cin >> k;
	int ans = 0;
	while (n!=0)
	{
		n /= k;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;

    int memo[300] = {};
    for(int i = 0;i < s.size();i++){
        memo[s[i]] = 1;
    }

    if(memo['S'] == memo['N'] && memo['W'] == memo['E']){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    string S;
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> S;
        if (S == "Y"){
            cout << "Four" << endl;
            break;
        }
        if (i == N-1){
            cout << "Three" << endl;
        }
    }
}

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

using namespace std;

int main(int argc, char **argv) {
    int A[3][3];
    int N;

    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            cin >> A[i][j];

    cin >> N;

    for (int i = 0; i < N; i++) {
        int b;
        cin >> b;
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (A[i][j] == b)
                    A[i][j] = 0;
    }

    bool bingo = false;
    for (int i = 0; i < 3; i++) {
        if (A[i][0] + A[i][1] + A[i][2] == 0)
            bingo = true;
        if (A[0][i] + A[1][i] + A[2][i] == 0)
            bingo = true;
    }
    if (A[0][0] + A[1][1] + A[2][2] == 0)
        bingo = true;
    if (A[2][0] + A[1][1] + A[0][2] == 0)
        bingo = true;


    cout << (bingo ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int N,Y,i,j,k;
	cin >> N >> Y;
	int tmp = Y / 1000;
	for(i=0; i<=2000; i++){
		for(j=0; j<=2000; j++){
			if(i + 5*j + (N-i-j)*10 == tmp && N-i-j >= 0){
				cout << N-i-j << ' ' << j << ' ' << i << endl;
				return 0;
			}
		}
	}
	cout << -1 << ' ' << -1 << ' ' << -1 << endl; 
	
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a, b) a = min((a),(b))
#define CHMAX(a, b) a = max((a),(b))
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
    int x, t;
    cin >> x >> t;
    auto ans = x - t;
    if (ans < 0) {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, a, b;
  cin >> N >> a >> b;
  cout << (abs(b-a)%2 == 0 ? "Alice" : "Borys") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    char c;
    cin >> c;
    if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
        cout << "vowel";
    else cout << "consonant";
    cout << endl;
    return 0;
}


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

int main() {
  int64_t X, ans;
  cin >> X;
  ans=1;
  for (int64_t i=1; i<X; i++) {
    if (i*(i+1)<2*X) {
      ans=ans+1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stack>

int
main(void)
{
	char line[80];
	int m;
	std::stack<int> s;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &m) == 1) {
			if (m == 0) {
				printf("%d\n", s.top());
				s.pop();
			} else {
				s.push(m);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1052
x = int(input())
ans = 8
if x < 600: ans=8
elif x < 800: ans=7
elif x < 1000: ans=6
elif x < 1200: ans=5
elif x < 1400: ans=4
elif x < 1600: ans=3
elif x < 1800: ans=2
else: ans=1
print(ans)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
	int N, K, i, x, sumdistance;

  	sumdistance = 0;
	cin >> N >> K;
	for (i = 0; i < N; ++i)
    {
      cin >> x;
      if ( x < K - x)
      {
        sumdistance += x *2;
      }
      else
      {
        sumdistance +=(K - x) * 2;
      }
    }
	cout << sumdistance << endl;
	return (0);
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int n=s.size(),cnt=15-n;
	for(int i=0;i<n;++i)
		if(s[i]=='o') ++cnt;
	if(cnt>=8) cout<<"YES";
	else cout<<"NO";
	return 0; 
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli a[15][15];
lli c[15];

int main(){

    lli n,m,x;
    cin>>n>>m>>x;

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


    lli ans = INF;
    for(lli bit=0;bit<(1LL<<n);bit++){
        lli sumCost = 0;
        vector<lli> alSum(m,0);

        REP(i,0,n){
            if(!(bit&(1LL<<i)))continue;
            REP(j,0,m)alSum[j] += a[i][j];
            sumCost += c[i];
        }

        bool ok = true;
        REP(i,0,m){
            if(alSum[i]<x)ok=false;
        }

        if(ok){
            chmin(ans,sumCost);
        }

    }
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3596
n = gets.chomp.to_i
def count(i)
  cnt = 0
  while i.even?
    i = i/2
    cnt +=1
  end
  cnt
end
ans = 1
max_cnt = 0
(1..n).each do |i|
  if count(i) > max_cnt
    max_cnt = count(i)
    ans = i
  end
end
puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define deb(x) cout<<#x<<" : "<<x<<"\n";
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define deb_arr(a,n) {cout<<#a<<":";for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';}
#define deb_mat(dist,n,m) {cout<<#dist<<"\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}}
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define all(a) (a).begin(),(a).end()
#define bs binary_search
#define sz size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define clr fflush(stdout);
//#define clr cout.flush();
#define N 200001
#define fpr(i,a,b) for(int i=a;i<b;i++)
#define fdr(i,a,b) for(int i=a;i>b;i--)
#define repp(i,a,b,d) for(int i=a;i<b;i+=d)
#define repd(i,a,b,d) for(int i=a;i>b;i-=d)
#define LLMIN LLONG_MIN
#define LLMAX LLONG_MAX
#define AKASH_PATEL ios_base::sync_with_stdio(false);
#define SVNIT_SURAT cin.tie(NULL);cout.tie(NULL);
#define mset(x,a) memset(x,a,sizeof(x));
#define nl cout<<'\n';
#define print(c) cout<<c<<'\n';
#define setp(n) cout << fixed << setprecision(n)
#define take_arr(a,n) fpr(i,0,n) cin>>a[i];
#define print_arr(a,n) for(int i=0;i<n;i++) {cout<<a[i]<<" ";} cout<<'\n';
#define take_mat(mat,n,m) fpr(i,0,n) fpr(j,0,m) cin>>mat[i][j];
#define set_mat(mat,n,m,k) fpr(i,0,n) fpr(j,0,m) mat[i][j]=k;
#define print_mat(dist,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<dist[i][j]<<" ";}cout<<'\n';}
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > bool odd(T a) { return a&1; }
template< class T > bool even(T a) { return !(a&1); }
int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("../ip.txt", "r", stdin);
//    freopen("../op.txt", "w", stdout);
//#endif
    AKASH_PATEL;
    SVNIT_SURAT;
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[0]=='7' || s[1]=='7' || s[2]=='7')
        {
            print("Yes")
        } else{
            print("No")
        }
    }
    return 0;
}





Measured memory_bytes: 3608
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;
int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
	ll n, m, h, w;
	//cin >> x;
	//string s, t;
	ll x[1005];
	ll y[1005];
	cin >> n;
	for (ll i = 0; i < n; i++)
	{
		cin >> x[i];
		cin >> y[i];
	}
	m = (x[0] + y[0] + ll(pow(2, 32))) % 2;
	for (ll i = 1; i < n; i++)
	{
		if ((x[i] + y[i] + ll(pow(2, 32))) % 2 != m)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	if (m == 0)
	{
		cout << 34 << endl;
	}
	else
	{
		cout << 33 << endl;
	}

	//m = pow(2, 30);
	if (m == 0)
	{
		cout << 1;
		cout << " ";
	}
	for (ll i = 32; i >= 0; i--)
	{
		cout << ll(pow(2, i));
		cout << " ";
	}
	cout << endl;
	for (ll i = 0; i < n; i++)
	{
		w = x[i];
		h = y[i];
		if (m == 0)
		{
			cout << "R";
			w--;
		}
		for (ll k = 32; k >= 0; k--)
		{
			if (abs(w) > abs(h))
			{
				if (w > 0)
				{
					cout << "R";
					w -= pow(2, k);
				}
				else
				{
					cout << "L";
					w += pow(2, k);
				}
			}
			else
			{
				if (h > 0)
				{
					cout << "U";
					h -= pow(2, k);
				}
				else
				{
					cout << "D";
					h += pow(2, k);
				}
			}
		}

		//cout << w << endl;
		//cout << "," << endl;
		//cout << h << endl;
		cout << endl;
	}




	//cout << sum << endl;
	//cout <<  endl;
	return 0;
	}

//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}




//
//ll insuusyurui[1000] = {};
//ll insuukazu[1000] = {};
//ll memo[4000] = {};
//ll memo2[4000] = {};
//cin >> n;
//cin >> m;
//a = 2;
//// √n ≧ a ( n ≧ a * a ) の間ループ処理
//while (n >= a * a) {
//	// a で割り切れたら、a は素因数
//	// そして、割られる数を a で割る
//	// a で割り切れなかったら、 a を 1 増加させる
//	if (n % a == 0) {
//		printf("%lld * ", a);
//		insuukazu[c]++;
//		n /= a;
//	}
//	else {
//		a++;
//		//if (insuukazu[c] != 0)
//		{
//			c++;
//			//cout << c << endl;
//
//		}
//	}
//}
//printf("%lld\n", n);
//for (int i = 0; i < c; i++)
//{
//	//cout << insuukazu[i] << endl;
//}
//
//cout << "Yes" << endl;












//ll n, m;
//cin >> n;
//cin >> m;
//cin >> s;
//cin >> t;
//ll i;
//c = n;
//d = m;
//if (c<d)
//{
//	swap(c, d);
//}
//i = c % d;
//while (i != 0) {
//	c = d;
//	d = i;
//	i = c % d;
//}
//i = n*m / d;

//a = min(n, m);
//b = -1;
//for (ll z = 0; z < i; z++)
//{
//	if (z%m == 0&&z%n==0)
//	{
//		if (s[z / n] != t[z / m])
//		{
//			cout << -1 << endl;
//			return 0;
//		}
//	}


//	z += a;
//	z--;
//	/*
//	if (z % (i / n) == 0)
//	{
//	a++;
//	}
//	if (z % (i / m) == 0)
//	{
//	b++;
//	}
//	if (z % (i / n) == z % (i / m))
//	{
//	if (s[a] != t[b])
//	{
//	cout << -1 << endl;
//	return 0;
//	}
//	}
//	*/
//}


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

int main(){
   int n,a,b;
   string s,t,d;
   cin >> s >> t;
   cin >> a >> b;
   cin >> d;

   if(s==d){
       a--;
   }
   if(t==d){
       b--;
   }



   cout << a <<" "<< b << endl;
}

Measured memory_bytes: 256
/*
** シェルソート
*/
#include <stdio.h>

#define MAX 1000000


int insertionSort(int[], int, int);
int shellSort(int [], int);

int main() {
    int i;
    int array[MAX], n;

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

    shellSort(array, n);

    for (i = 0; i < n; i++) {
        printf("%d\n", array[i]);
    }
}

int shellSort(int array[], int n) {
    int i, m = 0, cnt = 0;
    int gap[MAX];

    for (i = n - 1; i > 1 ; i /= 2) {
        gap[m++] = i;
    }
    gap[m++] = 1;

    printf("%d\n", m);
    for (i = 0; i < m; i++) {
        printf("%d ", gap[i]);
    }
    printf("\n");

    for (i = 0; gap[i] > 0; i++) {
        cnt += insertionSort(array, n, gap[i]);
    }
    printf("%d\n", cnt);
    return cnt;
}

int insertionSort(int array[], int n, int gap) {
    int i, j, cnt = 0;
    int key;

    for (i = gap; i < n; i++) {
        key = array[i];
        j = i - gap;
        while (j >= 0 && key < array[j]) {
            array[j + gap] = array[j];
            j -= gap;
            cnt++;
        }
        array[j + gap] = key;
    }
    return cnt;
}



Measured memory_bytes: 5716
N, M = [int(x) for x in input().split()]
shops = []
for i in range(N):
    shops.append([int(x) for x in input().split()])

shops.sort(key=lambda x:x[0])

money = 0
last = M
for s in shops:
    if s[1] <= last:
        money += s[0] * s[1]
        last -= s[1]
    else:
        money += s[0] * last
        break

print(money)

Measured memory_bytes: 22752
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int count=0;
  string s;
  cin >> s;
  REP(i,s.size()) {
    if(s[i]=='x') count++;
  }
  if(count<8) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

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

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

int main() {
  int N,A;
  cin >> N >> A;
 N=N%500;
  if (9>A&&9>N) {
    cout << "Yay!"<< endl;
  }
  else {
  cout << ":(" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  INT(H);
  INT(W);
  INT(Cy);
  INT(Cx);
  INT(Dy);
  INT(Dx);
  Cy--;
  Cx--;
  Dy--;
  Dx--;
  vector<string> A(H);
  REP(i, H){
    cin >> A.at(i);
  }

  deque<P> deq;
  deq.push_back({Cy,Cx});
  vector<vector<int>> dist(H,vector<int> (W,INF));
  dist[Cy][Cx]=0;
  while(!deq.empty()){
    int vy=deq.front().first;
    int vx=deq.front().second;
    deq.pop_front();
    REP(i,4){
      int nvy=vy+dy[i];
      int nvx=vx+dx[i];
      if(nvy<0||nvx<0||nvy>H-1||nvx>W-1||A[nvy][nvx]=='#') continue;
      if(dist[nvy][nvx]>dist[vy][vx]){
        dist[nvy][nvx]=dist[vy][vx];
        deq.push_front({nvy,nvx});
      }
    }
    REP2(i,-2,2){
      REP2(j,-2,2){
        int nvy=vy+i;
        int nvx=vx+j;
        if(nvy<0||nvx<0||nvy>H-1||nvx>W-1||A[nvy][nvx]=='#') continue;
        if(dist[nvy][nvx]>dist[vy][vx]+1){
          dist[nvy][nvx]=dist[vy][vx]+1;
          deq.push_back({nvy,nvx});
        }
      }
    }
  }

  // REP(i,H){
  //   REP(j,W){
  //     cout << dist[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  if(dist[Dy][Dx]==INF){
    cout << -1 << endl;
  }else{
    cout << dist[Dy][Dx] << endl;
  }
}

Measured memory_bytes: 9532
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

ll n;
ll a[200010];

int main(){
	scanf("%lld",&n);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		a[t-1]=i;
	}
	ll ans=1,temp=1;
	rep(i,1,n){
		if(a[i-1]<a[i])temp++;
		else {ans=max(ans,temp);temp=1;}
	}
	ans=max(ans,temp);
	printf("%lld",n-ans);
}

Measured memory_bytes: 1664
while 1:
	n = input()
	if n == 0: break
	A = sorted(map(int,raw_input().split()))
	c,l = A[0],1
	for i in range(1,n):
		if A[i] == c:
			l += 1
			if l > n/2:
				print c
				break
		else:
			c = A[i]
			l = 1
	else:
		print c if l > n/2 else "NO COLOR"

Measured memory_bytes: 119740
import java.util.*

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

fun problem100a(a: Int, b: Int): String {
    return if (a > 8 || b > 8) ":(" else "Yay!"
}

Measured memory_bytes: 31516
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] dg = br.readLine().split(" ");
		int d = Integer.parseInt(dg[0]);
		int g = Integer.parseInt(dg[1]);

		HashMap<Integer, String[]> map = new HashMap<Integer, String[]>();
		for (int i = 0; i < d; i++) {
			map.put(new Integer((i + 1) * 100), br.readLine().split(" "));
		}

		AtomicInteger min = new AtomicInteger(99999);

		defs(map, g, 0, min);

		System.out.println(min.get());

	}

	public static void defs(HashMap<Integer, String[]> map, int g, int count, AtomicInteger min) {
		Set<Integer> set = map.keySet();
		for (Integer point : set) {
			int gc = g;
			int countc = count;
			String[] pointinfo = map.get(point);
			int monsuu = Integer.parseInt(pointinfo[0]);
			int bonus = Integer.parseInt(pointinfo[1]);
			if (monsuu * point + bonus < gc) {
				gc -= monsuu * point + bonus;
				countc += monsuu;
			} else {
				for (int i = 0; i < monsuu; i++) {
					gc -= point;
					countc++;
					if (min.get() <= countc) {
						continue;
					}
					if (gc <= 0) {
						if (countc < min.get()) {
							min.set(countc);
						}
						continue;
					}
				}
				gc -= bonus;
				if (gc <= 0) {
					if (countc < min.get()) {
						min.set(countc);
					}
					continue;
				}
			}
			HashMap<Integer, String[]> newmap = new HashMap<Integer, String[]>(map);
			newmap.remove(point);
			defs(newmap, gc, countc, min);
		}
	}

}


Measured memory_bytes: 94308
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=998244353;
const ll INF=1e18;

int N;
int a[3030];
int dp[3030][3030];

int solve(int l,int r,int turn){
    if(dp[l][r]!=-1)return dp[l][r];
    if(l==r){
        if(turn%2){
            dp[l][r]=a[l];
            return a[l];
        }else{
            dp[l][r]=-a[l];
            return -a[l];
        }
    }
    if(turn==N+1)return 0;
    
    int ans=0;
    if(turn%2){
        ans=max(solve(l+1,r,turn+1)+a[l],solve(l,r-1,turn+1)+a[r]);
    }else{
        ans=min(solve(l+1,r,turn+1)-a[l],solve(l,r-1,turn+1)-a[r]);
    }
    dp[l][r]=ans;
    return ans;
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N;
    rep(i,0,N){
        cin>>a[i];
    }
    rep(i,0,3030)rep(j,0,3030)dp[i][j]=-1;
    cout<<solve(0,N-1,1)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 72320
#include<bits/stdc++.h>
     
    using namespace std;
    int main(){
      
    	int N;
    	cin>>N;
    	string s;
    	int ac=0, tle= 0, wa= 0, re =0;
      	while(N--){
			cin>>s;
			if( s == "WA") ++wa;
			else if (s == "AC" ) ++ac;
			else if ( s == "TLE" ) ++tle;
			else if(s == "RE" ) ++re;
		
		};
			
		cout<<"AC x " <<ac<<endl;
		cout<<"WA x " <<wa<<endl;
		cout<<"TLE x " <<tle<<endl;
		cout<<"RE x " <<re<<endl;
      
      return 0;
      
    }


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    vector<vector<int>>vec(N,vector<int>(2));
    for(int i=0;i<N;i++){
        for(int j=0;j<2;j++){
            cin >>vec.at(i).at(j);
        }
    }
    int count=0;
    int maxx=0;
    for(int i=0;i<N;i++){
       if(vec.at(i).at(0)==vec.at(i).at(1)){
           count++;
           if(i==N-1){
        maxx=max(count,maxx);
           }
       }
       else{
        maxx=max(count,maxx);
           count=0;
       }
    }
    if(maxx>=3){
        cout<<"Yes"<<endl;
    }
    else{
    cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 3005;
ll dp[nax][nax];

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    // dp[0][n-1]
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = a[L];
            }
            else {
                dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]); // minus here, dp[L+1][R]is the component 
            }
        }
    }
    printf("%lld\n", dp[0][n-1]);
}

Measured memory_bytes: 70016
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		ArrayList<Long> list=new ArrayList<>();
		
		long num=1;
		
		while(num!=n+1)
		{
			if(num%3!=0&&num%5!=0)
			{
				list.add(num);
				num++;
			}
			else
			{
				num++;
			}
		}
		
		long sum=0;
		
		for(int i=0;i<list.size();i++)
		{
			sum=sum+list.get(i);
		}
		
		System.out.println(sum);
		
	}
	
}


Measured memory_bytes: 59488
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;

void solve(){
	int n;
	cin>>n;
	int a[n];
	rep(i,0,n)cin>>a[i];
	sort(a,a+n);
	cout<<a[n/2]-a[(n/2)-1]<<endl;	
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#include <string>
#define ll long long int
#define endl '\n'

void solve()
{
    string s;
    cin>>s;
    ll n = s.length();
    if(s[n-1] == 's')
    {
    	cout<<s<<"es"<<endl;
    	return;
    }
    else
    {
    	cout<<s<<"s"<<endl;
    	return;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef JAY
        freopen("C:/Users/jayra/Desktop/cp/input.txt","r",stdin);
        freopen("C:/Users/jayra/Desktop/cp/output.txt","w",stdout);
    #endif

    int t=1;
    while(t--) {
        solve();
   }
}

Measured memory_bytes: 3644
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	string S;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> S;
			char c = 'A' + j-1;
			if (S == "snuke")cout << c << i<< endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
int set_pasta[101] = { 0 };
int dp[101][4][4] = { 0 };
using namespace std;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1;i <= k;++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		set_pasta[a] = b;
	}
	if (set_pasta[1] == 0) {
		if (set_pasta[2] == 0) {
			for (int a = 1;a <= 3;++a) {
				for (int b = 1;b <= 3;++b) {
					dp[2][a][b] = 1;
				}
			}
		}
		else {
			for (int a = 1;a <= 3;++a) {
				dp[2][a][set_pasta[2]] = 1;
			}
		}
	}
	else {
		if (set_pasta[2] == 0) {
			for (int a = 1;a <= 3;++a) {
				dp[2][set_pasta[1]][a] = 1;
			}
		}
		else {
			dp[2][set_pasta[1]][set_pasta[2]] = 1;
		}
	}
	for (int day = 3;day <= n;++day) {
		if (set_pasta[day] == 0) {
			for (int oldoldpasta = 1;oldoldpasta <= 3;++oldoldpasta) {
				for (int oldpasta = 1;oldpasta <= 3;++oldpasta) {
					for (int nowpasta = 1;nowpasta <= 3;++nowpasta) {
						if (oldoldpasta != oldpasta || oldpasta != nowpasta) {
							dp[day][oldpasta][nowpasta] += dp[day - 1][oldoldpasta][oldpasta];
						}
					}
				}
			}
		}
		else {
			for (int i = 1;i <= 3;++i) {
				for (int q = 1;q <= 3;++q) {
					if (i != q || q != set_pasta[day]) {
						dp[day][q][set_pasta[day]] += dp[day - 1][i][q];
					}
				}
			}
		}
		for (int i = 1;i <= 3;++i) {
			for (int q = 1;q <= 3;++q) {
				dp[day][i][q] = dp[day][i][q] % 10000;
			}

		}
	}
	int num = 0;
	for (int a = 1;a <= 3;++a) {
		for (int b = 1;b <= 3;++b) {
			num += dp[n][a][b];
		}
	}
	num = num % 10000;
	printf("%d\n", num);
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    if ((s[0] == 'R') && (s[1] == 'R') && (s[2] == 'R')) {
        cout << 3 << endl;
    }
    else if ((s[0] == 'R') && (s[1] == 'R')) {
        cout << 2 << endl;
    }
    else if ((s[1] == 'R') && (s[2] == 'R')) {
        cout << 2 << endl;
    }
    else if ((s[0] == 'R') || (s[1] == 'R') || (s[2] == 'R')) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}


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

int main(){
    int X;
    cin >> X;

    int ans = 1;
    for(int i=2;i<32;i++){
        int p = 2;
        while(pow(i, p)<=X){
            if(ans < pow(i, p)){
                ans = pow(i, p);
            }
            p++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main () {
  int K, N;
  cin >> K >> N;

  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  // L.at(i) = (A.at(i)からA.at(i+1)番目までの距離)
  // ただし、L.at(N-1) = (A.at(N-1)からA.at(0)番目までの距離)
  vector<int> L(N, 0);
  for (int i = 0; i < N - 1; i++) {
	L.at(i) = A.at(i+1) - A.at(i);
  }
  L.at(N-1) = K - A.at(N-1) + A.at(0);
  
  sort(L.begin(), L.end());
  int sum = 0;
  for (int i = 0; i < N - 1; i++) {
	sum += L.at(i);
  }
  
  cout << sum;
}

Measured memory_bytes: 1792
n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

from operator import mul
from functools import reduce
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 5
fact = [1, 1]  
factinv = [1, 1]
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if k == 1:
  print(0)
else:
  for i in range(1,n):
    if n-i < k-1:
      break
    ans += a[n-i]*cmb(n-i,k-1,p)
    ans -= a[i-1]*cmb(n-i,k-1,p)
  print(ans%1000000007)

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

using namespace std;

set<string> dic;

int main()
{
	int n;
	string s1,s2;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> s1 >> s2;
		if(s1.length() == 6){
			dic.insert(s2);
		}else{
			set<string>::iterator it = dic.find(s2);
			if(it == dic.end()){
				cout << "no" << "\n";
			}else{
				cout << "yes" << "\n";
			}
		}
	}
}

Measured memory_bytes: 32520
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
#define int long long
int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
int nCrModPFermat(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    int fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
  
int32_t main()
{
  
  int n,i,j,k=1e9+7,l;
  int x,y;
  cin>>x>>y;
  int x1,x2;bool hi=true;
  if((2*y-x)>=0&&(2*y-x)%3==0)
  {
    if((2*x-y)>=0&&(2*x-y)%3==0)
    {
      x1=(2*y-x)/3;x2=(2*x-y)/3;
    }
    else
     hi=false;
  }
  else
   hi=false;
   if(hi)
   {
    l=nCrModPFermat(x1+x2,x1,k);
    cout<<l;
   }
   else
    cout<<"0";
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=1000000007>struct fp {
   int v; static unsigned get_mod(){return mod;}
   int inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp():v(0){}
   fp(ll x):v(x>=0?x%mod:mod+(x%mod)){}
   fp operator-()const{return fp(-v);}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){if((v+=x.v)>=(int)mod)v-=mod; return *this;}
   fp& operator-=(const fp& x){if((v+=mod-x.v)>=(int)mod)v-=mod; return *this;}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
}; using Fp=fp<>;
template<typename T>struct factorial {
   vector<T> Fact,Finv,Inv;
   factorial(int maxx){
      Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
      Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1;
      rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv();
      for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];}
   }
   T fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   T inv(int n){return Inv[n];}
   T nPr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[n-r];}
   T nCr(int n,int r){if(n<0||n<r||r<0)return Fp(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

factorial<Fp> fact(2010101);

int main(){
   int k; cin>>k;
   string s; cin>>s; int n=s.size();
   Fp res;
   rep(i,0,k+1)res+=fact.nCr(n+k-i-1,n-1)*Fp(26).pow(i)*Fp(25).pow(k-i);
   cout<<res.v<<endl;
   return 0;
}

Measured memory_bytes: 28896