akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inclass in = new inclass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMaximumDifference solver = new BMaximumDifference();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumDifference {
        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt();
            TreeSet<Integer> set = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                set.add(in.nextInt());
            }
            out.print(set.last() - set.first());
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

        public inclass(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21076
# coding: utf-8


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = sorted(A, key=lambda x: abs(x), reverse=True)
    Bp = [x for x in B if x > 0]
    Bm = [x for x in B if x < 0]
    Bpm = [x for x in B if x != 0]
    Bmm = []
    for i in range(0, len(Bm)-1, 2):
        Bmm.append(Bm[i]*Bm[i+1])

    q = 10**9 + 7

    n_plus, n_zero, n_minus = 0, 0, 0
    for a in A:
        if a > 0:
            n_plus += 1
        elif a < 0:
            n_minus += 1
        else:
            n_zero += 1

    # if K > n_plus + n_minus:
    #     return 0

    # ans != 0
    rest = K
    ans = 1

    if K <= n_plus + n_minus and not ((n_plus == 0 or K == n_plus + n_minus) and (K-n_plus) % 2 == 1):
        # ans > 0
        i, j = 0, 0
        while rest > 0:
            if rest >= 2 and j < len(Bmm):
                if i+1 < len(Bp):
                    if Bmm[j] >= Bp[i] * Bp[i+1]:
                        ans = (ans * (Bmm[j] % q)) % q
                        j += 1
                        rest -= 2
                    else:
                        ans = (ans * Bp[i]) % q
                        i += 1
                        rest -= 1
                elif i < len(Bp):
                    if Bmm[j] >= Bp[i]:
                        ans = (ans * (Bmm[j] % q)) % q
                        j += 1
                        rest -= 2
                    else:
                        ans = (ans * Bp[i]) % q
                        i += 1
                        rest -= 1
                else:
                    ans = (ans * (Bmm[j] % q)) % q
                    j += 1
                    rest -= 2
            else:
                ans = (ans * Bp[i]) % q
                i += 1
                rest -= 1
        return ans
    elif n_zero > 0:
        return 0
    else:
        # ans < 0
        for i in range(K):
            ans = (ans * Bpm[len(Bpm)-1-i]) % q
        return ans

        # i = 0
        # ip = 0
        # im = 0
        # while rest > 0:
        #     if B[i] > 0:
        #         ans = (ans * B[i]) % q
        #         i += 1
        #         ip += 1
        #         rest -= 1
        #     else:  # B[i] < 0
        #         if rest == 1:
        #             i += 1
        #         elif B[i+1] < 0:  # rest >= 2
        #             ans = (ans * (B[i]*B[i+1] % q)) % q
        #             i += 2
        #             im += 2
        #             rest -= 2
        #         else:  # rest >= 2 and B[i+1] > 0
        #             if Bp[ip] * Bp[ip+1] > Bm[im] * Bm[im+1]:
        #                 ans = (ans * (Bp[ip]*Bp[ip+1] % q)) % q


print(main())


Measured memory_bytes: 31876
#include <stdio.h>
int main(void){
    int x;
    int i;
    int n[100];
    for(i=0;i<100;i++)n[i]=0;
    int max=0;
    
    while(scanf("%d",&x)>0){
        n[x-1]++;
        if(max<n[x-1])max=n[x-1];
    }
    
    for(i=0;i<100;i++){
        if(n[i]==max)printf("%d\n",i+1);
    }
    
    return 0;    
}



Measured memory_bytes: 2104
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    string S;
    int count=0;
    cin>>N;
    cin>>S;
    
    for(int j=0;j<N/2;j++){
        if(S.at(j)==S.at(j+N/2)){
            count++;
        }
    }
    if(N%2!=0){
        cout<<"No"<<endl;
    }
    else if(count==N/2){
        
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define WEIGHTSUM (it -> second) + weight
#define VALUESUM (it -> first) + value
using namespace std;
map <int, int> minWeight;

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

    int n, w, weight, value;
    minWeight[0] = 0;

    cin >> n >> w;
    for (int i = 1; i <= n; i++) {
        cin >> weight >> value;

        //cout << "i = " << i << ":\n";
        for (map <int, int> :: reverse_iterator it = minWeight.rbegin(); it != minWeight.rend(); it++)
            if (WEIGHTSUM <= w) {
                int val = VALUESUM;
                int wei = WEIGHTSUM;
                if (!minWeight[val])
                    minWeight[val] = wei;
                minWeight[val] = min(wei, minWeight[val]);
            }

        //for (pair <int, int> current : minWeight)
        //    cout << current.first << " " << current.second << '\n';
    }

    int result = 0;
    for (pair <int, int> current : minWeight)
    /*    cout << current.first << " " << current.second << '\n';*/result = max(result, current.first);
    cout << result << " ";

    return 0;
}


Measured memory_bytes: 6016
import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    for(int i=0 ; i<s.length() ; i++){
      if(i%2 == 0){
        if(s.charAt(i) == 'L'){
          System.out.println("No");
          return;
        }
      }
      if(i%2 == 1){
        if(s.charAt(i) == 'R'){
          System.out.println("No");
          return;
        }
      }
    }
    System.out.println("Yes");
  }
}


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

dp = [0] * (10**6+1)

for a in A:
    dp[a] += 1

for i in range(1, len(dp)):
    if dp[i]:
        for j in range(i+i, len(dp), i):
            dp[j] = 0
print(dp.count(1))

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll r;
  cin>>r;
  
  ld ans=M_PI*r*2.0;
  cout<<Decimal;
  cout<<ans<<endl;
}



Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, val;
    cin >> n;
    unordered_map<int, int> cnt;
    for(int i = 0; i < n; i++) {
        cin >> val;
        cnt[val] += 1;
    }
    int even_cnt = 0;
    for(auto p: cnt) {
        if (p.second % 2 == 0) {
            even_cnt += 1;
        }
    }
    if (even_cnt % 2 == 1) {
        cout << cnt.size() -1 << endl;
    } else {
        cout << cnt.size() << endl;
    }

    return 0;
}




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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int a, b, k;
    cin >> a >> b >> k;

    if(b - a+1 <= 2 * k){
        for (int i = a; i <= b; ++i) {
            cout << i << endl;
        }
    }else{
        for (int i = a; i < a+k; ++i) {
            cout << i << endl;
        }
        for (int i = b-k+1; i <= b; ++i) {
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// GCD : greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	N, X := getInt(), getInt()
	x := make([]int, N+1)
	for i := 0; i < N; i++ {
		x[i] = getInt()
	}
	x[N] = X
	sort.Ints(x)

	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = x[i+1] - x[i]
	}
	ans := d[0]
	for i := 1; i < N; i++ {
		ans = GCD(ans, d[i])
	}
	out(ans)
}


Measured memory_bytes: 3840
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(),h = sc.nextInt(),w = sc.nextInt();
		int length = n - h + 1;
		int width = n - w + 1;
		System.out.println(length * width);
	}
}

Measured memory_bytes: 23760
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	ll c,res=0;
	cin>>n>>c;
	vector<ll> x(n),v(n);
	for(int i=0;i<n;++i) 
		cin>>x[i]>>v[i];
	vector<ll> pf(n),pmx(n);
	for(int i=0;i<n;++i){
		pf[i]=v[i]-x[i];
		if(i) pf[i]+=pf[i-1]+x[i-1];
		if(i) pmx[i]=max(pmx[i-1],pf[i]);
		else pmx[i]=pf[i];
	}	
	vector<ll> sf(n),smx(n);
	for(int i=n-1;~i;--i){
		sf[i]=v[i]-(c-x[i]);
		if(i<n-1) sf[i]+=sf[i+1]+(c-x[i+1]);
		if(i<n-1) smx[i]=max(smx[i+1],sf[i]);
		else smx[i]=sf[i];
	}
	res=max(pmx[n-1],smx[0]);
	for(int i=0;i<n-1;++i) res=max(res,pf[i]+smx[i+1]-x[i]);
	for(int i=n-1;i>0;--i) res=max(res,sf[i]+pmx[i-1]-(c-x[i]));
	if(res<0) res=0;
	cout<<res<<'\n';
}




Measured memory_bytes: 7912
#include<stdio.h>

int main(){
	char a,c,b;
	int satu;
	scanf("%c%c%c",&a,&c,&b);fflush(stdin);
	if(a == 'H')
		printf("%c",b);
	else
		if(b == 'H')
			printf("D");
		else
			printf("H");
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 12 10:38:04 2019
D - Decayed Bridges
実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 
400
 点
@author: justwah
"""

import sys
read = sys.stdin.readline

n, m = map(int, input().split())
score = n * (n-1) // 2

l = reversed([list(tuple(map(int, read().split()))) for i in range(m)])

parent = [i for i in range(n+1)]
rank = [0]*(n+1)
size = [1]*(n+1)

def root(x): #recursively find root for a node
    if parent[x] == x: # if at root, return self
        return x
    else:
        parent[x] = root(parent[x])  # while searching rejoint queried node to a common parent for hierarchical tree
        return parent[x]
    
def merge(a, b):
    a = root(a)
    b = root(b)
    if rank[a] < rank[b]: # joint lower rank node to a higher rank one
        parent[a] = b
    else:
        parent[b] = a
        if rank[a] == rank[b]: # rank only change if two same rank node joined
            rank[a] +=1
    size[a] += size[b]
    size[b] = size[a]
    return

ans = [score]
for a, b in l:
    a = root(a)
    b = root(b)
    if a != b:
        score -= size[a] * size[b]    
        merge(a, b)
        ans.append(score)
    else:
        ans.append(score)

print(*reversed(ans[:-1]))


Measured memory_bytes: 30896
#line 1 "template.cpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
d = deque()
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    if i % 2 == 0:
        d.append(a[i])
    else:
        d.appendleft(a[i])

if n % 2 == 1:
    d.reverse()

for i in d:
    print(i)


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

using namespace std;

int calc(vector<int> &arr, int key){
	int ans = arr[0];
	for(int i = 0; i < 3; i++){
		if((key & (1 << i)) == (1 << i)){
			ans += arr[i+1];
		}
		else{
			ans -= arr[i+1];
		}
	}
	return ans;
}

int main(){
	string str; cin >> str;
	vector<int> arr(4);
	for(int i = 0; i < 4; i++){
		arr[i] = str[i] - '0';
	}
	int ans = -1;
	for(int i = 0; i < (1 << 4); i++){
		if(calc(arr,i) == 7){
			ans = i;
			break;
		}
	}
	cout << arr[0];
	for(int i = 1; i < 4; i++){
		if((ans & (1 << (i-1))) == (1 << (i-1))){
			cout << '+';
		}
		else{
			cout << '-';
		}
		cout << arr[i];
	}
	cout << "=7" << endl;


	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<stack>
#include<set>
#include<sstream>
#include<fstream>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

int main(){
	int H, W;
	cin >> H >> W;
	
	string ans;
	for(char i = 0; i < H; ++i){
		for(char j = 0; j < W; ++j){
			string str;
			cin >> str;
			if(str == "snuke"){
				cout << (char)('A' + j) << i+1 << endl;
			}
		}
	}

	//cout << ans << endl;

	//system("pause");
	return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

const initBufSize, maxBufSize = 10000, 1000000

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	n := nextInt()
	m := nextInt()
	//丘の高さを格納
	height := make([]int, n+1)
	//良い展望台はTrue
	goodHill := make(map[int]bool)
	for i := 1; i <= n; i++ {
		height[i] = nextInt()
		goodHill[i] = true
	}
	//道が繋がっている丘の高さを比較する
	var from, to, count int
	for i := 0; i < m; i++ {
		from = nextInt()
		to = nextInt()
		//低い方は良い展望台ではない。同じ高さの場合はどちらも良い展望台ではない。
		if height[from] < height[to] && goodHill[from] {
			goodHill[from] = false
		} else if height[from] > height[to] && goodHill[to] {
			goodHill[to] = false
		} else if height[from] == height[to] {
			if goodHill[from] {
				goodHill[from] = false
			}
			if goodHill[to] {
				goodHill[to] = false
			}
		}
	}
	for i := range goodHill {
		if goodHill[i] {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll l,r;
	cin >> l >> r;
	vector <ll> arr;
	for (int z=l;z<=r;z++){
		if (ll(arr.size()) == 2019) break;
		arr.push_back(z%2019);
	}
	ll mini = 2019;
	for (int z=0;z<arr.size();z++){
		for (int x=z+1;x<arr.size();x++){
			mini = min((arr[z]*arr[x])%2019,mini);
		}
	}
	cout << mini << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int N,M,C,cor;
  cin>>N>>M>>C;
  vector<int> B(M);
  for (int i = 0; i < M; i++) cin>>B[i];
  cor = 0;
  vector< vector<int> > A(N, (vector<int>(M,0)));
  for (int i = 0; i < N; i++) {
    int res; res = 0;
    for (int j = 0; j < M; j++) {
      cin>>A[i][j];
      res += A[i][j]*B[j];
    }
    res += C;
    if (res > 0) cor++;
  }
  cout<<cor<<endl;
  return 0;
}

Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]

b2_1 = c[0][1] - c[0][0]
b3_1 = c[0][2] - c[0][0]

if any([b2_1 != c[x][1] - c[x][0] for x in [1, 2]]) or any([b3_1 != c[x][2] - c[x][0] for x in [1, 2]]):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
n,k,q=map(int,input().split())
a=[0]*q
for i in range(q):
  a[i]=int(input())
  
b=[0]*n
for i in range(q):
  b[a[i]-1]+=1
  
for i in range(n):
  if b[i]+k-q>0:
    print('Yes')
  else:
    print('No')




Measured memory_bytes: 8636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d,area1,area2;
  cin>>a>>b>>c>>d;
  area1=a*b;
  area2=c*d;
  if(area1>area2)
    cout<<area1<<endl;
  else if(area1<area2)
    cout<<area2<<endl;
  else if(area1==area2)
    cout<<area1<<endl;
  return 0;
  
}

Measured memory_bytes: 256
n = int(input())
c = input()

w2r = 0 # 白 → 赤に変える数
r2w = 0 # 赤 → 白に変える数
for i in range(n):
    if c[i] == 'R': r2w += 1 # 初期値は赤い石の数

needed = lambda a,b: a + b - min(a,b)
# 必要な手数は W2R と R2W の計 - ペアで変えれる数（min(w2r, r2w))
ans = needed(w2r,r2w)
for i in range(n):
    if c[i] == 'R':
        r2w -= 1
    else:
        w2r += 1
    ans = min(ans, needed(w2r,r2w))

print(ans)


Measured memory_bytes: 9496
#include <stdio.h>
#define N -1

typedef struct
{
  int id;
  int p;
  int l;
  int r;
}Tree;
  
Tree T[25];
void pre( int );
void in( int );
void post( int );

int main()
{
  int i, j, n;
  int id;
  int data;
    
  scanf("%d", &n);
 
  for(i = 0; i < n; i++)
    T[i].p = N;
      
  for(i=0;i<n;i++)
    {
      scanf("%d", &id);
      T[id].id = id;
 
      scanf("%d", &data);
      T[id].l = data;
      if(data != N) T[data].p = id;
      scanf("%d", &data);
      T[id].r = data;
      if(data != N)
	T[data].p = id;
    }
     
  i = 0;
  while(T[i].p != N)
    i++;
  id = i;
      
  printf("Preorder\n");
  pre(id);
      
  printf("\nInorder\n");
  in(id);
      
  printf("\nPostorder\n");
  post(id);
 
  printf("\n");
      
  return 0;
}

void pre(int i)
{
  printf(" %d", i);
  if(T[i].l != N) pre(T[i].l);
  if(T[i].r != N) pre(T[i].r);
}
  
void in(int i)
{
  if(T[i].l != N) in(T[i].l);
  printf(" %d",i);
 
  if(T[i].r != N) in(T[i].r);
}
  
void post(int i)
{
  if(T[i].l != N) post(T[i].l);
 
  if(T[i].r != N) post(T[i].r);
  printf(" %d",i);
}

Measured memory_bytes: 616
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>

int main() {
	int n, l;
	std::cin >> n >> l;
	std::vector<std::string>s(n);
	for (int i = 0;i < n;i++) {
		std::cin >> s[i];
	}
	std::sort(s.begin(), s.end());
	for (int i = 0;i < n;i++) {
		std::cout << s[i];
	}
	std::cout << std::endl;
	return 0;
	}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 4;

void solve() {
    ll n; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        --a[i];
    }
    ll ans = 0, num = 0;
    for (int i = 0; i < n; ++i) {
        if(a[i] == num){
            ++num;
            continue;
        }
        else{
            ++ans;
        }
    }
    if(ans == n){
        ans = -1;
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int n,k;
    long double ans=0,count;
    cin >> n >> k;
    for(int i=1;i<=n;i++)
    {
        count=1;
        for(int s=i;s<k;s*=2)
        {
            count*=0.5;
        }
        long double z=(long double)1/n;
        ans+=z*count;
    }
    cout << std::setprecision(11) << ans << '\n';
}

Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline())
num_line = stdin.readline()
nums = num_line.split(' ')
odd = True;
counter = 0
for i in nums:
    number = int(i)
    if (number%2 == 1 and odd):
        counter +=1 
    odd = not odd
    
print(counter)

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

int main(){
int n,x;
cin >> n;
int M = 0;
int sum = 0;
for (int i = 0;i < n;i++){
  cin >> x;
  M = max(M,x);
  sum += x;
}
if(M * 2 < sum){
  cout << "Yes" << endl;
}
else{
  cout << "No" << endl;
}
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

max_a = max(a)
a.remove(max_a)
da = [abs(ai - max_a / 2) for ai in a]
med_i = da.index(min(da))

print("%d %d" % (max_a, a[med_i]))


Measured memory_bytes: 63724
#include<stdio.h>

int dsum(int n);

int main()
{
	int a,b;
	scanf("%d",&a);
	b=dsum(a);
	if(a%b==0)printf("Yes");
	else printf("No");
	
}

int dsum(int n)
{
	int ans=0;
	while(n>0)
	{
		ans+=n%10;
		n/=10;
	}
	return ans;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in(), k = in();
    vector<pair<ll, ll>>vp(n);
    REP(i, n) {
        ll a = in(), b = in();
        vp[i].first = a;
        vp[i].second = b;
    }
    sort(ALL(vp));
    ll cnt = 0;
    REPC(p, vp) {
        if ((cnt += p.second) >= k) {
            cout << p.first << endl;
            break;
        }
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int mx = 1<<19;
int n, a[mx], r = 0, S = 0, c, i;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s;
	cin >> s;
	n = s.size();
	for(int i = 0; i < n; i++) a[i] = 9*(s[n-i-1]-'0');
	for(int i = 0; i+1 < mx; i++) {
		a[i+1] += a[i]/10;
		a[i] %= 10;
		S += a[i];
	}
	do {
		r += 9;
		for(int j = 0; j < 9; j++)
		for(c = 1, i = 0; c && i < mx; i++) {
			S -= a[i];
			(a[i]++ == 9 ? a[i] : c) = 0;
			S += a[i];
		}
	} while(S > r);
	cout << r/9;
	return 0;
}


Measured memory_bytes: 5848
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define P pair<ll, ll>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;

int
main()
{
  int N; cin >> N;
  map<int, int> m;
  set<int> oder;
  rep(i, 0, N){
    int tmp; cin >> tmp;
    m[tmp] += 1;
    oder.insert(tmp);
  }
  ll ans = 0;

  for(auto x: m){
    if(x.first > x.second){
      ans += x.second;
    } else {
      ans += x.second - x.first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12400
<?php

	$inputArr = ReadStd();
	$octalArr = ChangeOctalToDecimal($inputArr);
	$answerArr = CreateAnswer($octalArr);
	Display($answerArr);

	/**
      * ?¨??????\?????????????????????????????????????????????????????????
      */
    function ReadStd(){

	    $inputArr = array();//?¨??????\?????????????????°??????????´???????

		while(intval($line_num = trim(fgets(STDIN)))!=0){
			$inputArr[] =  intval($line_num);
		}

		return $inputArr;

	}

	/**
      * ?????°??§??????????????????????????°???????????????????????°????????????????????????
      */
	function ChangeOctalToDecimal($inputArr){

		$octalArr = array();

		foreach ($inputArr as $num) {
			$octalArr[] = decoct ( $num );
		}

		return $octalArr;

	}

	/**
      * 4567???????????????5789??????????????????
      * ?????????8?????°???0,1,2,3,4,5,6,7?????????
      * ?????????8?????°???0,1,2,3,5,7,8,9???????????????????????????
      */
	function CreateAnswer($octalArr){

		$answerArr = array();

		foreach ($octalArr as $num) {

            $num = str_replace ( "7" , "9" , $num );
            $num = str_replace ( "6" , "8" , $num );            
            $num = str_replace ( "5" , "7" , $num );
            $num = str_replace ( "4" , "5" , $num );

            $answerArr[] = $num;
		}


		return $answerArr;

	}

	/**
      * ?????????????????????
      */
	function Display($answerArr){

		echo implode("\n",$answerArr);
	}

?>

Measured memory_bytes: 27580
A,B,C,D=map(int,input().split())
if C<=B:
    if A<=C:
        if D>=B:
            print(B-C)
        else:
            print(D-C)
    else:
        if D>=B:
            print(B-A)
        elif A<=D<B:
            print(D-A)
        else:
            print(0)
else:
    print(0)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define int long long
using namespace std;
int vis[1000005]={0};
signed main()
{
	int k;
	scanf("%lld",&k);
	int ans=1,a=7%k;
	while(1){
		if(!a){
			printf("%lld\n",ans);
			return 0;
		}
		if(vis[a])
		{
			printf("-1\n");
			return 0;
		}
		vis[a]=1;
	//	printf("%lld\n",a);
		a=(a*10+7)%k;
		ans++;
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

bool is_p(string s)
{
	auto z = s;
	reverse(z.begin(), z.end());
	return s == z;
}

int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	string s;
	cin >> s;

	int n = s.length();
	if (is_p(s))
	{
		if (is_p(s.substr(0, (n-1)/2)))
		{
			int g = (n+3) / 2;
			if (is_p(s.substr(g-1, n-(g-1))))
			{
				cout << "Yes\n";
				return 0;
			}
		}
	}

	cout << "No\n";

	return 0;
}


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

using namespace std;

int main() {
    string s, t;    cin >> s >> t;
    int sl = s.length(), tl = t.length();

    if (sl < tl) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    int i;
    int ans;
    bool comp = false;
    for (i = 0; i <= sl - tl; i++) {
        bool check = true;
        for (int k = 0; k < tl; k++)
            if (s[i+k] != '?' && s[i+k] != t[k])
                check = false;
        if (check) {
            comp = true;
            ans = i;
        }
    }
        
    if (comp) {
        for (i = 0; i < sl; i++) {
            if (i != ans) {
                if (s[i] == '?')
                    cout << 'a';
                else
                    cout << s[i];
            }
            else {
                cout << t;
                i += tl - 1;
            }
        }
        cout << endl;
    }

    else
        cout << "UNRESTORABLE" << endl;

    return 0;
}

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

int dir[4]{-1, 1, 0, 0};

int main() {
    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<string> grid(h);
    for (int i = 0; i < h; ++i) {
        cin >> grid[i];
    }

    vector<vector<int>> dp(h, vector<int>(w, 1e9));
    dp[ch][cw] = 0;
    deque<pair<int, int>> dq;
    dq.emplace_front(ch, cw);
    while(dq.size()) {
        auto p = dq.front();
        dq.pop_front();
        int r = p.first, c = p.second;

        for (int i = 0; i < 4; ++i) {
            int nr = r + dir[i];
            int nc = c + dir[3-i];
            if(nr < 0 || nc < 0 || h <= nr || w <= nc) continue;
            if(grid[nr][nc] == '#') continue;
            if(dp[nr][nc] > dp[r][c]) {
                dp[nr][nc] = dp[r][c];
                dq.emplace_front(nr, nc);
            }
        }

        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j) {
                int nr = r - 2 + i;
                int nc = c - 2 + j;
                if(nr < 0 || nc < 0 || h <= nr || w <= nc) continue;
                if(grid[nr][nc] == '#') continue;
                if(dp[nr][nc] > dp[r][c] + 1) {
                    dp[nr][nc] = dp[r][c] + 1;
                    dq.emplace_back(nr, nc);
                }
            }
        }
    }

    cout << (dp[dh][dw] == 1e9 ? -1 : dp[dh][dw]) << endl;
}


Measured memory_bytes: 9488
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
int main()
{
    int a;
    cin>>a;
    int n = 0;
    while(n*(n+1)/2 < a)//?????°????????°?±?????????´??¬???????????°
        n++;
    int cnt = n*(n+1)/2 - a;//???????????¢??°??£??????????§???¨?????¬??????????????????
    for(int i = 0;i < n-cnt;i++)
        printf(")");
    printf("(");
    for(int i = n-cnt+1;i < n+1;i++)
        printf(")");
    for(int i = n+1;i < n*2;i++)
        printf("(");
    printf("\n");
    return 0;
}

Measured memory_bytes: 3092
package main

import (
	"fmt"
	"os"
	"math"
)

func getAverage(nums []float64) float64{
	var sum float64
	for _, v := range nums {
		sum += v
	}
	return sum/float64(len(nums))
}

func main() {
	for {
		var n int
		fmt.Scan(&n)
		if n == 0 {
			break
		}
		scores := make([]float64, n)
		for i := range scores {
			fmt.Scan(&scores[i])
		}
		// fmt.Println(scores)
		aveTwo := math.Pow(getAverage(scores), 2)
		for i, v := range scores {
			scores[i] = math.Pow(v, 2)
		}
		// fmt.Println(scores)
		twoAve := getAverage(scores)
		fmt.Printf("%f\n", math.Sqrt(twoAve - aveTwo))
	}
	os.Exit(0)
}



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

int main(int argc, char** argv) {
  int N;
  long long K;
  cin >> N >> K;
  long long A[N];
  for(int cnt0=0; cnt0<N; cnt0++){
    cin >> A[cnt0];
  }
  if(K==0){
    long long ans = 0;
    for(int cnt0=0; cnt0<N; cnt0++) ans += A[cnt0];
    printf("%lld\n", ans);
    return 0;
  }
  long long num = 0;
  int p = log2(K);
  for(int cnt0 = p; cnt0 >= 0; cnt0--){
    int flagcnt = 0;
    for(int cnt1 = 0; cnt1<N; cnt1++){
      if(A[cnt1] & (1LL << cnt0)) flagcnt++;
    }
    bool flag = false;
//    cout << "cnt0: " << cnt0 << ", flaging: " << flagcnt << endl;
    if(flagcnt < N - flagcnt) flag = true; /* 各数のcnt0桁目の1が少ない時 */
    if(flag && (num + (1LL<<cnt0) <= K)) {
//      cout << "cnt0: " << cnt0 << ", in" << endl;    
      num += (1LL<<cnt0);
//      ans += (N-flagcnt)*1LL<<cnt0;
    }
/*
    }else if(flagcnt < N - flagcnt || flagcnt >= N - flagcnt){
      ans += flagcnt*1LL<<cnt0;
    }
*/
  }
  long long ans = 0;
  for(int cnt0 = 0; cnt0 < N; cnt0++){
    ans += num ^ A[cnt0];
  }
  
  printf("%lld\n", ans);
  return 0;
}


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

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

    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x[N];
    int y[M];
    for (int i = 0; i < N; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> y[i];
    }
    sort(x, x + N);
    sort(y, y + M);
    int Z = y[0];
    if (x[N - 1] >= Z || X >= Z || Y < Z) {
        cout << "War" << '\n';
    } else {
        cout << "No War" << '\n';
    }

    return 0;
}


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


int main() {

  long double a,b,c;
  cin>>a>>b>>c;


  if(sqrt(a*b)<(c-a-b)/2)
    cout<<"Yes"<<endl;  
  else
    cout<<"No"<<endl;
  
  return 0;
}



Measured memory_bytes: 256
using System;
public class Program{
  public static void Main(string[] args){
    var s = int.Parse(Console.ReadLine());
    var numsStr = Console.ReadLine().Split(' ');
    var result = 0.0f;
    for(int i = 0; i < s; i++)
    {
      result += 1.0f / float.Parse(numsStr[i]);
    }
    result = 1.0f/result;
    Console.WriteLine(result);
  }
}

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n,0);
  rep(i,n){
    cin >> a[i];
  }

  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(3, vector<ll>(2,-longinf)));
  dp[0][1][0] = 0;
  rep(i,n){
    if(i%2){
      dp[i+1][0][0] = max(dp[i][1][0],dp[i][1][1]);
      dp[i+1][1][0] = max(dp[i][2][0],dp[i][2][1]);
      dp[i+1][1][1] =     dp[i][1][0]+a[i];
    } else {
      dp[i+1][1][0] = max(dp[i][1][0],dp[i][1][1]);
      dp[i+1][1][1] =     dp[i][0][0]+a[i];
      dp[i+1][2][1] =     dp[i][1][0]+a[i];
    }
  }
  cout << max(dp[n][1][0],dp[n][1][1]) << endl;
  return 0;
}


Measured memory_bytes: 43840
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n,ans=0;
	string s="No";
	bool flag = false;

	cin >> n;

	vecstr x(n);

	forll(i, 0, n)
		cin >> x[i];

	vecll num(5,0);

	forll(i, 0, n)
	{
		if (x[i][0] == 'M')
		{
			num[0]++;
		}
		else if (x[i][0] == 'A')
		{
			num[1]++;
		}
		else if (x[i][0] == 'R')
		{
			num[2]++;
		}
		else if (x[i][0] == 'C')
		{
			num[3]++;
		}
		else if (x[i][0] == 'H')
		{
			num[4]++;
		}
	}

	forll(i,0,5)
		if (num[i] > 0)
		{
			flag = true;
			break;
		}

	if (flag)
	{
		forll(i, 0, 3)
		{
			forll(j, i + 1, 4)
			{
				forll(k, j + 1, 5)
				{
					ans += num[i] * num[j] * num[k];
				}
			}
		}
	}

	cout << ans;
}

Measured memory_bytes: 6304
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream> 
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define ull unsigned long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 200010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int p[110],q[110];
int n,m,tot=0;
ll C(int n,int m)
{
	ll ans=1;
	for(int i=1;i<=m;i++)
		ans=ans*(n-i+1)%mod*power(i,mod-2)%mod;
	return ans;
}
int main()
{
	n=read(); m=read();
	for(ll i=2;i*i<=m;i++)
		if(m%i==0){
			p[++tot]=i; q[tot]=0;
			for(;m%i==0;m/=i)++q[tot];
		}
	if(m>1)p[++tot]=m,q[tot]=1;
//	for(int i=1;i<=tot;i++)
//		printf("%d ^ %d\n",p[i],q[i]);
	ll ans=1;
	for(int i=1;i<=tot;i++)
		ans=ans*C(n+q[i]-1,q[i])%mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int main() {
  int n, k, x, y;
  scanf("%d%d%d%d", &n, &k, &x, &y);
  int ret = 0;
  for(int i = 0; i < n; i++) {
    if(i < k) ret += x;
    else ret += y;
  }
  printf("%d\n", ret);
}


Measured memory_bytes: 256
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
ans = 0
for i in range(n + 1):
    ans += abs(a[i + 1] - a[i])

for i in range(n):
    print(ans - abs(a[i + 2] - a[i + 1]) -
          abs(a[i + 1] - a[i]) + abs(a[i + 2] - a[i]))


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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int H;
	int W;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);

		H = Integer.parseInt(strArr[0]);
		W = Integer.parseInt(strArr[1]);

		for (int i = 0; i < W + 2; i++)
			System.out.print("#");
		System.out.println();

	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < H;
	}

	public void readBody(String str) {
		// System.out.println(str);
		System.out.print("#");
		System.out.print(str);
		System.out.println("#");
		cnt++;
	}

	public void solve() {
		for (int i = 0; i < W + 2; i++)
			System.out.print("#");
		System.out.println();
	}
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x1,y1,x2,y2,x3,y3,x4,y4,dx,dy;
  cin>>x1>>y1>>x2>>y2;
  dx=x2-x1;
  dy=y2-y1;
  x3=x2-dy;
  y3=y2+dx;
  x4=x3-dx;
  y4=y3-dy;
  cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REP1(i,a,b) for(ll i=a;i<=b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll a, b, n, ans = 0;
	cin >> a >> b >> n;
	if (a == 0) {
		cout << 1 + (b / n) << endl;
	}
	else {
		cout << (b / n) - ((a - 1) / n) <<endl;
	}
	//cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
f = 0
c = 1
i = 0
while i < N-1:
    if f == 0:
        if A[i] < A[i+1]:
            f = 1
        elif A[i] > A[i+1]:
            f = -1
    elif f == 1:
        if A[i] > A[i+1]:
            c += 1
            f = 0
    elif f == -1:
        if A[i] < A[i+1]:
            c += 1
            f = 0
    i += 1
print(c)

Measured memory_bytes: 14224
wl = {}
N = int(input())
for n in range(N):
    w = input()
    if w in wl:
        wl[w] = wl[w]+1
    else:
        wl[w] = 1 
M = int(input())
for m in range(M):
    w = input()
    if w in wl:
        wl[w] = wl[w]-1
    else:
        wl[w] = -1

mc = ""
c = 0
for k, v in wl.items():
    if c < v:
        mc = k
        c = v

print(c)

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin>>N;
int result=0;
if(N<10){
    result=N;
}
else if(N>=10 && N<100){
    result=9;
}
else if(N>=100 && N<1000){
    result=9+(N+1-100);
}
else if(N>=1000 && N<10000){
    result=9+900;
}
else if(N>=10000 && N<100000){
    result=9+900+(N+1-10000);
}
else if(N==100000){
    result=9+900+90000;
}
cout<<result<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
int32_t main()
{
	fast;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(i%2==0 && s[i]=='L')
		{
			cout<<"No"<<endl;
			return 0;
		}
		else if(i%2!=0 && s[i]=='R')
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,i,m;
    cin>>n;
    int arr[n];
    memset(arr,0,sizeof(arr));
    m=n-1;
    while(m--)
    {
     cin>>a;
     arr[a-1]++;
    }
    for(i=0;i<n;i++)
       cout<<arr[i]<<endl;
    
}

Measured memory_bytes: 4420
n=int(input())
a=[]
if n%2==0:
    for i in range(1,n//2+1):
        a.append(2*i-1)
        a.append(2*i-1)
else:
    a.append(0)
    for j in range(1,n//2+1):
        a.append(2*j)
        a.append(2*j)
b=list(map(int,input().split()))
b.sort()
if a==b:
    print((2**(n//2))%(10**9+7))
else:print(0)

Measured memory_bytes: 17840
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))

    c = []
    mark = [-1]*n
    pos,l = 0,0
    while 1:
        if mark[pos] >= 0:
            l = mark[pos]
            break
        mark[pos] = len(c)
        c.append(pos)
        pos = a[pos] - 1
    if k <= l:
        print(c[k] + 1)
    else:
        k -= l
        print(c[l + k%(len(c) - l)] + 1)
if __name__=="__main__":
    main()


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

nb_even = len(list(filter(lambda x: x % 2 == 0, A)))
nb_odd = len(A) - nb_even


if nb_odd == 1:
    if nb_even == 0:
        print('YES')
    else:
        print('NO')
else:
    if nb_odd % 2 == 0:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 14364
#include <cstdio>
#include <algorithm>

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

const int maxn=100000;

int n,pre[maxn*2+10],now[maxn+10],son[maxn*2+10],tot,f[maxn+10],tmp[maxn+10];

int ins(int a,int b)
{
  pre[++tot]=now[a];
  now[a]=tot;
  son[tot]=b;
  return 0;
}

int search(int u,int fa)
{
  int cnt=0;
  for(int i=now[u]; i; i=pre[i])
    {
      int v=son[i];
      if(v==fa)
        {
          continue;
        }
      search(v,u);
    }
  for(int i=now[u]; i; i=pre[i])
    {
      int v=son[i];
      if(v==fa)
        {
          continue;
        }
      tmp[++cnt]=f[v];
    }
  std::sort(tmp+1,tmp+cnt+1);
  for(int i=cnt; i; --i)
    {
      f[u]=std::max(f[u],tmp[i]+cnt-i+1);
    }
  return 0;
}

int main()
{
  n=read();
  for(int i=2; i<=n; ++i)
    {
      int a=read();
      ins(a,i);
      ins(i,a);
    }
  search(1,0);
  printf("%d\n",f[1]);
  return 0;
}


Measured memory_bytes: 7168