akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
L = []
R = []
for _ in range(M):
    a, b = map(int, input().split())
    L.append(a)
    R.append(b)

left = 0
right = N
for l, r in zip(L, R):
    left = max(left, l)
    right = min(right, r)
    
print(max(0, right - left + 1))

Measured memory_bytes: 10996
#include<bits/stdc++.h>
using namespace std;
const int maxn =  1e6 + 10;
#define ll long long
#define ios std::ios::sync_with_stdio(false)
const ll INF(0x3f3f3f3f3f3f3f3fll);
const int inf(0x3f3f3f3f);
#define int long long
#define pb(a) push_back(a)
#define debug(a) cout << "a : " << a << '\n'
#define mp(a , b) make_pair(a ,b)
const int mod = 998244353;
const double eps = 1e-6;
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
template<typename T>void Out(T x){if(x<0)putchar('-'),x=-x;if(x>9)Out(x/10);putchar(x%10+'0');}

signed main()
{
    ios,cin.tie(0);
    int a , b , c;
    cin >> a >> b >> c;
    if(b * c >= a) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

/*
1
12
LLLLRRLRRRLL
*/


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    void Calc()
    {
        cin = new Scanner();

        int n = cin.nextInt();

        if (n == 1)
        {
            Console.WriteLine("Hello World");
        }
        else
        {
            int a = cin.nextInt();
            int b = cin.nextInt();
            Console.WriteLine(a + b);
        }
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n,m;
int a[110];
string s;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>a[i];
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=min(2*a[i],2*abs(m-a[i]));
  }
  cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

//sort(ALL(v),greater<int>());


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

	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 764
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(scan.readLine());
        LinkedList<Integer> list = new LinkedList<>();
        int counter = 0;
        for(int x = 0; x < n; x++){
            String check = scan.readLine();
            if(check.startsWith("insert")){
                int y = Integer.parseInt(check.substring(check.indexOf(" ")+1));
                list.addFirst(y);
                counter++;
            }
            else if(check.startsWith("delete ")){
                int y = Integer.parseInt(check.substring(check.indexOf(" ")+1));
                if(list.remove((Integer) y)) {
                    counter--;
                }
            }
            else if(check.equals("deleteFirst")){
                list.pollFirst();
                counter--;
            }
            else{
                list.pollLast();
                counter--;
            }
        }
        for(int x = 0; x < counter; x++){
            if(x == counter - 1){
                System.out.println(list.poll());
            }
            else {
                System.out.print(list.poll() + " ");
            }
        }
    }
}


Measured memory_bytes: 140236
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

const int N = 1001010;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  vector<int> v(3);
  for(int i = 0; i < 3; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  if(v[0] == v[1] && v[1] != v[2]) {
    cout << "Yes" << endl;
    return 0;
  }

  if(v[2] == v[1] && v[1] != v[0]) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = max(a).bit_length()
    c = [0] * n
    for i in range(k):
        b = [ai // 2**i % 2 for ai in a]
        if sum(b) % 2:
            b = [1 - bi for bi in b]
        for j in range(n):
            c[j] += b[j] * 2**i
    print(*c)


if __name__ == '__main__':
    main()

Measured memory_bytes: 169624
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N;
    int debt = 100000;
    cin >> N;
    for(int i = 0;i < N;i++){
        debt *= 1.05;
        debt = (debt+999)/1000*1000;
    }
    cout << debt << endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N;
	string s;
	cin >> N >> s;
	VV<int> G(N);
	rep(i,N-1){
		int x,y;
		cin>>x>>y;
		x--,y--;
		G[x].pb(y);
		G[y].pb(x);
	}
	int inf = 1e9;
	int ans = inf;

	rep(r,N){
		V<int> mn(N),mx(N),sz(N);
		int dsum = 0;
		function<void(int,int,int)> dfs = [&](int v,int p,int d){
			if(s[v] == '1') sz[v] = 1, dsum += d;
			int mxsum = 0;
			int mxs = -inf;
			for(int u: G[v]) if(u!=p){
				dfs(u,v,d+1);
				sz[v] += sz[u];
				mxsum += mx[u];
				chmax(mxs,mn[u]+mx[u]);
			}
			mx[v] = mxsum;
			mn[v] = mxs == -inf ? 0 : max(mxs - mxsum,mx[v]%2);
			mn[v] += sz[v], mx[v] += sz[v];
		};
		dfs(r,-1,0);
		if(false){
			cerr << "------------ r = " << r << endl;
			rep(v,N){
				show("------");
				show(v);
				show(mn[v]);
				show(mx[v]);
			}
			show(dsum);
		}
		if(mn[r] == sz[r]) chmin(ans,dsum/2);
	}
	if(ans == inf) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main(){
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++)
	{
		if(s[i] == '7'){
			cout << "Yes" << endl;
			return 0;
					}
		/* code */
	}
	cout << "No" << endl;
	return 0;
	
}


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

int main(){
	// your code goes here

  double a,b,c,d,e,f;
  double x,y;

  while(cin >> a >> b >> c >> d >> e >>f){

    x =(double)((e*c-b*f)/(a*e-b*d));
    y = (double)((-(d*c)+a*f)/(a*e-b*d));
    if(y == 0)y = 0;

    if(x == 0) x = 0;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 3084
import sys
R = lambda:map(int,raw_input().split())

digit = 4
n = int(raw_input())
for i in xrange(n):
    s = int(raw_input())
    ran = []
    for j in xrange(10):
        s2 = str(s*s)
        s2 = s2.zfill(8)
        #print s2
        s = int(s2[digit-2:digit+2])
        ran.append(s)

    print "Case %d:" % (i+1)
    for j in xrange(len(ran)):
        print ran[j]
    

Measured memory_bytes: 4236
N = int(input())
S = [0] * (N + 1)
for i in range(N):
  S[i + 1] = int(input())
  
AA = sum(S)
ans = -1
for i in range(N + 1):
  now = AA - S[i]
  if now % 10 != 0:
    ans = max(ans, now)
    
if ans == -1:
  ans = 0
  
print(ans)  
  

Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    int i = 0;
    vector<int> ans;
    while (i < n) {
        int step = -1;
        for (int j = i+1; j <= i+m && j < n+1; ++j) {
            if (s[j] == '0') step = j;
        }
        if (step == -1) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(step-i);        
        i = step;
    }
    rrep(i, ans.size()) cout << ans[i] << (i == 0 ? '\n' : ' ');
}


Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>
#define N 105
#define M 100005

ll n,w,dp[N][M],we[N],va[N],ans;

int main() {
	// freopen("input.txt", "r", stdin); 
	// freopen("output.txt", "w", stdout);
	fast_io;	 
	accuracy;
	cin >> n >> w;
	fr(i,1,n) cin >> we[i] >> va[i];
	fr(i,0,N-1) {
		fr(j,0,w) dp[i][j] = LLONG_MIN;
	}
	dp[0][0] = 0;
	fr(i,1,n) {
		fr(j,0,w) {
			if(dp[i-1][j] != LLONG_MIN) {
				if(j + we[i] <= w) {
					dp[i][j + we[i]] = max(dp[i][j + we[i]],dp[i-1][j] + va[i]);
				}
			}
			dp[i][j] = max(dp[i][j],dp[i-1][j]);
		}
	}
	fr(j,0,w) {
		ans = max(ans,dp[n][j]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 82304
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;



int main() {
	string s;
	cin >> s;
	int count = 0, maxi = 0;
	for (char x : s) {
		if (x == 'A' || x == 'C' || x == 'G' || x == 'T') {
			count++;
		}
		else {
			maxi = max(maxi, count);
			count = 0;
		}
	}
	cout << max(maxi, count) << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from bisect import bisect
N = int(input())
A = list(map(int,input().split()))

d = defaultdict(lambda:0)

for i in range(N):
    d[A[i]] += 1

C = [0]*(N+1)

for i in d:
    C[d[i]] += 1

C1 = [0]*(N+1)
C2 = [0]*(N+1)

for i in range(N):
    C1[i+1] = C1[i] + (i+1)*C[i+1]
    C2[i+1] = C2[i] + C[i+1]

l = [0]*N
for n in range(N):
    l[n] = C1[n+1]//(n+1)+C2[N]-C2[n+1]
    l[n] *= -1


for i in range(N):
    print(bisect(l,-(i+1)))

Measured memory_bytes: 60116
import sys
import numpy as np

# S = input()
# N, M = map(int, input().split())
# As = [int(input()) for _ in range(N)]
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    solve()


def solve():
    N = int(input())
    S = input()

    ridxs = []
    gidxs = []
    bidxs = []

    rdic = dict()
    gdic = dict()
    bdic = dict()

    for i in range(N):
        s = S[i]
        if s == 'R':
            ridxs.append(i)
            rdic[i*2] = 1
        if s == 'G':
            gidxs.append(i)
            gdic[i*2] = 1
        if s == 'B':
            bidxs.append(i)
            bdic[i*2] = 1

    total = len(ridxs) * len(gidxs) * len(bidxs)

    for ri in ridxs:
        for gi in gidxs:
            if ri + gi in bdic:
                total -= 1

    for gi in gidxs:
        for bi in bidxs:
            if gi + bi in rdic:
                total -= 1

    for bi in bidxs:
        for ri in ridxs:
            if bi + ri in gdic:
                total -= 1

    print(total)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 27176
def mips():
    return map(int,input().split())
def msps():
    return map(str,input().split())
N,M = mips()
H = [el for el in mips()]
G = dict()
ans = 0
no = 0
for i in range(1,N+1):
    G[i] = set()
for i in range(M):
    a,b = mips()
    G[a].add(b)
    G[b].add(a)
for i in range(1,N+1):
    if G[i] == set():
        ans += 1
        continue
    else:
        for el in G[i]:
            if H[el-1] >= H[i-1]:
                no = 1
                break
    if no == 0:
        ans += 1
    no = 0
print(ans)      

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
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); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)
int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i,1,n+1) cin >> a[i];
    vector<int> b(n+1);
    for(int i = n; 0 < i; i--){
        int state = 0;
        int cnt = i * 2;
        while(cnt < n + 1){
            state = state ^ b[cnt]; 
            cnt += i;
        }
        b[i] = state ^ a[i];
    }
    int sum = 0;
    rep(i,1,n+1){
        if(b[i]) sum++;
    }
    cout << sum << endl;
    rep(i,1,n+1){
        if(b[i]) cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
import java.util.*;
import java.util.Map.Entry;
 
 

class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();
       int K = sc.nextInt();

  	   List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
       for(long i=0;i<N;i++)list.add(new ArrayList<Integer>());
       
       int[] a = new int[N];
       int[] b = new int[N];
       for (int i=0 ; i<N-1; i++) {
           a[i] = sc.nextInt()-1;
           b[i] = sc.nextInt()-1;
       	   list.get(a[i]).add(b[i]);
       	   list.get(b[i]).add(a[i]);
       }
       
       long ans=1;
       LinkedList<Integer> queue = new LinkedList<Integer>();
       queue.add(a[0]);
       queue.add(-1);
       queue.add(0);
       while(!queue.isEmpty()) {
    	   int node = queue.poll();
    	   int pre = queue.poll();
    	   int f = queue.poll();
    	   ans=(ans*(K-f))%mod;
    	   int cnt=1;
    	   if(pre==-1)cnt=0;
    	   for(int i:list.get(node)) {
    		   if(i==pre)continue;
    		   cnt++;
    		   queue.add(i);
    		   queue.add(node);
    		   queue.add(cnt);
    	   }
       }


       System.out.println(ans); 	
              		
   }

}

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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())


/* constant */
const int inf = 100100100100100;
const int mod = 1000000007;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T& n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T& n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";for(auto e = s.begin(); e != s.end(); e++){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";for(auto e = mp.begin(); e != mp.end(); e++){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }



/* main */


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    

    string s = raw_input();

    map<char, int> mp;
    rep(i,0,s.size()){
        mp[s[i]]++;
    }
 
    
    if(exist(mp, 'N') && not exist(mp,'S') || exist(mp,'S') && not exist(mp, 'N') || exist(mp, 'W') && not exist(mp, 'E') || exist(mp, 'E') && not exist(mp, 'W')){
        print("No");
        return 0;
    }

    print("Yes");
    return 0;

    

    








}   

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 088 B "Card Game for Two"
 *   https://abc088.contest.atcoder.jp/tasks/abc088_b/
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = in.nextInt();
		int[] a = in.nextIntArray(N);

		Arrays.sort(a);

		int aNum = 0;
		int bNum = 0;
		for (int i = 0; i < N; i++) {
			if (i % 2 == 0) {
				aNum += a[N - 1 - i];
			} else {
				bNum += a[N - 1 - i];
			}
		}

		out.println(aNum - bNum);

		in.close();
		out.close();
	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner {

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public int[][] nextIntArray(int h, int w) {
			int[][] ret = new int[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextInt();
				}
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public long[][] nextlongArray(int h, int w) {
			long[][] ret = new long[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public double[] nextDoubleArray(int n) {
			double[] ret = new double[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextDouble();
			}
			return ret;
		}

		public double[][] nextDoubleArray(int h, int w) {
			double[][] ret = new double[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(String split) {
			String[] ret = scanner.next().split(split);
			return ret;
		}

		public String[][] nextStringArray(int h, int w) {
			String[][] ret = new String[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.next();
				}
			}
			return ret;
		}

		public String[][] nextStringArray(int h, String split) {
			String[][] ret = new String[h][];
			for (int i = 0; i < h; i++) {
				ret[i] = scanner.next().split(split);
			}
			return ret;
		}

		public void close() {
			scanner.close();
		}

	}

}


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

int main(){
    int H,W;
    cin >> H >> W;
    char a[101][101];
    int c[26]={0};
    for(int y=0;y<H;y++){
        for(int x=0;x<W;x++){
            cin >> a[x][y];
            c[(int)a[x][y]-97]+=1;
        }
    }
    int c4=0,c2=0,c1=0;
    for(int i=0;i<26;i++){
        int x=0,y=0;
        while(1){
            if((x+1)*4>c[i]){
                c4+=x;
                break;
            }
            x++;
        }
        while(1){
            if((y+1)*2>c[i]-4*x){
                c2+=y;
                break;
            }
            y++;
        }
        c1+=c[i]-4*x-2*y;
    }
    if(H%2==0&&W%2==0){
        if(c4==(H*W)/4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(H%2==1&&W%2==1){
        if(c1==1&&c2<=H/2+W/2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(H%2==0&&W%2==1){
        if(c1==0&&c2<=H/2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(H%2==1&&W%2==0){
        if(c1==0&&c2<=W/2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

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

int main()
{
	ll a,b,k;
	cin >> a >> b >> k;
	if(k <= a){
		printf("%lld %lld\n",a-k,b);
	}
	else{
		if(k - a < b){
			printf("0 %lld\n",b - (k-a));
		}
		else{
			printf("0 0\n");
		}
	}
    return 0;
}

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

bool isPrime(int a)
{
	//偶数除く
	if (a == 2) {
		return true;
	}
	else if (a % 2 == 0 || a < 2) {
		return false;
	}

	double Asqrt = sqrtf(a);

	for (int i = 3; i <= Asqrt; i += 2) {
		if (a%i == 0) {
			return false;
		}
	}

	return true;
}

int main()
{
	int n, a = 0, number;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> number;
		if (isPrime(number)) {
			a++;
		}
	}

	cout << a << endl;

	return 0;
}


Measured memory_bytes: 3100
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <random>
#include <stdio.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef string ST;


#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) for(auto (a): v )   cerr << a << endl
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl

vector<LL> arg_sort(vector<LL> A, bool ascend = true) {

  // 配列のインデックス indiecs = {0, 1, 2, 3, 4} を作成する。
  vector<LL> index(A.size());
  iota(index.begin(), index.end(), 0);

  // ソートする。
  if (ascend) {
    std::sort(index.begin(), index.end(), [&A](LL i1, LL i2) {
      return A[i1] < A[i2];
      });
  }
  else {
    std::sort(index.begin(), index.end(), [&A](LL i1, LL i2) {
      return A[i1] > A[i2];
      });
  }

  return index;
}

void func() {
  LL N;
  cin >> N;
  vector<LL> A(N);
  REP(i, N) {
    cin >> A[i];
  }
  
  auto B = arg_sort(A);
  for (auto b : B) {
    cout << b + 1 <<" ";
  }
}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 2560
#include<cstdio>
#include<vector>
#include<queue>
using graph=std::vector<std::vector<int>>;
constexpr int infty=1e8;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    graph g(3*n+1);
    for(int i=0;i<m;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(n+v);
        g[n+u].push_back(2*n+v);
        g[2*n+u].push_back(v);
    }
    int s,t;
    scanf("%d%d",&s,&t);
    std::queue<int> qu;
    std::vector<int> visited(300001,infty);
    qu.push(s);
    visited[s]=0;
    while(!qu.empty()){
        int u=qu.front();
        qu.pop();
        for(auto &v:g[u]){
            if(visited[v]>visited[u]+1){
                visited[v]=visited[u]+1;
                qu.push(v);
            }
        }
    }
    if(visited[t]==infty)printf("-1\n");
    else printf("%d\n",visited[t]/3);
    return 0;
}

Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,ans;
int x[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(x[i]);
    int pre = 0;
    int cnt = 0,ans = 1;
    for(int i = 1 ; i <= N ; ++i) {
        if(x[i] > pre) {++cnt;pre += 2;}
        else ans = mul(ans,cnt + 1);
    }
    for(int i = 1 ; i <= cnt ; ++i) ans = mul(ans,i);
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vll x(n);
    rep(i, n) cin >> x[i];
    sort(all(x));
    ll min_num = inf;
    for (ll p = x[0]; p <= x[x.size()-1]; p++) {
        ll num = 0;
        for (auto elem : x) {
            num += (ll)pow(abs(elem - p), 2);
        }
        min_num = min(num, min_num);
    }
    cout << min_num << endl;
    return 0;
}

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

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

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

    int d = N - int(N / 10) * 10;

    if (d == 3) {
        cout << "bon" << endl;
    } else if (d == 0 || d == 1 || d == 6 || d == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3036
//#define MYDEBUG
#include <bits/stdc++.h>
#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define debug(x)
#define ifcin(x)
#endif
#define ll long long
#define esp 1e-14
#define all(x) x.begin(),x.end()
#define rep(i,from,to) for(int i=from;i<to;++i)
#define REP(i,from,to) for(int i=from;i<=to;++i)
using namespace std;
vector<char> Y;
string x;
int mid,cnt,len;
int gu(vector<char> S){
	int ret;
	cnt=0;
	S.pop_back();
	if(S.size()%2!=0)S.pop_back();
	while(S.size()!=0){
		mid=S.size()/2;
		len=S.size();
		cnt=0;
		for(int i=0;i<mid;++i){
			if(S[i]==S[i+mid]){cnt++;}
		}
		if(cnt==mid)break;
		S.pop_back();
		S.pop_back();

	}
	ret=2*cnt;
	return ret;
}
void solve(){
	int k;
	int ans,leng;
	cin>>x;
	leng=x.size();
	for(k=0;k<leng;++k){
	Y.push_back(x[k]);
	}
	for(k=0;k<leng;++k){
		debug(Y[k]);
		}
	ans=gu(Y);

	debug(Y.size());

	cout<<ans<<endl;
}
int main() {
	solve();
	return 0;
}


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

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    int mi = a[0], ma = a[0];
    ll total = 0;
    rep(i, n){
        mi = min(a[i], mi);
        ma = max(a[i], ma);
        total += a[i];
    }
    cout << mi << " " << ma << " " << total << endl;

    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k;
	string s;
	cin>>k>>s;
	if(k<s.size()){
		for(int i=0;i<k;i++)  cout<<s[i];
		cout<<"...";
		return 0;
	}
	if(k>=s.size()){
		cout<<s;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<set>
#include<map>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define Sort(a)	sort(a.begin(),a.end())
#define rev(a)	reverse(a.begin(),a.end())
#define all(a)	(a).begin(),(a).end()
#define vll vector<long long int>
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
#define INF 1e18

#define MAX 200005

using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli power(lli a,lli b,lli m){if(b==0)	return 1;if(b==1)	return a%m;lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli Ceil(lli a,lli b){lli res=a/b;if(a%b!=0)	res++;return res;}

template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

lli dxx[]={1,1,0,-1,-1,-1,0,1};
lli dyy[]={0,1,1,1,0,-1,-1,-1};
lli dx[]={1,0,-1,0};
lli dy[]={0,1,0,-1};

struct pll{
	lli x,y;
};
bool comp(pll a,pll b){
	if(a.x==b.x)	return a.y<b.y;
	else	return a.x<b.x;
}
void solve(lli the)
{
	char ch;
	db aa,bb,cc,dd,xx;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,d,n,m,l,r,x,y,z,low,high,mid,sum=0,ans=0,temp,t;
    cin >> n >> m;
    map<lli,lli>count_wa;
    map<lli,lli>is_ac;
    while(m--){
    	cin >> x >> s1;
    	if(s1=="AC"){
    		is_ac[x]=1;
    	}
    	else{
    		if(is_ac[x]!=1){
    			count_wa[x]++;
    		}
    	}
    }
    lli ac=0;
    for(i=1;i<=n;i++){
    	if(is_ac[i]==1)	ac++;
    }
    lli wa=0;
    for(i=1;i<=n;i++){
    	if(is_ac[i])	wa+=count_wa[i];
    }
    cout << ac << " " << wa << endl;
    
    
}















int main()
{
	long long int t=1,c=1;
	// scanf("%lld",&t);
	while(t--){
		solve(c);
		c++;
	}
	return 0;
}
/* UJJWAL KESHRI */

Measured memory_bytes: 16092
#include<iostream>
using namespace std;
int main(){
  int a[3];
  int cnt_5=0,cnt_7=0;
  cin>>a[0]>>a[1]>>a[2];
  for(int i=0;i<3;i++){
    if(a[i]==5)cnt_5++;
  	if(a[i]==7)cnt_7++;
  }
  if(cnt_5==2&&cnt_7==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

int main() {
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) h -= a[i];
  if (h <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0)
    {
        if(b&1)
            res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)
        return true;
    while(d!=n-1)
    {
        x=(x*x)%n;
        d*=2;
        if(x==1)
            return false;
        if(x==n-1)
            return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)
        return false;
    if(n<=3)
        return true;
    ll d=n-1;
    while(d%2==0)
        d/=2;
    for(int i=0; i<k; i++)
    {
        if(!miller_rabin(d,n))
            return false;
    }
    return true;
}
bool p[100005];
void sieve()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i*i<=100000;i++){
        if(p[i]){
            for(int j=i*i;j<=100000;j+=i){
                p[j]=false;
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sieve();
    vector<int>v;
    for(int i=2;i<=100000;i++)if(p[i]){v.push_back(i);}
    int q;
    cin>>q;
    while(q-->0){
        int l,r,cnt=0;
        cin>>l>>r;
        int id=lower_bound(v.begin(),v.end(),l)-v.begin();
        int ses=lower_bound(v.begin(),v.end(),r)-v.begin();
        if(v[ses]>r)ses--;
        for(int i=id;i<=ses;i++){
            int n=(v[i]+1)/2;
            if(p[n])cnt++;
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3816
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) FOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

struct UnionFind {
    vector<int> p;

    UnionFind(int n) : p(n, -1) {
    }

    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }

    void unite(int u, int v) {
        int ru = root(u);
        int rv = root(v);
        if (ru == rv) {
            return;
        }
        if (p[ru] > p[rv]) {
            swap(ru, rv);
        }
        p[ru] += p[rv];
        p[rv] = ru;
    }

    bool same(int u, int v) {
        int ru = root(u);
        int rv = root(v);
        return ru == rv;
    }
};

// main
int main() {
    const int MAX_N = 100000, MAX_M = 100000;
    int N, M, p[MAX_N], x, y;
    cin >> N >> M;
    UnionFind tree(N);
    REP(i, N) {
        cin >> p[i];
    }
    REP(i, M) {
        cin >> x >> y;
        tree.unite(x - 1, y - 1);
    }
    int res = 0;
    REP(i, N) {
        if (tree.same(i, p[i] - 1)) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*

fun main(args : Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val s = scanner.next()
    var spre = s.get(0)
    var sum = 1
    for (i in 1..n-1) {
        val si = s.get(i)
        if (spre != si) {
            spre = si
            sum += 1
        }
    }
    println(sum)
}

Measured memory_bytes: 31952
import java.util.*;
public class Main {

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

		int n = sc.nextInt();
		Set<Integer> set = new HashSet<Integer>();
		boolean distinct = true;
		for(int i=0;i<n;i++) {
			int a = sc.nextInt();
			if(set.contains(a)) {
				distinct = false;
				break;
			}
			else {
				set.add(a);
			}
		}
		
		System.out.println(distinct ? "YES" : "NO");
	}

}


Measured memory_bytes: 98724
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,w,dp[10001],tv,tw,max_n;
  cin >> n >> w;
  fill(dp,dp+10001,-1);
  dp[0]=0;
  for(int i=0;i<n;i++){
    cin >> tv >> tw;
    for(int j=tw;j<=w;j++){
      if(dp[j-tw]!=-1){
        dp[j]=max(dp[j-tw]+tv,dp[j]);
      }
    }
    for(int j=1;j<=w;j++){
      dp[j]=max(dp[j],dp[j-1]);
    }
  }
  cout << dp[w]<<endl;
}



Measured memory_bytes: 3196
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
  c = a[i] + a[i+1]
  if c > b[i]:
    ans += b[i]
    if a[i] > b[i]:
      continue
    else:
      a[i+1] -= b[i] - a[i]
  else:
    ans += c
    a[i+1] = 0
print(ans)

Measured memory_bytes: 19116
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str0[100005];
char str1[100005];

int main(int argc, char* argv[])
{
    scanf("%s", str0);
    int n0=strlen(str0);
    
    scanf("%s", str1);
    int n1=strlen(str1);

    vector<int> z[26];
    int cnt0[26]={0};
    int cnt1[26]={0};
    int i;
    for(i=0; i<n0; i++) {
        int tmp=str0[i]-'a';
        cnt0[tmp]++;
        z[tmp].push_back(i);
    }
    for(i=0; i<n1; i++) {
        cnt1[str1[i]-'a']++;
    }

    for(i=0; i<26; i++) {
        if(cnt1[i] && cnt0[i]==0) {
            printf("-1\n"); return 0;
        }
    }

    ll ans=0;
    int curr=0;
    for(i=0; i<n1; i++) {
        int tmp=str1[i]-'a';
        auto it = lower_bound( z[tmp].begin(), z[tmp].end(), curr );
        if(it==z[tmp].end()) {
            ans += n0;
            it = z[tmp].begin();
            assert(it!=z[tmp].end());
        }
        curr = (*it)+1;
    }
    ans += curr;
    printf("%lld\n", ans);

    return 0;
}


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

int main() {
	int s;
  	cin >> s;
  
  	vector<int> vec(1000000);
  	vec.at(0) = s;

  	bool stop = false;
  
  	for(int i = 0; i < vec.size(); i++) {
    	if(vec.at(i) % 2 == 0) {
        	vec.at(i + 1) = vec.at(i) / 2;
        }else {
        	vec.at(i + 1) = 3 * vec.at(i) + 1;
        }
      for(int j = 0; j < i + 1; j++) {
      	if(vec.at(j) == vec.at(i + 1)) {
        	cout << i + 2 << endl;
          	stop = true;
        }
      }
      
      	if(stop) break;
    }
}

Measured memory_bytes: 4096
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    cnt = 0
    total = 0
    mi = f_inf
    for a in A:
        total += abs(a)
        if a < 0:
            cnt += 1
        if mi > abs(a):
            mi = abs(a)

    if cnt % 2 == 0:
        print(total)
    else:
        print(total - mi * 2)


if __name__ == '__main__':
    resolve()


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

struct edge {
    int u, v;

    edge() { }
    ~edge() { }

    edge(int a, int b): u(a), v(b) { }
};

void rec(int ind, int depth, vector<edge>& ve, vector<string>& vm) {
    for(int _ = 0; _ < depth; ++_) cout << '.';
    cout << vm[ind] << endl;
    for(edge& e: ve) {
        if (e.u == ind) {
            rec(e.v, depth + 1, ve, vm);
        }
    }
}


int main() {
    int n;
    vector<edge> ve;
    vector<string> vm;
    cin >> n;
    for (int j = 0; j < n; ++j) {
        int k;
        string m;
        cin >> k >> m;
        ve.push_back(edge(k-1, j));
        vm.push_back(m);
    }
    rec(0, 0, ve, vm);
    return 0;
}

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

using namespace std;
typedef long long ll;


int main()
{
    int n, cnt = 0;
    cin >> n;

    int a[n+2];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (i%2 && a[i]%2)
            cnt++;
    }
    cout << cnt;

    return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,k;
    cin >> a >> b >> c >> k;
    long long int sum=0;
    if(k<=a)
        cout << k;
    else{
        sum+=a;
        k-=a;
        if(k<=b)
            cout << sum;
        else{
            k-=b;
            sum-=k;
            cout << sum;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	ll n,k;
	cin >> n >> k;
	ll a[n];
	for(int i=0;i<n;i++) cin >> a[i];

	ll ans = 0;
	ll ret = 0;
	for(int i=40;i>=0;i--){
		ll mask = 1ll << i;
		ll cnt = 0;
		for(int j=0;j<n;j++){
			if((a[j]&mask)>0) cnt++;
		}
		//cout << cnt << endl;
		if(cnt>=n-cnt){
			ans += mask*cnt;
		}else{
			if(mask+ret<=k){
				ans += (n-cnt)*mask;
				ret += mask;
			}else{
				ans += mask*cnt;
			}
		}
		
	}

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

Measured memory_bytes: 1024