akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>

using namespace std;
#define rep(i,n) for ( int i = 0; i < n; i++ )
#define REP(i, b, e) for ( int i = b; i <= e; i++ )
#define MAX 100
#define LIMIT 180
#define BLOCK '#'
#define SPACE '.'
#define EXIT 'X'
static const string DIR = "ENWS";
static const int di[4] = {0, -1, 0, 1};
static const int dj[4] = {1, 0, -1, 0};
int H, W;
char G[MAX+2][MAX+2];

char oposite( int r ){
    return DIR[(r+2)%4];
}

bool isPerson(char ch){
    rep(d, 4) if ( ch == DIR[d] ) return true;
    return false;
}

int getDirection(char ch){
    rep(d, 4) if ( ch == DIR[d] ) return d;
}

int chengeDirection(){
    int nperson = 0;
    REP(i, 1, H) REP(j, 1, W){
	if ( !isPerson(G[i][j]) ) continue;
	nperson++;
	int curd = getDirection(G[i][j]);
	int v = curd;
	curd = ((curd == 0) ? 3 : curd-1);
	for ( int r = curd; r < curd + 4; r++ ){
	    char ch = G[i+di[r%4]][j+dj[r%4]];
	    if ( ch == SPACE || ch == EXIT ){
		v = r%4;
		break;
	    }
	}
	G[i][j] = DIR[v];
    }
    return nperson;
}

void move(){
    bool possible[MAX+2][MAX+2];
    rep(i, H+2) rep(j, W+2 ) possible[i][j] = false;

    REP(i, 1, H) REP(j, 1, W){
	if ( G[i][j] == SPACE || G[i][j] == EXIT){
	    for ( int r = 0; r < 4; r++ ){
		char target = G[i+di[r]][j+dj[r]];
		if ( isPerson(target) && target == oposite(r) ){
		    possible[i+di[r]][j+dj[r]] = true;
		    break;
		}
	    }
	}
    }

    REP(i, 1, H) REP(j, 1, W){
	if ( !isPerson(G[i][j]) || !possible[i][j] ) continue;

	int ni, nj;
	for ( int r = 0; r < 4; r++ ){
	    if ( DIR[r] == G[i][j] ) {
		ni = i + di[r];
		nj = j + dj[r];
		break;
	    }
	}

	if ( G[ni][nj] == EXIT ){
	    G[i][j] = SPACE;
	} else if ( G[ni][nj] == SPACE ){
	    G[ni][nj] = G[i][j];
	    G[i][j] = SPACE;
	}
    }
}

void trace(){
    REP(i, 1, H){
	REP(j, 1, W){
	    cout << G[i][j];
	}
	cout << endl;
    }
    cout << endl;
}

int main(){
    while(1){
	cin >> W >> H;
	if ( H == 0 && W == 0 ) break;
	rep(i,H+2) rep(j,W+2) G[i][j] = BLOCK;
	REP(i, 1, H) REP(j, 1, W) {
	    cin >> G[i][j];
	    char c = G[i][j];
	}
	
	int t = 0;
	while(1){
	    if ( t > LIMIT ) break;
	    if( !chengeDirection() ) break;
	    move();
	    t++;
	}
	if ( t > LIMIT ) cout << "NA" << endl;
	else cout << t <<  endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
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);
    }
};

int digits(ll n) {
    int dig = 0;
    while (n > 0) {
        n /= 10;
        dig++;
    }
    return dig;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (digits(i) % 2) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

double a,b,n,x;

int main()
{
	cin>>a>>b>>n;
	x=min(b-1,n);
	cout<<floor(a*x/b)-a*floor(x/b)<<endl;
	return 0;
}

Measured memory_bytes: 3788
#include <iostream>

int main() {
	long long n, m, d;
	std::cin >> n >> m >> d;
	
	if(n == 0) {
		std::cout << 0 << std::endl;
		return 0;
	}

	int p;
	if(d == 0) {
		p = n;
	} else if(d >= n) {
		p = 0;
	} else {
		p = (n - d) * 2;
	}

	const long double result = static_cast<long double>((m - 1) * p) / (n * n);

	std::cout << std::fixed << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n, i, ans = 0, sum = 0;
    scanf("%d",&n);
    int d[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&d[i]);
        sum += d[i];
    }
    for(i=0;i<n;i++)
    {
        ans += (sum-d[i])*d[i];
        sum = sum-d[i];
    }
    printf("%d",ans);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(10) << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  ll ans = LINF;
  //全ての切り方
  for(int i = 0; i < 1 << (h - 1); ++i) {
    ll buf = 0;
    VL a(h, 0);
    //貪欲
    rep(j, w) {
      int idx = 0;
      a[0] += (s[0][j] - '0');
      //下から見る
      rep(t, h - 1) {
        idx += (i >> t) & 1;
        a[idx] += (s[t + 1][j] - '0');
      }
      if(*max_element(all(a)) > k && j == 0) break;
      else if(*max_element(all(a)) > k) {
        buf += 1;
        fill(all(a), 0);
        j -= 1;
      }
    }
    int idx = 0;
    fill(all(a), 0);
    a[0] += (s[0][w - 1] - '0');
      rep(t, h - 1) {
        idx += (i >> t) & 1;
        a[idx] += (s[t + 1][w - 1] - '0');
    }
    if(*max_element(all(a)) > k) continue;
    ans = min(ans, buf + __builtin_popcount(i));
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 256
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void solve(){
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<n;++i)
	cout<<s[i]<<t[i];
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)//
	solve();
	return 0;
}


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

int main(void)
{
  int N;
  std::cin >> N;
  
  std::vector<std::string> strList;
  std::string str;
  for(int i=0; i<N;i++)
  {
    std::cin >> str;
    strList.push_back(str);
  }
  
  int counta[4] = {0,0,0,0};
  
  for(int i=0; i<N;i++)
  {
    if(strList[i] == "AC")
    {
      counta[0]++;
    }
    
    if(strList[i] == "WA")
    {
      counta[1]++;
    }

        if(strList[i] == "TLE")
    {
      counta[2]++;
    }

        if(strList[i] == "RE")
    {
      counta[3]++;
    }

  }
  
  
  std::cout << "AC x " <<counta[0]<<std::endl;
  std::cout << "WA x " <<counta[1]<<std::endl;
  std::cout << "TLE x " <<counta[2]<<std::endl;
  std::cout << "RE x " <<counta[3]<<std::endl;
  return 0;
}

Measured memory_bytes: 5940
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    S = input().strip()
    if S.isupper():
        print("A")
    else:
        print("a")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8960
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
string X;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>X;

    ll ans = X.size();

    stack<char> stk;
    REP(i,0,X.size()){
        char c = X[i];
        if(stk.empty()){
            stk.push(c);
            continue;
        }

        if(stk.top() == 'S' && c == 'T'){
            ans -= 2;
            stk.pop();
        }else{
            stk.push(c);
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    map<string,int> mp;
    mp["SUN"] = 7;
    mp["MON"] = 6;
    mp["TUE"] = 5;
    mp["WED"] = 4;
    mp["THU"] = 3;
    mp["FRI"] = 2;
    mp["SAT"] = 1;
    cout << mp[s] << endl;
    return 0;
}

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

#define MAX 40

#define WALL '#'
#define EXIT 'X'
#define TILE '.'

#define EAST 0
#define NORTH 1
#define WEST 2
#define SOUTH 3
#define MAXDIR 4

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

int condir[128];
char revdir[4];
const int di[] = {0,-1,0,1};
const int dj[] = {1,0,-1,0};

using namespace std;

typedef pair<int,int> pi;

struct Squares{
  int H,W;
  Squares():H(0),W(0){}
  Squares(int H, int W):H(H),W(W){}
  char D[MAX][MAX];

  bool isInside(int i, int j)const{
    return 0<=i&&i<H&&0<=j&&j<W;
  }
  bool isEmpty(int i, int j)const{
    return D[i][j] == EXIT || D[i][j] == TILE;
  }
  bool isPerson(int i, int j)const{
    return D[i][j] == 'E' || D[i][j] == 'N' || D[i][j] == 'W' || D[i][j] == 'S';
  }
  void escapersStage1(){
    rep(i,0,H){
      rep(j,0,W){
	if( isPerson(i,j) ){
	  int initk = condir[D[i][j]]-1+MAXDIR;
	  int endk = initk + MAXDIR;
	  for(int k = initk; k < endk; ++k){
	    int ti = i+di[k%MAXDIR];
	    int tj = j+dj[k%MAXDIR];
	    if( isInside(ti,tj) ){
	      if( isEmpty( ti, tj ) ){
		D[i][j] = revdir[k%MAXDIR];
		break;
	      }
	    }
	  }
	}
      }
    }
  }

  pi getfront(int i, int j, int dir){
    return make_pair(i+di[dir],j+dj[dir]);
  }
  
  void escapersStage2(){
    char newD[MAX][MAX];
    rep(i,0,MAX)rep(j,0,MAX)newD[i][j]=-1;
    rep(i,0,H){
      rep(j,0,W){
	if( isEmpty(i,j) ){
	  for(int k = 0; k < MAXDIR; ++k){
	    int ti = i+di[k];
	    int tj = j+dj[k];
	    if( isInside(ti,tj) ){
	      pi pfront = getfront(ti,tj,condir[D[ti][tj]]);
	      if( isPerson( ti, tj ) && pfront.first == i && pfront.second == j ){
		newD[i][j]=D[ti][tj];
		newD[ti][tj]=TILE;
		if(D[i][j]==EXIT)newD[i][j]=EXIT;
		break;
	      }
	    }
	  }
	}
      }
    }
    rep(i,0,H)rep(j,0,W){if(newD[i][j]==-1)newD[i][j]=D[i][j];}
    rep(i,0,H)rep(j,0,W){D[i][j]=newD[i][j];}
  }
  int getRemainedPersons(){
    int ret = 0;
    rep(i,0,H)rep(j,0,W){
      if( isPerson(i,j) )++ret;
    }
    return ret;
  }
  void Print(){
    cout << " THE SQUARES COND : " << endl;
    rep(i,0,H){rep(j,0,W){
	cout << D[i][j];}cout<<endl;}
  }
};

int main()
{
  revdir[EAST] = 'E';
  revdir[NORTH] = 'N';
  revdir[WEST] = 'W';
  revdir[SOUTH] = 'S';
  condir[(int)'E'] = EAST;
  condir[(int)'N'] = NORTH;
  condir[(int)'W'] = WEST;
  condir[(int)'S'] = SOUTH;

  while(true){
    int W,H;
    int t = 0;
    cin >> W >> H;

    if( W == 0 && H == 0 ) break;
    
    Squares sq(H,W);
    rep(i,0,H){
      rep(j,0,W){
	cin >> sq.D[i][j];
      }
    }
  
    while( t <= 180 && sq.getRemainedPersons() > 0 ){
      //sq.Print();
      sq.escapersStage1();
      sq.escapersStage2();
      ++t;
    }

    if( t > 180 ) cout << "NA" << endl;
    else cout << t << endl;
  }
  return 0;
}

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

int main()
{
   // cout << "Hello World!" << endl;
   int n;
   cin>>n;
   double d=0.0;
   double a[n],b[n];
   
   for(int i=0;i<n;i++)cin>>a[i]>>b[i];
   
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<n;j++)
       {
           
           d+=sqrt((abs(a[i]-a[j])*abs(a[i]-a[j])+abs(b[i]-b[j])*abs(b[i]-b[j])));
       }
       
   }
   
   int k=1;
   
   //for(int i=1;i<=n;i++)k=k*i;
   
   d=d/double(n);
   
   printf("%0.10f",d);
   
   
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <map>
#include <vector>

using namespace std;

constexpr int64_t kMod = 1e9+7;
constexpr int64_t kMax = 1000001;

int divs[1000001];

void Divs(int mx) {
//  vector<int> divs(mx+1);
//  iota(divs.begin(), divs.end(), 0);
  for (int i = 0; i <= mx; ++i) divs[i] = i;
  for (int i = 2; i <= sqrt(mx); ++i) {
    if (divs[i] < i) continue;
    for (int j = i+i; j <= mx; j+=i) {
      divs[j] = i;
    }
  }
//  return divs;
}

int64_t ModInv(int64_t a, int64_t m) {
  int64_t b = m, u = 1, v = 0;
  while (b) {
    int64_t t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

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

  vector<int64_t> nums(N);
  int64_t mx = 0;
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
	mx = max(mx, nums[n]);
  }
  /*vector<int> divs =*/ Divs(mx);
  map<int, int> lcm;
  for (int n = 0; n < N; ++n) {
    int64_t num = nums[n];
    while (num > 1) {
      int cnt = 0;
      int d = divs[num];
      while (num % d == 0) {
        ++cnt;
        num /= d;
      }
      lcm[d] = max(lcm[d], cnt);
    }
  }

  int64_t mod_lcm = 1;
  for (const auto& p : lcm) {
    for (int i = 0; i < p.second; ++i) {
      mod_lcm *= p.first;
      mod_lcm %= kMod;
    }
  }

  int64_t res = 0;
  for (const int64_t num : nums) {
    res += mod_lcm * ModInv(num, kMod);
    res %= kMod;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 7796
import sys
import math
sys.setrecursionlimit(int(1e6))
dprint = print
#def dprint(*args):
#   pass

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

DD = D * D
count = 0

for i in range(N):
    x, y = list(map(int, input().split()))
    if (x**2 + y**2) <= DD:
        count = count + 1

print(count)


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

int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int n;
  cin>>n;
  map<int, int> mp;
  ll sum = 0;
  int a;
  rep(i,n) {
    cin>>a;
    sum += a;
    mp[a]++;
  }
  int q;
  cin>>q;
  rep(i,q) {
    int b,c;
    cin>>b>>c;
    sum += (c-b)*mp[b];
    cout << sum << endl;
    mp[c] += mp[b];
    mp[b] = 0;
  }
  return 0;
}

Measured memory_bytes: 7896
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n,m;
   cin >> n >> m;
   cout << (n*(n-1)+m*(m-1))/2 << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    ll minabs = 1000000000;
    bool zero = false;
    ll MAX = 0LL;
    ll minus = 0;

    for(int i=0; i<N; i++){
        ll n; cin >> n;
        if(n == 0) zero = true;
        MAX += abs(n);
        minabs = min(minabs, abs(n));
        if(n < 0) minus++;
    }

    // cout << minabs << endl;
    // cout << minus << endl;

    if(zero == true || minus%2 == 0){
        cout << MAX << endl;
    }
    else{
        cout << MAX - 2*minabs << endl;
    }
}

Measured memory_bytes: 1024
n = int(input())
xy = []
for _ in range(n):
  a = int(input())
  xy.append([[int(i) for i in input().split()] for __ in range(a)])

ans = 0
for i in range(2**n):
  flag = True
  for j in range(n):
    if i >> j & 1:
      for x,y in xy[j]:
        if (i >> (x-1)&1) != y:
          flag = False
          break
  if flag:
    ans = max(ans, sum(map(int, bin(i)[2:])))
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;

    ll step = min(k, abs(x / d));
    k -= step;
    ll now = x > 0 ? x - step * d : x + step * d;
    ll ans = abs(now);
    if (k > 0)
    {
        if (k % 2)
        {
            ans = min(abs(now + d), abs(now - d));
        }
        else
        {
            ans = abs(now);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
using namespace std;
int a[110];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	long long mmin=9223372036854775806;
	for(int i=1;i<=100;i++){
		long long sum=0;
		for(int j=0;j<n;j++){
			sum+=pow(a[j]-i,2);
		}
		if(sum<mmin)
			mmin=sum;
	}
	cout<<mmin;
	return 0;
}


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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point owari;

double TimeLeft(){
    owari = std::chrono::system_clock::now();
    double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(owari-start).count();
    return elapsed;
}



int d=365;
int c[26]={};
int s[365][26]={};

void calcNewScore(int d,int newT){

}


struct sl{
    ll score=0;
    vector<int> arr;
    sl(){
        arr.resize(365);
    }
};

ll sigk(ll n){
    return n*(n+1)/2;
}



int main(){

    start = std::chrono::system_clock::now(); //Timer start

    bool flag=false;
    ll ans=0,sum=0;

    cin>>d;

    rep(i,26){
        cin>>c[i];
    }

    sl old;
    rep(i,d){
        int Conf=0,Tp=-1;
        rep(j,26){
            cin>>s[i][j];
            if(chmax(Conf,s[i][j]))Tp=j;
        }
        old.arr[i]=Tp;
    }

    rep(i,d){
        old.score += s[i][ old.arr[i] ];
    }

    int lastheld[365]={};
    rep(i,d){
        lastheld[old.arr[i]] = i+1;
    }

    /*
    while( TimeLeft() < 1919){

    }
    */


    for(int ai:old.arr)cout<< ai+1 <<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
string a,b;
int main(){
	cin>>a>>b;
	if(a=="H"){
		if(b=="H")cout<<"H"<<endl;
		if(b=="D")cout<<"D"<<endl;
	}
	if(a=="D"){
		if(b=="H")cout<<"D"<<endl;
		if(b=="D")cout<<"H"<<endl;
	}
}

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

int main(){
  int N,D,p=0;
  cin>>N>>D;
  vector<vector<int>> X(N,vector<int>(D));
  for(vector<int> &i:X)
    for(int &j:i)
      cin>>j;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      int l=0;
      for(int k=0;k<D;k++)
        l+=pow(X[i][k]-X[j][k],2);
      if(pow(l,0.5)==(int)pow(l,0.5))
        p++;
    }
  }
  cout<<p<<endl;
}

Measured memory_bytes: 512
#include<stdio.h>


int main(void) {
	int a, b,c;
	char op;

	scanf("%d %c %d", &a, &op, &b);
	while (op!='?') {
		

		if (op == '+') {
			c= a + b;
		}

		if (op == '-') {
			c = a - b;
		}

		if (op == '*') {
			c = a * b;
		}
		if (op == '/') {
			c = a / b;
		}

		printf("%d\n", c);
		scanf("%d %c %d", &a, &op, &b);
}


	
	return 0;

}



Measured memory_bytes: 2712
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll arr[n+5];
    ll cop[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        cop[i]=arr[i];
    }
    ll mx=arr[0];
    for(int i=0;i<n;i++)
    {
        if(mx<arr[i])
        mx=arr[i];
    }
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        if(mx==arr[i])
            cnt++;
    }

    sort(cop,cop+n);
    ll smx=cop[n-2];
    //cout<<"Here"<<smx<<endl;
    if(cnt>=2)
    {
        for(int i=0;i<n;i++)
            cout<<mx<<endl;
    }
    else
    {

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

            if(arr[i]==mx)
                cout<<smx<<endl;
           else if(arr[i]!=mx)
                cout<<mx<<endl;

        }
    }
    //cout<<mx<<endl;
    return 0;

}


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

int main(){
  long long a, b, x;
  cin >> a >> b >> x;
  if(a != 0){
  cout << b/x - (a-1)/x << endl;
  }
  else{
    cout << b/x + 1 << endl;
  }
}



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

int main() {
  int a,b,c;cin>>a>>b>>c;
  for(int i=1;i<=b;i++){
    if(a*i%b==c){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
}

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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(i%2==0) continue;
        int num = 0;
        for(int j=1; j<=i; j++){
            if(i%j == 0){
                num += 1;
            }
        }
        if(num==8) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){

  int N;
  cin>>N;
  int page=N/2;
  
  if(N%2==1)page+=1;
  cout<<page;
 
  
}


Measured memory_bytes: 256
#include<stdio.h>

int A[1000000], n;

// 二分探索
int binarySearch(int key) {
    int left = 0;
    int right = n;
    int mid;

    while (left<right) {
        mid = (left+right)/2;
        if (key==A[mid]) {
            return 1;
        }
        if (key>A[mid]) {
            left = mid+1;
        }
        else if (key<A[mid]) {
            right = mid;
        }
    }
    return 0;  // 探索できなかった場合
}

int main() {
    int i, q, k, sum = 0;

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

    scanf("%d", &q);
    for (i=0; i<q; i++) {
        scanf("%d", &k);
        if (binarySearch(k)) sum++;
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 2104
import numpy as np

def solve(_k, _A):
  ans = np.inf
  tmp_list = _A + [i+_k for i in _A]
  for i in range(len(_A)):
    dist = tmp_list[len(_A)+i-1] - tmp_list[i]
    if ans > dist:
      ans = dist
  return ans

if __name__ == "__main__":
  _k,_n = map(int, input().split())
  _A = [int(i) for i in input().split()]
  print(int(solve(_k, _A)))


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

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long sum[n+1];
  sum[0] = 0;
  for (long i = 1; i < n+1; i++) {
    sum[i] = sum[i-1]+a[i-1];
  }
  qsort(sum, n+1, sizeof(long), cmpnum);
  long answer = 0;
  long count = 1;
  for (long i = 1; i < n+1; i++) {
    if (sum[i] == sum[i-1]) {
      count++;
    } else {
      if (count >= 2) {
        answer += count*(count-1)/2;
      }
      count = 1;
    }
  }
  if (count >= 2) {
    answer += count*(count-1)/2;
  }
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 4860
#include <vector>
#include <set>
#include <cstdio>
using namespace std;

int main(){
	long long H,W;
	int N;
	scanf("%lld%lld%d",&H,&W,&N);
	vector<long long>v(10);
	set<pair<int,int>>points;
	v[0]=(H-2)*(W-2);
	for(;N--;){
		int h,w;
		scanf("%d%d",&h,&w);h--,w--;
		points.emplace(h,w);
		for(int h0=-1;h0<2;h0++)for(int w0=-1;w0<2;w0++){
			if(1<=h+h0&&h+h0<H-1 && 1<=w+w0&&w+w0<W-1){
				int t=0;
				for(int h1=-1;h1<2;h1++)for(int w1=-1;w1<2;w1++){
					t+=points.find({h+h0+h1,w+w0+w1})!=points.end();
				}
				v[t-1]--;
				v[t]++;
			}
		}
	}
	for(auto &e:v)printf("%lld\n",e);
}

Measured memory_bytes: 4864
a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
    for j in range(len(str(i))//2+1):
        #print(str(i), str(i)[j],str(i)[-j-1],j , len(str(i))//2)
        if str(i)[j] != str(i)[-j-1]:
            break
        if j == len(str(i))//2:
            ans += 1


print(ans)

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin>>n>>s;
    int pos[4][n];
    pos[0][0]=0;
    pos[0][1]=0;
    pos[1][0]=0;
    pos[1][1]=1;
    pos[2][0]=1;
    pos[2][1]=0;
    pos[3][0]=1;
    pos[3][1]=1;
    for (int i=1; i<n-1; i++) {
        for (int j=0; j<4; j++) {
            pos[j][i+1]=pos[j][i]^pos[j][i-1];
            if (s[i]=='x') pos[j][i+1]=1-pos[j][i+1];
            //printf("%d %d %d\n", i,j,pos[j][i+1]);
        }
    }
    bool f = false;
    for (int j=0; j<4; j++) {
        bool tr = true;
        if ((pos[j][n-2]^pos[j][0])!=(pos[j][n-1]^(s[n-1]=='x'))) tr=false;
        if ((pos[j][n-1]^pos[j][1])!=(pos[j][0]^(s[0]=='x'))) tr = false;
        f |= tr;
        if (tr) {
            for (int i=0; i<n; i++) {
                if (pos[j][i]==0) printf("S");
                else printf("W");
            }
            printf("\n");
            break;
        }
    }
    if (!f) printf("-1\n");
}

Measured memory_bytes: 2128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

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

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

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

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

int main() {

	int xs, ys, xt, yt;
	scanf("%d %d %d %d",  &xs, &ys, &xt, &yt);
	int N;
	scanf("%d", &N);
	VI X(N + 2), Y(N + 2), R(N + 2);
	REP(i, N) scanf("%d %d %d", &X[i + 1], &Y[i + 1], &R[i + 1]);
	X[0] = xs; Y[0] = ys, R[0] = 0;
	X[N + 1] = xt, Y[N + 1] = yt, R[N + 1] = 0;

	vector<vector<double>> D(N + 2, vector<double>(N + 2, 0));
	REP(i, N + 2){
		REP(j, N + 2){
			D[i][j] = max(0.0, sqrt(1.0 * (X[i] - X[j]) * (X[i] - X[j]) +1.0 * (Y[i] - Y[j]) * (Y[i] - Y[j])) - R[i] - R[j]);
			D[j][i] = D[i][j];
//			cout << i << " "<< j << " " << D[i][j] << endl;;
		}
	}

	vector<double> dp(N + 2, 1e18);
	priority_queue<int, vector<int>, greater<int>> que;
	que.push(0);
	dp[0] = 0;
	while(!que.empty()){
		int cur = que.top();
//		cout << cur << endl;
		que.pop();
		REP(next, N + 2){
			if(dp[next] > dp[cur] + D[cur][next]){
				dp[next] = dp[cur] + D[cur][next];
				que.push(next);
			}
		}
	}

	printf("%.10f", dp[N + 1]);

	return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if (a1+a2+a3 >= 22)
        cout << "bust";
    else
        cout << "win";
    return 0;
}


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

using namespace std;
typedef long long ll;

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

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

    set<ll> se;
    vector<int> a(n);
    int gcd = -1;
    {
        cin >> a[0], gcd = a[0];
        auto ma = prime_factor(a[0]);
        for (auto &x:ma)se.insert(x.first);
    }

    bool pairwise = true;
    for (int i = 1; i < n; i++) {
        cin >> a[i];
        gcd = __gcd(gcd, a[i]);

        if (pairwise) {
            auto ma = prime_factor(a[i]);
            for (auto &x:ma) {
                if (se.count(x.first) > 0)pairwise = false;
                se.insert(x.first);
            }
        }
    }

    if (gcd > 1)cout << "not coprime" << endl;
    else if (pairwise)cout << "pairwise coprime" << endl;
    else cout << "setwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 7300
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Collections;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] S = new String[N];

        Set<String> set =new HashSet<String>();
        for (int i = 0; i < N; i++) {
            S[i] = sc.next();
            set.add(S[i]);
        }

        System.out.println(set.size());
    }

}

Measured memory_bytes: 77664
#include<stdio.h>
#define N 101

int n,A[N][N];
 
int main(){
    int i,j,u,k,v;
 
    scanf("%d",&n);
    
    for(i = 1; i <= n;i++){
        scanf("%d%d",&u,&k);
        for(j = 0; j < k; j++){
            scanf("%d",&v);
            A[i][v] = 1;
        }
    }
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            printf("%d",A[i][j]);
            if(j != n){
                printf(" ");
               }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
int p=0,np=1,dp[2][2][2];
// 是否顶上界,进位 
ll n;
int main(){
	scanf("%lld",&n);
	dp[np][0][0]=1;
	for(int i=0;n>=(1ll<<i);i++,swap(p,np)){
		int d=!!(n&(1ll<<i));
		memset(dp[p],0,sizeof(dp[p]));
		for(int j=0;j<2;++j)
			for(int k=0;k<2;++k)if(dp[np][j][k])
				for(int s=0;s<2;++s)
					for(int t=0;t<2;++t){
						if(s==1&&t==0)continue;
						int x=s+t+k;
						int nj=x%2>d?1:(x%2<d?0:j);
						int nk=x/2;
//						printf("[%d,%d,%d]->[%d,%d,%d]\n",i,j,k,i+1,nj,nk);
						dp[p][nj][nk]+=dp[np][j][k];
						if(dp[p][nj][nk]>=mod)dp[p][nj][nk]-=mod;
					}
	}
	printf("%d",dp[np][0][0]);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll				long long int
#define fast			ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);	
#define vi 			vector<int>
#define vll 			vector<long long int>
#define all(v)			v.begin(),v.end()
const ll MOD = 1e9 + 7;
const ll INF = 10000000000000000;
const ll MAX_N = 1e5 + 7;
using namespace std;
//vector<bool> h(10000001,1);



int main(){
	int a,b,m;
	cin >> a >> b >> m;
	vll v1(a),v2(b);
	for(int i=0;i<a;i++)cin >> v1[i];
	for(int j=0;j<b;j++)cin >> v2[j];
	ll k = *min_element(all(v1))+*min_element(all(v2));
	
	ll sum = INT_MAX;
	for(int i=0;i<m;i++){
		ll a,b,c;
		cin >> a >> b >> c;
		a--,b--;
		sum=min(sum,v1[a]+v2[b]-c);
	
	}
	cout << min(k,sum); 
}



Measured memory_bytes: 1792
def selectionSort(A, N):
    cnt = 0
    for i in range(N):
        minJ = i
        for j in range(i, N):
            if A[minJ] > A[j]:
                minJ = j
        if A[i] != A[minJ]:
            tmp = A[i]
            A[i] = A[minJ]
            A[minJ] = tmp
            cnt += 1
    return A, cnt


def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans, cnt = selectionSort(A, N)
    print(*ans)
    print(cnt)


resolve()



Measured memory_bytes: 5608
s=gets.chomp
ans=Array.new(s.size,0)
r_cnt=0
l_cnt=0
0.upto(s.size-2) do |i|
  if s[i] == 'R' && s[i+1] == 'R'
    ans[i] = 0
    r_cnt += 1
  elsif s[i] == 'R' && s[i+1] == 'L'
    r_cnt+=1
    l_cnt=1
    (i+2).upto(s.size-1) do |j|
      if s[j] == 'L'
        l_cnt += 1
      else
        break
      end
    end

    if r_cnt.odd?
      ans[i] += r_cnt/2+1
      ans[i+1] += r_cnt/2
    else
      ans[i] += r_cnt/2
      ans[i+1] += r_cnt/2
    end

    if l_cnt.odd?
      ans[i] += l_cnt/2
      ans[i+1] += l_cnt/2+1
    else
      ans[i] += l_cnt/2
      ans[i+1] += l_cnt/2
    end
    r_cnt=0
    l_cnt=0
  elsif s[i] == 'L' && s[i+1] == 'L'
    ans[i+1] = 0
  elsif s[i] == 'L' && s[i+1] == 'R'
  end
end
puts ans.join(" ")

Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    int x;
    cin >> x;
    if(x) cout << 0 << endl;
    else cout << 1 << endl;
}

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

long long f( long long n, long long b ) {
    if( n < b )
        return n;
    else
        return f( n / b, b ) + n % b;
}

inline long long check( long long n, long long s, long long b ) {
    if( b >= 2 && f( n, b ) == s )
        return b;
    else
        return numeric_limits<long long> :: max();
}

int main( void ) {
    
    long long n, s;
    cin >> n >> s;
    
    long long ans = numeric_limits<long long> :: max();
    
    if( s == 1 )
        ans = n;
    if( n == s )
        ans = n + 1;
    
    for( int i = 1; 1LL * i * i <= n; i ++ ) {
        ans = min( ans, check( n, s, i ) );
        
        if( ( n - s ) % i == 0 && ( n - s ) / i + 1 >= 2 )
            ans = min( ans, check( n, s, ( n - s ) / i + 1 ) );
    }
   
    ans = min( ans, check( n, s, n - s ) );
    
    if( ans == numeric_limits<long long> :: max() )
        cout << -1 << endl;
    else
        cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,i;
  cin >> n;
  string s1,s2;
  int t=0,h=0;
  
  for(i=0;i<n;i++){
    cin >> s1 >> s2;
    if(s1.compare(s2)==0) {
      t++;h++;
    }else if(s1.compare(s2)>0) t+=3;
    else h+=3;
  }
  cout << t << " " << h << endl;
}



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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }


signed main() {

	int S;
	cin >> S;
	int a1, a2, b1, b2;
	a1 = 1000000000;
	b2 = (S +a1-1)/ a1;
	int p = a1 * b2 - S;

	a2 = 1;
	b1 = p;

	cout << "0 0 " << a1 << " " << a2 << " " << b1 << " " << b2 << endl;

	cerr << abs(a1 * b2 - b1 * a2) << endl;

	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=100+10;
int a[maxn];
int main(){
	int n=read(),sum=read(),cnt=0;
	REP(i,1,n) a[i]=read();
	sort(a+1,a+n+1);
	REP(i,1,n) if(sum>=a[i]) sum-=a[i],++cnt;
	if(cnt==n && sum) --cnt;
	printf("%d\n",cnt);
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	ll n;
	char arf[27] = "zabcdefghijklmnopqrstuvwxy";
	cin >> n;
	string s;
	while(n >= 0) {
		ll i = n % 26;
		s += arf[i];
		if(i == 0) n -= 26;
		n -= i;
		n /= 26;
		if(n == 0) n--;
	}
	reverse(s.begin(), s.end());
		cout << s << endl;
	return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, m;
    cin >> n >> m;
    bool g[10][10];
    rep(i, 10) rep(j, 10) g[i][j] = false;
    rep(i, m) {
        int a,b;
        cin >> a >> b;
        --a, --b;
        g[a][b] = g[b][a] = true;
    }
    vector<int> v(n);
    rep(i, n) v[i] = i;
    int ans = 0;
    do {
        bool c = true;
        rep(i, n-1) c = c && g[v[i]][v[i+1]];
        ans += c;
    } while(next_permutation(v.begin()+1, v.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;
int GCD(int a,int b){
	if(a<b){
		swap(a,b);
	}
	if(a%b==0){
		return b;
	}else{
		return GCD(b,a%b); 
	}
}
int main(){
	int N,x[100000];
	int X;
	cin>>N>>X;
	for(int i=0;i<N;i++){
		cin>>x[i];
		x[i]=abs(X-x[i]);
	}
	X=x[0];
	for(int i=0;i<N;i++){
		X=GCD(X,x[i]);
	}
	cout<<X<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();
        sc.close();
        if (e - a <= k) {

            System.out.println("Yay!");
            return;

        }
        System.out.println(":(");
    }
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    ll a , b , k ;
    cin >> a >> b >> k ;

    ll t = min ( a , k ) ;
    a -= t ; k -= t ;

    t = min ( k , b ) ;
    b -= t ;

    cout << a << " " << b ;
    line
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
#define ill int64_t
void abc117a()
{
  double t, x;
  cin >> t >> x;
  cout << t / x;
}
void abc117b()
{
  int n;
  cin >> n;
  int sum = 0;
  int max = 0;
  for (int i = 0; i < n; i++)
  {
    int temp;
    cin >> temp;
    sum += temp;
    if (temp > max)
      max = temp;
  }
  if (max < sum - max)
    cout << "Yes";
  else
  {
    cout << "No";
  }
}
/*ill max(ill a, ill b)
{
  if (a > b)
    return a;
  else
    return b;
}*/
void abc117d()
{
  ill n, k;
  cin >> n >> k;
  ill a[n];
  ill count[64];
  memset(count, 0, sizeof(count));
  for (ill i = 0; i < n; i++)
  {
    cin >> a[i];
    for (int j = 0; j < 64; j++)
    {
      if (a[i] & (1ll << j))
        count[j]++;
    }
  }
  vector<int> ones;
  int n_max = 0;
  ill sum_max = 0;
  for (int j = 0; j < 64; j++)
  {
    if (k & (1ll << j))
    {
      ones.push_back(j);
      n_max = j;
      sum_max += (1ll << j) * (n - count[j]);
    }
    else
      sum_max += (1ll << j) * count[j];
  }
  if ((int)ones.size() == 0)
  {
    ill sum = 0;
    for (int i = 0; i < 64; i++)
    {
      sum += (1ll << i) * count[i];
    }
    cout << sum;
    return;
  }
  for (int i = 0; i < (int)ones.size(); i++)
  {
    ill temp = 0;
    for (int j = 63; j > n_max; j--)
    {
      temp += (1ll << j) * count[j];
    }
    for (int j = n_max; j > ones[i]; j--)
    {
      ill p = (1ll << j);
      if (k & (1ll << j))
      {
        temp += p * (n - count[j]);
      }
      else
      {
        temp += p * count[j];
      }
    }
    temp += (ill)(1ll << ones[i]) * count[ones[i]];
    if (ones[i] == 0)
    {
      if (temp > sum_max)
        sum_max = temp;
      continue;
    }
    for (int j = ones[i] - 1; j >= 0; j--)
      temp += (ill)(1ll << j) * max(count[j], n - count[j]);
    if (temp > sum_max)
      sum_max = temp;
  }
  cout << sum_max;
}
int main(void)
{
  abc117d();
  //abc117b();
  //abc117a();
  return 0;
}


Measured memory_bytes: 1024
N,M,C = map(int,input().split())
B=[int(x) for x in input().split()]
ans=0

for i in range(N):
    res=[int(x) for x in input().split()]
    cnt=0
    for j in range(M):
        cnt += B[j]*res[j]
    if cnt+C >0:
        ans+=1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

bool seen[1005][1005][1005];

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x);
  vector<ll> b(y);
  vector<ll> c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());
  priority_queue<tuple<ll, ll, ll, ll>> pq;
  ll sum = a[0]+b[0]+c[0];
  int idx = 0;
  int idy = 0;
  int idz = 0;
  tuple<ll, ll, ll, ll> t = make_tuple(sum, 0, 0, 0);
  pq.push(t);
  rep(i, k) {
    t = pq.top();
    pq.pop();
    sum = get<0>(t);
    idx = get<1>(t);
    idy = get<2>(t);
    idz = get<3>(t);
    cout << sum << endl;
    if (idx < x-1 && seen[idx+1][idy][idz] == false) {
      sum = a[idx+1]+b[idy]+c[idz];
      seen[idx+1][idy][idz] = true;
      t = make_tuple(sum, idx+1, idy, idz);
      pq.push(t);
    }
    if (idy < y-1 && seen[idx][idy+1][idz] == false) {
      sum = a[idx]+b[idy+1]+c[idz];
      seen[idx][idy+1][idz] = true;
      t = make_tuple(sum, idx, idy+1, idz);
      pq.push(t);
    }
    if (idz < z-1 && seen[idx][idy][idz+1] == false) {
      sum = a[idx]+b[idy]+c[idz+1];
      seen[idx][idy][idz+1] = true;
      t = make_tuple(sum, idx, idy, idz+1);
      pq.push(t);
    }
  }

}

Measured memory_bytes: 985600
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

result = []

for x in range(X):
  for y in range(Y):
    if x * y > K:
      break
    for z in range(Z):
      if x * y * z > K:
        break
      result.append(A[x] + B[y] + C[z])

for k in list(sorted(result, reverse=True))[:K]:
  print(k)

Measured memory_bytes: 140840