akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    int M; cin >> M;
    int sum = 0;
    vi data(N);
    F0R(i, N) {
        cin >> data[i]; sum += data[i];
    }
    int cnt = (sum + 4*M - 1) / (4*M);
    int ans = 0;
    F0R(i, N) if (data[i] >= cnt) ans++;

    cout << (ans >= M ? "Yes" : "No") << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int S, W;
    cin >> S >> W;
    if (W>=S){
        cout << "unsafe" << endl;
    } else{
        cout << "safe" << endl;
    }

    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,zx,xc,jm,f[200009];
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(i=1; i<=a; i++){
        cin>>f[i];
        jm^=f[i];
    }
    for(i=1; i<=a; i++){
        cout<<(jm^f[i])<<" ";
    }
    return 0;
}

Measured memory_bytes: 5196
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        H: usize, W: usize, K: usize,
        c: [Chars; H],
    }
    let mut ans = 0;
    for i_bit in 0..1 << H {
        for j_bit in 0..1 << W {
            let mut count = 0;
            for i in 0..H {
                for j in 0..W {
                    if (i_bit & (1 << i) != 0) && (j_bit & (1 << j) != 0) {
                        if c[i][j] == '#' {
                            count += 1;
                        }
                    }
                }
            }
            if count == K {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2176
operator = {'+': lambda a,b:b+a,
            '-': lambda a,b:b-a,
            '*': lambda a,b:b*a,
            '/': lambda a,b:b/a}

rpn = input().split()
def calcurate(rpn):
    stack = []
    for d in rpn:
        if d in operator:
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(operator[d](a, b))
        else :
            stack.append(d)
    return stack.pop()

print(calcurate(rpn))


Measured memory_bytes: 5600
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
        int int1 = Integer.parseInt(scan.next());
        int int2 = Integer.parseInt(scan.next());
        int int3 = Integer.parseInt(scan.next());
//        String temp_str1 = "";
//        String temp_str2 = "";
        int temp_int1 = 0;
//        String str1 = scan.next();
        int ans_int = 0;
        String ans = "";
//        double ans_dob = 0;
        if(Math.abs(int1-int2) > Math.abs(int1-int3)){
            ans = "B";
        }else{
            ans = "A";
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
        scan.close();
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#define MP make_pair
#define PB push_back
#define S size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define SE second
#define ld long double



using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ld area(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3){
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
}
 
ld dp[301][301][301];
bool vis[301][301][301];
ld solve(ll a, ll b, ll c, ld n){
    if(vis[a][b][c]){
        return dp[a][b][c];
    }
    vis[a][b][c]=1;
    if(a==0 && b==0 && c==0){
        return 0;
    }
    ld total= (ld)(a+b+c);
    dp[a][b][c]=(n-total)/total;
    if(a!=0){
        dp[a][b][c]+=(a/total)*(solve(a-1,b,c,n)+1);
    }
    if(b!=0){
        dp[a][b][c]+=(b/total)*(solve(a+1,b-1,c,n)+1);
    }
    if(c!=0){
        dp[a][b][c]+=(c/total)*(solve(a,b+1,c-1,n)+1);
    }
    return dp[a][b][c];

}

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
   REP(i,0,301){
       REP(j,0,301){
           REP(k,0,301){
               dp[i][j][k]=0;
               vis[i][j][k]=0;
           }
       }
   }
   ld n;
   cin>>n;
   ll a=0, b=0, c=0;
   REP(i,0,n){
       ld x;
       cin>>x;
       x==1?a++:x==2?b++:c++;
   }
    cout<<fixed<<setprecision(20)<<solve(a,b,c,n);
}


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

int main() {
	int n;
	scanf("%d", &n);
	vector<int> l(n);
	int tei = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d", &l[i]);
		cnt += l[i];
		tei = max(l[i], tei);
	}
	if(tei < cnt - tei) {
		printf("%s\n", "Yes");
	}else {
		printf("%s\n", "No");
	}
}

Measured memory_bytes: 256
def main():
    n,k,*a=map(int,open(0).read().split())
    a,f=sorted(a[:n]),sorted(a[n:],reverse=1)
    ok=10**12
    ng=-1
    while ok-ng>1:
        mid=(ok+ng)//2
        l=k
        for b,g in zip(a,f):
            t=b-mid//g
            if t>0:l-=t
        if l<0:ng=mid
        else:ok=mid
    print(ok)
main()

Measured memory_bytes: 127928
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//よくわかんないけど通った？

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


	int N, K;
	cin >> N >> K;
	int H[302] = {};
	rep1(i, N) cin >> H[i];
	ll hutuu = 0;
	rep(i, N + 1) {
		if (H[i + 1] > H[i]) hutuu += H[i + 1] - H[i];
	}

	ll dp[302][301] = {};
	rep(i, N + 1) {
		auto dpi = dp[i];
		ll tmp1 = max(0, H[i + 1] - H[i]);
		ll tmp2 = max(0, H[i] - H[i + 1]);
		ll tmp3 = min(tmp1, tmp2);
		int mae = H[i + 1];
		ll maetmp = tmp3;
		for (int j = i + 2; j <= N + 1; j++) {
			if (mae < H[j]) tmp1 += H[j] - mae;
			if (mae > H[j]) tmp2 += mae - H[j];
			tmp3 = min(tmp1, tmp2);
			if (maetmp < tmp3) {
				int k = j - i - 1;
				auto dpj = dp[j] + k;
				rep(p, K - k + 1) chmax(dpj[p], dpi[p] + tmp3);
			}
			mae = H[j];
			maetmp = tmp3;
		}
		auto dpi2 = dp[i + 1];
		rep(p, K + 1) chmax(dpi2[p], dpi[p]);
	}
	co(hutuu - dp[N + 1][K]);


	Would you please return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1299709

int isPrime(int a){
  int i;
  if (a==2) return 1;
  if (a%2==0) return 0;
  for (i=3;i<=sqrt(a);i+=2){
    if (a%i==0) return 0;
  }
  return 1;
}

int main(){
  int n,a,b;
  cin >> n;
  while (n!=0){
    a=0;
    b=0;
    if (isPrime(n)) cout << 0 << endl;
    else{
      for (int i=1;;i++){
	if (a==0) if (isPrime(n-i))a=n-i;
	if (b==0) if (isPrime(n+i))b=n+i;
	if (a!=0&&b!=0) break;
      }
      cout << b-a << endl;
    }
    cin >> n;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <cctype>
#include <ctype.h>
#define ll long long
char toupper(char c);
char toupper(char c)
{
    return (c - 0x20);
}

using namespace std;
int main()
{
    int n;
    cin >> n;
    cout << n * 800 - n / 15 * 200 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
#define crep(i, n) for(int i=1; i<=n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

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



int main() {

  int n, maxv = 0, nextv;
  cin >> n;

  int b[101];
  rep(i, n-1) cin >> b[i];

  nextv = b[0];

  rep(i, n-1) {
    maxv += nextv;
    if(b[i]<=b[i+1]) {
      nextv = b[i];
    }else {
      nextv = b[i+1];
    }
  }

  cout << maxv + b[n-2] << endl;

  return 0;
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())

list1=[a,b,c,d]
list2=[e,f]

list1.sort()
list2.sort()

print(list1[1]+list1[2]+list1[3]+list2[1])


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

#define SEG_LEN (1 << 19)

ll seg[SEG_LEN*2];

ll get(ll ind){
    ll res = 0;
    ind += SEG_LEN;
    res += seg[ind];
    while(1){
        ind /= 2;
        if(ind <= 0) break;
        res += seg[ind];
    }
    return res;
}

void add(ll l, ll r,ll v){
    l += SEG_LEN; r += SEG_LEN;
    while(l < r){
        if(l % 2 == 1){
            seg[l] += v;
            l++;
        }
        l /= 2;
        
        if(r % 2 == 1){
            seg[r-1] += v;
            r--;
        }
        r /= 2;
    }
}

int main(){
    ll n,d,a;
    cin >> n >> d >> a;

    P p[n];
    rep(i,0,n){
        cin >> p[i].fs >> p[i].sc;
    }
    sort(p,p+n);

    rep(i,0,n) add(i+1,i+2,p[i].sc);

    ll ans = 0;
    rep(i,0,n){
        ll ok = i,ng = n;
        while(abs(ok-ng) > 1){
            ll mid = (ok+ng)/2;
            if(p[mid].fs <= p[i].fs + 2*d){
                ok = mid;
            }
            else{
                ng = mid;
            }
        }

        if(get(i+1) > 0){
            ll temp = a*(ll)ceil((double)get(i+1)/a);
            ans += temp/a;
            add(i+1,ok+2,-temp);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 9884
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# atcoder.main
# Date: 2020/06/18
# Filename: main 
# Author: acto_mini

def main():
    X, Y = map(int, input().split())

    for i in range(X+1):
        turu_2 = i
        kame_4 = X - i
        if (turu_2*2 + kame_4*4) == Y:
            print("Yes")
            break
    else:
        print("No")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61860
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int x=0, y=0, z=0;
    for(int i=0; i<N; i++){
        int P;
        cin >> P;
        if(P <= A) x++;
        else if(P <= B) y++;
        else z++;
    }
    cout << min(x, min(y, z)) << endl;


    return 0;
}

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

int main(){
  string S;
  int N,i = 0,count = 0;
  
  cin >> N;
  cin >> S;
  
  for(i;i < N - 2;i++){
    if(S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C'){
		count++;
    }
  }
  
  cout << count << endl;
}
  
  

Measured memory_bytes: 256
use std::cmp::max;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut xyhv = vec![(0i32, 0i32, 0i32); n];
    for i in 0..n {
        xyhv[i].0 = read(&mut stdin_lock, &mut buf, b' ');
        xyhv[i].1 = read(&mut stdin_lock, &mut buf, b' ');
        xyhv[i].2 = read(&mut stdin_lock, &mut buf, b'\n');
    }

    let mut ans = (0i32, 0i32, 0i32);
    for x in 0..100 + 1 {
        for y in 0..100 + 1 {
            let mut any = false;
            let mut h0 = 0;
            for i in 0..n {
                if xyhv[i].2 > 0 {
                    h0 = max((xyhv[i].0 - x).abs() + (xyhv[i].1 - y).abs() + xyhv[i].2, 0);
                    any = true;
                    break;
                }
            }
            if !any {
                continue;
            }

            let mut all = true;
            for i in 1..n {
                if xyhv[i].2 != max(h0 - ((xyhv[i].0 - x).abs() + (xyhv[i].1 - y).abs()), 0) {
                    all = false;
                    break;
                }
            }
            if all {
                ans = (x, y, h0);
            }
        }
    }
    println!("{} {} {}", ans.0, ans.1, ans.2);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // get value from StandardIn
    String s = sc.nextLine();
    String t = sc.nextLine();
    if(s.equals(t.substring(0,s.length()))){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    // System.out.println(n);
  }
}


Measured memory_bytes: 35748
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    insert(node(x));
  }
  return 0;
}

Measured memory_bytes: 26556
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 2e5 + 1;
ll n;
double dp[3000][3000];
double p[3000];

 
int main()
{
FIO
 
    cin >> n;
    FOR(n) cin >> p[i];
    dp[0][0] = 1;
    FOR(n)
    {
        dp[i][0] = dp[i-1][0] * (1 - p[i]);
        Rep(j,1,i)
        {
            dp[i][j] = dp[i-1][j] * (1 - p[i]) + dp[i-1][j-1] * p[i];
        }
    }
    double ans = 0;
    for(int i = n/2 + 1; i <= n; i++)
    {
        ans += dp[n][i];
    }
    cout << fixed << setprecision(11) << ans << endl;
}

Measured memory_bytes: 49856
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

#define MOD (1'000'000'000+7)

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H+1, vector<char>(W+1));
    vector<vector<int>> dp(H+1, vector<int>(W+1));
    REP(i, H) {
        REP(j, W) {
            cin >> a[i+1][j+1];
        }
    }
    
    
//    auto rec = [&](auto f, int i, int j) mutable -> int {
//        if (i == 0 || j == 0) return 0;
//        if (i == 1 && j == 1) return 1;
//        if (a[i][j] == '#') return 0;
//        if (dp[i][j] > 0) return dp[i][j];
//        ll m = ll(f(f, i-1, j)) + f(f, i, j-1);
//        dp[i][j] = m % MOD;
//        return dp[i][j];
//    };
    dp[1][1] = 1;
    REP(i, H) {
        REP(j, W) {
            if (i == 0 && j == 0) continue;
            ll u = dp[i][j+1];
            if (a[i][j+1] == '#') u = 0;
            
            ll l = dp[i+1][j];
            if (a[i+1][j] == '#') l = 0;
            
            dp[i+1][j+1] = (u+l)%MOD;
        }
    }

    cout << dp[H][W] << endl;
}


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

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

int main(){
	ll N, K;
	cin >> N >> K;
	ll A = 0;
	ll B = 0;
	for(int i=1;i<=N;i++){
		if(i%K==0) A++;
		if(i%K==(K/2)) B++;
	}
	if(K%2==0){
		cout << A*A*A + B*B*B  << endl;
	}else{
		cout << A*A*A << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, 0, n)cin >> a[i];
	int cnt = 0, ans = 0;
	rep(i, 0, n-1) {
		if (a[i] >= a[i+1]) cnt++;
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
string str;
int num = 0;
void DFS(int flag3, int flag5, int flag7, string s)
{
	if (s.size() == str.size())
	{
		if (s > str)
			return;
	}
	else if (s.size() > str.size())
		return;
	if (flag3 == 1 && flag5 == 1 && flag7 == 1)
		num++;
	DFS(1, flag5, flag7, s + '3');
	DFS(flag3, 1, flag7, s + '5');
	DFS(flag3, flag5, 1, s + '7');
}
int main()
{
	cin >> str;
	string s = "";
	DFS(0, 0, 0, s);
	cout << num << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;


void solve(){

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

    int x,t;
    cin >> x >> t;
    int ans=x-t;
    cout << max(0,ans) << endl;
    

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) a[i] = 30000 * i + 1, b[i] = 30000 * (n - i);
    for (int i = 0; i < n; i++) {
        int p;
        scanf("%d", &p);
        a[p - 1] += i;
    }
    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
    for (int i = 0; i < n; i++) cout << b[i] << " ";
    cout << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 3005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
ll dp[4][MAX][MAX];
int item[MAX][MAX];
/* function */
/* main */
int main(){
    int R, C, K;
    cin >> R >> C >> K;
    for (int i = 0; i < K; i++) {
        int r, c, v;
        cin >> r >> c >> v;
        r--, c--;
        item[r][c] = v;
    }

    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            // take item
            for (int k = 2; k >= 0; k--) {
                dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + item[i][j]);
            }
            for (int k = 0; k <= 3; k++) {
                // 列の移動
                dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j]);
                // 行の移動
                dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j]);
            }
        }
    }

    ll ans = 0;
    for (int k = 0; k <= 3; k++) {
        ans = max(ans, dp[k][R-1][C-1]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 320532
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  int flag;
  for (int i = 0; i < 26; i++) {
    flag = 1;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == 97 + i) {
        flag = 0;
      }
    }
    if (flag) {
      cout << (char)(97 + i) << endl;
      return 0;
    }
  }

  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
//L:Deque

using namespace::std;

const int SIZE = 3e3 + 1;
int A[SIZE];
long long DP[SIZE][SIZE][2],TA[SIZE];

long long suma(int i,int f){
	return TA[f] - TA[i - 1];
}

long long dp(int i,int j,int p){
	if(!DP[i][j][p]){
		DP[i][j][p] = suma(i,j) - min(dp(i + 1,j,!p),dp(i,j - 1,!p));
	}
	return DP[i][j][p];	
}

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

	int N;
	cin >> N;

	for(int i = 1;i <= N;i++){
		cin >> A[i];
		TA[i] = TA[i - 1] + A[i];
		DP[i][i][0] = DP[i][i][1] = A[i];
	}

	long long j1 = dp(1,N,0);
    long long j2 = suma(1,N) - j1;

	cout << j1 - j2 << '\n';
	
	return 0;
}


Measured memory_bytes: 139776
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}   

signed main()
{
    showoff;
    string s;
    cin >> s;
    bool fo = 1;
    int n = sz(s);
    FOR(i,0,(n-1)/2){
        if(s[i] != s[n-1-i])fo = 0;
    }
    n = (n-1)/2;
    FOR(i,0,n/2){
        if(s[i] != s[n-1-i])fo = 0;
    }
    if(fo)cout << "Yes";
    else cout << "No";
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...
 

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

int main(){
	long long n,a,b; scanf("%lld%lld%lld",&n,&a,&b);
	if(n>1&&a<=b||n==1&&a==b)
		printf("%lld\n",(n-2)*(b-a)+1);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
//typedef complex<double>P;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS*(abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑


int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int aa = a * e, bb;
	if (e <= c) {
		bb = b;
	}
	else {
		bb = b + (e - c)*d;
	}
	cout << min(aa, bb) << endl;
}


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

int main()
{
    const long long MOD = 1000000007;
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    long long s;
    for(long long i = 1; i < n-k+3; i++){
        s = (n*(k+i-1)-(k+i-1)*(k+i-2)+1) % MOD;
        // cout << s << endl;
        ans += s;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
std::string s;
int main () {
  std::cin >> s;
  std::sort(s.begin(), s.end());
  int count = 0;
  for (int i = 0; i < s.size()-1; ++i) {
    if (s[i] == s[i+1])
	  count += 1;
    }
  if(count == 0){
	std::cout << "yes" <<std::endl;
  }
  else{
	std::cout << "no" <<std::endl;
  } 
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <climits>


using namespace std;

int main()
{
	int x,y;
	cin >> x >> y;
	if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12){
		if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12){
			cout << "Yes" << endl;
			}else{cout << "No" << endl;}
	}else if(x==2){
		if(y==2){cout << "Yes" << endl;}
		else{cout << "No" << endl;}
	}else{
		if(y==4 || y==6 || y==9 || y==11){cout << "Yes" << endl;}
		else{cout << "No" << endl;}
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    H = [i for i in map(int, input().split())]

    ans = 0
    highest = H[0]
    for h in H:
        if highest <= h:
            ans += 1
            highest = h

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{int a,b,i,j,o;
scanf("%d%d",&a,&b);
int c[a];
for(i=0;i<a;i++){
scanf("%d",&c[i]);
}
for(i=0;i<a;i++){
    for(j=i+1;j<a;j++){
        if(c[i]>c[j]){
            o=c[i];
            c[i]=c[j];
            c[j]=o;
        }}}
j=0;
for(i=0;i<b;i++){
    j=c[i]+j;
}
printf("%d",j);

return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>  
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <cmath>
#include <cstdio>
#include<unordered_set>
#include <cstring>
#include <iomanip>
#include <list>
typedef long long ll;
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define MAX 1000000 
using namespace std;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a,b,c;
  	cin >> a >> b >> c;
  	if ((a == b && c != a) || (b == c && a != b) || (c == a && b != c)) {
      cout << "Yes";
    }
  	else cout << "No";
  	
	return 0;

}    
                

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll A[200010], dp[200010][2];

int main(void){
    int N;
    cin >> N;
    for(int i=0; i<N; ++i) cin >> A[i];
    dp[0][0]=A[0];
    dp[1][0]=A[1];
    if(N%2==0){
        for(int i=1; i*2<N; ++i){
            dp[i*2][0]=dp[i*2-2][0]+A[i*2];
            dp[i*2+1][0]=max(dp[i*2-2][0], dp[i*2-1][0])+A[i*2+1];
        }
        cout << max(dp[N-2][0], dp[N-1][0]) << endl;
    }
    else{
        dp[0][1]=A[0];
        dp[2][0]=A[2];
        dp[2][1]=dp[0][0]+A[2];
        for(int i=2; i*2<N; ++i){
            dp[i*2-1][0]=max(dp[i*2-4][1], dp[i*2-3][0])+A[i*2-1];
            dp[i*2][0]=max({dp[i*2-4][1], dp[i*2-3][0], dp[i*2-2][0]})+A[i*2];
            dp[i*2][1]=dp[i*2-2][1]+A[i*2];
        }
        cout << max({dp[N-3][1], dp[N-2][0], dp[N-1][0]}) << endl;
    }
    return 0;
}


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

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

  vector<double> a(N);
  vector<double> b(N);

  for (int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  for (int i = 0; i < N; i++){
    b.at(i) = 1 / a.at(i);
  }

  double ans = 0;

  for (int i = 0; i < N; i++){
    ans += b.at(i);
  }

    cout << 1 / ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }



struct UnionFind {
    vector<double> data;
    int sz;
    UnionFind(int _sz) : data(_sz, -1) { sz = _sz; }
    bool connect(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        return true;
    }
    bool issame(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

bool comp(pair<pii, int> a, pair<pii, int> b) {
    return a.S < b.S;
}
int main() {
    int v, e;
    cin >> v >> e;
    vector<pair<pii, int> > g;
    
    rep(i, e) {
        int s, t, w;
        cin >> s >> t >> w;
        g.eb(make_pair(pii(s, t), w));
    }
    sort(all(g), comp);
    int ans = 0;
    UnionFind uni(v);
    rep(i, e) {
        // cout << g[i].F.F << " " << g[i].F.S << endl;
        if (uni.connect(g[i].F.F, g[i].F.S) == 0) continue;
        ans += g[i].S;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4496
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'


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

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

	map<int,int> m;
	m[a]++;
	m[b]++;
	m[c]++;

	if((m[a]==2 && m[b]==2) || (m[c]==2 && m[b]==2)  || (m[c]==2 && m[a]==2) ) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;



}

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

int main() {
    string s,t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();

    int ans = 0;
    if(n > m) ans = 1;
    else if(n < m) ans = -1;
    else{
        rep(i,n){
            if(s[i] > t[i]) ans = 1;
            else if(s[i] < t[i]) ans = -1;
            break;
        }
    }

    if(ans == 1) cout << "GREATER" << endl;
    else if(ans == -1) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
}

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

//macro
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(int)(b) - 1;i>=(int)(a);i--)
#define RREP(i,n) RFOR(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define INF 114514810
#define INFL 1145148100000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define equals(a,b)(fabs((a)-(b))<EPS)

//alias
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vs = vector<string>;
using vvs = vector<vs>;
using P = pair<ll, ll>;
template<class T> using heap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H);    REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template<class T> inline void print(const T &x) { cout << x; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;


int main(void) {
	ull N, A, B;
	cin >> N >> A >> B;
	ull sum = 0;
	ull ans = 0;
	for (ull i = 1; i <= N; ++i) {
		ull tmp = i;
		for (ull j = 0; j < 6; ++j) {
			sum += tmp % 10;
			tmp /= 10;
		}
		if (A <= sum && sum <= B)ans += i;
		sum = 0;
	}

	print(ans);
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,m,cnt = 0;
  cin >> n >> m;
  for (int i = 1; 0 < n-i; i++){
    cnt += n-i;
  }
  for (int i = 1; 0 < m-i; i++){
    cnt += m-i;
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
#include        <map>
#include      <cmath>
#include      <queue>
#include     <string>
#include     <cstdio>
#include     <vector>
#include    <cstring>
#include   <iostream>
#include  <algorithm>
using namespace std;
#define ll long long
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1000000+5;
const ll mod = 1e9+7;

int main(){
    int n , m;
    string s;
    map<string,int>M;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>s;
        M[s]++;
    }
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>s;
        M[s]--;
    }
    int ans = 0;
    for(auto m:M){
        ans = max(ans,m.second);

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


Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

ll N;
ll d[MAX];

int main() {
    cin >> N;

    multiset<ll> m;
    REP(i, N) {
        cin >> d[i];
        m.insert(d[i]);
    }
    
    if (N%2==1) {
        print("0");
        return 0;
    }    
    auto itr = m.begin();
    REP(i, (N/2-1)) {
        itr++;
    }

    auto a = *itr;
    itr++;
    auto b = *itr;
    print((b-a));
    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define M 1000000007
#define pie 3.141592653589793238
using namespace std;


signed main(){  
    int n,x,t; cin >> n >> x >> t;
    cout << (int)(ceil(n/float(x)))*t;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if(a + b < c && c-a-b > 2 * sqrt((long double)a * b)) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
d.sort()
if len(list(set(d[:int(n/2)]).intersection(d[int(n/2):]))) != 0:
    print(0)
    exit()
else:
    print(d[int(n/2):][0] - d[:int(n/2)][-1])

Measured memory_bytes: 14428
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
using namespace std;

typedef long long lli;

const double inf = 1.0e100;
const double eps = 1e-6;
const int MAXN = 102;
const int MAXM = 52;
int N, M;
double L;
double P[MAXN];
double T[MAXN];
double V[MAXN];
lli comb[MAXM][MAXM];

vector<double> U[MAXN];
vector<double> Q[MAXN];

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

void make() {
  comb[0][0] = 1;
  for(int i = 1; i < MAXM; ++i) {
    for(int j = 0; j <= i; ++j) {
      comb[i][j] = 0;
      if(j) comb[i][j] += comb[i-1][j-1];
      if(j <= i-1) comb[i][j] += comb[i-1][j];
    }
  }
}

int main() {
  make();
  while(cin >> N >> M >> L) {
    for(int i = 0; i < N; ++i) {
      cin >> P[i] >> T[i] >> V[i];
      P[i] /= 100.0;
    }

    for(int i = 0; i < MAXN; ++i) {
      U[i].clear();
      Q[i].clear();
    }
    for(int i = 0; i < N; ++i) {
      for(int k = 0; k <= M; ++k) { // rest k times.
	if(V[i] == 0.0) U[i].push_back(inf);
	else U[i].push_back(L/V[i] + T[i]*k);
	Q[i].push_back(pow(P[i],k)*pow(1.0-P[i],M-k)*comb[M][k]);
      }
    }

    for(int i = 0; i < N; ++i) {
      double res = 0.0;
      for(int k = 0; k <= M; ++k) {
	if(V[i] == 0.0) break;
	double tmp = Q[i][k];
	for(int j = 0; j < N; ++j) {
	  if(i == j) continue;
	  /*
	  vector<double>::iterator it = 
	    lower_bound(U[j].begin(), U[j].end(), U[i][k]);
	  */
	  double a = 0;
	  for(int b = 0; b < U[j].size(); ++b) {
	    if(equals(U[j][b], U[i][k]) || U[j][b] < U[i][k]) continue;
	    a += Q[j][b];
	  }
	  tmp *= a;
	}
	res += tmp;
      }
      printf("%.8f\n", res);
    }
    //puts("");
    return 0;
  }
  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 
 

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


 
 int n;
 cin>>n;
 vector<int>v(n);
 vector<int>a(n),b(n);

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

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

 int x=-1,y=-1;
 if(v==a)x=1;
 if(v==b)y=1;
  int cnt=1;
 while(next_permutation(v.begin(),v.end()))
 {
   cnt++;
    if(v==a)x=cnt;
    if(v==b)y=cnt;
 }

 cout<<abs(x-y);
 
}

Measured memory_bytes: 256
from typing import List


def bubble_sort(A: List[str], N: int) -> List[str]:
    for i in range(N - 1):
        for j in range(N - 1, i, -1):
            if A[j - 1][1] > A[j][1]:
                A[j - 1], A[j] = A[j], A[j - 1]
    return A


def selection_sort(A: List[str], N: int) -> List[str]:
    for i in range(N - 1):
        tmp_min_index: int = i
        for j in range(i + 1, N):
            if A[tmp_min_index][1] > A[j][1]:
                tmp_min_index = j
        A[i], A[tmp_min_index] = A[tmp_min_index], A[i]
    return A


def is_stable(A: List[str], A_sorted: List[str], N: int) -> bool:
    for i in range(N - 1):
        for j in range(i + 1, N):
            # for a in range(N - 1):
            #     for b in range(a + 1, N):
            #         if A[i][1] == A[j][1] and A_sorted[a] == A[j] and A_sorted[b] == A[i]:
            #             return False
            if A[i][1] == A[j][1] and A_sorted.index(A[j]) < A_sorted.index(A[i]):
                return False
    return True


def main():
    N: int = int(input())
    A: List[str] = list(input().split())

    A_bubble = bubble_sort(A[:], N)
    A_selection = selection_sort(A[:], N)

    print(*A_bubble, sep=" ")
    print("Stable")
    print(*A_selection, sep=" ")
    print("Stable") if A_bubble == A_selection else print("Not stable")

    # print("Stable") if is_stable(A, A_bubble,
    #                              N) else print("Not stable")
    # print("Stable") if is_stable(A, A_selection,
    #                              N) else print("Not stable")


if __name__ == "__main__":
    main()



Measured memory_bytes: 7172
import sys
a,b,c,k = [int(_) for _ in input().split()]

ans = 0
if a >= k: #
  print(k)
  sys.exit()
else:
  ans = a
  k = k -a

if k != 0 and k - b > 0:
  print(a-(k-b))
else:
  print(a)


Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		char a[n+1][m];
		rep(i,1,n+1)
		{
			rep(j,0,m)cin>>a[i][j];
		}
		rep(i,1,2*n+1)
		{
			rep(j,0,m)cout<<a[(i+1)/2][j];
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
minus = [-x for x in a if x < 0]
plus = [x for x in a if x >= 0]

minus.sort()
plus.sort()

def cnt(x):
    ans = 0
    if x < 0:
        x = -x
        r = 0
        for num in minus[::-1]:
            while r < len(plus) and plus[r] * num < x:
                r += 1
            ans += len(plus) -  r
        return ans

    r = 0
    for num in minus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(minus) and minus[r] * num <= x:
            r += 1
        ans += r
    r = 0
    for num in plus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(plus) and plus[r] * num <= x:
            r += 1
        ans += r
    ans //= 2
    ans += len(minus) * len(plus)    
    return ans

bottom = 0
top = 2*(10**18) + 2


while top - bottom > 1:
    mid = (top + bottom) // 2
    if cnt(mid - 10**18-1) < k:
        bottom = mid
    else:
        top = mid

print(int(top - 10**18-1))

Measured memory_bytes: 119536