akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
struct card
{
	char ch;
	int value;
} C[36];
struct card D[36],C1[36],C2[36];
int BubbleSort(struct card C[],int N)
{
	for(int i=0;i<N;i++)
		for(int j=N-1;j>i;j--)
			if(C[j].value < C[j-1].value)
				swap(C[j],C[j-1]);
	
	for(int i=0;i<N;i++)
		D[i]=C[i];
	return 0;
}
int SelectionSort(struct card C[],int N)
{
	int minj;
	for(int i=0;i<N;i++)
	{
		minj=i;
		for(int j=i;j<N;j++)
		{
			if(C[j].value < C[minj].value)
				minj = j;
		}
		swap(C[i],C[minj]);
	}
}
int isStable(struct card C[],int N)
{
	int i;
	for(i = 0;i < N;i++)
	{
		if(D[i].ch!=C[i].ch)
			break;
	}
	if(i==N)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
}
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
		cin >> C[i].ch >> C[i].value;
	for(int i=0;i<N;i++)
		C1[i]=C[i];
	for(int i=0;i<N;i++)
		C2[i]=C[i];	
	BubbleSort(C1,N);
	for(int i=0;i<N;i++)
	{
		if(i)
			cout << " ";
		cout << C1[i].ch << C1[i].value;
	}	
	cout << endl;
	isStable(C1,N);
	SelectionSort(C2,N);
	for(int i=0;i<N;i++)
	{
		if(i)
			cout << " ";
		cout << C2[i].ch << C2[i].value;
	}	
	cout << endl;
	isStable(C2,N);
	return 0;
}













Measured memory_bytes: 3128
n = input()
n = int(n)
l=[]
l = input().split(" ")
ans=0
for i in range(1,n-1):
	a=int(l[i-1])
	b=int(l[i])
	c=int(l[i+1])
	if(b>=a and b<=c or b>=c and b<=a):
		ans=ans+1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] str = new String[h];
		for (int i = 0; i < h; i++) {
			str[i] = "#" + sc.next() + "#";
		}
		String frame = "";
		for (int i = 0; i < str[0].length(); i++) {
			frame += "#";
		}

		sb.append(frame + "\n");
		for (int i = 0; i < h; i++) {
			sb.append(str[i] + "\n");
		}
		sb.append(frame + "\n");
		System.out.print(sb);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    long long A;
    long long B;
    long long V;
    long long W;
    long long T;

    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    long long D = abs(A-B);

    if (D == 0) {
        cout << "YES" << endl;
    } else if (V <= W) {
        cout << "NO" << endl;
    } else {
        long long DV = V - W;
        if (T*DV >= D) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }


    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,k,count=0,ans;
  cin >> a >>b >>k;
  for (int i=min(a,b);i>=1;i--){
    if(a%i==0 && b%i==0)count++;
    if(k==count){
      ans=i;
      break;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
from collections import defaultdict
n,k = map(int, raw_input().split())
d = defaultdict(int)
for _ in range(n):
    a,b = map(int, raw_input().split())
    d[a] += b
s = 0
for p in sorted(d.keys()):
    if k <= s + d[p]:
        print p
        break
    s += d[p]


Measured memory_bytes: 12192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}
ll tpm[15]={4,6,10,14,22,26,34,38,46,58,62,74,82,86,94};//3
ll fpm[9]={6,9,20,28,44,52,68,76,92};//5
ll ftpm[4]={16,30,60,91};//15
ll tfpm[3]={28,54,100};//25
ll sfpm[1]={78};//75
int main(){
  ll i,N,ans=0,a=0,b=0,c=0,d=0,e=0;
  cin>>N;
  while(a<15&&tpm[a]<=N)a++;
  while(b<9&&fpm[b]<=N)b++;
  while(c<4&&ftpm[c]<=N)c++;
  while(d<3&&tfpm[d]<=N)d++;
  while(e<1&&sfpm[e]<=N)e++;
  //3,5,5
  if(N>=10){
    ans+=(a-b)*modncr(b,2);
    if(N>=20)ans+=modncr(b,3)*3;
  }
  //5,15
  if(N>=16){
    ans+=(b-c)*c;
    if(N>=30)ans+=modncr(c,2)*2;
  }
  //3,25
  if(N>=28){
    ans+=(a-d)*d;
    if(N>=54)ans+=modncr(d,2)*2;
  }
  if(N>=78)ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

ll p, q, r;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> p >> q >> r;
	cout << p + q + r - max(p, max(q, r));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n+1);
    map<ll,ll>m;
    REP(i,1,n+1){
        ll b;cin>>b;
        a[i]=a[i-1]+b;
    }
    ll ans=0;
    rep(i,n+1){
        if(i>=k){
            ll s=a[i-k]-(i-k);
            s%=k;
            if(s<0)s+=k;
            m[s]--;
        }
        ll s=a[i]-i;
        s%=k;
        if(s<0)s+=k;
        ans+=m[s];
        m[s]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 14336
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int a,b,x;
    scanf("%d %d %d",&a,&b,&x);
    if(a+b>=x&&a<=x)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

int N, A;
int x[111];
ll coudp[111][111][5555];

int main() 
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
	{
		cout << "vowel" << endl;
	}
	else
	{
		cout << "consonant" << endl;
	}

	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <string>
#include <math.h>
using namespace std;

int main(){
    long long int n,k,ans=300000000,s=0;
    cin>>n>>k;
    vector<long long int>a(1000000);
    for(long long int i=0;i<n;i++){
        cin>>a[i];
    }
    for(long long int i=0;i<=n-k;i++){
        if(a[i]*a[i+k-1]<0){
            if(-a[i]<a[i+k-1]){
                s=-2*a[i]+a[i+k-1];
            }
            else{
                s=-a[i]+2*a[i+k-1];
            }
        }
        else{
            if(a[i]>0){
                s=a[i+k-1];
            }
            else{
                s=-a[i];
            }
        }
        if(ans>s){
            ans=s;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

std::vector<int> v[26];
std::vector<int> preorder;
std::vector<int> inorder;
std::vector<int> postorder;

struct Sibling
{
    int left, right;
};
Sibling sibling[26];
void dfs(const int index, const int parent_index)
{
    /*
    if(parent_index != -1){
        std::vector<int>::iterator itr = std::find(v[index].begin(), v[index].end(), parent_index);
        v[index].erase(itr);
    }
    */
    preorder.push_back(index);
    if(sibling[index].left == -1 && sibling[index].right == -1){
        inorder.push_back(index);
        postorder.push_back(index);
        return;
    }
    if(sibling[index].left != -1){
        dfs(sibling[index].left, index);
    }
    inorder.push_back(index);
    if(sibling[index].right != -1){
        dfs(sibling[index].right, index);
    }
    postorder.push_back(index);
}

int main()
{
    int n;
    cin >> n;
    std::vector<int> childlist;
    for(int i=0; i<n; i++){
        int id, left, right;
        cin >> id >> left >> right;
        if(left != -1){
            //v[id].push_back(left);
            //v[left].push_back(id);
            childlist.push_back(left);  // root検索用
        }
        if(right != -1){
            //v[id].push_back(right);
            //v[right].push_back(id);
            childlist.push_back(right);  // root検索用
        }
        Sibling s;
        s.left = left; s.right = right;
        sibling[id] = s;
    }
    int root = -1;
    for(int i=0; i<n; i++){
        std::vector<int>::iterator itr;
        itr = std::find(childlist.begin(), childlist.end(), i);
        if(itr == childlist.end()){
            root = i;
        }
    }
    if(root == -1) cout << "root not found." << endl;
    dfs(root, -1);
    
    cout << "Preorder" << endl;
    std::vector<int>::iterator itr = preorder.begin();
    while(itr != preorder.end()){
        cout << " " << *itr; ++itr;
    }
    cout << endl;
    
    cout << "Inorder" << endl;
    itr = inorder.begin();
    while(itr != inorder.end()){
        cout << " " << *itr; ++itr;
    }
    cout << endl;
    
    cout << "Postorder" << endl;
    itr = postorder.begin();
    while(itr != postorder.end()){
        cout << " " << *itr; ++itr;
    }
    cout << endl;
}



Measured memory_bytes: 3168
#include<iostream>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<list>
#include<stack>
#include<queue>
#define ff first
#define ss second 
#define li list<int>
#define vi vector<int>
#define ll long long
#define vvi vector<vector<int> >
#define vii vector<pair<int,int> >
#define forl(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define custom  pair<int,pair<int,int> >
using namespace std;
int n;
int maximum(custom *c,int i,int n,int pre,int dp[][4]){
    if(i==n){
        return 0;
    }
    if(dp[i][pre]!=-1){
        return dp[i][pre];
    }
    int op1=INT_MIN;
    int op2=INT_MIN;
    int op3=INT_MIN;
    if(pre==0){
        op1=c[i].ff+maximum(c,i+1,n,1,dp);
        op2=c[i].ss.ff+maximum(c,i+1,n,2,dp);
        op3=c[i].ss.ss+maximum(c,i+1,n,3,dp);
    }
    if(pre==1){
        op2=c[i].ss.ff+maximum(c,i+1,n,2,dp);
        op3=c[i].ss.ss+maximum(c,i+1,n,3,dp);
    }
    if(pre==2){
        op1=c[i].ff+maximum(c,i+1,n,1,dp);
        //op2=c[i].ss.ff+maximum(c,i+1,n,2);
        op3=c[i].ss.ss+maximum(c,i+1,n,3,dp);
    }
    if(pre==3){
        op1=c[i].ff+maximum(c,i+1,n,1,dp);
        op2=c[i].ss.ff+maximum(c,i+1,n,2,dp);
        //op3=c[i].ss.ss+maximum(c,i+1,n,3);
    }
    dp[i][pre]=max(op1,max(op2,op3));
    return dp[i][pre];

}
int main(){
    int n;
    cin>>n;
    custom c[n];
    int dp[n][4];
    memset(dp,-1,sizeof dp);
    forl(i,0,n){
        cin>>c[i].first>>c[i].second.first>>c[i].second.second;
    }
    cout<<maximum(c,0,n,0,dp);
    return 0;
}                   

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

#include<random> 

#define int long long 

#define pp pair<int,int> 

#define ss second 

#define ff first 

#define pb push_back 

#define mod 1000000007 

using namespace std; 

void fastio() 

{ 

    #ifndef ONLINE_JUDGE 

        freopen("INPUT.txt","r",stdin); 

            freopen("OUTPUT.txt","w",stdout); 

                #endif 

                    ios_base :: sync_with_stdio(false); 

                        cin.tie(NULL) ; 

                            cout.tie(NULL); 

                            }

signed main() 

{ 

    fastio(); 

        int t=1;

           // cin>>t;

                while(t--)

                    {

                          int n;

                          cin>>n;

                          cout<<n*(n-1)/2;

    }

    }

    

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

using int64 = long long;

const int MAXN = 60;
static int cumsum[MAXN][MAXN];

int calc(int x1, int x2, int y1, int y2) {
    int res = cumsum[x2][y2];
    if (x1 - 1 >= 0) res -= cumsum[x1 - 1][y2];
    if (y1 - 1 >= 0) res -= cumsum[x2][y1 - 1];
    if (x1 - 1 >= 0 and y1 - 1 >= 0) res += cumsum[x1 - 1][y1 - 1];
    return res;
}

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

    int64 X[MAXN], Y[MAXN];
    map<int64, int> xmp, ymp;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
        xmp[X[i]] = 0;
        ymp[Y[i]] = 0;
    }

    static int64 xrev[MAXN], yrev[MAXN];

    int xid = 0, yid = 0;
    for (auto p : xmp) { xmp[p.first] = xid; xrev[xid++] = p.first; }
    for (auto p : ymp) { ymp[p.first] = yid; yrev[yid++] = p.first; }


    for (int i = 0; i < N; i++) {
        cumsum[xmp[X[i]]][ymp[Y[i]]]++;
    }

    for (int x = 0; x < xid; x++) {
        for (int y = 1; y < yid; y++) {
            cumsum[x][y] += cumsum[x][y - 1];
        }
        if (x == 0) continue;
        for (int y = 0; y < yid; y++) {
            cumsum[x][y] += cumsum[x - 1][y];
        }
    }

    int64 ans = (1LL << 62);
    for (int x1 = 0; x1 < xid; x1++) {
        for (int x2 = x1 + 1; x2 < xid; x2++) {
            for (int y1 = 0; y1 < yid; y1++) {
                for (int y2 = y1 + 1; y2 < yid; y2++) {
                    if (calc(x1, x2, y1, y2) < K) continue;
                    ans = min(ans, (xrev[x2] - xrev[x1]) * (yrev[y2] - yrev[y1]));
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
#define ll long long 
const ll maxn = 55;
int n; // number of nodes
vector<int> adj[maxn]; // adjacency list of graph
int bridges=0;
vector<bool> visited;
vector<int> tin, low;
int timer;

void dfs(int v, int p = -1) {
    visited[v] = true;
    tin[v] = low[v] = timer++;
    for (int to : adj[v]) {
        if (to == p) continue;
        if (visited[to]) {
            low[v] = min(low[v], tin[to]);
        } else {
            dfs(to, v);
            low[v] = min(low[v], low[to]);
            if (low[to] > tin[v])
                bridges++;
        }
    }
}

void find_bridges() {
    timer = 0;
    visited.assign(maxn, false);
    tin.assign(maxn, -1);
    low.assign(maxn, -1);
    for (int i = 0; i < n; ++i) {
        if (!visited[i])
            dfs(i);
    }
}
int main(){
    int m;
   cin >> n >> m;
   int a,b;
   for(int i=0;i<m;i++){
       cin >> a >> b;
       adj[a].push_back(b);
       adj[b].push_back(a);
   }
   find_bridges();
   cout << bridges;
}

Measured memory_bytes: 3524
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <cassert>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main(){
    int k; cin >> k;
    map<vector<int>, int> mp;
    ll ans = 0;
    rrep(x, k)rrep(y, k)rrep(z, k){
        ll gcd = GCD(x, y);
        ans += GCD(gcd, z);
//        vector<int> abc = {x, y, z};
//        sort(abc.begin(), abc.end());
//        auto itr = mp.find(abc);
//        if (itr != mp.end()){
//            ans += mp[abc];
//        }else {
//            ll gcd = GCD(x, y);
//            gcd = GCD(gcd, z);
//            mp.insert({abc, gcd});
//            ans += gcd;
//        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int vals[55][2];

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	for(int i = 0; i < n; i++) {
		std::cin >> vals[i][(i)%2];
	}
	for(int i = 0; i < n; i++) {
		std::cin >> vals[i][(i+1)%2];
	}
	const int INF = 1e9;
	int ans = INF;
	for(int mask = 0; mask < (1 << n); mask++) {
		int bits = 0;
		for(int j = 0; j < n; j++) {
			bits += (mask >> j) & 1;
		}
		if(bits != (n+1) / 2) continue;
		std::vector<int> a, b;
		for(int j = 0; j < n; j++) {
			if(mask & (1 << j)) {
				// even positions
				a.push_back(j);
				//std::cout << '1';
			} else {
				// odd positions
				b.push_back(j);
				//std::cout << '0';
			}
		}
		assert(a.size() >= b.size());
		std::sort(a.begin(), a.end(), [&](int v1, int v2) { return vals[v1][0] != vals[v2][0] ? vals[v1][0] < vals[v2][0] : v1 < v2; });
		std::sort(b.begin(), b.end(), [&](int v1, int v2) { return vals[v1][1] != vals[v2][1] ? vals[v1][1] < vals[v2][1] : v1 < v2; });
		int cur = 0;
		std::vector<int> perm;
		for(int i = 0; i < n; i++) {
			perm.push_back((i % 2 == 0 ? a : b)[i/2]);
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < i; j++) {
				if(perm[j] > perm[i]) {
					cur++;
				}
			}
		}
		for(int i = 1; i < n; i++) {
			if(vals[perm[i]][i%2] < vals[perm[i-1]][(i-1)%2]) {
				cur = INF;
			}
		}
		ans = std::min(ans, cur);
		//std::cout << " got " << cur << '\n';
	}
	if(ans == INF) ans = -1;
	std::cout << ans << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A(N);
    int ans = X;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] == 1)
        {
            ans += D / A[i];
        }
        else if (D % A[i] == 0)
        {
            ans += D / A[i];
        }
        else
        {
            ans += D / A[i] + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List

solve :: [[Int]] -> String
solve (rc:cs) =
    let matrix = transpose $ map attachSumCell $ transpose $ map attachSumCell cs in
    unlines [unwords [show c | c<-y] | y<-matrix]
    where
    attachSumCell :: [Int] -> [Int]
    attachSumCell c = c ++ [sum c]

main =
    putStr =<< solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = map (map read . words) 


Measured memory_bytes: 8060
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=1e5+5,MOD=1e9+7;

using namespace std;

int n,k,a[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
      
        
        scanf("%d %d",&n,&k);


        for(int i=0;i<n;i++)scanf("%d",&a[i]);

        sort(a,a+n);
       int ans = 1e9;
       for(int i=k-1;i<n;i++){
            ans = min(ans , a[i]-a[i-k+1]);
       }

       printf("%d\n",ans );

        
      
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(3*N);
  REP(i, 3*N) cin >> A[i];


  vector<int> right(N+1);
  priority_queue<int, vector<int>, greater<int>> r;
  REP(i, N){
    r.push(A[i]);
    right[0] += A[i];
  }
  FOR(i, N, 2*N){
    right[i-N+1] = right[i-N];
    int p = r.top();
    if(p < A[i]){
      r.pop();
      r.push(A[i]);
      right[i-N+1] += A[i]-p;
    }
  }

  vector<int> left(N+1);
  priority_queue<int> l;
  FOR(i, 2*N, 3*N){
    l.push(A[i]);
    left[N] += A[i];
  }
  RFOR(i, N, 2*N){
    left[i-N] = left[i-N+1];
    int p = l.top();
    if(p > A[i]){
      l.pop();
      l.push(A[i]);
      left[i-N] += A[i]-p;
    }
  }

  int ans = -INF;
  REP(i, N+1){
    chmax(ans, right[i]-left[i]);
  }

  cout << ans << "\n";

  return 0;
}

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

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
long long int euclidean_gcd(long long int a, long long int b) {
	if (a < b) return euclidean_gcd(b, a);
	long long int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
int main() {
	long long int N,gc=1,bo=0;
	cin >> N;
	vector<long long int>A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		gc=gc*(A[i]/ euclidean_gcd(A[i], gc));
	}
	for (int i = 0; i < N; i++)
	{
		bo += gc / A[i];
	}
	cout <<(long double)(gc)/(long double)(bo);
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int d, w;
	while (cin >> d >> w, d) {
		vvi v(d, vi(w));
		int ans = 0;
		REP(i, d)REP(j, w)cin >> v[i][j];
		REP(i, d - 2)REP(j, w - 2)FOR(x, i + 2, d)FOR(y, j + 2, w) {
			int m = INF;
			for (int k = i; k <= x; ++k) {
				m = min(m, v[k][j]);
				m = min(m, v[k][y]);
			}

			for (int k = j; k <= y; ++k) {
				m = min(m, v[i][k]);
				m = min(m, v[x][k]);
			}
			bool ok = true;
			int sum = 0;
			FOR(l, i + 1, x)FOR(k, j + 1, y) {
				if (v[l][k] >= m)ok = false;
				else sum += m - v[l][k];
			}
			if (ok)ans = max(ans, sum);
		}
		cout << ans << endl;
	}

}


Measured memory_bytes: 3124
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int a, b; rd(a, b);

  if(a+b==15){
    writeln("+");
  }else if(a*b==15){
    writeln("*");
  }else{
    writeln("x");
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

Measured memory_bytes: 256
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
echo str_replace(","," ",getq());

?>

Measured memory_bytes: 4604
/***



***/

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <queue>

#define PI acos(-1)

using namespace std;

void solve(){

    double r;
    cin >> r;
    cout << 2*PI*r<< endl;


}


int main(){
//    freopen("in.txt","r",stdin);
//    freopen("output.txt","w",stdout);

//
//    long long t;
//
//    cin >> t;
//
//    while(t--){
        solve();

//    }

    return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
int n;
double dp[3011][3011];
double a[3011];

double Solve(int i=0,int Cnt=0)
{
    if(i == n)
        R (Cnt > (n/2));

    double &Res = dp[i][Cnt];
    if(Res == Res)
        R Res;

    Res = Solve(i+1,Cnt+1)*a[i];
    Res += Solve(i+1,Cnt)*(1-a[i]);

    R Res;

}

int main()
{

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

    Mdp;

    printf("%.9f",Solve());

    R 0;
}


Measured memory_bytes: 71296
#include <stdio.h>

int main(){
  int n,m,i,j,c=0;

  scanf("%d",&n);

  int S[n];

  for(i=0; i < n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&m);

  int T[m];

  for(i=0; i < n; i++){
    scanf("%d",&T[i]);
  }

  for(i=0; i < n; i++){
    for(j=0; j < m; j++){
      if(S[i] == T[j]){
	T[j] = -1;
	c++;
      }
    }
  }

  printf("%d\n",c);

  return 0;
}




Measured memory_bytes: 2108
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }


vector<int> calc_required_level_to_rooms()
{
	int w, h, sx, sy;
	static int req[512][512];
	cin >> w >> h >> sx >> sy;
	--sx, --sy;
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			cin >> req[y][x];

	vector<int> res;
	res.push_back(0);

	static bool visit[512][512];
	CLEAR(visit, 0);

	typedef pair<int, pint> P;
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(P(1, pint(sx, sy)));
	while (!q.empty())
	{
		P tt = q.top(); q.pop();
		int level = tt.first;
		int x = tt.second.first, y = tt.second.second;
		if (visit[y][x])
			continue;

		visit[y][x] = true;
		res.push_back(level);

		for (int i = 0; i < 4; ++i)
		{
			int tx = x + dx[i], ty = y + dy[i];
			if (valid_pos(tx, ty, w, h) && !visit[ty][tx])
				q.push(P(max(level, req[ty][tx]), pint(tx, ty)));
		}
	}
	return res;
}
int min_level(int r, const vector<int>& a, const vector<int>& b)
{
	int res = 1e9;
	for (int i = min<int>(r, a.size() - 1); i >= 0 && r - i < b.size(); --i)
		min_swap(res, a[i] + b[r - i]);
	return res;
}
int main()
{
	ios::sync_with_stdio(false);

	int r;
	while (cin >> r, r)
	{
		vector<int> a = calc_required_level_to_rooms();
		vector<int> b = calc_required_level_to_rooms();

		int res;
		if (a.size() >= b.size())
			res = min_level(r, a, b);
		else
			res = min_level(r, b, a);
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct UnionFind {
	vector<int>d;

	UnionFind(int N) :d(N, -1) {}

	int find(int x) {
		if (d[x] < 0)return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return false;
		if (d[x] > d[y])swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return -d[find(x)];
	}
};

int main() {
	init();

	int H, W; cin >> H >> W;
	vector<string>maze(H);
	rep(i, 0, H)cin >> maze[i];
	UnionFind h(H * W), w(H * W);
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (maze[i][j] == '.') {
				if (i - 1 >= 0 && maze[i - 1][j] == '.') {
					h.unite(i * W + j, (i - 1) * W + j);
				}
				if (j - 1 >= 0 && maze[i][j - 1] == '.') {
					w.unite(i * W + j, i * W + j - 1);
				}
			}
		}
	}
	int ans = 0;
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (maze[i][j] == '#')continue;
			int cnt = h.size(i * W + j) + w.size(i * W + j) - 1;
			chmax(ans, cnt);
		}
	}
	cout << ans << "\n";
	

	return 0;
}

Measured memory_bytes: 35840
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;

int main() {
	int n;
	scanf("%d", &n);
	int br = 0;
	for (int i=0 ; i<n ; i++) {
		int x;
		scanf("%d", &x);
		br += x%2;
	}
	if (br%2) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long int
ll a[55];
int main()
{
   ll n;
   while(~scanf("%lld",&n))
   {
       if(n<50)
       {
           if(n==0)
           {
               printf("2\n0\n0\n");
               continue;
           }
           if(n==1)
           {
               printf("2\n2\n0\n");
               continue;
           }
           printf("%lld\n",n);
           for(int i=1;i<=n;i++)
           {
               if(i>1)printf(" ");
               printf("%d",i);
           }
           printf("\n");
           continue;
       }
       for(int i=1;i<=50;i++)a[i]=i;
       for(int i=1;i<=50;i++)a[i]+=(n-50)/50;
       n-=50;
       n%=50;
       for(int i=50;i>=1;i--)
       {
           if(n>0)n--,a[i]++;
       }
       printf("50\n");
       for(int i=1;i<=50;i++)
       {
           if(i>1)printf(" ");
            printf("%lld",a[i]);
       }
       printf("\n");
   }
}


Measured memory_bytes: 128
#include <stdio.h>
#define SIZE 50

/* ---------------------------------------------------------------------------- */

typedef unsigned short point;
#define point(y, x) (((y)<<8) | (x))
#define x(pt) ((pt) & 255)
#define y(pt) (((pt)>>8) & 255)

/* ---------------------------------------------------------------------------- */

point queue[SIZE*SIZE], pp, gp;
#define put(pt) (queue[pp++] = pt)
#define get() (queue[gp++])
#define empty() (gp == pp)
#define init() (pp = gp = 0)

/* ---------------------------------------------------------------------------- */

#define search(y, x) (map[y][x] = 0, put(point(y, x)))

int w, h;
int map[SIZE][SIZE+1];

void fill(int y, int x)
{
    point p;

    init(); search(y, x);

    while(!empty())
    {
        p = get(); x = x(p), y = y(p);

        if(x-1 >= 0){
            if(y-1 >= 0 && map[y-1][x-1]) search(y-1, x-1);
            if(            map[y  ][x-1]) search(y  , x-1);
            if(y+1 <  h && map[y+1][x-1]) search(y+1, x-1);
        }

        if(y-1 >= 0 && map[y-1][x]) search(y-1, x);
        if(y+1 < h  && map[y+1][x]) search(y+1, x);

        if(x+1 < w)
        {
            if(y-1 >= 0 && map[y-1][x+1]) search(y-1, x+1);
            if(            map[y  ][x+1]) search(y  , x+1);
            if(y+1 <  h && map[y+1][x+1]) search(y+1, x+1);
        }
    }
}

int main(void)
{
    int x, y, count;

    while(scanf("%d %d", &w, &h), w+h)
    {
        /* init, input */

        count = 0;

        for(y=0; y<h; y++)
            for(x=0; x<w; x++)
                scanf("%d", &(map[y][x]));

        /* search */

        for(y=0; y<h; y++)
            for(x=0; x<w; x++)
                if(map[y][x]) fill(y, x), count++;

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

    return 0;
}

Measured memory_bytes: 612
#include <stdio.h>
int main(void){
  int k,s,x,t,ans=0;
  scanf("%d%d",&k,&s);
  for (x=0;x<=s&&x<=k;x++){
    t=s-x;
    if (t<=k*2) ans+=(t<=k)? t+1:k*2-t+1;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;


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

    set<int> a;
    for(int i = 0;i < n;i++){
        int x; cin >> x;
        a.insert(x);
    }

    cout << (a.size() == n ? "YES" : "NO") << endl;

    return 0;
}

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

int main() {
  long long int s;
  cin>>s;
  
  long long int Y3=(s-(s%1000000000))/1000000000+1;
    if(s%1000000000==0){
    Y3-=1;
  }
  long long int X2=1000000000*Y3-s;
  
  
  cout<<"0 0 1000000000 "<<X2<<" 1 "<<Y3<<endl;
 }

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;

    cout << (n-1) * (m-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
const unsigned long MOD = 1000000007;
 
int main(){
    int N, M, *a, i, x, memo;
    unsigned long sum=0, *d;
    cin >> N >> M;
    a = new int[M];
    d = new unsigned long [N];
    d[0] = 1;
    if(N>2){
        d[1] = 1;
        d[2] = 2;
    }else{
        if(N==2){
            d[1] = 1;
        }
    }
    for(i=3;i<N;i++){
        d[i] = d[i-1] + d[i-2];
        d[i] %= MOD;
    }
    for(i=0;i<M;i++){
        cin >> a[i];
        if(i!=0){
            if(a[i]-a[i-1]==1){
                cout << 0 << endl;
                return 0;
            }else{
                x = a[i] - a[i-1] - 2;
                // if(x>memo){
                //     if(memo<2){
                //         memo = 2;
                //     }
                //     for(int j=memo+1;j<=x;j++){
                //         d[j] = d[j-1] + d[j-2];
                //         d[j] = d[j] % MOD;
                //     }
                //     memo = x;
                // }
                sum *= d[x];
                sum %= MOD;
            }
        }else{
            memo = a[0] - 1;
            // if(memo>2){
            //     for(int j=3;j<=memo;j++){
            //         d[j] = d[j-1] + d[j-2];
            //         d[j] %= MOD;
            //     }
            // }
            sum += d[memo];
            sum %= MOD;
        }
    }
    if(M==0){
        if(N==1){
            cout << 1 << endl;
            return 0;
        }
        cout << d[N-1] + d[N-2] << endl;
        return 0;
    }
    x = N - a[M-1] - 1;
    // if(x>memo){
    //     if(memo<2){
    //     	memo = 2;
    //     }
    //     for(int j=memo+1;j<=x;j++){
    //         d[j] = d[j-1] + d[j-2];
    //         d[j] %= MOD;
    //     }
    //     memo = x;
    // }
    sum *= d[x];
    sum %= MOD;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1280
//==========================================
// ABC130c
//
// 2019/08/21
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  double w, h, x, y;
  cin >> w >> h >> x >> y;

  cout << w*h/2 << " " << flush;
  if(x == w/2 && y == h/2) cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    const int MAXV = 51;
    int N;
    cin >> N;

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

    auto can = [&](vi ops) {
        vvb can(MAXV, vb(MAXV, false));
        for (int i = 0; i < MAXV; i++) {
            can[i][i] = true;
        }

        sort(all(ops));
        for (int v : ops) {
            for (int a = MAXV - 1; a >= 0; a--) {
                for (int b = 0; b <= a; b++)
                    can[a][b] = can[a][b] | can[a%v][b];
            }
        }
        for (int i = 0; i < N; i++) {
            if (!can[a[i]][b[i]])
                return false;
        }
        return true;
    };

    vi avail;
    for (int v = 1; v <= 50; v++) {
        avail.push_back(v);
    }
    if (!can(avail)) {
        cout << -1 << endl;
        return 0;
    }

    vi bought;
    for (int v = 50; v >= 1; v--) {
        vi would = bought;
        for (int i = 1; i < v; i++)
            would.push_back(i);
        if (!can(would)) {
            bought.push_back(v);
        }
    }

    ll cost = 0;
    for (int v : bought)
        cost |= 1ll << v;
    cout << cost << endl;

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var h = io.I;
        var w = io.I;
        var n = io.I;
        var a = io.Is(n);

        var seq = new List<int>();

        for (var i = 0; i < n; i++)
        {
            for (var j = 0; j < a[i]; j++)
            {
                seq.Add(i + 1);
            }
        }

        var ans = new int[h, w];
        var cnt = 0;

        for (var i = 0; i < h; i++)
        {
            for (var j = 0; j < w; j++)
            {
                var idx = i % 2 == 0 ? j : w - j - 1;
                ans[i, idx] = seq[cnt++];
            }
        }

        for (var i = 0; i < h; i++)
        {
            for (var j = 0; j < w; j++)
            {
                Write(ans[i, j] + " ");
            }
            WriteLine();
        }
    }
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N;
	vector<int> a;

	cin >> N;
	a.resize(3*N);
	for(int i = 0; i < 3*N; i++)
		cin >> a[i];

	sort(BE(a));

	llong ans = 0;
	for(int i = N; i < 3*N; i += 2)
		ans += a[i];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
mod = 10 ** 9 + 7

def pow(x, n, mod)
  return 1 if n == 0
  return pow(x**2 % mod, n / 2, mod) if (n % 2) == 0
  return pow(x**2 % mod, n / 2, mod) * x % mod if (n % 2) == 1
end

n, k = gets.split.map(&:to_i)

a = [1] * (k+1)
b = Array.new(k+1){|i| i }

(k/2).downto(1) do |i|
  cnt = pow( k / i , n, mod )
  (i*2).step(k, i){|j| cnt = ( cnt - a[j] ) % mod }
  a[i] = cnt
  b[i] = i * cnt % mod
end

ans = 0
(1..k).each do |i|
  ans += b[i]
  ans %= mod if ans >= mod
end

puts ans

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }




int solve(int a, int b){
    int best =0;
    amax(best, a + a-1);
    amax(best, a + b);
    amax(best, b + b-1);
    return best;
}

int main() {
    int a,b; cin >> a >> b;
    cout << solve(a,b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 200005
using namespace std;
typedef long long ll;
int n,a[maxn];
vector <int> b;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b.push_back(a[i] - i);
	}
	sort(b.begin(),b.end());
	int opt = (n+1) / 2 - 1;
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ans += abs(b[opt] + i - a[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x,a,b,numberconter,lapcounter,counter;
  counter = 0;
  cin >> n;
  vector<int> vecx(0);
  for (int i = 0; i < n; i++) {
    cin >> x;
    vecx.push_back(x);
  }
  for (int i = 0; i < n; i++) { 
    lapcounter = 0;
    a = vecx.at(i);
    for (int j = 0; j < n; j++) {
      b = vecx.at(j);
      if (a == b) {
        lapcounter++;
        if (lapcounter != 1) {
          vecx.at(j) = 0;
        }
      }
    }
  }
  
  for (int j = 0; j < n; j++) {
    if (vecx.at(j) == 0) {
      counter++;
    }
  }
  cout << vecx.size() - counter ; 
    
}
          

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#define minn 1e-10
#define INF 50
typedef long long ll;
using namespace std;
int arr[INF][INF];
int dist(int a,int b)
{
	return pow(a-b,2);
}
int main()
{
    int n,d;
    cin >> n >> d;
    for(int i=1;i<=n;i++) {
        for(int j=0;j<d;j++) {
            cin >> arr[i][j];
        }
    }

    int sum=0;
    for(int i=1;i<=n;i++) {
        for(int j=i+1;j<=n;j++) {
            double ans=0;
            for(int k=0;k<d;k++) {
                ans += dist(arr[j][k],arr[i][k]);
            }
            double ans1=sqrt(ans);
            if(ans1-floor(ans1)<minn)
               sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256