akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
bool is_prime(int x){
  if(x<=1) return false;
  for(int i=2;i*i<=x;i++)
  if(x%i==0) return false;
  return true;
}
int main() {
  int n;
  cin>>n;
  vector<int>a;
  for(int i=2;i<=n;i++){
    if(is_prime(i))a.push_back(i);
  }
  int kotae=0;
  if(a.size()<=3){
    cout<<0<<endl;
    return 0;
  }
  for(int i=0;i<a.size()-2;i++){
    for(int j=i+1;j<a.size()-1;j++){
      for(int k=j+1;k<a.size();k++){
        //cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
        if(a[i]*a[j]*a[k]%2==1&&n>=a[i]*a[j]*a[k]){
          //cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
          kotae++;
        }
      }
    }
  }
  for(int i=0;i<a.size()-1;i++){
    for(int j=i+1;j<a.size();j++){
      if(a[i]*a[i]*a[i]*a[j]%2==1&&n>=a[i]*a[i]*a[i]*a[j]){
        //cout<<a[i]<<" "<<a[j]<<endl;
        kotae++;
      }
    }
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3504
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e3 + 10, mod = 1e9 + 7;

int a[N], b[N];

int main() {
	fast_cin();
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> b[i];
	}
	sort(a, a + n, greater<int>());
	sort(b, b + m, greater<int>());
	int nr = 0, nc = 0, free = 0;
	ll ans = 1;
	for (int i = n * m; i >= 1; --i) {
		if (i == a[nr] and i == b[nc]) {
			free += nr + nc;
			++nr; ++nc;
		} else if (i == a[nr]) {
			ans *= nc;
			free += nc - 1;
			++nr;
		} else if (i == b[nc]) {
			ans *= nr;
			free += nr - 1;
			++nc;
		} else {
			ans *= free;
			--free;
		}
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
a = N * (N + 1) // 2
b = (N // 3) * (3 + 3 * (N // 3)) // 2
c = (N // 5) * (5 + 5 * (N // 5)) // 2
d = (N // 15) * (15 + 15 * (N // 15)) // 2
print(a-b-c+d)


Measured memory_bytes: 9180
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        long N = sc.nextLong();
        int ans = 0;
        long originN = N;
        int sqrtN = (int)Math.sqrt(N);
        for(int i = 2; i < sqrtN; i += 2) {

            int e = 0;
            while(N % i == 0) {
                N /= i;
                e++;
            }

            int t = 1;
            while (e >= t) {
                ans++;
                e -= t;
                t++;
            }

            if (i == 2)
                i = 1;
        }
        if(N != 1 && originN % N == 0)
            ans++;

        os.println(ans);
    }
}

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

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

// BFSで最短経路を求められる
// https://atcoder.jp/contests/abc088/tasks/abc088_d
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int H,W; cin >> H >> W;

  vector<string> M(H);
  int white = 0;

  rep(h, H) {
    cin >> M[h];
    rep(w, W) {
      if(M[h][w] == '.') white++;
    }
  }

  vector<vector<int>> D(H, vector<int>(W, -1));
  D[0][0] = 0;

  queue<pair<int,int>> Q;
  Q.push(make_pair(0, 0));

  while(!Q.empty()) {
    auto cur = Q.front(); Q.pop();
    rep(i, 4) {
      int nh = cur.first + dy[i];
      int nw = cur.second + dx[i];
      if(nh >= 0 && nh < H && nw >= 0 && nw < W && M[nh][nw] == '.') {
        if(D[nh][nw] != -1) continue;
        D[nh][nw] = D[cur.first][cur.second] + 1;
        Q.push(make_pair(nh, nw));
      }
    }
  }

  if(D[H-1][W-1] != -1) {
    cout << white - D[H-1][W-1] - 1 << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m,l,x,y;
	string s;
	while(cin>>n,n){
		int d[21][21]={};
		int f=0,dx=10,dy=10;
		for(int i=0;i<n;i++){
			cin>>x>>y;
			d[x][y]=1;
		}
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>s>>l;
			for(int j=0;j<l;j++){
				if(s=="N")
				dy++;
				if(s=="S")
				dy--;
				if(s=="E")
				dx++;
				if(s=="W")
				dx--;
				if(d[dx][dy]==1)
				d[dx][dy]=0;
			}
		}
		for(int i=0;i<=20;i++){
			for(int j=0;j<=20;j++){
				if(d[i][j]==1)
				f=1;
			}
		}
		if(f==1)
		cout<<"No"<<endl;
		else
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
string S;

void solve() {
    cin >> N >> S;
    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << endl;
    return;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	std::ios::sync_with_stdio(false);
	int t = 1;
	// cin >> t;
	while (t--) {
		int a, b, c;
		cin >> a >> b >> c;
		int ctr = 0;
		for (int i = a ; i <= b; i++) {
			if (i % c == 0)ctr++;
		}
		cout << ctr;
	}
	return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var n = inputs[0];
            var m = inputs[1];
            var l = inputs[2];

            var aVector = new long[n, m];
            var bVector = new long[m, l];
            var cVector = new long[n, l];

            for (int i = 0; i < n; i++)
            {
                int[] oneLine = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < m; j++)
                {
                    aVector[i, j] = oneLine[j];
                }
            }

            for (int i = 0; i < m; i++)
            {
                var oneLine = Console.ReadLine().Split().Select(int.Parse).ToList();
                for (int j = 0; j < l; j++)
                {
                    bVector[i, j] = oneLine[j];
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    for (int k = 0; k < m; k++)
                    {
                        cVector[i, j] += aVector[i, k] * bVector[k, j];
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                var list = new List<long>();
                for (int j = 0; j < l; j++)
                {
                    list.Add(cVector[i, j]);
                }
                Console.WriteLine($"{string.Join(" ", list)}");
            }
        }
    }
}



Measured memory_bytes: 20480
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  cin>>k;
  int a,b,con=0;
  cin>>a>>b;
  for(int i=a;i<=b;i++)
  {
    if(i%k==0)
    {
      con++;
    }
  }
  if(con>0)
  {
    cout<<"OK"<<endl;
  }
  else
    
  {
    cout<<"NG"<<endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    string s; cin>>s;
    int w; cin>>w;
    for(int i=0;i<(int)s.size();i+=w){
        cout<<s[i];
    }
    cout<<endl;
	return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  int cnt_0 = 0, cnt_1 = 0;
  for (auto ch : s) {
    if (ch == '0') {
      cnt_0++;
    } else {
      cnt_1++;
    }
  }

  cout << min(cnt_0, cnt_1) * 2 << '\n';
  return 0;
}

Measured memory_bytes: 512
var cc : ansistring ;
    a,b,c : longint ;
begin
 readln(cc);
  b:=1;
 for a:=length(cc) downto 1 do
  begin
   if cc[a]<>cc[b] then
    begin
    c:=1;
    break;
    end
   else
    b:=b+1;
  end;
 if c=0 then
  writeln('Yes')
 else
  writeln('No');
end.


Measured memory_bytes: 128
#include <algorithm>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int Q;
  cin >> Q;

  deque<char> head;
  deque<char> tail;
  bool rev = false;
  rep(i, Q) {
    int T;
    cin >> T;
    if (T == 1) {
      rev = !rev;
    } else {
      int F;
      char C;
      cin >> F >> C;
      if (F == 1) {
        if (rev)
          tail.emplace_back(C);
        else
          head.emplace_front(C);
      } else {
        if (rev)
          head.emplace_front(C);
        else
          tail.emplace_back(C);
      }
    }
  }

  string answer;
  for (auto c : head) answer += c;
  for (auto c : S) answer += c;
  for (auto c : tail) answer += c;
  if (rev) reverse(answer.begin(), answer.end());
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;


int H, W;
set<ll> memo[20][20][4];
int id[20][20];
char field[20][20];
const string dirs = "ULDR";

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

inline bool inside(int r, int c){
  return 0 <= r && r < H && 0 <= c && c < W;
}

bool calc(string &res, ll mask, int r, int c, int dir,int pos){
  if(__builtin_popcountll(mask) == 0) return true;
  assert(pos < (int)res.size());
  
  for(int i = -1; i <= 1; i++){
    int ndir = (dir + i + 4) % 4;
    int nr = r;
    int nc = c;
    while(inside(nr, nc)){
      if(id[nr][nc] >= 0 && PARITY(mask >> id[nr][nc]) == 1){
	break;
      }
      nr += dr[ndir];
      nc += dc[ndir];
    }
    
    
    if(inside(nr, nc)){
      ll nmask = mask ^ (1LL << id[nr][nc]);
      if(memo[nr][nc][ndir].count(nmask)) continue;

      res[pos] = dirs[ndir];
      if(calc(res, nmask, nr, nc, ndir, pos + 1)) return true;
      memo[nr][nc][ndir].insert(nmask);
    }
  }
  return false;
}

int main(){
  cin >> H >> W;
  REP(i, H)REP(j, W) cin >> field[i][j];
  int r, c, dir, count = 0;
  memset(id, -1, sizeof(id));  
  
  REP(i, H)REP(j, W){
    if(field[i][j] == 'o'){
      id[i][j] = count++;
    }
    if(isupper(field[i][j])){
      r = i;
      c = j;
      dir = find(ALL(dirs), field[i][j]) - dirs.begin();
    }
  }
  string res(count, ' ');
  assert(calc(res, (1LL << count) - 1, r, c, dir, 0));
  cout << res << endl;
  
  return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while (x->left->key != NIL)
    x->key = x->left->key;
  return x;
}

Node treeMaximum(Node x){
while (x->right->key != NIL)
    x->key = x->right->key;
  return x;

}

Node treeSearch(Node u, int k){
  if((u->key == NIL)||(u->key == k))
    return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  
  if(x->right != NIL)
    return treeMinimum(x->right);

  y = x->parent;
  while ((y != NIL)&&(x==y->right)){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if (y == NIL)
    root = z;

  else if (z->key<y->key)
    y->left = z;
  else
    y->right = z;
}

void inorder(Node u){

  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);


  
}
void preorder(Node u){

  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25168
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        System.out.println(n-100*(n/100)+100*(10-(n/100))-n/10%10*10+(10-n/10%10)*10-n%10+(10-n%10));
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

int P, Q, A, N;

int dfs(double total, int Atotal, int xmax, int n){
    if(EQ(double(P)/Q, total)){
        return 1;
    }
    
    int res = 0;
    if(n == N)
        return res;
    
    for(int i=xmax; i*Atotal<=A; i++){
        if(total + 1.0/i > double(P)/Q + EPS)
            continue;
        
        res += dfs(total+1.0/i, Atotal*i, i, n+1);
    }
    return res;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    while(cin >> P >> Q >> A >> N, P|Q|A|N)
        cout << dfs(0, 1, 1, 0) << endl;
    
    return 0;
}

Measured memory_bytes: 3060
N,K = map(int,input().split())
inf = 10**9+7

def fact(a,b):
    tmp = 1
    for i in range(a,a-b,-1):
        tmp *= i
        #tmp = tmp%inf
    return tmp


def conv(a,b):
    if a-b > b:
        p1 = fact(a,b)
        p2 = fact(b,b)
    else:
        p1 = fact(a,a-b)
        p2 = fact(a-b,a-b)
    return p1//p2%inf

for i in range(1,K+1):
    if i-1 > N-K:
        print(0)
    else:
        print(int(conv(K-1,i-1)*conv(N-K+1,i))%inf)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int flag=0;
int main(){
  string S, T;
  cin >> S >> T;
  int L=S.size();
  for(int i=0; i<L; i++){
    char swa;  
    swa=S.at(0);
    for(int j=1; j<L; j++){
      S.at(j-1)=S.at(j);
    }
    S.at(L-1)=swa;
    if(S==T) flag++;
  }
  if(flag!=0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    int H, W;
    std::cin >> H >> W;

    boost::multi_array<bool, 2> mat(boost::extents[H][W]);
    for (auto p = mat.data(); p < (mat.origin() + mat.num_elements()); ++p) {
        char c;
        std::cin >> c;
        *p = (c == '#');
    }


    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W; ++w) {
            if (mat[h][w]) {
                bool ok = false;
                std::pair<int, int> dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
                for (auto d : dir) {
                    auto xx = w + d.first;
                    auto yy = h + d.second;
                    if (0 <= xx && xx < W && 0 <= yy && yy < H) {
                        if (mat[yy][xx]) {
                            ok = true;
                            break;
                        }
                    }
                }
                if (!ok) {
                    std::cout << "No" << std::endl;
                    return 0;
                }
            }
        }
    }
    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 256
l = raw_input().split()

N = int(l[0])
M = int(l[1])

strA = raw_input()
strB = raw_input()


#nmgcd = math.gcd(N,M)
nmgcd = N
eu = M

while eu:
	nmgcd, eu = eu, nmgcd % eu


nmlcm = (N*M)//nmgcd




itr = 0

for i in range(nmgcd):
    if strA[0+i*(nmlcm//M)] == strB[0+i*(nmlcm//N)]:
        itr = itr +1

if itr == nmgcd:
    print(nmlcm)
else:
    print(-1)




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

int main()
{
	string S;
  cin >> S;
  bool flag = false;
  
  for(int i = 0; i < S.size(); i++){
   if(i%2 == 0){
     if(S.at(i) == 'L'){
       flag = false;
       break;
     }	else {
       flag = true;
     }
   } else{
     if(S.at(i) == 'R'){
       flag = false;
       break;
     } else {
       flag = true;
     }
   }
  }    

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

Measured memory_bytes: 384
typedef long long ll;

#include <algorithm>
#include <numeric>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

ll a[100000];
vector<int> g[100000];

ll dfs(int pos, int prev = -1){
  if(g[pos].size() == 1){
    return a[pos];
  }else{
    vector<ll> v;

    REP(i,g[pos].size()){
      if(g[pos][i] == prev) continue;
      const ll t = dfs(g[pos][i], pos);
      if(t == -1) return -1;
      v.push_back(t);
    }

    const ll tot = accumulate(v.begin(), v.end(), 0ll);

    if(v.size() == 1) {
      if(v[0] != a[pos]) return -1;
      return a[pos];
    } else {
      // q = match; p = pass through
      // p + q = a
      // p + 2 * q = tot
      // -q = a - tot
      // q = tot - a
      // p = 2 * a - tot

      const ll p = 2 * a[pos] - tot;
      const ll q = tot - a[pos];

      if(p < 0 || q < 0) return -1;

      const ll mx = *max_element(v.begin(), v.end());
      // if((tot - p) / 2 < mx) return -1;
      if((tot - mx) < q) return -1;

      return p;
    }
  }
}

int main(){
  const int n = getInt();

  REP(i,n) a[i] = getInt();
  REP(i,n-1){
    const int p = getInt() - 1;
    const int q = getInt() - 1;
    g[p].push_back(q);
    g[q].push_back(p);
  }

  bool ans = true;
  if(n == 2){
    ans = a[0] == a[1];
  }else{
    REP(i,n){
      if(g[i].size() > 1){
        ans = dfs(i) == 0;
        break;
      }
    }
  }

  puts(ans ? "YES" : "NO");

  return 0;
}


Measured memory_bytes: 17152
# -*- coding:utf-8 -*-

def solve():
    import sys
    from collections import deque

    while True:
        W, H = map(int, sys.stdin.readline().split())
        if W==0 and H==0: break

        grid = []
        for i in range(H*2-1):
            _in = sys.stdin.readline().rstrip("\n")
            if i%2==0:
                _in += " "
            grid.append(list(_in))

        dist = [[0 for _ in range(W*2-1)] for __ in range(H*2-1)]
        dist[0][0] = 1
        que = deque([(0, 0)])

        while que:
            y, x = que.popleft()
            if grid[y][x] == "x": continue
            grid[y][x] = "x"

            if y==H*2-2 and x==W*2-2:
                # ゴールに到着できた
                break
            # for i in range(len(grid)):
            #     print(grid[i])
            # print()
            # input()

            for ny, nx, direct in ((y-1,x,"up"), (y+1,x,"down"), (y,x-1,"left"), (y,x+1,"right")):
                if ny==-1 or ny==(H*2-1) or nx==-1 or nx==(W*2-1): continue
                if grid[ny][nx] != "0": continue
                if direct=="up" and grid[ny-1][nx]!="x":
                    dist[ny-1][nx] = dist[y][x] + 1
                    que.append((ny-1, nx))
                elif direct=="down" and grid[ny+1][nx]!="x":
                    dist[ny+1][nx] = dist[y][x] + 1
                    que.append((ny+1, nx))
                elif direct=="left" and grid[ny][nx-1]!="x":
                    dist[ny][nx-1] = dist[y][x] + 1
                    que.append((ny, nx-1))
                elif direct=="right" and grid[ny][nx+1]!="x":
                    dist[ny][nx+1] = dist[y][x] + 1
                    que.append((ny, nx+1))

        print(dist[H*2-2][W*2-2])


if __name__ == "__main__":
    solve()



Measured memory_bytes: 6196
#include<stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<10;i++){
        if(n%i==0&&n/i>0&&n/i<10){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        l: [usize; n]
    }

    let mut cnt = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            for k in (j + 1)..n {
                if l[i] == l[j] || l[j] == l[k] || l[k] == l[i] {
                    continue;
                }
                if l[k] < l[i] + l[j] && l[i] < l[j] + l[k] && l[j] < l[k] + l[i] {
                    cnt += 1;
                }
            }
        }
    }
    println!("{}", cnt);

}


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

ll N;

int main(){
    ll idx = 0;
    ll sum = 0;

    cin>>N;

    for(ll i=1; i<=N; i++){
        if((i*(i+1))/2 >= N){
            sum = (i*(i+1))/2;
            idx = i;
            break;
        }
    }

    sum -= N;

    for(int i=1; i<=idx; i++){
        if(i == sum) continue;
        cout<<i<<endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int selection_sort (vector<int> & a )
{
	int n = a.size();
	int res = 0;
	rep (i, n ){
		int mini = i;
		for (int j = i; j < n; j++ ){
			if (a[j] < a[mini] ){
				mini = j;
			} // end if
		} // end for
		if (i != mini ){
			swap (a[i], a[mini] );
			res++;
		} // end if
	} // end rep

	return res;
}

int main()
{
	int n;
	scanf ("%d", &n );
	vector<int> a (n, 0 );
	rep (i, n ) scanf ("%d", &a[i] );
	int cnt = selection_sort (a );
	rep (i, n ){
		printf ("%d", a[i] );
		i != n - 1 ? printf (" " ) : printf ("\n" );
	} // end rep
	printf ("%d\n", cnt );
	
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<string>
int dp[2000][2000];
using namespace std;
int main(){
	int t,n;
	int w[2000],v[2000];
	int k=0;
	char z;
	while(true){
	cin>>t;
	if(t==0)
		break;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<=t;j++){
			dp[i][j]=-1;
		}
	}
	for(int i=0;i<n;i++){
		cin>>v[i]>>z>>w[i];
		dp[i][0]=0;
	}
	dp[0][w[0]]=v[0];
	for(int i=1;i<n;i++){
		for(int j=1;j<=t;j++){
			if(j-w[i]<0){
				if(dp[i-1][j]==-1)
					dp[i][j]=-1;
				if(dp[i-1][j]!=-1)
					dp[i][j]=dp[i-1][j];
			}
			if(j-w[i]>=0){
				if(dp[i-1][j]==-1&&dp[i-1][j-w[i]]==-1)
					dp[i][j]=-1;
				if(dp[i-1][j]==-1&&dp[i-1][j-w[i]]!=-1)
					dp[i][j]=dp[i-1][j-w[i]]+v[i];
				if(dp[i-1][j]!=-1&&dp[i-1][j-w[i]]==-1)
					dp[i][j]=dp[i-1][j];
				if(dp[i-1][j]!=-1&&dp[i-1][j-w[i]]!=-1){
					if(dp[i-1][j]>=dp[i-1][j-w[i]]+v[i])
						dp[i][j]=dp[i-1][j];
					if(dp[i-1][j]<dp[i-1][j-w[i]]+v[i])
						dp[i][j]=dp[i-1][j-w[i]]+v[i];
				}
			}
		}
	}
	int c=0;
	for(int j=0;j<=t;j++){
		if(dp[n-1][j]>c)
			c=dp[n-1][j];
	}
	k++;
	bool g=false;
	for(int j=0;j<=t;j++){
		if(c==dp[n-1][j]&&g==false){
			cout<<"Case "<<k<<":"<<endl;
			cout<<c<<endl;
			cout<<j<<endl;
			g=true;
		}
	}
	}
	return 0;
}

Measured memory_bytes: 9360
##!/usr/bin/env python3
import sys
# from operator import itemgetter
# gcd
# from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
# from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
# 提出時はコメントアウト+上のshebangを有効にする
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int

    # write code
    if K > (N - 1) * (N - 2) // 2:
        print(-1)
    else:
        Lis = []
        for i in range(2, N+1):
            Lis.append((1, i))
        for i in range(2, N + 1):
            for j in range(i + 1, N + 1):
                Lis.append((i, j))
        print(N - 1 + (N - 1) * (N - 2) // 2-K)
        for i in range(N - 1 + (N - 1) * (N - 2) // 2-K):
            print(Lis[i][0],Lis[i][1])



Measured memory_bytes: 44912
n = int(input())

minCount = 10 ** 6
for i in range(1, n):
    # a = i, b = n - i として各位の和を計算
    _a = str(i)
    _b = str(n - i)
    count = 0
    for j in range(len(_a)):
        count += int(_a[j])
    for j in range(len(_b)):
        count += int(_b[j])
    minCount = min(minCount, count)
print(minCount)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string l[10] = {"pon", "pon", "hon", "bon", "hon",
                  "hon", "pon", "hon", "pon", "hon"};
  int n;cin >> n;
  cout << l[n%10] << endl;
  return 0;
}

Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n;cin>>n;
    int a[n];rep(i,n)cin>>a[i];
    int cnt=0;
    rep(i, n-2){
        if((a[i]>a[i+1]&&a[i+1]>a[i+2])||(a[i]<a[i+1]&&a[i+1]<a[i+2]))cnt++;
    }
    co(cnt);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main () {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> l(c);
    for(int i = 0; i < c; i++) cin >> l[i];
    vector<pair<int, int>> cw(n);
    for(int i = 0; i < n; i++) cin >> cw[i].first >> cw[i].second;
    for(int i = 0; i < n; i++) cw[i].first--;
    sort(cw.begin(), cw.end(), [](const pair<int, int> &lhs, const pair<int, int> &rhs) {return lhs.second > rhs.second; });
    long long ans = 0;
    vector<int> ll(c);
    int cnt = 0;
    for(int i = 0; i < n && cnt < m; i++) if (ll[cw[i].first] < l[cw[i].first]) {
        ans += cw[i].second;
        ll[cw[i].first]++;
        cnt++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4284
#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(){
  string s;
  cin >> s;
  int a[3]={0,0,0};
  for(int i=0;i<s.length();i++){
    a[s[i]-'a']++;
  }
  if(max(a[0],max(a[1],a[2]))-min(a[0],min(a[1],a[2]))<=1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

using namespace std;

int main(void)
{

    int N;
    cin >> N;
    vector<int> a(N, 0);
    for(auto& x: a){
        cin >> x;
    }
    vector<int> box(N, 0);
    vector<int> ans;
    for(int i = N; i > 0; i--){
        int sum = 0;
        for(int j = 2*(i); j <= N; j+=(i)){
            sum += box[j-1];
        }
        if((sum % 2) != a[i-1]){
            box[i-1]++;
           ans.push_back(i);
        }
    }

    int M = ans.size();
    cout << M << endl;
    for(int i = 0; i < M-1; i++){
        cout << ans[i] << " ";
    }
    if (M > 0) cout << ans[M-1] << endl;
    return 0;
}

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

ll f(){
	ll n,k;
	cin>>n>>k;
	if(n%k==0) return 0;
	if(n>k) n=n%k;
	return min(n,k-n);
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout<<f()<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int total = 0;
		for (int i=0; i<5; i++) {
			int n = sc.nextInt();
			if (n < 40) {n = 40;}
			total += n;
		}
		out.println(total/5);
	}
}


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

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

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

  int ab, bc, ca;
  cin >> ab >> bc >> ca;
  int ans = 1;
  int maximum = max(ab, max(bc, ca));

  if (ab != maximum) {
    ans *= ab;
  }
  if (bc != maximum) {
    ans *= bc;
  }
  if (ca != maximum) {
    ans *= ca;
  }
  cout << ans / 2 << endl;

  return 0;
}


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

int compare_int(const void *a, const void *b)
{
  return *(int*)a - *(int*)b;
}

int main(void)
{
  int n;
  scanf("%d", &n);
  int i, a[n];
  i = 0;
  while (i < n)
  {
    scanf("%d", &a[i]);
    i++;
  }
  
  qsort(a, n, sizeof(int), compare_int);
  
  i = 0;
  while (i + 1 < n)
  {
    if (a[i] == a[i + 1])
    {
      printf("NO");
      return 0;
    }
    i++;
  }
  printf("YES");
  return 0;
}


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

int main(){
  int n,N[200],flag,temp,swap=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>N[i];
  flag=1;
  while(flag){
    flag=0;
    for(int j=n-1;j>0;j--){
      if(N[j]<N[j-1]){
        temp=N[j];
        N[j]=N[j-1];
        N[j-1]=temp;
        flag=1;
        swap++;
      }
    }
  }
  for(int i=0;i<n;i++){
    if(i!=n-1)cout<<N[i]<<" ";
    else cout<<N[i]<<endl;
  }
  cout<<swap<<endl;
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;

string S;

int main()
{
  cin >> S;
  if (S == "AAA" || S == "BBB")
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll a;
int main(){
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;

    return 0;
}

Measured memory_bytes: 3616
N, M = map(int, input().split())
Nissu = []
for x in input().split():
	Nissu.append(int(x))
#print(Nissu)
#print(sum(Nissu))

if N - sum(Nissu) <= -1:
	print(-1)
else:
	print(N- sum(Nissu))
    

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (((bit >> i) & 1) > 0)

typedef long long LL;
template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a, Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}    // C++14
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };


using namespace std;



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

    LL N;
    cin >> N;

    LL ans = 0;
    for(LL i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            // i
            LL m = i - 1;

            if (m != 0 and N / m == N % m) {
                ans += m;
            }

            if (i * i != N) {
                // N / i
                m  = (N / i) - 1;
                if (m != 0 and N / m == N % m) {
                    ans += m;
                }
            }
        }
    }

    print(ans);

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
pos = [0, 0]
S = [input() for i in range(H)]
p = 1
def whiteout(Map, h, w):
  y = 0
  for i in range(h):
    for j in range(w):
      if Map[i][j] == '#':
        y += 1
  return y == 0

while pos != [H-1, W-1]:
  cnt = 0
  x, y = pos[0], pos[1]
  S[x] = S[x][:y] + '.' + S[x][y+1:]
  if x < H-1:
    if S[x+1][y] == '#':
      cnt += 1
      pos = [x+1, y]
  if y < W-1:
    if S[x][y+1] == '#':
      cnt += 1
      pos = [x, y+1]
  if cnt != 1:
    p = 0
    break
S[H-1] = S[H-1][:W-1] + '.'
if p == 1 and whiteout(S, H, W):
  print("Possible")
else:
  print("Impossible")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int MOD = 1e9 + 7;

signed main(){

  int n, k; cin >> n >> k;
  vector<vector<int>> G(n);
  for(int i = 0; i < n-1; i++){
    int a, b; cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int ans = k;
  function< void(int,int) > dfs =
  [&](int u, int pre){
    int have = k - 1;
    if(pre != -1) have--;
    for(int v : G[u]){
      if(v == pre) continue;
      dfs(v, u);
      ans = (ans * have) % MOD;
      have--;
    }
    return;
  };
  dfs(0, -1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector< pair<int, int> > students(N);
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    students[i] = make_pair(a, b);
  }

  vector< pair<int, int> > ans(N, pair<int, int>(0, 1e9));
  for (int i = 0; i < M; ++i) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j < N; ++j) {
      int distance = abs(students[j].first - c) + abs(students[j].second - d);
      if (ans[j].second > distance) {
	ans[j].first = i;
	ans[j].second = distance;
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    cout << ans[i].first + 1 << endl;
  }

  return 0;
}


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

ll n,k,a[N_MAX];	
int l;
vector<ll> ks,best; // ks : Kを2進数表記, best : 最適解

int len(ll K) {
	// Kを２進数表記したときの桁数
	int cnt = 1;
	while(K>=2) {
		K /= 2;
		cnt++;
	}
	return cnt;
}

ll f(ll x) {
	// f(x)を計算する O(n)
	ll ans = 0;
	rep(i, n) {
		ans += x ^ a[i];
	}
	return ans;
}

ll make(int i) {
	// l-1 ~ i+1 bitはks
	// iは0
	// i ~ 0 bitはbest
	ll ans = 0;
	for (ll j = 0; j < i; j++) {
		if (best[j]) {
			ans |= (1ll << j);
		}
	}
	for (ll j = i+1; j < l; j++) {
		if (ks[j]) {
			ans |= (1ll << j);
		} 
	}
	return ans;
}

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

	l = len(k);
	rep(i,n) {
		cin >> a[i];
	}


	rep(i,l) {	// iは桁数を表す
		int cnt0 = 0, cnt1 = 0;
		rep(j,n) { // jはa配列のどれを巡っているかを表す
			if (a[j] & (1ll << i)) {
				cnt1++;
			} else {
				cnt0++;
			}
		}
		if (cnt1 >= cnt0) {
			best.push_back(0);
		} else {
			best.push_back(1);
		}
	}

	rep(i,l) {
		ks.push_back(k&(1ll<<i));
	}

	// rep(i, (int)ks.size()) {
	// 	cout << ks[i];
	// }
	// cout << endl;

	// K以下で最適解探す
	ll ma = f(k);
	rep(i,l) {
		if (ks[i]) {
			ma = max(ma, f(make(i)));
		}
	}

	cout << ma << endl;
}



Measured memory_bytes: 1024
N,M,T=map(int,input().split())
l=list(map(int,input().split()))
t=0
for (i,j) in enumerate(l):
    if not i:
        t+=(l[i]-M)
    elif (l[i]-l[i-1])>2*M:
        t+=(l[i]-l[i-1])-2*M
if T-l[-1]>M:
    t+=(T-l[-1])-M
print(t)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
struct Graph{int to,coin; ll cost;};
struct Edge{int from,to,coin; ll cost;};
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 main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n,m;cin>>n>>m;
    bool ac[100010]; memset(ac,0,sizeof(ac));
    vi wa(n,0);
    int c = 0,p = 0;
    for(int i = 0; i < m; i++) {
        int s;cin>>s;s--;
        string str;cin>>str;
        if(str=="AC"){
            if(!ac[s]){
                c++;ac[s] = 1;
                p += wa[s];
            }
        }
        else{
            wa[s]++;
        }
    }
    if(c==0){
        cout<<0<<' '<<0<<endl;
    }
    else{
        cout<<c<<' '<<p<<endl;
    }
}


Measured memory_bytes: 3676
n, q = map(int, raw_input().split())
fish = [0] * n
ans1 = 0
ans2 = 0
for i in range(q):
	a, v = map(int, raw_input().split())
	fish[a-1] = fish[a-1] + v
	if ans1 == a and v < 0:
		ans1 = fish.index(max(fish)) + 1
		ans2 = max(fish)
	elif ans2 < fish[a-1]:
		ans1 = a
		ans2 = fish[a-1]
	elif ans2 == fish[a-1] and a < ans1:
		ans1 = a
	print "{} {}".format(ans1, ans2)

Measured memory_bytes: 15088
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int N;
vector<pair<int,int> >G[1<<17];
main()
{
	cin>>N;
	vector<pair<int,int> >X(N),Y(N);
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;
		X[i]=make_pair(a,i);
	}
	for(int i=0;i<N;i++)
	{
		int b;cin>>b;
		Y[i]=make_pair(b,i);
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	for(int i=1;i<N;i++)
	{
		int u=X[i-1].second,v=X[i].second;
		int c=X[i].first-X[i-1].first;
		G[u].push_back(make_pair(v,c));
		G[v].push_back(make_pair(u,c));
		u=Y[i-1].second,v=Y[i].second;
		c=Y[i].first-Y[i-1].first;
		G[u].push_back(make_pair(v,c));
		G[v].push_back(make_pair(u,c));
	}
	vector<int>d(N,2e9);
	d[0]=0;
	priority_queue<pair<int,int> >P;
	P.push(make_pair(0,0));
	while(!P.empty())
	{
		int u=P.top().second;
		int cost=-P.top().first;
		P.pop();
		if(d[u]<cost)continue;
		for(pair<int,int>p:G[u])
		{
			int v=p.first;
			int nxt=d[u]+p.second;
			if(d[v]>nxt)
			{
				d[v]=nxt;
				P.push(make_pair(-nxt,v));
			}
		}
	}
	for(int i=0;i<N;i++)cout<<d[i]<<endl;
}



Measured memory_bytes: 13768
#include <bits/stdc++.h>
using namespace std;
int aa, bb;
int dp[3001][3001];
string a, b;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();
	cin >> a >> b;
	aa=a.length(), bb=b.length();
	for(int i=1;i<=aa;i++){
		for(int j=1;j<=bb;j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}
			else{
				(a[i-1]==b[j-1])?dp[i][j]=1+dp[i-1][j-1] : dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	deque<char>ar;
	int x=aa;
	int y=bb;
	while(x>0&&y>0){
		if(a[x-1]==b[y-1]){
			ar.push_front(a[x-1]);
			x--;
			y--;
		}
		else{
			(dp[x-1][y]>dp[x][y-1])? x-- : y--;
		}
	}
	for(auto i:ar){
		cout << i;
	}
	cout << '\n';
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
int H, W; string s;
int main() {
	cin >> H >> W;
	for(int i = 0; i < H; i++) {
		cin >> s;
		int p = -1;
		for(int j = 0; j < W; j++) {
			if(j) cout << ' ';
			if(s[j] == 'c') p = 0;
			else if(p != -1) p++;
			cout << p;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3208
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n,q,ans=0;cin>>n;
  vll s(n);
  rep(i,0,n){
    cin>>s[i];
  }
  cin>>q;
  rep(i,0,q){
    ll t;
    cin>>t;
    if(binary_search(s.begin(),s.end(),t)){
      ans++;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,m;
int g[N][N];
int dp[N],e[N],vis[N],x,y;
void dfs(int p,int t)
{
    if(vis[p])
	{
        if(vis[p]!=t+1)
        {
        	puts("-1");
        	exit(0);
        }
        return;
    }
    vis[p]=t+1;
    if(t)x++;
    else y++;
    for(int i=1;i<=n;i++)
        if(i!=p&&!g[p][i])dfs(i,t^1);
}
int calc(int x)
{
    return x*(x-1)/2;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1,a,b;i<=m;i++)
	{
        scanf("%d%d",&a,&b);
        g[a][b]=g[b][a]=1;
    }
    memset(dp,0,sizeof dp);
    dp[0]=1;
    for (int i=1;i<=n;i++)
	{
        if(vis[i])continue;
        x=0,y=0;
        dfs(i,0);
        memset(e,0,sizeof e);
        for(int j=n;j>=0;j--)
            e[j+x]|=dp[j],e[j+y]|=dp[j];
        for(int j=0;j<=n;j++)dp[j]=e[j];
    }
    int ans=n*n*2;
    for(int i=0;i<=n;i++)
        if(dp[i])ans=min(ans,calc(i)+calc(n-i));
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = 0;
	for (int i = 0; i <= a; i++) for (int j = 0; j <= b; j++)for (int k = 0; k <= c; k++)if (i * 500 + j * 100 + k * 50 == d)ans++;
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define REP1(i, N) for (int i = 1; i < N; i++)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ANS(a) cout << a << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())
#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

int a;

int
main()
{
  scanf("%d", &a);
  printf("%d\n", a + a*a + a*a*a);
  return 0;
}


Measured memory_bytes: 3784