akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

/*
<url:https://arc064.contest.atcoder.jp/tasks/arc064_c>
問題文============================================================
 xy 平面があります。 すぬけ君は座標 (xs,ys) から座標 (xt,yt) まで移動しようとしています。
 すぬけ君は好きな向きへ速さ 1 で動くことができます。 なお、すぬけ君は大きさのない点と見なすことにします。
 
 平面上には N 個の円形のバリアが張ってあります。
 i 番目のバリアは中心が (xi,yi) で半径が ri です。
 バリアは互いに重なっていたり、互いを含んでいたりすることがあります。
 
 平面上の各座標について、その座標がどのバリアの内部にも含まれない場合、その座標には宇宙線が降り注いでいます。
 
 すぬけ君は移動中にできるだけ宇宙線を浴びたくないので、宇宙線を浴びる時間が最小になるように移動します。
 すぬけ君が移動中に宇宙線を浴びる時間の最小値を求めてください。

=================================================================

解説=============================================================
よくあるパターン　頻出　ICPCにも似たようなやつあった
 
 自由な向きに移動できるので
 あるバリア内の自由な位置から出ることができる為
 バリアi -> バリアj への移動は単純な円同士の距離で出せる。
 始点と終点に関しては 半径0の円とみなせるので
 この問題は 円から円へ最短経路を取って言った時に、 0 -> N+1までの最短距離と言った
 単純なdijkstraに落とし込める
================================================================
*/
struct edge{
    int u,v;
    double c;
    edge(){}
    edge(int u,int v,double c):u(u),v(v),c(c){}
};

#define MAX_N 1000
ll x[MAX_N+2],y[MAX_N+2],r[MAX_N+2];

inline double c_dist(int i,int j){
    double d = hypot(x[i]-x[j],y[i]-y[j]);
    return max(d-(r[i]+r[j]),0.0);
}
double solve(){
    ll xs,ys,xt,yt; cin >> xs >> ys>> xt >> yt;
    int N; cin >> N;
    x[0] = xs; y[0] = ys; r[0] = 0;
    for(int i = 1; i <= N;i++) cin >> x[i] >> y[i] >> r[i];
    x[N+1] = xt; y[N+1] = yt; r[N+1] = 0;
    
    vector<vector<edge>> G(N+2);
    for(int i = 0; i < N+2;i++){
        for(int j = i+1; j < N+2;j++){
            double d = c_dist(i,j);
            G[i].push_back(edge(i,j,d));
            G[j].push_back(edge(j,i,d));
        }
    }
    
    vector<double> dist(N+2,LINF*2);
    typedef pair<double,int> pdi;
    priority_queue<pdi,vector<pdi>,greater<pdi>> pq;
    dist[0] = 0; pq.push(pdi(0.0,0));
    while(pq.size()){
        pdi p = pq.top(); pq.pop();
        double d; int n; tie(d,n) = p;
        if(d > dist[n]) continue;
        for(edge& e:G[n]){
            if(dist[e.v] > dist[e.u] + e.c){
                dist[e.v] = dist[e.u] + e.c;
                pq.push(pdi(dist[e.v],e.v));
            }
        }
    }
    return dist[N+1];
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(12) << solve() << endl;
	return 0;
}


Measured memory_bytes: 21012
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#define INF 100000000
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
vector<P> V(200005);

bool comp(const P& a, const P& b) {
	//if (a.second > b.second) return (a.second > b.second);
	return a.second > b.second;
}
int main() {
	int N, K;
	cin >> N >> K;
	//memset(&V[0], 0, sizeof(V[0])*V.size());
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		V[x].first = x;
		V[x].second++;
	}
	sort(V.begin(), V.end(), comp);

	int cnt = 0;
	for (int i = 0;; i++) {
		if (V[i].second == 0) break;
		if (i + 1 > K) {
			cnt += V[i].second;
		}
	}
	cout << cnt << endl;
	//for (int i = 0; i < N+1; i++) {
	//	cout << V[i].first << " " << V[i].second << endl;
	//}

	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>

using namespace std;

int main(void){

    int a,b;
    cin>>a>>b;
    int c=1;
    int sum = a;

    if(b==1){
        cout<<"0"<<endl;
        return 0;
    }

    while(sum < b ){
        sum = (a - 1)*c + a;
        c ++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
use std::io::{self, BufRead};

fn readline() -> String {
    let mut line = String::new();
    let stdin = io::stdin();
    stdin.lock().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn id(first: char) -> Option<usize> {
    let str = "MARCH";
    for (i, c) in str.chars().enumerate() {
        if c == first {
            return Some(i);
        }
    }
    None
}

fn main() {
    let n: i32 = readline().parse().unwrap();
    let mut count: [i64; 5] = [0, 0, 0, 0, 0];

    for _ in 0..n {
        let str = readline();
        if let Some(j) = id(str.chars().next().unwrap()) {
            count[j] = count[j] + 1;
        }
    }

    let mut ans: i64 = 0;

    for i in 0..5 {
        for j in i+1..5 {
            for k in j+1..5 {
                ans += count[i] * count[j] * count[k];
            }
        }
    }

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

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

vector<int> manacher(string& S) {
  vector<int> R(S.size());
  int i = 0, j = 0;
  while (i < S.size()) {
    while (i-j >= 0 && i+j < S.size() && S[i-j] == S[i+j]) ++j;
    R[i] = j;
    int k = 1;
    while (i-k >= 0 && i+k < S.size() && k+R[i-k] < j) R[i+k] = R[i-k], ++k;
    i += k; j -= k;
  }
  return R;
}
signed main() {
  int n; cin >> n;
  string s; cin >> s;
  vector<int> a = manacher(s);
  dump(a);
  bool same = true;
  REP (i, n) {
    if (s[0] != s[i]) same = false;
  }
  if (same) {
    cout << 2 << endl; return 0;
  }
  REPI (k, 2, n + 1) {
    dump(k);
    bool ok = true;
    for (int cen = k - 1; cen < n; cen += k - 1) {
      dump(cen);
      dump(a[cen], min(k, n - cen));
      if (a[cen] < min(k, n - cen)) ok = false;
    }
    if (ok) {
      cout << k << endl; return 0;
    }
  }
}



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

typedef long long ll;

int main() {
  int N; cin >> N;
  ll p = 1;
  int cnt = 0;
  for ( int i = 1; i <= N; i++ ) {
    p*=i;
    p %= 1000000007;
  }
  //cout << "p" << p << endl;
  cout << p << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

const int N = 300111;
int n, k;
int a[N];
int t1[4 * N];
int t2[4 * N];

void build1(int v, int l, int r){
    if (l == r){
        t1[v] = a[l];
    }
    else {
        int mid = (l + r) / 2;
        build1(v * 2, l, mid);
        build1(v * 2 + 1, mid + 1, r);
        t1[v] = max(t1[v * 2], t1[v * 2 + 1]);
    }
}

int get1(int v, int l, int r, int tl, int tr){
    if (l > r || tl > tr){
        return 0;
    }
    if (l == tl && r == tr){
        return t1[v];
    }
    else {
        int mid = (l + r) / 2;
        return max( get1(v * 2, l, mid, tl, min(mid, tr)),
                         get1(v * 2 + 1, mid + 1, r, max(mid + 1, tl), tr));
    }
}

void build2(int v, int l, int r){
    if (l == r){
        t2[v] = a[l];
    }
    else {
        int mid = (l + r) / 2;
        build2(v * 2, l, mid);
        build2(v * 2 + 1, mid + 1, r);
        t2[v] = min(t2[v * 2], t2[v * 2 + 1]);
    }
}

int get2(int v, int l, int r, int tl, int tr){
    if (l > r || tl > tr){
        return 1e9;
    }
    if (l == tl && r == tr){
        return t2[v];
    }
    else {
        int mid = (l + r) / 2;
        return min( get2(v * 2, l, mid, tl, min(mid, tr)),
                         get2(v * 2 + 1, mid + 1, r, max(mid + 1, tl), tr));
    }
}

vector <int> g[N];
bool used[N];

void dfs(int v){
    //cout << v << " ";
    used[v] = 1;
    for (int i = 0; i < g[v].size(); i++){
        int to = g[v][i];
        if (!used[to]){
            dfs(to);
        }
    }
}

int nx = 0;
signed main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("diameter.in", "r", stdin);
    //freopen("diameter.out", "w", stdout);
    cin >> n >> k;

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


    int r = n + 1;
    for (int i = n - 1; i >= 1; i--){
        if (a[i] > a[i + 1]){
            r = i + 1;
        }
        if (i + k - 1 <= n && i + k - 1 < r){
            //cout << i << " i " << endl;
            if (nx == 0){
                nx = i;
            }
            else {
                g[i].pb(nx);
                nx = i;
            }
        }
    }

    build1(1, 1, n);
    build2(1, 1, n);


    for (int i = 1; i + k <= n; i++){
        int r1 = get2(1, 1, n, i + 1, i + k);
        int l1 = get1(1, 1, n, i, i + k - 1);
        if (r1 > a[i] && l1 < a[i + k]){
            g[i].pb(i + 1);
        }
        //cout << a[i] << " " << r1 << " " << a[i + k] <<" " << l1 << endl;
    }

    int cnt = 0;

    for (int i = 1; i + k - 1 <= n; i++){
        if (!used[i]){
            cnt++;
            dfs(i);
            //cout << endl;
        }
    }


    cout << cnt << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

//#define len(array)  (sizeof(array)/sizeof((array)[0]))
#define endl '\n'
#define int ll

const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;
const int MX = 777777 + 5;
const int mod = 1777777777;
const double EPS = 1e-10;
const ll MXP = 8999251775770639633;

inline int len(string s){return s.size();}
inline int len(int* A){return (sizeof(A))/sizeof(A[0]);}
template <typename T>inline int len(vector<T> v){return v.size();}
template <typename T>inline int len(set<T> v){return v.size();}
template <typename T,typename S>inline int len(map<T,S> v){return v.size();}

int fac[MX+5];
int power(int x, int y, int p)
{
    int res = 1;

    x = x % p;

    while (y)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}

int C(int n, int r, int p)
{
    if (r==0)
        return 1;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}

void init(int mod){
    fac[0] = 1;
    for (int i=1 ; i<=MX; i++)
        fac[i] = fac[i-1]*i%mod;
}

int CC(int a, int b){
    int res = 1;
    rep(i,a+1,a-b+1)res *= i,res/=a-i+1;
//    rep(i,1,b+1)res /= i;
    return res;
}

bool equal(double a, double b) {
    return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}

map<string, int> m;
string trim(string s){
    string res;
    for (int i = 0; i < s.size() && isalpha(s[i]); ++i) {
        res += tolower(s[i]);
    }
    return res;
}

int A[2043];
void _() {
    int n;
    int t,a;
    cin >> n >> t >> a;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
//    sort(A,A+n,[a,t](int a1, int a2){return abs(t-a1*.006-a) < abs(t-a2*.006-a);});
    cout << (max_element(A,A+n,[a,t](int a1, int a2){return abs(t-a1*.006-a) > abs(t-a2*.006-a);}) - A +1  );


};

#undef int
int main() {
#if __MINGW32__
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Input.txt", "r", stdin);
    freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Output.txt", "w", stdout);

#endif

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

}

Measured memory_bytes: 256
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	ll n,k;
	cin>>n>>k;
	cout<<(n-k+1);
	
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int  i, n, w, a, b;
	cin >> n >> w >> w;
	if (n > 1)
	{
		for (i = 0; i < n - 1; i++)
			scanf("%d",&a);
		cin >> b;
		n = (abs(b - w) < abs(a - b)) ? abs(a - b) : abs(b - w);
		cout << n;
	}
	else
	{
		cin >> a;
		cout << abs(a - w);
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
int n;
ll la,lb,a,b,x;
int main()
{
	scanf("%d",&n);
	scanf("%lld%lld",&a,&b);la=a,lb=b;
	for(int i=2;i<=n;++i)
	{
		scanf("%lld%lld",&a,&b);
		x=max((la+a-1)/a,(lb+b-1)/b);
		la=a*x,lb=b*x;
	}
	printf("%lld\n",la+lb);
	return 0;
} 

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())

    if H + W == 0:
        break

    for hi in range(H):
        if hi % 2 == 1:
            for wi in range(W):
                if wi % 2 == 1:
                    print("#", end="")
                else:
                    print(".", end="")
            print()
        else:
            for wi in range(W):
                if wi % 2 == 1:
                    print(".", end="")
                else:
                    print("#", end="")
            print()
    print()



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

int main() {
  int h,w; cin>>h>>w;
  char masu[h][w];
  int cnt=0;
  rep(i, h){
    rep(j, w){
      cin>>masu[i][j];
      if(masu[i][j]=='#')
        cnt++;
    }
  }
  bool imp=false;
    rep(i, h){
    rep(j, w){
      if(masu[i][j]=='#'){
        if(i!=h-1&&j!=w-1){
          if(masu[i+1][j]=='.'&&masu[i][j+1]=='.'){
            imp=true;}
        }
        else if(i==h-1&&j!=w-1){
          if(masu[i][j+1]=='.'){
            imp=true;}
        }
        else if(i!=h-1&&j==w-1){
          if(masu[i+1][j]=='.'){
            imp=true;}
        }  
      }
    }
  }
     if(imp==true||cnt!=h+w-1)
       cout<<"Impossible"<<endl;
      else
        cout<<"Possible"<<endl;
      

}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    vector<ll> A(N);
    vector<ll> B(M);

    REP(i, N){
        cin >> A[i];
    }
    REP(i, M){
        cin >> B[i];
    }

    vector<ll> C = convolution<998244353>(A, B);

    REP(i, N+M-1){
        if(i == N+M-2){
            cout << C[i] << endl;
        }
        else{
            cout << C[i] << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 27212
# include<iostream>
# include<cstring>
# include<cstdlib>
# include<cstdio>
# include<algorithm>
# define tl (k<<1)
# define tr (k<<1|1)
# define mid (l+r>>1)
# define LL long long
using namespace std;
const int MAX=2e5+5;
const LL inf=1e14;
struct p{
	LL x,xup,xdn,tags;
	p(LL X=0,LL XU=0,LL XD=0,LL TAG=0) {x=X,xup=XU,xdn=XD,tags=TAG;}
}s[MAX<<2];
int n,Q,A,B;
int X[MAX];
int read()
{
	int x(0);
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar());
	for(;isdigit(ch);x=x*10+ch-48,ch=getchar());
	return x;
}
p min(p a,p b) {return p(min(a.x,b.x),min(a.xup,b.xup),min(a.xdn,b.xdn));}
void pus(int k) {s[k]=min(s[tl],s[tr]);}
void Add(int k,LL d) {s[k].tags+=d,s[k].x+=d,s[k].xup+=d,s[k].xdn+=d;}
void down(int k) {if(s[k].tags) Add(tl,s[k].tags),Add(tr,s[k].tags),s[k].tags=0;}
void change(int l,int r,int k,int x,LL d)
{
	if(l==r) {d=min(d,inf),s[k].x=d,s[k].xup=d+l,s[k].xdn=d-l;return;}
	down(k);
	if(x<=mid) change(l,mid,tl,x,d);
	else change(mid+1,r,tr,x,d);
	pus(k);
}
void change(int l,int r,int k,int L,int R,int d)
{
	if(r<L||R<l) return;
	if(l>=L&&r<=R) return void(Add(k,d));
	down(k),change(l,mid,tl,L,R,d),change(mid+1,r,tr,L,R,d),pus(k);
}
LL ask(int l,int r,int k,int L,int R)
{
	if(r<L||R<l) return inf;
	if(l>=L&&r<=R) return s[k].x;
	return down(k),min(ask(l,mid,tl,L,R),ask(mid+1,r,tr,L,R));
}
LL ask_up(int l,int r,int k,int L,int R)
{
	if(r<L||R<l) return inf;
	if(l>=L&&r<=R) return s[k].xup;
	return down(k),min(ask_up(l,mid,tl,L,R),ask_up(mid+1,r,tr,L,R));
}
LL ask_down(int l,int r,int k,int L,int R)
{
	if(r<L||R<l) return inf;
	if(l>=L&&r<=R) return s[k].xdn;
	return down(k),min(ask_down(l,mid,tl,L,R),ask_down(mid+1,r,tr,L,R));
}
void build(int l=1,int r=n,int k=1)
{
	s[k]=p(inf,inf,inf);
	if(l==r) return;
	build(l,mid,tl),build(mid+1,r,tr);
}
int main()
{
	n=read(),Q=read(),A=read(),B=read(),build();
	for(int i=1;i<=Q;++i)
	  {
	  	X[i]=read();
	  	if(i==1) change(1,n,1,A,abs(B-X[i])),change(1,n,1,B,abs(A-X[i]));
		else
		{
			LL Lv=ask_down(1,n,1,1,X[i])+X[i],Rv=ask_up(1,n,1,X[i]+1,n)-X[i],Xv=ask(1,n,1,X[i-1],X[i-1]);
			change(1,n,1,X[i-1],min(Xv+abs(X[i]-X[i-1]),min(Lv,Rv))),change(1,n,1,1,X[i-1]-1,abs(X[i]-X[i-1])),change(1,n,1,X[i-1]+1,n,abs(X[i]-X[i-1]));
		}
	  }
	LL ans=1e18;
	for(int i=1;i<=n;++i)
	  ans=min(ans,ask(1,n,1,i,i));
	return printf("%lld",ans),0;
}

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

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()


int main(){
    ll N,M;
    cin>>N>>M;
    if(N>M){
        N+=M;
        M=N-M;
        N-=M;
    }

    if(N==1&&M==1)cout<<1<<endl;
    else if(N==1&&M!=1)cout<<M-2<<endl;
    else cout<<(N-2)*(M-2)<<endl;
    //両端は二回、それ以外は三階なので、
    //紙で考える重要性


    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
def maxHeapify(i)
	l = 2 * i
	r = 2 * i + 1
	
	if l <= H && $a[l] > $a[i]
		largest = l
	else
		largest = i
	end
	largest = r if r <= H && $a[r] > $a[largest]

	if largest != i
		$a[i], $a[largest] = $a[largest], $a[i]
		maxHeapify(largest)
	end
end

H = gets.to_i
$a = gets.split.map &:to_i
$a.unshift(nil)

(H/2).downto(1) do |i|
	maxHeapify(i)
end

$a.shift
print " ", $a.join(" ")
puts

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

using namespace std;

int main(){
  long long n, k, h[100009], mn=1e9;
  cin >> n >> k;
  vector<long long> v;
  for(int i=0;i<n;i++){
    cin >> h[i];
    v.push_back(h[i]);
  }
  sort(v.begin(), v.end());
  for(int i=k;i<=n;i++){
    mn = min(mn, v[i-1] - v[i-k]);
  }
  cout << mn << endl;
}

Measured memory_bytes: 1912
import java.util.Scanner;

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

    long N = scanner.nextLong();
    long A = scanner.nextLong();
    long B = scanner.nextLong();

    long i = N / (A + B);
    long j = N % (A + B);
    System.out.println(i * A + Math.min(A, j));
  }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N;

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

    vector<int> ans;
    while (true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int cnt = 0;
        FOR(i, 1, n - 1) {
            FOR(j, i + 1, n) {
                int k = x - (i + j);
                if (j < k && k <= n) cnt++;
            }
        }
        ans.push_back(cnt);
    }

    for (auto i : ans) {
        cout << i << endl;
    }

    return 0;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define fi first
#define se second
using namespace std;
template <class T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y){x=x<y?x:y;return;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;

ll n,k;

int main()
{
	cin>>n>>k;
	n-=n/k*k;
	cout<<min(n,k-n)<<endl;
	return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;cin>>n>>m>>k;
    UnionFind sns(n+1);
    vector<P> fri(m);
    vector<int> ans(n+1); // 1~n
    rep(i, m){
        int a,b;cin>>a>>b;
        fri[i].first=a; fri[i].second=b;
        sns.merge(a,b);
    }
    for(int i=1;i<=n; i++){
        ans[i] = sns.size(i)-1; // 自分自身
    }
    // rep(i,n) cout<<ans[i+1]<<" ";
    // cout<<endl;
    for(auto a : fri){
        if(sns.issame(a.first, a.second)){
            --ans[a.first];
            --ans[a.second];
        }
    }
    rep(i, k){
        int c,d;cin>>c>>d;
        if(sns.issame(c,d)){
            ans[c]-=1;
            ans[d]-=1;
        }
    }
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define f(i, l, r) for (int i = l; i <= r; i++)
#define rf(i, r, l) for (int i = r; i >= l; i--)
#define all(x) (x).begin(), (x).end()
#define sf(a) scanf("%d",&a)
#define llsf(a) scanf("%lld", &a)
#define l l
#define r r
#define lch (o << 1)
#define rch (o << 1 | 1)
#define mid ((l + r) >> 1)
#define mem(x, y) memset(x, y, sizeof(x))

const int inf = 2e9 + 7;
const ll INF = INT64_MAX;
double eps = 1e-6;
int mod = 1e9 + 7;
const int N = 1e6 + 10;
const double pi = acos(-1.0);

ll a[N];
int n;
ll work(ll b) {
	ll res = 0;
	f(i, 1, n) {
		res += abs(a[i] - b);
	}
	return res;
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	sf(n);
	f(i, 1, n)cin>>a[i],a[i]-=i;
	ll l = -1e10, r = 1e10;
	int k = 70;
	ll res = INF;
	while (k--) {
		ll L = l + (r - l) / 3;
		ll R = r - (r - l) / 3;
		ll lres = work(L), rres = work(R);
		if (lres <= rres) r = R;
		else l = L;
		res = min(res, min(lres, rres));
	}
	cout << res;
}

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

const int N = 1e5 + 10;

int n , a , b , w[N];

bool check(int x){
	long long sum = 0;
	for(int i = 1; i <= n; i++)
		sum += ceil(1.0 * max(0ll , 1ll * w[i] - 1ll * x * b) / a);
	return sum <= x;
}

int Find(int L , int R){
	if(L == R) return L;
	int mid = (L + R) >> 1;
	if(check(mid)) return Find(L , mid);
	else return Find(mid + 1 , R);
} 

int main(){
	scanf("%d %d %d" , &n , &a , &b) , a -= b;
	for(int i = 1; i <= n; i++) scanf("%d" , &w[i]);
	printf("%d" , Find(0 , 1e9));
	return 0;
}

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

const int INF=0x3f3f3f3f;
int a[55];

int main(){
	int n,idx1,idx2;
	int MAX=-1,MIN=INF;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]<MIN) {MIN=a[i];idx1=i;}
		if(a[i]>MAX) {MAX=a[i];idx2=i;}
	}
	if(abs(MAX)>=abs(MIN)){
		cout<<2*n-1<<endl;
		for(int i=1;i<=n;i++){
			cout<<idx2<<" "<<i<<endl;
		}
		for(int i=1;i<n;i++){
			cout<<i<<" "<<i+1<<endl;
		}
	}
	else{
		cout<<2*n-1<<endl;
		for(int i=1;i<=n;i++){
			cout<<idx1<<" "<<i<<endl;
		}
		for(int i=n;i>1;i--){
			cout<<i<<" "<<i-1<<endl;
		}
	}
	return 0;
}


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

int e[101]={0};
int N;
//
int num(int n){
	int c = 0;
	for(int i=2;i<=N;i++){
		if(e[i]>=n-1)c++;
	}
	return c;
}

int main(void){
	int i,j,ans;
	scanf("%d",&N);
	for(i=2;i<=N;i++){
		int kazu = i;
		for(j=2;j<=i;j++){
			while(kazu%j==0){
				e[j]++;
				kazu /= j;
			}
		}
	}
	ans = num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)/2;
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 1700
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	for {
		c -= b
		if c <= 0 {
			fmt.Println("Yes")
			break
		}

		a -= d
		if a <= 0 {
			fmt.Println("No")
			break
		}
	}
}


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

using namespace std;

int main(){
	
  	int x1,ans;
  
  	for(int a=0;a<5;a++){
    	cin>>x1;
      
      	if(x1 == 0){ans=a+1;}
    }
  
  	cout<<ans<<endl;
}

Measured memory_bytes: 3632
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e6+10;
string str[N];	int n,res;
vector<pair<int,int> > v1,v2;
inline int ch(char c){if(c=='(') return 1; return -1;}
signed main(){
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>str[i];	int s=0,mi=1e9;
		for(int j=0;j<str[i].size();j++)	s+=ch(str[i][j]),mi=min(s,mi);
		if(mi>=0&&s>=0)	res+=s;
		else if(mi<0&&s>=0) v1.push_back({mi,s});
		else v2.push_back({mi,s});
	}
	sort(v1.begin(),v1.end(),[](pair<int,int> a,pair<int,int> b){
		return a.first>b.first;
	});
	for(auto i:v1){
		if(res+i.first<0)	return puts("No"),0;
		res+=i.second;
	}
	sort(v2.begin(),v2.end(),[](pair<int,int> a,pair<int,int> b){
		return a.first-a.second<b.first-b.second;
	});
	for(auto i:v2){
		if(res+i.first<0)	return puts("No"),0;
		res+=i.second;
	}
	puts(res==0?"Yes":"No");
	return 0;
}


Measured memory_bytes: 38820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF = (1LL<<60);
const int MOD = 1000000007;

int N,K;
vector<vector<int> > G(100010);
vector<ll> color(100010,0);   // v で使える色の種類数

void dfs(int p, int v){
    int k = color[v];

    if(k <= K-2) k = K-1;

    int cnt = 1;
    for(auto nv: G[v]){
        if(nv == p) continue;
        color[nv] = k-cnt;
        dfs(v, nv);
        cnt++;
    }
    return;
}

int main(){
    cin >> N >> K;
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    color[0] = K;
    dfs(-1, 0);

    ll res = 1;
    rep(i,N) {
        res *= color[i];
        res %= MOD;
    }
    res = max((ll)0,res);
    cout << res << endl;
}


Measured memory_bytes: 13912
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
int P[212345];
int idx[212345];
int cnt = 1;
int num = 1;
int ans = 0;

int main(){
	
	cin>>N;
	REP( i, N ){
		scanf("%d", P+i);
		P[i]--;
		idx[P[i]] = i;
	}
	
	
	FOR( i, 1, N ){
		if( idx[i] > idx[i-1] ) cnt++;
		else{
			cnt = 1;
		}
		num = max( num, cnt );
	}
	
	ans = N-num;
	
	cout<<ans<<endl;
	
	return 0;
}

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

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

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    string s, t;
    s = "CODEFESTIVAL2016";
    cin >> t;
    int a = 0;
    for (int i = 0; i < s.length(); i++) if (s[i] != t[i]) a++;
    cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	string S;
	cin >> a >> b >> S;

	rep(i, a + b + 1) {
		if (i == a) {
			if (S[i] != '-') {
				puts("No");
				return 0;
			}
		}
		else {
			if (!isdigit(S[i])) {
				puts("No");
				return 0;
			}
		}
	}

	puts("Yes");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int n; cin >> n;
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		if (i % 2 == 1) continue;
		if (a % 2 == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<iostream>

using namespace std;

int main(){
int N,K,A[200010],i,j,k,x=1,y=1;

cin >> N  >> K;
for(i=1;i<=N;i++){cin >> A[i];}


for(j=K;j<N;j++){
if(A[(j-(K-1))]<A[j+1]){cout << "Yes" <<endl;}else{cout << "No" <<endl;}
}
 cout << endl;




return 0;
}

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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
/* -------------------------------------------------------------------------- */
static void push(const int v, const int d, vi &dist, queue<int> &qu) {
    if (dist[v] != INF) return;
    dist[v] = d;
    qu.push(v);
}

int main(int argc, char *argv[])
{
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;Y--;

    vi ans(N, 0);
    queue<int> qu /* methods() = push, pop, front, back, size, empty(qu == empty?) */;

    rep(sv, N) {
        vi dist(N, INF);
        push(sv, 0, dist, qu);
        while (!qu.empty()) {
            int v = qu.front(); qu.pop();
            int d = dist[v];

            if (v+1 < N) push(v+1, d+1, dist, qu);
            if (v == X)  push(Y, d+1, dist, qu);
            if (v-1 >= 0) push(v-1, d+1, dist, qu);
            if (v == Y)  push(X, d+1, dist, qu);
        }

        rep(i, N) {
            ans[dist[i]]++;
        }
    }

    reb(i, 1, N) { cout << ans[i]/2 << endl; }

    return 0;
}


Measured memory_bytes: 256
//TO CHANGE THE WORLD
#include <bits/stdc++.h>

using namespace std;

#define L first
#define R second
#define mp make_pair
#define pb push_back
typedef long long ll;

const int maxn=1e5+10;
string st;
bool w,s,n,e;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>st;
    for(int i=0; i<st.size(); i++)
    {
	if(st[i]=='W') w++;
	if(st[i]=='S') s++;
	if(st[i]=='E') e++;
	if(st[i]=='N') n++;
    }
    if((s^n)||(w^e)) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 102

struct inf{
    char form;
    int num;
};

struct inf ori[N];

void bubblesort(struct inf *a,int n){
    struct inf tmp;
    int i,j,side;
    side = 0;
    for(i = 0; i < n-1;i++){
        for (j = n-1; j > side; j--) {
            if (a[j].num < a[j-1].num) {
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
            }
        }
        side++;
    }
}

void selectionsort(struct inf *b,int n){
    struct inf tmp;
    int i,j,minj;

    for (i = 0; i < n-1; i++) {
        minj = i;
        for (j = i; j < n; j++) {
            if (b[j].num < b[minj].num) {
                minj = j;
            }
        }
        tmp = b[i];
        b[i] = b[minj];
        b[minj] = tmp;
    }
}

int judge(struct inf *x,struct inf *y,int n){
    int i;

    for (i = 0; i < n; i++) {
        if(x[i].form != y[i].form){
            return 0;
        }
    }
    return 1;
}

void print(struct inf *x,struct inf *y, int n){
    int i,hantei;
    for (i = 0; i < n; i++) {
        if(i == 0){
            printf("%c%d",x[i].form,x[i].num);
        }else{
            printf(" %c%d",x[i].form,x[i].num);
        }
    }
    printf("\nStable\n");

    for (i = 0; i < n; i++) {
        if(i == 0){
            printf("%c%d",y[i].form,y[i].num);
        }else{
            printf(" %c%d",y[i].form,y[i].num);
        }
    }
    hantei = judge(x,y,n);
    if(hantei == 1){
        printf("\nStable\n");
    }else{
        printf("\nNot stable\n");
    }

}

int main(int argc, char const *argv[]) {
    struct inf a[N],b[N];
    int n,i;

    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf(" %c%d",&ori[i].form,&ori[i].num);
        a[i] = b[i] = ori[i];
    }
    bubblesort(a,n);
    selectionsort(b,n);
    print(a,b,n);


    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)
typedef long long ll;

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

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
#define el '\n'
typedef long long ll;
const int MAXN = 2e5+2;
int N, A[MAXN];
ll odd[MAXN], dp[MAXN];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N;
	for(int i = 1;i<=N;i++) cin >> A[i];
	odd[1] = A[1];
	for(int i = 2;i<=N;i++){
		if(i%2){
			odd[i] = odd[i-2]+A[i];
		}
	}
	dp[1] = 0;
	for(int i = 2;i<=N;i++){
		if(i%2){
			dp[i] = max(dp[i-2]+A[i], dp[i-1]);
		}else{
			dp[i] = max(dp[i-2]+A[i], odd[i-1]);
		}
	}
	cout << dp[N] << el;
}

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

int main(){
	int n,m;
	cin>>n>>m;
	priority_queue<int> a;
	int temp;
	for (int i = 0; i < n; i++) {
		cin>>temp;
		a.push(temp);
	}
	while (m>0) {
		temp=a.top();
		a.pop();
		a.push(temp/2);
		m--;
	}
	long long int ans=0;
	while (a.size()>0) {
		ans+=a.top();
		a.pop();
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<" ";
	int t=a+b-n;
	if(t<=0)
			cout<<"0";
		
	else
		cout<<t;
	return 0;
}

Measured memory_bytes: 256
//没用return的代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,m,q,a[50],b[50],c[50],d[50],ans;
int p[10];

void dfs(int len,int pre){
    if(len==n){
        int sum=0;
        for(int i=0;i<q;i++) if(p[b[i]-1]-p[a[i]-1]==c[i]) sum+=d[i];
        ans=max(ans,sum);
        return;
    }
    else{
        for(int i=pre;i<=m;i++){
            p[len]=i;
            dfs(len+1,i);
        }
    }
}

main()
{
    cin>>n>>m>>q;
    for(int i=0;i<q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(0,1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3588
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)[0..n]
n.times do |i|
  v = a[i]
  j = i-1
  while j >= 0 && a[j] > v
    a[j+1] = a[j]
    j-=1
  end
  a[j+1] = v
  puts a.join(' ')
end

Measured memory_bytes: 8760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const vector<int> dy = {1, -1, 0, 0};
const vector<int> dx = {0, 0, 1, -1};

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

    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    for (auto &S : A) cin >> S;

    for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
            if (A.at(y).at(x) == '.') continue;
            bool can = false;
            for (int i = 0; i < 4; ++i) {
                int ny = y + dy.at(i);
                int nx = x + dx.at(i);
                if (ny < 0 || H <= ny) continue;
                if (nx < 0 || W <= nx) continue;
                if (A.at(ny).at(nx) == '#') can = true;
            }
            if (!can) {
                cout << "No" << endl;
                exit(0);
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

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

int n;
vector<int> a, b, c;
int dp[3][100005];

signed main()
{
    cin >> n;
    a = b = c = vector<int>(n);
    rep(i, n)
    {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = dp[1][0] = dp[2][0] = 0;

    rep1(i, n + 1)
    {
        chmax(dp[0][i], max(dp[1][i - 1] + a[i - 1], dp[2][i - 1] + a[i - 1]));
        chmax(dp[1][i], max(dp[0][i - 1] + b[i - 1], dp[2][i - 1] + b[i - 1]));
        chmax(dp[2][i], max(dp[1][i - 1] + c[i - 1], dp[0][i - 1] + c[i - 1]));
    }

    print(max(dp[0][n], max(dp[1][n], dp[2][n])));
}


Measured memory_bytes: 4992
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long Gcd(long x,long y)
        {
            if (x < y) Gcd(y, x);
            while (y > 0)
            {
                var z = x;
                x = y;
                y = z % y;
            }
            return x;
        }

        public static long Lcm(long x,long y)
        {
            return x * y / Lcm(x, y);
        }


        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var q = Reads();
            var n = q[0];
            var s = q[1];
            var x = Reads();
            long ans = 0;
            if (n > 1)
            {
                ans = Gcd(Math.Abs(s - x[0]), Math.Abs(s - x[1]));

                for (int i = 2; i < n; i++)
                {
                    ans = Gcd(ans, Math.Abs(s - x[i]));
                }
            }
            else ans = Math.Abs(s - x[0]);
            WriteLine(ans);
            

            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 29304
import java.util.Scanner;

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

		int ans = Math.min(N*A, B);
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	ans := 0
	for i := 1; i <= N; i++ {
		if i%2 == 0 {
			continue
		}
		c := 0
		for j := 1; j <= i; j++ {
			if i%j == 0 {
				c++
			}
		}
		if c == 8 {
			ans++
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844