akhauriyash/Code-Regression huggingface dataset:
//██████╗ ██╗   ██╗██╗      ██████╗ ███████╗
//██╔══██╗██║   ██║██║      ██╔══██╗██╔════╝
//██████╔╝██║   ██║██║█████╗██║  ██║█████╗
//██╔══██╗██║   ██║██║╚════╝██║  ██║██╔══╝
//██║  ██║╚██████╔╝██║      ██████╔╝███████╗
//╚═╝  ╚═╝ ╚═════╝ ╚═╝      ╚═════╝ ╚══════╝
#include <bits/stdc++.h>

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back

#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))

#define ADD_OPERATORS_IN(T, COMP) \
    bool operator < (const T& ot) const { return COMP(ot) == -1; } \
    bool operator > (const T& ot) const { return COMP(ot) == 1; } \
    bool operator == (const T& ot) const { return COMP(ot) == 0; } \
    bool operator != (const T& ot) const { return COMP(ot) != 0; }

#define ADD_OPERATORS_OUT(T, COMP) \
    bool operator < (const T& a, const T& b) const { return COMP(a, b) == -1; } \
    bool operator > (const T& a, const T& b) const { return COMP(a, b) == 1; } \
    bool operator == (const T& a, const T&b) const { return COMP(a, b) == 0; } \
    bool operator != (const T& a, const T&b) const { return COMP(a, b) != 0; }


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;

mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());

template<typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); }
template<typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); }

const int maxn = (int) 1e6+10;
const int maxlog = 21;
const int base = 998'244'353;
const ld eps = (ld) 1e-9;
const ld PI = acos(-1.);
const int pp = 41;
const int INF = (int) 2e9;
const ll llinf = (ll) 1e18;


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

//  freopen("input.txt", "r", stdin);
  int k, x;
  cin >> k >> x;
  int l = x - k + 1;
  int r = x + k - 1;
  for (int i = l; i <= r; i ++) {
    cout << i << " ";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define si set<int>
#define mp map<ll,ll>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{ 
	fast 
	ll n,a[MAX],dp[MAX],i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	dp[0]=1e9;
	dp[1]=0;
	for(i=2;i<=n;i++)
	{
		dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
	}
	cout<<dp[n];


}

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

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<long long>());
    
    long long ans=0;
    vector<int> cnt(n);
    vector<int> cnt2(n);
    for(int i=0;i<n;i++){
        cnt2[i]=1;
    }
    cnt2[0]=0;
    int j=0;
    for(int i=0;i<n-1;i++){
        ans += a[j];
        cnt[j]++;
        if(cnt[j]>cnt2[j]){
            j+=1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6352
# coding: utf-8
N, M = map(int, input().split())
for i in range(N):
    if i == 0:
        K = list(map(int, input().split()))
        K = set(K[1:])
    else:
        A = list(map(int, input().split()))
        A = set(A[1:])
        K = K & A
print(len(K))

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

using namespace std;

int main(){
  int A,B,x=1;
  cin >>A>>B;
  if(B==1){
    cout<<0;
  }else{
  for(int i=1;i<30;i++){
    if(B<=(1+(A-1)*i)){
      break;
    }else{
      x=x+1;
    }
  }
  cout<<x;
}

 return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

long long getKey(char str[]) {
	long long sum = 0, p = 1;
	for (int i = 0; i < strlen(str); i++) {
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
	long long key, h;
	key = getKey(str);
	for (int i = 0;; i++) {
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0)return 1;
		else if (strlen(H[h]) == 0)return 0;
	}
	return 0;
}

int insert(char str[]) {
	long long key, h;
	key = getKey(str);
	for (int i = 0;; i++) {
		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h], str) == 0)return 1;
		else if (strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main(void) {
	int n, h;
	char str[L], com[9];
	
	//for (int i = 0; i < M; i++) H[i][0] = '\0';
	scanf("%d ", &n);
	for (int i = 0; i < n; i++) {
		cin >> com >> str;
		if (com[0] == 'i') {
			insert(str);
		} else {
			if (find(str)) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 15500
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-24 22:00:19
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

bool dp[101010];

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

  int x; cin >> x;

  dp[0] = true;

  for (int i = 0; i < 101010; ++i) {
    for (int j = 0; j < 6; ++j) {
      if (i - (100 + j) < 0) continue;
      dp[i] |= dp[i - (100 + j)];
    }
  }

  cout << dp[x] << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n, k; cin >> n >> k;
    vint a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        int s = i * k - (i - 1);
        if(n <= s) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

int main() {
  
  string S;
  cin >> S;
  
  if(S.at(0) == S.at(1) ){
    cout << "Bad" << endl;
  }
  
  else if(S.at(1) == S.at(2) ){
    cout << "Bad" << endl;
  }
  
  else if(S.at(2) == S.at(3) ){
    cout << "Bad" << endl;
  }
  
  else{
    cout << "Good" << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int isSqure(int x);
int main()
{
    int a,b,c;
    cin>>a>>b;
    stringstream ss1,ss2,ss3;
    string m,n,s;

    ss1<<a;
    ss1>>m;
    ss2<<b;
    ss2>>n;

    s = m+n;
    ss3<<s;
    ss3>>c;


    if(isSqure(c) == 1)
        cout<<"Yes"<<endl;
    else if(isSqure(c) == 0)
        cout<<"No"<<endl;

    return 0;
}

int isSqure(int x)
{
    for(int i=1; i*i <=x; i++){
        if( (x %i ==0) && (x/i == i) ){
            return 1;
        }
    }
    return 0;
}


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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int k;
	cin >> k;
	Int ans = 0;
	ARC(i, 1, k + 1){
		ARC(j, 1, k + 1){
			Int tmp = std::gcd(i, j);
			ARC(l, 1, k + 1){
				ans += std::gcd(tmp, l);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
# coding: utf-8
from math import floor, ceil
n = int(input())
tmp = n / 1.08

if tmp % 1 == 0:
    print(int(tmp))
else:
    f_tmp = floor(tmp)
    c_tmp = ceil(tmp)

    if floor(f_tmp * 1.08) == n:
        print(f_tmp)
    elif floor(c_tmp * 1.08) == n:
        print(c_tmp)
    else:
        print(':(')


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())
x = input()
z = '1' * n
o = '0' * n
X = int(x, 2)

if (n == 1 and x == '1'):
  print(0)
  exit()

if (z == x):
  u = n - 1
  d = n - 1
elif (o == x):
  u = 1
  d = 1
else:
  tmp = len(list(filter(lambda x: x == '1', x)))
  u = tmp + 1
  d = tmp - 1


def popcount(i):
  return i % len(list(filter(lambda x: x == '1', format(i, 'b'))))


def solve(i, count):
  if (i <= 2 * 10**5 and ans[i] != 0):
    return count + ans[i]
  elif (i == 0):
    return count
  else:
    return solve(popcount(i), count + 1)


def solve2(i, div):
  if (i <= 2 * 10**5):
    return ans[i]
  else:
    return ans[i % div] + 1


ans = [0] * (2 * 10 ** 5 + 4)
_u = (2 * 10 ** 5) // u
U = X % u + (u * _u) + u
if(d != 0):
  _d = (2 * 10 ** 5) // d
  D = X % d + (d * _d) * 2 + d * 2
Us = [0] * (2 * 10 ** 5)
Ds = [0] * (2 * 10 ** 5)
for i in range(1, 2 * 10 ** 5 + 4):
  ans[i] = solve(i, 0)
Us[0] = 1 % u
if(d != 0):
  Ds[0] = 1 % d
for i in range(1, 2 * 10 ** 5):
  Us[i] = (Us[i - 1] * 2) % u
  if(d != 0):
    Ds[i] = (Ds[i-1] * 2) % d

for i in range(n):
  if(x[i] == '0'):
    print(solve2(U + Us[n-i-1], u))
  else:
    if (d == 0):
      print(0)
    else:
      print(solve2(D - Ds[n-i-1], d))

Measured memory_bytes: 27476
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
#define fst first
#define snd second
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll n; cin >> n;
    vll a(n);
    ll s = 0;
    rep(i, 0, n){
        cin >> a[i];
        s += a[i];
    }
    sort(a.begin(),a.end());
    reverse(all(a));
    ll aans = 0;
    while(a[0] >= n){
    ll g = (n-1)*n;
    ll ans = 0;
    ll b = INF;
    vll ud(n, 0);
    rep(i, 0, n){
        if(a[i] > n-1){
            ll d = a[i] - n + 1; ll h;
            if(d%n == 0){h = d/n;}
            else{h = d/n + 1;}
            ans += h;
            ud[i] = h;
            a[i] -= h*n;
        }else{
            b = i; break;
        }
    }
    rep(i, 0, n){
        if(i < b){
            a[i] += ans - ud[i];
        }else{
            a[i] += ans;
        }
    }
    aans += ans;
    sort(a.begin(),a.end());
    reverse(all(a));
    }
    prtl(aans);
}


Measured memory_bytes: 3536
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main(){
  int n,a[30];
  while(1){
    cin >> n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
  
    int r=32;
    for(int i=0;;i++){
      r -= (r-1) % 5;        //一郎クン
      printf("%d\n", r);

      r -= a[i%n];           //次郎クン。実はHM
      if(r<0) r=0;
      printf("%d\n", r);

      if(r==0) break;
    }
  }
}

Measured memory_bytes: 1144
mod = 998244353
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(k)]
dp = [0] * (n + 1)
dp_sum = [0] * (n + 1)
dp[1] = 1
dp_sum[1] = 1
for i in range(2, n + 1):
    for j in range(k):
        li = max(1, i - lr[j][1])
        ri = i - lr[j][0]
        if ri < 0:
            continue
        dp[i] += dp_sum[ri] - dp_sum[li - 1]
        dp[i] %= mod
    dp_sum[i] = dp_sum[i - 1] + dp[i]
    dp_sum[i] %= mod
print(dp[n])


Measured memory_bytes: 24644
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n,m,c=1;
	cin>>n>>m;
	
	rep(i,m){
	   cout<<i+1<<" "<<n-i<<endl; 
	   if(c&&n%2==0&&i+1==n/4){
	       n--;
	       c=0;
	   }
	}
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a+b){
        if(k<=a){
        cout<<k;
        }
        else{
            cout<<a;
        }
    }
    else{
        cout<<a-(k-a-b);
    }
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll n;
string s[2]={"No","Yes"};
int main(){
	cin>>n;
	cout<<s[(n>=30)];
	return 0;
}


Measured memory_bytes: 3604
n = int(input())
xs = [ input() for i in range(n)]

import string

def str2vec(xs):
    cs = [0] * len(string.ascii_lowercase)
    for x in xs:
        cs[ord(x) - ord('a')] += 1
    return cs
    
print("".join(map(lambda x: x[0]*x[1], zip(string.ascii_lowercase, map(min, zip(*map(str2vec, xs)))))))


Measured memory_bytes: 3956
def gcd(a, b):
	while a > 0 and b > 0:
		a, b = b, a % b
	return a + b

def st(a, b):
	if b == 0:
		return 1
	if b % 2 == 0:
		q = st(a, b // 2)
		return q * q
	return a * st(a, b - 1)

n = int(input())
a = []
for i in range(n + 1):
	x = int(input())
	a.append(x)
ans = 0
for x in range(1, 18):
	tmp = 0
	r = st(x, n)
	for i in range(0, n + 1):
		tmp += a[i] * r
		r //= x
	ans = gcd(ans, abs(tmp))
v = []
j = 2
while j * j <= ans:
	if ans % j == 0:
		ans //= j
		v.append(j)
	else:
		j += 1
if ans != 1:
	v.append(ans)
v.sort()
for i in range(len(v)):
	if i == 0 or v[i] != v[i - 1]:
		print(v[i])


Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 1000000000000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[5]={1,0,-1,0,0},dy[5]={0,1,0,-1,0};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

signed main(){
	int d; cin>>d;
	if(d==25){
		cout<<"Christmas"<<en;
	}else if(d==24) cout<<"Christmas Eve"<<en;
	else if(d==23) cout<<"Christmas Eve Eve"<<en;
	else cout<<"Christmas Eve Eve Eve"<<en;
}




Measured memory_bytes: 764
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String s = br.readLine();
        String t = br.readLine();
        
        List<TreeSet<Integer>> table = new ArrayList<>(26);
        for(int i = 0; i < 26; i++){
            table.add(new TreeSet<>());
        }
        
        for(int i = 0; i < s.length(); i++){
            int k = s.charAt(i) - 'a';
            table.get(k).add(i);
            table.get(k).add(i + s.length());
        }
        
        long base = 0;
        int idx = -1;
        for(int i = 0; i < t.length(); i++){
            int k = t.charAt(i) - 'a';
            Integer j = table.get(k).higher(idx);
            if( j == null ){
                System.out.println(-1);
                return;
            }
            
            idx = j;
            if(idx >= s.length()){
                base += s.length();
                idx -= s.length();
            }
        }
        
        System.out.println(base + idx + 1);
        
    }
}


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

int x[555][555];
int s[555];

int main(){
    int n,m,a,b; cin>>n>>m>>a>>b;
    if(n%a==0 && m%b==0)exit((cout<<"No"<<endl,0));
    cout<<"Yes"<<endl;
    if(m%b!=0){
        for(int i=1;i<=m;++i){
            if(i>=b){
                s[i]=s[i-b]-1;
            }
            else s[i]=10000;
        }
        for(int i=1;i<=n;++i){
            for(int j=1;j<=m;++j){
                cout<<s[j]-s[j-1]<<" ";
            }
            cout<<endl;
        }
    }
    else{
        for(int i=1;i<=n;++i){
            if(i>=a){
                s[i]=s[i-a]-1;
            }
            else s[i]=10000;
        }
        for(int i=1;i<=n;++i){
            for(int j=1;j<=m;++j){
                cout<<s[i]-s[i-1]<<" ";
            }
            cout<<endl;
        }
    }
}


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

int main(void)
{
  int n,m;
  cin >> n >> m;
  int total = 0;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
    total += a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  int flag = 1;
  for(int i=0; i < m; i++)
  {
    if(a[i] * 4 * m < total)
      flag = 0;
  }
  if(flag)
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
package main

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

const mod = 1000000007
const facNum = 300001
const MAX_A = 1000000 + 5

func main() {
	sc := newScanner(os.Stdin)
	N := sc.i()
	A := sc.is(N)
	cnt := make([]int, MAX_A)
	for _, a := range A {
		cnt[a] += 1
	}
	dp := make([]int, MAX_A)
	for index, a := range cnt {
		if a == 0 {
			continue
		}
		for i := index; i < MAX_A; i = i + index {
			dp[i] += a
		}
	}
	sum := 0
	for _, a := range A {
		if dp[a] == 1 {
			sum += 1
		}
	}
	fmt.Println(sum)

}

// 素因数分解
func primeFactor(n int) {

}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 21196
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

k = inp()
if k%2 == 0 or k%5 == 0:
    print(-1)
    quit()
now = 0
for i in range(k+10000):
    now += pow(10,i+1,k)*7
    # print(now)
    now %= k
    if now == 0:
        print(i+1)
        quit()



Measured memory_bytes: 10452
import itertools as it
l = []
for i in range(5):
    l.append(int(input()))
anss = []
def calcTime(ls):
    time = 0
    count = 0
    for i in ls:
        count += 1
        time += l[i]
        if count == 5:
            break
        if time % 10 != 0:
            time += 10 - (time % 10)
    anss.append(time)
perm = it.permutations(range(5),5)
lperm = list(perm)
for tup in lperm:
    calcTime(list(tup))
print(min(anss))

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	string s;
	int ans = 0;
	cin >> s;
	ans = s.size();
	for(int i = 0; i < s.size() - 1; i++){
		if(s[i] != s[i + 1]){
			ans = min(ans, max(i + 1, (int)s.size() - i - 1));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main()
{   char a[11],b[11],c[11];
    scanf("%s%s%s",a,b,c);
    if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0])
    printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int value[3][101];
int sum[3][101];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> value[1][i];
	for (int i = 1; i <= n; i++) cin >> value[2][i];
	for (int i = 0; i <= 2; i++) sum[i][0] = 0;
	for (int i = 0; i <= n; i++) sum[0][i] = 0;
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= n; j++)
			sum[i][j] = max(sum[i][j - 1], sum[i - 1][j]) + value[i][j];
	cout << sum[2][n] << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  vector<int> a(3);
  REP(i,3)cin >> a[i];
  sort(ALL(a));

  if((2*a[2]-a[0]-a[1])%2 == 0){
    cout << (2*a[2]-a[0]-a[1])/2 << endl;
  }else{
    cout << (2*a[2]-a[0]-a[1])/2 +2 << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
int l,r,ans=Inf;
int main()
{
	cin>>l>>r;
	for(int i=l;i<min(r,l+2019);i++)
		for(int j=i+1;j<=min(r,l+2019);j++)
			ans=min(ans,i%2019*(j%2019)%2019);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (){
  int a,b,tmp,r;
  scanf("%d%d",&a,&b);
if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 

 r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }


 printf("%d\n", b);


  
  return 0;

}



Measured memory_bytes: 2756
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

INF = 1 << 60

def main():
  N = read()
  A = reads()
  offset = sum(a for a in A if a > 0)
  di = dinic(N+2) # 0: source, N+1: target
  for i in range(1, N+1):
    a = A[i-1]
    if a <= 0:
      di.add_edge(0, i, -a)
    else:
      di.add_edge(i, N+1, a)
    for j in range(2*i, N+1, i):
      di.add_edge(i, j, INF)
  ans = offset - di.max_flow(0, N+1)
  print(ans)

class dinic:
  def __init__(self, N): self.size = N; self.edges = [[] for _ in range(N)]
  def add_edge(self, u, v, c): self.edges[u].append((v, c)); self.edges[v].append((u, 0))
  def bfs(self, cap, s):
    N = self.size; edges = self.edges
    level = [-1] * N; level[s] = 0
    que = deque([s])
    while len(que) > 0:
      u = que.popleft()
      for v, _ in edges[u]:
        if cap[u][v] > 0 and level[v] < 0: level[v] = level[u] + 1; que.append(v)
    return level
  def dfs(self, cap, itr, level, u, t, f):
    N = self.size; edges = self.edges
    if u == t: return f
    for i in range(itr[u], len(edges[u])):
      itr[u] = i
      v, _ = edges[u][i]
      if cap[u][v] > 0 and level[u] < level[v]:
        d = self.dfs(cap, itr, level, v, t, min(f, cap[u][v]))
        if d > 0: cap[u][v] -= d; cap[v][u] += d; return d
    return 0
  def max_flow(self, s, t):
    N = self.size; edges = self.edges; cap = [[0] * N for _ in range(N)]
    for u in range(N):
      for v, c in edges[u]: cap[u][v] += c
    flow = 0
    while True:
      level = self.bfs(cap, s)
      if level[t] < 0: return flow
      itr = [0] * N
      while True:
        f = self.dfs(cap, itr, level, s, t, INF)
        if f <= 0: break
        flow += f

main()

Measured memory_bytes: 39920
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <vector>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long

int main(void){
    ll n, h;
    cin >> n >> h;
    ll a[n], b[n];
    ll maa = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        maa = max(maa, a[i]);
    }
    ll ans = 0;
    sort(b, b+n);
    for(ll i = n-1; i >= 0; i--){
        if(b[i] > maa){
            ans++;
            h -= b[i];
        }
        if(h <= 0)
            break;
    }
    if(h > 0){
        ans += h/maa;
        if(h%maa != 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int64_t beki(int64_t n){
 int64_t s,ans;
  s=(n*n)%1000000007;
  ans=(s*n)%1000000007;
  return ans;}

int main() {
int64_t k,a;
  a=0;
  cin>>k;
  vector<int64_t> ans(k);
  ans.at(k-1)=1;
  for(int64_t i=k-2;i>=0;i--){
  ans.at(i)=beki(k/(i+1));
    for(int64_t j=1;(i+1)*j<=k;j++){
    ans.at(i)=ans.at(i)-ans.at((i+1)*j-1);
     }
    ans.at(i)=ans.at(i)+beki(k/(i+1));
  }
  for(int64_t i=0;i<k;i++){a=a+(i+1)*ans.at(i);
  while(a>=1000000007){a=a-1000000007;}}
  cout<<a<<endl;
}  

Measured memory_bytes: 3532
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

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


int main() {
    string S;
    cin >> S;

    string ans="No";

    map<char,int> mp;

    REP(i,4){
    	char t;
    	t= S[i];
    	mp[t]++;

    }


    if(mp.size()!=2){
    	cout << ans << endl;
    	return 0;
    }

    char t=S[0];
    if(mp[t]!=2){
    	cout << ans << endl;
    	return 0;
    }

    ans = "Yes";
	cout << ans << endl;

}



Measured memory_bytes: 256
#include<iostream>

int main()
{
    int a[3], b[3], c[3][3];
    bool f=false;
    
    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)
            std::cin >> c[i][j];
    
    for(a[0]=0; a[0]<=100; a[0]++)
    {
        if(a[0]>c[0][0] || a[0]>c[0][1] || a[0]>c[0][2])
            break;
        for(a[1]=0; a[1]<=100; a[1]++)
        {
            if(a[1]>c[1][0] || a[1]>c[1][1] || a[1]>c[1][2])
                break;
            for(a[2]=0; a[2]<=100; a[2]++)
            {
                if(a[2]>c[2][0] || a[2]>c[2][1] || a[2]>c[2][2])
                    break;
                f=true;
                b[0] = c[0][0]-a[0];
                b[1] = c[1][1]-a[1];
                b[2] = c[2][2]-a[2];
                
                for(int i=0; i<3; i++)
                {
                    for(int j=0; j<3; j++)
                    {
                        if(c[i][j]-a[i]-b[j])
                            f=false;
                    }
                }
                if(f)
                {
                    std::cout << "Yes" <<std::endl;
                    return 0;
                }
            }
        }
        
    }
    std::cout << "No" <<std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include<unordered_map>
#include <cassert>
#include <string>
#include <cstring>
#include<stack>
#include<list>
#include<queue>
using namespace std;
typedef long long int ll;
# define INF 0x3f3f3f3f
# define M 1000000007

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	char c;
	cin>>c;
	if(isupper(c)) cout<<"A"<<endl;
	else cout<<"a"<<endl;
}

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

using namespace std;

int main() {
  int age, cost;
  cin >> age >> cost;
  if (age >= 13) {
  } else if (age >= 6) {
    cost /= 2;
  } else {
    cost = 0;
  }
  cout << cost << endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <fstream>
#include<iostream>
#include <cmath>
#include <chrono>
#include <thread>
#include <stack>
#include <memory.h>
#include <numeric>
#include <iostream>
#include<climits>

//  vector<vector<int>> b(row_size, vector<int>(col_size,n));   //  n->initialized value

#define MOD 1000000007LL
#define ff first
#define fs second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<long long>
#define vvi vector< vector <int> >
#define vpii vector< pair<int, int> >
#define pii pair<int,int>
#define mii map<int, int>
#define mp make_pair
#define tc                int T;cin>>T;while(T--)
#define fast_io            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int

using namespace std;

vector<string> order;
map<string, bool> state;
map<string, vector<string>> path;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, W, totval = 0; cin >> n >> W;
    vector<pair<ll, ll>> items(n);
    for (auto& p : items)cin >> p.first >> p.second;
    for (auto& p : items)totval += p.second;
    vector<vector<ll>> dp(n + 1, vector<ll>(totval + 1));
    for (int i = 0; i <= totval; ++i)dp[1][i] = 1000000000+1;
    //for (int i = 0; i <= n; ++i)dp[i][0] = 0;
    dp[1][0] = 0;
    dp[1][items[0].second] = items[0].first;
    for (ll i = 2; i <= n; ++i)
        for (ll j = 0; j <= totval; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j>=items[i - 1].second) {
                dp[i][j] = min(dp[i][j], items[i - 1].first + dp[i - 1][j - items[i - 1].second]);
            }

        }
    for (ll i = totval; i > -1; --i)if (dp[n][i] <= W) {
        cout << i << '\n'; break;
    }
    // printtable(dp);
    return 0;

}


Measured memory_bytes: 80256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n, m; cin >> n >> m;
  ll sum = 0;
  rep(i, m) {
    ll ai; cin >> ai;
    sum += ai;
  }
  if (sum <= n) {
    outl(n-sum);
  } else {
    outl(-1);
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 3196
from collections import deque

n=int(input())
A=deque(list(map(int,input().split())))

while len(A)>1:
    a=A.popleft()
    for _ in range(len(A)):
        aa=A.popleft()
        if aa%a>0:
            A.append(aa%a)
    A.append(a)

print(A[0])

Measured memory_bytes: 14636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException{
		InputReader in = new InputReader(System.in);
		
		int n = in.readInt();
		
		int[] aArray = new int[n];
		long sum = 0;
		for (int i = 0; i < n; i++) {
			aArray[i] = in.readInt();
			sum += aArray[i];
		}
		Arrays.sort(aArray);
		
		System.out.println(aArray[0] + " " + aArray[n - 1] + " " + sum);		
	}
}
class InputReader{
	private BufferedReader br;
	private StringTokenizer buffer = null;	
	
	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));				
	}

	public String read() throws IOException {
		while(buffer == null || !buffer.hasMoreTokens()) {
			buffer = new StringTokenizer(br.readLine());
		}
		return buffer.nextToken();
	}
	
	public int readInt() throws IOException {
		while(buffer == null || !buffer.hasMoreTokens()) {
			buffer = new StringTokenizer(br.readLine());
		}
		return Integer.parseInt(buffer.nextToken());
	}
	
}


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

int main(void) {
	int a,b,n,i,t;
	char s[8];
	while(scanf("%d\n",&a) , a != 0){
		t = 0;
		b = -1023;
		for(i = 1;i <= a;i++){
			scanf("%s",s);
			if(!(strcmp("lu",s))) n = 0;
			if(!(strcmp("ru",s))) n = 1;
			if(!(strcmp("ld",s))) n = 2;
			if(!(strcmp("rd",s))) n = 3;
			if(n + b == 1 || n + b == 5) t++;
			b = n;
		}
		printf("%d\n",t);
	}
	return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n, k, x, y; cin >> n >> k >> x >> y;
  int res = min(k, n) * x + max(n - k, 0) * y;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
x = []
y = []
list = []
ans = 0
for i in range(n):
  x0, y0 = input().split()
  x.append(int(x0))
  y.append(int(y0))
for i in range(n):
  for j in range(n):
    list.append(((x[i] - x[j])**2 + (y[i] - y[j])**2)**0.5)
print(sum(list)/len(x))

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Collections.Generic;

namespace ABC099B
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var A = ss.Next(int.Parse);
            var B = ss.Next(int.Parse);

            for (var i = 1; i < 999; i++)
            {
                var l = i * (i + 1) / 2;
                var r = (i + 1) * (i + 2) / 2;

                if (l - A > 0 && l - A == r - B)
                {
                    sw.WriteLine(l - A);
                    return;
                }
            }
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

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

int main(){
  while(true){
    int n;
    cin>> n;
    if(n==0)break;
    char c[100];
    for(int i=0;i<n;i++){
      cin>>c[i];
    }
    int cnt[26]={0};
    for(int i=0;i<n;i++){
      cnt[(int)(c[i]-'A')]++;
      int max1=-1;
      int max2=-1;
      for(int j=0;j<26;j++){
        if(cnt[j]>max1){
          max2=max1;
          max1=cnt[j];
        }else if(cnt[j]>max2){
          max2=cnt[j];
        }
      }
      if(max1-max2>n-(i+1)){
        for(int j=0;j<26;j++){
          if(cnt[j]==max1){
            cout<<(char)(j+'A')<<' ';
            break;
          }
        }
        cout<<(i+1)<<endl;
        break;
      }
      if(i==n-1){
        cout<<"TIE"<<endl;
        break;
      }
    }
  }
  return 0;
}



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

int main(){
    int a[5], i;
    int x = 10, d, p, s = 0;
    for(i = 0; i < 5; i++){
        cin >> a[i];
        d = a[i] / 10;
        p = a[i] % 10;
        if(p == 0){
            s += d * 10;
        }
        else{
            s += (d+1) * 10;
            if(p < x) x = p;
        }
    }
    s -= 10 - x;
    cout << s << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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();}

int main(){
    std::ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;

    if(a + b > c)
    {
        cout << "No" << endl;
        return 0;
    }

    cout << ((4 * a * b < (c - a - b) * (c - a - b)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
    
int main(void)
{
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    ll ans = 0;
    ll tot = 0;
    REP(i, N){
        if(A[i]==0){
            ans += tot/2;
            tot = 0;
        }else{
            tot += A[i];
        }
    }
    ans += tot/2;
    pr(ans);
}

Measured memory_bytes: 4052