akhauriyash/Code-Regression huggingface dataset:
package main

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

func main(){
  defer stdout.Flush()
  n := readInt()
  a := make([]int, n)
  b := make([]int, n)
  for i := range a {
    a[i] = readInt()
    b[i] = a[i]-i-1
  }
  ans1 := 0
  ans2 := 0
  sort.Ints(b)
  chuou1 := b[n/2]
  chuou2 := 0
  if n>1 {
    chuou2 = b[n/2]
  }
  for i := range a {
    ans1 += absInt(a[i]-(chuou1+i+1))
    
    ans2 += absInt(a[i]-(chuou2+i+1))
  }
  fmt.Println(minInt(ans1, ans2))
}

//====  ↓↓↓ Scanner ↓↓↓  ====================================

var (
  readString func() string
  stdout     *bufio.Writer
)
 
func init() {
  readString = newReadString(os.Stdin)
  stdout = bufio.NewWriter(os.Stdout)
}
 
func newReadString(ior io.Reader) func() string {
  r := bufio.NewScanner(ior)
  r.Buffer(make([]byte, 1024), int(1e+11))
  r.Split(bufio.ScanWords)
 
  return func() string {
    if !r.Scan() {
      panic("Scan failed")
    }
    return r.Text()
  }
}
 
func readInt() int {
  return int(readInt64())
}
 
func readInt64() int64 {
  i, err := strconv.ParseInt(readString(), 0, 64)
  if err != nil {
    panic(err.Error())
  }
  return i
}
 
func readIntSlice(n int) []int {
  b := make([]int, n)
  for i := 0; i < n; i++ {
    b[i] = readInt()
  }
  return b
}
 
func readLengthAndSlice() []int {
  n := readInt()
  return readIntSlice(n)
}


//====  ↓↓↓ template functions ↓↓↓  ===========================

//min max
func minInt(a, b int) int{
  if a < b {
    return a
  }
  return b
}

func minInt64(a, b int64) int64{
  if a < b {
    return a
  }
  return b
}

func minFloat64(a, b float64) float64{
  if a < b {
    return a
  }
  return b
}

func maxInt(a, b int) int{
  if a > b {
    return a
  }
  return b
}

func maxInt64(a, b int64) int64{
  if a > b {
    return a
  }
  return b
}

func maxFloat64(a, b float64) float64{
  if a > b {
    return a
  }
  return b
}

//abs
func absInt(x int) int{
  if x < 0 {
    return -x
  }
  return x
}

func absInt64(x int64) int64{
  if x < 0 {
    return -x
  }
  return x
}

func absFloat64(x float64) float64{
  if x < 0 {
    return -x
  }
  return x
}

//gcd lcm
func gcdInt(a, b int) int{
  if b == 0 {
    return a
  }else{
    return gcdInt(b, a%b)
  }
}

func gcdInt64(a, b int64) int64{
  if b == 0 {
    return a
  }else{
    return gcdInt64(b, a%b)
  }
}

func lcmInt(a, b int) int{
  return a*b/gcdInt(a, b);
}

func lcmInt64(a, b int64) int64{
  return a*b/gcdInt64(a, b);
}

func swapInt(x, y *int){
  *x, *y = *y, *x
}

func swapInt64(x, y *int64){
  *x, *y = *y, *x
}

func swapFloat64(x, y *float64){
  *x, *y = *y, *x
}



Measured memory_bytes: 6272
MOD = 10**9 + 7
MOD_t_MAX = 2 * 10**6 + 10

fac  = [None] * MOD_t_MAX
finv = [None] * MOD_t_MAX
inv  = [None] * MOD_t_MAX
def MOD_COM_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MOD_t_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
def MOD_COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    r1, c1, r2, c2 = map(int, input().split())
    MOD_COM_init()
    a = MOD_COM(r2+1+c2+1, r2+1) - 1
    b = MOD_COM(r2+1+c1, c1) - 1
    c = MOD_COM(r1+c2+1, r1) - 1
    d = MOD_COM(r1+c1, c1) - 1
    ans = a - (b + c) + d
    print(ans % MOD)

if __name__ == "__main__":
    main()

Measured memory_bytes: 246332
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;


#define INF (1ll<<60)

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

vector<vector<int>> G;
typedef pair<int,int> pii;
int main(int argc, char const *argv[]) {
  int n,m;cin>>n>>m;
  vector<int> d(n);
  for(int i=0;i<m;++i){
    int u,v;cin>>u>>v;
    u--;v--;
    d[u]++;
    d[v]++;
  }
  int res=0;
  for(int i=0;i<n;++i)res+=(d[i]%2);
  if(res>0){
    cout<<"NO"<<endl;
  }
  else cout<<"YES"<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
 int main(void)
 {
     int A,B,C,K,S;

     scanf("%d%d%d%d",&A,&B,&C,&K);

     if(A>=K) S=K;
     if((A<K)&&(A+B>=K)) S=A;
     if((A+B<K)&&(A+B+C>=K)){
       if((C>0)&&(K-A-B<=C)){
         S=A-(K-A-B);
         }
     }
     printf("%d\n",S);

    return 0;
 }



Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int arr[1001];
int main()
{

    //  #ifndef oj
    // freopen("in", "r", stdin);
    //freopen("out.txt","w",stdout);
    //#endif
    // system("cls");
    //getchar();
    string s,ans="No";
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7')
        {
            ans="Yes";
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  if (s == "a" || s == "e" || s == "i" || s == "o" || s == "u") {
    cout << "vowel";
  } else {
    cout << "consonant";
  }
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#define REP(i, a, b) for ( int i = (a); i < (b); i++ )

using namespace std;

int main(void) {
  char s[5];

	scanf("%s", s);

	sort(s, s + 4);
	
	if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) puts("Yes");
	else puts("No");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int cards[520];
char mark[400];
bool trump[40][520]; 
int main() {
	int n;
	int  i = 0;
	cin >> n;
	for (int j = 0; j < n; j++) {
		cin >> mark[i] >> cards[j];
		if (mark[i] == 'S') {
			i = 0;
		}
		else if (mark[i] == 'H') {
			i = 1;
		}
		else if (mark[i] == 'C') {
			i = 2;
		}
		else if (mark[i] == 'D') {
			i = 3;
		}
		trump[i][cards[j]] = true;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j <= 13; j++) {
		    	if (i == 0) {
					mark[i] = 'S';
				}
				else if (i == 1) {
					mark[i] = 'H';
				}
				else if (i == 2) {
					mark[i] = 'C';
				}
				else if (i == 3) {
					mark[i] = 'D';
				}
			if (trump[i][j] == false) {
				cout << mark[i] << " " << j << endl;
			}
		}
	}
	return 0;
}


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

int main() {
	int n, m;
	cin >> n ;
	string s[100], t[100];
	for (int i = 0;i < n;i++)cin >> s[i];
	cin >> m;
	for (int i = 0;i < m;i++)cin >> t[i];
	int ma=0;
	for (int i = 0;i < n;i++) {
		int res = 1;
		for (int j = i + 1;j < n;j++) {
			if (s[i] == s[j])res++;
		}
		for (int j = 0;j < m;j++) {
			if (s[i] == t[j])res--;
		}
		ma = max(res, ma);
	}
	cout << ma << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define LL long long
using namespace std;
const int N=100007;
int n,m;
struct P {
	LL x,l,r,sc;
	bool operator < (const P &_) const {
		return sc+l*x>_.sc+_.l*_.x;
	}
}A[N];
int win(LL s) {
	int x=s/m,y=s%m;
	LL t=0;
	For(i,1,x) t+=A[i].sc;
	For(i,x+1,n) t-=A[i].l*A[i].x;
	if(t>=0) return 1;
	For(i,1,n) {
		LL w;
		if(y<A[i].x) w=-A[i].l*(A[i].x-y);
		else w=A[i].r*(y-A[i].x);
		if(i<=x) {
			LL r=t+A[x+1].l*A[x+1].x+A[x+1].sc-A[i].sc+w;
			if(r>=0) return 1;
		}
		else {
			LL r=t+A[i].l*A[i].x+w;
			if(r>=0) return 1;
		}
	}
	return 0;
}
int main() {
	scanf("%d%d",&n,&m);
	For(i,1,n) {
		scanf("%lld%lld%lld",&A[i].x,&A[i].l,&A[i].r);
		A[i].sc=(m-A[i].x)*A[i].r;
	}
	sort(A+1,A+1+n);
	LL l=0,r=0;
	For(i,1,n) r+=A[i].x;
	while(l<=r) {
		LL mi=(l+r)>>1;
		if(win(mi)) r=mi-1;
		else l=mi+1;
	}
	printf("%lld",l);
	return 0;
}


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

using namespace std;

int main(int argc, char *argv[])
{
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int X, Y;
    bool exist = false;
    
    cin >> X >> Y;
    
    for (int t = 0; t <= 100; t++) {
        int k = X - t;
        if (k < 0) {
            continue;
        }
        
        if (2 * t + 4 * k == Y) {
            cout << "Yes" << endl;
            exist = true;
            break;
        }
        
    }
    
    if (!exist) {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define re register 
#define ll long long
#define in inline
using namespace std;
inline ll read(){
	int t=0;
	char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+v-'0';
		v=getchar();
	}
	return t;
}
string s,t;
ll n,m,a[52],sum;
int main(){
	m=0;
	n=read();
	for(re ll i=1;i<=n;++i){
		a[i]=read();
		m+=a[i]*sum;
		sum+=a[i];
	}
	printf("%lld",m);
}

Measured memory_bytes: 256
def resolve():
    MOD = 10 ** 9 + 7
    N = int(input())
    AB = [list(map(int, input().split())) for _ in range(N)]

    dp = [[0] * (1 << N) for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        for bit in range(1 << N):
            # 更新されている箇所は飛ばす
            if not dp[i][bit]:
                continue
            # N人の女性を見ていく
            for k in range(N):
                # i番目の男性とk番目の女性が相性○ かつ その女性がまだマッチング済みでない場合
                if AB[i][k] == 1 and (bit >> k & 1) == 0:
                    # 今の状態からk番目の女性だけを新たにbit立てる
                    dp[i + 1][(bit ^ (1 << k))] += dp[i][bit]
                    dp[i + 1][(bit ^ (1 << k))] %= MOD
    print(dp[N][(1 << N) - 1])


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 434876
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
//------show vector---------
template <typename T>
void showV(vector < T > a){
  EACH(i,a){
    cerr << *i << ',';
  }  
  cerr << endl;
}
 
//------show matrix---------
template <typename T>
void showVV(vector < vector < T > > a){
  EACH(i,a){
    showV(*i);
  }  
}
//grobal var
//------------------------------------------
LL dp[2000][2000];
 
int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N,D;
  while(cin >> N >> D){
    int ans = 0;
    VI sq;
    FOR(i,1,200){
      sq.PB(i*i);
    }
 
    VVI DV(N);
    REP(i,N){
      REP(j,D){
        int in;
        cin >> in;
        DV[i].PB(in); 
      }
    }
    REP(i,N){
      FOR(j,i+1,N){
        int dist = 0;
        REP(k,D){
          dist+=(DV[i][k]-DV[j][k])*(DV[i][k]-DV[j][k]);
        }
        if(find(ALL(sq),dist)!=sq.end()) ++ans;
      }
    }
    cout << ans << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
from math import sqrt

def isSquare(n):
    m = int(sqrt(n))
    for x in range(1, m+1):
        if x**2 == n:
            return True

def getDistance(xi, xj, dimention):
    d = 0
    for i in range(dimention):
        d += (xi[i] - xj[i])**2
    return d

def main():
    lines = input()

    n, d = list(map(int, lines[0].split()))
    x = []
    for i, xi in enumerate(lines[1:]):
        x.append(list(map(int, xi.split())))

    cnt = 0

    for i, xi in enumerate(x):
        for j, xj in enumerate(x[i+1:]):
            dist = getDistance(xi, xj, d)
            if isSquare(dist):
                cnt += 1
    print(cnt)

main()

Measured memory_bytes: 9024
#include <iostream>
int main(void)
{
	long long n, a[100000], b[100000];
	long long ans = 0;
	std::cin >> n;
	for(int i = 0; i != n; i++) std::cin >> a[i] >> b[i];
	for(int i = n - 1; i >= 0; i--){
		long long t = (a[i] + ans) % b[i];
		if(t != 0) ans += b[i] - t;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	int N;
	cin >> N;

	vint A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ans ^= A[i];
	}

	if (ans == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 2000000
 
 
int A[N],c=1;
  
void maxHeap(int i){
  int l,v,r,largest;
 
  l=left(i);
  r=right(i);
 
  if(l<=c&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=c&&A[r]>A[largest])
    largest=r;
 
  if(largest!=i){
    v=A[i];
    A[i]=A[largest];
    A[largest]=v;
    maxHeap(largest);
  }
 
}
void insert(int i){
  c++;
  A[c]=-270000000;
  Heapincreace(c,i);
}
 
int extract(){
  int max;
  if(c<1){
    printf("heap underflow");
    exit(8);
  }
  max=A[1];
  A[1]=A[c];
  c--;
  maxHeap(1);
  return max;
}
 
void Heapincreace(int a,int i){
  int k;
  if(i<A[a]){
    printf("new key is smaller than current key");
    exit(8);
  }
  A[a]=i;
  while(a>1&&A[parent(a)]<A[a]){
    k=A[a];
    A[a]=A[parent(a)];
    A[parent(a)]=k;
    a=parent(a);
  }
}
 
int parent(int i){
  return i/2;
}
 
int left(int i){
  return 2*i;
}
 
int right(int i){
  return 2*i+1;
}

int main(){
  int i=1,kp,k;
  char C[20];
 
  
   
  while(1){
    
    scanf("%s",C);
    if(C[0]=='i'){
      scanf("%d",&kp);
      insert(kp);
       
    }
      
    else if(C[0]=='e'&&C[1]=='x'){
    k=extract();
    printf("%d\n",k);
    }
    else
      break;
     
  }
   
  return 0;
}

Measured memory_bytes: 4696
_, *lines = open(0).readlines()
H = [[[0]*10 for i in range(3)] for j in range(4)]
for line in lines:
    b, f, r, v = map(int, line.split())
    H[b-1][f-1][r-1] += v
for i, h in enumerate(H):
    if i:
        print("#"*20)
    for r in h:
        print("",*r)


Measured memory_bytes: 5624
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    cout <<( n * (n - 1) + m * (m - 1)) / 2 << endl;
}


Measured memory_bytes: 256
n,m,l = [int(i) for i in input().split()]
ans = [[0 for i in range(l)] for j in range(n)]
a = []
b = []
sum = 0
for i in range(n):
    x = [int(i) for i in input().split()]
    a.append(x)

for i in range(m):
    y = [int(i) for i in input().split()]
    b.append(y)

for i in range(n):
    for j in range(l):
        for k in range(m):
            sum += a[i][k] * b[k][j]
        ans[i][j] = sum
        sum = 0

for i in range(n):
    for j in range(l):
        if j == l-1:
            print(ans[i][j])
        else:
            print(ans[i][j],end = " ")



Measured memory_bytes: 7060
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    VI a(n + 1);
    REP(i,n) a[i + 1] = a[i] + (s[i] == 'R');
    int ans = n;
    REP(i,n+1){
        int w1 = i - a[i];
        int r2 = a[n] - a[i];
        int x = max(w1, r2);
        chmin(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4452
import java.util.*;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
      	
      	if(s.equals("Sunny")) {
          System.out.println("Cloudy");
        }else if(s.equals("Cloudy")){
          System.out.println("Rainy");
        }else if(s.equals("Rainy")){
          System.out.println("Sunny");
        }
      
      
	}

}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class Mod{
  public:
    ll mod;
    // mod must be a prime number
    Mod(ll m){
        mod = m;
    }
    //a^p
    ll modpow(ll a, ll p){
        if(p == 0) return 1;
        if(p%2 == 0){
            ll half = modpow(a, p/2);
            return half * half % mod;
        }
        else return a * modpow(a,p-1) % mod;
    }

    //nCr
    ll comb(ll n, ll r){
        if(r > n-r) return comb(n,n-r);
        ll mul = 1;
        ll div = 1;
        for (int i = 0;i < r;i++){
            mul *= n-i;
            mul %= mod;
            div *= i+1;
            div %= mod;
        }
        return mul * modpow(div,mod-2) % mod;
    }
};

ll tmp[1000006];
Mod mod(2);

ll comb(ll n, ll r){
    if(r > n-r) return comb(n,n-r);
    if(r == 0) return 1;
    //cout << n << " " << r << " " << tmp[n]-tmp[n-r]-tmp[r] << endl;
    if(tmp[n]-tmp[n-r]-tmp[r]==0) return 1;
    else return 0;
}

  ll diff[1000006];
  ll a[1000006];

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

    ll N;
    
    cin >> N;

    for (int i = 0;i < N;i++){
        char c; cin >> c;
        a[i] = c-'0';
    }

    for (int i = 0;i < N-1;i++){
        diff[i] = abs<ll>(a[i]-a[i+1]);
    }

    bool has1 = false;

    for (int i = 0;i < N-1;i++){
        if(diff[i] == 1) has1 = true;
    }

    tmp[0] = 0;
    
    for (int i = 1;i <= N+1;i++){
        tmp[i] = tmp[i-1]+__builtin_ctz(i);
        //cout << tmp[i] << endl;
    }

    if(!has1){
        ll cnt2 = 0;
        ll sum = 0;
        for (int i = 0;i < N-1;i++){
            if(diff[i] == 2){
                sum += comb(N-2,i);
                //cout << N-2 << " " << i << " " << comb(N-2,i) << " " << sum << endl;
                sum %= mod.mod;
            }
        }
        if(sum%2) cout << 2 << endl;
        else cout << 0 << endl;
        return 0;
    }

    ll sum = 0;

    for (int i = 0;i < N-1;i++){
        if(diff[i] == 1){
            sum += comb(N-2,i);
            sum %= mod.mod;
        }
    }

    //cout << sum << endl;

    if(sum%2) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;

}

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

int main() {
  int N;
  cin >> N;
  map<string, int> map_S;
  for (int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    map_S[tmp]++;
  }
  cout << map_S.size() << endl;
}

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

int common_alpha[26];
int tmp_alpha[26];

int main(void) {
	string S[50];
	int n;
	cin >> n;
	for (int i= 0; i < n; i++) cin >> S[i];

	for (int i = 0; i < 26; i++) common_alpha[i] = 51;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) tmp_alpha[j] = 0;

		for (unsigned int j = 0; j < S[i].length(); j++) {
			tmp_alpha[(int)(S[i][j]-'a')]++;
		}
		for (int j = 0; j < 26; j++) {
			common_alpha[j] = std::min(common_alpha[j], tmp_alpha[j]);
		}
	}

	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < common_alpha[i]; j++) {
			cout <<  (char)((int)'a'+i);
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <random> 
#include <vector>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>

#define ID(x,y) (((x)-1) * m + (y))
#define CL clear
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define low_bit(x) ((x)&(-(x)))
#define dmp(x) cerr<<#x<<"="<<x<<"\n"  
#define MIN(a,b,c) min(a,min(b,c))
#define MAX(a,b,c) max(a,max(b,c))
#define SZ(x) ((int)(x.size())) 
#define sc scanf
#define pf printf
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dep(i,a,b) for(int i=(a);i>=(b);i--)

#define int long long

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;

const int N = (int)1e6+10;
const int mod = 1e9+7;
const int inf = 1e9;
const double eps = 1e-16;
const double pi = acos(-1);


inline int rd() {
  int p=0; int f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f*=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}



signed main() {
  // freopen("a.in","r",stdin);
  // freopen("a.out","w",stdout);
  int k = rd(); int a = rd(); int b = rd();
  rep(i,a,b) if(i%k == 0){puts("OK"); return 0;}
  puts("NG");

  return 0;
}

/*
*/


Measured memory_bytes: 3624
import java.util.*;
class Main {
	public static void main (String[] args) throws java.lang.Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		for(int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if('a' <= c && c <= 'z') System.out.print((char)(c - 32));
			else if('A' <= c && c <= 'Z') System.out.print((char)(c + 32));
			else System.out.print(c);
		}
		System.out.println();
	}
}

Measured memory_bytes: 26528
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt() - i - 1;
		}
		Arrays.sort(arr);
		int m;
		if (n % 2 == 0) {
			m = (arr[n / 2] + arr[(n - 1) / 2]) / 2;
		} else {
			m = arr[n / 2];
		}
		long total = 0;
		for (int i = 0; i < n; i++) {
			total += Math.abs(arr[i] - m);
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 64828
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 200000 + 5;
const double PI = acos(-1);
#define ll long long

class TaskC {
private:
	Debugger debugger;
public:
	void solveOne(int it){
		int x, n;
		cin >> x >> n;
		vector<int> nums(n);
		for(int i = 0; i < n; i++){
			cin >> nums[i];
		}
		set<int> s(nums.begin(), nums.end());
		if(!s.count(x)){
			cout << x << endl;
			return;
		}
		if(!s.count(x-1)){
			cout << x-1 << endl;
			return;
		}
		if(!s.count(x+1)){
			cout << x+1 << endl;
			return;
		}
		int ans;
		bool found = false;
		for(int i = 0; i < n; i++){
			for(int op = nums[i] - 1; op <= nums[i] + 1; op += 2 ){
				if(!s.count(op)){
					if(!found or abs(x - op) < abs(x - ans) or (abs(x - op) == abs(x - ans) and op < ans) ){
						ans = op;
						found = true;
					}
				}
			}
		}
		cout << ans << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>

int main(void){
  char S[100000];
  scanf("%s", S);
  
  int N = strlen(S);
  int ans[N];
  int flag[N];
  for (int i = 0; i < N; i++) {
    ans[i] = 0;
    flag[i] = 0;
  }

  for (int i = 0; i < N-1; i++) {
    if(S[i] == 'R' && S[i+1] == 'L'){
      flag[i] = 1;
      ans[i] = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    if(flag[i] == 1){
      int j = i-1;
      int cnt = 0;
      while(flag[j] == 0 && j >= 0 && S[j] == 'R'){
        j--;
        cnt++;
      }
      if(cnt%2 == 0){
        ans[i] += cnt/2;
        ans[i+1] += cnt/2;
      }else{
        ans[i] += cnt/2;
        ans[i+1] += cnt/2+1;
      }

      j = i+1;
      cnt = 0;
      while(flag[j] == 0 && j < N && S[j] == 'L'){
        j++;
        cnt++;
      }
      if(cnt%2 == 0){
        ans[i] += cnt/2;
        ans[i+1] += cnt/2;
      }else{
        ans[i] += cnt/2;
        ans[i+1] += cnt/2+1;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    printf("%d%c", ans[i], i == N-1?'\n':' ');
  }

  return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.nextLine();
        String[] nImage = new String[n];
        for (int i = 0; i < n; i++) {
            nImage[i] = sc.nextLine();
        }
        String[] mImage = new String[m];
        for (int i = 0; i < m; i++) {
            mImage[i] = sc.nextLine();
        }

        for (int i = 0; i < n - m + 1; i++) {
            int index = nImage[i].indexOf(mImage[0]);
            while (index != -1) {
                if (isMutch(nImage, mImage, index, i)) {
                    System.out.println("Yes");
                    return;
                }
                index = nImage[i].indexOf(mImage[0], index + 1);
            }
        }

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

    static boolean isMutch(String[] nImage, String[] mImage, int xOffset, int yOffset) {
        for (int i = 0; i < mImage.length; i++) {
            if (nImage[yOffset + i].startsWith(mImage[i], xOffset) == false) {
                return false;
            }
        }

        return true;
    }
}

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

const int nax = 3010;
int cx = 0, cy = 0;
vector<int> lx, ly;
ll area = 0;
int done[nax][nax], bx[nax][nax], by[nax][nax];

void bfs(int sx, int sy) {
  queue<pair<int,int>> q;
  q.emplace(sx,sy);
  while (q.size()) {
    auto [xi,yi] = q.front();
    q.pop();
    if (xi < 0 || yi < 0 || xi+1 >= cx || yi+1 >= cy) {
      cout << "INF" << endl;
      exit(0);
    }
    if (done[yi][xi]++) continue;
    ll x0 = lx[xi], x1 = lx[xi+1];
    ll y0 = ly[yi], y1 = ly[yi+1];
    area += (x1-x0)*(y1-y0);
    if (!bx[yi][xi])
      q.emplace(xi-1,yi);
    if (!bx[yi][xi+1])
      q.emplace(xi+1,yi);
    if (!by[yi][xi])
      q.emplace(xi,yi-1);
    if (!by[yi+1][xi])
      q.emplace(xi,yi+1);
  }
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int nv, nh;
  cin >> nv >> nh;
  map<int,int> mx, my;
  mx[0],my[0];
  vector<array<int,3>> hori, vert;
  for (int i = 0; i < nv; i++) {
    int sy, ey, x;
    cin >> sy >> ey >> x;
    vert.push_back({sy, ey, x});
    mx[x];
    my[sy], my[ey];
  }
  for (int i = 0; i < nh; i++) {
    int y, sx, ex;
    cin >> y >> sx >> ex;
    hori.push_back({y, sx, ex});
    mx[sx], mx[ex];
    my[y];
  }
  for (auto&[x,c] : mx) {
    c = cx++;
    lx.push_back(x);
  }
  for (auto&[y,c] : my) {
    c = cy++;
    ly.push_back(y);
  }
  for (auto [sy, ey, x] : vert) {
    int ei = my[ey];
    int xi = mx[x];
    for (int i = my[sy]; i < ei; i++) {
      bx[i][xi] = 1;
    }
  }
  for (auto [y, sx, ex] : hori) {
    int ei = mx[ex];
    int yi = my[y];
    for (int i = mx[sx]; i < ei; i++) {
      by[yi][i] = 1;
    }
  }

  /*for (int i = 0; i < cy; i++) {
    for (int j = 0; j < cx; j++)
      cout << bx[i][j] << ' ' << by[i][j] << "   ";
  cout << endl;
  }*/
  bfs(mx[0],my[0]);
  cout << area << endl;
}


Measured memory_bytes: 76776
#include <stdio.h>

int main() {
	int sum, i, j;
	int a[100000];
	int tmp[100000];

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

	for (i = 0; i < sum; i++) {
		tmp[a[i] - 1] = i + 1;
	}

	for (i = 0; i < sum; i++) {
		printf("%d\n", tmp[i]);
	}

	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#define INF 1e+9
using namespace std;

int fric[301][301];
string field[300];

int calc(int a,int b,int num){
	if(fric[a][b] != -1) return fric[a][b];
	if(!a || !b) return fric[a][b] = 0;
	return fric[a][b] = calc(a - 1,b - 1,num) + (field[a - 1][num] == field[b - 1][num + 1] ? 1 : 0);
}

int main(){
	int h,w,ans = 0;
	cin >> h >> w;
	for(int i = 0;i < h;i++) cin >> field[i];
	for(int i = 0;i < w - 1;i++){
		int dp[301][301];
		for(int j = 0;j <= h;j++){
			for(int k = 0;k <= h;k++){
				fric[j][k] = -1;
				dp[j][k] = INF;
			}
		}
		dp[h][h] = 0;
		for(int j = h;j >= 0;j--){
			for(int k = h;k >= 0;k--){
				if(j) dp[j - 1][k] = min(dp[j - 1][k],dp[j][k] + calc(j,k,i));
				if(k) dp[j][k - 1] = min(dp[j][k - 1],dp[j][k] + calc(j,k,i));
			}
		}
		ans += dp[0][0];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;

int main() {
	int n, current_min = 10000000;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}

	long long ans = 0;

	for (int i = 0; i < n; i++) {
		if (current_min >= p[i]) {
			ans++;
			current_min = p[i];
		}
	}

	cout << ans << endl;
	return 0;
}

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

int n, a[200005];
map<int, int> mp;

bool check(int lmt) {
  mp.clear();
  int now = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] > now) now = a[i];
    else {
      now = a[i];
      while (!mp.empty()) {
        int last = (--mp.end())->first;
        if (last >= now) mp.erase(last);
        else break;
      }
      int nnow = now - 1;
      mp[nnow]++;
      while (nnow >= 0 && mp[nnow] >= lmt) {
        mp.erase(nnow);
        --nnow;
        mp[nnow]++;
      }
      if (nnow < 0) return false;
    }
  }
  return true;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  bool flag = true;
  for (int i = 1; i <= n; ++i)
    flag &= (a[i] > a[i - 1]);
  if (flag) return puts("1") & 0;
  int l = 2, r = n, ans = n;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid)) ans = mid, r = mid - 1;
    else l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long n,W;
long long w[109],v[109];
long long dp[109][100009];
int main(){
    cin>>n>>W;
    for(int i=0;i<n;i++) cin>>w[i]>>v[i];
    dp[0][w[0]] = v[0];
    for(int i=1;i<n;i++){
        for(int j=0;j<=W;j++){
            if(j-w[i] >= 0) dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    long long mx = 0;
    for(int i=0;i<=W;i++){
        mx = max(mx,dp[n-1][i]);
    }
    cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 79360
num = int(input())
if num % 10 == 3:
        print("bon")
elif num %  10 == 2:
        print("hon")
elif num %  10 == 4:
        print("hon")
elif num %  10 == 5:
        print("hon")
elif num %  10 == 7:
        print("hon")
elif num %  10 == 9:
        print("hon")
elif num %  10 == 0:
        print("pon") 
elif num %  10 == 1:
        print("pon")       
elif num %  10 == 6:
        print("pon")       
elif num %  10 == 8:
        print("pon")        

Measured memory_bytes: 9140
#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,t; cin>>s>>t;
    int n=s.size();
    s+=s;
    string ans="No";
    for(int i=0;i<n;i++){
        string tmp;
        for(int j=i;j<i+n;j++){
            tmp+=s[j];
        }
        if(tmp==t) ans="Yes";
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
int a;
int ans=1000000000;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        int k=0;
        while(a%2==0){
            a=a/2;
            k++;
        }
        ans=min(ans,k);
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3540
#include <cstdio>
int main(void){
    int N;
    scanf("%d", &N);
    int array[N+1];
    for(int i=N-1; i>=0; i--){
        scanf("%d", &array[i]);
    }
    for(int j=0; j<N; j++){
        if(j==N-1)printf("%d\n",array[j]);
        else printf("%d ", array[j]);
    }
}

Measured memory_bytes: 2712
/*input
2 0
5 5
*/

#include <iostream>
#include <vector>

using namespace std;

int main()
{

	long N, x;
	cin >> N >> x;
	vector<long> a(N);

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

	// for(auto aa:a){
	// 	cout << aa << " ";
	// }
	// cout << endl;

	long sum = 0;
	if(a[0] > x){
		sum += a[0] - x;
		a[0] = x;
	}

	for(long i=1;i<N;i++){
		if(a[i] + a[i-1] > x){
			sum += a[i] + a[i-1] - x;
			a[i] += x - (a[i] + a[i-1]);
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 1024
using System;

class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            double a = double.Parse(input[0] + input[1]);
            int ai = (int)a;
            double heiho = Math.Sqrt(a);
            int heihoi = (int)heiho;
            if (ai == heihoi * heihoi){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
 
        }
    }

Measured memory_bytes: 13140
#include <stdio.h>

typedef long long ll;

ll t[200005];

int main(){

	int N;

	ll T;

	scanf("%d %lld",&N,&T);

	int i;

	for(i=1;i<=N;i++){
	scanf(" %lld",&t[i]);
	}

	ll ans=0ll;
	for(i=1;i<=N;i++){
		if(t[i]<t[i-1]+T){
		ans+=t[i]-t[i-1];
		}
		else{
		ans+=T;
		}
	}
	ans+=T;

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 1664
n = gets.to_i
a1 = [0] + gets.split.map(&:to_i)
a2 = [0] + gets.split.map(&:to_i)

1.upto(n) do |i|
    a1[i] += a1[i-1]
    a2[i] += a2[i-1]
end

ans = 0

1.upto(n) do |i|
    x = a1[i] + a2[n] - a2[i-1]
    ans = x if ans < x
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,k;
    cin>>n>>k;
    int a=n/k;
    int b=n/k+(n%k);
    cout<<b-a<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <deque>
#include <bitset>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i) = 0; (i) <= (n); (i)++)
using namespace std;

int N;
int A[50];
int B[50];

bool ans[51];

vector<int> link[51];

bool can(int n)
{
	REP(i, 51)
	{
		link[i].clear();
	}

	for (int i = 1; i <= 50; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			if (ans[j] || j <= n)
			{
				int d = i % j;
				if (!CONTAINS(link[i], d))
				{
					link[i].push_back(i % j);
				}
			}
		}
	}

	for (int i = 0; i < N; i++)
	{
		bool flg[51] = {};
		stack<int> s;
		s.push(A[i]);

		bool has_link = false;
		while (!s.empty())
		{
			int n = s.top();
			s.pop();
			if (n == B[i])
			{
				has_link = true;
				break;
			}
			if (!flg[n])
			{
				flg[n] = true;
				for (int l : link[n])
				{
					if (!flg[l])
					{
						s.push(l);
					}
				}
			}
		}

		if (!has_link)
		{
			return false;
		}
	}

	return true;
}

signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i];
	REP(i, N) cin >> B[i];

	if (!can(50))
	{
		cout << "-1" << endl;
		return 0;
	}

	for (int i = 50 - 1; i >= 0; i--)
	{
		if (!can(i))
		{
			ans[i + 1] = true;
		}
	}

	int sum = 0;
	for (int i = 1; i <= 50; i++)
	{
		if (ans[i])
		{
			sum += pow(2, i);
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(), m = scanner.nextInt();
		
		Point[] students = new Point[n];
		Point[] checks= new Point[m];
		int[] ans = new int[n];
		
		for (int i = 0; i < students.length; i++) {
			students[i] = new Point(scanner.nextInt(), scanner.nextInt()); 
		}
		for (int i = 0; i < checks.length; i++) {
			checks[i] = new Point(scanner.nextInt(), scanner.nextInt());
		}
		for (int i = 0; i <  students.length; i++) {
			int[] distances = new int[m];
			for (int j = 0; j < checks.length; j++) {
				distances[j] = students[i].distance(checks[j]);
			}
			int number = 0, min =distances[0];
			for (int j = 1; j < distances.length; j++) {
				if (distances[j]<min) {
					min = distances[j];
					number = j;
				}
			}
			ans[i] = number;
		}
		
		for (int i = 0; i < ans.length; i++) {
			System.out.println(ans[i]+1);
			
		}
		
		scanner.close();
	}
	
	static class Point{
		int x;
		int y;
		
		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
		
		public int distance(Point p) {
			int distanceX = 0;
			int distanceY = 0;
			if (x<p.x) {
				distanceX = p.x - x;
			}else{
				distanceX = x - p.x;
			}
			if (y<p.y) {
				distanceY = p.y - y;
			}else{
				distanceY = y - p.y;
			}
			return distanceX+distanceY;
		}
	}
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,W = map(int,readline().split())
A1 = []
A2 = []
A3 = []
A4 = []
w1,v1 = map(int,readline().split())
A1.append(v1)

for _ in range(N-1):
    w,v = map(int,readline().split())
    if w == w1:
        A1.append(v)
    elif w == w1+1:
        A2.append(v)
    elif w == w1+2:
        A3.append(v)
    else:
        A4.append(v)

S1 = list(accumulate(sorted(A1,reverse = True)))
S2 = list(accumulate(sorted(A2,reverse = True)))
S3 = list(accumulate(sorted(A3,reverse = True)))
S4 = list(accumulate(sorted(A4,reverse = True)))

S1 = [0] + S1
S2 = [0] + S2
S3 = [0] + S3
S4 = [0] + S4

ans = 0
for a in range(len(S1)):
    for b in range(len(S2)):
        for c in range(len(S3)):
            for d in range(len(S4)):
                tmp = w1*(a+b+c+d)+b+2*c+3*d
                total = S1[a]+S2[b]+S3[c]+S4[d]
                if tmp <= W:
                    ans = max(ans,total)
print(ans)

Measured memory_bytes: 73716
#include <stdio.h>

int main(void)
{
  int card[200], a[200], b[200], i, j, k, l, n, m;

  scanf("%d", &n);
  scanf("%d", &m);

  for(i = 0; i < 2*n; i++)
    card[i] = i+1;

  while(m--){
    scanf("%d", &k);

    if(k == 0){
      j = 0;
      for(i = 0; i < n; i++)
	a[i] = card[i];
      for(i = n; i < 2*n; i++)
	b[j++] = card[i];

      j = l = 0;
      for(i = 0; i < 2*n; i++){
	if(i%2 == 0)
	  card[i] = a[j++];
	else
	    card[i] = b[l++];
	}
      }

      j = 0;
      if(1 <= k && k < 200){
	for(i = 0; i < k; i++)
	  a[i] = card[i];

	for(i = k; i < 2*n; i++)
	  b[j++] = card[i];
      
	l = 0;
	for(i = 0; i < 2*n; i++){
	  if(i < j)
	    card[i] = b[i];
	  else
	    card[i] = a[l++];
	}
      }
  }
    
  for(i = 0; i < 2*n; i++)
    printf("%d\n", card[i]);

  return 0;
}

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

using namespace std;

const int N=1e4+10;
int h[N];
int main(){
    int n,val;
    cin>>n;
    h[0]=1;
    while (n--){
        cin>>val;
        for(int i=N-1;i>=val;i--) h[i]|=h[i-val];
    }
    int ans=N-1;
    while (ans&&(!h[ans]||ans%10==0)) ans--;
    cout<<ans;
}


Measured memory_bytes: 256
import math

n = int(input())
s = int(input())

if n == 1:
    if s == 1:
        print(2)
    else:
        print(-1)
    exit()

if n == s:
    print(n + 1)
    exit()

if n < s:
    print(-1)
    exit()


def ds(N, b):
    ret = 0
    while True:
        N, mod = divmod(N, b)
        ret += mod
        if N == 0:
            return ret


i = 0
for i in range(2, math.floor(n**(1/2)) + 1):
    if ds(n, i) == s:
        print(i)
        exit()

if i == 0:
    i = math.floor(n**(1/2))
c = n // (i + 1)
for i in range(c, 0, -1):
    if (n-s) % i == 0:
        b = (n-s)//i + 1
        if i < b and 0 <= s-i < b:
            print(b)
            exit()

print(-1)


Measured memory_bytes: 40812
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    s = sorted([int(input()) for i in range(N)])

    tmp = sum(s)
    if tmp%10 == 0:
        ans = 0
        for i in range(N):
            if s[i]%10 != 0:
                ans = tmp - s[i]
                break
        print(ans)
    else:
        print(tmp)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#!/usr/bin/env python
# coding: utf-8

# In[1]:


from operator import itemgetter


# In[2]:


N = int(input())
LR = [[0, 0] for _ in range(N)]
for i in range(N):
    LR[i][0], LR[i][1] = map(int, input().split())


# In[3]:


maxL = 0
minR = 10 ** 9
for i in range(N):
    maxL = max(maxL, LR[i][0])
    minR = min(minR, LR[i][1])


# In[4]:


ans = 0


# In[5]:


def func(list):
    ret = []
    left = list[0][0]
    right = list[0][1]
    ret.append(right - left + 1)
    for i in range(1, len(list)):
        left = max(left, list[i][0])
        right = min(right, list[i][1])
        ret.append(right - left + 1)
    return ret


# In[6]:


LR.sort(key=itemgetter(1))
LR.sort(key=itemgetter(0))
list1 = func(LR)
LR.reverse()
list2 = func(LR)


# In[7]:


m = 0
for i in range(N - 1):
    m = max(m, list1[i] + list2[N - i - 2])
ans = max(ans, m)


# In[8]:


LR.sort(key=itemgetter(1), reverse=True)
LR.sort(key=itemgetter(0))
list1 = func(LR)
LR.reverse()
list2 = func(LR)


# In[9]:


m = 0
for i in range(N - 1):
    m = max(m, list1[i] + list2[N - i - 2])
ans = max(ans, m)


# In[10]:


LR.sort(key=itemgetter(0))
LR.sort(key=itemgetter(1))
list1 = func(LR)
LR.reverse()
list2 = func(LR)


# In[11]:


m = 0
for i in range(N - 1):
    m = max(m, list1[i] + list2[N - i - 2])
ans = max(ans, m)


# In[12]:


LR.sort(key=itemgetter(0), reverse=True)
LR.sort(key=itemgetter(1))
list1 = func(LR)
LR.reverse()
list2 = func(LR)


# In[13]:


m = 0
for i in range(N):
    m = max(m, LR[i][1] - LR[i][0] + 1)

if minR >= maxL:
    ans = max(ans, m + minR - maxL + 1)
else:
    ans = max(ans, m)


# In[14]:


print(ans)


# In[ ]:






Measured memory_bytes: 32380
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String s = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i+=2) {
			sb.append(s.charAt(i));
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 25872
#coding:utf-8
N  = int(input())
A = list(map(int,input().split()))
def c(A,B):
    for a,b in zip(A,B):
        if a != b:
            return False
    return True
while True:
    A.sort()
    prev = A[:]
    
    s = A[0]
    for i in range(N):
        if A[i] % s == 0:
            A[i] = s
        else:
            A[i] = A[i] % s
    A.sort()
    #print("A  :",A)
    #print("pre:",prev)
    if  c(prev,A) : break
#print("A  :",A)
#print("pre:",prev)
print(A[0])


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

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  for (int ans = -1e6; ans <= 1e6; ++ans)
  {
    if ((a + ans) == 2*b)
    {
      cout << ans << endl;
      break;
    }
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int K;
    cin >> K;
    vector<int> val(n, INT_MAX);
    priority_queue<pair<int, int>> q;
    for (int i = 0; i < K; i++) {
        int v, p;
        scanf("%d %d", &v, &p);
        v--;
        val[v] = p;
        q.emplace(val[v], v);
    }
    while (!q.empty()) {
        int u;
        tie(ignore, u) = q.top(); q.pop();
        for (int v : g[u]) {
            if (val[v] == INT_MAX) {
                val[v] = val[u] - 1;
                q.emplace(val[v], v);
            } else if (abs(val[v] - val[u]) != 1) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    for (int i = 0; i < n; i++) {
        printf("%d\n", val[i]);
    }
}

Measured memory_bytes: 7924