akhauriyash/Code-Regression huggingface dataset:
N, Z, W = map(int, input().split())
a = [0]*N
*a, = map(int, input().split())

dpx = [0]*(N+1)
dpy = [0]*(N+1)
x = [Z]+a[:]
y = [W]+a[:]

for i in range(1, N+1):
    if i == 1:
        dpx[i] = abs(x[N] - y[N-1])
        dpy[i] = abs(y[N] - x[N-1])
    else:
        dpx[i] = max([abs(x[N] - y[N-i])] + [dpy[j] for j in range(1,i)])
        dpy[i] = min([abs(y[N] - x[N-i])] + [dpx[j] for j in range(1,i)])

print(dpx[N])

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

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long

#define MAX 100000
#define INF 100000000


class Edge {
public:
	int goTo,weight;
	Edge() {}
	Edge(int t,int w):goTo(t),weight(w){}
};

//???
vector<Edge> graph[MAX];

//????´???°??¨?????¢
int n,dist[MAX];

bool vis[MAX];
int cnt;

//??±???????????¢?´¢
void dfs(int s) {
	//?????????
	REP(i, n)dist[i]=INF;
	queue<int> Q;
	Q.push(s);
	dist[s]=0;
	int u;     //?????¨??°

	//?¨????
	while (!Q.empty()) {
		u=Q.front();Q.pop();
		//?????¨??°?????????????????????????????¨??¢?´¢
		REP(i,graph[u].size()){
			Edge e=graph[u][i];
			//???????????¨???????????¢?´¢???????????¢????¨???\???????§???????
			if (dist[e.goTo] == INF) {
				dist[e.goTo]=dist[u]+e.weight;
				Q.push(e.goTo);
			}
		}
	}
}

void solve() {
	//???????????????s(=0)????????????????????????target????±??????????
	dfs(0);
	int maxValue=0;
	int target=0;
	REP(i, n) {
		//???????????????????????¨???????????????
		if(dist[i]==INF)continue;
		//????????????????????????????????´??°?????????
		if (maxValue < dist[i]) {
			maxValue=dist[i];
			target=i;
		}
	}
	//???????????§??§??????????????????????????????????????????(target)???????????£??????

	//??????????????????target????????????????????????????????¢maxValue????±??????????
	dfs(target);
	maxValue=0;
	REP(i, n) {
		if(dist[i]==INF)continue;
		maxValue=max(maxValue,dist[i]);
	}
	//??????????±??????£????????§??????
	cout<<maxValue<<endl;
}

int main() {
	//??\???
	int s,t,w;
	cin>>n;
	REP(i, n - 1) {
		cin>>s>>t>>w;
		graph[s].push_back(Edge(t, w));
		graph[t].push_back(Edge(s, w));
	}
	//??????
	solve();
	cin>>n;
}

Measured memory_bytes: 9888
n = int(input())
f = [input().replace(" ", '') for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

outcome_list = []
for i in range(1, 1 << 10):
    outcome = 0
    for j, x in enumerate(f):
        both = "{:010b}".format(i & int(x, 2))
        n_store = sum(map(int, list(both)))
        outcome += p[j][n_store]
    outcome_list.append(outcome)
print(max(outcome_list))

Measured memory_bytes: 3064
(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])
 
for i in range(m):
    b.append(int(input()))
 
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)

Measured memory_bytes: 7012
#include<iostream>
#include<algorithm>
int  a, b, c, d;
int main() {
	std::cin >> a >> b >> c >> d;
	if (a + b > c + d)std::cout << "Left" << std::endl;
	if (a + b < c + d)std::cout << "Right" << std::endl;
	if (a + b == c + d)std::cout << "Balanced" << std::endl;
	return 0;
}

Measured memory_bytes: 256
import collections as ct

n = int(input())

def calc(x):
    num = 1
    ref = 0

    while num <= x:
        x -= num
        ref += 1
        num += 1
    
    return ref

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = ct.Counter(prime_factorize(n))
d = list(c.values())
ans = list(map(calc,d))

print(sum(ans))

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

int main(void)
{
	int f1, n, p, cnt, *J;
	unsigned int k, sum, max;

	while( scanf("%d", &n) && n > 0)
	{	
		J = new int [n - 1];
		sum = 0;
		cnt = 1;
		for(f1 = 0; f1 < n; f1++)
		{
			scanf("%d", &p);
			sum += p;
		}
		for(f1 = 0; f1 < n-1; f1++)
		{
			scanf("%d", &p);
			sum += p;
			J[f1] = p;
		}

		max = sum;
		sort(J, J + (n - 1)); //平均O(nlogn)
		for(f1 = 0; f1 < n - 1; f1++)
		{
			sum -= J[f1];
			k = ++cnt * sum;

			if(k > max)
				max = k;
		}
		printf("%u\n", max);
	}

	return 0;
}

Measured memory_bytes: 2116
N = int(input())
A = list(map(int, input().split()))
for i in range(1, N):
    print(*A)
    for j in range(i):
        if A[j] > A[i]:
            break
    else:
        continue
    tmp = A[i]
    for k in range(i, j, -1):
        A[k] = A[k - 1]
    A[j] = tmp
print(*A)



Measured memory_bytes: 5984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
	int n;
	ll a, b;
	cin >> n >> a >> b;
	ll ans = 0, prevx;
	cin >> prevx;
	rep(i,n-1){
        ll x;
        cin >> x;
        ans += min(a*(x - prevx), b);
        prevx = x;
	}
	cout << ans << endl;
}


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

a = list((map(int, input().split())))
a = [0] + a + [0]

totalcost = 0
for i in range(len(a) - 1):
    totalcost += abs(a[i] - a[i+1])

for i in range(1, n+1):
    icost = totalcost + abs(a[i-1] - a[i+1]) - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1])
    print(icost)

Measured memory_bytes: 13920
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, L, R; cin >> N >> M;
  int min_ans=1, max_ans=100000;
  for (int i=0; i<M; i++) {
    cin >> L >> R;
    min_ans = max(min_ans, L);
    max_ans = min(max_ans, R);
  }
  cout << max(max_ans-min_ans+1,0) << "\n";
}

Measured memory_bytes: 256
package main

import "fmt"

var n, a, b, extDmg int
var monsters []int

func main() {
	fmt.Scan(&n, &a, &b)
	extDmg = a - b
	monsters = make([]int, n)

	maxHP := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&(monsters[i]))
		if maxHP < monsters[i] {
			maxHP = monsters[i]
		}
	}
	maxCount := maxHP/b + 1
	minCount := 0

	ans := maxCount
	trial := maxCount
	for {
		if ok(trial) {
			maxCount = trial
			if trial < ans {
				ans = trial
			}
		} else {
			minCount = trial
		}

		if maxCount-minCount == 1 {
			break
		}
		trial = (maxCount-minCount)/2 + minCount
	}

	fmt.Println(ans)
}

func ok(count int) bool {
	remainingCount := count
	for i := 0; i < n; i++ {
		remainingHP := monsters[i] - count*b
		if remainingHP <= 0 {
			continue
		}
		quotient := remainingHP / extDmg
		remainder := remainingHP % extDmg
		if remainder > 0 {
			quotient += 1
		}
		remainingCount -= quotient

		if remainingCount < 0 {
			return false
		}
	}
	return true
}

// nの階乗(mod M) ただしMは素数
// return: nまでの階乗を示す全値(e.g., fact[5] = 5!を示す値)
func mfactorial(n int, M int) []int {
	fact := make([]int, n+1)
	fact[0] = 1
	for i := 1; i <= n; i++ {
		fact[i] = (fact[i-1] * i) % M
	}
	return fact
}

// x^n (mod M) ただしMは素数
// See https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
func mpow(x, n, M int) int {
	ans := 1
	for n != 0 {
		if n&1 == 1 {
			ans = ans * x % M
		}
		x = x * x % M
		n = n >> 1
	}
	return ans
}

// nCk (mod M) ただしMは素数
// @see https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
func combi(n, k, M int) int {
	return commonPermutationAndCombination(n, k, M, true)
}

// nPk (mod M) ただしMは素数
// @see https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
func permutation(n, k, M int) int {
	return commonPermutationAndCombination(n, k, M, false)
}

func commonPermutationAndCombination(n, k, M int, combi bool) int {
	if n == 0 && k == 0 {
		return 1
	} else if n < k || n < 0 {
		return 0
	}
	fact := mfactorial(n, M)

	ans := fact[n] * mpow(fact[n-k], M-2, M) % M
	if combi {
		ans *= mpow(fact[k], M-2, M) % M
	}

	return ans % M
}


Measured memory_bytes: 5504
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
#include<ctime>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>

using namespace std;
typedef long long ll;
#define MP make_pair

int main(void) {
    int n,m,a[50000]={},sum=0;
    cin>>n>>m;

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

    if(sum>n)cout<<"-1\n";
    else cout<<n-sum<<"\n";


    
    return 0;
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int32_t main()
{
	k_007();
	int n, m;
	cin >> n >> m;
	if (n <= m)
	{
		f(i, m) cout << n;
	}
	else
	{
		f(i, n) cout << m;
	}
}


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

Measured memory_bytes: 3488
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define in inline
#define reg register
#define int long long
#define MAX 20030813
using namespace std;
namespace qwq{
	in void read(int &o) {
		o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9') {
			if(c=='-')w*=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9') {
			o=(o<<3)+(o<<1)+(c^48);c=getchar();
		}
		o*=w;
	}
	void write(int x){
	   	if(x<0)putchar('-'),x=-x;
    	if(x>9)write(x/10);
		putchar(x%10+48);
	}
	void Write(int x) {
		write(x);putchar(' ');
	}
	in int max(int x,int y){return x>y?x:y;}
	in int min(int x,int y){return x<y?x:y;}
}
using namespace qwq;
int r; 
signed main()
{
	read(r);
	write(3*r*r);
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#define ll long long
         
using namespace std;
     
long long gcd(int x, int y){
     if ( x == 0 ) return y;
     
     return gcd(y%x, x);
}
     
long long lcm(int x, int y){
     if ( y == 0 ){
          return x;
     }
     
     return x*y/gcd(x, y);
}
     
int min(int a, int b){
     return a > b ? b : a;
}
     
int max(int a, int b){
     return a > b ? a : b;
}

int main()
{
     cin.sync_with_stdio( false );

     int n;
     cin>>n;

     ll res = 0;
     map <ll, ll> m;
     for (int i=0;i<n;i++){
          int a;
          cin>>a;
          res+=m[i-a];
          m[i+a]++;
     }

     cout<<res<<endl;
}

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

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main()
{
    string s;
    cin >> s;
    
    vector<int> ans;
    int countR = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'R' && s[i+1] == 'L')
        {
            int countL = 0;
            for (int k = i+2; k < s.size(); k++)
            {
                if (s[k] == 'L')
                {
                    countL++;
                }
                else
                {
                    break;
                }
            }

            int numR = countR/2;
            int numL = countL/2;
            ans.push_back(numR + (countL - numL)+1);
            ans.push_back(countR - numR + numL+1);
            countR = 0;
            i++;
        }
        else
        {
            ans.push_back(0);
            if (s[i] == 'R')
            {
                countR++;
            }
        }
        
    }

    for (int i = 0; i < ans.size(); i++)
    {
        if (i == ans.size()-1)
        {
            cout << ans[i] << endl;
        }
        else
        {
            cout << ans[i] << " ";
        }
    }
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
  int n;
  cin >> n;
  if(n%2==0){
    cout << n*(n-1)/2 - n/2 << endl;
    FOR(i,1,n){
      FOR(j,i,n){
        if(i==j) continue;
        if(i+j==n+1) continue;
        cout << i << " " << j << endl;
      }
    }
  }

  else{
    cout << n*(n-1)/2 - (n-1)/2 << endl;
    FOR(i,1,n){
      FOR(j,i,n){
        
        if(i==j) continue;
        if(i+j==n) continue;
        cout << i << " " << j << endl;
      }
    }
  }
}



Measured memory_bytes: 256
S = raw_input()
f1 = f2 = f3 = False
for s in S:
    if s.isdigit(): f1 = True
    if s.isupper(): f2 = True
    if s.islower(): f3 = True
print "VALID" if len(S) >= 6 and f1 and f2 and f3 else "INVALID"

Measured memory_bytes: 6436
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("gymnastics.in", "r", stdin)
#define fout freopen("gymnastics.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
LL a, b, c, d = 1, e;
STR ss;

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin >> a >> b >> c;
    if (c - b >= 2) {
        d += min(a, b - 1);
        a -= d - 1;
        (a < 2) ? cout << d + a << '\n' : cout << (a / 2) * (c - b) + (a % 2) + d << '\n';
    }
    else cout << a + 1 << endl;
    ///time;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int main(){
	int sum=0,M=-1;
	for(int i=0;i<3;i++){
		int n;
		cin>>n;
		sum+=n;
		M=max(M,n);
	}
	if(sum==2*M) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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


int main(int argc, const char * argv[]) {

    int x, a, b;
    cin >> x >> a >> b;
    if(abs(a-x) > abs(b-x)){
        cout << "B" << endl;
    }else{
        cout << "A" << endl;
    }
    return 0;
}


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

# abs(x):数の絶対値を返します。引数は整数または浮動小数点数です。

# aからcまでの距離：abs(a - c)
# aからbまでの距離：abs(a - b)
# bからcまでの距離：abs(b - c)

# aからcまでの距離が、dよりも短い場合Yes
if abs(a - c) <= d:
    print('Yes')

# aからbまでの距離と、bからcまでの距離が、dよりも短い場合もYes
elif abs(a - b) <= d and abs(b - c) <= d:
    print('Yes')

else:
    print('No')


Measured memory_bytes: 9072
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

template<class T>
inline istream& operator >>( istream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) { s >> v[i]; }
	return s;
}

template<class T>
inline ostream& operator <<( ostream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) {
		if( i ) { s << ' '; }
		s << v[i];
	}
	return s;
}


int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;
	vector<int> a( n );
	cin >> a;
	a.erase( unique( a.begin(), a.end() ), a.end() );
	cout << a << endl;

	return 0;
}



Measured memory_bytes: 3324
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.size();
    ll ans = N;
    rep(i,0,N-1){
        if(S[i] != S[i+1]){
            ans = min(ans, max(i+1, N - (i+1)));
        }
    }
    print(ans);
    

}

Measured memory_bytes: 512
// ABC049B - たてなが

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	int H, W;
	cin >> H >> W;
	string s[H];
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}

	for (int i = 0; i < H; i++) {
		cout << s[i] << "\n" << s[i] << endl;
	}

	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

const int nmax = 100010;
vector<int> tree[nmax];

int deg[nmax],used[nmax];

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

	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		tree[a - 1].push_back(b - 1);
		tree[b - 1].push_back(a - 1);
		deg[a - 1]++, deg[b - 1]++;
	}

	queue<int> q;
	rep(v, n) if (deg[v] == 1) q.push(v);

	bool fwin = false;

	while (!q.empty()) {
		int v = q.front(); q.pop();
		if(deg[v]==0) continue;

		int u = -1;
		for (auto &to : tree[v]) {
			if (deg[to] == 0) continue;
			u = to;
		}

		//cout << v << " " << u << endl;

		if (u == -1) {
			fwin = true;
			break;
		}

		deg[v] = 0, deg[u] = 0;
		
		for(auto &to :tree[u]){
			if (deg[to] == 0) continue;
			deg[to]--;
			if(deg[to]==1) q.push(to);
			if(deg[to]==0) fwin = true;
		}
	}

	if (fwin)
		puts("First");
	else
		puts("Second");

	return 0;
}

Measured memory_bytes: 6400
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#define SIZE 2005
#define MX 10005

using namespace std;

char instr[MX];
string str[SIZE];
bool dp[2][MX];
bool can[SIZE][MX];
int gt[MX*2];
string ans;

string get_in()
{
	scanf("%s",&instr);
	string ret=instr;
	return ret;
}
void Z_algo(string s)
{
	gt[0]=0;
	int c=0;
	for(int i=1;i<=s.size();i++)
	{
		if(i+gt[i-c]<c+gt[c]) gt[i]=gt[i-c];
		else
		{
			int to=max(0,c+gt[c]-i);
			while(i+to<s.size()&&s[i+to]==s[to]) to++;
			gt[i]=to;
			c=i;
		}
	}
	gt[0]=s.size();/*
	printf("%s\n",s.c_str());
	for(int i=0;i<=s.size();i++) printf("%d ",gt[i]);puts("");*/
}
int main()
{
	int n,K;
	scanf("%d %d",&n,&K);
	for(int i=0;i<n;i++) str[i]=get_in();
	can[n][0]=true;
	for(int i=n-1;i>=0;i--)
	{
		for(int j=0;j<=K;j++)
		{
			if(can[i+1][j])
			{
				can[i][j]=true;
				if(j+str[i].size()<=K) can[i][j+str[i].size()]=true;
			}
		}
	}
	int pos=0;
	memset(dp,false,sizeof(dp));
	dp[pos][0]=true;
	for(int i=0;i<n;i++)
	{
		//printf("%s\n",ans.c_str());
		//for(int j=0;j<=K;j++) printf("%d ",dp[pos][j]);puts("");
		pos^=1;
		memset(dp[pos],false,sizeof(dp[pos]));
		Z_algo(str[i]+ans);
		int bef=-1;
		for(int j=0;j<=K;j++)
		{
			if(!dp[pos^1][j]||j+str[i].size()>K||!can[i+1][K-(j+str[i].size())]) continue;
			if(bef==-1) bef=j;
			else//bef+Sとj+Sを比較 -> |bef|～j-1までとSがどれだけ一致するか
			{
				int to;
				int len=min(gt[str[i].size()+bef],(int) str[i].size());
				if(len<j-bef) to=bef+len;
				else
				{
					len=min(gt[j-bef],(int) str[i].size()-(j-bef));
					to=j+len;
				}
				//printf("* %d %d : %d %d\n",bef,j,to,len);
				if(to==bef+str[i].size()) bef=j;
				else
				{
					char l=str[i][to-bef];
					char r=to<j?ans[to]:str[i][to-j];
					if(l>r) bef=j;
				}
			}
		}//+Sするときの最小の中での最大を求めた
		if(bef==-1)
		{
			pos^=1;
			continue;
		}
		bool up=true;
		for(int j=K;j>=0;j--)
		{
			if(!dp[pos^1][j]||!can[i+1][K-j]) continue;
			//jまでとbef+S比較
			if(j<=bef) break;
			int len=min(gt[str[i].size()+bef],min((int) str[i].size(),j-bef));
			if(bef+len==bef+str[i].size()) up=false;
			else
			{
				if(bef+len<j)
				{
					char l=str[i][len];
					char r=ans[bef+len];
					if(l>r) up=false;
				}
			}
			break;
		}
		if(!up)
		{
			for(int j=0;j<=K;j++)
			{
				dp[pos][j]=dp[pos^1][j]&&can[i+1][K-j];
			}
			continue;
		}
		//printf("%d\n",bef);
		ans.resize(bef);
		ans+=str[i];
		for(int j=0;j<=bef;j++)
		{
			if(!dp[pos^1][j]||!can[i+1][K-(j+str[i].size())]) continue;
			//bef+Sとj+Sを比較
			int to;
			int len=min(gt[str[i].size()+j],(int) str[i].size());
			if(len<bef-j) to=j+len;
			else
			{
				len=min(gt[bef-j],(int) str[i].size()-(bef-j));
				to=bef+len;
			}
			if(to==j+str[i].size()) dp[pos][j+str[i].size()]=true;
		}
		//このままでokのやつも追加
		for(int j=0;j<bef+str[i].size();j++)
		{
			if(!dp[pos^1][j]||!can[i+1][K-j]) continue;
			if(j<=bef) dp[pos][j]=true;
			else
			{
				int len=min(gt[str[i].size()+bef],j-bef);
				dp[pos][j]=bef+len==j;
			}
		}
	}
	printf("%s\n",ans.c_str());
	return 0;
}


Measured memory_bytes: 20992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds;
using namespace std;
#define pi pair<int,int>
#define ff first
#define ss second
#define int long long
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"

typedef tree<
   int, 
   null_type,
   less_equal<int>,
   rb_tree_tag, 
   tree_order_statistics_node_update
>ordered_set; 

ordered_set s;

int find_mediun() {
	int x = (s.size() - 1) / 2;
	int ans=*s.find_by_order(x);
	return ans;
}

int32_t main() {
	boost;
	int n;
	cin>>n;
	int c = 0;
	multiset<int>l,r;
	int left = 0,right = 0,mid = 0 ;
	while(n--) {
		int t;
		cin>>t;
		if(t == 1) {
			int a,b;
			cin >> a >> b;
			c += b;
			s.insert(a);
			mid = find_mediun();
			if(a >= mid){
				r.insert(a);
				right += a;
			}
			else{
				l.insert(a);
				left += a;
			}

			while(!l.empty() && *l.rbegin() > mid) {
				int tt = *l.rbegin();
				l.erase(l.find(tt));
				left -= tt;
				right += tt;
				r.insert(tt);
			} 

			while(!r.empty() && *r.begin() < mid ) {
				int tt = *r.begin();
				r.erase(r.find(tt));
				left += tt;
				right -= tt;
				l.insert(tt);
			}
		}
		else{
			int ans = mid * l.size() - mid * r.size() - left + right;
			cout<< mid << " " << ans + c <<endl;
		}
	}
}

Measured memory_bytes: 25500
#include <bits/stdc++.h>
#define max(a,b) (a>b?a:b)
#define S(x,y) (s[x][y]+s[x][y+1]+s[x+1][y]+s[x+1][y+1])
using namespace std;
const int N=2050;
int s[N][N],f[N][N];
int gc(){
  char ch=getchar();
  while(ch!='.'&&ch!='#') ch=getchar();
  return ch=='#';
}
struct date{
  int l,s;
}st[N];
int main(){
  int n,m; cin>>n>>m;
  for (int i=1; i<=n; ++i)
    for (int j=1; j<=m; ++j)
      s[i][j]=gc();
  for (int i=n-1; i>=1; --i)
    for (int j=m-1; j>=1; --j)
      if (!(S(i,j)&1))
	f[i][j]=f[i+1][j]+1;
  for (int i=1; i<=n; ++i)
    for (int j=1; j<=m; ++j)
      ++f[i][j];
  int ans=max(n,m);
  for (int i=1; i<n; ++i){
    int top=0,len;
    for (int j=1; j<m; ++j){
      len=0;
      while(top&&st[top].l>f[i][j])
	ans=max(ans,st[top].l*(st[top].s+len+1)),len+=st[top].s,--top;
      st[++top]=(date){f[i][j],len+1};
    }
    while(top) ans=max(ans,st[top].l*(st[top].s+1)),st[top-1].s+=st[top].s,--top;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 33024
#include<stdio.h>
int main(void)
{
	int w[10],k[10];
	int i,j;
	int s,s1;
	int temp;
	for(i=0;i<10;i++){
		scanf("%d",&w[i]);
	}
	for(i=0;i<10;i++){
		scanf("%d",&k[i]);
	}
		for(i=0;i<9;i++){
			for(j=i+1;j<10;j++){
				if(w[i]<w[j]){
				temp=w[i];
				w[i]=w[j];
				w[j]=temp;
				}
			}
		}
			s=w[0]+w[1]+w[2];
		for(i=0;i<9;i++){
			for(j=i+1;j<10;j++){
				if(k[i]<k[j]){
				temp=k[i];
				k[i]=k[j];
				k[j]=temp;
				}
			}
		}
			s1=k[0]+k[1]+k[2];
	printf("%d %d\n",s,s1);
	return 0;
}

Measured memory_bytes: 1024
N = gets.to_i
S = Array.new(N){gets.chomp}
M = gets.to_i
T = Array.new(M){gets.chomp}

C = Hash.new(0)
S.each do |s|
    C[s] += 1
end
T.each do |s|
    C[s] -= 1  
end

puts [C.values.sort[-1], 0].max

Measured memory_bytes: 1788
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from operator import itemgetter

N = int(input())
AB = sorted([[int(i) for i in input().split()] for _ in range(N)], key=itemgetter(1))

time = 0
for a,b in AB:
    time += a
    if time <= b:
        continue
    else:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 42748
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
#define int ll
void solve(){
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return;
}
#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <queue>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl
 
//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)
 
constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;
 
int main(){
 
    long long int n, w;
    scanf("%lld %lld", &n, &w);
    vector<pair<long long int, long long int >> bg(n);//value,weight
    REP(i,n){
        scanf("%lld %lld", &bg[i].first, &bg[i].second);
    }
    vector<long long int> dp(n*100+1,-1);
    dp[0] = 0;

    REP(i,n){
            DEFOR(j,n*100+1,0){
            if(dp[j]>=0&&dp[j]+bg[i].second<=w){
                if(dp[j + bg[i].first]==-1){
                    dp[j + bg[i].first] = dp[j] + bg[i].second;
                }else{
                    dp[j + bg[i].first] = min(dp[j] + bg[i].second,dp[j + bg[i].first]);
                }
            }
        }
    }



    DEFOR(i,n*100+1,0){
        if(dp[i]>=0){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3292
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    ll I, O, T, J, L, S, Z; cin >> I >> O >> T >> J >> L >> S >> Z;
    
    ll a = 0, b = 0;
    if (I && J && L) {
        a = 3 + (I - 1) / 2 * 2 + (J - 1) / 2 * 2 + (L - 1) / 2 *2;
    }
    {
        b = I / 2 * 2 + J / 2 * 2 + L / 2 * 2;
    }
    print(max(a, b) + O);

    return 0;
}

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

queue<int> V[1000];

int main() {
 UL N,Q;scanf("%u%u",&N,&Q);
 rep(q,Q){
  UL c; scanf("%u",&c);
  if(c==0){
   UL t; int x; scanf("%u%d",&t,&x);
   V[t].push(x);
  } else if(c==1){
   UL t; scanf("%u",&t);
   if(V[t].size()) printf("%d\n",V[t].front());
  } else if(c==2){
   UL t; scanf("%u",&t);
   if(V[t].size()) V[t].pop();
  }
 }
 return 0;
}




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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	FIO();
	int n; cin >> n;
	int a[n];
	int b[n];

	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];

	for (int i = 0; i < n - 2; i++)
	{
		if (a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2])
		{
			cout << "Yes" << '\n';
			return 0;
		}
	}
	cout << "No" << '\n';
	return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

#ifdef DEBUG   
    const int CHAR_NUM = 3;
#else
    const int CHAR_NUM = 26;
#endif

const int MAX_N = 2e5;
int dp[MAX_N+2];
int pre[MAX_N+1];

int main()
{
    ios::sync_with_stdio(false);
    fill(dp, dp+MAX_N, INF);
    fill(pre, pre+MAX_N, INF);

    string S;
    int N;

    cin >> S;
    N = S.size();

    vector<vector<int>> next(CHAR_NUM, vector<int>(N+1, INF));

    for (int i=N-1; i>=0; i--) {
        rep(c, CHAR_NUM) {
            if (S[i] == 'a' + c) next[c][i] = i;
            else next[c][i] = next[c][i+1];
        }
    }

#ifdef DEBUG
    rep(i, N) {
        rep(c, CHAR_NUM) cerr << next[c][i] << " ";
        cerr << endl;
    }
#endif

    dp[N+1] = 0;
    dp[N] = 1;
    for (int i=N-1; i>=0; i--) {
        rep(c, CHAR_NUM) {
             int len = 1;
             if (next[c][i] != INF) {
                len = dp[next[c][i] + 1] + 1;
             }
            if (len < dp[i]) {
                dp[i] = len;
                pre[i] = min(pre[i], c);
            }
        }
    }

#ifdef DEBUG
    rep(i, N+1) cerr << dp[i] << " "; cerr << endl;
#endif

    string ans;
    int i=0; 
    while (i<N) {
        int tmp_c;
        rep(c, CHAR_NUM) {
            int tmp = next[c][i] == INF ? 0 : dp[next[c][i] + 1];
            if (dp[i] == tmp + 1) {
                tmp_c = c;
                break;
            }
        }
        ans += (tmp_c + 'a');
        i = next[tmp_c][i] + 1;
    }
    // cerr << dp[0] << endl;
    cout << ans << endl;
}

Measured memory_bytes: 23316
#include <stdio.h>
#include <math.h>
typedef long long int lli;

int main(){
    lli N,tmp,sum;
    int i;
    scanf("%lld",&N);
    i = 0;
    tmp=N;
    while(1)
    {
        i++;
        if(tmp/10==0)break;
        tmp=tmp/10;
    }
    sum=0;
    for(int j=0;j<i;j++)
    {
        if(j%2!=0)continue;
        if(j==i-1)sum += N-(pow(10,j)-1);
        else if(j==0)sum += (lli)(pow(10,j+1)-pow(10,j));
        else sum += (lli)(pow(10,j+1)-pow(10,j));
    }
    fprintf(stdout,"%lld",sum);
    return 0;
}

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

int main(){
	while(true){
		bool map[21][21]={};
		int gem,n,get=0,cx=10,cy=10;
		cin>>gem;
		if(gem==0)break;
		for(int i=0;i<gem;i++){
			int x,y;
			cin>>x>>y;
			map[x][y]=true;
		}
		cin>>n;
		for(int i=0;i<n;i++){
			char oder;
			int leng;
			cin>>oder>>leng;
			for(int j=0;j<leng;j++){
			switch (oder){
			case 'N':
				cy++;
				break;
			case 'S':
				cy--;
				break;
			case 'W':
				cx--;
				break;
			case 'E':
				cx++;
				break;
			}
			if(map[cx][cy]){
				map[cx][cy]=false;
				get++;
			}
			}
		}
		cout<<(get==gem?"Yes":"No")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=998244353;
const long long int INF=99999999999999999;

long long int n,m,sum=0,res;
string str;
int main() {
	cout << fixed << setprecision(10);
    cin>>n>>str;
    if(str.substr(0,n/2)==str.substr(n/2,n/2)&&n%2==0){cout<<"Yes";}
    else{cout<<"No";}
} 


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

#define int long long

signed main(){
    int n;
    cin>>n;
    vector<int> B(n-1);
    for(int i=0; i<n-1; i++) cin>>B[i];

    vector<int> A(n);
    A[0] = B[0];
    A[n-1] = B[n-2];
    for(int i=n-2; i>=1; i--){
       A[i] = B[i];
       if(B[i-1] < B[i]){
           A[i] = B[i-1];
       }
        
    }

    int res = 0;
    for(int i=0; i<n; i++) res += A[i];

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE TypeApplications #-}
import qualified Data.ByteString.Char8 as BS

check :: Int -> [Int] -> Int
check n list =
  if n >= sum
  then n - sum
  else -1
  where
    sum = foldr (+) 0 list

main :: IO()
main = do  
  [n,m] <- map (read @Int . BS.unpack) . BS.words <$> BS.getLine
  as <- map (read @Int . BS.unpack) . BS.words <$> BS.getLine
  print $ check n as

Measured memory_bytes: 5072
X = int(input())
if X == 2:
    print(2)
    exit()

N = 100010
flags = [True for i in range(N//2 + 1)]
flags[0] = False

lim = int(pow(N, 1/2))//2 + 1

for i in range(lim):
    if flags[i] is True:
        p = 2*i + 1
        for j in range(2*i*(i+1), N//2+1, p):
            flags[j] = False

for i in range(X//2, N//2 + 1):
    if flags[i] is True:
        print(2*i+1)
        break


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

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

struct matrix_bit {
    vector<vector<int> > a;
    matrix_bit(int n, int m) : a(n, vector<int>(m)) { }
    int size1() const { return a.size(); }
    int size2() const { return a[0].size(); }
    int& operator()(int i, int j) { return a[i][j]; }
    int  operator()(int i, int j) const { return a[i][j]; }
    matrix_bit operator*(matrix_bit const& rhs) {
        matrix_bit r(size1(), rhs.size2());
        rep (i,size1()) rep (j,size2()) rep (k,rhs.size2()) r(i,k) |= a[i][j] & rhs(j,k);
        return r;
    }
    matrix_bit& operator*=(matrix_bit const& rhs) {
        return *this = operator*(rhs);
    }
};

matrix_bit pow(matrix_bit x, int n) {
    matrix_bit r(x.size1(), x.size1());
    rep (i,x.size1()) r(i,i) = 1;
    for ( ; n > 0; x *= x, n >>= 1) if (n & 1) r *= x;
    return r;
}    

int main() {
    int N, M, Z;
    int s[100], d[100];
    while (cin >> N >> M >> Z && N > 0) {
        rep (i,M) {
            cin >> s[i] >> d[i];            
            if (s[i] > d[i]) swap(s[i], d[i]);
            s[M+i] = d[i];
            d[M+i] = s[i];
        }

        matrix_bit v(1,2*M), A(2*M,2*M), u(2*M,1);
        rep (i,2*M) {
            if (s[i] == 1) u(i,0) = 1;
            if (d[i] == N) v(0,i) = 1;
        }
        rep (i,2*M) rep (j,2*M) {
            if (d[i] == s[j] && s[i] != d[j]) A(j,i) = 1;
        }

        auto r = v*pow(A,Z-1)*u;
        cout << (r(0,0) > 0 ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 1388
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<tuple<int, int, int>> vti;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, d;
    cin >> n >> d;
    d = d * 2 + 1;
    int ans = n / d;
    if (n%d > 0) ans += 1;
    cout << ans << endl;
}


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

void fastio()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}

void solve()
{
	string s,t;
	cin>>s>>t;
	unordered_map<char,int> m;
	// for(auto x:s)
	// {
	// 	m[x]++;
	// }
	// for(auto x:t)
	// {
	// 	m[x]--;
	// }
	// int sum = 0;
	// for(auto x:m)
	// {
	// 	// cout<<x.first<<" "<<x.second<<endl;
	// 	sum+=abs(x.second);
	// }
	// cout<<endl;
	// cout<<sum/2<<e
	// ndl;
	int sum=0;
	int n = s.size();
	for(int i=0;i<n;i++)
	{
		if(s[i]!=t[i])sum++;
	}
	cout<<sum<<endl;
}

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

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
int a,b;
int x=0,y=0;
int main()
{
    cin>>a>>b;
    if(a==2||b==2)
        {
            printf("No\n");
            return 0;
        }
    if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)
        x++;
    if(b==1||b==3||b==5||b==7||b==8||b==10||b==12)
        x++;
    if(a==4||a==6||a==9||a==11)
        y++;
    if(b==4||b==6||b==9||b==11)
        y++;
        //cout<<x<<y;
    if(x==2||y==2)
        printf("Yes\n");
    else
        printf("No\n");

}


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

using namespace std;

int main(){

  while(1){

    int n,sum,ave;
  cin >> n;
  vector<int>vec(n);
  sum=0;
  ave=0;

  if(n==0)break;

  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());

  for(int i=1;i<n-1;i++){
    sum+=vec.at(i);
  }

  ave = sum/(n-2);
  cout << ave <<endl;
  }


}



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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\01.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;

int main() {


    int n, i;

    cin >> n >> i;

    cout << n - i + 1 << endl;

}


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

int main() {
  int n; cin >> n;
  map<char,ll> m;
  vector<char> c = {'M', 'A', 'R', 'C', 'H'};
  ll ans = 0;
  rep(i,n) {
    string s; cin >> s;
    if (s[0] == 'M' ||
        s[0] == 'A' ||
        s[0] == 'R' ||
        s[0] == 'C' ||
        s[0] == 'H' ) m[s[0]]++;
  }
  for (int i = 0; i<5; i++) {
    for (int j = i+1; j<5; j++) {
      for (int k = j+1; k<5; k++) {
        ans += m[c[i]] * m[c[j]] * m[c[k]];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>




int main(int argc, const char * argv[]){
    
    //Input
    int i, n ,q, mid, middle, left, right, ans = 0;
    
    scanf("%d", &n);
    int S[n];
    for (i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
    
    
    scanf("%d", &q);
    int Q[q];
    for (i = 0; i < q; i++) {
        scanf("%d", &Q[i]);
    }
    
    for(i = 0; i < q; i++){
        left = 0;
        right = n - 1;
        
        while(left <= right){
            mid = (left + right)/2;
            middle = S[mid];
            
            if(Q[i] == middle){
                ans++;
                break;
            }
            else if(Q[i] > middle){
                left = mid + 1;
            }
            else{
                right = mid -1;
            }
        }
    }
    
    
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;

int N, F;
map<pair<string, string>, int> m;

int main() {
	cin >> N >> F;
	REP(i, N) {
		int M; cin >> M;
		vector<string> item(M);
		REP(j, M) cin >> item[j];
		sort(ALL(item));
		REP(j, M) FOR(k, j + 1, M) m[make_pair(item[j], item[k])]++;
	}
	
	vector<pair<string, string> > ans;
	for (map<pair<string, string>, int>::iterator it = m.begin(); it != m.end(); ++it) {
		if (it->se >= F) ans.push_back(it->fi);
	}
	
	cout << ans.size() << endl;
	REP(i, ans.size()) cout << ans[i].fi << " " << ans[i].se << endl;
	
	return 0;
}

Measured memory_bytes: 3660