akhauriyash/Code-Regression huggingface dataset:
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
a=[[False]*3 for i in range(3)]
for i in range(3):
    for j in range(3):
        for b in B:
            if A[i][j]==b:
                a[i][j]=True
bingo=False
for i in range(3):
    if a[i][0] and a[i][1] and a[i][2]:
        bingo=True
for j in range(3):
    if a[0][j] and a[1][j] and a[2][j]:
        bingo=True
if a[0][0] and a[1][1] and a[2][2]:
    bingo=True
if a[2][0] and a[1][1] and a[2][0]:
    bingo=True
print("Yes" if bingo else "No")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main {

	private static final int BIG_NUM  = 2000000000;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long sum = 0;
		int minimum = BIG_NUM,maximum = -BIG_NUM;

		try {

			int N = Integer.parseInt(br.readLine());

			String first[] = br.readLine().split("[\\s]+");
			int array[] = new int[first.length];

			for(int i = 0; i < first.length; i++){

				array[i] = Integer.parseInt(first[i]);
				minimum = Math.min(minimum, array[i]);
				maximum = Math.max(maximum, array[i]);
				sum += array[i];
			}

			System.out.printf("%d %d %d\n",minimum,maximum,sum);

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}





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

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

Measured memory_bytes: 3580
import sys

N, Q = map(int, sys.stdin.readline().split())

s = sys.stdin.readline()

Query = [sys.stdin.readline().split() for i in range(Q)]

left, right = 0, N - 1

for t, d in reversed(Query):
    if d == "L":
        if t == s[left]:
            left += 1
        if right < N - 1 and t == s[right + 1]:
            right = min(right + 1, N - 1)
    else:
        if left > 0 and t == s[left - 1]:
            left = max(left - 1, 0)
        if t == s[right]:
            right -= 1
print(max(right - left + 1, 0))


Measured memory_bytes: 39348
# include<stdio.h>
int n,kk,a[20];
long long ans=10000000000007;
void solve(int k,long long sum,int i,int cut)
{
	if(cut==kk)
	{
		if(ans>sum)
		ans=sum;
	}
	if(k==n)
	return; 
	if(a[k]<=i)
	{
		solve(k+1,sum+(i-a[k]+1),i+1,cut+1);
		solve(k+1,sum,i,cut);
	}
	else
	{
		solve(k+1,sum,a[k],cut+1);
	} 
	
 } 
int main () 
{
	scanf("%d %d",&n,&kk);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	solve(1,0,a[0],1);
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=100100;
const int INF=1e9+9;
int n,m;
int beg[maxn],tto[maxn<<1],nex[maxn<<1],w[maxn<<1],e;
void putin(int s,int t,int v){
	tto[++e]=t;
	nex[e]=beg[s];
	beg[s]=e;
	w[e]=v;
}
struct node{
	int k;
	long long b;
}dp[maxn];
void chkmax(long long &x,long long y){
	x=x>y?x:y;
}
void chkmin(long long &x,long long y){
	x=x<y?x:y;
}
long long l=0,r=INF;
bool vis[maxn];
void dfs(int u,const node &st){
	if(vis[u]){
		if(st.k==dp[u].k){
			if(st.b==dp[u].b) return;
			printf("0\n");
			exit(0);
		}
		if((st.b-dp[u].b)%2!=0){
			printf("0\n");
			exit(0);
		}
		long long x=(st.b-dp[u].b)/(dp[u].k-st.k);
		if(x<=0){
			printf("0\n");
			exit(0);
		}
		if(!(l<x&&x<r)){
			printf("0\n");
			exit(0);
		}
		l=x-1,r=x+1;
		return;
	}
	vis[u]=1;
	dp[u]=st;
	if(st.k==1) chkmax(l,-st.b);
	else chkmin(r,st.b);
	if(r<=l+1){
		printf("0\n");
		exit(0);
	}
	for(int i=beg[u];i;i=nex[i])
		dfs(tto[i],(node){-st.k,w[i]-st.b});
}
int main(){
//	freopen("A.in","r",stdin);
	scanf("%d%d",&n,&m);
	int s,t,v;
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&s,&t,&v);
		putin(s,t,v);
		putin(t,s,v);
	}
	dfs(1,(node){1,0});
	printf("%lld\n",r-l-1);
	return 0;
}


Measured memory_bytes: 9344
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <tuple>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<tuple<string, int , int>> a;

	for (int i = 1; i <= N; ++i) {
		string s;
		int p;

		cin >> s >> p;

		p = -p;

		a.push_back(tie(s, p, i));
	}

	sort(a.begin(), a.end());

	for (int i = 0; i < N; i++) {
		cout << get<2>(a[i]) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int a[N]={};
    int A=0;
    int counter=0;
   for(int i=0;i<N;i++){
   cin>>a[i];}
   for(int j=0;j<N;j++){
   counter+=(1-a[j])*(1-a[j]);}
   for(int i=1;i<=100;i++){
   for(int j=0;j<N;j++){
   A+=(i-a[j])*(i-a[j]);}
   counter=min(counter,A);
   A=0;}
   cout<<counter<<endl;}
   


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

int main(){
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];
	int dp[n];
	memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	for(int j=1;j<n;j++){
		dp[j]=INT_MAX;
		for(int K=1;K<=k;K++){
			if(K<=j) {
				long x = fabs(arr[j]-arr[j-K]) + dp[j - K];
				if(dp[j]>x) dp[j] = x;
			}
		}
	}
	cout<<dp[n-1]<<"\n";
}


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

void Main()
{
  int n,q; cin >> n;
  vector<int> S(n);
  for(int i = 0; i < n; i++) cin >> S[i];
  cin >> q;
  vector<int> T(q);
  int cnt = 0;
  for(int i = 0; i < q; i++) {
    cin >> T[i];
    if (binary_search(S.begin(), S.end(), T[i])) cnt++;
  }
  cout << cnt << endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}



Measured memory_bytes: 3308
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());
		int l = Integer.parseInt(sc.next());

		int minAbs = 100;
		int sum = 0;

		for (int i = l; i < l + n; i++) {
			sum += i;
			if (Math.abs(i) < Math.abs(minAbs)) {
				minAbs = i;
			}
		}
		System.out.println(sum - minAbs);
	}
}

Measured memory_bytes: 23636
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

H1, M1, H2, M2, K = rl()

t1 = H1*60+M1
t2 = H2*60+M2

print(max(t2-t1-K, 0))


Measured memory_bytes: 61860
#include <iostream>
#include "cstdio"
#include "algorithm"
using namespace std;
const int maxn = 200005;
int n, tx[maxn];
int clk, cur;
int sum, u, t;
int main() 
{
	scanf("%d %d", &n, &t);
	clk = 0;cur = 0;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &tx[i]);
	}
	sort(tx+1, tx+1+n);
	long long ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ans += tx[i] + t - max(tx[i], cur);
		cur = tx[i] + t;
	}
	
	/*	if(u - cur > t || cur == 0)	clk = 0;
		else 						clk = 1;
		
		if(clk)	
			sum += u - cur;
		else
			sum += t;
		cur = u;
	*/
	cout << ans << endl;
	return 0;
	
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
using namespace std;

int parent[100010];
int p[100010];

int find(int a){
	if(parent[a]==a)return a;
	return parent[a]=find(parent[a]);
}

void unite(int a,int b){
	int p=find(a),q=find(b);
	parent[p]=q;
}

int main(){
	int n,m,a,b;
	cin>>n>>m;
	loop(i,1,n+1){
		cin>>p[i];
		parent[i]=i;
	}
	rep(i,m){
		cin>>a>>b;
		unite(a,b);
	}
	int ans=0;
	loop(i,1,n+1){
		if(find(i)==find(p[i]))ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        Read().ToList().ForEach(v => Console.WriteLine(v.Where(x => x <= v.Average()).Count()));
    }

    private static IEnumerable<List<int>> Read()
    {
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
            yield return Console.ReadLine().Split().Select(int.Parse).ToList();
    }
}


Measured memory_bytes: 21564
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;

int main(){
    long long H,X,sum;
    cin >> H;
    X=0;
    sum=0;
    while(H!=0){
        H=H/2;
        X=X+1;
    }
    for(double i=0;i<X;i++){
        sum=sum+pow(2,i);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
   

  int main(){      
   lint t=100;
   lint count=0;
   lint x;
   cin>>x;
   while(t<x){
       count++;
       t*=1.01;
   }
    cout<<count;
  }
          
  

Measured memory_bytes: 3684
S = input()
K = int(input())

ans = 0
len_S = len(S)
a = b = 0
c = 1
same_letter = True
for i in range(len_S - 1):
    if S[i] == S[i + 1]:
        c += 1
    else:
        same_letter = False
        ans += c // 2
        if i == c - 1:
            a = c
        c = 1
b = c
ans += c // 2
if same_letter:
    ans = len_S * K // 2
else:
    ans *= K
    if S[0] == S[-1] and K >= 2 and (a % 2) * (b % 2) == 1:
        ans += K - 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int func(int N){
    int cnt = 0;
    rep(i,1,N){
        int sum = 0;
        for(int j = i;sum < N;j++)sum += j;
        if(sum == N){
            cnt++;
        }
    }
    return cnt;
}
main(){
    int N;
    cin >> N;
    while(N){
        cout << func(N) << endl;
        cin >> N;
    }
}


Measured memory_bytes: 3076
gets
ar = gets.split.map(&:to_i)
co = 0
(ar.size - 2).downto(0) do |i|
  (i + 1).times do |j|
    if ar[j] > ar[j + 1]
      ar[j], ar[j + 1] = ar[j + 1], ar[j]
      co += 1
    end
  end
end
puts ar.join(" ")
puts co



Measured memory_bytes: 6872
n,l = map(int,input().split())
a = [i+l for i in range(n)] 

amax = max(a)
amin = min(a)

if a.count(0) == 0:
    if amax > 0:
        a.pop(0)
    else:
        a.pop()
        
print(sum(a))

Measured memory_bytes: 3060
# coding: utf-8
import math

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
P=callIsPrime(100010)

X=int(input())

for i in range(len(P)):
    if P[i]>=X:
        print(P[i])
        break


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

long N;
long C[200020];
long A[200020];
long X[200020];
int main(){
  cin >> N;
  for (int i=1;i<=N;i++)cin >> C[i];
  for (int i=0;i<200020;i++)X[i]=-1;
  A[0]=1;
  for (int i=1;i<=N;i++){
    if (X[C[i]]!=-1 && X[C[i]]!=i-1){A[i]=A[X[C[i]]]+A[i-1];}
    else {A[i]=A[i-1];}
    A[i]%=1000000007;
    X[C[i]]=i;
  }
  cout << A[N] << endl;
}


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


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

  int N;
  cin >> N;
  int M = N *100 / 108;
  if(M *108/100 == N){
    cout << M << endl;
  }
  else if((M+1) * 108 / 100 == N){
    cout << M+1 << endl;
  }
  else cout << ":(" << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    for( int i = 0; i < 4; ++i ) {
        int a, b;
        cin >> a >> b;
        if( a == 1 ) a = 6000;
        if( a == 2 ) a = 4000;
        if( a == 3 ) a = 3000;
        if( a == 4 ) a = 2000;
        cout << a * b << endl;
    }
    return 0;
}



Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {
	
	static boolean[] num=new boolean[1000000];
	
	static void prime(int n) {
		for(int i=2; i*n<1000000; i++) {
			num[n*i]=false;
		}
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				for(int i=2; i<1000000; i++) {
					num[i]=true;
				}
				for(int i=2; i<1000000; i++) {
					if(num[i]) {
						prime(i);
					}
				}
				int n=sc.nextInt();
				int count=0;
				for(int i=n; i>1; i--) {
					if(num[i]) {
						count++;
					}
				}
				System.out.println(count);
			}
			
		}
	}
}


Measured memory_bytes: 28140
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
cnt=0
enable=false
N.times do|i|
    d1,d2=get_i
    if d1==d2
      cnt+=1
      if cnt==3
          enable=true
          break
      end
    else
      cnt=0
    end
end
puts yn_judge(enable)

Measured memory_bytes: 14352
s = gets.chomp
a = s[0].to_i
b = s[1].to_i
c = s[2].to_i
d = s[3].to_i
ans = []
["-","+"].repeated_permutation(3).each do |x|
  sum = a
  sum += b if x[0] == "+"
  sum -= b if x[0] == "-"
  sum += c if x[1] == "+"
  sum -= c if x[1] == "-"
  sum += d if x[2] == "+"
  sum -= d if x[2] == "-"
  if sum == 7
    ans << x
  end
end
str = s[0] + ans[0][0] + s[1] + ans[0][1] + s[2] + ans[0][2] + s[3] + "=7"
puts str


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int N;
    cin>>N;
    vector<string> W(N);
    map<string,bool> check;
    vi len(N);
    rep(i,N){
        cin>>W[i];
        len[i]=W[i].length();
    }
    check[W[0]]=true;
    REP(i,1,N){
        if(W[i-1][len[i-1]-1]!=W[i][0]||check[W[i]]){
            cout<<"No"<<endl;
            return 0;
        }else{
            check[W[i]]=true;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	char S[100000];
	int i = 0, C0 = 0, C1 = 0, an = 0;
	scanf("%s", S);
	while (S[i] != '\0') {
		if (S[i] == '0') {
			C0++;
		}
		else if(S[i]=='1'){
			C1++;
		}
		i++;
	}
	printf("%d", min(C0, C1) * 2);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll N, A[21], B[21], C[21], ans=0;
    scanf("%lld", &N);
    rep(i, 1, N+1) scanf("%lld", A+i);
    rep(i, 1, N+1) scanf("%lld", B+i);
    rep(i, 1, N) scanf("%lld", C+i);
    rep(i, 1, N+1){
        ans += B[A[i]];
        if(i>1){
            if(A[i]-A[i-1]==1) ans += C[A[i-1]];
        }
    }
    printf("%lld\n", ans);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


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

#define MAX_N   (100000)

int N;
long long A[MAX_N];
long long B[MAX_N];
long long sabun[MAX_N];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /* Sの取得 */
    cin >> N;
    
    /* A, Bの取得 */
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    
    /* A < Bとなるものを数える */
    int result = 0;
    long long num = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] < B[i]) {
            result++;
            num += B[i] - A[i];
            sabun[i] = 0;
        } else {
            sabun[i] = A[i] - B[i];
        }
    }
    if (result != 0) {
        sort(sabun, sabun + N);
        for (int i = N - 1; i >= 0; i--) {
            result++;
            if (num - sabun[i] <= 0) {
                break;
            } else {
                num -= sabun[i];
            }
            if (i == 0) {
                result = -1;
            }
        }
    }
        
    /* 結果の出力 */
    cout << result << endl;
    
    return 0;
}



Measured memory_bytes: 2560
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] x = new int[m];
    for(int i = 0; i < m; i++) {
      x[i] = sc.nextInt();
    }
    Arrays.sort(x);
    int[] b = new int[m - 1];
    for(int i = 1; i < m; i++) {
      b[i - 1] = x[i] - x[i - 1];
    }
    Arrays.sort(b);
    int ans = x[m - 1] - x[0];
    int sum = 0;
    if(n < m) {
      for(int i = m - 2; i >= (m - n); i--) {
        sum += b[i];
      }
    }
    ans -= sum;
    if(n >= m) ans = 0;
    System.out.println(ans);
  }
}

Measured memory_bytes: 60392
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    int N; cin>>N;

    map<ll,ll> L;
    map<ll,ll> R;

    for (ll i = 1; i <= N; ++i) {
        ll A; cin>>A;
        L[i + A]++;
        R[i - A]++;
    }
    ll sum=0;

    for(auto it1:L){
        sum += it1.second * R[it1.first];
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 37708
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<ll, ll>P;
typedef vector<int>vec;
ll mod = pow(10, 9) + 7;

int main() {
	char t[4];
	int s[4];
	cin>>t;
	for(int i=0;i<4;i++){
		s[i]=t[i]-'0';
	}
	int n=s[0]*10+s[1];
	int m=s[2]*10+s[3];
	if(1<=n&&n<=12){
		if(1<=m&&m<=12){
			cout<<"AMBIGUOUS"<<endl;
		}
		else{
			cout<<"MMYY"<<endl;
		}
	}
	else{
		if(1<=m&&m<=12){
			cout<<"YYMM"<<endl;
		}
		else{
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<long long>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define vs vector<string>
#define mx INT_MAX
#define mn INT_MIN
#define all(z) z.begin(),z.end()
#define mcc 1000000007
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
using namespace std;

//ll maxl(ll a,ll b) {return (a>b)? a:b;}
//ll minl(ll a,ll b) {return (a<b)? a:b;}
//ll gcdl(ll a,ll b) {return b ? gcdl(b,a%b):a;}


void solve()
{
    int n,m,sum=0,ct=0; double bdry;
    cin>>n>>m;
    vi v(n);
    for (int i=0;i<n;i++)
    {
        cin>>v[i];
        sum+=v[i];
    }
    bdry=(double)sum/(4*m);
    //cout<<sum<<' '<<bdry<<endl;
    for (auto &a: v)
    {
        if (a>=bdry) ct++;
    }
    if (ct>=m) cout<<"Yes";
    else cout<<"No";
}


#if 1
int main()
{
    #ifdef __WIN32
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
#endif

//------------------------Google-------------------
#if 0
int main()
{
    #ifdef __WIN32
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,ct=0;
    cin>>t;
    while(t--)
    {
        cout<<"Case #"<<++ct<<": ";
        solve();
    }
    return 0;
}
#endif


Measured memory_bytes: 256
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

int read_problem()
{
    int n;
    scanf("%d\n", &n);
    return n;
}

#if 0
constexpr int SQRTN_MAX = 31622; // sqrt(1e9) = 31622.77...

array<bool, SQRTN_MAX+1> is_prime;

void init_prime_table()
{
    fill(is_prime.begin(), is_prime.end(), true);
    is_prime[0] = is_prime[1] = false;

    for(int i = 2; i <= SQRTN_MAX; ++i) {
        if(!is_prime[i]) continue;

        for(int j = 2*i; j <= SQRTN_MAX; j += i) {
            is_prime[j] = false;
        }
    }
}
#endif

void factor_one(int& n, int k, vector<int>& facs)
{
    while(n % k == 0) {
        facs.push_back(k);
        n /= k;
    }
}

vector<int> factor(int n)
{
    vector<int> result;

    int sqrtn = static_cast<int>(sqrt(n));
    for(int i = 2; i <= sqrtn; ++i) {
        factor_one(n, i, result);
    }
    if(n != 1)
        result.push_back(n);

    return result;
}

vector<int> factor2(int n)
{
    vector<int> result;

    // 2?????????3??§?????????????????????
    factor_one(n, 2, result);
    factor_one(n, 3, result);

    // 2?????????3????????°?????????????????¨ 6n?±1???????????§??????????????°??????
    int sqrtn = static_cast<int>(sqrt(n));
    for(int i = 6; i-1 <= sqrtn; i += 6) {
        factor_one(n, i-1, result);
        factor_one(n, i+1, result);
    }
    if(n != 1)
        result.push_back(n);

    return result;
}

int main()
{
    int n = read_problem();

    vector<int> facs = factor2(n);
    printf("%d:", n);
    for(int p : facs) {
        printf(" %d", p);
    }
    puts("");

    return 0;
}

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

using namespace std;

int main(){
    int n,k,x,y,s,c,s1,s2;
    cin>>n>>k>>x>>y;
    if(n>=k){s=n-k;c=k;}
    else if(n<k){c=n;s=0;}
    s1=x*c;
    s2=y*s;
    cout<<s1+s2;

    return 0;
}


Measured memory_bytes: 256
import collections

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr) #小さい順にソートしておく
s=set()
cnt=collections.Counter(arr) #各要素の個数を事前に数えておく
for i in range(n):
 if arr[i] in s: #Aiがすでに列挙した数に含まれていれば処理を行わない
   continue
 if cnt[arr[i]]>=2: #Aiが2個以上含まれているとき、Ai自身を列挙した数に加える
   s.add(arr[i])
 for j in range(2,10**6//arr[i]+1): #Ai自身を除くAiの倍数を列挙する
   s.add(arr[i]*j)
ans=0
for i in range(n): #列挙した数に含まれないAiの個数を数える
 if arr[i] in s:
   continue
 ans+=1
print(ans)

Measured memory_bytes: 103016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main() {
  ll n;
  cin >> n;
  ll sum = 1;
  for (ll i = 1; i <= n; i++) {
    sum *= i;
    sum %= mod;
  }
  cout << sum << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/

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

int main(){
 int c1 , c2 , c3;
 c1 = c2 = 0;
 for(int i = 0 ; i < 3; i++){
  cin>>c3;
  if(c3 == 7){
   c2++;
  }else if(c3 == 5){
   c1++;
  }
 }

 if(c1 == 2 && c2 == 1){
  cout<<"YES"<<endl;
 }else{
  cout<<"NO"<<endl;
 }
 return 0;
}


Measured memory_bytes: 256
from sys import stdin
N, Y = map(int, stdin.readline().rstrip().split())
for i in  range(N+1):
    for j in range(N+1-i):
        if 1000 * i + 5000 * j + 10000 * (N - i - j) == Y:
            print(N-i-j, j ,i)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 2940
n = int(input())

s = []
t = []

for i in range(n):
    a,b = input().split()
    s.append(a)
    t.append(int(b))

x = input()

flag = False
ans = 0

for i in range(n):
    if flag == True:
        ans += t[i]
    if s[i] == x:
        flag = True

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS

int main(int argc, char const *argv[]){
	char c1[3],c2[3];
	scanf("%s %s",c1,c2);
	if(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char c[3][4];

    for(int i = 0; i < 3; i++){
        scanf("%s", c[i]);
    }

    printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);

    return 0;
}

Measured memory_bytes: 1652
#include <stdio.h>

int main(void)
{
  int h, w;
  scanf("%d%d", &h, &w);
  int grid[h][w];

  for (int y = 0; y < h; y++) {
    char s[w + 1];
    scanf("%s", s);
    for (int x = 0; x < w; x++) {
      grid[y][x] = s[x] == '#' ? 0 : 10000;
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 1; x < w; x++) {
      if (grid[y][x] > grid[y][x - 1] + 1) {
        grid[y][x] = grid[y][x - 1] + 1;
      }
      int xx = w - 1 - x;
      if (grid[y][xx] > grid[y][xx + 1] + 1) {
        grid[y][xx] = grid[y][xx + 1] + 1;
      }
    }
  }

  for (int x = 0; x < w; x++) {
    for (int y = 1; y < h; y++) {
      if (grid[y][x] > grid[y - 1][x] + 1) {
        grid[y][x] = grid[y - 1][x] + 1;
      }
      int yy = h - 1 - y;
      if (grid[yy][x] > grid[yy + 1][x] + 1) {
        grid[yy][x] = grid[yy + 1][x] + 1;
      }
    }
  }

  int ans = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (ans < grid[y][x]) {
        ans = grid[y][x];
      }
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < n; i++)
ull A = 9999973;
ull B = 950527;

int H, W, R, C;
string txt[1005];
string pat[1005];
ull t[1005][1005];
ull t2[1005][1005];

int main()
{
    cin >> H >> W;
    rep(i, H)
    {
        cin >> txt[i];
    }
    cin >> R >> C;
    rep(i, R)
    {
        cin >> pat[i];
    }

    ull target = 0;
    rep(i, R)
    {
        ull key = 0;
        rep(j, C)
        {
            key = key * B + pat[i][j];
        }
        target = target * A + key;
    }

    ull c = 1;
    rep(i, C) c *= B;

    rep(i, H)
    {
        ull key = 0;
        rep(j, W)
        {
            key = key * B + txt[i][j];
            if (j - C >= 0)
                key -= txt[i][j - C] * c;
            t[i][j] = key;
            t2[i][j] = t[i][j];
        }
    }

    c = 1;
    rep(i, R) c *= A;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (i) {
                t[i][j] += t[i - 1][j] * A;
            }
            if (i - R >= 0) {
                t[i][j] -= t2[i - R][j] * c;
            }
            if (t[i][j] == target) {
                if (i - R + 1 >= 0 && j - C + 1 >= 0)
                    printf("%d %d\n", i - R + 1, j - C + 1);
            }
        }
    }

    return 0;
}



Measured memory_bytes: 20844
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
const int MX = 220000;
int n;
char s[MX];
int cc[MX];
int p[MX];
int p2[MX];
int c[MX];
int c2[MX];
int en[MX];
int ans[MX];
int nm(int a, int b) {
	if (a < 0)
		return a + b;
	if (a >= b)
		return a - b;
	return a;
}

void sa() {
	n += 1;
	for (int i = 0; i < n; ++i)
		c[i] = s[i];
	for (int i = 0; i < n; ++i)
		++cc[c[i] + 1];
	for (int i = 1; i < MX; ++i)
		cc[i] += cc[i - 1];
	for (int i = 0; i < n; ++i)
		p[cc[c[i]]++] = i;
	for (int k = 0; (1 << k) < n; ++k) {
		for (int i = 0; i < n; ++i)
			p[i] = nm(p[i] - (1 << k), n);
		memset(cc, 0, sizeof(cc));
		for (int i = 0; i < n; ++i)
			++cc[c[i] + 1];
		for (int i = 1; i < MX; ++i)
			cc[i] += cc[i - 1];
		for (int i = 0; i < n; ++i)
			p2[cc[c[p[i]]]++] = p[i];
		memcpy(p, p2, sizeof(p));
		int now = 0;
		c2[p[0]] = 0;
		for (int i = 1; i < n; ++i) {
			if (c[p[i]] == c[p[i - 1]] && c[nm(p[i] + (1 << k), n)] == c[nm(p[i - 1] + (1 << k), n)])
				c2[p[i]] = now;
			else
				c2[p[i]] = ++now;
		}
		memcpy(c, c2, sizeof(c));
		if (now + 1 >= n)
			break;
	}
	n -= 1;
}
int l;
int k;

int check(int x) {
	memset(en, 0, sizeof(en));
	for (int i = 0; i <= x; ++i) {
		if (p[i] + l <= n)
			en[p[i]] = 1;
	}
	for (int i = 0; i <= n; ++i)
		ans[i] = 1e9;
	ans[0] = 0;
	for (int i = 0; i < n; ++i) {
		if (l && i + (l - 1) <= n)
			ans[i + l - 1] = min(ans[i + l - 1], ans[i] + 1);
		if (en[i] && i + l <= n)
			ans[i + l] = min(ans[i + l], ans[i] + 1);
	}
	if (ans[n] <= k)
		return 1;
	else
		return 0;

}


int main() {
	scanf("%d", &k);
	scanf(" %s", s);
	n = strlen(s);
	sa();
	++k;
	l = (n + k - 1) / k;
	int lb = 0;
	int rb = n;
	while (rb - lb > 1) {
		int mid = (lb + rb) >> 1;
		if (check(mid))
			rb = mid;
		else
			lb = mid;
	}
	int st = p[rb];
	for (int i = 0; i < l; ++i)
		cout << s[st + i];
	return 0;
}




Measured memory_bytes: 5120
#include<stdio.h>
long long R=1,C=1,H[6010],N[6010],X[6010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return (N[H[a]]<N[H[b]]||(N[H[a]]==N[H[b]]&&X[H[a]]<X[H[b]]))?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  long long n,x[100],y[100],i,j,c=1,max=1;
  long long a,b;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld %lld",&x[i],&y[i]);
    for(j=0;j<i;j++){
      if(y[i]>y[j]||(y[i]==y[j]&&x[i]>x[j])){
	X[R]=x[i]-x[j];
	hin(y[i]-y[j]);
      }
      else{
	X[R]=x[j]-x[i];
	hin(y[j]-y[i]);
      }
    }
  }
  if(n==1){
    printf("1\n");
    return 0;
  }
  i=hout();
  a=X[i];
  b=N[i];//printf("%d %d\n",a,b);
  while(C-1){//printf("%lld %lld\n",a,b);
    i=hout();
    if(a==X[i]&&b==N[i])c++;
    else{
      if(max<c)max=c;
      c=1;
    }
    a=X[i];
    b=N[i];
  }//printf("%lld %lld\n",a,b);
  if(max<c)max=c;
  printf("%lld\n",n-max);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  int alice, bob;
  int card[100];
  alice = 0;
  bob = 0;
  for(int i = 0; i <N;i++)cin >> card[i];
  sort(card, card+N, greater<int>());
  for(int i=0; i<N;i++){
    if(i%2==0)alice+=card[i];
    else bob+=card[i];
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define NMAX 52
#define MMAX 52

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

char A[NMAX][NMAX],B[MMAX][MMAX];
int C,N,M,W,H,ans;
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

bool check(int a,int b){
	for (int i = 0; i < M; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			if(B[i][j] != A[a+i][b+j]){
				return false;
			}
		}
	}
	return true;
}

bool solve(){
	for (int i = 0; i < N-M+1; ++i)
	{
		for (int j = 0; j < N-M+1; ++j)
		{
			if(check(i,j)){
				return true;
			}
		}
	}
	return false;
}

void debug(){

}

void answer(){

}

int main(){
	cin >> N >> M;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < M; ++i)
	{
		for (int j = 0; j < M; ++j)
		{
			cin >> B[i][j];
		}
	}
	if(solve()){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int N = 200000;



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

    char c;
    cin >> c;
    if(isupper(c)){
        cout << "A";
    }
    else{
        cout << "a";
    }

    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	string N;
	cin >> N;
	int rsl = 0;
	rep(i, 0, N.size()) {
		if(N[i] == '2') rsl++;
	}

	cout << rsl << endl;
}


Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;
int k, a, b;
long long ans = 1;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> k >> a >> b;
	if (b - a > 2) {
		int tmp = min(a - 1, k);
		k -= tmp;
		ans += tmp;
		ans += (k / 2) * 1LL * (b - a);
		if (k % 2) ans++;
	}
	else {
		ans += k;
	}
	cout << ans << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	std::fill( (T*)array, (T*)(array+N), val );
}

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

ll C,N,W,H,dp[HMAX][WMAX];
string A,B,ans;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
dy[8] = {1,1,0,-1,-1,-1,0,1};

int solve(){
	if(A.size() > B.size()){
		ans = "GREATER";
		return 0;
	}else if(A.size() < B.size()){
		ans = "LESS";
		return 0;
	}
	for (int i = 0; i < A.size(); ++i)
	{
		if(A[i] > B[i]){
			ans = "GREATER";
			return 0;
		}else if(A[i] < B[i]){
			ans = "LESS";
			return 0;
		}	
	}
	ans = "EQUAL";
	return 0;
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> A >> B;
	C = solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  char c[N];
  int num=0;
  for(int i=0;i<N;i++){
    cin >> c[i];
    if(c[i]=='R') num++;
  }
  int ans = 0;
  for(int i=0;i<num;i++){
    if(c[i]!='R') ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3356
n, m = map(int, input().split())
stores = []
for i in range(n):
    store = input().split()
    stores.append([int(store[i]) for i in range(2)])
stores.sort()

drinks = 0
cost = 0
for store in stores:
    if drinks + store[1] <= m:
        drinks += store[1]
        cost += store[0]*store[1]
    elif drinks + store[1] > m:
        cost += (m - drinks)*store[0]
        break
print(cost)

Measured memory_bytes: 21544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n,m,p;
    string s;
    cin>>n>>m;
    vector<string> v[n+1];
    forn(i,0,m){
        cin>>p>>s;
        v[p].pb(s);
    }
    ll ans=0, c=0, cc=0;
    forn(i, 1, n+1){
        cc=0;
        forn(j, 0, v[i].size()){
            cc++;
            if(v[i][j] == "AC"){
                cc--;
                ans+=cc;
                c++;
                break;
            }
        }

    }
    cout<<c<<" "<<ans<<endl;
}

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

using namespace std;

bool is_prime(int x) {
    if (x <= 1)
        return false;
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) 
            return false;
    }
    return true;
}

signed main() {
    int x;
    cin >> x;
    int p = x;
    while (!is_prime(p))
        p++;
    cout << p << "\n";      
    return false;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(i,n) {
    int cnt = 0;
    while(a[i]%2==0){
      a[i] /= 2;
      cnt++;
    }
    ans += cnt;
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	int h = 100, w = 100;
	cout << h << ' ' << w << '\n';
	string g[111];
	for (int i = 0; i < h / 2; i++) {
		g[i].insert(0, w, '.');
		g[i + h / 2].insert(0, w, '#');
	}
	for (int i = 0; i < h / 2; i += 2) {
		for (int j = 0; j < w; j += 2) {
			if (--b > 0) g[i][j] = '#';
			if (--a > 0) g[h - 1 - i][j] = '.';
		}
	}
	for (int i = 0; i < h; i++)
		cout << g[i] << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
ab = []
for i in range(m):
  a, b = list(map(int, input().split()))
  ab.append((a, b))
ab.sort(key=lambda x:x[1])

ans = 0
max_ = 0
for ele in ab:
  if ele[0]>=max_:
    max_ = ele[1]
    ans += 1
print(ans)

Measured memory_bytes: 18212
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int n;
ll L[100];
int main(){
	cin >> n;
	L[0]=2ll;
	L[1]=1ll;
	for(int i=2;i<=86;i++){
		L[i]=L[i-1]+L[i-2];
	}
	cout << L[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int a[N];

int partition(int p,int r){
  int x=a[r],i=p-1,j,n;

  for(j=p;j<r;j++){
    if(a[j]<=x){
      i++;
      n=a[i]; a[i]=a[j]; a[j]=n;
    }
  }
    n=a[i+1]; a[i+1]=a[r]; a[r]=n;

    return i+1;
}

int main(){
  int n,i,di;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  di=partition(0,n-1);

  for(i=0;i<n-1;i++){
    if(i==di) printf("[%d] ",a[i]);
    else printf("%d ",a[i]);
  }
    printf("%d\n",a[i]);
  
  return 0;
}



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

int main(){
  int N,M; cin >>N >>M;
  int a[M+2]; a[0]=-1; a[M+1]=N+1;

  for(int i=1;i<M+1;i++){
    cin >>a[i];
  }

  long long int x[N+1];
  x[0]=1; x[1]=1;
  for(int i=2; i<N+1; i++){
    x[i] = (x[i-1]+x[i-2])%1000000007;
  }

  long long int ans=1;
  for(int i=1; i<M+2; i++){
    if(a[i]-a[i-1]==1){
      ans = 0;
      break;
    } else {
      ans *= x[(a[i]-1)-(a[i-1]+1)];
      ans %= 1000000007;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int m,n; cin >> m >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int ans=0;
	if(m==2){
		int ans2=0;
		for(int i=0;i<n;i++){
			if(i%2==0&&a[i]==1)ans++;
			if(i%2&&a[i]==2)ans++;
			if(i%2==0&&a[i]==2)ans2++;
			if(i%2&&a[i]==1)ans2++;
		}
		cout << min(ans,ans2) << endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		int cnt=0;
		int cp=a[i];
		while(i<n&&a[i]==cp){
			i++;
			cnt++;
		}
		i--;
		ans+=cnt/2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        int n,c=0;

        cin>>n;

        for(int i=1;i<=9;i++)
            for(int j=1;j<=9;j++)
        {
            if(i*j==n)
                c++;
        }

        if(c!=0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    bool isHaveC=false;
    int l=a.size();
    for(int i=0;i<l;i++)
    {
        if(a[i]=='C')
        {
			isHaveC=true;
        }
        if(a[i]=='F')
        {
        	if(isHaveC)
        	{
        		cout<<"Yes"<<endl;
            	return 0;
			}
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i, n, a[100002];
    int s, yen, s1, s2, s3;

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

    // トータルの金額
    s = 0;
    for (i=1; i<=n+1; i++) {
        yen = a[i]-a[i-1];
        if (yen<0)  yen = -yen;
        s += yen;
    }

//  printf("s = %d\n", s);


    // iをやめたときの差額
    for (i=1; i<=n; i++) {
        s1 = a[i]-a[i-1]; if (s1<0) s1 = -s1;
        s2 = a[i+1]-a[i]; if (s2<0) s2 = -s2;
        s3 = a[i+1]-a[i-1]; if (s3<0)   s3 = -s3;
        printf("%d\n", s-(s1+s2)+s3);
    }

    return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << 800*n - 200*(n/15) << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}

ll N, A, B, C, D;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> A >> B >> C >> D;
    N -= 1;
    ll aim = B - A;
    
    //vector<ll> Y;
    //cout << aim << endl;
    rep(i,N+1){
        //i回-. N-i回+
        ll mi = C*(N-i) - D*i;
        ll ma = D*(N-i) - C*i;
        //cout << mi << " " << ma << endl;;
        if(mi <= aim && aim <= ma){
            cout << "YES" << endl;
            /*
            if(D * (N-i-i) >diff){
                rep(j,i){
                    Y.pb((ll)0- D);
                }
                aim += (D*i);
            }
            else{
                rep(j,i){
                    Y.pb((ll)0-C);
                }
                aim += (C+i);
            }
            ll ad = aim/(N-i);;
            ll ot_num = aim - (ad * (N-i));
            
            rep(j, N-i){
                if(j <= ot_num-1) Y.pb(ad+(ll)1);
                else Y.pb(ad);
            }
            
        }
        
        
             */
            return 0;
        }
    }
    
    cout << "NO" << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256