akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr),out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr),out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    if(n%3==0){
        sort(all(a));
        vector<int> b(3);
        REP(i,3){
            b[i]=a[i*n/3];
        }
        bool flag = true;
        int temp=0;
        REP(i,3){
            temp^=b[i];
        }
        if(temp!=0){
            flag=false;
        }
        REP(i,3){
            REP(j,n/3){
                if(b[i]!=a[j+i*n/3]){
                    flag=false;
                }
            }
        }
        if(flag){
            put("Yes");
        }else{
            put("No");
        }
    }else{
        bool all0 = true;
        REP(i,n){
            if(a[i]!=0){
                all0=false;
            }
        }
        if(all0){
            put("Yes");
        }else{
            put("No");
        }
    }
    return 0;
}


Measured memory_bytes: 640
MOD = 998244353
n, s = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
dp = Array.new(n + 1) { Array.new(s + 1, 0) }

# dp[確認した数字][合計] の出現数
dp[0][0] = 1

n.times do |current|
  dp_current = dp[current]
  dp_next = dp[current + 1]
  num = nums[current]
  (s + 1).times do |current_sum|
    count = dp_current[current_sum]
    next if count.zero?
    dp_next[current_sum] += count * 2
    dp_next[current_sum] %= MOD
    next_sum = current_sum + num
    next if next_sum > s
    dp_next[next_sum] += count
    dp_next[next_sum] %= MOD
  end
end

puts dp.last.last % MOD


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

int main() {
    int n;
    vector<int> cand = {1};
    cin >> n;
    for(int base: {6, 9}) {
        int fac = base;
        while (fac <= n) {
            cand.push_back(fac);
            fac *= base;
        }
    }
    vector<int> dp(n+1, INT_MAX);
    dp[0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int pre: cand) {
            if (i-pre >= 0) {
                dp[i] = min(dp[i], dp[i-pre]+1);
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int N,M,c[16],dp[256];

int main(){
	while(cin>>N>>M&&N){
		fill(dp,dp+256,INF);
		dp[128]=0;
		rep(i,M)cin>>c[i];
		rep(i,N){
			int m,dp2[256];
			fill(dp2,dp2+256,INF);
			cin>>m;
			rep(j,256)rep(k,M){
				int n=j+c[k];
				if(n<0)n=0;
				if(n>255)n=255;
				dp2[n]=min(dp2[n],dp[j]+(m-n)*(m-n));
			}
			rep(j,256)dp[j]=dp2[j];
		}
		int ans=INF;
		rep(i,256)ans=min(ans,dp[i]);
		cout<<ans<<endl;
	}
}

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

using namespace std;

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

int main(void) {
    int n;
    cin >> n;
    vector<vector<int>> h(n, vector<int>(3, 0));
    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> h[i][j];
        }
    }
    dp[0][0] = h[0][0];
    dp[0][1] = h[0][1];
    dp[0][2] = h[0][2];

    for (int i = 0; i < n; ++i) {
        if (i < n - 1) {
            chmax(dp[i + 1][0], max(dp[i][1] + h[i + 1][0], dp[i][2] + h[i + 1][0]));
            chmax(dp[i + 1][1], max(dp[i][0] + h[i + 1][1], dp[i][2] + h[i + 1][1]));
            chmax(dp[i + 1][2], max(dp[i][0] + h[i + 1][2], dp[i][1] + h[i + 1][2]));
        }
    }

    int ans = *max_element(dp[n-1].begin(), dp[n-1].end());
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;
    vector<string> vs(n);

    rep(i, n) cin >> vs[i];

    bool flag = true;
    rem(i, 1, n)
    {
        // std::cout << std::endl;
        // std::cout << vs[i - 1] << " , " << vs[i] << std::endl
        //           << endl;
        if (vs[i - 1].back() != vs[i].front())
        {
            flag = false;
        }
        rep(j, i)
        {
            if (vs[i] == vs[j])
            {
                flag = false;
            }
        }
    }

    if (flag)
        cout << "Yes"
             << "\n";
    else

        cout << "No"
             << "\n";

    return 0;
}

Measured memory_bytes: 256
import math
A,B,H,M = map(int,input().split())

CC = ((H * 60 + M) * 0.5) - (M * 6)
cc = math.cos(math.radians(CC))
XX = A ** 2 + B ** 2 - 2 * A * B * cc
print(math.sqrt(XX))

Measured memory_bytes: 9500
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
    char a[10];
    cin>>a;
    int n1,n2;
    n1=(a[0]-'0')*10+(a[1]-'0');
    n2=(a[2]-'0')*10+(a[3]-'0');
    if(n1>0&&n1<=12)
    {
        if(n2>0&&n2<=12)
        cout<<"AMBIGUOUS";
        else 
        cout<<"MMYY";
    }
    else
    {
        if(n2>0&&n2<=12)
        cout<<"YYMM";
        else 
        cout<<"NA";
    }
    return 0;
}

Measured memory_bytes: 256
/*
AizuOnline A0000
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int n;
char msg[1025];
char key[10][5] = {{'\0'},
		   {'.',',','!','?',' '},
                   {'a','b','c'},
		   {'d','e','f'},
		   {'g','h','i'},
		   {'j','k','l'},
		   {'m','n','o'},
		   {'p','q','r','s'},
		   {'t','u','v'},
		   {'w','x','y','z'}};
struct RUN {
  char chr;
  int  len;} runlen[513];
char res[77]; 
struct RUN *pRUN;
//
int shrink()
{
  char * sp,c,c1;
  int len1;
  
  len1=0;
  sp = msg;pRUN = runlen;c1 = '\0';    //runlen[0] dummy
  while(c = *sp)
    {
      //printf("%c:\n",c);
      if(c == c1)
	pRUN->len++;
      else
	{
	  pRUN ++;
	  len1++;
	  pRUN->len=0;
	  pRUN->chr = c;
	}
      c1 = c;sp ++;
    }
  return(len1);
}
void expand(int len)
{
  int i;
  char c;
  char *p;

  for(i=0;i<77;i++)
    res[i]='\0';
  p = res;

  for(i=1;i<len;i++)   // 0th dummy
    {
      c=runlen[i].chr;
      if(c=='0')continue;
      if(c=='7' ||c=='9')
	*p = key[c-'0'][(runlen[i].len % 4)];
      else if (c == '1')
	*p = key[c-'0'][(runlen[i].len % 5)];
      else
	*p = key[c-'0'][(runlen[i].len % 3)];
      p++;
    }
  p='\0';
}
main()
{
  int len,i;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",msg);
      //printf("S=%s\n",msg);
      len=shrink();
      //printf("LEN=%d\n",len);
      expand(len);
      printf("%s\n",res);
    }
return(0);
}

Measured memory_bytes: 592
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  string s, t; cin >> s >> t;
  map<string, int> mp;
  int a; cin >> a;
  mp[s] = a;
  cin >> a; mp[t] = a;
  string u; cin >> u;
  mp[u]--;
  cout << mp[s] << " " << mp[t] << "\n";
}


Measured memory_bytes: 256
# coding: utf-8
import time
import re
import math
import fractions

def main():
    X=int(input())
    S=str(X)
    total=0
    for a in range(len(S)):
        total+=int(S[a])
    if X%total==0:
        print("Yes")
    else:
        print("No")


start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())



Measured memory_bytes: 5044
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	A, op, B := ReadInt(), ReadString(), ReadInt()
	if op == "+" {
		fmt.Println(A + B)
	} else {
		fmt.Println(A - B)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1840
import sys
def input():
    return sys.stdin.readline()[:-1]
import heapq

N,M = map(int,input().split(' '))
l = list(map(int, input().split()))
h = []
for i in range(N):
    heapq.heappush(h, -l[i])
for i in range(M):
    p = heapq.heappop(h)
    if p==0:
        print(0)
        exit()
    p = p / 2
    heapq.heappush(h, p)
cnt = 0
for i in range(N):
    cnt += int(-h[i])
print(cnt)

Measured memory_bytes: 14180
#include<stdio.h>
int main(){
    char strt[100];
    char *ptime=strt;
    int i=0;
    int flag=0;
    char strflag[4][10] = {0};
    fgets(strt, sizeof(strt), stdin);
    
    //数字をすべてchar型で読み込みstrflagに一文字ずつ格納していっている。
    while(*ptime){
        //改行文字削除して文字列の最後にNULLを入れる
        if(*ptime=='\n'){
            *ptime='\0';
        }else if(*ptime==' '){  //ひとまとまりの数字を読み込むとflagをインクリメントすることで、flagと数字のまとまりを対応させる
            flag++;
            i=0;
            ptime++;
        }else{
            strflag[flag][i]=*ptime;
            i++;
            ptime++;
        }
    }
    
    if(atoi(&strflag[0]) > atoi(&strflag[1]) ) printf("a > b\n");
    else if(atoi(&strflag[0])< atoi(&strflag[1]) ) printf("a < b\n");
    else printf("a == b\n");
}


Measured memory_bytes: 2080
n,m = map(int,input().split())
tree= [[] for i in range(n)]
for i in range(m):
  tmp1,tmp2 = map(int,input().split())
  tree[tmp1-1].append(tmp2-1)
  tree[tmp2-1].append(tmp1-1)
for i in range(n):
  print(len(tree[i]))

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  int s,w; cin>>s>>w;
  if(w>=s)cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
}

Measured memory_bytes: 3672
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int[] AB = new int[2];
        int cont = 0;
        for (String s:str.split(" ")){
            AB[cont] = Integer.parseInt(s);
            cont++;
        }
        if (AB[0]<=8 && AB[1]<=8){
            System.out.println("Yay!");
        } else {
            System.out.println(":(");
        }
    }
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long a,b,c,d;
    cin >> a >> b >> c ;
    d=max(a,b);
    if(c%d==0) cout<<c/d<<"\n";
    else cout<<(c/d)+1<<"\n";
    return 0;
}


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

int main() {
  int N;
  char S;
  bool flag = false;

  cin >> N;

  for (int i=0; i < N; i++) {
    cin >> S;
    if (S == 'Y') {
      flag = true;
    }
  }

  if (flag) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
int main(){
	long long int A, B;
  	long int C,D;
	long long int c1, c2, c3, c4;
  // Taking input
  cin >> A >> B >> C >> D;
  c1 = B/C - A/C;
  c2 = B/D - A/D;
  // c3 : lcm of A & B
  c3 = (C*D)/__gcd(C,D);
  c4 = B/c3 - A/c3;
  if (A % C == 0) c1 += 1;
  if (A % D == 0) c2 += 1;
  if (A % c3 == 0) c4 += 1;
  cout << B - A +1 - c1 - c2 + c4 <<'\n';
  //cout << "c1 : "<< c1 << "c2 : "<< c2 << "c4 : "<< c4 <<'\n';
  
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1009;
const int M=100009;
int n;ll a[N],pri[M];
int f[M],tot;
void init(){
    memset(f,0,sizeof(f));f[1]=1;
    for(int i=2;i<=M-9;i++){
        if(!f[i]) pri[++tot]=i;
        for(int j=1;j<=tot&&pri[j]*i<=M-9;j++){
            f[pri[j]*i]=1;
            if(i%pri[j]==0) break;
        }
    }
    return ;
}
int main(){
    init();
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++){
        ll t=a[i];
        for(int j=1;j<=tot;j++)
            if(t%pri[j]==0){
                while(!(t%pri[j])) t/=pri[j];
                if(t<M-9) break;
            }
        if(t>M-9) pri[++tot]=t;    
    }
    ll ans=0;
    for(int i=1;i<=tot;i++){
        ll area=0;
        for(int j=1;j<=n;j++)
            if(a[j]%pri[i]==0) area+=a[j];
        ans=max(ans,area);    
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3708
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




















 
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    
    vector<pair<ll, ll>> ans;
    for(ll i = 1; i < n - 1 && a[i] <= 0; i++){
        ans.push_back({a.back(), a[i]});
        a[n - 1] -= a[i];
    }
    for(ll i = n - 2; i > 0 && a[i] > 0; i--){
        ans.push_back({a[0], a[i]});
        a[0] -= a[i];
    }
    ans.push_back({a.back(), a[0]});
    a[n - 1] -= a[0];
    cout << a[n - 1] << endl;
    REP(i, n - 1){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

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

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

  vector<string> W(N);
  for(int i = 0; i < N; i++){
    cin >> W[i];
  }

  bool end_begin_check = true;
  for(int i = 0; i < N - 1; i++){
    if(W[i][W[i].length() - 1] != W[i + 1][0]){
      end_begin_check = false;
    }
  }

  bool dup_check = true;
  set<string> dup;
  for(int i = 0; i < N; i++){
    if(dup.count(W[i])){
      dup_check = false;
    }
    dup.insert(W[i]);
  }

  if(end_begin_check && dup_check){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
int main(int argc, char **argv) {
    cin >> N;
    bool res = false;
    for(int i = 1; i <= 9; ++i)
        for(int j = 1; j <= 9; ++j)
            if(i * j == N) {
                res = true;
            }

    cout << (res ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, i, count;
    char str[50+1];

    scanf("%d", &n);
    scanf("%s", str);

    count = 0;
    for(i=0; i<n-2; i++){
        if(str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C'){
            count++;
        }
    }
    printf("%d", count);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <ctime>
#include <fstream>
#include <cmath>
#include <assert.h>

using namespace std;

#ifndef LOCAL
#define cerr if(0)cerr
#endif

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define RT fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC);

typedef long long ll;
typedef long double ld;

const int INFint = 2e9;
const ll INF = 2e18;
const int MOD = 1e9 + 7;

#define FILE "palindrome"

ll go(ll a, ll b, ll c) {
    ll r = a / 2;
    a -= r;
    return abs(a * b * c - r * b * c);
}

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    //    freopen(FILE".in", "r", stdin); freopen(FILE".out", "w", stdout);
    //    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ll a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
        cout << "0";
        return 0;
    }
    ll ans = INF;
    ans = min(go(a, b, c), ans);
    ans = min(go(b, a, c), ans);
    ans = min(go(c, b, a), ans);
    cout << ans;
    RT;
    return 0;
}

Measured memory_bytes: 256
r = gets.split(' ').first.to_i
rc = []
r.times { rc << gets.split(' ').map(&:to_i) }
rc.map! { |c| c << c.inject(:+) }
rc << rc.transpose.map { |c| c.inject(:+) }
puts rc.map { |c| c.join(' ') }

Measured memory_bytes: 9000
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: i64,
        K: i64,
        X: i64,
        Y: i64,
    }
    println!("{}", X*min(N,K) + Y*max(0,N-K));
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, M;
    cin >> N >> M;
    vector<ll> X(N);
    REP(i, N) cin >> X[i];

    ll res = 0;
    vector<vector<ll>> D(M);
    REP(i, N){
    	D[X[i]%M].push_back(X[i]);
    }

    res += (int)D[0].size()/2;
    if(M%2==0) res += (int)D[M/2].size()/2;

    //cout << D << endl;

    REP(i, (M-1)/2){
    	ll idx = i+1;
    	ll jdx = M-i-1;
    	if(D[idx].size()>D[jdx].size()) swap(idx, jdx);
    	map<ll, ll> mp;
    	REP(j, D[jdx].size()){
    		mp[D[jdx][j]]++;
    	}
    	ll tmp = 0;
    	for(auto x:mp){
    		tmp += x.second/2;
    	}
    	res += (int)D[idx].size();
    	ll sa = (int)D[jdx].size() - (int)D[idx].size();
    	res += min(sa/2, tmp);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6528
N,M,X=list(map(int,input().split()))
A=list(map(int,input().split()))

small,big=0,0
for i in range(X):
    if i in A:
        small+=1
for i in range(X+1,N+1):
    if i in A:
        big+=1
print(min(small,big))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>V(N), C(N);
	vector<int>ans(N);
	for (int i = 0;i < N;i++) {
		cin >> V[i];
	}
	for (int i = 0;i < N;i++) {
		cin >> C[i];
	}
	for (int i = 0;i < N;i++) {
		if (V[i] > C[i]) {
			ans[i] = V[i] - C[i];
		}
		else {
			ans[i] = 0;
		}
	}
	sort(ans.begin(), ans.end());
	int ANS = 0;
	for (int i = 0;i < N;i++) {
		ANS += ans[i];
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, j, n, l, be = 0, a;
  scanf("%d%d", &n, &l);
  for(i = 0; i < n; ++i) {
    scanf("%d", &a);
    if(i) {
      if(a + be >= l) {
        printf("Possible\n");
        for(j = 1; j < i; ++j) printf("%d\n", j);
        for(j = n - 1; j > i; --j) printf("%d\n", j);
        printf("%d\n", i);
        return 0;
      }
    }
    be = a;
  }
  printf("Impossible\n");
  return 0;
}

Measured memory_bytes: 768
#include<stdio.h>

int main()
{
	int a , b ,c ;
	scanf("%d %d %d", & a , & b , &c);
    if (a < b && b < c )
    {
    printf ("Yes\n");
    }
    else
    {
    printf ("No\n");
    }
	return 0;
} 


Measured memory_bytes: 2064
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define REP(i,n) for(LL i=0, i##_len=(n); i<i##_len; ++i)

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

template <LL MOD=1000000007> class MODLL {
public:
  LL x;
  MODLL(const LL _x) : x(_x % MOD) {};
  MODLL operator+(const MODLL rhs) const { return MODLL(*this) += rhs; }
  MODLL operator-(const MODLL rhs) const { return MODLL(*this) -= rhs; }
  MODLL operator*(const MODLL rhs) const { return MODLL(*this) *= rhs; }
  MODLL operator/(const MODLL rhs) const { return MODLL(*this) /= rhs; }
  MODLL& operator+=(const MODLL rhs) { x += rhs.x; x %= MOD; return *this; }
  MODLL& operator-=(const MODLL rhs) { x -= rhs.x; x %= MOD; if(x<0) x += MOD; return *this; }
  MODLL& operator*=(const MODLL rhs) { x *= rhs.x; x %= MOD; return *this; }
  MODLL inv() const {
    if(x == 0) { throw "does not have inverse"; }
    LL a = x, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return MODLL(u);
  }
  MODLL& operator/=(const MODLL rhs) { (*this) *= rhs.inv(); return *this; }
  MODLL pow(ULL n) const {
    MODLL res = 1;
    MODLL a = x;
    while (n > 0) {
      if (n & 1) res *= a;
      a = a * a;
      n >>= 1;
    }
    return res;
  }
};

typedef MODLL<> ML;

void test() {
  {
    ML x = 3;
    assert(x.pow(45).x == 644897553);
  }
  {
    for(int i=1; i<13; i++) {
      MODLL<13> x = i;
      assert( (x.inv().x * i) % 13 == 1 );
    }
  }
}


int main() {
  LL N;
  std::cin >> N;
  std::string S;
  std::cin >> S;

  std::vector<int> is_r(2*N);

  for(LL i=0; i<2*N; i++) {
    LL n_flip = 2 * N - 1 - i;
    if (S[i] == 'W') {
      is_r[i] = (n_flip % 2) ? 1 : 0;
    } else {
      is_r[i] = (n_flip % 2) ? 0 : 1;
    }
  }

  ML ans = 1;
  int l = 0;
  for(LL i=0; i<2*N; i++) {
    if(is_r[i]) {
      ans *= l;
      l--;
    }
    else {
      l++;
    }
  }
  if(l != 0) { ans = 0; }
  for(int i=0; i<N; i++) {
    ans *= (i+1);
  }

  std::cout << ans.x << std::endl;

  return 0;
}



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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

int N;
vi mp(1 << 22);
vi used(1 << 22);
std::vector<std::vector<long long>> a;
int cnt = 0;

ll rec(int cur, int bits) {
    cnt++;
    if (cur == N) return 1;
    if (used[bits]) {
        return mp[bits];
    }
    used[bits] = true;

    int ret = 0;
    rep(i, N) {
        if ((bits >> i) & 1) continue;
        if (a[cur][i]) {
            ret += rec(cur + 1, bits + (1 << i));
            ret %= mod;
        }
    }

    return mp[bits] = ret;
}

void solve() {
    cout << rec(0, 0) << endl;
    // cout << cnt << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    scanf("%lld", &N);
    a = vvi(N, std::vector<long long>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            scanf("%lld", &a[i][j]);
        }
    }
    solve();
    return 0;
}


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

typedef long long ll;

int main(void){
  int n;
  ll sum=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    if(i%3==0||i%5==0){
    }
    else{
      sum+=i;  
    }
  }
  cout<<sum;
  
  return 0;
}


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

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

  while (N != 0) {
    vector<int> s(N);
    double ave = 0;
    for (int i=0; i<N; i++) {
      cin >> s[i];
      ave += s[i];
    }
    ave /= N;

    double sd = 0;
    for (int i=0; i<N; i++) {
      sd += pow(s[i] - ave, 2);
    }
    sd /= N;

    printf("%.5f\n", sqrt(sd));

    cin >> N;
  }

  return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;


int main()
{
	int t;
	cin>>t;
	if(t>=30) cout<<"Yes\n";
	else cout<<"No\n"; 
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<queue>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);++(i))
#define fd1(i,n) for ((i)=(n);(i)>=1;--(i))
#define fz0g(i,n) for ((i)=0;(i)<=(n);++(i))
#define fd0g(i,n) for ((i)=(n);(i)>=0;--(i))
#define fz0k(i,n) for ((i)=0;(i)<(n);++(i))
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;--(i))
#define fz(i,x,y) for ((i)=(x);(i)<=(y);++(i))
#define fd(i,y,x) for ((i)=(y);(i)>=(x);--(i))
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
using namespace std;
int n,mod,i,j,k,dp[505][505],ans,lb[505],rb[505];
pair<int,int> seq[505];
void inc(int &x,int y)
{
	x+=y;if(x>=mod) x-=mod;
}
void dec(int &x,int y)
{
	x-=y;if(x<0) x+=mod;
}
bool cmp(pair<int,int> x,pair<int,int> y)
{
	if(x.first!=y.first) return x.first<y.first;
	return x.second>y.second; 
}
int solve(int x)
{
	int i,j,cl=0,cr=0;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	fz1(i,n+n){
		if(seq[i].second>n){
			fz0g(j,x){
				dp[i][j]=1ll*dp[i-1][j]*(seq[i].first-(j+cr))%mod;
			}
			cr++;
		}
		else{
			fd0g(j,x){
				inc(dp[i][j+1],1ll*dp[i-1][j]*(seq[i].first-(j+cr))%mod);
				dp[i][j]=1ll*dp[i-1][j]*(rb[seq[i].second]-(n+x+(cl-j)))%mod;
			}
			cl++;
		}
//		cerr<<dp[i][0]<<endl;
	}
	return dp[n+n][x]; 
}
int main()
{
	scanf("%d%d",&n,&mod);
	fz1(i,n){
		while(lb[i]<n*2&&(i-1)*(i-1)+lb[i]*lb[i]<n*n) lb[i]++;
	}
	fz1(i,n+n){
		while(rb[i]<n*2&&(i-1)*(i-1)+rb[i]*rb[i]<=n*n*4) rb[i]++;
	}
	fz1(i,n){
		seq[i]=make_pair(lb[i],i);
	}
	fz1(i,n){
		seq[i+n]=make_pair(rb[i+n],i+n);
	}
	sort(seq+1,seq+n+n+1,cmp);
	fz0g(i,n){
		int t=solve(i);
		if(i&1) dec(ans,t); else inc(ans,t);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>
#include <algorithm>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG

static uint64_t g_numOfInv = 0;

void mergeSort(int array[], int helper[], int start, int end)
{

  if (!(start + 1 < end))
    return;

  int mid = (start + end) / 2;

  mergeSort(array, helper, start, mid);
  mergeSort(array, helper, mid, end);

  DPRINTF("START %d  MID %d  END %d\n", start, mid, end);

#if DEBUG
  for (int i = start; i < end; i++)
  {
    if (i == start) DPRINTF("Before: %d", array[i]);
    else            printf(" %d", array[i]);
  }
  cout << endl;
#endif // DEBUG

  for (int i = start; i < end; i++)
    helper[i] = array[i];

  int i = start;
  int left = start;
  int right = mid;

  while (left < mid && right < end)
  {
    if (helper[left] < helper[right])
    {
      array[i] = helper[left];
      i++;
      left++;
    }
    else
    {
      array[i] = helper[right];

      int numOfSkip = mid - left;
      g_numOfInv += numOfSkip;

      DPRINTF("g_numOfInv %d (+= %d - %d)\n", g_numOfInv, mid, left);

      i++;
      right++;
    }
  }

  DPRINTF("i %d  left %d  right %d\n", i, left, right);

  while (left < mid)
  {
    array[i] = helper[left];
    i++;
    left++;
  }

#if DEBUG
  for (int i = start; i < end; i++)
  {
    if (i == start) DPRINTF("After: %d", array[i]);
    else            printf(" %d", array[i]);
  }
  cout << endl;
#endif // DEBUG
}

int main()
{
  int numOfArray;
  cin >> numOfArray; cin.ignore();

  DPRINTF("NUM OF ARRAY %d\n", numOfArray);

  int array[numOfArray];
  for (int i = 0; i < numOfArray; i++)
    cin >> array[i];

#if DEBUG
  for (int i = 0; i < numOfArray; i++)
  {
    if (i == 0) DPRINTF("%d", array[i]);
    else        printf(" %d", array[i]);
  }
  cout << endl;
#endif // DEBUG

  const int start = 0;
  const int end = numOfArray;
  int helper[numOfArray];

  mergeSort(array, helper, start, end);

#if DEBUG
  for (int i = 0; i < numOfArray; i++)
  {
    if (i == 0) DPRINTF("%d", array[i]);
    else        printf(" %d", array[i]);
  }
  cout << endl;
#endif // DEBUG

  cout << g_numOfInv << endl;

  return 0;
}



Measured memory_bytes: 4648
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979

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


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}


ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}

int N;

void dfs(string s, char m, int N){
  size_t len = s.length();
  if(len == N){
    cout << s << endl;
  }else{
    for(char c = 'a'; c <= m; c++){
      dfs(s + c, ((c == m)? (m + 1) : m), N);
    }
  }
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

struct Edge {
    int to, coin;
    int64_t cost;
    Edge(int _to, int _coin, int64_t _cost) : to(_to), coin(_coin), cost(_cost) {}
};
 
const int MAX = 2525;
const int64_t INF = 1e18;
 
int main() {
    int N, M, S;
    cin >> N >> M >> S;
    vector<vector<Edge>> G(N);
    for(int i = 0; i < M; ++i) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }
    vector<int> C(N), D(N);
    for(int i = 0; i < N; ++i) cin >> C[i] >> D[i];
 
    using V = tuple<int64_t, int, int>;
    priority_queue<V, vector<V>, greater<V>> que;
    vector<vector<int64_t>> dist(N, vector<int64_t>(MAX + 1, INF));
    S = min(S, MAX);
    dist[0][S] = 0;
    que.emplace(0, S, 0);
 
    auto push = [&](int v, int coin, int64_t cost) {
        if(coin >= 0 and dist[v][coin] > cost) {
            dist[v][coin] = cost;
            que.emplace(cost, coin, v);
        }
    };
    while(!que.empty()) {
        auto[cost, coin, cur] = que.top(); que.pop();
        for(auto &e : G[cur]) push(e.to, coin - e.coin, cost + e.cost);
        push(cur, min(coin + C[cur], MAX), cost + D[cur]);
    }
 
    for(int i = 1; i < N; ++i) cout << *min_element(dist[i].begin(), dist[i].end()) << '\n';
    return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>

using namespace std;



int main(){
    int n;
    cin >> n;
    vector<int> xs(n), ys(n), is(n);
    for(int i=0; i<n; ++i){
        cin >> xs[i] >> ys[i];
        is[i]=i;
    }
    double sum_dist=0;
    int num=0;
    do{
        ++num;
        double dist=0;
        for(int i=1; i<n; ++i){
            double dx=xs[is[i]]-xs[is[i-1]];
            double dy=ys[is[i]]-ys[is[i-1]];
            dist+=sqrt(dx*dx+dy*dy);
        }
        sum_dist+=dist;
    }while(next_permutation(is.begin(), is.end()));
    cout << setprecision(15) << sum_dist/num << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long MOD = 1e9 + 7;
const int MAX = 2e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    for(auto &e : S) {
        e += N;
        if(e > 'Z') e -= 26;
    }
    cout << S;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
a.sort()

s = [[int(i) for i in input().split()] for j in range(m)]
s.sort(key=lambda x: x[1], reverse=True)

ss = []
for i, j in s:
    ss.extend([j] * i)
    if len(ss) >= n:
        break

ss = ss[:n]
r = ss + a
r.sort(reverse=True)
r = r[:n]

print(sum(r))

Measured memory_bytes: 92952
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    int n,m;cin>>n>>m;
    vector<int>a(m);
    rep(i,m)cin>>a[i];
    int ans=n;
    rep(i,m)ans-=a[i];
    if(ans<0)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main() {
	int n, now;
	scanf("%d", &n);
	now = 7 % n;
	for (int i = 1; i <= n; i++) {
		if (now == 0) {
			printf("%d\n", i);
			return 0;
		}
		now = (now * 10 + 7) % n;
	}
	printf("-1\n");
}


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

int main()
{
	int x, n;
	while (scanf("%d%d", &x, &n) != EOF) {
		if (n == 0) {
			printf("%d\n", x);
			continue;
		}
		int i, p;
		int f[105];
		memset(f, 0, sizeof(f));
		for (i = 0; i < n; i ++) {
			scanf("%d", &p);
			f[p] = 1;
		}
		
		int a1, a2;
		int mina = 9999;
		a1 = 0;
		for (i = 1; i <=101; i ++) {
			if (f[i] == 0) {
				int diff = abs(i - x);
				if (diff < mina) {
					a1 = i;
					mina = diff;
				}
			}
		}
		
		if (abs(a1 - x) < abs(0 - x)) {
			printf("%d\n", a1);
		} else {
			printf("%d\n", 0);
		}
	}
	return (0);
}


Measured memory_bytes: 1728
#include <cstdio>

const int N=100005,mo=1000000007;
int f0[N],f1[N];
long long a[N],A,B;

int main(){
	int n,l0=0,l1=0,r0=0,r1=0,s0=0,s1=0;
	scanf("%d%lld%lld\n%lld",&n,&A,&B,&a[1]);
	a[0]=-1e18;f0[0]=f1[0]=1;
	for (int i=1;i<n;i++){
		scanf("%lld",&a[i+1]);
		for (;l0<i && a[i+1]-a[l0]>=B;l0++) (s0+=f0[l0])%=mo;
		for (;l1<i && a[i+1]-a[l1]>=A;l1++) (s1+=f1[l1])%=mo;
		f0[i]=s1;f1[i]=s0;
		if (a[i+1]-a[i]<A) for (;r0<i;f0[r0++]=0) if (r0<l0) (s0-=f0[r0])%=mo;
		if (a[i+1]-a[i]<B) for (;r1<i;f1[r1++]=0) if (r1<l1) (s1-=f1[r1])%=mo;
	}
	int ans=0;
	for (int i=r0;i<n;i++) (ans+=f0[i])%=mo;
	for (int i=r1;i<n;i++) (ans+=f1[i])%=mo;
	printf("%d\n",(ans+mo)%mo);
}

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

typedef long long ll;

const int N = 45;

int n;
char s[N][N];
ll f[N][N][N], ans;

int main()
{
	std::cin >> n; n <<= 1;
	for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
	for (int i = 1; i < n; i++) f[i][i][i] = 1;
	for (int l = n - 1; l >= 1; l--) for (int r = l + 2; r < n; r += 2)
	for (int i = l + 1; i < r; i++) for (int a = l; a < i; a++)
	for (int b = a; b < i; b++) for (int c = r; c > i; c--) for (int d = c; d > i; d--)
		if (s[a][c] == '1') f[l][r][i] += f[l][b][a] * f[b + 1][d - 1][i] * f[d][r][c];
	for (int i = 1; i < n; i++) if (s[i][n] == '1') ans += f[1][n - 1][i];
	return std::cout << ans << std::endl, 0;
}

Measured memory_bytes: 4156
#include <stdio.h>
#define MAX 100005
#define NIL -1

struct Node {
	int p , r , l;
};

struct Node T[MAX];
int n , D[MAX];

void print(int u)
{
	int i , c;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].p);
	printf("depth = %d, ",D[u]);
	
	if( T[u].p == NIL) printf("root, ");
	else if(T[u].l == NIL) printf("leaf, ");
	else printf("internal node, ");
	
	printf("[");
	
	for( i = 0, c = T[u].l; c != NIL; i++ , c = T[c].r)
	{
		if(i)printf(", ");
		printf("%d",c);
	}
	printf("]\n");
}

int rec( int u , int p)
{
	D[u] = p;
	if(T[u].r != NIL) rec(T[u].r,p);
	if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void)
{
	int i , j , d , v , c , l , r;
	scanf("%d",&n);
	for( i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
	
	for( i = 0; i < n; i++)
	{
		scanf("%d %d",&v,&d);
		for( j = 0; j < d; j++)
		{
			scanf("%d",&c);
			if( j == 0)T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	for( i = 0; i < n; i++)
	{
			if(T[i].p == NIL) r = i;
	}
	
	rec(r,0);
	for( i = 0; i < n; i++) print(i);
	return 0;
}



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

using namespace std;

int main() {
   int n,a,b;
   cin >> n >> a >> b;

   cout << min(a,b);
   if(a+b <= n){
      cout << " 0"; 
   }else{
      cout << " " << (a+b-n) << endl;
   }
   return 0;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
import numpy as np

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    cumsum = [A[0]]
    for n in range(1, N):
        cumsum.append(cumsum[n - 1] + A[n])

    ret = 0
    for n in range(N):
        ret += A[n] * (cumsum[-1] - cumsum[n])
        ret %= MOD
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 46176
#include <bits/stdc++.h>
using namespace std;
const int maxn=1000001;
typedef long long ll;
const ll MOD = 1e9+7;
int cnt[100];
bool cov[100];
ll fac[maxn];
ll inv[maxn];
ll rev[maxn];
ll C(ll n,ll k){
    if (n<0)
        return 0;
    if (k<0)
        return 0;
    if (n<k)
        return 0;
    return fac[n]*inv[k]%MOD*inv[n-k]%MOD;
}
ll f(ll n,ll k){
    return C(k-1,n-k-1);
}
ll z[maxn];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    fac[0]=1;
    for(int i=1; i<=n; ++i)
        fac[i]=fac[i-1]*i%MOD;
    rev[1]=1;
    inv[1]=1;
    inv[0]=1;

    for(int i=2; i<=n; ++i){
        rev[i]=rev[MOD%i]*(MOD-MOD/i)%MOD;
        inv[i]=inv[i-1]*rev[i]%MOD;
    }
    for(int i=1; i<=n; ++i)
        z[i]=f(n,i);
    ll ans=0;
    for(int i=1; i<n; ++i){
        //cout<<i<<" "<<z[i]<<endl;
        z[i]*=fac[i];
        z[i]%=MOD;
        z[i]*=fac[n-1-i];
        z[i]%=MOD;
        //cout<<" "<<i<<" "<<z[i]<<endl;
        //cout<<z[i]-z[i-1]<<endl;
        ans+=(z[i]-z[i-1]+MOD)*i%MOD;
        if (ans>=MOD)
            ans-=MOD;
    }
    cout<<ans;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
#define double long double
const int mod=1000000007,MAX=205,INF=1<<28;
string S;
int N;
set<int> dp[MAX][MAX];
bool seen[MAX][MAX];

bool num(int i){
    if('0'<=S[i]&&S[i]<='9') return 1;
    else return 0;
}

void merge(int l1,int r1,int l2,int r2,char c){
    for(auto a:dp[l1][r1]){
        for(auto b:dp[l2][r2]){
            if(c=='/'&&b==0) continue;
            
            if(c=='+') dp[l1][r2].insert(a+b);
            if(c=='-') dp[l1][r2].insert(a-b);
            if(c=='*') dp[l1][r2].insert(a*b);
            if(c=='/') dp[l1][r2].insert(a/b);
        }
    }
}

void solve(int l,int r){
    if(seen[l][r]) return;
    seen[l][r]=1;
    
    bool numcheck=true;
    if(l&&num(l-1)) return;
    if(r<N&&num(r)) return;
    for(int i=l;i<r;i++) if(!num(i)) numcheck=false;
    
    if(numcheck){
        int ret=0;
        for(int i=l;i<r;i++){
            ret*=10;
            ret+=S[i]-'0';
        }
        dp[l][r].insert(ret);
    }
    
    if(S[l]=='('){
        if(S[r-1]==')'){
            solve(l+1,r-1);
            dp[l][r]=dp[l+1][r-1];
        }
    }
    
    for(int i=l+1;i<r-1;i++){
        if(S[i]=='+'||S[i]=='-'||S[i]=='*'||S[i]=='/'){
            solve(l,i);
            solve(i+1,r);
            merge(l,i,i+1,r,S[i]);
        }
    }
    
    return;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        cin>>S;
        if(S=="#") break;
        
        N=si(S);
        for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) dp[i][j].clear();
        memset(seen,0,sizeof(seen));
        
        solve(0,N);
        
        cout<<si(dp[0][N])<<endl;
    }
}





Measured memory_bytes: 5264
#include<iostream>

using namespace std;

int main(){

   int N, M;
   cin>> N>> M;
   char a[N][N], b[M][M];
   for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
         cin>> a[i][j];
      }
   }
   for(int i=0; i<M; i++){
      for(int j=0; j<M; j++){
         cin>> b[i][j];
      }
   }

   bool okok=false;
   for(int i=0; i+M-1<N; i++){
      for(int j=0; j+M-1<N; j++){
         bool ok=true;
         for(int k=0; k<M; k++){
            for(int l=0; l<M; l++){
               ok&=a[i+k][j+l]==b[k][l];
            }
         }
         okok|=ok;
      }
   }

   if(okok){
      cout<< "Yes"<< endl;
   }else{
      cout<< "No"<< endl;
   }

   return 0;
}


Measured memory_bytes: 256