akhauriyash/Code-Regression huggingface dataset:
n=int(input())
b=list(map(int,input().split()))
s_b=sorted(list(set(b)),reverse=True)
if 1 not in s_b:
  print(-1)
  exit()
ans=[]
for itr in range(n):
  for j in s_b:
    if len(b)>=j:
      if b[j-1]==j:
        b.pop(j-1)
        ans.append(j)
        break
    if j==1:
      print(-1)
      exit()
ans.reverse()
for i in range(n):
  print(ans[i])


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    abc071a()
}

fun abc071a() {
    val (x, a, b) = readLine()!!.split(" ").map { it.toInt() }

    val answer = if (Math.abs(x - a) < Math.abs(x - b)) "A" else "B"

    println(answer)
}


Measured memory_bytes: 37928
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  string S;
  cin >> S;
  while(1){
    if(S == "erase" || S == "dream" || S=="dreamer" || S == "eraser"){
      cout << "YES" << endl;
      return 0;
    }
  
    if(S.substr(S.size()-5,5) == "dream"){
      S = S.substr(0,S.size()-5);
      continue;
    }
    if(S.substr(S.size()-7,7) == "dreamer"){
      S = S.substr(0,S.size()-7);
      continue;
    }
    if(S.substr(S.size()-5,5) == "erase"){
      S = S.substr(0,S.size()-5);
      continue;
    }
    if(S.substr(S.size()-6,6) == "eraser"){
      S = S.substr(0,S.size()-6);
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }
  
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        int inputCount = int.Parse(Reader.ReadLine());
        string inpt = Reader.ReadLine();

        int cnt = 0;
        int addLeftKakko = 0;
        for (int i = 0; i < inpt.Length; i++) {
            if(inpt[i] == '(') {
                cnt++;
            } else {
                cnt--;
            }
            if(cnt < 0) {
                addLeftKakko++;
                cnt++;
            }
        }
        string ans = string.Empty.PadLeft(addLeftKakko, '(') + inpt + string.Empty.PadLeft(cnt, ')');
        Console.WriteLine(ans);

    }

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


6
)))())



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long K, std::vector<long long> A){
  vector<ll> AA(N+1);
  REP(N){
    AA[i+1]=(AA[i]+A[i]+K-1)%K;
  }
  dump(AA);
  map<ll,ll> cnt;
  ll ans=0;
  REP(N+1){
    if(cnt.count(AA[i])){
      ++cnt[AA[i]];
    }else{
      cnt[AA[i]]=1;
    }
    if(i>=K-1){
      ll tmp=AA[i-(K-1)];
      --cnt[tmp];
      if(cnt[tmp]==0){
        cnt.erase(tmp);
      }else{
        ans+=cnt[tmp];
      }
    }
  }
  for (auto &&i : cnt)
  {
    ll tmp=i.second;
    ans+=tmp*(tmp-1)/2;
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=50,Mo=1000000007;
int f[N][1<<17],d[N];
int main() {
    int n,X,Y,Z,c,ans=0;
    cin>>n>>X>>Y>>Z;
    f[0][1]=d[0]=1,c=1<<X+Y+Z;
    for(int i=1;i<=n;i++) d[i]=10LL*d[i-1]%Mo;
    for(int i=0;i<n;i++)
	for(int j=0;j<c;j++)
	    if(f[i][j]) {
		for(int k=1;k<=10;k++) {
		    int s=j<<k|1;
		    if(s>>Z&1 && s>>Y+Z&1 && s>>X+Y+Z&1)
			ans=(ans+1LL*f[i][j]*d[n-i-1])%Mo;
		    else
			s&=c-1,f[i+1][s]=(f[i+1][s]+f[i][j])%Mo;
		}
	    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 20992
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n, m;
	cin >> n >> m;
	int ans = 0;
	if(n>=2){
		ans += n*(n-1);
		ans/=2;
	}
	if(m>=2){
		ans+=((m*(m-1))/2);
		
	}
	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	string s;cin>>s;
	int cnt = 0;
	rep(i,0,3) if(s[i]=='o') cnt++;
	cout<<700 + 100 * cnt<<endl;
}

Measured memory_bytes: 256
n = int(input())

A = []
if n == 0:
    print(0)
else:
    while(n != 1):
        if n % (-2) == -1:
            t = n // (-2) + 1
            n =  t
            A.append('1')
        else:
            A.append('0')
            t = n // (-2)
            n = t
    A.append(str(n))
    A = A[::-1]
    print("".join(A))

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  int n = s.size();
  if(s == "keyence") {
    cout << "YES" << endl;
    return 0;
  }
  for(int l = 0; l < n; l++) {
    for(int r = l + 1; r <= n; r++) {
      string t = "";
      for(int i = 0; i < l; i++) t += s[i];
      for(int i = r; i < n; i++) t += s[i];
      if("keyence" == t) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int  n;
int res[505][505];
void dfs(int start,int to,int index){
	if(to-start+1<=1) return;
	for(int i=start;i<to;i++)
		for(int j=i+1;j<=to;j++) {res[i][j]=index;
		}
	int mid=(start+to)>>1;
	dfs(start,mid,index+1),dfs(mid+1,to,index+1);
}
int main(){
	cin>>n;
	dfs(1,n,1);
 
	for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
	cout<<res[i][j]<<" "<<endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans,x,m;
map<ll,ll> a;
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		scanf("%lld",&m);
		x+=m;
		ans+=a[x];
		if(x==0)ans++;
		a[x]++;
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 12800
import random

def solve(d,c,s):
    A=[]
    cnt=0
    while cnt<=1000:
        last=[0]*27
        srate=[]
        ans=[]
        for i in range(1,d+1):
            a=0
            for j in range(1,27):
                a-=c[j-1]*(i-last[j])
            t=random.randint(1,26)
            a+=s[i-1][t-1]+c[t-1]*(i-last[t])
            last[t]=i           
            ans.append(t)
            srate.append(a)
        A.append([srate[-1]]+ans)
        cnt+=1
    A.sort(reverse=True)
    return A[0]

def main():
    d=int(input())
    c=list(map(int,input().split()))
    s=[list(map(int,input().split())) for _ in range(d)]
    ans=solve(d,c,s)
    #print(ans[0])
    for i in ans[1:]:
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12708
num_obs, num_roads = list(map(int, input().split()))


class Obs:
    def __init__(self, elevation, idd):
        self.elevation = elevation
        self.roads_connecting = []
        self.id = idd

    def __repr__(self):
        return "ID:"+str(self.id)+" E:"+str(self.elevation)+"m"


heights = input().split()

observatories = []
i = 1
for h in heights:
    observatories.append(Obs(int(h), i))
    i += 1

for j in range(num_roads):
    road = list(map(int, input().split()))
    observatories[road[0]-1].roads_connecting.append(observatories[road[1]-1])
    observatories[road[1]-1].roads_connecting.append(observatories[road[0]-1])

good_boys = 0

for o in observatories:
    is_good = True
    if len(set(o.roads_connecting)) == 0:
        good_boys += 1
        continue
    for subo in set(o.roads_connecting):
        if subo.elevation >= o.elevation and subo.id != o.id:
            is_good = False
            break
    if is_good:
        good_boys += 1

print(good_boys)


Measured memory_bytes: 51104
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

typedef long long ll;
#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

int main(){
	int R, G;
	cin >> R >> G;
	
	cout << 2 * G - R << endl;
}


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

int main() {
  int H,N;
    cin >> H >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++)
    cin >> A.at(i);
  
  for(int i=0; i<N; i++)
    H-=A.at(i);
  
  if(H>0)
    cout << "No" << endl;
  
  else
    cout << "Yes" << endl;
}
    

Measured memory_bytes: 640
while True:
    a, op, b = input().split()
    if op == "?":
        break
    a = int(a)
    b = int(b)
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)



Measured memory_bytes: 5592
import fractions
import bisect
import math
import copy


N=int(input())
A=list(map(int,input().split()))
B=copy.copy(A)
A.sort(reverse=True)
B.sort()
total=0

for i in range(N):
    for j in range(i+1,N-1):
        x=bisect.bisect_right(B, A[i]-A[j])

        if N-j>x:
            total+=N-x-(j+1)
        #print(total,x,j)

print(total)

Measured memory_bytes: 68824
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;


int main() {
	int n;
	double d;
	cin >> n >> d;
	int sol = 0;
	for (int i = 0; i < n; ++i) {
		ll x, y;
		cin >> x >> y;
		if (sqrt(x * x + y * y) <= d) ++sol;
	}

	cout << sol << '\n';
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
 
vi g[N];
int a[N];
int b[N];
int n;
map<pl, int> dp;
int go(ll x, ll y){
	if(abs(x-y)<=1) return -1;
	return 1;
	if(x<=1 and y <=1 ) return -1;	
	int lose = 1;
	ll i = 1;
	int &ans = dp[{x,y}];
	if(ans!=0) return ans; 
	while(2*i<=x){
		int res = go(x-2*i, y+i);
		if(res==-1){
			return ans = 1;
		}
		i++;
	}
	i = 1;
	while(2*i<=y){
		int res = go(y-2*i, x+i);
		if(res==-1){
			return ans = 1;
		}
		i++;
	}
	return ans = -1;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,k,j;
	ll x , y;
	cin >> x >> y;
	int win = go(x, y);
	if(win==1) cout << "Alice\n";
	else cout << "Brown\n";
	
	return 0;
} 

Measured memory_bytes: 7552
#include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<vector>
    #include<map>
    #include<set>
    using namespace std;
    int n;
    void rec(string s, int a, int u)
    {
        if(u==n+1)
        {
            cout<<s<<endl;
            return;
        }
        for(int i=1;i<=a;i++)
        {
            char c = 'a' + i - 1;
            bool in_string=false;
            for(int j=0;j<s.size();j++)
            {
                if(s[j] == c)
                {
                    in_string=true;
                    break;
                }
            }
            if(in_string)
                rec(s+c, a, u + 1);
            else
                rec(s+c, a+1, u + 1);
            
        }
    }
    int main()
    {
        cin>>n;
        rec("", 1, 1);
        return 0;
    }

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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 int INF = 100000; 

void print(int w){
    for(int i = 1; i <= w + 2; i++){
        cout << "#";
    }
    cout << endl;
}

int main(){
    int h, w;
    cin >> h >> w;

    vector<string> a(h);
    for(int i = 0; i < h; i++) cin >> a[i];

    print(w);
    for(int i = 0; i < h; i++){
        cout << "#" << a[i] << "#" << endl;
    }
    print(w);

    return 0;
}


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

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

constexpr int INF = 1e7;

int main() {
    int N; cin >> N;
    vector<vector<int>> graph(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        for (int j = 0; j < N; j++) {
            if (s[j] == '1') graph[i][j] = 1;
            else graph[i][j] = INF;
        }
    }
    vector<bool> added(N, false);
    vector<int> color(N, 0);
    queue<Pii> q; q.push(Pii(0, 1)); added[0] = true;
    while (!q.empty()) {
        Pii x = q.front(); q.pop();
        for (int i = 0; i < N; i++) {
            if (graph[x.first][i] == 1) {
                if (color[i] == x.second) {
                    cout << -1 << endl;
                    return 0;
                } else {
                    color[i] = x.second * -1;
                    if (!added[i]) {
                        q.push(Pii(i, x.second * -1));
                        added[i] = true;
                    }
                }
            }
        }
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i != j) ans = max(ans, graph[i][j]);
        }
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 384
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  COMinit();
  ll n,k,ans=0;cin>>n>>k;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  sort(ALL(v));
  rep(i,n-1){
    ll tmp=(COM(n,k)-COM(i+1,k)-COM(n-i-1,k));
    tmp%=MOD;
    ans+=tmp*(v[i+1]-v[i]);
    ans%=MOD;
  }
  while(ans<0) ans+=MOD;
  cout<<ans<<endl;
  
}

Measured memory_bytes: 13056
#!/usr/bin/env python3
from itertools import takewhile
from math import sqrt


def is_prime(primes, i):
    if i in primes:
        return True
    for p in takewhile(lambda x: x * x <= i, sorted(primes)):
        if i % p == 0:
            return False
    return True


def sieve_of_eratosthenes(max):
    is_prime = [True] * (max + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(sqrt(max)) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * i, max + 1, i):
            is_prime[j] = False
    return filter(lambda x: is_prime[x], range(max + 1))

primes = set(sieve_of_eratosthenes(10000))

n = int(input())
c = 0
for _ in range(n):
    i = int(input())
    if is_prime(primes, i):
        c += 1
print(c)

Measured memory_bytes: 6892
N, K = map(int, input().split())
A = list(map(int, input().split()))

i = 1
while i <= K:
  i *= 2

x = 0
while i != 0:
  if sum([1 for a in A if a&i==0]) > N/2:
    if x+i <= K:
      x += i
  i //= 2;

print(sum([a^x for a in A]))

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



int main (void){
    double n, k;
    cin >> n >> k;

    double sum = 1/n;

    double ans = 0;

    int bai;
    for (int i = 1; i <= n;i++){
        if(i>=k){
            sum = 1/n;
            
            ans += sum;
            continue;
        }

        bai = i;
        while(1){
            bai *= 2;
            sum *= 0.5;
            if(bai>=k){
                ans += sum;
                sum = 1 / n;
                break;
            }
        }


    }
    cout << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=n; i<N; i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;

int main() {
	int R0,W0,C,R;
	while(cin >> R0 >> W0 >> C >> R && R0 != 0){
		int x=0;
		while(1){
			if(((R0+x*R)/W0) >= C)break;
			x++;
		}
		p(x);
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

ll A[200100];
ll DP[200100][10];

int main(){
    ll N;
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }

    REP(i,N){
        REP(j,5){
            DP[i][j] = -1e18;
        }
    }

    DP[0][0] = A[0];
    DP[1][1] = A[1];
    DP[2][2] = A[2];
    REP(i,N){
        //ll a = A[i];
        REP(j,3){
            chmax(DP[i+2][j], DP[i][j] + A[i+2]);
            chmax(DP[i+3][j+1], DP[i][j] + A[i+3]);
            chmax(DP[i+4][j+2], DP[i][j] + A[i+4]);
        }
    }

    ll num = N - (2*(N/2) - 1);
    ll ans = LLONG_MIN;
    for(int k = 0; k <= num; k++)
        //chmax(ans, DP[N-1][k]);
        chmax(ans, DP[N-1-k][num-k]);

    //ll num = 1 + N%2;
    //for(int d = 0; d <= num; d++){
    //    int i = N-1-d;
    //    chmax(ans, DP[i][num-d]);
    //}

    //REP(i,N){
    //    REP(j,3){
    //        if(DP[i][j] < 0)
    //            printf("x ");
    //        else
    //            printf("%lld ", DP[i][j]);
    //    }
    //    printf("\n");
    //}

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20816
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one

    // 1^2^3...^nの値を求める
    ll F(ll n) {
        switch (n & 3) {
        case 0: return n;
        case 1: return 1;
        case 2: return n + 1;
        case 3: return 0;
        }

        // 考え方
        // 任意の自然数aが偶数の時 a ^ (a + 1) = 1 となる

        // 以下の処理と同じ

        //if (n % 2 == 1) {
        //    if ((n + 1) / 2 % 2 == 0) return 0;
        //    else return 1;
        //}
        //else {
        //    if (n / 2 % 2 == 0) return n;
        //    else return n ^ 1;
        //}
    }
}

int main() {

    ll a, b;
    cin >> a >> b;

    Cout(F(a - 1) ^ F(b));

    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ABCD[4];
  for (int i=0; i<4; i++) {
    ABCD[i]=(s[i]-'0');
  }
  for (int x=0; x<8; x++) {
    int sum=ABCD[0];
    string s;
    s+=(char)(ABCD[0]+'0');
    for (int i=0; i<3; i++) {
      if (x&(1<<i)) {
        sum+=ABCD[i+1];
        s+='+';
        s+=(char)(ABCD[i+1]+'0');
      } else {
        sum-=ABCD[i+1];
        s+='-';
        s+=(char)(ABCD[i+1]+'0');
      }
    }
    if (sum==7) {
      cout << s << "=" << sum << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,D,A,B=0,cnt=0;
    cin>>N>>D>>A;
    vector<pair<ll,ll>> p(N);
    queue<pair<ll,ll>> q;
    pair<ll,ll> y;
    for(ll i=0;i<N;i++){
        cin>>p[i].first>>p[i].second;
    }
    sort(p.begin(),p.end());
    for(ll i=0;i<N;i++){
        while(q.size()){
            pair<ll,ll> d;
            d=q.front();
            if(d.first>=p[i].first) break;
            if(d.first<p[i].first){
                q.pop();
                B-=d.second*A;
            }
        }
        p[i].second-=B;
        //cout<<i<<" "<<p[i].second<<endl;
        if(p[i].second<=0) continue;
        ll b=p[i].second/A;
        if(p[i].second%A!=0) b++;
        q.push(pair<ll,ll>(p[i].first+2*D,b));
        B+=b*A;
        cnt+=b;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 4992
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
		ll N, K;
		cin >> N >> K;

		if (K % 2 == 0) {
				ll a = N / K;
				ll b = (N + (K/2)) / K;
				cout << a*a*a + b*b*b << endl;
		} else {
				ll a = N / K;
				cout << a*a*a << endl;
		}
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
   ll x;
   mint(ll x = 0) { (this->x = (x + MOD)) %= MOD; }
   mint& operator+=(const mint a) {
      if ((this->x += a.x) >= MOD) x -= MOD;
      return *this;
   }
   mint& operator-=(const mint a) {
      if ((this->x += MOD - a.x) >= MOD) this->x -= MOD;
      return *this;
   }
   mint& operator*=(const mint a) {
      (this->x *= a.x) %= MOD;
      return *this;
   }
   mint operator+(const mint a) const {
      mint res(*this);
      return res += a;
   }
   mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
   }
   mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
   }
   mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
   }
   mint inv() const { return pow(MOD - 2); }
   mint& operator/=(const mint a) { return *this *= a.inv(); }
   mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
   }
};
struct combination {
   vector<mint> fact, ifact;
   combination(int n) : fact(n + 1), ifact(n + 1) {
      assert(n < MOD);
      fact[0] = 1;
      for (int i = 1; i <= n; ++i)
         fact[i] = fact[i - 1] * i;
      ifact[n] = fact[n].inv();
      for (int i = n; i >= 1; --i)
         ifact[i - 1] = ifact[i] * i;
   }
   mint operator()(int n, int k) {
      if (k < 0 || k > n) return 0;
      return fact[n] * ifact[k] * ifact[n - k];
   }
} comb(100005);

mint f(int n, int k) {
   if (n < 0) return 0;
   mint res = comb(n, k);
   res *= comb.fact[k];
   return res;
}
int k;
mint ans;
vector<int> to[100005];
void dfs(int v, int p = -1) {
   for (int u : to[v]) {
      if (u == p) continue;
      dfs(u, v);
   }
   int nk = (p == -1) ? k : k - 2;
   int c = (p == -1) ? to[v].size() + 1 : to[v].size() - 1;
   ans *= f(nk, c);
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n >> k;
   rep(i, 0, n - 1) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      to[a].push_back(b);
      to[b].push_back(a);
   }
   ans = 1;
   dfs(0);
   cout << ans.x << endl;
   return 0;
}

Measured memory_bytes: 10880
n,k = gets.chomp.split().map(&:to_i)
h = []
n.times do
  h.push gets.chomp.to_i
end

h.sort!

ans = Float::INFINITY

(n-k+1).times do |i|
  ans = [ans, h[i+k-1] - h[i]].min
end

puts ans

Measured memory_bytes: 3704
from bisect import bisect_left

n = int(input())
*a, = sorted(map(int, input().split()))
*b, = sorted(map(int, input().split()))
*c, = sorted(map(int, input().split()))

ret = 0
for mid in b:
    ret += bisect_left(a, mid) * (n - bisect_left(c, mid + 1))
print(ret)


Measured memory_bytes: 23504
# ビット演算
n,m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]

def S(case):
    return sum( sorted([x*case[0]+y*case[1]+z*case[2] for x, y, z in xyz], reverse=True)[:m] )

from itertools import product
ans = 0
for case in product([-1,1], repeat=3):
    ans = max(ans, S(case))
print(ans)


Measured memory_bytes: 3296
#include<stdio.h>
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return i*2;}
int right(int i){return i*2+1;}

int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);

  for(i=1;i<=H;i++)scanf("%d",&A[i]);

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 608
import java.util.*;

public class Main {

    private static class AB {
        int A;
        int B;
        AB(int A, int B) {
            this.A = A;
            this.B = B;
        }
    }

    private static int N;
    private static AB[] AB;

    public static void main(String[] args) {
        load();
        solve();
    }

    private static void load() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        AB = new AB[N];
        for (int i = 0; i < N; i += 1) {
            AB[i] = new AB(Integer.parseInt(sc.next()), Integer.parseInt(sc.next()));
        }
    }

    private static void solve() {
        Arrays.sort(AB, new Comparator<Main.AB>() {
            @Override
            public int compare(Main.AB o1, Main.AB o2) {
                return Integer.compare(o1.B, o2.B);
            }
        });

        int time = 0;
        for (AB ab : AB) {
            time += ab.A;
            if (time > ab.B) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

}


Measured memory_bytes: 71176
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;

struct edge{int to,cost;};


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

	int n,m;
	cin >> n >> m;
	
	int a,b;
	set<int> from1,toN;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		if(a == 1 && b == n){
			cout << "POSSIBLE\n";
			return 0;
		}
		else if(a == 1){
			if(toN.find(b) == toN.end()){
				from1.insert(b);
			}else{
				cout << "POSSIBLE\n";
				return 0;
			}
		}
		else if(b == n){ 
			if(from1.find(a) == from1.end()){
				toN.insert(a);
			}else{
				cout << "POSSIBLE\n";
				return 0;
			}
		}
	}
	for(auto i=from1.begin();i!=from1.end();i++){
		if(toN.find(*i) != toN.end()){
			cout << "POSSIBLE\n";
			return 0;
		}
	}
	cout << "IMPOSSIBLE\n";
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string t = "CF$";
	int j = 0;
	for(char c : s){
		if(c == t[j]) j ++;
	}
	cout << (j == 2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7
fact = [1]
for i in range(1, H + W + 1):
    fact.append((fact[-1] * i) % MOD)

u = {}
for i in range(B, W):
    t = fact[i + H - A - 1] * pow(fact[i] * fact[H - A - 1], MOD - 2, MOD)
    u[i + 1] = t % MOD

ans = 0
for k, v in u.items():
    t = fact[W - k + A - 1] * pow(fact[W - k] * fact[A - 1], MOD - 2, MOD) % MOD
    ans = (ans + t * v) % MOD

print(ans)

Measured memory_bytes: 25724
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
const int INF = 1e9;
typedef long long ll;
using namespace std;
int main() {
    string SS;
    string T;
    cin >> SS;
    cin >> T;
    bool sub_string = false;
    int sub_index = 0;
    int start = 0;
    if(SS.length() < T.length()) sub_string = false;
    while(start+T.length() <= SS.length()) {
        bool flag = true;
        string sub = SS.substr(start, T.length());
        REP(i, sub.length()) {
            if(sub[i] == T[i] || sub[i] == '?') continue;
            else {
                flag = false;
                break;
            }
        }
        if(flag) {
            sub_index = start;
            sub_string = true;
        }
        start++;
    }
    if(!sub_string) cout << "UNRESTORABLE" << endl;
    else {
        int cnt = 0;
        FOR(i, sub_index, sub_index+T.length()) {
            SS[i] = T[cnt];
            cnt++;
        }
        REP(i, SS.length()) {
            if(SS[i] == '?') SS[i] = 'a';
        }
        cout << SS << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

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

  vt<std::pair<bool,bool>> ans(2);
  rep(i,s.size()) {
      if(s[i] == 'N')
        ans[0].first = true;
      else if(s[i] == 'W')
        ans[1].second = true;
      else if(s[i] == 'S')
        ans[0].second = true;
      else
        ans[1].first = true;
  }

  if(ans[0].first == ans[0].second && ans[1].first == ans[1].second)
    std::cout << "Yes" << '\n';
  else
    std::cout << "No" << '\n';
  return 0;
}


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

ll MOD = 1000000007;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res % mod;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll ncr2(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;

    ll res=1;
    k=min(k,n-k);
    for(ll i=0;i<k;i++){
        res = res * (n-i) % MOD;
    }
    for(ll i=k;i>=1;i--){
        res = res * modinv(i, MOD) % MOD;
    }
    return res;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  ll n,a,b;cin>>n>>a>>b;

  ll ans = (MOD + modpow(2, n, MOD) - 1 - ncr2(n, a)) % MOD;
  ans = (MOD + ans - ncr2(n, b))%MOD;
  cout<<ans%MOD<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,j,n) for(int i = (int)(j); i < (int)(n); i++)
#define mrep(i,n) for (int i = (int)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll modn = 998244353;

int main() {
	int x,y; cin >> x >> y;
	if(x%y==0) {
		cout << -1 << endl;
		return 0;
	}
	for(ll i=x;i<=1e18;i++) {
		if(i%y!=0) {
			cout << i << endl;
			return 0;
		}
      	i+=x;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s[0]=='S')
        cout<<"Cloudy"<<endl;
    else if(s[0]=='C')
        cout<<"Rainy"<<endl;
    else
        cout<<"Sunny"<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int start, end, sum = 0;
  
  rep(i, N) {
    cin >> start >> end;
    sum += end - start + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;
  char c2i[256];
  c2i[(int)'M'] = 0;
  c2i[(int)'A'] = 1;
  c2i[(int)'R'] = 2;
  c2i[(int)'C'] = 3;
  c2i[(int)'H'] = 4;
  vector<ull> xs(5, 0);

  for (auto i = 0; i < N; i++) {
    string s;
    cin >> s;
    char c = s[0];
    if (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H') {
      xs[c2i[c]]++;
    }
  }
  ull res = 0;
  for (auto i = 0; i < 5; i++) {
    for (auto j = i + 1; j < 5; j++) {
      for (auto k = j + 1; k < 5; k++) {
        res += xs[i] * xs[j] * xs[k];
      }
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P.at(i);
    rep(i, N) cin >> Q.at(i);
    vector<int> order(N);
    rep(i, N) order.at(i) = i + 1;
    int a = 0, b = 0, count = 0;
    do{
        bool flagP = true;
        bool flagQ = true;
        rep(i, N){
            if(order[i] != P[i]){
                flagP = false;
            }
            if(order[i] != Q[i]){
                flagQ = false;
            }
        }
        if(flagP == true) a = count;
        if(flagQ == true) b = count;
        count++;
    }while(next_permutation(all(order)));
    cout << abs(a-b) << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll X;
double P;

double F(int N) {
	return 1.0/P*N;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>P;
	
	P/=100;
	
	if(X%2==1) {
		_P("%.12lf\n",1+P*F((X-1)/2)+(1-P)*F((X+1)/2));
	}
	else {
		_P("%.12lf\n",F(X/2));
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

void merge(vector<int>& A,int left,int mid,int right,long long int& counter){
  int n1 = mid - left,n2 = right - mid;
  vector<int> L,R;
  L.resize(n1+1);
  R.resize(n2+1);
  for(int i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(int i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1-1] > R[n2-1] ? L[n1] = R[n2] = L[n1-1]+1 : L[n1] = R[n2] = R[n2-1]+1;
  for(int i=0,j=0,k=left;k<right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
      counter += n1 - i;
    }
  }
}

void mergeSort(vector<int>& A,int left,int right,long long int& counter){
  if(left+1<right){
    int mid = (left + right)/2;
    mergeSort(A,left,mid,counter);
    mergeSort(A,mid,right,counter);
    merge(A,left,mid,right,counter);
  }
}

int main(){
  vector<int> A;
  int n;
  long long int counter=0;

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

  mergeSort(A,0,n,counter);
  cout << counter << endl;
}


Measured memory_bytes: 4304