akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
use std::collections::VecDeque;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn calc_point(v: &Vec<Vec<usize>>, d: &Vec<usize>, cur: usize, prev: usize) -> usize {
    let mut res = 0;
    for next in &v[cur] {
        if *next == prev {
            continue;
        }
        res += calc_point(v, d, *next, cur);
        res += cmp::min(d[*next], d[cur]);
    }
    return res;
}

fn main() {
    let n: usize = read_as_vec()[0];
    let mut tree: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..n - 1 {
        let line = read_as_vec::<usize>();
        let (a, b) = (line[0] - 1, line[1] - 1);
        tree[a].push(b);
        tree[b].push(a);
    }
    let mut c = read_as_vec::<usize>();
    c.sort();

    let sum: usize = c.iter().sum::<usize>() - *c.last().unwrap();
    let mut ans: Vec<usize> = vec![0; n];
    ans[0] = c.pop().unwrap();

    let mut queue: VecDeque<usize> = VecDeque::new();
    for next_cur in &tree[0] {
        queue.push_back(*next_cur);
    }

    while let Some(cur) = queue.pop_front() {
        ans[cur] = c.pop().unwrap();

        for next_node in tree[cur].iter().filter(|x| ans[**x] == 0) {
            queue.push_back(*next_node);
        }
    }

    println!("{}", sum);
    for elem in ans {
        print!("{} ", elem);
    }
    println!("");
}


Measured memory_bytes: 3000
#include<iostream>

using namespace std;


int main() {

	long long a, b, c, d;

	cin >> a >> b >> c >> d;

	long long ue, sita,r,tmp,x;
	long long c1 = c;
	long long d1 = d;
	x = c * d;

	if (d < c) {
		tmp = d;
		d = c;
		c = tmp;
	}

	r = d % c;
	while (r != 0) {
		d = c;
		c = r;
		r = d % c;
	}
	long long saibai = x / c;
	ue = b / c1 + b / d1 -b/saibai;
	sita = (a-1) / c1 + (a-1) / d1 - (a-1) / saibai;
	long long ans1 = b - ue;
	long long ans2 = a-1 - sita;
	long long ans = ans1 - ans2;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const ll MOD = 998244353;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, S;
    cin >> n >> S;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector< vector<ll> > dp(n, vector<ll>(S + 1, 0));
    if (a[0] <= S)
        dp[0][a[0]] = 1;
    for (int i = 1; i < n; ++i)
    {
        for (int j = 1; j <= S; ++j)
        {
            if (j - a[i] >= 0)
                dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % MOD;
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
        }
        if (a[i] <= S)
            dp[i][a[i]] = (dp[i][a[i]] + i + 1) % MOD;
    }
    ll odp = 0;
    for (int i = 0; i < n; ++i)
        odp = (odp + dp[i][S]) % MOD;
    cout << odp;
    return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>

int	main(void)
{
  	int	N;
  	int	K;
  	int	num;
  	int	d;
  
  	num = scanf("%d %d", &N, &K);
  	if (num != 2)
    {
      	return (0);
    }
  	
  	d = 0;
  	while (N != 0)
    {
      	N = N / K;
      	d++;
    }
  
  	printf("%d", d);
  	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    
    int a,b,c,d;

    cin >> a >> b >> c >>d;

    int ma = max(b,d);

    int cnt = 0;
    rep(i,ma){
        if( i >= a && i >= c && i < b && i < d) cnt++;
    }
    cout << cnt << endl;
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			int[] h = new int[n];
			IntStream.range(0, n).forEach(i -> h[i] = scanner.nextInt());
			Set<Integer> set = IntStream.range(0, n).boxed().collect(Collectors.toSet());
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt() - 1, b = scanner.nextInt() - 1;
				if (h[a] < h[b]) {
					set.remove(a);
				} else if (h[a] > h[b]) {
					set.remove(b);
				} else {
					// h[a]==h[b]
					set.remove(a);
					set.remove(b);
				}
			});
			System.out.println(set.size());
		}
	}
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 1005;
const ll inf = 1e16;
ll dp[2][N][8];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	for(int i = 0; i <= m; i++){
		for(int mask = 0; mask < 8; mask++){
			dp[0][i][mask] = -inf;
		}
	}
	for(int mask = 0; mask < 8; mask++){
		dp[0][0][mask] = 0;
	}
	ll x[3];
	int flg = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			cin>>x[j];
		}
		for(int mask = 0; mask < 8; mask++){
			ll cost = 0;
			for(int j = 0; j < 3; j++){
				if(mask&(1<<j))cost += x[j];
				else cost -= x[j];
			}
			dp[flg^1][0][mask] = 0;
			for(int cnt = 1; cnt <= m; cnt++){
				dp[flg^1][cnt][mask] = max(dp[flg][cnt][mask], dp[flg][cnt - 1][mask] + cost);
			}
		}
		for(int cnt = 0; cnt <= m; cnt++){
			for(int mask = 0; mask < 8; mask++){
				dp[flg][cnt][mask] = -inf;
			}
		}
		flg ^= 1;
	}
	ll ans = -inf;
	for(int mask = 0; mask < 8; mask++){
		ans = max(ans, dp[flg][m][mask]);
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}




int dis[10][10];





int main()
{

	int n, h;
	cin >> n >> h;

		
	int a;
	int maxA = 0;

	vector<int> b(n);
	
	for (int i = 0; i < n; i++) {
		cin >> a >> b[i];
		if (a > maxA)maxA = a;
	}
	
	sort(b.begin(), b.end(), greater<int>());


	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (b[i] > maxA) {
			h -= b[i];
			ans++;
		}
		else {
			break;
		}
		
		if (h <= 0)break;

	}

	if (h > 0) {
		ans += (h + maxA - 1) / maxA;
	}

	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>

using std::list;
using std::max;
using std::min;
using std::vector;

int main()
{
  int n;
  scanf("%d", &n);
  int result = 0;
  for(int i = 0; i < n; i++) {
    int tmp;
    scanf("%d", &tmp);
    result += tmp;
  }
  result -= n;
  printf("%d\n", result);
  return 0;
}


Measured memory_bytes: 128
import Numeric

d (x,y) (z,w) = sqrt $ (x - z) ** 2 + (y - w) ** 2
 
r n l = if n < 0.001 then return l else do
        s <- (map read . words) <$> getLine :: IO [Double]
        let (x,y) = (s !! 0, s !! 1)
        r (n - 1) ((x,y) : l)

f [] = 0
f (x:[]) = 0
f (x:xs) = foldl (\s p -> s + d x p) 0 xs + f xs

main = do
    n <- read <$> getLine :: IO Double
    l <- r n []
    let x = f l
    print $ x / (n * (n - 1) / 2) * (n - 1)

Measured memory_bytes: 636
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c){
  stack<int> S;
  S.push(r);
  color[r] = c;
  while(!S.empty()){
    int u = S.top();
    S.pop();
    for(int i = 0; i < G[u].size(); i++){
      int v = G[u][i];
      if(color[v] == NIL){
	color[v] = c;
	S.push(v);
      }
    }
  }
}

void assignColor(){
  int id = 1;
  for(int i = 0; i < n; i++) color[i] = NIL;
  for(int u = 0; u < n; u++) if(color[u] == NIL) dfs(u, id++);
}

int main(){
  int s, t, m, q;

  cin >> n >> m;

  for(int i = 0; i < m; i++){
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  string echo[q];

  for(int i = 0; i < q; i++){
    cin >> s >> t;
    if(color[s] == color[t]) echo[i] = "yes";
    else echo[i] = "no";
  }
  for(int i = 0; i < q; i++) cout << echo[i] << endl;

  return 0;
}

Measured memory_bytes: 9632
// Author: Jashan Bansal
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second	
#define mp make_pair
#define int long long
#define ll long long
#define pii pair<int,int>
#define all(arr) arr.begin(), arr.end()
#define sz(arr) ((long long)arr.size())
// const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
#define log1(x) cout << x << '\n'
#define log2(x,y) cout << x << " " << y <<'\n'
#define log3(x,y,z) cout << x <<" " << y <<" " << z << '\n'
#define logarr(arr,n) for(int __=0; __ < n; __++)	cout << arr[__] << " "; cout << '\n'

int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}


void solve() {
	// int n; cin >> n;
	// vi arr(n);
	// for(auto &x: arr) cin >> x;
	string str; cin >> str;
	cout << ((str== "ABC") ? "ARC": "ABC");	

}
 
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	// cin>>t;
	while(t--)
		solve();
	return 0;
}

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

int main() {
  int n,cur=1,cnt=0,pre;
  cin >> n;
  vector<int> vec(n+1);
  for(int i=1 ;i<n+1 ;i++){
    cin >> vec[i];
  }
  while(cur != 0 && cur != 2){
    cnt++;
    pre = cur;
    cur = vec[cur];
    vec[pre] = 0;
  }
  cout << (cur?cnt:-1) << endl;
}

Measured memory_bytes: 640
function main(input){
    let lines = input.split("\n");
    let i = 0;
    while(lines[i]!=="0 0"){
        console.log(board(lines[i]));
        i++;
    }
    
    
}

function board(line){
    let args = line.split(" ").map(item=>parseInt(item));
    let height = args[0];
    let width = args[1];
    let put ="";
    let color = ["#","."];

    for(let i=0;i<height;i++){
        for(let j=0;j<width;j++){
            put+=color[(i+j)%2];
        }
        put+="\n";
    }
    return put;
    
    
    
    
    
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


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

int main() {
int n;
cin>>n;
vector<int> a(n);
rep(i,n) {
 cin>>a.at(i);
 }
 
 long long sum = 0;
 for(long long i = 0;i<n-1;i++) {
  if(a.at(i)>a.at(i+1)) {
   sum = sum + a.at(i)-a.at(i+1);
   a.at(i+1) = a.at(i);
   }
   
 
  }
 cout <<sum;

}

Measured memory_bytes: 4048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.InputMismatchException;


public class Main {

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

		int n = sc.nextInt();

		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		long sum = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			min = Math.min(min, a);
			max = Math.max(max, a);
			sum += a;
		}

		System.out.println(min + " " + max + " " + sum);

		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		InputStreamReader isr;
		BufferedReader br;
		StreamTokenizer st;

		private Scanner() {
		}

		Scanner (InputStream in) {
			isr = new InputStreamReader(in);
			br = new BufferedReader(isr);
			st = new StreamTokenizer(br);
		}

		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return st.sval;
		}

		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return (int)st.nval;
		}

		void close() {
		}
	}
}

Measured memory_bytes: 24556
// =====================================================
//   File    :   main.cpp
//   Author  :   eezyl
//   Synopsis:   codeforces/atcoder template
//   Address :
//   Date    :   2020/08/21
// =====================================================
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<vi> vvi;

#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) { return b ? "true" : "false"; }
str ts(vector<bool> v) { str res; F0R(i,sz(v)) res += char('0'+v[i]); return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res; F0R(i,SZ) res += char('0'+b[i]); return res; }

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))

const ll MOD = 1e9+7; // 998244353;
const int MX = 3e5+5;

void solve() {
    int N;
    cin >> N;
    vll A(N);
    F0R(i, N) {
        cin >> A[i];
    }
    ll sum = 0;
    FOR(i, 1, N) if (A[i] < A[i-1]){
        sum += A[i-1] - A[i];
        A[i] = A[i-1];
    }
    cout << sum << endl;
}


int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define LOCAL
#ifdef LOCAL
freopen("data.in", "r", stdin);
while (!feof(stdin)) {
#endif // LOCAL

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

#ifdef LOCAL
}
printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
#endif // LOCAL
    return 0;
}


Measured memory_bytes: 4780
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private static final String[][] TABLE = {
        {},
        {".", ",", "!", "?", " "},
        {"a", "b", "c"},
        {"d", "e", "f"},
        {"g", "h", "i"},
        {"j", "k", "l"},
        {"m", "n", "o"},
        {"p", "q", "r", "s"},
        {"t", "u", "v"},
        {"w", "x", "y", "z"}
    };
    
    public static void main(String[] args) {
        scn.nextLine();
        while(scn.hasNextLine()) {
            Scanner reader = new Scanner(scn.nextLine());
            reader.useDelimiter("0+");
            StringBuilder sb = new StringBuilder();
            while(reader.hasNext()) {
                String tmp = reader.next();
                int y = Integer.parseInt(tmp.substring(0, 1));
                int x = (tmp.length() - 1) % TABLE[y].length;
                sb.append(TABLE[y][x]);
            }
            System.out.println(sb);
        }
    }
}

Measured memory_bytes: 37424
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <functional>
#include <cstring>
#include <set>
using namespace std;

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

int main()
{
	int n; cin >> n;
	ll num = 1;
	ll cnt = 0;
	int a; cin >> a;
	cnt += a - 1;
	num += 1;
	for (int i = 1; i < n; i++) {
		int a; cin >> a;
		if (a < num) continue;
		else if (a == num) {
			num++;
			continue;
		}

		cnt += (a-1) / num;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
const int INF = 1<<29;
int main(){
	string S,T;
	//int n,m;
	//scan(n);scan(m);
	scan(S);scan(T);
	int dp[1001][1001];
	rep(i,S.size()+1){
		dp[i][0]=i;
	}
	rep(j,T.size()+1){
		dp[0][j]=j;
	}
	rep(i,S.size()){
		rep(j,T.size()){
			if(S[i]==T[j]) dp[i+1][j+1]=min(dp[i][j],min(dp[i][j+1]+1,dp[i+1][j]+1));
			else dp[i+1][j+1]=min(dp[i][j]+1,min(dp[i][j+1]+1,dp[i+1][j]+1));
		}
	}
	prin(dp[S.size()][T.size()]);
	return 0;
}



Measured memory_bytes: 7068
n,q=map(int,input().split())
s=input()
ans_l=[0]*n
for i in range(n-1):
    tmp=s[i]+s[i+1]
    if tmp=='AC':
        ans_l[i+1]=ans_l[i]+1
    else:
        ans_l[i+1]=ans_l[i]
for i in range(q):
    l,r=map(int,input().split())
    print(ans_l[r-1]-ans_l[l-1])

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

using namespace std;

#define MAX_N 100
#define MAX_V 1000
long long w[MAX_N], dp[MAX_N + 1][MAX_V * MAX_N + 1];
int v[MAX_N];
int n;
long long W;
#define INF 1e18

void solve() {
  fill(dp[0], dp[0] + MAX_N * MAX_V + 1, INF);
  dp[0][0] = 0;
  for (int i = 0 ; i < n; i++)
    for (int j = 0; j <= MAX_N * MAX_V; j++) {
      if (j < v[i])
        dp[i + 1][j] = dp[i][j];
      else dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
    }
  long long res = 0;
  for (int i = 0; i <= MAX_N * MAX_V; i++)
    if (dp[n][i] <= W) res = i;
  printf("%lld", res);
}

int main () {
  cin >> n;
  cin >> W;
  for (int i = 0; i < n; i++)
    cin >> w[i] >> v[i];
  solve();
  return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

const int N=100000, M=300000;
const int INF=12345678;

int d[2][N];
vector<int> G[N];

int d_ct=0;
void dijkstra(int s)
{
    // dijkstra
    priority_queue<pi,vector<pi>,greater<pi>> que;
    fill(d[d_ct],d[d_ct]+N,INF);
    d[d_ct][s]=0;
    que.push(pi(0,s));
    while(!que.empty())
    {
        pi p=que.top();
        que.pop();
        int v=p.se;
        if(d[d_ct][v]<p.fi) continue;
        rep(i,G[v].size())
        {
            int nx=G[v][i];
            if(d[d_ct][nx]>d[d_ct][v]+1)
            {
                d[d_ct][nx]=d[d_ct][v]+1;
                que.push(pi(d[d_ct][nx],nx));
            }
        }
    }
    ++d_ct;
}

int cts[N]={0}, ctt[N]={0};

int main()
{
    int n,m,s,t;
    scanf(" %d %d %d %d", &n, &m, &s, &t);
    --s;
    --t;
    rep(i,m)
    {
        int x,y;
        scanf(" %d %d", &x, &y);
        --x;
        --y;
        G[x].pb(y);
        G[y].pb(x);
    }

    dijkstra(s);
    dijkstra(t);

    rep(i,n) if(d[0][i]<N) ++cts[d[0][i]];
    rep(i,n) if(d[1][i]<N) ++ctt[d[1][i]];

    ll ans=0;
    rep(i,d[0][t]-1) ans+=(ll)cts[i]*ctt[d[0][t]-2-i];
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n,k;
  vector<int> p;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int pi;
    cin >> pi;
    p.push_back(pi);
  }

  sort(p.begin(),p.end());
  int sum = 0;
  for (int j = 0; j < k; ++j) {
    sum += p[j];
  }
  cout << sum <<endl;

  return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    string k;
    int d;
    cin >> k >> d;

    vector< vector<int> > dp(d, vector<int>(2));
    dp[0][true] = 1;

    rep(i, k.size()) {
        int here = k[i] - '0';
        vector< vector<int> > after(d, vector<int>(2));

        for(int prevmod = 0; prevmod < d; prevmod++) {
            for(int now = 0; now <= 9; now++) {
                int nowmod = (prevmod + now) % d;
                if(now < here) {
                    after[nowmod][false] += dp[prevmod][true], after[nowmod][false] %= MOD;
                } else if(now == here) {
                    after[nowmod][true] += dp[prevmod][true], after[nowmod][true] %= MOD;
                }
                after[nowmod][false] += dp[prevmod][false], after[nowmod][false] %= MOD;
            }
        }
        dp = after;
    }

    cout << (dp[0][true] + dp[0][false] - 1 + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   debug::instance

using namespace std;

template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	auto S = fetch<string>();
	if(len(S)&1) {
		cout << "No\n";
		return;
	}
	for(int i = 0; i < len(S); ++i) {
		char must = (i&1 ? 'i' : 'h');
		if(S[i] != must) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	map<pair<string, string>, int> sp;
	for (int i = 0; i < (1 << n); i++) {
		string a, b;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) a += s[j + n];
			else b += s[j + n]; 
		}
		sp[{a, b}]++;
	}	
	int ans = 0;
	for (int i = 0; i < (1 << n); i++) {
		string a, b;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) a += s[j];
			else b += s[j]; 
		}
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		ans += sp[{b, a}];
	}	
	cout << ans << endl;
}


Measured memory_bytes: 49408
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n, p;
    string s;
    cin >> n >> p >> s;
    ll ans = 0;
    if (p == 2 || p == 5) {
        for (int i=0; i<n; i++) {
            if ((s[i] - '0') % p == 0) ans += (ll)i + 1;
        }
    } else {
        reverse(s.begin(), s.end());
        ll cnt[p];
        fill(cnt, cnt+p, 0);
        cnt[0]++;
        int r = 0, d = 1;
        for (auto &c:s) {
            int ci = c - '0';
            r = (r + ci * d) % p;
            d = (d * 10) % p;
            ans += cnt[r];
            cnt[r]++;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 644
A = int(input())
B = int(input())
C = int(input())
X = int(input())

n = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if X == i*500 + j*100 + k*50:
                n += 1
print (n)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl "\n"
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fb(i, a, b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector <int>
#define vl vector <long long>
#define pi pair <int, int>
#define sz(x) (int) x.size()
#define M 100005
#define mod 1000000007
using namespace std;

void solve()
{
	int n, k;
	cin>>n>>k;
	int h[n], dp[n];
	f(i, 0, n) cin>>h[i];
	if(k >= n-1)
	{
		cout<<abs(h[n-1]-h[0]);
		return;
	}
	dp[0] = 0; dp[1] = abs(h[1] - h[0]);
	f(i, 2, k)
	{
		dp[i] = INT_MAX;
		fb(j, i-1, 0) dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
	}
	f(i, k, n)
	{
		dp[i] = INT_MAX;
		f(j, 1, k+1) dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
	}
	// f(i,0, n) cout<<dp[i]<<' ';
	cout<<dp[n-1];
}

int main()
{
    IOS
    int t = 1;
    //cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    REP(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    
    if (n == 1) {
        cout << "YES\n";
        return 0;
    }
    if (sum % ((n + 1) * n / 2)) {
        cout << "NO\n";
        return 0;
    }
    ll k = sum / ((n + 1) * n / 2);
    a.push_back(a[0]);
    vector<ll> vec(n, 0);
    REP(i, n) {
        ll x = k - (a[i + 1] - a[i]);
        if (x % n) {
            cout << "NO\n";
            return 0;
        }
        vec[i] = x / n;
    }
    
    bool judge = true;
    REP(i, n) {
        if (vec[i] < 0 || vec[i] > k) judge = false;
    }
    if (!judge) {
        cout << "NO\n";
        return 0;
    }
    ll s = 0;
    REP(i, n) s += vec[i];
    if (s > k) {
        cout << "NO\n";
    } else {
        if ((k - s) % n) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }
    return 0;
}


Measured memory_bytes: 4784
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{

    char S;
    int countA, countB;
    
    countA = countB = 0;
    
    while(cin >> S)
    {
        if(S=='0')
        {
            countA++;
        }
        else
        {
            countB++;
        }
        
    }
    
    if(countA > countB)
    {
        cout << countB*2 << endl;
    }
    else
    {
        cout << countA*2 << endl;
    }

}
    
    

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

int main(){
  string s;
  cin>> s;
  
  int n=s.size();
  // RLで固まる、LRで区切れる
  int start=0;
  vector<int> ans(n);
  for (int i=1; i<n; i++){
    if (s.at(i)=='L'){
      for (int j=i; j<n; j++){
        if (j+1==n || s.at(j+1)=='R'){
          int num=j+1-start;
          ans.at(i-1)=num/2;
          ans.at(i)=num/2;
          if (num%2==1){
            if ((i-start)%2==1) ans.at(i-1)++;
            else ans.at(i)++;
          }
          start=j+1;
          i=j+1;
          break;
        }
      }
    }
  }
  
  for (int i=0; i<n; i++){
    cout<< ans.at(i);
    if (i==n-1) cout<<endl;
    else cout<<" ";
  }
}

Measured memory_bytes: 1024
#Take the value of X
#Take the value of Y
#Do double equation

X, Y = map(int, input().split(" "))

C = (Y-4*X)/-2

T = X - ((Y-4*X)/-2)

total = int(T + C)

if (T<0) or (C<0):
    print("No")
elif (T%1 != 0) or (C%1 != 0):
    print("No")
elif (T+C) == X and (4*T + 2*C) == Y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9236
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = ReadLongs();
            var H = inputs[0];
            var W = inputs[1];
            var C = new long[10, 10];
            for (int i = 0; i < 10; i++)
            {
                var c = ReadLongs();
                for (int j = 0; j < 10; j++)
                {
                    C[i, j] = c[j];
                }
            }

            var Counts = new long[10];
            var A = new long[H, W];
            for (int i = 0; i < H; i++)
            {
                var a = ReadLongs();
                for (int j = 0; j < W; j++)
                {
                    A[i, j] = a[j];
                    if (a[j] != -1)
                    {
                        Counts[a[j]]++;
                    }
                }
            }

            // 経由点
            for (int via = 0; via < 10; via++)
            {
                // 開始点
                for (int start = 0; start < 10; start++)
                {
                    //終了点
                    for (int goal = 0; goal < 10; goal++)
                    {
                        C[start, goal] = Math.Min(C[start, goal], C[start, via] + C[via, goal]);
                    }
                }
            }

            var totalCost = Enumerable.Range(0, 10)
                .Where(x => x != 1)
                .Select(x => C[x, 1] * Counts[x])
                .Sum();

            return totalCost;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
typedef vector<vector<ll> > matrix;
const int mod = 1e9+7;
ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){ans = ans*base;ans = ans%mod;}
        base *= base;base%=mod;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

double pi = 3.141592653589793238462643;
double error = 0.0000001;
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/* -------Template ends here-------- */

const int M = 100001;
const int N = 1234567;

int a[N], b[N], c[N];


int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    //cin.sync_with_stdio(false);
    //cin.tie(0); cout.tie(0);

    int n, k;
    cin >> n;
    vector <int> vec(n);
    int cnt0, cnt1, cnt2;
    cnt0 = cnt1 = cnt2 = 0;
    for(int i = 0; i < n; i++){
        cin >> vec[i];
        if(vec[i]%2){
           cnt0++;
        }
        else{
            if(vec[i]%4){
               cnt1++;
            }
            else cnt2++;
        }
    }
    if(cnt1){
    if(cnt0 > cnt2){
      cout << "No";
    }
    else cout << "Yes";
    }
    else{
       if(cnt0 <= cnt2+1){
          cout << "Yes";
       }
       else cout << "No";
    }
}



Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Objects;

public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();

        boolean[][] isExist = new boolean[4][13];
        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            String suit = sc.nextToken();
            int num = sc.nextInt();
            if(suit.equals("S"))isExist[0][num-1] = true;
            else if(suit.equals("H"))isExist[1][num-1] = true;
            else if(suit.equals("C"))isExist[2][num-1] = true;
            else if(suit.equals("D"))isExist[3][num-1] = true;
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<13;j++){
                if(!isExist[i][j]){
                    if(i==0)System.out.println("S "+(j+1));
                    else if(i==1)System.out.println("H "+(j+1));
                    else if(i==2)System.out.println("C "+(j+1));
                    else if(i==3)System.out.println("D "+(j+1));
                }
            }
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}



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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int p[n];
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	int cou = 0;
	for(int i = 1; i < n-1; i++){
		if((p[i-1] > p[i] && p[i+1] < p[i]) || (p[i-1] < p[i] && p[i+1] > p[i])){
			cou++;
		}
	}
	cout << cou << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	int x, y, z; cin >> x >> y >> z;
	int cur = z;
	int ans = 0;
	while (cur + y + z <= x) {
		cur += y + z; ans++;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#define make_pair mp
#define pb push_bacck
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

const int jx[] = {-1,0,1,
						2,2,2,
						1,0,-1,
						-2,-2,-2};
const int jy[] = {-2,-2,-2,
						-1,0,1,
						2,2,2,
						1,0,-1};
const int sx[] = {-1,0,1,-1,0,1,-1,0,1};
const int sy[] = {-1,-1,-1,0,0,0,1,1,1};

int n;
int park[10][10];
pii sp[10];
bool memo[10][9];

bool isInside( int x, int y ){
	return ( 0 <= x && x < 10 && 0 <= y && y < 10 );
}

bool dfs( int x, int y , int pos ){
	//cout << "pos:" << pos << " " << x << "," << y << endl;
	if( pos == n ) return true;
	for( int i = 0; i < 12; i++ ){
		int nx = x + jx[i],
				ny = y + jy[i];
		if( !isInside(nx,ny) ) continue;
		if( abs(nx - sp[pos].first) <= 1 && abs(ny - sp[pos].second) <= 1 ){
			if( dfs(nx,ny,pos+1) ) return true;
		}
		/*for( int j = 0; j < 9; j++ ){
			int nsx = sp[pos].first + sx[j],
					nsy = sp[pos].second + sy[j];
			if( !isInside(nsx,nsy) || !memo[pos][j] ) continue;
			if( nx == nsx && ny == nsy ){
				if( dfs(nx,ny,pos+1) ) return true;
				else memo[pos][j] = false;
			}
		}*/
	}
	return false;
}

int main(){
	int px, py;
	while( cin >> px >> py, px || py ){
		for( int i = 0; i < 10; i++ ){
			for( int j = 0; j < 9; j++ ){
				memo[i][j] = true;
			}
		}
		cin >> n;
		for( int i = 0; i < n; i++ ){
			cin >> sp[i].first >> sp[i].second;
		}
		if( dfs(px,py,0) ) cout << "OK" << endl;
		else							 cout << "NA" << endl;
	}
}

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

int main(){
  char a[1001];
  int s=0,n=0,e=0,w=0;
  scanf("%s",a);
  for(int i=0; i<1001 ; i++){
    if(a[i]==0)break;
    else if(a[i]=='S')s=1;
    else if(a[i]=='N')n=1;
    else if(a[i]=='E')e=1;
    else w=1;
  }
  if(s==n&&e==w){
    cout << "Yes" << endl   ;
  }
  else cout << "No" << endl ;
  return 0;
}


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

ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
ll lcm(ll x,ll y)
{
    ll P=x*y;
    P/=gcd(x,y);
    return P;
}
int main()
{
    char p;
    cin>>p;
    p++;
    cout<<p;
















}


Measured memory_bytes: 256
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
a = inl()
cb = []
for i in range(m):
    bb,cc = inm()
    cb.append((cc,bb))
a.sort()
cb.sort(reverse=True)
top = 0
for z in cb:
    c,b = z
    done = False
    for i in range(b):
        if a[top] >= c:
            done = True
            break
        a[top] = c
        top += 1
        if top >= len(a):
            done = True
            break
    if done:
        break
print(sum(a))


Measured memory_bytes: 71960
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define FF first
#define SS second

map<int,int> ss;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++){
		int x; cin>>x;
		ss[x]++;
	}
	bool flag = true;
	int m; cin>>m;
	for(int i=0;i<m;i++){
		int x; cin>>x;
		if(ss.find(x)==ss.end()) flag = false;
		ss[x]--;
		if(ss[x]==0) ss.erase(x);
	}
	cout<<(flag?"YES":"NO")<<'\n';
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
int main(){

	int N=0;  //都市の数

        int M=0;  //道の本数
	
	int P[51];
	
	int i=0;
	int a[51];
	int b[51];
	
	cin>>N>>M;
	
	for(i=0;i<51;i++){
		P[i]=0;
	}
	
	for(i=0;i<M;i++){
		cin>>a[i]>>b[i];
		P[a[i]]++;
		P[b[i]]++;
        }
        for(i=1;i<N+1;i++){
		cout<<P[i]<<endl;
	}



}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import deque

def is_connected(path, N):
    visited = [False] * N
    visited[0] = True
    que = deque([0])
    while que:
        pre = que.popleft()
        for next in range(N):
            if not visited[next] and path[pre][next]:
                visited[next] = True
                que.append(next)
    
    if sum(visited) == N:
        return True
    else:
        return False

def main():
    N, M = map(int, readline().rstrip().split())
    path = [[False] * N for _ in range(N)]
    edge = []
    for _ in range(M):
        a, b = map(int, readline().rstrip().split())
        edge.append((a-1, b-1))
        path[a-1][b-1] = True
        path[b-1][a-1] = True
    
    res = 0
    for a, b in edge:
        path[a][b] = False
        path[b][a] = False

        if not is_connected(path, N):
            res += 1

        path[a][b] = True
        path[b][a] = True

    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


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


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


void solve(){
	int n;
	cin>>n; bool fg=false;
	while(n--){
		char t;
		cin>>t;
		if(t=='Y')
		fg=true;
	}	
	if(fg)
	cout<<"Four";
	else
	cout<<"Three";
}


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


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())

w_o = [['.' for i in range(3)] for j in range(3)]
b_o = [['#' for i in range(3)] for j in range(3)]

        
w_c = [['#' for i in range(3)] for j in range(3)]
b_c = [['.' for i in range(3)] for j in range(3)]

w_c[1][1] = '.'
b_c[1][1] = '#'

ab = [['.' for i in range(99)] for j in range(99)]

a -= 1
b -= 1

a_y = a//33
a_x = a % 33

for i in range(17):
    for j in range(33):
        if a_y > i:
            #w_c
            for k in range(3):
                for l in range(3):
                    ab[i*3+k][j*3+l] = w_c[k][l]
        elif a_y == i:
            if a_x > j:
                for k in range(3):
                    for l in range(3):
                        ab[i*3+k][j*3+l] = w_c[k][l]
            else:
                for k in range(3):
                    for l in range(3):
                        ab[i*3+k][j*3+l] = w_o[k][l]
        else:
            for k in range(3):
                for l in range(3):
                    ab[i*3+k][j*3+l] = w_o[k][l]

if a > 0:
    b -= 1

if b == -1:
    print(51,99)
    for i in range(51):
        print(*ab[i],sep="")
    exit()

b_y = b//33
b_x = b % 33

for i in range(17,17+16,1):
    for j in range(33):
        if b_y > i-17:
            #w_c
            for k in range(3):
                for l in range(3):
                    ab[i*3+k][j*3+l] = b_c[k][l]
        elif b_y == i-17:
            if b_x > j:
                for k in range(3):
                    for l in range(3):
                        ab[i*3+k][j*3+l] = b_c[k][l]
            else:
                for k in range(3):
                    for l in range(3):
                        ab[i*3+k][j*3+l] = b_o[k][l]
        else:
            for k in range(3):
                for l in range(3):
                    ab[i*3+k][j*3+l] = b_o[k][l]                    

print(99,99)
                    
for i in range(99):
    print(*ab[i],sep="")



Measured memory_bytes: 4724