akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                 
                                        using namespace std;

int par[500100],ranks[500100],kosuu[500100];     

void shoki(int n){
	for(int i=0;i<n;i++){
		par[i]=i;
		ranks[i]=0;
		kosuu[i]=1;
	}
}

int root(int x){
	return par[x]==x ? x : par[x]=root(par[x]);
}

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

void unite(int x,int y){
 x=root(x);
 y=root(y);
	int xx=kosuu[x],yy=kosuu[y];
 if(x==y) return;
	if(ranks[x]<ranks[y]){
		par[x]=y;
		kosuu[y]=yy+xx;
	}
 else {
	par[y]=x;
	if(ranks[x]==ranks[y]) ranks[x]=ranks[x]+1;
 	kosuu[x]=yy+xx;
 }
	return;
}

int gcd(int a1,int a2){
	if(a1<a2) return gcd(a2,a1);
	if(a2==1) return 1;
	if(a1%a2==0) return a2;
	return gcd(a2,a1%a2);
}


int rui2(int e,int r){
	if(r==0) return 1;
	if(r==1) return e%inf;
	if(r%2==1) return (e*rui2(e,r-1))%inf;
	int w=rui2(e,r/2)%inf;
	return (w*w)%inf;
}


int dp[1000][1000]={0};
            signed main(){
   int l,k;
            	cin>>l>>k;
            	
            	dp[0][1]=1;
            	dp[0][k]=1;
            	for(int i=1;i<100;i++){
            		for(int j=0;j<=l;j++){
            			if(j-2>=0){
            				dp[i][j]+=dp[i-1][j-2];
            			}
            			if(j-k-1>=0){
            				dp[i][j]+=dp[i-1][j-k-1];
            			}
            		}
            	}
            	int ans=0;
            	
            	for(int i=0;i<500;i++)for(int j=0;j<=l;j++)ans+=dp[i][j];
            	
            //	cout<<(ans>5 ? "yes":"no")<<endl;
            	
            	cout<<ans<<endl;
            	return 0;
            }
             

Measured memory_bytes: 3576
#include <queue>
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
int INF = 1000000000;

vector<int> dijkstra(int s, int v, vector< vector<pii> > G){
  //s: 始点, v: 頂点数, G: 隣接リスト
  priority_queue<pii> wait;
  vector<int> result(v, INF);
  result[s] = 0;
  wait.push(make_pair(0, s));
  while(!wait.empty()){
    int nowpoint = wait.top().second;
    int nowcost = wait.top().first;
    wait.pop();
    if(nowcost <= result[nowpoint]){
      for(int i = 0; i < G[nowpoint].size(); ++i){
	int nextpoint = G[nowpoint][i].second;
	int nextcost = -nowcost + G[nowpoint][i].first;
	if(nextcost < result[nextpoint]){
	  wait.push(make_pair(-nextcost, nextpoint));
	  result[nextpoint] = nextcost;
	}
      }
    }
  }
  return result;
}

int main(){
  int N;
  cin >> N;
  vector< vector<pii> > G(N);
  int a, b;
  for(int i = 0; i < N-1; ++i){
    cin >> a >> b;
    --a;--b;
    G[a].push_back(make_pair(1,b));
    G[b].push_back(make_pair(1,a));
  }

  vector<int> dist_to_1 = dijkstra(0,N,G), dist_to_N = dijkstra(N-1,N,G);
  int ans = 0;

  for(int i = 0; i < N; ++i){
    if(dist_to_1[i] <= dist_to_N[i]) ++ans;
    else --ans;
  }
  if(ans > 0) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
  return 0;
}


Measured memory_bytes: 12980
# -*- coding: utf-8 -*-
import sys


N,M=[int(i) for i in input().rstrip().split()]
ab_list=[[int(j) for j in input().split()] for i in range(M)]
#-----

vertex_dic={}  # dic{int:set()}

for va,vb in ab_list:
    vertex_dic.setdefault(va,set())
    vertex_dic[va].add(vb)
    vertex_dic.setdefault(vb,set())
    vertex_dic[vb].add(va)


def check(vertex_dic :dict, passed :set, start :int):
    if len(vertex_dic) == len(passed):
        return 1
    
    next_set = vertex_dic[start] - passed # :set
    
    ans=0
    for i_next in next_set:
        next_passed = passed | {i_next}
        ans += check(vertex_dic, next_passed, i_next)
    
    return ans
    

result=check(vertex_dic, {1}, 1 )
print(result)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main(){
	char m[9];
	while(1){
		for(int i=0;i<9;i++){
			cin >> m[i];
			if(m[i]=='0')return 0;
		}
		string win = "NA";
		for(int i=0;i<3;i++){
			if(m[i*3]!='+' && m[i*3]==m[i*3+1] && m[i*3+1]==m[i*3+2])
				win = m[i*3];
			if(m[ i ]!='+' && m[ i ]==m[ i+3 ] && m[ i+3 ]==m[ i+6 ])
				win = m[i];
		}
		if(m[4]!='+' && m[0]==m[4] && m[4]==m[8])
			win = m[4];
		if(m[4]!='+' && m[2]==m[4] && m[4]==m[6])
			win = m[4];
 
		cout << win << endl;		
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int N=3e3+5;
const int MD=998244353;
int fac[N],inv[N];
int f[N][N<<1];
void init() {
	fac[0]=inv[0]=fac[1]=inv[1]=1;
	for(int i=2;i<N;i++) fac[i]=1LL*fac[i-1]*i%MD,inv[i]=1LL*(MD-MD/i)*inv[MD%i]%MD;
	for(int i=2;i<N;i++) inv[i]=1LL*inv[i]*inv[i-1]%MD;
}
int C(int n,int m) {return 1LL*fac[n]*inv[m]%MD*inv[n-m]%MD;}
int add(int &x,int y) {
	x+=y;
	if(x>=MD) x-=MD;
}
int main() {
	init();
	int n,x;
	scanf("%d%d",&n,&x);
	f[0][0]=1;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=x;j++) {
			add(f[i][j],f[i-1][j-1]);
			if(j>1) add(f[i][j],f[i-1][j-2]);
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++) {
		int s=0;
		for(int j=0;j<x-1;j++) add(s,f[i][j]);
		for(int j=0;j<=i;j++) {
			if(i-j<=j&&x-1-2*(i-j)>=0) add(s,f[j-(i-j)][x-1-2*(i-j)]);
			else if(i-j>j&&j*2==x-1) add(s,1);
		}
		add(ans,1LL*C(n,i)*s%MD);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 70656
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	line1 := nextInt()

	numMap := map[int]int{}
	var count int
	for i := 0; i < line1[0]; i++ {
		n := nextInt()[0]
		if numMap[n] == 0 {
			count++
			numMap[n] = 1
		}
	}

	fmt.Println(count)
}

// ------ Mathライブラリ ---------------------------------//
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func maxIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

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

// ------ Mathライブラリ ---------------------------------//

// ----- 標準入力用の関数 ----------------------------------//
var nextReader func() []string

func NewScanner() func() []string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	return func() []string {
		r.Scan()
		return strings.Fields(r.Text())
	}
}

func nextString() []string {
	return nextReader()
}

func nextInt() []int {
	var intArray []int
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.Atoi(v)
		intArray = append(intArray, i)
	}
	return intArray
}

func nextFloat64() []float64 {
	var floatArray []float64
	strArray := nextReader()
	for _, v := range strArray {
		f, _ := strconv.ParseFloat(v, 64)
		floatArray = append(floatArray, f)
	}
	return floatArray
}

// ------ 標準入力用の関数 ---------------------------------//

// ------ あまり使わない -----------------------------------//
func nextInt64() []int64 {
	var int64Array []int64
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.ParseInt(v, 10, 64)
		int64Array = append(int64Array, i)
	}
	return int64Array
}

// ------ あまり使わない -----------------------------------//


Measured memory_bytes: 640
/************************************************************
	> File Name: a.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 22 Dec 2019 10:03:28 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
//#include <unordered_map>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
int main(void){
	int a[2];
	scanf("%d%d",a,a+1);
	sort(a,a+2);
	if(a[0]==1&&a[1]==2)
		printf("3\n");
	else if(a[0]==1&&a[1]==3)
		printf("2\n");
	else if(a[0]==2&&a[1]==3)
		printf("1\n");
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()

import heapq
from collections import defaultdict
h = []
heapq.heapify(h)

n, m, s = list(map(int, input().split()))
a, b = [[None] * m for _ in range(2)]
c, d = [[None] * n for _ in range(2)]

ns = defaultdict(list)
uv2e = {}
for i in range(m):
    u,v,a[i],b[i] = list(map(int, input().split()))
    ns[u-1].append(v-1)
    ns[v-1].append(u-1)
    uv2e[u-1,v-1] = i
    uv2e[v-1,u-1] = i
for i in range(n):
    c[i], d[i] = list(map(int, input().split()))

maxs = max(a)*(n-1)
s = min(s, maxs)
state = (0, 0, s) # (距離, ノード, 銀貨枚数)
ans = [[None] * (maxs+1) for _ in range(n)]
heapq.heappush(h, state)
count = 0
while h:
    count += 1
    dd, u, ss = heapq.heappop(h)
#     print(dd, u, ss)
    if ans[u][ss] is not None and ans[u][ss] <= dd:
        continue
    ans[u][ss] = dd
    
    # グラフの隣接点
    for v in ns[u]:
        e= uv2e[u,v]
        if ss<a[e] or ans[v][ss-a[e]] is not None:
            continue
        heapq.heappush(h, (dd + b[e], v, ss-a[e]))
    # 両替
    if ss+c[u] <= maxs:
        heapq.heappush(h, (dd + d[u], u, ss+c[u]))
    elif ss < maxs:
        heapq.heappush(h, (dd + d[u], u, maxs))

for item in ans[1:]:
    print(min(item))

Measured memory_bytes: 124720
n = int(input())
x = list( map(int, input().split()))


def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod

ans = 0
MOD = 10**9 + 7

factorial = 1
for i in range(2,n):
    factorial = (factorial * i%MOD) %MOD

p = [0]*(n-1)
p[0] = 1 * factorial%MOD

for i in range(1,n-1):
    p[i] = p[i-1] + factorial*mod_inv(i+1,MOD)
    p[i] %= MOD

for i in range(n-1):
    ans += (x[i+1]-x[i])%MOD*p[i]
    ans %= MOD

print(int(ans))



Measured memory_bytes: 14252
from heapq import heappush, heappop
N, M = map(int, input().split())

ab = [[int(i) for i in input().split()] for _ in range(M)]

ab.sort(key=lambda x: x[1])
ab.sort()

ret = 1
end = float('inf')
for a, b in ab :
    if a >= end :
        ret += 1
        end = b
    else :
        end = min(end, b)

print(ret)

Measured memory_bytes: 64600
// https://github.com/PabloMessina/Competitive-Programming-Material/blob/master/Codejam_template.cpp
#pragma GCC optimize("Ofast") // OPTIONAL: for faster execution
#include <bits/stdc++.h>      // import everything in one shot
using namespace std;
// defines
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define invrep(i, a, b) for (int i = b - 1; i >= a; --i)
#define umap unordered_map
#define uset unordered_set
// typedefs
typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
// -------------------------------

int main()
{
    // OPTIONAL: for faster input/output (only if using cin/cout)
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N, X, T;
    cin >> N >> X >> T;
    cout << (N / X + (N%X != 0)) * T << endl;
    return 0;
}

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

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

    long long int a,b,f,min=10000000000;
    
    // 整数/0をやるとfloatin point exceptionのエラーが出るのでi=1から始める
    // i*i<=nでやってもiはなぜかこの条件をすり抜ける
    for(int i=1;i<=n/i;i++){
        f=1;
        if(n%i==0){
            a=i;
            b=n/a;
            while(b>0){
                if(b/10!=0){
                    f++;
                }
                b/=10;
            }
            if(f<min) min=f;
        }
    } 

    cout<<min<<endl;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b, q;

	cin>>a>>b>>q;

	vll s(a), t(b);

	rep(i, a) cin>>s[i];

	rep(i, b) cin>>t[i];

	rep(i, q){
		ll x;
		cin>>x;
		vll::iterator ita=lower_bound(all(s), x);
		vll::iterator itb=lower_bound(all(t), x);

		ll a_l=ita-s.begin(), b_l=itb-t.begin();

		//cout<<a_l<<" "<<b_l<<" ";

		ll ans=1e18;
		for(int i=0; i<2; i++){
			for(int j=0; j<2; j++){
				if(a_l-i>=0&&a_l-i<a&&b_l-j>=0&&b_l-j<b){
					ll a_cost=llabs(x-s[a_l-i]), b_cost=llabs(x-t[b_l-j]);
					if(s[a_l-i]<t[b_l-j]){
						if(x<s[a_l-i]){
							ans=min(ans, b_cost);
						} else if(x<t[b_l-j]){
							ans=min(ans, min(a_cost, b_cost)+llabs(t[b_l-j]-s[a_l-i]));
						} else{
							ans=min(ans, a_cost);
						}
					} else{
						if(x<t[b_l-j]){
							ans=min(ans, a_cost);
						} else if(x<s[a_l-i]){
							ans=min(ans, min(a_cost, b_cost)+llabs(t[b_l-j]-s[a_l-i]));
						} else{
							ans=min(ans, b_cost);
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main(void){
    std::vector<long long> x(5);
    for(int i=0; i<5; i++){
        std::cin >> x[i];
    }
    auto result = std::find(x.begin(), x.end(), (long long)0);
    if(result == x.begin()){
        std::cout << *(result+1)-1 <<std::endl;
        return 0;
    }
    std::cout << *(result-1)+1 <<std::endl;
    return 0;
}

Measured memory_bytes: 3620
from collections import defaultdict


def main():
    N, A = map(int, input().split())
    x_list = list(map(int, input().split()))

    dp = [[None] * (50 * 50 + 1) for _ in range(51)]
    dp[0][0] = 1
    for x in x_list:
        for i in range(len(dp) - 2, -1, -1):
            for j in range(len(dp[i])):
                if dp[i][j] is not None:
                    if dp[i + 1][j + x] is None:
                        dp[i + 1][j + x] = 0
                    dp[i + 1][j + x] += dp[i][j]

    ans = 0
    for i in range(1, len(dp)):
        for j in range(len(dp[i])):
            if j == A * i and dp[i][j] is not None:
                ans += dp[i][j]
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4980
//   PIGMEISTER™   //

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define PI (ld)3.141592653589793238
#define MAX 100005

int main()
{
    jaldi;
    
    ll a;
    sidha (i, 1, 6) {
        cin >> a;
        if (a == 0) {
            cout << i;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
#define F first
#define S second
using namespace std;
typedef pair<int,int>p;
const int INF = 2000000000;

priority_queue<p> p_que;
vector<p> g[100000];
int d[100000];

void pre(int size) {
  for ( int i = 0; i < size; i++) {
    d[i] = INF;
  }
}

main() {
  int v, e, r;
  int s, t, w;
  
  cin >> v >> e >> r;
  pre(v);
  for (int i = 0; i < e; i++) {
    cin >> s >> t >> w;
    g[s].push_back(p(t,w));
  }

  p_que.push(p(r,0));
  d[r] = 0;
  while ( !p_que.empty() ) {
    p now = p_que.top(); p_que.pop();
    int pos = now.F;
    int cost = now.S;
    
    for ( int i = 0; i < g[pos].size() ; i++) {
      int next = g[pos][i].F;
      int ncost = cost + g[pos][i].S;
      if ( d[next] > ncost ) {
	d[next] = ncost;
	p_que.push(p(next,ncost));
      }
    }
    
  }
  
  for ( int i = 0; i < v; i++) {
    if ( d[i] == INF ) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }

  return (0);
}



Measured memory_bytes: 20340
#include <stdio.h>
int tmp(int a, int b){
    int t;

    if( a < b ) { t = a; a = b; b = t; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return tmp( b, a % b );
}
int main(void){
    int k;
    scanf("%d", &k);
    int a, b, c;
    int sum = 0;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            a = tmp(i, j);
            for(int n = 1; n <= k; n++){
                b = tmp(a, n);
                sum = sum + b;
            }
        }
    }

    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(ReadLine());
            var A = ReadLine().Split().Select(long.Parse).ToList();

            var min = A.Min();

            while (A.Count(s => s % min != 0) > 0)
                min = A.Select(s => s % min).Where(x => x != 0).Min();
            WriteLine(min);
        }
    }
}


Measured memory_bytes: 22112
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
sum_A = sum(A)

if sum_A > N:
    print("-1")
else:
    print(N-sum_A)

Measured memory_bytes: 10572
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

// -------------------------------------------------------------------------------------

ll dp[2002][2002];
ll combMOD(ll n, ll k) {
  if(dp[n][k] != -1) return dp[n][k];

  if (k == 0 || k == n) {
    dp[n][k] = 1;
    return 1;
  } else if (k == 1) {
    dp[n][k] = n;
    return n;
  }
  return dp[n][k] = (combMOD(n - 1, k - 1) + combMOD(n - 1, k)) % MOD;
}

ll solve(ll n, ll k, ll i) {
  if(n-k+1 < i) return 0;
  ll c1 = combMOD(n - k + 1, i);
  ll c2 = combMOD(k - 1, i - 1);
  return (c1 * c2) % MOD;
}

int main() {
  rep(i, 2002) {
    rep(j, 2002) {
      dp[i][j] = -1;
    }
  }

  ll n, k;
  cin >> n >> k;

  rep1(i, k+1) {
    cout << solve(n, k, i) << endl;
  }

  return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>
#include <complex>
#include <bitset>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};


class UnionFind {
public:
    int n;
    vector<int> parent;
    vector<int> rank;
    UnionFind(int m) {
        n = m;
        parent.resize(n);
        rank.resize(n, 0);
        for (int i = 0; i < n; i++) {
            parent[i] = i;
        }
    }

    int find(int node) {
        if (parent[node] == node) {
            return node;
        } else {
            parent[node] = find(parent[node]);
            return parent[node];
        }
    }

    void unite(int node1, int node2) {
        node1 = find(node1);
        node2 = find(node2);
        if (node1 == node2) {
            return;
        } else {
            if (rank[node1] < rank[node2]) {
                parent[node1] = node2;
            } else if (rank[node1] > rank[node2]) {
                parent[node2] = node1;
            } else {
                parent[node1] = node2;
                rank[node1] += 1;
            }
        }
    }

    bool same(int node1, int node2) {
        node1 = find(node1);
        node2 = find(node2);
        if (node1 == node2) {
            return true;
        } else {
            return false;
        }
    }
};


int main() {
    int n, k, l; cin >> n >> k >> l;
    UnionFind uf1(n), uf2(n);
    rep(i, k) {
        int p, q; cin >> p >> q;
        p--; q--;
        uf1.unite(p, q);
    }
    rep(i, l) {
        int r, s; cin >> r >> s;
        r--; s--;
        uf2.unite(r, s);
    }

    map<pint, int> mp;
    rep(i, n) {
        mp[make_pair(uf1.find(i), uf2.find(i))]++;
    }

    rep(i, n-1) {
        cout << mp[make_pair(uf1.find(i), uf2.find(i))] << " ";
    }
    cout << mp[make_pair(uf1.find(n-1), uf2.find(n-1))] << endl;

    return 0;
}


    


Measured memory_bytes: 15104
h, w = list(map(int, input().split()))
s = [["." for i in range(w+2)]]
for i in range(h):
    si = ["."]
    sie = list(input())
    for e in sie:
        si.append(e)
    si.append(".")
    s.append(si)
s.append(["." for i in range(w+2)])
ans = "Yes"
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == "#":
            if not ((s[i - 1][j] == "#") or (s[i + 1][j] == "#") or (s[i][j - 1] == "#") or (s[i][j + 1] == "#")):
                ans = "No"
print(ans)


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

using namespace std;

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

ll gcd(ll a, ll b){
    if(a<b){
    }
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}
template <typename T>
T lcm(T x, T y) {
    return x / gcd(max(x,y), min(x,y)) * y;
}

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    vector<ll> a(n);
    ll l = 1;
    for(auto &x : a) {
        cin >> x;
        l=lcm(l,x/2);
    }
    ll ret = 0;
    //cout << l << endl;
    for(auto &x:a){
        if(l%x==0){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m/l+1)/2 << endl;
    return 0;
}


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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 1e5+5;

vector <ll> h1(L);
vector <ll> h2(L);

vector < pair <ll, ll> > v1;
vector < pair <ll, ll> > v2;

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

    for(ll i=0; i<n; i++)
    {
        ll a;
        cin >> a;

        if(i%2==0)
        {
            h1[a]++;
        }

        else
        {
            h2[a]++;
        }
    }

    for(ll i=0; i<L; i++)
    {
        v1.pb(mp(h1[i], i));
        v2.pb(mp(h2[i], i));
    }

    sort(all(v1));
    reverse(all(v1));


    sort(all(v2));
    reverse(all(v2));

    if(v1[0].ss!=v2[0].ss)
    {
        cout << n - min(n/2,v1[0].ff) - min(n/2, v2[0].ff) << endl;
    }
    
    else
    {
        cout << n - min(n/2, v1[0].ff) - min(n/2, max(v1[1].ff, v2[1].ff)) << endl;
    }   

    return 0;
}

Measured memory_bytes: 6124
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
//a,m=MOD MOD逆元
long double n;
long double dp[301][301][301];
long double cal(int i,int j,int k){
    if(dp[i][j][k]!=-1)
        return dp[i][j][k];
    if(i==0&&j==0&&k==0)
        return 0.0;
    long double res = n;
    if(i>=1)
        res += cal(i - 1, j, k) * i;
    if(j>=1)
        res += cal(i + 1, j - 1, k) * j;
    if(k>=1)
        res += cal(i, j + 1, k - 1) * k;
    res /= (i + j + k);
    return dp[i][j][k] = res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,w;
    cin>>n>>w;
    V val(n);
    V wei(n);
    rep(i,n)cin>>wei[i]>>val[i];
    vector<vector<long long>> dp(n +1, vector<long long>(w + 1e6, 0));
    for (int i = 0; i < n ; i++)
    {
        for (int j = 0; j < w + 1; j++)
        {
            chmax(dp[i + 1][j], dp[i][j]);
            dp[i+1][j+wei[i]] = dp[i][j]+val[i];

        }
    }
    cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 877056
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <deque>
#include <queue>
#include <stack>
 
using namespace std;	
 
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define mp make_pair
#define all(x) x.begin(), x.end()
#define ll long long
#define sz(x) (int)x.size()
/*
string lower(string a)
{
	for(int i=0;i<a.size();i++)
	{
		a[i]=tolower(a[i]);
	}
	return a;
}
ll nod(ll a,ll b)
{
    if(a==0)
        return b;
    else if(b==0)
        return a;
    if(a>=b)
        return nod(a%b,b);
    else if(a<=b)
        return nod(a,b%a);
}
ll nok(ll x, ll y)
{
	return x/nod(x,y)*y;
}
*/
const ll INF = 1e9;
int main()
{
//	freopen("D.in", "r", stdin);
//	freopen("D.out", "w", stdout);	
	IOS;
	ll n, k, s;
	cin >> n >> k >> s;
	for(int i = 1; i <= n; i++)
	{
		if(k > 0)
		{
			cout << s << " ";
			k--;	
		}
		else
		{
			if(s == INF)
			cout << s-1 << " ";
			else
			cout << s+1 << " ";
		}
	}
	cout << endl;
}

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

int main(){
    int n,q;
    string s;
    cin>>n>>q>>s;
    int v[n]; v[0]=0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='A' and s[i+1]=='C'){
            v[i+1]=v[i]+1;
        }
        else v[i+1]=v[i];
    }
    int l,r;
    while(q--){
        cin>>l>>r;
        cout<<v[r-1]-v[l-1]<<"\n";
    }
return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,p,n) for(ll i=n-1;i>=p;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define trav(it,a) for(auto it=a.begin();it!=a.end();++it)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll n,k;
  cin>>k>>n;
  ll arr[n];
  fo(i,n)
  cin>>arr[i];
  ll q=min(k-arr[n-1]+arr[0],arr[n-1]-arr[0]),in=n-1;ll f=0;
  for(ll i=1;i<n;i++)
  {
    ll p=arr[i]-arr[i-1];
    if(p>q)
    {
      f=1;
      q=p;
      in=i;
    }
  }
 // cout<<in<<kk;
  ll s=0;
  if(f==0)
  {
    for(ll i=1;i<n;i++)
      s=s+arr[i]-arr[i-1];
  }
  else
  {
    for(ll i=in+1;i<n;i++)
      s=s+arr[i]-arr[i-1];
    s=s+k-arr[n-1]+arr[0];
    for(ll i=1;i<in;i++)
      s=s+arr[i]-arr[i-1];
  }
  cout<<s;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#pragma warning( disable:4996 )
using namespace std;

#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	/*int r;
	scanf("%d", &r);
	printf("%d\n", 3 * r*r);*/

	/*int n, d;
	scanf("%d %d", &n, &d);
	int one = 1 + 2 * d;
	if (n%one) {
		printf("%d\n", n / one + 1);
	}
	else {
		printf("%d\n", n / one);
	}*/

	/*int n;
	int a[200001];
	int s[200001];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		s[i] = a[i];
	}
	sort(s, s + n);
	for (int i = 0; i < n; i++) {
		if (s[n - 1] == a[i])
			printf("%d\n", s[n - 2]);
		else
			printf("%d\n", s[n - 1]);
	}*/

	int n;
	int a[200001];
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	int v[200001];
	int count = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		v[i] = a[i];
		if (v[i])count++;
	}
	for (int i = n / 2; i >= 1; i--) {
		int sum = 0;
		for (int j = i * 2; j <= n; j += i) {
			sum += v[j];
		}
		//sum %= 2;
		v[i] = (sum % 2) ^ a[i];
		if(v[i])count++;
	}
	printf("%d\n", count);
	if (count == 0)return 0;
	int first = 1;
	for (int i = 1; i <= n; i++) {
		if (v[i]) {
			if (first) {
				printf("%d", i);
				first = 0;
			}
			else {
				printf(" %d", i);
			}
			
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2432
#include<stdio.h>

#define N 100000

int bserch(int a[], int b, int key){
  int i,left =0, right =b;

  while(left < right){
    i = (left+right)/2;
    if(a[i] == key){
      return 1;
    }
    else if(key < a[i]){
      right = i;
    }
    else{
      left = i +1;
    }
  }
  return 0;
}

int main(){
  int n, q, i, j, count = 0, discount = 0;
  int S[N],T[N];
  
   scanf("%d",&n);
  
  for(i=0; i<=n-1;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);

  for(i=0;i<=q-1;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<=q-1;i++){
    if(bserch(S,n,T[i]) == 1){
      count += 1;
    }
  }

  printf("%d\n", count);
  
  
  return 0;
}

Measured memory_bytes: 1192
N = int(input())

dls = []

for n in range(N):
    dls.append(int(input()))

dls.sort(reverse = True)

count=0
prev_length = 10**10
for nowRice in dls:
    
    if(prev_length > nowRice):
        count += 1
    prev_length = nowRice

print(count)


Measured memory_bytes: 3060
//嘘っぽいのに通ってたやつでいこう

#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[2000100], *ci = cn, c;

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


	fread(cn, 1, 2000100, stdin);
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';
	int sL[1001] = {}, sR[1001] = {};
	pair<int, int> RR[500], LL[500];
	int rr = 0, ll = 0;
	int tot = 0;
	rep(i, N) {
		int l = 0, r = 0;
		while ((c = *ci++) >= '(') {
			if (c == '(') r++;
			else {
				if (r > 0) r--;
				else l++;
			}
		}
		tot += r - l;
		if (l < r) {
			if (l <= 1000) sR[l] += r;
			else RR[rr++] = { l,r };
		}
		else {
			if (r <= 1000) sL[r] += l;
			else LL[ll++] = { r,l };
		}
	}

	if (tot != 0) {
		printf("No");
		return 0;
	}

	sort(RR, RR + rr);
	sort(LL, LL + ll);

	int OK = 1;
	int k = 0;
	rep(i, 1001) {
		if (sR[i]) {
			if (k < i) OK = 0;
			k += sR[i];
		}
	}
	rep(i, rr) {
		if (k < RR[i].first) OK = 0;
		k += RR[i].second - RR[i].first;
	}
	k = 0;
	rep(i, 1001) {
		if (sL[i]) {
			if (k < i) OK = 0;
			k += sL[i];
		}
	}
	rep(i, ll) {
		if (k < LL[i].first) {
			OK = 0;
		}
		k += LL[i].second - LL[i].first;
	}

	if (OK) printf("Yes");
	else printf("No");

	Would you please return 0;
}

Measured memory_bytes: 3536
#include<iostream>
main(){int n,v[5000],m;while(std::cin>>n,m=n){for(;m--;)std::cin>>v[m];m=*v;for(int i=0;i<n;i++)for(int j=i,k=v[i];j++<n;k+=v[j])m=k>m?k:m;std::cout<<m<<'\n';}}

Measured memory_bytes: 0
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <iomanip>
#define PI (acos(-1.0))
#define Abs(a) (((a)<0) ? (-(a)) :(a) )
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=((n)-1);i>=0;i--)
#define rrep(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define Pii pair<int,int>
#define PB push_back
#define Size(x) ((int)(x.size()))
using namespace std;
typedef long long mint;
typedef unsigned long long umint;
mint val[205];
mint nCk(int n, int k)
{
    mint ans = 1;
    Rep(i,k)
    {
        ans *= (n - i);
        ans /= (i + 1);
    }
    return ans;
}
int countVals(mint *arr, int n, mint val)
{
    int cnt = 0;
    Rep(i,n)
    {
        cnt += (val == arr[i]);
    }
    return cnt;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n, a, b;
    cin >> n >> a >> b;
    if(b < a)
    {
        cout << 0.0 << endl;
        cout << 0 << endl;
        return 0;
    }
    Rep(i,n)
    {
        cin >> val[i];
    }
    sort(val, val + n, greater<mint>());
    double sm = 0.0;
    Rep(i,a)
    {
        sm += val[i];
    }
    
    double ans = sm / a;
    mint ways = 0;
    if(val[0] > val[a - 1])
    {
        int nn = countVals(val, n, val[a - 1]);
        int k = countVals(val, a, val[a - 1]);
        ways = nCk(nn, k);
    }
    else
    {
        int nn = countVals(val, n, val[0]);
        for(int i = a; i <= min(nn, b); i++)
        {
            ways += nCk(nn, i );
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
    cout << ways << endl;
    return 0;
}




Measured memory_bytes: 256
#!/usr/bin/php
<?php

function judge($n){
  $ma=0;
  $mi=1000;
  $s=0;
  for($i=0;$i<$n;$i++){
    $x=fgets(STDIN)+0;
    if($x<$mi){$mi=$x;}
    if($x>$ma){$ma=$x;}
    $s+=$x;
  }
  echo floor(($s-$ma-$mi)/($n-2)),"\n";
}

while(1){
  $n=fgets(STDIN);
  if($n==0){break;}
  judge($n);
}
?>

Measured memory_bytes: 6596
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
#pragma GCC optimize ("trapv")

#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define what_is(x) cerr << #x << " is " << x << endl;
#define wis cout<<endl<<"I already speak english, bitch"<<endl<<endl;
 
typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef pair<ii,lli> iii;
typedef long double C; 

#define trace(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cerr <<  *it  << " : " << a << endl;
    err(++it, args...);
}

const int N=40;
vector<int> v[N];

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


/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

/*
tip:
 crtl+B to find errors in the code  
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int t,p,r;
int tid[510],pid[510],tim[510];
string mes[510];
int clear[55][15];
struct team{
	int no;
	int cor;
	int pen;
	

};
bool operator<(team& b,team& a){
	if(b.cor!=a.cor){
		return b.cor>a.cor;
	}else if(b.pen!=a.pen){
		return b.pen<a.pen;
	}else{
		return b.no<a.no;
	}
}
int main(){
	while(1){
		cin>>t>>p>>r;
		if(t==0&&p==0&&r==0)break;
		REP(i,55)
			REP(j,15)
			clear[i][j]=0;
		team te[55];
		for(int i=1;i<=t;i++){
			te[i]=team{i,0,0};
		}
		REP(i,r){
			cin>>tid[i]>>pid[i]>>tim[i]>>mes[i];
			if(mes[i]=="CORRECT")clear[tid[i]][pid[i]]=1;
		}
		REP(i,r){
			if(mes[i]=="CORRECT"){
				te[tid[i]].cor++;
				te[tid[i]].pen+=tim[i];
			}else if(mes[i]=="WRONG"&&clear[tid[i]][pid[i]]==1){
				te[tid[i]].pen+=1200;
			}
		}
		
		sort(te+1,te+t+1);
		for(int i=1;i<=t;i++){
			cout<<te[i].no<<" "<<te[i].cor<<" "<<te[i].pen<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=305;
int n,K,mo;
int C[N][N],f[N][N],S[N][N];
int main(){
	scanf("%d%d%d",&n,&K,&mo);
	For(i,0,N-1) C[i][0]=1;
	For(i,1,N-1) For(j,1,i)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
	For(i,0,K){
		f[1][i]=1;
		S[1][i]=K-i+1;
	}
	For(i,2,n+1){
		For(j,1,i-1) For(k,0,K)
			f[i][k]=(f[i][k]+1ll*f[i-j][k]*S[j][k+1]%mo*C[i-2][j-1])%mo;
		Rep(j,K,0) S[i][j]=(S[i][j+1]+f[i][j])%mo;
	}
	printf("%d\n",f[n+1][0]);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
char a[110][110];
int n,m,b[110],c[110];
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n) rep(j,1,m){
		scanf(" %c",&a[i][j]);
		if(a[i][j]=='#') b[i]|=1,c[j]|=1;
	}
	//rep(i,1,n) printf("%d",b[i]);puts("");
	rep(i,1,n){
		if(!b[i]) continue;
		rep(j,1,m) if(c[j]) printf("%c",a[i][j]);
		puts("");
	}
	return 0;
}

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

int main(){
	int n, b_count, w_count, all_c, b_min, lb, rw;
	string s;
	cin >> n >> s;
	vector<int> b_sum(n+1);
	b_count = 0;
	w_count = 0;
	for(int i=0; i<n; i++){
		if(s[i]=='#'){
			b_count++;
		}
	}
	for(int i=0; i<n; i++){
		if(s[i]=='.'){
			w_count++;
		}
	}
	all_c =  min(b_count, w_count);

	b_sum[0] = 0;
	for(int i=0; i<n; i++){
		if(s[i]=='#'){
			b_sum[i+1] = b_sum[i] + 1;
		}else{
			b_sum[i+1] = b_sum[i];
		}
	}
	b_min = 200000;
	for(int i=0; i<n+1; i++){
		lb = b_sum[i];
		rw = n-i - (b_sum[n] - b_sum[i]);
	//cout << "lb: " << lb << endl << "rw: " << rw << endl;
		b_min = min(b_min , lb+rw);
	}
	cout << min(b_min, all_c) << endl;;
	return 0;
}

Measured memory_bytes: 1412
import re
def main():
    n = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    BC = [list(map(int,input().split())) for _ in range(Q)]
    dic = [0]*(10**5 + 1)
    sm = 0
    for a in A:
        dic[a] += 1
        sm += a
    
    for b,c in BC:
        num = dic[b]
        dic[c] += dic[b]
        dic[b] = 0
        sm = sm - num*b + num*c
        print(sm)
    return 

if __name__ == "__main__":
    main()

Measured memory_bytes: 33184
m, k = gets.split.map(&:to_i)

n = 2**m - 1

if (k > n || (m == 1 && k == 1))
  puts(-1)
else
  as = if (k == 0) then [] else [k] end
  bs = (1..k-1).to_a + (k+1..n).to_a
  cs = [0] + as + [0] + bs + as + bs.reverse

  puts(cs.join(' '))
end


Measured memory_bytes: 11256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static class Edge {
		int from, to, cost;
		public Edge(int from, int to, int cost) {
			this.from = from;
			this.to = to;
			this.cost = cost;
		}
	}
	static int V = 10;
	static int E = 100;
	static Edge[] edges = new Edge[E];
	static int[] d;
	static int INF = Integer.MAX_VALUE / 2;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		int k = 0;
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)
				edges[k++] = new Edge(i, j, Integer.parseInt(sc.next()));
		int[] ans = new int[10];
		for (int i = 0; i < 10; i++) {
			bellman_ford(i);
			ans[i] = d[1];
		}
		int sum = 0;
		for (int i = 0; i < h * w; i++) {
			int t = Integer.parseInt(sc.next());
			if (t != -1)
				sum += ans[t];
		}
		System.out.println(sum);
	}
	static void bellman_ford(int sv) {
		d = new int[V];
		Arrays.fill(d, INF);
		d[sv] = 0;
		while (true) {
			boolean update = false;
			for (int i = 0; i < E; i++) {
				int u = edges[i].from;
				int v = edges[i].to;
				int c = edges[i].cost;
				if (d[u] + c < d[v]) {
					d[v] = d[u] + c;
					update = true;
				}
			}
			if (!update) {
				break;
			}
		}
	}
}

Measured memory_bytes: 39540
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int memo[1 << 17][16];
vector<vector<int>>times;
int N;
int getans(bitset<17>bs, const int stage) {
	if (memo[bs.to_ulong()][stage])return memo[bs.to_ulong()][stage];
	int time = 99999999;
	for (int i = 0; i < N+1; ++i) {
		if (bs[i]&&i!=stage+1) {
			time = min(time, times[stage][i]);
		}
		
	}
	int restmin = 99999999;
	if (bs.count() == N+1)return memo[bs.to_ulong()][stage] = time;
	for (int i = 1; i <= N; ++i) {
		if (!bs[i]) {
			bs[i] = true;
			restmin = min(restmin, getans(bs, i-1));
			bs[i] = false;
		}
	}
	return memo[bs.to_ulong()][stage] = time + restmin;
}

int main() {
	while (1) {
		cin >> N;
		if (!N)break;
		times.clear();
		times.resize(N);
		memset(memo, 0, sizeof(memo));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N + 1; ++j) {
				int t; cin >> t;
				times[i].push_back(t);
			}
		}
		
		vector<int>perm(N);
		iota(perm.begin(), perm.end(), 0);
		
		bitset<17>bs(0);
		int ans = 99999999;
		bs[0] = true;
		for (int i = 1; i <= N; ++i) {
			bs[i] = true;
			ans = min(ans, getans(bs, i-1));
			bs[i] = false;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 11264
import math
a,b,C=map(float,input().split())
C=math.radians(C)
c=math.sqrt(a*a+b*b-2.0*a*b*math.cos(C))
S=a*b*math.sin(C)/2.0
L=a+b+c
h=b*math.sin(C)
print("{:.8f} {:.8f} {:.8f}".format(S,L,h))



Measured memory_bytes: 5696