akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

class Dice{
public:
  int s[6];
  Dice(){}
  void roll(int i,int j,int k,int l){
    int t = s[i];
    s[i] = s[j];
    s[j] = s[k];
    s[k] = s[l];
    s[l] = t;
  }
  void roll_y(){ roll(0, 2, 5, 3); } // to W
  void roll_x(){ roll(0, 1, 5, 4); } // to N
  void move(char ch){
    if( ch == 'E' ) for(int i = 0; i < 3; i++) roll_y();
    if( ch == 'W' ) roll_y();
    if( ch == 'N' ) roll_x();
    if( ch == 'S' ) for(int i = 0; i < 3; i++) roll_x();
  }
};

int main(){
  Dice d;
  string com;

  for(int i = 0; i < 6; i++) cin >> d.s[i];
  cin >> com;

  for(int i = 0; i < com.size(); i++) d.move( com[i] );

  cout << d.s[0] << endl;
  
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<pii,int>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {for(auto e:x) cerr<<e<<",";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    string s; cin>>s;
    int ans=0;
    int cnt=0;
    for(int i=0;s[i];i++) {
        if(s[i]=='R') cnt++;
        else {
            ans=max(ans,cnt); cnt=0;
        }
    }
    cout<<max(ans,cnt)<<endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> V;

#define _ cin.tie(0);ios::sync_with_stdio(false);
int a,b;
int main(){ _;
  cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll MAX=500000;
const ll INF=(1ll<<62)-1;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=finv[1]=finv[0]=inv[0]=inv[1]=1;
    rep(i,2,MAX){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=modpow(i,MOD-2);
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
signed main(){
    ll N,K; cin >> N >> K;
    ll ans=0;
    if(K==1){
        rep(i,0,N){
            int X; cin >> X;
            if(X!=1) ans++;
        }
    }
    else{
        vii Edge(N);
        vi cnt(N);
        int _; cin >> _;
        if(_!=1) ans++;
        rep(i,1,N){
            int X; cin >> X;
            Edge[i].pb(X-1);
            cnt[X-1]++;
        }
        std::stack<int>  que;
        rep(i,0,N){
            if(cnt[i]==0) que.push(i);
        }
        vi memo;
        while(!que.empty()){
            int X=que.top(); que.pop();
            memo.pb(X);
            rep(i,0,Edge[X].size()){
                int Y=Edge[X][i];
                cnt[Y]--;
                if(cnt[Y]==0) que.push(Y);
            }
        }
        vi dp(N,1);
        rep(i,0,memo.size()){
            int X=memo[i];
            rep(j,0,Edge[X].size()){
                int Y=Edge[X][j];
                if(dp[X]==K&&Y!=0) ans++;
                else dp[Y]=std::max(dp[X]+1,dp[Y]);
            }
        }
    }
    cout << ans << endl;
}

 

Measured memory_bytes: 8500
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize);

    println!(
        "{}",
        if n == 25 {
            "Christmas"
        } else if n == 24 {
            "Christmas Eve"
        } else if n == 23 {
            "Christmas Eve Eve"
        } else {
            "Christmas Eve Eve Eve"
        }
    );
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ll long long int
#define pii <pair<ll,ll>>
#define pb push_back
using namespace std;

void solve()
{
    ll a,b;
    cin >> a >> b;
    cout << a*b << endl;
}

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) (a).begin(),(a).end()

template<typename T>
T lcs(T a, T b) {
    if (b.size() > a.size()) swap(a,b);
    int I = a.size();
    int J = b.size();
    vector<vector<int>> dp(I+1, vector<int>(J+1));
    rep1(i,I) rep1(j,J) {
        if (a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
        else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    }

    int cost = dp[I][J];
    T result;
    rep(ii,I) rep(jj,J) {
        int i = I-ii, j = J-jj;
        if(dp[i-1][j-1] == cost-1 && a[i-1] == b[j-1]) {
            result.push_back(a[i-1]);
            cost--;
            break;
        }
    }
    reverse(all(result));
    return result;
}


int main(void){
    string a,b;
    cin >> a >> b;
    cout << lcs(a,b) << endl;
    return 0;
}


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

long long n, ans=0, a[100010], p,l,idx ;
int main() {
	cin >>n;
    for (int i=1; i<=n; i++){
        cin>>a[i];
    }
    sort(a+1, a+n+1);
    
    for (int i=n; i>=1 ;i--){
        if (a[i]==a[i-1]){
            p=a[i];
            idx=i;
            break;
        }
    }
    
    for (int i=idx-2; i>=1; i--){
        if (a[i]==a[i-1]){
            l=a[i];
            break;
        }
    }
    
    cout<<p*l<<endl;
}


Measured memory_bytes: 4364
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t,x,i,j,k,l,dp[100001],a[100001];
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        dp[i]=LLONG_MAX;
        cin>>a[i];
        if(i==1)
            dp[i]=0;
        else
        {
            for(j=1;j<=k&&(i-j)>=1;j++)
            {
            dp[i]=min({dp[i],dp[i-j]+abs(a[i]-a[i-j])});
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
hoge = [int(input()) for i in range(n)]
max_value = max(hoge)
second_value = sorted(hoge)[-2]
if max_value == second_value:
    for i in range(len(hoge)):
        print(max_value)
else:
    for i in hoge:
        if i != max_value:
            print(max_value)
        else:
            print(second_value)

Measured memory_bytes: 13384
import math

def isPrime(x):
	for i in range(2,int(math.sqrt(x))+1):
		if x%i == 0:
			return 0
	return 1

n=int(input())
ans=0
for i in range(n):
	x=int(input())
	if isPrime(x):
		ans+=1
print(ans)


Measured memory_bytes: 5676
// 私はは情報学愛する！<3
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

using i64 = long long;
using pii = pair<int, int>;

i64 h, mx;
vector<i64> d;

int main() {
#ifdef HOME
	freopen("abc85d.in", "r", stdin);
	freopen("abc85d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 t;
	int n;

	cin >> n >> h;
	d.resize(n);
	for (auto &i: d) {
		cin >> t >> i;
		mx = max(mx, t); }

	for (int i = 0; i < n; ++i)
		if (d[i] <= mx) {
			swap(d[i], d.back());
			d.pop_back();
			--n, --i; }

	sort(begin(d), end(d));
	reverse(begin(d), end(d));

	for (int i = 0; i < n; ++i) {
		h-= d[i];
		if (h <= 0) {
			cout << i + 1 << endl;
			return 0; } }

	cout << n + h / mx + int(h % mx > 0) << endl;

	return 0; }



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> 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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);


int main(){
    vector<ll>C2(200010,0LL);
    for(ll i=1;i<200003;i++){
        C2[i]=i*(i-1)/2;
    }
    C2[0]=0LL;
    int n;
    cin >> n;
    ll serve=0LL;
    ll ans=0LL;
    vector<int>a(200010,0);
    map<int,int>p;
  
 
rep(i,n){
    cin>>a[i];
    p[a[i]]+=0;
    p[a[i]]++;    
}
    for(auto itr=p.begin();itr!=p.end();itr++){
        serve+=C2[itr->S];
     //   clog<<(itr->F)<<" "<<(itr->S)<<endl;
    }
   // clog<<serve<<endl;
    for(int i=0;i<n;i++){
        ans=serve-C2[p[a[i]]]+C2[p[a[i]]-1];
        
        cout<<ans<<endl;
    }
    //cout<<ans<<endl;
}

Measured memory_bytes: 9856
{-# LANGUAGE BangPatterns #-}
import Data.List
import Control.Monad
import Data.Array.Unboxed
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInteger = toInteger . fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
read2dInts = map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents


main :: IO ()
main = do
  (a:b:q:_) <- fmap (map read . words) getLine :: IO [Int]
  ss <- replicateM a $ readInteger <$> B.getLine :: IO [Integer]
  ts <- replicateM b $ readInteger <$> B.getLine :: IO [Integer]
  qs <- replicateM q $ readInteger <$> B.getLine :: IO [Integer]
  mapM_ (print . solve a b ss ts) qs

maxB = 10^15
minB = negate maxB

solve a b ss ts = go
  where
    sarr = listArray (0, a+1) $ (minB:sort ss) ++ [maxB] :: Array Int Integer
    tarr = listArray (0, b+1) $ (minB:sort ts) ++ [maxB] :: Array Int Integer
    go q = minimum candidates
      where
        candidates = [
          (max sr tr) - q, 
          sr - tl + sr - q, 
          sr - tl + q - tl, 
          tr - sl + tr - q,
          tr - sl + q - sl, 
          q - (min sl tl)
          ]
        s = lowerBound (\i -> sarr!i > q) (0, a+1)
        t = lowerBound (\i -> tarr!i > q) (0, b+1)
        (sl, sr) = (sarr!(s-1), sarr!s)
        (tl, tr) = (tarr!(t-1), tarr!t)

-- lowerBound :: (Int -> Bool) -> (Int, Int) -> Int
lowerBound predicate bounds = go bounds
  where
    go !(!l, !h) | l + 1 == h  = h
                 | predicate m = m `seq` go (l, m)
                 | otherwise   = m `seq` go (m, h)
      where m = (l + h) `div` 2

Measured memory_bytes: 82428
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
    private static final int[] queen = new int[8];
    private static final boolean[] lock = new boolean[8];
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        for(int i = 0; i<n; i++){
            final StringTokenizer st = new StringTokenizer(br.readLine(), " ");
            final int r = Integer.parseInt(st.nextToken());
            final int c = Integer.parseInt(st.nextToken());
            queen[r] = c;
            lock[r] = true;
        }
        search(0);
        final char[] ans = new char[72];
        Arrays.fill(ans, '.');
        for(int i = 8; i<72; i += 9)
            ans[i] = '\n';
        for(int i = 0; i<8; i++)
            ans[i*9+queen[i]] = 'Q';
        System.out.print(ans);
    }
    private static boolean search(int r){
        if(r>=8) return true;
        if(lock[r]) return canPut(r, queen[r])&&search(r+1);
        for(int i = 0; i<8; i++){
            queen[r] = i;
            if(canPut(r, i)&&search(r+1)) return true;
        }
        return false;
    }
    private static boolean canPut(int r, int c){
        for(int i = 0; i<8; i++){
            if(i<r||(i>r&&lock[i])){
                if(c==queen[i]) return false;
                if(Math.abs(c-queen[i])==Math.abs(r-i)) return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 24432
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
	int64_t x;
	mint(int64_t x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
	mint operator+(const mint a) const { return mint(*this) += a;}
	mint operator-(const mint a) const { return mint(*this) -= a;}
	mint operator*(const mint a) const { return mint(*this) *= a;}
	mint pow(int64_t t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const { return pow(mod-2);}
	mint& operator/=(const mint a) { return *this *= a.inv();}
	mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int N = 1e5+10;

//head

int n;
vi G[N];

pair<mint, mint> dfs(int i, int j) {
	mint resb(1), resw(1);
	for(int ne:G[i]) {
		if(ne == j) continue;
		mint nb, nw;
		tie(nb, nw) = dfs(ne, i);
		resb *= nw;
		resw *= nw+nb;
	}
	return make_pair(resb, resw);
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	rep(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}
	mint u, i;
	tie(u, i) = dfs(0, -1);
	cout << u + i << endl;
}

Measured memory_bytes: 16020
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    int n;
    int k;
    cin >> n;
    cin >> k;
    int p[n];
    for(int i=0;i<n;i++) {
        cin >> p[i];
    }
    sort(p,p+n);
    int total = 0;
    for(int i=0;i<k;i++) {
        total+=p[i];
    }
    cout << total << endl;
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 3680
N,M=map(int,input().split())
A=[int(input()) for n in range(M)]
S=[1]*(N+1)
for a in A:
  S[a]=0
for i in range(2,N+1):
  S[i]=(S[i-1]+S[i-2])%1000000007*S[i]

print(S[-1])

Measured memory_bytes: 7848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD=1e9+7;
ll inv(ll a, ll b = MOD){
    ll x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b != 0) {
        const ll q = a / b;
        ll tmp = a % b;
        a = b;
        b = tmp;
        tmp = x0 - q * x1;
        x0 = x1;
        x1 = tmp;
        tmp = y0 - q * y1;
        y0 = y1;
        y1 = tmp;
    }
    return (x0 + MOD) % MOD;
}
ll fact(ll x){
    // 再帰だとスタックオーバーフローするので
    ll ret = 1;
    for(ll a=2; a<=x; ++a){
        ret = (ret * a) % MOD;
    }
    return ret;
}
/*
【解法】
A = [1, 2, ..., n] と固定する（求める場合の数は、固定した場合の数の mPn 倍）。B を長さ n の数列とする

ある集合 S \subset {1, ..., n} の上で値が一致する（そのほかにも一致する値のある可能性がある）ような B の場合の数は g(S) = (m-|S|)P(n-|S|) 通り
（まだ決まっていない n-|S| 箇所の値を、使っていない m-|S| 個の値から重複しないように決める）

ある集合 S \subset {1, ..., n} の上でちょうど値が一致する（ S に属さない点 i ではA[i] != B[i] となる）ような
B の場合の数を f(S) 通りとすると、g(S) = \sum_{S\subset T} f(T) となる。

F(S) = f({1, ..., n} \setminus S), G(S) = g({1, ..., n} \setminus S) とおくと、
G(S) = \sum_{T\subset S} F(S) なので、包除原理から F(S) = \sum_{T\subset S} (-1)^|S\setminus T| G(T) が成り立つ。

求めるのは f(\emptyset)
= F({1, ..., n})
= \sum_{T\subset {1, ..., n}} (-1)^|{1, ..., n}\setminus T| G(T)
= \sum_{T\subset {1, ..., n}} (-1)^|{1, ..., n}\setminus T| g({1, ..., n} \setminus T)
= \sum_{T\subset {1, ..., n}} (-1)^|T| g(T)
（ T -> T\setminus {1, ..., n} で置換）
ここで g は size の関数なので g(T) = g(|T|) とおくと、 k 元集合の選び方が nCk 通りなので 
= \sum_{k=0}^n (-1)^k nCk g(k)
= \sum_{k=0}^n (-1)^k n! / (n-k)! / k! * (m-k)! / (m-n)!
となる。

これを高速に計算する。 k == 0 のとき m! / (m-n)! で、

    n! (m-k)!             n! (m-(k-1))!          n-k+1
---------------- == ------------------------ * ---------
(n-k)! k! (m-n)!    (n-(k-1))! (k-1)! (m-n)!   (m-k+1) k

なので、 k がふえるたびに (n-k+1) / (m-k+1) / k 倍すればよい
*/
ll inv_table[500001] = {};
void make_inv_table(int n){
    inv_table[1] = 1;
    for (int i=2; i<=n; ++i){
        // (MOD / i) * i + MOD % i = 0 なので
        // (MOD / i) * i = - (MOD % i)
        // - (MOD / i) * (MOD % i)^(-1) = i^(-1)
        inv_table[i] = inv_table[MOD%i] * (MOD - MOD / i) % MOD;
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;

    const ll mpn = fact(m) * inv(fact(m-n)) % MOD;
    ll tmp = mpn;
    ll sum = tmp;
    const ll sign[2] = {1, MOD-1};
    make_inv_table(m);
    for(int k=1; k<=n; ++k){
        tmp = ((tmp * inv_table[m-k+1]) % MOD * inv_table[k] % MOD) * (n-k+1) % MOD;
        sum = (sum + sign[k%2] * tmp) % MOD;
    }
    cout << (sum * mpn) % MOD;
    return 0;
}


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

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

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

  sort(p.begin(), p.end(), greater<int>());
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      sum += (p[i] / 2);
    } else {
      sum += p[i];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAXDATANUM 100000

//ユークリッドの互除法
int gcd(int a, int b){
    int m,n,r;
    if(a > b){
        m = a;
        n = b;
    }else{
        m = b;
        n = a;
    }
    
    while(n){
        r = m % n;
        m = n;
        n = r;
    }
    return m;
}

int main(void){
    int n;
    int a[MAXDATANUM];
    int memo[MAXDATANUM][2] = {};
    int i;
    int max = 0;
    

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

    for(i = 1; i < n; i++){
        memo[i][0] = gcd(a[i - 1], memo[i - 1][0]);
    }
    
    for(i = n - 2; i >= 0; i--){
        memo[i][1] = gcd(a[i + 1], memo[i + 1][1]);
    }
    
    for(i = 0; i < n; i++){
        if(max < gcd(memo[i][0], memo[i][1])){
            max = gcd(memo[i][0], memo[i][1]);
        }
    }
    printf("%d", max);
    
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

#define _USE_MATH_DEFINES
#include <math.h>

int main(void) {

	int R;
	double result;

	scanf("%d", &R);

	if (R >= 1, R <= 100) {

		result = R * 2 * M_PI;

		printf("%lf", result);
	}

	return 0;

}

Measured memory_bytes: 1724
#include<iostream>
using namespace std;
int main(){
int n,num[100];
cin >> n;
for(int a=0; a<n; a++){
cin >> num[a];
}
for(int b=n-1; b>=0; b--){
if(b!=n-1) cout << " ";
cout << num[b];
}
cout <<endl;
return 0;
}


Measured memory_bytes: 3096
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    T, X = map(int, input().split())
    print(T / X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll N,M,K;
        cin>>N>>M>>K;
        ll x=min(M-1,K);
        cout<<(N*x)/M-N*(x/M)<<endl;
    }
}


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a,b,x;
  cin>>a>>b>>x;
  if(a<=x && x<=a+b)
    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++)
typedef long long int ll;
typedef pair<int, int> P;

const int MOD = 2019;

int main()
{
  ll l, r;
  cin >> l >> r;
  if(r-l >= MOD-1)
  {
    cout << 0 << endl;
    //cout << "return";
    return 0;
  }
  
  ll res = 1e9;
  for(ll i = l; i < r; i++)
  {
    for(ll j = i + 1; j <= r; j++)
    {
      res = min(res, (i*j)%MOD);
    }
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vvl v(n, vl(3));
    rep(i, n) {
        rep(j, 3) {
            cin >> v[i][j];
        }
    }

    ll ans = 0;
    rep(b, 1<<3) {
        vl w(n);
        rep(i, n) {
            ll u = 0;
            rep(j, 3) {
                if(b & 1<<j) {
                    u += -v[i][j];
                }
                else {
                    u += v[i][j];
                }
            }
            w[i] = u;
        }
        sort(rall(w));
        ll now = 0;
        rep(i, m) {
            now += w[i];
        }
        chmax(ans, now);
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a<c&&c<b)printf("Yes");
	else if(b<c&&c<a)printf("Yes");
	else printf("No");
	return 0;
}

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

n,x = map(int, raw_input().split())
a = map(int, raw_input().split())

cnt = 0
for i in range(n-1):
    if(a[i+1]+a[i]>x):
        surplus = a[i+1]+a[i]-x
        cnt += surplus
        if(a[i+1] >= surplus):
            a[i+1] -= surplus
        else:
            surplus -= a[i+1]
            a[i+1] = 0
            a[i] -= surplus 
print(cnt)         
 
    

Measured memory_bytes: 11316
//あらためて見るとこの問題全然わからない

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
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 Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int a[2][200000], b[2][200000];
	rep(i, N) a[0][i] = getint();
	rep(i, N) b[0][i] = getint();

	int kotae = 0;
	rep(i, 29) {
		int p = i & 1;

		int kazu[2] = {};
		rep(j, N) kazu[a[p][j] >> i & 1]++;
		kazu[1] += kazu[0];
		for (int j = N - 1; j >= 0; j--) a[!p][--kazu[a[p][j] >> i & 1]] = a[p][j];
		kazu[0] = 0;
		kazu[1] = 0;
		rep(j, N) kazu[b[p][j] >> i & 1]++;
		kazu[1] += kazu[0];
		for (int j = N - 1; j >= 0; j--) b[!p][--kazu[b[p][j] >> i & 1]] = b[p][j];

		int kari = N;
		int k1 = kazu[1];
		int k2 = N;
		int k3 = N;
		int d = (1 << i + 1) - 1;
		int d2 = 1 << i;
		rep(j, N) {
			while (k3 > 0 && (a[!p][j] & d) + (b[!p][k3 - 1] & d) >= d2 * 3) k3--;
			k2 = min(k2, k3);
			while (k2 > 0 && (a[!p][j] & d) + (b[!p][k2 - 1] & d) >= d2 * 2) k2--;
			k1 = min(k1, k2);
			while (k1 > 0 && (a[!p][j] & d) + (b[!p][k1 - 1] & d) >= d2) k1--;
			kari ^= k1 ^ k2 ^ k3;
		}
		kotae += (kari & 1) << i;
	}
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int K;
    cin >> K;
    int X;
    int A = 0;
    for (int i = 0; i < N; i++){
        cin >> X;
        if (K - X < X){
            A = A + (K - X) * 2;
        }
        else {
            A = A + X * 2;
        }
    }
    cout << A << endl;
    
}


Measured memory_bytes: 256
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Sep  1 21:23:25 2019
//
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)

	ans := 0
	for i := range s {
		if s[i] == t[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	rep(i, 5) {
		ll x;
		cin >> x;
		if (x == 0) {
			cout << (i + 1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll n;
    cin>>n;
    ll x=0;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        x=x^a[i];
    }
    for(int i=0;i<n;i++)
        cout<<(x^a[i])<<' ';
    subt;
    return 0;
}

Measured memory_bytes: 5224
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <fstream>
#include <map>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <array>
#include <chrono>

int main()
{
    int N, M;
    std::cin >> N; std::cin >> M;

    std::vector<std::bitset<10>> s;

    for(int j=0; j<M; j++) {
        int v;
        std::cin >> v;
        int bit = 0;
        
        for(int i=0; i<v; i++) {
            int x; std::cin >> x;
            bit += 1 << (x - 1);
        }

        s.emplace_back(bit);
    }

    std::vector<int> P; P.resize(M);
    for(auto&& p : P) {
        std::cin >> p;
    }

    int lit = 0;
    for(int i=0; i<(std::pow(2, N)); i++) {
        std::bitset<10> test(i);
        
        for(int j=0; j<M; j++) {
            if((s[j] & test).count() % 2 != P[j])
                goto next;
        }

        lit++;
next:;
    }

    std::cout << lit << std::endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    string s = "Sunny", c = "Cloudy", r = "Rainy", x;
    cin >> x;
    if(x == s) cout << c << endl;
    elif(x == c) cout << r << endl;
    else cout << s << endl;
}

Measured memory_bytes: 256
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    alist = intina()

    ans = 0
    for a in alist:
        ans += (a - 1)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];
vector<int> val;
int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    val.resize(n);

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

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

    for(int i=0;i<n;i++){
        idx = lower_bound(val.begin(),val.end(),A[i])-val.begin();
        if((idx&1)^(i&1))cnt++;
    }

    cnt>>=1;

    cout<<cnt<<"\n";

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
int gcd(int a, int b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string N;
	cin >> N;
	int n4 = 0;
	int n2 = 0;
	int n1 = 0;
	vector<char> data(N.size());
	//char re = reverse(N.begin(), N.end());

	if (N[0] == N[2])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	
	return 0;

	


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,s=0;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
      cin >> d[i];
  }
  for(int i=0 ; i<N-1 ;i++){
      for(int j=i+1;j<N ;j++){
          s += d[i]*d[j];
      }
  }
  cout << s << endl;
}

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

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int sum[n]={0};
    for(int i = 1; i < n; i++)
    {
        sum[i] += sum[i-1];
        if(s[i-1]=='A'&&s[i]=='C'){
            sum[i]++;
        }
    }
    
    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        int ans = sum[r]-sum[l];
        cout << ans << endl;
    }
        
    
    
    return 0;
}

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

int SelectionSort(vector<int> &A){
    int N = A.size();
    int cnt = 0;
    for(int i = 0; i < N; ++i){
        int minj = i;
        int flag = 0;
        for(int j = i; j < N; ++j){
            if(A[j] < A[minj]){
                minj = j;
                flag = 1;
            }
        }
        if(flag){
            int tmp = A[i];
            A[i] = A[minj];
            A[minj] = tmp;
            ++cnt;
        }
    }
    return cnt;
}
int main(void){
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for(int i = 0; i < N; ++i)
        cin >> A[i];
    int cnt = SelectionSort(A);
    for(int i = 0; i < N; ++i){
        cout << A[i];
        if(i != N - 1)
            cout << " ";
    }
    cout << endl << cnt << endl;
    return 0;
}

Measured memory_bytes: 3052
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string>
#define qw() freopen("in.txt","r",stdin)
#define er() freopen("out.txt","w",stdout)
using namespace std;
int main(void)
{
    char s[105];
    while(cin>>s)
        printf("%c%d%c\n",s[0],strlen(s)-2,s[strlen(s)-1]);
    return 0;
}


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

void fast_IO() { ios_base::sync_with_stdio(false);cin.tie(NULL);}
void test_here_once(){ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);}


void knapsack2(ll wt[], ll val[], ll n, ll w)
{
	ll Vmax=0, Vmin=INT_MAX;
	for(ll i=0;i<n;i++){ Vmax+=val[i]; Vmin=min(Vmin, val[i]);}

	ll dp[n+1][Vmax+1];

	// initialisation
	for(ll v=0;v<=Vmax;v++) dp[1][v]= INT_MAX;
	dp[1][0]=0;
	dp[1][val[0]]= wt[0];

	for(ll i=2;i<=n;i++)
	{
		for(ll j=0;j<=Vmax;j++)
		{
			if(val[i-1]<=j)
			{
				dp[i][j]= min(dp[i-1][j-val[i-1]]+wt[i-1], dp[i-1][j]);
			}
			else dp[i][j]= dp[i-1][j];
		}
	}

	// for(ll i=0;i<=n;i++)
	// {
	// 	for(ll j=0;j<=Vmax;j++) cout<<dp[i][j]<<" "; cout<<endl;
	// }

	ll ans;
	for(ll j=0;j<=Vmax;j++)
	{
		if(dp[n][j]<=w)	ans=j;
	}
	cout<<ans;
}


void fun()
{
	ll n,w; cin>>n>>w;
	ll wt[n], val[n];
	for(ll i=0;i<n;i++) cin>>wt[i]>>val[i];

	knapsack2(wt,val,n,w);
}

int main()
{
	//test_here_once();
	fast_IO();

	fun();
/*	int t; cin>>t;
	while(t--)
	{
		fun();
	}*/
}

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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    int n,x;
    cin>>n;
    if(n>=400 && n<=599)
        x=8;
    else if(n>=600 && n<=799)
        x=7;
    else if(n>=800 && n<=999)
        x=6;
    else if(n>=1000 && n<=1199)
        x=5;
    else if(n>=1200 && n<=1399)
        x=4;
    else if(n>=1400 && n<=1599)
        x=3;
    else if(n>=1600 && n<=1799)
        x=2;
    else
        x=1;

    cout<<x<<nl;
    return 0;
}



Measured memory_bytes: 3632
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n; cin >> n;
  vector<string> S(n);
  loop(i,0,n) cin >> S[i];
  char c = S[0][0];
  set<string> S2;
  for (auto&&s: S) {
    if (S2.count(s)) {
      cout << "No" << endl;
      return 0;
    }
    
    if (s[0] != c) {
      cout << "No" << endl;
      return 0;
    }
    c = s[s.size()-1];
    S2.insert(s);
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3612
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=17;
const int FULLS=1<<16;
int n,w,a[N][N];ll s[FULLS],dp[FULLS];
inline ll Calc(int S,int x){
	ll sum=0;
	for(register int i=1;i<=n;i++)
		if((S>>(i-1))&1)sum+=a[x][i];
	return sum;
}
int main(){
	scanf("%d",&n);w=(1<<n)-1;
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	for(register int S=0;S<=w;S++)
		for(register int i=1;i<=n;i++)
			if(s[S|(1<<(i-1))]||(S&(1<<(i-1))))continue;
			else s[S|(1<<(i-1))]=s[S]+Calc(S,i);
	for(register int S=0;S<=w;S++)dp[S]=s[S];
	for(register int S=0;S<=w;S++)//由于S的子集比他小，所以在更新S之前其子集一定都已经被更新到最优状态了 
		for(register int sta=S;sta;sta=(sta-1)&S)
			dp[S]=max(dp[S],dp[sta]+dp[S^sta]);
	printf("%lld\n",dp[w]);
	return 0;
}

Measured memory_bytes: 1280
def solution():
    n = input()
    data = []
    for _ in range(n):
        data.append([int(val) for val in raw_input().split()])
    for i in range(n):
        ans = True
        l = 0
        r = 0
        for j in range(10):
            if data[i][j] > l:
                l = data[i][j]
            elif data[i][j] > r:
                r = data[i][j]
            else:
                ans = False
                break
        if ans:
            print 'YES'
        else:
            print 'NO'

solution()


Measured memory_bytes: 4660
#include <iostream>
using namespace std;
//Takahashi the Jumbo will practice golf.
//His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between 
//A and  B (inclusive). If he can achieve the objective, print OK; if he cannot, print NG

string isItPossible(int A, int B, int K){
for (int i=0; i<=B-A; ++i){
		if((B-i)%K==0)
		return "OK";}
		return "NG";

}
int main(){
	int K;
	int A;
	int B;
	string possible;
	cin >> K>>A>>B;
	possible= isItPossible(A,B,K);
	cout<<possible<<endl;
	return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = -inf;
	}
	
	void update(int i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = max(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return -inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return max(lval, rval);
	}
	llint query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint n, k;
llint a[300005], pos[300005];
vector<P> vec;
SegTree seg(19);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		vec.push_back(P(a[i], i));
	}
	sort(vec.begin(), vec.end());
	for(int i = 0; i < vec.size(); i++){
		pos[vec[i].second] = i;
	}
	
	seg.init();
	for(int i = 1; i <= n; i++){
		llint l = lower_bound(vec.begin(), vec.end(), P(a[i]-k, -inf)) - vec.begin();
		llint r = upper_bound(vec.begin(), vec.end(), P(a[i]+k, inf)) - vec.begin() - 1;
		llint res = max(seg.query(l, r) + 1, 1LL);
		seg.update(pos[i], res);
	}
	cout << seg.query(0, n+1) << endl;
	
	return 0;
}

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

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int N = 200002;
LL read() {
	LL s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x < 0) x = -x, putchar('-');
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int A[N], nxt[N], lst[N], fir[N];
int f[41][N]; LL bin[41];
int tp, sta[N];
bool v[N];

int main() {
	int n = read(); LL k = read() - 1;
	for(int i = 1; i <= n; i++) {A[i] = read(); if(!fir[A[i]]) fir[A[i]] = i;}
	bin[0] = 1; for(int i = 1; i <= 40; i++) bin[i] = bin[i - 1] << 1;
	f[0][n + 1] = 1;
	for(int i = n; i >= 1; i--) {
		if(!nxt[A[i]]) f[0][i] = fir[A[i]] + 1;
		else f[0][i] = f[0][nxt[A[i]] + 1];
		nxt[A[i]] = i;
	} int pos = 1;
	for(int i = 1; i <= 40; i++) for(int j = 1; j <= n + 1; j++) f[i][j] = f[i - 1][f[i - 1][j]];
	for(int i = 40; i >= 0; i--) if(k >= bin[i]){
		k -= bin[i], pos = f[i][pos];
	} for( ; pos <= n; pos++) {
		if(lst[A[pos]]) {
			while(A[sta[tp]] != A[pos]) lst[A[sta[tp]]] = 0, tp--;
			tp--, lst[A[pos]] = 0;
		} else sta[++tp] = pos, lst[A[pos]] = 1;
	} for(int i = 1; i <= tp; i++) put(A[sta[i]]), putchar(' ');
	return 0;
}



Measured memory_bytes: 37504