akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int[] Solve(int M, int K)
        {
            int N = 1 << (M + 1);
            if (K == 0)
            {
                var ans = new int[N];
                for (int i = 0; i < N / 2; ++i)
                {
                    ans[i] = i;
                    ans[N - 1 - i] = i;
                }
                return ans;
            }
            else if (M > 1 && K < (1 << M))
            {
                var ans = new int[N];
                ans[0] = 0;
                ans[N / 2 - 1] = 0;
                ans[N / 2] = K;
                ans[N - 1] = K;
                int c = 1;
                for (int i = 1; i < N / 2 - 1; ++i)
                {
                    if (c == K) { ++c; }
                    ans[i] = c;
                    ans[N - 1 - i] = c;
                    ++c;
                }
                return ans;
            }
            else
            {
                return null;
            }
        }
        static void Main(string[] args)
        {
            int[] V = ReadInts();
            var ans = Solve(V[0], V[1]);
            if (ans != null)
            {
                Console.WriteLine(string.Join(" ", ans));
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 27224
#include <bits/stdc++.h>
//#define DEBUG
#define REP( i , nn ) for(int i = 0 ; i < (int) nn; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    string S;
    cin >> S;
    int ans1 = 0;
    char next_color = '0';
    REP(i, S.size()){
        if( S[i] != next_color){
            ans1++;
        }
        next_color = '0' + 1 - (next_color - '0');
    }
    next_color = '1';
    int ans2 = 0;
    REP(i, S.size()){
        if( S[i] != next_color){
            ans2++;
        }
        next_color = '0' + 1 - (next_color - '0');
    }
    cout << min(ans1, ans2) << "\n";
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3784
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]
B=[0]
for i in range(n):
    A.append(a[i]+A[i])
for j in range(m):
    B.append(b[j]+B[j])

i=0
j=m
ans=0
tmp=0
while(i<n+1 and j>=0):
    if(k>=A[i]):
        tmp=k-A[i]
        if(tmp-B[j]>=0):
            ans=max(ans,i+j)
            i+=1
        else:
            j-=1
    else:
        break
print(ans)
        
    

            


Measured memory_bytes: 47336
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    vector<pair<int,int> > a;
    int n;
    cin >> n;
    rep(i,n){
        int b;
        cin >> b;
        a.push_back(MP(b,i));
    }
    sort(a.begin(),a.end());
    int c = 0;
    rep(i,n){
        if(a[i].second!=i)c++;
    }
    if(c<=2){
        cout << "YES" << endl;
    }else{ 
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b;
  string s;
  cin >> a >> b >> s;
  bool flag = true;
  for (int i = 0; i < a; i++) {
    if (!('0' <= s[i] && s[i] <= '9')) {
      flag = false;
    }
  }
  if (s[a] != '-')
    flag = false;
  for (int i = a + 1; i < a + b + 1; i++) {
    if (!('0' <= s[i] && s[i] <= '9')) {
      flag = false;
    }
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  REP(i, n) {
    string s;
    cin >> s;
    if (s == "AC") {
      ac++;
    } else if (s == "WA") {
      wa++;
    } else if (s == "TLE") {
      tle++;
    } else if (s == "RE") {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 3656
import math
A, B, H, M = map(int, input().split())

l_ = M * 6
s_ = (H*60+M) * 360 / (12*60)
k_ = abs(s_ - l_)

ans = A**2 + B**2 - (2*A*B*math.cos(math.radians(k_)))
print(math.sqrt(ans))


Measured memory_bytes: 9436
fn main() {
    proconio::input! {
        n: usize,
        c: usize,
        k: i64,
        mut ts: [i64; n],
    }
    ts.sort();
    struct Bus {
        start: i64,
        num: usize,
    }
    let mut count = 0usize;
    let mut bus = Bus { start: 0, num: 0 };
    for t in ts {
        if bus.start < t || bus.num == c {
            count += 1;
            bus.start = t + k;
            bus.num = 1;
        } else {
            bus.num += 1;
        }
    }
    println!("{}", count);
}


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

using namespace std;

class Edge {
public:
    explicit Edge(int s, int d, int l) : src(s), dst(d), len(l) {}
    void print() const { cout << src << " " << dst << " " << len << endl; }
private:
    int src, dst, len;
};

int main(){
    int L;
    vector<int> pow3;
    pow3.push_back(1);
    while(pow3.back() * 3 <= 1000000) pow3.push_back(3 * pow3.back());
    while(cin >> L){
        vector<Edge> edges;
        for(int i=0;i<pow3.size();i++){
            for(int j=0;j<3;j++){
                if(j * pow3[i] <= 1000000){
                    edges.emplace_back(20-i-1, 20-i, j * pow3[i]);
                }
            }
        }
        int base = 0;
        for(int i=0;i<pow3.size();i++){
            for(int j=0;j<L%3;j++){
                edges.emplace_back(1, 20-i, base + j * pow3[i]);
            }
            base += (L%3) * pow3[i];
            L /= 3;
        }
        cout << 20 << " " << edges.size() << endl;
        for(const auto& e : edges) e.print();
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){

  int i,j,a,n,count= 0;
  int A[100];
  int temp = 0;

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


  for(i = 0; i < n-1; i++){
    for(j = n-1; j >= i+1; j--){
      if(A[j] < A[j-1]){
        temp = A[j];
        A[j] = A[j-1];
        A[j-1] = temp;
        count++;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%d",A[i]);
    if(i != n - 1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
ab = []
for _ in range(3):
    ab.append(list(map(int,input().split())))

#%%
# ab = [
# [4, 2],
# [1, 3],
# [2, 3]]

#%%
node = [0] * 4


#%%


for abi in ab:
    node[abi[0]-1] += 1
    node[abi[1]-1] += 1


#%%
if len(ab) < 3:
    print("NO")
elif 3 in node:
    print("NO")
else:
    print("YES")

#%%


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main(){

    int r;
    int d;
    int x;

    cin >> r >> d >> x;

    int tmp = x;
    for(int i = 0; i < 10; ++i){
        
        int out;
        out = r * tmp - d;
        cout << out << endl;
        tmp = out;

    }

}

Measured memory_bytes: 256
/* - - - - - - - - - - - - - - -
	User : 		VanishD
	problem :
	Points : 	
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define 	ll 		long long
# define 	N 		200010
using namespace std;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
int read(){
	int tmp = 0, fh = 1; char ch = getchar();
	while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
	return tmp * fh;
}
int n;
ll num[N], sum[N];
bool check(int l, int mid, int r){
	if (mid == r) return false;
	ll now1 = max(sum[mid] - sum[l - 1], sum[r] - sum[mid]) - min(sum[mid] - sum[l - 1], sum[r] - sum[mid]);
	ll now2 = max(sum[mid + 1] - sum[l - 1], sum[r] - sum[mid + 1]) - min(sum[mid + 1] - sum[l - 1], sum[r] - sum[mid + 1]);
	return now2 <= now1; 
}
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for (int i = 1; i <= n; i++) num[i] = read();
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + num[i];
	int cntl = 1, cntr = 3;
	ll ans = infll;
	for (int i = 2; i <= n - 2; i++){
		while (check(1, cntl, i) == true) cntl++;
		while (check(i + 1, cntr, n) == true) cntr++;
		ll mn = min(sum[cntl], min(sum[i] - sum[cntl], min(sum[cntr] - sum[i], sum[n] - sum[cntr])));
		ll mx = max(sum[cntl], max(sum[i] - sum[cntl], max(sum[cntr] - sum[i], sum[n] - sum[cntr])));
		ans = min(ans, mx - mn);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
//#define REP(i,n)  for(int i =0;i<n;++i)
#define mod (ll)(1e9+7)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int  A= 0,B=0;
    cin >> A >> B;
    if(A<=8&&B<=8)cout<<"Yay!"<<endl;
    else cout << ":("<<endl;
    return 0;
}



Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char s[10000];
int main()
{
    int x, i, r, a;
    scanf("%d", &x);
    scanf("%s", &s);
    int t = strlen(s);
    r = x%26;
    if(r>0)
    {
        x = r;
    }
    for(i=0; i<t; i++)
    {
        a = s[i] + x;
        if(a>90)
            s[i] = (a%90) + 64;
        else
            s[i] = s[i] + x;
        printf("%c", s[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define M 100005
using namespace std;
const int mod=1e9+7;
int n;
char s[M];
int cnt[27];
int dfs(int v){
	if(v==26)return 1;
	return 1LL*dfs(v+1)*(cnt[v]+1)%mod;
}
int main(){
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++)cnt[s[i]-'a']++;
	printf("%d\n",dfs(0)-1);
	return 0;
}

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


int main(){


    int a, b, i;

 
    cin >> a >> b;


    if( 0 < a ) cout << "Positive" << endl;

    else if( a == 0 ) cout << "Zero" << endl;

    else if( a < 0 && 0 <= b ) cout << "Zero" << endl;

    else if( b == 0 ) cout << "Zero" << endl;

    else{

          if( ( b - a + 1 ) % 2 == 0 ) cout << "Positive" << endl;

          else cout << "Negative" << endl;

          }


    return 0;


    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int q;
  cin >> q;
  set<int> st;
  rep(qi, q)
  {
    int type;
    cin >> type;
    if (type == 0)
    {
      int x;
      cin >> x;
      st.insert(x);
      cout << st.size() << endl;
    }
    else if (type == 1)
    {
      int x;
      cin >> x;
      cout << st.count(x) << endl;
    }
    else
    {
      int x;
      cin >> x;
      st.erase(x);
    }
  }
  return 0;
}



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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

typedef pair<int, string> PIS;

string s;

char next(char c) {
    if (isalpha(c)) return 'A' + (c - 'A' + 1) % 26;
    else return c;
}

char prev(char c) {
    if (isalpha(c)) return 'A' + (c - 'A' + 25) % 26;
    else return c;
}

PIS p_letter(int pos);
PIS p_string(int pos);
PIS p_cipher(int pos);

PIS p_letter(int pos) {
    char c = s[pos];
    if (c == '+') {
        PIS res = p_letter(pos + 1);
        return MP(res.fst, string("") + next(res.snd[0]));
    }
    if (c == '-') {
        PIS res = p_letter(pos + 1);
        return MP(res.fst, string("") + prev(res.snd[0]));
    }
    // alpha
    return MP(pos + 1, string("") + c);
}

PIS p_string(int pos) {
    char c = s[pos];
    if (c == '[') {
        PIS res = p_cipher(pos + 1);
        reverse(ALL(res.snd));
        return MP(res.fst + 1, res.snd);
    }
    // letter
    return p_letter(pos);
}

PIS p_cipher(int pos) {
    PIS res = p_string(pos);
    if (res.fst < (int)s.size() && s[res.fst] != ']') {
        PIS res2 = p_cipher(res.fst);
        return MP(res2.fst, res.snd + res2.snd);
    }
    return MP(res.fst, res.snd);
}

string solve() {
    string s2 = p_cipher(0).snd;
    replace(ALL(s2), '?', 'A');
    return s2;
}

int main(void) {
    while (cin >> s, s != ".") {
        cout << solve() << endl;
    }

	return 0;
}

Measured memory_bytes: 1204
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)


typedef long long ll;
const int maxn = 1e6 + 10;
int n, A[maxn];

int main() {
    cin >> n;
    rep(i, 1, n) scanf("%1d", A + i);
    for( int i = 1 ; i < n ; ++ i ) {
        A[i] = abs( A[i] - A[i + 1] );
    }
    int ok = 0;
    for( int i = 1 ; i < n ; ++ i ) ok |= ( A[i] == 1 );
    if( ok ) for( int i = 1 ; i < n ; ++ i ) A[i] = ( A[i] == 2 ? 0 : A[i] );
    int re = 0;
    for( int i = 1 ; i < n ; ++ i )
        if( A[i] ) re ^= ( (((n - 2) & (i - 1)) == (i - 1)) );
    cout << ( ok ? re : ( re << 1 ) ) << endl;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
int plans(int n,int m)
{
  if(n==0) return 0;
  else if(m>n) return plans(n,m-1);
  else{
    //cout << n << endl;
    cout << m << endl;
    return plans(n-m,m-1);
  }
}
int main(void)
{
  int n;
  cin >> n;
  REP(i,n+1) if(i*(i+1)/2>=n) return plans(n,i);
  return 0;
}

Measured memory_bytes: 256
n=gets.to_i
v=gets.split.map(&:to_i)
v.sort!
ans = (v[0] + v[1]) / 2.0
if n <= 2
  puts ans
  exit
else
  (2...n).each do |i|
    ans = (ans + v[i]) / 2.0
  end
  puts sprintf("%.10f", ans)
  exit
end




Measured memory_bytes: 1788
N = int(input())
s = {}
for i in range(N):
    x = input()
    if x in s:
        s[x] += 1
    else:
        s[x] = 1
M = int(input())
t = {}
for i in range(M):
    x = input()
    if x in t:
        t[x] += 1
    else:
        t[x] = 1

b = list(s.keys())
r = list(t.keys())
subs = []

for i in range(len(b)):
    if b[i] in r:
        subs.append(s[b[i]]-t[b[i]])
    else:
        subs.append(s[b[i]])
print(max(0,max(subs)))


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

#define int long long int
#define ff first
#define ss second
#define pb push_back

int bexp(int a, int b, int mod)
{
    int res = 1;
    if (mod <= 0)
        return 0;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

#define N 200010
#define MOD 1000000007

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

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;
    int j = n - 1, i = 0;

    while (j > i)
    {
        while (i < n && s[i] == 'R')
            i++;

        while (j >= 0 && s[j] == 'W')
            j--;

        if (i < n && j >= 0 && j > i)
        {
            ans++;
            swap(s[i], s[j]);
            i++, j--;
        }
        else break;
    }
    i = 0;

    while (i < n && s[i] == 'R') i++;

    while (i < n)
    {
        if (s[i] == 'R') s[i] = 'W', ans++;
        i++;
    } 

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


Measured memory_bytes: 3720
object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  val a = readLine().split(" ").map(_.toInt)
  println(if(a.forall(x => x % 2 == 1 || x % 3 == 0 || x % 5 == 0)) "APPROVED" else "DENIED")
}

Measured memory_bytes: 25544
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define puts(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

const double EPS = 1e-12;
typedef complex<double> comp;

void solve(void){

	int x1, y1, x2, y2, Q;
	cin >> x1 >> y1 >> x2 >> y2 >> Q;

	comp o(x1, y1), p(x2-x1, y2-y1), r;

	//回転用
	r = polar(1.0, arg(p));

	while(Q--)
	{
		int x3, y3;
		cin >> x3 >> y3;

		comp q(x3-x1, y3-y1);

		q /= r;

		//printf("%.12lf %.12lf\n", norm(p), norm(q));

		if (abs(arg(q)) < EPS)
		{
			if (norm(p) >= norm(q) - 1e-6)
			{
				putln("ON_SEGMENT");
			}
			else
			{
				putln("ONLINE_FRONT");
			}
		}
		else if (abs(abs(arg(q))-M_PI) < EPS)
		{
			putln("ONLINE_BACK");
		}
		else if (arg(q) > 0)
		{
			putln("COUNTER_CLOCKWISE");
		}
		else
		{
			putln("CLOCKWISE");
		}
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



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

int main(){
  int n,a,b,c,d;
  while(cin >> n){
    int ans = 0;
    for(a=0;a<10;a++){
      for(b=0;b<10;b++){
        for(c=0;c<10;c++){
          for(d=0;d<10;d++){
            if(a+b+c+d == n) ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int , int>
#define fast ios_base::sync_with_stdio(0)
#define mx 3002
ll arr[mx], dp[mx][mx];
int n;
ll fun(int b, int e)
{
    if(b>e) return 0;
    if(b==e)
        return arr[b];
    ll& ret = dp[b][e];
    if(ret!=-1) return ret;
    ret = max(arr[b]  - fun(b+1,e) , arr[e] - fun(b, e-1));
    return ret;
}
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%lld",&arr[i]);
    memset(dp, -1, sizeof dp);
    printf("%lld\n",fun(1,n));
}



Measured memory_bytes: 70784
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) {
	n := sc.getInt()

	sum := 0
	i := 0
	for sum < n {
		sum += (i + 1)
		i++
	}

	ans := make([]int, 0, i)
	for n > 0 && i > 0 {
		if n-i >= 0 {
			n -= i
			ans = append(ans, i)
		}
		i--
	}

	for _, p := range ans {
		fmt.Fprintln(wr, p)
	}
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


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


int main() {
	while (true) {
		int n, m;
		int f[25][25] = { 0 }, nowx = 0, nowy = 0;
		nowx = 10, nowy = 10;
		cin >> n;
		if (n == 0) return 0;
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			f[x][y] = 1;
		}
		cin >> m;
		for (int i = 0; i < m; i++) {
			char c;
			int num;
			cin >> c >> num;
			if (c == 'N') {
				for (int j = 0; j <= num; j++) {
					f[nowx][nowy + j] = 0;
				}
				nowy += num;
			}
			if (c == 'E') {
				for (int j = 0; j <= num; j++) {
					f[nowx+j][nowy] = 0;
				}
				nowx += num;
			}
			if (c == 'S') {
				for (int j = 0; j <= num; j++) {
					f[nowx][nowy - j] = 0;
				}
				nowy -= num;
			}
			if (c == 'W') {
				for (int j = 0; j <= num; j++) {
					f[nowx-j][nowy] = 0;
				}
				nowx -= num;
			}
		}
		for (int i = 0; i <= 20; i++) {
			for (int j = 0; j <= 20; j++) {
				if (f[i][j] == 1) {
					printf("No\n");
					goto e;
				}
			}
		}
		printf("Yes\n");
	e:;
	}
	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

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

	range(i, 1, 10) {
		range(j, 1, 10) {
			if (i * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
#define LN 30
using namespace std;

ll gcd(ll n1,ll n2){
	if(!n1)return n2;
	if(!n2)return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
	base%=mod;
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	ans%=mod;
	return ans;
}
ll a[upperlimit+1];
ll b[upperlimit+1];
int main()
{
	int i,j,k,n;
	sd(n);sd(k);
	ll answer=0,tempans;
	for(i=1;i<=n;i++){
		slld(a[i]);slld(b[i]);
		if((k&a[i])==a[i])answer+=b[i];
	}
	int temp=0;
	for(j=LN;j>=0;j--)if((k>>j)&1){
		tempans=0;
		temp=(k>>(j+1));
		for(i=1;i<=n;i++){
			int temp2=(a[i]>>(j+1));
			if((temp2&temp)==temp2){
				if(!((a[i]>>j)&1))tempans+=b[i];
			}
		}
		answer=max(answer,tempans);
	}
	plldn(answer);
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8


int main(){
    char S[207];cin >> S;
    ll C=0;
    for(int i=1;2*i<strlen(S);i++){
        int k=0;
        rep(j,i){
            if(S[j]!=S[j+i]){
                k++;
            }
        }
        if(k==0){
            C=i*2;
        }
    }
    cout << C <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep( i, n ) for (int i = 0; i < ( long long )(n); i++)
using namespace std;
int main(){
	long long n;
	long long ans = 0;
	long long min= 2e5+1;
	cin>>n;
	
	vector< long long > p( n );
	rep( i , n ){
		cin>>p.at( i );
	}
	
	rep( j , n ){
		if( p.at( j ) <= min ){
			ans++;
			min = p.at( j );
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(10);
#define int long long
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define tr(x) for(auto it:x)
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
int N=100001;
int mod=1e9+7;
int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
int32_t main()
{
    IOS;
    int t=1;
    //cin>>t;
    while(t--) 
    {
    	string s, t;
    	cin>>s>>t;
    	if(sz(s)!=sz(t)-1)
    	{
    		cout<<"No";
    		return 0;
    	}
    	rep(i,0,sz(s))
    	{
    		if(s[i]!=t[i])
    		{
    			cout<<"No";
    			return 0;
    		}
    	}
    	cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
pl P[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> P[i].sec >> P[i].fst;
	sort(P, P + N);
	ll t = 0;
	rep(i, 0, N) {
		if(t + P[i].sec > P[i].fst) {
			cout << "No\n"; return;
		}
		t += P[i].sec;
	}
	cout << "Yes\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

ll tc,n;
bool c[3];

int main()
{
	ll a,b;
	cin>>a>>b;
	for(int i=1;i<=3;i++)
	{
		if(i!=a && i!=b)
		{
			cout<<i<<'\n';
			return 0;
		}
	}
}

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

int main() {
  string s;
  cin >> s;
  vector<bool> used(26, false);
  int tmp = -1;
  string s0;
  char c1;
  if (s.size() < 26) {
    for (auto&& w : s) used[w - 'a'] = true;
    for (int i = 0; i < 26; i++)
      if (used[i] == false) {
        char c = 'a' + i;
        cout << s + c << endl, exit(0);
      }
  } else {
    for (int i = 25; i >= 1; i--) {
      if (s[i - 1] < s[i]) {
        tmp = i - 1;
        break;
      }
    }
    if (tmp == -1) cout << -1 << endl, exit(0);
    s0 = string(begin(s), begin(s) + tmp);
    for (int i = 25; i >= 1; i--) {
      if (s[i] > s[tmp]) {
        c1 = s[i];
        break;
      }
    }
    cout << s0 + c1 << endl, exit(0);
  }
}


Measured memory_bytes: 256
def cmb(n, r, MOD, g1, g2):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % MOD


def main():
    X, Y = map(int, input().split())
    MOD = 10 ** 9 + 7
    if (X + Y) % 3 != 0:
        print(0)
        exit()
    m = (2 * X - Y) // 3
    n = (2 * Y - X) // 3

    
    N = 10**6
    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 )
    
    ans = cmb(n + m, n, MOD, g1, g2)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 128300
#include <bits/stdc++.h>
using namespace std;
 int main() {
	int N,Y;
    cin >> N >> Y;
   int flag=0;
   for(int i=0;i<=N;i++){
     for(int j=0;j<=N-i;j++){
       int k = N - i -j;
       if(10000*i + 5000*j + 1000*k == Y){
         cout << i <<" " << j << " " << k << endl;
         i += N;
         j += N;
         flag =1;
       }
     }
   }
   if(flag==0) cout<< "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
  int n;scanf("%d",&n);
  int a[n];
  int m;
  int c=30;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    m=0;
    while(a[i]%2==0){
      a[i]/=2;
      m++;
    }
    c=(c<m)?c:m;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
(* O(|s|) *)
let s = read_line ()
let ans = ref max_int
let cs = [|'0'; '1'|]
let cnt1, cnt2 = ref 0, ref 0
let _ =
  String.iteri (fun i c -> if c <> cs.(i mod 2) then incr cnt1) s;
  String.iteri (fun i c -> if c = cs.(i mod 2) then incr cnt2) s;
  min !cnt1 !cnt2 |> Printf.printf "%d\n"

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

int main() {
	int a, b; cin >> a >> b;
	if (a == b)cout << "Draw";
	else {
		if (a == 1)cout << "Alice";
		else if (b == 1)cout << "Bob";
		else cout << (a > b ? "Alice" : "Bob");
	}
	cout << endl;

	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v[i] = make_pair(a, i + 1);
  }

  sort(v.begin(), v.end());
  for (int i = 0; i < n - 1; i++) {
    cout << v[i].second << " ";
  }
  cout << v[n - 1].second << endl;
}


Measured memory_bytes: 1536
#include<stdio.h>
int  main()

{
  int x,a,b;
  int c;

  //持ってるお金
  scanf("%d", &x);

  //ケーキの金額
  scanf("%d", &a);

  //ドーナツの金額
  scanf("%d", &b);

  c= x-a;

  printf("%d\n", c%b);

  return 0;
}

Measured memory_bytes: 128
N = int(input())
MOD = 10 ** 9 + 7
prime = []
for n in range(2, N+1):
    cnt = 0
    for i in range(1, n+1):
        if n % i == 0:
            cnt += 1
    if cnt == 2:
        prime.append(n)

ans = 1
for p in prime:
    cnt = 0
    for n in range(1, N + 1):
        # p で何回割り切れるか
        tmp = n
        while n / p == n // p:
            cnt += 1
            n //= p
    ans *= (cnt + 1)
    ans %= MOD

print(ans)


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

#define rep(i,n) for(int i=0;i<n;i++)
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;

//条件式 ? 真の場合の文 : 偽の場合の文
//abs(x) = (x の絶対値)
//string S  S,at(i),S += T,S += c,S.size(),S.substr(l)l文字目から最後まで,
///S.substr(l, r)l文字目からl+r-1文字目 n文字目から0個で空列を返せる
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//swap(a, b)    c
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool,b.size() 要素が小さい順
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1; 変数[key] = value; 変数.erase(key); 変数.at(key); 変数.count(key)所属判定　変数.size()
//find(all(x), key)boolソート済みのベクトル
//*lower_bound(all(x),k)以上の最小の要素,*uppper_bound(all(x),k)より大きい最小の要素
//char('0'+cnt) 数字cntからcharへの変換
//int(char-'0') charからintへの変換


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

    vector<bool> ok(n,false);
    ok.at(0) = true;
    vector<int> ko(n,1);

    int x,y;
    rep(i,m){
        cin >> x >> y;
        x--;y--;
        if(ok.at(x)){
            ok.at(y) = true;
            if(ko.at(x) == 1) ok.at(x) = false;
        } 
        ko.at(x)--;
        ko.at(y)++;
    }
    cout << count(all(ok),true) << endl;
}
    




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
#define INF 1e9

int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N);
    for(int i = 0;i < N;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(3, vector<int>(N, INF));
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < N-1;j++){
            dp[0][j+1] = max(dp[1][j]+a[j+1], dp[2][j]+a[j+1]);
            dp[1][j+1] = max(dp[0][j]+b[j+1], dp[2][j]+b[j+1]);
            dp[2][j+1] = max(dp[0][j]+c[j+1], dp[1][j]+c[j+1]);
        }
    }
    int ans = 0;
    for(int i = 0;i < 3;i++)    ans = max(ans, dp[i][N-1]);
    cout << ans << endl;
}

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

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  ll r = 1;
  for(ll i = 1; i * i <= m; i++) {
    if(m%i) continue;
    if(n*i <= m) {
      r = max(r, i);
    }
    if(n*(m/i) <= m) {
      r = max(r, m/i);
    }
  }
  printf("%lld\n", r);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
void Main()
{
  int n;
  cin >> n;
  vector<int> b(n-1);
  REP(i, n)
  cin >> b[i];
  
  vector<int> a(n);
  
  int sum = 0;
  
  for(int i = 0; i < n; i++){
    if(i == 0){
      a[0] = b[0];
    }
    else if(i != n - 1){
      if(b[i] > b[i-1]){
        a[i] = b[i-1];
      }
      else{
        a[i] = b[i];
      }
    }
    else{
      a[i] = b[i - 1];
    }
  }
  REP(i, n)
    sum += a[i];
  printf("%d", sum);
}
 
int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n";
ll arr1[200001],arr2[200001],arr3[300001],arr4[300001];
void solve()
{
    ll i,j,k,l,m,n,q,s,t;
    cin>>n;
    string a;
    cin>>a;
    string b=string(n,'R'),c=string(n,'W');
    if(a==b||a==c)
    {
    cout<<0<<endl;
    return;
    }
    q=0;
    s=0;
    a='$'+a;
    arr1[0]=0;
    arr2[0]=0;
    for(i=1;i<=n;i++)
    {
         arr1[i]=arr1[i-1];
         arr2[i]=arr2[i-1];
         if(a[i]=='W')
         arr1[i]++;
         else 
         arr2[i]++;
    }
    arr3[n+1]=0;
    arr4[n+1]=0;
    for(i=n;i>=1;i--)
    {
        arr3[i]=arr3[i+1];
        arr4[i]=arr4[i+1];
        if(a[i]=='W')
         arr3[i]++;
         else 
         arr4[i]++;
    }
    ll ans=LLONG_MAX;
    for(i=1;i<=n;i++)
    {
        if(a[i]=='W')
        ans=min(ans,max(arr4[i+1],arr1[i-1]));
    }
    cout<<ans<<endl;
}
int main()
{
    ll i,j,k,l,m,n,o,p,q,r,t,x;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 10132
#include<bits/stdc++.h>
using namespace std;
int a[10086];
bool cmp(int a,int b)
{
	return a>b;
}//从大到小的排序规则 
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1,cmp);
	int ans=0;
	for(int i=1;i<=k;i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 int n;
 cin >> n;
 double v[n],ans=0;
 for(int i=0;i<n;i++) cin >> v[i];
 sort(v, v+n, greater<int>());
 for(int i=0;i<n;i++){
   if(i!=n-1) ans+=v[i]*pow(0.5, i+1);
   else ans+=v[i]*pow(0.5, i);
 }
 cout << fixed << setprecision(8) << ans;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, j, x, y, z, a, b;

    cin >> N;

    for(i=1; i<=3500; i++){
        for(j=1; j<=3500; j++){
            a = N*i*j;
            b = 4*i*j - N*i - N*j;

            if(b>0 && a%b==0){
                x = i;
                y = j;
                z = a/b;
            }
        }
    }

    cout << x << " " << y << " " << z << endl;

    return 0;
}

Measured memory_bytes: 384
using System;
 
class Program {
	static void Main(string[] args) {
	    string input = Console.ReadLine();
	    string[] lines = input.Split(' ');
	    
	    int divisor = int.Parse(lines[0]);
	    int dividend = int.Parse(lines[1]);
	    
	    int outputNumber = 0;
	    
	    if (dividend % divisor == 0) {
	        outputNumber = divisor + dividend;
	    } else {
	        outputNumber = dividend - divisor;
	    }
	    
	    string outputLine = outputNumber.ToString();
		Console.WriteLine(outputLine);
	}
}

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

typedef long double     ld;
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;

const int inf = 0x3f3f3f3f;
const ll  INF = 0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e)    for(int i=b; i<=e; i++)
#define FORD(i, b, e)   for(int i=b; i>=e; i--)
#define SIZE(x)         ((int)(x).size())
#define pb              push_back
#define st              first
#define nd              second
#define all(a)          begin(a), end(a)
#define watch(x)        cerr << (#x) << " is " << (x) << '\n';

string s;
int dp[200010][2];

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

    cin>>s;

    dp[0][0]=1;
    dp[0][1]=-inf;
    dp[1][0]=(s[0]!=s[1] ? 2:-inf);
    dp[1][1]=1;

    FOR(i,2,SIZE(s)-1){
        dp[i][0]=dp[i][1]=-inf;
        if(s[i-1]!=s[i]) dp[i][0]=max(dp[i][0],dp[i-1][0]+1);
        dp[i][0]=max(dp[i][0],dp[i-1][1]+1);
        if(i>2) if(!(s[i-2]==s[i]&&s[i-3]==s[i-1])) dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
        dp[i][1]=max(dp[i][1],dp[i-2][0]+1);
    }
    cout<<max(dp[SIZE(s)-1][0],dp[SIZE(s)-1][1])<<'\n';

    return 0;
}


Measured memory_bytes: 2196