akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define ff(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b) 
string solve(int n){
    int d = n % 10;
    if(d == 2 or d == 4 or d == 5 or d == 7 or d == 9)
        return "hon";
    if(d == 0 or d == 1 or d == 6 or d == 8)
        return "pon";
    return "bon";
}
int main(){
    //FL;
    fin;
    int n;
    cin >> n;
    cout << solve(n) << '\n';
    time;
    return 0;
}   

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

int A, B, C;

int main() {
    cin >> A >> B >> C;
    int count = 0;

    while(true){
    	if(C == 0){
    		count += B;
    		break;
    	}else{
    		C -= 1;
    		count++;
    		if(B == 0){
    			if(A == 0) break;
    			else{
    				A -= 1;
    			}
    		}else{
    			B -= 1;
    			count++;
    		}
    	}
    }

	cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
#define ld long double
#define CS ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main()
{
    CS
    char a,b;cin>>a>>b;
    if(a=='H'){
        cout<<b<<endl;
    }else{
        if(b=='H')cout<<"D"<<endl;
        else cout<<"H"<<endl;
    }
    return 0;
}


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

using namespace std;
const int somod = 1e9 + 7;
const int maxn = 1007;

int n, m, a, b, dp[maxn][maxn], c, d, fact[maxn], invfact[maxn], cac[maxn][maxn];

void Add(int &a, int b)
{
    a += b;
    if(a >= somod) a -= somod;
}

int Pow(int a, int b)
{
    int ans = 1;
    for(; b > 0; b >>= 1, a = a * a % somod)
    {
        if(b & 1) ans = ans * a % somod;
    }
    return ans;
}

void Prepare()
{
    fact[0] = 1;
    for(int i = 1; i < maxn; i++) fact[i] = fact[i - 1] * i % somod;
    invfact[maxn - 1] = Pow(fact[maxn - 1], somod - 2);
    for(int i = maxn - 2; i >= 0; i--) invfact[i] = (invfact[i + 1] * (i + 1)) % somod;
}

int C(int k, int n)
{
    return fact[n] * invfact[k] % somod * invfact[n - k] % somod;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    Prepare();
    cin >> n >>a >> b >> c >> d;
    for(int i = 1; i < maxn; i++)
    {
        cac[i][0] = 1;
        for(int j = 1; j < maxn; j++)
        {
            if(i * j <= n) cac[i][j] = cac[i][j - 1] * C(i, j * i) % somod;
        }
    }
    dp[a - 1][0] = 1;
    for(int i = a; i <= b; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = c; k <= d; k++)
            {
                if(i * k > j) break;
                Add(dp[i][j], dp[i - 1][j - i * k] * C(i * k, n - j + i * k) % somod * cac[i][k] % somod * invfact[k] % somod);
            }
        }
        for(int j = 0; j <= n; j++) Add(dp[i][j], dp[i - 1][j]);
    }
    cout << dp[b][n];
}

Measured memory_bytes: 15104
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  sort(all(v));
  reverse(all(v));
  vector<ll> v1;
  v1.pb(v[0]);
  rep(i,1,v.sz){
    v1.pb(v[i]);
    v1.pb(v[i]);
  }
  ll ans = 0;
  rep(i,0,n-1){
    ans += v1[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8964
#include <iostream>
#include <string>
#include <vector>
#include <iterator>

using namespace std;

int main() {
	int i;
	int count = 0;
	int change = true;
	string s;
	vector<int> x;

	cin >> s;

	for (i = 0; i < s.length(); i++) {
		x.push_back((int)(s[i])-48);
	}

	while (change) {
		change = false;
		for (i = 0; i < x.size() - 1; i++) {
			if (x.size() < 2) {
				break;
			}
			if (x[i] != x[i + 1]) {
				x.erase(x.begin() + i);
				x.erase(x.begin() + i);
				change = true;
				count += 2;
				break;
			}
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1020
# coding: utf-8

def is_echo(txt:str):
    if len(txt) % 2 != 0:
        return False
    tmp = int(len(txt) / 2)
    return txt[0:tmp] == txt[tmp:]


n = int(input().rstrip())
print("Yes" if is_echo(input().rstrip()) else "No")


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, m;
  cin >> n >> m;
  pqdesc<int> pq;
  rep(i, n) {
    int a;
    cin >> a;
    pq.emplace(a);
  }
  while (m) {
    int a = pq.top(); pq.pop();
    pq.emplace(a >> 1);
    m--;
  }
  i64 ans = 0;
  while (pq.size()) {
    ans += pq.top(), pq.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 892
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int, C: int):
    print(C - min(A-B, C))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def main():
    S = input()
    from string import ascii_lowercase
    ans = 1000
    for tar in ascii_lowercase:
        T = [s for s in S]
        if tar not in T:
            continue
        cur = 0
        while len(set(T)) != 1:
            for i in range(len(T)-1):
                if T[i] == tar or (i + 1 < len(T) and T[i+1] == tar):
                    T[i] = tar
            if T:
                T.pop()
            cur += 1
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3768
#include <stdio.h>

int main(void)
{
    long int W,a,b,exchange;
    scanf("%ld %ld %ld",&W,&a,&b);
    if(a>b){
        exchange=a;
        a=b;
        b=exchange;
    }
    
    if(b-a<=W)printf("0\n");
    else printf("%ld\n",b-a-W);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int n;

void dfs(string t, char mx){
  if (t.size() == n){
    cout <<t <<endl;
    return;
  }
  for (char c = 'a'; c<=mx; c++){
    dfs(t+c, ((c==mx) ? (char)(mx+1) : mx));
  }

}

int main() {
  cin >>n;
  string s = "";
  dfs(s, 'a');
}

/*
0
00 01
000 001 010 011 012
0000 0001 0010 0100 0111 0012 0102 0120 0112 0121 0122 0123
00000 00001 00010 00100 01000 01111 
a
aa ab
aaa aab aba abb abc
aaaa aaab aaba abaa abbb aabc a

*/

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

double dist(vector<int> p1, vector<int> p2){
    double dx = p1[0] - p2[0];
    double dy = p1[1] - p2[1];
    return pow(dx*dx + dy*dy, 0.5);
}

int main(){

    // 入力
    int N; cin >> N;
    vector<vector<int>> Map(N, vector<int>(2));
    for(int n=0; n<N; n++) cin >> Map[n][0] >> Map[n][1];

    // 順列全探索
    double kyori=0;
    int cnt=0;
    vector<int> ptn(N); for (int n=0; n<N; n++) ptn[n] = n;
    do{
        double tmp_kyori=0;
        for(int n=1; n<N; n++) tmp_kyori += dist(Map[ptn[n-1]], Map[ptn[n]]);
        kyori += tmp_kyori;
        cnt++ ;
    } while(next_permutation(ptn.begin(), ptn.end()));
    
    cout << fixed<<setprecision(10)<<kyori/cnt << endl;
}

Measured memory_bytes: 4240
A1 = list(map(int,input().rstrip().split()))
A2 = list(map(int,input().rstrip().split()))
A3 = list(map(int,input().rstrip().split()))

a = []
a.append(A1)
a.append(A2)
a.append(A3)

N = int(input().rstrip())
b = []
for i in range(N):
  b.append(int(input().rstrip()))

out = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for t in b:
  for m in range(3):
    for n in range(3):
      if a[m][n] == t :
        out[m][n] = 1

if (out[0][0]==out[1][1]==out[2][2] and out[0][0]== 1 )or \
(out[0][0]==out[1][0]==out[2][0] and out[0][0]== 1 ) or \
(out[0][2]==out[1][1]==out[2][0] and out[0][2]== 1 ) or \
(out[0][1]==out[1][1]==out[2][1] and out[0][1]== 1 ) or \
(out[0][2]==out[1][2]==out[2][2] and out[0][2]== 1 ) or \
(out[0][0]==out[0][1]==out[0][2] and out[0][0]== 1 ) or \
(out[1][0]==out[1][1]==out[1][2] and out[1][0]== 1 ) or \
(out[2][0]==out[2][1]==out[2][2] and out[2][0]== 1 ):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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(){
  string S; cin >> S;
  if(sz(S)%2==1){
    cout << "No" << endl;
    return 0;
  }
  rep(i,sz(S)/2){
    if(S.substr(i*2,2)!="hi"){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  string s;
  cin>>s;

  int ans=0;
  int con=0;
  rep(i,3){
    if(s[i]!='R'){
      chmax(ans,con);
      con=0;
    }else{
      con++;
    }
  }
  chmax(ans,con);

  return ans;
}

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


Measured memory_bytes: 3624
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

a,b,c,x,y =inp
able = [x,y].min
fans = 1e30
ans = c*able*2
ans += (x-able)*a
ans += (y-able)*b
fans = [ans,fans].min
fans = [a*x + b*y,fans].min
fans = [c*[x,y].max*2,fans].min
puts fans

Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

	string s;
	cin >> s;

	for (int i = 0; i < 4; i++) {
		char tmp = s[i];
		int num = 0;
		for (int j = 0; j < 4; j++) {
			if (tmp == s[j]) {
				num++;
			}
		}
		if (num != 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int n, root = 0;
vector<int> c, ans;
vector<vector<int>> v;
queue<long long> qu;
bool ch[100005] = {0};

bool asc(const int l, const int r) {
  return v[l].size() > v[r].size();
}

long long solve();

int main() {
  cin >> n;
  v.resize(n);
  ans.assign(n, -1);
  c.resize(n);
  for(int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for(int i = 0; i < n; ++i) cin >> c[i];
  cout << solve() << endl;
  for(int i = 0; i < n; ++i) {
    if(i != 0) cout << " ";
    cout << ans[i];
  }
  return 0;
}

long long solve() {
  long long ansnum = 0;
  sort(c.begin(), c.end());
  for(int i = 0; i < n; ++i)
    if(v[i].size() > v[root].size()) root = i;
  ans[root] = c[n - 1];
  qu.push(root);
  c.pop_back();
  ch[root] = 1;
  while(qu.size() > 0) {
    int now = qu.front();
    qu.pop();
    // sort(v[now].begin(), v[now].end());
    for(int i = 0; i < v[now].size(); ++i)
      if(!ch[v[now][i]]) {
        ans[v[now][i]] = c[c.size() - 1];
        c.pop_back();
        ansnum += ans[v[now][i]];
        qu.push(v[now][i]);
        ch[v[now][i]] = 1;
      }
  }
  return ansnum;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	if(N<4){
		cout << "No";
		return 0;
	}

	for(int x = 0; x<=N; x++){
		for(int y = 0; y<=N; y++){
			if(4*x + 7*y == N){
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";


}



Measured memory_bytes: 256
from itertools import product

S = input()
N = len(S)
ans = 0
for opes in product(("", "+"), repeat=N - 1):
    eqn = "".join(s + o for s, o in zip(S[:-1], opes)) + S[-1]
    ans += sum(map(int, eqn.split("+")))
print(ans)


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

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

using namespace std;

using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    const ll limit = pow(10, 18);
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    sort(all(A));

    cpp_int ans = 1;
    rep(i, N) {
        ans *= A[i];
        if (ans > limit) {
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll x;
   cin>>x;
  ll y=100;
 
  int count = 0;
  
  while(y<x){
    y += y/100;
      count++ ;
    }
    
    cout<<count<<endl;
}
    
  
  


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M;
  cin >> N >> M;

  VVI G(N);
  REP(i,M){
	int a, b;
	cin >> a >> b;
	--a;
	--b;
	G[a].PB(b);
	G[b].PB(a);
  }

  vector<bool> vis(N);
  function<int(int)> dfs = [&](int u){
	vis[u] = true;
	int res = 1;
	for(int to: G[u]){
	  if(vis[to]) continue;
	  res += dfs(to);
	}
	return res;
  };

  LL a = dfs(0);
  LL b = dfs(1);
  LL s = N - a - b;
  auto C2 = [](LL x){ return x*(x-1)/2; };
  if(a < b) swap(a, b);
  cout << C2(a+s)+C2(b) - M << endl;
  
  return 0;
}


Measured memory_bytes: 12032
#include<stdio.h>
 
#define N 100000
  
typedef struct{
  int a;
  int b;
  int c;
  int d;
}node;
   
node A[100000];
int n;
void init(){
  int i;
  for(i=0;i<n;i++){
    A[i].b=-1;
    A[i].c=-1;
    A[i].d=-1;
  }
  return;
}
  
  
int depth(int now){
  int dep = 0; 
  while(1){
    if(A[now].b == -1)return dep;
    else {
      now=A[now].b;
      dep++;
    }
  }
}
  

int main(int argc,char *argv[]){
  int i,j,now,leaf,k;
    
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%d",&now);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&leaf);
      if(j==0){
    A[now].c=leaf;
    A[leaf].b=now;
      }
      else {
    A[now].d=leaf;
    A[leaf].b=A[now].b;
      }  
      now=leaf;
    }
  }
  for(i=0;i<n;i++){
    A[i].a=depth(i);
  }
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,A[i].b,A[i].a);
    if(A[i].b==-1)printf("root, ");
    else if(A[i].c==-1)printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    for(j=A[i].c;j!=-1;j=A[j].d){
      if(j==A[i].c)printf("%d",j);
      else printf(", %d",j);
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>

using namespace std;
typedef long long ll;

int __gcd(int x, int y)
{
    if (y == 0) return x;
    return __gcd(y, x % y);
}


int main(){
    int s, w, a;
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }


    return 0;
}

Measured memory_bytes: 3128
n = int(input())
b = list(map(int, input().split()))

ans = []
flg = True
for x in range(n):
    memo = -1
    for i in range(len(b)):
        if b[i] == i+1:
            memo = i
    if memo == -1:
        flg = False
        break
    ans.append(memo+1)
    b.pop(memo)

if flg:
    print(*ans[::-1], sep='\n')
else:
    print(-1)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,sum=0,mini=101;

int main(){
    cin>>N;
    int s[N];
    rep(i,N){
        cin>>s[i];
        sum+=s[i];
        if(s[i]%10!=0){
            mini=min(mini,s[i]);
        }
    }
    if(sum%10!=0){
        out(sum);
    }else if(sum%10==0&&mini!=101){
        out(sum-mini);
    }else{
        out(0);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
int main(){
	daman;
	double a,b,c,k;
	cin>>a>>b>>c>>k;
	
	double cons = a/b;
	
	int count = log(a/b)/(double)log(2) + 1.0;
	
	
	if(count > k)
		cout<<"No\n";
	else
	{
		cons = (pow(2,count)*b/c); 
		
		count += log(cons)/(double)log(2) + 1;
		
		if(count <= k)
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
}

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

using namespace std;
using ll = long long;

//constructor: LCA(graph);
template<class T> 
class LCA_weight {
private:
    int n;
    int D = 30;                        //hight
    vector<int> depth;                 //depth from root
    vector<vector<pair<int,T>>> hen;   //tree
    vector<vector<int>> par;           //doubling array
    vector<T> dista;                    //distance form root

    void dfs(int v, int p, int dep, T dep_dist) {
        par[v][0] = p;
        depth[v] = dep;
        dista[v] = dep_dist;
        for(auto i : hen[v]) {
            if(i.first == p)continue;
            dfs(i.first, v, dep + 1, dep_dist + i.second);
        }
    }

public:

    LCA_weight(const vector<vector<pair<int,T>>>& hen):hen(hen) {
        n = hen.size();
        par.resize(n, vector<int>(D + 1));
        depth.resize(n);
        dista.resize(n);

        dfs(0, -1, 0, 0);
        for(int i = 0; i < D; i++) {
            for(int j = 0; j < n; j++) {
                if(par[j][i] == -1)par[j][i + 1] = -1;
                else par[j][i + 1] = par[par[j][i]][i];
            }
        }
    }

    //go back to root
    int back(int v, int dist) {
        for(int i = 0; i < D; i++)if((1 << i) & dist) {
            if(v == -1)return v;
            v = par[v][i];
        }
        return v;
    }



    //get LCA
    int get(int u, int v) {
        int ret = 0;
        if(depth[u] > depth[v])swap(u, v);
        ret = depth[v] - depth[u];
        v = back(v, ret);
        if(u == v)return v;

        for(int i = D; i >= 0; i--) {
            if(par[u][i] != par[v][i]) {
                u = par[u][i];
                v = par[v][i];
            }
        }
        return par[u][0];
    }

    //u-v path distance
    T dist(int u, int v) {
        int lca = get(u, v);
        return (dista[u] + dista[v]) - dista[lca] * 2;
    }

    //print parents
    void print(int i) {
        cerr << "[";
        for(int j = 0; j < n; j++)cerr << par[j][i] << (j == n - 1 ? "" : ",");
        cerr << "]";
    }

};

int main()
{
    int n; cin >> n;
    vector<vector<pair<int,ll>>> hen(n);
    for(int i = 0; i < n - 1; i++) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        hen[a].emplace_back(b, c);
        hen[b].emplace_back(a, c);
    }
    LCA_weight<ll> lca(hen);
    int q, k; cin >> q >> k;
    k--;
    while(q--) {
        int s, t; cin >> s >> t; s--, t--;
        cout << lca.dist(s, k) + lca.dist(t, k) << endl;
    }
}

Measured memory_bytes: 42548
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

signed main(){
	int n, m;
	cin >> n >> m;
	if(n == m)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string n;
    cin >> n;
    if (n[n.size()-1]=='s') {
        n.push_back('e');
        n.push_back('s');
    }
    else n.push_back('s');
    cout << n << endl;
    return 0;
}

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

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

	if ((n - 1) * (n - 2) / 2 < k)
	{
		cout << -1 << endl;
		return 0;
	}

	int64_t x = (n - 1) * (n - 2) / 2 - k;

	vector<pair<int64_t, int64_t>> vs;
	for (int64_t i = 2; i <= n; i++)
	{
		vs.push_back({1, i});
	}

	for (int64_t t = 0, i = 2; t < x && i <= n; i++)
	{
		for (int64_t j = i + 1; j <= n && t < x; j++, t++)
		{
			vs.push_back({i, j});
		}
	}

	cout << vs.size() << endl;
	for (auto &p : vs)
	{
		cout << p.first << ' ' << p.second << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(){
  char S[100000] = {}; scanf("%s", S);
  int length = strlen(S);
  /* int ans = sizeof(S); */
  int i, j, count, ans;

  for(i = 0; i < 2; i++){
    count = 0;
    for(j = 0; j < length; j++){
      if(j % 2 == 0 && S[j] != (char)(i + '0')) count++;
      if(j % 2 == 1 && S[j] == (char)(i + '0')) count++;
    }
    if(i == 0)ans = count;
  }

  ans = (ans < count ? ans : count);
  
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/


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

	int n;
	cin >> n;
	vector<int> c(n - 1), s(n - 1), f(n - 1);

	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}

	vector<int> ans(n, 0);

	rep(i, n) { // 駅iから出発する
		Rep(j, i, n - 1) { // 駅jから駅j + 1へ移動する
			if (s[j] > ans[i]) {
				ans[i] = s[j];
			}
			if (ans[i] % f[j] != 0) {
				ans[i] += f[j] - (ans[i] % f[j]);
			}
			ans[i] += c[j];
		}
	}

	rep(i, n) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int W, H;
  while (cin >> W >> H, W) {
    vs v(H);
    rep(i, H) cin >> v[i];
    vvi dp(H, vi(W));
    int b = 0, w = 0;
    rep(i, H) rep(j, W) {
      dp[i][j] = 2 * (v[i][j] == 'B') + (v[i][j] == 'W');
      b -= v[i][j] == 'B';
      w -= v[i][j] == 'W';
    }
    rep(_, W * H) rep(i, H) rep(j, W) {
      if (v[i][j] != '.') continue;
      if (i > 0) dp[i][j] |= dp[i - 1][j];
      if (j > 0) dp[i][j] |= dp[i][j - 1];
      if (i < H - 1) dp[i][j] |= dp[i + 1][j];
      if (j < W - 1) dp[i][j] |= dp[i][j + 1];
    }
    rep(i, H) rep(j, W) {
      b += dp[i][j] == 2;
      w += dp[i][j] == 1;
    }
    cout << b << ' ' << w << endl;
  }
}

Measured memory_bytes: 3004
data = input().split(" ")
n = int(data[0])
k = int(data[1])
q = int(data[2])
a = [0] * n
for i in range(q):
	a[int(input())-1] += 1
for i in range(n):
	if k - q + a[i] <= 0:
		print("No")
	else:
		print("Yes")


Measured memory_bytes: 4804
function Main(input) {
    input = input.split("\n");
    var a = parseInt(input[0].split(" ")[0]);
    var b = parseInt(input[0].split(" ")[1]);
    var  po = 1;
    var  ans = 0;

    var k = 1 / a;
    for (var i = 0; i < a; i++) {
        po=0;
        while (true) {
            c = (i+1)*Math.pow(2, po);
            if (c >= b) {
                break;
            }
            po++;
        }
        ans += k*Math.pow((0.5), po);
    }
    console.log(ans);
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define REP(x,a) for(int i = x;i < a;i++)
int main(){
	int n,m,x;
	cin >> n >> m >> x;
	bool e[n];
	REP(0,n) e[i] = false;
	REP(0,m) {
		int tmp;
		cin>>tmp;
		e[tmp-1] = true;
	}
	int a =0,b = 0;
	REP(0,x) {
		if(e[i]) a++;
	}
	REP(x, n)
	{
		if (e[i])
			b++;
	}
	cout << (min(b, a)) << endl;
}

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

for i in range(0,n):
    v = a[i]
    j = i - 1
    while 0 <= j and v < a[j]:
        a[j+1] = a[j]
        j = j - 1
    
    a[j+1] = v

    print(*a)


Measured memory_bytes: 5976
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {

  ll N;
  cin>>N;
  ll A[N+2]={};
  FOR(i,0,N-1){
    cin>>A[i+1];
  }
  ll sum=0;
  FOR(i,0,N){
    sum=abs(A[i],A[i+1])+sum;
  }

  FOR(i,0,N-1){
    if( ( (A[i]-A[i+1]) * (A[i+1]-A[i+2]) )<0 ){
      ll sabun= 2*min(abs(A[i]-A[i+1]),abs(A[i+1]-A[i+2]));
      cout<<(sum-sabun)<<endl;

    }else{
      cout<<sum<<endl;
    }
  }


  return 0;
}
 


Measured memory_bytes: 2048
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    # a, b = map(int, input().split())

    s = input()

    for i in s:
        if s.count(i) != 2:
            print('No')
            return

    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 7708
#include <stdio.h>

int main(){
	int K;
	int X;
	int total;
	scanf ("%d %d",&K,&X);
	total = K * 500;
	if (total < X){
		printf("No");
	}
	else if (total >= X){
		printf("Yes");
	}
	return 0;
}

Measured memory_bytes: 2104
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

int main(){
    int A,B,C;
    cin >> A >> B >> C;

    if (A==B)cout << C << endl;
    else if (B==C) cout << A << endl;
    else cout << B << endl;

    return 0;
}


Measured memory_bytes: 256
n, m, x = gets.split.map(&:to_i)
books = []
n.times { books << gets.split.map(&:to_i) }
tmp = []
tmp << [0] * (m + 1)
n.times do |i|
  tmp_2 = []
  tmp.each do |ary|
    ary_1 = ary.dup
    ary_2 = ary.dup
    books[i].each_with_index do |b, b_i|
      ary_1[b_i] += b
    end
    tmp_2 << ary_1
    tmp_2 << ary_2
  end
  tmp = tmp_2
end
ans = -1
tmp.each do |ary|
  cost = ary.shift
  next if ary.any? { |skill| skill < x }
  ans = cost if ans == -1 || ans > cost
end
puts ans


Measured memory_bytes: 14812
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        String line = br.readLine();
        char[] str = new char[line.length()];
        char c;
        for(int i = 0; i < line.length(); i++){
            c = line.charAt(i);
            if(c >= 65 && c <= 90){ c += 32; }
            else if(c >= 97 && c <= 122){ c -= 32; }
            str[i] = c;
        }
        String newline = new String(str);
        System.out.println(newline);
    }
}


Measured memory_bytes: 24332
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var str = "1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51";
        var x = str.Split().ToArray();
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine(x[n-1]);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int n , k , x[200000] , maxi , f;
int fpb(int a , int b){
	if(a == 0)return b;
	return fpb(b % a , a);
}
int main(){
	cin >> n >> k;
	for(int i = 1 ; i <=n ; i++){
		cin >> x[i];
		if(i == 1)f = x[i];
		maxi = max(x[i] , maxi);
		f = fpb(f , x[i]);
	}
	if(k <= maxi && k % f == 0)cout << "POSSIBLE" << endl;
	else cout <<  "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3944
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
signed main() {
	int n; cin >> n;
	string s; cin >> s;
	reverse(s.begin(), s.end());
	int white = 0;
	int redplase = 0;
	rip(i, n) {
		if (s[i] == 'W')redplase++;
		else break;
	}
	rip(i, n)if (s[i] == 'W')white++;
	int red = n - white;
	white -= redplase;
	int white2 = 0;
	for (int i = redplase; i < redplase + white; i++)if (s[i] == 'W')white2++;
	cout << min({ red,white-white2 }) << endl;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long
#define N 400005
int n,q;
struct segment{
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r
	int mi[N<<2],tag[N<<2];
	inline void up(int rt){mi[rt]=std::min(mi[ls],mi[rs]);}
	inline void build(int rt,int l,int r){
		mi[rt]=2e9,tag[rt]=2e9;
		if(l==r) return mi[rt]=n,void();
		int mid=l+r>>1; build(lson),build(rson),up(rt);
	}
	inline void down(int rt){
		if(tag[rt]==2e9) return;
		mi[ls]=std::min(mi[ls],tag[rt]);
		mi[rs]=std::min(mi[rs],tag[rt]);
		tag[ls]=std::min(tag[ls],tag[rt]);
		tag[rs]=std::min(tag[rs],tag[rt]);
		tag[rt]=2e9;
	}
	inline void assign(int rt,int l,int r,int x,int y,int v){
		if(x<=l&&r<=y) return mi[rt]=std::min(mi[rt],v),tag[rt]=std::min(tag[rt],v),void();
		int mid=l+r>>1; down(rt);
		if(x<=mid) assign(lson,x,y,v); if(mid<y) assign(rson,x,y,v); up(rt);
	}
	inline int qry(int rt,int l,int r,int x){
		
		if(l==r) return mi[rt];
		int mid=l+r>>1; down(rt);
//		std::cerr<<"seg: "<<(ls)<<' '<<l<<' '<<r<<' '<<tag[ls]<<'\n';
		if(x<=mid) return qry(lson,x); else return qry(rson,x);
	}
} r,c;
int main(){
	std::ios::sync_with_stdio(0);
	std::cin>>n>>q;
	ll sum=0;
	r.build(1,1,n),c.build(1,1,n);
	while(q--){
		int opt,x; std::cin>>opt>>x;
		if(opt==1){
			int pos=c.qry(1,1,n,x);
			sum+=pos-2;
			c.assign(1,1,n,x,x,1);
			r.assign(1,1,n,1,pos,x);
		} else {
			int pos=r.qry(1,1,n,x);
			sum+=pos-2;
			r.assign(1,1,n,x,x,1);
			c.assign(1,1,n,1,pos,x);
		}
//		rep(i,1,n) std::cerr<<r.qry(1,1,n,i)<<" \n"[i==n];
//		rep(i,1,n) std::cerr<<c.qry(1,1,n,i)<<" \n"[i==n];
	}
	std::cout<<(n-2ll)*(n-2ll)-sum<<'\n';
	return 0;
}

Measured memory_bytes: 11792
import java.util.*;

public class Main{
    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        String S = scanner.nextLine();
        String T = scanner.nextLine();

        if( T.substring(0,T.length()-1).equals(S) ){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35552
#include<stdio.h>
int d[26];
char str[42];
int main(){
	scanf("%s",str);
	for(int i=0;str[i];i++)d[str[i]-'a']++;
	int v=0;
	for(int i=0;i<26;i++)if(d[i]%2)v++;
	if(v>1)printf("0\n");
	else{
		int n=0;
		for(int i=0;i<26;i++){
			d[i]/=2;
			n+=d[i];
		}
		long long ret=1;
		for(int i=0;i<n;i++)ret*=i+1;
		for(int i=0;i<26;i++){
			//long long val=1;
			for(int j=1;j<=d[i];j++)ret/=j;
		}
		printf("%lld\n",ret);
	}
}

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


int main(void){
    int a, b;
    cin >> a >> b;
    string s;
    if(a%2==0 || b%2==0){
        s = "No";
    }else{
        s = "Yes";
    }
    cout << s << endl;
    return 0;
}


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

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    int N, K;
    vector<int> p;

    cin >> N >> K;
    p = vector<int>(N);
    rep(i, N) cin >> p[i];

    // Process
    int ans;

    sort(p.begin(), p.end());

    ans = 0;
    rep(i, K) ans += p[i];

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
const int INF = 1000000009;

std::string s;
int des[2];
int init = -1;
std::vector<int> move[2];//[0]:x, [1]:y

int main(){
	std::cin >> s;
	scanf("%d%d", &des[0], &des[1]);
	bool a = true;
	int cnt = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'T'){
			if(init == -1){
				init = cnt;
			}else{
				if(a){
					move[0].push_back(cnt);
				}else{
					move[1].push_back(cnt);
				}
			}
			a = !a;
			cnt = 0;
		}else{
			cnt++;
		}
		/*/
		if(s[i] == 'T'){
			if(init == -1){
				init = cnt;
				cnt = 0;
				a = !a;
				continue;
			}
			if(cnt){
				if(a){
					if(init != -1){
						move[0].push_back(cnt);
					}else{
						init = cnt;
					}
				}else{
					move[1].push_back(cnt);
				}
			}
			cnt = 0;
			a = !a;
		}else{
			cnt++;
		}
		//*/
	}
	if(a){
		if(init == -1){
			init = cnt;
		}else{
			move[0].push_back(cnt);
		}
	}else{
		move[1].push_back(cnt);
	}
	std::set<int> pos[2][2];//[XorY][FirstOrSecond]
	pos[0][1].insert(init);
	pos[1][1].insert(0);
	bool possible = true;
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < move[i].size(); j++){
			for(auto k = pos[i][1].begin(); k != pos[i][1].end(); k++){
				pos[i][0].insert(*k + move[i][j]);
				pos[i][0].insert(*k - move[i][j]);
			}
			pos[i][1] = pos[i][0];
			pos[i][0].clear();
		}
		if(pos[i][1].find(des[i]) == pos[i][1].end()){
			possible = false;
		}
	}
	if(possible){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	/*/
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < move[i].size(); j++){
			printf("%d ", move[i][j]);
		}
		printf("\n");
	}
	printf("init %d\n", init);
	//*/
	return 0;
}

Measured memory_bytes: 896
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=3000;
const int MOD=1000000007;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }
void dec(int &a,int b) { inc(a,MOD-b); }

int n;
char s[MAXN-1+1];

int dp[MAXN];
int sum[MAXN+1];
int ndp[MAXN];

int solve() {
	dp[0]=1;
	FOR(i,1,n) {
		char c=s[i-1];
		sum[0]=0; REP(j,i) { sum[j+1]=sum[j]; inc(sum[j+1],dp[j]); }
		REPE(j,i) {
			ndp[j]=0;
			if(c=='<') {
				inc(ndp[j],sum[i]);
				dec(ndp[j],sum[j]);
			} else {
				inc(ndp[j],sum[j]);
			}
		}
		REPE(j,i) dp[j]=ndp[j];
		//printf("%d:",i); REPE(j,i) printf(" %d",dp[j]); puts("");
	}
	int ret=0; REP(j,n) inc(ret,dp[j]); return ret;
}

void run() {
	scanf("%d",&n);
	scanf("%s",s);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 256
import numpy as np
start,end = [int(x) for x in input().strip().split(" ")]

def get_nth_sum(n,x):
    if x < 0:
        return 0
    ret =x//(2**n)* (2**(n-1)) + max(0,x%(2**n) - 2**(n-1)+1 ) 
    return ret %2

ret = 0
for i in range(1,np.log2(end).astype(int)+3):
    ret += 2**(i-1) * ((get_nth_sum(i,end) - get_nth_sum(i,start-1))%2)
print(ret) 

Measured memory_bytes: 12440