akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

const int MAX_ROW = 70;
const int MAX_COL = 100005;
struct BitMatrix {
	int H, W;
	bitset<MAX_COL> val[MAX_ROW];
	BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
	inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

void GaussJordan(BitMatrix& A, bool is_extended = false) {
	vector<bool> used(A.H, 0);
	for (int col = 0; col < A.W; ++col) {
		if (is_extended && col == A.W - 1) break;
		int pivot = -1;
		for (int row = 0; row < A.H; ++row) {
			if (used[row]) continue;
			if (A[row][col]) {
				pivot = row;
				break;
			}
		}
		if (pivot == -1) continue;
		for (int row = 0; row < A.H; ++row) {
			if (row != pivot && A[row][col]) A[row] ^= A[pivot];
		}
		used[pivot] = true;
	}
}
const int MD = 59;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);


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

	ll ans = 0;

	BitMatrix BM(MD+1, N+1);//65個の方程式，各方程式に対してN+1個の変数(0か1)
	//初期化時は，MD桁で， A_1+...+A_N=0ならば，列はN+1個で初期化すること（でないと落ちる）
	vector<bool> cannot(MD+1, 0);

	for (ll mask = MD; mask >= 0; mask--)
	{
		int num = 0;
		for (int i = 0; i < N; i++)
		{
			if ((A[i] >> mask) & 1LL) {
				num++;
			}
		}

		if (num == 0) {
			//全て0
			cannot[mask] = 1;
			continue;
		}
		else if (num & 1) {
			//1が奇数個(この桁は値は一定)
			cannot[mask] = 1;
			ans += (1LL << mask);
			continue;
		}

		//ここは1が偶数個存在する場合
		for (int i = 0; i < N; i++)
		{
			if ((A[i] >> mask) & 1LL) {
				BM[MD - mask][i] = 1;
			}

		}
		BM[MD - mask][N] = 1;
	}

	GaussJordan(BM, true);

	for (int mask = MD; mask >= 0; mask--)
	{
		if (cannot[mask]) {
			continue;
		}

		bool ok = false;

		for (int i = 0; i < N; i++)
		{
			if (BM[MD - mask][i]) {
				ok = true;
			}
		}
		if (!BM[MD - mask][N]) {
			ok = true;
		}

		if (ok) {
			ans += (1LL << (mask + 1));
		}
	}

	cout << ans << endl;
	

}



Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

#define int64_t ll
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int j=1;j<=n;++j){
  ll num=j;
  for(int64_t i = 2; i * i <= num; i++) {
    while(num % i == 0) {
      ret[i]++;
      num /= i;
    }
  }
  if(num != 1) ret[num]++;
  }
  return ret;
}

//ここから
void solve(){
  int n;
  cin>>n;
  map<ll,int>mp=prime_factor(n);
  ll five=0,three=0,a=0,b=0,c=0;;
  for(auto x:mp){
    if(x.second>=4)++five;
    if(x.second>=2)++three;
    if(x.second>=74)++a;
    if(x.second>=24)++b;
    if(x.second>=14)++c;
  }
  //cout<<five<<" "<<three<<" "<<a<<" "<<b<<" "<<c<<endl;
  cout<<(five*(five-1))/2*(three-five)+(five*(five-1)*(five-2))/2+a+b*(three-b)+b*(b-1)+c*(five-c)+c*(c-1);
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	//cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void){
    int n;
    char s[100], t[100];

    cin >> n;

    cin >> s;
    cin >> t;

    for(int i=0;i<n;i++){
        cout << (char)s[i] << (char)t[i];
    }

    cout << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int d,t,s;
  cin >> d >> t >> s;
  Yes(d<=s*t);


  return 0;
}


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

public class Main {
	
	static int M[][];
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(); M=new int[n][n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++)M[i][j]=Integer.parseInt(in.next());
		}
		prim(n);
	}
	
	static void prim(int n) {
		int INF=2000000000, d[]=new int[n], p[]=new int[n];
		char color[]=new char [n]; 
		for(int i=0;i<n;i++) {
			d[i]=INF;
			color[i]='W';
		}
		
		d[0]=0; p[0]=-1; //set [0] as start node
		
		while(true) {
			int mincost=INF,u=-1;
			for(int i=0;i<n;i++) {
				if(color[i] !='B' && d[i]<mincost) {
					mincost=d[i];
					u=i;
				}
			}
			
			if(mincost==INF)break;
			
			color[u]='B';
			
			for(int v=0;v<n;v++) {
				if(color[v]!='B' && M[u][v]!=-1) {
					if(M[u][v]<d[v]) {
						d[v]=M[u][v];
						p[v]=u;
						color[v]='G';
					}
				}
			}
		}
		
		int dsum=0;
		for(int i=1;i<n;i++) {
			dsum+=M[i][p[i]];
		}
		System.out.println(dsum);
	}

}



Measured memory_bytes: 38540
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) throws Exception {
         
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        br.readLine();
        String[] s = br.readLine().split(" ");
        br.readLine();
        String[] t = br.readLine().split(" ");
         
        Set<String> set = new HashSet<String>(Arrays.asList(s));
        set.retainAll(Arrays.asList(t));
        System.out.println(set.size());
    }
}


Measured memory_bytes: 27572
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int id;
  int parent;
  int left;
  int right;
}Tree;

Tree *T;
int n;

void Preorder(int id){
  printf(" %d",T[id].id);
  if(T[id].left != -1) Preorder(T[id].left);
  if(T[id].right != -1) Preorder(T[id].right);
  return;
}

void Inorder(int id){
  if(T[id].left != -1){
    Inorder(T[id].left);
  }
  printf(" %d",T[id].id);
  if(T[id].right != -1){
    Inorder(T[id].right);
  }
  return;
}

void Postorder(int id){
  if(T[id].left != -1) Postorder(T[id].left);
  if(T[id].right != -1) Postorder(T[id].right);
  printf(" %d",T[id].id);
  return;
}

void getParent(){
  int i;

  for(i=0; i<n; i++){
    if(T[i].left != -1){
      T[T[i].left].parent = T[i].id;
    }
    if(T[i].right != -1){
      T[T[i].right].parent = T[i].id;
    }
  }
}

int getRoot(){
  int i,root;
  for(i=0; i<n; i++){
    if(T[i].parent == -1){
      root = T[i].id;
    }
  }
  return root;
}

int main() {
  int i,id,left,right,root;

  scanf("%d",&n);
  T = malloc(sizeof(Tree) * n);
  for(i=0; i<n; i++){
    scanf("%d%d%d",&id,&left,&right);
    T[id].id = id;
    T[id].left = left;
    T[id].right = right;
    T[id].parent = -1;
  }
  getParent();
  root = getRoot();

  printf("Preorder\n");
  Preorder(T[root].id);
  printf("\nInorder\n");
  Inorder(T[root].id);
  printf("\nPostorder\n");
  Postorder(T[root].id);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2060
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
   ll n; cin >> n;
   vector<ll> a(n);
   ll ans = 0;
   rep(i, n){
      cin >> a.at(i);
   }

   sort(a.rbegin(), a.rend());
   ll cnt = 1;
   ll cnt2 = 0;
   ll human = 0;
   ans += a.at(0);
   while(human!=n-2){
      ans += a.at(cnt);
      cnt2++;
      cnt2%=2;
      if(cnt2==0){
         cnt++;
      }
      human++;
   }

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


Measured memory_bytes: 4828
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        string s;
        cin >> s;
        //int n = s.length();
        int n = 0, w = 0;
        set<char> st;
        for(auto &it : s){
            st.insert(it);
        }
        for(auto &it : st){
            if(it == 'N'){
                n++;
            }
            if(it == 'S'){
                n--;
            }
            if(it == 'E'){
                w++;
            }
            if(it == 'W'){
                w--;
            }
        }
        if(n == 0 and w == 0){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 31488
#include <iostream>
using namespace std;
 
int main(){
	int a, b, c, tmp;
	cin >> a >> b >> c;
	
	while (!(a <= b && b <= c)){
		if (a > b){
			tmp = a;
			a = b;
			b = tmp;
		}
		if (b > c){
			tmp = b;
			b = c;
			c = tmp;
		}
	}

	cout<<a<<" "<<b<<" "<<c<<endl;;
	
	return 0;
}

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

namespace AGC005STing
{
    class Program
    {
        static void Main(string[] args)
        {
            string X = Console.ReadLine();
            Stack<char> stack = new Stack<char>();

            foreach(var c in X)
            {
                if(c == 'T')
                {
                    if(stack.Count > 0 && stack.Peek() == 'S')
                    {
                        stack.Pop();
                    }
                    else
                    {
                        stack.Push(c);
                    }
                }
                else
                {
                    stack.Push(c);
                }
            }

            Console.WriteLine(stack.Count);
            
        }
    }
}


Measured memory_bytes: 13240
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
#include<queue>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long N,M,k,s;
vector<vector<long>>v;
vector<long>p;
inline void solve(void){
  in(N,M);
  v.rs(M);
  rep(i,M){
    in(k);
    rep(j,k){
      in(s);
      v[i].pb(s);
    }
  }
  p.rs(M);
  long ans=0;
  rep(i,M)in(p[i]);
  for(long i=0;i<1<<N;i++){
    long cnt2=0;
    rep(j,M){
      long cnt=0;
      for(auto e:v[j]){
        if(i>>(e-1)&1)cnt++;
      }
      if(cnt%2==p[j])cnt2++;
    }
    if(cnt2==M)ans++;
  }
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;

int main() {
    int n,W;
    cin>>n;
    cin>>W;
    vector<vector<int>> h(n, vector<int>(2));
    vector<vector<long long int>> dp(n+1, vector<long long int>(W+1, 0));
    for(int i=0;i<n;i++) {
        cin>>h[i][0]>>h[i][1];
    }
    for(int i=1;i<n+1;i++) {
        for(int j=1;j<W+1;j++) {
            if(h[i-1][0]<=j)
                dp[i][j] = max(dp[i-1][j], h[i-1][1] + dp[i-1][j-h[i-1][0]]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][W]<<endl;
}


Measured memory_bytes: 80256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto P = s[1];
    auto WB = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    long score(long w, long b) {
        return w * (100 - P) - b * P;
    }
    WB.sort!((a, b) => score(a[0], -a[1]) > score(b[0], -b[1]));

    long w = 0;
    long b = WB.map!(wb => wb[1]).sum;
    int ans = N;

    foreach (i; 0..N) {
        if (score(w, b) >= 0 && ans == N)
            ans = i;
        w += WB[i][0];
        b -= WB[i][1];
    }

    ans.writeln;
}


Measured memory_bytes: 12284
N, M = map(int, input().split())
qs = [list(map(int, input().split())) for _ in range(M)]
qs.sort(key = lambda x: x[1], reverse = True)
ans = 0
prv = 0
while qs:
    a, b = qs.pop()
    if prv <= a:
        ans += 1
        prv = b
print(ans)

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

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

ll decode(string s){
    ll res = 0;
    for(auto c : s){
        res <<= 4;
        if(isdigit(c)){
            res |= (c-'0');
        }else{
            res |= (c-'a'+10);
        }
    }
    return res;
}

string encode(ll x){
    if(x == 0) return "0";
    string res = "";
    const ll base = (1<<4)-1;
    while(x > 0){
        ll b = x&base;
        if(b<10){
            res.push_back('0'+b);
        }else{
            res.push_back('a'+b-10);
        }
        x >>= 4;
    }
    reverse(res.begin(), res.end());
    return res;
}

ll A[9], c[32]{};

vector<P> build(int a, int b){
    vector<P> res;
    int n = b-a;
    for(ll S=0;S<1<<n;S++){
        ll sum = 0;
        for(int i=0;i<n;i++){
            if((S>>i)&1){
                sum += c[a+i];
            }
        }
        sum -= ((A[8]^(S<<a))-A[8]);
        res.push_back(P(sum, S<<a));
    }
    sort(res.begin(),res.end());
    return res;
}

int solve(){
    ll S = 0;
    string str;
    for(int i=0;i<9;i++){
        cin >> str;
        A[i] = decode(str);
        if(i<8) S+=A[i];
    }
    ll K = 0;
    for(int i=0;i<32;i++){
        if(((S>>i)&1) != ((A[8]>>i)&1)){
            K |= 1LL<<i;
            S = 0;
            for(int i=0;i<8;i++){
                S += A[i]^K;
            }
        }
    }
    cout << encode(K) << endl;
    return 0;
}


int main(){
    int t; cin >> t; for(;t>0;t--) solve();
    return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;



int main() {
    int n, W;
    cin >> n >> W;
    vector<int> w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(n+1, vector<ll>(W+1));
    rep(i,n) {
        rep(j,W+1) {
            if(j - w[i] >= 0) dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 83100
fun main() {
    val n = readLine()!!.toInt()
    val xs = (0 until n).map {
        val (a, b) = readLine()!!.split(' ').map { it.toInt() }
        a to b
    }

    val ans = if (n % 2 == 0) {
        val l = xs.map { it.first }.sorted().let { it[n / 2 - 1] + it[n / 2] }
        val r = xs.map { it.second }.sorted().let { it[n / 2 - 1] + it[n / 2] }
        r - l + 1
    } else {
        val l = xs.map { it.first }.sorted()[n / 2]
        val r = xs.map { it.second }.sorted()[n / 2]
        r - l + 1
    }

    println(ans)
}


Measured memory_bytes: 81356
#include<stdio.h>
int main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if (a + b > c + d) {
		printf("Left");
	}
	else if (a + b == c + d) {
		printf("Balanced");
	}
	else {
		printf("Right");
	}

	return 0;
}

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

long long N, A[100009], c1, c2, c3;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		if (A[i] % 4 == 0) c1++;
		else if (A[i] % 2 == 0) c2++;
		else c3++;
	}
	if (c2 >= 1) {
		if (c1 >= c3) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (c1 + 1 >= c3) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict
from itertools import accumulate

n, k = map(int, input().split())
aaa = list(map(int, input().split()))
acc = [0] + list(accumulate(aaa))
subs = defaultdict(lambda: 0)

for l in range(n):
    acl = acc[l]
    for r in range(l + 1, n + 1):
        beu = acc[r] - acl
        subs[beu] += 1

ans = 0

for i in range(40):
    bit = 1 << (39 - i)
    new_subs = {}
    remain = 0

    for sub, cnt in subs.items():
        if sub & bit > 0:
            new_subs[sub] = cnt
            remain += cnt

    if remain >= k:
        subs = new_subs
        ans |= bit

print(ans)


Measured memory_bytes: 56148
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int M=gi();
	    int[] H = new int[N];
	    int[] A = new int[M];
	    int[] B = new int[M];
	    boolean[] G = new boolean[N];
	    
	    
	    for (int i=0; i<N;i++) {
	    	H[i]=gi();
	    	G[i]=true;
	    }
	    
	    for (int j=0; j<M;j++) {
	    	A[j]=gi();
	    	B[j]=gi();
	    }
	    
	    for (int j=0; j<M;j++) {
	    	int a=A[j];
	    	int b=B[j];
	    	if(H[a-1]>H[b-1]) {
	    		G[b-1]=false;
	    	} else if(H[b-1]>H[a-1]) {
	    		G[a-1]=false;
	    	} else {
	    		G[a-1]=false;
	    		G[b-1]=false;
	    	}
	    }
	    
	    int c=0;
	    for (int i=0; i<N;i++) {
	    	if(G[i]==true)c++;
	    }
	    



	   
	    System.out.print(c);

//        if (t.equals("Sunny")) {
//        	System.out.print("Cloudy");
//        }else if(t.equals("Cloudy")){
//        	System.out.print("Rainy");
//        } else {
//        	System.out.print("Sunny");
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 61072
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
  speed_up;
  ll n, m, i, j, k, x;
  ll M = 1e9 + 7;

    cin >> n;
    map<ll, ll> a;
    for(k = 2; k <= n; ++k)
    {
        ll cnt = 0;
        ll num = k;
        while(num % 2 == 0) {
            ++cnt;
            num /= 2;
        }
        if(cnt) a[2] += cnt;
        for(i = 3; i <= num; i += 2) {
            if(num % i == 0) {
                cnt = 0;
                while(num % i == 0) {
                    ++cnt;
                    num /= i;
                }
                a[i] += cnt;
            }
        }
        if(num > 1) a[num]++;
    }

    ll tot = 1;
    for(auto t : a)
    {
        tot *= (t.second + 1);
        tot %= M;
    }
    cout << tot << endl;




return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#define ll long long
using namespace std;

int main(){
	ll N;cin >> N;
	ll ans=0;
	for(int i=1;i<=N;i++){
		if(i%3!=0 && i%5!=0){
			ans = ans + i;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <iomanip>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main() {
  int N, M;
  cin >> N;
  map<int,int> D, T;
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    D[a]++;
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    T[a]++;
  }

  for(auto t : T) {
    if (t.second > D[t.first]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 18944
#include <iostream>
#include <vector>

using namespace std;

long long kMod = 1e9+7;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<long long> s(n);
  vector<long long> t(m);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> t.at(i);
  }
  vector<vector<long long>> sum(n, vector<long long>(m));
  sum.at(0).at(0) = (int)(s.at(0) == t.at(0)) + 1;
  for (int x = 1; x < n; x++) {
    sum.at(x).at(0) = (int)(s.at(x) == t.at(0)) + sum.at(x-1).at(0);
  }
  for (int y = 1; y < m; y++) {
    sum.at(0).at(y) = (int)(s.at(0) == t.at(y)) + sum.at(0).at(y-1);
  }
  for (int x = 1; x < n; x++) {
    for (int y = 1; y < m; y++) {
      if (s.at(x) == t.at(y)) {
        sum.at(x).at(y) = sum.at(x-1).at(y-1);
      }
      sum.at(x).at(y) += sum.at(x-1).at(y) + sum.at(x).at(y-1) - sum.at(x-1).at(y-1) + kMod;
      sum.at(x).at(y) %= kMod;
    }
  }
  cout << sum.at(n-1).at(m-1) << '\n';
  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main(){

  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if(s[0] == s[3]){
    cout << "No" << endl;
    return 0;
  }
  if(s[0] == s[1] && s[2] == s[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long ll;
string ans[6];
string s;
bool check(string ans)
{
     int y=s.size()-1;
     if(((s[y]=='o'&&ans[y]=='S')||(s[y]=='x'&&ans[y]=='W'))&&ans[y-1]==ans[0])
     {
         return true;
     }
     else if(((s[y]=='o'&&ans[y]=='W')||(s[y]=='x'&&ans[y]=='S'))&&ans[y-1]!=ans[0])
     {
         return true;
     }
     return false;
}

bool check1(string ans)
{
     int y=s.size()-1;
     if(((s[0]=='o'&&ans[0]=='S')||(s[0]=='x'&&ans[0]=='W'))&&ans[y]==ans[1])
     {
         return true;
     }
     else if(((s[0]=='o'&&ans[0]=='W')||(s[0]=='x'&&ans[0]=='S'))&&ans[y]!=ans[1])
     {
         return true;
     }
     return false;
}
int main()
{
    int n,i,j;
    cin>>n>>s;
    ans[1]="SS";
    ans[2]="SW";
    ans[3]="WS";
    ans[4]="WW";
    for(i=1;i<=4;i++)
    {
        for(j=1;j<n-1;j++)
        {
            if((ans[i][j]=='S'&&s[j]=='o')||(ans[i][j]=='W'&&s[j]=='x'))
            {
                ans[i].push_back(ans[i][j-1]);
            }
            else if((ans[i][j]=='S'&&s[j]=='x')||(ans[i][j]=='W'&&s[j]=='o'))
            {
                if(ans[i][j-1]=='S')
                {
                    ans[i].push_back('W');
                }
                else
                {
                    ans[i].push_back('S');
                }
            }
        }
    }
    for(i=1;i<=4;i++)
    {
        if(check(ans[i])&&check1(ans[i]))
        {
            cout<<ans[i]<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int b[n];
long long int sum=0;
    for(int i=0;i<n-1;i++){
      cin>>b[i];
    }
sum=sum+b[0];
for(int i=0;i<n-2;i++){
sum=sum+min(b[i],b[i+1]);
}
sum=sum+b[n-2];

cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    int N, C;
    int comp[33][33];
    int grid[505][505];
    cin >> N >> C;
    for (int i = 1; i <= C;i++)
    {
        for (int j = 1; j <= C;j++){
            scanf("%d", &comp[i][j]);
        }
    }
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            scanf("%d", &grid[i][j]);
        }
    }

    int prev_col[3][31] = {};
    int m1;
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            m1 = grid[i][j];
            prev_col[(i + j) % 3][m1]++;
        }
    }

    int answer = 260000000;
    int preans = 0;
    for (int aftcolz = 1; aftcolz <= C; aftcolz++)
    {
        for (int aftcolo = 1; aftcolo <= C;aftcolo++){
            for (int aftcolt = 1; aftcolt <= C;aftcolt++){
                if(aftcolz==aftcolo || aftcolo==aftcolt ||aftcolz==aftcolt)
                    continue;
                for (int i = 1; i <= C; i++)
                {
                    preans += comp[i][aftcolz] * prev_col[0][i];
                    preans += comp[i][aftcolo] * prev_col[1][i];
                    preans += comp[i][aftcolt] * prev_col[2][i];
                }
                if(preans<=answer)
                    answer = preans;

                preans = 0;
                
            }
        }
    }



    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 1280
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val ds = Array.fill(n)(readLine().split(" ").map(_.toInt))
    .map(list => (list(0), list(1)))
  def solve(): String = {
    val (maxCnt, _) = ds.foldLeft((0,0)) { case ((maxCnt, tmpCnt), (d1, d2)) =>
      if(d1 == d2) (Math.max(maxCnt, tmpCnt+1), tmpCnt+1)
      else (maxCnt, 0)
    }
    if(maxCnt >= 3) "Yes" else "No"
  }

  println(solve())

}



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



int main() {
	vector<int> atoz(26, 0);
	string w;
	cin >> w;
	for(int i = 0; i < w.size(); i++){
		atoz.at(w.at(i) - 97)++;
	}
	bool beautiful = true;
	for(int i = 0; i < 26; i++){
		if(atoz.at(i) % 2 != 0){
			beautiful = false;
			break;
		}
	}
	if(beautiful){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

int main(){
	string S;
	cin >> S;

  	int i;
  	for(i = 1; i < 3; i++) {
  		if(S[i] != S[0]) {
          	break;
        }
    }
      if (i == 1) {
    	if(S[2] == S[0] && S[3] == S[1] || S[2] == S[1] && S[3] == S[0]) {
        	 
		  cout << "Yes" << endl;

        } else {
         
	  cout << "No" << endl;
        }
    } else if (i == 2) {
    	if(S[2] == S[3]) {
        	cout << "Yes" << endl;
        } else {
                   
		  cout << "No" << endl;
    
        }
    } else {
	  	  cout << "No" << endl;
    }
  }


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int dr[] = { 1, 1, 1, 0, -1, -1, -1, 0 };
int dc[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
string b[8];

bool ok(int r, int c) {
    return 0 <= r and r < 8 and 0 <= c and c < 8;
}

int f1(bool turn, int r, int c, int dir, int sum) {
    int res = 0;
    if (dir == -1) {
        rep(d, 8) {
            int nr = r+dr[d], nc = c+dc[d];
            if (!ok(nr, nc) or b[nr][nc] != (turn ? 'x' : 'o')) continue;
            res += f1(turn, nr, nc, d, sum+1);
        }
        return res;
    }
    else {
        int nr = r + dr[dir], nc = c + dc[dir];
        if (!ok(nr, nc)) return 0;
        if (b[nr][nc] == (turn ? 'o' : 'x')) {
            return sum;
        }
        else if (b[nr][nc] == (turn ? 'x' : 'o')) {
            res += f1(turn, nr, nc, dir, sum+1);
        }
        return res;
    }
}

bool f2(bool turn, int r, int c, int dir) {
    if (dir == -1) {
        rep(d, 8) {
            int nr = r+dr[d], nc = c+dc[d];
            if (!ok(nr, nc) or b[nr][nc] != (turn ? 'x' : 'o')) continue;
            bool f = f2(turn, nr, nc, d);
            if (f) b[nr][nc] = (turn ? 'o' : 'x');
        }
        return true;
    }
    else {
        int nr = r + dr[dir], nc = c + dc[dir];
        if (!ok(nr, nc)) return false;
        if (b[nr][nc] == (turn ? 'o' : 'x')) {
            b[nr][nc] = (turn ? 'o' : 'x');
            return true;
        }
        else if (b[nr][nc] == (turn ? 'x' : 'o')) {
            bool f = f2(turn, nr, nc, dir);
            if (f) b[nr][nc] = (turn ? 'o' : 'x');
            return f;
        }
    }
    return false;
}

int main() {
    rep(d, 8) cin >> b[d];
    bool turn = true, update = true;
    int cnt = 0;
    while (true) {
        if (cnt >= 2) break;
        int ma = 0, tr, tc;

        rep(rr, 8) rep(cc, 8) {
            int r = (turn ? rr : 7-rr);
            int c = (turn ? cc : 7-cc);
            if (b[r][c] == '.') {
                int tmp = f1(turn, r, c, -1, 0);
                if (tmp > ma) {
                    ma = tmp;
                    tr = r, tc = c;
                }
            }
        }

        if (ma > 0) {
            f2(turn, tr, tc, -1);
            b[tr][tc] = (turn ? 'o' : 'x');
        }

        if (ma > 0) cnt = 0;
        else ++cnt;

        turn = !turn;
    }
    rep(r, 8) cout << b[r] << endl;
}



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

int main(){
  
  int A,B,C; cin >> A >> B >> C;
  
  if(C >= A && C <= B){
	cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc160/submissions/11310424

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    def dist(a, b):
        return min(
            abs(a - b),
            abs(a - X) + abs(b - Y) + 1,
            abs(a - Y) + abs(b - X) + 1
        )

    ctr = [0] * N
    for b in range(N):
        for a in range(b):
            d = dist(a, b)
            ctr[d] += 1

    it = iter(ctr)
    next(it)
    print(*it, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
}



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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long A, long long B, long long T) {
  cout << (T / A) * B << endl;
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long T;
  scanf("%lld", &T);
  solve(A, B, T);
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

ll t[100001] = {};
int main() {
	ll n, c, k; cin >> n >> c >> k;
	rep(i, 0, n)cin >> t[i];
	sort(t, t + n);

	ll i = 0;
	ll bus_cnt = 0;

	while (i < n) {
		ll T = t[i];
		bus_cnt++;
		ll p_cnt = 1;
		while (i < n && t[i] <= T + k && p_cnt <= c) {
			i++;
			p_cnt++;
		};
	}

	cout << bus_cnt << endl;
	return 0;
}

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

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

int main() {
	int n;
	while(cin >> n){
		int ans = 0;
		REP(i, 10)REP(j, 10)REP(k, 10)REP(l, 10){
			if(i + j + k + l == n)
				ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    ll n;cin >>n;
    Vl cnt(n+1,0);
    for (int i =1; i <=n; ++i) {
        for (int j =i; j <=n;j+=i) {
            cnt[j]++;
        }
    }
    ll ans=0;
    for (int i =1; i <=n; ++i) {
        ans+=i*cnt[i];
    }
    cout <<ans <<endl;
}



Measured memory_bytes: 81380
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  ll N;
  cin >> N;
  ll ans = 1;
  ll ans2 = 1;
  ll X;
  rep(i, N) {
    cin >> X;
    if(X % 2 == 0) {
      ans2 *= 2;
    }
    else {
      ans2 *= 1;
    }
    ans *= 3;
  }
  cout << ans - ans2 << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll MOD = 1e9+7;
vector < P > pairs;
 
#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)
#define ALL(c) (c).begin(), (c).end()
 
// pair (降順, 降順)
bool compare_pair(P a, P b) {
    if (a.first > b.first) return true;//firstが先に書いてあるからfirst基準ソート
    if (a.first < b.first) return false;
    if (a.second > b.second) return true;//今は降順、true falseひっくり返せば降順、昇順切り替え
    if (a.second < b.second) return false;
    return false;
}

int main(){
    int N;
    cin >> N ;
    rep(i,N*100,N*100+100){
        if( (i % 108) == 0 ){
            cout << (i / 108);
            break;
        }
        if(i == N*100+99){
            cout << ":(";
            break;
        }
    }
    int ans;
}

Measured memory_bytes: 256
def solve(h, w):
    w1 = round(w/3)
    s1 = h*w1
    w21 = w - w1
    h2 = h//2
    s21 = h2*w21
    h3 = h - h2
    s31 = h3*w21
    ans1 = max([s1, s21, s31]) - min([s1, s21, s31])

    w22 = w21//2
    s22 = h*w22
    w32 = w - w1 - w22
    s32 = h*w32
    ans2 = max([s1, s22, s32]) - min([s1, s22, s32])

    return min(ans1, ans2)

h, w = list(map(int, input().split()))

if h%3 == 0 or w%3 == 0:
    print(0)
else:
    ans1 = solve(h, w)
    ans2 = solve(w, h)
    print(min([ans1, ans2]))


Measured memory_bytes: 3064
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int h,w,i,j,cnt,mn,x,y,sum,a[25][25],k,l;
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++)	{
		for(j=0;j<w;j++)	{
			scanf("%d",&a[i][j]);
		}
	}
	mn=100000000;
	for(i=0;i<h;i++)	{
		for(j=0;j<w;j++)	{
			sum=0;
			for(k=0;k<h;k++)	{
				for(l=0;l<w;l++)	{
					y=k-i;	if(y<0)	y=-y;
					x=j-l;	if(x<0)	x=-x;
					sum+=min(y*a[k][l],x*a[k][l]);
				}
			}
			mn=min(mn,sum);
		}
	}
	printf("%d\n",mn);
	return 0;
}



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

int main(){
  
  string N; cin >> N;
  
  if(N[0] == N[1] && N[1] == N[2]){
    cout << "Yes" << endl;
  }
  
  else if(N[1] == N[2] && N[2] == N[3]){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

int main() {
     
    long long i,j,l,q,t,m,n,h;
    long long k,z,p1,h1,x,y;
    string st="",st1="";
    q=1;
    long long a,b,c,d;
    for(l=0;l<q;l++)
    {
          std::cin >> a >> b >> c >> d;
          x=b*d;
          x=max(a*c,x);
          x=max(x,b*c);
          x=max(x,a*d);
          std::cout << x << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s = sc.next();
		int n = sc.nextInt(),m = sc.nextInt(),c = sc.nextInt();
		int[] array = new int[n];

		/*for(int i=0;i<n;i++) {
			array[i] = sc.nextInt();
		}*/
		if(c-(n-m)>=0) {
		System.out.println(c-(n-m));
		}else {
			System.out.println(0);
		}

	}
	public static int sample() {
		return 1;
	}

}


Measured memory_bytes: 23764
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    sort(arr , arr + n , greater<int>());

    // int min_sofar = INT_MAX;
    ans = arr[0];
    count = 2;

    for(int i=1; i<n; i++) {

        if(count >= n) break;

        ans += arr[i];
        count++;
        if(count >= n) break;
        ans += arr[i];
        count+=1;
    }
    cout<<ans<<endl;

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 5224
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()

  l=[]
  for _ in range(n):
    a,b=LI()
    l.append([a,b])

  l=sorted(l,key=lambda x:x[0])

  sm=0
  for x in l:
    if m>x[1]:
      m-=x[1]
      sm+=x[0]*x[1]
    else:
      sm+=x[0]*m
      return sm

print(main())


Measured memory_bytes: 24932
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var UnionFind = (function(){
  var a;
  function f(n){return new UnionFind(n);}
  function UnionFind(n){
    a = this.a = Array(n+1).fill(-1);
  }
  UnionFind.prototype.root = function(i){
    if(a[i] < 0)return i;
    return a[i] = this.root(a[i]);
  };
  UnionFind.prototype.same = function(x,y){
    return this.root(x) === this.root(y);
  };
  UnionFind.prototype.unite = function(x,y){
    x = this.root(x), y = this.root(y);
    if(x === y)return false;
    if(x < y)a[x] += a[y], a[y] = x;
    else a[y] += a[x], a[x] = y;
    return true;
  };
  UnionFind.prototype.size = function(i){
    return -a[this.root(i)];
  }
  return f;
})();

function Z_Algorithm(s){
  var l=s.length,a=Array(l);
  a[0]=l;
  for(var i=1,j=0;i<l;){
    while(i+j<l && s[j]===s[i+j])++j;
    a[i]=j;
    if(j === 0){++i; continue;}
    var k=1;
    while(i+k<l && k+a[k]<j)a[i+k]=a[k], ++k;
    i += k; j -= k;
  }
  return a;
}

console.log(main());
function main(){
  var s = o.a(1);
  var t = o.a(1);
  var sl=s.length;
  var tl=t.length;
  var ss=s+s;
  while(ss.length<sl+tl)ss+=s;
  var uf=UnionFind(sl);
  var za=Z_Algorithm(t+ss);
  for(var i=0;i<sl;i++){
    if(za[i+tl]>=tl){
      if(!uf.unite(i,(i+tl)%sl))return -1;
    }
  }
  var ans=1;
  for(i=0;i<sl;i++){
    var t=uf.size(i);
    if(ans<t)ans=t;
  }
  return ans-1;
}

Measured memory_bytes: 57036
A,B,C=list(map(int,input().split()))
if A == B == C:
    if A%2==1 or B%2==1 or C%2==1:
        print(0)
        exit()
    else:
        print(-1)
        exit()
for i in range(10**9):
    if A%2==1 or B%2==1 or C%2==1:
        print(i)
        exit()
    A,B,C=(B+C)//2,(A+C)//2,(A+B)//2

Measured memory_bytes: 3064
n = int(input())
s = []
for _ in range(n):
    x, l = map(int, input().split())
    s.append([x + l, x - l])
s.sort()
t = s[0][0]
ans = 1
for i in range(1, n):
    if s[i][1] >= t:
        ans += 1
        t = s[i][0]
print(ans)

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

int X,Y,Z;
int ans;

int main(){
  // freopen("test.txt","r",stdin);
    cin >> X >> Y >> Z;
    ans++;
    X -= Y;
    X -= 2*Z;
    if ( X < 0) {
        cout << 0 << endl;
        return 0;
    }
    int tmp = Y + Z;
    ans += X / tmp;
    cout << ans << endl;
}


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

inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch&15);ch=getchar();}
	return x*f;
}

ll n,x,ans;

inline ll dfs(ll n,ll x)
{
	if(!(n%x)) return n*2-x;
	ans=n/x*x*2+dfs(x,n%x);
	return ans;
}

int main()
{
	n=read(),x=read();
	printf("%lld\n",dfs(n-x,x)+n);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n,m;

/* add your algorithm here */

// 階乗を計算 (MODあり)
ll factorial_mod(ll n) {
  ll ans = 1;
  for (ll i = n; i > 0; --i) {
    ans = (ans % MOD) * (i % MOD) % MOD;
  }
  return ans;
}

int main() {
  cin >> n >> m;
  if (abs(n-m) > 1) {
    cout << 0 << endl;
    return 0;
  }

  ll res;

  if (abs(n-m) == 1) {
    res = (factorial_mod(n) * factorial_mod(m)) % MOD;
    cout << res << endl;
  } else {
    res = (factorial_mod(n) * factorial_mod(n)) % MOD;
    res *= 2;
    res %= MOD;
    cout << res << endl;
  }
}


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

int n;
int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  cin >> n;
  for(int i=0;i<n;i++) {
    for(int j=i+1;j<n;j++) {
      int k=0;
      while((i>>k&1)==(j>>k&1)) k++;
      cout << k+1 <<  " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 512