akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        int T = scanner.nextInt();
        long time = 0;
        long last = -1;
        for (int i = 0; i < N; i++) {
            long t = scanner.nextLong();
            if (last == -1) {
                last = t;
                time += T;
            } else {
                long diff = (t + T) - (last + T);
                if (diff > T) {
                    diff = T;
                }
                last = t;
                time += diff;
            }
        }
        System.out.println(time);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String line = br.readLine();
            while (line.equals("")) {
                line = br.readLine();
            }
            s = line.split(reg, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() {
            try {
                return Integer.parseInt(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public double nextDouble() {
            try {
                return Double.parseDouble(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public long nextLong()  {
            try {
                return Long.parseLong(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
    }
}


Measured memory_bytes: 47512
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

vi  g[10005]; 
bool vis[10005];

signed main()
{
    int n,ans = 0; cin>>n; 
    vi c(n),res(n+1); 
    for (int i=0;i<n-1;i++){ 
    	int  u, v ; 
    	cin >> u >> v ; 
    	g[u].pb(v) ; 
    	g[v].pb(u) ; 
    } 
    for (int i=0;i<n;i++) cin >> c[i] ; 
    sort(all(c)) ; 
	int  i = n-2 ; 
    function < void(int) > dfs = [&] (int u){
    	if (vis[u]) return ; 
    	vis[u] = true;
    	for (auto &it: g[u]){
    		if (!vis[it]){
    			ans += res[it] = c[i--] ; 
    			dfs(it); 
    		}
    	}
    };
    res[1] = c[n-1] ; 
    dfs(1) ; 
    co (ans) ; 
    for (int i=1;i<=n;i++) 
    	cout << res[i] << " " ; 
    cout << endl; 
    return 0;
}
/* 

5 
1 2 
1 3 
3 4 
3 5 
2 3 4 5 6 

		ans -> 14 



*/


Measured memory_bytes: 4872
#include "bits/stdc++.h"
using namespace std;

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

    vector<int> vec(N * 2);
    for (int i = 0; i < N * 2; i++) {
        cin >> vec.at(i);
    }

    int sum = 0;
    for (int i = 0; i < N * 2; i += 2) {
        sum = sum + vec.at(i + 1) - vec.at(i) + 1;
    }

    cout << sum << endl;
}

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

#define N 3

int main() {
  int C[N][N];
  for(int i=0 ; i<N ; i++)
    for(int j=0 ; j<N ; j++)
      cin >> C[i][j];
  
  for(int i=0 ; i<N ; i++){
    int x=C[i][0]-C[(i+1)%N][0];
    if(C[i][1]-C[(i+1)%N][1]!=x || C[i][2]-C[(i+1)%N][2]!=x){
      cout << "No" << endl;
      return 0;
    }
  }
  
  for(int i=0 ; i<N ; i++){
    int x=C[0][i]-C[0][(i+1)%N];
    if(C[1][i]-C[1][(i+1)%N]!=x || C[2][i]-C[2][(i+1)%N]!=x){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if(x < 1200) {
			System.out.println("ABC");
		} else {
			System.out.println("ARC");
		}

	}

}


Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N;
    cin >> N;
    string s = "";
    while(N){
        ll r = N % 2;
        if(r < 0)r += 2;
        N = (N - r) / (-2);
        s += (char)('0' + r);
    }
    reverse(s.begin(), s.end());
    if(s == "")s = "0";
    cout << s << endl;

    return 0;
}

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

const int mod = 1e9 + 7;

vector<int64_t> fac, inv;
void init(int n) {
  fac.assign(n + 1, 1);
  inv.assign(n + 1, 1);

  for (int i = 1; i <= n; ++i) {
    fac[i] = i * fac[i - 1] % mod;
  }
  for (int p = mod - 2, x = fac[n]; p; p >>= 1) {
    if (p & 1) inv[n] = inv[n] * x % mod;
    x = 1ll * x * x % mod;
  }
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  }
}

int64_t C(int n, int r) {
  if (r < 0 || n < r) return 0;
  return fac[n] * inv[r] % mod * inv[n - r] % mod;
}

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

  init(n--);
  int64_t ans = 0, pre = 0;
  for (int i = n / 2; i >= 0; --i) {
    int64_t k = C(n - 1 - i, i) * fac[i] % mod * fac[n - i] % mod;
    (ans += (k - pre + mod) * (n - i) % mod) %= mod;
    pre = k;
  }

  cout << ans << endl;
}


Measured memory_bytes: 15872
/*
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int w,a,b;
    cin>>w>>a>>b;
    cout<<max(abs(b-a)-w,0)<<endl;

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	ll N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	struct Query {
		char t;
		char d;
	};
	vector<Query> queries(Q);
	rep(i,0,Q) {
		cin >> queries[i].t >> queries[i].d;
	}
	ll left_end = 0;
	ll right_end = N-1;
	rrep(i,Q,0) {
		Query q = queries[i];
		if (q.d == 'R' && s[right_end] == q.t) {
			right_end--;
		}
		if (right_end < N-1 && q.d == 'L' && s[right_end+1] == q.t) {
			right_end++;
		}
		if (q.d == 'L' && s[left_end] == q.t) {
			left_end++;
		}
		if (left_end > 0 && q.d == 'R' && s[left_end-1] == q.t) {
			left_end--;
		}
		if (right_end < left_end) {
			cout << 0 << endl;
			return 0;
		}
	}
	cout << N - left_end - (N-1 - right_end) << endl;
}



Measured memory_bytes: 1020
n = int(input())
for i in range(n):
    x,y,b,p = map(int,input().split())
    s = x * b + y * p
    t = int((x * 5 + y * 2) * 0.8)
    u = s
    if s <= t:
        print(s)

    else:
        if 5 - b > 0:
            u += (5 - b) * x

        if 2 - p > 0:
            u += (2 - p) * y
        print(min(s,int(u * 0.8)))


Measured memory_bytes: 5620
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc169_a solver = new abc169_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc169_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.print(in.nextInt() * in.nextInt());
        }

    }
}



Measured memory_bytes: 35820
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int ans = 0;

	int x;
	cin >> x;
	rep(i, x) {
		if (i * 100 > x)break;
		int rem = x - i * 100;
		if (rem <= i*5) {
			ans = 1;
			break;
		}
	}


	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import heapq

def main(): 

    N,K = map(int,input().split())
    S=list(input().split())
    S=list(S[0])
    S[K-1]=S[K-1].swapcase()
    print("".join(S))

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 38384
#include <cstdio>
#include <vector>

typedef long long llong;

constexpr int kMaxN = 400;
constexpr int kMaxNN = kMaxN * kMaxN;

char maze[kMaxN + 3][kMaxN + 3];
int union_set_id[kMaxNN + 3];
int union_set_count0[kMaxNN + 3];
int union_set_count1[kMaxNN + 3];
bool tmp[kMaxNN + 3];

int GetRoot(int i) {
  if (union_set_id[i] != i) {
    return union_set_id[i] = GetRoot(union_set_id[i]);
  }
  return i;
}

void UnionSetUnion(int i, int j) {
  i = GetRoot(i);
  j = GetRoot(j);
  if (i == j) {
    return;
  }
  union_set_id[i] = j;
  union_set_count0[j] += union_set_count0[i];
  union_set_count1[j] += union_set_count1[i];
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);

  for (int i = 0; i < n; ++i) {
    scanf("%s", maze[i]);
    for (int j = 0; j < m; ++j) {
      union_set_id[i * m + j] = i * m + j;
      union_set_count0[i * m + j] = maze[i][j] == '.';
      union_set_count1[i * m + j] = maze[i][j] == '#';
    }
  }

  int goi[] = {1, -1, 0, 0};
  int goj[] = {0, 0, 1, -1};

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c0 = maze[i][j];
      for (int k = 0; k < 4; ++k) {
        int i1 = i + goi[k];
        int j1 = j + goj[k];
        if (0 <= i1 && i1 < n && 0 <= j1 && j1 < m) {
          char c1 = maze[i1][j1];
          if (c0 != c1) {
            // printf("union (%d,%d) and (%d,%d)\n", i, j, i1, j1);
            UnionSetUnion(i * m + j, i1 * m + j1);
          }
        }
      }
    }
  }

  int nm = n * m;
  for (int i = 0; i < nm; ++i) {
    tmp[i] = false;
  }

  llong total = 0;
  for (int i = 0; i < nm; ++i) {
    int r = GetRoot(i);
    if (!tmp[r]) {
      tmp[r] = true;
      total += llong(union_set_count0[r]) * llong(union_set_count1[r]);
    }
  }

  printf("%lld\n", total);
  return 0;
}

Measured memory_bytes: 2432
#include "bits/stdc++.h"
using namespace std;

int main() {
    long long H, W;
    cin >> H >> W;

    if (H % 3 == 0 || W % 3 == 0) cout << 0 << endl;
    else {
        long long ans = 1e9;
        for (long long i = 1; i <= H / 2; i++) {
            long long S1 = i * W;
            long long S2 = (H - i) * (W / 2);
            long long S3 = (H - i) * (W - W / 2);
            ans = min(ans, max(S1, max(S2, S3)) - min(S1, min(S2, S3)));
        }
        for (long long i = 1; i <= W / 2; i++) {
            long long S1 = i * H;
            long long S2 = (W - i) * (H / 2);
            long long S3 = (W - i) * (H - H / 2);
            ans = min(ans, max(S1, max(S2, S3)) - min(S1, min(S2, S3)));
        }
        ans = min(ans, ((H + 2) / 3) * W - (H / 3) * W);
        ans = min(ans, ((W + 2) / 3) * H - (W / 3) * H);
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
gets
A = gets.split.map(&:to_i)

min_price = 10**9
max_gain = -1
cost = 0

A.each{|price|
  min_price = [min_price, price].min
  gain = price - min_price
  if gain == max_gain
    cost += 1
  elsif gain > max_gain
    cost = 1
    max_gain = gain
  end
}
p cost


Measured memory_bytes: 11140
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
T = list(map(int, sys.stdin.readline().split()))
M = int(sys.stdin.readline())
P, X = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

s = sum(T)
for p, x in zip(P, X):
    print(s - T[p-1] + x)


Measured memory_bytes: 23236
h,n = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]

dp = [float("inf")]*(h+1)
dp[0] = 0

for i in range(h):
  for d,c in ab:
    hp = min(i+d,h)
    dp[hp] = min(dp[hp],dp[i]+c)

print(dp[-1])

Measured memory_bytes: 74396
k,n = map(int, input().split())
lst = list(map(int, input().split()))

maxDis = (k-lst[-1]) + lst[0]
for i in range(n-1):
  if lst[i+1] - lst[i] > maxDis:
    maxDis = lst[i+1] - lst[i]
print(k-maxDis)

Measured memory_bytes: 26420
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int m,n,c[15],a[15][15],p[15],x,ans=2e9+7;
int main(){
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		for(int j=1;j<=m;j++) cin>>a[i][j];
	}
	while(p[0]==0)
	{
		int in[15]={0},mo=0;
		for(int i=1;i<=n;i++)
		{
			if(p[i]==1)
			{
				mo+=c[i];
				for(int j=1;j<=m;j++) in[j]+=a[i][j];
			}
		}
		int f=1;
		for(int i=1;i<=m;i++)
			if(in[i]<x) {f=0;break;}
		if(f==1) ans=min(ans,mo);
		for(int i=n;i>=0;i--)
		{
			if(p[i]==1) p[i]=0;
			else {p[i]=1;break;}
		}
	}
	if(ans!=2e9+7) cout<<ans;
	else cout<<-1;
    return 0;
}
//01枚举 

Measured memory_bytes: 3640
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;

string s;
ll dp[2][11][2];

int main(){
  while(cin >> s, s!="0"){
    int n = s.size();
    
    memset(dp,0,sizeof(dp));
    dp[0][0][0] = 1;

    for(int i=0;i<n;i++){
      int now = i&1, nxt = 1-now;
      for(int j=0;j<11;j++)dp[nxt][j][0] = dp[nxt][j][1] = 0;

      int val = s[i] - '0';
      dp[nxt][0][0] += dp[now][0][0] + dp[now][0][1];
      if(val)dp[nxt][val][1]++;
 
      for(int j=0;j<11;j++){
	dp[nxt][(j*10+val)%11][1] += dp[now][j][1];
      }
      /*
      for(int j=0;j<11;j++){
	cout << dp[nxt][j][0] << " ";
      }cout << endl;
      for(int j=0;j<11;j++){
	cout << dp[nxt][j][1] << " ";
      }cout << endl;
      cout << endl;
      */
    }

    cout << dp[n&1][0][0] + dp[n&1][0][1] -1 << endl;
  }
}

Measured memory_bytes: 1316
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>vec;
int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    cin>>x>>k>>d;
    if(x>=0)
    {
        y=x;
        y=y/d;
        y=min(y,k);
        x=x-(d*y);
        k-=y;
        if(k%2==1)
        {
            x-=d;
        }
    }
    else
    {
        y=abs(x);
        y=y/d;
        y=min(y,k);
        x=x+(d*y);
        k-=y;
        if(k%2==1)
        {
            x+=d;
        }
    }
    x=abs(x);
    cout<<x<<endl;
}



Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#define rep(i,n) for(int i = 0;i<(n);i++);
using namespace std;
using ll = long long;
const ll INF = 100100100100100;

int main() {
	ll H, W;
	cin >> H >> W;
	if (H == 1 || W == 1)cout << "1" << endl;
	else {
		if (H * W % 2 == 1) cout << H * W / 2 + 1 << endl;
		else cout << H * W / 2 << endl;
	}
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  string a ,b;
  if(s.size()%2!=0){
    cout << "No" << endl;
  }else{
    for(int i=0;i<=(n-1)/2;i++) a+=s[i];
    for(int i=(n-1)/2 + 1;i<=n-1;i++) b+=s[i];
    if( a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
}

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

keyStr=input()
keyence="keyence"
chkflg=False

for char in range(len(keyence)-1):
  before=keyence[0:char+1]
  after=keyence[char+1:len(keyence)]
  
  if keyStr.startswith(before) and keyStr.endswith(after):
    print("YES")
    chkflg=True
    break
  if keyStr.startswith(keyence) or keyStr.endswith(keyence):
    print("YES")
    chkflg=True
    break

if chkflg == False:
  print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;  cin >> a >> b >> c;
    vector<int> vec = {a, b, c};
    sort(vec.begin(), vec.end());
    if (vec[0]==vec[2]) cout << "1" << endl;
    else if (vec[0]==vec[1]) cout << "2" << endl;
    else if (vec[1]==vec[2]) cout << "2" << endl;
    else cout << "3" << endl;
}


Measured memory_bytes: 256
function main(input) {
  input=input.trim();
  const n = parseInt(input.split(" ")[0], 10);
  const a = parseInt(input.split(" ")[1], 10);
  const b = parseInt(input.split(" ")[2], 10);

  var ans=[]
  for(var i=1; i<=n; i++){
    var nagasa=String(i).length
    var wa=0
    for(var j=0; j<nagasa; j++){
      wa+=Number(String(i).substr(j,1))
    }
    if(wa>=a&&wa<=b){
      ans.push(i)
    }
  }
  //console.log(ans);
  console.log(ans.reduce((x,y)=>x+y));
}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 8244
var lines=[];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
const date = ['SUN','MON','TUE','WED','THU','FRI','SAT']
reader.on('line', function (line) {
  console.log(7 - date.indexOf(line))
  process.exit(0)
});

Measured memory_bytes: 7500
#include <stdio.h>

int main()
{
    int i,j;
    for (i=1; i<10;i++)
    {
        for (j=1;j<10;j++)
        {
            printf("%dx%d=%d",i,j,i*j);
            printf("\n");
        }
    }
    return 0;
}

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

namespace _2019APC
{
    class Program
    {
        static void Main(string[] args)
        {
            string n = Console.ReadLine();
            string h = Console.ReadLine();
            string w = Console.ReadLine();

            int N = int.Parse(n);
            int H = int.Parse(h);
            int W = int.Parse(w);

            int num = (N - H + 1) * (N - W + 1);

            Console.WriteLine(num);
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		sc.close();
		System.out.println(Math.sqrt(Integer.parseInt(a + b)) % 1 == 0 ? "Yes" : "No");
	}
}

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

int main() {
  int H,W = 0;
  cin >> H >> W;  
  vector<string> A(H);
  for(int i=0 ; i<W+2 ; i++){
    cout << "#";
  }
  cout << endl;
  for(int i=0 ; i<H ; i++){
    cin >> A.at(i);
    cout << "#" << A.at(i) << "#" << endl;
  }
  for(int i=0; i<W+2;i++){
    cout << "#";
  }
  cout << endl;
}

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

int main(){
	int n, ans;
	while(scanf("%d", &n) != EOF){
		ans = 0;
		for(int i = n; i < 600; i += n){
			ans += n * i * i;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)

int bubbleSort(int *A, int n)
{
	int c, f, i, j;

	c = 0;
	for (i = 0, f = 1; f; i++)
	{
		f = 0;
		for (j = n - 1; j >= i + 1; j--)
		{
			if (A[j] < A[j - 1])
			{
				swap(int, A[j], A[j - 1]);
				f = 1;
				c++;
			}
		}
	}
	return c;
}

int main()
{
	int c, i, n;
	int A[100];

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

	c = bubbleSort(A, n);

	for (i = 0; i < n; i++) {
		printf("%d", A[i]);
		if (i < n - 1) printf(" ");
	}
	printf("\n");

	printf("%d\n", c);

	return 0;
}

Measured memory_bytes: 1816
#include<iostream>
#include<complex>
#include<vector>
#include<cmath>

#define EPS 1.0e-9

using namespace std;

typedef double elem;
typedef complex<elem> point,vec;

inline elem cross(point a, point b){ return a.real()*b.imag()-a.imag()*b.real(); }
inline bool eq(elem a, elem b){return abs(b-a)<EPS; }
inline bool eqv(point a, point b){return abs(b-a)<EPS; }
inline elem dist(point a, point b, point x){ return abs(cross(b-a,x-a))/abs(b-a); }
inline bool intersected_seg(point a1, point a2, point b1, point b2){ return ( cross(a2-a1,b1-a1)*cross(a2-a1,b2-a1)<EPS && cross(b2-b1,a1-b1)*cross(b2-b1,a2-b1)<EPS ); }
inline point intersection_seg(point a1, point a2, point b1, point b2){ elem d1=dist(b1,b2,a1); elem d2=dist(b1,b2,a2); elem t=d1/(d1+d2); return a1 + t * ( a2 - a1 ); }

struct Area
{
	vector< pair<point, point> > seps;

	unsigned int add_sep(const point a, const point b)
	{
		int ret = 0;
		vector<point> vt;
		
		for(unsigned int i = 0; i < seps.size(); ++i)
		{
			if( intersected_seg( a, b, seps[i].first, seps[i].second ) )
			{
				bool bValid=true;
				point t = intersection_seg( a, b, seps[i].first, seps[i].second );
				
				for(unsigned int j = 0; j < vt.size(); ++j)
					if( eqv( vt[j], t ) )
						bValid=false;

				if( bValid )
					vt.push_back(t);
			}
		}
		seps.push_back( make_pair(a,b) );
		return vt.size();
	}
};


int main(){
	const int inix[] = {-100,100,100,-100};
	const int iniy[] = {100,100,-100,-100};

	while(true)
	{
		int n;
		int ans=1;
		Area area;
		
		cin>>n;
		if( n == 0 ) break;
		
		for(int i = 0; i < 4; ++i)
		{
			area.seps.push_back( make_pair(point(inix[i],iniy[i]), point(inix[(i+1)%4],iniy[(i+1)%4])) );
		}
		
		for(int i = 0; i < n; ++i)
		{
			elem x1,y1,x2,y2;
			
			cin>>x1>>y1>>x2>>y2;
			point a(x1,y1);
			point b(x2,y2);
			int t = area.add_sep(a,b);

			ans += t - 1;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 100
#define vmax 10000
#define sentinel 2000000000
#define INF (1<<30)
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
static const int NIL=-1;

//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

class UnionFind{

    vector<int> par;
    int groupcount;

public:
// UnionFind uf(n)でn要素のUF木uf
    UnionFind(int n=0){
        init(n);
    }

    //n要素で初期化
    void init(int n=0){
        par.resize(n);
        fill(par.begin(),par.end(),-1);
        groupcount=n;
        return;
    }

    //xが属する集合の根を求める
    int root(int x){
        if(par[x]<0){
            return x;
        }
        return par[x]=root(par[x]);
    }

    //xとyが同じ集合に属するかどうか調べる
    bool same(int x,int y){
        return root(x)==root(y);
    }

    //xが属する集合の大きさを求める
    int size(int x){                
        return -par[root(x)];
    }

    //xが属する集合とyが属する集合を繋ぐ
    //既に繋がっていたらfalseが返る
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y){
            return false;
        }
        if(par[y]<par[x]){ 
            swap(x,y);
        }
        par[x]+=par[y];     
        par[y]=x;
        --groupcount;
        return true;        
    }

    //UF内にある集合の個数を求める
    int size(void){
        return groupcount;
    }
};

int main() {
    int n,a,b,q,t;
    cin>>n>>q;
    UnionFind uf(n);
    for(int i=0;i<q;i++){
        cin>>t>>a>>b;
        if(t==0){
            uf.unite(a,b);
        }else{
            if(uf.same(a,b)){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
    return 0;
}






Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int sb[10][10000];

#define MAX (50000000)

int main(){
  int n,k;
  while(cin>>n>>k, n+k){
    int dist[n][n];
    REP(i,n) REP(j,n) dist[i][j] = MAX;
    REP(i,n) dist[i][i] = 0;
    while(k --> 0){
      int s; cin>>s;
      if(s == 0){
        int a,b;
        cin>>a>>b; a--; b--;
        if(dist[a][b] == MAX) cout << -1 << endl;
        else cout << dist[a][b] << endl;
      }else{
        int a,b,c;
        cin>>a>>b>>c; a--; b--;
        if(dist[a][b] < c) continue;
        dist[a][b] = dist[b][a] = c;
        REP(i,n){
          dist[a][i] = dist[i][a] = min(dist[a][i], dist[a][b] + dist[b][i]);
          dist[b][i] = dist[i][b] = min(dist[b][i], dist[b][a] + dist[a][i]);
        }
        REP(i,n) REP(j,n){
          dist[i][j] = min(dist[i][j], dist[i][a] + dist[a][j]);
          dist[i][j] = min(dist[i][j], dist[i][b] + dist[b][j]);
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int A, B;
	cin >> A >> B;
	cout << A * B;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)


int main() {
	long long n;
	cin >> n;
	list<pair<long long, long long>> li;
	for (long long i = 1, j = sqrt(n); i <= j; i++) {
		if (n % i == 0) li.push_back(make_pair(n / i, i));
	}
	long long ans = 1000000000000000LL;
	for (auto p : li) {
		if ((p.first + p.second - 2LL) < ans) ans = (p.first + p.second - 2LL);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<50000;i++){
        if(i*108/100==n){
            ans=i;
        }
    }
    if(ans==0){cout<<":("<<endl;}
    else{cout<<ans<<endl;}
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> inpts;
	map<int,int> rbt;
	for (int i=0; i<n; i++) {
		int a;
		cin >> a;
		if (rbt.find(a) == rbt.end()) {
			inpts.push_back(a);
			rbt[a] = 1;
		}
		else 
			rbt[a]++;
	}

	int cost = 0;
	for (int i=0; i<inpts.size(); i++) {
		if (rbt[inpts[i]] > inpts[i])
			cost += rbt[inpts[i]] - inpts[i];
		else if (rbt[inpts[i]] < inpts[i])
			cost += rbt[inpts[i]];
	}

	cout << cost << endl;

}

Measured memory_bytes: 5112
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,j,k,n,m,sss,sssss,dist[200];
char ppp,seat[200],next[200];


int main(){
	while(scanf("%d %d%*c",&n,&m)*n){
		for(k=0;k<n;k++){
			seat[k]='#';
			next[k]='#';
			dist[k]=99999;
		}
		seat[n]='\0';

		for(k=0;k<m;k++){
			scanf("%c%*c",&ppp);

			sss=-1;sssss=-1;
			switch(ppp){
				case 'A':
					for(i=0;i<n;i++){if(seat[i]=='#'){sss=i;break;}}
				break;
				case 'B':
					for(i=n-1;i>=0;i--){
						if(seat[i]=='#' && next[i]!='A'){sss=i;break;}
						if(sssss<0 && seat[i]=='#')sssss=i;
					}
					if(sss==-1)sss=sssss;
				break;
				case 'C':
					if(k==0)sss=n/2;
					else{
						for(i=0;i<n;i++){
							if(seat[i]!='#'){
								if(i+1<n && seat[i+1]=='#'){sss=i+1;break;}
								if(i-1>=0 && seat[i-1]=='#'){sss=i-1;break;}
							}
						}
					}
				break;
				case 'D':
					sssss=0;
					for(i=0;i<n;i++){
						if(dist[i]>sssss){sss=i;sssss=dist[i];}
					}
				break;
			}

			seat[sss]=ppp;
			if(sss>0)next[sss-1]=ppp;
			next[sss+1]=ppp;
			for(i=0;sss-i>=0;i++){if(dist[sss-i]>i)dist[sss-i]=i; else break;}
			for(i=1;sss+i<n;i++){if(dist[sss+i]>i)dist[sss+i]=i; else break;}


			//for(i=0;i<n;i++){printf("%c",seat[i]);}printf("\n");
			//for(i=0;i<n;i++){printf("%c",next[i]);}printf("\n");
			//for(i=0;i<n;i++){printf("%d",dist[i]);}printf("\n");
		}
		
		printf("%s\n",seat);
	}
	return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

ll dp[100005][2];

int main(void){
    string l;
    cin>>l;
    dp[0][0] = 1;
    rep(i,l.size()){
        if(l[i] == '0'){
            dp[i+1][1] = (dp[i][1] + 2*dp[i][1]) % mod;
            dp[i+1][0] = dp[i][0];
        }
        else{
            dp[i+1][1] = (3*dp[i][1]+dp[i][0])%mod;
            dp[i+1][0] = (2*dp[i][0])%mod;
        }
    }
    cout<<(dp[l.size()][0]+dp[l.size()][1])%mod<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int a, b, c;
  cin >> a >> b >> c;

  if (b - a == c - b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
for char in 'abcdefghijklmnopqrstuvwxyz':
    if char not in s:
        print(char)
        exit()
else:
    print('None')














Measured memory_bytes: 27216
#include <iostream>
#include <cstring>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <unordered_map>
#include <map>
#include <cmath>

#define MP make_pair
#define F first
#define S second
#define PB push_back

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    string s;
    int a, b;
    cin >> a >> b;
    cin >> s;
    int cnt = 0, cur = 0;
    int idx = -1;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == '-'){
            cnt ++; 
            idx = i + 1;
        }
    }   
    if (cnt == 1 and idx == a + 1)
        cout << "Yes" << endl; 
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

long long gcd(long long a, long long b){ // Ååöñ
    if(a == 0 || b == 0)
        return 0;
    if(b > a)
        swap(a, b);
    long long tmp;
    while((tmp = a % b) != 0){
        a = b;
        b = tmp;
    }
    return b;
}

long long lcm(long long a, long long b){ // Å¬ö{
    return a / gcd(a, b) * b;
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

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

        long long num = 0;
        long long sum = 0;
        for(int i=0; i<(1<<m); ++i){
            bitset<20> bs(i);
            long long x = 1;
            for(int j=0; j<m; ++j){
                if(bs[j]){
                    x = lcm(x, p[j]);
                    if(x > n){
                        x = -1;
                        break;
                    }
                }
            }
            if(x == -1)
                continue;

            long long y = n / x;
            if(bs.count() % 2 == 0){
                num += y;
                sum += y * (y+1) / 2 * x;
            }else{
                num -= y;
                sum -= y * (y+1) / 2 * x;
            }
        }

        if(num == 0)
            cout << 0 << endl;
        else
            printf("%.10f\n", (double)sum / num);
    }
}

Measured memory_bytes: 980
import pdb

def main():
    param = list(map(int, input().split()))

    n = param[0]
    m = param[1]

    data = []
    for i in range(n):
        param = list(map(int, input().split()))
        data.append(param)

    data.sort(key=lambda data:data[0])

    ans = 0
    for i in range(n):
        if m <= data[i][1]:
            ans += m * data[i][0]
            break
        else:
            ans += data[i][1] * data[i][0]
            m -= data[i][1]

    print(ans)
    
    return

        
if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, m; cin >> n >> m;
    vector<pair<ll,int>> ab(n);
    rep(i,n) cin >> ab[i].first >> ab[i].second;
    
    sort(all(ab));
    bool can = true;
    int itr = 0;
    ll cnt = 0;
    while(can){
        m--;
        if(ab[itr].second == 0) itr++;
        cnt += ab[itr].first;
        ab[itr].second--;
        if(m == 0) can = false;
    }
    
    cout << cnt << '\n';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int n;
VI pena;
VVI gain;
int eval(VI &order)
{
    VI last(26, -1);
    int ret = 0;
    rep(i, n)
    {
        ret += gain[i][order[i]];
        last[order[i]] = i;
        rep(j, 26)
        {
            ret -= pena[j] * (i - last[j]);
        }
    }
    return ret;
}
void print(VI &order)
{
    for (auto &&x : order)
    {
        cout << x + 1 << endl;
    }
}

void search()
{
    typedef pair<int, VI> Tact;
    priority_queue<Tact> pque;
    VI base(n);
    VI last(26, -1);
    rep(i, n)
    {
        int cur = -IINF;
        int penasum = 0;
        rep(j, 26)
        {
            penasum += pena[j] * (i - last[j]);
        }
        rep(j, 26)
        {
            if (cur < gain[i][j] - penasum + pena[j] * (i - last[j]))
            {
                base[i] = j;
                cur = gain[i][j] - penasum + pena[j] * (i - last[j]);
            }
        }
        last[base[i]] = i;
    }
    print(base);
    cerr << eval(base) << endl;
    ;
}
int main()
{
    cin >> n;
    pena = VI(26);
    gain = VVI(n, VI(26));
    rep(i, 26)
    {
        cin >> pena[i];
    }
    rep(i, n)
    {
        rep(j, 26)
        {
            cin >> gain[i][j];
        }
    }
    search();
    return 0;
}

Measured memory_bytes: 3684
#include<stdio.h>
int main()
{
	int A,B,C,D;
	1<=A,B,C,D && A,B,C,D<=10;
	scanf("%d%d%d%d",&A,&B,&C,&D);
    int sum1=A+B;
    int sum2=C+D;
    if(sum1==sum2)
    	printf("Balanced");
    if(sum1>sum2)
    	printf("Left");
    if(sum1<sum2)
    	printf("Right");
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		int x=Integer.parseInt(br.readLine());
		int i=0;

		while(x!=0) {
			i++;
			System.out.println("Case "+i+": "+x);
			x=Integer.parseInt(br.readLine());
		}
	}
}


Measured memory_bytes: 31332
#include<bits/stdc++.h>
using namespace std;
int a[200010],inn[200010];
vector <int> des[200010];
int dfs(int s,int pre)
{
	if (inn[s]==1) return a[s];
	vector <int> vec;long long sum=0;
	for (int k=0;k<des[s].size();k++) if (des[s][k]!=pre)
	{
		int d=dfs(des[s][k],s);
		sum+=d;if (d>a[s]) {puts("NO");exit(0);}
	}
	if ((sum>2*a[s])||(sum<a[s])) {puts("NO");exit(0);}
	return 2*a[s]-sum;
}
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	if (n==2) {puts((a[1]==a[2])?"YES":"NO");return 0;}
	for (int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		des[u].push_back(v);des[v].push_back(u);
		inn[u]++;inn[v]++;
	}
	int root=1;while (inn[root]==1) root++;
	if (dfs(root,0)) {puts("NO");exit(0);}
	puts("YES");
}

Measured memory_bytes: 16128
from sys import stdin
from collections import defaultdict
n = int(stdin.readline())
a = stdin.readline().split()
d = defaultdict(int)
for x in a:
    d[x] += 1
m = int(stdin.readline())
a = stdin.readline().split()
for x in a:
    d[x] -= 1
    if d[x] < 0:
        print "NO"
        quit()
print "YES"


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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};

const ll mod=1000000000+7;
const int MAX_N=1000;

int main(){
	string s;
	cin>>s;
	bool flag[4];
	fill(flag,flag+4,false);
	REP(i,s.size()){
		if(s[i]=='N')flag[0]=true;
		if(s[i]=='S')flag[1]=true;
		if(s[i]=='E')flag[2]=true;
		if(s[i]=='W')flag[3]=true;
	}
	string ans;
	if((flag[0] && !flag[1]) || (!flag[0] && flag[1])){
		ans="No";
	}else if((flag[2] && !flag[3]) || (!flag[2] && flag[3])){
		ans="No";
	}else{
		ans="Yes";
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	s := nextString()
	ans := ""
	for i := 0; i < len(s); i += 2 {
		ans += string(s[i])
	}
	fmt.Println(ans)
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
int n,m,q;
vector<vector<int>> g;
void dfs(vector<int> c){
    int f = c.size();
    if(f==n) g.push_back(c);
    else{
        for(int i=c[f-1];i<=m;i++){
            vector<int> b = c;
            b.push_back(i);
            dfs(b);
        }
    }
}
int main(void){
    long ans = 0;
    cin >> n >> m >> q;
    vector<int> e;
    int a[q],b[q],c[q],d[q];
    for(int i=0;i<q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        b[i]--;a[i]--;
    }
    e.push_back(1);
    dfs(e);
    for(auto i:g){
        long cur = 0;
        for(int j=0;j<q;j++){
            if(i[b[j]]-i[a[j]]==c[j]) cur += d[j];
        }
        ans = max(ans,cur);
    }
    cout << ans << endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s;
    cin >> s;

    int n = s.size();
    int cnt = 0;
    ll ans = 0;
    REP(i, n) {
        if (s[i] == 'W') {
            ans += i - cnt;
            cnt++;
        }
    }

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


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,d,x,dp[2001][2001];
const ll mod = 1e9+7;
 
ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}
 
ll nCr(ll n,ll r){
  ll N=1,K=1; 
  for(int i=0;i<r;i++) N=N*((n-i)%mod)%mod,K=K*((r-i)%mod)%mod;
  ll R=mod_pow(K,mod-2);
  return N*R%mod;
}
 
int main(){
  while(1){
    cin>>n>>d>>x;
    if(!n&&!d&&!x) break;
 
    memset(dp,0,sizeof(dp));  
    for(int i=0;i<x;i++) dp[0][i]=1;
 
   
    for(int i=1;i<=min(d,n);i++){
      ll sum=0;
      for(int j=i+1;j<=n;j++){
	if(j-x>=i)sum=(sum-dp[i-1][j-x]+mod)%mod;
	sum=(sum+dp[i-1][j-1])%mod; 
	dp[i][j]=sum;
      }
    }
     
    ll ans=0;
    for(int i=0;i<min(d,n);i++)
      if(dp[i][n]) ans=(ans+dp[i][n]*nCr(d,i+1)%mod)%mod;
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 34336
#include<bits/stdc++.h>
#define int long long  
#define PI 3.14159265358979323846
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb emplace_back
#define watch5(a,b,c,d,e) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d << " | "<<#e<<": "<<e<<endl;
#define watch4(a,b,c,d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define watch3(a,b,c) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define watch2(a,b) cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define watch(a) cerr <<#a<<": "<<a<<endl;
#define F first
#define S second
#define mod 1073741824
using namespace std;

int32_t main(){
	IOS
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int ans = 0;
	for(int i = 1;i < n; i++){
		if(a[i] < a[i-1]){
			ans += (a[i-1]-a[i]);
			a[i] = a[i-1];
		}
	}
	cout << ans;
}																				

Measured memory_bytes: 5216
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Ruby 1st Try
si = gets.chomp.split('')
lengthm = si.size-1
apos = 0
zpos = si.size-1
0.step(lengthm,+1){|j|
    if si[j] == 'A'
        apos = j
        break
    end
}
lengthm.step(0,-1){|j|
    if si[j] == 'Z'
        zpos = j
        break
    end

}
# p zpos
# p apos
answer = (zpos-apos)+1
puts(answer)


Measured memory_bytes: 16764
#include<iostream>//cinなど
#include<string>//文字列
#include<algorithm>//sort など
#include<math.h>//paw(冪乗など)
#include<set>// 集合
#include<map>//写像
#include<stdio.h>//printf
#include<stack>

using namespace std;
int main(){
  string a;
  cin>>a;
  string ans = "";
  for(int i = 0; i < 19; i++){
    if(i== 5 || i==13){
      ans += " ";
    }else{
      ans += a[i];
    }
  }

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


Measured memory_bytes: 256
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0) break;

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

    double m = (double)sum / n;
    double sg2 = 0.0;

    for (int i = 0; i < n; i++) {
      double d = (double)as[i] - m;
      sg2 += d * d;
    }

    printf("%.8lf\n", sqrt(sg2 / n));
  }
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

int main(void) {
	char  S[7];
	int   i, cnt=0;
	s_cin(S);
	for (i = 0; i < 6; i++) 
		if (S[i] == '1') cnt++;

	i_cout(cnt);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}




void oneCase () {
    int x;
    cin >> x;
    if (x < 1200) {
        cout << "ABC" <<"\n";
    } else {
        cout << "ARC" << "\n";
    }
}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 256