akhauriyash/Code-Regression huggingface dataset:
import sys
fin = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush


def initialize(adj, s):
    MAX_NUM = float('inf')
    parent = {s: None}
    d = {vertex: MAX_NUM for vertex in adj.keys()}
    d[s] = 0
    return d, parent


def initialize_int(adj, s):
    """
    assume that all vertex in {0, 1, 2, ..., N - 1}
    """
    N = len(adj)
    MAX_NUM = float('inf')
    d = [MAX_NUM] * N
    d[s] = 0
    parent = [None] * N
    return d, parent


# Dijkstra can work using a minheap which does not have decrease_key.
# and also we do not have to implement Vertex class.
# Instead, we can use (distance, vertex).
# in this case, the time it takes is O(ElgE).
# E is at most O(V^2), thus O(ElgE) = O(ElgV).
def dijkstra_simple(adj, w, s):
    d, parent = initialize_int(adj, s)
    priority_queue = []
    heappush(priority_queue, (d[s], s))
    while priority_queue:
        distance, source = heappop(priority_queue) 
        for neighbor in adj[source]:
            new_distance = distance + w[(source, neighbor)]
            if new_distance < d[neighbor]:
                d[neighbor] = new_distance
                parent[neighbor] = source
                heappush(priority_queue, (new_distance, neighbor))
    return d


n, m, s, t = [int(elem) for elem in fin().split()]
s -= 1
t -= 1
adj = [[] for _ in range(n)]
yen_weights = dict()
snuuk_weights = dict()
for _ in range(m):
    u, v, a, b = [int(elem) for elem in fin().split()]
    u -= 1
    v -= 1
    for v1, v2 in [(u, v), (v, u)]:
        adj[v1].append(v2)
        yen_weights[(v1, v2)] = a
        snuuk_weights[(v1, v2)] = b

d_yen = dijkstra_simple(adj, yen_weights, s)
d_snuuk = dijkstra_simple(adj, snuuk_weights, t)
min_cost = float('inf')
min_cost_after_each_year_reversed = []
for vertex in reversed(range(n)):
    min_cost = min(min_cost, d_yen[vertex] + d_snuuk[vertex])
    min_cost_after_each_year_reversed.append(min_cost)

initial_money = 10**15
for cost in reversed(min_cost_after_each_year_reversed):
    print(initial_money - cost)


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

using namespace std;

int sum(vector<int> &xs, int pos) {
  int sum = 0;
  for (auto x : xs) {
    int base = (x - pos);
    sum += base * base;
  }

  return sum;
}

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }

  int min = -1;
  for (int i = 0; i <= 100; i++) {
    int hp_sum = sum(xs, i);
    if (min < 0 || min > hp_sum) {
      min = hp_sum;
    }
  }

  cout << min << "\n";
}

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

ll a[N],h[N];
ll dp[N],bit[N];
int n;

int lowbit(int x)
{
    return x&(-x);
}

void add(int x,ll y)
{
    for(;x<=n;x+=lowbit(x)) bit[x] = max(bit[x],y);
}

ll query(int x)
{
    ll res = 0;
    for(;x;x-=lowbit(x)) res = max(res,bit[x]);
    return res;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>h[i];
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        dp[i] = query(h[i])+a[i];
        add(h[i],dp[i]);
    }
    cout<<query(n)<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define rall(v) v.rbegin(),v.rend()
#define MP make_pair
#define pb(n) push_back(n)
#define int long long

signed main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int ans = 0;
    rep(i,N){
        int inc = i;
        int dec = i;
        while(A[inc] <= A[inc+1] && inc < N) ++inc;
        while(A[dec] >= A[dec+1] && dec < N) ++dec;
        i = max(inc,dec);
        ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    rep(i,0,n-2){
        if(a[i]==a[i+1]){
            cout<<"NO"<<endl;return 0;
        }
    }
    cout<<"YES"<<endl;
    
    
    
    return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

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

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}


int main(){

    ll n; cin >> n;
    vector<map<char,ll>> s_cnt(n);
    string s;
    rep(i, n){
        cin >> s;
        for(auto c:s){
            s_cnt[i][c]++;
        }
    }

    map<char, ll> mn;
    for(auto c:"abcdefghijklmnopqrstuvwxyz"){
        mn[c] = INF;
    }

    rep(i, n){
        for(auto c:"abcdefghijklmnopqrstuvwxyz"){
            mn[c] = min(mn[c], s_cnt[i][c]);
        }
    }

    string ans = "";
    for(auto c:"abcdefghijklmnopqrstuvwxyz"){
        rep(i, mn[c]) ans.push_back(c);
    }

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

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

void swap(int* a,int* b)
{
 int tmp;
 tmp = *a;
 *a = *b;
 *b = tmp;
}
int main()
{
 int n;
 cin >> n;
 int nums[10000];
 int i;
 for(i=0;i<n;i++)
 {
  cin >> nums[i];
 }
 int j;
 int count = 0;
 for(i=0;i<n;i++)
 {
  for(j=n-1;j>i;j--)
  {
    if(nums[j]<nums[j-1]){swap(&nums[j],&nums[j-1]);count++;}
  }
 }
 
 cout << nums[0];
 for(i=1;i<n;i++)
 {
  cout << " " << nums[i];
 }
 cout << "\n" << count << endl;

}

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

int main() {
    string s;
    cin >> s;
    map<char, int> mp;
    for (auto e : s) mp[e]++;
    int ans = 1e9;
    for (char c = 'a'; c <= 'z'; c++) {
        if (mp[c] == 0) continue;
        if (mp[c] == s.size()) {
            cout << 0 << endl;
            return 0;
        }
        int cnt = 0, t = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == c)
                cnt = 0;
            else
                cnt++;
            t = max(t, cnt);
        }
        ans = min(ans, max(t, cnt));
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprv(i, n) for (int i = n - 1; i >= 0; i--)
#define ll long long
using namespace std;

int main() {
    ll a,b,c,k;
    ll total;
    cin >> a >> b >> c >> k;

    if (k <= a){
        total = k;
    } else {
        total = a;
        k = k - a;

        if (k <= b) {
            // do nothing;
        } else {
            k = k - b;
            total = total - k;
        }

    }

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
using namespace std;

#define MAXN 100010

char s1[55][55],s2[55][55];


int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",s1[i]);
    for(int i=0;i<m;i++)
        scanf("%s",s2[i]);
    int len1=strlen(s1[0]);
    int len2=strlen(s2[0]);
    int ans=0;

    for(int i=0;i<=n-m;i++)
    {
        for(int j=0;j<=len1-len2;j++)
        {
            int ok=0;

            for(int k=0;k<m;k++)
                for(int x=0;x<len2;x++)
                    if(s1[i+k][j+x]!=s2[k][x])
                        ok=1;
            if(ok==0)
                ans=1;
        }
    }
    if(ans==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

namespace ABC0603
{
	class Program
	{
		static void Main(string[] args)
		{

			var ps = Console.ReadLine();

			var l = ps.Length;

			var sub = ps.Substring(0, l - 2);

			while (l > 0)
			{
				l -= 2;
				var f = sub.Substring(0, l / 2);
				var b = sub.Substring(l / 2, l / 2);

				if(f == b)
				{
					Console.WriteLine(l);
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
typedef long long ll;
 
int main() {
    ll K, A, B;
    cin >> K >> A >> B;
    if (A + 3 > B || K < A + 1) cout << K + 1 << endl;
    else {
        cout << A + (K - A + 1) / 2 * (B - A) + (K - A + 1) % 2 << endl;
    }
}

Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, _n, func, inf=float('inf')):
        '''
        _n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(_n-1).bit_length()
        self.inf = inf
        self.data = [inf]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のminを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


N = int(input())
L = list(map(int, input().split()))
T = SegmentTree(N, gcd, 0)
for i, l in enumerate(L):
    T.set(i, l)
T.build()

ans = 0
for i in range(N):
    l = i
    r = i+1
    ans = max(ans, gcd(T.query(0, l), T.query(r, N)))
print(ans)


Measured memory_bytes: 60908
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		if(a/10 == 9 ||a % 10 == 9)System.out.print("Yes");
		else System.out.print("No");
	}

}


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

int main() {
    int n;
    cin >> n;
    vector<double> a(n);
    double ave = 0;
    rep(i, n) {
        cin >> a[i];
        ave += a[i];
    }
    ave /= n;
    double mi = 1e8;
    int ans = 0;
    rep(i, n) {
        if (mi > abs(ave - a[i])) {
            mi = abs(ave - a[i]);
            ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int n, count, a, b;
  count = 1;
  read n;
  vector<int> p(n);
  vector<int> q(n);
  vector<int> line(n);
  REP(i, n) { line[i] = i + 1; }
  REP(i, n) { read p[i]; }
  REP(i, n) { read q[i]; }
  do {
    REP(i, n) {
      if (line[i] == p[i]) {
        if (i == n - 1) {
          a = count;
        }
      } else {
        break;
      }
    }
    REP(i, n) {
      if (line[i] == q[i]) {
        if (i == n - 1) {
          b = count;
        }
      } else {
        break;
      }
    }
    count++;
  } while (next_permutation(line.begin(), line.end()));
  cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int
#define pb push_back
#define fi first 
#define se second 
#define mod 1000000007
/* Iterative Function to calculate (x^y) in O(log y) */
ll power(ll x, ll y) 
{ 
	int res = 1;	 // Initialize result 

	while (y > 0) 
	{ 
		// If y is odd, multiply x with result 
		if (y & 1) 
			res = res*x; 

		// y must be even now 
		y = y>>1; // y = y/2 
		x = x*x; // Change x to x^2 
	} 
	return res; 
}

int power(ll x, ll  y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
// vector<vector<ll>> v ;
// vector<ll> chld,bol,lst ;
// void dfs(ll a)
// {
//   lst.pb(a) ;
//   for(ll i=0;i<v[a].size();i++)
//   {
//     if(bol[v[a][i]]==0)
//     {
//       bol[v[a][i]]=1 ;
//       dfs(v[a][i]) ;
//     }
//   }
// }
// ll ch(ll a)
// {
//   ll p=0;
//   if(v[a].size()==0)
//   {
//     chld[a] =1 ;
//    return 1;
//   }
//   else
//   {
//     for(ll i=0;i<v[a].size();i++)
//     p += ch(v[a][i]) ;
//     p++ ;
//     chld[a] = p;
//     return p;
//   }
// }
int main()
{
  ll n ;
  cin >> n ;
  cout << n + n*n + (n*n)*n << endl;
}

Measured memory_bytes: 3604
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let A = read::<i32>();
    let B = read::<i32>();
    let C = read::<i32>();

    if A+B >= C {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define MAX 1000005


int main()
{
 //O_O ;
   ll n,k;
   cin>>n>>k;
   ll count=0;
   while(n){
        n=n/k;
       count++;
}
cout<<count<<nn;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

class Union_Find{
  private:
    vector<int> par;// parent
    vector<int> rank;// depth

  public:
    Union_Find(int N){
      par.resize(N);
      rank.resize(N);
      for(int i=0; i<N; ++i){
        par[i] = i;
        rank[i] = 0;
      }
      return;
    };

    ~Union_Find(void){
      return;
    };

    //search the root
    int find(int x){
      if(par[x] == x){
        return x;
      }else{
        return par[x] = find(par[x]);
      }
    };

    //merge the sets x or y belong
    void unite(int x, int y){
      x = find(x);
      y = find(y);
      if(x == y) return;

      if(rank[x] < rank[y]){
        par[x] = y;
      }else{
        par[y] = x;
        if(rank[x] == rank[y]){
          rank[x]++;
        }
      }
      return;
    };

    //judge x and y belong the same set or not
    bool same(int x, int y){
      return find(x) == find(y);
    };
};

int main(){
  ll N, M;
  cin >> N >> M;
  vector<ll> p(N);
  rep(i, 0, N){
    cin >> p[i];
    p[i]--;
  }

  vector<ll> x(M), y(M);
  rep(i, 0, M){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }

  Union_Find que(N);
  rep(i, 0, M){
    que.unite(p[x[i]], p[y[i]]);
  }

  ll count = 0;
  rep(i, 0, N){
    if(que.same(i, p[i])){
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#define N 26
#define OOMOJI 65 // to 90
#define KOMOJI 97 // to 122

int main(void){
  int i;
  int c;
  int a[N] = {0};

  while((c=getchar()) != EOF){

    if((c>=65 && c<=90) == 1){
    a[c-OOMOJI]++;
    }else if((c>=97 && c<=122) == 1){
    a[c-KOMOJI]++;
    }
  }

  for(i=0;i<N;i++){
    printf("%c : %d\n",i+KOMOJI, a[i]);
  }

  return 0;

}

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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
ll gcd(ll v,ll b){
	if(v>b) return gcd(b,v);
	if(v==b) return b;
	if(b%v==0) return v;
	return gcd(v,b%v);
}
int main(){
    int t;
    cin >> t;
    rep(zz,t){
        ll a,b,c,d;
        cin >> a >> b >> c>> d;
        bool flag = 0;
        if(b>d)flag = 1;
        if(a<b)flag = 1;
        ll x = gcd(b,d);
        if(a<c+1){
            if(b>=d){
                if(flag){
                    cout << "No" << endl;
                }else{
                    cout << "Yes" << endl;
                }
                continue;
            }
            a += (d-b)*(1+(c-a)/(d-b));
        }
        ll y = (a-c-1);
        y %= x;
        if(c+1+y<b)flag = 1;
        if(flag){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n ;
  while(cin>>n,n){
    int ans = n;
    for(int i = 0 ; i*i*i <= n ; i ++){
      int  j = sqrt(n - i*i*i);
      if(n < i*i*i + j*j)
	continue;
      ans = min(ans,i+j+(n-i*i*i-j*j));
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  set <ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    s.insert(a);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main implements Runnable {

	long hash(int[] cs) {
		long ret = Long.MAX_VALUE;
		for (int i = 0; i < cs.length; ++i) {
			long hash = 0;
			for (int j = 0; j < cs.length; ++j) {
				hash = hash * 1000 + cs[(i + j) % cs.length];
			}
			ret = Math.min(ret, hash);
		}
		return ret;
	}

	long rot(int[] cs) {
		int cnt = 0;
		long originHash = hash(cs);
		for (int i = 0; i < cs.length; ++i) {
			long hash = 0;
			for (int j = 0; j < cs.length; ++j) {
				hash = hash * 1000 + cs[(i + j) % cs.length];
			}
			if (hash == originHash) {
				++cnt;
			}
		}
		return cnt;
	}

	void solver(int n, int[][] C) {
		HashMap<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; ++i) {
			if (map.containsKey(hash(C[i]))) {
				map.put(hash(C[i]), map.get(hash(C[i])) + 1);
			} else {
				map.put(hash(C[i]), 1);
			}
		}

		long ans = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (i == j)
					continue;
				loop: for (int rotation = 0; rotation < 4; ++rotation) {
					long sum = 1;
					HashMap<Long, Integer> pending = new HashMap<>();
					pending.put(hash(C[i]), 1);
					pending.put(hash(C[j]), hash(C[i]) == hash(C[j]) ? 2 : 1);

					for (int k = 0; k < 4; ++k) {
						int[] nc = { C[j][(-k + 1 + rotation + 4) % 4], C[j][(-k + rotation + 4) % 4],
								C[i][(k + 1) % 4], C[i][k] };
						if (!map.containsKey(hash(nc))) {
							continue loop;
						}
						if (pending.containsKey(hash(nc)) && map.get(hash(nc)) == pending.get(hash(nc)))
							continue loop;
						sum *= (map.get(hash(nc)) - (!pending.containsKey(hash(nc)) ? 0 : pending.get(hash(nc))))
								* rot(nc);
						if (pending.containsKey(hash(nc))) {
							pending.put(hash(nc), pending.get(hash(nc)) + 1);
						} else {
							pending.put(hash(nc), 1);
						}
					}
					ans += sum;
				}
			}
		}
		System.out.println(ans / 6);
	}

	void start() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] C = new int[n][4];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 4; ++j) {
				C[i][j] = sc.nextInt();
			}
		}
		solver(n, C);
	}

	public void run() {
		start();
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 206692
n,a,b,c,d = (int(i) for i in input().split())  
s = input()
e = 0
if c<d:
  if s[a:c-1].count("##")==0 and s[b:d-1].count("##")==0:
    print("Yes")
  else:
    print("No")
else:
  if s[a:c-1].count("##")==0 and s[b:d-1].count("##")==0:
    for i in range(b-1,d):
      if s[i-1:i+2]=="..." :
        e = 1 
    if e == 1:
      print("Yes")
    else:
      print("No")
  else:
    print("No")



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

const int MAXF = 1e5 + 5;

ll f[MAXF], f_inv[MAXF];

ll pow_mod(ll a, ll st) {
	ll ans = 1ll;
	for(; st; st >>= 1ll) {
		if (st & 1) {
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
	}
	return ans;
}

ll get_inv(ll v) {
	return pow_mod(v, MOD - 2);
}

void gen_f() {
	f[0] = 1;
	REP(i, 1, MAXF) {
		f[i] = (f[i - 1] * i) % MOD;
	}
	f_inv[MAXF - 1] = get_inv(f[MAXF - 1]);
	for(int i = MAXF - 2; i >= 0; i--) {
		f_inv[i] = (f_inv[i + 1] * (i + 1)) % MOD;
	}
}

ll get_c(int i, int j) {
	if (j > i || j < 0) {
		return 0ll;
	}
	return (((f[i] * f_inv[j]) % MOD) * f_inv[i - j]) % MOD;
}

int ind[MAXN];
int ind1, ind2;


void solve(){
	gen_f();
	int n;
	scanf("%d", &n);
	REPN(i, 1, n + 1) {
		int a;
		scanf("%d", &a);
		if (ind[a]) {
			ind1 = ind[a];
			ind2 = i;
		}
		ind[a] = i;
	}
	REPN(k, 1, n + 1) {
		ll v0 = get_c(n - 1, k);
		ll v2 = get_c(n - 1, k - 2);
		ll v11 = get_c(n - 1, k - 1);
		ll v12 = get_c(ind1 - 1 + n + 1 - ind2, k - 1);
		ll v1 = (MOD + v11 + v11 - v12) % MOD;
		ll ans = (v0 + v1 + v2) % MOD;
		printf("%lld\n", ans);
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
 
int main(){
  int N,K;
  int min = 1;
  cin >> N >> K;
  
  rep(i,N){
    if(min < K)
      min *= 2;
      
    else
      min += K;
    }
  cout << min << endl;
  }

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 3e5 + 10;

int N, A, B, Nr[MAX_N];
int main() {
	cin >> N >> A >> B;
	if(N > 1ll * A * B || N < A + B - 1) return puts("-1") < 0;
	int rest = N;
	Nr[0] = A, rest -= A;
	for(int i=1; i<B; i++) Nr[i] = 1, rest -= 1;
	for(int i=1; i<B; i++) {
		int v = min(rest, A-1);
		Nr[i] += v, rest -= v;
	}
	rest = N;
	for(int i=0; i<B; i++) {
		for(int ix=rest-Nr[i]; ix<rest; ix++) printf("%d ", ix+1);
		rest -= Nr[i];
	}
	puts("");
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define LL long long
#define mp make_pair
#define next tipa_next
#define hash tipa_hash
#define ll long long
const int INF = 1000LL*1000*1000;
const int base = 1000 * 1000 * 1000;
LL n , sum;
LL a[200005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i] % 2)
        {
            cout << "first";
            return 0;
        }
    }
    cout << "second";
    
}

Measured memory_bytes: 1024
N=int(input())
from collections import Counter
A=[]
for i in range(N):
  s=input()
  A.append(s)
a=Counter(A).most_common()
b=a[0][1]
ans=[]
for i in range(len(a)):
  if a[i][1]==b:
    ans.append(a[i][0])
ans.sort()
for i in ans:
  print(i)

Measured memory_bytes: 45044
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  long double r; cin >> r;
  long double pi = 3.1415926535;
  long double ans = 2*pi*r;
  cout << fixed << setprecision(12) << ans << '\n';

  

  return 0;
}

Measured memory_bytes: 3808
# include <stdio.h>
# include <string.h>
# include <iostream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int M = 2e5 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;

int n, D, A[M];

struct pa {
  ll w;
  int id;
  pa() {}
  pa(ll w, int id) : w(w), id(id) {}
  friend pa operator + (const pa &a, const pa &b) {
    if(a.w < b.w) return a;
    else return b;
  }
};

struct SMT {
  # define ls (x << 1)
  # define rs (x << 1 | 1)
  pa w[2][M << 2];
  
  void build(int x, int l, int r) {
    w[0][x] = w[1][x] = pa(inf, l);
    if(l == r) return ;
    int mid = l + r >> 1;
    build(ls, l, mid);
    build(rs, mid+1, r);
  }
  
  void modify(int x, int l, int r, int pos, ll _w, int op) {
    if(l == r) {
      w[op][x].w = _w;
      return ;
    }
    int mid = l + r >> 1;
    if(pos <= mid) modify(ls, l, mid, pos, _w, op);
    else modify(rs, mid+1, r, pos, _w, op);
    w[op][x] = w[op][ls] + w[op][rs]; 
  }
  
  # undef ls
  # undef rs 
} tag, untag;

struct SMT2 {
  # define ls (x << 1)
  # define rs (x << 1 | 1)
  pa w[M << 2];
  
  void build(int x, int l, int r) {
    w[x] = pa(inf, l);
    if(l == r) return ;
    int mid = l + r >> 1;
    build(ls, l, mid);
    build(rs, mid+1, r);
  }
  
  void update(int x, int l, int r, int pos) {
    if (l == r) return ;
    int mid = l + r >> 1;
    if(pos <= mid) update(ls, l, mid, pos);
    else update(rs, mid+1, r, pos);
    // edge only in ls || only in rs.
    w[x] = w[ls] + w[rs];
    // edge across ls & rs
    // tag.ls with untag.rs
    w[x] = w[x] + pa(tag.w[0][ls].w + untag.w[1][rs].w, untag.w[1][rs].id);
    // untag.ls with tag.rs
    w[x] = w[x] + pa(untag.w[0][ls].w + tag.w[1][rs].w, untag.w[0][ls].id); 
  }
  # undef ls
  # undef rs
}edge;

int main() {
  std :: ios :: sync_with_stdio(false);
  std :: cin.tie(0);
  std :: cout.tie(0);
  cin >> n >> D;
  for (int i = 1; i <= n; ++ i) cin >> A[i];
  tag.build(1, 1, n);
  untag.build(1, 1, n);
  tag.modify(1, 1, n, 1, -1ll * D + A[1], 0);
  tag.modify(1, 1, n, 1, 1ll * D + A[1], 1);
  for (int i = 2; i <= n; ++ i) {
    untag.modify(1, 1, n, i, -1ll * D * i + A[i], 0);
    untag.modify(1, 1, n, i, 1ll * D * i + A[i], 1);
  }
  edge.build(1, 1, n);
  edge.update(1, 1, n, 1);
  
  ll ans = 0; 
  for (int i = 1; i < n; ++ i) {
    ans += edge.w[1].w;
    int p = edge.w[1].id;
    untag.modify(1, 1, n, p, inf, 0);
    untag.modify(1, 1, n, p, inf, 1);
    tag.modify(1, 1, n, p, -1ll * D * p + A[p], 0);
    tag.modify(1, 1, n, p, 1ll * D * p + A[p], 1);
    edge.update(1, 1, n, p);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 52224
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>

int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	if (K == 1) {
		printf("0");
	}
	else {
		printf("%d", N - K);
	}

	return 0;
}

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

namespace AtCoder.ABC069
{
    class Program
    {
        static void Main()
        {
            string[] inputs = Console.ReadLine().Split(' ');
            int n = int.Parse(inputs[0]) - 1;
            int m = int.Parse(inputs[1]) - 1;
            Console.WriteLine(n * m);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
using namespace std;





int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
       ll x,k;
       cin>>k>>x;
       if(k*500>=x) cout<<"Yes";
       else cout<<"No";
        
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    
    
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        long sum = 0;
        for(int i = 0 ; i < arr.length ; i++){
            arr[i] = sc.nextInt();
            sum += arr[i];
        }
        int max = arr[0];
        int min = arr[0];
        for(int i = 0 ; i < arr.length ; i++){
            if(arr[i] > max)    max = arr[i];
            if(arr[i] < min)    min = arr[i];
        }
        System.out.println(min+" "+max+" "+sum);
        
        
    }
}


Measured memory_bytes: 41904
import java.util.Scanner;

public class Main {

    int N;
    int x = 1, ans = 0;
    boolean[][] rinsetsu;
    boolean[] already;

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        rinsetsu = new boolean[N][N];
        already = new boolean[N];
        already[0] = true;
        int M = sc.nextInt();
        for (int i = 0; i < M; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            rinsetsu[a][b] = true;
            rinsetsu[b][a] = true;
        }
        bfs(0);
        System.out.println(ans);
    }

    void bfs(int parent) {
        if (x == N) {
            ans++;
            return;
        }
        x++;
        for (int i = 0; i < N; i++) {
            if (!already[i] && rinsetsu[parent][i]) {
                already[i] = true;
                bfs(i);
                already[i] = false;
            }
        }
        x--;
    }
}


Measured memory_bytes: 23892
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  startupcpp();
  ll N,o,e;
  cin>>N;
  o=(N+1)/2;
  e=N/2;
  cout<<o*e<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = sum(b)
for i in range(1, n):
    if a[i] - a[i-1] == 1:
        ans += c[a[i-1]-1]
print(ans)

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

typedef unsigned long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+5, mod = 1e9+7;

void solve() {
    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            ++ans;
        }
    }

    int t = 0;
    for (int i = 0; i < ans; ++i) {
        if (s[i] == 'R') {
            ++t;
        }
    }
    
    cout << ans - t << endl;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; 
    while (t--) solve();
    return 0;
}


Measured memory_bytes: 3760
input()
aa = list(map(int, input().split()))
state = {(0,False)}
skipmax = len(aa)%2 + 1
state_all = {(i, True) for i in range(skipmax+1)}.union({(j, False) for j in range(skipmax+1)})
dp_0 = {a:None for a in state_all }
dp_0[(0,False)] = 0
skipcount = 0

def getmax(a, b):
    if a is None:
        return b
    if b is None:
        return a
    return max(a,b)

for i,a in enumerate(aa):
    dp_1 = {}
    for s in state_all:
        if s[1] & (dp_0[(s[0], False)] is not None):
            dp_1[s] = dp_0[(s[0], False)] + a
            continue
        dp_1[s] = getmax(dp_0[(s[0], True)], dp_0.get((s[0]-1, False), None))
    dp_0 = dp_1.copy()
if len(aa)%2:
    print(getmax(dp_0[(2,True)], dp_0[(1,False)]))
else:
    print(getmax(dp_0[(1,True)], dp_0[(0,False)]))


Measured memory_bytes: 33088
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

void no() {
  cout << "Impossible" << endl;
  exit(0);
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll h, w;
  cin >> h >> w;
  vector<string> mp(h);
  rep(i, h) cin >> mp[i];

  ll cnt = 0;
  rep(i, h) rep(j, w) if (mp[i][j] == '#') cnt++;

  if (cnt == h + w - 1)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
  return 0;
}


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

typedef struct WeightedUnionFind{
  int *parent;
  int *distance;
  int n;
} UnionFind;

UnionFind* newUnionFind(int n){
  UnionFind *u=(UnionFind *)calloc(1,sizeof(UnionFind));
  u->parent=(int *)calloc(2*n,sizeof(int));
  u->distance=u->parent+n;
  u->n=n;
  int i;
  for(i=0;i<n;i++){
    u->parent[i]=i;
    u->distance[i]=0;
  }
  return u;
}

int root(UnionFind *u,int x){
  if(u->parent[x]==x) return x;
  int p=u->parent[x];
  u->parent[x]=root(u,u->parent[x]);
  u->distance[x]+=u->distance[p];
  return u->parent[x];
}

int same(UnionFind *u,int x,int y){
  return root(u,x)==root(u,y);
}

int weight(UnionFind *u,int x){
  root(u,x);
  return u->distance[x];
}

int diff(UnionFind *u,int x,int y){
  return weight(u,y)-weight(u,x);
}

void unite(UnionFind *u,int x,int y,int w){
  w+=weight(u,x);
  w-=weight(u,y);
  x=root(u,x);
  y=root(u,y);
  if(x==y) return;
  u->parent[y]=x;
  u->distance[y]+=w;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  UnionFind *u=newUnionFind(n+1);
  while(m--){
    int l,r,d;
    scanf("%d%d%d",&l,&r,&d);
    if(!same(u,l,r)){
      unite(u,l,r,d);
    } else if(diff(u,l,r)!=d){
      puts("No");
      return;
    }
  }
  puts("Yes");
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 1024
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
using namespace std;

int main() {
  string s;
  cin >> s;
  const auto size = s.size();
  vector<int> changed = {0, 0};
  REP(i, size)
  (s[i] != (i % 2 == 0 ? '0' : '1') ? changed[0] : changed[1]) += 1;

  cout << min(changed[0], changed[1]) << endl;
  return 0;
}


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

char getgrade(int m, int f, int r) {
  int sum = m + f;
  char grade;
  if (m == -1 || f == -1) {
    grade = 'F';
  } else if ( sum >= 80) {
    grade = 'A';
  } else if (65 <= sum && sum < 80) {
    grade = 'B';
  } else if (50 <= sum && sum < 65) {
    grade = 'C';
  } else if (30 <= sum && sum < 50) {
    grade = 'D';
    if(r >= 50) grade = 'C';
  } else if ( sum < 30) {
    grade = 'F';
  }

return grade;

}

int main(){
  int m, f, r;
  while(1){
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;

    cout << getgrade(m, f, r) << endl;
  }

return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long

using namespace std;
const int N=3e5+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int n,a[N],bt[N],b[N],c1[N],c2[N];
void add(int x,int y){while(x<=n) bt[x]+=y,x+=x&(-x);}
int gsm(int x){int an=0;while(x) an+=bt[x],x-=x&(-x);return an;}
void wa(){puts("No");exit(0);}
void ac(){puts("Yes");}

int main()
{
    n=rd();
    for(int i=1;i<=n;++i) a[i]=rd();
    for(int i=1;i<=n;++i)
	if((a[i]^i)&1) wa();
    for(int o=0;o<=1;++o)
    {
	memset(bt,0,sizeof(bt));
	for(int i=1+((o^1)&1);i<=n;i+=2)
	{
	    b[i]+=(bool)(gsm(n)-gsm(a[i]));
	    add(a[i],1);
	}
	memset(bt,0,sizeof(bt));
	for(int i=n-((o^n)&1);i>=1;i-=2)
	{
	    b[i]+=(bool)gsm(a[i]);
	    add(a[i],1);
	    if(b[i]==2) wa();
	}
    }
    for(int i=1;i<=n;i+=2)
	if(i<a[i]) ++c1[i],--c1[a[i]+1];
    for(int i=2;i<=n;i+=2)
	if(i<a[i]) ++c2[i],--c2[a[i]+1];
    for(int i=1;i<=n;++i)
    {
	c1[i]+=c1[i-1],c2[i]+=c2[i-1];
	if(c1[i]&&c2[i]) wa();
    }
    ac();
    return 0;
}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb puah_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n; cin >> n;
    vector<ll> clis(n), slis(n), flis(n);
    REP(i, 0, n-1){cin >> clis[i] >> slis[i] >> flis[i];}
    REP(i, 0, n){
        int k = i;
        ll time = 0;
        while(k != n-1){
            ll c = max((ll)ceil((double)(time - slis[k]) / flis[k]), 0LL);
            //cout << "time" <<time << "c"<< c  << endl; 
            time = slis[k] + (flis[k] * c) + clis[k];
            k++; 
        }
        cout << time << endl;
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;

fn main(){
    let s:String = read();
    let ans = match &s[..] {
        "SUN" => 7,
        "MON" => 6,
        "TUE" => 5,
        "WED" => 4,
        "THU" => 3,
        "FRI" => 2,
        "SAT" => 1,
        _ => 0,
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352