akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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



int N;
int a[110000];
int d[110000][3];

int main () {
  cin >> N;
  ll ans = 1;

  Rep(i, N) {
    int a;
    cin >> a;

    bool flg = false;
    int ct = 0;
    if (d[i][0] == a) {
      d[i+1][0] = flg ? d[i][0] : d[i][0] + 1;
      flg = true;
      ct++;
    } else {
      d[i+1][0] = d[i][0];
    }

    if (d[i][1] == a) {
      d[i+1][1] = flg ? d[i][1] : d[i][1] + 1;
      flg = true;
      ct++;
    } else {
      d[i+1][1] = d[i][1];
    }

    if (d[i][2] == a) {
      d[i+1][2] = flg ? d[i][2] : d[i][2] + 1;
      flg = true;
      ct++;
    } else {
      d[i+1][2] = d[i][2];
    }

    if (!flg) {
      cout << 0 << "\n";
      return 0;
    } else {
      ans *= ct;
      ans %= MOD;
    }
  }

  cout << ans << "\n";

}

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

#define rep(i,N) repv(i,0,N)
#define reps(i,N) repvs(i,0,N)
#define repv(i,a,b) for(int i=a;i<b;i++)
#define repvs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<","
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d
#define da(arr,N){if(isDebugMode){rep(i,N+1){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N+1){rep(j,M+1){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back
#define s(a) cout<<a<<endl;

auto chmax =[](int &a,int b){ a = max(a, b);};
auto chmin =[](int &a,int b){ a = min(a, b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1};
const int dy[4] = { 1, 0,-1, 0};

bool isDebugMode=1;
//--------------------------------------//
string s;
int ans;
void solve(){
	if(s.size()%2==0) ans++;
	if(s[0]==s[s.size()-1]) ans++;
	if(ans%2==0) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}

int main(){
	cin>>s;
	solve();
	return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;

int main() {

	cin >> N;

	if (N < 600) cout << "8" << endl;
	else if (N < 800) cout << "7" << endl;
	else if (N < 1000) cout << "6" << endl;
	else if (N < 1200) cout << "5" << endl;
	else if (N < 1400) cout << "4" << endl;
	else if (N < 1600) cout << "3" << endl;
	else if (N < 1800) cout << "2" << endl;
	else cout << "1" << endl;


	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl x(n);
	cin>>x;
	ll l,q;
	cin>>l>>q;
	int c=ceil(log2(n+1))+1;
	vvl dp(n,vl(c+1,-1));
	rep(i,n){
		dp[i][0]=upper_bound(all(x),x[i]+l)-x.begin()-1;
		//cout<<dp[i][0]<<",";
	}
	//cout<<endl;
	rep(j,c){
		rep(i,n){
			dp[i][j+1]=dp[dp[i][j]][j];
			//cout<<dp[i][j+1]<<",";
		}
		//cout<<endl;
	}
	rep(_,q){
		int a,b;
		cin>>a>>b;
		a--;b--;
		if(a>b)swap(a,b);
		ll ans=1;
		rrep(i,c+1){
			if(dp[a][i]<b){
				a=dp[a][i];
				ans+=1<<i;
			}
		}
		puta(ans);
	}
	return 0;
}

Measured memory_bytes: 19584
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int K, A, B;
	cin >> K >> A >> B;
	for(int i = A; i <= B; i++){
		if(i%K == 0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;

	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)


using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;


int main(){
	fast_io; cout_precision;
	int k,x;	cin >> k >> x;	for(int i=x-k+1; i<=x+k-1; i++)	cout<<i<<" ";
	
	return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
	sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
	type x;          \
cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f)                  \
	if ((f))                      \
{                             \
	cout << (TRUE__) << endl; \
}                             \
else                          \
{                             \
	cout << FALSE__ << endl;  \
}
#define RS resize
#define CINV(v, N)             \
	do                         \
{                          \
	v.RS(N);               \
	rep(i, N) cin >> v[i]; \
} while (0);
#define RCINV(v, N)             \
	do                          \
{                           \
	v.RS(N);                \
	rrep(i, N) cin >> v[i]; \
} while (0);
	template <typename T>
inline T GET()
{
	T val;
	cin >> val;
	return val;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

string s;
string ans = "keyence";

void init()
{
	cin >> s;
}

bool ch(int a, int b)
{
	string res = "";
	rep(i, s.length()) {
		if (i < a || b <= i) {
			res += s[i];
		}
	}
	return res == ans;
}

void solve()
{
	rep(i, s.length()) {
		reps(j, i, s.length()+1) {
			if (ch(i, j)) {
				cout << "YES" << endl;
				return;
			}
		}
	}
	cout << "NO" << endl;
}


Measured memory_bytes: 256
N, M = map( int, input().split() )
war = []
for _ in range(M):
    a, b = map( int, input().split() )
    war.append( [b, a] )

war.sort()

ans = 1
removed_bridge = war[0][0]-1
for i in range(M):
    if war[i][1] > removed_bridge:
        removed_bridge = war[i][0]-1
        ans += 1

print(ans)

Measured memory_bytes: 20068
import java.io.*;
import java.util.*;
public class Main {
    
    static int solve(int[] arr, int k, int s, HashMap<Integer, Integer> map) {
        if(s >= arr.length) 
            return 0;
        
        if(map.containsKey(s))
            return map.get(s);
        
        int sum = Integer.MAX_VALUE;
        for(int i = 1; i <= k; i++) {
            sum = Math.min(sum, solve(arr, k, s + i, map) + Math.abs(arr[s] - arr[s + i]));
        }
        
        map.put(s, sum);
        return sum;
    }
    
    public static void main(String args[]) {
        int n = 0, k = 0;
        int[] arr = null;
        try (Scanner scanner = new Scanner(System.in)) {
            n = scanner.nextInt();
            k = scanner.nextInt();
            
            arr = new int[n];
            for (int i=0; i < n; i++) {
                arr[i] = scanner.nextInt();
            }
        }
        int[] dp = new int[n];
        dp[1] = Math.abs(arr[1] - arr[0]);
        for(int i = 2; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = 1; j <= k ; j++) {
                if(i - j >= 0)
                    dp[i] = Math.min(dp[i - j] + Math.abs(arr[i] - arr[i - j]), dp[i]);
            }
        }
        
        System.out.println(dp[n - 1]);
    }
}

Measured memory_bytes: 49848
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n,k;
  cin>>n>>k;
    vector<pair<int,int>> ab(n);
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    ab.at(i)=make_pair(a,b);
  }
  sort(ab.begin(),ab.end());
  int64_t B=0;
  for(int i=0;i<n;i++){
    B+=ab.at(i).second;
    if(B>=k){
      cout<<ab.at(i).first;
      break;
    }
  }
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Dice dice = new Dice();
        dice.inputDice(sc);

        String t = sc.next();
        dice.move(t);

        System.out.println(dice.getTop());

    }

    static class Dice {
        private List<Integer> D = new ArrayList<>();

        void inputDice(Scanner sc)  {
            for (int i = 0; i < 6; i++) D.add(Integer.parseInt(sc.next()));
        }

        int getTop() {
            return D.get(0);
        }

        void move(String t) {
            for (String s : t.split("")) {
                switch (s) {
                    case "N":
                        moveN();
                        break;
                    case "E":
                        moveE();
                        break;
                    case "W":
                        moveW();
                        break;
                    case "S":
                        moveS();
                        break;
                }
            }
        }

        private void moveN() {
            List<Integer> tmp = new ArrayList<>();

            tmp.add(D.get(1));
            tmp.add(D.get(5));
            tmp.add(D.get(2));
            tmp.add(D.get(3));
            tmp.add(D.get(0));
            tmp.add(D.get(4));

            D = new ArrayList<>(tmp);
        }

        private void moveE() {
            List<Integer> tmp = new ArrayList<>();

            tmp.add(D.get(3));
            tmp.add(D.get(1));
            tmp.add(D.get(0));
            tmp.add(D.get(5));
            tmp.add(D.get(4));
            tmp.add(D.get(2));

            D = new ArrayList<>(tmp);
        }

        private void moveW() {
            moveE();
            moveE();
            moveE();
        }

        private void moveS() {
            moveN();
            moveN();
            moveN();
        }
    }
}

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

int n;

void makeStr(int i, char x, string s){
  if(i == n){
    cout << s << endl;
  }else{
    for(char c = 'a'; c <= x+1; c++){
      if(c != x+1){
      	makeStr(i+1, x, s + c);  
      }else{
        makeStr(i+1, c, s + c);
      }
    }
  }
}

int main() {
  cin >> n;
  
  makeStr(1, 'a', "a");
  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
const int MOD = 1e9+7;

int n;
int dp[1000010][2][2]; // [N][0を含むかどうか][9を含むかどうか]

ll modpow(ll x, ll y) {
  ll v = 1;
  REP(i,y) { v *= x; v %= MOD; }
  return v;
}

// 包除原理解法
void solve1() {
  ll p1 = modpow(10, n);
  ll p2 = (modpow(9, n) * 2) % MOD;
  ll p3 = modpow(8, n);
  ll ans = p1 - (p2 - p3);
  ans %= MOD;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}

// DP解法
void solve2() {
  dp[0][0][0] = 1;
  REP(i,n) {
    REP(j,2) {
      REP(k,2) {
        REP(x,10) {
          int nj = j | x == 0;
          int nk = k | x == 9;
          dp[i+1][nj][nk] += dp[i][j][k];
          dp[i+1][nj][nk] %= MOD;
        }
      }
    }
  }
  cout << dp[n][1][1] << endl;
}

int main() {
  cin >> n;
  // solve1();
  solve2();
  return 0;
}

Measured memory_bytes: 19200
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int k = sc.nextInt();
      for(int i = 0;i <= n;i++)
        if(i*m==k){
          System.out.println("Yes");
          return;
        }
      for(int i = 0;i <= m;i++)
        if(i*n==k){
        	System.out.println("Yes");
            return;
        }
      for(int i = 1;i <= n;i++){
      	for(int j = 1;j <= m;j++){
          if(i*m+j*n-i*j*2==k){
          	System.out.println("Yes");
            return;
          }
        }
      }
      System.out.println("No");
    }
}


Measured memory_bytes: 21844
n = gets.to_i
inputs = gets.chomp.split(" ").map { |n| n.to_i } # [3 ,1 ,4 ,1 ,5 ,9 ,2]
result = Array.new(inputs.max+5,0)

for i in 0..n-1
	result[inputs[i]] += 1
	result[inputs[i]+1] += 1
	result[inputs[i]+2] += 1
end
puts result.max



Measured memory_bytes: 9476
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		int N = nextInt();
		HashMap<String,Integer> map = new HashMap<>();
		for(int i=0;i<N;i++){
			char[] c = nextString().toCharArray();
			Arrays.sort(c);
			String s = String.valueOf(c);
			map.put(s, map.getOrDefault(s,0)+1);
		}
		long ans = 0;
		for(int val:map.values()){
			if(val!=1){
				ans+=(long)(val)*(val-1)/2L;
			}
		}
		System.out.println(ans);
	}



	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 47060
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(m));
    for (auto& v: A) {
        for (auto& x: v) {
            cin >> x;
        }
    }
    vector<int> v(m);
    for (auto& x: v) {
        cin >> x;
    }
    for (int i = 0; i < n; i++) {
        int res = 0;
        for (int j = 0; j < m; j++) {
            res += A[i][j] * v[j];
        }
        cout << res << endl;
    }
}


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

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

  int n = s.size();
  int ans = 999;

  for (int i = 0; i < n-2; i++) {
    int num = (s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
    ans = min(ans,abs(753-num));
  }
  cout << ans << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[1000006][2];
int main(void) {
    ios_base::sync_with_stdio(false);
    string n;
    while (cin >> n) {
        memset(dp,0,sizeof(dp));
        for(int i =0; i < n.size();i++){
            if(i == 0){
                dp[i][0]=n[i]-'0';
                dp[i][1]=(10-(n[i]-'0'))+1;
            }
            else{
                dp[i][0]=min(dp[i-1][0]+n[i]-'0',dp[i-1][1]+n[i]-'0');
                dp[i][1]=min(dp[i-1][0]+(10-(n[i]-'0'))+1,dp[i-1][1]+(10-(n[i]-'0'))-1);
            }
        }
        cout<<min(dp[n.size()-1][0],dp[n.size()-1][1])<<'\n';
    }
}

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

template <class T>
struct BIT {
  vector<T> lst;
  int treesize;
  // constructor
  BIT(int newn = 0) {
    treesize = newn;
    lst.resize(treesize + 1);
    for(int i = 0; i <= treesize; ++i) lst[i] = 0;
  }
  // a_place += num
  bool add(int place, T num) {
    while(place <= treesize) {
      lst[place] += num;
      place += place & -place;
    }
    return 1;
  }
  // add wide ver.(add num between l and r)
  bool addw(int left, int right, T num) {
    while(left <= right && left >= 1 && right <= treesize)
      add(left++, num);
    return 1;
  }
  // sum between l and r
  T calcsum(int place) {
    T answer = 0;
    while(place > 0) {
      answer += lst[place];
      place -= place & -place;
    }
    return answer;
  }
  // sum between l and r(calcsum wide ver.)
  T calcsumw(int left, int right) {
    return calcsum(right) - calcsum(left - 1);
  }
};

string s;

long long solve();

int main() {
  cin >> s;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  BIT<int> bit(4);
  for(int i = 0; i < s.size(); ++i) {
    int x = (s[i] == 'B') + 1;
    ans += i - bit.calcsum(x);
    bit.add(x, 1);
  }
  return ans;
}

Measured memory_bytes: 640
#include<stdio.h>
#define N 100
main(){
  int j, i, n, flag, A[N], count;
  
  scanf("%d", &n);
  
  for(i = 0; i <= n - 1; i++){
    scanf("%d", &A[i]);
  }
  
  count = 0;
  
  for(i = 0; i < n; i++){
    for(j = n - 1; j >= i + 1; j--){
      if(A[j] < A[j-1]){
	flag = A[j];
	A[j] = A[j-1];
      A[j-1] = flag;
      count++;
      }
    }
  }
  
  for(i =0; i <= j; i++){
    printf("%d",A[i]);
    if(i < j)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int a[505][505];
bool used[505][505];
int H,W;
vector<string> ans;

void output(int a, int b, int c, int d){
  ans.pb(to_string(a + 1) + " " + to_string(b + 1) + " " +  to_string(c + 1) + " " + to_string(d + 1));
}

void Debug(){
  cout << endl;
  
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}

int main(){
  cin>>H>>W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> a[i][j];
    }
  }

  int j=0;
  for(int i = 0; i < H; i++){
    if(i%2==0){
      for(; j < W - 1; j++){
	if(a[i][j] % 2 == 1){
	  output(i, j, i, j + 1);
	  a[i][j]--;
	  a[i][j+1]++;
	}
      }
      if(i != H - 1 && a[i][j] % 2 == 1){
	output(i, j, i + 1, j);
	a[i][j]--;
	a[i + 1][j]++;
      }
    }else{
      for(; j > 0; j--){
	if(a[i][j] % 2 == 1){
	  output(i, j, i, j - 1);
	  a[i][j]--;
	  a[i][j-1]++;
	}
      }
      if(i != H - 1 && a[i][j] % 2 == 1){
	output(i, j, i + 1, j);
	a[i][j]--;
	a[i + 1][j]++;
      }
    }
  }
  
  cout << ans.size() << endl;
  for(auto str: ans)cout << str << endl;

  // Debug();
  
  return 0;
}


Measured memory_bytes: 12532
s = input()
mod = 2019
array = [0]*(len(s)+1)

for i in range(len(s)):
    array[i+1] = (array[i] + pow(10,i,mod)*int(s[len(s)-(i+1)])) % mod
    

    
array.sort()

cnt = 0
w = 1

for i in range(0, len(array)-1):
    if array[i] == array[i+1]:
        w += 1
    else:
        if w >= 2:
            cnt += w*(w-1)/2
            w = 1
            
if w != 1:
    cnt += w*(w-1)/2
    
print(int(cnt))

Measured memory_bytes: 71348
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;
/*int main(){
    int n;std::cin >> n;
    int keta=0;
    while(true){
        keta++;
        if(n/10==0)break;
        n=n/10;
    }
    keta=keta-1;
    if(n>=7)n=3;
    else if(n>=5)n=2;
    else if(n>=3)n=1;
    int k=0;
    for(int i=3;i<=keta;i++){
        k+=comb(i-1,2);
        std::cout << k << std::endl;
    }std::cout << k << std::endl;
    k+=n*(keta);
    
    std::cout << k << std::endl;
    
}


*/

int main(){
  unsigned long long a,b,n;
  int s=0;
  std::cin>>a>>b>>n;
  
  std::cout << a*min((b-1),n)/b<< std::endl;
  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
inline int read()
{
	int x=0,pd=1; char ch=getchar();
	while(ch<'0' || '9'<ch){if(ch=='-')pd=-1; ch=getchar();}
	while('0'<=ch && ch<='9'){x=(x<<1)+(x<<3)+(ch&15); ch=getchar();}
	return x*pd;
}
int stack[20];//递归快输好像比较慢
inline void write(int x)//快输 
{
	if(x<0){putchar('-'); x=-x;}
	if(!x){putchar('0'); return ;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
const int mod=998244353;
inline int ad(int x){return x>=mod?x-mod:x;}//超出不大时用于代替模运算 卡常？！ 
inline int dec(int x){return x<0?x+mod:x;}//去负化 没鬼用 
inline int power(int a,int b)//快速幂 
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
int fac[1110000],inv[1110000];
inline int C(int n,int m){return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;}//组合数 套公式(n!/(m!*(n-m)!)) 乘逆元 
int main()
{
//	freopen("b.in","r",stdin);
//	freopen("b.out","w",stdout);

	fac[0]=1;
	for(int i=1;i<=1000000;i++)fac[i]=1LL*fac[i-1]*i%mod;inv[1000000]=power(fac[1000000],mod-2);//费马小定理
	for(int i=1000000;i>=1;i--)inv[i-1]=1LL*inv[i]*i%mod;//莫非是阶乘的逆元？ 在mod p的意义下，除以一个数相当于乘以这个数的逆元 
	int n=read(),m=read(),sum=0;if(n<m)swap(n,m);//取n>=m 
	
	for(int i=1;i<=m;i++)sum=ad(sum+1LL*C(2*i,i)*C(n+m-2*i,n-i)%mod);//玄学公式
	sum=1LL*sum*power( ad(2*C(n+m,m)),mod-2 )%mod;//用组合数去算出经过对角线的至少一个点的路径数，再除以总路径数，就可以得出答案
	write( ad(sum+n) ); putchar('\n');//n,m中必定有一个最大的是固定到达的收益 
	
	return 0;
}

Measured memory_bytes: 8448
#include <stdio.h>
 
int n,num[4000];
long long int tanka,sale_num,sale_sum[4000],sale_all[4001];
short judge[4001];
 
int main(void)
{
int i,j,k;
     
while(scanf("%d",&n),n){
    for(i=0;i<n;i++){
        scanf("%d %lld %lld",&num[i],&tanka,&sale_num);
        sale_sum[i] = tanka*sale_num;
    }
    k=0;
    for(j=0;j<4001;j++){
    judge[j]=0;
    sale_all[j]=0;
    }
    for(i=0;i<n;i++){
        sale_all[num[i]] += sale_sum[i];
    }
    for(i=0; i < n; i++){
        if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
            printf("%d\n",num[i]);
            judge[num[i]]=1;
            k=1;
        }
    }
    if(k!=1)printf("NA\n");
}
 
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long m;
	scanf("%lld",&m);
	if(m<=10000)
	{
		puts("2");
		if(m&1ll) printf("%lld %lld\n",m/2ll+3ll,m/2ll);
		else printf("%lld %lld\n",m/2ll+1ll,m/2ll+1ll);
	}
	else
	{
		puts("50");
		long long x=m%50,y=(2450+m-x)/50-x;
		for(long long i=1;i<=x;i++)
			printf("%lld ",y+51);
		for(long long i=x+1;i<=50;i++)
			printf("%lld ",y);
	}
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using ll = long long;

int main() {
    // freopen('a.txt', 'r', stdin);
    // fastio;
    int n;
    scanf("%d", &n);

    int arr[n];
    for (int& e : arr)
        scanf("%d", &e);

    bool ok = is_sorted(arr, arr+n);

    if (ok)
        goto ans;

    for (int x = 0; x < n; x ++) {
        for (int y = x+1; y < n; y ++) {
            swap(arr[x], arr[y]);
            if (is_sorted(arr, arr+n)) {
                ok = true;
                goto ans;
            }
            swap(arr[x], arr[y]);
        }
    }

ans:
    if (ok)
        puts("YES");
    else
        puts("NO");

    return 0;
}



Measured memory_bytes: 3744
import itertools


def roll(dice, commands):
    for command in commands:
        if command == 'N':
            dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]
        elif command == 'W':
            dice[0], dice[3], dice[5], dice[2] = dice[2], dice[0], dice[3], dice[5]


def solve():
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    for i in range(4):
        for j in range(4):
            for commands in itertools.permutations('N' * i + 'W' * j):
                a = A[::]
                roll(a, commands)
                if B == a:
                    return True
    return False


if __name__ == '__main__':
    print('Yes' if solve() else 'No')

Measured memory_bytes: 6740
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const li mxN = 2e5+4;
li n;
li a[mxN], ans[mxN];
vector<li> g[mxN];
vector<li> seq;
void dfs(li u, li p)
{
	li in = lower_bound(seq.begin(), seq.end(), a[u])-seq.begin();
	bool nw=false;
	li pre;
	if(in==seq.size()) seq.pb(a[u]), nw=true;
	else pre=seq[in], seq[in]=a[u];
	ans[u] = seq.size();
	for(auto v : g[u])
	{
		if(v!=p) dfs(v, u);
	}
	if(nw) seq.pop_back();
	else seq[in]=pre;
}
int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	cin >> n;
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int i=1, x, y; i<=n-1; i++)
	{
		cin >> x >> y;
		g[x].pb(y); g[y].pb(x);
	}
	dfs(1, -1);
	for(int i=1; i<=n; i++)
	{
		cout << ans[i] << "\n";
	}
	return 0;
}


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

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

    int sum = 0;
    int ans = 0;

    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }
    int i = 0;
    while (1) {
        sum = ((a - 1) * i + a);
        if (sum >= b) {
            break;
        }
        i++;
    }

    cout << i+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long a[3*n];
    for(int i=0;i<3*n;i++) cin>>a[i];
    priority_queue<long long, vector<long long>, greater<long long> > que1;
    priority_queue<long long> que2;
    for(int i=0;i<n;i++) que1.push(a[i]);
    for(int i=2*n;i<3*n;i++) que2.push(a[i]);
    long long b1[n+1],b2[n+1],b3[n+1];
    b1[0]=0,b2[n]=0;
    for(int i=0;i<n;i++) b1[0]+=a[i];
    for(int i=2*n;i<3*n;i++) b2[n]+=a[i];
    for(int i=0;i<n;i++){
        que1.push(a[n+i]);
        b1[i+1]=b1[i]+a[n+i]-que1.top();
        que1.pop();
    }
    for(int i=n-1;i>=0;i--){
        que2.push(a[n+i]);
        b2[i]=b2[i+1]+a[n+i]-que2.top();
        que2.pop();
    }
    
    for(int i=0;i<=n;i++) b3[i]=b1[i]-b2[i];
    long long c=b3[0];
    for(int i=1;i<=n;i++) c=max(c,b3[i]);
    cout<<c<<endl;
}


Measured memory_bytes: 6772
using System;


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] spText = input.Split(' ');
            Console.WriteLine(spText[0].Substring(0, 1)+ spText[1].Substring(0, 1)+ spText[2].Substring(0, 1));
            //Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main(){
   ll N,h,n;
   cin >> N;
   for(h=1; h < 3501; h++) {
     for(n=1; n<3501; n++) {
       if(4*h*n - N*n - N*h > 0 && N*h*n%(4*h*n - N*n - N*h) == 0) {
            cout << h << " " << n << " " << N*h*n/(4*h*n-N*n-N*h) << endl;
            return 0;
        }
      }
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
vector<string> v;
string s;
bool check(string in){
	rep(i,25){
		rep(j,in.size()){
			if(in[j]=='b'+i){
				in[j]='b'+i-1;
				break;
			}
		}
	}
	if(in==s.substr(0,in.size())) return true;
	return false;
}
void foo(string in){
	if(s.size()==in.size()){
		if(check(in)) v.push_back(in);
		return;
	}
	string tmp=s.substr(in.size(),1);
	if(check(in+tmp)) foo(in+tmp);
	if(tmp[0]=='z') return;
	tmp[0]++;
	if(check(in+tmp)) foo(in+tmp);
	return;
}
int main(){
	while(cin>>s,s[0]!='#'){
		v.clear();
		foo("");
		sort(v.begin(),v.end());
		cout<<v.size()<<endl;
		if(v.size()<=10){
			rep(i,v.size()){
				cout<<v[i]<<endl;
			}
		}
		else{
			rep(i,5){
				cout<<v[i]<<endl;
			}
			rep(i,5){
				cout<<v[v.size()+i-5]<<endl;
			}
		}
	}
}

Measured memory_bytes: 2388
#include<stdio.h>
int main()
{
	int a,b,c,temp=0;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b)
	{
		temp=a;
		a=b;
		b=temp;
		if(b>c)
		{
			temp=b;
			b=c;
			c=temp;
		}
		if(a>b)
		{
			temp=a;
			a=b;
			b=temp;
		}
	}
	else if(a<b)
	{
		a=a;
		b=b;
		if(b>c)
		{
			temp=b;
			b=c;
			c=temp;
		}
		if(a>b)
		{
			temp=a;
			a=b;
			b=temp;
		}
	}
	printf("%d %d %d\n",a,b,c);
	
	
	return 0;
}


Measured memory_bytes: 1992
class SegTree:
    def __init__(self, a, func):
        self.n = 2**(len(a) - 1).bit_length()
        self.f = func
        self.d = [0] * (2 * self.n - 1)
        self.d[self.n - 1:self.n - 1 + len(a)] = a
        for i in reversed(range(self.n - 1)):
            self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])

    def update(self, i, v):
        i += self.n - 1
        self.d[i] = v
        while i:
            i = (i - 1) // 2
            self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])
    # l <= i < r
    def query(self, l, r):
        assert l <= r
        l += self.n
        r += self.n
        s = self.d[l - 1]
        while l < r:
            if l & 1:
                s = self.f(s, self.d[l - 1])
                l += 1
            if r & 1:
                r -= 1
                s = self.f(s, self.d[r - 1])
            l //= 2
            r //= 2
        return s
def main():
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    if N == 2:
        return 1
    def func(a, b):
        if a >= b:
            return a
        return b
    s = SegTree(A, func)
    d = {}
    for i in range(N):
        t = s.query(i+1, N) - A[i]
        d[t] = d.get(t, 0) + 1
    m = 0
    for i in d:
        if i > m:
            m = i
    return d[m]
print(main())


Measured memory_bytes: 22728
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

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

const int mod=1e9+7;

int main(){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    cout << H*W-h*W-H*w+h*w << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char s[200001];
  scanf("%s",s);
  int len=strlen(s);
  int count=0,i;
  for(i=0;i<len;i++)
    count+=s[i]-'0';
  printf("%s\n",count%9==0?"Yes":"No");
  return 0;
}


Measured memory_bytes: 1856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

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

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    ll X,K,D;
    cin >> X >> K >> D;
    if(X < 0) {
        if(abs(X) / D >= K) {
            cout << abs(X + D * K) << endl;
        }
        else {
            ll cnt = abs(X) / D;
            K -= cnt;
            if(K % 2 == 0) {
                cout << abs(abs(X) % D) << endl;
            }
            else {
                cout << abs(abs(X) % D - D) << endl; 
            }
        }
    }
    else {
        if(X / D >= K) {
            cout << abs(X - D * K) << endl;
        }
        else {
            ll cnt = X / D;
            K -= cnt;
            if(K % 2 == 0) {
                cout << X % D << endl;
            }
            else {
                cout << abs(X % D - D) << endl;
            }
        }
    }
}

Measured memory_bytes: 3628
///*****************************************************///
///*.......................Faiyaj Bin Amin............................*///
///*...................................................................*///
///*.........................KUET CSE 2K17......................*///
///*...................................................*///
///*****************************************************///


#include<bits/stdc++.h>

#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define sf(n) scanf("%d", &n);
#define sff(n, m) scanf("%d %d", &n, &m);
#define pf(n) printf("%d", n);
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)  /// type rep(t, 1, n+1) when t is to be iterated from 1 to n
#define rrep(q, i, n) for(int q=i; q>n; q--)
#define mems(a,x) memset(a,x,sizeof(a))
#define io ios_base::sync_with_stdio;cin.tie(0);cout.tie(0)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>
#define pll pair<ll,ll>

#define watch(x) cout << (#x) << " is " << (x) << endl

#define gcd(a, b)  __gcd(a, b)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define PI 2*acos(0.0)

#define mx 100005
#define MAX 1000000005
#define inf 1e9
#define INF 1e18
#define MOD 1000000007
//#define MOD 4294967296another
#define MIN 0


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}
/**-----------------------------------------------------------------------------------------------**/

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);

    int a[n];

    rep(i, 0, n)
    {
        scanf("%d", &a[i]);
    }

    sort(a, a+n);
    int ans = a[n/2]-a[n/2-1];

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    ll n,k,x,a,m;
    cin>>n>>k>>x;
    m=x;
    rep(i,n-1){
        cin>>a;
        m=max(a,m);
        x=gcd(a,x);
    }
    if(k%x || k>m)cout<<"IM";
    cout<<"POSSIBLE\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long double
#define fin {cout<<fixed<<setprecision(18)<<ans<<endl;return 0;}
//template

//main
signed main(){
  const int pi=3.1415926535897932384626433832795028841971;
  int sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy;
  int N;cin>>N;
  std::vector<int> x(N),y(N);
  for(int i=0;i<N;i++)cin>>x[i]>>y[i];
  if(sy<gy)swap(sx,gx),swap(sy,gy);//sの方がyが大きい
  if(sx<gx){//sの方がxが大きい
    for(int i=0;i<N;i++)x[i]*=-1;
    sx*=-1;gx*=-1;
  }
  if(sx-gx<sy-gy){//移動距離はy方向よりもx方向の方が大きい
    swap(sx,sy);
    swap(gx,gy);
    for(int i=0;i<N;i++)swap(x[i],y[i]);
  }
  typedef pair<int,int> P;
  std::vector<P> c(N);
  for(int i=0;i<N;i++)c[i]=P(y[i],x[i]);
  sort(c.rbegin(),c.rend());
  std::vector<int> v(2e5+5,-LINF);//i回くるんをする時にx座標を最大でいくつに保てるか
  v[0]=sx;
  for(int i=0;i<N;i++){
    int px=c[i].second,py=c[i].first;
    if(px>sx||px<gx||py>sy||py<gy)continue;
    int l=0,r=2e5+2;
    while(r-l>1){
      int m=(r+l)/2;
      if(v[m]>=px)l=m;
      else r=m;
    }
    v[r]=px;
  }
  int ans=0;
  for(int i=0;i<2e5+2;i++)if(v[i]>-LINF)ans=i;
  ans=100*((sx-gx)+(sy-gy))-10*(2-pi/2)*ans;
  int a=0;
  for(;a<N;a++)if(c[a].first==sy)break;
  if(c[a].first!=sy)fin;
  if(c[a].second>sx||c[a].second<gx)fin;
  int i;
  for(i=1;a+i<N&&c[a+i].first>=gy;i++)if(c[a+i].first!=sy-i||c[a+i].second>c[a+i-1].second||c[a+i].second<gx)fin;
  if(c[a+i-1].first!=gy)fin;
  cout<<fixed<<setprecision(18)<<ans+10*pi/2<<endl;
}


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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

ll numj[1000010];
ll numi[1000010];
ll numjo[1000010];
ll numoi[1000010];

int main(){
    int n;
    cin >> n;
        string s;
        cin >> s;
        REP(i,n) {
            if (s[i] == 'J') {
                numj[i+1]++;
            }
            if (s[i] == 'I') {
                numi[i+1]++;
            }
            numj[i+1] += numj[i];
            numi[i+1] += numi[i];
        }
        numj[n+1] = numj[n];
        numi[n+1] = numi[n];
        ll ans = 0;
        numoi[n+1] = 0;
        REP(i,n) {
            if (s[i] == 'O') {
                numjo[i+1] = numj[i];
            }
            numjo[i+1] += numjo[i];
        }
        for (int i = n-1; i >= 0; i--) {
            if (s[i] == 'O') {
                numoi[i+1] = numi[n+1] - numi[i+1];
            }
            numoi[i+1] += numoi[i+2];
        }
        ll mx = 0;
        REP(i,n) {
            if (s[i] == 'O') {
                ans += numj[i] * (numi[n+1] - numi[i+1]);
            }
        }
        REP(i,n+1) {
            mx = max(mx,numj[i] * (numi[n+1] - numi[i]));
        }
        mx = max(mx,numjo[n]);
        mx = max(mx,numoi[1]);
        // REP(i,n+2) {
        //     cout << numj[i] << " ";
        // }
        // cout << endl;
        // REP(i,n+2) {
        //     cout << numi[i] << " ";
        // }
        // cout << endl;
        // REP(i,n+2) {
        //     cout << numjo[i] << " ";
        // }
        // cout << endl;
        // REP(i,n+2) {
        //     cout << numoi[i] << " ";
        // }
        // cout << endl;
        cout << ans + mx << endl;
    return 0;
}



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

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	char s[100][101],t[102][102];

	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}

	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			t[i][j] = '#';
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			t[i + 1][j + 1] = s[i][j];
		}
	}
	for (int i = 0; i < H + 2; i++) {
		for (int j = 0; j < W + 2; j++) {
			cout << t[i][j];	
		}
		cout << endl;
	}



	return 0;
}

Measured memory_bytes: 256
import statistics
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
    
A = MULT_INT_LIST()
mean = statistics.mean(A)

if is_integer_num(mean):
  print(int(mean))
else:
  print('IMPOSSIBLE')




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

#define forn(i,n) for(ll i = 0;i<n;i++)
#define forne(i,j,n) for(ll i = j;i<n;i++)
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ll INF = 1000000001;
const ll N = 100001;
const lld PI = 3.141593;
#define F first
#define pb(a) push_back(a)
#define S second
#define pii pair<int,int>
typedef pair<ll,ll> pll;

lld powm(ll base,ll exp) {
	ll ans=1;
	while(exp){
		if(exp&1) ans=(ans*base)%mod;
		exp>>=1,base=(base*base)%mod;
	}
	return ans;
}

// ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
// bool valid(ll i, ll j) {
// 	return i >= 1 && i <= n && j >= 1 && j <= m; 
// }
// int maxdepth = INT_MAX;
// vector<int> edgeVector[100000];
// ll minans = 1;
// printf("1 %d D\n",abs(r));
// priority_queue<ll,vector<ll>,greater<ll>> pq;
// ll a[N],b[N];
// vector<vector<ll>> adj(N);
// vector<set<ll>> adjs(N);
// ll adj[1001][1001];
// vector<vector<ll>> ans(1001);
// bool visited[N];
// ll cnt[1001];
// ll h,c,t;
// vector<pair<int, pair<int, int> > > g[300043];


int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll a;
cin>>a;
ll fa = a+a*a+a*a*a;
cout<<fa<<endl;



}

Measured memory_bytes: 3628
n, x = map(int, input().split())

dp = [1]*(n+1)
res = 0

for i in range(1,n+1):
    dp[i] = dp[i-1]*2+3

for j in range(n,1,-1):
    if dp[j] ==x:
        res += (dp[j]+1) //2
        x =0        
    elif dp[j-1]+2 <= x :
        res += 1 + (dp[j-1]+1)//2
        x -= dp[j-1]+2
    elif dp[j-1]+1 ==x:
        res += (dp[j-1]+1)//2
        x = 0
    else:
        x -=1
    
    if x ==0:
        break
        
if x ==5:
    res += 3
elif x ==0:
    pass
else:
    res +=x-1

print(res)


Measured memory_bytes: 9056