akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
	int H,W;
	while(cin>>H>>W){
		if(H==0 && W==0) break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i==0 || i==H-1 || j==0 || j==W-1){
					cout<<"#";
				}else{
					cout<<".";
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,a=1;
  cin >> N;
  for (int i=0;i<10;i++){
  if (N>=2){
  N=N/2;
  a*=2;
  }
  else if (N==1){
  break;
  }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm;

int[100] a;

void main(){
	int n, ans;
	while (readf("%d\n", &n), n) {
		foreach (i; 0..n) readf("%d\n", &a[i]);
		ans = 0;
		foreach (i; 0..n) {
			for (int j = 1; j < n-i; j++) {
				if (a[j-1] > a[j]) {
					ans++;
					swap(a[j-1], a[j]);
				}
			}
		}
		writeln(ans);
	}
}

Measured memory_bytes: 984
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		try{
			BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
			String str;
			if((str = stdReader.readLine()) != null)
			{
				int x = Integer.parseInt(str);
				System.out.println(x*x*x);
			}
			
		}
		catch (Exception e)
		{
			e.getStackTrace();
			System.exit(0);
		}
	}
}

Measured memory_bytes: 24484
#include <bits/stdc++.h>
  using namespace std;
  
  #define ll long long
  #define N 1100
  const ll MOD = (ll)1e9 + 7;
  int n, m, a[N], b[N];
  
  bool check()
 {
     for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j)
         if (a[i] == a[j]) return false;
     for (int i = 1; i <= m; ++i) for (int j = i + 1; j <= m; ++j)
         if (b[i] == b[j]) return false; 
    return true; 
 }
 
 int main()
 {
     while (scanf("%d%d", &n, &m) != EOF)
    {
         for (int i = 1; i <= n; ++i) scanf("%d", a + i);
         for (int i = 1; i <= m; ++i) scanf("%d", b + i);
         sort(a + 1, a + 1 + n);
         sort(b + 1, b + 1 + m);
         if (!check()) puts("0");  
         else
         {
             a[n + 1] = n + 1;
             b[m + 1] = m + 1;
             int l[2] = {0, 0};
             ll res = 1; 
             for (int i = 1; i <= n * m; ++i)
             {
                 while (l[0] <= n && a[l[0]] < i) ++l[0]; 
                 while (l[1] <= m && b[l[1]] < i) ++l[1];
                 ll d = 0;
                 if (a[l[0]] == i && b[l[1]] == i)
                     d = 1;
                 else if (a[l[0]] == i && b[l[1]] != i)
                     d = m - l[1] + 1;
                 else if (b[l[1]] == i && a[l[0]] != i)
                     d = n - l[0] + 1;
                 else
                     d = (m - l[1] + 1) * (n - l[0] + 1) - (n * m - i);
                 res = (res * d) % MOD; 
             } 
             printf("%lld\n", res);
         }
     }
     return 0;
 }

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

#define ll long long int
#define int long long int
#define ff first
#define ss second
#define pb push_back

#define N 10001000

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b;
    cin >> a >> b;
    int m = __gcd(a, b);
    
    int ans = 1;

    for(int i = 2; i * i <= m; ++i)
    {
        if(m % i == 0)
        {
            while(m % i == 0)
            {
                m /= i;
            }
            ans++;
        }
    }
    if(m > 1)
        ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
class CodeGen:
    codes = []
    cnt = 100

    def __init__(self, A, B):
        self.A = A
        self.B = B    
        self.C1 = self.one()
        self.C2 = self.pow2(self.C1, 1)
        self.C3 = self.pow2(self.C1, 2)
        self.C4 = self.pow2(self.C1, 3)

        self.POW2 = [self.C1]
        for i in range(32):
            self.POW2.append(self.pow2(self.C1, i + 1))
    
    def allocate(self):
        self.cnt += 1
        return self.cnt - 1

    def plus(self, x, y):
        l = self.allocate()
        self.codes.append(f"+ {x} {y} {l}")
        return l

    def gt(self, x, y):
        l = self.allocate()
        self.codes.append(f"< {x} {y} {l}")
        return l

    def ge(self, x, y):
        return self.gt(x, self.plus(y, self.C1))

    def pow2(self, x, n):
        t = x
        for _ in range(n):
            t = self.plus(t, t)
        return t

    def one(self):
        return self.gt(self.allocate(), self.plus(self.A, self.B))

    def bits(self, x, n):
        result = []

        t = self.allocate()
        for i in range(n - 1, -1, -1):
            bit = self.ge(self.plus(self.POW2[i], t), x)
            result.append(bit)
            t = self.plus(t, self.pow2(bit, i))
        return result

    def mult(self, x, y):
        return self.gt(self.C1, self.plus(x, y))

    def show(self, ans):
        t = self.allocate()
        self.codes.append(f"+ {ans} {t} 2")

        print(len(self.codes))
        for c in self.codes:
            print(c)

    def pluss(self, xs):
        if len(xs) == 1:
            return xs[0]
        return self.plus(xs[0], self.pluss(xs[1:]))

class Eval(CodeGen):
    def __init__(self, A, B):
        super().__init__(A, B)
    
    def allocate(self):
        return 0

    def plus(self, x, y):
        return x + y

    def gt(self, x, y):
        if x < y:
            return 1
        return 0

    def show(self, ans):
        print(ans)


if __name__ == "__main__":
    gen = CodeGen(0, 1)
    # gen = Eval(1000, 1234)

    A = gen.bits(gen.A, 32)
    B = gen.bits(gen.B, 32)
    X = []
    for _ in range(64):
        X.append(gen.allocate())
    for i in range(32):
        for j in range(32):
            X[i + j] = gen.plus(X[i + j], gen.mult(A[i], B[j]))
    ans = gen.allocate()
    for i in range(64):
        ans = gen.plus(ans, gen.pow2(X[i], 62- i))
    gen.show(ans)



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

int main(){
  int N,M; cin>>N>>M;
  int count[50]={0};
  int n[110];

  for(int i=0;i<M*2;i++){
    cin>>n[i];
  }

  for(int i=0;i<M*2;i++){
    for(int j=0;j<N;j++){
      if(n[i]==j+1){
        count[j]++;
      }
    }
  }

  for(int i=0;i<N;i++){
    cout<<count[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
# C
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    nb = max(da, dc) + b
    nc = max(da, db) + c
    da = na
    db = nb
    dc = nc
    
print(max([na, nb, nc]))

Measured memory_bytes: 30580
M = int(input())

if(M>=400 and M<600):
    print("8")
elif(M>=600 and M<800):
    print("7")
elif(M>=800 and M<1000):
    print("6")
elif(M>=1000 and M<1200):
    print("5")
elif(M>=1200 and M<1400):
    print("4")
elif(M>=1400 and M<1600):
    print("3")
elif(M>=1600 and M<1800):
    print("2")
elif(M>=1800 and M<2000):
    print("1")


Measured memory_bytes: 9192
#include <iostream>
int main(){
	for(int a,b,c;std::cin>>a>>b>>c;){
		int x=20-a-b,f=3;
		if(x<a)f--;
		if(x<b)f--;
		if(x<c)f--;
		std::cout<<((x-f>3)?"YES\n":"NO\n");
	}
}

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

int main() {
	string s;
	cin>>s;
	int ans=0;
	int count=0;
	for(int i=0;i<s.size();i++) {
		if(s[i]!='A' && s[i]!='C' && s[i]!='G' && s[i] != 'T') {
			ans = max(ans,count);
			count = 0;
		}
		else count++;
	}
	ans = max(ans,count);
	cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#ABC105C
import sys

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

res=[]

if(n==0):
	print("0")
	sys.exit()

while(1):
	#print(n)
	if(n==0):
		break
	if n%2==1:
		res.append(1)
		n-=1
		n=n//(-2)
	else:
		res.append(0)
		n=n//(-2)

res2=""
for i in range(0,len(res)):
	#res2=res2+str(res[len(res)-i-1])
	res2=res2+str(res[-i-1])
print(res2)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define int long long

int32_t main()
{
    int n; cin>>n;
    vector<int> v(n),c(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
    }
    int sum=0;
    for(int i=0;i<n;i++)
    if(v[i]>c[i]) sum+=v[i]-c[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[] arr = new long[n];
		int count = 0;

		for(int i=0;i<n;i++) {
			arr[i] = scan.nextLong();
		}
		scan.close();

		for(int i=0;i<n;i++) {
			for(int j=i;j<n;j++){
				for(int k=j;k<n;k++) {
					if(arr[i]!=arr[j] && arr[j]!=arr[k] && arr[k]!=arr[i]) {
						if(arr[i]+arr[j]>arr[k] && arr[j]+arr[k]>arr[i] && arr[k]+arr[i]>arr[j]) {
							count++;
						}
					}

				}
			}
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 35896
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include <unordered_map>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S; cin >> S;
	int X, Y; cin >> X >> Y;
	queue<int>x, y;
	int N = S.size();
	int cnt = 0;
	int t = 0;
	REP(i, N) {
		if (S[i] == 'F') cnt++;
		if (i == N - 1 || S[i] == 'T') {
			
			if (x.empty() && y.empty()) {
				x.push(cnt);
				y.push(0);
			}
			else if (t % 2) {
				queue<int>tmp;
				unordered_map<int, bool>mp;
				while (!y.empty()) {
					if (!mp[y.front() - cnt]) {
						tmp.push(y.front() - cnt);
						mp[y.front() - cnt] = 1;
					}
					if (!mp[y.front() + cnt]) {
						tmp.push(y.front() + cnt);
						mp[y.front() + cnt] = 1;
					}
					y.pop();
				}
				y = tmp;
			}
			else {
				queue<int>tmp;
				unordered_map<int, bool>mp;
				while (!x.empty()) {
					if (!mp[x.front() - cnt]) {
						tmp.push(x.front() - cnt);
						mp[x.front() - cnt] = 1;
					}
					if (!mp[x.front() + cnt]) {
						tmp.push(x.front() + cnt);
						mp[x.front() + cnt] = 1;
					}
					x.pop();
				}
				x = tmp;
			}
			t++;
			cnt = 0;
		}

	}

	int F = 0;
	while (!x.empty()) {
		if (x.front() == X)F++;
		//cout << x.front() << endl;
		x.pop();
	}
	//cout << endl;
	while (!y.empty()) {
		if (y.front() == Y)F++;
		//cout << y.front() << endl;
		y.pop();
	}
	if (F == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 640
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		mut abc: [usize; 3],
		k: u32,
	}

	abc.sort();
	println!("{}", abc[0]+ abc[1] + abc[2] * 2usize.pow(k));
}



Measured memory_bytes: 2164
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long int parr[100010];
long long int rankk[100010];

void init(long long int n) {
	for (long long int i = 0; i < n; i++) {
		parr[i] = i;
		rankk[i] = 0;
	}
}

long long int find(long long int x) {
	if (parr[x] == x) {
		return x;
	}
	else {
		return parr[x] = find(parr[x]);
	}
}

void unite(long long int x, long long int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (rankk[x] < rankk[y]) {
		parr[x] = y;
	}
	else {
		parr[y] = x;
		if (rankk[x] == rankk[y]) {
			rankk[x]++;
		}
	}
}

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

	long long int x, y;
	init(n+1);
	for (long long int i = 0; i < m; i++) {
		cin >> x >> y;
		unite(x, y);
	}

	for (int i = 0; i <= n; i++) {
		find(i);
		//cout << i << ' ' << parr[i] << endl;
	}

	vector< vector<long long int> > aa(n+1);
	vector< vector<long long int> > bb(n+1);

	for (long long int i = 0; i <= n; i++) {
		aa[parr[i + 1]].push_back(i+1);
		bb[parr[i + 1]].push_back(p[i]);
	}

	//cout << 'a' << endl;

	long long int ans = 0;

	for (long long int i = 0; i < n+1; i++) {
		//cout << aa[i].size() << ' ' << bb[i].size() << 'a' << endl;
		sort(aa[i].begin(), aa[i].end());
		sort(bb[i].begin(), bb[i].end());
		long long int k = 0;
		for (long long int j = 0; j < aa[i].size(); j++) {
			//cout << aa[i][j] << ' ' << bb[i][k] << endl;
			if (k == bb[i].size()) {
				break;
			}
			if (aa[i][j] == bb[i][k]) {
				//cout << aa[i][j] << endl;
				ans++;
				k++;
			}
			else if (aa[i][j] < bb[i][k]) {

			}
			else {
				j--;
				k++;
			}
		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
	int n;
	cin >> n;
	int now = 0;
	for(int i=0; i<n; i++){
		int d1,d2;
		cin >> d1 >> d2;
		if(d1==d2) now++;
		else now = 0;
		if(now==3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double x, y;
  x = (360.0 * (double)(h * 60 + m)) / (double)(12.0 * 60.0);
  y = (360.0 * (double)(m)) / (60.0);

  double A = abs(x - y);

  double result = sqrt(a*a + b*b - (2*a*b * cos(A*M_PI / 180)));

    printf("%.12f\n", result);
}


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

const int MOD=1000000007;

std::vector<ll int> mfac(1000001);

void mfactorial(){
    mfac[0]=1;
    mfac[1]=1;
    for (ll int i = 2; i <= 1000000; i++) {
        mfac[i]=(mfac[i-1]*i)%MOD;
    }        
}

ll int mpow(ll int a,ll int b){
    if(b==0){
        return 1;
    }
    if(b%2==1){
        return ((mpow(a,b/2)*mpow(a,b/2))%MOD*a)%MOD;
    }else{
        return mpow(a,b/2)*mpow(a,b/2)%MOD;
    }
}

int cmb(int n,int r){
    if(n==0 && r==0){
        return 0;
    }else if(n<r ||n<0){
        return 1;
    }
    ll int a=mfac[n];
    ll int b=mpow(mfac[r],MOD-2);
    ll int c=mpow(mfac[n-r],MOD-2);
    return a*b%MOD*c%MOD;
}

int main(void){
    int x,y;
    std::cin >> x >>y;
    if((x+y)%3!=0){
        std::cout << 0 << std::endl;
        return 0;
    }
    ll int n=(2*y-x)/3;
    ll int m=(2*x-y)/3;
    if(n<0 || m<0){
        std::cout << 0 << std::endl;
        return 0;
    }
    mfactorial();
    
    std::cout << cmb(n+m,n) << std::endl;
    
}

Measured memory_bytes: 8064
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int gcd(int a, int b) {
  while (b) {
    int c = a;
    a = b;
    b = c % b;
  }
  return a;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  vector<int> L(n), R(n);
  L[0] = a[0];
  for (int i = 1; i < n; ++i) {
    L[i] = gcd(L[i - 1], a[i]);
  }
  R[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    R[i] = gcd(R[i + 1], a[i]);
  }
  int best = max(L[n - 2], R[1]);
  for (int i = 1; i < n - 1; ++i) {
    best = max(best, gcd(L[i - 1], R[i + 1]));
  }
  printf("%d\n", best);
  return 0;
}


Measured memory_bytes: 1408
from collections import Counter

N,K = map(int,input().split())
A = list(map(int,input().split()))

C = Counter(A).most_common()
L = len(C)

if L <= K:
  print(0)
  exit()

ans = 0
cnt = 0
for k,v in C:
  cnt += 1
  if K < cnt:
    ans += v
    
print(ans)


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

int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   set <int, greater <int> > s;
   s.insert(a);
   s.insert(b);
   s.insert(c);
   int ans;
   ans = s.size();
   cout<<ans<<endl;
}


Measured memory_bytes: 256
while True:
  m,f,r = map(int, input().split())
  if m==-1 and f==-1 and r==-1:
    break
  if m==-1 or f==-1:
    print('F')
    continue
  if m+f >= 80:
    print('A')
  if 80 > m+f >= 65:
    print('B')
  if 65 > m+f >= 50:
    print('C')
  if 50 > m+f >= 30:
    if r >= 50:
      print('C')
    else:
      print('D')
  if 30 > m+f:
    print('F')


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;

void solve()
{	
	vector<string> decks;
	vector<int> h_sum;
	while (true)
	{
		string s;cin >> s;
		if(s == "-")break;
		decks.push_back(s);
		int n; cin >> n;
		int sum = 0;
		rep(i, n)
		{
			int tmp; cin >> tmp;
			sum += tmp;
		}
		h_sum.push_back(sum);
	}
	rep(i, sz(decks))
	{
		string deck = decks[i];
		int r = h_sum[i];
		r %= sz(deck);
		string ans = deck.substr(r,sz(deck)-r)+deck.substr(0,r);
		cout << ans << endl;
	}
	
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}



Measured memory_bytes: 3224
//by shubham_bitsg

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;
 
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sort(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,n;
    cin>>x>>n;
    set <int> p;
    int ans;
    forl(i,0,n) {
        int t; cin>>t;
        p.insert(t);
    }
    int a = x-1;
    if(n==0 || p.find(x)==p.end()) {
        cout<<x<<"\n";
        return 0;
    }
    if(p.find(a)==p.end()) {
        cout<<a<<"\n";
        return 0;
    }
    a = x+1;
    if(p.find(a)==p.end()) {
        cout<<a<<"\n";
        return 0;
    }
    int ans1, ans2;
    while(1) {
        a++;
        if(p.find(a)==p.end()) {
            ans1 = a;
            break;
        }
    }
    a = x-1;
    while(1) {
        a--;
        if(p.find(a)==p.end()) {
            ans2 = a;
            break;
        }
    }
    if((ans1-x)<(x-ans2)) ans = ans1;
    else if((ans1-x)>=(x-ans2)) ans = ans2;
    cout<<ans<<"\n";
}

Measured memory_bytes: 3660
#include <stdio.h>

long long int abs(long long int a){
	if(a < 0)
		return -a;
	else
		return a;
}

int main(){
	long long int N;
	long long int a[2*10*10*10*10*10*10];
	long long int result = 100000000000;
	long long int total_count = 0;
	long long int count = 0;

	scanf("%lld", &N);

	long long int i, j;
	for(i = 0; i < N; i++){
		scanf("%lld", &a[i]);
		total_count += a[i];
	}

	for(i = 0; i < N-1; i++){
		count += a[i];
		if(abs(total_count - 2*count) < result)
			result = abs(total_count - 2*count);
	}

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

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 211111
#define rep(i,s,t) for(int i=s;i<t;i++)
typedef long long ll;
ll sum[MAXNUM];
unordered_map<ll,int> mm;
int main()
{
    int n,k;scanf("%d%d",&n,&k);
    mm[0]++;ll res=0;
    rep(i,1,n+1){
        scanf("%lld",&sum[i]),sum[i]+=sum[i-1],mm[(sum[i]-i+k)%k]++;
        if(i-k>=0)mm[(sum[i-k]-(i-k)+k)%k]--;
        res+=mm[(sum[i]-i+k)%k]-1;
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 10056
#include<iostream>
#include<string.h>
using namespace std;
int main(){
    char a[1000];
    char b[30]={'X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    cin>>a;
    for(int i=0;i<strlen(a);i++){
        for(int i2=3;i2<30;i2++){
            if(a[i]==b[i2]){
                cout<<b[i2-3];
                break;
            }
        }
    }
    cout<<endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vpll vector<pll>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
 
using namespace std ;
 
#define MAXN 10000000
//lli spf[MAXN];  
//void sieve();
//set<lli> factors(lli x);
//lli power(lli x,lli y,lli p);

//void getZarr(string str, lli Z[]);

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

    lli a[n];
    loopl(i,0,n)
    cin>>a[i];

    lli dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);


    loopl(i,2,n)
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));

    cout<<dp[n-1]<<endl;
    
}
        
 

        
 
 
 
 /*   void sieve() 
    { 
        spf[1] = 1; 
        loopl(i,2,MAXN) 
            spf[i] = i; 
        for (lli i=4; i<MAXN; i+=2) 
            spf[i] = 2; 
      
        for (lli i=3; i*i<MAXN; i++) { 
            if (spf[i] == i) { 
                for (lli j=i*i; j<MAXN; j+=i) 
                    if (spf[j]==j) 
                        spf[j] = i; 
            } 
        }
 
    }*/ 
    /*
    multiset<lli> factors(lli x) 
    { 
        multiset<lli> pr; 
        while (x != 1) 
        { 
            pr.insert(spf[x]); 
            x = x / spf[x]; 
        } 
        return pr; 
    }
 
    */
 
    /*
    void dfs(lli q,lli root) 
    {
        vis[q]=1;
        
        ans[q]=1;
        for(auto x: v[q])
        {
            if(!vis[x])
            {
                if(a[x]==a[root] && x<root) continue;
                if(a[x]<a[root] || a[x]>a[root]+d) continue;
                dfs(x,root);
                ans[q]=(ans[q]*((ans[x]+1)%mod))%mod ;
            }
        }
            
    }
    */
 
 
 
    /*void getZarr(string str, lli Z[])
    {
        lli n = str.length();
        lli L, R, k;
        L = R = 0;
        for (lli i = 1; i < n; ++i){
            if (i > R){
                L = R = i;
                while (R<n && str[R-L] == str[R])
                    R++;
                Z[i] = R-L;
                R--;
            } else {
                k = i-L;
                if (Z[k] < R-i+1)
                    Z[i] = Z[k];
                else {
                    L = i;
                    while (R<n && str[R-L] == str[R])
                        R++;
                    Z[i] = R-L;
                    R--;
                }
            }
        }
    }
 
    */
 
    
  /*  lli power(lli x, lli y, lli p) 
    { 
        lli res = 1;   
        x = x % p;  
        while (y > 0) 
        { 
            if (y & 1) 
                res = (res*x) % p; 
      
            y = y>>1;  
            x = (x*x) % p;   
        } 
        return res; 
    } 
    */  
 
 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  char s;
  cin>>s;
  putout(char(s+1));
}

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

int main() {
    int x, n;
    cin >> x >> n;
    vector<bool> list(105, false);
    rep(i,n) {
        int p;
        cin >> p;
        list.at(p) = true;
    }
    if(!list.at(x)) {
        cout << x << endl;
        return 0;
    }
    int upper = x, lower = x;
    while(upper < 101) {
        if(!list.at(upper)) break;
        upper++;
    }
    while(0 <= lower) {
        if(!list.at(lower)) break;
        lower--;
    }
    if(abs(x-lower) <= abs(x-upper)) {
        cout << lower << endl;
    }
    else {
        cout << upper << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]
for i in range(H+2):
    for j in range(W+2):
        if i==0 or i==H+1 or j==0 or j==W+1:
            print("#", end="")
        else:
            print(a[i-1][j-1],end="")
    print("\n")

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

#define MAX_V 10000
#define INF 1e9
typedef pair<int, int> pii;

struct edge{
    int to, cost;
};

int V;
bool used[MAX_V];
vector<edge> G[MAX_V];

/*
  O(E log V)
  ?????°??±?????????????????´???vector?????????????????¨???
*/
int prim()
{
    priority_queue<pii, vector<pii>, greater<pii> > Q;
    Q.push(pii(0, 0));
    memset(used, false, sizeof(used));
    int res = 0;
  
    while (!Q.empty()) {
	pii p = Q.top(); Q.pop();
	int v = p.second;
	if (used[v]) continue;
	used[v] = true;
	res += p.first;
	for (int i = 0; i < (int)G[v].size(); i++) {
	    edge e = G[v][i];
	    Q.push(pii(e.cost, e.to));
	}
    }
    return res;
}

int main()
{
    int E,s,t,w;
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
	cin >> s >> t >> w;
	G[s].push_back((edge){t, w});
	G[t].push_back((edge){s, w});
    }
    cout << prim() << endl;
    return 0;
}

Measured memory_bytes: 7904
N,M=map(int,input().split())
ab=list(list(map(int,input().split()))for _ in range(M))
graph=list([0]*N for _ in range(2))
for a,b in ab:
    if a==1:
        graph[0][b-1]=1
    elif b==N:
        graph[1][a-1]=1

for i,j in zip(graph[0],graph[1]):
    if i==1 and j==1:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Measured memory_bytes: 54920
#include<bits/stdc++.h>
using namespace std;
#define int long
signed main(){
  string s;
  cin>>s;
  int pos=0,n=s.size(),i,j,b=0,r=0;
  while(pos<n){
    i=j=0;
    while(s[pos+i]=='>')++i;
    while(s[pos+i+j]=='<')++j;
    if(b<=i)r-=b;
    else r-=i;
    r+=i*(i+1)/2+j*(j+1)/2;
    b=j;
    pos+=i+j;
  }
  cout<<r;
}

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

int main(){
  int h,w,a=0;
  cin>>h>>w;
  vector<vector<char>> v(h+2,vector<char>(w+2,'#'));
  vector<vector<int>> u(h+2,vector<int>(w+2));
  vector<vector<int>> d(h+2,vector<int>(w+2));
  vector<vector<int>> l(h+2,vector<int>(w+2));
  vector<vector<int>> r(h+2,vector<int>(w+2));
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++) cin>>v[i][j];
  }
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      if(v.at(i).at(j)=='#')u.at(i).at(j)=0;
      else u.at(i).at(j)=u.at(i-1).at(j)+1;
    }
  }
  for(int i=h+1;i>=0;i--){
    for(int j=0;j<w+2;j++){
      if(v.at(i).at(j)=='#')d.at(i).at(j)=0;
      else d.at(i).at(j)=d.at(i+1).at(j)+1;
    }
  }
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      if(v.at(i).at(j)=='#')l.at(i).at(j)=0;
      else l.at(i).at(j)=l.at(i).at(j-1)+1;
    }
  }
  for(int i=0;i<h+2;i++){
    for(int j=w+1;j>=0;j--){
      if(v.at(i).at(j)=='#')r.at(i).at(j)=0;
      else r.at(i).at(j)=r.at(i).at(j+1)+1;
    }
  }
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      a=max(a,u.at(i).at(j)+d.at(i).at(j)+l.at(i).at(j)+r.at(i).at(j)-3);
    }
  }
  cout<<a<<endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  if ((A + B) == (C + D)) {
    cout << "Balanced" << endl;
  }
  if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  }
} 

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL N;
	cin >> N;
	LL NG = 0;
	LL OK = N;
	while(OK-NG>1){
		LL mid = (NG+OK)/2;
		LL res = mid*(1+mid)/2;
		if( res < N ){
			NG = mid;
		}else{
			OK = mid;
		}
	}
	for(int i=OK;N;--i){
		if( i <= N ){
			cout << i << endl;
			N -= i;
		}
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
N = int(input())
remain = N
i = 0
huyou = 0
dog = []
while (remain > 0):
    kurai = 26**i
    ans = remain // kurai
    keta = ans % 26
    if keta == 0:
        keta += 26
    dog.append(keta)
    huyou = keta * kurai
    remain -= huyou
    i += 1
out = ""
for j in reversed(dog):
    out += chr(j+96)
print(out)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

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

  ll N,K;
  cin >> N >>K;
  vector<ll> vec(N);

for (ll i = 0; i < N; i++) {
  cin >>vec.at(i);
}

ll sum = 0,max_sum,max_num=0;
for (ll i = 0; i < K; i++)
{
  sum+=vec.at(i);
  }
  max_sum = sum;

  for (ll i = 0; i < N-K; i++) {
    sum-=vec.at(i);
    sum += vec.at(i + K);
    if(max_sum<sum){
      max_sum = sum;
      max_num = i+1;
    }
  }
  //cout << max_num << endl;

  double kitaichi = 0;

  
  for (ll i = max_num; i <= max_num + K-1; i++)
  {
    kitaichi+=(double)(vec.at(i)+1)/2;
  }
  std::cout << std::fixed;
  cout << setprecision(9) << kitaichi << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}

	if (sum == x) {
		cout << n << endl;
		return 0;
	}

	sort(a.begin(), a.end());

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (x - a[i] >= 0) {
			x -= a[i];
			cnt++;
		}
	}

	if (cnt == n) {
		cout << n - 1 << endl;
		return 0;
	}

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

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

const int NIL = -1;

struct Node{
    int key;
    Node *left, *right;
    Node(int v = NIL) : key(v) {
        left = right = nullptr;
    }
};

void insert(Node* node, int key)
{
    if(node->key > key){
        if(node->left)
        {
            insert(node->left, key);
        }
        else{
            Node* newnode = new Node(key);
            node->left = newnode;
        }
    }
    else if(node->key < key){
        if(node->right){
            insert(node->right, key);
        }
        else{
            Node* newnode = new Node(key);
            node->right = newnode;
        }
    }
}

struct PrintTree
{
    void preorder(Node* node)
    {
        if(node){
            cout << " " << node->key;
            preorder(node->left);
            preorder(node->right);
        }
    }

    void inorder(Node* node)
    {
        if(node){
            inorder(node->left);
            cout << " " << node->key;
            inorder(node->right);
        }
    }

    void printTree(Node* root)
    {
        // inorder
        inorder(root);
        cout << endl;
        // preorder
        preorder(root);
        cout << endl;
    }
};

int main()
{
    int n, key;
    char command[10];
    Node* root = nullptr;
    PrintTree print;
    cin >> n;
    for(int i=0;i<n;++i)
    {
        cin >> command;
        if(command[0] == 'i')
        {
            if(root){
                cin >> key;
                insert(root, key);
            }
            else{
                cin >> key;
                root = new Node(key);
            }
        }
        else{
            print.printTree(root);
        }
    }
}



Measured memory_bytes: 18708
N, M = map(int, input().split())
A = []
for _ in range(N):
    *S, = map(int, input().split())
    A.append(S[1:])
unique_number = A[0]
for a in A[1:]:
    unique_number = set(unique_number) & set(a)
print(len(unique_number))

Measured memory_bytes: 3060
#if defined(LOCAL)
#define PROBLEM_NAME "c"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vs = vector<string>; // TODO: update template
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)

void solve(istream& cin, ostream& cout) {
  l rows, cols; cin >> rows >> cols;
  vs mm(rows); F(i, 0, rows) cin >> mm[i];
  bool ok = true;
  l dx[] = {1, -1, 0, 0};
  l dy[] = {0, 0, 1, -1};
  F(i, 0, rows) F(j, 0, cols) {
    if (mm[i][j] == '.') continue;
    bool t = false;
    F(d, 0, 4) {
      l x = i + dx[d];
      l y = j + dy[d];
      if (x < 0 or y < 0 or x >= rows or y >= cols) continue;
      t = t or mm[x][y] == '#';
    }
    ok = ok and t;
  }
  cout << (ok ? "Yes" : "No") << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=1e5+5;
int n,a[N],b[N];
map<int,int> ok,cb,fa,exi;
int getfa(int x){return fa[x]?fa[x]=getfa(fa[x]):x;}
int main()
{
	n=read();
	int x=0;
	fo(i,1,n) a[i]=read(),x^=a[i];
	a[0]=x;
	x=0;
	fo(i,1,n) b[i]=read(),x^=b[i];
	b[0]=x;
	fo(i,0,n) ok[a[i]]++,cb[b[i]]++;
																										bool same=1;
																									fo(i,1,n) if(a[i]!=b[i]) same=0;
																								if(same) return puts("0"),0;
	fo(i,0,n)
		if(ok[a[i]]!=cb[a[i]]) return puts("-1"),0;
	int ans=0;
	fo(i,0,n) if(a[i]!=b[i])
	{
		exi[a[i]]=1;
		if(i) ++ans;
		int f1=getfa(a[i]),f2=getfa(b[i]);
		if(f1!=f2) fa[f2]=f1;
	}
	fo(i,0,n) if(exi[a[i]] && getfa(a[i])==a[i]) ++ans,exi[a[i]]=0;
	if(!(a[0]==b[0] && ok[a[0]]==1)) --ans;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 19712
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in range(1, abs(b - a) + 1):
        t += i
    print(t - b)


if __name__ == '__main__':
    slove()


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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)            \
    sort(x.begin(), x.end()); \
    x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

    int k, a, b;
    cin >> k >> a >> b;

    repi(i, a, b + 1)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

const int maxN = 20 * 1e5 + 5;
int cnt[maxN], N, K, ed;
map<int, int> mp;
int main() {
	scanf("%d%d", &N, &K);
	for(int i = 1; i <= N; ++i) {
		int val; scanf("%d", &val);
		if(mp.find(val) == mp.end()) mp[val] = 1;
		else mp[val]++;
	}
	for(map<int, int> :: iterator it = mp.begin(); it != mp.end(); it++) {
		cnt[++ed] = (it -> second);
	}
	sort(cnt + 1, cnt + 1 + ed);
	int ans = 0;
	for(int i = 1; i <= ed - K; ++i) ans += cnt[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 10368
import math
import sys
import collections
import sys

sys.setrecursionlimit(200000)




N,M = list(map(int,input().split(" ")))

dp =[-1] * (N + 1)

def rec(v):
    if dp[v] != -1:
        return dp[v]


    res = 0
    for nv in di[v]:
        res = max(rec(nv) + 1 ,res)  # × dp[nv] ○ rec(nv) ∵ dp[nv]が未計算の場合があるから
    dp[v] = res
    return res

qs = [ list(map(int,input().split(" "))) for _ in range(M)]

# print(qs)
di = collections.defaultdict(lambda :[])
for q in qs:
    x,y = q
    di[x].append(y)
    #dp[y] → yを終点としたlongest path

for i in range(N + 1):
    rec(i)
print(max(dp))

Measured memory_bytes: 150020
#include <bits/stdc++.h>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;
 
int main()
{
	long long int n, sum = 0;
	long double d;

	cin >> n >> d;

	long double x[n], y[n], t;

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

	for (int i = 0; i < n; i++)
	{
		t = pow(x[i], 2) + pow(y[i], 2);
		if (t <= pow(d, 2))
		{
			sum ++;
		}
	}

	cout << sum;

  	return 0;
}

Measured memory_bytes: 10036
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = ~~arg[0].split(" ")[0];
    const B = ~~arg[0].split(" ")[1];
    
    if(A + B === 15) {
        console.log("+");
    } else if(A * B === 15) {
        console.log("*");
    } else {
        console.log("x");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int s = sc.nextInt();
      int[] a = new int[n];
      int inf = 1000000000;
      Arrays.fill(a,inf);
      if(s<inf){
        for(int i=0;i<k;i++)a[i]=s;
      }else{
        for(int i=0;i<n-k;i++)a[i]--;
      }
      System.out.print(a[0]);
      for(int i=1;i<n;i++)System.out.print(" "+a[i]);
      System.out.println("");
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 42412
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

ll N, K;
vector<ll> A(200010, 0);
vector<ll> arv(200010, 0);

int main() {
    cin >> N >> K;
    REP(i, 1, N + 1) cin >> A[i];

    //arv[Ai]はAi町の到着順がarv[Ai]であることを行っている
    ll cnt = 1;
    arv[1] = cnt;
    ll ind = 1;

    while (true) {
        //cnt番目に着く
        cnt++;
        if (arv[A[ind]] != 0) {
            //もう着いたことある
            //初めてでたのはarv[A[ind]]で二回目の順番はind
            break;
        }
        else {
            //次の場所を
            arv[A[ind]] = cnt;

            ind = A[ind];
            
            //cout << cnt << " " << ind << endl;
            
            
            if (cnt == K) {
                cout << A[ind] << endl;
                return 0;
            }
        }
    }
    K++;
    //cout << "cnt:" << cnt << endl;
    //cout << "arv:" << arv[A[ind]] << endl;
    ll T = cnt - arv[A[ind]];
    K -= arv[A[ind]];
    K %= T;
    K += arv[A[ind]];

    //cout << "K:" << K << endl;

    auto it = find(arv.begin(), arv.end(), K);
    auto wanted_index = distance(arv.begin(), it);
    cout << wanted_index << endl;

    //REP(i, 1, N + 1) {
    //    cout << A[i] << endl;
    //}
}

/*
4 2
2 3 4 2

1 2 3 4 2 3 4

T == 3
arv[A[ind]] == 2
cnt == 5

K == 1, 2, 3,...のとき
ans == 1, 2, 3, 4, 2, 3, 4

K -= arv[A[ind]];
K %= T;
K += arv[A[ind]];
*/

Measured memory_bytes: 6264
import java.util.Scanner;

public class Main {

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

		String S = sc.nextLine();
		int z = 0;
		int x = 0;
		for(int i = 0; i< S.length();i++) {
			if(S.charAt(i)=='0') z++;
			else if(S.charAt(i)=='1') x++;
		}
		System.out.println(Math.min(z, x)*2);

	}

}


Measured memory_bytes: 26296
#include<bits/stdc++.h>
using namespace std;
int k,x;
int main()
{
	cin>>k>>x;
	for(int i=k-1;i>=0;i--)
	printf("%d ",x-i);
	for(int i=1;i<=k-1;i++)
	printf("%d ",x+i);
	return 0;
}

Measured memory_bytes: 256