akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
using P = pair<int, int>;
/***** MAIN *****/
signed main() {
  int n = in();
  map<string, vector<P>> mp;
  REP(i,n) {
    string name = stin();
    int score = in();
    P tmp = P(score, i+1);
    mp[name].PB(tmp);
  }
  for(auto& itr : mp) {
    string name = itr.first;
    vector<P> v = mp[name];
    SORTR(v);
    for(auto& itr_v : v) {
      cout << itr_v.second << endl;
    }
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

const int N = 200020;

int main()
{
  int n;
  cin >> n;
  long long arr[N], a[n];
  long long sol = 0;
  memset(arr, 0, sizeof arr);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
    arr[a[i]]++;
  }
  for(int i = 1; i < N; i++)
  {
    sol += arr[i] * (arr[i] - 1) / 2;
  } 
  long long ans = sol;
  for(int i = 0; i < n; i++)
  {
    ans = sol;
    if(arr[a[i]] > 1)
      ans = ans - (arr[a[i]] - 1);
    cout << ans << "\n";
  }
  return 0;
}

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

int main() {
	// your code goes here
	string s, t;
	cin >> s >> t;
	int n = s.length(), m = t.length();
	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++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 x = n, y = m;
	while (x > 0 and y > 0) {
		if (s[x - 1] == t[y - 1])
			ans += s[x - 1], x--, y--;
		else {
			if (dp[x - 1][y] > dp[x][y - 1]) {
				x--;
			}
			else
				--y;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
	return 0;
}

Measured memory_bytes: 38520
module RegExp : sig
  type t
  val empty_set : t
  val empty_str : t
  val char : Char.t -> t
  val app : t -> t -> t
  val union : t -> t -> t
  val star : t -> t

  val matches : t -> Char.t list -> bool
end = struct
  type t = { body : regexp; is_nullable : bool }
  and regexp =
    | EmptySet
    | EmptyStr
    | Char of Char.t
    | App of t * t
    | Union of t * t
    | Star of t

  let empty_set =
    { body = EmptySet; is_nullable = false }

  let empty_str =
    { body = EmptyStr; is_nullable = true }

  let char c =
    { body = Char c; is_nullable = false }

  let app re1 re2 =
    match re1, re2 with
    | { body = EmptySet }, _ -> empty_set
    | _, { body = EmptySet } -> empty_set
    | { body = EmptyStr }, _ -> re2
    | _, { body = EmptyStr } -> re1
    | _, _ ->
        { body = App (re1, re2);
          is_nullable = re1.is_nullable && re2.is_nullable }

  let union re1 re2 =
    match re1, re2 with
    | { body = EmptySet }, _ -> re2
    | _, { body = EmptySet } -> re1
    | _, _ ->
        { body = Union (re1, re2);
          is_nullable = re1.is_nullable || re2.is_nullable }

  let star re =
    { body = Star re; is_nullable = true }

  let rec derive c = function
    | { body = EmptySet } -> empty_set
    | { body = EmptyStr } -> empty_set
    | { body = Char c' } ->
        if Char.compare c c' = 0 then empty_str else empty_set
    | { body = App (re1, re2) } ->
        union (if re1.is_nullable then derive c re2 else empty_set) (app (derive c re1) re2)
    | { body = Union (re1, re2) } ->
        union (derive c re1) (derive c re2)
    | { body = Star re } ->
        app (derive c re) (star re)

  let matches re s =
    (List.fold_left (fun re c -> derive c re) re s).is_nullable
end

let () =
  let s = read_line () in
  print_endline @@
  if
    let open RegExp in
    matches
      (* ((dream(er)?)|(erase(r)))* *)
      (star @@
        union
          (app (char 'd') @@ app (char 'r') @@ app (char 'e') @@ app (char 'a') @@ app (char 'm') @@
            union empty_str @@ app (char 'e') @@ char 'r')
          (app (char 'e') @@ app (char 'r') @@ app (char 'a') @@ app (char 's') @@ app (char 'e') @@
            (union empty_str @@ char 'r'))) @@
      Array.to_list @@ Array.init (String.length s) (String.get s)
  then "YES"
  else "NO"

Measured memory_bytes: 6400
#include <stdio.h>

int main(void){
    char str[8][5];
    int i, j;
    int n, n_tmp;
	int a, f = 0;
    while(scanf("%d", &n) != EOF){
 		if(f != 0){
    		putchar('\n');
    	}else {
    		f = 1;
    	}
        n_tmp = n;
        for(i = 0; i < 8; i++){
            for(j = 0; j < 5; j++){
                str[i][j] = '*';
            }
        }

        for(i = 0; i < 8; i++){
            n = n_tmp;
            for(j = 5-1; j >= 0; j--){
            	a = n % 10;
                if(i == 0){
                    if(a >= 5){
                        str[i][j] = ' ';
                    }
                }else if(i == 1){
                	if(a < 5){
                		str[i][j] = ' ';
                	}
                }else if(i == 2){
                    str[i][j] = '=';
                }else if(i > 2){
                    switch(i){
                    case 3:
                        if(a == 0 || a == 5 ){
                            str[i][j] = ' ';
                        }
                        break;
                    case 4:
                        if(a == 1 || a == 6){
                            str[i][j] = ' ';
                        }
                        break;
                    case 5:
                        if(a == 2 || a == 7){
                            str[i][j] = ' ';
                        }
                        break;
                    case 6:
                        if(a == 3 || a == 8){
                            str[i][j] = ' ';
                        }
                        break;
                    case 7:
                        if(a == 4 || a == 9){
                            str[i][j] = ' ';
                        }
                        break;
                    }
                    
                }
                n /= 10;
            }
        }
        for(i = 0; i < 8; i++){
            for(j = 0; j < 5; j++){
                printf("%c", str[i][j]);
            }
            putchar('\n');
        }
        
    }
    return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll INF=1e18+5;
int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);

    int n;cin>>n;
    vl a(n);
    rep(i,n)cin>>a[i];
    int m=1;
    if(n%2)m++;
    vvl dp(n+10,vl(m+1,-INF));
    rep(i,m+1)dp[i][i]=0;
    rep(i,n){
        rep(j,m+1){
            if(dp[i][j]==-INF)continue;
            dp[i+2][j]=max(dp[i+2][j],dp[i][j]+a[i]);
            if (j+1<=m)dp[i+3][j+1]=max(dp[i+3][j+1],dp[i][j]+a[i]);
            if (j + 2 <= m)dp[i+4][j+2]=max(dp[i+4][j],dp[i][j]+a[i]);
        }
    }
 
    ll ans = -INF;
    int mi;
    if (n % 2 == 0) mi = 0;
    else mi = 1;
    for (int i = n; i <= n + 5; i++) {
        for (int j = mi; j <= m; j++) {
            ans=max(ans,dp[i][j]);
        }
    }
    cout << ans << endl;
}

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

bool cmp(char a, char b)
{
	return a>b;
}

int main()
{
	string n, m;
	cin>>n >>m;
	sort(n.begin(), n.end());
	sort(m.begin(), m.end(), cmp);
	if(n<m) cout<<"Yes";
	else cout<<"No";
} 


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c>>d;
	if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d){
		cout<<"Yes";
	}else{cout<<"No";}





	cout<<endl;
} 


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i=0;
    int n;
    int a[1000];
    
    scanf("%d\n", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    
    for(i=n-1; i>=0; i--){
        if(i>0) printf("%d ", a[i]);
        else printf("%d", a[i]);
    }
    
    printf("\n");
    
    return 0;
}



Measured memory_bytes: 2056
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------


int main() {

    LL N;
    cin >> N;

    LL D = (int) pow(2, N);

    vector<LL> S(D);
    for (int i = 0; i < D; i++)cin >> S[i], S[i] = -S[i];
    sort(S.begin(), S.end());

    multiset<LL> mst;
    for (int i = 1; i < D; i++) mst.insert(S[i]);

    vector<LL> already;
    already.push_back(S[0]);

    for (int i = 0; i < N; i++) {
        vector<LL> time;
        for (int j = 0; j < already.size(); j++) {
            LL x = already[j];
            auto it = mst.upper_bound(x);
            if (it == mst.end()) continue;
            time.push_back(*it);
            mst.erase(it);
        }
        for (int j = 0; j < time.size(); j++) already.push_back(time[j]);
    }

    if (mst.size() == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}






























































Measured memory_bytes: 14592
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend()))

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

    if (s=="Sunny") {
        cout<<"Cloudy"<<endl;
    }
    else if (s=="Cloudy") {
        cout<<"Rainy"<<endl;
    }
    else {
        cout<<"Sunny"<<endl;
    }
    
}

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

int main()
{
    int n,i,co=0;
    std::cin>>n;
    std::vector<int>vec;
    while(n--){
        int x;
        std::cin>>x;
        vec.push_back(x);
    }
    for(i=0;i<vec.size();i++){
        if(vec[i]!=i+1)co++;
    }
    (co>2)?
        std::cout<<"NO"<<std::endl:
        std::cout<<"YES"<<std::endl;
}


Measured memory_bytes: 3168
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let x: i32 = sc.read();
    let mut o = 1;
    let even = 2;
    let mut e = 2;
    let mut res = 0;

    while o <= x {
        while e <= x {
            e = e + 2;
            res = res + 1;
        }
        o = o + 2;
        e = even;
    }

    println!("{}", res);
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main() {
  long int N;
  cin >> N;
  long int answer = 100;
  for(long int divide = 1; divide*divide <= N; ++divide){
    if(N % divide == 0){
      long int r = N / divide; 
      long int temp;
      temp = max(log10(r)+1,log10(divide)+1);
      answer = min(answer, temp);
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
 
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
 
ll n, k, m, M = 1e9 + 7;
 
ll gcd(ll a, ll b) {
    if(a % b == 0) return b;
    else return gcd(b, a % b);
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
 
    int min = M;
    rep(i, 100) {
        int sum = 0;
        rep(j, n) {
            sum += pow(a[j] - i, 2);
        }
        if(sum < min) {
            min = sum;
        }
    }
 
    cout << min << endl;
}

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

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

    for(int i=n-1;i>=0;i--){
        if(i==0 ){
            a[i] = b[i];
        }else if(i == n-1){
            a[i] = b[i-1];
        }else{
            a[i] = min(b[i],b[i-1]);
        }
    }

    int sum =0;
    for(int it:a) sum +=it;
    cout << sum << endl;

    return 0;
}


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

int main(){
    
    int N,M,K;
    cin >> N >> M >> K;
    
    for(int i = 0; i <= N;i++){
        for(int j = 0; j <= M ; j++){
            if(j*(N-i)+i*(M-j)==K){
                
                cout << "Yes" <<endl;
                
                return 0;
            }
            
        }
        
    }
    
    cout << "No" << endl;
    return 0;
    
    
}


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

#define GET_STDIN fgets(buf, 1024, stdin)
#define FOR(i, f, n, b) for(int i = (f); i < (n); i += (b))

typedef long long ll;

using namespace std;

int main() {
  char s[1024];
  char buf[1024];

  int a,b,c,d;

  GET_STDIN;
  sscanf(buf, "%1d%1d%1d%1d", &a,&b,&c,&d);

  FOR(i, 0, 8, 1) {
    int op1, op2, op3;

    if (i & 1) {
      op1 = 1;
    } else {
      op1 = 0;
    }

    if (i & 2) {
      op2 = 1;
    } else {
      op2 = 0;
    }

    if (i & 4) {
      op3 = 1;
    } else {
      op3 = 0;
    }

    int result = 0;

    if (op1 == 1) {
      result = a + b;
    } else {
      result = a - b;
    }

    if (op2 == 1) {
      result += c;
    } else {
      result -= c;
    }

    if (op3 == 1) {
      result += d;
    } else {
      result -= d;
    }

    if (result == 7) {
      char op1_c =  op1 ? '+' : '-';
      char op2_c =  op2 ? '+' : '-';
      char op3_c =  op3 ? '+' : '-';
      cout << a << op1_c << b << op2_c << c << op3_c << d << "=7" << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
4 3
0 12 71
81 0 53
14 92 0
1 1 2 1
2 1 1 2
2 2 1 3
1 1 2 2
)");
#define cin input
#endif

int main()
{
	int n, c;
	cin >> n >> c;

	vector<vector<int>> d(c, vector<int>(c));

	REP (i, c)
		REP (j, c)
			cin >> d[i][j];

	vector<vector<int>> h(3, vector<int>(c, 0));

	REP (i, n)
		REP (j, n)
		{
			int x;
			cin >> x;
			++h[(i + j) % 3][--x];
		}

	vector<vector<int>> g(3, vector<int>(c, 0));
	REP (i, 3)
		REP (j, c)
			REP (k, c)
				g[i][j] += h[i][k] * d[k][j];

	int r = 999999999;
	REP (i, c)
		REP (j, c)
		{
			if (j == i)
				continue;
			REP (k, c)
			{
				if (k == i || k == j)
					continue;
				r = min(r, g[0][i] + g[1][j] + g[2][k]);
			}
		}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){
int ans=0;
int n;

scanf("%d",&n);
int a[n],b[n],c[n],d[n];
int use[n];
for(int i=0;i<n;i++){
use[i]=1;
}
for(int i=0;i<n;i++){
	scanf("%d %d",&a[i],&b[i]);
}
for(int i=0;i<n;i++){
	scanf("%d %d",&c[i],&d[i]);
}
int temp;
for(int i=0;i<n-1;i++){
	for(int j=0;j<n-1;j++){
		if(d[j]>d[j+1]){
			temp=d[j+1];
			d[j+1]=d[j];
			d[j]=temp;
			temp=c[j+1];
			c[j+1]=c[j];
			c[j]=temp;
		}
		if(a[j]>a[j+1]){
			temp=a[j+1];
			a[j+1]=a[j];
			a[j]=temp;
			temp=b[j+1];
			b[j+1]=b[j];
			b[j]=temp;
		}
	}
}
for(int i=0;i<n;i++){
	for(int j=n-1;j>=0;j--){
		if((a[j]<c[i])*(b[j]<d[i])){
			if(use[j]){
				use[j]=0;
				ans=ans+1;
				break;
			}
		}
	}
}
printf("%d\n",ans);

}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <iomanip>
#include <math.h>
using namespace std;
typedef long long ll;
 
int main() {
    ll n;
    cin >> n;
    if (n % 2) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0, k = 5;
    while (k <= n) {
        ans += ll(n / k) / 2;
        k*= 5;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
//#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

#define MAX 1000000

bool chk_unique(int a){
    bool ans = true;
    for(int i=2; i<(int)sqrt(a)+1; i++){
        if(a%i==0){
            ans=false;
            break;
        }
    }
    return ans;
}

int main(){
    int x;
    int tmp_x_max;
    int ans;
    cin >> x;
    ans = MAX;
    while(true){
        if(chk_unique(x)==true && x<ans){
            ans = x;
            break;
        }
        x++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

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

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int N = in();

	cout << (N & 1 ? 2 * N : N) << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
S = input().strip()
N = len(S)
A = []
cur = 0
for i in range(1,N):
    if S[i]=="R" and S[i-1]=="L":
        x = S[cur:i]
        A.append((cur,x))
        cur = i
A.append((cur,S[cur:N]))
B = [0 for _ in range(N)]
while A:
    cur,x = A.pop()
    n = len(x)
    for i in range(1,n):
        if x[i]=="L" and x[i-1]=="R":
            ind = i
            break
    if n%2==0:
        B[cur+ind]=n//2
        B[cur+ind-1]=n//2
    else:
        if ind%2==0:
            B[cur+ind] = (n+1)//2
            B[cur+ind-1]=n//2
        else:
            B[cur+ind] = n//2
            B[cur+ind-1]=(n+1)//2
print(*B)

Measured memory_bytes: 17844
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

const long long MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    int ds[n];
    for(int i = 0; i < n; i++){
        cin >> ds[i];
    }

    sort(ds, ds+n);

    cout << (ds[n/2]-ds[n/2-1]) << endl;

    
    return 0;
}


Measured memory_bytes: 888
N,A,B = gets.split.map(&:to_i)
S = gets.chomp
num = 0
rank_b = 1
S.split('').each do |s|
    if s == 'c' then
        puts 'No'
        next
    end
    if num == A+B then
        puts 'No'
        next
    end
    if s == 'b' then
        if rank_b <= B then
            num += 1
            rank_b += 1
            puts "Yes"
        else
            puts 'No'
            next
        end
    else
        num += 1
        puts "Yes"
    end
end

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

using namespace std;

const int N = 1e6;

bool InRange(int x){
    return -N <= x && x <= N;
}

int main()
{
    int k, x;	cin >> k >> x;

    k--;

    for(int i = x - k; i <= x + k; i++)
        if(InRange(i))
            printf("%d ", i);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for (long long i = (long long)(n); i > 0; i--)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define rrepi(i, a, b) for (long long i = (long long)(a); i > (long long)(b); i--)
using namespace std;
typedef long long ll;

// 考える整数の最大値
const int MAX = 500000;
// 今回採用する大きい素数
const long long MOD = 1000000007;

// メモを保管する場所
ll fact[MAX], inv_fact[MAX], inv[MAX];

// メモを計算する
void init() {
    // 初期値設定と1はじまりインデックスに直す
    fact[0] = 1;
    fact[1] = 1;
    inv[0] = 1;
    inv[1] = 1;
    inv_fact[0] = 1;
    inv_fact[1] = 1;
    // メモの計算
    repi(i, 2, MAX){
        // 階乗
        fact[i] = fact[i - 1] * i % MOD;
        // 逆元
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        // 逆元の階乗
        inv_fact[i] = inv_fact[i - 1] * inv[i] % MOD;
    }
}

// 二項係数の実体
ll nCk(long long n, long long k) {
    ll x = fact[n]; // n!の計算
    ll y = inv_fact[n-k]; // (n-k)!の計算
    ll z = inv_fact[k]; // k!の計算
    if (n < k) return 0; // 例外処理
    if (n < 0 || k < 0) return 0; // 例外処理
    return x * ((y * z) % MOD) % MOD; //二項係数の計算
}

int main() {
  init();
  long long S;
  cin>>S;
  long long ans = 0;
  long long kai = S/3;
  rep(i,kai){
    if(i==0){
      S -= 3;
      ans += 1;
    }
    else{
      S -= 3;
      long long ci = S+i;
      ans += nCk(ci,i);
    }
  }
  ans = ans%MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 15308
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;


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

vector<int> G[100010] = {};

int a[100010] = {};
int flag[100010] = {};


// v d c
int query[100010][3] = {};

void dfs(const int& v,const int& dis,const int& color){
    
    
    if( flag[v] >= dis){
        return ;
    }
    
    if(dis == -1){
        return ;
    }
    
    if(!a[v])
        a[v] = color;
    
    flag[v] = dis;
    
    for(const int & V : G[v] ){
        dfs(V,dis-1,color);
    }
    
}

int main(void){
    // Here your code !
    
    for(int i = 0; i < 100010; i++) flag[i] = -10;
    
    ll n,m,q;
    cin >> n >> m;
    
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        
        G[a].push_back(b);
        G[b].push_back(a);
        
    }
    
    cin >> q;
    
    for(int i = 0; i < q; i++){
        
        cin >> query[i][0] >> query[i][1] >> query[i][2];
        
    }
    
    for(int i = q-1; i >= 0; i-- ){
        
        dfs(query[i][0],query[i][1],query[i][2]);
        
    }
    
    
    for(int i = 1; i <= n; i++){
        cout << a[i] << endl;
    }
    
    
}


Measured memory_bytes: 8440
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;;


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

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int maxn = 1e5 + 7;
ll dp[maxn], price[maxn];
int n, m;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	priority_queue<ll> pq; 
	cin >> n >> m;
	rep(i, 0, n) {
		cin >> price[i];
		pq.push(price[i]);
	}
	rep(i, 0, m) {
		ll x = pq.top();
		pq.pop();
		x /= 2;
		pq.push(x);
	}
	ll sum = 0;
	while (!pq.empty()) {
		ll x = pq.top();
		pq.pop();
		sum += x;
	}
	cout << sum << endl;
}

Measured memory_bytes: 4624
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    ll n,k,q;
    cin >> n >> k >> q;
    vector<int> v(n,0);
    REP(i,q) {
        int x;
        cin >> x;
        v[x-1]++;
    }

    REP(i,n) {
        if (k - q + v[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main(){
	long long n,x=0,i;
	cin>>n;
	string s;
	cin>>s;
	for(i = 0;i <= s.size()-1;i ++)
	{
		if(s[i] =='D')
		{
			x --;
			a[i]=x;
		}	
		if(s[i] =='I')
		{
			x ++;
			a[i]=x;
		}
	}
	int mx=-1;
	for(i=0;i<=n;i++){
		if(mx<a[i]){
			mx=a[i];
		}
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<int> pre(200010, -1);
    for(int i=n-1; i>=0; i--){
        pre[a[i]] = i;
    }

    vector<int> nxt;
    for(int i=n-1; i>=0; i--){
        nxt.emplace_back(pre[a[i]]);
        pre[a[i]] = i;
    }

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

    int id = 0;
    int period = 1;
    while(1){
        int nid = nxt[id];
        if(nid <= id) period++;
        id = (nid + 1) % n;
        if(id == 0) break;
    }

    k %= period;
    
    id = 0;
    period = 1;
    while(period < k){
        int nid = nxt[id];
        if(nid <= id) period++;
        id = (nid + 1) % n;
    }

    vector<int> ans;
    set<int> st;
    while(id < n){
        if(ans.size() && st.size() && st.find(a[id]) != st.end()){
            while(1){
                int val = ans.back();
                ans.pop_back();
                st.erase(val);
                if(val == a[id]) break;
            }
        }
        else{
            ans.emplace_back(a[id]);
            st.emplace(a[id]);
        }

        id++;
    }

    int m = ans.size();
    for(int i=0; i<m; i++){
        cout << ans[i] << " \n"[i == m-1];
    }
}

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

int main(){
	std::vector<int> out;
	std::vector<int> stock;
	int a;
	while( std::cin >> a ){
		if( a == 0 ){
			out.push_back(stock.back());
			stock.pop_back();
		}
		else{
			stock.push_back(a);
		}
	}
	
	for(unsigned int i=0; i<out.size(); ++i){
		std::cout << out[i] << std::endl;
	}
	
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string N; cin >> N;
    
    if(N.size()<=2){
        cout << 0 << endl;
        return 0;
    }

    int dp[12][2][2][2][2];
    REP(i,12){
        REP(k,2){
            REP(l,2){
                REP(m,2){
                    REP(n,2){
                        dp[i][k][l][m][n] = 0;
                    }
                }
            }
        } 
    }

    dp[0][0][0][0][0] = 1;
    FOR(i,1,N.size()-2){
        dp[i][1][0][0][0] = 1;
    }

    REP(i,N.size()){//何桁目
        REP(smaller,2){//Smaller？
            REP(three,2){
                REP(five,2){
                    REP(seven,2){
                        REP(x, (smaller?10:(N[i]-'0')+1) ){
                            if(x!=3 && x!=5 && x!=7) continue;
                            //x=3,5,7のみ考慮
                            

                            //N[i]の値で変わっていく
                            dp[i+1][smaller || x<(N[i]-'0')][three || x==3][five || x==5][seven || x==7] += dp[i][smaller][three][five][seven];
                        }
                    }
                }
            }
        }           
    }

    
    cout << dp[N.size()][0][1][1][1] + dp[N.size()][1][1][1][1] << endl;


    return 0;
}

Measured memory_bytes: 3576
(defun prime-p (n)
  (null
    (loop :as i
          :from 2
          :while (<= (* i i) n)
          :when (zerop (mod n i))
          :return '(i))))

(defun solve (n)
  (loop :as i
        :from n
        :when (prime-p i)
        :return i))

(princ (solve (read)))

Measured memory_bytes: 11368
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}

ll inv(ll base) {
    int g = MOD, r = base, x = 0, y = 1;
    while (r != 0) {
        int q = g / r;
        g %= r; swap(g, r);
        x -= q * y; swap(x, y);
    }
    return x < 0 ? x+MOD : x;
}

ll mul(ll A, ll B) {
	return (A*B)%MOD;
}

ll add(ll A, ll B) {
	return (A+B)%MOD;
}

ll dvd(ll A, ll B) {
    return mul(A, inv(B));
}

ll sub(ll A, ll B) {
    return (A-B+MOD)%MOD;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
    int N; cin >> N; int P; cin >> P;
    string S; cin >> S;
    if (P == 5 || P == 2) {
        ll ans = 0;
        F0R(i, N) {
            if ((S[i] - '0') % P == 0) {
                ans += i+1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    ll counts[P]; F0R(i, P) counts[i] = 0;
    counts[0] = 1;
    int cur = 0;
    MOD = P;
    F0R(i, N) {
        cur *= 10; cur += S[i] - '0'; cur %= MOD;
        int val = modExp(10, N-1-i) * cur; val %= MOD;
        counts[val]++;
    }

    ll ans = 0;
    F0R(i, P) ans += (counts[i] * (counts[i] - 1)) / 2;

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



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

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int next = a[0];
  if (next == 2) {
    cout << 1 << endl;
    return 0;
  }

  int num = 1;
  for (int i = 0; i < n - 1; i++) {
    next = a[next - 1];
    num++;

    if (next == 2) {
      cout << num << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Chara
{
	int p;
	string name;
	Chara(string name, int p)
		: name(name), p(p) {}
};
bool operator<(const Chara& a, const Chara& b)
{
	return a.p > b.p || a.p == b.p && a.name < b.name;
}
const int MAX = 114514;
vector<Chara> chara;
bool fav[MAX];
int sum[MAX];
int n, m, k, l;
bool can(int p)
{
	int insert = -1;
	for (int i = k; i >= 0 && insert == -1; --i)
		if (sum[i] + k - i >= p)
			insert = i;
	if (insert == -1)
		return false;
	else if (sum[insert] >= p)
		return true;

	int need = p - sum[insert];
	int left = l;
	for (int i = insert; i < n && need > 0 && left > 0; ++i)
	{
		if (fav[i])
		{
			--need;
			left -= (chara[insert].p - chara[i].p)
				+ (chara[insert].name < chara[i].name ? 1 : 0);
		}
	}
	return need == 0 && left >= 0;
}
int main()
{
	while (scanf("%d%d%d%d", &n, &m, &k, &l), n)
	{
		char buf[16];
		chara.clear();
		rep (i, n)
		{
			int t;
			scanf("%s%d", buf, &t);
			chara.push_back(Chara(buf, t));
		}
		set<string> f;
		rep (i, m)
		{
			scanf("%s", buf);
			f.insert(buf);
		}
		sort(all(chara));


		sum[0] = 0;
		rep (i, n)
		{
			int t = f.count(chara[i].name);
			fav[i] = t == 1;
			sum[i + 1] = sum[i] + t;
		}


		int low = 0, high = k + 1;
		while (low + 1 < high)
		{
			int mid = (low + high) / 2;
			if (can(mid))
				low = mid;
			else
				high = mid;
		}
		printf("%d\n", low);
	}
}

Measured memory_bytes: 8904
#include <stdio.h>
typedef struct {
  char e;
  int num;
}To;
void BubbleSort(To*, int);
void SelectionSort(To*, int);
int main(){
  int flag,n,i;
  char a[3];
  To data[36],data2[36];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",a);
    data[i].e=a[0];
    data[i].num=a[1]-'0';
    data2[i]=data[i];
  }
  
  BubbleSort(data,n);
  for(i=0;i<n;i++){
    printf("%c%d",data[i].e,data[i].num);
    if(i==n-1)break;
    printf(" ");
  }
  printf("\n");
  printf("Stable\n");
 
  SelectionSort(data2,n);
  flag=0;
  for(i=0;i<n;i++){
    printf("%c%d",data2[i].e,data2[i].num);
    if(data2[i].e!=data[i].e)
      flag=1;
    if(i==n-1)break;
    printf(" ");
  }
  printf("\n");
  if(flag==1)
    printf("Not stable\n");
  else printf("Stable\n");
  
 
  return 0;
}
void BubbleSort(To* A, int N){
  int flag=1,i,j;
  To tmp;
  while(flag==1){
    flag=0;
    for(j=N-1;j>=1;j--){
      if(A[j].num<A[j-1].num){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	flag=1;       
      }
    }
  } 
}
void SelectionSort(To* A, int N){
  int i,j,minj;
  To tmp;
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j].num<A[minj].num)
	minj=j;
    }
    tmp=A[i];
    A[i]=A[minj];
    A[minj]=tmp; 
  }
}



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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n, k;
  cin >> n >> k;
  V<int> x(n);
  REP(i, n) cin >> x[i];

  V<int> a, b;
  REP(i, n) {
    if(x[i]>0) a.PB(x[i]);
    else b.PB(-x[i]);
  }
  a.PB(0); b.PB(0);
  sort(ALL(a)); sort(ALL(b));

  int ret = INF;
  REP(i, a.size()) {
    int num = k - i;
    if(num >= b.size() || num < 0) continue;
    chmin(ret, a[i]+b[num]+min(a[i],b[num]));
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  int a, b, c; cin >> a >> b >> c;
  if( a == 5 && b == 5 && c == 7 ) cout << "YES" << endl;
  else if( a == 5 && b == 7 && c == 5 ) cout << "YES" << endl;
  else if( a == 7 && b == 5 && c == 5 ) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
#define ST first
#define ND second
#define PB push_back
#define DET(a,b,c) (LL(b.x-a.x)*LL((c.y-a.y))-LL((c.x-a.x))*LL((b.y-a.y)))

const int MAXN = 100*1000+10;
int n;
int h[MAXN];
int dp[MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<=n;i++) cin>>h[i];
    h[0] = -1000*1000*1000;
    for(int i=2; i<=n;i++) {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n];
}


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

int main() {
	// your code goes here
	while(true){
		int X,Y,n,barrier[17][17]={0},DP[17][17]={0};
		cin >> X >> Y >> n;
		if(X==0 && Y==0)
			break;
		for(int i=0;i<n;i++){
			int x,y;
			cin >> x >> y;
			barrier[x][y]=1;
		}
		DP[1][1]=1;
		for(int i=1;i<=Y;i++){
			for(int j=1;j<=X;j++){
				if(barrier[j][i]==0 && !(i==1 && j==1)){
				DP[j][i]=DP[j-1][i]+DP[j][i-1];
				}
			}
		}
		cout << DP[X][Y] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>

int n,m;

signed main(){
	cin>>n>>m;
	int ans=0;
	if(2*n<=m){
		ans=n+(m-2*n)/4;
	}else{
		ans=m/2;
	}
	cout<<ans<<en;
}




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

using namespace std;

void solve()
{
	string str;
	while(cin >> str)
	{
		bool flag = true;
		for(int i = 1; i < str.size(); ++i)
		{
			if(str[i] == 'A')
			{
				if(!(str[i - 1] == 'B' || str[i - 1] == 'D'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'B')
			{
				if(!(str[i - 1] == 'A' || str[i - 1] == 'C' || str[i - 1] == 'E'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'C')
			{
				if(!(str[i - 1] == 'B' || str[i - 1] == 'F'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'D')
			{
				if(!(str[i - 1] == 'A' || str[i - 1] == 'E' || str[i - 1] == 'G'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'E')
			{
				if(!(str[i - 1] == 'B' || str[i - 1] == 'D' || str[i - 1] == 'F' || str[i - 1] == 'H'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'F')
			{
				if(!(str[i - 1] == 'C' || str[i - 1] == 'E' || str[i - 1] == 'I'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'G')
			{
				if(!(str[i - 1] == 'D' || str[i - 1] == 'H'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'H')
			{
				if(!(str[i - 1] == 'E' || str[i - 1] == 'G' || str[i - 1] == 'I'))
				{
					flag = false;
					break;
				}
			}

			if(str[i] == 'I')
			{
				if(!(str[i - 1] == 'F' || str[i - 1] == 'H'))
				{
					flag = false;
					break;
				}
			}
		}
		if(flag)
		{
			cout << str << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 0;

int main() {
	ll N, M, K;
	cin >> N >> M >> K;
	vector<ll> A(N + 1, 0), B(M + 1, 0);
	for (int i = 1;i <= N;i++) {
		cin >> A[i];
		A[i] += A[i - 1];
	}
	for (int i = 1;i <= M;i++) {
		cin >> B[i];
		B[i] += B[i - 1];
	}
	ll lf = 0, ans = 0, cnt = 0;
	for (int i = 0;i <= N;i++) {
		if (A[i] > K)break;
		lf = K - A[i];
		auto it = upper_bound(all(B), lf);
		it--;
		cnt = it - B.begin();
		ans = max(ans, cnt + i);
	}
	cout << ans << endl;
}

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

int main() {
  int A,B,M;
  cin>>A>>B>>M;
  vector<int>a(A);
  vector<int>b(B);
  for(int i=0;i<A;i++){
    cin>>a.at(i);
  }
  for(int i=0;i<B;i++){
    cin>>b.at(i);
  }
  vector<int>x(M);
  vector<int>y(M);
  vector<int>c(M);
  for(int i=0;i<M;i++){
    cin>>x.at(i)>>y.at(i)>>c.at(i);
  }
  vector<int>answer(M+1);
  for(int i=0;i<M;i++){
    answer.at(i)=a.at(x.at(i)-1)+b.at(y.at(i)-1)-c.at(i);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  answer.at(M)=a.at(0)+b.at(0);
  sort(answer.begin(),answer.end());
  cout<<answer.at(0)<< endl;
}
  

Measured memory_bytes: 2560