akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

#define pb emplace_back
#define forn(i, x, n) for(auto i = (int)x; i < (int)n; ++i)

#define int long long

struct init {
    init() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cout << fixed << setprecision(10);
    }

    ~init() {
        cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
    }
} init;

const int N = 1005000 * 1, MOD = 1000 * 1000 * 1000 + 7;
const ldb EPS = 5e-12, HALF = 0.5;

double sum(int x) {
    int sum = 0;
    while (x) {
        sum += x % 10;
        x /= 10;
    }

    return sum;
}

signed main() {
    int k;
    cin >> k;
    int base = 1;
    int cnt = -2;
    while (k) {
        forn(i, 1, 10) {
            if (i <= cnt) {
                if (cnt > 9 && i == 1) {
                    int c = cnt - 11 - i + 1;
                    forn(j, 0, 10) {
                        if (j < c) {
                            forn(l, 0, 10) {
                                cout << i * base + base - 1 - (9 - j) * base / 10 - (9 - l) * base / 100 << '\n';
                                --k;
                                if (!k)
                                    break;
                            }
                        } else {
                            cout << i * base + base - 1 - (9 - j) * base / 10 << '\n';
                            --k;
                            if (!k)
                                break;
                        }
                        if (!k)
                            break;
                    }
                } else {
                    forn(j, 0, 10) {
                        cout << i * base + base - 1 - (9 - j) * base / 10 << '\n';
                        --k;
                        if (!k)
                            break;
                    }
                }
            } else {
                cout << i * base + base - 1 << '\n';
                --k;
                if (!k)
                    break;
            }
            if (!k)
                break;
        }

        base *= 10;
        ++cnt;
    }

//    int n = 1;
//    while (n < 100000) {
//        double res = n / sum(n);
//        bool fl = 1;
//        forn(i, n + 1, 100000 + 1) {
//            if (i / sum(i) - res < EPS) {
//                fl = 0;
//                break;
//            }
//        }
//
//        if (fl) {
//            cout << n << '\n';
//        }
//        ++n;
//    }
}


Measured memory_bytes: 256
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=l if l<H and A[i]<A[l]else i
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64172
#include<bits/stdc++.h>
typedef long long ll;
const int MN=21,MOD=1e9+7;
int N,A[MN][MN],dp[MN][1<<MN];
inline int cb(int msk, int b) {
    return msk & ~(1<<b);
}
inline int sb(int msk, int b) {
    return msk | (1<<b);
}
inline int tb(int msk, int b) {
    return msk ^ (1<<b);
}
inline bool ib(int msk, int b) {
    return msk & (1<<b);
}
int solve(int n,int msk) {
    if(n<0) return 1;
    if(~dp[n][msk]) return dp[n][msk];
    dp[n][msk]=0;
    for(int i=0;i<N;++i)
        if(A[n][i] && !ib(msk,i)) dp[n][msk]=(dp[n][msk]+solve(n-1,sb(msk,i)))%MOD;
    return dp[n][msk];
}
int main() {
    scanf("%d",&N);
    for(int i=0;i<N;++i)
        for(int j=0;j<N;++j)
            scanf("%d",&A[i][j]);
    memset(dp,-1,sizeof dp);
    printf("%d\n",solve(N-1,0));
}


Measured memory_bytes: 172288
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

signed main(){
    int n;
    cin>>n;
    ll ans=0;
    while(n--){
        ll l,r;
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
}

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

int main(){
  int N;
  cin>>N;
  
  vector<long long int> L(N+1);
  
  L.at(0)=2;
    L.at(1)=1;
  

  for(int i=2;i<=N;i++){
    L.at(i)=L.at(i-2)+L.at(i-1);
  }
  
  cout<<L.at(N)<<endl;
}

    


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
    ll n,m,ans;
    cin >> n >> m;
    if (n==2 or m==2) ans = 0;
    else if (n==1 or m==1) {
        if (n!=1) ans=n-2;
        else if (m!=1) ans=m-2;
        else ans=1;
    }
    else ans=(n-2)*(m-2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// AtCoderを信じる！！

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector< int > d;
  int64 lost = 0;
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    lost += y;
    d.emplace_back(x + y);
  }
  sort(d.rbegin(), d.rend());
  int64 ret = 0;
  for(int i = 0; i < N; i += 2) {
    ret += d[i];
  }
  cout << ret - lost << endl;
}



Measured memory_bytes: 892
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N;
    int rate[10]={1,400,800,1200,1600,2000,2400,2800,3200,4801};
    bool color[10]={false};
    int minimum=0, maximum=0;
    int gachipro=0;
    cin >> N;
    vector<int>a(N);

    for(int i=0; i<N; i++){
        cin>>a[i];
        for(int j=0; j<9; j++){
            if(rate[j]<=a[i] && a[i] <rate[j+1]) {
                color[j] = true;
                if(j==8)
                    gachipro++;
                break;
            }
        }
    }

    for(int i=0; i<8; i++){
        if(color[i])
            minimum++;
    }
    
    maximum=minimum+gachipro;
    if(minimum==0){
        minimum=1;
    }


    cout << minimum << " " << maximum << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n;
    cin >> n;
    if (n == 1) {
        P("Hello World");
    }
    else {
        int a, b;
        cin >> a >> b;
        P(a + b);
    }

    return 0;
}


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

int main(){
  int N,ans;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
  cin>>d.at(i);
  }
  ans = 0;

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i!=j){
        ans+=d.at(i)*d.at(j);
      }
    }
  }
  ans/=2;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, cnt, now, now2, ans = 1e9, sum;
  scanf("%lld", &n);
  m = 1 << n;
  ll a[n], b[n], dp[m][n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < n; ++i) scanf("%lld", &b[i]);
  for(i = 0; i < m; ++i) for(j = 0; j < n; ++j) dp[i][j] = 1e9;
  for(i = 0; i < n; ++i) dp[1 << i][i] = i;
  for(i = 1; i < m; ++i) {
    cnt = 0;
    for(j = 0; j < n; ++j) if((i >> j) & 1) ++cnt;
    for(j = 0; j < n; ++j) {
      now = ((cnt & 1) == (j & 1) ? b[j] : a[j]);
      sum = 0;
      for(k = 0; k < n; ++k) if(!((i >> k) & 1)) {
        now2 = ((cnt & 1) == (k & 1) ? a[k] : b[k]);
        if(now <= now2 && dp[i][j] + sum < dp[i | (1 << k)][k])
          dp[i | (1 << k)][k] = dp[i][j] + sum;
        sum++;
      }
    }
  }
  for(i = 0; i < n; ++i) if(ans > dp[m - 1][i]) ans = dp[m - 1][i];
  printf("%lld", ans == 1e9 ? -1 : ans);
  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> f(h);
  for (int i = 0; i < h; i++){
    cin >> f.at(i);
  }

  vector<int> x = {1, 1, 0, -1, -1, -1, 0, 1};
  vector<int> y = {0, 1, 1, 1, 0, -1, -1, -1};
  
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (f.at(i).at(j) == '#'){
        continue;
      }
      else{
        int n = 0;
        for (int k = 0; k < 8; k++){
          int iy = i + y.at(k);
          int jx = j + x.at(k);
          if (iy < 0 || iy >= h){
            continue;
          }
          if (jx < 0 || jx >= w){
            continue;
          }
          if (f.at(iy).at(jx) == '#'){
            n++;
          }
        }
        f.at(i).at(j) = '0' + n;
      }
    }
  }
  
  for (int i = 0; i < h; i++){
    cout << f.at(i) << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
st = list(list(map(str, input().split())) for _ in range(n))
x = input()

time_t = 0
for k, l in st:
    time_t += int(l)

time = 0
for i, j in st:
    if i == x:
        time += int(j)
        break
    else:
        time += int(j)

print(time_t - time)


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

int main(){

  int n, m, a, b;
  int to[200010] = {0};
  int from[200010] = {0};
  int flag = 0;

  cin >> n >> m;

  for(int i = 0; i < m; i++){
    cin >> a >> b;
    if(a == 1) to[b] = 1;
    if(b == n) from[a] = 1;
  }

  for(int i = 0; i < n; i++){
    if(to[i] == 1 && from[i] == 1) flag = 1;
  }

  if(flag){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  vs a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  bool ans = false;
  rep(i, n - m + 1) rep(j, n - m + 1) {
    bool now = true;
    rep(di, m) rep(dj, m) if(a[i + di][j + dj] != b[di][dj]) now = false;
    if(now) ans = true;
  }
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3624
n,x = map(int, raw_input().split())
l = map(int, raw_input().split())
ret = sum(l)
ll = [i for i in l]
for k in range(1,n):
    for i in range(n):
        p = (i+n-k) % n
        ll[i] = min(ll[i], l[p])
    ret = min(ret, sum(ll) + k * x)
print ret


Measured memory_bytes: 2816
#include <iostream>
using namespace std;
typedef long long ll;
int N,P,A[60];
ll dp[60][2] = {{0}},ans = 0;

int main(){
	cin >> N >> P;
	for(int i=1;i<=N;i++) cin >> A[i];
	dp[0][0] = 1; dp[0][1] = 0;
	for(int i=0;i<=N;i++){
		for(int j=i-1;j>=0;j--){
			if(A[i]%2==0){
				dp[i][0] += dp[j][0]; dp[i][1] += dp[j][1];
			}else{
				dp[i][0] += dp[j][1]; dp[i][1] += dp[j][0];
			}
		}
		ans += dp[i][P];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
    long A,B,K;
    
    scanf("%ld",&A);
    scanf("%ld",&B);
    scanf("%ld",&K);

    long X,Y;
    X = A+K-1;
    Y = B-K+1;

    if(X>=Y){
        while(A<=B){
            printf("%ld\n",A);
            A++;
        }
    }else{
        while(A<=X){
            printf("%ld\n",A);
            A++;
        }
        while(Y<=B){
            printf("%ld\n",Y);
            Y++;
        }
    }

    return 0;
}

Measured memory_bytes: 128
//#include<bits/stdc++.h>
#include<iostream>
#define MAX 100000
int partition(int,int);

using namespace std;
int S[MAX];
int n;

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

  for(i = 0; i < n; i++){
    cin >> S[i];
  }
  q = partition(0,n-1);
  for(i = 0; i < n; i++){
    if(0 < i){
      cout << " ";
    }
    if(i == q){
      cout << "[";
    }
    cout << S[i];
    if(i == q){
      cout << "]";
    }
  }
  cout << endl;
  return 0;
}//end main func

int partition(int p,int r){
  int i,j,x;
  int tmp;
  x = S[r];
  i = p-1;
  for(j = p; j < r; j++){
    if(S[j] <= x){
      i++;
      tmp = S[i];
      S[i] = S[j];
      S[j] = tmp;
    }
  }
  tmp = S[i+1];
  S[i+1] = S[r];
  S[r] = tmp;
  return i+1;
}// end partition func

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	vector <int> cnt( 101, 0 );
	int max_value = 0;
	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;
		cnt[n]++;
		max_value = max( cnt[n], max_value );
	}

	for ( int i = 1; i <= 100; i++ )
	{
		if ( cnt[i] == max_value )
		{
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
N = int(input())
ans = []

if N <= 26:
    r = N
    print(chr(ord("a")+r-1))
else:
    while N//26>0:
        r = N%26
        r -= 1
        d = N//26
        if r == -1:
            r = 25
            d -= 1
        N=d
        ans.append(chr(ord("a")+r))
    if N>0:
        r = N
        ans.append(chr(ord("a")+r-1))
    ans = ans[::-1]
    print("".join(ans))

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

int main() {
     
    long long i,j,l,q,t,m,n,h;
    long long k,z,p1,h1,x,y;
    string st="",st1="";
    q=1;
    for(l=0;l<q;l++)
    {
         std::cin >> n;
         n=n^1;
         std::cout << n << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3588
from collections import defaultdict
    
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)
    
n, k = map(int, input().split())
MOD = 10**9 + 7
com = Combinatorics(n+k, MOD)
ans = com.hom(k, n)
print(ans)


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

using namespace std;

int main()
{
    int N,a[110];
    scanf("%d",&N);
    for (int i=1;i<=N;i++)
    {
        scanf("%d",&a[i]);
    }
    int ans = 1e9;
    for (int t=-100;t<=100;t++)
    {
        int tmp = 0;
        for (int i=1;i<=N;i++) tmp += (t - a[i]) * (t - a[i]);
        ans = min(ans,tmp);
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i,n,x=-1,y=-1,z=-1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&x,&y,&z);
    if(z*z==x*x+y*y||y*y==x*x+z*z||x*x==y*y+z*z)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return(0);
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		private const int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start();
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long n = vs[0];
			long a = vs[1];
			long b = vs[2];
			long ans = 0;

			long x = n / (a + b);
			ans += a * x;
			long y = n % (a + b);
			if (y < a) {
				ans += y;
			} else {
				ans += a;
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
			//System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed);
		}
	}
}


Measured memory_bytes: 13396
import java.util.HashSet;
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sn = new Scanner(System.in);
		String n1, n2;
		while(sn.hasNext()){
			n1 = sn.next();
			n2 = sn.next();
			if(n1.equals("0") && n2.equals("0")) break;
			int hit = 0;
			int blow = 0;
			for(int i  = 0; i < 4; i++){
				if(n1.charAt(i) == n2.charAt(i)) hit++;
			}
			for(int i = 0; i < 4; i++){
				for(int j = 0; j < 4; j++){
					if(n1.charAt(i) == n2.charAt(j)) blow++;
				}
			}
			blow -= hit;
			System.out.println(hit+" "+blow);
		}
	}
}

Measured memory_bytes: 44244
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct node{
  int key;
  struct node *next, *prev;
};

typedef struct node *NP;

NP listsearch(int);
void init();
void printlist();
void delenode(NP);
void delfirst();
void dellast();
void delkey(int);
void insert(int);

NP nil;



int main(){
  int key, n, i, size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    } else if(com[0]=='d') {
      if(strlen(com)>6){
        if(com[6]=='F') delfirst();
        else if(com[6]=='L') dellast();
      } else {
        delkey(key);
        nd++;
      }
      size--;
    }
  }

  printlist();

return 0;
}

NP listsearch(int key){
  NP cur = nil->next;
  while(cur!=nil && cur->key!=key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printlist(){
  NP cur = nil->next;
  int isf = 1;
  while(1){
    if(cur==nil) break;
    if (isf==0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void delenode(NP t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void delfirst(){
  NP t = nil->next;
  if(t==nil) {
    return;
  }
  delenode(t);
}

void dellast(){
  NP t = nil->prev;
  if(t==nil) {
    return;
  }
  delenode(t);
}

void delkey(int key){
  delenode(listsearch(key));
}

void insert(int key){
  NP x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}



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

int main(){
char tenki[4];
char tenki_t[4];

scanf("%s", tenki);
scanf("%s", tenki_t);

int i;
int cnt=0;
for ( i = 0; i < 3; i++){
    if(tenki[i]==tenki_t[i]){
        cnt++;
    }
}

printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,m,q,t,x;
    cin>>n>>m;
    vector <vector <long long> > a(n);
    for(long long i=0;i<m;i++){
        cin>>q>>t;
        if(q==0){
            cin>>x;
            a.at(t).push_back(x);
        }
        else if(q==1){
            if(a.at(t).empty()){
                cout<<endl;
            }
            else{
                for(long long i=0;i<a.at(t).size()-1;i++){
                    cout<<a.at(t).at(i)<<" ";
                }
                cout<<a.at(t).at(a.at(t).size()-1)<<endl;
            }
        }
        else{
            if(!a.at(t).empty()){
                a.at(t).clear();
            }
        }
    }
    
    return 0;
}


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

using namespace std;

signed main(){
    int n;
    cin >> n;
    int* a = new int[n];
    int* sorted_a = new int[n];
    for (int i = 0;i < n;++i){
        cin >> a[i];
        sorted_a[i] = a[i];
    }
    sort(sorted_a,sorted_a + n);
    /*
     AiがAの最大値でなければ最大値を、
     最大値に一致するなら2番目を出力
     */
     int max1 = sorted_a[n - 1]; // 最大値
     int max2 = sorted_a[n - 2]; // 2番目
     for (int i = 0;i < n;i++){
         if (a[i] == max1)
            cout << max2 << endl;
        else
            cout << max1 << endl;
     }
    delete[] a;
    delete[] sorted_a;
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;


int main(){
	int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n){
      cin>>a[i];
    }
    vector<int> b;
    b.push_back(a[n-1]);
    for(int i=n-2;i>=0;i--){
        if(a[i]>=b[SZ(b)-1]){
            b.push_back(a[i]);
        }else{
            auto x=upper_bound(ALL(b),a[i]);
            b[x-b.begin()]=a[i];
        }
    }
    OUT(SZ(b));
	return 0;
}

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

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

  int size = 1 << n;
  int dp[size];
  for (int i=0; i<size; i++) dp[i] = 1e9;
  for (int i=0; i<m; i++) {
    int a, b;
    cin>>a>>b;
    bool can_open[n];
    for (int j=0; j<n; j++) {
      can_open[j] = false;
    }
    for (int j=0; j<b; j++) {
      int c;
      cin>>c;
      can_open[c-1] = true;
    }
    int state = 0;
    for (int j=n-1; j>=0; j--) {
      state *= 2;
      if (can_open[j]) {
        ++state;
      }
    }
    dp[state] = min(a, dp[state]);
  }
  for (int i=0; i<size; i++) {
    for (int j=0; j<size; j++) {
      if (dp[i] < 1e9 && dp[j] < 1e9) {
        dp[i|j] = min(dp[i] + dp[j], dp[i|j]);
      }
    }
  }
  if (dp[size-1] == 1e9) {
    cout<<-1<<endl;
  } else {
    cout<<dp[size-1]<<endl;
  }
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var N, K int
	var x []int
	count := 0

	fmt.Scanf("%d %d", &N, &K)

	for i := 0; i < N; i++ {
		x = append(x, nextInt())
	}

	sort.Sort(sort.Reverse(sort.IntSlice(x)))

	if N <= K {
		fmt.Println(0)
	} else {
		for j := 0; j < K; j++ {
			x[j] = 0
		}
		for k := 0; k < N; k++ {
			count += x[k]
		}

		fmt.Printf("%d", count)
	}
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[50],b[50];
	int len;
	cin>>len;
	string str;
	cin>>str;
	int ans=-1;
	for(int i=0;i<len;i++)
	{
		memset(a,0,sizeof a);
		memset(b,0,sizeof b);
		int cnt=0;
		for (int j=0;j<=i;j++)
			a[str[j]-'a']++;			
		for(int j=i+1;j<len;j++)
			b[str[j]-'a']++;		
		for(int j=0;j<26;j++)
		{
			if(a[j]==0&&b[j]==0)continue;
			if(a[j]>0&&b[j]>0)cnt++;
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
int a,b;
cin>>a>>b;
if(a>b){
  cout<<a+a-1<<endl;
}else if(a<b){
	cout<<b+b-1<<endl;
} else if(a=b){
  	cout<<a+b<<endl;}
  return 0;
}
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N,M;
    cin >> N >> M;
    int a[N],b[N],c[M],d[M];
    rep(i,N) cin >> a[i] >> b[i];
    rep(i,M) cin >> c[i] >> d[i];
    int ans=0;
    int sum=0;
    rep(i,N){
        sum=INF;
        ans=0;
        rep(j,M){
            int x=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(sum>x) {
                sum=x;
                ans=j+1;
            }

        }
        cout << ans << endl;
    }
 

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18
int INF = 100000000;//10^8
int X,Y,Z,K;
vector<ll> A(1000),B(1000),C(1000);
int main(void){
    cin >> X >> Y >> Z >> K;
    for(int i = 0; i < X; i++)cin >> A.at(i);
    for(int i = 0; i < Y; i++)cin >> B.at(i);
    for(int i = 0; i < Z; i++)cin >> C.at(i);
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    sort(B.begin(), B.end());
    reverse(B.begin(), B.end());
    sort(C.begin(), C.end());
    reverse(C.begin(), C.end());
    vector<ll> ABC;
    for(int i = 0; i < X; i++){
        if(i+1 > K) break;
        for(int j = 0; j < Y; j++){
            if((i+1) * (j+1) > K) break;
            for(int k = 0; k < Z; k++){
                if((i+1) * (j+1) * (k+1) > K) break;
                ABC.push_back(A.at(i) + B.at(j) + C.at(k));
            }
        }
    }
    sort(ABC.begin(), ABC.end());
    reverse(ABC.begin(), ABC.end());
    for(int i = 0; i < K; i++) cout << ABC.at(i) << endl;
}


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

int main(){
    ll n; cin>>n;
    for(ll i=1; i<=n; i++) {
        ll price = i*1.08;
        if(price==n) {
            cout<<i;
            return 0;
        }
    }
    cout<<":(";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;


int main(){
    int n,m;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    int b[m-1];
    sort(a,a+m);
    for(int i=0;i<m-1;i++){
        b[i]=a[i+1]-a[i];
    }
    sort(b,b+m-1);
    int ans=0;
    for(int i=0;i<m-n;i++){
        ans+=b[i];
    }
    cout<<ans;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
using namespace std;

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

vector<int> taro, hanako;

int main() {
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        taro.clear(); hanako.clear();
        repeat(i, n) {
            int tmp; cin >> tmp;
            taro.push_back(tmp);
        }
        repeat(i, m) {
            int tmp; cin >> tmp;
            hanako.push_back(tmp);
        }
        sort(taro.begin(), taro.end());
        sort(hanako.begin(), hanako.end());

//        repeat(i, taro.size()) cout << taro[i] << ' ';
//        cout << endl;
//        repeat(i, hanako.size()) cout << hanako[i] << ' ';
//        cout << endl;

        int sum_taro = accumulate(taro.begin(), taro.end(), 0);
        int sum_hanako = accumulate(hanako.begin(), hanako.end(), 0);
        int diff = sum_taro - sum_hanako;
        if (abs(diff) % 2 == 1) {
            cout << -1 << endl;
            continue;
        }
//        cout << "diff: " << diff << endl;
        int ex_taro = -1, ex_hanako = -1;
        repeat(i, taro.size()) {
            vector<int>::iterator it = find(hanako.begin(), hanako.end(), taro[i]-diff/2);
            if (it != hanako.end()) {
                ex_taro = taro[i];
                ex_hanako = *it;
                break;
            }
        }
        if (ex_taro == -1) {
            cout << -1 << endl;
        } else {
            cout << ex_taro << ' ' << ex_hanako << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	inputs := strings.Split(sc.Text(), " ")
	x, _ := strconv.Atoi(inputs[0])
	y, _ := strconv.Atoi(inputs[1])

	var r int
	for {
		r = x % y
		if r == 0 {
			fmt.Println(y)
			break
		}
		x = y
		y = r
	}
}



Measured memory_bytes: 1092
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
	//変数の宣言
	char a[200010];
	long int alphabet[30];
	int i,j,k;
	long int len;
	long int ans;
	
	//データの読み込み
	scanf("%s",&a);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<30;i++){
		alphabet[i]=0;
	}
	
	len=strlen(a);
	for(i=0;i<len;i++){
		alphabet[a[i]-'a']++;
	}
	
	ans=len*(len-1)/2+1;
	for(i=0;i<26;i++){
//		if(alphabet[i]!=0) printf("%cは%d個\n",'a'+i,alphabet[i]);
		ans=ans-alphabet[i]*(alphabet[i]-1)/2;
	}
	
	
	
//	printf("計算部分終了\n");
	
	//出力
	printf("%ld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n,a,min,max,i;
    long m=0;
    int kan[10001];
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        kan[i]=a;
        m=m+a;
        a=0;
    }
    sort(kan,kan+n);
    min=kan[0];
    max=kan[i-1];
    cout<<min<<" "<<max<<" "<<m<<endl;
    return 0;
}


Measured memory_bytes: 3136
import math
n,m = map(int,input().split())
if abs(n-m) > 1:
    print(0)
else:
    if n == m:
        print((2*math.factorial(n)*math.factorial(m))%(10**9+7))
    else:
        print((math.factorial(n)*math.factorial(m))%(10**9+7))

Measured memory_bytes: 54768
#include <stdio.h>

int main (){
	int input[100];
	for (int a=0;a<3;a++){
		scanf ("%d",&input[a]);
	}
	int total=input[0]*100+input[1]*10+input[2];
//	printf ("%d",total);
	if (total%4==0){
		printf ("YES\n");
	}else printf ("NO\n");

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	int ways=0;
	cin>>n>>k;
	if(n==k)
	{
		cout<<"1";
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(i<=n)
		{
			ways++;
		}
		if(i+k>n)
		{
			cout<<ways;
			return 0;
		}

	}
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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 ll INF = 1LL <<60;
const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 510000;
const int MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int r,g,b,n;
  cin>>r>>g>>b>>n;
  ll ans = 0;
  for(int i = 0; i <= 3000; i++){
    for(int j = 0; j <= 3000; j++){
      int bmax = n-i*r-j*g;
      // cout<<i<<" "<<j<<" "<<bmax<<endl;
      if(bmax%b==0&&bmax/b>=0&&bmax/b<=3000){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}



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

vector<int> x(3,-1);
vector<vector<int>> dp(100001, x) ;
vector<vector<int>> arr(100001, x) ;

int fn(int id, int t){
    
    int u = -1 ;
    
    if(id == 0){
        for(int i = 0 ; i < 3; ++i){
            if(i == t)continue ;
            u = max(u, arr[0][i]) ;
        }
        return u ;
    }
    
    if(dp[id][t] != -1) return dp[id][t] ;
    
    for(int i = 0 ; i < 3; ++i){
        if(i == t)continue ;
        u = max(arr[id][i] + fn(id - 1, i), u) ;
    }
    
    return dp[id][t] = u ;
}

main(){
    
        int n ;
        cin>>n ;
        for(int i = 0 ; i < n; ++i)cin>>arr[i][0]>>arr[i][1]>>arr[i][2] ;
        cout<<max(fn(n-1, 2), min(fn(n-1, 1), fn(n-1, 0))) ;
    
}

Measured memory_bytes: 20608
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        String s = in.next();
        int k = in.nextInt();

        char t = s.charAt(k - 1);
        out.println(s.replaceAll("[^" + String.valueOf(t) + "]", "*"));
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

    int nextInt() {
        return Integer.parseInt(this.sc.next());
    }

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 22868
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a:i64, b:i64) -> i64 {
    if a==0 { b }
    else { gcd(b%a,a) }
}

fn main() {
    input! {
        n: usize, x0: i64,
        xs: [i64; n]
    };

    println!("{}", xs.iter().map(|x| (x-x0).abs()).fold(0, gcd));
}


Measured memory_bytes: 4476
/*ABC174-D*/
#include<stdio.h>
#define reg register
#define ri reg int
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define nrep(i, x, y) for(ri i = x; i >= y; --i)
#define DEBUG 1
#define ll long long
#define max(i, j) (i) > (j) ? (i) : (j)
#define min(i, j) (i) < (j) ? (i) : (j)
struct IO {
	#define MAXSIZE (1 << 20)
	#define isdigit(x) (x >= '0' && x <= '9')
	char buf[MAXSIZE], *p1, *p2;
	char pbuf[MAXSIZE], *pp;
	#if DEBUG
	#else
		IO() : p1(buf), p2(buf), pp(pbuf) {}
		~IO() {
			fwrite(pbuf, 1, pp - pbuf, stdout);
		}
	#endif
	inline char gc() {
		#if DEBUG
    		return getchar();
		#endif
    	if(p1 == p2)
			p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
    	return p1 == p2 ? ' ' : *p1++;
	}
	inline bool blank(char ch) {
    	return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
	}
	template <class T>
	inline void read(T &x) {
    	register double tmp = 1;
    	register bool sign = 0;
    	x = 0;
    	register char ch = gc();
    	for(; !isdigit(ch); ch = gc())
    		if(ch == '-') sign = 1;
    	for(; isdigit(ch); ch = gc())
			x = x * 10 + (ch - '0');
    	if(ch == '.')
			for(ch = gc(); isdigit(ch); ch = gc())
        		tmp /= 10.0, x += tmp * (ch - '0');
    	if(sign) x = -x;
	}
	inline void read(char *s) {
		register char ch = gc();
		for(; blank(ch); ch = gc());
		for(; !blank(ch); ch = gc())
			*s++ = ch;
    	*s = 0;
	}
	inline void read(char &c) {
    	for(c = gc(); blank(c); c = gc());
	}
	inline void push(const char &c) {
		#if DEBUG
    		putchar(c);
		#else
    		if(pp - pbuf == MAXSIZE) {
				fwrite(pbuf, 1, MAXSIZE, stdout);
				pp = pbuf;
			}
    		*pp++ = c;
		#endif
	}
	template <class T>
	inline void write(T x) {
    	if(x < 0) {
			x = -x;
			push('-');
		}
    	static T sta[35];
    	T top = 0;
    	do{
			sta[top++] = x % 10;
			x /= 10;
    	}while(x);
    	while(top)
			push(sta[--top] + '0');
	}
	template <class T>
	inline void write(T x, char lastChar) {
    	write(x);
		push(lastChar);
	}
} io;
char st[200010];
int n, cr, ans;
int main() {
	io.read(n);
	rep(i, 1, n) {
		io.read(st[i]);
		if(st[i] == 'R') ++cr;
	}
	rep(i, 1, cr) if(st[i] == 'W') ++ans;
	io.write(ans);
}

Measured memory_bytes: 1660
// https://atcoder.jp/contests/dp/tasks/dp_b

import * as fs from "fs";

const split = (str: string): string[] => str.split(" ").map((v: string) => v.trim());
const split_number = (str: string): number[] => split(str).map((v: string) => +v);

export function main(input: string) {
  const lines = input.split("\n");
  const [n, k] = split_number(lines[0]);

  const h: number[] = split_number(lines[1]);
  let dp: number[] = new Array(n).fill(Infinity);
  dp[0] = 0;

  for (let i = 0; i < n; i++) {
    for (let j = 1; j < k + 1; j++) {
      if (i >= j) {
        dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i] - h[i - j]));
      }
    }

  }

  return dp[n - 1];
}

if (!process.env.LOCAL_DEBUG) {
  console.log(main(fs.readFileSync("/dev/stdin", "utf8")));
}


Measured memory_bytes: 27888
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a*b > c ? c : a*b) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A,B = map(int,input().split(" "))
P = list(map(int,input().split(" ")))
P.sort()
ansA = 0
ansB = 0
ansC = 0
for i in range(N):
    if P[i] <= A:
        ansA += 1
    elif P[i] <= B:
        ansB += 1
    else:
        ansC += 1
print(min(ansA,ansB,ansC))

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

int main() {
	int N;
	cin >> N;
	vector<long long> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a.at(i);
	}
	int countN2 = 0, countN4 = 0;
	for (int i = 0; i < N; i++) {
		if (a.at(i) % 2 == 0) {
			countN2++;
		}
		if (a.at(i) % 4 == 0) {
			countN4++;
		}
	}
	if (N/2 <= countN4) {
		cout << "Yes" << endl;
	}
	else if (N - 2*countN4 <= countN2 - countN4) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

int white[50];
int blue[50];
int red[50];
signed main()
{
  int h = in(), w = in();
  string table[h];
  int ans = 0;
  rep(i, h){
    cin >> table[i];
    white[i] = w - count(all(table[i]), 'W');
    blue[i] = w - count(all(table[i]), 'B');
    red[i] = w - count(all(table[i]), 'R');
  }
  int m = INF;
  reps(i, 1, h - 1){
    reps(j, i + 1, h){
      int chcnt = 0;
      rep(k, i) chcnt += white[k];
      reps(k, i, j) chcnt += blue[k];
      reps(k, j, h) chcnt += red[k];
      m = min(m, chcnt);
    }
  }
  print(m);

  return (0);
}

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

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

  int ans = 1001;

  for (int i = 0; i < N; i++) {
    int c, t;
    cin >> c >> t;
    if (t > T) continue;
    else ans = min(ans, c);
  }

  if (ans == 1001) cout << "TLE" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
from heapq import heappop, heappush
N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)


Measured memory_bytes: 31976
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;cin>>s;
	string s1=s;
	reverse(s1.begin(),s1.end());
	if(s==s1){
		string s2=s.substr(0,(s.length()-1)/2);
		string s3=s2;
		reverse(s3.begin(),s3.end());
		if(s2==s3){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn];
int b[maxn];
struct Node
{
    int x,y;
}s[maxn];
bool cmp(Node a,Node b)
{
      if(a.y==b.y)
        return a.x>b.x;
      else
        return a.y>b.y;
}
int main()
{
   int m,n,x,y;
    cin>>m>>n;
   for(int i=0;i<m;i++)
    scanf("%d",&a[i]);
    sort(a,a+m);
    for(int i=0;i<n;i++)
    scanf("%d%d",&s[i].x,&s[i].y);
    sort(s,s+n,cmp);
    int temp=0;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
         int it=lower_bound(a+temp,a+m,s[i].y)-(a+temp);
         it--;
        // cout<<it<<endl;
        if(it<0)
            continue;
         else
            {
                int ss=min(it+1,s[i].x);
                ans+=(ll)ss*s[i].y;
                temp+=ss;
            }
    }
   // cout<<temp<<' '<<ans;
    for(int i=temp;i<m;i++)
        ans+=a[i];
        cout<<ans<<endl;






    return 0;
}


Measured memory_bytes: 1408