akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e3+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	// freopen("out10.txt","w",stdout);
	#endif
	int x;
	cin>>x;
	cout<<(x/500)*1000+((x%500)/5)*5;
}
// Don't be afraid to fail. Be afraid not to try.
// "Become grindian instead of greendian" - aryanc403
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll a(n);
    map<ll, ll> mp;
    REP(i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    map<ll, ll> pass, hit;
    ll mem = 0;
    for (auto x : mp) {
        pass[x.first] = x.second * (x.second - 1) / 2;
        hit[x.first] = (x.second - 1) * (x.second - 2) / 2;
        mem += pass[x.first];
    }

    REP(i, n) {
        ll res = mem - pass[a[i]] + hit[a[i]];
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 26880
#include <iostream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
	int n;
	cin >> n;
	int mi = -1;
	int a, res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (mi == -1 || a <= mi) {
			mi = a;
			++res;
		}
	}
	cout << res;
 	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Point
{
	double x;
	double y;
	Point(double x, double y)
	{
		this.x = x;
		this.y = y;
	}
}
public class Main 
{
	static double helon(Point p1, Point p2, Point p3)
	{
		double a = Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
		double b = Math.sqrt((p2.x - p3.x) * (p2.x - p3.x) + (p2.y - p3.y) * (p2.y - p3.y));
		double c = Math.sqrt((p3.x - p1.x) * (p3.x - p1.x) + (p3.y - p1.y) * (p3.y - p1.y));
		double s = (a + b + c) / 2;
		return(Math.sqrt(s * (s - a) * (s - b) * (s - c)));
	}
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			List<Point> list = new ArrayList<Point>();
			for(int i = 0; i < 3; ++i)
			{
				double a = stdIn.nextDouble();
				double b = stdIn.nextDouble();
				list.add(new Point(a, b));
			}
			double a = stdIn.nextDouble();
			double b = stdIn.nextDouble();
			Point xp = new Point(a, b);
			double s1 = helon(list.get(0), list.get(1), list.get(2));
			double s2 = helon(list.get(0), list.get(1), xp);
			double s3 = helon(list.get(0), list.get(2), xp);
			double s4 = helon(list.get(1), list.get(2), xp);
			if(Math.abs(s1 - s2 - s3 - s4) < 1e-8)
			{
				System.out.println("YES");
			}
			else
			{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 12000
# coding: utf-8
# Your code here!

S = input()
array = ["A", "C", "G", "T"]
ctr, max_ctr = 0, 0

for i in range(len(S)):
    if S[i] in array:
        ctr += 1
        if max_ctr < ctr:
            max_ctr = ctr
    else: ctr = 0
    
print(max_ctr)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll x;
ll a[51],p[51];
ll sum=0;

void dfs(int n,ll rest){
    //printf("%d %lld %lld\n",n,rest,sum);
    if(rest<=1)return;
    rest--;
    if(rest>=a[n-1]){
        sum+=p[n-1];
        rest-=a[n-1];
    }else{
        dfs(n-1,rest);
        rest=0;
    }
    if(rest<=0)return;
    rest--;
    sum++;
    if(rest>=a[n-1]){
        sum+=p[n-1];
        rest-=a[n-1];
    }else{
        dfs(n-1,rest);
    }
    if(rest<=1)return;
    rest--;
}

int main(void){
    scanf("%d%lld",&n,&x);
    a[0]=1;
    p[0]=1;
    for(int i=1;i<50;i++){
        a[i]=3LL+a[i-1]*2LL;
        p[i]=p[i-1]*2LL+1LL;
    }
    dfs(n,x);
    printf("%lld\n",sum);
    return 0;
}

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

double a,b;
int mini,maxi;
int main(){
	cin >> a >> b;
	mini = ceil(max(a*100/8,b*10));
	maxi = floor(min((a+0.99999)*100/8,(b+0.99999)*10));
	if (mini > maxi) cout << "-1";
	else cout << mini;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define puts(x) cout << x << "\n"
#define endwith return
using namespace std;
set<int>ans;
signed main() {
	int n; cin >> n;
	if (n == 2) { puts(1); endwith 0; }
	ans.insert(n - 1);
	ans.insert(n);
	for (int i = 2; i <= sqrt(n); i++) {
		if ((n - 1) % i == 0) { ans.insert(i); ans.insert((n - 1) / i); }
		else if (n % i == 0) {
			int n1 = n;
			while (n1 % i == 0)n1 /= i;
			while (n1 > i)n1 %= i;
			if (n1 == 1)ans.insert(i);
			n1 = n;
			while (n1 % (n / i) == 0)n1 /= (n / i);
			while (n1 > (n / i))n1 %= (n / i);
			if (n1 == 1)ans.insert((n / i));
		}
	}
	puts(ans.size());
}

Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll

using namespace std;
using Graph = vector<vector<int> >;


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

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

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

vector<string> field;

/* if bfs

   queue<pair<int, int> > que
   que.push(start x, start y);

   int dist[x][y];
   memset(dist, -1, sizeof(dist));
   dist[start x][start y] = 0;
*/


// int N; cin >> N;
// field.resize(N);


int H, W;

int DP[1010][1010];

void show2dimDP(int sizex = 0, int sizey = 0) {
  int xmax;
  int ymax;
  if (sizex == 0 && sizey == 0) {
    xmax = 10;
    ymax = 10;
  } else {
    if (sizex == 0 || sizey == 0) {
      printf("error in show2dimDP size");
      return;
    }
    xmax = sizex;
    ymax = sizey;
  }
  cout << "showing " << xmax << " * " << ymax << "..." << endl;
  for (int i = 0; i < xmax; i++) {
    if (i == 0) {
      cout << setw(3) << " ";
      for (int j = 0; j < ymax; j++){
        cout << setw(3) << j;
      }
      cout << endl;
    }
    cout << setw(3) << i << ":";
    for (int j = 0; j < ymax; j++) {
      cout << setw(3) << DP[i][j];
    }
    cout << endl;
  }
}

int rec(int i, int j) {
  if (DP[i][j] != -1) return DP[i][j];

  int cnt = 0;
  for (int dir = 0; dir < 2; dir++) {
    int nx = i + dx[dir];
    int ny = j + dy[dir];
    if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
    if (field[nx][ny] == '#') continue;
    if (nx == H - 1 && ny == W - 1) cnt += 1;
    cnt += rec(nx, ny);
    cnt %= (ll)(1e9 + 7);
  }

  return DP[i][j] = cnt;
}
signed main() {
  cin >> H >> W;
  field.resize(H);

  for (int i = 0; i < H; i++) {
    cin >> field[i];
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      DP[i][j] = -1;
    }
  }
  cout << rec(0, 0) << endl;

  // show2dimDP(20, 20);
}


Measured memory_bytes: 9344
p=*0..gets.to_i
s=0
f=->a{a!=p[a]?p[a]=f[p[a]]:a}
a,b=$<.map(&:split).transpose.map{|a|i=0
(x,i),*y=a.map{[_1.to_i,i+=1]}.sort
y.map{[-x+x=_1,i,i=_2]}}
(a+b).sort.map{|c,*a|a,b=a.map &f
a!=b&&(s+=c
p[b]=a)}
p s

Measured memory_bytes: 52912
# -*- coding: utf-8 -*-
import bisect

n, k = map(int, input().split())
v_list = list(map(int, input().split()))

ret = 0

for i in range(0, min(n, k) + 1):
    for j in range(0, min(n, k) - i + 1):
        num_refund = k - i - j
        got_list = v_list[:i] if i > 0 else []
        got_list.extend(v_list[-j:] if j > 0 else [])
        sorted_list = sorted(got_list)

        if num_refund == 0:
            val = sum(sorted_list)
            if val > ret:
                ret = val

        insert_index = bisect.bisect_left(sorted_list, 0)
        if insert_index > num_refund:
            val = sum(sorted_list[num_refund:])
            if val > ret:
                ret = val
        else:
            val = sum(sorted_list[insert_index:])
            if val > ret:
                ret = val

print(ret)


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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  rep(i,n){
    cin >> x[i] >> y[i];
  }
  auto norm = [&](int i,int j){
    double xx = x[i] - x[j];
    double yy = y[i] - y[j];
    return sqrt(xx*xx+yy*yy);
  };
  int cnt = 0;
  double len = 0;
  vector<int> p(n);
  rep(i,n) p[i] = i;
  do{
    rep(i,n-1){
      len += norm(p[i],p[i+1]);
    }
    cnt++;
  }while(next_permutation(p.begin(),p.end()));
  
  double ans = len/cnt;
  printf("%.10f",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}


int main(){
    ll h,w,n; cin >> h >> w >> n;
    // bool gr[h][w];
    vector<ll> a(n), b(n);
    map<Pll,bool> used,m;
    rep(i,n){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        // gr[a[i]][b[i]] = 1;
        m[Pll(a[i],b[i])] = true;
        used[Pll(a[i],b[i])] = false;
    }
    // bool used[n];
    vector<ll> res(10,0);
    
    auto check = [&](ll x, ll y){
        for(int i = -2; i <= 0; i++){
            for(int j = -2;j <= 0; j++){
                ll xs = x + i;
                ll ys = y + j;
                if(xs < 0 || ys < 0 || h <= xs+2 || w <= ys + 2)continue;
                int temp = 0;
                bool ok = true;
                rep(ii,3)rep(jj,3){
                    // if(gr[xs + ii][ys + jj])temp++;
                    // if(m[Pll(xs+ii , ys+jj)])temp++;
                    auto it = m.find(Pll(xs+ii , ys+jj));
                    if(it != m.end()){
                        temp++;
                        if(used[Pll(xs+ii, ys+jj)])ok = false;
                    }
                }
                if(ok)res[temp]++;
            }
        }
        used[Pll(x,y)] = true;
    };
    rep(i,n)check(a[i], b[i]);
    ll sum = 0;
    rep(i,10)sum += res[i];
    res[0] = (h-2)*(w-2) - sum;
    print(res);
}

Measured memory_bytes: 14336
using System;
using System.Collections.Generic;
using System.Linq;


namespace ConsoleApp11
{
    class Class20
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            Dictionary<int, int> A = new Dictionary<int, int>();
            bool[] Loop = new bool[N];
            for(int i = 0; i < N; i++)
            {
                A.Add(i, int.Parse(Console.ReadLine()) - 1);
                Loop[i] = false;
            }
            int search = 0, count = 0;
            while (search != 1)
            {
                if (Loop[search]) { count = -1;break; }

                Loop[search] = true;
                search = A[search];
                count += 1;
            }
            Console.WriteLine(count);

        }
    }
}


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

int main(){
  int n; cin>>n;
  vector<int> a(n), b(n), c(n-1);
  for(int i=0; i<n; ++i){cin>>a[i]; --a[i];}
  for(int i=0; i<n; ++i)cin>>b[i];
  for(int i=0; i<n-1; ++i)cin>>c[i];

  int ans=b[a[0]], now=a[0];
  for(int i=1; i<n; ++i){
    ans+=b[a[i]];
    if(now==a[i]-1)ans+=c[now];
    now=a[i];
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
/* 
 * File:   main.c
 * Author: s1252007
 *
 * Created on July 6, 2018, 12:00 PM
 */

#include <stdio.h>
#include <stdlib.h>
#define MAX 100005
#define NIL -1

typedef struct { 
    int parent, left, right;
}Node;

Node Tree[MAX];
int num, H, Depth[MAX];

int getDepth(int u);
void print(int u);

int main(int argc, char** argv) {
    int index, depth, child, l, size;
    scanf("%d", &size);

    //Initialize binary tree
    for (int i = 0; i < size; i++ ) Tree[i].parent = Tree[i].left = Tree[i].right = NIL;

    for (int ix = 0; ix < size; ix++ )
    {
        scanf("%d %d", &index, &depth);
        for (int j = 0; j < depth; j++ )
        {
            scanf("%d", &child);
            if ( j == 0 ) Tree[index].left = child;
            else Tree[l].right = child;
            l = child;
            Tree[child].parent = index;
        }
    }

    H = 0;
    for (int i = 0; i < size; i++ )
    {
        Depth[i] = getDepth(i);
        if ( Depth[i] > H ) H = Depth[i];
    }

    for (int i = 0; i < size; i++ ) print(i);
    return 0;
}

int getDepth(int u)
{
    int i = 0;
    for(; Tree[u].parent != NIL ; i++) u = Tree[u].parent;
    return i;
}

void print(int u)
{
    int c;
    printf("node %d: ", u);
    printf("parent = %d, ", Tree[u].parent);
    printf("depth = %d, ", Depth[u]);

    if ( Tree[u].parent == NIL ) printf("root, ");
    else if ( Tree[u].left == NIL ) printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    for(int i = 0, c = Tree[u].left; c != NIL; i++, c = Tree[c].right)
    {
        if (i) printf(", ");
        printf("%d", c);
    }
    printf("]\n");
}





Measured memory_bytes: 3368
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int X,A,B;
	cin>>X>>A>>B;
	cout<<(X-A)%B<<"\n";
}


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

using namespace std;

int main(void){
    
    int n;
    cin >> n;
    
    vector<long long> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    
    cout << *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end()) << endl;

    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())

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

// 最大公約数
int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

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

int ctoi(char c){
  return c - '0';
}


int main(){
  int64_t n,m;
  cin >> n >> m;
  vector<int64_t> d(m);
  REP(i,m){
    cin >> d.at(i);
  }
  vector<int64_t> dp(65000);
  REP(i,n+1){
    dp.at(i) = INT_MAX;
  }
  dp.at(0) = 0;
  REP(i,n+1){
    REP(j,m){
      int64_t t = dp.at(i) + 1;
      int64_t u = dp.at(i+d.at(j));
      dp.at(i+d.at(j)) = min(t,u);
    }
  }
  cout << dp.at(n) << endl;
  return 0;
}




Measured memory_bytes: 3300
import sys
from collections import deque
sys.setrecursionlimit(1000000)
readline = sys.stdin.buffer.readline
n = int(readline())

g = [[] for _ in range(n+1)] #隣接リスト
for i in range(n-1):
    a,b = map(int,readline().split())
    g[a].append(b)
    g[b].append(a)

colors = [0] * (n+1)
 
colors[1] = 1
 
todo = []
for to in g[1]:
    todo.append([to, -1])
 
while todo:
    node, color = todo.pop()
 
    if colors[node] != 0:
        continue
 
    colors[node] = color
    new_color = -color
    for to in g[node]:
        if colors[to] != 0:
            continue
        todo.append([to, new_color])
ans = [0]*(n+1)
t0 = deque([])
t1 = deque([])
t2 = deque([])
for i in range(1,n+1):
    if i%3==1:
        t1.append(i)
    elif i%3==2:
        t2.append(i)
    else:
        t0.append(i)
black = 0
for i in colors[1:]:
    if i == 1:
        black += 1

if black <= n//3:
    for i in range(1,n+1):
        if colors[i] == 1:
            ans[i] = t0.pop()
        else:
            if t1:
                ans[i] = t1.pop()
            elif t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
elif black >= n-n//3:
    for i in range(1,n+1):
        if colors[i] == -1:
            ans[i] = t0.pop()
        else:
            if t1:
                ans[i] = t1.pop()
            elif t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
else:
    for i in range(1,n+1):
        if colors[i] == 1:
            if t1:
                ans[i] = t1.pop()
            else:
                ans[i] = t0.pop()
        else:
            if t2:
                ans[i] = t2.pop()
            else:
                ans[i] = t0.pop()
print(*ans[1:])

Measured memory_bytes: 110540
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, u, v, a[100000], b[100000];
vector<int> vec[100010];
int d[100010];
bool bl[100010];

signed main() {
	cin >> n >> u >> v;
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i] >> b[i];
		vec[a[i]].push_back(b[i]);
		vec[b[i]].push_back(a[i]);
	}
	queue<P> que;
	que.push({ v,0 });
	while (que.size()) {
		P p = que.front(); que.pop();
		bl[p.first] = true;
		d[p.first] = p.second;
		for (int i = 0; i < (int)vec[p.first].size(); i++) {
			if (!bl[vec[p.first][i]])que.push({ vec[p.first][i],p.second + 1 });
		}
	}
	int ma = d[u];
	queue<int> q;
	q.push(u);
	int k = d[u] / 2 + (d[u] % 2);
	while (q.size()) {
		int p = q.front(); q.pop();
		bl[p] = false;
		ma = max(ma, d[p]);
		for (int i = 0; i < (int)vec[p].size(); i++) {
			if (bl[vec[p][i]] && d[vec[p][i]] >= k)q.push(vec[p][i]);
		}
	}
	cout << ma - 1 << endl;
}

Measured memory_bytes: 9076
#!/usr/bin/env python3
import sys

t  = [0,1,2,3,4,5,6,7,8,9]
tb = [0,7,0,9,0,0,0,1,0,3]

def solve(K: int):
    k =K
    temp = 0
    ct = 0
    b = k%10

    while(True):
        ct+=1
        u = temp%10
        p = -1
        for i in range(10):
            if (u + (b*i)) %10 == 7:
                p = i
                break
        if p == -1:
            print(-1)
            return
        temp += k*p
        if temp == 7:
            print(ct)
            return
        temp //= 10

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67872
S=list(input())
A=[]
B=[]
a=0
b=0
for i in range(len(S)):
    if i%2==0:
        A.append("0")
    else:
        A.append("1")
for i in range(len(S)):
    if A[i]!=S[i]:
        a+=1
for j in range(len(S)):
    if j%2==0:
        B.append("1")
    else:
        B.append("0")
for j in range(len(S)):
    if B[j]!=S[j]:
        b+=1
print(min(a, b))

Measured memory_bytes: 5548
import fractions
n,k=map(int,input().split())
al=list(map(int,input().split()))
m=max(al)
f=al[0]
for i in range(1,n):
    f=fractions.gcd(f,al[i])
print('POSSIBLE' if k<=m and k%f==0 else 'IMPOSSIBLE')

Measured memory_bytes: 16280
#include <stdio.h>

int main(void)
{
	int d,a,b,c;
	long long s;
	while(scanf("%d",&d)!=EOF){
		b=1;
		s=0;
		a=d;
		while(a<600){
			c=a*a*d;
			s=s+c;
			b++;
			a=d*b;
		}
		printf("%lld\n",s);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
int main()
{
	int n[5];
	for (int i = 0; i < 5; i++)
	{
		std::cin >> n[i];
	}
	for (int i = 0; i < 5; i++)
	{
		int max = -100001, max_index = 0;
		for (int j = i; j < 5; j++)
		{
			if (max < n[j])
			{
				max = n[j];
				max_index = j;
			}
		}
		std::swap(n[i], n[max_index]);
	}
	for (int i = 0; i < 5; i++)
	{
		std::cout << n[i];
		if (i != 4)
		{
			std::cout << ' ';
		}
	}
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll n, m;
    cin >> n >> m;
    vector<p> check;
    vector<vector<ll>> g(n+1);
    vector<ll> use(n+1, 1);
    ll len[n+1];
    ll ans = 0;
    for(ll i = 0; i < n; i++)
        cin >> len[i+1];
    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        check.push_back(p(a,b));
        g[a].push_back(b);
        g[b].push_back(a);
        use[a] = -1; use[b] = -1;
    }
    ll sum = 0;
    ll dc = 0;
    for(ll i = 1; i <= n; i++){
        if(use[i]==1) continue;
        ans = 0;
        vector<ll> dist(n+1, -1);
        queue<ll> que;
        que.push(i);
        dist[i] = 0;
        ll count = 0;
        while(!que.empty()){
            ll v = que.front();
            que.pop();
            for(ll nv : g[v]){
                if(dist[nv]!=-1) continue;
                dist[nv] = dist[v]+1;
                que.push(nv);
               use[nv] = 1;
               count++;
            }
        }
        if(ans >= count) continue;
        for(ll i = 1; i <= n; i++){
            if(len[i]==i)
                ans++;
            else if(dist[i]==-1) continue;
            else if(len[i]!=i && dist[len[i]]!=-1)
                ans++;
        }
        sum = max(ans, sum);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 10096
#include <iostream>
#include <string>

using namespace std;

int main(void){
  int line_length;
  cin>>line_length;
  string str;
  std::getline(std::cin, str);

  for(int i=0;i<line_length;++i){
    string input;
    getline(cin,input);
    std::string::size_type pos;
    while(( pos = input.find("Hoshino")) != std::string::npos){
      input.replace(pos, 7, "Hoshina");
    }
    cout << input<<endl;
  }
  return 0;
}



Measured memory_bytes: 3144
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

from itertools import accumulate
    
for _ in range(K):
    ans=[0]*(N+1)
    for i,a in enumerate(A):
        ans[max(0,i-a)]+=1
        ans[min(i+a+1,N)]-=1
    A = list(accumulate(ans))[:-1]
    if all(i == N for i in A):
        break
print(*A)

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

int main(){
	string s;
	int n,h;
	while(1){
		cin >> s;
		if(s == "-"){
			break;
		}
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> h;
			s=s.substr(h)+s.substr(0,h);
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3176
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    a--,b--,c--,d--;
    string s;
    cin >> s;
    bool flag = true;
    for(int i = b; i <= d-1; i++){
        if(s[i] == '#' and s[i+1] == '#'){
            flag = false;
        }
    }
    for(int i = a; i <= c-1; i++){
        if(s[i] == '#' and s[i+1] == '#'){
            flag = false;
        }
    }
    if(!flag){
        cout << "No" << endl;
        return 0;
    }
    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }else{
        bool f = false;
        for(int i = b-1; i <= d-1; i++){
            if(s[i] == '.' and s[i+1] == '.' and s[i+2] == '.')f = true;
        }
        if(f){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 640
#include <stdio.h>
int main (void){
    int a =0,b =0,c =0;
    int fcount =0,scount =0;
    scanf("%d %d %d",&a, &b, &c );
    if(a == 5){
        fcount++;
    }else if( a ==7){
        scount++;
    }

    if(b == 5){
        fcount++;
    }else if( b ==7){
        scount++;
    }

    if(c == 5){
        fcount++;
    }else if( c ==7){
        scount++;
    }

    if(fcount ==2 && scount ==1){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		String str = sc.nextLine();
		String sl[] = str.split(" ");
		int a = Integer.parseInt(sl[0]);
		int b = Integer.parseInt(sl[1]);
		int c = Integer.parseInt(sl[2]);

		System.out.println(a + b >= c ? "Yes" : "No");
	}
}

Measured memory_bytes: 20820
#include<bits/stdc++.h>
using namespace std;
long long c[100010];

int main(void){
	int n;cin >> n;
	vector<int> a(n); for(int i = 0;i < n;i++) cin >> a[i];
	sort(a.begin(),a.end());
	for(int i = 0;i < n;i++){
		c[i+1] = c[i] + a[i];
	}
	int ans = 1;
	for(int i = n-1;i >= 0;i--){
		if(c[i]*2 >= a[i])ans++;
		else break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,fr = 0;
  cin >> n;
  int a[n];
  for(int i = 0;i < n;i++){
    cin >> a[i];
    if(a[i] >= 3200){
      fr++;
    }
  }
  int color = 0;
  for(int i = 0;i < 2801;i += 400){
    for(int j = 0;j < n;j++){
      if(a[j] < i + 400 && i <= a[j]){
        color++;
        break;
      }
    }
  }
  int mi = color,ma = color+fr;
  if(color != 0){
    cout << mi << " " << ma << endl;
  }
  else{
    cout << 1 << " " << ma << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
  int N,Q;
  cin >> N >> Q;

  string s;
  cin >> s;

  vector<vector<int> >question(Q,vector<int>(2,0));
  for(int i=0;i<Q;i++){
    cin >> question[i][0];
    cin >> question[i][1];
  }

  for(int i=0;i<N - 1;i++){
    if(s[i] == 'A' && s[i + 1] == 'C')
      s[i] = 'p';
  }

  vector<int>num_p(N + 1,0);
  for(int i=0;i<N;i++){
    if(i == 0){
      if(s[i] == 'p')
        num_p[i + 1] = 1;
      else
        num_p[i + 1] = 0;
    }
    else{
      if(s[i] == 'p')
        num_p[i + 1] = num_p[i] + 1;
      else
        num_p[i + 1] = num_p[i];
    }
  }

  for(int i=0;i<Q;i++){
    cout << num_p[question[i][1] - 1] - num_p[question[i][0] - 1] << endl;
  }

  return 0;
}
  
    

Measured memory_bytes: 8576
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int main(){
  string str;
  while(cin >> str){
    string next_str = str;
    const string aid = "AIZUNYAN";

    for(int i=0;i<str.size();i++){
      string tmp = str.substr(i,8);
      int freq[256] = {};
      for(int j=0;j<8;j++) freq[tmp[j]]++;

      if(freq['A'] == 2
	 && freq['I'] == 1 
	 && freq['D'] == 1 
	 && freq['U'] == 1 
	 // && freq['N'] == 2
	 && freq['Y'] == 1
	 // && freq['A'] == 2
	 && freq['N'] == 2){ 
	for(int j=0;j<8;j++) next_str[i+j] = aid[j];
      }
    }
    cout << next_str << endl;
  }
}

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

using namespace std;
int _wno;

int n, m, k;

int main() {
	_wno = scanf( "%d%d%d", &n, &m, &k );
	for( int i = 0; i <= n; ++i )
		for( int j = 0; j <= m; ++j )
			if( k == i*(m-j) + j*(n-i) )
				return puts("Yes"), 0;
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int a,b;
	char c;
	double x=0, y=0, r=0;
	while(1){
		cin>>a>>c>>b;
		if(a==0&&b==0) break;
		x+=a*sin((pi()*r)/180);
		y+=a*cos((pi()*r)/180);
		r+=b;
	}
	cout<<(int)x<<endl;
	cout<<(int)y<<endl;
}

Measured memory_bytes: 1164
using System;
using System.Linq;

namespace Streamline
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse);
            var input = Console.ReadLine().Split().Select(int.Parse).OrderBy(i => i).ToArray();
            int fullLenght = input[input.Length - 1] - input[0];
            var diffrences = new int[input.Length - 1];
            for (int i = 0, j = 1; i < input.Length - 1; i++, j++)
            {
                diffrences[i] = input[j] - input[i];
            }
            Console.WriteLine(fullLenght - diffrences.OrderBy(d => -d).Take(nm.ElementAt(0) - 1).Sum());
        }
    }
}


Measured memory_bytes: 23904
#include <iostream>

bool A[101];

int main()
{
	int x, n, p, t;
	std::cin >> x >> n;
	for (int i = 0; i < n; ++i)
	{
		std::cin >> p;
		A[p] = true;
	}

	int l = 0;
	t = x;
	while (0 < t && A[t])
	{
		++l;
		--t;
	}

	int r = 0;
	t = x;
	while (t < 101 && A[t])
	{
		++r;
		++t;
	}

	int ans;
	if (l <= r)
	{
		ans = x - l;
	}
	else
	{
		ans = x + r;
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 3536
n, k, q = gets.chomp.split.map(&:to_i)
scores = [k]*n
ac = [0]*n
q.times do
  ai = gets.chomp.to_i
  ac[ai - 1] += 1
end

ac.each.with_index do |aci, i|
  scores[i] -= q - aci
end

scores.each do |s|
  puts s > 0 ? 'Yes' : 'No'
end


Measured memory_bytes: 3708
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

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

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

    string s;
    cin >> s;

    string pre;

    for (int i=0; i<n/2; i++){
        pre += s[i];
    }

    string ju = pre + pre;

    if (s == ju){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    string s;cin>>s;
    ll ans = ll(s.size());
    REP(i,s.size()-1){
        if (s[i] != s[i+1]) {
            ll mx = max(i+1, ll(s.size()-(i+1)));
            ans  = min(mx, ans);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3696
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		/*
		 * ケツからたどればよさそう（ケツは情報量が少ないので）
		 * ケツからだと情報が把握できる
		 * いま連結かどうかを何度も判定するので、高速なアルゴリズムが必要
		 * UnionFndで共通祖先を連結か何かに応用できないか？
		 */
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[][] data=new int[M][2];
		long[] res=new long[M+1];
		long fumando=((long)N)*((long)N-1)/2L;
		res[0]=fumando;
		for(int i=M-1; i>=0; i--) {
			data[i][0]=sc.nextInt();
			data[i][1]=sc.nextInt();
		}
		UnionFindTree UFT=new UnionFindTree(N);
		for(int i=0; i<M; i++) {
			int AR=UFT.find(data[i][0]);
			int BR=UFT.find(data[i][1]);
			long a=(long)UFT.size(AR);
			long b=(long)UFT.size(BR);
			//pl(AR+" "+BR+" "+a+" "+b);
			UFT.union(data[i][0], data[i][1]);
			if(AR!=BR) {
				res[i+1]=res[i]-a*b;
			}
			else {
				res[i+1]=res[i];
			}
		}
		for(int i=M-1; i>=0; i--) {
			System.out.println(res[i]);
		}
	}
	public static class UnionFindTree {
		int nodeNum;	//頂点数
		int [] parent;	//親の頂点の値
		int [] height;	//高さ（祖先からの距離）
		int [] treeSize;	//共通祖先を持つ頂点集合の数（クラスタ内の頂点の数）

		public UnionFindTree(int nodeNum) {
			this.nodeNum = nodeNum;
			parent = new int[nodeNum+1];
			height = new int[nodeNum+1];
			treeSize = new int[nodeNum+1];
			for (int i = 1; i <= nodeNum; i++) {
				parent[i] = i;
				height[i] = 0;
				treeSize[i] = 1;
			}
		}
		int find(int x) {
			if (parent[x] == x) {
				return x;
			} else {
				return parent[x] = find(parent[x]);
			}
		}
		void union(int x, int y) {
			int rootX = find(x);
			int rootY = find(y);
			if (rootX == rootY) {
				return;
			}
			if (height[rootX] < height[rootY]) {
				parent[rootX] = rootY;
				treeSize[rootY] += treeSize[rootX];
			} else {
				if (height[rootX] == height[rootY]) {
					height[rootX]++;
				}
				parent[rootY] = rootX;
				treeSize[rootX] += treeSize[rootY];
			}
		}
		int size(int vertex) {
			return treeSize[vertex];
		}
	}
}


Measured memory_bytes: 99752
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
sys.setrecursionlimit(10**5)

n,x = readline().split()
n = int(n)
x = int(x,2)
*a, = map(lambda x:int(x,2), read().split())

def gcd(a,b):
    c = 0
    while b:
        if a < b:
            a,b = b,a
            continue
        a ^= b<<(a.bit_length() - b.bit_length())
    return a

v = 0
for ai in a: v = gcd(ai,v)

MOD = 998244353
p2 = [1]
for _ in range(5000): p2.append(p2[-1]*2%MOD)

dv = v.bit_length()
dx = x.bit_length()

def dfs(x,y,d):
    if d < dv:
        return int(x >= y)
    else:
        bx = x>>(d-1)&1
        by = y>>(d-1)&1
        if bx and by:
            return (p2[d-dv] + dfs(x,y,d-1)) %MOD
        elif not bx and by:
            return dfs(x,y^(v<<(d-dv)),d-1)
        elif not by and bx:
            return (p2[d-dv] + dfs(x,y^(v<<(d-dv)),d-1)) %MOD
        else:
            return dfs(x,y,d-1)

print(dfs(x,0,dx))




Measured memory_bytes: 13500
N, K = map(int, input().split())
S = list(input())

countR = S.count("R")
countL = S.count("L")
idx_list = []

for i in range(1, N):
    if S[i-1] != S[i]:
        idx_list.append(i)
idx_list.append(N)

i = 1
count = 0
for i in range(1, len(idx_list), 2):
    idx_start = idx_list[i - 1]
    idx_end = idx_list[i]
    
    for j in range(idx_start, idx_end):
        if S[j] == "R":
            S[j] = "L"
        else:
            S[j] = "R"    
    
    count += 1
    if count == K:
        break

ans = 0
for i in range(len(S)):
    if i == 0 and S[i] == "L":
        continue
    if i == (len(S)-1) and S[i] == "R":
        break
    
    if (S[i] == "L" and S[i-1] == "L") or (S[i] == "R" and S[i+1] == "R"):
        ans += 1

print(ans)

Measured memory_bytes: 7804
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define GCD(v) gcd(ALL(v), 0l)

/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/

template <typename T>
using vec = vector<T>;

template <typename T>
using vvec = vector<vector<T>>;

int main(){
  int n;
  cin>>n;
  string c;
  cin>>c;
  int cnt=0,cnt2=0;
  for (int i = 0; i < n; i++) {
    if(c[i]=='R')cnt++;
  }
  for (int i = 0; i < cnt; i++) {
    if(c[i]=='W')cnt2++;
  }
  cout<<cnt2;
}


/* きょむ〜 */


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll dp[101][100001];
ll wight[101], value[101];

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

    rep(i, n) cin >> wight[i] >> value[i];

    rep(j, 100001) dp[0][j] = 0;
    rep(i, n)
    {
        for (int j = 0; j <= w; j++)
        {
            if (j - wight[i] >= 0)
                dp[i + 1][j] = max(dp[i][j], dp[i][j - wight[i]] + value[i]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }
    OP(dp[n][w]);
    return 0;
}

Measured memory_bytes: 79104
while True:
    b, r, g, c, s, t = map(int, raw_input().split())
    if b == r == g == c == s == t == 0:
        break
    m = 100
    m += (b + r) * 15 + 13 * (5 * b + 3 * r)
    m += 7 * g + 2 * c
    m -= (t - s - b * 5 - r * 3) * 3
    print(m)

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

UL N;
int A[2000000];

void maxHeapify(UL i){
 UL l = (i<<1)+1;
 UL r = (i<<1)+2;
 UL largest=i;
 if(l<N && A[l]>A[largest]) largest = l;
 if(r<N && A[r]>A[largest]) largest = r;

 if(largest != i){
  swap(A[i],A[largest]);
  maxHeapify(largest);
 }
}

void maxHeapify2(UL i){
 if(i==0) return;
 UL p = (i-1)>>1;
 UL least=i;
 if(A[p]<A[least]) least = p;

 if(least != i){
  swap(A[i],A[least]);
  maxHeapify2(least);
 }
}

void insert(int v){
 A[N]=v; N++;
 maxHeapify2(N-1);
}

void pop(){
 swap(A[0],A[N-1]); N--;
 maxHeapify(0);
}

void buildMaxHeap(){ for(UL i=(N-1)/2; i!=~0; i--) maxHeapify(i); }

int main() {
 N=0;
 char strbuf[10];
 while(true){
  scanf("%s",strbuf);
  string S{strbuf};
  if(S=="insert"){
   int v; scanf("%d",&v);
   insert(v);
  }
  else if(S=="extract"){
   printf("%d\n",A[0]);
   pop();
  }
  else break;
 }
 return 0;
}



Measured memory_bytes: 7208
#include <bits/stdc++.h>
#define rep(i, n, init) for (int i = init, len = (n); i < len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define _GLIBCXX_DEBUG
#define int long long
#define float long double
#define len(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;

template <class Key, class Value>
pair<Key, Value> findMaxValuePair(unordered_map<Key, Value> const &x) {
  return *max_element(
      x.begin(), x.end(),
      [](const pair<Key, Value> &p1, const pair<Key, Value> &p2) { return p1.second < p2.second; });
}

string padStart(int target, int len, char padString) {
  ostringstream ss;
  ss << setfill(padString) << right << setw(len) << target << flush;
  return ss.str();
}

bool isEven(const int &n) {
  return !(n & 1);
}

int ctoi(const char c) {
  return ('0' <= c && c <= '9') ? (c - '0') : -1;
}

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

  int A;
  float B;

  cin >> A >> B;

  cout << fixed << setprecision(0);
  cout << (int)((A * (B * 1000)) / 1000) << endl;

  return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
//#define P pair<int,int>


signed main(){
    int N;
    int Ans=3;
    string S[2];
    cin >> N;
    cin >> S[0] >> S[1];
    if(N==1){
        cout << 3 << endl;return 0;
    }
    REP(i,S[0].size()){
        if(S[0][i]==S[0][i+1] && S[1][i]==S[1][i+1]){
            S[0].erase(S[0].begin() + i);
            S[1].erase(S[1].begin() + i);
        }
    }
    if(S[0][0]!=S[1][0])Ans*=2;
    //cout << S[0] << endl << S[1] << endl;
    REP(i,S[0].size()-1){
        if(S[0][i]==S[1][i] && S[0][i+1]==S[1][i+1]){
            Ans=(Ans*2)%MOD;
        }else if(S[0][i]==S[1][i] && S[0][i+1]!=S[1][i+1]){
            Ans=(Ans*2)%MOD;
        }else if(S[0][i]!=S[1][i] && S[0][i+1]==S[1][i+1]){
            Ans=Ans%MOD;
        }else if(S[0][i]!=S[1][i] && S[0][i+1]!=S[1][i+1]){
            Ans=(Ans*3)%MOD;
        }
    }
    cout << Ans << endl;
    
	return 0;
}

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

using i64 = int64_t;

int main(){
    string s, t;
    cin >> s >> t;
    vector<int> cumsums((int)s.size()+1), cumsumt((int)t.size()+1);
    for(int i=1;i<=(int)s.size();++i){
        cumsums[i] = cumsums[i-1] + (s[i-1] == 'A' ? 1 : 2);
    }
    for(int i=1;i<=(int)t.size();++i){
        cumsumt[i] = cumsumt[i-1] + (t[i-1] == 'A' ? 1 : 2);
    }
    int q;
    cin >> q;
    for(int i=0;i<q;++i){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x = (cumsums[b] - cumsums[a-1]) % 3;
        int y = (cumsumt[d] - cumsumt[c-1]) % 3;
        cout << (x == y ? "YES" : "NO") << endl;
    }

    return 0;
}

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

typedef pair<ll, pair<int, int> > p;

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int ac = max(A, C);
    int bd = min(B, D);

    cout << max(0, bd - ac) << endl;
}

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

int main() {
  
  string s;
  cin >>  s;
  
  int n = s.size();
  int ans = 0;
  
  REP(i,n/2) {
    if (s[i] != s[n-i-1]) ans++;
  }
  
  cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

auto main () -> int
{
    auto z = 100000;
    int n;
    std::cin >> n;
    for (auto i = 0; i < n; ++ i)
    {
        auto d = z / 100 * 5; // 5%
        if (d % 1000)
        {
            d += 1000 - d % 1000;
        }
        z += d;
    }
    std::cout << z << std::endl;
}

Measured memory_bytes: 3084