akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 10;

vector < int > g[MR];

bool done[MR];

int res;

vector < int > S;

int N, M;

void dfs(int nr)
{
	done[nr] = 1;
	S.push_back(nr);

	REP(i,g[nr].size())
		if(!done[g[nr][i]])
			dfs(g[nr][i]);

	if(S.size() == N)
		res++;

	S.pop_back();
	done[nr] = 0;
}

int main()
{
	scanf("%d%d", &N, &M);
	REP(i,M)
	{
		int a, b;
		scanf("%d%d", &a, &b);a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfs(0);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,stack,stack2;
    while(1){
        cin>>x>>y;
        if(x==0&&y==0)break;
        else{
            stack=max(x,y);
            stack2=min(x,y);
            cout<<stack2<<' '<<stack<<endl;
        }
    }
}



Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int i;
 	string s;
 	cin>>i;
 	cin>>s;
 	if(i>=3200)
 		cout<<s<<endl;
 	else
 		cout<<"red"<<endl;
	 	  	
 	return 0;
}
 	
 					

Measured memory_bytes: 3564
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define cmax(_i,_j) ((_i)<(_j)?(_i)=(_j):0)
#define cmin(_i,_j) ((_i)>(_j)?(_i)=(_j):0)
#define N 200005
using namespace std;
namespace runzhe2000
{
	typedef long long ll;
	int n; ll a[N], ans = 1ll<<60;
	void main()
	{
		scanf("%d",&n);
		for(int i = 1; i <= n; i++) scanf("%lld",&a[i]), a[i] += a[i-1];
		
		int l = 1, r = 3;
		
		for(int i = 2; i < n-1; i++)
		{
			for(; l + 1 < i && abs(a[i]-2*a[l+1]) < abs(a[i]-2*a[l]); l++);
			for(; r + 1 < n && abs(a[n]-a[r+1]-a[r+1]+a[i]) < abs(a[n]-a[r]-a[r]+a[i]); r++);
			cmin(ans, max(max(a[l],a[i]-a[l]),max(a[r]-a[i], a[n]-a[r]))-min(min(a[l],a[i]-a[l]),min(a[r]-a[i], a[n]-a[r])));
		}
		printf("%lld\n",ans);
	}
}
int main()
{
	runzhe2000::main();
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>

using namespace std;

const int DIV = 1000000007;

int dfs(int idx, vector<int> &a, vector<int64_t> &time, int64_t k, int64_t t) {
    if (k == 0)
        return idx;
    if (time[idx] < 0)
        time[idx] = t;
    int to = a[idx];
    if (time[to] >= 0 && time[to] <= time[idx]) {
        int len = time[idx] - time[to] + 1;
        k = k % len;
        if (k == 0)
            return idx;
    }
    return dfs(to, a, time, k - 1, t + 1);
}

void solve(int test, istream &in) {
    int n;
    int64_t k;
    in >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        in >> a[i];
        a[i]--;
    }
    vector<int64_t> time(n, -1);
    int result = dfs(0, a, time, k, 0);
    printf("%d\n", result + 1);
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
    ifstream f("in.txt");
#else
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }

    return 0;
}


Measured memory_bytes: 5636
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
def kaijo(n):
  if n== 1:
    return n
  return n * kaijo(n-1)
N_kaijo = kaijo(N)
a = []
for i in range(N):
  a.append(i+1)
X = list(itertools.permutations(a,N))
p_number = 0
q_number = 0
for i in range(len(X)):
  s = []
  for j in range(N):
    s.append(X[i][j])
  if s == P:
    p_number = i+1
  if s == Q:
    q_number = i+1
if p_number > q_number:
  ans = p_number - q_number
else:
  ans = q_number - p_number
print(ans)

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

int main(){

  int ans;
  string s;
  int a,b;
  string d = "IVXLCDM";
  int k[] = {1,5,10,50,100,500,1000};

  while(cin >> s){
    ans = 0;

    for(int i=0;i<s.size();i++){
      
      a = b = 0;
      for(int j=0;j<7;j++){
	if(s[i] == d[j]) a = k[j];
	if(s[i+1] == d[j]) b = k[j];
      }

      if(a < b){
	ans += b - a;
	i++;
      }
      else ans += a;

    }
  
    cout << ans << endl;

  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define gc() getchar()
#define lowbit(x) ((x) & (-(x)))
using namespace std;
const int N = 4010;
int dp[N][N],n,col[N],val[N],pos[2][N];
int bit[N];
void add(int p,int v) {
  for ( ; p <= n ; p += lowbit(p))
    bit[p] += v;
}
int query(int p) {
  int res = 0;
  for ( ; p ; p -= lowbit(p))
    res += bit[p];
  return res;
}
int ask(int x,int p,int cur) {
  if (x <= cur) return query(x) - 1;
  else return x - p + query(n) - query(x);
}
int main() {
  char tmp;
  scanf("%d",&n);
  n *= 2;
  for (int i = 1 ; i <= n ; ++ i) {
    for (tmp = gc() ; tmp != 'W' && tmp != 'B' ; tmp = gc());
    col[i] = (tmp == 'B');
    scanf("%d",&val[i]);
    pos[col[i]][val[i]] = i;
  }
  memset(dp,0x3f,sizeof dp);
  dp[0][0] = 0;
  for (int i = 0 ; i < n ; ++ i) {
    int st = max(0,i - n/2);
    for (int j = 1 ; j <= i ; ++ j)
      if ((col[j] == 0 && val[j] > st)||(col[j] == 1 && val[j] > i - st)) add(j,1);
    for (int j = i + 1 ; j <= n ; ++ j)
      if ((col[j] == 1 && val[j] <= i - st) || (col[j] == 0 && val[j] <= st)) add(j,1);
    for (int j = st ; j <= i && j <= n/2 ; ++ j) {
      dp[i+1][j] = min(dp[i+1][j],dp[i][j] + ask(pos[1][i-j+1],i+1,i));
      if (j != n/2) dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j] + ask(pos[0][j+1],i+1,i));
      if (j != n/2) {
        if (pos[0][j+1] > i) add(pos[0][j+1],1);
        else add(pos[0][j+1],-1);
      }
      if (i - j != 0) {
        if (pos[1][i-j] <= i) add(pos[1][i-j],1);
        else add(pos[1][i-j],-1);
      }
    }
    int en = min(n/2,i) + 1;
    for (int j = 1 ; j <= i ; ++ j)
      if ((col[j] == 0 && val[j] > en)||(col[j] == 1 && val[j] > i - en)) add(j,-1);
    for (int j = i + 1 ; j <= n ; ++ j)
      if ((col[j] == 1 && val[j] <= i - en) || (col[j] == 0 && val[j] <= en)) add(j,-1);
  }
  printf("%d\n",dp[n][n/2]);
  return 0;
}

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

int main()
{
  string str;

  while (getline(cin,str))
  {
    if (str == ".") return 0;

    stack<char> p;
    bool flag = true;

    for (int i=0;i<str.length();i++)
    {
      if (str[i] == '(') p.push('(');
      else if (str[i] == ')')
      {
        if (!p.empty() && (p.top() != '(')) { flag = false; break; }
        if (p.empty()) { flag = false; break; }
        p.pop();
      }
      else if (str[i] == '[')  p.push('[');
      else if (str[i] == ']')
      {
        if (!p.empty() && (p.top() != '[')) { flag = false; break; }
        if (p.empty()) { flag = false; break; }
        p.pop();
      }
    }
    if (flag && p.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

Measured memory_bytes: 1176
#include<stdio.h>
#include<math.h>

struct Point {double x,y; };

void koch(int n,Point a,Point b){
    if(n==0) return;
    Point s,t,u;
    double th = M_PI*60.0 / 180.0;

    s.x = (2.0*a.x+1.0*b.x) / 3.0;
    s.y = (2.0*a.y+1.0*b.y) / 3.0;
    t.x = (1.0*a.x+2.0*b.x) / 3.0;
    t.y = (1.0*a.y+2.0*b.y) / 3.0;
    u.x = (t.x-s.x)*cos(th) - (t.y-s.y)*sin(th)+s.x;
    u.y = (t.x-s.x)*sin(th) + (t.y-s.y)*cos(th)+s.y;

    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}

int main(){
    Point a,b;
    int n;

    scanf("%d",&n);
    a.x=0;a.y=0;
    b.x=100;b.y=0;
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    return 0;
}



Measured memory_bytes: 2668
var input: string = require('fs').readFileSync('/dev/stdin', 'utf8');
var inputLines: string[] = input.trim().split("\n");
var parts = inputLines[0].split(" ");

var A = parseInt(parts[0]);
var B = parseInt(parts[1]);
var C = parseInt(parts[2]);
var D = parseInt(parts[3]);
console.log(A*B > C*D ? A*B : C*D);

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

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

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

  cin >> s >> w;
  if (w >= s)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  
  return 0;
}


Measured memory_bytes: 3520
import math
def Base_10_to_m2(n):
  if int(n / (-2)) or n < 0:
    a = math.ceil(n / (-2))
    ans.append(n - a * (-2))
    return Base_10_to_m2(a)
  ans.append(n - math.ceil(n / (-2)) * (-2))
  return ans

n = int(input())
ans = []
print("".join(map(str, Base_10_to_m2(n)[::-1])))

Measured memory_bytes: 3064
ns = [int(ls) for ls in input().split()]

X = ns[0]
K = ns[1]
D = ns[2]

if X + K * D <= 0:
  print(abs(X + K * D))
elif X - K * D >= 0:
  print(X - K * D)
elif X + (K - 2) * D <= 0:
  print(min(abs(X + K * D),abs(X + (K - 2) * D)))
elif X - (K - 2) * D >= 0:
  print(min(abs(X - K * D),abs(X - (K - 2) * D)))
else:
  if K % 2 == 1:
    K -= 1
    X += D
  n = X // (D * 2)
  print(min([abs(ns) for ns in
             [X - (2 * a * D) for a in list(range(n-2,n+3))]]))

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
int N, M;
int WA[105000];
bool AC[105000];

void solve() {
	cin >> N >> M;
	int WAnum = 0;
	int ACnum = 0;

	for(int i = 0; i < N; i++) {
	 	WA[i] = 0;
	 	AC[i] = false;
	}

	while(M--) {
	 	int p;
	 	string s1;
	 	cin >> p >> s1;
	 	if(AC[p]) continue;
	 	if(s1 == "AC") {
	 	 	ACnum++;
	 	 	AC[p] = true;
	 	 	WAnum += WA[p];	
	 	}
	 	else if(s1 == "WA")
	 	 	WA[p]++;
	 	}
	 	cout << ACnum << " " << WAnum;
}                                 
	
	int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);

	solve();	

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) {
        ll a, b; cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(all(ab));
    rep(i, n) {
        ll a, b; a = ab[i].first, b = ab[i].second;
        if (i == 0) ab[i] = make_pair(a, b);
        else {
            ab[i] = make_pair(a, ab[i-1].second + b);
        }
    }

    rep(i, n) {
        if (ab[i].second >= k) {
            cout << ab[i].first << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>

int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    int a;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a);
        ans += __builtin_ctz(a);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 128
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    int a,b;
    cin >> a >> b;

    cout << max({a + b, a - b, a * b}) << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int a,b;cin>>a>>b;
  if(a*b%2==0){
    cout<<"Even";
  }else{
    cout<<"Odd";
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*
#ifndef ONLINE_JUDGE
    #define cin f
    #define cout g
    ifstream cin("a.in");
    ofstream cout("a.out");
#endif
*/
long long n,w,x,y,dp[1<<17];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>w;
    for(int i=1;i<=1e5;++i) dp[i]=1e15;
    for(int i=1;i<=n;++i)
    {
        cin>>x>>y;
        for(int j=1e5-y;j>=0;--j) dp[j+y]=min(dp[j+y],dp[j]+x);
    }
    long long ans=0;
    for(int i=1;i<=1e5;++i)
        if(dp[i]<=w) ans=i;
    cout<<ans;
    return 0;
}


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

int main(void)
{
    // input
    vector<vector<int>> a(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, n) cin >> b[i];

    // compute
    vector<vector<int>> bingo(3, vector<int>(3));
    rep(i,3) {
        rep(j, 3) {
            bingo[i][j] = 0;
            rep(b_index, n) {
                if (a[i][j] == b[b_index]) {
                    bingo[i][j] = 1;
                    break;
                }
            }
        }   
    }

    // horizon
    int correspond;
    rep (i, 3) {
        correspond = 1;
        rep (j, 3) {
            if (bingo[i][j] != 1) correspond = 0;
        }
        if (correspond == 1) {
            cout << "Yes" << endl;
            return (0);
        }
    }

    // vertical
    correspond = 0;
    rep (i, 3) {
        correspond = 1;
        rep (j, 3) {
            if (bingo[j][i] != 1) correspond = 0;
        }
        if (correspond == 1) {
            cout << "Yes" << endl;
            return (0);
        }
    }

    // diagonal 1
    correspond = 1;
    rep (i, 3) if (bingo[i][i] != 1) correspond = 0;
    if (correspond == 1) {
        cout << "Yes" << endl;
        return (0);
    }

    // diagonal 2
    correspond = 1;
    rep(i, 3) if (bingo[i][2-i] != 1) correspond = 0;
    if (correspond == 1) {
        cout << "Yes" << endl;
        return (0);
    }

    // output
    cout << "No" << endl;

    // debug
    //rep(i, 3) rep(j, 3) cout << a[i][j];
}


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

using namespace std;

#define ll long long


//1: 1  -> 1
//2: 11 -> 2
//3: 110 101 011 111 -> 4
//4: 1110 1101 1011 0111 1111 -> 5
//5: 01110 01101 01011 00111 01111, 10110 10101 10011 00111 10111, 11010 11001 10011 01011 11011

//dp[i][j] = prob using i coins having j ones
//dp[0][0] = 0, dp[1][0] = (1-p1), dp[2][0] = (1-p1)*(1-p2) ...
//dp[0][1] = 0, dp[0][2] = 0, ...
//dp[i][i] = dp[i-1][i-1] * pi
//dp[1][1] = p1, dp[1][2] = 0, dp[1][3] = 0
//dp[2][1] = dp[1][1] * dp[1][0] + dp[1][0] * dp[1][1], dp[2][2] = dp[1][1] * dp[1][1], dp[2][3] = 0, ...
//dp[3][1] = dp[2][1] * dp[1][0] + dp[2][0] * dp[1][1], dp[3][2] = dp[2][2] * dp[1][0] + dp[1][0] * dp[2][2]
//dp[4][1] = dp[3][1] * dp[1][0] + dp[3][0] * dp[1][1], dp[4][2] = dp[2][2] * dp[2][0] + dp[2][0] * dp[2][2]
//dp[i][j] =                                            dp[4][2] = dp[1][0] * dp[3][2] * dp[1][0]
                                                     // 2*dp[2][2] * dp[1][0] * dp[1][0] * dp[1][0]
                                                     // 2*dp[2][2]*dp[2][0] =

//dp[2][1] = p1 * dp[1][0] + p2 * dp[0][1]
//dp[3][1] = p1 * dp[2][0] + p3 * dp[2][0], dp[3][2] = dp[2][2] * (1-p3) + p3 * dp[2][1]
//dp[3][1] = p3 * dp[2][0] + (1-p3) * dp[2][1]
//dp[i][j] = pi * dp[i-1][j-1] + (1-pi) * dp[i-1][j]

//p1 * (1-p1) + (1-p1)*p1


double totalProb(vector<double>& probs)
{
    vector<vector<double>> dp(probs.size()+1, vector<double>(probs.size()+1, 0));
    dp[1][0] = 1 - probs[0];
    dp[0][0] = 1;
    for(int i = 2; i <= probs.size(); i++)
        dp[i][0] = dp[i-1][0] * (1 - probs[i-1]);
    for(int i = 1; i <= probs.size(); i++)
    {
        for(int j = 1; j <= probs.size(); j++)
        {
            dp[i][j] = probs[i-1] * dp[i-1][j-1] + (1-probs[i-1]) * dp[i-1][j];
        }
    }

//    for(auto& v: dp)
//    {
//        for(auto e: v)
//            cout << e << "                       ";
//        cout << endl;
//    }

    double total = 0;
    for(int i = probs.size() / 2 + 1; i <= probs.size(); i++)
        total += dp[probs.size()][i];

    return total;
}

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

    vector<double> probs;
    for(int i = 0; i < N; i++)
    {
        double prob;
        cin >> prob;
        probs.push_back(prob);
    }

    double answer = totalProb(probs);
    cout << std::setprecision(10) << answer << endl;
    return 0;
}




Measured memory_bytes: 70784
(n,m,),*a=$<.map{|z|z.split.map &:to_i}
r=[-1]*-~n
c=r.dup
f=->x{r[x]>0?f[r[x]]:x}
a.map{|u,v|x,y=[f[u],f[v]].sort|[]
!y||m>0&&[r[x]+=r[y],r[y]=x]and[c[u]-=1,c[v]-=1]
m-=1}
(1..n).map{|i|p c[i]-r[f[i]]}

Measured memory_bytes: 32508
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

public class Program {
	public static void Main() {
		new Calc().calc();
	}
	public class Calc {
		public Calc() { }
		public void calc() {
			Dictionary<char, int> dic = new Dictionary<char, int>();
			for (char i = 'a'; i <= 'z'; i++) {
				dic.Add(i, 0);
			}
			foreach(var item in Console.ReadLine()) {
				dic[item] += 1;
			}
			foreach (var item in dic) {
				if (item.Value % 2 == 1) { Console.WriteLine("No"); return; }
			}
			Console.WriteLine("Yes");
			return;
		}
	}
}

Measured memory_bytes: 13152
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<ll>
using namespace std;

int main(){
    ll t;
    cin >> t;
    ll a = 0, b = 0, c = 0, d = 0;
    while(t--){
        string s;
        cin >> s;
        
        if(s == "AC"){
            a += 1;
        }
        
        if(s == "WA"){
            b += 1;
        }
        
        if(s == "TLE"){
            c += 1;
        }
        
        if(s == "RE"){
            d += 1;
        }
    }
    
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (k == 0) break;
		char c = s[i];
		if (c == 'a') continue;
		if ('z' - c + 1 <= k) {
			k -= 'z' - c + 1;
			s[i] = 'a';
		}
	}
	if (k != 0) {
		s[n-1] = s[n-1] + (k % 26);
	}
	cout << s << endl;
}

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

Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    int N,M; cin >> N >> M;
    if(N==M) cout << "Yes" << endl;
    else     cout << "No" << endl;
    return 0;
}


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

using ll = long long;

#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;

	vector<ll> A;

	ll leaves=0;

	for(int i=0; i<=n; i++)
	{
		ll a;
		cin>>a;
		A.push_back(a);
		if(i>=1) leaves+=a;
	}

	if(A[0]>=1LL)
	{
		if(n==0&&A[0]==1LL) cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}

	ll cur=1LL;
	ll prop=min(2LL,leaves);

	for(int d=1; d<=n; d++)
	{
		// cout << A[d] << " " << prop << endl;

		if(A[d]>prop)
		{
			cout << -1 << endl;
			return 0;
		}

		cur += prop;
		leaves -= A[d];
		prop -= A[d];
		prop = min(leaves,prop+prop);
	}

	if(prop==0) cout << cur << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 4260
def divisor(N):
    div = []
    for i in range(1, int(N ** 0.5 + 1)):
        if N % i == 0:
            div.append(i)
            if i * i != N:
                div.append(N // i)
    return sorted(div)


N = int(input())
ans = 11
for div in divisor(N):
    ans = min(ans, max(len(str(div)), len(str(N // div))))

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int r, g, b, n;
int dp[3001];
int main() {
	scanf("%d %d %d %d", &r, &g, &b, &n);
	dp[0] = 1;
	for (int i = n - 1; 0 <= i; i--)
		for (int j = 1; i + j * r <= n; j++)
			dp[i + j * r] += dp[i];
	for (int i = n - 1; 0 <= i; i--)
		for (int j = 1; i + j * g <= n; j++)
			dp[i + j * g] += dp[i];
	for (int i = n - 1; 0 <= i; i--)
		for (int j = 1; i + j * b <= n; j++)
			dp[i + j * b] += dp[i];
	printf("%d\n", dp[n]);
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, x int
	fmt.Scan(&n, &x)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)

	cnt := 0
	for i := 0; i < len(a); i++ {
		if x >= a[i] {
			cnt++
			x -= a[i]
		}
	}

	if cnt == n && 0 < x {
		cnt--
	}
	
	fmt.Println(cnt)
}

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

using namespace std;

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

int main(){
    int n,p;
    while(cin>>n>>p,n||p){
        int stone = p;
        int turn = 0;
        vector<int> cand(n,0);
        while(1){
            if(stone){
                cand[turn]++;
                stone--;
            }
            else{
                stone = cand[turn];
                cand[turn] = 0;
            }
            if(cand[turn] == p){
                cout << turn << endl;
                break;
            }
            turn++;
            turn %= n;
        }
    }
}

Measured memory_bytes: 1196
n, m = map(int, raw_input().split())
A = []
b = []
    
for i in range(0, n):
   A += [map(int, raw_input().split())]
  
for j in range(0, m):
   b += [input()]
     
for i in range(0, n):
   c = 0
   for j in range(0, m):
      c += A[i][j] * b[j]
   print c

Measured memory_bytes: 6644
n, m = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

xsum = 0
for i, x in enumerate(xlist):
  xsum += i * x - (n - i - 1) * x

ysum = 0
for i, y in enumerate(ylist):
  ysum += i * y - (m - i - 1) * y

print(xsum * ysum % 1000000007)


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

int main() {
  string S;
  cin >> S;
  bool b = false;
  if(S.size()%2 == 1) {
    b = true;
  }
  for(int i = 0; i < S.size(); i++) {
    if(i%2 == 0) {
      if(S.at(i) != 'h') {
        b = true;
        break;
      }
    }
    else if(i%2 == 1) {
      if(S.at(i) != 'i') {
        b = true;
        break;
      }
    }
  }
  if(b == true) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen("A.in","r",stdin);
	long long l,r;
	scanf("%lld%lld",&l,&r);
	int cnt=0;
	while(l<=r) l<<=1,cnt++;
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

typedef long double lld;

#define REP(i,n) for(int i=0;i<n;i++)
#define EPS (1e-9)
#define INF (1e9 + 1)
#define PI (acos(-1))

int N, L;
int a[1000];
int aji = 0;
int ans = 0;
int j;
int zettai = INF;
int main() {
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		a[i] = L;
		aji += a[i];
		L++;
		if (abs(a[i]) < zettai) {
			zettai = abs(a[i]);
			j = i;
		}
	}
	for (int i = 0; i < N; i++) {
		if (i == j) continue;
		ans += a[i];
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s;
  cin >> s;
  sort(ALL(s));
  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <numeric>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

ll powmod(ll x, ll y, ll p) { // O(log y)
    assert (0 <= x and x < p);
    assert (0 <= y);
    ll z = 1;
    for (ll i = 1; i <= y; i <<= 1) {
        if (y & i) z = z * x % p;
        x = x * x % p;
    }
    return z;
}
ll inv(ll x, ll p) { // p must be a prime, O(log p)
    assert ((x % p + p) % p != 0);
    return powmod(x, p-2, p);
}
template <int mod>
int fact(int n) {
    static vector<int> memo(1,1);
    if (memo.size() <= n) {
        int l = memo.size();
        memo.resize(n+1);
        repeat_from (i,l,n+1) memo[i] = memo[i-1] *(ll) i % mod;
    }
    return memo[n];
}
template <int mod>
int choose(int n, int r) { // O(n) at first time, otherwise O(\log n)
    if (n < r) return 0;
    r = min(r, n - r);
    return fact<mod>(n) *(ll) inv(fact<mod>(n-r), mod) % mod *(ll) inv(fact<mod>(r), mod) % mod;
}

constexpr int mod = 1e9+7;
int main() {
    int n, x, y; scanf("%d%d%d", &n, &x, &y);
    vector<vector<int> > w(n);
    repeat (i, n) {
        int c, w_i; scanf("%d%d", &c, &w_i); -- c;
        w[c].push_back(w_i);
    }
    vector<pair<int, int> > min_balls;
    repeat (c, n) if (not w[c].empty()) {
        whole(sort, w[c]);
        min_balls.emplace_back(w[c][0], c);
        whole(sort, min_balls);
        if (min_balls.size() >= 3) min_balls.pop_back();
    }
    if (min_balls.size() == 1) {
        printf("%d\n", 1); // all balls have the same color
        return 0;
    }
    assert (min_balls.size() == 2);
    int min_w = min_balls[0].first;
    int min_w_color = min_balls[0].second;
    int second_w = min_balls[1].first;
    vector<int> connected;
    repeat (c, n) if (not w[c].empty()) {
        int x_connected = whole(upper_bound, w[c], x - w[c][0])  - w[c].begin();
        int y_connected = whole(upper_bound, w[c], y - min_w)    - w[c].begin();
        if (c == min_w_color and second_w != min_w) {
            y_connected = whole(upper_bound, w[c], y - second_w) - w[c].begin();
        }
        if (y_connected) {
            connected.push_back(max(x_connected, y_connected));
        }
    }
    ll result = 1;
    int a = whole(accumulate, connected, 0);
    for (int b : connected) {
        result = result * choose<mod>(a, b) % mod;
        a -= b;
    }
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 10488
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
#define pll pair<ll, ll>
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define um unordered_map
# define pii pair<ll,ll>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int  main()
{
	ll n,m;
	cin>>n>>m;
	vector<ll>arr;
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		ll x;
      	cin>>x;
      	arr.pb(x);
		sum+=arr[i];
	}
	sort(arr.begin(),arr.end());
  	vector<pair<ll,ll>>bha;
    for(ll i=0;i<m;i++)
    {
    	ll x,y;
      	cin>>x>>y;
      	bha.pb(mp(y,x));
    }
  	sort(bha.begin(),bha.end());
  	ll cnt=0;
	sum=0;
    for(ll i=bha.size()-1;i>=0;i--)
    {
    	ll d=min(cnt+bha[i].ss,n);
      	std::vector<ll>::iterator upper1 ;
    	upper1 = std::upper_bound(arr.begin()+cnt, arr.begin()+d, bha[i].ff); 
	ll k=upper1-arr.begin();
      //cout<<bha[i].ff<<" "<<bha[i].ss<<" "<<k<<" "<<d<<"\n";
	sum=sum+(k-cnt)*bha[i].ff;
      cnt=k;
    }
	for(ll i=cnt;i<n;i++)
			sum+=arr[i];
	cout<<sum;
  
}
	
 
	

Measured memory_bytes: 3316
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int M = Integer.parseInt(sc.next());
	  
	  System.out.println(24 + (24 - M));
	  
	  
	  sc.close();
	  
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long int
#define vi vector <int>
#define FOR(i,a,b) for(int i=a; i<b; i++)
using namespace std;
long long x;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   
    cin>>x;
    long long y=x/500;
    long long z=x-y*500;
    cout<<y*1000+(z/5)*5;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#define ll long long
#define endl '\n'
using namespace std;

struct Number{
  int value;
  int idx;
};
vector<Number> vec;
int answer[200001];

int main(void)
{
  cin.tie(NULL); ios_base::sync_with_stdio(false); int N; cin >> N;
  for(int i = 1; i <= N; i++)
    {
      int temp; cin >> temp; vec.push_back(Number{temp, i});
    }
  sort(vec.begin(), vec.end(), [](Number a, Number b) { return a.value < b.value; } );

  for(int i = 0; i < vec.size(); i++)
    {
      auto idx = vec[i].idx;
      if(i < vec.size() / 2) // left side
	{
	  answer[idx] = vec[vec.size() / 2].value;
	}
      else // right side
	{
	  answer[idx] = vec[vec.size() / 2 - 1].value;
	}
    }

  for(int i = 1; i <= N; i++)
    cout << answer[i] << endl;
    
    return 0;
}

/*
 1 2 3 4 5 6 7 8
 */


/*
2 4 4 3
//     2 3 4 4    // vec.size() = 4




 */


Measured memory_bytes: 4720
n = gets.to_i
inputs = gets.chomp.split(" ").map(&:to_i)
m = gets.to_i
drinks = (1..m).map{gets.chomp.split(" ").map(&:to_i)}
m.times { |i|
	tmp = inputs[drinks[i][0]-1]
	inputs[drinks[i][0]-1] = drinks[i][1]
	puts inputs.reduce(:+)
	inputs[drinks[i][0]-1] = tmp
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'

const int mn = 2e5+1;
char a[mn];

signed main() {
  fastio;
  int n; cin >> n;
  int w = 0, r = 0;
  rep(i, n) {
    char ai;
    cin >> ai;
    a[i] = ai;
    if (ai == 'W') w++;
    else r++;
  }

  int res = 0;
  rep(i, r) {
    char& ai = a[i];
    if (ai == 'W') res++;
  }
  cout << res << endl;
}


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

using namespace std;
long long a[85];
void buy(long long &i,long long &yen,long long &stock){
	stock+=yen/a[i];
	yen-=yen/a[i]*a[i];
	return;
}
void sell(long long &i,long long &yen,long long &stock){
	yen+=stock*a[i];
	stock=0;
	return;
}
int main(){
	long long n;
	long long yen=1000,stock=0;
	cin>>n;
	for(long long i=1;i<=n;i++){
		cin>>a[i];
	}
	for(long long i=1;i<n;i++){
		if(a[i]<=a[i+1]){
			sell(i,yen,stock);
			buy(i,yen,stock);
		}
		else{
			sell(i,yen,stock);
		}
	}
	sell(n,yen,stock);
	cout<<yen;
	return 0;
}

Measured memory_bytes: 3620
function read_Int64()
	return Base.parse(Base.Int64, Base.readline(Base.STDIN))
end

function abc123_A()

	const num_antennas = 5

	# STEP.01
	# read out the coordinates of the each antenna
	coordinate = Base.Array{Base.Int64}(num_antennas)

	for itr in Base.range(1, 1, num_antennas)
		coordinate[itr] = read_Int64()
	end

	# STEP.02
	# read out the maximum distance to communicate
	distance_max = read_Int64()

	if coordinate[num_antennas] - coordinate[1] > distance_max
		return ":("
	else
		return "Yay!"
	end


end

Base.println(Base.STDOUT, Main.abc123_A())

Measured memory_bytes: 162908
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            String S=sc.next();
            int L=S.length();
            if(S.equals("-")) break;
            int N=sc.nextInt();
            for(int i=0;i<N;i++){
                int K=sc.nextInt();
                String S2=S.substring(K,L);
                S2+=S.substring(0,K);
                S=S2;
            }
            System.out.println(S);
        }
    }
}


Measured memory_bytes: 26288
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

int main() {
	cin >> N;
	vector<int> vec;
	if (N == 0) {
		cout << 0;
	}
	while (N != 0) {
		int a = abs(N) % 2;
		N -= a;
		N /= -2;
		vec.push_back(a);
	}
	reverse(vec.begin(), vec.end());
	rep(i, vec.size()) {
		cout << vec[i];
	}
}



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

int main(){
	string a,b;
	cin>>a>>b;

	if(a=="H"){
		if(b=="H"){
			cout<<"H";
		}else{
			cout<<"D";
		}
	}else{
		if(b=="H"){
			cout<<"D";
		}else{
			cout<<"H";
		}
	}
}


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

map<ll,ll> mp;

ll ans;

vector< ll > v;

void dfs(int d,int t){
  if(d==(int)v.size()){
    ans+=t;
    return;
  }
  for(int i=0;i<=v[d];i++){
    int nt=t;
    if(v[d]==i)nt*=i+1;
    dfs(d+1,nt);
  }
}

int main(){
  ll n;

  while(cin>>n&&n){
    ans=0;
    v.clear();
    mp.clear();

    ll tmp=n;
    for(ll i=2;i*i<=n;i++){
      while(tmp%i==0){
	mp[i]++;
	tmp/=i;
      }
    }
    if(tmp>1)mp[tmp]++;

    map<ll,ll> :: iterator it;

    for(it=mp.begin();it!=mp.end();it++){
      v.push_back( it->second );
    }

    dfs(0,1);
    cout<< (ans+1)/2<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool isPrime(int x) {
    for (int i = 2; i*i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

int main() {
    speed();
    int x; cin >> x;
    int prime = x;
    while (!isPrime(prime))
        prime++;
    cout << prime << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Ti4 tuple<int, int, int, int>
#define Tlll tuple<ll, ll, ll>
#define PI 3.141592653589793

int main() {
    string s, t = "yuiophjklnm";
    bool b[200] = {};
    for (int i = 0; i < t.size(); i++) b[t[i]] = 1;
    
    while (cin >> s) {
        if (s == "#") return 0;
        int ans = 0;
        for (int i = 0; i < s.size() - 1; i++) {
            if (b[s[i]] ^ b[s[i + 1]]) ans++;
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
int d[100005];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for (int i=0;i<n;i++)
        cin>>d[i];
    sort(d,d+n);
    if (d[n/2]==d[n/2-1])
        cout<<"0\n";
    else cout<<d[n/2]-d[n/2-1]<<'\n';  
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cstdlib>

const int kN = 6;
const int kC = 50;
const int kM = kN * kC + 5;

int N, C, L[kN], M;
double f[kM][1 << kN];

double solve()
{
    std::sort(L, L + N);
    std::vector<int> idx(N - 1);
    for (int i = 0; i < idx.size(); ++ i)
        idx[i] = i;
    M = N * C;

    double ret = 0;
    do {
        memset(f, 0, sizeof(f));
        f[L[N - 1] * N][0] = 1;
        for (int i = 0; i < M; ++ i) {
            if (i % N == 0) continue;
            int id = idx[(i - 1) % N];
            for (int mask = 0; mask < 1 << N - 1; ++ mask) if (~mask >> id & 1) {
                for (int j = i; j <= M; ++ j) {
                    f[std::max(j, std::min(M, i + L[id] * N))][mask ^ 1 << id] += f[j][mask];
                }
            }
        }
        ret += f[M][(1 << N - 1) - 1];
    } while (std::next_permutation(idx.begin(), idx.end()));
    for (int i = 0; i < N - 1; ++ i) {
        ret /= i + 1;
        ret /= C;
    }
    return ret;
}

int main()
{
    scanf("%d%d", &N, &C);
    for (int i = 0; i < N; ++ i)
        scanf("%d", L + i);
    printf("%.13f\n", solve());
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
	int S;
	cin >> S;
	int H = S / 100;
	int U = S - H * 100;
	if ((U==0 || U>12)&&(H==0 || H>12)) {
		cout << "NA" << endl;
	}
	else if (U == 0 || U > 12) {
		cout << "MMYY" << endl;
	}
	else if (H == 0 || H > 12) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "AMBIGUOUS" << endl;
	}
	return 0;
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    int times = x / d;

    if (times >= k) {
        print(x - k * d);
        return 0;
    }
    if ((k - times) % 2 == 0) {
        print(abs(x - times * d));
    } else {
        print(abs(x - (times + 1) * d));
    }

    return 0;
}


Measured memory_bytes: 3656
# -*- coding: utf-8 -*-

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    from collections import Counter

    s = Counter(input())

    if ('S' in s.keys()) and ('N' not in s.keys()):
        print('No')
    elif ('N' in s.keys()) and ('S' not in s.keys()):
        print('No')
    elif ('W' in s.keys()) and ('E' not in s.keys()):
        print('No')
    elif ('E' in s.keys()) and ('W' not in s.keys()):
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 3316
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int a[3];
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	sort(AALL(a, 3));
	bool flag = false;
	if(a[0] == a[1] && a[1] != a[2]) {
		flag = true;
	} else if(a[0] != a[1] && a[1] == a[2]) {
		flag = true;
	}
	puts(flag ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a = IL()
for i in range(5):
  if a[i] == 0:
    print(i+1)
    exit()

Measured memory_bytes: 77256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

const int INF = 1e9;
int N;
vector<int> A;

int memo[100010];
bool vis[100010];

int go(int pos){
  if(pos >= N - 1){
    return 0;
  }
  if(vis[pos]){ return memo[pos]; }
  int best = 0, w = INF, z = INF;
  //salto a n + 1
  w = abs(A[pos] - A[pos + 1]) + go(pos + 1);
  //salto a n + 2
  if(pos + 2 < N){
    z = abs(A[pos] - A[pos + 2]) + go(pos + 2);
  }

  best = min(z, w);
  memo[pos] = best;
  vis[pos] = 1;
  return best;
}

int main() {
  cin>>N;
  A = vector<int> (N);
  for(int &i : A) cin>>i;

  cout<<go(0);
  return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2

int n,M[N][N];
int col[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  col[u] = G;
  d[u] = ++tt;
  for(v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(col[v]==W){
      dfs_visit(v);
    }
  }
  col[u] = B;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++)col[u] = W;
  tt=0;

  for(u=0;u<n;u++){
    if(col[u] == W)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u] );
  }
}

int main(){
  int u,v,i,j,k;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] =0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  dfs();

  return 0;
}



Measured memory_bytes: 2048
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        long[] arr = new long[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();

        long[] dp = new long[n];
        for(int i = 1; i < n; i++)
        	dp[i] = dp[i-1] + Math.min(b, (arr[i] - arr[i-1]) * a);
        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 49836