akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S_list = []
for i in range(N):
    S_list.append(input())

M = int(input())
T_list = []
for i in range(M):
    T_list.append(input())

count_Max = 0
for l in S_list:
    count = 0
    for m in S_list:
        if m == l:
            count += 1
    for n in T_list:
        if n == l:
            count -= 1

    if count > count_Max:
        count_Max = count
print(count_Max)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！

    
   char str[3][4];
   for(int i=0;i<3;i++){
       scanf("%s",str[i]);
   }
   printf("%c%c%c\n",str[0][0],str[1][1],str[2][2]);
   
    
    return 0;
}

Measured memory_bytes: 1644
N = int(input())
S = []

dic_={}
n = 1

for i in range(N):
    a = input()
    if a in dic_.keys():
        b = dic_.get(a) + 1
        dic_.update({a: b})
        if n < b:
            n = b
    else:
        dic_.update({a: 1})

ANS = []

for i in dic_:
    if dic_.get(i) == n:
        ANS += [i]

ANS = sorted(ANS)

for key in ANS:
        print(key)



Measured memory_bytes: 33116
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

bool dp[2000000];

int main(){
	int x; cin >> x;
	vector<int> color = {100, 101, 102, 103, 104, 105};
	dp[0] = 1;
	for( int i = 1; i <= 100000; ++i ){
		for( auto k : color ){
			if( i-k >= 0 ) dp[i] |= dp[i-k];
		}
	}
	cout << ( dp[x] ? 1 : 0 ) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  map<int,int> mp;
  int n;
  bool f = true;
  cin >> n;
  rep(i,n){
    int a;
    cin >> a;
    if(mp[a]>0) f = false;
    mp[a]++;
  }
  if(f) cout << "YES" << "\n";
  else cout << "NO" << "\n";
  return 0;
}


Measured memory_bytes: 10240
import math


N = int(input())
borderNum = int(math.sqrt(N))
ans = float("inf")


for a in range(1, borderNum + 1):
    if N % a == 0:
        b = N // a
        numF = max(len(str(b)), len(str(a)))
        ans = min(ans, numF)


print(ans)


Measured memory_bytes: 3060
n,*a=map(int,open(0).read().split())
c=0
while 1:
  m=max(a)
  if m<n:break
  t,f=m//n,1
  c+=t
  for i,b in enumerate(a):
    if b==m and f:
      a[i]%=n
      f=0
    else:
      a[i]+=t
print(c)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
import collections
from functools import reduce

def solve(N: int, S: str):
    c = collections.Counter(S)
    if len(c.keys()) < 3:
        print(0)
        return
    rgb = reduce(lambda x, y: x*y, [int(i) for i in c.values()])
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k > N - 1:
                continue
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                cnt += 1
    print(rgb - cnt)
    return


# Generated by 1.1.6 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
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9472
#include<bits/stdc++.h>
#define int long long
#define f first
#define ss second
#define mp make_pair
#define pb push_back
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5+2;

signed main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    int n,i,j,k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for(int i=0; i<n; i++) std::cin >> a[i];
    std::sort(a.begin(), a.end());
    int ans = 0;
    for(i=0; i<k; i++) ans += a[i];
    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	ll n,a[3010],G=0,min=INF,max=0,ans=0;
	cin>>n;
	REP(i,n){
		cin>>a[i];
		ans+=a[i]-1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
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; }
const ll INF = 1LL << 60;
const ll mod = 1000000007;

int main(){
	//乱数srand((unsigned)time(NULL));
	ll A,B; cin>>A>>B;
	cout<<lcm(A,B)<<endl;
}

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

int main() {
  int N;
  cin >> N;
  
  for (int i=1; i<=N; i++) {
    if (int(i*1.08) == N) {
      cout << i << endl;
      return 0;
    }
  }
  
  cout << ":(" << endl;
  
}

Measured memory_bytes: 384
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
int main()
{
	int data;
	scanf("%d", &data);
	for (int p = 0; p < data; p++)
	{
		ll n, a, b, c, d;
		scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
		set<ll>se;
		priority_queue<pii>que;
		que.push(make_pair(0LL, n));
		for (;;)
		{
			pii z = que.top();
			que.pop();
			ll t = -z.first, x = z.second;
			if (se.find(x) != se.end())continue;
			se.insert(x);
			if (x == 0)
			{
				printf("%lld\n", t);
				break;
			}
			if (double(d)*double(x) < 2e18)que.push(make_pair(-t - d*x, 0));
			que.push(make_pair(-t - a - d*(x % 2), x / 2));
			if (x % 2 != 0)que.push(make_pair(-t - a - d*(2 - x % 2), x / 2 + 1));
			que.push(make_pair(-t - b - d*(x % 3), x / 3));
			if (x % 3 != 0)que.push(make_pair(-t - b - d*(3 - x % 3), x / 3 + 1));
			que.push(make_pair(-t - c - d*(x % 5), x / 5));
			if (x % 5 != 0)que.push(make_pair(-t - c - d*(5 - x % 5), x / 5 + 1));
		}
	}
}

Measured memory_bytes: 3892
def main():
  input()
  ary = list(map(int,input().split()))

  print(*ary)
  for i in range(1, len(ary)):
    v = ary[i]
    j = i - 1
    while (j >= 0) and (ary[j] > v):
      ary[j + 1] = ary[j]
      j -= 1
    ary[j + 1] = v
    print(*ary)

if __name__ == '__main__':
  main()



Measured memory_bytes: 5976
N, K = map(int,input().split())

sum = 0
# サイコロの出た目がiの時
for i in range(1, N+1):
    j = 0
    probability = 1
    score = i
    while score < K:
        # 表が出たら2倍
        score *= 2
        probability *= 0.5
    sum += ( probability / N )

print("{}".format(sum))

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

void insertionSort(int *A,int n,int g);
void shellSort(int *A,int n);

	
	int cnt=0;
	
int main(void){
	
	int A[1000000],G[1000];
	int i,n;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	shellSort(A,n);
	
	printf("%d\n",cnt);
	
	for(i=0;i<n;i++){
		printf("%d\n",A[i]);
	}
	
	return 0;
}

void insertionSort(int *A,int n,int g){
	
	int i,j,v;
	
	for(i=g;i<n;i++){
		v=A[i];
		j=i-g;
		while(j>=0 && A[j]>v){
			A[j+g]=A[j];
			j=j-g;
			cnt++;
		}
		A[j+g]=v;
	}
}

void shellSort(int *A,int n){
	
	int cnt,m=0,i,h;
	int G[1000];
	
	cnt=0;
	
	for(h=1,i=0;;i++){
		if(h>n){
			break;
		}
		G[i]=h;
		h=3*h+1;
		m++;
	}
	
	
	for(i=m-1;i>=0;i--){
		insertionSort(A,n,G[i]);
	}
	
	printf("%d\n",m);
	
	for(i=m-1;i>=0;i--){
		printf("%d",G[i]);
		if(i!=0){
			printf(" ");
		}
	}
	printf("\n");
	

}



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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define pr(a, b) pair<a, b>
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left  (2*idx)+1
#define right (2*idx)+2
#define frt(i,a,b) for(ll i=a; i<b; i++)
#define rew(i,a,b) for(ll i=a; i>=b; i--)
#define fre(i,a,b) for(ll i=a; i<=b; i++)

#define mod %
#define N 13
#define MOD (ll)(1e9 + 7)
#define test if(!true)


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

	if(n mod ((2 * d) + 1) == 0)
	{
		cout << n/((2 * d) + 1) << "\n";
	}
	else
	{
		cout << (n/((2 * d) + 1)) + 1 << "\n";
	}
    return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>

typedef long long ll ;

using namespace std;

ll arry[100005];

int main(){
	ll n,k,sum=0;
	cin>>n>>k;
	int a,b;
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		arry[a]+=b;
	}
	int i=1;
	while(sum<k){
		sum+=arry[i++];
	}
	cout<<i-1<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	static String[] S;
	static String[] T;
	static int N;

	public static void main(String args[]) throws IOException {
		Scanner scan = new Scanner(System.in);
		int ansDiv = 1000000007;

		//標準入力からの受取
		N = Integer.parseInt(scan.nextLine());

		String s = scan.nextLine();
		String t = scan.nextLine();

		S = s.split("");
		T = t.split("");

		//確認用配列の初期化
		//先頭のみ1、それ以外は0を代入
		//long[] check = new long[N];
		//Arrays.fill(check, 0) ;
		//check[0] = 1;
		//for(int i = 1;i < N;i++) {
		//for(int j = 0;j < i;j++) {
		//		if(S[j].equals(T[i])) {
		//			check[i] += check[j];
		//			check %= ansDiv;
		//		}
		//	}
		//}

		HashMap<String , Integer> hash = new HashMap<String,Integer>();
		hash.put(S[0], 1);

		//配列を先頭から順番に見て
		//入口と出口が一致する場所を確認する
		for(int i = 1;i < N - 1;i++) {
			if(!hash.containsKey(S[i])) {hash.put(S[i], 0);	}
			if(!hash.containsKey(T[i])) {hash.put(T[i], 0);	}
			
			hash.put(S[i], (hash.get(T[i]) + hash.get(S[i])) % ansDiv);
		}
		System.out.println(hash.get(T[N-1]));

		scan.close();
	}

}



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

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    for(int& x : a) {
        scanf("%d", &x);
    }
    int x;
    vector<bool> dp(k + 1);
    for(int stones = 0; stones <= k; ++stones) {
        for(int i=0;i<n;i++) {
            x=a[i];
            if(stones >= x && !dp[stones-x]) {
                dp[stones] = true;
            }
        }
    }
    
    puts(dp[k] ? "First" : "Second");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int A, B;
  
  scanf("%d %d\n",&A ,&B);
  
  if(13<=A){
    printf("%d\n",B);
  }else if(6<=A&&A<=12){
    B=B/2;
    printf("%d\n",B);
  }else{
    printf("0");
  }
  
  return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
      cin >> h.at(i);
  }
  
  vector<int> DP(N);
  DP[0] = 0;
  DP[1] = abs(h[1] - h[0]);
  for (int i = 2; i < N; i++) {
    int res = 0x7FFFFFFF;
    for (int j = max(i - K, 0); j < i; j++) {
      res = min(res, DP[j] + abs(h[j] - h[i]));
    }
    DP[i] = res;
  }
  cout << DP[N-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> A >> B >> C >> D;
  flag=1;
  while(A>0&&C>0){
   if(flag)C-=B;
   else A-=D;
   flag^=1; 
  }
  if(A>0)Out("Yes");
  else Out("No");
}

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

int main() {
	char X, Y;
	cin >> X >> Y;
	if (X < Y) cout << '<';
	else if (X == Y) cout << '=';
	else cout << '>';
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

16進数に変換せずとも、アルファベットをchar型にしたときにAが最も小さくZが最も大きいことを利用する
そうすると、そのままchar型で大小比較するのと等しいということが分かる
*/

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

int dp[200][200][200];//sx,sy,ex
int x[]{ 1,1,0,0 }, y[]{ 0,1,0,1 };
int dx[]{ 1,0 }, dy[]{ 0,1 };
int a[200][200];
int main() {
	int h, w; scanf("%d%d", &h, &w);
	rep(i, h)rep(j, w)scanf("%d", &a[i][j]);
	dp[0][0][0] = a[0][0];
	rep(i, h)rep(j, w)rep(k, h) {
		if (i + j - k < 0 || i + j - k >= w)continue;
		if ((i || j) && i == k&&j == i + j - k)continue;
		rep(t, 4) {
			int sx = i + dx[x[t]], sy = j + dy[x[t]], ex = k + dx[y[t]], ey = i + j - k + dy[y[t]];
			if (0 <= sx&&sx < h && 0 <= sy&&sy < w && 0 <= ex&&ex < h && 0 <= ey&&ey < w)
				dp[sx][sy][ex] = max(dp[sx][sy][ex], dp[i][j][k] + a[sx][sy] + a[ex][ey]);
		}
	}
	printf("%d\n", dp[h - 1][w - 1][h - 1] - a[h - 1][w - 1]);
}

Measured memory_bytes: 31616
x,n=map(int, input().split())
if n==0:
    print(x)
else:
    a=list(map(int, input().split()))
    a.sort()
    sa=1000
    for i in range(0,102):
        if i not in a:
            if sa>abs(x-i):
                ans=i
                sa=abs(x-i)
    print(ans)

Measured memory_bytes: 9192
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C,D = IL()
print(max(A*B, C*D))

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;

int n, mx, a[N];
int main()
{
	int i, t;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf("%d", &t);
		a[t] = a[t - 1] + 1;
		mx = max(mx, a[t]);
	}
    cout << n - mx << endl;
    return 0;
}

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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin >> n;
	
	ll s = (n/500) * 1000;
	n %= 500;
	s += (n / 5) * 5;
	
	cout << s;
}


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


#define REP(A, H) for(int A = 0; A < H; A++)

typedef long long ll;

int main(void) {
  ll l, r; std::cin >> l >> r;
  
  int modl = l % 4038;
  int modr = r % 4038;

  int big = std::max(modl, modr);
  int sml = std::min(modl, modr);
  
  int min = 2018;
  for (int i = sml; i <= big; i++)
      for (int j = i + 1; j <= big; j++) {
        min = std::min(i * j % 2019, min);
      }
  
  std::cout << min << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<map>
using namespace std;
typedef long long LL;

int main(){
	int n ,a = 0;
	cin >> n;
	int l[2*n];
	for(int i = 0; i < 2*n; i++)
		cin >> l[i];
	sort(l,l + 2*n);
	for(int i = 0;i < 2*n; i = i+2)
		a = a + l[i];
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import           Data.Char
import           Data.List

main :: IO ()
main = do
    [_, k] <- readInts
    xs <- readInts
    print $ solve k xs

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

solve :: Int -> [Int] -> Int
solve k xs = minimum $ zipWith cost (drop (k-1) xs) xs

cost :: Int -> Int -> Int
cost x y
    | x <= 0    = -y
    | y >= 0    = x
    | x + y < 0 = 2 * x - y
    | otherwise = x - 2 * y

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

bool square();

int main()
{
    if (square()) printf("Yes\n");
    else printf("No\n");

    return 0;
}

bool square()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if (b < 10) b += a * 10;
    else if (b < 100) b += a * 100;
    else b += a * 1000;
    for (int i = 4; i * i <= b; i++)
        if (i * i == b) return true;

    return false;
}

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

int main(){
  string s;
  cin>>s;
  int cou=0;
  int cou2=0;
  char ch='\0';
  char key;
  for(int i=0;i<3;i++)
  {
  	key=s[i];
  	if(key!=ch){
  		cou= count(s.begin(),s.end(),key);
    	if(cou==2){
            ch=key;
            cou2+=1;
            if(cou2==2) break;
            continue;
            }
        else{
            cout<<"No"<<endl;
            break;
            }
  	}
  }
  if(cou2==2)   cout<<"Yes"<<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    ll res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}

ll f[200001];
 
ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a; 
 while(b > 0)
    {
        if(b%2 == 1)
    {
        x=(x*y);
        if(x>MOD) x%=MOD;
    }
    y = (y*y);
    if(y>MOD) y%=MOD; 
    b /= 2;
    }
 return x;
}
 
/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}
 
ll C(ll n, ll r, ll MOD)
{
 
 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
 


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt();
    cout<<a+a*a+a*a*a<<endl;


    return 0;   
}


 
 


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, m, d; cin >> n >> m >> d;
  if (d==0) printf("%.12f", (m-1)/(double)n);
  else printf("%.12f", 2*(m-1)*(n-d)/(double)n/(double)n);
  return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int answer = 1e9;
    for (char i = 'a'; i <= 'z'; ++i) {
        int section = 0, count = 0;
        for (int j = 0; j < S.length(); ++j) {
            if (S[j] == i) {
                section = max(section, count);
                count = 0;
            } else {
                ++count;
            }
        }
        if (count != 0) section = max(section, count);
        answer = min(answer, section);
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

a.sort()
alice = 0
bob = 0
for i in range(N):
    if i % 2 == 0:
        alice += a[N - 1 - i]
    else:
        bob += a[N - 1 - i]
        
print(alice - bob)

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    static int mod = 1_000_000_007;
static long pow(long a,int n) {
    long res=1;
    while (n>0) {
        if ((n-n/2*2)==1) {
            res=res*a%mod;
        }
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

static ArrayList<int[]> factorization (int n) {
    ArrayList<int[]> list = new ArrayList<int[]>();
    int tmp= n ;
    for (int i=2;i<=Math.sqrt(n);i++) {
        if (tmp%i==0) {
            int cnt=0;
            while (tmp%i==0) {
                cnt++;
                tmp/=i;
            }
            int[] x = {i, cnt};
            list.add(x);
        }
    }
    if (tmp!=1) {
        int[] x = {tmp, 1};
        list.add(x);
    }

    if (list.size()==0) {
        int[] x = {n, 1};
        list.add(x);
    }
    return list;
}

static long modinv(long n) {
    return pow(n, mod-2);
}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
            ArrayList<int[]> list = factorization(A[i]);
            for (int[] arr : list) {
                if (!map.containsKey(arr[0])) {
                    map.put(arr[0], arr[1]);
                } else {
                    if (map.get(arr[0])<arr[1]) {
                        map.put(arr[0], arr[1]);
                    }
                }
            }
        }


        ArrayList<Integer> key = new ArrayList<Integer>(map.keySet());
        ArrayList<Integer> val = new ArrayList<Integer>(map.values());
        long lcm = 1L;
        for (int j=0;j<key.size();j++) {
            lcm = lcm*pow(key.get(j), val.get(j))%mod;
        }

        long ans = 0L;
        for (int i=0;i<N;i++) {
            ans = (ans+lcm*modinv(A[i])%mod)%mod;
            // ArrayList<int[]> list = factorization(A[i]);
            // long tmp = 1L;
            // HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(map);
            // for (int[] arr : list) {
            //     map_tmp.put(arr[0], map_tmp.get(arr[0])-arr[1]);
            // }
            // ArrayList<Integer> key = new ArrayList<Integer>(map_tmp.keySet());
            // ArrayList<Integer> val = new ArrayList<Integer>(map_tmp.values());
            // for (int j=0;j<key.size();j++) {
            //     tmp = tmp*pow(key.get(j), val.get(j))%mod;
            // }
            // ans = (ans+tmp)%mod;
        }
        System.out.println(ans);
        // System.out.println(map);
    }
}


Measured memory_bytes: 34480
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    ll N;
    cin >> N;
    cout << N / 3 << endl;
    
    return 0;
}



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

using namespace std;

typedef long long LL;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC k<<1
#define RC k<<1|1

const int N=110000;
const int M=1100000;
const LL mod=1e9+7;
int n;
char s[10];
int main()
{
   scanf("%s",s+1);
   int flag1=0,flag2=0;
   for (int i=1;i<=3;i++)
     	if (s[i]=='A') flag1=1;
        else if (s[i]='B') flag2=1;
    if (flag1&&flag2) printf("Yes\n");
    else printf("No\n");
	return 0;
}

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

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        int n,k,r,s,p,i,j,cnt=0;
        cin >> n >> k >> r>>s >> p;
        string st;
        cin >> st;
        int roc[n+1],pap[n+1],sis[n+1];
        memset(roc,0,sizeof(roc));
        memset(sis,0,sizeof(sis));
        memset(pap,0,sizeof(pap));
        for(i=0;i<st.size();i++){
            if(i==0){
                if(st[i]=='r'){
                    cnt+=p;
                    pap[i]=1;
                }if(st[i]=='s'){
                    cnt+=r;
                    roc[i]=1;
                }if(st[i]=='p'){
                    cnt+=s;
                    sis[i]=1;
                }
            }else{
                if(i-k>=0&&st[i]==st[i-k]){
                    //f=0;
                    if(st[i]=='r' && pap[i-k]==1){
                        pap[i-k]=0;
                    }else if(st[i]=='r'){
                        cnt+=p;
                        pap[i]=1;
                    }
                    if(st[i]=='s' && roc[i-k]==1){
                        roc[i-k]=0;
                    }else if(st[i]=='s'){
                        cnt+=r;
                        roc[i]=1;
                    }
                    if(st[i]=='p' && sis[i-k]==1){
                        sis[i-k]=0;
                    }else if(st[i]=='p'){
                        cnt+=s;
                        sis[i]=1;
                    }
                }else{
                    if(st[i]=='r'){
                    cnt+=p;
                    pap[i]=1;
                }if(st[i]=='s'){
                    cnt+=r;
                    roc[i]=1;
                }if(st[i]=='p'){
                    cnt+=s;
                    sis[i]=1;
                }
                }
            }
        }
        cout << cnt << endl;
        
    }
}

Measured memory_bytes: 4900
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
a_sorted = sorted(a)
max_a = a_sorted.pop()
second_a = a_sorted.pop()
if max_a == second_a:
    for _ in range(N):
        print(max_a)
else:
    idx = 0
    while idx < N:
        if a[idx] == max_a:
            print(second_a)
        else:
            print(max_a)
        idx += 1


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

signed main(){
    int N;
  	cin >>N;
    if(N%2==0){
        cout <<0.5<<endl;
    }
    else{
        double ans=(N+1)/(2.0*N);
        cout <<ans<<endl;
    }
}


Measured memory_bytes: 256
/*
	Nishant Singh
	nishant.ns19
*/
#include <bits/stdc++.h>
#include <functional> 
#include <iostream> 

// ******** Big Integer ********
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #define ll1024  int1024_t
// ******** Big Integer ********

// ******** Using PBDS ********
// #include <ext/pb_ds/assoc_container.hpp> // Common file 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// ******** Using PBDS ********

using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vll vector<ll>
#define vec vector
#define setcount(x) __builtin_popcountll(x)
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define REV(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define in insert
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
#define pq priority_queue
#define ffl fflush(stdout)
#define mset multiset
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define ub upper_bound
#define lb lower_bound 
#define ln "\n"
#define Y "YES"
#define N "NO"
ll const mod=1e9 + 7;
ll const inf=2e18;

// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// ******** Using PBDS ********

inline ll add(ll a,ll b) 
{ 
	return (a%mod + b%mod + mod)%mod; 
}

inline ll mul(ll a,ll b) 
{ 
	return (a%mod * b%mod + mod)%mod; 
}

inline ll sub(ll a,ll b) 
{ 
	return (a%mod - b%mod + mod)%mod; 
}

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

ll modexp(ll x, ll n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}

ll modinv(ll n)
{
	return modexp(n,mod-2);
}

// ******** GLOBAL VARIABLES ********


// ******** GLOBAL VARIABLES ********

void solve(){
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	ll temp[k+1];
	for(ll i=k;i>=1;i--)
	{
		ll multiples=(k/i);
		ll x=modexp(multiples,n);
		temp[i]=x;
	}
	for(int i=k;i>=1;i--)
	{
		for(int j=2*i;j<=k;j=j+i)
		{
			temp[i]=sub(temp[i],temp[j]);
		}
		ans=add(ans,mul(i,temp[i]));
	}
	cout<<ans;
}  

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1;
	// cin>>T; 	
	for(int t=1;t<=T;t++)
	{
		// cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 4412
a, b, c = sorted(list(map(int, input().split())))

ans = 0
if a % 2 == b % 2 == c % 2:
    ans += (c - b) // 2 + (c - a) // 2
elif a % 2 == b % 2:
    ans += 1
    a += 1
    b += 1
    ans += (c - b) // 2 + (c - a) // 2
elif a % 2 == c % 2:
    ans += 1
    a += 1
    c += 1
    ans += (c - b) // 2 + (c - a) // 2
elif c % 2 == b % 2:
    ans += 1
    c += 1
    b += 1
    ans += (c - b) // 2 + (c - a) // 2

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int col(double xa, double ya, double ra, double xb, double yb, double rb);

int main(void)
{
	double xa, ya, ra, xb, yb, rb;
	int n, result;

	scanf("%d", &n);

	while (n) {
		scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb);

		result = col(xa, ya, ra, xb, yb, rb);
		
		printf("%d\n", result);
		n--;
	}

	return (0);
}

int col(double xa, double ya, double ra, double xb, double yb, double rb)
{
	double d;
	double rl, rs;

	if (ra > rb) {
		rl = ra;
		rs = rb;
	} else {
		rl = rb;
		rs = ra;
	}

	d = sqrt(((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)));

	if (d > (ra + rb)) {
		return (0);
	}
	else if ((ra + rb) > d && d > (rl - rs)) {
		return (1);
	}
	else if (d < (rl - rs)) {
		return ((ra > rb)? 2 : -2);
	}
	else {
		return (1);
	}
}

Measured memory_bytes: 636
def main():
    W = [512,256,128,64,32,16,8,4,2,1]
    while True:
        try:
            w = []
            weight = int(input())
            for value in W:
                if weight >= value:
                    weight -= value
                    w.append(value)
            print(*reversed(w))
        except EOFError:
            break
if __name__ == '__main__':
    main()



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

using namespace std;
#define ll long long
int n;
double a[3000];
double dp[3000][3000];

double func(int i, int kitne){
	//base case
	if(kitne == 0){return 1;}
	if(i == n){return 0;}
	//recursive case
	if(dp[i][kitne]>-1.0){return dp[i][kitne];}

	double case1= a[i]*func(i+1, kitne-1);
	double case2= (1-a[i])*func(i+1, kitne);

	dp[i][kitne]= case1+case2;

	return dp[i][kitne];
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	memset(dp, -1.0, sizeof(dp));
	double ans=0;
	cout<<setprecision(10)<<func(0, (n+1)/2);
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int L = 1;
  int R = N;
  for (int i = 0; i < M; i++) {
    if (L == N/4+1 && N%2 == 0) R--;
    cout << L << " " << R << endl;
    L++;
    R--;
  }
}


Measured memory_bytes: 3584
inf = [int(i) for i in input().split()]
L = inf[0]
R = inf[1]

if R-L>=2019:
  print(0)
else:
  m = 2019
  for j in range(L,R+1):
    for i in range(L,j):
      if (i*j)%2019<m:
        m = (i*j)%2019
  print(m)

Measured memory_bytes: 40428
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))

def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
def S(): return sys.stdin.readline().rstrip()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 998244353
INF = float("inf")
sys.setrecursionlimit(10**6+10)
input = sys.stdin.readline

N,K = MI()
A = [0]+LI()
ans_l = []
next = 1
done = [0]*(N+1)
while done[next]==0:
    ans_l.append(next)
    done[next]=1
    next = A[next]
idx = ans_l.index(next)
c = len(ans_l)-idx
if K<idx:
    print(ans_l[K])
else:
    ans_idx = (K-idx)%c+idx
    print(ans_l[ans_idx])


Measured memory_bytes: 103176
N = int(input())
S = input()
ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N-2):
    for j in range(i+1, N + (-(N-i-1)//2)):
        k = j+(j-i)
        if len(set([S[i], S[j], S[k]])) == 3:
            ans-=1
print(ans)

Measured memory_bytes: 9204
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
sums = [0] * (n - 1)
total = 0
for i in range(n - 1):
    total += a[i]
    sums[i] = total
ans = 2 * 10 ** 9 + 1
a_sum = sum(a)
for i in sums:
    ans = min(ans, abs(i - (a_sum - i)))
print(ans)


Measured memory_bytes: 27228
import math
def combination(x,y):
    return math.factorial(x)//(math.factorial(y)*math.factorial(x-y))

n = int(input())
xs = []
ys = []
sum = 0
for i in range(n):
    [x,y] = [int(i) for i in input().split()]
    xs.append(x)
    ys.append(y)
for i in range(n):
    for j in range(i+1, n):
        sum += math.sqrt((xs[i]-xs[j])**2 +(ys[i] - ys[j])**2)
if n > 2:
    sum *= math.factorial(n-1)*2
else:
    sum *= 2
print(sum/math.factorial(n))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define RFOR(i,a,b) for(int i=a;i>=b;i--)
#define inf 0x3f3f3f3f
using namespace std;

const int maxn = 2e5+5;
typedef unsigned long long ULL;
typedef long long ll;

int n;
int A[maxn];
map<int,int>mp;

int main(){
    cin>>n;
    FOR(i,1,n)scanf("%d",A+i),mp[-A[i]+i]++;
    ll ans=0;
    FOR(i,1,n){
        ans+=mp[A[i]+i];
    }
    cout<<ans<<endl;
}


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

int main()
{
	int a,b;
	cin >> a >> b;
	int d = b - a;
	int sum = d * (d + 1) / 2;
	cout << sum - b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  map<string, int> ans;
  ans["SUN"]=7;
  ans["MON"]=6;
  ans["TUE"]=5;
  ans["WED"]=4;
  ans["THU"]=3;
  ans["FRI"]=2;
  ans["SAT"]=1;
  cout<<ans[s]<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


s = str_inp()
for i in range(len(s)):
    if s[i] == "?":
        s[i] = "D"
print("".join(s))


Measured memory_bytes: 72620
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String a=sc.next();
String b=sc.next();
String z="";
for(int i=0;i<n;i++)
{
z=z+a.charAt(i)+b.charAt(i);
}
System.out.println(z);


}
}



Measured memory_bytes: 19924
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int n=ir.nextInt();
		int k=ir.nextInt();
		int x=ir.nextInt();
		int y=ir.nextInt();
		out.println(n<=k?x*n:x*k+(n-k)*y);
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
int main(){
	int R,G,B,N;
	cin>>R>>G>>B>>N;
	int m,n;
	int x;
	m=N/R;
	n=N/G;
	for(int i=0;i<=(m);i++){
		for(int j=0;j<=(n);j++){
			if((N-R*i-G*j)%B==0 && (N-R*i-G*j)>=0){
				int k;
				k=(N-R*i-G*j)/B;
				x++;
		
			}
		}
	}
	cout<<x;

	

	
	}

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

int n,m,x,y,x_max,y_min;
int X[110];        
int Y[110];

int main() {
    cin >> n >> m >> x >> y;
    for (int i = 0; i < n; ++i) cin >> X[i];
  	for (int i = 0; i < m; ++i) cin >> Y[i];
	
  	x_max=X[0];
  	y_min=Y[0];
  	for (int i = 0; i < n; ++i){
      if(X[i]>x_max) x_max=X[i];
    }
  
  	for (int i = 0; i < m; ++i){
      if(Y[i]<y_min) y_min=Y[i];
    }
  

    if(y_min-x_max>0 && y-x>0 ){
      if(min(y,y_min)>max(x,x_max)){
      	cout << "No War" << endl;
      }else{
        cout << "War" << endl;
      }
    }else{
      cout << "War" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000007
#define inf 2000000009
#define N 2005
#define LOG 33
#define M 10
#define EPS 0.0000001
using namespace std; 


int n,z,w,a[N],dp[N][2];

int dfs(int now,int turn) {

	int res=abs(a[now-1]-a[n]);
	if(~dp[now][turn]) return dp[now][turn];
	for(int i=now;i<n;i++) {
		if(!turn) {
			res=max(res,dfs(i+1,!turn));
		}
		else {
			res=min(res,dfs(i+1,!turn));
		}
	}
	return dp[now][turn]=res;

}

int main() {  

	memset(dp,-1,sizeof(dp));
	scanf("%d %d %d",&n,&z,&w);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	a[0]=w;
	printf("%d",dfs(1,0));

}

Measured memory_bytes: 384
n = int(input())
xx = [0] * n
yy = [0] * n
hh = [0] * n
for i in range(n):
    x, y, h = map(int, input().split())
    xx[i], yy[i], hh[i] = x, y, h
    if h > 0:
        x0, y0, h0 = x, y, h

for cx in range(101):
    for cy in range(101):
        f = True
        h = h0 + abs(x0 - cx) + abs(y0 - cy)
        for i in range(n):
            if hh[i] != max(h - abs(xx[i] - cx) - abs(yy[i] - cy), 0):
                f = False
                break
        if f:
            print("{} {} {}".format(cx, cy, h))
            exit(0)


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int d[10001];
long long n;

void process()
{
    for (int x=1;x<100;++x)
    {
        for (int y=1;y<100;++y)
        {
            for (int z=1;z<100;++z)
            {
                long long val=(x+y)*(x+y)+(z+y)*(z+y)+(x+z)*(x+z);
                if (val<=n*2) d[val/2]++;
            }
        }
    }
    for (int i=1;i<=n;++i)
        cout<<d[i]<<"\n";
}

int main()
{
    cin>>n;
    process();
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int n, k;

int a[202020];
int d[202020];
int b[202020];

bool ok;

void round() {
	for (int i = 1; i <= n; i++) d[i] = 0;
	for (int i = 1; i <= n; i++) {
		d[max(i-a[i],1)]++;
		d[min(i+a[i]+1,n+1)]--;
	}
	int c = 0;
	for (int i = 1; i <= n; i++) {
		c += d[i];
		b[i] = c;
	}
	ok = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] != b[i]) ok = 1;
		a[i] = b[i];
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	ok = 1;
	for (int i = 1; i <= k && ok; i++) round();
	for (int i = 1; i <= n; i++) cout << a[i] << " ";
	cout << "\n";
}


Measured memory_bytes: 5972
#include <bits/stdc++.h>
using namespace std;
int sum,cunt2,cunt,N,H,a_max;
static const int MAX=10000;
vector<int> a,b;

void solve(){
    sort(b.begin(),b.end(),greater<int>());
    for(int i=0;i<N;i++){
        if(b[i]<a_max)break;
        cunt++;
        sum+=b[i];
        
        if(sum>=H){
            cout<<cunt<<"\n";
            return;
        }    
    }
/*    sort(b.begin(),b.end());
    vector<int>::iterator low_it= lower_bound(b.begin(),b.end(),a_max);      
    for(vector<int>::iterator it=low_it;it<b.end();it++){
        cunt++;
        sum+=*it;
        if(sum>=H){
            cout<<cunt<<"\n";
            return;
        }
    }*/    
    if((H-sum)%a_max)
        cunt2=cunt+(H-sum)/a_max+1;
    else
        cunt2=cunt+(H-sum)/a_max;                 
    cout<<cunt2<<"\n";    
}        

int main(){
    cin>>N>>H;
    for(int i=0;i<N;i++){
        int x,y;
        cin>>x>>y;
        if(a_max<x)a_max=x;
        a.push_back(x);
        b.push_back(y);
    }
    solve();
    return 0;
}


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

int main(){
	string str;
	double x, y;
	int step, carb, arg;
	int p;
	bool minus;
	
	x = 0; y = 0; arg = 90;
	while(true){
		cin >> str;
		step = 0; carb = 0;
		p = 0;
		while(str[p] != ','){
			step = step * 10 + (str[p] - 48);
			p++;
		}
		p++;
		minus = false;
		while(p < str.size()){
			if(str[p] == '-') minus = true;
			else carb = carb * 10 + (str[p] - 48);
			p++;
		}
		if(step == 0 && carb == 0) break;
		if(!minus) carb *= -1;
		
		x += (double)step * cos((double)arg * 3.1415 / 180.0);
		y += (double)step * sin((double)arg * 3.1415 / 180.0);
		
		arg += carb;
	}
	
	cout << (int)x << endl << (int)y << endl;
	
	return 0;
}

Measured memory_bytes: 1180