akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var d = cin.ReadIntArray(N);
            Array.Sort(d);
            var ans = 0;
            if (N % 2 == 0)
            {
                ans = d[N / 2] - d[N / 2 - 1];
            }
            else
            {
                ans = 0;
            }
            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


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

int main() {
  int N; cin >> N;
  string str = "";
  while (N != 0) {
	int r = N % 2;
	if (r < 0) r += 2;
	N -= r; N /= -2;
	str += (char)('0' + r);
  }
  reverse(str.begin(), str.end());
  if (str == "") str = "0";
  cout << str << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int mxsz = 1e5 + 3;
int n, m;
vector<pii> v;
int main(){
	cin >> n >> m;
	v.resize(m);
	for (int i = 0; i < m; i++){
		cin >> v[i].fi >> v[i].se;
	}
	sort(v.begin(), v.end());
	int tot = 0;
	int l = 0, r = 0x3f3f3f3f;
	for (int i = 0; i < m; i++){
		l = max(l, v[i].fi);
		r = min(r, v[i].se);
	}
	cout << max(0, r - l + 1) << '\n';
	return 0;
}


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

int main() {
  int n;
  LL T;
  scanf("%d %lld", &n, &T);
  LL ans = 0;
  for (int i = 0, p = 0, t; i < n; i ++) {
    scanf("%d", &t);
    ans += T - max(0, p - t);
    p = t + T;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
s=[0]*N
t=[0]*N
for i in range(N):
  s[i],t[i] = input().split()
  t[i]=int(t[i])
X=input()

j= s.index(X)
if X==s[-1]:
  ans=0
else:
  ans= sum(t[j+1:])

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  if(s=="SUN") cout << "7" << endl;
  else if(s=="MON") cout << "6" << endl;
  else if(s=="TUE") cout << "5" << endl;
  else if(s=="WED") cout << "4" << endl;
  else if(s=="THU") cout << "3" << endl;
  else if(s=="FRI") cout << "2" << endl;
  else if(s=="SAT") cout << "1" << endl;
  return 0;
}


Measured memory_bytes: 256
import fractions
import math

def devide_num(num, p):
    if num % p == 0:
        return devide_num(num//p, p)
    else:
        return num

a, b = list(map(lambda x: int(x), input().split()))

ab_gcd = fractions.gcd(a, b)

max_num =  math.ceil(math.sqrt(ab_gcd))
ans_list = []

for i in range(max_num):
    val = i+1
    if val == 1:
        ans_list.append(val)
    else:
        if ab_gcd % val == 0:
            ans_list.append(val)
            ab_gcd = devide_num(ab_gcd, val)
            
    if ab_gcd == 1:
        break
     
if ab_gcd != 1:
    ans_list.append(ab_gcd)

print(len(ans_list))

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

int main() {
  int a,b,c; cin >> a >> b >> c;
  int m = max(a,max(b,c));
  int ans = 0;
  ans += (m - a) / 2;
  ans += (m - b) / 2;
  ans += (m - c) / 2;
  int n = (m-a)%2 + (m-b)%2 + (m-c)%2;
  if (n == 1) ans+=2;
  if (n == 2) ans+=1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
vector<int> node[100005];
map<int,int> mp[100005];
bool vis[100005];
int cnt=0;
void dfs(int x,int par)
{
    vis[x]=1;
    int ase=0;
    for(int i=0; i<node[x].size(); i++)
    {
        int y=node[x][i];
        if(vis[y]==0)
        {
            ase++;
            //dfs(y,x);
        }
    }
    if(par==0)
    {
        if(ase<=cnt)
        {
            int j=0;
            for(int i=0; i<node[x].size(); i++)
            {
                int y=node[x][i];
                if(vis[y]==0)
                {
                    j++;
                    mp[x][y]=j;
                    mp[y][x]=j;
                    //dfs(y,x);
                }
            }
        }
        else
        {
            cnt=ase;
            int j=0;
            for(int i=0; i<node[x].size(); i++)
            {
                int y=node[x][i];
                if(vis[y]==0)
                {
                    j++;
                    mp[x][y]=j;
                    mp[y][x]=j;
                    //dfs(y,x);
                }
            }
        }
    }
    else
    {
        int col=mp[par][x];
        if(ase<cnt)
        {
            int j=0;
            for(int i=0; i<node[x].size(); i++)
            {
                int y=node[x][i];
                if(vis[y]==0)
                {
                    j++;
                    if(j==col)
                    {
                        j++;
                    }
                    mp[x][y]=j;
                    mp[y][x]=j;
                    //dfs(y,x);
                }
            }
        }
        else
        {
            cnt=ase+1;
            int j=0;
            for(int i=0; i<node[x].size(); i++)
            {
                int y=node[x][i];
                if(vis[y]==0)
                {
                    j++;
                    if(j==col)
                    {
                        j++;
                    }
                    mp[x][y]=j;
                    mp[y][x]=j;
                    //dfs(y,x);
                }
            }
        }
    }
    for(int i=0; i<node[x].size(); i++)
    {
        int y=node[x][i];
        if(vis[y]==0)
        {
            dfs(y,x);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<pair<int,pair<int,int> > > tmp;
    for(int i=1; i<n; i++)
    {
        int u,v;
        cin>>u>>v;
        node[u].push_back(v);
        node[v].push_back(u);
        tmp.push_back(make_pair(i,make_pair(u,v)));
    }
    cnt=0;
    dfs(1,0);
    cout<<cnt<<endl;
    for(int i=0;i<tmp.size();i++)
    {
        int u=tmp[i].second.first;
        int v=tmp[i].second.second;
        cout<<mp[u][v]<<endl;
    }

    return 0;
}


Measured memory_bytes: 21428
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll H;
  cin>>H;
  ll ans = 0;
  ll two = 1;
  while(H>0) {
    ans += two;
    two *= 2;
    H /= 2;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
	long long int a,b,k;
	long long int s=0;
	cin>>k>>a>>b;
	if(b-2<=a)s=k+1;
	else{
		if(a>1)s+=a-1,k-=a-1;
		s+=(b-a)*(k/2)+k%2+1;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

ll a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;

int main()
{
	cin >> s;
	if (s[1] == 'B')cout << "ARC" << endl;
	else cout << "ABC" << endl;

	return 0;
}


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

int main()
{
	double d = 100000.0;
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		d *= 1.05;
		d /= 1000.0;
		d = ceil(d);
		d *= 1000;
	}
	cout << (int)d << '\n';
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
int main() {

	int n, b[105]={},a[105]={},s=0; 
	cin >> n;
    for(int i=1;i<n;i++){
        cin>>b[i];
    }	
    a[1]=b[1];
    a[2]=b[1];
    for(int i=2;i<n;i++){
        a[i]=min(a[i],b[i]);
        a[i+1]=b[i];
    }
    for(int i=1;i<=n;i++){
      //  cout<<a[i]<<" ";
        s+=a[i];
    }
    cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>

const int N = 1e5 + 51;

std::map<int, int> mp;
int sz;
int id(int x) {
	if (!mp.count(x)) return mp[x] = ++sz;
	return mp[x];
}

int p[N];
int f(int x) { return x[p] ? x[p] = f(x[p]) : x; }

int n, a[N], b[N], ans, fl = 1;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i), a[n + 1] ^= a[i];
	for (int i = 1; i <= n; i++) scanf("%d", b + i), b[n + 1] ^= b[i];
	for (int i = 1, x, y; i <= n; i++)
		if (a[i] != b[i]) {
			ans++;
			if ((x = f(id(a[i]))) != (y = f(id(b[i])))) x[p] = y;
			if (a[i] == a[n + 1] && fl) ans--, fl = 0;
			if (b[i] == b[n + 1] && fl) ans--, fl = 0;
			if (a[i] == b[n + 1] && fl) ans--, fl = 0;
			if (b[i] == a[n + 1] && fl) ans--, fl = 0;
		}
	std::sort(a + 1, a + n + 2);
	std::sort(b + 1, b + n + 2);
	for (int i = 1; i <= n + 1; i++)
		if (a[i] != b[i]) return puts("-1"), 0;
	for (int i = 1; i <= sz; i++) ans += !i[p];
	printf("%d", ans);
}

Measured memory_bytes: 7680
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int K;

int main()
{
    cin >> K;
    int even = K / 2;
    int odd = (K + 1) / 2;
    cout << even * odd << endl;
}


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

vector<ll> totals;
vector<ll> patties;

ll saiki(ll N, ll X)
{
    //レベル0なら1を返す
    if(N == 0)
    {
        return 1;
    }
    //現在の(レベル-1)での位置をカウントし、その区切りより右のレベルはその層数をそのまま使う
    if(X == totals.at(N))
    {
        //左端
        return patties.at(N);
    }else if(X > totals.at(N - 1) + 2){
        //左のレベルN - 1のどこか
        ll nextX = X - totals.at(N - 1) - 2;
        return patties.at(N - 1) + saiki(N - 1, nextX) + 1;
    }else if(X == totals.at(N - 1) + 2){
        //真ん中
        return patties.at(N - 1) + 1;
    }else if(X > 1){
        //右のレベルN - 1 のどこか
        return saiki(N - 1, X - 1);
    }else if(X == 1){
        //右端
        return 0;        
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    totals = vector<ll>(N + 1);//レベルNのバーガー全体の層数
    patties = vector<ll>(N + 1);//レベルNのパティの数
    totals.at(0) = 1;
    patties.at(0) = 1;
    for (int i = 1; i <= N; i++)
    {
        totals.at(i) = totals.at(i - 1) * 2 + 3;
        patties.at(i) = patties.at(i - 1) * 2 + 1;
    }
    cout << saiki(N, X) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    long long a, ans = 1;
    long long lim = pow(10, 18);
    bool flag = false;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a == 0){
            cout << 0 << endl;
            return 0;
        }
        if(a <= lim / ans) ans *= a;
        else flag = true;
    }
    if(flag) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3584
n=int(input())
a=sorted(list(map(int,input().split())))
b=[0]*n
b[0]=a[0]
for i in range(1,n):
  b[i]=b[i-1]+a[i]
p=1
for i in range(n-1)[::-1]:
  if b[i]*2>=a[i+1]:
    p+=1
  else:
    break
print(p)

Measured memory_bytes: 14252
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int v[20], c[20];

int main(void) {

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}

	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += max(0,v[i] - c[i]);
	}
	COUT(sum);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<ll, vector<ll>, less<ll> > que;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        que.push(a);
    }
    for(int i = 0; i < m; i++){
        ll p = que.top();
        que.pop();
        que.push( p / 2);
    }
    ll ans = 0LL;
    while(!que.empty()){
        ll p = que.top();
        ans += p;
        que.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var k = long.Parse(spl[1]);

        var ab = new int[n][];
        for(int i=0; i<n; i++) {
            ab[i] = new int[2];
            spl = input.ReadLine().Split(' ');
            ab[i][0] = int.Parse(spl[0]);
            ab[i][1] = int.Parse(spl[1]);
        }

        Array.Sort(ab, (x,y) => x[0] - y[0]);

        long p = 0;
        for(int i=0; i<n; i++) {
            var a = ab[i][0];
            var b = ab[i][1];

            p += b;
            if(p >= k) return a;
        }

        return -1;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<pair<int,int>> ab(m);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
        ab[i] = {a-1,b-1};
    }

    int ans = 0;
    vector<bool> seen(n, false);
    queue<int> que;

    rep(i,m) {
        fill(seen.begin(),seen.end(),false);
        int seen_cnt = 0;
        que.push(0);
        seen[0] = true;
        ++seen_cnt;

        while(!que.empty()) {
            int cv = que.front();
            que.pop();
            for(auto nv:g[cv]) {
                if(seen[nv]) continue;
                if(cv == ab[i].first && nv == ab[i].second)
                    continue;
                if(cv == ab[i].second && nv == ab[i].first)
                    continue;
                que.push(nv);
                seen[nv] = true;
                ++seen_cnt;
            }
        }

        if(seen_cnt != n) ++ans;
    }

    cout << ans << endl;
    return 0;
}

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

int main(){
    int h,a;
    cin >>h>>a;
    cout << (h+a-1)/a <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) begin(x),end(x)
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
	int N, M;
	cin >> N >> M;

	vector<int> e( M );
	for( auto &x : e )
	{
		cin >> x;
	}

	reverse( ALL( e ) );

	vector<int> vc, flag( N + 1, 0 );
	REP( i, M )//O(n)
	{
		if( flag[ e[ i ] ] == 0 )//O(1)
		{
			vc.emplace_back( e[ i ] );//O(1)
			flag[ e[ i ] ] = 1;
		}
	}

	//move
	for( const auto &x : vc )
	{
		cout << x << endl;
	}

	//not move
	REP2( i, 1, N + 1 )//O(n)
	{
		if( flag[ i ] != 0 )//O(1)
		{
			continue;
		}
		cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 4740
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll getScore(vector<bool> givingList) {
    ll ans = 0;
    for (bool b : givingList) {
        if (b) {
            ans++;
        }
    }
    return ans;
}

ll calcPath(vector<ll> holdingTrashes, ll X) {
    ll score = 0;
    ll cost = 1;
    score += holdingTrashes[0];
    holdingTrashes.push_back(0);
    FOR(i, 1, holdingTrashes.size()) {
        cost++;
        score += (holdingTrashes[i - 1] - holdingTrashes[i]) * cost * cost;
    }
    score += X * holdingTrashes.size();
    return score;
}

int main() {
    ll N, T, A;
    cin >> N >> T >> A;
    double diff = 10000;
    ll index = 0;
    REP(i, N) {
        ll n;
        cin >> n;
        double temp = T -  0.006 * n;
        double thisDiff = abs(temp - A);
        if (thisDiff < diff) {
            index = i;
            diff = thisDiff;
        }
    }
    cout << index + 1;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
const int size=2e5+5;
typedef long long int ll;
ll tree[size];
ll query(int x)
{
    ll ret = 0;
    for(int i=x;i;i -= i & -i)
        ret = max(ret,tree[i]);
    return ret;
}
void update(int x,ll val)
{
    for(int i=x;i<size;i += i & -i)
        tree[i] = max(tree[i],val);
}
int main()
{
    int n;
    cin>>n;
    int h[n],a[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll ans = 0;
    for(int i=0;i<n;i++)
    {
        ll idx = query(h[i]);
        update(h[i],1LL*idx+a[i]);
        ans = max(ans,tree[h[i]]);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

ll p(ll i,ll j){
  if(i>=j){
    return i-j;
  }
  else{
    return j-i;
  }
}

int main(){
  ll n;cin>>n;
  vector<P> v(n);
  ll a;
  rep(i,n) {
    cin>>a;
    v[i]=P(a,i);
  }
  sort(all(v));
  ll dp[n+1][n+1];
  rep(i,n+1)rep(j,n+1) dp[i][j]=0;
  dp[0][0]=0;
  Rep(i,1,n+1){
    ll u=n-i;
    rep(j,i+1){
      if(j-1<0) dp[j][i-j]=dp[j][i-j-1]+v[u].fi*p(v[u].se,n-(i-j));
      else if(i-j-1<0) dp[j][i-j]=dp[j-1][i-j]+v[u].fi*p(v[u].se,j-1);
      else dp[j][i-j]=max(dp[j-1][i-j]+v[u].fi*p(v[u].se,j-1),dp[j][i-j-1]+v[u].fi*p(v[u].se,n-(i-j)));
    }
  }
  ll ans=0;
  rep(i,n+1){
    ans=max(ans,dp[i][n-i]);
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 34956
module.exports=function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){i(1)(i(3).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(t,e,i){var n=i(2);t.exports=function(t){for(var e=t[0].split(" "),i=Number(e[0]),r=Number(e[1]),s=[],o=0,u=new n(1e7),d=0;d<i;d++){for(var f=t[d+1].split(""),l=0;l<r;l++)"#"==f[l]?u.enq({x:l,y:d,dist:0}):o+=1;s.push(f)}for(;u.size>0;){var c=u.deq();if("."==s[c.y][c.x]||0==c.dist){if("."==s[c.y][c.x]&&(s[c.y][c.x]="#",o-=1),o<=0)return void console.log(c.dist);c.x+1<r&&"#"!=s[c.y][c.x+1]&&u.enq({x:c.x+1,y:c.y,dist:c.dist+1}),c.x-1>=0&&"#"!=s[c.y][c.x-1]&&u.enq({x:c.x-1,y:c.y,dist:c.dist+1}),c.y+1<i&&"#"!=s[c.y+1][c.x]&&u.enq({x:c.x,y:c.y+1,dist:c.dist+1}),c.y-1>=0&&"#"!=s[c.y-1][c.x]&&u.enq({x:c.x,y:c.y-1,dist:c.dist+1})}}}},function(t,e,i){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e4;this.size=0,this.items=[],this.ind=0,this.maxGap=t}enq(t){this.size+=1,this.items.push(t),this.items.size-this.ind>this.maxGap&&(this.items=this.items.slice(this.ind))}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,e){t.exports=require("fs")}]);

Measured memory_bytes: 200640
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int ans = 1 ^ 2 ^ 3 ^ 4 ^ 5;
	for (int i = 0; i < 5; i++) {
		int n;
		cin >> n;
		ans ^= n;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3612
import math
n = int(input())
l1 = list(range(1,n+1))
l2 = list(range(1,n+1))
n2 = n
p = list(map(int,input().split()))
q = list(map(int,input().split()))
ans_p = 1
ans_q = 1
# print(l1)
for i in range(n):
    ans_p += (math.factorial(n-1)) * l1.index(p[0])
    # print(p.index(i+1))
    # print(i)
    l1.remove(p[0])
    p.remove(p[0])
    n-=1
# print(ans_p)
for j in range(n2):
    ans_q += (math.factorial(n2-1)) * l2.index(q[0])
    # print((math.factorial(n2)) * l2.index(q[0]))
    # print(p.index(i+1))
    # print(i)
    l2.remove(q[0])
    q.remove(q[0])
    n2 -= 1

# print(ans_p)
# print(ans_q)
print(abs(ans_p-ans_q))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t long long
// std::sort(&a[0], &a[4], [](auto& x, auto& y){return x[0] < y[0];});
//accumulate(&arr2[n], &arr2[m-1], 0);
using namespace std;

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

  int N;
  std::cin >> N;
  int d[N] = {};

  for (size_t i = 0; i < N; i++) {
    std::cin >> d[i];
  }
  sort(&d[0], &d[N]);
  std::cout << d[(N-1)/2+1]-d[(N-1)/2] << '\n';

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
int q,r,m,o,k=0,l,n,a[12][12],b[12][12],c[12],i,j,d[12];
scanf("%d\n",&n);
for(l=0;l<n;l++){
for(i=1;i<10;i++){
for(j=1;j<10;j++){
scanf("%d",&a[i][j]);
b[i][j]=0;
}
scanf("\n");
}
for(i=1;i<10;i++){
for(j=0;j<10;j++){
c[j]=0;
}
for(j=1;j<10;j++){
if(c[a[i][j]]==0){
c[a[i][j]]++;
}
else{
d[k]=a[i][j];
k++;
}
}
for(o=0;o<k;o++){
for(j=1;j<10;j++){
if(a[i][j]==d[o]){
b[i][j]=1;
}
}
}
k=0;
}
for(i=1;i<10;i++){
for(j=0;j<10;j++){
c[j]=0;
}
for(j=1;j<10;j++){
if(c[a[j][i]]==0){
c[a[j][i]]++;
}
else{
d[k]=a[j][i];
k++;
}
}
for(o=0;o<k;o++){
for(j=1;j<10;j++){
if(a[j][i]==d[o]){
b[j][i]=1;
}
}
}
k=0;
}
for(i=3;i<10;i=i+3){
for(j=3;j<10;j=j+3){
for(q=0;q<10;q++){
c[q]=0;
}
for(m=i-2;m<=i;m++){
for(o=j-2;o<=j;o++){
if(c[a[m][o]]==0){
c[a[m][o]]++;
}
else{
d[k]=a[m][o];
k++;
}
}
}
for(r=0;r<k;r++){
for(m=i-2;m<=i;m++){
for(o=j-2;o<=j;o++){
if(a[m][o]==d[r]){
b[m][o]=1;
}
}
}
}
k=0;
}
}
for(i=1;i<10;i++){
for(j=1;j<10;j++){
if(b[i][j]==1){
printf("*%d",a[i][j]);
}
else{
printf(" %d",a[i][j]);
}
}
printf("\n");
}
if(l!=n-1){
printf("\n");
}
}
return 0;
}


Measured memory_bytes: 2092
#include <cstdio>
#include <algorithm>
int N, a[200], O;
int main()
{
	scanf("%d", &N);
	N <<= 1;
	for (int i = 0; i < N; i++)
		scanf("%d", a + i);
	std::sort(a, a + N);
	for (int i = 0; i < N; i += 2)
		O += a[i];
	printf("%d\n", O);
	return 0;
}


Measured memory_bytes: 128
n = int(input())
s = list()
h = list()
c = list()
d = list()
for i in range(n):
  a = input().split()
  p = a[0]
  q = int(a[1])
  if p == 'S':
    s.append(q)
  elif p == 'H':
    h.append(q)
  elif p == 'C':
    c.append(q)
  else:# p == 'D'
    d.append(q)
x = 1
for j in range(13):
  if x not in s:
    print('S',x)
  x += 1
x =1
for k in range(13):
  if x not in h:
    print('H',x)
  x += 1
x = 1
for l in range(13):
  if x not in c:
    print('C',x)
  x += 1
x =1
for m in range(13):
  if x not in d:
    print('D',x)
  x += 1



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i,0,n-1) {
        int u,v;
        cin>>u>>v;
        --u;
        --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<bool> vis(n);
    vector<ll> dp1(n), dp2(n);
    const ll MOD = 1e9+7;
    function<void(int)> dfs = [&](int u) {
        vis[u] = true;
        dp1[u] = 1;
        dp2[u] = 1;
        for(int v:g[u]) {
            if(!vis[v]) {
                dfs(v);
                dp1[u] = (dp1[u]*(dp1[v]+dp2[v]))%MOD;
                dp2[u] = (dp2[u]*(dp1[v]))%MOD;
            }
        }
    };
    dfs(0);
    ll tot = (dp1[0]+dp2[0])%MOD;
    cout<<tot<<"\n";
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;
typedef long long ll;



  int main(){

   int n,k,Q;
   cin>>n>>k>>Q;
   int a[n];

   for(int i=1;i<=n;i++)
     a[i] = k;

 long long ani = Q;
 while(ani--){
  int x;
  cin>>x;
  a[x] += 1; }


  int cnt=0;
 for(int i=1;i<=n;i++){
     a[i] -= Q;
 }


 for(int i=1;i<=n;i++){
    if(a[i] > 0)
      cout<<"Yes"<<endl;
      else
      cout<<"No"<<endl;
    }


  return 0;
  }



Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n);
    REP(i,n) cin >> v[i];
    sort(RALL(v));
    int ans = 1;
    int cnt = v[0];
    REP(i,n) {
        if (v[i] < cnt) {
            ans++;
            cnt = v[i];
        }
    }

    OUT(ans)

    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int max=a.at(N-1);
  cout << max << " ";
  int c,C,ans;
  for(int i=0;i<N;i++){
    c=a.at(i)*2-max;
    if(c>=0){
      ans=i;
      break;
    }
    C=c;
  }
  if(abs(C)>abs(c))
    cout << a.at(ans);
  else if(ans==0)
    cout << a.at(ans);
  else
    cout << a.at(ans-1);
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int a, b;
  cin >> a >> b;

  // 解答
  cout << max(a + b, max(a - b, a * b)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<int> v;
  long long ans = 0;
  bool c = true;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] >= 0) {
      c = false;
    }
  }

  if (c) {
    long long mi = 0;
    for (int i = 1; i < n; i++)
      if (a[mi] < a[i])
        mi = i;
    v.push_back(mi);
    ans = a[mi];
  } else {
    long long odd = 0, even = 0;
    vector<int> ov, ev;
    for (int i = 0; i < n; i += 2)
      if (a[i] >= 0) {
        ov.push_back(i);
        odd += a[i];
      }
    for (int i = 1; i < n; i += 2)
      if (a[i] >= 0) {
        ev.push_back(i);
        even += a[i];
      }
    if (odd > even) {
      v = ov;
      ans = odd;
    } else {
      v = ev;
      ans = even;
    }
  }

  cout << ans << endl;
  int size = n;
  vector<int> w;
  for (int i = 0; i < v[0]; i++) {
    w.push_back(1);
    size--;
  }
  int del = 0;
  for (int i = 1; i < v.size();) {
    if (v[i] - v[0] - del == 2) {
      w.push_back(2);
      size -= 2;
      del += 2;
      i++;
    } else {
      w.push_back(3);
      size -= 2;
      del += 2;
    }
  }
  while (size > 1) {
    w.push_back(size);
    size--;
  }
  cout << w.size() << endl;
  for (int i = 0; i < w.size(); i++)
    cout << w[i] << endl;

  return 0;
}


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

# n までに2**(i-1)が何個含まれるか

def solve(n, i):
    res = 0
    mod = 2**i
    c = n // mod
    res += c*mod//2
    if n % mod >= mod//2:
        res += (n%mod - mod//2 + 1)
    return res

b_list = [0]*40
a_list = [0]*40
ans = 0
for i in range(1, 41):
    num_l = solve(b, i)
    num_r = solve(a-1, i)
    num_one = num_l - num_r
    if num_one% 2 == 1:
        ans += 2**(i-1)
print(ans)



Measured memory_bytes: 3188
s=input()
ans=0
n=len(s)
for i in range(1,n+1):
    for j in range(i):
        m=int(s[j:i])
        if j!=0:
            m*=2**(j-1)
        if i!=n:
            m*=2**(n-i-1)
        ans+=m
print(int(ans))


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector <char> a[n];
	vector <int> dp[n];
	queue <pair <int, int>> bfs;
	for (int i=0; i<n; i++) {
		a[i].resize(m);
		dp[i].resize(m);
		for (int j=0; j<m; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				bfs.push({i, j});
				dp[i][j] = 1;
			}
		}
	}
	int ans;
	pair <int, int> t[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
	while (!bfs.empty()) {
		int x = bfs.front().first, y = bfs.front().second;
		bfs.pop();
		for (int i=0; i<4; i++) {
			int xx = x+t[i].first;
			int yy = y+t[i].second;
			if (!(xx >= 0 && xx < n && yy >= 0 && yy < m)) continue;
			if (!dp[xx][yy]) {
				dp[xx][yy] = dp[x][y] + 1;
				bfs.push({xx, yy});
			}
		}
		if (bfs.empty()) {
			ans = dp[x][y];
		}
	}
	cout << ans-1;
	return 0;
}


Measured memory_bytes: 13456
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = str(input())

BAN = [""]*N
score = 0

for i in range(K):#手が制限されるまではどんな手を出そうが問題はない
    if T[i]=="r":
        score += P
        BAN[i] = "p"
    elif T[i]=="s":
        score += R
        BAN[i] = "r"
    else:
        score += S
        BAN[i] = "s"


for j in range(K,N):
    if T[j]=="r":#相手の手はなんですか
        if BAN[j-K]=="p" :#もしこの手がBANされたものであるならあいこまたは負けの処理
            continue
        else:#でなければ得点になりK回先の手が制限される
            score += P
            BAN[j] = "p"
    elif T[j] == "s":
        if BAN[j-K] == "r":
            continue
        else:
            score += R
            BAN[j] = "r"
    else:
        if BAN[j-K] == "s":
            continue
        else:
            score += S
            BAN[j] = "s"

print(score)


Measured memory_bytes: 4084
#a=int(input())
#b,c=int(input()),int(input())
# c=[]
#  for i in b:
#     c.append(i)
N,X = map(int,input().split())
# f = list(map(int,input().split()))
#j = [input() for _ in range(a)]
# h = []
# for i in range(e1):
#     h.append(list(map(int,input().split())))
a=[]
for i in range(N):
    m=int(input())
    a.append(m)
b=min(a)
c=(X-sum(a))//b
print(c+N)


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

int main()
{
int W, H, x, y, r = 0;
	cin >> W >> H >> x >> y >> r;
	if ((x < r) || (y < r) || (x + r > W) || (y + r > H))
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
	return 0;
}

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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
typedef long long ll;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    cout << min(C,B/A) << endl; 

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	int n,x=0,y=0;
	cin>>n;
	int a[n];
	map<int,int>m1,m2;
	int mx1=-1e8,mx2=-1e8;
	int xx=0,yy=0;
	rep(i,n){
		cin>>a[i];
		if(i & 1){
			x++;
			m1[a[i]]++;
			if(mx1<m1[a[i]]){
				mx1=m1[a[i]];
				xx=a[i];
			}
		}
		else{
			y++;
			m2[a[i]]++;
			if(mx2<m2[a[i]]){
				mx2=m2[a[i]];
				yy=a[i];
			}
		}
	}
	if(xx==yy){
			vi v,vv;
			for(auto it:m2){
				v.pb(it.S);
			}
			sort(all(v));
			for(auto it:m1){
				vv.pb(it.S);
			}
			sort(all(vv));
			cout<<n-mx1-max((sz(v)-2<0?0:v[sz(v)-2]),(sz(vv)-2<0?0:vv[sz(vv)-2]));
	}
	else{
		cout<<x-mx1+y-mx2;
	}

}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  int c = 0;
  cin >> N >> K;
  vector<int>v(N);
  for(int i = 0;i < N;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  for (int i = 0;i < K;i++){
  cin >> v.at(i);
    c += v.at(i);
  }
  cout << c << endl; 
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, k; cin >> n >> k;
  set<char> d;
  rep(i, k) {
    int x; cin >> x;
    d.insert('0'+x);
  }

  for(int i = n; i <= 10*n; ++i) {
    string s = to_string(i);
    bool ok = true;
    for(auto c : s) {
      if(d.find(c) != d.end()) ok = false;
    }
    if(ok) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3700
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define pf printf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node

using namespace std;
///check n=1;
///check corner case;

int main()
{
    ll a,b;
    cin>>a>>b;
    if((a==1 && b==2) ||(a==2 && b==1))cout<<3<<endl;
    if((a==2 && b==3) ||(a==3 && b==2))cout<<1<<endl;
    if((a==1 && b==3) ||(a==3 && b==1))cout<<2<<endl;
    return 0;
}


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

int64_t count(const vector<int> &A_vec, const vector<int> &C_vec, int B)
{
    auto lb_A = lower_bound(A_vec.begin(), A_vec.end(), B);
    auto ub_C = upper_bound(C_vec.begin(), C_vec.end(), B);
    int64_t cnt_A = lb_A - A_vec.begin();
    int64_t cnt_C = C_vec.end() - ub_C;
    return cnt_A * cnt_C;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A_vec(N), B_vec(N), C_vec(N);
    for (int i = 0; i < N; ++i)
        cin >> A_vec.at(i);
    for (int i = 0; i < N; ++i)
        cin >> B_vec.at(i);
    for (int i = 0; i < N; ++i)
        cin >> C_vec.at(i);
    sort(A_vec.begin(), A_vec.end());
    sort(C_vec.begin(), C_vec.end());
    int64_t cnt = 0;
    for (int i = 0; i < N; ++i) 
        cnt += count(A_vec, C_vec, B_vec.at(i));
    cout << cnt << endl;
}


Measured memory_bytes: 4540
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main()  {
    fastio;
    ll n , d;
    cin>>n>>d;
    d*=d;
    int ans = 0;

    for(int i =0 ; i < n ; i++ ) {
        ll x , y;
        cin>>x>>y;
        ll tmp = x*x + y*y;
        if(tmp <= d) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3648
c=[list(map(int,input().split())) for i in range(3)]

a=max(c[0])
for i in range(a+1):
    a1=i
    b=[0,0,0]
    a=[0,0,0]
    cnt=0
    for j in range(3):
        for k in range(3):
            if j==0:
                #b1,b2,b3を決める
                b[k]=c[j][k]-a1

            elif j==2 or j==1:
                a[k]=c[j][k]-b[k]

            if (j==1 or j==2) and k==2:
                #print(a1,a,b)
                if len(set(a))==1 and a[0]>=0:
                    cnt+=1

print('Yes' if cnt==2 else'No')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  if (n <= 999) {
    cout << "ABC" << endl;
  } else {
    cout << "ABD" << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(s: str, t: str):
    s = list(s)
    t = list(t)
    s.sort()
    t.sort(reverse= True)
    s = ''.join(s)
    t = ''.join(t)
    if s<t:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    solve(s, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064