akhauriyash/Code-Regression huggingface dataset:
//  atcodder.xcode
//  main.cpp
//  Created by conan1024hao on 2019/11/11.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリ
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,m;
    cin>>n>>m;
    vector<ll>a(n),b(n);
    vector<pair<ll,ll> >ab;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        ab.push_back(make_pair(a[i],b[i]));
    }
    sort(all(ab));
    int cnt=0;
    int i=0;
    ll sum=0;
    while(cnt!=m){
        if(ab[i].se>0){
            cnt++;
            sum+=ab[i].fi;
            ab[i].se--;
        }
        else
            i++;
    }
    cout<<sum<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 3956
def solve():
    H, W = map(int,input().split())
    cost = [list(map(int,input().split())) for _ in range(10)]
    A = [list(map(int,input().split())) for _ in range(H)]
    d = warshall_floyd(cost, 10)
    
    ans = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] != -1:
                ans += d[A[h][w]][1]
    
    print(ans)

def warshall_floyd(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 40284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <cmath>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
 
using namespace std;
 
int main() {
    long long n;
    long long ans = 1;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        ans *= i;
        ans %= 1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     int n;cin>>n;
     int x,y;
     cin>>x>>y;
     map<int,int> m;
     for(int i=1;i<=n;i++)
     {
         for(int j=i+1;j<=n;j++)
         {
             int dist = min({abs(j-i),abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x)});
             m[dist]++;
         }
     }
     int res[n];
     memset(res,0,sizeof res);
     for(auto it:m)
     {
         res[it.first] = it.second;
     }
     for(int i=1;i<n;i++)
     {
         cout<<res[i]<<endl;
     }

}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 384
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
    int n = s.Length;
    bool firstWin = true;
    if(n%2==1 && s[0]==s[n-1] || n%2==0 && s[0]!=s[n-1]) firstWin = false;
		
		Console.WriteLine((firstWin) ? "First" : "Second");
	}
}

Measured memory_bytes: 13116
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
const int N=200005;
int n,H,W,fa[N],fl[N];
ll ans;
struct node{
	int x,y,v;
}e[N];
bool cmp(node a,node b){
	return a.v>b.v;
}
int get(int x){
	return x==fa[x]?x:fa[x]=get(fa[x]);
}
int main(){
	scanf("%d%d%d",&n,&H,&W);
	For(i,1,n) scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].v);
	For(i,1,H+W) fa[i]=i,fl[i]=0;
	sort(e+1,e+n+1,cmp);
	For(i,1,n){
		int x=get(e[i].x);
		int y=get(e[i].y+H);
		if (x!=y&&(!fl[x]||!fl[y])){
			ans+=e[i].v;
			fa[x]=y; fl[y]|=fl[x];
		}
		else if (x==y&&!fl[x]){
			ans+=e[i].v;
			fl[x]=1;
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define cont continue  
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 2147483646;
const double pi = 3.141592653589793;

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

  int N;
  cin >> N;

  vector<int> stick;
  for(int i = 0 ; i < N ; i++) {
    int a; 
    cin >> a;
    stick.pb(a);
  }
  sort(stick.begin(), stick.end()); 
  ll ans = 0;
  for(int i = 0 ; i < N ; i++) {
    vector<int> plus;  
    for(int j = i + 1 ; j < N ; j++) {
      if(upper_bound(plus.begin(), plus.end(), stick[j]) != plus.end()) {
        int idx = upper_bound(plus.begin(), plus.end(), stick[j]) - plus.begin();
        // cout << "cur stick : " << stick[j] << endl;
        // cout << "cur find : " << plus[idx] << endl;
        ans += plus.size() - idx;
      }
      plus.pb(stick[i] + stick[j]);
    }
  }

  cout << ans << endl;
} 

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  long long l,r;

  cin >> l >> r;


  if((r - l) > 2018){
    cout << 0 << endl;
  }
  else{
    int min = 2018;
    for(long long i =l; i <r;i++)
      for(long long j = i+1; j <= r; j++)
        if( min > (i*j)%2019)min = (i*j)%2019;
    cout << min << endl;
  }
}



Measured memory_bytes: 256
while True:
    a, way, b = input().split()
    a = int(a)
    b = int(b)
    way = str(way)

    if way == "+":
        print(a + b)
    elif way == "-":
        print(a - b)
    elif way == "*":
        print(a * b)
    elif way == "/":
        print(a // b)
    else:
        break



Measured memory_bytes: 5592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve();
        }

        void Solve()
        {
            var count = Enumerable.Range(0, int.Parse(Console.ReadLine()))
                .Select(x => int.Parse(Console.ReadLine()))
                .ToArray()
                .Distinct()
                .Count();

            Console.WriteLine(count);
        }
    }
}


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

int main(){
  int X;
  cin >> X;
  
  if(X == 3){
    cout << "YES";
  }
  else if(X == 5){
    cout << "YES";
  }
  else if(X == 7){
    cout << "YES";
  }
  else{cout << "NO";}
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

using Data = pair<pii, int>;
using Edge = pair<pii, char>;

int A;
int B;
int d[114][114];

void Output(vector<Data> &ds) {
  int N = 202;
  vector<Edge> es;

  puts("Possible");
  rep(i, 100) {
    es.eb(Edge(pii(i, i+1), 'X'));
    es.eb(Edge(pii(i+101, i+102), 'Y'));
  }

  map<pii, int> cnt;
  for (auto &d : ds) {
    int p, q;
    tie(p, q) = d.X;
    assert(!cnt.count(d.X));
    cnt[d.X]++;
    assert(p <= 100 && q <= 100);
    int t = d.Y;
    es.eb(Edge(pii(p, N-1-q), -t));
  }

  cout << N << " " << es.size() << endl;
  for (auto &e : es) {
    int u, v;
    tie(u, v) = e.X;
    char c = e.Y;
    if (c <= 0) {
      int l = -c;
      cout << u+1 << " " << v+1 << " " << l << endl;
    } else {
      assert(c == 'X' || c == 'Y');
      cout << u+1 << " " << v+1 << " " << c << endl;
    }
  }
  cout << 1 << " " << N << endl;
}

int main() {
  cin >> A >> B;
  reps(i, 1, A+1) {
    reps(j, 1, B+1) {
      cin >> d[i][j];
    }
  }

  vector<Data> ds;
  reps(i, 1, A+1) {
    reps(j, 1, B+1) {
      int p = 1000;
      int q = 1000;
      rep(a, 101) {
        rep(b, 101) {
          int t = d[i][j] - a*i - b*j;
          if (t < 0) break;

          bool ok = true;
          reps(k, 1, A+1) {
            reps(l, 1, B+1) {
              if ((k-i)*a + (l-j)*b < d[k][l] - d[i][j]) {
                ok = false;
                goto L_OUT;
              }
            }
          }
L_OUT:
          if (ok) {
            if (p+q > a+b) {
              p = a;
              q = b;
            }
          }
        }
      }

      if (p == 1000) {
        puts("Impossible");
        return 0;
      }

      ds.eb(Data(pii(p, q), d[i][j] - p*i - q*j));
    }
  }
  sort(all(ds));
  ds.erase(unique(all(ds)), ds.end());
  Output(ds);
}



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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

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

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define S (0)
#define W (1)

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

	int N;
	cin >> N;

	string s;
	cin >> s;

	int init[4][2] = {{S, S}, {S, W}, {W, S}, {W, W}};

	REP(i, 4){
		VI A(N + 1);
		A[0] = init[i][0];
		A[1] = init[i][1];

		FOR(j, 1, N){
			if(s[j] == 'o'){
				if(A[j] == S) A[j + 1] = A[j - 1];
				else A[j + 1] = !A[j - 1];
			}
			else{
				if(A[j] == S) A[j + 1] = !A[j - 1];
				else A[j + 1] = A[j - 1];
			}
		}

		if(A[0] != A[N]) continue;

		if(s[0] == 'o'){
			if(A[0] == S){
				if(A[1] != A[N - 1]) continue;
			}
			else{
				if(A[1] == A[N - 1]) continue;
			}
		}
		else{
			if(A[0] == S){
				if(A[1] == A[N - 1]) continue;
			}
			else{
				if(A[1] != A[N - 1]) continue;
			}
		}

		REP(j, N){
			if(A[j] == S) cout << "S";
			else cout << "W";
		}
		cout << endl;
		return 0;
	}

	cout << -1 << endl;

	return 0;
}


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

int main(){
    int W,H,x,y,r;
    bool X = false, Y = false;
    cin >> W >> H >> x >> y >> r;
    if((x + r <= W)&&(x - r >= 0))
        X = true;
    if((y + r <= H)&&(y - r >= 0))
        Y = true;
    if(X&&Y)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
    
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = k; i <= b; i += k) {
        if (i >= a) return cout << "OK\n", 0;
    }
    cout << "NG\n";
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
// #include<math.h>
// #include<stdlib.h>
// #include<string.h>
// #include<stdbool.h>

// #define MOD 998244353

// #define MIN(a,b) ((a)<(b)?(a):(b));
// #define MAX(a,b) ((a)>(b)?(a):(b));

// typedef long long int64;

int main(void){
    int N,M,C;
    scanf("%d %d %d",&N,&M,&C);

    int ans=0;

    int sum=0;


    int A[N][M];
    int B[M];

    for(int i=0;i<M;i++){
        scanf("%d",&B[i]);
    }

    for(int i=0;i<N;i++){
        sum=0;
        for(int j=0;j<M;j++){
            scanf("%d",&A[i][j]);
            sum+=A[i][j]*B[j];
        }
        sum+=C;
        if(sum>0) ans++;
    }
    
    printf("%d",ans);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include"stdio.h"
#include <cstring>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#include"time.h"
#define MAX_INT  ((unsigned)(-1)>>1)
#define MIN_INT  (~MAX_INT)
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
template<class T>inline void read(T &res){
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}

int main(){
	int n,m;
	cin>>n>>m;
	int a;
	for(int i=1;i<=m;i++){
        read(a);
        n-=a;
	}
	if(n>=0)cout<<n;
	else cout<<-1;
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5 + 1;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

int main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    while(cin >> n && n){
    	int a[50000] = {0}, b[50000] = {0};
    	REP(i,n)
    		cin >> a[i];
    	REP(i,n)
    		cin >> b[i];
    	stable_sort(a, a + n, greater<int>());
    	stable_sort(b, b + n, greater<int>());
    	int cnt[50000] = {0}, s = 0, t = 0;
    	while(s < n && t < n){
    		while(a[s] > b[t] && s < n) s++;
    		if(a[s] <= b[t] && s < n){
    			cnt[s+1]++;
    			t++;
    			s++;
    		}
    	}
    	FOR(i,1,n+1)
    		cnt[i] += cnt[i - 1];
    	bool ok = false;
    	int k;
    	FOR(i,1,n+1){
    		if((i - cnt[i]) > i / 2){
    			k = i;
    			ok = true;
    			break;
    		}
    	}
    	if(!ok || k == n)
    		cout << "NA" << endl;
    	else
    		cout << k << endl;
    }
	return 0;
}

Measured memory_bytes: 1904
#include<stdio.h>
int main(void){
    int min=2147483647,max=-2147483648,a,n,i=0;
    long long int sum=0;
    scanf("%d",&n);
    while(n>i){
        scanf("%d",&a);
        if(min>a)min=a;
        if(max<a)max=a;
        sum=sum+a;
        i++;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}

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

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        final int n = in.i();
        int[] v = in.ii();
        int[] odd = new int[100001];
        int[] evn = new int[100001];
        int mo1 = 0, mo2 = 0, me1 = 0, me2 = 0, mov = 0, mev = 0;
        for(int i = 0; i < n/2; i++){
            int o = ++odd[v[2*i]];
            int e = ++evn[v[2*i+1]];
            if(mo1 < o){
                mo1 = o;
                mov = v[2*i];
            } else if(mo2 < o) mo2 = o;
            if(me1 < e){
                me1 = e;
                mev = v[2*i+1];
            }else if(me2 < e) me2 = e;
        }
       
        int ans = mov == mev ? n-Math.max(mo1+me2, mo2+me1) : n-mo1-me1;
        out.println(ans);
        
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 38360
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;


namespace AtCoder
{
    class AtCoderrr
    {
        static void Main(string[] args)
        {
            int a = int.Parse(ReadLine());
            string s = ReadLine();

            if (a >= 3200)
            {
                WriteLine(s);
            }
            else WriteLine("red");
        }
    }
}


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


int main(){
	int N,K;
	cin >> N >> K;
	vector<int> C(N);
	rep(i,K){
		int d; cin >> d;
		rep(j,d){
			int a; cin >> a; a--;
			C[a]++;
		}
	}
	cout << count(C.begin(),C.end(),0) << endl;

	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long n,i,j,a,b,c=0;
 cin>>n;
 long long A[n];
 for(i=0;i<n;i++)
 cin>>A[i];
 sort(A,A+n);
 for(i=0;i<n-1;i++)
 c+=A[i];
 if(A[n-1]<c) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}


ll n,k;
vll a(200001);

int count(double x) {
  int cnt=0;
  REP(i,n) {
    cnt+=ceil(a[i]/x)-1;
  }
  return cnt;
}

int main() {
  cin >> n >> k;
  REP(i,n) cin >> a[i];
  sort(ALL(a),greater<int>());
  double l=0,r=a[0]*2;
  double c;
  int temp=k+1;
  while(l+0.1<r) {
    c=(l+r)/2.0;
    temp=count(c);
    if(temp>k) l=c;
    else r=c; 
  }
  ll ans = ceil(c);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4656
N, M = map(int, input().split())
a = [list(map(int, input().split()))[1:] for _ in range(N)]
b = [i for i in range(1, M + 1)]
c = [i for i in range(1, M + 1)]
for i in range(N):
  for j in range(M):
    if b[j] in c and (not b[j] in a[i]):
      c.remove(b[j])
print(len(c))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		double r = scan.nextInt();
		double ans = 2 * r * Math.PI;
		
		System.out.println(ans);
		
		
	}

}


Measured memory_bytes: 35772
#include <cstdio>
#include <tuple>
#include <cmath>
using namespace std;
const double eps = 1e-6;
long long N, X;

tuple<long long, long long, long long> calc(long long w, long long h) {
    long long cnt = w / h;
    return make_tuple(h, w % h, 2 * cnt * h);
}

int main () {
    scanf("%lld %lld", &N, &X);

    long long ans = N;
    long long h = X, w = N - X;
    while(h) {
        long long l;
        tie(w, h, l) = calc(w, h);
        if(!h) l -= w;
        ans += l;
//        printf("%lld, %lld\n", w, h);
    }
    printf("%lld\n", ans);

    return 0;
}

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


def solve(H: int, W: int, a: "List[List[int]]"):
    ans = []
    for i in range(H):
        for j in range(W-1):
            if a[i][j] % 2 == 1:
                ans.append([i+1, j+1, i+1, j+1+1])  # 右に
                a[i][j] -= 1
                a[i][j+1] += 1
    j = W-1
    for i in range(H-1):
        if a[i][j] % 2 == 1:
            ans.append([i+1, j+1, i+1+1, j+1])  # 下に
            a[i][j] -= 1
            a[i+1][j] += 1
    print(len(ans))
    for a in ans:
        print(" ".join(map(str, a)))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [[int(next(tokens)) for _ in range(W)]
         for _ in range(H)]  # type: "List[List[int]]"
    solve(H, W, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29744
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;

int N;
const int MAXN = 1001;
int X1[MAXN], X2[MAXN], Y1[MAXN], Y2[MAXN];
bool f[MAXN * 6][MAXN * 6];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int compress(int *x1, int *x2, int w) {
   vector<int> xs;

   for (int i = 0; i < N; i++) {
      for (int d = -1; d <= 1; d++) {
         int tx1 = x1[i] + d, tx2 = x2[i] + d;
         if (0 <= tx1 && tx1 < w) xs.push_back(tx1);
         if (0 <= tx2 && tx2 < w) xs.push_back(tx2);
      }
   }
   xs.push_back(0);
   xs.push_back(w - 1);
   sort(xs.begin(), xs.end());
   xs.erase(unique(xs.begin(), xs.end()), xs.end());

   for (int i = 0; i < N; i++) {
      x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
      x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
   }

   return xs.size();
}

int W, H;
int main() {
   for(;;) {
      cin >> W >> H;
      if (W == 0 && H == 0) return 0;
      cin >> N;
      for (int i = 0; i < N; i++) {
         cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
         X2[i]--;
         Y2[i]--;
      }
      
      W = compress(X1, X2, W);
      H = compress(Y1, Y2, H);
      
      memset(f, 0, sizeof(f));
      for (int i = 0; i < N; i++) {
         for (int y = Y1[i]; y <= Y2[i]; y++) {
            for (int x = X1[i]; x <= X2[i]; x++) {
               f[y][x] = true;
            }
         }
      }
      
      int ans = 0;
      for (int y = 0; y < H; y++) {
         for (int x = 0; x < W; x++) {
            if (f[y][x]) continue;
            ans++;

            queue<ipair> q;
            q.push(ipair(x, y));
            
            while (!q.empty()) {
               auto cur = q.front();
               q.pop();

               for (int dir = 0; dir < 4; dir++) {
                  int nx = cur.first + dx[dir];
                  int ny = cur.second + dy[dir];
                  if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
                  if (f[ny][nx]) continue;
                  q.push(ipair(nx, ny));
                  f[ny][nx] = true;
               }
            }
         }
      }
      cout << ans << endl;
   }
   return 0;
}



Measured memory_bytes: 38376
{-# LANGUAGE BangPatterns #-}
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.List

getAsCharArray1DWithLength :: IO (Int, UArray Int Char)
getAsCharArray1DWithLength = BS.getLine >>= \ !cs ->
  let !n = BS.length cs
      !ary = (U.listArray (1,n) $ unfoldr BS.uncons cs) :: UArray Int Char
  in return (n, ary)

main :: IO ()
main = do
  (!n,!sa) <- getAsCharArray1DWithLength
  (!m,!ta) <- getAsCharArray1DWithLength
  let !result = solve (n,sa) (m,ta)
  putStrLn $ restore sa result n m

solve :: (Int, UArray Int Char) -> (Int, UArray Int Char) -> UArray (Int,Int) Int
solve (!n',!sa) (!m',!ta) = runSTUArray $ do
  !dp <- newArray ((0,0),(n',m')) 0
  forM_ [(n_,m_) | !n_ <- [1..n'], !m_ <- [1..m']] $ \(!n,!m) -> do
    !a <- readArray dp (n-1,m-1)
    !b <- readArray dp (n,m-1)
    !c <- readArray dp (n-1,m)
    if sa U.! n == ta U.! m
      then writeArray dp (n,m) $ maximum [a+1,b,c]
      else writeArray dp (n,m) $ maximum [b,c]
  return dp

restore :: UArray Int Char -> UArray (Int,Int) Int -> Int -> Int -> String
restore !st !ary !n !m = go n m ""
  where go 0 _ !ss = ss
        go _ 0 !ss = ss
        go !i !j !ss
          | ary U.! (i,j) == ary U.! (i-1,j) = go (i-1) j ss
          | ary U.! (i,j) == ary U.! (i,j-1) = go i (j-1) ss
          | otherwise                        = go (i-1) (j-1) ((st U.! i):ss)


Measured memory_bytes: 72060
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,Q = list(map(int,input().split()))
Network = UnionFind(N)

for i in range(Q):
    t,u,v = list(map(int,input().split()))
    if t==1:
        if Network.same(u,v):
            print(1)
        else:
            print(0)
    else:
        Network.union(u,v)

Measured memory_bytes: 82456
inputs = [input() for i in range(6)]
k = int(inputs[5])
m = -1
for i in range(4):
    for j in range(i, 5):
        dist = int(inputs[i]) - int(inputs[j])
        if dist < 0:
            dist = - dist
        if dist > m:
            m = dist

if m > k:
    print(":(")
else:
    print("Yay!")


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

const int MAX_N = 105;

int n, A[MAX_N];

int rozwiaz(int x, int y) {
    if(x > y) {
        return 0;
    }
    if(x == y) {
        return A[x];
    }
    
    int najmniejszy = A[x];
    int najmniejszy_indeks = x;
    for(int i = x + 1; i <= y; i++) {
        if(A[i] < najmniejszy) {
            najmniejszy = A[i];
            najmniejszy_indeks = i;
        }
    }
    for(int i = x; i <= y; i++) {
        A[i] -= najmniejszy;
    }
    int wynik = najmniejszy;
    wynik += rozwiaz(x, najmniejszy_indeks - 1);
    wynik += rozwiaz(najmniejszy_indeks + 1, y);
    return wynik;
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> A[i];
    }
    cout << rozwiaz(1, n);    
    return 0;
}

Measured memory_bytes: 256
import sys
#read = sys.stdin.read
from math import floor
def main():
    a, b = map(int, input().split())
    for i1 in range(1251):
        if floor(i1 * 0.08) == a and floor(i1 * 0.1) == b:
            print(i1)
            sys.exit()
    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9076
#include<iostream>
#include<string>
using namespace std;
int main(){
  string st,sh;
  int n,t=0,h=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> st >> sh;
    if(sh>st)h+=3;
    else if(st>sh) t+=3;
    else h+=1,t+=1;
  }
  cout << t << " " << h << endl;
}


Measured memory_bytes: 3160
#include <cstdio>

int main(){
    int n;
    scanf("%d",&n);
    char s[n];
    for(int i = 0; i < n; i++){
        scanf("\n %c",&s[i]);
    }

    bool c[4];
    for(int i = 0; i < 4; i++){
        c[i] = true;
    }

    int count = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'P' && c[0] == true){
            count++;
            c[0] = false;
        }else if(s[i] == 'W' && c[1] == true){
            count++;
            c[1] = false;
        }else if(s[i] == 'G' && c[2] == true){
            count++;
            c[2] = false;
        }else if(s[i] == 'Y' && c[3] == true){
            count++;
            c[3] = false;
        }
        if(count == 4){
            break;
        }
    }

    if(count == 3){
        printf("Three\n");
    }
    if(count == 4){
        printf("Four\n");
    }

    return 0;
}

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


int main() {
    int N;
    cin >> N;
    bool a = false;
    for (int i = 0; i <= N/4; ++i) {
        for (int j = 0; j <= N/7; ++j) {
            if (i*4 + j*7 == N) {
                a = true;
                break;
            }
        }
    }

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

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc081/tasks/arc086_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, K, A, m[200000] = {0}, r = 0;

  cin >> N >> K;

  REP(i, N)
  {
    cin >> A;
    m[A - 1]++;
  }
  sort(m, m + 200000, greater<int>());

  FOR(i, K, 200000)
  {
    if (m[i] == 0)
      break;
    r += m[i];
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void select_Sort(int n, int A[]) {
        int min = 0;
        int mini = 0;
        int x=0;
        int sortNum = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                if(j==i+1){
                    min=A[j];
                    mini=j;
                }
                if(min > A[j]){
                    min=A[j];
                    mini=j;
                }
            }
            if (A[i] > A[mini]) {
                x = A[mini];
                A[mini] = A[i];
                A[i] = x;
                sortNum++;
            }
        }
        System.out.printf("%d", A[0]);
        for (int k = 1; k < n; k++) {
            System.out.printf(" %d", A[k]);
        }
        System.out.printf("\n");
        System.out.println(sortNum);
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = scan.nextInt();
        }
        scan.close();
        select_Sort(n, A);
        return;
    }
}


Measured memory_bytes: 26636
// https://atcoder.jp/contests/abc065/tasks/abc065_b
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n + 1);
    REP(i, n) cin >> v[i + 1];
    int pos = 1, cnt = -1;
    REP(i, n) {
        pos = v[pos];
        if (pos == 2) {
            cnt = i + 1;
            break;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using ll = long long;
const ll INF_LL = 1000000000000;
#define fir first
#define sec second
using namespace std;


ll n,k;
vector<ll> a,f;


bool chack(ll mid){
    ll sum = 0;
    //mid以下にする
    for(int i = 0; i < n; i++){
        sum += std::max(0LL,a[i] - ((mid) / f[i])); //ceil(a,fi)
    }
    return (sum <= k);
}




int main()
{
    cin >> n >> k;
    a.resize(n), f.resize(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    for(int i = 0; i < n; i++)cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<ll>());

    
    ll right = 10000000000000;
    ll left = -1;
    //(left,right]
    while(right - left > 1){
        ll mid = (right + left) / 2;
        (chack(mid) ? right : left) = mid;
    }
    cout << right << endl;
}


Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        //入力の受け取り
        char[] input = ReadChar();

        //配列→list
        List<char> numList = new List<char>();
        for (int jj = 0; jj < input.Length; jj++)
        {
            numList.Add(input[jj]);
        }

        //答え用カウンター
        int answer = 0;

        //隣合う0と1を取り除いてカウントしていく
        for (int ii = 0; ii < numList.Count - 1; ii++)
        {
            if (numList[ii] != numList[ii + 1])
            {
                numList.RemoveAt(ii);
                numList.RemoveAt(ii);
                answer = answer + 2;
                if (ii < 2)
                {
                    ii = -1;
                }
                else
                {
                    ii = ii - 2;
                }
            }
        }

        //回答提出
        Console.WriteLine(answer);

    }

    //読み取り用
    static String Read()
    {
        return Console.ReadLine();
    }

    static int ReadInt()
    {
        return int.Parse(Console.ReadLine());
    }

    static char[] ReadChar()
    {
        return Console.ReadLine().ToCharArray();
    }


}

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

int main(){
    string s;
    cin >> s;
    int res = 1;
    if(s == "SUN") res = 7;
    if(s == "MON") res = 6;
    if(s == "TUE") res = 5;
    if(s == "WED") res = 4;
    if(s == "THU") res = 3;
    if(s == "FRI") res = 2;
    cout << res << endl;

    return 0;
}

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

int return_index(int k, int max_idx);

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;
    vector<int> index_change;
    index_change.push_back(0);
    for (int i = 1; i < N; i++) {
        if (S[i] != S[i-1]) index_change.push_back(i);
    }
    int idx, idx_c = index_change.size(), num, max_continue = 0;
    index_change.push_back(N);
    for (int i = 0; i < idx_c ; i++) {
        idx = index_change.at(i);
        if (S[idx] == '0') num = index_change.at(return_index(i+2*K, idx_c-1)) - idx;
        else num = index_change.at(return_index(i+2*K+1, idx_c-1)) - idx;
        max_continue = max(max_continue, num);
    }
    cout << max_continue << endl;
    return 0;
}

int return_index(int k, int max_idx) {
    if (k > max_idx) return max_idx+1;
    else return k;
}


Measured memory_bytes: 1020
#include <stdio.h>
#include <string.h>
int main(){
char str[1001],mei[10],q[1001],abc[1001];
int kazu,a,b,j,i,ba,k,l;



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



for(i=0;i<kazu;i++){
scanf("%s %d %d",mei,&a,&b);


    if(mei[2]=='p'){
        scanf("%s",q);
        for(k=0;k<(b-a+1);k++){
            str[a+k]=q[k];}
        }





    if(mei[2]=='v'){
        ba=strlen(str);
            strncpy(abc,str,ba);
            for(j=0;j<=b-a;j++){
            str[j+a]=abc[b-j];}
}


if(mei[0]=='p'){
    for(l=a;l<=b;l++){
        printf("%c",str[l]);
        }
        puts("");
        }
        





}

return 0;
}

Measured memory_bytes: 604
import Control.Monad

readIntLine :: IO ([Int])
readIntLine = do
    x <- getLine
    return $ map (read :: String -> Int) $ words x

main :: IO ()
main = do
    [r,d,x] <- readIntLine
    mapM_ print $ solve r d x 10

solve r d x 0 = []
solve r d x z = a:(solve r d a (z-1))
    where a = r*x - d


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n,a,b; cin >> n >> a >> b;
  ll ans = 0;
  FOR(i, 1, n+1){
    ll dsum = 0;
    ll tmp = i;
    while(tmp > 0){
      dsum += tmp%10;
      tmp /= 10;
    }
    if(dsum >= a && dsum <= b) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string s; cin >> s;
  map<string, string> m = {{"Sunny", "Cloudy"}, {"Cloudy", "Rainy"}, {"Rainy", "Sunny"}};
  cout << m[s] << endl;
}


Measured memory_bytes: 3584
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    int x, y, a, b, c;
    cin>>x>>y>>a>>b>>c;
    vi ia(a), ib(b), ic(c);

    for(auto& x: ia) cin>>x;
    for(auto& x: ib) cin>>x;
    for(auto& x: ic) cin>>x;

    sort(ia.begin(), ia.end(), greater<int>());
    sort(ib.rbegin(), ib.rend());

    for(int i= 0; i< min(a, x); i++)
        ic.pb(ia[i]);

    for(int i =0 ; i< min(y, b); i++)
        ic.pb(ib[i]);

    sort(ic.rbegin(), ic.rend());
    ll ans =0 ;
    for(int i =0 ; i< x+y; i++)
        ans += ic[i];
    cout<<ans;
    return 0;
}

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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 61;

int64 po[51];
int N, A[50], B[50];

bool dfs(int64 bit, int cur_val, int to_val) {
  if(cur_val == to_val) return true;
  for(int i = cur_val; i >= 1; i--) {
    if((bit >> i) & 1 && dfs(bit, cur_val % i, to_val)) return true;
  }
  return false;
}

bool check(int64 bit) {
  for(int i = 0; i < N; i++) {
    if(!dfs(bit, A[i], B[i])) return false;
  }
  return true;
}

int main() {

  po[0] = 1;
  for(int i = 1; i < 51; i++) {
    po[i] = po[i - 1] * 2;
  }

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> B[i];
  }
  int64 ret = INF, bit = (1LL << 51) - 1;

  if(!check(bit)) {
    cout << -1 << endl;
    return (0);
  }

  for(int i = 50; i >= 0; i--) {
    int64 next_bit = bit ^(1LL << i);
    if(check(next_bit)) bit = next_bit;
  }

  int64 sum = 0;
  for(int i = 50; i >= 0; i--) {
    if((bit >> i) & 1) sum += po[i];
  }
  cout << sum << endl;
}


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

int main() {
	while(true){
		int n,m;
		cin>>n>>m;
		
		if(n==0 && m==0){
			break;
		}
		
		int square[n];
		for(int i=0;i<n;i++){
			cin>>square[i];
		}
		
		int place=0,ans=0;
		for(int i=0;i<m;i++){
			int x;
			cin>>x;
			
			if(place>=n-1){
				continue;
			}
			
			place+=x;
			if(square[place]){
				place+=square[place];
			}
			
				ans++;
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const Arr = (input.trim()).split("\n");
const N1 = Number(Arr[0]);
const arr1 = Arr[1].split(" ").map(Number);
const arr2 = Arr[3].split(" ").map(Number);

const summing = (a, b) => a + b;
console.log(arr2.map(key => {   
    let mid;
    let left = 0;
    let right = N1;
    if (key < arr1[0] || arr1[N1-1] < key) return 0;
    while (left < right) {
      mid = Math.floor((left + right) / 2);
      if (key < arr1[mid]) right = mid;
      else if (key > arr1[mid]) left = mid + 1;
      else return 1;
    }
    return 0;
}).reduce((a, b) => a + b, 0));



Measured memory_bytes: 34940
import sys  
input = sys.stdin.readline

N, M = list(map(int, input().split()))



ans = -1
l_min , r_max = list(map(int, input().split()))
for i in range(M-1):
    l, r = list(map(int, input().split()))
    if r_max < l or r < l_min:
        ans = 0
        break

    if l_min <= l and l <= r_max:
        l_min = l

    if l_min <= r and r <= r_max:
        r_max = r


if ans == 0:
    print(ans)
else:
    print(r_max - l_min + 1)

Measured memory_bytes: 3064
h,n = map(int,input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())
dp = [0] * (h + 1)

for i in range(1,h+1):
    s = 100000000000
    for j in range(n):
        if i - a[j] < 0:
            s = min(s,b[j])
        else:
            s = min(s,dp[i-a[j]] + b[j])
    dp[i] = s
print(dp[h])


Measured memory_bytes: 42092
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
 
void solve() {
    string s;
    cin >> s;
 
    int l = 0, h = (int) s.size() - 1;
    int ct = 0;
    while (l <= h) {
        if (s[l] == s[h])l++, h--;
        else if (s[l] != s[h]) {
            if (s[l] != 'x' and s[h] != 'x') {
                cout << "-1";
                return;
            }
            if (s[l] == 'x')l++;
            else h--;
            ct++;
        }
    }
    cout << ct << endl;
}
 
int32_t main() {
int t=1;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    int N,K; cin>>N>>K;
    map<int,int> cnt;
    REP(i,N){
        int a; cin>>a;
        cnt[a]++;
    }

    int ans=0;
    if(cnt.size()>K){
        vector<int> a;
        for(auto p:cnt){
            a.push_back(p.second);
        }
        sort(ALL(a));
        int x=cnt.size()-K;
        REP(i,x){
            ans+=a[i];
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 14964
import sys
import heapq

input = sys.stdin.readline

NCOSTS = 2501
TIME_MAX = 10 ** 15

N, M, S = map(int, input().split())
adj = [[] for _ in range(N * NCOSTS)]
fare_adj = [[NCOSTS] * N for _ in range(N)]
time_adj = [[TIME_MAX] * N for _ in range(N)]
fare_max = 0


def node(city, silvers):
    return silvers * N + city


for i in range(M):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    for j in range(a, NCOSTS):
        adj[node(u, j)].append((node(v, j - a), b))
        adj[node(v, j)].append((node(u, j - a), b))

for i in range(N):
    # g-s rate, waiting duration
    c, d = map(int, input().split())
    for j in range(NCOSTS - c):
        adj[node(i, j)].append((node(i, j + c), d))


mintime = [TIME_MAX for _ in range(N * NCOSTS)]


def search():
    q = [(0, node(0, min(S, NCOSTS - 1)))]
    while q:
        t, node1 = heapq.heappop(q)
        if t > mintime[node1]:
            continue
        for node2, cost in adj[node1]:
            ntime = t + cost
            if mintime[node2] > ntime:
                mintime[node2] = ntime
                heapq.heappush(q, (ntime, node2))


search()
for i in range(1, N):
    print(min(mintime[node(i, j)] for j in range(NCOSTS)))


Measured memory_bytes: 114192