akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
	int a,b,c,t,flag=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b)
	{
		t=a;
		a=b;
		b=t;
	}
	if(a<c)
	{
		t=a;
		a=c;
		c=t;
	}
	if(b<c)
	{
		t=b;
		b=c;
		c=t;
	}
	if(a-c==b)
	printf("Yes");
	else
	printf("No");
	return 0;
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0,};

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll k; cin>>k;
    ll n = 50;

    ll x,y;
    x = k/n;
    y = k%n;
    // ll a_base = (x+1)*n - 1 - y;
    ll a_base = ( n - 1 ) + x - y;
    vint ans(n, a_base);
    rep(i,y){
        ans[i] += n - (i+1) + 2;
    }

    cout << n <<endl;
    for(auto e:ans) cout<<e<<" ";
    cout<<endl;


    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		while(stdIn.hasNext()){
			int n = stdIn.nextInt();
			int cnt = 0;
			int end = Math.min(n, 1000);
			for(int a=0;a<=end;a++){
				for(int b=0;b<=end;b++){
					int cd = n-a-b;
					if(cd<0) break;
					if(cd>2000) continue;
					if(cd<=1000) cnt+=cd+1;
					else cnt+=1000-(cd-1000)+1;
				}
			}
			System.out.println(cnt);
		}
	}
}

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

using namespace std;

int main()
{
  long n,i,brk=0,cnt=0,a;
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>a;
    if(a==(i-brk))
    {
      cnt++;
    }
    else
    {
      brk++;
    }
  }
  if(cnt)
    cout<<brk;
else
    cout<<"-1";
  return 0;
}

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

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

template <typename T> class DisjointSet {
private:
    vector<T> rank, p;

    void link(T x, T y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        } else {
            p[x] = y;
            if (rank[x] == rank[y]) { rank[y]++; }
        }
    }

public:
    DisjointSet() {}
    DisjointSet(const DisjointSet& tree) : rank(tree.rank), p(tree.p) {}
    DisjointSet(T size) : rank(size, 0), p(size, 0) {
        rep(i, 0, size) { make_set(i); }
    }
    void make_set(T x) {
        p[x] = x;
        rank[x] = 0;
    }
    bool same(T x, T y) { return find_set(x) == find_set(y); }
    void unite(T x, T y) { link(find_set(x), find_set(y)); }
    T find_set(T x) {
        if (x != p[x]) {
            p[x] = find_set(p[x]);
            rank[x] = 1;
        }
        return p[x];
    }
};

struct Edge {
    int s, t, w;
    Edge(int _s = 0, int _t = 0, int _w = 0) : s(_s), t(_t), w(_w) {}
    Edge(const Edge& e) : s(e.s), t(e.t), w(e.w) {}
    bool operator<(const Edge& e) const { return w < e.w; }
};

vector<Edge> kruskal(int n, vector<Edge>& edges) {
    sort(edges.begin(), edges.end());

    DisjointSet<int> dset(n + 1);
    vector<Edge> K;

    for (auto e : edges) {
        // Append e only if e connects different parts of the graph.
        if (dset.find_set(e.s) != dset.find_set(e.t)) {
            dset.unite(e.s, e.t);
            K.push_back(e);
        }
    }
    return K;
}

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

    int n, e;
    cin >> n >> e;

    vector<Edge> edges;
    rep(i, 0, e) {
        int s, t, w;
        cin >> s >> t >> w;
        edges.emplace_back(s, t, w);
    }

    vector<Edge> K = kruskal(n, edges);
    int ans = 0;
    for (auto e : K) { ans += e.w; }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4572
// doot diddly donger cuckerino Hahahahahah


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vi = vector<int>;

template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());





#ifdef LOCAL
void signalHandler(int) {
  throw "Abort detected";
}
#endif

void doReplace() {
}

template <typename T, typename U, typename...Vs>
void doReplace(T &t, const U &u, Vs &&...vs) {
  t = u;
  doReplace(vs...);
}

template <typename T, typename...Us>
T minim(T &was, const T &cand, Us &&...us) {
  if (was > cand) {
    was = cand;
    doReplace(us...);
  }
  return was;
}

template <typename T, typename...Us>
T maxim(T &was, const T &cand, Us &&...us) {
  if (was < cand) {
    was = cand;
    doReplace(us...);
  }
  return was;
}

struct DSU {
  int n;
  std::vector<int> par;
  std::vector<int> rank;
  
  explicit DSU(int _n) : n(_n) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 1;
    }
  }
  
  int root(int x) {
    return par[x] = (x == par[x]) ? x : root(par[x]);
  }
  
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return true;
    if (rank[x] < rank[y]) swap(x, y);
    par[y] = x;
//    if (rank[x] == rank[y]) rank[x]++;
    rank[x] += rank[y];
    return false;
  }
  
  int Count() {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (root(i) == i) cnt++;
    }
    return cnt;
  }
};

class AReachableTowns {
public:
  
  void solve(std::istream& cin, std::ostream& cout) {
    int n;
    cin >> n;
    DSU dsu(n);
    vector<pair<pair<int, int>, int>> vec(n);
    for (int i = 0; i < n; ++i) {
      cin >> vec[i].first.first >> vec[i].first.second;
      vec[i].second = i;
    }
    sort(vec.begin(), vec.end());
    stack<pair<int, int>> st;
    for (auto v: vec) {
      auto[x, y, id] = tie(v.first.first, v.first.second, v.second);
      int z = y;
      while (!st.empty() && st.top().first < y) {
        mini(z, st.top().first);
        dsu.unite(id, st.top().second);
        st.pop();
      }
      st.push({z, id});
    }
    for (int i = 0; i < n; ++i) {
      cout << dsu.rank[dsu.root(i)] << '\n';
    }
  }
};

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	AReachableTowns solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 7160
from bisect import bisect_right
from numpy import cumsum

n, m, k = map(int, input().split())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
a_cum = cumsum(alst)
b_cum = cumsum(blst)
ans = bisect_right(b_cum, k)
for i, num in enumerate(a_cum, start = 1):
    if num > k:
        break
    tmp = k - num
    ans = max(ans, bisect_right(b_cum, tmp) + i)
print(ans)

Measured memory_bytes: 58512
n, c, k = map(int, input().split())
T = [0] * n
for i in range(n):
    T[i] = int(input())
 
T.sort()
ans, s, m = 0, 0, 0
 
for t in T:
    if m == 0:
        s = t
        m = 1
        ans += 1
    else:
        if t <= s + k:  # kill me now
            m += 1
        else:
            s = t
            m = 1
            ans += 1
    if m == c:
        m = 0
 
print(ans)

Measured memory_bytes: 13180
s = input()
s=s[::-1]
words = ['maerd','remaerd','esare','resare']
s_long=len(s)
i=0
flag = 1
while i<s_long:
    flag2 = 0
    for j in range(4):
        words_long=len(words[j])
        if s[i:i+words_long]==words[j]:
            i += words_long
            break
        else:
            flag2 += 1
    if flag2 == 4:
        flag = 0
    if not flag:
        break
if flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
import bisect
n,m,k = map(int,input().split())
a_list = [0]+list(map(int,input().split()))
b_list = list(map(int,input().split()))
b_added = [0]
for b_i in b_list:
    b_added.append(b_added[-1]+b_i)
    if b_added[-1]>k:
        break
    
max_book = 0
temp_ki = 0
break_flag = False
for i in range(len(a_list)):
    temp_ki += a_list[i]
    if temp_ki > k:
        if i-1>max_book:
            max_book = i-1
        break_flag = True
        break
    temp_j = bisect.bisect(b_added,k-temp_ki)-1
    if i+temp_j > max_book:
        max_book = i+temp_j
        
print(max_book)

Measured memory_bytes: 113556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String input[] = br.readLine().split("\\s+");

			BigInteger A = new BigInteger(input[0]);
			BigInteger B = new BigInteger(input[1]);

			BigInteger ans = A.multiply(B);

			System.out.println(ans);

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
}




Measured memory_bytes: 246540
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

main = do
  [n,a,b] <- getInts
  xs <- getInts
  print $ fst $ foldl (\(acc,px) x -> (acc + min ((x-px)*a) b, x)) (0,head xs) xs

-- util
getInts :: IO [Integer]
getInts = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine

substr :: Int -> Int -> B.ByteString -> B.ByteString
substr b l s = B.take l $ B.drop b s


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

using namespace std;

int solve(vector<int> a, int n) {
	vector<int> b(n);
	iota(b.begin(), b.end(), 0);
	int ans = 0;
	do {
		if (a == b) {
			return ans;
		}
		ans++;
	} while (next_permutation(b.begin(), b.end()));
}

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

    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for (auto &t : p) {
    	cin >> t;
    	t--;
    }
    for (auto &t : q) {
    	cin >> t;
    	t--;
    }
    cout << abs(solve(p, n) - solve(q, n)) << endl;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
class sub
{
    private:
        int ac;
        int wa;
    public:
        sub()
        {
            ac=0;
            wa=0;
        }
        int getac()
        {
            return ac;
        }
        int getwa()
        {
            return wa;
        }
        void inrac()
        {
            ac++;
        }
        void inrwa()
        {
            wa++;
        }
};
int main()
{
    int n,m;
    cin>>n>>m;
    sub S[n+1];
    int p;
    char s[3];
    while(m--)
    {
        cin>>p>>s;
        if(s[0]=='A')
        {
            if(S[p].getac()==0)
                S[p].inrac();
        }
        else
        {
            if(S[p].getac()==0)
                S[p].inrwa();
        }
    }
    int c=0,w=0;
    for(int i=0;i<=n;i++)
    {
        c=c+S[i].getac();
        if(S[i].getac()!=0)
            w=w+S[i].getwa();
    }
    cout<<c<<" "<<w<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  set<int> st;
  rep(i,n){
    int a; cin >> a;
    if(st.find(a)==st.end()){ st.insert(a); }
    else{ cout<<"NO"<<endl; return 0; }
  }
  cout << "YES" << endl;
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    string T;
    cin >> T;
    
    //PDを繰り返すのが最適解
    //->前の文字がPならDを入れ、後ろの文字がDだったらPを入れるのが最適？
    //1文字目が?だったら？⇒二文字目がDならPを入れ、PならDを入れる？
    REP(i,T.length())
    {
        if(i==0 && T.at(i) == '?')
        {
            //1文字目はD固定でOK　（2文字目がPでもDでも+1になるのは変わらないので）
            T.at(i) = 'D';
        }

        if(T.at(i) == '?')
        {
            //全部D置き換えでいいのでは？
            T.at(i) = 'D';
        }
    }

    cout << T << endl;

    //PD指数を計算
    // ll PD_value = 0;
    // REP(i,T.length())
    // {
    //     if(T.at(i) == 'P')
    //     {
    //         //Pのとき、何もしない？
    //     }
    //     else
    //     {
    //         //Dのとき
    //         if(T.at(i-1) == 'P')
    //         {
    //             //前にPがあればPDで+2、前もDなら+1
    //             PD_value += 2;
    //         }
    //         else
    //         {
    //             //前もDなら+1
    //             PD_value += 1;
    //         }
    //     }
    // }

    // cout << PD_value << endl;
    
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

vector<int> cnt; 

void dfs(Graph &G,int v, int p = -1){ // pはvの親
  for(int nv : G[v]){
    if(nv == p) continue;
    cnt[nv] += cnt[v];
    dfs(G, nv, v);
  }
}

int main(){
  int N; int Q; cin >> N >> Q; 
  Graph G(N);
  for(int i = 1; i < N; i++){
    int a, b; cin >> a >> b;
    a--; b--; //0スタートの木に変える
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cnt.resize(N);
  for(int i = 0; i < Q; i++){
    int p, x; cin >> p >> x;
    p--;
    cnt[p] += x; 
  }
  dfs(G, 0); //index0が根
  for(int i = 0; i < N; i++){
    cout << cnt[i] << " ";
  }
}



Measured memory_bytes: 26624
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N, M, A, B, C, X, Y, L;
    string S, T;
    cin >> N >> L;
    vl a(N);
    FOR(i, 0, N) {
        a[i] = L + i;
    }
ll sum = 0;
    FOR(i, 0, N) {
        sum += a[i];
    }
    ll ans = LINF;
    ll arg = 0;
    FOR(i, 0, N) {
        ll sum2 = 0;
        FOR(j,0,N){
            if(i != j){
                sum2 += a[j];
            }
        }
        if(ans > abs(sum2-sum)){
            ans = abs(sum2-sum);
            arg = sum2;
        }
    }
    cout << arg << endl;
}

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;
const int INF = 1001001001;
const int mod = 1000000007;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> l(m);
    vector<int> r(m);
    rep(i,m) cin >> l.at(i) >> r.at(i);
    int l_max = 0;
    int r_min = INF;
    rep(i,m) l_max = max(l_max,l.at(i));
    rep(i,m) r_min = min(r_min,r.at(i));
    int ans = max(0,r_min-l_max+1);
    cout << ans << endl;
}

Measured memory_bytes: 4028
import sys

n = int(input())
s = [int(input()) for i in range(n)]

s.sort()
p = sum(s)
if p%10 != 0:
    print(p)
    sys.exit()
for i in s:
    if i % 10 != 0:
        print(p - i)
        sys.exit()
print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)


// copied from https://stackoverflow.com/questions/61922160/how-many-distinct-numbers-can-be-generated-by-doing-bitwise-or-of-one-or-more-in
ll fldb(ll  A, ll  B)
{
	ll sft = 0;
  	while ((A >> sft) != (B >> sft))
  	{
    	++sft;
  	}
  	return sft - 1;
}
ll util(ll B, ll n)
{
	for (int m = n - 1; m >= 0; --m)
  	{
    	if ((B >> m) % 2)
      		return m;
    }
  return -1;
}

ll solve(ll A, ll B) {
	if (A == B)
  		return 1;
  	ll n = fldb(A, B);
  	ll m = util(B, n);
  	ll sbits = ((A >> (n + 1)) << (n + 1));
  	ll  c1l = A;
  	ll c2u = sbits + (1ll << n) + (1ll << (m + 1)) - 1;
  	ll c3l = A + (1ll << n);
  	ll c3u = sbits + (1ll << (n + 1)) - 1;
  	if (c2u < c3l - 1)
  		return (c3u - c3l + 1) + (c2u - c1l + 1);
  	else 
    	return c3u - c1l + 1;
}
int main(int argc, char const *argv[])
{
	fast;
	ll a, b;
	cin >> a >> b;
	cout << solve(a, b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
bool solve() {
  int n; cin >> n;
  if(n == 0) return false;
  vector<P> p(n);
  for(int i=0;i<(n);++i) {
    cin >> p[i].first >> p[i].second;
  }
  vector<P> carten(4);
  int u = -INF, d = INF, l = INF, r = -INF;
  for(int i=0;i<(4);++i) {
    int x, y;
    cin >> x >> y;
    chmin(l, x);
    chmax(r, x);
    chmin(d, y);
    chmax(u, y);
  }
  l += 20000;
  r += 20000;
  u += 20000;
  d += 20000;
  vector<pair<int, bitset<40002>>> v;
  for(int i=0;i<(n);++i) {
    P p1 = p[i];
    P p2 = p[(i+1)%n];
    if(p1.first == p2.first) {
      bitset<40002> now;
      int mi = p1.second, ma = p2.second;
      if(mi > ma) swap(mi, ma);
      mi += 20000;
      ma += 20000;
      for(int j=(mi);j<(ma);++j) {
        now[j] = 1;
      }
      v.emplace_back(make_pair(p1.first + 20000, now));
    }
  }
  sort(v.rbegin(), v.rend(), [](pair<int, bitset<40002>> a, pair<int, bitset<40002>> b){return a.first < b.first;});
  bitset<40002> bs(0), tmp(0);
  for(int i=(d);i<(u);++i) {
    tmp[i] = 1;
  }
  int mask = 0;
  int area = 0;
  for(int i=0;i<(40002);++i) {
    while(!v.empty() && v.back().first == i) {
      bs ^= v.back().second;
      v.pop_back();
    }
    if(l <= i && i < r) {
      mask += (bs & tmp).count();
    }
    area += bs.count();
  }
  cout << area - mask << endl;
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(solve()) {}
}



Measured memory_bytes: 3436
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;
#define EXEC(...) void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); }

void exec();
void solve(int t);
void multi() { int TT; cin>>TT; REP1(t,TT) solve(t); }
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    exec();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,M;
vector<int> A(SIZE);

void solve(int _t) {
    cin>>N>>M;
    double x,y;
    int ans = 0;
    REP(i,N) {
        cin>>x>>y;
        if (x*x+y*y <= M*M) {
            ans++;
        }
    }
    _PN(ans);
}
EXEC(1)



Measured memory_bytes: 4960
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n,m; cin >> n >> m;
    int time = 100*(n-m) + 1900*m;

    cout << time * pow(2,m) << endl;
}

Measured memory_bytes: 512
def solve():
  N = int(input())
  A = [int(i) for i in input().split()]
  s = sum(A) // 2
  first = s - sum(A[1::2])
  ans = [ first ]
  for i in range(N - 1):
    ans.append(A[i] - ans[-1])
  print(*map(lambda v: v * 2, ans))

solve()

Measured memory_bytes: 16840
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int num[n+1]={0};
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            cin>>num[i];
            sum+=num[i];
        }
        cout<<sum-n<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}
int main (){
    int N;
    scanf("%d",&N);
    int a[N];
    for (int i = 0; i < N; i++){
        scanf("%d",&a[i]);
    }
    double value=0.0;
    double tmpvalue;

    std::qsort(a,N,sizeof(int),desc);

    for (int i = 0; i < N-1; i++){
        tmpvalue=a[i]/std::pow(2,i+1);
        value+=tmpvalue;
    }
    tmpvalue=a[N-1]/std::pow(2,N-1);
    value+=tmpvalue;
    printf("\n%lf\n",value);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
const int INF = 1001001001;

int dp[1005][4102];

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, 1005) rep(j, 4102) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        int now = 0;
        rep(j, b) {
            int x;
            cin >> x;
            x--;
            now |= 1<<x;
        }
        rep(j, 1<<n) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j|now] = min(dp[i+1][j|now], dp[i][j]+a);
        }
    }
    int ans = dp[m][(1<<n)-1];
    if (ans>=INF) ans = -1;
    
    
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    unordered_set<string> dict;
    string cmd, s;
    for(int i = 0; i < n; ++i) {
        cin >> cmd >> s;
        if(cmd == "insert") dict.emplace(s);
        else if(cmd == "find") {
            if(dict.find(s) == dict.end()) printf("no\n");
            else printf("yes\n");
        }
    }

    return 0;
}


Measured memory_bytes: 29716
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e16
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){rep(i,0,n)cout<<v[i]+1<<"\n";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n,m;cin>>n>>m;
	vvll w(n);
	rep(i,0,m){ll a,b;cin>>a>>b;a--,b--;w[a].pb(b);}
	ll mn=1<<30,pp,v;
	vll real_ans;
	vll ans;
	for(ll start=0;start<n;++start){
		vll p(n,-1),d(n,-1);
		queue<ll>q;
		d[start]=0;
		q.push(start);
		while(!q.empty()){
			v=q.front();q.pop();
			for(auto u:w[v]){
				if(u==start&&mn>d[v]+1){
					mn=d[v]+1,pp=v;
					ans.clear();
					while(pp!=start)ans.pb(pp),pp=p[pp];ans.pb(start);
					// teln(ans,sz(ans));
					// real_ans=ans;
				}
				else if(d[u]==-1)d[u]=d[v]+1,p[u]=v,q.push(u);
			}
		}
	}
	if(sz(ans)==0){tel(-1);}
	else {tel(sz(ans));teln(ans,sz(ans));}
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable, numberOFbegin, numberOFend) for (long long int  LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 2019;//(´^ω^`)

int main(){

    long long int l,r,result=linf;
    cin>>l>>r;
    if(l % mod>=r%mod||(r-l)>=mod){
        l %= mod;    
        r = mod + (r % mod);
    }else{
        l %= mod;
        r %= mod;
    }
    FOR(i,l,r){
        FOR(j, i + 1,r+1){
            //cout << i << " " << j << endl;
            result = min(result, (i*j)%mod);
         //   cout << result << endl;
        }   
    }
    cout<<result<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, m, a, b, c, d, e, f;
string s, t;
int arr[N];

int32_t main(){_

   cin>>n;
      
   int ans = 0;
   for (int i = 1; i <= n; ++i)
   {
      for (int j = 1; j <= n; ++j)
        {
           for (int k = 1; k <= n; ++k)
           {
              ans++;
           }
        }  
   }
   
   cout<<ans;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

void solve(){
  int n; cin >> n;
  set<string> st;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return;
}

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


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

int N;

int main(){
    cin >> N;
    multiset<int> ends;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        // a未満の終端が見つからなかったとき
        if(ends.lower_bound(a) == ends.begin()){
            ends.insert(a);
        }else{// a未満の終端が見つかったとき
            ends.erase(--(ends.lower_bound(a)));
            ends.insert(a);
        }
    }
    cout << ends.size() << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define FOR(n) for(int i=0;i<n;i++)
#define MOD 1e9+7
#define INF 1e9
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
int main(void){
  int a,b;
  cin>>a>>b;
  int ans=abs(a-b);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3100
S = input()

key = list("keyence")
target = 'keyence'

flg = False
for i in range(len(S)):
    for j in range(len(S)):
        tmp = S[0:i]+S[j:]

        if tmp == target and not flg:
            print("YES")
            flg = True
            break

if not flg:
    print("NO")


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


int main() {
  int a,b,c,x;
  cin >>a>>b>>c>>x;
  
  int counter;
  
  for(int i=0;i<=a;++i){
    for(int j=0;j<=b;++j){
      for(int k=0;k<=c;++k){
        if(500*i+100*j+50*k == x) ++counter;
      }
    }
  }
  cout << counter << endl;

}


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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    int x, y;
    cin >> x >> y;
    string q;
    cin >> q;
    if (q == a) {
        cout << x - 1 << ' ' << y << '\n';
    } else {
        cout << x << ' ' << y - 1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    long double ans = 0.0;
    rep(i, n){
        ans += 1. / a[i];
    }
    cout << 1./ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php namespace Track;

function main($lines) {
  foreach ($lines as $index=>$value) {
    if($value == "0"){
        break;
    }
    echo 'Case ',$index+1,': ',$value,PHP_EOL;
  }
}

$array = array();
while (true) {
  $stdin = fgets(STDIN);
  if ($stdin == "") {
    break;
  }
  $array[] = rtrim($stdin);
}
main($array);



Measured memory_bytes: 12040
N=int(input())
ac,wa,tl,re=0,0,0,0
for n in range(N):
  s=input()
  if s=='AC':
    ac+=1
  elif s=='WA':
    wa+=1
  elif s=='TLE':
    tl+=1
  else:
    re+=1
print('AC x {0}'.format(ac))
print('WA x {0}'.format(wa))
print('TLE x {0}'.format(tl))
print('RE x {0}'.format(re))

Measured memory_bytes: 9200
A,B,M = map(int,input().split())
*a, = map(int,input().split())
*b, = map(int,input().split())
XYC = [list(map(int,input().split())) for _ in [0]*M]

ans = min(a) + min(b)
for x,y,c in XYC:
    a0 = a[x-1]
    b0 = b[y-1]
    tmp = a0+b0-c
    ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 39328
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string s;

int main() {
    while (cin >> s) {
	  int res = 0;
	  for (auto c : s) {
		res += (int)(c - '0');
	  }
	  cout << res << endl;
    }
}


















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

int main() {
    int n;
    cin >> n;
    std::string s;
    std::cin >> s;

    bool ng_flg = false;

    for ( int i = 0; i < n / 2; i++ ) {
        if ( s.substr( i , 1 ) != s.substr( i + n / 2, 1 ) ) {
            ng_flg = true;
        }
    }

    if ( n % 2 != 0 | ng_flg == true ) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;

long long int n,m;

int main(){
    scanf("%lld %lld",&n,&m);
    n*=2;
    if(n<m){
        printf("%lld\n",(n+m)/4);
    }
    else{
        printf("%lld\n",min(n,m)/2);
    }
    
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
ans=0
N.times do|i|
    l,r=get_i
  ans+=r-l+1
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

/*
    if you have any question about any part of my code,
    please don't shy to ask anytime :)
*/

void solve()
{
    ll n;
    cin >> n;
    string x;
    cin >> x;

    vector<ll> cumw(n + 5, 0), cumr(n + 5, 0);
    for (int i = 0; i < n; i++)
    {
        cumr[i + 1] = cumr[i];
        cumw[i + 1] = cumw[i];
        if (x[i] == 'R')
        {
            cumr[i + 1]++;
        }
        else
        {
            cumw[i + 1]++;
        }
    }

    ll ans = 0;
    ll l = 0, r = n - 1;
    while (l<r)
    {
        while (l < r && x[l] == 'R')
        {
            l++;
        }

        while (r > l && x[r] == 'W')
        {
            r--;
        }

        if(l==r)
        {
            break;
        }
        ll lol1 = cumr[r+1]-cumr[l];
        ll lol2 = cumw[r+1]-cumw[l];
        if(lol1 && lol2)
        {
            ans++;
            l++;
            r--;
        }
        else
        {
            ans++;
            break;
        }
    }

    cout << ans << endl;
}

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

    // ll t;
    // cin >> t;
    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 6760
s = input()
if s[0] == s[1]:
    if s[2] != s[0]:
        if s[3] == s[2]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if s[2] == s[0]:
        if s[3] == s[1]:
            print('Yes')
        else:
            print('No')
    else:
        if s[2] == s[1]:
            if s[3] == s[0]:
                print('Yes')
            else:
                print('No')
        else:
            print('No')

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

int main() {
    string ans;
    for(int i = 0; i < 3; i++) {
        string S;
        cin >> S;
        ans += S[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int h1, m1, h2, m2, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int mi = ((h2 * 60) - (h1 * 60)) + (m2 - m1);
  cout << mi - k << endl;
}


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

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

using namespace std;                    

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)1e5 + 123, inf = 1e9;
const ll INF = 1e18;

int main(){
	ll a, b, c, d;
	ll ans = 0;
	cin >> a >> b >> c;
	
	d = min(c, b);
	b -= d;
	c -= d;
	ans += 2 * d;

	d = min(c, a);
	a -= d;
	c -= d;
	ans += d;

	cout << ans + min(1ll, c) + b;
	return 0;
}


Measured memory_bytes: 768
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    int N;
    long x;
    readf("%d %d\n", &N, &x);
    long[] a = readln.split.to!(long[]);
    a.reverse();

    long[][] ary = N.iota.map!(i => N.iota.map!(j => a[(i+j)%$]).array).array;
    foreach(i; 0..N) foreach(j; 1..N) {
        ary[i][j] = min(ary[i][j], ary[i][j-1]);
    }

    N.iota.map!(k => k*x + ary.map!(e => e[k]).sum).reduce!min.writeln;
}


Measured memory_bytes: 32508
#include <stdio.h>
 
int main(void)
{
        int n, i, j;
 
        scanf("%d", &n);
 
        for (i = 0; i < n; i++){
                for (j = 0; j < n; j++){
                        if (7 * i + 4 * j == n){
                                printf("Yes\n");
                                return 0;
                        }
                }
        }
 
        printf("No\n");
 
        return 0;
}

Measured memory_bytes: 128
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	string S;
	cin >> S;
	int zero_count = (int)count(S.cbegin(), S.cend(), '0');
	int one_count = (int)S.length() - zero_count;
	cout << 2 * min(zero_count, one_count) << endl;
	return 0;
}

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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n, m, a;
	while(cin >> n >> m >> a, n || m || a)
	{
		vector< vector<P> > Vec(1001);
		for(int i = 0; i < m; ++i)
		{
			int height;
			P p;
			cin >> height >> p.first >> p.second;
			Vec[height].push_back(p);
		}
		int pos = a;
		for(int i = 1000; i >= 0; --i)
		{
			int size = Vec[i].size();
			for(int j = 0; j < size; ++j)
			{
				if(Vec[i][j].first == pos)
				{
					pos = Vec[i][j].second;
					break;
				}
				else if(Vec[i][j].second == pos)
				{
					pos = Vec[i][j].first;
					break;
				}
			}
		}
		cout << pos << endl;
	}
}

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

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

int main()
{
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	ll ans;
	ans=h*W+w*(H-h);
	cout<<H*W-ans<<endl;
	return 0;
}

Measured memory_bytes: 256