akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int m;
int a[100000], b[100000], par[100001], s[100001];
long long n;
long long u[100001];

int find(int u) {
	if (u == par[u])
		return u;
	else
		return par[u] = find(par[u]);
}

void unite(int x, int y) {
	if (x == y)
		return;
	
	par[x] = y;
	s[y] += s[x];
}

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

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

	for (int i = 0; i <= n; i++) {
		par[i] = i;
		s[i] = 1;
	}

	u[0] = n * (n - 1) / 2;

	for (int i = 0; i < m - 1; i++) {
		int v = find(a[m - 1 - i]);
		int	w = find(b[m - 1 - i]);

		u[i + 1] = u[i];

		if (v != w){
			u[i + 1] -= (long long)s[v] * (long long)s[w];
			unite(v, w);
		}
	}

	for (int i = 0; i < m; i++)
		cout << u[m - 1 - i] << endl;

	return 0;
}


Measured memory_bytes: 3712
import java.util.*;
import java.io.*;

class Main
{
    public static void main(String[] args) throws IOException{
        PrintWriter out = new PrintWriter(System.out);

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());


        st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];

        for (int i=0; i<n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }
        int ans = 0;
        for (int i=0; i<n; i++) {
            for (int j=i+1; j<n; j++) {
                if (arr[i]==arr[j]) {
                    continue;
                }
                for (int k=j+1; k<n; k++) {
                    if (arr[j]==arr[k] || arr[i]==arr[k]) {
                        continue;
                    }
                    if (arr[j]+arr[k]>arr[i] && arr[i]+arr[k]>arr[j] && arr[i]+arr[j]>arr[k]) {
                        ans++;
                    }
                }
            }
        }

        out.println(ans);

        out.close();
    }

    

}


Measured memory_bytes: 33512
#include<bits/stdc++.h>
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
#define ll long long
inline int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}

inline void file(){
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
}

using namespace std;
const ll maxn=1e6+10;
ll a[maxn],b[maxn];

int main(){
	ll k,n,h;
	//scanf("%lld%lld",&n,&h);
	cin>>n>>h;
	for(register ll i=1;i<=n;++i)
		cin>>a[i]>>b[i];
	sort(b+1,b+n+1);
	sort(a+1,a+n+1);
	for(register ll i=1;i<=n;++i)
		b[i]=max(b[i],a[n]);
	ll ovo=0;
	for(register ll i=n;i>=1;--i){
		ovo+=b[i];
		if(ovo>=h){
			printf("%lld",n-i+1);
			return 0;
		}
	}
	if(ovo<h){
		h-=ovo;
		printf("%lld",n+(h/a[n])+(h%a[n]==0?0:1));
	}
	return 0;
}




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

typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18


int main() {
    vector<int> A(3); cin >> A[0] >> A[1] >> A[2];
    sort(ALL(A));
    cout << A[2] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    
    if(a >= b * 2) {
        cout << a - (b * 2) << endl;
    }
    else {
        cout << 0 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
/* 
 Author:N_o_o_B 
 Created:November 19 2019 13:56:45
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    int n;
    cin >> n;
    vi a(n);
    iota(a.begin(),a.end(),0);
    vii p(n);
    fori(i,n){
        cin >> p[i].fi >> p[i].se;
    }
    ld tot=0;
    ll cnt=0;
    do{
        cnt++;
        rep(i,1,n-1){
            ld dis = pow(p[a[i]].fi-p[a[i-1]].fi,2)+pow(p[a[i]].se-p[a[i-1]].se,2);
            dis = sqrt(dis);
            tot += dis;
        }
    }while(next_permutation(all(a)));
    cout << tot/cnt << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s,data[9]={
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};
int n,i,p,t;
int main(){
	cin>>n;while(n--){
		cin>>s,t=1,p=s[0]-'0';
		for(i=1;i<s.length();i++){
			if(s[i]=='0'){
				if(p!=0)cout<<data[p-1][(t-1)%data[p-1].length()];
				i++,p=s[i]-'0',t=1;
			}else if(p==0)p=s[i]-'0';
			else t++;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 3152
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double pi = 3.14159265358979323846264338327950288;
bool a[100001];
vector<int>e[100001];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i <= n; i++)
		a[i] = 0;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	int st, en;
	list<int>path;
	st = 1;
	en = e[1][0];
	path.push_back(st);
	path.push_back(en);
	a[st] = 1;
	a[en] = 1;
	while (true) {
	stop:;
		for (int i = 0; i < e[st].size(); i++) {
			if (!a[e[st][i]]) {
				a[e[st][i]] = 1;
				st = e[st][i];
				path.push_front(st);
				goto stop;
			}
		}
		for (int i = 0; i < e[en].size(); i++) {
			if (!a[e[en][i]]) {
				en = e[en][i];
				a[en] = 1;
				path.push_back(en);
				goto stop;
			}
		}
		break;
	}
	cout << path.size() << endl;
	list<int>::iterator it = path.begin();
	while (it != path.end()) {
		if (it == path.begin()) {
			cout << (*it);
		}
		else
			cout << " " << (*it);
		it++;
	}
	cout << endl;
	cin >> n;
}

Measured memory_bytes: 9472
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#ifdef DEBUG
    mt19937 gen(857204);
#else
    mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
template<class T> inline T sorted(T a) { sort(a); return a; }

void minimize(string &s) {
    char curr = 'a';
    for (auto &i : s) {
        if (i > curr) {
            char check = i;
            for (auto &j : s)
                if (j == check)
                    j = curr;
        }
        ++curr;
    }
}

int n;
string s;
//set<string> st;
vector<string> st;

void rec(int i, int mx) {
    if (i == n) {
        //minimize(t);
        st.pb(s);
        return;
    }
    for (int t = 0; t <= i && t <= mx + 1; ++t) {
        s.pb('a' + t);
        rec(i + 1, max(t, mx));
        s.popb();
    }
}

signed main() {
    FAST; FIXED;
    cin >> n;
    rec(0, -1);
    for (auto i : st) cout << i << '\n';
    #ifdef DEBUG
        cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}

Measured memory_bytes: 9716
n = input()
ans = []
a = list(map(int, input().split()))
half = int(sum(a)/2)
b = 0
for i in range(1, len(a), 2):
    b += a[i]
ans.append(int((half - b)*2))

for i in range(0, len(a)-1):
    ans.append(int(a[i]-ans[i]/2)*2)

for i in range(len(ans)):
    print(ans[i], end=" ")


Measured memory_bytes: 14040
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> frac, ifrac;
    combination(int n):frac(n+1), ifrac(n+1) {
        assert(n < mod);
        frac[0] = 1;
        for (int i = 1; i <= n; ++i) frac[i] = frac[i-1]*i;
        ifrac[n] = frac[n].inv();
        for (int i = n; i >= 1; --i) ifrac[i-1] = ifrac[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return frac[n]*ifrac[k]*ifrac[n-k];
    }
} c(2000);

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

    rep(i, k) {
        int i_ = i+1;
        mint ans;
        ans = c(k-1, i);
        ans *= c(n-k+1, i_);
        cout << ans << '\n';
    }
}

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

static class Extensions
{
    public static int ToInt(this string s) => int.Parse(s);
    public static long ToLong(this string s) => long.Parse(s);
    public static char ToChar(this string s) => char.Parse(s);
    public static double ToDouble(this string s) => double.Parse(s);
    public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray();
    public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray();
    public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray();
}


class Program
{
    static void Main()
    {
        int[] abcd = Console.ReadLine().ToIntArray();
        int a = abcd[0];
        int b = abcd[1];
        int c = abcd[2];
        int d = abcd[3];

        bool ans = false;
        if (Math.Abs(a - c) <= d) ans = true;
        if (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) ans = true;

        Console.WriteLine(ans ? "Yes" : "No");
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	vector <int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	int c = 0;
	while(true) {
		sort(all(v));
		if(v[0] == v[1] && v[1] == v[2])
			break;
		c++;
		if(v[1] < v[2]) {
			v[0] += 1;
			v[1] += 1;
		}
		else if(v[0] < v[1]) {
			v[0] += 2;
		}
	}
	cout << c;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int h, w;
    cin >> h >> w;

    vector<string> str(h);
    REP(i, h)
        cin >> str[i];

    REP(i, h) {
        cout << str[i] << '\n';
        cout << str[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
# 2019-11-11 18:30:26(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    d = int(sys.stdin.readline().rstrip())
    ans = 'Christmas'
    if d <= 24:
        ans += ' Eve'
    if d <= 23:
        ans += ' Eve'
    if d == 22:
        ans += ' Eve'
    print(ans)


if __name__ == "__main__":
    main()

    

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

using namespace std;

typedef long long ll;

const int N = 51;

int kek[N][N];

bool go(int x, int y, ll mask) {
    if (kek[x][y]) {
        return kek[x][y] == 1;
    }
    if (x == y) {
        kek[x][y] = 1;
        return true;
    }
    if (x < y) {
        kek[x][y] = -1;
        return false;
    }
    bool f = false;
    for (int i = 1; i < N; ++i) {
        if (i > x || !((1LL << i) & mask)) {
            continue;
        }
        bool g = go(x % i, y, mask);
        f |= g;
    }
    if (f) {
        kek[x][y] = 1;
    } else {
        kek[x][y] = -1;
    }
    return f;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    ll mask = (1LL << N) - 1;
    for (int i = 0; i < n; ++i) {
        if (!go(a[i], b[i], mask)) {
            cout << -1;
            return 0;
        }
    }
    ll ans = 0;
    for (int i = N - 1; i >= 1; --i) {
        mask ^= 1LL << i;
        for (int j = 0; j < N; ++j) {
            for (int k = 0; k < N; ++k) {
                kek[j][k] = 0;
            }
        }
        bool f = true;
        for (int j = 0; j < n; ++j) {
            f &= go(a[j], b[j], mask);
        }
        if (!f) {
            mask ^= 1LL << i;
            ans += 1LL << i;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n,a,b;
  scanf("%ld %ld %ld", &n, &a, &b);
  long x[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &x[i]);
  }
  long min = 0;
  for (long i = 1; i < n; i++) {
    if ((x[i]-x[i-1])*a <= b) {
      min += (x[i]-x[i-1])*a;
    } else {
      min += b;
    }
  }
  printf("%ld\n", min);

  return 0;
}

Measured memory_bytes: 896
import math
import sys
sys.setrecursionlimit(10 ** 6 + 10)
from collections import defaultdict

def kari():
    map(int, input().split())

    num, num2 = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num2)]

def main():
    num1, num2 = map(int, input().split())
    data = list(map(int, input().split()))
    data2 = [list(map(int, input().split())) for i in range(num2)]

    data.sort(reverse=True)
    data2.sort(key=lambda x: -x[1])

    data_ind = 0
    data2_ind = 0
    ans = 0

    nokori = num1

    for i in range(num1):
        if data2_ind < num2:
            if data2[data2_ind][1] >= data[data_ind]:
                ans += min(nokori, data2[data2_ind][0]) * data2[data2_ind][1]
                nokori -= min(nokori, data2[data2_ind][0])
                data2_ind += 1
            elif data_ind < num1:
                ans += data[data_ind]
                nokori -= 1
                data_ind += 1
            else:
                ans += min(nokori, data2[data2_ind][0]) * data2[data2_ind][1]
                nokori -= min(nokori, data2[data2_ind][0])
                data2_ind += 1
        else:
            ans += data[data_ind]
            nokori -= 1
            data_ind += 1
        if nokori == 0:
            break

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81688
#include <cstdio>  
using namespace std;  
int main() { 	
	int a,b,c,d,e; 	
	scanf("%d %d %d", &a, &b, &c); 	
	if(a==b){
		printf("%d", c);
	}
	if(a==c){
		printf("%d", b);
	}
	if(c==b){
		printf("%d",a);
	}
	
} 

Measured memory_bytes: 128
from collections import deque

def resolve():
    s = input()
    s = deque(s)
    q = int(input())
    flag = False
    for i in range(q):
        list = input().split()
        t = list[0]
        if t == "1":
            if len(s) > 1:
                flag = not flag
        elif (list[1] == "1") ^ flag:
            s.appendleft(list[2])
        else:
            s.append(list[2])
    s = ''.join(s)
    if flag:
        s = ''.join(reversed(s))
    print(s)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 8436
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
ll n, v[110],ct;
int main() {
	cin >> n;
	rep(i, n)cin >> v[i];
	rep(i, n) {
		if (i > 0)if (v[i] == v[i - 1])++ct, v[i] = min(v[i - 1], v[i+1]) - 1;
	}
	cout << ct << endl;
	return 0;
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int count=0;
    for(int i=0;s[i];++i){
        if(s[i]!=t[i])count++;
    }
    cout<<count;
    return 0;
}

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

using namespace std;
using ll = long long;

vector<vector<int>> item;
vector<int> i2g;

void init(int N) {
  item.resize(N);
  i2g.resize(N);
  for(int i = 0; i < N; i++) {
    item[i].push_back(i);
    i2g[i] = i;
  }
}

void merge(int a, int b) {
  int ga = i2g[a], gb = i2g[b];
  if (item[ga].size() < item[gb].size()) {
    swap(ga, gb);
  }
  for(int i = 0; i < item[gb].size(); i++) {
    i2g[item[gb][i]] = i2g[item[ga][0]];
  }
  for(int i = 0; i < item[gb].size(); i++) {
    item[ga].push_back(item[gb][i]);
  }
  item[gb].clear();
}

int main() {
  ll N, M;
  cin >> N >> M;
  init(N);
  vector<int> A(M), B(M);
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    A[i] = a; B[i] = b;
  }

  vector<ll> ans(M);
  ll now = N * (N - 1) / 2;
  ans.back() = now;
  for(int i = M - 1; i > 0; i--) {
    if (i2g[A[i]] == i2g[B[i]]) {
      ans[i - 1] = now;
    } else {
      ll s1 = item[i2g[A[i]]].size();
      ll s2 = item[i2g[B[i]]].size();
      now -= s1 * s2;
      ans[i - 1] = now;
      merge(A[i], B[i]);
    }
  }

  for(int i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 12536
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        sc.close();

        // 主処理
        boolean judge = t.matches(s + ".");
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ll long long
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7;
const ll inf=1e10;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;


ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}



ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

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

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}



ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

const long sz=1e5+10;

int main()
{
    //fast;
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        ll a,b;
        cin>>a>>b;
        if(((a+b))&1){
            cout<<"IMPOSSIBLE";
        }else  cout<<(a+b)/2;

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,g = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		while(a >= b && a % b){
			if((a - (a / b + 1)) / b < a / b) a -= a / b + 1;
			else{
				int t = b * (int)(a / b),d = a / b + 1;
				a = t + (a % d - t % d + d) % d;
			}
		}
		g ^= (a / b);
	}
	if(!g) cout << "Aoki" << endl;
	else cout << "Takahashi" << endl;
	return 0;
}

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

int main() {
	int n; cin >> n;
	vector<pair<int, int>> v;
	for(int i = 0; i < n * n; ++i) {
		int p; cin >> p;
		--p;
		v.emplace_back(p / n, p % n);
	}
	int dist[n][n];
	bool obj[n][n];
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			dist[i][j] = min({i, j, n - 1 - i, n - 1 - j});
			obj[i][j] = true;
		}
	}
	int ans = 0;
	constexpr int dy[] = {0, 1, 0, -1};
	constexpr int dx[] = {1, 0, -1, 0};
	for(int i = 0; i < n * n; ++i) {
		auto [sy, sx] = v[i];
		ans += dist[sy][sx];
		obj[sy][sx] = false;
		for(int d = 0; d < 4; ++d) {
			int ny = sy + dy[d];
			int nx = sx + dx[d];
			if(ny < 0 or n <= ny) continue;
			if(nx < 0 or n <= nx) continue;
			dist[sy][sx] = min(dist[sy][sx], dist[ny][nx] + obj[ny][nx]);
		}
		queue<tuple<int, int, int>> que;
		que.emplace(sy, sx, dist[sy][sx]);
		while(not que.empty()) {
			auto [y, x, c] = que.front();
			que.pop();
			if(c > dist[y][x]) continue;
			for(int d = 0; d < 4; ++d) {
				int ny = y + dy[d];
				int nx = x + dx[d];
				if(ny < 0 or n <= ny) continue;
				if(nx < 0 or n <= nx) continue;
				int nc = c;
				if(obj[y][x]) ++nc;
				if(nc >= dist[ny][nx]) continue;
				dist[ny][nx] = nc;
				que.emplace(ny, nx, nc);
			}
		}
		// cout << i << '\n';
		// for(int i = 0; i < n; ++i) {
		// 	for(int j = 0; j < n; ++j) {
		// 		cout << dist[i][j] << " ";
		// 	}
		// 	cout << '\n';
		// }
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 6676
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    set<int> st;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        st.insert(d);
    }
    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left as bl
while True:
    try:
        *l, v1, v2 = map(int, input().split(','))
        a = [l[0]] + [0] * 9
        for i in range(1, 10):
            a[i] = a[i-1] + l[i]
        print(bl(a,a[9]/(v1+v2)*v1) + 1)
    except:
        break


Measured memory_bytes: 5636
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;

#define prec(i) cout << fixed << setprecision(i)

void outPut_YN(bool isYes) {
	if(isYes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {

	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;

	return u;
}

long long _gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);

	if (a % b == 0)
		return b;
	else
		return _gcd(b, a % b);
}

long long _lcm(long long a, long long b)
{
	return (((a * b) % MOD) * modinv(_gcd(a, b))) % MOD;
}

int main()
{
	long long a, b, lcm, sum = 0;
	string s, t, u;

	cin >> s >> t;
	cin >> a >> b;
	cin >> u;

	if (s == u)
		a -= 1;
	else
		b -= 1;

	cout << a << " " << b << endl;

	return 0;
}

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

namespace ConsoleApp15
{
    class Class281
    {
        static  readonly long mod = 1000000007;
        static void Main()
        {
            var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NK[0], K = NK[1];
            long ans = 0;

            int nums = K;
            long[] min = new long[N + 1];
            long[] max = new long[N + 1];
            max[0] = N;
            for (int i = 1; i < N + 1; i++)
            {
                min[i] = min[i - 1] + i;
                max[i] = max[i - 1] + N - i;
            }
            
            for(int i = K-1; i <= N; i++)
            {
                ans += max[i] - min[i]+1;
                ans %= mod;
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 31272
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define satoi(n) atoi(n.c_str())

string pls(string a,string b){
	string ret;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	if(a.size()<b.size())swap(a,b);
	while(a.size()!=b.size())b+='0';
	while(a.size()+1!=ret.size())ret+='0';
	for(int i=0;i < a.size(); i++){
		ret[i] = a[i] + b[i] + ret[i] - '0'*3;
		if(ret[i]>9){
			ret[i] = '0' + ret[i]%10;
			ret[i+1] = '1';
		}else{
			ret[i]= '0' + ret[i];
		}
	}
	
	reverse(ret.begin(),ret.end());
	if(~ret.find_first_not_of('0'))return ret.substr(ret.find_first_not_of('0'),ret.size()-ret.find_first_not_of('0'));
	else return "0";
}
bool func(vector<string> f , int n){
	for(int i=0;i<3;i++){
		for(int j=0;j<f[i].length();j++){
			if(f[i][j]=='X'){
				f[i][j]='0'+n;
			}
		}
	}
	return (pls(f[0],f[1]) == f[2]);
}

int main(){
	bool flag;
	int ret;
	vector<string> m;
	string s,t;
	while(cin >> s){
		s+=" ";
		m.clear();
		flag = false;
		ret = -1;
		
		for(int i=0;i<s.length();i++){
			if(s[i]>='0' && s[i]<='9' || s[i]=='X'){
				t+=s[i];
			}else{
				if(t.size()>=2 && t[0] == 'X')flag = true;
				m.push_back(t);
				t.clear();
			}
		}
		for(int i=(flag?1:0);i<10;i++){
			if(func(m,i))ret=i;
		}
		if(~ret)cout << ret << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n , k ;
long long h[N]  ;
long long dp[N];


int32_t main(){
	for(int i = 0 ; i < N ; i ++) dp[i] = (long long) 1e18;
	scanf("%d" , &n);
	//scanf("%d" , &k);
	k = 2;
	for(int i = 1 ; i <= n; i ++) scanf("%lld" , & h[i]);
	dp[1] = 0;
	for(int i = 1 ; i <= n ;i ++){
		for(int j = i + 1 ; j <= n && j - i <= k ; j++){
			dp[j] = min(dp[j] , dp[i] + abs(h[i] - h[j]));
		}
	}
	printf("%lld\n" , dp[n]);
}

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

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

void shellSort( vector<int>& a );
void insertSort( vector<int>& a, int h );
void printArray( vector<int>& a );

int main() {
	int n; cin >> n;
	vector<int> a( n );
	REP( i, n ) cin >> a[i];

	shellSort( a );
	printArray( a );

}


void shellSort( vector<int>& a ) {
	int h = 1, h_tmp, h_cnt = 0;
	for( h_tmp = 1; h_tmp < a.size(); h_tmp = h_tmp * 3 + 1 ) {
		h = h_tmp;
		h_cnt++;
	}

	cout << ( a.size() == 1 ? h_cnt + 1 : h_cnt ) << endl;
	
	while( h > 0 ) {
		if( h / 3 != 0 ) cout << h << " ";
		else			 cout << h << endl;
		insertSort( a, h );
		h /= 3;
	}
}

void insertSort( vector<int>& a, int h ) {
	static int cnt = 0;
	int tmp, j;
	FOR( i, h, a.size() ) {
		tmp = a[i];
		for( j = i; j >= h && a[j - h] > tmp; j -= h ) {
			cnt++;
			a[j] = a[j - h];
		}
		a[j] = tmp;
	}

	if( h == 1 ) cout << cnt << endl;
}

void printArray( vector<int>& a ) {
	REP( i, a.size() ) cout << a[i] << endl;
}


Measured memory_bytes: 6668
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

string a, b;
int dp[3010][3010], pre[3010][3010];

void lcs() {
    int n = a.size(), m = b.size();
    a = "0" + a;
    b = "1" + b;
    fill(dp[0], dp[1111], 0);
    fill(pre[0], pre[1111], 0);
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i] == b[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                pre[i][j] = 1;
            }
            else if (dp[i - 1][j] > dp[i][j - 1]) {
                dp[i][j] = dp[i - 1][j];
                pre[i][j] = 2;
            }
            else {
                dp[i][j] = dp[i][j - 1];
                pre[i][j] = 3;
            }
        }
    }
}

string solve() {
    string ans = "";

    int i = a.size() - 1;
    int j = b.size() - 1;
    while (i >= 1 && j >= 1) {
        if (pre[i][j] == 1) { // 左上に遷移
            ans += a[i];
            i--;  j--;
        }
        else if (pre[i][j] == 2) i--;
        else j--;
    }

    reverse(ans.begin(), ans.end());
    return ans;
}

int main(void) {
    cin >> a >> b;
    lcs();
    cout << solve() << endl;
}

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

int main() {
  int N;
  cin>>N;
  vector<vector<int>>ls(2,vector<int>(N,0));
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){cin>>ls.at(i).at(j);}
  }
  ls.at(0).at(N-1)+=ls.at(1).at(N-1);
  for(int i=N-2;i>=0;i--){ls.at(1).at(i)+=ls.at(1).at(i+1);}
  for(int i=N-2;i>=0;i--){ls.at(0).at(i)+=max(ls.at(0).at(i+1),ls.at(1).at(i));}
  cout<<ls.at(0).at(0)<<endl;
}


Measured memory_bytes: 256
dice = gets.split.map(&:to_i)
commands = gets.chomp.chars.map(&:to_sym)
throw = {E: [3, 2, 6, 1, 5, 4], N: [5, 1, 3, 4, 6, 2],
         S: [2, 6, 3, 4, 1, 5], W: [4, 2, 1, 6, 5, 3]}
th = {}
throw.each_key {|k| th[k] = throw[k].map(&:pred)}

commands.each do |c|
  next_dice = Array.new(6, 0)
  dice.each_with_index do |d, i|
    next_dice[th[c][i]] = d
  end
  dice = next_dice
end
puts dice[0]



Measured memory_bytes: 6876
b1,b2,b3 = map(int,input().split())
if b1==1 and b2 == b3 == 0 :
    print('Close')
elif b1 == b3 == 0 and b2 == 1 :
    print('Close')
elif b1 == b2 == 1 and b3 == 0 :
    print('Open')
elif b1 == b2 == 0 and b3 == 1 :
    print('Open')
else :
    print('Close')



Measured memory_bytes: 5596
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

long long gcd(long long a, long long b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

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

int main(){
    string postfix = "FESTIVAL";
    string name;
    cin >> name;
    size_t pos = name.rfind(postfix);
    dump(pos);
    cout << name.substr(0, pos) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
    int n,a[200000],i,num=1;

    scanf("%d",&n);
    for ( i = 0; i < n; i++)
    {
        scanf("%d",a+i);
    }

    for ( i = 0; i < n; i++)
    {
        if(a[i]==num) num++;
    }

    num--;

    if(num==0)
    {
        printf("%d",-1);
        return 0;
    }

    printf("%d",n-num);

    return 0;
}

Measured memory_bytes: 896
use proconio::{input, fastout};

fn gcd(mut a: usize, mut b: usize) -> usize {
    if a<b {
        let mut tmp = a;
        a = b;
        b = tmp;
    } 
    let mut r = a % b;
    while r!=0 {
        a = b;
        b = r;
        r = a % b;
    }
    b
}

#[fastout]
fn main() {
    input!{
        n: usize,
        mut a: [usize;n],
    }

    a.sort();
    let mut mins: Vec<usize> = Vec::new();
    let mut flag = false;
    let mut tmp = a[0];
    for i in 0..n {
        // if a[i]%a[0]!=0 {
        //     mins.push(gcd(a[0], a[i]%a[0]));
        //     flag = true;
        // }
        tmp = gcd(tmp, a[i]);
    }

    println!("{}", tmp);
    // mins.sort();
    // if flag==true{
    //     println!("{}", mins[0]);
    // } else {
    //     println!("{}", a[0]);
    // }
}


Measured memory_bytes: 4256
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int A = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int[] cards = new int[N];

        for(int i=0;i<N;i++)
            cards[i]=Integer.parseInt(st.nextToken());

        Long[][][] dp = new Long[2502][52][52];
        System.out.println(findWays(0,cards,0,0,A,dp));
    }

    public static long findWays(int idx, int[] cards, int sum, int count, int A, Long[][][] dp){
        if(idx>cards.length-1){
            if(count!=0 && sum/count==A && sum%count==0)
                return 1;
            return 0;
        }
        // if(count!=0 && sum/count==A && sum%count==0)
        //     return 1;
        if(dp[sum][idx][count]!=null)
            return dp[sum][idx][count];

        

        long ans=0;
        ans+=findWays(idx+1, cards, sum, count, A, dp);
        ans+=findWays(idx+1, cards, sum+cards[idx], count+1, A, dp);

        return (dp[sum][idx][count]=ans);

    }
}

Measured memory_bytes: 79568
N=int(input())
slimes = []
all_slime=input()
slimes.append(all_slime[0])
lastColor = all_slime[0]
for i in range(1,N):
    new_slime = all_slime[i]
    if not lastColor == new_slime:
        slimes.append(new_slime)
    lastColor=new_slime
print(len(slimes))

Measured memory_bytes: 3956
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

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

			String in = br.readLine();
			String chr[] = in.split("");
			List<String> ans = Arrays.asList(chr);

			System.out.println(ans.contains("7")?"Yes":"No");
		}
	}
}

Measured memory_bytes: 25536
#include <iostream>

using namespace std;

int main()
{
  string line;
  getline(cin, line);
  int array[4] = {};
  for(char ch : line)
  {
    if(ch == 'W') array[0] = 1;
    else if(ch == 'E') array[1] = 1;
    else if(ch == 'N') array[2] = 1;
    else if(ch == 'S') array[3] = 1;
  }
  if((array[0] ^ array[1] == 0) && (array[2] ^ array[3] == 0)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll x;
  cin>>x;
  ll a=360;
  ll i=1;
  while(i>0){
    ll A=a*i;
    //cout<<A<<x;
    if(A/x*x==A){
      x=A/x;
      break;
    }
    else{
      i++;
    }
  }
  cout<<x;
}


Measured memory_bytes: 3632
n = int(input())
s1 = input()
s2 = input()
mod = 10**9 + 7

if n == 1:
    print(3)
    exit()

yoko_flag = False
domino = []
for i in range(n-1):
    if s1[i+1] == s1[i]:  # yoko
        yoko_flag = True
        domino.append("yoko")
    elif s1[i+1] != s1[i] and yoko_flag:
        yoko_flag = False
    elif s1[i+1] != s1[i] and not yoko_flag:  # tate
        domino.append("tate")
    if i == n-2:
        if s1[i+1] != s1[i]:
            domino.append("tate")
#print(domino)
len_domino = len(domino)
pre_domino = domino[0]
if domino[0] == "yoko":
    ans = 6
else:
    ans = 3
for i in range(1, len_domino):
    if domino[i] == "tate" and pre_domino == "tate":
        ans = ans*2 % mod
        pre_domino = domino[i]
    elif domino[i] == "tate" and pre_domino == "yoko":
        ans = ans*1 % mod
        pre_domino = domino[i]
    elif domino[i] == "yoko" and pre_domino == "tate":
        ans = ans*2 % mod
        pre_domino = domino[i]
    elif domino[i] == "yoko" and pre_domino == "yoko":
        ans = ans*3 % mod
        pre_domino = domino[i]
print(ans)





Measured memory_bytes: 67872
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int d, g; cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    rep(i, d) cin >> p[i] >> c[i];
    ll ans = 1001001001;
    rep(bit, 1<<d) {
        ll sum = 0;
        ll num = 0;
        rep(i, d) {
            if((bit>>i)&1) sum += c[i]+p[i]*100*(i+1), num+=p[i];
        }
        if(sum>=g) ans = min(ans, num);
        else {
            for(int i=d-1; i>=0; i--) {
                if((bit>>i)&1) continue;
                for(int j=0; j<p[i];j++) {
                    if (sum >= g) break;
                    sum += 100 * (i+1);
                    ++num;
                }
            }
        }
        ans = min(ans, num);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 999999999999
#define F first
#define S second
#define pb push_back
#define read(x)  freopen("input.txt","r",stdin);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 200009
using namespace std;
ll sqr(ll a,ll b,ll c){
return (a*a+b*b+c*c+a*b+b*c+c*a);
}
ll m[10009];
int main(){//read(x);
fast;
ll a,b,c,d,e,f,g,h,i,j,k,l,n,t;
for(i=1;i<=100;i++){
    for(j=1;j<=100;j++){
        for(k=1;k<=100;k++){
            a=sqr(i,j,k);
            if(a>10000)break;
            m[a]++;
        }
    }
}
cin>>n;
for(i=1;i<=n;i++){
    cout<<m[i]<<endl;
}

}















Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;

int arr[5];

int main(void)
{
	int ans;
	for (int i = 0; i < 5; i++)
	{
		scanf("%d", &arr[i]);
		if (arr[i] == 0)
			ans = i + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
typedef long long int ll;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int main(){
  string s,t;
  cin >> s >> t;
  
  int count = 0;
  
  rep(i,3) if(s[i]==t[i]) count++;
  
  
  cout<<count<<endl;
}


Measured memory_bytes: 256
//
// Created by tattsun on 2017/02/20.
//

#include <iostream>

#define N_MAX 10001

using namespace std;

int n, q;
int s[N_MAX];

int min(int x, int y) {
    if(x<y) return x;
    return y;
}

void _unite(int sm, int lg) {
    int smset = s[sm];
    int lgset = s[lg];
    for(int i=0; i<n; i++) {
        if(s[i] == lgset)
            s[i] = smset;
    }
}

void unite(int x, int y) {
    if(s[x]<s[y]) _unite(x, y);
    else _unite(y, x);
}

int same(int x, int y) {
    return s[x] == s[y];
}

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

    for(int i=0; i<=n; i++) {
        s[i] = i;
    }

    int com, x, y;
    for(int i=0; i<q; i++) {
        cin >> com >> x >> y;
        if(com == 0) {
            unite(x, y);
        } else if(com == 1) {
            cout << same(x, y) << endl;
        } else {
            cout << "error: unknown command " << com << endl;
            exit(1);
        }
    }
}

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

int main(){
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    rep(i, d){
        cin >> p[i] >> c[i];
    }
    int ans = 1000;
    for(int bi = 0; bi < (1 << d); bi++){
        int sum = 0, rest_max, cnt = 0;
        for(int i = 0; i < d; i++){
            if(bi >> i & 1){
                sum += 100 * (i+1) * p[i] + c[i];
                cnt += p[i];
            } else {
                rest_max = i;
            }
        }
        if(sum < g){
            int tmp = 100 * (rest_max+1);
            int need = (g - sum + tmp - 1) / tmp;
            if(need < p[rest_max]){
                cnt += need;
            } else {
                continue;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = np.array(read().split(), np.int64)
I = np.argsort(A)[::-1].tolist()
A = A[I].tolist()

dp = np.zeros(1, np.int64)

for n, (i, x) in enumerate(zip(I, A)):
    newdp = np.zeros(len(dp) + 1, np.int64)
    left_ind = np.arange(len(dp))
    right_ind = N - 1 - n + left_ind
    left_cost = x * np.abs(left_ind - i)
    right_cost = x * np.abs(right_ind - i)
    np.maximum(newdp[:-1], dp + right_cost, out=newdp[:-1])
    np.maximum(newdp[1:], dp + left_cost, out=newdp[1:])
    dp = newdp

print(dp.max())


Measured memory_bytes: 27992
#include <stdio.h>

int main(){
    int num;
    int result[100];
    int count=-1;
    
    while(scanf("%d",&num)!=EOF){
        if (num == 0) {
            printf("%d\n",result[count]);
            count--;
        }
        else {
            count++;
            result[count]=num;
        }
    }
    return 0;
}


Measured memory_bytes: 2120