akhauriyash/Code-Regression huggingface dataset:
class SegmentTree: #1-indexed
    def __init__(self,list,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.zero=2**(self.height-1) #最下段に添字を合わせる用
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            self.tree[self.zero+i]=list[i]
        for i in range(self.zero-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更
        i+=self.zero
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r): #区間[l,r)
        l+=self.zero
        r+=self.zero
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf)

    '''
    FFFFTTTTとしたときの最小のTを求める
    '''
    def BinarySearch(self,l,r,f): #fの返り値はboolにする
        if not f(self.query(l,r)): #そもそも区間内にTがなければ右端をreturn
            return r
        l+=self.zero
        while True:
            if f(self.tree[l]):
                if l>=self.zero:
                    return l-self.zero+1 #最下段ならreturn
                else:
                    l*=2 #左の子供を見る
            else:
                if l%2==0:
                    l+=1 #左の子なら右を見る
                else:
                    l=(l//2)+1 #右の子なら親の右を見る

n,k=map(int,input().split())
a=[int(input()) for _ in range(n)]
am=300005
S=SegmentTree([0]*am,max)
for i in range(n):
    x=S.query(max(0,a[i]-k),min(a[i]+k+1,am))
    S.update(a[i],x+1)
print(S.query(0,am))

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

int main() {
    int N, K, x, cnt0 = 0;
    cin >> N >> K;
    vector<ll> Plus(1), Minus(1);
    rep(i,N) {
        cin >> x;
        if (x == 0) ++cnt0;
        else if (x > 0) Plus.push_back(x);
        else Minus.push_back(-x);
    }
    sort(Plus.begin(), Plus.end());
    sort(Minus.begin(), Minus.end());
    
    ll ans = INFINITY;
    if (cnt0 == K) ans = 0;
    int i = 0;
    while (i < K - cnt0) {
        if (i < Minus.size() && K - cnt0 - i < Plus.size()) {
            ll tmp = Minus.at(i) * 2 + Plus.at(K - cnt0 - i);
            ans = min(ans, tmp);
        }
        ++i;
    }
    i = 0;
    while (i < K - cnt0) {
        if (i < Plus.size() && K - cnt0 - i < Minus.size()) {
            ll tmp = Plus.at(i) * 2 + Minus.at(K - cnt0 - i);
            ans = min(ans, tmp);
        }
        ++i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4552
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

int main()
{
	int n, m, c;
	
	cin >> n >> m >> c;
	
	int a[m+5], val, total, cnt = 0;
	for(int i = 1; i <= m; i++) cin >> a[i];
	
	for(int i = 1; i <= n; i++){
		total = c;
		for(int j =  1; j <= m; j++){
			cin >> val;
			total += (a[j]*val);
		}
		
		if(total > 0) cnt++;
	}
	
	cout << cnt << "\n";
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<cmath>
using namespace std;

int main()
{
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << fixed << setprecision(8);
	cout << sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) << endl;
	return 0;
}

Measured memory_bytes: 1280
cross_section = input()

stack = []
areas_stack = []
area = 0
for i in range(len(cross_section)):
    c = cross_section[i]
    if c == '\\':
        stack.append(i)
    elif c == '/' and len(stack) != 0:
        j = stack.pop()
        a = i - j
        area += a
        while len(areas_stack) != 0 and areas_stack[-1][0] > j:
            a += areas_stack.pop()[1]
        areas_stack.append([j, a])

print(area)
if area == 0:
    print(0)
else:
    print(len(areas_stack), ' '.join([str(x[1]) for x in areas_stack]))



Measured memory_bytes: 6180
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int H, A;
    cin >> H >> A;
    if(H%A==0) cout << H/A << endl;
    else cout << H/A+1 << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  map<int,ll> mp;
  ll sum = 0;
  rep(i,n) {
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  while(q--) {
    ll b, c;
    cin >> b >> c;
    if (mp.count(b)) {
      sum -= b * mp[b];
      sum += c * mp[b];
      mp[c] += mp[b];
      mp[b] = 0;
    }
    cout << sum << "\n";
  }
  return 0;
}

Measured memory_bytes: 8716
N = int(input())
a = list(map(int, input().split()))
M = 8
count = [0] * (M + 1)
for x in a:
    q = min(x // 400, M)
    count[q] += 1
nonzero = 0
for i in range(M):
    if count[i] > 0:
        nonzero += 1
print(max(nonzero, 1), nonzero + count[M])

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int sum = 0;
    for(int i = 0; i < M; i++){
        cin >> A.at(i); 
        sum += A.at(i);
    }
    if( N >= sum){
        cout << N -sum << endl;
    }else{
        cout << -1 << endl;
    }    
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>

using namespace std;

int main(){

	double a,b;

	while(cin>>a>>b){
		if(a<35.50&&b<71.0) cout<<"AAA"<<endl;
		else if(a<37.50&&b<77.0) cout<<"AA"<<endl;
		else if(a<40.0&&b<83.0) cout<<"A"<<endl;
		else if(a<43.0&&b<89.0) cout<<"B"<<endl;
		else if(a<50.0&&b<105.0) cout<<"C"<<endl;
		else if(a<55.0&&b<116.0) cout<<"D"<<endl;
		else if(a<70.0&&b<148.0) cout<<"E"<<endl;
		else cout<<"NA"<<endl;
	}

}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(string,S);
  REP(i,S.size()-1){
    if(S[i] == S[i+1]){
      OUT("Bad");
      return 0;
    }
  }
  OUT("Good");
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]

left_i = [0] * N
right_i = [0] * N

for i in range(1, N):
    left_i[i] = max(left_i[i-1], A[i-1])
    right_i[i] = max(right_i[i-1], A[N-i])

for i in range(N):
    print(max(left_i[i], right_i[N-1-i]))

Measured memory_bytes: 15656
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

const int N = int(3e5) + 7;
const int mod = int(1e9) + 7;

int n, a[N], res, fac, cur, inv[N];

int Pow(int x, int y) {
    int res = 1;
    while(y) {
        if(y & 1) res = res * x % mod;
        x = x * x % mod; y >>= 1;
    }
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n; fac = 1;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i]; fac = fac * i % mod;
        inv[i] = inv[i - 1] + Pow(i, mod - 2);
        if(inv[i] >= mod) inv[i] -= mod;
    } int res = 0;
    for(int i = 1; i <= n; ++i) {
        res += ((inv[i] + inv[n - i + 1] - 1) * a[i] % mod);
        if(res >= mod) res -= mod;
    }
    cout << res * fac % mod;
}


Measured memory_bytes: 3072
S = list(input())
N = len(S)
a = 0
b = 0
for i in range(N):
  # for a(01010101...)
  if i % 2 == 0:
    if S[i] == '1':
      a += 1
  else:
    if S[i] == '0':
      a += 1
  # for b(10101010...)
  if i % 2 == 0:
    if S[i] == '0':
      b += 1
  else:
    if S[i] == '1':
      b += 1
print(min(a, b))


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

struct UnionFind{

    vector<int> par;
    vector<int> sizes;

    UnionFind(int n):par(n),sizes(n,1){
        for(int i=0;i<n;i++){
            par[i]=i;
            //sizes[i]=1;
        }
    }

    int find(int x) { //xの根を得る
        if (x == par[x]) return x;
        return par[x] = find(par[x]); //根を張り替えながら再帰的に根ノードを探す
    }

    void unite(int x, int y) { //xとyの集合を併合
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }
};

int main(){
    long long n,m;
    cin >> n >> m;
    int a[m],b[m];
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    UnionFind uf(n);
    long long cur=n*(n-1)/2;
    vector<long long> res;
    for(int i=0;i<m;i++){
        res.push_back(cur);
        int x=a[m-1-i],y=b[m-1-i];
        if(uf.same(x,y)) continue;
        
        long long n1=uf.size(x),n2=uf.size(y);
        cur-=n1*n2;
        uf.unite(x,y);
    }

    for(int i=res.size()-1;i>=0;i--){
        cout << res[i] << endl;
    }
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
 
const int MOD = 1000000007;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    string s,t;
    cin>>s>>t;

    int lcs[s.length()+1][t.length()+1];
    for(int i=0;i<=s.length();i++)
    {
        for(int j=0;j<=t.length();j++)
        {
            if(i==0||j==0)
            {
                lcs[i][j]=0;
            }
            else if(s[i-1]==t[j-1])
            {
                lcs[i][j]=lcs[i-1][j-1]+1;
            }
            else
            {
                lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
            }
        }
    }
    string ans="";
    int i=s.length(), j=t.length();
    //cout<<lcs[i][j]<<"\n";
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans+=s[i-1];
            i--;j--;
        }
        else if(lcs[i-1][j]>lcs[i][j-1])
            i--;
        else
            j--;
    }

    reverse(ans.begin(),ans.end());
    cout<<ans;


    return 0;
} 

Measured memory_bytes: 70656
#!/usr/bin/env python3
import sys
from heapq import heappop, heappush

sys.setrecursionlimit(10 ** 7)


def solve(N: int, M: int, A: "List[int]"):
    pool = []
    for a in A:
        heappush(pool, -a)
    for _ in range(M):
        v = heappop(pool)
        heappush(pool, v / 2)
    result = 0
    for i in pool:
        result += int(i)
    print(-result)

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 21276
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    int n = scanner.nextInt();
    List<Integer> values = new ArrayList<>();

    for (int valueCount = 1; valueCount <= n; valueCount++) {
      values.add(scanner.nextInt());
    }

    values.sort((a, b) -> {
      return b - a;
    });
    
    int alice = 0;
    int bob = 0;
    boolean isAlice = true;
    for (int value : values) {
      if (isAlice) {
        alice += value;
      } else {
        bob += value;
      }

      isAlice = !isAlice;
    }

    System.out.println(alice - bob);

    scanner.close();
  }
}


Measured memory_bytes: 26836
import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])
max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
for i in range(N):
    if i==max_index:
        print(a_second)
    else:
        print(a_max)


Measured memory_bytes: 21864
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
using namespace std;
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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    pr(max(a*b, c*d));
    
}


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

int main(void){
	int N,A,B;
	cin >> N >> A >> B;
	string s;
	cin >> s;


	int cnt = 0,cnt2 = 0;
	for(int i=0;i<s.size();i++){
		if(s[i] == 'a'){
			if( cnt < A + B ){
				cnt++;
				cout << "Yes" << endl;
			}
			else cout << "No" << endl;
		}

		else if(s[i] == 'b'){
			if( cnt < A + B ){
				if( cnt2 < B ){
					cnt2++;
					cnt++;
					cout << "Yes" << endl;
				}else cout << "No" << endl;
			}else cout << "No" << endl;
		}
		else cout << "No" << endl;

	}


	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<string.h>


struct card{
	char kind;
	int value;
};

void bubble_sort(int n, struct card c[])
{
	struct card temp;

	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<n-1;j++)
		{
			if(c[j].value>c[j+1].value)
			{

				temp = c[j];

				c[j]=c[j+1];

				c[j+1]=temp;

			}
		}
	}
}

void selection_sort(int n,struct card c[])
{
	int min;
	struct card temp;
	for(int i=0;i<n;i++)
	{
		min=i;
		for(int j=i;j<n;j++)
		{
			if(c[j].value<c[min].value)
			{
				min = j;
			}
		}
		temp = c[min];

		c[min]=c[i];

		c[i]=temp;
	}
}
int stable(int n,struct card a[],struct card b[])
{
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int c=0;c<n;c++)
			{
				for(int d=c+1;d<n;d++)
				{
					if(a[i].value==a[j].value&&a[i].kind==b[d].kind&&a[j].kind==b[c].kind&&
					a[i].value==b[d].value&&a[j].value==b[c].value)
					{
						return 1;
					}
				}
			}
		}
	}
	return 0;
}

int main(void)
{
  int n;
  scanf("%d",&n);
  struct card a[n];
	struct card b[n];
	struct card c[n];
	for(int i=0;i<n;i++)
	{
    	scanf(" %c%d",&a[i].kind,&a[i].value);
	}
	for(int i=0;i<n;i++)
	{
		b[i]=a[i];
		c[i]=a[i];
	}
	bubble_sort(n, b);
	 printf("%c%d",b[0].kind,b[0].value);
	for(int i=1;i<n;i++)
	{
   		 printf(" %c%d",b[i].kind,b[i].value);
	}
	printf("\n");
	if(stable(n,a,b)==0)
	{
		printf("Stable\n");
	}
	else if(stable(n,a,b)==1)
	{
		printf("Not stable\n");
	}
	selection_sort(n,c);
	printf("%c%d",c[0].kind,c[0].value);
	for(int i=1;i<n;i++)
	{
   		 printf(" %c%d",c[i].kind,c[i].value);
	}
	printf("\n");
	if(stable(n,a,c)==0)
	{
		printf("Stable\n");
	}
	else if(stable(n,a,c)==1)
	{
		printf("Not stable\n");
	}
  return 0;
}



Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int INF = 1000000;


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

   if(a>=k)a-=k;
   else if(a+b>=k){
      b-=(k-a);
       a-=a;
   }else{
       a=0;
       b=0;
   }

   cout<<a<<' '<<b<<endl;
}


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

using namespace std;

const int MAXN = 1e5 + 1;



int main() {
	ios_base::sync_with_stdio(0);
	
	int n, k;
	cin >> n >> k;
	
	double ans = 0;
	
	for(int m = 1; m <= n; m++) {
		int z = m;
		int x = 0;
		while(z < k) {
			z <<= 1;
			x++;
		}
		ans += 1.0 / n * 1.0 / (1 << x);
	}
	
	cout.precision(12);
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mx 100000000
#define pb push_back
#define mp make_pair
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()


ll md=1e9+7;
ll __gcd(ll a, ll b) {if(b==0) return a; return __gcd(b, a%b);}
ll poww(ll a, ll b) {ll res=1;while(b) {if(b&1){res*=a;res%=md;}a*=a;a%=md;b>>=1;}return res;}
void ainp(int arr[], int n) {for(int i=0;i<n;i++) cin>>arr[i];}

const ll N=3e5+5;

void fun()
{ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}


signed main()
{  
fun();
int t;
//cin>>t;
t=1;
while(t--)
{
	int r=0,w=0,n,i;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;i<n;i++)
	{
		if(s[i]=='R')
		r++;
	}
	for(i=0;i<r;i++)
	{
		if(s[i]=='W')
		w++;
	}
	cout<<w;
}
}



Measured memory_bytes: 3688
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

const long long MOD = 1000000007;

void solve(long long N, long long K, std::vector<long long> A) {
    sort(A.begin(), A.end(),
         [](long long a, long long b) { return abs(a) < abs(b); });
    reverse(A.begin(), A.end());

    vector<long long> plus, minus;
    rep(i, N) {
        if (0 <= A[i])
            plus.push_back(A[i]);
        else
            minus.push_back(A[i]);
    }

    long long ans = 1;
    int pi = 0, mi = 0;

    if (K % 2 == 1) {
        if (pi < plus.size()) {
            ans = (ans * plus[pi]) % MOD;
            pi++;
        }
    }

    while (pi + mi + 2 <= K) {
        long long a = -1;
        long long b = -1;
        if (pi + 1 < plus.size()) {
            a = plus[pi] * plus[pi + 1];
        }
        if (mi + 1 < minus.size()) {
            b = minus[mi] * minus[mi + 1];
        }

        if (a == -1 && b == -1) {
            break;
        }

        if (a >= b) {
            pi += 2;
            ans = (ans * (a % MOD)) % MOD;
        } else {
            mi += 2;
            ans = (ans * (b % MOD)) % MOD;
        }
    }

    if (pi + mi == K) {
        cout << (ans + MOD) % MOD << endl;
        return;
    }

    sort(A.begin(), A.end(),
         [](long long a, long long b) { return abs(a) < abs(b); });
    ans = 1;
    rep(i, K) { ans = (ans * A[i] + MOD) % MOD; }
    cout << (ans + MOD) % MOD << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 6936
using System;
using System.Collections.Generic;
using System.Linq;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (input[0] % input[1] == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1);
            }
        }
    }
}

Measured memory_bytes: 13268
import time
import random
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]


def calc_score(T):
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    return score


# 各日に一番満足度の増加が大きいコンテストを開催する
T = [S[i].index(max(S[i])) for i in range(d)]
score = calc_score(T)
start = time.time()
cnt = 0
while True:
    now = time.time()
    if now - start > 1.8:
        break
    p = (cnt // 26) % d
    q = cnt % 26
    memo = T[p]
    T[p] = q
    new_score = calc_score(T)
    temp = 20000 * (1 - (now - start) / 2)
    prob = 2**((new_score - score) / temp)
    if random.random() < prob:
        score = new_score
    else:
        T[p] = memo
    cnt = (cnt + 1) % (10**9 + 7)

for t in T:
    print(t + 1)


Measured memory_bytes: 84972
use std::fmt::Debug;
use std::str::FromStr;

#[allow(dead_code)]
#[allow(deprecated)]
fn read_line_from_stdin() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer.trim_right().to_owned()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_single<T>() -> T
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    T::from_str(buffer.trim_right()).unwrap()
}

#[allow(dead_code)]
#[allow(deprecated)]
fn parse_line_to_multiple<T>() -> Vec<T>
where
    T: FromStr,
    T::Err: Debug,
{
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer
        .trim_right()
        .split_whitespace()
        .flat_map(|s| T::from_str(s))
        .collect()
}

#[allow(unused_macros)]
macro_rules! parse_line {
    [$( $x:tt : $t:ty ),+] => {
        //declare variables
        $( let $x: $t; )+
        {
            use std::str::FromStr;
            // read
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            #[allow(deprecated)]
            let mut splits = buf.trim_right().split_whitespace();
            // assign each variable
            $(
                $x = splits.next().and_then(|s| <$t>::from_str(s).ok()).unwrap();
            )+
            // all strs should be used for assignment
            assert!(splits.next().is_none());
        }
    };
}

fn main() {
    parse_line![_n: usize];

    let mut nums = parse_line_to_multiple::<u128>();

    nums.sort();

    if nums[0] == 0 {
        println!("0",);
        return;
    }

    let mut product = 1;

    for x in nums.into_iter() {
        product *= x;

        if product > 1000000000000000000 {
            println!("-1",);
            return;
        }
    }

    println!("{}", product);
}


Measured memory_bytes: 5572
/*
Competitive programming template
Author: Aswin Sampath

*/


#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef priority_queue<ll,vl,greater<ll>()> pq_ll_min;
typedef priority_queue<ll> pq_ll_max; 
typedef stack<ll> s;
typedef queue<ll> q;


#define pi 3.141592653589793
#define PI  acos(-1.0)
#define space " "
#define endl '\n'
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define testcase ll t;cin>>t;while(t--)
#define dbxstl(x){for(auto ele:x)cout<<ele<<space; cout<<endl;}
#define dbxval(x){cout<<x<<endl;}

const ll INF = 1e18+7;
const ll MOD=1e9+7;

void solve(){
    printf("Hello\n");
}

int main(int argc, char const *argv[])
{
    ll n;
    cin>>n;
    vector<ll>dp(n,0);
    
    for(int days=0;days<n;++days){
        vector<ll>temp(3,0);
        vector<ll>params(3);
        for(ll i=0;i<3;i++){
            cin>>params[i];
        }

        for(ll i=0;i<3;i++){
            for(ll j=0;j<3;j++){
                if(i!=j){
                    temp[j]=max(params[j]+ dp[i],temp[j]);
                }
            }
        }
        dp=temp;
    }
    cout<<max({dp[0],dp[1],dp[2]})<<endl;
    return 0;
}



Measured memory_bytes: 1024
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 9284
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];
 
 
int main () {
    int L;
    cin >> L;
    cout << fixed << setprecision(8) << (double) (L*L*L)/27 << endl;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;



int main(void)
{
	//変数の宣言
	int n,m;
	char s[3][10];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	char stemp[11];
	
	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

//	scanf("%s",&s);
//	scanf_s("%s",&s,10);


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


/*	for(i=0;i<3;i++){
//		scanf("%s",&s);
		scanf_s("%s",&s[i],10);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();

	printf("%d",n/3);

//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	//printf("%d",min(sum+2*m,n-1));

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



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

using namespace std;

int main(){
    int n, k, c;
    cin >> n >> k >> c;
    string S;
    cin >> S;
    vector<int> L(n), R(n);

    int cur = 0;
    int cnt = 1;
    L[0] = 1;
    while (k != 1){
        cur += c + 1;
        cnt++;
        while (S[cur] == 'x')
            cur++;
        L[cur] = cnt;
        if (cnt == k)
            break;
    }

    cur = n - 1;
    R[n - 1] = k;
    cnt = k;
    while (k != 1){
        cur -= c + 1;
        cnt--;
        while (S[cur] == 'x')
            cur--;
        R[cur] = cnt;
        if (cnt == 1)
            break;
    }

    for (int i = 0; i < n; i++){
        if (L[i] == R[i] and L[i] != 0)
            cout << i + 1 << endl;
    }
}

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

using namespace std;


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

    string S;
    cin >> S;
    S += '2';
    
    vector<int> L;
    vector<int> R;
    
    int a = 0;
    int b = 0;
    int size = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '1') {
            a += 1;
        }else if(S[i] == '0'){
            b += 1;
        }
        
        if ((S[i] == '0' && S[i+1] == '1') || S[i+1] == '2') {
            
            L.push_back(a);
            R.push_back(b);
            a = 0;
            b = 0;
            size += 1;
            
        }
    }
    
    L.push_back(0);
    
    
    int ans = L[0];
    int aa = min(K, size);
    
    
    for (int i = 0; i < aa; i++) {
        ans += L[i+1];
        ans += R[i];
    }
    
    
    int ansn = ans;
    int k = 0;
    
    for (int i = aa; i < size; i++) {
        
        ansn = ansn-L[k]-R[k]+R[i]+L[i+1];
        ans = max(ansn, ans);
        k += 1;
        
        
        
    }
    
    
    cout << ans << endl;
    
}


Measured memory_bytes: 1020
#include<iostream>

int selection_sort(int A[], int N) {
  int i, j, tmp, sw = 0, min_i;
  for (i = 0; i < N-1; i++) {
    min_i = i;
    for (j = i+1; j < N; j++) {
      if (A[j] < A[min_i]) min_i = j;
    }
    tmp = A[i];
    A[i] = A[min_i];
    A[min_i] = tmp;
    if (i != min_i) sw++;
  }
  return sw;
}

int main() {
  int A[100], i, N, sw;

  std::cin >> N;
  for (i = 0; i < N; i++) std::cin >> A[i];

  sw = selection_sort(A, N);
  
  for (i = 0; i < N; i++) {
    if (i > 0) std::cout << ' ';
    std::cout << A[i];
  }
  std::cout << std::endl;
  std::cout << sw << std::endl;

  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vll a(x), b(y), c(z);

    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];

    vll ab;
    rep(i, x) rep(j, y) {
        ab.push_back(a[i] + b[j]);
    } 
    sort(rall(ab));
    vll abc;
    rep(i, min(x*y, k)) rep(j, z) {
        abc.push_back(ab[i] + c[j]);
    }
    sort(rall(abc));
    rep(i, k) cout << abc[i] << endl;

    return 0;
}

Measured memory_bytes: 43240
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 


int n,m;
int lights[11][11];
vi p;
int sw[11];
int ans =0;
void dfs(int k=0){
  if (k==n) {
    // do something
    vi p2(m,0);
    rep(i,n) {
      int on = sw[i];
      if (!on) continue;
      rep(j,m) {
        if (lights[j][i]) p2[j]++; 
      }
    }
    rep(i,m) {
      if (p2[i]%2!=p[i]) return;
    }
    ans++;
    return ;
  } 
  sw[k] = true;
  dfs(k+1);
  sw[k] = false;
  dfs(k+1);
   
}

int main() {
  cin >> n >> m;
  rep(i,m) {
    int k;cin>>k;
    rep(j,k) {
      int hoge; cin >> hoge;
      hoge--;
      lights[i][hoge]=1;
    }
  } 
  p.resize(m);
  rep(i,m) cin >> p[i];
  dfs();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def a_dividing_a_string():
    S = input()
    previous = ''
    ans = 0
    is_2_character_taken = False
    for k, c in enumerate(S):
        if is_2_character_taken:  # 前に2文字取ったので、次は1文字取ればよい
            ans += 1
            previous = ''
            is_2_character_taken = False
        elif previous == '':  # 最初の文字は1文字だけ取ることにする
            ans += 1
            previous = c
        else:
            if c == previous:
                # 1文字だけ取ると前の文字と重複するので、2文字取る必要がある
                is_2_character_taken = True
            else:
                ans += 1
                previous = c
    return ans

print(a_dividing_a_string())

Measured memory_bytes: 3500
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>
#include <chrono>
#include <cmath>

#define int long long

using namespace std;

int N, K, C;
string S;

signed main() {
  cin >> N >> K >> C >> S;

  static int l[200002] = { };
  static int r[200002] = { };

  {
    int counter = 0;
    int prev = -1;
    for (int i = 0; i < N; i++) {
      if (S[i] == 'o' && (prev == -1 || prev + C < i)) {
        l[counter] = i;
        prev = i;
        counter++;
      }
    }
  }

  {
    int counter = K - 1;
    int prev = -1;
    for (int i = N - 1; i >= 0 && counter >= 0; i--) {
      if (S[i] == 'o' && (prev == -1 || prev - C > i)) {
        r[counter] = i;
        prev = i;
        counter--;
      }
    }
  }

  for (int i = 0; i < K; i++) {
    if (l[i] == r[i]) {
      cout << l[i] + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4996
import java.util.Scanner;

public class Main {

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

        int matchMax = 0;
        for (int i = 0; i <= s.length() - t.length(); i++) {
            int match = 0;
            for (int j = 0; j < t.length(); j++) {
                if (s.charAt(i + j) == t.charAt(j)) {
                    match++;
                }
            }
            if (matchMax < match) matchMax = match;
        }

        System.out.println(t.length() - matchMax);
    }
}

Measured memory_bytes: 36204
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	int n;
	while (cin >> n) {
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			a[i]--;
		}

		int ans = 0;
		for (int i = 0; i < n; i++) ans += a[a[i]] == i;

		cout << ans / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll dist[123456];
deque<int> dq;

int main(void){
	int k,v,x,y;
	cin >> k;
	fill(dist,dist+k,INFLL);
	dist[1] = 1ll;
	dq.push_front(1);
	while(!dq.empty()){
		v = dq.front();
		x = (v+1)%k;
		y = (v*10)%k;
		dq.pop_front();
		if(dist[x] > dist[v] + 1ll){
			dist[x] = dist[v] + 1ll;
			dq.push_back(x);
		}
		if(dist[y] > dist[v]){
			dist[y] = dist[v];
			dq.push_front(y);
		}
	}
	cout << dist[0] << endl;
	return 0;
}


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

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n;
    int ans;
    
    scanf("%d", &n);
    
    ans=(int)sqrt(n);
    
    printf("%d", ans*ans);

    return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include <cmath>
#include <algorithm>

int a[110], v[110];

int main() {
  int x, n, ans = 1000, ansi;
  scanf("%d%d", &x, &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) v[a[i] + 1] = 1;
  for (int i = -1; i <= 101; ++i) if (!v[i + 1]) {
    if (abs(i - x) < ans) {
      ans = abs(i - x), ansi = i;
    }
  }
  printf("%d\n", ansi);
  return 0;
}

Measured memory_bytes: 1732
<?php
/*
    Problem URL : http://agc004.contest.atcoder.jp/tasks/agc004_b
12-
    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%d", $K);
fscanf(STDIN, "%d", $X);
fscanf(STDIN, "%d", $Y);

$ans = 0;
$ans += min($K, $N) * $X;
if ($K < $N) {
    $ans += ($N - $K) * $Y;
}
echo $ans . PHP_EOL;


Measured memory_bytes: 3832
import java.util.Scanner;

class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (b - a == c - b) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll; 
typedef pair<int,int > pp;
 
 
#define sz(x) (int)x.size() 
#define PI acos(-1)
int const N=3e5;
int  oo = 1e9;
int mod = 998244353;
ll OO = 3e18;

int n,aa[302][302];

void solve(){
	cin>>n;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>aa[i][j];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				if(i==j||i==k||j==k)continue;
				if(aa[i][j] > aa[i][k]+aa[k][j]){
					cout<<-1;
					return ;
				}
			}
		}
	}
	ll an=0; 
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j)continue;
			bool no=0;
			for(int k=0;k<n;k++){
				if(i==k||j==k)continue;
				if(aa[i][j] == aa[i][k]+aa[k][j]){
					no=1;
					break;
				}
			}
			if(!no){
				an+=aa[i][j];
			}
		}
	}
	cout<<an/2<<'\n';
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	// cin>>t;
	while(t--)solve();	
	return 0;
}


Measured memory_bytes: 640
//In The Name Of GOD
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 1000000007;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 100000;
#define pb push_back
#define pp pop_back
#define IO ios_base::sync_with_stdio(false);

int main(){
  IO;
  string s;
  cin>>s;
  int ans=1;
  string h=string (1, s[0]);
  string p;
  for(int i=1;i<s.size();i++){
    p+=s[i];
    if(p==h){
      continue;
    }else{
      ans+=1;
      h=p;
      p.clear();
    }
  }
  cout<<ans;
}


Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
using namespace std;

int main()
{
	long long n;
	cin >> n;
	vector<long long>h(n);
	for (int i = 0; i < n; i++)cin >> h[i];
	vector<long long>::iterator minIt = min_element(h.begin(), h.end());
	vector<long long>::iterator maxIt = max_element(h.begin(), h.end());
	size_t minIndex = distance(h.begin(), minIt);
	size_t maxIndex = distance(h.begin(), maxIt);
	for (int i = 0; i < n-1; i++) {
		if(h[maxIndex] - 1 > h[n-1])return cout << "No" << endl, 0;
		if (h[i] - 1 > h[i + 1] || (maxIndex<i && h[maxIndex]-1 > h[i]))return cout << "No" << endl, 0;
		else continue;
	}
	cout << "Yes" << endl;
}

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

Int n, d, m;
vector<vector<Int>> a;
vector<Int> b;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n, vector<Int>(n-1));
	for(Int i=0; i<n; ++i)
		for(Int j=0; j<n-1; ++j){
			cin >> a[i][j];
			--a[i][j];
		}
	b.resize(n, 0);
	while(m < n*(n-1)/2){
		++d;
		vector<Int> f(n);
		Int cnt = 0;
		for(Int i=0; i<n; ++i){
			if(b[i] == n-1 || f[i]) continue;
			Int p = a[i][b[i]];
			if(a[p][b[p]] == i && !f[p]){
				++b[i];
				++b[p];
				f[i] = true;
				f[p] = true;
				++cnt;
			}
		}
		if(cnt == 0){
			cout << -1 << "\n";
			return 0;
		}else{
			m += cnt;
		}
	}
	cout << d << "\n";
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int n = s.size();

  ll ans = 0;
  rep(bit, (1<<n-1)){
    ll sum = 0;
    string t;
    t += s[0];
    rep(i, n-1){
      if(bit & (1<<i)){
        sum += stol(t);
        t = s[i+1];
      }
      else{
        t += s[i+1];
      }
    }
    sum += stol(t);
    ans += sum;
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
s = input().split()
N = int(s[0])
L = int(s[1])

al = int((L-1)*N + 0.5*N*(N+1))
if L >= 0:
    tmp = L
elif L < 0 and abs(N) > abs(L):
    tmp = 0
else:
    tmp = L + N - 1

print(al -tmp)


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

template <class T> struct FenwickTree {
  const int n;
  vector<T> t;
  FenwickTree(int _n) : n(_n), t(n + 1) {}
  void add(int i, T a) { for (++i; i <= n; i += i & -i) t[i] += a; }
  T sum(int i) const {
    T s = 0;
    for (; i; i -= i & -i) s += t[i];
    return s;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, d, a;
  cin >> n >> d >> a;
  vector<int> x(n), h(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> h[i];
  }
  vector<int> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) { return x[i] < x[j]; });
  FenwickTree<long long> ft(n + 1);
  for (int t = 0; t < n; ++t) {
    int i = idx[t];
    ft.add(t, h[i]);
    ft.add(t + 1, -h[i]);
  }
  long long res = 0;
  for (int t = 0; t < n; ++t) {
    auto z = ft.sum(t + 1);
    if (z > 0) {
      long long c = (z + a - 1) / a;
      int ok = 0, ng = n;
      while (ng - ok > 1) {
        int mid = (ok + ng) / 2;
        (x[idx[mid]] <= (long long)x[idx[t]] + 2 * d ? ok : ng) = mid;
      }
      ft.add(t, -c * a);
      ft.add(ng, c * a);
      res += c;
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	for(int i=1;;i++){
		if(i%2==1){
			c-=b;
			if(c<=0){
				cout<<"Yes";
				return 0;
			}
		}
		if(i%2==0){
			a-=d;
			if(a<=0){
				cout<<"No";
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3564
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 110000
using namespace std;
int n,a[N];
inline bool check(int x){
	long long ans=a[x],sum=1;
	for(int i=1;i<=n;++i){
		if(i==x) continue;
		if(a[i]<=ans*2) ans+=a[i],sum++;
	}
	if(sum==n) return true;
	return false;
}
int find(int l,int r){
	if(l==r) return l;
	if(l+1==r){
		if(check(l)) return l;
		return r;
	}
	int mid=(l+r)/2;
	if(check(mid)) return find(l,mid);
	return find(mid+1,r);
}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	printf("%d",n-find(1,n)+1);
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
  int N,i,j=0;
  scanf("%d",&N);
  int P[N];
  for(i=0;i<N;i++){
    scanf("%d",&P[i]);
  }
  for(i=0;i<N;i++){
    if((i+1)!=P[i])
      j++;
    if(j>2)
      break;
  }
  if(j==2||j==0)
    printf("YES");
  else
    printf("NO");
  
	return 0;
}


Measured memory_bytes: 128