akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    map<int, int> cnt1, cnt2;
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    REP(i, n) {
        if (i % 2) cnt1[a[i]]++;
        else cnt2[a[i]]++;
    }

    vector<pii> mx1, mx2;
    FORE(p, cnt1) {
        mx1.pb({p.second, p.first});
    }
    FORE(p, cnt2) {
        mx2.pb({p.second, p.first});
    }
    sort(RALL(mx1));
    sort(RALL(mx2));

    int ans = 0;
    if (mx1[0].second != mx2[0].second) {
        REP(i, n) {
            if (i % 2) {
                if (a[i] != mx1[0].second) ans++;
            } else {
                if (a[i] != mx2[0].second) ans++;
            }
        }
    } else {
        int tmp = n;
        if (SZ(mx1) >= 1 && SZ(mx2) >= 2) {
            int t = 0;
            REP(i, n) {
                if (i % 2) {
                    if (a[i] != mx1[0].second) t++;
                } else {
                    if (a[i] != mx2[1].second) t++;
                }
            }
            chmin(tmp, t);
        }
        if (SZ(mx2) >= 1 && SZ(mx1) >= 2) {
            int t = 0;
            REP(i, n) {
                if (i % 2) {
                    if (a[i] != mx1[1].second) t++;
                } else {
                    if (a[i] != mx2[0].second) t++;
                }
            }
            chmin(tmp, t);
        }
        if (SZ(mx1) == 1 && SZ(mx2) == 1) {
            chmin(tmp, n / 2);
        }
        ans = tmp;
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 9592
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;

int N;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M;
    cin >> N >> M;
    vector<pLL> a(N);
    ll ans=0;
    for(int i=0;i<N;++i){
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(),a.end());
    int buy_count=M;
    for(int i=0;i<N;++i){
        ans+=a[i].first*a[i].second;
        buy_count-=a[i].second;
        if(buy_count<=0){
            ans-=abs(buy_count)*a[i].first;
            cout << ans <<endl;
            return 0;
        }
    }
    
    cout << endl;
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  long double l;
  cin>>l;
  l/=3.0;
  cout<<fixed<<setprecision(10);
  cout<<l*l*l<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  int i;
  char a[50];
  int cnt=0;
  scanf("%d%s",&n,a); 
  for(i=0;i<n-2;i++)
    if(a[i]=='A')
      if(a[i+1]=='B')
	if(a[i+2]=='C')
	  cnt++;
  printf("%d",cnt);
}


Measured memory_bytes: 128
/*
  AOJ 2182
  Titl Eleven Lover
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
char digits[80001];
int  hist[11];
int keta;

main()
{
  int ret,i;
  char d;

  while(scanf("%s",digits) && 0!=strcmp("0",digits))
    {
      memset(hist,0,sizeof(hist));
      keta=strlen(digits);
      while(digits[keta-1]<' ')
	{
	  digits[keta-1]='\0';
	  keta--;
	}
      d=ret=0;
      hist[0]=1;
      for(i=keta-1;i>=0;i--)
	{
	  digits[i] -= '0';
	  if((i % 2)==0)
	    d += digits[i];
	  else
	    d -= digits[i];
	  if(d < 0)
	    d+=11;
	  else if(d>10)
	    d-=11;
	  if(digits[i])
	    ret += hist[d]; 
	  hist[d]++;
	}
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 616
import java.util.Scanner;
import java.util.*;

public class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();
        String str2 = sc.nextLine();

        char s = 'S';
        char c = 'C';
        char r = 'R';

        int ss = 0;
        int cc = 0;
        int rr = 0;
        int sum = 0;

       for(int i = 0; i < str.length(); i++) {
           if(str.charAt(i) == str2.charAt(i) && str.charAt(i) == s) {
                ss++;
           } else if(str.charAt(i) == str2.charAt(i) && str.charAt(i) == c) {
               cc++;
           } else if(str.charAt(i) == str2.charAt(i) && str.charAt(i) == r) {
               rr++;
           }
       }
	  sum = (ss + cc + rr);
      System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
	char s1[10],s2[10],s3[10];
	cin>>s1>>s2>>s3;
	s1[0]=toupper(s1[0]);
	s2[0]=toupper(s2[0]);
	s3[0]=toupper(s3[0]);
    cout<<s1[0]<<s2[0]<<s3[0]<<endl;
	
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, x, a[101010];
void solve(){
	cin >> n >> x;
	int gcd;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(i == 0) gcd = abs(a[i]-x);
		else gcd = __gcd(gcd,abs(a[i]-x));
	}
	cout << gcd << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    bool flag = false;

    repd(i, 1, 10) {
        repd(j, 1, 10) {
            if (i * j == n) {
                flag = true;
            }
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> red(A), green(B), other(C);
    rep(i, A) cin >> red[i];
    rep(i, B) cin >> green[i];
    rep(i, C) cin >> other[i];
    sort(red.begin(), red.end(), greater<>());
    sort(green.begin(), green.end(), greater<>());
    rep(i, X) other.push_back(red[i]);
    rep(i, Y) other.push_back(green[i]);
    sort(other.begin(), other.end(), greater<>());
    ll delicious = 0;
    rep(i, X + Y) delicious += other[i];
    cout << delicious << endl;
    return 0;
}


Measured memory_bytes: 7800
import sys
N = int(input())
W = [input() for _ in range(N)]
for i in range(N - 1):
    if W[i][-1] != W[i + 1][0]:
        print('No')
        sys.exit()
    else:
        for j in range(i + 1):
            if W[j] == W[i + 1]:
                print('No')
                sys.exit()
print('Yes')


Measured memory_bytes: 9140
# Picking Up
# グラフ,有向グラフ,ベクトル, ２次元、コスト,

N = int(input())
S = []
for _ in range(N):
    x, y = map(int, input().split())
    S.append([x, y])
cost = N
d = {}

if N==1:
    print(1)
    exit()
for l,le in enumerate(S):
    for m, me in enumerate(S):
        if l == m:
            continue
        t = (me[0] - le[0], me[1] - le[1])
        if t in d:
            d[t] +=1
        else:
            d[t] = 1

print(N - max(d.values()))


Measured memory_bytes: 3444
<?php
  
fscanf(STDIN,"%d",$N);
 
$count = 0;
 
$ans = [];
 
for($i = 2; $i<55555; $i++){
   if($i % 5 == 1 && isPrime($i)){
     array_push($ans,$i);
     if(count($ans) >= $N){
       break;
     }
   }
}
 
echo trim(implode(" ",$ans));
 
function isPrime($num){
  for($j=2;$j<$num; $j++){
    if($num % $j == 0){
      return false;
    }
  }
  return true;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define asll unsigned long long
#define ll long long //20190711
#define pii pair<int,int>
#define st first
#define nd second
#define jn <<" "<< 			//20190830
#define ml <<endl; 			//20190831->20190903
#define co cout<<           //20190903


asll M=1e9+7;				//20190518->20190821
int n;						//20190831

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	srand(time(0));			//20190709
	
	
	cin>>n;
	int a,b,c,d;
	asll jml=((asll)n)*((asll)n+2)*((asll)n+1)/6;
	//cout<<jml<<endl;
	for(int i=0;i<n-1;i++){
		cin>>a>>b;
		c=min(a,b);
		d=max(a,b);
		jml-=(asll)(n-d+1)*(asll)c;
		//cout<<(n-d+1)*c ml
	}
	cout<<jml<<endl;
	
}



Measured memory_bytes: 3620
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,K;
int main(){
	scanf("%d%d%d",&n,&m,&K);
 	for (int i=0;i<=n;i++)
 		for (int j=0;j<=m;j++)
 			if (i*j+(n-i)*(m-j)==K){
 				printf("Yes\n");
 				return 0;
 			}
 	printf("No\n");
 }

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


int main()
{	
	int a,b;
	cin >> a >>b;
	if (a<b)
	{
		cout << "a < b" <<endl;
	}

	if (a>b)
	{
		cout << "a > b" << endl;
	}

	if (a==b)
	{
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
#define N 50
string g[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> g[i];
    }
    bool can = true;
    for(int i = 0; i < n and can; i++) {
        for(int j = 0; j < m and can; j++) {
            if(g[i][j] == '#') {
                can &= i >= 1 and g[i-1][j] == '#'
                    or i+1 < n and g[i+1][j] == '#'
                    or j >= 1 and g[i][j-1] == '#'
                    or j+1 < m and g[i][j+1] == '#';
            }
        }
    }
    cout << (can ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
	int A, B, C, D, P;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	cin >> P;
	int X = A * P;
	int Y = B + (P - C)*D;
	if (P <= C) {
	 if (X < B) {
		cout << X << endl;
	}
	else{
		cout << B << endl;
	}
}
	if (P > C) {
	if (X < Y) {
		cout << X << endl;
	}
	else {
		cout << Y << endl;
	}
	}
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    int a,b,c,x,y,xy,xi,yi;
    long long ans,answer;
    cin >> a >> b >> c >> x >> y;
    answer = a*x+b*y;
    if(x>y) xy=x;
    else xy = y;
    rep(i,2*xy+1){
        if(i%2==0){
            xi=a*(x-i/2);
            yi=b*(y-i/2);
            if(xi<0) xi=0;
            if(yi<0) yi=0;
            ans = xi+yi+c*i;
            // cout << ans<<endl;
            if(ans<answer) answer = ans;
        }
    }
    cout<<answer<<endl;

}

Measured memory_bytes: 3540
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int n;
int checkZero(vi &h){
  int cnt = 0;
  int ans = 0;
  rep(i, n){
    if(h[i]){
      cnt++;
    }else{
      if(cnt) ans++;
      cnt = 0;
    }
  }
  if(cnt) ans++;
  return ans;
}
int main(){
  cin >> n;
  vi h(n);
  rep(i, n) cin >> h[i];
  int ans = 0;
  int cnt = 0;
  while(true){
    int a = checkZero(h);
    if(!a) break;
    rep(i, n){
      if(h[i]) h[i]--;
    }
    ans += a;
  }
  cout << ans << endl;
}

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

int main() {
  
  int N; cin >> N;
  
  for (int i = 1; i < 100001; i++) {
    
    int tmp = pow(i, 2);
    
    if (N < tmp) {
      cout << (i - 1) * (i - 1) << endl;
      return 0;
    }
    
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

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

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

  cout << d.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	cin >> s;
	int n = s.size();
	int cnt1, cnt2;
	cnt1 = cnt2 = 0;
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) {
			//101010101010
			if (s[i] != '1') {
				cnt1++;
			}
		}
		else {
			if (s[i] != '0') {
				cnt1++;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) {
			//01010101010101
			if (s[i] != '0') {
				cnt2++;
			}
		}
		else {
			if (s[i] != '1') {
				cnt2++;
			}
		}
	}
	cout << min(cnt1, cnt2) << endl;
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int n, q, c, x, y, size_, dat[262144];
inline void update(int pos, int x) {
	pos += size_; dat[pos] = x;
	while(pos != 1) {
		pos >>= 1;
		dat[pos] = min(dat[2 * pos], dat[2 * pos + 1]);
	}
}
inline int query(int a, int b, int k, int l, int r) {
	if(r <= a || b <= l) return 2147483647;
	if(a <= l && r <= b) return dat[k];
	int lc = query(a, b, 2 * k, l, (l + r) / 2);
	int rc = query(a, b, 2 * k + 1, (l + r) / 2, r);
	return min(lc, rc);
}
int main() {
	scanf("%d%d", &n, &q);
	for(size_ = 1; size_ < n;) size_ *= 2;
	for(int i = 0; i < size_ * 2; i++) dat[i] = 2147483647;
	for(int i = 0; i < q; i++) {
		scanf("%d%d%d", &c, &x, &y);
		if(c == 0) update(x, y);
		else printf("%d\n", query(x, y + 1, 1, 0, size_));
	}
}

Measured memory_bytes: 4228
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll a, v;
    cin >> a >> v;
    ll b, w;
    cin >> b >> w;
    ll t;
    cin >> t;

    ll tmp = abs(a-b);

    if(v <= w){
        cout << "NO" << endl;
        return 0;
    }

    ll tmp2 = (v-w) * t;

    if(tmp2 >= tmp){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    string s;cin>>s;
    int cntg=0,cntp=0,ans=0;
    rep(i,s.size()){
        if(cntg==cntp){
            if(s[i]=='p'){
                cntg++;
                ans--;
            }
            else{
                cntg++;
            }
        }
        else if(cntg>cntp){
            if(s[i]=='p'){
                cntp++;
            }
            else{
                cntp++;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
using namespace std;

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

    ll ans = 0;
    rep(i, n) ans += i;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#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 FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;
#define INF 1000000000000
#define NOD 1000000007
#define PI 3.141592653589793238462643

int main() {
    int x, t=0;
    cin >> x;
    REP(i, 1000000000) {
        t += i+1;
        if(t >= x) {
            cout << i+1 << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=22;
const int dx[]={0,1,0,-1};
const int dy[]={-1,0,1,0};
int n,m,ans=0;
bool mp[N][N];
#define fe(i,j,n,m) for(int i=1; i<=n; i++)\
					for(int j=1; j<=m; j++)
struct szc{int x,y,dis;};
int bfs(int X,int Y)
{
	bool vis[N][N];
	fe(i,j,n,m) vis[i][j]=mp[i][j];
	queue <szc> q;
	q.push({X,Y,0});
	vis[X][Y]=1;
	int D=0;
	while(!q.empty())
	{
		szc t=q.front();q.pop();
		int x=t.x,y=t.y,dis=t.dis;
		D=max(D,dis);
		for(int i=0; i<4; i++)
		{
			int xx=x+dx[i];
			int yy=y+dy[i];
			if(xx<1||xx>n||yy<1||yy>m||vis[xx][yy]) continue;
			vis[xx][yy]=1;
			q.push({xx,yy,dis+1});
		}
	}
	return D;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++)
	{
		char c;getchar();
		for(int j=1; j<=m; j++)
		{
			c=getchar();
			mp[i][j]=c=='#';
		}
	}
	getchar();
	fe(i,j,n,m) if(!mp[i][j]) ans=max(ans,bfs(i,j));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

int n, c;

int dp[100][(1 << 16) + 10];

int bitnum(int mask){
	int res = 0;
	while (mask > 0){
		res += mask & 1;
		mask >>= 1;
	}
	return res;
}

int main(){
	while (cin >> n >> c&&n + c){
		vector<int> a(n + 10), b(n + 10);
		REP(i, n){
			REP(j, 16){
				int t;
				cin >> t;
				if (t == 1){
					a[i] |= (1 << j);
				}
			}
		}
		REP(i, c){
			REP(j, 16){
				int t;
				cin >> t;
				if (t == 1){
					b[i] |= (1 << j);
				}
			}
		}
		REP(i, 100){
			REP(mask, (1 << 16) + 10){
				dp[i][mask] = -INF;
			}
		}
		dp[0][a[0]] = 0;

		REP(i, n){
			REP(j, c){
				REP(mask, (1 << 16)){
					if (dp[i][mask] == -INF)continue;
					int nxt = mask - (mask&b[j]);
					if (i < n - 1){
						nxt |= a[i + 1];
					}
					dp[i + 1][nxt] = max(dp[i + 1][nxt], dp[i][mask] + bitnum((mask&b[j])));
				}
			}
		}

		int ans = 0;
		REP(i, (1 << 16)){
			if (dp[n][i] != -INF)ans = max(ans, dp[n][i]);
		}
		cout << ans << endl;
	}
}

//struct pic
//
//int N;
//
//int main(){
//	while (cin >> N&&N){
//		REP(i, N - 1){
//			int n, d;
//			cin >> n >> d;
//
//		}
//	}
//}

Measured memory_bytes: 28696
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

constexpr int MAX_N = 100;
int N;
char S[MAX_N + 1];

void _main() {
  cin >> N;
  rep(i, 0, N) cin >> S[i];

  rep(i, 0, N) {
    if (S[i] == 'Y') {
      cout << "Four" << "\n";
      return;
    }
  }
  cout << "Three" << "\n";
}

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

int main() {
    int n;
    cin >> n;
    int acnt = 0;
    int ans = 0;
    
    rep(i, n + 1) {
        int cnt = 0;
        int p = i;
        
        while(p) {
            if ((p != 1) && ((p % 2) != 0)) {
                break;
            }
            
            cnt++;
            p /= 2;
        }
        
        if (acnt < cnt) {
            acnt = cnt;
            ans = i;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>
using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int a;
    string b;
    cin >> a >> b;
    ld ans = a*(b[0]-'0');
    ans += a*(b[2]-'0')/10.0;
    ans += a*(b[3]-'0')/100.0;
    cout << (int)ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;


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

	int n,m;
	cin >> n >> m;

	cout << pow(2,m)*(100*n + m*1800) << "\n";

	return 0;
}

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

using namespace std;

int main(){


	int N;
	cin>>N;
	vector<int> vec(N);
	
	long long inst;
	for(int i=0; i<N; i++){
		
		cin>>inst;
		vec.at(i) = inst - i;
	}
	

	
	
	std::sort(vec.begin(),vec.end());
	long long res=0;
	int x = (N/2);
	for(int i=0; i<N; i++){
		res= res + std::abs(vec.at(i) - vec.at(x));
	}
	
	
	
	cout<< res <<endl;
	
	
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> ans(n+1, INT_MAX), h(n+1);
    ans[1] = 0; 
    for (int i = 1 ; i <= n ; i++) cin>>h[i];
    for (int i = 1 ; i <= n ; i++) {
        for (int j = 1 ; j <= k ; j++) {
            if ((i + j) > n) continue;
            ans[i+j] = min(ans[i+j], ans[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << ans[n];
    return 0;
}


Measured memory_bytes: 1024
input1 = input().split()
input2 = list(map(int,input().split()))
U = input()
S = input1[0]
T = input1[1]
A = input2[0]
B = input2[1]
if U == S:
  A -= 1
else:
  B -= 1
print(str(A) + " " + str(B))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    int D; cin >> D;
    vector<int> C(26); vector<vector<int>> S(D, vector<int>(26));
    REP(i, 0, 26) cin >> C[i];
    REP(i, 0, D) REP(j, 0, 26) cin >> S[i][j];


    vector<int> T(D);
    REP(i, 0, D) {
        int max_idx = 0;
        REP(j, 0, 26) {
            if (S[i][max_idx] < S[i][j]) max_idx = j;
        }
        T[i] = max_idx + 1;
    }

    vector<vector<int>> last(26, vector<int>(D, 0));
    vector<ll> ret(26, 0);
    REP(i, 0, D) {
        ret[T[i] - 1] += S[i][T[i] - 1];
        last[T[i] - 1][i] = i + 1;
        REP(j, 0, 26) {
            if (i > 0 && !last[j][i]) last[j][i] = last[j][i - 1];
            ret[j] -= C[j] * (i + 1 - last[j][i]);
        }
    }

    ll best = accumulate(ALL(ret), 0LL);
    mt19937_64 mt(random_device{}());
    REP(i, 0, 1) {
        int d = mt() % D;
        int next = mt() % 26;
        int prev = T[d] - 1;
        T[d] = next + 1;
        last[prev].assign(D, 0);
        last[next].assign(D, 0);
        ret[prev] = 0;
        ret[next] = 0;
        REP(i, 0, D) {
            if (T[i] == prev + 1 || T[i] == next + 1) {
                ret[T[i] - 1] += S[i][T[i] - 1];
                last[T[i] - 1][i] = i + 1;
            }
            if (i > 0) {
                if (!last[prev][i]) last[prev][i] = last[prev][i - 1];
                if (!last[next][i]) last[next][i] = last[next][i - 1];
            }
            ret[prev] -= C[prev] * (i + 1 - last[prev][i]);
            ret[next] -= C[next] * (i + 1 - last[next][i]);
        }
        if (best > accumulate(ALL(ret), 0LL)) {
            T[d] = prev + 1;
        }
    }
    
    for (auto t : T) cout << t << endl;
    return 0;
}

Measured memory_bytes: 3712
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		IntStream alices = IntStream.range(sc.nextInt(), sc.nextInt());
		List<Integer> bobs = IntStream.range(sc.nextInt(), sc.nextInt()).boxed().collect(Collectors.toList());
		sc.close();
		Long count = alices.filter(alice -> bobs.contains(alice)).count();
		System.out.println(count);
	}
}


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

using namespace std;

int main()
{
	int N;
  	cin >> N;
	vector<char> S(N);
  	for(int i = 0; i < N; i++){
      	cin >> S.at(i);
    }
  	bool a = false;
  	for(int i = 0; i < N; i++){
      	if(S.at(i) == 'Y'){
          	a = true;
        }
    }
  	if(a){
      	cout << "Four";
    }else{
      	cout << "Three";
    }
  	return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=[0] * (M + 1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()

if D[0]!=0 :
    print(0)
    sys.exit()

for i in range(2,M+1):
    ans *= countlist[i-1]**countlist[i]

print(ans%998244353) 

Measured memory_bytes: 14396
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h> 
#define MAX(a,b) ((a)>(b)?(a):(b)) 


int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int i=0;
	while(n)
	{
		n/=k;
		i++;
	}
	printf("%d",i);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

int a,b,temp;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
    
	cin>>a>>b;
	a*=pow(10,int(log10(b)+1));
	a+=b;
	temp = sqrt(a);
	if(temp*temp==a)
		cout<<"Yes";
	else
		cout<<"No";

}
	

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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 単項演算子
	constexpr ModInt& operator++()
	{
		if (integer_ + 1 == mod_) integer_ = 0;
		else integer_++;
		return *this;
	}

	constexpr ModInt& operator--()
	{
		if (integer_ == 0) integer_ = mod_ - 1;
		else integer_--;
		return *this;
	}

	constexpr ModInt operator+()
	{
		return *this;
	}

	constexpr ModInt operator-()
	{
		if (integer_ == 0) return ModInt(0ll);
		else return ModInt(mod_ - integer_);
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}

	static constexpr int64_t mod{mod_};
};
using Mint = ModInt<>;

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int> A(N);
	for (auto& e: A) scanf("%d", &e);
	Mint ans(1);
	int count[3]{};
	for (int i{}; i < N; i++)
	{
		std::sort(count, count + 3);
		auto lb{std::lower_bound(count, count + 3, A[i])};
		auto ub{std::upper_bound(count, count + 3, A[i])};
		int num{(int)(ub - lb)};
		if (num == 0)
		{
			ans = Mint(0);
			break;
		}
		ans *= Mint(num);
		(*lb)++;
	}
	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <climits>

using namespace std;

int main() {

    ios::sync_with_stdio(false);

    pair<int, int> ans;
    ans.first = -1;

    int n,x,mi,t;
    mi = INT_MAX;
    cin >> n >> t;

    for(int i = 1; i <= n; i++) {
        cin >> x;
        mi = min(mi, x);

        if(x-mi > ans.first) {
            ans.second = 1;
            ans.first = x-mi;
        } else if(x-mi == ans.first) {
            ans.second++;
        }

    }

    cout << ans.second;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


long long N, K;
vector<long long> A;

int main() {
    while (cin >> N >> K) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        
        long long res = 0;
        // d までは K と同じ
        for (int d = 60; d >= 0; --d) {
            //cout << "--------------" << endl; COUT(d);
            
            long long tmp = 0;
            long long k = 0;
            for (int e = 60; e >= 0; --e) {
                long long add = 1LL<<e;
                int num = 0;
                for (int i = 0; i < N; ++i) {
                    if (A[i] & add) ++num;
                }
                int rem = (int)N - num;
                
                if (e >= d) {
                    if (K & add) {
                        k += add;
                        tmp += add * rem;
                    }
                    else {
                        tmp += add * num;
                    }
                }
                else {
                    if (num < rem && k + add <= K) {
                        k += add;
                        tmp += add * rem;
                    }
                    else {
                        tmp += add * num;
                    }
                }
            }
            
            //COUT(tmp);

            chmax(res, tmp);
        }
        cout << res << endl;
    }
}










Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//priority_queue <int, vector <int>, greater <int> > pq; ..for min heap
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979323846264
#define pii pair <int, int>
#define pipii pair <int, pair <int, int> > 
#define piipi pair <pair <int, int>, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
#define FOR(i, x, y) for (int i=x; i<=y; i++)
#define FORD(i, y, x) for (int i=y; i>=x; i--)
#define debug printf("OK\n")
int n;
double x;
priority_queue <double, vector <double>, greater <double> > pq;
int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        scanf("%lf", &x);
        pq.push(x);
    }
    while (!pq.empty()) {
        if (pq.size() == 1) {
            printf("%.10lf\n", pq.top());
            return 0;
        }
        double a = pq.top();
        pq.pop();
        double b = pq.top();
        pq.pop();
        pq.push((a + b) / 2);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF					INT_MAX
#define LLINF					LLONG_MAX
#define DEBUG					false
 
typedef long long				ll;
typedef pair <int, int> ii;

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

int main() {
	
	int w, h;
	
	while(cin >> w >> h, w, h){
		vector<string> mp(h);
		//vector<vector<bool> > used(h, vector<int>(w));
		rep(i, h) cin >> mp[i];
		
		int sx, sy;
		rep(i, h){
			rep(j, w) if(mp[i][j] == '@'){
				sx = j;
				sy = i;
			}
		}
		
		queue<ii> qu;
		qu.push(make_pair(sx, sy));
		
		int ans = 0;
		while(!qu.empty()){
			ii tmp = qu.front();
			qu.pop();
			ans++;
			
			
			rep(i, 4){
				int nx = tmp.first + dx[i];
				int ny = tmp.second + dy[i];
			
				if(nx < 0 || w <= nx) continue;
				if(ny < 0 || h <= ny) continue;
				
				if(mp[ny][nx] == '.'){
					qu.push(make_pair(nx, ny));
					mp[ny][nx] = '#';	
				}
				
			}
			
			
		}
		
		cout << ans << endl;
		
		
	}
	
	
	
	return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll dp[1010][1010];
ll comb[1010][1010];

#define N 1010
ll inv[N],fac[N],ifac[N];

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

  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<=1010;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;
    //cout<<inv[i]<<" "<<fac[i]<<" "<<ifac[i]<<endl;
  }

  dp[a-1][0]=1;
  for(int i=a;i<=b;i++){
    for(int j=0;j<=n;j++){
      if(dp[i-1][j]==0) continue;
      dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;

      ll tmp=1;
      for(int k=1;k<=d&&j+i*k<=n;k++){
        tmp=tmp*fac[n-j-i*(k-1)]%MOD*ifac[i]%MOD*ifac[n-j-i*k]%MOD*inv[k]%MOD;
        if(k>=c){
          dp[i][j+i*k]=(dp[i][j+i*k]+dp[i-1][j]*tmp%MOD+MOD)%MOD;
        }
      }
    }
  }

  cout<<dp[b][n]<<endl;

  return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    //freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	
	int N;
	int sum=0;
	cin >> N;
	
	for(int i=1; i<=N; i++){
		int a, b;
		cin >> a >> b;
		if(a==b){
			sum++;
		}
		else{
			sum=0;
		}
		if(sum==3){
			cout << "Yes";
			return 0;
		}
	}
	
	cout << "No";
	
	return 0;
}

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


int main(){
  string s;
  cin >> s;
  int R_count = 0;
  int B_count = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '0') R_count++;
    else B_count++;
  }
  int ans = min(R_count,B_count);
  cout << ans * 2 << endl;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

struct rest {
		string S;
		int P;
		int num;
};

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

		vector<rest> v(N, {"", 0});
		for (int i = 0; i < N; i++) {
				cin >> v[i].S >> v[i].P;
				v[i].num = i + 1;
		}

		sort(v.begin(), v.end(), [](const rest &a, const rest &b) {
				if (a.S != b.S) return a.S < b.S;
				else return a.P > b.P;
		});

		for (int i = 0; i < N; i++) {
				cout << v[i].num << endl;
		}

		return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 100000+10

using namespace std;

long long n;
long long MOD;
long long Ans[MAXN];
long long S[MAXN];

int main()
{
	long long Now;
	cin>>n>>Now>>MOD;
	memset(Ans,-1,sizeof(Ans));
	Ans[Now] = 1;
	S[1] = Now;
	//long long Count = Now;
	for(int i=2;i<=n;i++)
	{
		Now = Now*Now%MOD;
		S[i] = S[i-1] + Now;
		if(Ans[Now]!=-1)
		{
			long long Re = S[Ans[Now]-1];
			long long XHJ = S[i] - S[Ans[Now]];
			long long CD = i - Ans[Now];
			n -= Ans[Now] - 1;
			Re += XHJ * (n/CD);
			Re += S[Ans[Now]+n%CD-1] - S[Ans[Now]-1];
			cout<<Re;
			return 0;
		}
		Ans[Now] = i;
	}
	cout<<S[n];
	return 0;
}


Measured memory_bytes: 4776
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll h,w,tc=0,fc=0;
  ll g0,g1;
  cin >> h >> w;
  if(w%2==1){
    swap(h,w);
  }
  g0 = g1 = 0;
  if(h%2==1){
    g1 = w/2;
  }
  if(w%2==1){
    g0 = 1;
    g1 = h/2 + w/2;
  }
  int clist[26]={};
  char c;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c;
      clist[c-'a']++;
    }
  }
  for(int i=0;i<26;i++){
    if(clist[i]%4==1) fc++;
    else if(clist[i]%4==2) tc++;
    else if(clist[i]%4==3){
      fc++;
      tc++;
    }
  }
  if(g0>=fc&&g1>=tc){
    cout <<"Yes\n";
  }else{
    cout <<"No\n";
  }
}


Measured memory_bytes: 256