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

static const int g_lower_x = 0;
static const int g_lower_y = 0;

bool checkTop(int H, int y, int r) {
	return H >= y + r;
}

bool checkBot(int H, int y, int r) {
	return H <= y - r;
}

bool checkLeft(int W, int x, int r) {
	return W <= x - r;
}

bool checkRight(int W, int x, int r) {
	return W >= x + r;
}

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

	

	if (checkTop(H,y,r) && checkBot(g_lower_y,y,r) && checkLeft(g_lower_x,x,r) && checkRight(W,x,r))
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
    return 0;
}




Measured memory_bytes: 3112
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int h, w;
    cin >> h >> w;
    vvi a(h, vi(w)), b(h, vi(w)), c(h, vi(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> b[i][j];
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            c[i][j] = abs(a[i][j] - b[i][j]);
        }
    }
    vector<vector<bitset<12800>>> dp(h, vector<bitset<12800>>(w, 0));
    const int mid           = 6400;
    dp[0][0][mid + c[0][0]] = 1;
    dp[0][0][mid - c[0][0]] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (i != 0) {
                dp[i][j] |= dp[i - 1][j] >> c[i][j];
                dp[i][j] |= dp[i - 1][j] << c[i][j];
            }
            if (j != 0) {
                dp[i][j] |= dp[i][j - 1] >> c[i][j];
                dp[i][j] |= dp[i][j - 1] << c[i][j];
            }
        }
    }
    int ret = 1000000000;
    for (int i = 0; i < 12800; ++i) {
        if (dp[h - 1][w - 1][i])
            chmin(ret, abs(i - mid));
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    string N_;
    cin >> N;
    N_ = to_string(N);
    if (N_[0] == '9' || N_[1] == '9') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

char S[3];

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

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, K;
  cin >> N >> K;
  vll A(N);
  REP(i, 0, N) {
    ll a;
    cin >> a;
    A[i] = a - 1;
  }

  ll idx = 0;
  vll loop;
  usll e;
  for (;;) {
    ll a = A[idx];
    if (e.find(a) != e.end()) {
      break;
    }
    loop.emplace_back(a);
    e.emplace(a);
    idx = A[idx];
  }

  ll idx2 = idx;
  vll loop2;
  usll e2;
  for (;;) {
    ll a = A[idx2];
    if (e2.find(a) != e2.end()) {
      break;
    }
    loop2.emplace_back(a);
    e2.emplace(a);
    idx2 = A[idx2];
  }

  if (K <= loop.size()) {
    cout << loop[K - 1] + 1 << endl;
    return 0;
  }

  if ((K - loop.size()) % loop2.size() == 0) {
    cout << loop2[loop2.size() - 1] + 1 << endl;
  } else {
    cout << loop2[(K - loop.size()) % loop2.size() - 1] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 23360
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def ctoi(c):
	return ord(c) - ord('a')

SA = list(input()[::-1])
SB = list(input()[::-1])
SC = list(input()[::-1])
S = [SA, SB, SC]

turn = 0
while S[turn]:
	turn = ctoi(S[turn].pop())
print(ascii_lowercase[turn].upper())


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

int main() {
    long long N;
	cin >> N;
	if(N==2){
		cout << "1" << endl;
		return 0;
	}
	vector<long long> v;

	// long long k=N-1;
	int cnt = 0;
	int n=0;
	int m=0;
	// m = 0 or 1
	cnt++; // m=0, n=1, K=N-1
	cnt++; // m=1,n=0,K=N

	long long dev = 2;
	long long k = N/dev;
	while(k>=2){
		if((N-1)%k==0){ // m = 0
			// cout << " " << k << endl;
			cnt++;
		}else if(N%k==0 && (N/k-1)%k==0){ // m = 1
			// cout << " " << k << endl;
			cnt++;
		}

		if(N>dev*(dev+1)){ // N/(dev) - N/(dev+1) > 1
			dev++;
			k = N/dev;
		}else{
			k--;
		}
	}


	// m >= 2
	int max_m = (int)log2(N);
	for(int m=2;m<=max_m;m++){
		
		long long k=2;
		long long km = pow(k,m);
		while(km<=N){
			if(N%km==0){
				long long dev = N/km;
				if((dev-1)%k==0){
					// cout << " "  << k << endl;
					cnt++;
				}
			}
			k++;
			km=pow(k,m);
		}
	}

	cout << cnt << endl;
    return 0;
}



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

int main(void){
  int i = 0;
  int k = 0;
  int j = 0;
  int n;
  int input;
  int *num;
  int swapNum = 0;
  int temp;

  int minj;

  scanf("%d", &n);
  num = (int *)malloc(n * sizeof(int));

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

  for(i = 0; i < n-1; i++){
    minj = i;
    for(k = i+1; k < n; k++){
      if(num[k] < num[minj]){
        minj = k;
      }
    }
    if(minj != i){
      temp = num[i];
      num[i] = num[minj];
      num[minj] = temp;
      swapNum++;
    }
  }

  for(i = 0; i < n; i++){
    printf("%d", num[i]);
    if(i < n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n", swapNum);

  return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int a;
map<int,int> m;

signed main() {
    rep(i,3) cin >> a, m[a]++;
    if (m.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,D;
    cin >> N >> D;
    int x=2*D+1;
    cout << (N+x-1)/x << endl;



}


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

int main(){
    int n;
    string s;
    cin>>n>>s;
    int a=0;
    rep(i,n){
        if(s[i]=='E') a++;
    }
    int ans = a;
    rep(i,n){
        
        if(s[i]=='W') a++;
        if(s[i]=='E') a--;
        ans = min(ans,a);
    }
    cout << ans <<endl;
    
    return 0;
}



Measured memory_bytes: 900
// $%U%$ $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

string s;
int n;
const int MN = 1000006;
const int inf = 10000007;

int memo[MN][2];
bool memod[MN][2];
int f(int i, bool lp){
	if(i>=n&&lp)return 0;
	if(i>=n&&!lp)return inf;
	if(memod[i][lp])return memo[i][lp];
	memod[i][lp]=1;
	return memo[i][lp]=min(f(i+1,0)+(9-s[i])+lp, f(i+1,1)+s[i]+!lp);
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>s;
	reverse(s.begin(),s.end());
	s.push_back('0');
	n=s.size();
	for(auto &x:s)x-='0';
	cout<<f(0,1)<<endl;
	return 0;
}



Measured memory_bytes: 73628
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int ans = 2019;
	int l, r; cin >> l >> r;
	for (int i = l; i <= l + 2019 && i <= r; i++) {
		for (int j = r; j >= r - 2019 && j > i; j--) {
			ans = min(ans, i * j % 2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=int(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il bool getmin(T &x,const T &y){return y<x?x=y,true:false;}
template<typename T> il bool getmax(T &x,const T &y){return y>x?x=y,true:false;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=100005,mod=(int)1e9+7;

int n,a[N];

int main(){
//	fileio("queue");
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i);
	sort(a+1,a+n+1,greater<int>());
	rep(i,1,n){
		if(a[i]!=n-i+!(i&1)) return puts("0"),0;
	}
	int ans=1;
	per0(i,n>>1) ans=(ans<<1)%mod;
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

struct Data { int x, y, z; };
int n, k, s;

int cal(Data a, Data b)
{
	int x = s - abs(a.x - b.x);
	int y = s - abs(a.y - b.y);
	int z = s - abs(a.z - b.z);
	return 2 * (x * y + y * z + z * x);
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	while (cin >> n >> k >> s, n)
	{

		vector<Data> v;
		REP(i, n)
		{
			int x, y, z; cin >> x >> y >> z;
			v.emplace_back(Data{ x,y,z });
		}
		if (k == 1)
		{
			cout << s * s * 6 << endl;
			continue;
		}
		vector<vi> g(n);
		REP(i, n)REP(j, i)
		{
			Data a = v[i], b = v[j];
			if (abs(a.x - b.x) < s && abs(a.y - b.y) < s && abs(a.z - b.z) < s)
			{
				g[i].push_back(j);
				g[j].push_back(i);
			}
		}
		vector<vi> vl, vc;
		vector<bool> vis(n);
		REP(i, n)
		{
			if (!vis[i] && g[i].size() == 1)
			{
				vi tmp;
				tmp.push_back(i);
				vis[i] = true;
				int t = i;
				while (1)
				{
					bool f = true;
					for (auto x : g[t])
					{
						if (!vis[x])
						{
							f = false;
							t = x;
							vis[t] = true;
							tmp.push_back(t);
						}
					}
					if (f) break;
				}
				vl.push_back(tmp);
			}
		}
		REP(i, n)
		{
			if (!vis[i])
			{
				vi tmp;
				tmp.push_back(i);
				vis[i] = true;
				int t = i;
				while (1)
				{
					bool f = true;
					for (auto x : g[t])
					{
						if (!vis[x])
						{
							f = false;
							t = x;
							vis[t] = true;
							tmp.push_back(t);
							break;
						}
					}
					if (f) break;
				}
				vc.push_back(tmp);
			}
		}
		int ans = 1e9;
		for (auto l : vl)
		{
			if (l.size() < k) continue;
			REP(i, l.size() - k + 1)
			{
				int tmp = s * s * 6 * k;
				REP(j, k - 1)
				{
					tmp -= cal(v[l[i + j]], v[l[i + j + 1]]);
				}
				chmin(ans, tmp);
			}
		}

		for (auto c : vc)
		{
			if (c.size() < k) continue;
			if (c.size() == k)
			{
				c.push_back(c[0]);
				int tmp = s * s * 6 * k;
				REP(j, k)
				{
					tmp -= cal(v[c[j]], v[c[j + 1]]);
				}
				chmin(ans, tmp);
			}
			else
			{
				vi l = c;
				l.insert(l.end(), ALL(c));
				REP(i, l.size() - k + 1)
				{
					int tmp = s * s * 6 * k;
					REP(j, k - 1)
					{
						tmp -= cal(v[l[i + j]], v[l[i + j + 1]]);
					}
					chmin(ans, tmp);
				}
			}
		}
		if (ans == 1e9) ans = -1;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define mod 2019
int main()
{
    string s;
    cin >> s;
    int n = s.length();
    int pot = 1;
    int suf = 0;
    vector<int> cnt(mod);
    cnt[suf]++;
    long long ans = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        int digit = s[i] - '0';
        suf = (suf + digit * pot) % mod;
        pot = 10 * pot % mod;
        ans += cnt[suf];
        cnt[suf]++;
    }
    //for (int i = 0; i < cnt.size(); ++i)
    //    cout << cnt[i] << " ";
    //  cout << "\n";
    cout << ans << "\n";
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  double result = 0.5;
  if (N % 2 != 0) {
    double num = N / 2 + 1;
    result = double(num) / N;
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    string s = " < ";
    if(a==b){
        s = " == ";
    }else if(a>b){
        s = " > ";
    }
    
    cout << "a" << s << "b" << endl;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  double sum = 0.0, a;
  cin >> N;
  for(int i=0;i < N; i++){
  	cin >> a;
    sum += 1.0 / a;
  }
  
 cout << setprecision(16) << 1.0 / sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

 int main(void)
{

 int H,W,h,w,S,s;

  scanf("%d%d" ,&H, &W);

  scanf("%d%d" ,&h, &w);

 s=(H-h)*(W-w);

 printf("%d\n",s);

 return 0;
}


Measured memory_bytes: 128
#![allow(dead_code,unused_variables,unused_imports)]
use proconio::{fastout, input};
use proconio::marker::Chars;
use std::cmp::max;

#[fastout]
fn main() {
    input!(n:usize);
    
    let mut f : Vec<usize> = vec![];
    for i in 0..n{
        input!{c : [usize;10]}
        let mut tmp = 0;
        for i in 0..10{
            tmp += c[9-i] * 2u32.pow(i as u32) as usize
        }
        f.push(tmp);
    }

    let mut p = vec![];
    for i in 0..n{
        input!{pp : [i64;11]}
        p.push(pp);
    }

    let mut ans : i64= -1_000_000_000;
    for i in 1..(1 << 10){
        let mut tmp = 0;
        for j in 0..n{
            let x : usize = i & f[j];
            let y = (x as u32).count_ones();
            tmp += p[j][y as usize];
        }
        
        ans = max(ans,tmp);
    }

    println!("{}",ans);

}

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

int main() {
  int n, q;
  string s;
  cin >> n >> q >> s;

  vector<int> v(s.size(), 0);
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    v.at(i) = cnt; 
    if (s[i] == 'A' && s[i + 1] == 'C') cnt++;
  }
 
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << v.at(r - 1) - v.at(l - 1) << endl;
  }
}


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

int main()
{
    string str;
    cin >> str;
    int i = 0;
    while (str[i]!='\0')
    {
        if (str[i]=='9')
        {
            cout << "Yes" << endl;
            return (0);
        }
            i++;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
//AtCoderC++.cpp

using namespace std;

inline int ceileing(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}

void show(vector<int> a) {
	for (auto v : a)cout << v << " ";
	cout << endl;
}

int main() {
	int N; cin >> N;
	auto ps = vector<int>(N);
	int count = 0;
	for (size_t i = 0; i < N; i++) {
		cin >> ps[i];
		if (ps[i] != i + 1) {
			count++;
		}
	}
	cout << (count > 2 ? "NO" : "YES") << endl;
}

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

using namespace std;
#define ll long long
#define ld long double

set<int> s;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    int ans = 1e9;
    for(int p=1;p<=100;p++) {
        int temp = 0;
        for(int j=0;j<n;j++) {
            temp += (a[j] - p) * (a[j] - p);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, w, n;
  cin >> h >> w >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  set<pair<int, int>> board;
  for (int i = 0; i < n; i++) {
    board.insert(make_pair(a[i], b[i]));
  }
  set<pair<int, int>> already;
  vector<ll> answers(10, 0);
  answers[0] = (h - 2) * (w - 2);
  for (auto p: board) {
    int y = p.first, x = p.second;
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        int dy = y + i, dx = x + j;
        if (dy <= 1 || dy >= h || dx <= 1 || dx >= w) {
          continue;
        }
        if (already.count(make_pair(dy, dx)) > 0) {
          continue;
        }
        already.insert(make_pair(dy, dx));
        int cnt = 0;
        for (int k = -1; k <= 1; k++) {
          for (int l = -1; l <= 1; l++) {
            int fy = dy + k, fx = dx + l;
            auto yx = make_pair(fy, fx);
            if (board.count(yx) > 0) {
              cnt++;
            }
          }
        }
        if (cnt > 0) {
          answers[0]--;
          answers[cnt]++;
        }
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    cout << answers[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 48768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e18;
const int mod = 1e9 + 7;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        G[u].push_back(v);
    }
    int S, V;
    cin >> S >> V;
    --S; --V;
    vector<vector<int>> dist(1e5 + 5, vector<int>(3, inf));
    queue<pair<int, int>> bfs;
    bfs.emplace(S, 0);
    dist[S][0] = 0;
    while (!bfs.empty()) {
        int v = bfs.front().first;
        int l = bfs.front().second;
        bfs.pop();
        for (int u : G[v]) {
            int nl = (l + 1) % 3;
            if (dist[u][nl] != inf) continue;
            dist[u][nl] = dist[v][l] + 1;
            bfs.emplace(u, nl);
        }
    }
    cout << (dist[V][0] == inf ? -1 : dist[V][0] / 3) << endl;

}


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

using namespace std;

vector<int> a;

bool find(int &index, int &num) {
    for (int i = index; i < a.size(); i++)
        if (a[i] == num) {
            index = i + 1;
            num++;
            return true;
        }
    return false;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, index = 0, num = 1, c = 0;
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    while (find(index, num))
        c++;

    cout << (c == 0 ? -1 : n - c) << "\n";

    return 0;
}


Measured memory_bytes: 1024
def chk(s):
    if s[0]!="A" or s[2:len(s)-1].count("C")!=1: return "WA"
    l=s.index("C")
    for i in range(len(s)):
        if i not in [0,l] and s[i] not in "abcdefghijklmnopqrstuvwxyz": return "WA"
    return "AC"
    


s=input()

print(chk(s))

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

    vector< pair<int, pair<int, int> > > v(n);

    for(int i=0; i<n-1; i++){
        cin >> v[i].first >> v[i].second.first >> v[i].second.second;
    }

    for(int i=0; i<n-1; i++){
        int t = 0;
        t = v[i].first + v[i].second.first;
        for(int j=i+1; j<n-1; j++){
            if(t < v[j].second.first) t = v[j].second.first;
            else if(t % v[j].second.second != 0){
                t = t + v[j].second.second - t % v[j].second.second;
            }
            t += v[j].first;
        }
        cout << t << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}

int x[MAX_N], y[MAX_N];

int main() {
    int n, q;
    read(n); read(q);
    ll ans = (ll)(n-2)*(n-2);
    int xx = n;
    int yy = n;
    while(q--){
        int t, z;
        read(t), read(z);
        if(t == 1){
            if(z < xx){
                ans -= yy - 2;
                srep(i,z+1,xx) x[i] = yy;
                xx = z;
            }else{
                ans -= x[z] - 2;
            }
        }else{
            if(z < yy){
                ans -= xx - 2;
                srep(i,z+1,yy) y[i] = xx;
                yy = z;
            }else{
                ans -= y[z] - 2;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}




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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0)cout<<1<<endl;
    else if(b==0)cout<<2<<endl;
    else if(c==0)cout<<3<<endl;
    else if(d==0)cout<<4<<endl;
    else cout<<5<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int mas[50][50];
int dx[8] = {0,1,0,-1,1,-1,1,-1};
int dy[8] = {1,0,-1,0,-1,1,1,-1};
int w,h;
void dfs(int,int);

int main(){
    int cnt;
    while(1){
        cnt = 0;
        cin >> w >> h;
        if(w == 0 && h == 0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin >> mas[i][j];
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(mas[i][j] == 1){
                    cnt++;
                    dfs(j,i);
                }
            }
        }
        cout << cnt << endl;
    }
}

void dfs(int x,int y){
    mas[y][x] = 0;
    for(int i=0;i<8;i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx >= 0 && nx < w && ny >= 0 && ny < h && mas[ny][nx] == 1){
            dfs(nx,ny);
        }
    }
}

Measured memory_bytes: 1240
#include<iostream> 
#include<cstdio>
#include<cstring>
#include<math.h>
using namespace std; 
int main() 
{ 
	string a,b;
	cin>>a>>b;
	if(a>b) cout<<">";
	if(a==b) cout<<"=";
	if(a<b) cout<<"<";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define N 10005
using namespace std;
int n;
int head[N],ver[N],nxt[N],tot,v[N];
void add(int a,int b)
{
    tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int f[N],flag;
int now[1005][5005];
void dfs(int x)
{
    now[x][0]=0;int sum=0;
    for(int i=head[x];i;i=nxt[i])
    {
        dfs(ver[i]);
        int a=min(f[ver[i]],v[ver[i]]),b=max(f[ver[i]],v[ver[i]]);
        for(int j=v[x];j>=a;j--)
        {
            if(b>j)now[x][j]=now[x][j-a]+b;
            else now[x][j]=min(now[x][j-a]+b,now[x][j-b]+a);
        }
        for(int j=0;j<a;j++)now[x][j]=inf;
    }
    f[x]=now[x][0];
    for(int j=0;j<=v[x];j++)f[x]=min(f[x],now[x][j]);
    if(f[x]>=inf)
    {
        puts("IMPOSSIBLE");
        exit(0);
    }
    return ;
}
int main()
{
    cin>>n;
    memset(f,0x3f,sizeof(f));
    for(int i=2;i<=n;i++)
    {
        int tmp;cin>>tmp;
        add(tmp,i);
    }
    for(int i=1;i<=n;i++)cin>>v[i];
    dfs(1);
    puts("POSSIBLE");
    return 0;
}


Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ld=long double;
 
int main(){
    int n,k,q;
    cin>>n>>k>>q;
    int a[n];
    for(int i=1;i<=n;i++){
        a[i]=k;
    }
    for(int i=1;i<=q;i++){
        int x;
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        a[i]-=q;
        //cout<<a[i]<<" ";
        if(a[i]<=0)
        cout<<"No"<<endl;
        else
        cout<<"Yes"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<std::string>a(n);
    for(auto&&s:a)std::cin>>s;
    for(lint i=0;i<n-1;i++){
        if(a.at(i).back()!=a.at(i+1).front()){
            std::cout<<"No"<<'\n';
            return 0;
        }
    }
    std::sort(a.begin(),a.end());
    for(lint i=0;i<n-1;i++){
        if(a.at(i)==a.at(i+1)){
            std::cout<<"No"<<'\n';
            return 0;
        }
    }
    std::cout<<"Yes"<<'\n';
}


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

const int SIZE = 1e6;
bool isprime[SIZE];
vector<int> primes;

void make_primes(){
    for (int i = 0; i < SIZE; ++i)
        isprime[i] = true;
    isprime[0] = isprime[1] = false;
    for (int i = 2; i*i <= SIZE; ++i)
    {
        if (isprime[i]){
            int j = i+i;
            while (j < SIZE)
            {
                isprime[j] = false;
                j += i;
            }
        }
    }
    for (int i = 0; i < SIZE; i++)
        if (isprime[i])
            primes.push_back(i);
}
int main(){
    long long a, b, sum = 1;
    cin >> a >> b;
    make_primes();
    for (int i = 0; i < primes.size(); i++)
    {
        if (a % primes[i] == 0 && b % primes[i] == 0)
            sum += 1;
        while (a % primes[i] == 0)
            a /= primes[i];
        while (b % primes[i] == 0)
            b /= primes[i];
    }
    if (a != 1 && a == b) sum++;
    cout << sum << endl;
}

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

ll N,X;

ll p_sums[51];
ll all_sums[51];

ll dfs(ll t, ll layer){
  if(layer==0)return 1;
  if (t<=0)return 0;
  ll mid = all_sums[layer]/2;
  if(mid==t){
    return p_sums[layer-1] + 1;
  } else if (t < mid) {
    return dfs(t-1, layer-1);
  } else {
    return p_sums[layer-1] + 1 + dfs(t-mid-1, layer-1);
  }
}

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  cin>>N>>X;
  p_sums[0]=1;
  all_sums[0]=1;
  for(int i=1;i<=N;i++){
    p_sums[i] = p_sums[i-1]*2 + 1;
    all_sums[i] = all_sums[i-1]*2 + 3;
  }
  ll ans=dfs(X-1, N);
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3632
//2018.10.19 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register LL
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline LL read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline LL _abs(const res &x){
    return x>0?x:-x;
}
inline LL _max(const res &x,const res &y){
    return x>y?x:y;
}
inline LL _min(const res &x,const res &y){
    return x<y?x:y;
}
namespace MAIN{
    LL n,k,p,ans;
    inline void MAIN(){
        n=read(),k=read();
        p=n/k;
        ans=p*p*p;
        if(k%2==0)p=(n+(k/2))/k,ans+=p*p*p;
        printf("%lld\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>

using namespace std;

struct word{
	char moji[32];
	int count;
};

int main(void){
	
	struct word dt[500];
	char temp[33],max[33];
	int tempC,maxC,cou;
	bool flag=true;

	memset(dt,0,sizeof(dt));
	memset(max,'\0',sizeof(max));
	
	cou=0;
	while(scanf("%s",temp)!=EOF){
		
		tempC=strlen(temp);
		maxC=strlen(max);
		
				
		if(tempC>maxC){
			strcpy(max,temp);
		}
			
		for(int i=0;i<cou+1;i++){
			if(strcmp(dt[i].moji,temp)==0){
				dt[i].count++;
				flag=false;
				break;
			}
		}
	
		if(flag){
			strcpy(dt[cou].moji,temp);	
			cou++;
		}
		flag=true;
		memset(temp,'\0',sizeof(temp));
	}
	
	//バブルソート
	for(int i=0;i<cou;i++){
		for(int j=cou;j>i;j--){
			if(dt[j-1].count<dt[j].count){
				struct word swap;
				swap=dt[j];
				dt[j]=dt[j-1];
				dt[j-1]=swap;
			}
		}
	}

	cout<<dt[0].moji<<" "<<max<<endl;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.ReadLine();
            switch (line)
            {
                case "A":
                    return 'T';
                case "C":
                    return 'G';
                case "G":
                    return 'C';
                case "T":
                    return 'A';
                default:
                    return 0;
            }
        }

        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
    }

    public class ConsoleReader
    {
        public virtual string ReadLine() => Console.ReadLine();
        public int ReadLineInt32() => int.Parse(ReadLine());
        public long ReadLineInt64() => long.Parse(ReadLine());
        public ulong ReadLineUInt64() => ulong.Parse(ReadLine());
        public double ReadLineDouble() => double.Parse(ReadLine());
        public string[] Split() => ReadLine().Split().ToArray();
        public int[] SplitInt32() => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public long[] SplitInt64() => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public ulong[] SplitUInt64() => ReadLine().Split().Select(s => ulong.Parse(s)).ToArray();
        public double[] SplitDouble() => ReadLine().Split().Select(s => double.Parse(s)).ToArray();

        public IEnumerable<string> RepeatReadLines(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLine();
        }
        public IEnumerable<int> RepeatReadLinesInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineInt32();
        }
        public IEnumerable<long> RepeatReadLinesInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return ReadLineInt64();
        }
        public IEnumerable<string[]> RepeatReadLinesSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
    }
    static class DicExt
    {
        public static V GetOrDefault<K, V>(this Dictionary<K, V> dic, K key, V defaultValue = default(V))
        {
            V val;
            return dic.TryGetValue(key, out val) ? val : defaultValue;
        }
    }
}


Measured memory_bytes: 13140
N = int(input())
S = [input() for _ in range(N)]
first_c = []
last_c = []
XA = 0
BA = 0
BX = 0

ans = 0

for s in S:
    first_c.append(s[0])
    last_c.append(s[len(s)-1])
    ans += s.count("AB")

for i in range(len(S)):
    if first_c[i] == "B" and last_c[i] == "A":
        BA += 1
    elif first_c[i] == "B" and last_c[i] != "A":
        BX += 1
    elif first_c[i] != "B" and last_c[i] == "A":
        XA += 1

if BX > 0 and XA > 0:
    ans += min(BX, XA) + BA
elif BX > 0 or XA > 0:
    ans += BA
elif BA > 1:
    ans += BA-1

print(ans)


Measured memory_bytes: 3956
#include <stdio.h>

int main(){
    int A,B,K;
    scanf("%d %d %d",&A,&B,&K);
    while(true){
        if(K<=0)break;
        A/=2;
        B+=A;
        K--;

        if(K<=0)break;
        B/=2;
        A+=B;
        K--;
    }
    printf("%d %d\n",A,B);
    return 0;
}


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

using namespace std ;

int main() {

	string str;
	cin >> str;

	long long sum = 0;

	for (auto i : str) {
		sum += (i - '0');
	}

	if (sum % 9) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;

  return 0;
}

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

int main(){
	int N,A,B,judge,sum=0;
	cin>>N>>A>>B;
  	for(int i=1;i<=N;++i){
		judge=i/10000+i/1000%10+i/100%10+i/10%10+i%10;
      	if(A<=judge&&judge<=B)sum+=i;
      }
  	cout<<sum<<endl;
  	return 0;
}

Measured memory_bytes: 256
h,w = map(int, input().split())

smap = [list(input()) for _ in range(h)]
cmap = [[float('inf') for _ in range(w)] for _ in range(h)]
queue = [(0,0)]
l = [(1,0), (-1,0), (0,1), (0,-1)]

smap[0][0] = '#'

initial_whites = 0

for x in smap:
    for y in x:
        if y == '.':
            initial_whites += 1

cmap[0][0] = 0

while queue:
    v = queue.pop(0)
    for x in l:
        y = (v[0]+x[0], v[1]+x[1])
        if 0 <= y[0] <= h-1 and 0 <= y[1] <= w-1:
            if smap[y[0]][y[1]] == '.':
                smap[y[0]][y[1]] = '#'
                cmap[y[0]][y[1]] = cmap[v[0]][v[1]] + 1
                queue.append(y)
            else:
                pass
        else:
            pass


if cmap[h-1][w-1] == float('inf'):
    print(-1)
else:
    print(initial_whites - cmap[h-1][w-1])

Measured memory_bytes: 3064
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String s = sc.next();
    String str = "";
    int r = 0;
    int b = 0;
    for(int i = 0;i < a;i++){
      if(s.charAt(i)=='B')b++;
      else r++;
    }
    if(r > b)str = "Yes";
    else str = "No";
    System.out.println(str);
  }
}

Measured memory_bytes: 22996
#include<iostream>
#include<cstring>
using namespace std;
int h,w,mas[110][110];
bool d[110][110];
int dy[6]={-1,-1, 0, 0, 1, 1};
int dx_k[6]={ 0, 1,-1, 1, 0, 1};
int dx_g[6]={-1, 0,-1, 1,-1, 0};
int wall=0;
int wall_len=0;
void dfs(int,int);
int main(){
  memset(d,true,sizeof(d));
  memset(mas,0,sizeof(mas));

  cin >> w >> h;

  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cin >> mas[i][j];
    }
  }

  dfs(0,0);
  cout << wall_len << endl;
}

void dfs(int y,int x){
  d[y][x]=false;

  for(int i=0;i<6;i++){
    int ny=y + dy[i];
    int nx;
    if(y&1) nx=x + dx_k[i];//yの１バイト目が１だったら（奇数だったら）
    else nx=x + dx_g[i];

    if(ny>=0 && ny<=h+1 && nx>=0 && nx<=w+1 && d[ny][nx]==true){//規定範囲外に出ない間。
      if(mas[ny][nx]==0){//壁がなかったら
	dfs(ny,nx);
      }
      else{//壁があったら
	wall_len++;
      }
    }

  }
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  ll N, K;
  cin >> N >> K;
  vll A(N);
  cin >> A;

  ll ans = 0;
  for (ll i = 50; i >= 0; i--) {
    ll x = (1LL << i);
    // cout << i << " " << x << endl;

    ll cnt = 0;

    REP(j, N) {
      if (x & A[j])
        cnt++;
    }

    if (cnt < (N + 1) / 2 && ans + x <= K)
      ans += x;
  }

  REP(i, N) A[i] ^= ans;
  cout << accumulate(all(A), 0LL) << endl;
  return 0;
}


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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int ret = 0;
    for (int i = 0; i < 3; i++)
        if (s[i] == t[i])ret++;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		Dice dice = new Dice(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
		int eyes;
		String shijirow = sc.next();
		for(int i =0; i<shijirow.length(); i++) {
			dice.roll(shijirow.charAt(i));
		}
		System.out.println(dice.up);
	}
}

class Dice {
	int up =1;
	int front = 2;
	int left = 3;
	int right = 4;
	int back = 5;
	int down = 6;

	Dice(){};

	Dice(int up,int front,int left,int right, int back, int down){
		this.up = up;
		this.front = front;
		this.left =left;
		this.right = right;
		this.back = back;
		this.down = down;

	}

	void roll(char Shiji) {
		int  tmp;
		switch(Shiji) {
		case 'N':{
			tmp = up;
			this.up = this.front;
			this.front = this.down;
			this.down = this.back;
			this.back = tmp;
			break;
		}
		case 'E':{
			tmp = this.up;
			this.up = this.right;
			this.right = this.down;
			this.down = this.left;
			this.left = tmp;
			break;
		}
		case 'W':{
			tmp = this.up;
			this.up = this.left;
			this.left = this.down;
			this.down = this.right;
			this.right = tmp;
			break;
		}
		case 'S':{
			tmp = this.up;
			this.up = this.back;
			this.back = this.down;
			this.down = this.front;
			this.front = tmp;
			break;
		}
		}

	}

}



Measured memory_bytes: 26288
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N;
cin>>N;
vec(A)
vec(B)
fx(N){
	vecp(A)
	vecp2(B)
}
ll ans=0;
for(int x=N-1;x>=0;x--){
	if(A.at(x)+ans<=B.at(x)){
      if(A.at(x)+ans!=0)
		ans+=B.at(x)-A.at(x)-ans;
	}else{
		int a=(A.at(x)+ans)%B.at(x);
      if(a!=0)
		ans+=B.at(x)-a;
	}

}
ce(ans)

}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vi a(n);
  map<int, int> cnt;
  set<int> list;
  rep(i, n) {
    int l = i, r = n-i-1;
    list.insert(abs(l-r));
  }
  rep(i, n) {
    std::cin >> a[i];
    cnt[a[i]]++;
  }
  bool ok = true;
  ll ans = 1;
  for (auto &p : cnt) {
    if (list.count(p.fi) == 0 || (p.fi != 0 && p.se != 2)) ok = false;
    if (p.fi != 0) ans = (ans * 2) % mod;
  }
  std::cout << (ok ? ans : 0) << "\n";
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
#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 main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll N, A, B; cin >> N >> A >> B;
	
	ll res = 0LL;
	if (A == B && N == 1LL){
		res = 1LL;
	}else
	if (A <= B && N >= 2LL){
		if (A < B && N == 2){
			res = 0LL;
		}else{
			res = (B - A) * (N - 2LL) + 1LL;
		} // end if
	} // end if

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256