akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[][] m = new char[8][];
		for(int i=0;i<8;i++) {
			m[i] = sc.next().toCharArray();
		}
		
		int pass = 0;
		int turn = 1;
		while(true) {
			turn = 1 - turn;
			int max = 0;
			int maxi = -1;
			int maxj = -1;
			for(int i=0;i<8;i++) {
				for(int j=0;j<8;j++) {
					int x = num(m,i,j,turn);
					if (turn == 0) {
						if (x > max) {
							max = x;
							maxi = i;
							maxj = j;
						}
					}else{
						if (x >= max) {
							max = x;
							maxi = i;
							maxj = j;
						}
					}

				}
			}
			if (max == 0) {
				pass++;
				if (pass >= 2) {
					break;
				}
				continue;
			}
			pass = 0;
			put(m, maxi, maxj, turn);
//			print(m);
		}
		print(m);
	}
	
	public static void print(char[][] m) {
		for(int i=0;i<8;i++) {
			System.out.println(m[i]);
		}
	}
	
	public static int num(char[][] m,int si,int sj,int turn) {
		if (m[si][sj] != '.') {
			return 0;
		}
		char me = turn == 0 ? 'o' : 'x';
		char opp = turn == 0 ? 'x' : 'o';
		int sum = 0;
		for(int di=-1;di<=1;di++) {
			for(int dj=-1;dj<=1;dj++) {
				if (di == 0 && dj == 0) {
					continue;
				}
				int ni = si + di;
				int nj = sj + dj;
				int count = 0;
				while(0 <= ni && ni < 8 && 0 <= nj && nj < 8) {
					if (m[ni][nj] == opp) {
						count++;
					}else if(m[ni][nj] == me) {
						sum += count;
						break;
					}else{
						break;
					}
					ni += di;
					nj += dj;
				}
			}
		}
		return sum;
	}
	
	public static void put(char[][] m,int si,int sj,int turn) {
		char me = turn == 0 ? 'o' : 'x';
		char opp = turn == 0 ? 'x' : 'o';
		m[si][sj] = me;
		for(int di=-1;di<=1;di++) {
			for(int dj=-1;dj<=1;dj++) {
				if (di == 0 && dj == 0) {
					continue;
				}
				int ni = si + di;
				int nj = sj + dj;
				int count = 0;
				boolean flag = false;
				while(0 <= ni && ni < 8 && 0 <= nj && nj < 8) {
					if (m[ni][nj] == opp) {
						count++;
					}else if(m[ni][nj] == me) {
						flag = true;
						break;
					}else{
						break;
					}
					ni += di;
					nj += dj;
				}
				if (count > 0 && flag) {
					ni = si + di;
					nj = sj + dj;
					while(0 <= ni && ni < 8 && 0 <= nj && nj < 8) {
						if (m[ni][nj] == opp) {
							m[ni][nj] = me;
						}else{
							break;
						}
						ni += di;
						nj += dj;
					}
				}
			}
		}
	}

}

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

int main() {
  int n;
  cin >> n;
  int p[n];
  for (int i=0; i<n; i++)
    cin >> p[i];
  int ans = 0;
  bool lc = true;
  for (int i=0; i<n-1; i++) {
    if (p[i] == i+1) {
      ans++;
      if (i == n-2)
        lc = false;
      i++;
    }
  }
  if (lc && p[n-1] == n)
    ans++;
  cout << ans << '\n';
  return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll choose(int n, int r) {
    ll acc = 1;
    rep(i,r) acc = acc * (n-i) / (i+1);
    return acc;
}
signed main()
{   
    gearup;
    int n,p; cin >> n >> p;
    ll odd = 0,even =0;
    rep(i,n){
        int m; cin >> m;
        if(m%2==0)even++;
        else odd++;
    }
    ll res = 0;
    if(p==0){ //偶数を取り出す時
        if(even == n)res=(1LL<<even); 
        else{//奇数を偶数個取り出す組み合わせ
            for(int i=p;i<= odd;i+=2){
                res+=choose(odd,i);
            }
            res*=(1LL<<even);
        }
    }
    else{ //奇数を取り出す時
        if(even == n)res = 0;
        else{//奇数を奇数個取り出す組み合わせ
            for(int i=p;i<= odd;i+=2){
                res+=choose(odd,i);
            }
            res*=(1LL<<even);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
<?php

$n = trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$b = explode(' ', trim(fgets(STDIN)));
$ab = array_sum($a);

for($i=0; $i<$n; $i++){
  $m = min($a[$i],$b[$i]);
  $a[$i] -= $m;
  $b[$i] -= $m;
  $m = min($a[$i+1],$b[$i]);
  $a[$i+1] -= $m;
  $b[$i] -= $m;
}
$ae = array_sum($a);

echo $ab - $ae;


?>

Measured memory_bytes: 20980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,ans;
int main()
{
	scanf("%lld",&n);
	ans=(n+1)*n/2;
	if(n/3) ans-=3*(1+n/3)*(n/3)/2;
    if(n/5) ans-=5*(1+n/5)*(n/5)/2;
    if(n/15) ans+=15*(1+n/15)*(n/15)/2;
    printf("%lld",ans);
}

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

int main()
{
	long i, N, x[100001], y[100001], t[100001];
	scanf("%ld", &N);
	for (i = 1; i <= N; i++) scanf("%ld %ld %ld", &(t[i]), &(x[i]), &(y[i]));
	x[0] = 0;
	y[0] = 0;
	t[0] = 0;
	
	long d;
	for (i = 1; i <= N; i++) {
		d = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
		if (d > t[i] - t[i-1] || (d + t[i] + t[i-1]) % 2 == 1) break;
	}
	
	if (i == N + 1) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

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

int main() {
    long long n, m;
    cin >> n >> m;
    if (n>=3 && m>=3) cout << (n-2ll)*(m-2ll) << endl;
    else if ((n>=3 || m>=3) && (n==1 || m==1)) cout << n*m-2 << endl;
    else if (n*m == 1) cout << 1 << endl;
    else cout << 0 << endl;
}

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

int main() {
  int n;
  cin>>n;
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  int res=0;
  int count=0;
  for(int i=0;i<n;i++){
    if(i==0){
      if(a[1]!=a[0]) res++;
      else count++;
    }
    else if(i==n-1) {
      if(count%2==0) res++;
      else break;
    }
    else {
      if(a[i]!=a[i+1]){
        if(count%2==0){
          count=0;
          res++;
        }
        else count=0;
      }
      else count++;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>


#define MAX 101
#define WHITE 2
#define GRAY 1
#define BLACK 0

int col[MAX], d[MAX], a[MAX][MAX]; 
 
int n, h= 0, t = 0;


int Que[MAX];


/*Qの操作*/
 int Dequeque(){
  h++;
  return Que[h - 1];
}
void Enqueque(int b){
  Que[t] = b;
  t++;
}

 
void BFS(int s){
  int i, u;
  for(i = 1; i < n+1; i++){
      col[i] = WHITE;


      d[i] = -1;
  }
  d[s] = 0;
  

  col[s] = GRAY;
  
  Enqueque(s);
 
  while(h != t){
    u = Dequeque();
    for(i = 1; i <= n; i++){
      if((col[i] == WHITE) && (a[u][i] == 1)){


    col[i] = GRAY;
    d[i] = d[u] + 1;
    Enqueque(i);
      }
    }
   

    col[u] = BLACK;
  }
}
 

  
int main(){
 
  scanf("%d", &n);
 
  int i, u, j,y=1,e;



  /*配列の初期化*/
  for(i = 1; i < n+1; i++){
    for(j = 1; j < n+1; j++){
     

 a[i][j] = 0;

    }
  }

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

    scanf("%d%d",&u,&e);
    for(j = 1; j <= e; j++){
      scanf("%d", &x);
      a[i][x] = 1;
    }
  }
 
  BFS(y);
   
  for(i = 1; i < n+1; i++){
    printf("%d ", i);
    printf("%d\n", d[i]);
  }
  return 0;
}

Measured memory_bytes: 1064
//Code By CXY07
#include<bits/stdc++.h>
using namespace std;

//#define int long long

const int MAXN = 1;
const int INF = 2e9;
const int mod = 1e9 + 7;

int n,m;

signed main () {
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int[] a = new int[26];
        for (int i = 0; i < s.length(); i++) {
            a[s.charAt(i) - 'a']++;
        }
        boolean flag = true;
        for (int i = 0; i < 26; i++) {
            if(a[i] % 2 != 0){
                flag = false;
                break;
            }
        }
        if(flag)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 26812
from scipy.sparse.csgraph import csgraph_from_dense,floyd_warshall

h,w = map(int, input().split())
s = [input() for _ in range(h) ]

d = [[10**9] * (w*h) for _ in range(w*h)]

for i in range(h):
    for j in range(w):
        if(s[i][j] == '.'):
            if(i != h-1):
                if(s[i+1][j] == '.'):
                    d[(i*w + j)][((i+1)*w + j)] = 1
                    d[((i+1)*w + j)][(i*w + j)] = 1
            if(j != w-1):
                if(s[i][j+1] == '.'):
                    d[(i*w + j)][(i*w + j + 1)] = 1
                    d[(i*w + j + 1)][(i*w + j)] = 1

G = csgraph_from_dense(d, null_value=10**9)
len = floyd_warshall(G)

ans = 0
for i in range(h*w):
    for j in range(h*w):
        if(len[i][j] < 1000000):
            ans = max(len[i][j], ans)

print(int(ans))

Measured memory_bytes: 20936
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

vi G[100010];

int depth[100010];
int par[100010][22];

void lca_dfs(int v, int p, int d)
{
    depth[v] = d;
    par[v][0] = p;

    for (int ch : G[v]) {
        if (ch == p) continue;
        lca_dfs(ch, v, d + 1);
    }
}

void lca_init(int root = 0)
{
    lca_dfs(root, -1, 0);

    rep(i, 20) {
        rep(j, 100010) {
            par[j][i + 1] = par[j][i] == -1 ? -1 : par[par[j][i]][i];
        }
    }
}

int lca(int u, int v)
{
    if (depth[u] > depth[v]) swap(u, v);

    int diff = depth[v] - depth[u];

    rep(i, 20) {
        if (diff >> i & 1) v = par[v][i];
    }

    if (u == v) return u;

    rrep(i, 20) {
        if (par[u][i] != par[v][i]) {
            u = par[u][i];
            v = par[v][i];
        }
    }

    return par[u][0];
}

int main()
{
    int n = in();

    rep(i, n) {
        int k = in();

        rep(j, k) {
            int c = in();

            G[i].PB(c);
            G[c].PB(i);
        }
    }

    lca_init();

    int q = in();

    rep(_, q) {
        int u = in(), v = in();

        printf("%d\n", lca(u, v));
    }
}

Measured memory_bytes: 22376
x = "T"+input()+"S"
ans = len(x)-2
s = t = 0
for i in x:
    if i=="S":
        ans -= min(s,t)*2
        if s>t:
            s -= t
            t = 0
        else: t = s = 0
        s += 1
    else: t += 1
print(ans)

Measured memory_bytes: 3500
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,k=INPUT()
A=INPUT()
accepted=[]
for i in range(10):
    if i not in A:
        accepted.append(i)
L=len(accepted)
#print(accepted)
ans=n
i=0
p=len(str(ans))
while(i<p):
    if int(str(ans)[i]) in accepted:
        #print(str(ans))
        i+=1
    else:
        ans+=1
        i=0
    p=len(str(ans))
print(ans)


Measured memory_bytes: 40812
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong();
   long B = sc.nextLong();
   long K = sc.nextLong();
   long st = 0;
   
   if(A>K)
   {
     A-=K;
   }
   else
   {
     K-=A;
     A=0;
     if(K<B)
     {
       B-=K;
     }
     else
     {
       B=0;
     }
   }
   System.out.println(A+" "+B);
 }
}

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

int main() {
  string str;
  cin >> str;
  
  int ans = 0;
  
  for(int i = 0; i < 4; i++) {
    if(str.at(i) == '+') {
      ans++;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int parent,left,right;};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL)return ;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left != NIL)h1=setHeight(T[u].left)+1;
  if(T[u].right != NIL)h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2 ? h1:h2);
}

int getSibling(int u){
  if(T[u].parent == NIL)return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].parent,getSibling(u));
  int deg=0;
  if(T[u].left != NIL)deg++;
  if(T[u].right != NIL)deg++;
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
  if(T[u].parent == NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right == NIL)printf("leaf\n");
  else printf("internal node\n");
}

int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);

  for(i=0;i<n;i++)T[i].parent=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l != NIL)T[l].parent=v;
    if(r != NIL)T[r].parent=v;
  }
  for(i=0;i<n;i++)if(T[i].parent == NIL)root=i;

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++)print(i);
  
  return 0;
}




Measured memory_bytes: 2100
N=int(input())
for i in range(N):
    i = i + 1
    for j in range(N-i):
        j = i+j+1
        for k in range(9):
            if i % (2**(k+1)) != j % (2**(k+1)):
                print(k+1, end=" ")
                break
    print()


Measured memory_bytes: 55000
#include <cstdio>
#include <cstring>
int main() {
	char str[11],ring[21];
	int N,ring_size,ans=0;
	scanf("%s",str);
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		memset(ring,0,sizeof(ring));
		scanf("%s",ring);
		ring_size=strlen(ring);
		for(int i=0;i<ring_size;i++) {
			ring[i+ring_size]=ring[i];
		}
		if(strstr(ring,str)!=NULL) ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1032
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    int n;
    cin >> n;

    int arr1[n], arr2[n];

    char a1[n], a2[n];

    for(int i = 0; i < n; i++){
        cin >> a1[i];
        arr1[i] = a1[i] - '0';
    }

    for(int i = 0; i < n; i++){
        cin >> a2[i];
        arr2[i] = a2[i] - '0';
    }

    int myints[n];

    for(int i = 0; i < n; i++) myints[i] = i + 1;

    int cnt1 = 0, cnt2 = 0;

    do {
        int cnt3 = 0;
        for(int i = 0; i < n; i++){
            if(myints[i] == arr1[i]) cnt3++;
        }
        if(cnt3 == n) break;
        cnt1++;
    } while ( std::next_permutation(myints,myints + n) );

    sort(myints, myints + n);

    do {
        int cnt3 = 0;
        for(int i = 0; i < n; i++){
            if(myints[i] == arr2[i]) cnt3++;
        }
        if(cnt3 == n) break;
        cnt2++;
    } while ( std::next_permutation(myints,myints + n) );

    cout << abs(cnt1 - cnt2);
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  LL n,h;
  cin >> n >> h;
  vector<LL> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  sort(a.begin(),a.end(),greater<LL>());
  sort(b.begin(),b.end(),greater<LL>());
  int total=0,count=0;
  for(int i=0;b[i]>a[0]&&i<n&&h>0;i++){
    total+=b[i];
    count++;
    h-=b[i];
  }
  count+=max(0,(h+a[0]-1)/a[0]);
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cctype>

int main() {
   char ch;
   while(1) {
        scanf("%c", &ch);
        if ( isalpha(ch) ) {
            if ( islower(ch) ) printf( "%c", toupper(ch) );
            else               printf( "%c", tolower(ch) );
        } else {
            printf("%c", ch);
        }
        if ( ch == '\n' ) break;
   }
   return 0;
}

Measured memory_bytes: 2540
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    int ans = 700;
    cin >> s;
    for(int i = 0;i < 3;i++){
        if(s[i] == 'o'){
            ans = ans + 100;
        }else if(s[i] == 'x'){
            ans = ans + 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func getScanner(fp io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 500001), 500000)
	return sc
}

func getHugeScanner(fp io.Reader, size int) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, size), size)
	return sc
}

func getNextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func getNextInt(sc *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(sc))
	return i
}

func getNextInt64(sc *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(sc), 10, 64)
	return i
}
func getNextFloat64(sc *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(sc), 64)
	return i
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := getScanner(stdin)

	n := getNextInt(sc)

	a := make([]int, n + 1)
	b := make([]int, n + 1)

	for i := 1; i <= n; i++ {
		a[i] = getNextInt(sc)
	}

	for i := n; i > 0; i-- {
		sum := 0
		for j := i + i; j <= n; j += i {
			sum ^= b[j]
		}
		b[i] = sum ^ a[i]
	}

	ret := make([]int, 0)

	for i := 1; i <= n; i++ {
		if b[i] > 0 {
			ret = append(ret, i)
		}
	}

	_, _ = fmt.Fprintf(stdout, "%v\n", len(ret))
	for _, v := range ret {
		_, _ = fmt.Fprintf(stdout, "%v ", v)
	}
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

Measured memory_bytes: 7936
import java.util.*;
public 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();

      if(Math.abs(A - C) <= D || Math.abs(A - B) <= D && Math.abs(C - B) <= D){
      	System.out.println("Yes");
      }else {
        System.out.println("No");
      }
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
struct Point {
	int x, y;
};
int w, h;
string s[60];
bool check[60][10];

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

bool stable(const int x, const int y, const char c, int* Msum, int* bSum) {
	int M = 2;
	int blockNum = 4;
	int XL = 100, XR = -100;
	queue<Point> q;
	q.push(Point{ x, y });
	while(!q.empty()) {
		Point p = q.front();
		q.pop();
		if(check[p.y][p.x]) continue;
		check[p.y][p.x] = true;
		M += p.x;
		if(p.y == h - 1 || s[p.y + 1][p.x] != '.' && s[p.y + 1][p.x] != c) {
			XL = min(XL, p.x);
			XR = max(XR, p.x + 1);
		}
		if(p.y != 0 && !check[p.y - 1][p.x] && s[p.y - 1][p.x] != '.' && s[p.y - 1][p.x] != c) {
			if(!stable(p.x, p.y - 1, s[p.y - 1][p.x], &M, &blockNum)) return false;
		}
		for(int k = 0; k < 4; k++) {
			int nx = p.x + dx[k], ny = p.y + dy[k];
			if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if(check[ny][nx]) continue;
			if(s[ny][nx] != c) continue;
			q.push(Point{ nx, ny });
		}
	}

	*Msum += M;
	*bSum += blockNum;
	return XL < double(M) / blockNum && double(M) / blockNum < XR;
}

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

	while(cin >> w >> h, w | h) {
		for(int i = 0; i < h; i++) {
			cin >> s[i];
		}

		int m, b;
		memset(check, false, sizeof check);
		for(int j = 0; j < w; j++) {
			if(s[h - 1][j] != '.') {
				bool res = stable(j, h - 1, s[h - 1][j], &m, &b);
				if(res) {
					cout << "STABLE" << endl;
				}
				else {
					cout << "UNSTABLE" << endl;
				}
				break;
			}
		}
	}
}

Measured memory_bytes: 1240
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>


using namespace std;
typedef long long ll;

#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 10010

struct DEC{
    
    int num[SIZE+2];
    
    void add_reciprocal(int a){
        int b = 1;
        
        for(int i=0;i<SIZE;i++){
            num[i]+=b/a;
            b-=(b/a)*a;
            b*=10;
        }
        
        for(int i=SIZE-1;i>=1;i--){
            if(num[i]>=10){
                num[i-1]++;
                num[i]-=10;
            }
        }
    }
    
    DEC(){
        for(int i=0;i<SIZE+2;i++){
            num[i] = 0;
        }
    }
    
};


int main(){
    int n,k,m,r;
    
    while(1){
        DEC ans;
        
        scanf("%d%d%d%d",&n,&k,&m,&r);
        
        if(n==0) break;
        
        ans.add_reciprocal(n);
        
        if(m==1){
            for(int i=1;i<n;i++){
                ans.add_reciprocal(n*i);
            }
        }
        
        
        printf("%d.",ans.num[0]);
        
        for(int i=1;i<=r;i++){
            printf("%d",ans.num[i]);
        }
        
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


VS rot( VS L ) {
    VS res = L;
    for ( int i = 0; i < 8; ++ i ) {
        for ( int j = 0; j < 8; ++ j ) {
            res[j][7-i] = L[i][j];
        }
    }
    return res;
}

void print( VS L ) {
    for ( int i = 0; i < 8; ++ i ) {
        cout << L[i] << endl;
    }
}

int main() {
    VS L(8);
    for ( int i = 0; i < 8; ++ i ) {
        cin >> L[i];
    }
    cout << 90 << endl;
    print( rot( L ) );
    cout << 180 << endl;
    print( rot( rot( L ) ) );
    cout << 270 << endl;
    print( rot( rot( rot( L ) ) ) );
    return 0;
}

Measured memory_bytes: 0
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T square(T a) {
    return a * a;
}


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */


/* ---------- Functions ---------- */

ll calc_gcd(ll a, ll b) {
    if (a < b) {
        return calc_gcd(b, a);
    }

    if (a % b > 0) {
        return calc_gcd(b, a % b);
    } else {
        return b;
    }
}

/* ---------- Main Function ---------- */

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

    ll N, K;
    cin >> N >> K;

    ll gcd;
    cin >> gcd;

    ll max_A = gcd;

    REP(i, N - 1) {
        ll A;
        cin >> A;
        gcd = calc_gcd(gcd, A);
        max_A = max(max_A, A);
    }

    if (K % gcd == 0 && K <= max_A) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2e5+10;
ll a[N],vis[N],r[N],tot=0;
int main()
{
    ll n;
    cin>>n;
    memset(vis,0,sizeof(vis));
    for(ll i=0;i<n;i++){
        scanf("%lld",a+i);
        vis[a[i]]++;
        if(vis[a[i]]==2) r[tot++]=a[i];
    }
    ll ans=0;
    for(int i=0;i<tot;i++) ans+=vis[r[i]]*(vis[r[i]]-1)/2;
    for(int i=0;i<n;i++){
        if(vis[a[i]]==1) printf("%lld\n",ans);
        else if(vis[a[i]]==2) printf("%lld\n",ans-1);
        else printf("%lld\n",ans-(vis[a[i]]*(vis[a[i]]-1)/2)+((vis[a[i]]-2)*(vis[a[i]]-1)/2));
    }
    return 0;
}


Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

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

const ll INF = 1e9;
/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    int dp[50];
    dp[0] = 1;
    dp[1] = 1;

    for (int i = 2;i <= n;i++){
        dp[i] = dp[i-1] + dp[i-2];
    }

    cout << dp[n] << endl;

}


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

using namespace std;

struct xyz {
	int l;
	int r;
};

int main() {
	int n, q;
	cin >> n >> q;
	
	string s;
	cin >> s;
	
	vector<xyz> v(q);
	for(int i = 0; i < q; i++) {
		cin >> v[i].l >> v[i].r;
	}
	
	vector<int> index(n, 0);
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		index[i] = cnt;
		
		if(i < n - 1 && s[i] == 'A') {
			if(s[i + 1] == 'C') {
				cnt++;
			}
		}
	}
	
	for(int i = 0; i < q; i++) {
		int ans = index[v[i].r - 1] - index[v[i].l - 1];
		cout << ans << endl;
	}
	
	return 0;
}

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

#define ll long long int 
ll mod=1e9+7;

// vector<int> g[200005];
// int vis[200005];
// queue<int> q;
// int level[200005];

// void dfs(int i)
// {
//     vis[i] = 1;
//     for(int j=0;j<g[i].size();j++)
//     {
//         int child = g[i][j];
//         if(vis[child] == 0)
//         {
//             dfs(child);
//         }
//     }
// }

// void bfs(int i)
// {
//     vis[i] = 1;
//     while(!q.empty())
//     {
//         int top = q.front();
//         int len_adj = g[top].size();
//         int j;
//         for(j=0;j<len_adj;j++)
//         {
//             int v = g[top][j];
//             if(vis[v]==0)
//             {
//                 vis[v]=1;
//                 q.push(v);
//                 level[v] = level[top] + 1;
//             }
//         }   
//         q.pop();
//     }
// }

ll modular_exponentiation(ll base, ll power)
{
    ll ans = 1;
    base = base % mod;
    while (power > 0)
    {
        if (power & 1)
        {
            ans = (ans * base) % mod;
        }

        power /= 2;
        base = (base * base) % mod;
    }
    return ans;
}

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    int t = 1;
    // cin >> t;
    while(t--)
    {        
        double a,b,n,i,j;
        cin >> a >> b >> n;
        double ans = 0;
        
        if(n <= b)
        {
            if(n == b)
            {
                ans = floor((a*(n-1))/b) - a * floor((n-(double)1)/b);
            }
            else
            {
                ans = floor((a*(n))/b) - a * floor(n/b);
            }   
        }
        else
        {
            double quo = floor(n/b);
            // cout << quo << '\n';
            double x = (quo) * (b) - (double)1;
            // cout << x << '\n';
            ans = floor((a*(x))/b) - a * floor(x/b);
        }

        cout << (long long)ans << '\n';
    }

    
    
}

Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int size = 1005;

void prepare(vector<vector<int>>& a, vector<vector<int>>& prefix, int n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                prefix[i][j] = a[i][j];
                if (i > 0) {
                    prefix[i][j] += prefix[i - 1][j];
                }
                if (j > 0) {
                    prefix[i][j] += prefix[i][j - 1];
                }
                if (i > 0 && j > 0) {
                    prefix[i][j] -= prefix[i - 1][j - 1];
                }
            }
        }
    }

int main() {
    int n;
    cin >> n;
    vector<vector<int>> matrix(size, vector<int>(size, 0));
    
    for (int i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        matrix[x1][y1]++;
        matrix[x1][y2]--;
        matrix[x2][y1]--;
        matrix[x2][y2]++;
    }
    
    vector<vector<int>> sum(size, vector<int>(size, 0));
    
    prepare(matrix, sum, size);
    
    int ans = 0;
    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
            ans = max(ans, sum[i][j]);
        } 
    }
    
    cout << ans << endl;
    
    return 0;
}

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

#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=1e5+5;
int a[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n,l;
	cin>>n>>l;
	rep(i,1,n)scanf("%d",a+i);
	rep(i,1,n-1)
	if(a[i]+a[i+1]>=l)
	{
		puts("Possible");
		rep(j,1,i-1)printf("%d\n",j);
		per(j,n-1,i+1)printf("%d\n",j);
		printf("%d\n",i);
		exit(0);
	}
	puts("Impossible");
}

Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main() {
    int j,A,B,C;
    cin >> A>>B>>C; 
    
    
        j=A-B;
    C= C-j;
   
        if (C>0)
    {
    cout << C;
    }
    
    
    else
{ cout <<0;
    }

}

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

int main()
{
    cin >> N;
    vector<pair<pair<string, int>, int>> rest(N);
    string s;
    int a;
    rep(i, 0, N)
    {
        cin >> s >> a;
        rest[i].first = make_pair(s, -a);
        rest[i].second = i;
    }
    sort(rest.begin(), rest.end());
    rep(i, 0, N)
    {
        cout << rest[i].second + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n+1]={0},b[n+1]={0};
	for(int i = 1; i<=n; i++) cin>>a[i], a[i]+=a[i-1];
	for(int i = 1; i<= n; i++) cin>>b[i], b[i]+=b[i-1];
	int ans = 0;
	for(int i= 1; i<=n; i++) ans = max(ans,a[i]+b[n]-b[i-1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace _2738
{
    class Program
    {
        static void Main(string[] args)
        {
            int A = 0;
            int Un = 0;
            int n = int.Parse(Console.ReadLine());
            bool output = true;
            string s = "";
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine();   
                if (s == "A")
                {
                    A++;
                }
                else
                {
                    Un++;
                }
                if (A < Un)
                {
                    output = false;
                }
            }
            if (A != Un)
            {
                output = false;
            }
            Console.WriteLine(output ? "YES" : "NO");
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 8964
// D - Binomial Coefficients
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vi A(N); rpz(i, N) cin>>A[i];
	sort(all(A));
	int n = A[N-1], r = 0;
	int mindiff = INT_MAX;
	rpz(i, N-1){
		int diff = abs(n - 2*A[i]);// |n - 2*ai|
		if(mindiff > diff){
			mindiff = diff;
			r = A[i];
		}
	}
	cout<< n <<" "<< r <<endl;
}

Measured memory_bytes: 640
// AtCoder ABC126: A - Changing a Character
// 2019.9.8 bal4u

#include <stdio.h>

int main()
{
	int N, K;
	char S[55];
	
	scanf("%d%d%s", &N, &K, S);
	S[K-1] += 'a'-'A';
	puts(S);
	return 0;
}


Measured memory_bytes: 128
N = int(input())
list = list(map(int,input().split(" ")))

t = 1
ans=0

if 1 not in list:
    print(-1)
    exit()

for i in range(N):
    if list[i]==t:
        t+=1
    else:
        ans+=1

if t==ans:
    print(ans-1)

else:
    print(ans)

Measured memory_bytes: 24872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

/////////////////////////////////////////////////////////

void Main() {
  ll N, A, B; cin >> N >> A >> B;
  if(A > B){
    cout << 0 << endl;
    return;
  }
  if(A != B && N == 1){
    cout << 0 << endl;
    return;
  }
  cout << (B * (N - 1) + A) -  (A * (N - 1) + B) + 1 << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#define INF 2147483647
#define lli long long int

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

bool check(vector<string> &str1,vector<string> &str2,int x,int y){
	for (int i = y; i < str2.size() + y; i++){
		for (int j = x; j < str2.size() + x; j++){
			if (str1[i][j] != str2[i-y][j-x]){
				return false;
			}
		}
	}
	return true;
	
}


int main() {
	int n,m; cin >> n >> m;
	vector<string> str1(n);
	vector<string> str2(m);
	for (int i = 0; i < n; i++){
		cin >> str1[i];	
	}

	for (int i = 0; i < m ; i++){
		cin >> str2[i];	
	}

	for (int i = 0; i < str1.size() - str2.size() + 1; i++){
		for (int j = 0; j < str1.size() - str2.size() + 1; j++){
			if (check(str1,str2,i,j)){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}





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

  int n, k; rd(n, k);
  auto a=new long[n];
  auto b=new long[n];
  foreach(i; 0..n) rd(a[i], b[i]);

  long mx=0;
  foreach(pos; 0..32){
    long vsum=0;
    if(k&(1<<pos))foreach(i; 0..n){
      if(a[i]&(1<<pos)) continue;
      bool ok=true;
      foreach(j; (pos+1)..32){
        ok &= (((k&(1<<j)) | (a[i]&(1<<j))) == (k&(1<<j))); 
      }
      if(ok) vsum+=b[i];
    }
    mx=max(mx, vsum);
  }

  long mx2=0;
  foreach(i; 0..n){
    bool ok=true;
    foreach(j; 0..32){
      ok &= (((k&(1<<j)) | (a[i]&(1<<j))) == (k&(1<<j)));
    }
    if(ok) mx2+=b[i];
  }

  writeln(max(mx, mx2));
}


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

Measured memory_bytes: 4860
#include<bits/stdc++.h>
using namespace std;
int main(){
	string h;
  int ans=0;
  cin>>h;
  if(h.size()==1){puts("0");return 0;}
  for(int j=0,k=h.size()-1;j<=(h.size())/2,k>=(h.size())/2;j++,k--)if(h[j]!=h[k])ans++;
  cout<<ans<<'\n';
  return 0;
}

Measured memory_bytes: 256
#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; }
//---------------------------------------------------------------------------------------------------
struct StringMaster {
    string S; int N; StringMaster() {}StringMaster(string s) { init(s); }
    void init(string s) { S = s; N = S.length(); initgo(); }

    // get the nearest index for the char
    vector<int> hidari[26], migi[26];
    inline void initgo() {
        rep(c, 0, 26) { migi[c].resize(N); migi[c][N - 1] = inf; }
        rrep(i, N - 2, 0) { rep(c, 0, 26) migi[c][i] = migi[c][i + 1]; migi[S[i + 1]][i] = i + 1; }
        rep(c, 0, 26) { hidari[c].resize(N); hidari[c][0] = -1; }
        rep(i, 1, N) { rep(c, 0, 26) hidari[c][i] = hidari[c][i - 1]; hidari[S[i - 1]][i] = i - 1; }
    }
    inline int gomigi(int cu, int c) { 
		if (cu == inf) return inf;
		if (cu < 0) {
			if (S[0] == c) return 0;
			cu = 0;
		}
		return migi[c][cu];
	}
    inline int gohidari(int cu, int c) {
		if (cu < 0) return cu;
		return hidari[c][cu];
	}
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;

	fore(c, S) c -= '0';
	StringMaster sm(S);

	int ans = 0;
	rep(x0, 0, 10) rep(x1, 0, 10) rep(x2, 0, 10) {
		int cu = -1;
		cu = sm.gomigi(cu, x0);
		cu = sm.gomigi(cu, x1);
		cu = sm.gomigi(cu, x2);
		if (cu < inf) ans++;
	}
	cout << ans << endl;
}







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

int main() {
	int n;
	cin >> n;
	int x[n], y[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	copy(x, x + n, y);
	sort(y, y + n);

	for (int i = 0; i < n; i++)
		cout << (x[i] > y[n / 2 - 1] ? y[n / 2 - 1] : y[n / 2]) << endl;

}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

int main(){
	string S;
	cin>>S;
	long long cnt = 0;
	int W_cnt = 0;
	for(int i=0;i<S.size();i++){
		if(S[i]=='W'){
			cnt+=i-W_cnt;
			W_cnt++;
		}
	}
	cout<<cnt<<endl;
	
	return 0;
}


Measured memory_bytes: 640
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<climits>
#include<iostream>
#include<map>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << (n + 1) / 2 << endl;
    return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun sum(N: Int, C: Int, S: BooleanArray): IntArray {
        val L = IntArray(N)
        var n = 0
        var i = 0
        while (i < N) {
            if (S[i]) {
                n++
                for (j in 0 until C) {
                    L[i] = n
                    i++
                    if (i >= N - 1) return L
                }
            }
            L[i] = n
            i++
        }
        return L
    }

    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val K = sc.next().toInt()
        val C = sc.next().toInt()
        val S = sc.next().map { it == 'o' }

        val L = sum(N, C, S.toBooleanArray())
        val R = sum(N, C, S.reversed().toBooleanArray()).reversed().toIntArray()

        for (i in 0 until N) {
            val l = if (i > 0) L[i - 1] else 0
            val r = if (i + 1 < N) R[i + 1] else 0
            if (l + r < K) {
                pw.println(i + 1)
            }
        }
    }
}


Measured memory_bytes: 51308
Module Program
  Sub Main
    Dim s = GetInts()
    Dim a=s(0)
    Dim ans=If(a<1200,"ABC",If(a<2800,"ARC","AGC"))
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string str;
    cin >> str;
    reverse(all(str));
    str += '0';
    int len = str.size();

    vector<vector<int>> dp(len, vector<int>(2, 0));

    REP(i, len) {
        int d = str[i] - '0';
        if(i == 0) {
            dp[i][0] = d;
            dp[i][1] = 10 - d;
            continue;
        }
        dp[i][0] = min(dp[i-1][0] + d, dp[i-1][1] + d + 1);
        dp[i][1] = min(dp[i-1][0] + 10 - d, dp[i-1][1] + 10 - d - 1);
    }

    cout << min(dp[len-1][0], dp[len-1][1]) << endl;

    return 0;
}


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

int main() {
    std::vector<int> a(3);
    std::cin >> a[0] >> a[1] >> a[2];
    std::sort(a.begin(), a.end());
    std::cout << a[0] + a[1] + a[2] * 10 << std::endl;

    return 0;
}

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

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(a[i]==0){
            cout << 0 << "\n";
            return 0;
        }
    }
    long long ans=a[0];
    for(int i=1; i<n; ++i){
        if((ll)1e18/ans < a[i]){
            cout << -1 << "\n";
            return 0;
        }
        ans*=a[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4056