akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <map>

long long int H, W, N, a[112345], b[112345];
int px[] = { -1,-1,-1,0,0,0,1,1,1 }, py[] = { -1,0,1,-1,0,1,-1,0,1 };
std::map<std::pair<int, int>, int>xy;
long long int ans[10];

int main()
{
	scanf("%lld%lld%lld", &H, &W, &N);
	for (int i = 0; i < N; ++i) { scanf("%lld%lld", &a[i], &b[i]); }

	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 9; ++j)
		{
			int x = (a[i] - 1) + px[j], y = (b[i] - 1) + py[j];
			if ((x >= 1) && (x < H - 1)
				&& (y >= 1) && (y < W - 1))
			{
				++xy[std::pair<int, int>(x, y)];
			}
		}
	}
	for (auto iter = xy.begin(); iter != xy.end(); ++iter)
	{
		++ans[iter->second];
	}

	printf("%lld\n", ((H - 2)*(W - 2) - xy.size()));
	for (int i = 0; i < 9; ++i) { printf("%lld\n", ans[i + 1]); }
	return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> n >> k;
    vl l(n);
    NREP() {
        cin >> l[i];
    }
    sort(ALL(l), greater<ll>());

    ans = 0;

    REP(i, k) {
        ans += l[i];
    }

    MSG(ans)
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<int> t(n);
    for (int i=0; i<n; ++i) {
        cin >> t.at(i);
    }
    vector<int> v(n);
    for (int i=0; i<n; ++i) {
        cin >> v.at(i);
    }

    vector<int> time(n+1);
    for (int i=1; i<n+1; ++i) {
        time.at(i) = time.at(i-1) + t.at(i-1);
    }
    vector<function<double(double)>> f;
    f.push_back([=](double a){
        if (a < 0) return -a;
        else return a;
    });
    for (int i=0; i<n; ++i) {
        f.push_back([=](double a){
            if (a < time.at(i)) return v.at(i) + time.at(i) - a;
            else if (time.at(i+1) < a) return v.at(i) + a - time.at(i+1);
            else return (double)v.at(i);
        });
    }
    f.push_back([=](double a){
        if (a < time.back()) return time.back() - a;
        else return a - time.back();
    });

    double res = 0.0;
    for (double a=0.0; a<time.back(); a+=0.5) {
        pair<double, double> mini = {INF, INF};
        for (auto ff : f) {
            chmin(mini, make_pair(ff(a), ff(a+0.5)));
        }
        res += (mini.first + mini.second) * 0.5 / 2.0;
    }

    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 384
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
D, G = MAP()
pc = [LIST() for _ in range(D)]
count_min = 1000000000

#i番目の問題を完全に解くかをbitで場合わけしてからのfor　　O(D 2^D)
for i in range(1<<D):
	sum_ = 0
	count = 0
	i = list("{:b}".format(i).zfill(D))
	#print(i)
	for j in range(D):
		if i[j] == "1":    # j = "1" なら全部加える
			sum_ += (j+1)*100*pc[j][0] + pc[j][1]
			count += pc[j][0]
	if sum_ >= G:
		if count < count_min :
			#print("更新", count_min, "->", count)
			count_min = count
	else:  #中途半端にとる
		for j in range(D-1, -1, -1):
			if i[j] == "0":   # G-sum_ : 残りのポイント
				num = ceil((G-sum_)/((j+1)*100))
				#print(num)
				if num > pc[j][0]:
					count = 1000000000
					break
				count += ceil((G-sum_)/((j+1)*100))
				break
		if count < count_min:
			#print("更新", count_min, "->", count)
			count_min = count

print(count_min)

Measured memory_bytes: 13684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 110
#define Pair pair<int,int>

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    int N, K; cin >> N >> K;
    int h[N];
    int dp[N];
    for(int i = 0; i < N; i++){
        cin >> h[i];
        dp[i] = MM;
    }
    dp[0] = 0;

    for(int i = 0; i < N; i++){
        for(int j = 1; j <= K; j++){
            if(i+j < N){
                dp[i+j] = min(dp[i] + abs(h[i+j]- h[i]), dp[i+j]);
            }
        }
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    int n;cin >> n;cout << n / 2 + n % 2;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int cc = 0;
    for(int i = 100; i>= 1;i--){
        if( (a%i==0) && (b%i==0) ){
            cc++;
            if(cc == k){
                cout<<i<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

typedef pair<int,int> P;
int H,W;
char field[55][55];
int score[55][55];


void bfs(){
    queue<P> que;
    que.push(mp(0,0));
    
    while(sz(que) != 0){
        P ch = que.front(); que.pop();
        int i = ch.first, j = ch.second;
        rep(k,4){
            P next = mp(i+dx[k],j+dy[k]);
            if(next.first >= 0 && next.second >= 0 && next.first < H && next.second < W && field[next.first][next.second] != '#' && score[next.first][next.second] == 0){
                que.push(next);
                score[next.first][next.second] = score[i][j] + 1;
            }
        }
    }
    return;
}

int main(){
    cin >> H >> W;
    int ct = 0;
    rep(i,H) rep(j,W){
        cin >> field[i][j];
        if(field[i][j] == '.') ct++;
    }
    bfs();
    if(score[H-1][W-1] == 0) cout << -1 << '\n';
    else cout << ct - score[H-1][W-1] - 1 << '\n';
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;

long long frac(long long n) {
    long long res = 1;
    for (int i=1; i<=n; i++) res *= i;
    return res;
}
int main() {
    long long n;
    long double ans = 0;
    long double sum = 0;
    cin >> n;
    vector<long double> x(n);
    vector<long double> y(n);

    for (int i=0; i<n; i++) cin>>x[i]>>y[i];

    vector<int> c(n);
    iota(c.begin(), c.end(), 0);

    do {
        for (int i=0; i<n-1; i++) {
            sum += sqrt( pow(x[c[i]]-x[c[i+1]],2) + pow(y[c[i]]-y[c[i+1]],2));
        }
    } while(next_permutation(c.begin(), c.end()));

    cout << setprecision(14) << (sum/frac(n)) << endl;
}


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


Measured memory_bytes: 2028
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#define maxn 1000005
#define LL long long
#define mod 1000000007

using namespace std;

int x,y,a,b,c,num[3];
struct apples
{
    int c,val;
    bool operator <(const apples &a)const
    {
        if (val!=a.val) return val>a.val;
        else return c<a.c;
    }
}d[maxn];

int main()
{
    scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
    for (int i=0;i<a;i++) scanf("%d",&d[i].val),d[i].c=1;
    for (int i=a;i<a+b;i++) scanf("%d",&d[i].val),d[i].c=2;
    for (int i=a+b;i<a+b+c;i++) scanf("%d",&d[i].val),d[i].c=0;
    int n=a+b+c;
    sort(d,d+n);

    LL ans=0;
    for (int i=0;i<x+y;i++) num[d[i].c]++,ans+=d[i].val;
    if (num[1]<=x && num[2]<=y) printf("%lld\n",ans);
    else if (num[1]>x)
    {
        num[1]=0; int i=0; ans=0;
        while (num[1]<x && i<n)
        {
            if (d[i].c==1)
            {
                num[1]++;
                ans+=d[i].val;
            }
            i++;
        }
        num[2]=0; i=0;
        while (num[2]<y && i<n)
        {
            if (d[i].c!=1)
            {
                num[2]++;
                ans+=d[i].val;
            }
            i++;
        }
        printf("%lld\n",ans);
    }
    else if (num[2]>y)
    {
        num[2]=0; int i=0; ans=0;
        while (num[2]<y && i<n)
        {
            if (d[i].c==2)
            {
                num[2]++;
                ans+=d[i].val;
            }
            i++;
        }
        num[1]=0; i=0;
        while (num[1]<x && i<n)
        {
            if (d[i].c!=2)
            {
                num[1]++;
                ans+=d[i].val;
            }
            i++;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define LFOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define LREP(i, n) LFOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main()
{
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<int> l(k), r(k);
  for(int i = 0, cur = 0; i < n && cur < k;) {
    if (s[i] == 'x') {
      i++;
      continue;
    }
    l[cur] = i + 1;
    i += c + 1;
    cur++;
  }
  reverse(ALL(s));
  for(int i = 0, cur = 0; i < n && cur < k;) {
    if (s[i] == 'x') {
      i++;
      continue;
    }
    r[cur] = n - i;
    i += c + 1;
    cur++;
  }
  reverse(ALL(r));
  reverse(ALL(s));
  REP(i, k) {
    if (l[i] == r[i]) {
      cout << l[i] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3332
# coding: utf-8
# ?????????(?????????)????????°?????????????????????: BOOL
def integer_string?(str)
  Integer(str)
  true
rescue ArgumentError
  false
end
# mcxi????????????,10?????°??°????????????: INT
def mcxi_to_i(mcxi_s)
  result = 0;
  prefix_num = 1;
  mcxi_array = mcxi_s.split("")
  mcxi_array.each do |s|
    if(integer_string?(s))
      prefix_num = s.to_i
    else
      digit = 0
      case s
      when "m" then
        digit = 1000
      when "c" then
        digit = 100
      when "x" then
        digit = 10
      when "i" then
        digit = 1
      end
      result += prefix_num * digit
      prefix_num = 1
    end
  end
  result
end
# 10?????°?????°?????????mcxi??????????????????
def i_to_mcxi(i)
  str = ""
  digit = 1000
  while digit >= 1 do
    prefix = i / digit
    i -= prefix * digit
    mcxi_digit = ""
    if prefix != 0
      case digit
      when 1000
        mcxi_digit = "m"
      when 100
        mcxi_digit = "c"
      when 10
        mcxi_digit = "x"
      when 1
        mcxi_digit = "i"
      end
      if(prefix == 1)
        str << mcxi_digit
      else
        str << "#{prefix}#{mcxi_digit}"
      end
    end
    digit = digit / 10
  end
  str
end

line = gets
while line = gets do
  mcxi_a,mcxi_b = line.split
  a = mcxi_to_i(mcxi_a)
  b = mcxi_to_i(mcxi_b)
  sum = a + b
  puts i_to_mcxi(sum)
end

Measured memory_bytes: 9984
#include <iostream>

using namespace std;
int a,b,ans;
int main()
{
    cin >> a >> b;
    if (a > b){
        ans = a;
        a--;
    } else {
        ans = b;
        b--;
    }
    if (a > b){
        ans += a ;
        a--;
    } else {
        ans += b;
        b--;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
/*  2_3
    Y_Aizaki    */

#include <stdio.h>

int main(void){
    int row, white_square;

    scanf("%d", &row); //列の数
    scanf("%d", &white_square); //白マスの数
    printf("%d\n", (row * row) - white_square);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n;
    while(cin >> n, n){
        int m;
        cin >> m;
        int dx[8][11] = {0}, dy[8][11] = {0};
        int ax[11] = {0}, ay[11] = {0};
        rep(i, 0, m){
            cin >> ax[i] >> ay[i];
        }
        rep(i, 0, m){
            dx[0][i] = ax[i] - ax[0];
            dy[0][i] = ay[i] - ay[0];
            dx[1][i] = -dy[0][i];
            dy[1][i] = dx[0][i];
            dx[2][i] = -dx[0][i];
            dy[2][i] = -dy[0][i];
            dx[3][i] = dy[0][i];
            dy[3][i] = -dx[0][i];
        }
        vector<int> ans;
        rep(t, 1, n + 1){
            int am;
            cin >> am;
            int bx[11] = {0}, by[11] = {0};
            rep(i, 0, am){
                cin >> bx[i] >> by[i];
            }
            if(am != m) continue;
            rep(i, 0 ,am){
                int tx[11], ty[11];
                rep(j ,0, am){
                    tx[j] = bx[j] - bx[i];
                    ty[j] = by[j] - by[i];
                }
                rep(j, 0, 4){
                    rep(k, 0, m){
                        if(!(tx[k] == dx[j][k] && ty[k] == dy[j][k])) break;
                        if(k == m - 1){
                            ans. push_back(t);
                            j = 4; i = m; break;
                        }
                    }
                    rep(k, 0, m){
                        if(!(tx[k] == dx[j][m - 1 - k] && ty[k] == dy[j][m - 1 - k])) break;
                        if(k == m - 1){
                            ans. push_back(t);
                            j = 4; i = m; break;
                        }
                    }
                }
            }
        }
        rep(i, 0, ans.size()){
            cout << ans[i] << endl;
        }
        cout << "+++++" << endl;
    }
}

Measured memory_bytes: 1220
s = input()
ans = "YES"
while len(s) > 0:
  if s[-5:] == "dream":
    s = s[:-5]
  elif s[-7:] == "dreamer":
    s = s[:-7]
  elif s[-5:] == "erase":
    s = s[:-5]
  elif s[-6:] == "eraser":
    s = s[:-6]
  else:
    ans = "NO"
    break
print(ans)

Measured memory_bytes: 3188
use proconio::input;
use proconio::marker::Chars;
use std::collections::VecDeque;

fn main() {
    input! {
        s: Chars,
        mut q: usize,
    }

    let mut queue = VecDeque::new();
    for c in s {
        queue.push_back(c);
    }

    let mut opposite = false;
    for _ in 0..q {
        input! {
            t: usize,
        }
        if t == 1 {
            opposite = !opposite;
        } else {
            input! {
                f: usize,
                c: char,
            }
            if (f == 1 && !opposite) || (f != 1 && opposite) {
                queue.push_front(c);
            } else {
                queue.push_back(c);
            }
        }
    }
    if !opposite {
        // while queue.len() > 0 {
        //     print!("{}", queue.pop_front().unwrap());
        // }
        println!("{}", queue.iter().collect::<String>());
    } else {
        // while queue.len() > 0 {
        //     print!("{}", queue.pop_back().unwrap());
        // }
        println!("{}", queue.iter().rev().collect::<String>());
    }
    // println!("");
}


Measured memory_bytes: 5016
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,ans=0;
    cin>>n>>k;
    vector<int> p(n);
    for(int i=0;i<n;i++){
    	cin>>p[i];
    }
    sort(p.begin(),p.end());
    for(int i=0;i<k;i++){
    	ans+=p[i];
    }
  cout<<ans;
}


Measured memory_bytes: 3632
import sys
import math

n = int(input())

for _ in range(n):
    xa, ya, ra, xb, yb, rb = map(float, input().split())

    distance = math.sqrt((xa-xb)**2 + (ya-yb)**2)
    if ra + rb >= distance:
        if (distance + ra < rb):
            print(-2)
        elif (distance + rb < ra):
            print(2)
        else:
            print(1)
    else:
        print(0)

Measured memory_bytes: 6836
#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(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  string s;
  cin>>s;
  s.erase(unique(s.begin(),s.end()),s.end());
  if(s.size()!=4) cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
  return 0;
}


Measured memory_bytes: 256
import math

def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
    

def Koch(n, x1,y1, x2,y2):
    if n == 0:
        plot(x1,y1)
        return
    sx = (2 * x1 + x2) / 3
    sy = (2 * y1 + y2) / 3
    tx = (x1 + x2 * 2) / 3
    ty = (y1 + y2 * 2) / 3
    ux = (tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy = (tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    Koch(n-1, x1,y1, sx,sy)
    Koch(n-1, sx,sy, ux,uy)
    Koch(n-1, ux,uy, tx,ty)
    Koch(n-1, tx,ty, x2,y2)

n = int(input())
Koch(n, 0,0, 100,0)    
plot(100,0)


Measured memory_bytes: 5748
# coding: utf-8
# Your code here!

S = input()
N = len(S)

ans = 0
for i in range(N):
    for j in range(i,N):
        if all('ACGT'.count(c)==1 for c in S[i:j+1]):
            ans = max(ans, j-i+1)
print(ans)
        
        


Measured memory_bytes: 8920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		var N = GetLong();
		var K = GetLong();

		var code = GetString().Select(x => (long)(x - '0')).ToArray();
		var list = compress(N, code);
		var queue = new Queue<Tuple<long, long>>();
		long cnt = 0;
		long sum = 0;
		long max = 0;
		for(int i = 0, L = list.Count; i < L; i++)
		{
			queue.Enqueue(list[i]);
			sum += list[i].Item2;
			if(list[i].Item1 == 0)
				cnt++;

			while(cnt > K)
			{
				var top = queue.Dequeue();
				sum -= top.Item2;
				if(top.Item1 == 0)
					cnt--;
			}
			chmax(ref max, sum);
		}
		WriteLine(max);
	}

	private List<Tuple<long, long>> compress(long N, long[] code)
	{
		var res = new List<Tuple<long, long>>();
		long cnt = 1;
		for(long i = 1; i < N; i++)
		{
			if(code[i] == code[i - 1])
			{
				cnt++;
			}
			else
			{
				res.Add(Tuple.Create(code[i - 1], cnt));
				cnt = 1;
			}
		}
		res.Add(Tuple.Create(code[N - 1], cnt));
		return res;
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

int main(){
        vector<int> a(5);
        int d;
        for(int i=0;i<5;i++)cin>>a[i];
        cin>>d;
        if(a[4]-a[0] <= d)cout<<"Yay!"<<endl;
        else cout<<":("<<endl;

        return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

long long int INF = 1e18;
using namespace std;

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

int main(){
	
	int n;
	cin >> n;
	
	string A[2000], B[2000];
	for(int i = 0; i < n; i++){
		cin >> A[i];
		B[i] = A[i];
	}
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n - 1; j++){
			if(A[j][1] > A[j + 1][1]){
				swap(A[j], A[j + 1]);
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		int minj = i;
		for(int j = i; j < n; j++){
			if(B[j][1] < B[minj][1]){
				minj = j;
			}
		}
		if(B[i][1] != B[minj][1]){
			swap(B[i], B[minj]);
		}
	}
	
	for(int i = 0; i < n - 1; i++){
		cout << A[i] << " ";
	}
	cout << A[n - 1] << endl;
	
	cout << "Stable" << endl;
	
	bool flag = true;
	for(int i = 0; i < n - 1; i++){
		if(A[i] != B[i]){
			flag = false;
		}
		cout << B[i] << " ";
	}
	cout << B[n - 1] << endl;
	
	if(flag){
		cout << "Stable" << endl;
	}else{
		cout << "Not stable" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3252
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/


int main() {
    int n, t, a;
    cin >> n >> t >> a;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    double ans;
    int ind;

    for (int i = 0; i < n; i++) {
        double num = t - h[i] * 0.006;
        double temp = abs(num - a);

        if (i == 0) {
            ans = temp;
            ind = 1;
        }
        else {
            if (ans > temp) {
                ans = min(temp, ans);
                ind = i + 1;
            }
        }
    }
    
    cout << ind << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

int main() {
int n;
cin >> n;
vector<int> d(n);
for(int i = 0; i < n; i++) 
  cin >> d[i];
int ans = 0;
for(int i = 0; i < n; i++) {
	for(int j = i + 1; j < n; j++) {
		ans += d[i] * d[j];
	}
}
cout << ans;
 return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <stack>

using namespace std;

void solve()
{
	int n, r;
	while(cin >> n >> r, n , r)
	{
		int p, c;
		stack<int> data;
		stack<int> buf1;
		stack<int> buf2;
		for(int i = 1; i <= n; ++i)
		{
			data.push(i);
		}
		while(r--)
		{
			cin >> p >> c;
			for(int i = 0; i < p - 1; ++i)
			{
				buf1.push(data.top());
				data.pop();
			}
			for(int i = 0; i < c; ++i)
			{
				buf2.push(data.top());
				data.pop();
			}
			int size1 = buf1.size();
			int size2 = buf2.size();
			for(int i = 0; i < size1; ++i)
			{
				data.push(buf1.top());
				buf1.pop();
			}
			for(int i = 0; i < size2; ++i)
			{
				data.push(buf2.top());
				buf2.pop();
			}
		}
		cout << data.top() << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
import itertools
# import math

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# A, B, X = map(int, input().split())
# P = list(map(int, input().split()))
# Q = list(map(int, input().split()))
P = list(input().split())
Q = list(input().split())
# S = input()

P_str = ''.join(P)
Q_str = ''.join(Q)


all_cases = list(itertools.permutations(P))
all_cases_str = []
for l in all_cases:
    all_cases_str.append(''.join(l))
all_cases_str = sorted(all_cases_str)

a = 0
b = 0
cnt = 0

for s in all_cases_str:
    cnt += 1
    # print(s)
    if P_str == s:
        a = cnt
    if Q_str == s:
        b = cnt

print(abs(a-b))

Measured memory_bytes: 17316
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec.at(i);
	vector<bool> ans(n, true);

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		int x = vec.at(a - 1);
		int y = vec.at(b - 1);

		if (x < y) ans.at(a - 1) = false;
		else if (x > y) ans.at(b - 1) = false;
		else {
			ans.at(a - 1) = false;
			ans.at(b - 1) = false;
		}
	}

	int res = 0;
	for (int i = 0; i < n; i++) {
		if (ans.at(i)) res++;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3788
def Sieve_of_Eratosthenes(N):
    if N<2:
        prime = [False for i in range(N+1)]
        return prime
 
    prime = [True for i in range(N+1)]
    prime[0] = False
    prime[1] = False
 
    for i in range(2, int(N**0.5)+1):
        if prime[i]:
            for j in range(i*2, N+1, i):
                prime[j] = False
 
    return prime

prime=Sieve_of_Eratosthenes(10**5+5)
x=int(input())
while prime[x]==False:
    x+=1
print(x)

Measured memory_bytes: 44784
X, Y = [int(n) for n in input().split()]
V = {0: 400000, 1: 300000, 2: 200000, 3: 100000}
ans = 0
for i in [X, Y]:
    ans += V.setdefault(i, 0)
print(ans+V[0] if X==1==Y else ans)


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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
template< typename G >
struct StronglyConnectedComponents {
  const G &g;
  UnWeightedGraph gg, rg;
  vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return comp[k];
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(UnWeightedGraph &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
  }
};

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n,m;
  cin>>n>>m;
  UnWeightedGraph g(n),buff;
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
  }
  StronglyConnectedComponents<UnWeightedGraph> scc(g);
  scc.build(buff);
  vector<set<ll>> res(n);
  rep(i,n){
    rep(j,n){
      if(scc[i]==scc[j]){
        res[i].insert(j);
      }
    }
  }
  rep(i,n){
    for(auto x:res[i]){
      cout<<x+1;
      if(x!=*--res[i].end())cout<<" ";
    }
    cout<<endl;
  }

  


}



Measured memory_bytes: 8800
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <assert.h>

using namespace std;

const int inf = 1 << 30;
const long long base = (int) 1e6 + 3;

inline long long Hash( int a, int b ) {
	return (a * base) + b;
}

int main( void ) {
	int n, m;
	scanf("%i %i", &n, &m);
	
	vector<vector<pair<int,int>>> g(n+1);
	for( int i = 1; i <= m; i++ ) {
		int u, v, c;
		scanf("%i %i %i", &u, &v, &c);
		
		g[u].push_back(make_pair(c, v));
		g[v].push_back(make_pair(c, u));
	}
	
	for( int i = 1; i <= n; i++ ) {
		sort(g[i].begin(), g[i].end());
	}
	
	queue<int> Q;
	vector<int> cost(n+1, inf);
	vector<bool> visited(n+1, false);
	unordered_set<long long> seen;
	
	cost[1] = 0;
	visited[1] = true;
	Q.push(1);
	
	while( !Q.empty() ) {
		int u = Q.front(); Q.pop();
		
		for( auto edge : g[u] ) {
			int v = edge.second, c = edge.first;
						
			if( (cost[v] >= cost[u] + 1) && !seen.count(Hash(v, c)) ) {
				cost[v] = cost[u] + 1;
				
				queue<int> q;
				
				seen.insert(Hash(v, c));
				q.push(v);
				
				while( !q.empty() ) {
					int a = q.front(); q.pop();
					
					if( !visited[a] ) {
						Q.push(a);
						visited[a] = true;
					}
			
					int idx = lower_bound(g[a].begin(), g[a].end(), make_pair(c, 0)) - g[a].begin();					
					for( int i = idx; i < g[a].size(); i++ ) {
						if( g[a][i].first != c ) {
							break;
						}
				
						int b = g[a][i].second;
						if( !seen.count(Hash(b, c)) ) {
							seen.insert(Hash(b, c));
							cost[b] = min(cost[b], cost[v]);
							q.push(b);
						} 
					}
				}
			}
		}
	}
	
	printf("%i\n", (cost[n] < inf) ? cost[n] : -1);
	
	return 0;
}

Measured memory_bytes: 25156
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]

for k in range(1, H - 1):
    for i in range(1, W - 1):
        if S[k][i] == "#":
            if S[k][i + 1] != "#" and S[k + 1][i] != "#" and \
               S[k - 1][i] != "#" and S[k][i - 1] != "#":
                print("No")
                exit()

for i in range(1, W - 1):
    if S[0][i] == "#":
        if S[0][i + 1] != "#" and S[1][i] != "#" and S[0][i - 1] != "#":
            print("No")
            exit()

    if S[H - 1][i] == "#":
        if S[H - 1][i + 1] != "#" and S[H - 2][i] != "#" and \
           S[H - 1][i - 1] != "#":
            print("No")
            exit()

for i in range(1, H - 1):
    if S[i][0] == "#":
        if S[i + 1][0] != "#" and S[i - 1][0] != "#" and S[i][1] != "#":
            print("No")
            exit()

    if S[i][W - 1] == "#":
        if S[i + 1][W - 1] != "#" and S[i - 1][W - 1] != "#" and \
           S[i][W - 2] != "#":
            print("No")
            exit()

if S[0][0] == "#":
    if S[0][1] != "#" and S[1][0] != "#":
        print("No")
        exit()

if S[0][W - 1] == "#":
    if S[0][W - 2] != "#" and S[1][W - 1] != "#":
        print("No")
        exit()

if S[H - 1][0] == "#":
    if S[H - 2][0] != "#" and S[H - 1][1] != "#":
        print("No")
        exit()

if S[H - 1][W - 1] == "#":
    if S[H - 1][W - 2] != "#" and S[H - 2][W - 1] != "#":
        print("No")
        exit()

print("Yes")

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

int main(){
	string in[1001];
	int num[1001], i=0, max=0, lon=0, ansa, ansb;

	for(int i=0;i<1001;i++){
		num[i] = 0;
	}

	while (true)
	{
		cin >> in[i];
		if (cin.eof()||in[i] == "0") { break; }
		for(int j=0;j<i;j++){
			if(in[i] == in[j]){
				num[j]++;
				continue;
			}
		}
		i++;
	}
	for(int j=0;j<i;j++){
		if (max < num[j]) {
			max = num[j];
			ansa = j;
		}
		if (lon < in[j].size()) {
			lon = in[j].size();
			ansb = j;
		}
	}
	cout << in[ansa] << " " << in[ansb] << endl;
	return 0;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
char s[1001];
int sum[1001],f[10001];
main(){
    //file("");
	scanf("%s",s+1);
	int K=read(),n=strlen(s+1),ans=0;
	if(n==1&&K==1) cout<<"0",exit(0);
	if(n==1&&K>=2)
		cout<<K/2,exit(0);
	for(int i=1;i<=n;i++)
		if(s[i]==s[i-1])
			sum[i]=sum[i-1]+1;
		else sum[i]=1;
	int tot=0;
	for(int i=n;i>=1;i--)
		if(s[i]!=s[i+1])
			f[++tot]=sum[i];
	for(int i=2;i<tot;i++)
		ans+=f[i]/2*K;
	if(s[n]==s[1]) {
		if(tot==1)
			ans+=f[tot]*K/2;
		else
		ans+=(f[1]+f[tot])/2*(K-1)+(f[1]/2+f[tot]/2);
	}
	else ans+=(f[1]/2+f[tot]/2)*K;
	cout<<ans;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define out(n) cout << (n) << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n, ans = 0;

  cin >> n;

  vector<int> a(n);

  rep(i, 0, n) cin >> a[i], ans += a[i];

  if(ans % 10 != 0) {
    out(ans);
    return 0;
  }

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

  rep(i, 0, n) {
    if(a[i] % 10 != 0) {
      out(ans - a[i]);
      return 0;
    }
  }

  out(0);
}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N = i()
A = l()
A.sort(reverse=True)
ans = 0
lis = [A[0]]
A = A[1:]
for i in range(N-1):
    lis.append(A[i])
    lis.append(A[i])
for i in range(N-1):
    ans += lis[i]
print(ans)

Measured memory_bytes: 128660
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

#define MAX_V 11000

int V;
vector<int> G[MAX_V]; // グラフの隣接リスト表現
vector<int> rG[MAX_V];// 辺の向きを逆にしたグラフ
vector<int> vs;       // 帰りがけ順の並び
bool used[MAX_V];     // すでに調べたか
int cmp[MAX_V];       // 属する強連結成分のトポロジカル順序

// from から to への辺を張る関数
void add_edge(int from, int to){
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v){
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i]]){
			dfs(G[v][i]);
		}
	}
	vs.push_back(v);
}

void rdfs(int v, int k){
	used[v] = true;
	cmp[v] = k;
	for(int i = 0; i < rG[v].size(); i++){
		if(!used[rG[v][i]]){
			rdfs(rG[v][i], k);
		}
	}
}

// 強連結成分分解を行う関数、返り値は強連結成分の個数
int scc(){
	memset(used, 0, sizeof(used));
	vs.clear();
	for(int v = 0; v < V; v++){
		if(!used[v]){
			dfs(v);
		}
	}
	memset(used, 0, sizeof(used));
	int k = 0;
	for(int i = vs.size() - 1; i >= 0; i--){
		if(!used[vs[i]]){
			rdfs(vs[i], k++);
		}
	}
	return k;
}

int main(){
	
	int E, Q;
	
	cin >> V >> E;
	
	// s から t への有向辺を張る
	for(int i = 0; i < E; i++){
		int s, t;
		cin >> s >> t;
		add_edge(s, t);
	}
	
	cout << (scc() < V) << endl;
	
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
void f(set<int> &s,vector<int> &a,vector<int> &p,vector<int> &c,int &g,int &answer){
  int i,ans=0,tot=0;
  if (s.size()==0){
    ans=0,tot=0;
    for(i=0;i<a.size();i++){
      tot+=p.at(a.at(i))*100*(a.at(i)+1)+c.at(a.at(i));
      ans+=p.at(a.at(i));
      if(tot>=g) break;
    }
    tot-=c.at(a.at(i))+100*(a.at(i)+1);
    ans--;
    while(tot>=g){
      tot-=100*(a.at(i)+1);
      ans--;
    }
    ans++;
    answer=min(answer,ans);
  }
  else{
    set<int> t=s;
    for(auto b:t){
      a.push_back(b);
      s.erase(b);
      f(s,a,p,c,g,answer);
      a.pop_back();
      s.insert(b);
    }
  }
}
int main(){
  int d,g,i,answer=1000;
  cin>>d>>g;
  vector<int> p(d),c(d),a;
  set<int> s;
  for(i=0;i<d;i++){
    cin>>p.at(i)>>c.at(i);
    s.insert(i);
  }
  f(s,a,p,c,g,answer);
  cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,a,b,i,j,k,n;
    cin>>n>>k>>a>>b;
    i=0;
    cout<<min(k,n)*a+max(i,(n-k))*b<<endl;
    return 0;
}


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

constexpr int P = 1000000007;

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

    char s[2][64];
    for (int i = 0; i < 2; i++) {
        cin >> s[i];
    }

    int64_t t = 3;
    int64_t r = 1;
    for (int i = 0; i < n; i++) {
        if (s[0][i] == s[1][i]) {
            r *= t;
            r %= P;
            t = 2;
        } else {
            r *= t == 2 ? 2 : t == 3 ? 6 : 3;
            r %= P;
            t = 1;
            i++;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
function Main(arg) {
  let n = Number(arg.trim());
  if(n%1000 == 0){
    console.log(0);
    return;
  }
  let pay = 0;
  while(pay < n){
    pay+=1000;
  }
  console.log(pay-n);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

Scanner sc = new Scanner(System.in);
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();

int x3,y3,x4,y4,lx,ly;
lx=x2-x1;
ly=y2-y1;

y3=y2+lx;
x3=x2-ly;

y4=y3-ly;
x4=x3-lx;


System.out.println(x3+" "+y3+" "+x4+" "+y4);


sc.close();

	}


}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 25, M = 1e6 + 25, oo = 1e9, mod = 1e9 + 7;
const long long OO = 1e18+25;

int l1,l2, mem[N][N];
char s1[N], s2[N];

long long dp(int i=0, int j=0)
{
    if(i == l1 || j == l2) return 0;
    int &ret = mem[i][j];
    if(ret != -1) return ret;
    if(s1[i] == s2[j]) return ret = dp(i+1, j+1)+1;
    return ret = max(dp(i+1, j), dp(i,j+1));
}

void lcs(int i=0, int j=0)
{
    if(i == l1 || j == l2) return;
    int &ret = mem[i][j];
    if(s1[i] == s2[j]) 
    {
        printf("%c",s1[i]);
        lcs(i+1, j+1);
    }else if(mem[i+1][j] >= mem[i][j+1]) lcs(i+1, j);
    else lcs(i, j+1);
}

int main()
{
    memset(mem, -1, sizeof mem);
    scanf("%s%s",s1,s2);
    l1 = strlen(s1);
    l2 = strlen(s2);
    if(dp()) lcs();
    return 0;
}
	     		 					   	 	 								 	

Measured memory_bytes: 36224
n = int(input())
list1 = list(map(int,input().split()))
list2=list(map(int,input().split()))

a = list1[0]
b = list1[1]

num0 = sum([1 for p in list2 if p <=a])
num2 = sum([1 for p in list2 if p > b])
num1 = n - num0 -num2
print(min([num0,num1,num2]))

Measured memory_bytes: 3064
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl;
#define wa() cout<<"No"<<endl;
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
const int maxm=3e3+5;
const int mod=998244353;


signed main(){
    str s;cin>>s;
    map<char,int>mark;
    for(auto v:s)mark[v]++;
    if(mark.size()==2)puts("Yes");
    else puts("No");

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 
 
int dp[101][4][4][4];
 
int main() {
	int N;
	cin >> N;
	dp[0][3][3][3] = 1;
 
	int mod = 1'000'000'007;

	for (int len = 0; len < N; len++){
		for (int c1 = 0; c1 < 4; c1++){
			for (int c2 = 0; c2 < 4; c2++){
				for (int c3 = 0; c3 < 4; c3++){
					if (dp[len][c1][c2][c3] == 0) continue;
					for (int a = 0; a < 4; a++){
						if (a == 2 && c1 == 1 && c2 == 0) continue;
						if (a == 2 && c1 == 0 && c2 == 1) continue;
						if (a == 1 && c1 == 2 && c2 == 0) continue;
						if (a == 2 && c1 == 1 && c3 == 0) continue;
						if (a == 2 && c2 == 1 && c3 == 0) continue;
						dp[len + 1][a][c1][c2] += dp[len][c1][c2][c3];
						dp[len + 1][a][c1][c2] %= mod;
					}
				}
			}
		}
	}
 
	int ans = 0;
	for (int c1 = 0; c1 < 4; c1++){
		for (int c2 = 0; c2 < 4; c2++){
			for (int c3 = 0; c3 < 4; c3++){
				ans += dp[N][c1][c2][c3];
				ans %= mod;
			}
		}
	}
 
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a;
  cin >>a;
  if(a==22){
    cout << "Christmas Eve Eve Eve" << endl;
  }else if(a==23){
    cout << "Christmas Eve Eve" << endl;
  }else if(a==24){
    cout << "Christmas Eve" << endl;
  }else{
    cout << "Christmas" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
    int main() {
      string x;
      cin >> x;
      
      if (x == "abc" || x == "bac" || x == "cab" || x == "bca" || x == "acb" || x == "cba") {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    } 

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int x, y, z;
	scanf("%d%d", &x, &y);

	while(1){
		if(x%y!=0){
			z=x%y;
			x=y;
			y=z;
		
		}else{
			break;
		}
	}
	
	printf("%d\n", y);

return 0;

}

	

Measured memory_bytes: 592