akhauriyash/Code-Regression huggingface dataset:
// Warshall-Floyd  algorithm 
// reference Programming Contest Challenge Book Second Edition
// verify https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_B
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

template<typename T> struct Warshall_Froyd {
  vector<vector<T>> G;
  int V;
  T INF;

  Warshall_Froyd(int V_,T INF_ = 1e9) {
    init(V_,INF_);
  }

  void init (int V_,T INF_ = 1e9) {
    V = V_;
    INF = INF_;

    G.resize(V,vector<T>(V,INF_));
    rep(i,V)G[i][i] = 0;
  }

  void add_edge_directed(int from,int to,T cost) {
    G[from][to] = cost;
  }

  void add_edge_non_directed(int from,int to,T cost) {
    G[from][to] = G[to][from] = cost;
  }

  vector<vector<T>> shortest_path() {
    rep(k,V) {
      rep(i,V) {
        rep(j,V) {
          G[i][j] = min(G[i][k] + G[k][j],G[i][j]);
        }
      }
    }

    return G;
  }
};

using ll = long long;


int main() {
  int V,E;
  cin >> V >> E;
  ll INF = 1e18;
  Warshall_Froyd<ll> wf(V,INF);

  rep(i,E) {
    ll s,t,d;
    cin >> s >> t >> d;
    wf.add_edge_directed(s,t,d);
  }

  vector<vector<ll>> d = wf.shortest_path();

  rep(i,V) {
    if(d[i][i] != 0){
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }
  rep(i,V) {
    rep(j,V) {
      if(d[i][j] < INF / 2)cout << d[i][j];//負の辺があるとINFより小さくなることがある
      else cout << "INF";
      cout << ((j < V - 1) ? " " : "");
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){    
    int s,w;
    cin>>s>>w;
    cout<<((s>w)?"safe":"unsafe")<<endl;
}


Measured memory_bytes: 3632
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

import sys
write=sys.stdout.write

B,W=map(int,input().split())

p=[1]
for i in range(1,B+W+1) :
    p.append((p[-1]*inverse[2])%mod)

BD=[0]
for i in range(1,B+W+1):
    t=(BD[-1]+cmb(i-1,B-1,mod)*p[i])%mod
    BD.append(t)

WD=[0]
for i in range(1,B+W+1):
    t=(WD[-1]+cmb(i-1,W-1,mod)*p[i])%mod
    WD.append(t)

for i in range(1,B+W+1):
    ans=(1-BD[i-1]-WD[i-1])*p[1]+WD[i-1]
    ans%=mod
    write(str(ans)+"\n")

Measured memory_bytes: 85084
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;

int group(int n){
    if(n==2) return 3;
    if(n==4 || n==6 || n==9 || n==11) return 2;
    else return 1;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y; cin >> x >> y;
    int x_group = group(x);
    int y_group = group(y);
    if(x_group==y_group) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
from collections import Counter
s = [input() for i in range(N)]
c = Counter(s)

i = c.most_common(1)[0][1]
ans = []
for a, b in c.most_common():
    if i != b:
        break
    ans.append(a)

for i in sorted(ans):
    print(i)

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

const int nm = 1e5;
int n, a[nm], l[nm], r[nm], ans;

int gcd(int a, int b) {
	if (!(a % b))
		return b;
	return gcd(b, a % b);
}

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

	l[0] = a[0];
	for (int i = 1; i < n; i++)
		l[i] = gcd(l[i - 1], a[i]);

	r[n - 1] = a[n - 1];
	for (int i = n - 2; i >= 0; i--)
		r[i] = gcd(r[i + 1], a[i]);

	ans = max(l[n - 2], r[1]);
	for (int i = 1; i < n - 1; i++)
		ans = max(ans, gcd(l[i - 1], r[i + 1]));
	cout << ans << endl;
}


Measured memory_bytes: 1408
//
//AtCoder Beginner Contest 173
//D
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

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

    sort(ALL(a), greater<int>());

    ll ans=0;
    priority_queue<int, vector<int>, less<int>> pq;
    pq.push(a[0]);
    FOR(i,1,n-1){
        ans+=pq.top();
        pq.pop();
        pq.push(a[i]);
        pq.push(a[i]);
    }

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


Measured memory_bytes: 5096
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c,i,ans=0;
	cin>>a>>b;
	for(i=1;i<=b;i++)
	{
		cin>>c;
		ans+=c;
	}
	if(ans>=a)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>

ll H,N;
int main(){
    cin>>H>>N;
    VL A(N);
    ll cnt=0;
    ll i=0;
    while(H>0){
        cin>>A[i];
        H-=A[i];
        if(i==N-1)break;
        cnt++;
        i++;
    }
    if(i==N-1&&H>0)cout<<"No";
    else cout<<"Yes";

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

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

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////
queue<ll> que{};
ll ans;

void bfs(ll y){
	ll nc=y;

while(true){
ll t=que.front();
que.pop();
nc--;
if(nc==0){
ans=t;
return;
}
for(ll i=0;i<=9;i++){
ll last=t%10;
if(abs(last-i)<=1){
que.push((ll)10*t+i);
}
}
}

}




int main() {
ll k;
cin>>k;

ans=0;

for(ll i=1;i<=9;i++){
que.push(i);
}

bfs(k);

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



Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef pair<int,int> P;
struct edge {int to,cap,cost,rev;};
const int MAX_V=3002,INF=1e9+1;
int V;			//代入!!
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
void add_edge(int from, int to, int cap, int cost){
	edge e1={to,cap,cost,G[to].size()},e2={from,0,-cost,G[from].size()};
	G[from].push_back(e1);
	G[to].push_back(e2);
}
int min_cost_flow(int s, int t, int f){
	int res=0;
	fill(h,h+V,0);
	while(f>0){
		priority_queue< P,vector<P>,greater<P> > que;
		fill(dist,dist+V,INF);
		dist[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(dist[v]<p.first) continue;
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					prevv[e.to]=v;
					preve[e.to]=i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF) return -1;
		for(int v=0;v<V;v++) h[v]+=dist[v];
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}
vector<int> ash;
int N,A[1000],B[1000];
inline int id(int x){
	return N+(lower_bound(all(ash),x)-ash.begin());
}
int main(){
	cin>>N;
	rep(i,N) cin>>A[i]>>B[i];
	rep(i,N) if(A[i]>B[i]) swap(A[i],B[i]);
	rep(i,N) ash.pb(A[i]),ash.pb(B[i]);
	sort(all(ash));
	ash.erase(unique(all(ash)),ash.end());
	int M=ash.size();
	int s=N+M,t=N+M+1;
	V=t+1;
	rep(i,N) add_edge(s,i,1,0);
	int ans=0;
	rep(i,N){
		add_edge(i,id(A[i]),1,0);
		add_edge(i,id(B[i]),1,B[i]-A[i]);
		add_edge(i,t,1,B[i]);
		ans+=B[i];
	}
	rep(i,M){
		add_edge(N+i,t,1,0);
	}
	cout<<ans-min_cost_flow(s,t,N)<<endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	string S;
	cin >> S;
	bool find = false;
	int ans = 0;
	int cnt = 0;
	for (int i = 0; i < S.size(); i++) {
		if (!find && S[i] == 'A') {
			find = true;
		}
		if (find) cnt++;
		if (find && S[i] == 'Z') {
			ans = cnt;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3756
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n; cin >> n;
  string s; cin >> s;
  vector<ll> b(n);
  bool f1=0;
  rep(i,n){
    b[i]=ll(s[i]-'0');
  }
  vector<ll> a(n-1);
  rep(i,n-1){
    a[i]=abs(b[i]-b[i+1]);
    if(a[i]==1) f1=1;
  }
  n--;
  ll sum=0;
  rep(i,n){
    if(n-1==(i|(n-1-i))) sum+=a[i]%2;
  }
  if(sum%2==1){
    cout << 1 << endl;
    return 0;
  }
  if(f1){
    cout << 0 << endl;
    return 0;
  }
  rep(i,n){
    a[i]/=2;
  }
  sum=0;
  rep(i,n){
    if(n-1==(i|(n-1-i))) sum+=a[i]%2;
  }
  if(sum%2==1){
    cout << 2 << endl;
    return 0;
  }
  cout << 0 << endl;
}

Measured memory_bytes: 20076
A = []
B = [[0,0,0], [0,0,0], [0,0,0]]
for i in range(3):
  A.append(input().split())
  
N = int(input())
b = []
for i in range(N):
  b.append(int(input()))
  
for i in range(3):
  for j in range(3):
    if int(A[i][j]) in b:
      B[i][j] = 1

bingo = False
if B[0][0] and B[0][1] and B[0][2]:
  bingo = True
if B[1][0] and B[1][1] and B[1][2]:
  bingo = True
if B[2][0] and B[2][1] and B[2][2]:
  bingo = True
if B[0][0] and B[1][0] and B[2][0]:
  bingo = True
if B[0][1] and B[1][1] and B[2][1]:
  bingo = True
if B[0][2] and B[1][2] and B[2][2]:
  bingo = True
if B[0][0] and B[1][1] and B[2][2]:
  bingo = True
if B[0][2] and B[1][1] and B[2][0]:
  bingo = True
  
if bingo:
  print("Yes")
else:
  print("No")

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

const int MOD = 1e9 + 7;

map < long long , int > m;
ll getAns(long long dir){
	if(m[dir])
		return m[dir];
	return m[dir] = (getAns(dir - 2 >> 1) + getAns(dir - 1 >> 1) + getAns(dir >> 1)) % MOD;
}

int main(){
    m[0] = 1;
    m[1] = 2;
	long long N;
	cin >> N;
	cout << getAns(N);
	return 0;
}

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

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;}

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int m;
  cin >> m;
  cout << 48 - m << endl;
}






Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

vector<int> graph[202020];
vector<int> score(202020, 0);

void dfs(int cur, int prev) {
  score[cur] += score[prev];
  for (int next : graph[cur]) {
    if (next == prev) continue;
    dfs(next, cur);
  }
}

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

  int n, q; cin >> n >> q;
  for (int i = 0; i < n - 1; ++i) {
    int a, b; cin >> a >> b;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }

  for (int i = 0; i < q; ++i) {
    int p, x; cin >> p >> x;
    score[p] += x;
  }

  dfs(1, 0);

  for (int i = 1; i <= n; ++i) {
    cout << score[i] << " ";
  }

  return 0;
}

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

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

    char x, y;
    cin >> x >> y;
    int xtwo = x;
    int ytwo = y;
    if (xtwo < ytwo) {
        cout << '<';
        return 0;
    }
    if (xtwo == ytwo) {
        cout << '=';
        return 0;
    } else {
        cout << '>';
        return 0;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define range(i, a, b, s) for (int i = (a); i < (b); i += (s))
#define down(i, a, b, s) for (int i = (a); (b) < i; i -= (s))

int n, m, x, y;

int main(int argc, char const *argv[]) {
  // freopen("C.txt", "r", stdin);

  while (cin >> n >> m) {
    int xx = 1, yy = n;
    range(i, 0, m, 1) {
      cin >> x >> y;
      xx = max(xx, x);
      yy = min(yy, y);
    }
    cout << max(0, yy - xx + 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 888
def gcd(a,b):
    if a>b :
        while b!=0:
            a,b = b,a%b
        return a
    else :
        while a!=0:
            a,b = b%a,a
        return b
######################################
def pff(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf
############################
import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

A, B = LI()
ans = int(1)

cur = gcd(A,B)

ansC = pff(cur)

ans = len(ansC)+1

print(ans)


Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

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

int N, K;

double solve(int cur) {
    if(cur >= K) return 1;

    return 0.5 * solve(cur * 2);
}

int main(int argc, char **argv) {
    cin >> N >> K;

    double res = 0;
    for(int i = 1; i <= N; ++i) {
        res += 1.0 / N * solve(i);
    }
    printf("%.12lf\n", res);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int d,w,e[10][10];

	int x,y,x2,y2,v,max,dote,soko;

	int i,i2;

	for(;;){//データセット

		scanf("%d %d",&d,&w);
		if(d==0)break;

		for(i=0;i<d;i++){
			for(i2=0;i2<w;i2++)scanf("%d",&e[i][i2]);
		}

		max=0;

		for(x=0;x<=d-3;x++){//左上座標
		for(y=0;y<=w-3;y++){
		for(x2=x+2;x2<d;x2++){//右下座標
		for(y2=y+2;y2<w;y2++){

					dote=9;
					soko=0;

					for(i=x;i<=x2;i++){//高さ確認
					for(i2=y;i2<=y2;i2++){

						if(i==x || i==x2 || i2==y || i2== y2){

							if(e[i][i2]<dote)dote=e[i][i2];
							continue;
						}

						if(e[i][i2]>soko)soko=e[i][i2];
					}
					}
//printf("s %d",soko);
//printf("d %d",dote);


					if(dote>soko){//容量
						v=0;
						for(i=x+1;i<x2;i++){
						for(i2=y+1;i2<y2;i2++){
							v+=dote-e[i][i2];
						}
						}
//printf("%d %d\n",e[][],e[][]);
						if(max<v)max=v;

					}
		}
		}
		}
		}

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

	}




	return 0;
}


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

using namespace std;

#define INF 1<<28

struct edge{
    int a,b,c;
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> vec(n+1,vector<int>(n+1,INF));
    vector<edge> ed;

    for(int i = 0; i < m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        vec[a][b] = c;
        vec[b][a] = c;
        ed.push_back(edge{a,b,c});
    }

    for(int k = 1; k < n+1; k++){
        for(int i = 1; i < n+1; i++){
            for(int j = 1; j < n+1; j++){
                if(vec[i][j] > vec[i][k] + vec[k][j]){
                    vec[i][j] = vec[i][k] + vec[k][j];
                }
            }
        }
    }

    for(int i = 1; i < n+1; i++){
        for(int j = 1; j < n+1; j++){
            if(i == j){
                vec[i][j] = 0;
            }
        }
    }

    int result = 0;

    for(int i = 0; i < m; i++){
        bool frag = true;
        for(int j = 1; frag && j < n+1; j++){
            for(int k = 1; frag && k < n+1; k++){
                if( j != k && vec[j][ed[i].a] + ed[i].c + vec[ed[i].b][k] == vec[j][k]){
                    frag = false;
                }
            }
        }
        if(frag){
            result++;
        }
    }

    cout << result << endl;

    return 0;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int w = scn.nextInt();
      	int h = scn.nextInt();
      	int n = scn.nextInt();
		int[] x = new int[n];
      	int[] y = new int[n];
      	int[] a = new int[n];
		for(int i=0; i<n; i++){
			x[i] = scn.nextInt();
          	y[i] = scn.nextInt();
          	a[i] = scn.nextInt();
		}
      	int x0 = 0;
      	int y0 = 0;
      	int x1 = w;
      	int y1 = h;
      	for(int i=0; i<n; i++){
          if(a[i]==1 && x0 < x[i]) x0 = x[i];
          if(a[i]==2 && x1 > x[i]) x1 = x[i];
          if(a[i]==3 && y0 < y[i]) y0 = y[i];
          if(a[i]==4 && y1 > y[i]) y1 = y[i];
        }
      	int ans = (x1-x0)*(y1-y0);
      	if(x0>=x1 || y0>=y1) ans = 0;
      	System.out.println(ans);
	}
}


Measured memory_bytes: 36500
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 40)
using namespace std;
typedef long long ll;

struct state {
  ll v, d;

public:
  bool operator<(const state &s) const { return d > s.d; };
};

ll N, M, S, T, D[100000], A, B;
vector<ll> E[100000];

int main(void) {
  cin >> N >> M >> S >> T; S--; T--;
  REP(i, 0, N) cin >> D[i];
  REP(i, 0, M) {
    cin >> A >> B; A--; B--;
    if(A < B) E[A].push_back(B);
    if(B < A) E[B].push_back(A);
  }

  vector<ll> dp(N, INF);
  priority_queue<state> q;
  q.push((state) { S, 0 });

  while(q.size()) {
    state c = q.top();
    q.pop();

    // cout << c.v << " " << c.d << endl;

    if(c.d >= dp[c.v]) continue;
    dp[c.v] = c.d;

    if(c.v == T) {
      cout << c.d << endl;
      return 0;
    }

    if(c.v - 1 >= 0 && dp[c.v - 1] > c.d) q.push((state) { c.v - 1, c.d });
    for(ll u : E[c.v]) if(dp[u] > c.d + D[u]) q.push((state) { u, c.d + D[u] });
  }
}

Measured memory_bytes: 9792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#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 fir first
#define sec second
#define pb push_back
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; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> D(n);
	rep(i,n){
		cin >> D[i];
	}
	sort(all(D));
	cout << D[n/2] - D[n/2-1] << endl;
	return 0;
}


Measured memory_bytes: 640
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/


void solve() {
	int n; cin >> n;
	vector<string> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	a.resize(unique(a.begin(), a.end()) - a.begin());
	cout << (int)a.size() << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

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

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

using namespace std;

const int maxn = 2e6 + 10;

int n, m, k, bal;
char in[maxn << 1], out[maxn << 1], a[maxn], b[maxn], *pnt, *S, *T;
set<int> s;

struct Info {
	int l, r, a, b, c;

	Info() {}
	Info(int l, int r, int a, int b, int c): l(l), r(r), a(a), b(b), c(c) {}
};

vector<Info> f, nf;

void pb(int l, int r, int x, int y, int z) {
	if(!z || !x && !y) {
		return;
	}
	if(!nf.size()) {
		nf.push_back(Info(l, r, x, y, z));
		return;
	}
	auto &t = nf.back();
	int a = t.a, b = t.b, c = t.c;
	if(a == b) {
		if(x == y) {
			t = Info(t.l, r, a, b, c + z);
		}
		else {
			nf.push_back(Info(l, r, x, y, z));
		}
	}
	else {
		if(!(c & 1)) {
			a ^= 1;
			b ^= 1;
		}
		if(x != a && y != b) {
			t = Info(t.l, r, t.a, t.b, c + z);
		}
		else {
			nf.push_back(Info(l, r, x, y, z));
		}
	}
	return;
}

inline void ins(int i) {
	s.insert(i - bal);
	return;
}

inline void del(int i) {
	s.erase(i - bal);
	return;
}

inline int fnd_pre(int i) {
	auto it = s.lower_bound(i - bal);
	if(it == s.begin()) {
		return 0;
	}
	--it;
	return *it + bal;
}

inline int fnd_nxt(int i) {
	auto it = s.lower_bound(i - bal);
	if(it == s.end()) {
		return maxn;
	}
	return *it + bal;
}

void work(int &i, int &x, int &y, int l, int r, int a, int b, int c) {
	if(a && b && x == y) {
		if(x && y) {
			ins(i);
			pb(i + 1, i + 1, 1, 1, 1);
		}
		del(r);
		if(c > 1) {
			int j = fnd_pre(r);
			pb(l + 1, j + 1, 1, 1, c - 1);
		}
		i = r;
		x = y = 1;
		return;
	}
	for(;;) {
		int j = fnd_nxt(i + 1);
		if(j > r) {
			return;
		}
		del(j);
		if(x && y) {
			pb(i + 1, i + 1, 1, 1, 1);
			ins(i);
			x = a;
			y = b;
			i = j;
		}
		else {
			if(x + a > 1 || y + b > 1) {
				pb(j, j, x + a > 1, y + b > 1, 1);
				ins(j - 1);
			}
			x ^= a;
			y ^= b;
			i = j;
		}
		if(a != b) {
			a ^= 1;
			b ^= 1;
		}
	}
}

void Out(char *s) {
	int i = maxn - 1;
	while(!s[i]) {
		--i;
	}
	while(s[i] == '0') {
		--i;
	}
	while(i >= 0) {
		*pnt++ = s[i--];
	}
	*pnt++ = '\n';
	return;
}

int main() {
	fread(in, 1, sizeof in, stdin);
	pnt = in;
	while(*pnt < '0') {
		++pnt;
	}
	while(*pnt >= '0') {
		n = n * 10 + *pnt++ - '0';
	}
	while(*pnt < '0') {
		++pnt;
	}
	while(*pnt >= '0') {
		m = m * 10 + *pnt++ - '0';
	}
	while(*pnt < '0') {
		++pnt;
	}
	while(*pnt >= '0') {
		k = k * 10 + *pnt++ - '0';
	}
	while(*pnt < '0') {
		++pnt;
	}
	S = pnt + n - 1;
	pnt = S + 1;
	while(*pnt < '0') {
		++pnt;
	}
	T = pnt + m - 1;
	for (int i = 0; i < maxn; ++i) {
		if(i >= n && i >= m && !f.size()) {
			break;
		}
		int x = i < n ? S[-i] - '0' : 0, y = i < m ? T[-i] - '0' : 0, I = 0, z = fnd_pre(maxn);
		nf.clear();
		for (auto t: f) {
			work(I, x, y, t.l, t.r, t.a, t.b, t.c);
		}
		if(x && y) {
			if(z < k) {
				pb(z + 1, z + 1, 1, 1, 1);
				ins(z);
				x = y = 0;
			}
		}
		f = nf;
		++bal;
		a[i] = x + '0';
		b[i] = y + '0';
	}
	pnt = out;
	Out(a);
	Out(b);
	fwrite(out, 1, pnt - out, stdout);
	return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef pair<int,int>P;
int h[310000],w[310000];
int H,W,m,x,y,maxh,maxw;
map<P,int>f;
int main(void)
{
    scanf("%d %d %d",&H,&W,&m);
    while(m--)
    {
        scanf("%d %d",&x,&y);
        f[P(x,y)]=1;
        h[x]++;
        w[y]++;
    }
    for(int i=1;i<=H;i++)maxh=max(maxh,h[i]);
    for(int i=1;i<=W;i++)maxw=max(maxw,w[i]);
    vector<int>hh,ww;
    for(int i=1;i<=H;i++)
    {
        if(h[i]==maxh)hh.push_back(i);
    }
    for(int i=1;i<=W;i++)
    {
        if(w[i]==maxw)ww.push_back(i);
    }
    for(int i=0;i<hh.size();i++)
    {
        for(int j=0;j<ww.size();j++)
        {
            if(f[P(hh[i],ww[j])]==0)
            {
                printf("%d\n",maxw+maxh);
                return 0;
            }
        }
    }
    printf("%d\n",maxh+maxw-1);
    return 0;
}


Measured memory_bytes: 23412
#include <iostream>
#include <bits/stdc++.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(int argc, char** argv) {
	int n;
	cin>>n;
	
	int a1=0,a2=0,a4=0,shu;
	
	for(int i=0;i<n;i++)
	{
		scanf("%d",&shu);
		if(shu%4==0)
		 a4++;
		else if(shu%2==0)
		 a2++;
		else
		 a1++;
	}
	if(a2==0 && a1<=(a4+1))
	printf("Yes");
	else if(a2>0 && a1<=a4)
	printf("Yes");
	else
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int n = N % 10;

    switch(n){

        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;

        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;

        case 3:
            cout << "bon" << endl;
            break;
    }
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int A = int.Parse(str[1]);
            int B = int.Parse(str[2]);

            Console.WriteLine(Math.Min(N * A, B));
        }
    }
}


Measured memory_bytes: 13140
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, k = li()
s = ns()

# 幸福度の初期値
ans = 0
for si, sj in zip(s[:-1], s[1:]):
    if si == sj:
        ans += 1

print(min(n-1, ans + 2*k))


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;

int main() {

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

	int ans;
	ll cnt = 0;
	for (auto it = m.begin(); it != m.end(); it++) {

		
		cnt += it->second;
		if (cnt >= k) {
			ans = it->first;
			break;
		}
		
	}
	cout << ans << endl;
}

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

int main() {
    /*
	cin >> a >> b >> c;
	cout << a << " " << b << " " << c <<endl
	*/
	int a[4][3][10];
	int b,f,r,v,x;
	cin >> x;
	for(int bb=0;bb<4;bb++){
    	for(int ff=0;ff<3;ff++){
        	for(int rr=0;rr<10;rr++){
    	        a[bb][ff][rr]=0;
        	}
    	}
	}
	for(int i=0;i<x;i++){
	    cin >> b>> f>> r>> v;
	    a[b-1][f-1][r-1]+=v;
	}
	for(int bb=0;bb<4;bb++){
    	for(int ff=0;ff<3;ff++){
        	for(int rr=0;rr<10;rr++){
    	        cout << " "<< a[bb][ff][rr];
    	      //  if(rr!=9)cout << " ";
        	}
    	    cout << '\n';
    	}
        if(bb!=3)cout << "####################" << endl;
	}
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;

vll common(vll& A, vll& B){
  vll res;
  for(auto& a : A){
    if(a == 0) continue;
    bool ok = false;
    for(auto& b : B){
      if(b == 0) continue;
      if(a == b){
        ok = true;
        break;
      }
    }
    if(ok == true) res.push_back(a);
  }
  return res;
}

void print(vll& vec){
  for(auto& v : vec){
    cout << v;
  }
  cout << endl;
}

void solve(ll& N, ll& M, vll& K, vector<vll>& A){
  vll current = A.at(0);
  for(auto& a : A){
    current = common(current, a);
    //print(a);
  }
  cout << current.size() << endl;
}

int main(){
  ll N, M;
  cin >> N >> M;

  vll K(N, 0);
  vector<vll> A(N, vll(M));

  // ok

  for(ll i = 0; i < N; ++i){
    cin >> K.at(i);
    for(ll j = 0; j < K.at(i); ++j){
      cin >> A.at(i).at(j);
    }
  }

  solve(N, M, K, A);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



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

	int list[110] = { 0 };


	int base = 2;

	while (base < 100) {
		int i = base;
		while (i <= 100) {
			list[i] += 1;
			i += base;
		}
		base *= 2;
	}

	int score = 0;
	int out = 1;

	for (int i = 1; i <= N; i++) {
		if (list[i] > score) {
			score = list[i];
			out = i;
		}
	}
	print(out);







	



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A,B,C,K;
  scanf("%d %d %d %d",&A,&B,&C,&K);
  
  int max = 0;
  
  if(K <= A){
    max = K;
  }else if(K < A+B){
    max = A;
  }else{
    max = A - (K - A - B);
  }
  printf("%d",max);
  
  return 0;
}

Measured memory_bytes: 1724
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

int main(){

	int n,m; cin>>n>>m;
	int study=0;
	for(int i=0;i<m;i++){
		int a; cin>>a;
		study+=a;
	}

	if(n-study>=0) cout<<n-study<<endl;
	else cout<<-1<<endl;
	return 0;
}

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

int main() {
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> robots;
    for(long i{0}, x, d; i++ < N; robots.emplace_back(x, x + d))cin >> x >> d;
    sort(robots.begin(), robots.end(), greater<>());
    vector<pair<long, unsigned long>> v;
    v.emplace_back(3000000000, 1);
    for(const auto& i : robots){
        unsigned long r{1};
        while(v.back().first < i.second && ((r *= v.back().second) %= MOD))v.pop_back();
        v.emplace_back(i.first, r + 1);
    }
    cout << accumulate(v.begin(), v.end(), 1UL, [](auto i, auto j){return i * j.second % MOD;}) << endl;
    return 0;
}

Measured memory_bytes: 7276
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+4;
int n;
char s[N];
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int ans;
int main() {
	n=read();
	scanf("%s",s+1);
	int l=1,r=n;
	while (l<r) {
		while (s[l]^'W'&&l<n) ++l;
		while (s[r]^'R'&&r>1) --r;
		if (l<r) {
			++ans;
			++l,--r;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int N,M; cin >> N >> M;
    vector<bool> broken(N+10,false); //1-based
    for(int i = 0; i < M; i++){
        int n; cin >> n;
        broken.at(n) = true;
    }
    vector<long long> DP(N+100,0); //0-based
    
    DP.at(0) = 1;
    /*if(!broken.at(1)){
        DP.at(1) = DP.at(0);
        start = 1;
    }else{
        if(!broken.at(2)){ 
            DP.at(2) = DP.at(0);
            start = 2;
        }
        else{
            cout << ans << endl;
        }
    }*/
    for(int i = 0; i <= N; i++){
        if(broken.at(i+1) == false){
            DP.at(i+1) = ((DP.at(i+1) + DP.at(i)) % 1000000007);
        }
        if(broken.at(i+2) == false){
            DP.at(i+2) += ((DP.at(i+2) + DP.at(i)) % 1000000007);
        }
    }
    cout << DP.at(N) << endl;
}



Measured memory_bytes: 1024
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
map<int,int>mp;
set<string> s;
int ans[111];
int main()
{
    fast;
    w(t)
    {
        string x;
        cin>>x;
        s.insert(x);
    }
    cout<<s.sz<<endl;
}






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

int main() {
 int n;
    cin >> n;
    
    vector<string> s(n);
  rep(i,n) {
  cin >> s.at(i);
  }
  
    
    int ac=0,wa=0,tle=0,re=0;
    
    rep(i,n) {
     if(s.at(i) == "AC") {
      ac++;
     }
         else if(s.at(i) == "WA") {
          wa++;
         }
        else if(s.at(i) == "TLE") {
         tle++;
        }
        else {
         re++;
        }
        }
        cout << "AC x " << ac << endl;
        cout << "WA x " << wa << endl;
        cout << "TLE x " << tle << endl;
        cout << "RE x " << re << endl;
        
        }

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a;
    a.resize(n);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ans += a[i] - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

const int L=2*1e5;
int N,K;
LL a[L];
LL f(int s, int e){
	if(s+1==e){
		return a[s]>=0?1:0;
	}
	int m=(s+e)/2;
	LL ret=f(s,m)+f(m,e);
	LL l=0,r=0;
	vector<LL> ls,rs;
	for(int i=m-1;i>=s;i--){
		l+=a[i];
		ls.push_back(l);
	}
	for(int i=m;i<e;i++){
		r+=a[i];
		rs.push_back(r);
	}
	sort(ls.begin(),ls.end());
	sort(rs.begin(),rs.end());
	int q=rs.size();
	for(auto v:ls){
		while(q>0&&rs[q-1]+v>=0){
			q--;
		}
		ret+=rs.size()-q;
	}
	return ret;
}
int main() {
	cin >> N >> K;
	for(int i=0;i<N;i++){
		cin >> a[i];
		a[i]-=K;
	}
	cout << f(0,N) << endl;

	return 0;
}



Measured memory_bytes: 4168
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100
#define MAXV 100000
#define LL long long int
#define INF (1LL << 60)

int N, W, t, w[MAXN + 3], v[MAXN + 3], answer;
LL dp[2][MAXV + 3];

int main() {
    cin >> N >> W;
    for (int i = 1; i <= N; i++)
        cin >> w[i] >> v[i];

    t = 0;
    memset(dp, 0, sizeof(dp));
    for (int value = 0; value <= MAXV; value++)
        dp[0][value] = INF;

    dp[t][0] = 0;

    for (int n = 1; n <= N; n++) {
        t = 1 - t;
        for (int value = 1; value <= MAXV; value++) {
            dp[t][value] = dp[1 - t][value];
            if (value >= v[n])
                dp[t][value] = min(dp[t][value], dp[1 - t][value - v[n]] + w[n]);
        }
    }

    for (int value = 1; value <= MAXV; value++) {
        if (dp[t][value] <= W)
            answer = max(answer, value);
    }

    cout << answer << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vi b(n - 1);
    rep(i, n - 1) cin >> b[i];
    int sum = b[0] + b[n - 2];
    rem(i, 1, n - 1)
    {
        sum += min(b[i], b[i - 1]);
    }

    cout
        << sum << "\n";

    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  char A[M];
  for(int i=0;i<N;i++){
    for(int i=0;i<M;i++){
      cin >> A[i];
      cout << A[i];
    }
    cout << endl;
    for(int i=0;i<M;i++){
      cout << A[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
S = input()

ans = "WA"

if S[0] != "A":
  print(ans)
  
else:
  if S[2:len(S) - 1].count("C") != 1:
    print(ans)
  else:
    s = S.index("C")
    SS = S[1:s] + S[s + 1:]
    if SS.islower() == False:
      print(ans)
    else:
      print("AC")
      

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
using namespace std;
int a[300000];
bool b[300001];
bool c[300001];
int main() {
	for (int i = 0; i < 300001; i++) {
		b[i] = true;
		c[i] = false;
	}
	int s = 0;
	for (int i = 0; i < 300000; i++) {
		if (i * 7 + 1 < 300000) {
			a[s] = i * 7 + 1;
			c[a[s]] = true;
			s++;
		}
		if (i * 7 + 6 < 300000) {
			a[s] = i * 7 + 6;
			c[a[s]] = true;
			s++;
		}
		if (i * 7 >= 300000) break;
	}
	b[1] = false;
	for (int i = 1; i < s; i++) {
		if (b[a[i]]) {
			int j = 1;
			while (a[i] * a[j] < 300000) {
				b[a[i] * a[j]] = false;
				j++;
			}
		}
	}
	int n;
	while (cin >> n&&n != 1) {
		int n2 = n;
		set<int>d;
		for (int i = 1; i < s; i++) {
			if (n%a[i] == 0 && b[a[i]] && c[n/a[i]]) {
				d.insert(a[i]);
			}
		}
		set<int>::iterator it = d.begin();
		cout << n2 << ":";
		while (it != d.end()) {
			cout << " " << (*it);
			it++;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3972
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
data.sort(key=lambda x:-x[2])

def get_H(data,Cx,Cy):
    x,y,h = data
    return h+abs(x-Cx)+abs(y-Cy) , h==0
def estimate_H(data,Cx,Cy):
    H,_ = get_H(data[0],Cx,Cy)
    for cur_data in data[1:]:
        tmp,isZero = get_H(cur_data,Cx,Cy)
        if isZero and H <= tmp:
            continue
        if H != tmp:
            break
    else:
        return H
    return None

for Cx in range(101):
    for Cy in range(101):
        tmp = estimate_H(data,Cx,Cy)
        if tmp != None:
            print(Cx,Cy,tmp)
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF 1<<28

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	int T, A; cin >> T >> A;
	vector<int> H(N, 0);
	rep (i, N){
		cin >> H[i];
	} // end rep

	int res = INF;
	int ans = -1;
	rep (i, N){
		int curr = 1000*T - 6 * H[i];
		int diff = abs(curr - 1000 * A);
		if (res > diff){
			res = diff;
			ans = i;
		} // end if
	} // end rep

	cout << ans + 1 << endl;

	return 0;
}

Measured memory_bytes: 256