akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <map>
#include <deque>
#include <algorithm>
#include <set>
#include <string>
#include <math.h>
#include <stdio.h>
#include<iomanip>
#include <cstring>
#include <climits>

#define ll long long
#define p 1000000007
using namespace std;
//const ll MOD = (int) 10e9 + 7;

/*ll dp[100001];
vector<vector<ll>>adj;
ll dfs(ll node)
{
    if (dp[node] != -1)
        return dp[node];

    ll ans = 0;
    for (int i = 0; i < adj[node].size(); i++)
    {
        ans = max(dfs(adj[node][i]) + 1, ans);

    }
    return dp[node] = ans;
}
*/
ll dp[(int)(1<<21)];

ll help(ll mask, int man,const vector<vector<int>> &mp, int n)
{
    if (man >= n && (mask == (1 << n) - 1))
        return 1;
    else if (man >= n)
        return 0;

    if (dp[mask] != -1)
        return dp[mask];
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (mp[man][i] && !(mask & (1 << i))){
            ans += help(mask ^ (1 << i), man + 1, mp, n);
            ans %= p;
        }
    }
    return dp[mask] = ans;
}

ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;
    return  n * factorial(n - 1);
}

int main()
{
   // ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    ll n;
    cin >> n;
    vector<vector<int> >mp;
    for (int i = 0; i < n; i++)
    {
        vector<int>k;
        mp.push_back(k);
        for (int j = 0; j < n; j++)
        {
            ll d;
            cin >> d;
            mp[i].push_back(d);
        }
    }
    memset(dp, -1, sizeof(dp));
    cout << help(0, 0, mp, n);
    /*std::cout<<std::fixed;
    std::cout<<std::setprecision(10)<<ans;*/
             //   dp[i][i + 1 + j] = min(dp[i][i + j] + (pre[i + j + 2] - pre[i]),dp[i + 1][i + 1 + j] + (pre[i + j + 2] - pre[i]));

    return 0;
}


Measured memory_bytes: 16640
n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|s| (s.to_i)-1}
b=gets.chomp.split(" ").map{|s| s.to_i}
c=gets.chomp.split(" ").map{|s| s.to_i}
ans=0
for i in 0..n-2
  ans+=c[a[i]] if a[i+1]-a[i]==1
end
ans+=b.inject(:+)
p ans

Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n,m;cin>>n;){
		vi ss(n),ls(n),ps(n);
		rep(i,n) cin>>ss[i]>>ls[i]>>ps[i];
		cin>>m;
		vi ws(m);
		rep(i,m) cin>>ws[i];
		
		vi dp(394,-1); dp[0]=0;
		rep(i,n) repi(j,ss[i],ls[i]+1) repi(k,j,394){
			if(dp[k-j]==-1) continue;
			dp[k]=max(dp[k],dp[k-j]+ps[i]);
		}
		
		vi res;
		for(int w:ws){
			if(dp[w]==-1){res.assign(1,-1); break;}
			else          res.push_back(dp[w]);
		}
		rep(i,res.size())
			cout<<res[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1228
# 2019-11-17 10:52:21(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    s, t = [s.rstrip() for s in sys.stdin.read().split()]
   
    for l in set(t):
        if not l in s:
            print(-1)
            sys.exit()

    count = 0
    l = 0
    i = 0
    current = t[i]
    all_found = False
    while not all_found:
        j = s.find(current, l, len(s))
        if j == -1:
            count += len(s)
            l = 0
        else:
            if i == len(t) - 1:
                count += j + 1
                all_found = True
            else:
                if j == len(s) - 1:
                    count += len(s)
                    l = 0
                else:
                    l = j + 1
                i += 1
                current = t[i]
    print(count)



if __name__ == "__main__":
    main()


Measured memory_bytes: 3504
// Last Change: 03/29/2019 13:35:59.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N;
  cin >> N;

  ll cnt = 0;
  ll tmpN = N;
  while (tmpN > 0) {
    cnt += tmpN % 10;
    tmpN /= 10;
  }

  if (N % cnt == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  //NS::LoopUntilZeroInpput();
}



Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    char[] c=sc.next().toCharArray();
    int ans=0;
    for(int i=0;i<c.length/2;i++){
      if(c[i]!=c[c.length-1-i]){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<int,int> F;
void f(int n){
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            F[i]++;
            n/=i;
        }
    }
    if(n!=1){F[n]++;}
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,ans=0,c14=0,c74=0,c2=0,c4=0,c24=0;cin>>n;
    for(int j=2;j<=n;j++){
        f(j);
    }
    for(auto m:F){
        if(m.second>=74){ans++;}
    }
    for(auto m:F){
        if(m.second>=24){c24++;}
        else if(m.second>=14){c14++;}
        else if(m.second>=4){c4++;}
        else if(m.second>=2){c2++;}
    }
    int a=c24+c14+c4+c2,b=c4+c14+c24,c=c24,d=c24+c14;;
    //cout<<a<<' '<<b<<' '<<c<<' '<<c2<<endl;
    ans+=c*(a-1)+b*(b-1)*(a-2)/2+d*(b-1);
    cout<<ans;
    //ans+=(c4*(c4-1)*(c4-2))+c4*(c4-1)*c2+c24*(c24-1)*(c24-2);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    ll n; cin>>n;
    int ans=100;
    for(ll i=1;i*i<=n;i++){
        if(n%i!=0)continue;
        ll a=i;
        ll b=n/a;
        int tmp=0;
        while(a>0||b>0){
            a/=10;
            b/=10;
            tmp++;
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import static java.lang.Math.*;

import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				if(n == 0)break;
				int[] data = new int[n];
				for(int i = 0 ; i < data.length;i++){
					data[i] = scan.nextInt();
				}
				double ave = ave(data);
				double alpha = 0;
				for(int i = 0 ; i < n;i++){
					alpha += pow((data[i] - ave),2) / n;
				}
				alpha =Math.sqrt(alpha);
				System.out.println(alpha);
			}
		}finally{
			if(scan!=null)scan.close();
		}
	}
	public static double ave (int [] data){
		double sum = 0;
		for(int i = 0 ; i < data.length;i++){
			sum += data[i];
		}
		return sum / data.length;
	}
}

Measured memory_bytes: 23768
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  case class Shop(price: Int, limit: Int)

  val n, m = sc.nextInt
  val shops = Array.fill(n)(Shop(sc.nextInt, sc.nextInt)).sortBy(_.price)

  println(shops.foldLeft((0L, m.toLong)){case ((a, rem), s) =>
    val buy = Math.min(rem, s.limit)
    (a + buy * s.price, rem - buy) 
  }._1)
}

Measured memory_bytes: 73652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<ll>A,B,C;
	for(ll i=0;i<a;i++){
		ll now;
		cin>>now;
		A.push_back(now);
	}
	for(ll i=0;i<b;i++){
		ll now;
		cin>>now;
		B.push_back(now);
	}
	for(ll i=0;i<c;i++){
		ll now;
		cin>>now;
		C.push_back(now);
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	priority_queue<ll>qa,qb;
	for(ll i=0;i<x;i++){
		qa.push(-1*A[a-i-1]);
	}
	for(ll i=0;i<y;i++){
		qb.push(-1*B[b-i-1]);
	}
	for(ll i=0;i<c;i++){
		ll now=-1*C[i];
		ll nowa=qa.top();
		ll nowb=qb.top();
		if(nowa<nowb){
			if(now<nowb){
				qb.pop();
				qb.push(now);
			}
		}
		else{
			if(now<nowa){
				qa.pop();
				qa.push(now);
			}
		}			
	}

	ll ans=0;
	while(qa.size()!=0){
		ll now=qa.top();
		qa.pop();
		ans+=now;
//		cout <<now<<endl;
	}
//	cout <<endl;
	while(qb.size()!=0){
		ll now=qb.top();
		qb.pop();
		ans+=now;
//		cout <<now<<endl;
	}
//	cout <<endl;
	cout <<abs(ans);
	// your code goes here
	return 0;
}

Measured memory_bytes: 4852
# ABC88 D問題
from collections import deque
import sys
import math
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

H,W=na()
f = [input() for i in range(H)]
#print(f)

def bfs():
    Q=deque([(0,0,1)])
    visited = [[False] * W for _ in range(H)]
    while Q:
        h,w,d = Q.popleft()
        if(h==H-1 and w==W-1):
            return d
        #d = [[1,0],[-1,0],[0,1],[0,-1]]
        if visited[h][w]:
            continue
        visited[h][w] = True
        if h > 0 and f[h - 1][w] == '.':
            Q.append((h - 1, w, d + 1))
        if h < H - 1 and f[h + 1][w] == '.':
            Q.append((h + 1, w, d + 1))
        if w > 0 and f[h][w - 1] == '.':
            Q.append((h, w - 1, d + 1))
        if w < W - 1 and f[h][w + 1] == '.':
            Q.append((h, w + 1, d + 1))
    else:
        return -1

#幅優先で迷路を解く
#H*W-(最短経路長)-(黒いマス)が答え
black_sum=0
for i in range(H):
    black_sum+=f[i].count("#")
#print(black_sum)

res=bfs()
if(res==-1):
    print(res)
else:
    print(H*W-res-black_sum)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ma = max(a*c,a*d);
    ll mb = max(b*c,b*d);
    cout << max(ma,mb) << endl;
}

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

int main(){
	int n,k;
	cin >> n >> k;
	
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	
	int res = 0;
	
	for(int i = 0; i <= min(n,k); i++){
		for(int j = 0; j <= min(n,k)-i; j++){
			// (Aの回数,Bの回数) = (i,j)
			priority_queue<int, vector<int>, greater<int>> have; // 手持ちの石を昇順に整理
			
			for(int l = 0; l < i; l++) have.push(v[l]); // A
			for(int l = 0; l < j; l++) have.push(v[n-1-l]); // B
			
			for(int l = 0; l < k-(i+j); l++){
				if(!have.empty() && have.top() < 0) have.pop(); //負の石が手元にあればC
			}
			
			int cnt = 0;
			while(!have.empty()){
				cnt += have.top();
				have.pop();
			}
			
			res = max(res,cnt);
		}
	}
	
	cout << res << endl;
	return 0;
}

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


class UnionFind{
  public:
    vector<int> rank, parent;
    
    UnionFind(){}
    UnionFind(int size){
      rank.resize(size, 0);
      parent.resize(size, 0);
      for(int i = 0; i < size; i++) make_new_set(i);
    }

    void make_new_set(int x){
      rank[x] = 0;
      parent[x] = x;
    }

    int find_root(int x){
      if(parent[x] == x) return x;
      return parent[x] = find_root(parent[x]);
    }

    bool same(int x, int y){
      return find_root(x) == find_root(y);
    }

    void unite(int x, int y){
      int root_of_x = find_root(x);
      int root_of_y = find_root(y);

      if(x == y) return;

      if(rank[root_of_x] < rank[root_of_y]){
        parent[root_of_x] = root_of_y;
      }else{
        parent[root_of_y] = root_of_x;
        if(rank[root_of_x] == rank[root_of_y]) rank[root_of_x]++;
      }
    }
};

int main(void){
  ios_base::sync_with_stdio(0);
  int n, a, b, q;
  int t;
  cin >> n >> q;
  UnionFind uf = UnionFind(n);
  for(int i = 0; i < q; i++){
    cin >> t >> a >> b;
    if(t == 0) uf.unite(a, b);
    else if(t == 1){
      if(uf.same(a, b)) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }
  return 0; 
}

Measured memory_bytes: 1288
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextIntSlice(size int) []int {
	re := make([]int, size)
	for i := 0; i < size; i++ {
		re[i] = nextInt()
	}
	return re
}

func max(a ...int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func pow(x, n int) int {
	ans := 1
	for i := 0; i < n; i++ {
		ans *= x
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	ans := 1
	for i := 1; i <= n; i++ {
		ans *= i
		ans = ans % (pow(10, 9) + 7)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
//abc107_a.cpp
//Sat Aug 25 20:19:48 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	cout << n-m+1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
using namespace std;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> k(10001);
  for(int i=0;i<n;i++)
    cin >> a[i];

  for(int i=0;i<n;i++){
    k[a[i]]++;
  }
  for(int i=1;i<k.size();i++){
    k[i] += k[i-1];
  }

  for(int i=n-1;i>=0;i--){
    b[k[a[i]]-1] = a[i];
    k[a[i]]--;
  }

  for(int i=0;i<n;i++){
    cout << b[i];
    if(i != n-1)
      cout << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 16856
N=int(input())
a=list(map(int,input().split()))
c=[0,0,0,0,0,0,0,0]
r=0
ans=0
for i in a:
    if i <400:
        c[0] += 1
    elif i>=400 and i<800:
        c[1] += 1
    elif i>=800 and i<1200:
        c[2] += 1
    elif i>=1200 and i<1600:
        c[3] += 1
    elif i>=1600 and i<2000:
        c[4] += 1
    elif i>=2000 and i<2400:
        c[5] += 1
    elif i>=2400 and i<2800:
        c[6] += 1
    elif i>=2800 and i<3200:
        c[7] += 1
    else:
        r += 1
for i in c:
    if i>0:
        ans += 1

if ans==0:
    print(1,r)
else:
    print(ans,ans+r)

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

int main() {
 string a, b;
 cin >> a >> b ;
 int A,B;
 if(a.size() > b.size()) cout << "GREATER" << endl;
  else if (a.size() < b.size()) cout << "LESS" << endl;
  else {
    a = a.at(0);
    b = b.at(0);
    A = stoi (a);
    B = stoi (b);
    if(A > B) cout << "GREATER" << endl;
    if (A < B) cout << "LESS" << endl;
    if (A == B) cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        s: chars,
    }

    let mut ans = 0;

    for i in 0..n - 2 {
        if s[i..i + 3] == ['A', 'B', 'C'] {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

string line;
int cnt[10];

bool isOk(int *ccnt)
{
  REP(i,1,10)
    {
      if(ccnt[i] == 0)continue;
      if(ccnt[i] == 1)
	{
	  if(i+2 <= 9 && ccnt[i]-1 >= 0 && ccnt[i+1]-1 >= 0 && ccnt[i+2]-1 >= 0)
	    {
	      ccnt[i]--,ccnt[i+1]--,ccnt[i+2]--;
	    }
	}
      else if(ccnt[i] == 2)
	{
	  if(i+2 <= 9 && ccnt[i]-2 >= 0 && ccnt[i+1]-2 >= 0 && ccnt[i+2]-2 >= 0)
	    {
	      ccnt[i]-=2,ccnt[i+1]-=2,ccnt[i+2]-=2;
	    }
	}
      else if(ccnt[i] == 3)
	{
	  ccnt[i] -= 3;
	}
      else if(ccnt[i] == 4)
	{
	  if(i+2 <= 9 && ccnt[i]-1 >= 0 && ccnt[i+1]-1 >= 0 && ccnt[i+2]-1 >= 0)
	    {
	      ccnt[i]-=4,ccnt[i+1]--,ccnt[i+2]--;
	    }
	}
      if(ccnt[i] != 0)return false;
    }
  return true;
}

bool check(int piece)
{
  cnt[piece]++;
  int ccnt[10];
  REP(i,1,10)
    {//頭を決める
      if(cnt[i] <= 1)continue;
      rep(j,10)ccnt[j] = cnt[j];
      ccnt[i] -= 2;
      if(isOk(&ccnt[0]))
	{
	  cnt[piece]--;
	  return true;
	}
    }
  cnt[piece]--;
  return false;
}

void compute()
{
  rep(i,10)cnt[i] = 0;
  rep(i,13)cnt[line[i]-'0']++;
  bool ok = false;
  REP(i,1,10)
    {
      if(cnt[i]+1 >= 5)continue;

      if(check(i))
	{
	  if(ok)cout << " ";
	  ok = true;
	  cout << i;
	}
    }
  if(!ok)cout << 0 << endl;
  else   cout << endl;
}

int main()
{
  while(cin >> line)
    compute();    
  return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef  long long ll;
const int maxn=2e5+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;


int main()
{
    int n;
    cin>>n;
    int sign=0;
    int num=0;
    for(int i=1;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
        {
            num++;
            if(num>=3) sign=1;
        }
        else
        {
            num=0;
        }
    }
    if(sign) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007
typedef pair<int,int> P;

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n;
    cin >> n;
    vector<P> a(n);
    rep(i,n){
        cin >> a[i].second >> a[i].first;
    }
    sort(a.begin(),a.end());
    ll total=0;
    string ans="Yes";
    for(ll i=0;i<n;i++){
        total+=a[i].second;
        if(total>a[i].first) ans="No";
    }
    cout << ans << endl;
    
    return 0;
}











Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {

    int a, p;
    cin >> a >> p;

    int s;
    s = a*3 + p;

    cout << s/2 << endl;

}

Measured memory_bytes: 764
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int w, h;
	int[][] map;
	void run() {
		Scanner sc = new Scanner(System.in);
		for (;;) {
			h = sc.nextInt(); w = sc.nextInt();
			if ((h|w) == 0) break;
			map = new int[h+10][w+10];
			for (int[] a: map) fill(a, 0);
			for (int i=0;i<h;i++) {
				String l = sc.next();
				for (int j=0;j<w;j++) {
					if (l.charAt(j) == '#') map[i+3][j+3] = 1;
					if (l.charAt(j) == '@') map[i+3][j+3] = 2;
					if (l.charAt(j) == '*') map[i+3][j+3] = 3;
				}
			}
			int cnt = 0;
			for (short i=0;i<h+10;i++) for (short j=0;j<w+10;j++) if (map[i][j] != 0) {
				dfs(j, i);
				cnt++;
			}
			System.out.println(cnt);
		}
	}

	int[] dx = {-1,0,1,0};
	int[] dy = {0,-1,0,1};
	void dfs(int x, int y) {
		int tmp = map[y][x];
		LinkedList<Integer> sx = new LinkedList<Integer>();
		LinkedList<Integer> sy = new LinkedList<Integer>();
		sx.add(x);sy.add(y);
		map[y][x] = 0;
		while (!sx.isEmpty()) {
			int cx = sx.removeLast(), cy = sy.removeLast();
			for (int i=0;i<4;i++) if (map[cy+dy[i]][cx+dx[i]] == tmp) {
				sx.add(cx + dx[i]); sy.add(cy + dy[i]);
				map[cy+dy[i]][cx+dx[i]] = 0;
			}
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

int main()
{
    string S;
    cin >> S;
    int N = S.length();
    int n0 = 0, n1 = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] != (i % 2 == 0 ? '0' : '1')) {
            n0++;
        }
        if (S[i] != (i % 2 == 0 ? '1' : '0')) {
            n1++;
        }
    }

    cout << min(n0, n1);
    return 0;
}



Measured memory_bytes: 512
struct B{int w,s,v;}A[1111];
r;
comp(a,b)struct B*a,*b;{r=a->w+a->s-b->w-b->s;}
n,i,j;
long dp[22222],ans;
main(){
	scanf("%d",&n);
	for(;~scanf("%ld%ld%ld",&A[i].w,&A[i].s,&A[i].v);i++);
	qsort(A,n,sizeof(struct B),comp);
	for(i=0;i<n;i++)
	{
		for(j=A[i].s;j>=0;)ans=fmax(ans,dp[j+A[i].w]=fmax(dp[j--+A[i].w],dp[j]+A[i].v));
	}
	printf("%ld",ans);
}


Measured memory_bytes: 380
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
	int n;
	cin>>n;
	vector<int> a(n),b(n);
	int as=0,bs=0;
	for(int &i:a)cin>>i,as+=i;
	for(int &i:b)cin>>i,bs+=i;

	int k=bs-as;int tmp=0;
	for(int i=0;i<n;i++)
		if(a[i]<b[i])tmp+=(b[i]-a[i]+1)/2;
	if(tmp<=k)puts("Yes");
	else puts("No");

}


Measured memory_bytes: 3776
#include <stdio.h>

int main()
{
        int a,b,n;
        int sum, i;

        while( scanf( "%d%d%d", &a, &b, &n ) == 3 ){
                sum = 0;
                a = a % b;
                for ( i = 0 ; a > 0 && i < n ; i++ ) {
                        a = a * 10;
                        sum = a / b + sum;
                        a = a % b;
                }
                printf( "%d\n", sum );
        }
        return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<char> t, d;

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

    REP(i,q) {
        char tt, td;
        cin>>tt>>td;
        t.push_back(tt);
        d.push_back(td);
    }

    int l = 0, r = n, mid, lp, rp;
    while(l != r - 1) {
        mid = (l + r) / 2;
        lp = mid;
        REP(i,q) {
            if (t[i] == s[lp]) {
                if (d[i] == 'L') {
                    lp--;
                } else {
                    lp++;
                }
            }
            if (lp == -1 || lp == n) {
                break;
            }
        }
        if (lp == -1) {
            l = mid;
        } else {
            r = mid;
        }
    }
    lp = l;
    l = 0, r = n;
    while(l != r - 1) {
        mid = (l + r) / 2;
        rp = mid;
        REP(i,q) {
            if (t[i] == s[rp]) {
                if (d[i] == 'L') {
                    rp--;
                } else {
                    rp++;
                }
            }
            if (rp == -1 || rp == n) {
                break;
            }
        }
        if (rp == n) {
            r = mid;
        } else {
            l = mid;
        }
    }
    rp = r;
    cout<<rp - lp - 1<<endl;

    return 0;
}


Measured memory_bytes: 1024
struct Problem {
    n: u64,
    a: u64,
    b: u64,
}

impl Problem {
    fn read() -> Problem {
        let mut input = String::with_capacity(100);
        std::io::stdin().read_line(&mut input).ok();
        let input: Vec<u64> = input
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect();
        let n: u64 = input[0];
        let a: u64 = input[1];
        let b: u64 = input[2];
        Problem { n: n, a: a, b: b }
    }
    fn solve(&self) -> u64 {
        let n = self.n;
        let a = self.a;
        let b = self.b;
        if (b - a) % 2 == 0 {
            (b - a) / 2
        } else if a - 1 <= n - b {
            (a + b - 1) / 2
        } else {
            n - (a + b - 1) / 2
        }
    }
}

fn main() {
    println!("{}", Problem::read().solve())
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
typedef pair<ll,ll> P;
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
#define modinv(a,b) modpow((a),(b)-2,(b))
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,zero=0;
  ll a[LIMIT2]={0},b[LIMIT1]={0};
  string s;
  map<P,ll> dp;
  map<P,bool> ok;
  ll az=0,bz=0;
  
  cin >> n;
  rep(i,n){
    cin >> a[i] >> b[i];
    if(a[i]==0 && b[i]==0){
      zero++;
    }else if(a[i]==0){
      dp[{0,1}]++;
    }else if(b[i]==0){
      dp[{-1,0}]++;
    }else{
      ll tmp = gcd(a[i],b[i]);
      a[i] /= tmp;
      b[i] /= tmp;
      if(b[i]>0){
        dp[{a[i],b[i]}]++;
      }else{
        dp[{-a[i],-b[i]}]++;
      }
    }
  }
  result = 1;
  for(const auto& [key, value] : dp){
    ll tmp=1;
    if(ok.count(key)) continue;
    P key2 = P(-key.second,key.first);
    if(key2.second<0){
      key2.first *= -1;
      key2.second *= -1;
    }
    
    ll value2 = (dp.count(key2) ? dp[key2] : 0);
    //cout << key.first << " " << key.second << " " << value << " " << value2 << endl;
    tmp += modpow(2,value,MOD1)-1;
    tmp += modpow(2,value2,MOD1)-1;
    tmp %= MOD1;
    result *= tmp;
    result %= MOD1;
    
    ok[key]=true;
    ok[key2]=true;
  }
  
  result += (zero-1+MOD1)%MOD1;
  result %= MOD1;
  
  cout << result << endl;
  
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());    
    if(a.back()==0){
        for(int i=0;i<n;i++) cout<<0<<endl;
        return 0;
    }
    vector<int> b;
    int zcnt=0;
    int ocnt=0;
    int minv=-1;
    for(int i=0;i<n;i++){
        if(a[i]==0){
            zcnt++;
        }
        else if(a[i]==1){
            ocnt++;
        }
        else{
            b.push_back(a[i]);
        }
    }
    int gisei=-1;
    if(zcnt%2==1){
        if(ocnt){
            gisei=1;
            ocnt--;
        }
        else if(b.size()>=1){
            gisei=b[0];
            reverse(b.begin(),b.end());
            b.pop_back();
            reverse(b.begin(),b.end());
        }
    }
    
    if(b.size()>=2 && b.back()==3 && *(++b.rbegin())==2){
        for(int i=0;i<b.size()-2;i++){
            cout<<b[i]<<endl;
        }        
        cout<<b.back()<<endl;
        cout<<*(++b.rbegin())<<endl;
    }
    else{
        for(int i=0;i<b.size();i++){
            cout<<b[i]<<endl;
        }
    }
    while(zcnt>=2) cout<<0<<endl,zcnt--;
    if(gisei!=-1) cout<<gisei<<endl;
    while(zcnt) cout<<0<<endl,zcnt--;
    while(ocnt) cout<<1<<endl,ocnt--;
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int N, tmp;
    cin >> N;
    long long int count = 0;
    vector <long long int> monsters(N+1);
    vector <long long int> heros(N);

    for(long long int i=0; i<N+1; i++){
        cin >> monsters[i];
    }
    for(long long int i=0; i<N; i++){
        cin >> heros[i];
    }

    for(long long int i=0; i<N; i++){
        if(monsters[i] >= heros[i]){
            //tmp = monsters[i] - heros[i];
            count += heros[i];
        }
        else{
            tmp = monsters[i];
            count += tmp;
            int yoriki = heros[i] - tmp;
            if(monsters[i+1] > yoriki){
                tmp = monsters[i+1] - yoriki;
                count += yoriki;
                monsters[i+1] = tmp;
            }
            else{
                tmp = monsters[i+1];
                count += tmp;
                monsters[i+1] = 0;
            }
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1792
def main():

    N = int(input())
    A = list(map(int, input().split()))
    if 0 in A: return 0
    A.sort()
    u = 1
    bound = pow(10, 18)
    for v in A:
        u *= v
        if u > bound:
            return -1
    return u

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 84640
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int n,m;vector<vector<int>> v(100001);
int dp[100001];
/*


 */
int dfs(int n){
    if(dp[n]>0)  return dp[n];
    int ret=0;
    for(int i=0;i<v[n].size();i++){
        //max(dfs(v all))
        ret=max(dfs(v[n][i])+1,ret);
    }   
    dp[n]=ret;
    return ret;
}

int main(){
    cin>>n>>m;
    rep(i,n)    dp[i]=-1;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
    }
    int ans=0;
    rep(i,n){
        ans=max(ans,dfs(i));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=3e3+2,Mod=1e9+7;
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
double a[N],dp[N][N];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  dp[1][0]=1-a[1],dp[1][1]=a[1];
  for(int i=2;i<=n;i++) for(int j=0;j<=i;j++)
  dp[i][j]=(1-a[i])*dp[i-1][j]+a[i]*dp[i-1][j-1];
  double ans=0;
  for(int i=n/2+1;i<=n;i++) ans+=dp[n][i];
  printf("%.10lf\n",ans);
  return 0;
}


Measured memory_bytes: 68992
package main

import (
	"fmt"
	"go/token"
	"go/types"
	"strconv"
)

func main() {
	var S string
	fmt.Scan(&S)

	l := len(S)

	total := 0
	for i := 0; i < (1 << uint(l-1)); i++ {
		formula := string(S[0])
		for j := 0; j < (l - 1); j++ {
			if i&(1<<uint(j)) > 0 {
				formula += "+"
			}
			formula += string(S[j+1])
		}
		res, err := types.Eval(token.NewFileSet(), nil, token.NoPos, formula)
		if err != nil {
			panic(err)
		}
		sum, err := strconv.Atoi(res.Value.String())
		if err != nil {
			panic(err)
		}
		total += sum
	}
	fmt.Println(total)
}


Measured memory_bytes: 2560
from collections import deque

n, m = map(int, input().split())
eg = [[] for _ in range(n + 1)]

al = [0] * m
bl = [0] * m

for i in range(m):
    a, b = map(int, input().split())
    eg[a].append(b)
    eg[b].append(a)
    al[i], bl[i] = a, b

ans = 0
for i in range(m):
    x, y = al[i], bl[i]
    q = deque()
    q.append(1)
    seen = {1}
    while q:
        v = q.pop()
        for t in eg[v]:
            if t in seen:
                continue
            elif (v == x and t == y) or (v == y and t == x):
                continue
            q.append(t)
            seen.add(t)
    if len(seen) != n:
        ans += 1
print(ans)


Measured memory_bytes: 70564
function Main(input) {
  input = input.split(' ')
  var A = parseInt(input[0])
  var B = parseInt(input[1])

  if (A <= 8 && B <= 8) {
    console.log('Yay!')
  } else {
    console.log(':(')
  }
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.HashSet


fun main(args: Array<String>) {
    val (n, k) = getInts()
    val s = HashMap<Int, MutableSet<Int>>()

    repeat(k) {
        val (a, b) = getInts()
        if (s[a] == null) s[a] = HashSet()
        if (s[b] == null) s[b] = HashSet()
        s[a]!!.add(b)
        s[b]!!.add(a)
    }
    val out = IntArray(n + 1) { 0 }

    val q: Queue<Int> = LinkedList()
    q.add(1)
    var c = 0
    while (c < n - 1 && q.isNotEmpty()) {
        val now = q.poll()
        s[now]?.forEach {
            if (out[it] == 0 && it != 1) {
                out[it] = now
                c++
                q.add(it)
            }
        }
    }

    if (c == n - 1) {
        println("Yes")
        println(out.drop(2).joinToString("\n"))
    } else {
        println("No")
    }
}


fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }
fun getLong() = readLine()!!.toLong()
fun getLongs() = readLine()!!.split(" ").map { it.toLong() }


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

using namespace std;

int main(){
 int k,t; 
  cin >> k >> t;
  
 int a;
 int largest=0;
  for(int i=0;i<t;i++){
  cin >> a;
   largest=max(largest,a);
    
  }
  cout << max(2*largest-1-k,0) << endl;
   
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B,C=map(int,input().split())
    l=[int(input()) for _ in range(N)]
    ps=itertools.permutations(l)
    ans=INF
    for p in ps:
        S=[0]*(N+1)
        for i in range(N):
            S[i+1]=S[i]+p[i]
        for i in range(N-2):
            for j in range(N-1-(i+1)):
                for k in range(N-(i+1)-(j+1)):
                    tmp=0
                    a=S[i+1]
                    b=S[i+1+j+1]-S[i+1]
                    c=S[i+1+j+1+k+1]-S[i+1+j+1]
                    tmp=(i+j+k)*10+abs(A-a)+abs(B-b)+abs(C-c)
                    ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


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

using namespace std;

#define REP(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;


int N, M;
vector<vector<pair<int, int>>> conds;

const int64_t MOD = 1e9+7;

int DP[305][305][305];
bool DONE[305][305][305];

int ways(int r, int b, int g) {
	if (DONE[r][b][g])
		return DP[r][b][g];
	DONE[r][b][g] = 1;
	int i = max(r, g);
	i = max(i, b);
	++i;
	bool ok = 1;
	for (const auto& cond : conds[i-1]) {
		int l, c;
		tie(l, c) = cond;
		int cc = 0;
		if (r >= l)
			++cc;
		if (b >= l)
			++cc;
		if (g >= l)
			++cc;
		if (c != cc) {
			ok = 0;
			break;
		}
	}
	if (!ok)
		return DP[r][b][g] = 0;
	if (i == N+1)
		return DP[r][b][g] = 1;
	int64_t ans = ways(i, b, g);
	ans %= MOD;
	ans += ways(r, i, g);
	ans %= MOD;
	ans += ways(r, b, i);
	ans %= MOD;
	return DP[r][b][g] = ans;

}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	conds.resize(N+1);
	REP(i, M) {
		int l, r, x;
		cin >> l >> r >> x;
		conds[r].emplace_back(l, x);
	}

	cout << ways(0, 0, 0) << endl;
}

Measured memory_bytes: 137472
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXX=2*MAXN+2;

int n;
int a[MAXN]; int asum;
int b[MAXN]; int bsum;

int aa[MAXN+1];
int bb[MAXN+1];

int x[MAXX],nx;
int par[MAXX],sz[MAXX];
int find(int z) { if(par[z]==z) return z; return par[z]=find(par[z]); }
void unite(int a,int b) { a=find(a); b=find(b); if(a==b) return; if(sz[a]<sz[b]) swap(a,b); par[b]=a; sz[a]+=sz[b]; }


int solve() {
	asum=0; REP(i,n) asum^=a[i]; REP(i,n) aa[i]=a[i]; aa[n]=asum; sort(aa,aa+n+1);
	bsum=0; REP(i,n) bsum^=b[i]; REP(i,n) bb[i]=b[i]; bb[n]=bsum; sort(bb,bb+n+1);
	REPE(i,n) if(aa[i]!=bb[i]) return -1;
	nx=0; REPE(i,n) x[nx++]=aa[i]; REPE(i,n) x[nx++]=bb[i]; sort(x,x+nx); nx=unique(x,x+nx)-x;
	REP(i,nx) par[i]=-1,sz[i]=-1;
	int ndiff=0;
	REPE(i,n) {
		int ax=lower_bound(x,x+nx,i==n?asum:a[i])-x;
		int bx=lower_bound(x,x+nx,i==n?bsum:b[i])-x;
		if(i!=n) {
			if(ax==bx) continue;
			++ndiff;
		}
		if(par[ax]==-1||sz[ax]==-1) par[ax]=ax,sz[ax]=1;
		if(par[bx]==-1||sz[bx]==-1) par[bx]=bx,sz[bx]=1;
		unite(ax,bx);
	}
	int ncomp=0;
	REP(i,nx) if(par[i]==i) ++ncomp;
	if(ncomp==0) return 0;
	return ndiff+ncomp-1;
}


void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]); REP(i,n) scanf("%d",&b[i]);
	printf("%d\n",solve());
}

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


Measured memory_bytes: 3328
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i,n) for(int (i)=0, i##_len = (n);(i)<i##_len;(i)++)
#define reps(i,x) for(int (i)=1;(i)<=(int)(x);(i)++)
#define rrep(i,x) for(int (i)=((int)(x)-1);(i)>=0;(i)--)
#define rreps(i,x) for(int (i)=((int)(x));(i)>0;(i)--)
#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1)<<(n))
#define all(x) (x).begin(),(x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl 
#define nint int
using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
typedef pair<int,int> pii;
typedef pair<double,double> dop;
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;



signed main()
{
std::vector<int> a(4,0);
for(int i = 0; i < 3; i++){
    int x,y;
    std::cin >> x >> y;
    x--;
    y--;
    a[x]++;
    a[y]++;
}
int flag = 0;
for(int i = 0; i < 4; i++){
    if(a[i] >= 3 || a[i] == 0){
        flag = 1;
        break;
    }
}
if(flag){
    std::cout << "NO" << std::endl;
} else {
    std::cout << "YES" << std::endl;
}
return 0;
}

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

using namespace std;

int main() {
	vector<int> f(200000, 0);
	f[0] = f[1] = 1;
	for (int i = 2; i*i < 200000; i++) {
		if (f[i] == 0) {
			for (int j = 2; i*j < 200000; j++) {
				f[i*j] = 1;
			}
		}
	}
	vector<int> ff;
	for (int i = 0; i < 200000; i++) {
		if (f[i] == 0) {
			ff.push_back(i);
		}
	}
	int n, p;
	while (cin >> n >> p) {
		if (n == -1 && p == -1) {
			break;
		}
		vector<int>::iterator ite = upper_bound(ff.begin(), ff.end(), n);
		vector<int>::iterator ite2 = ite;
		vector<int> aa;
		for (int i = 0; i < 100; i++) {
			vector<int>::iterator ite3 = ite;
			for (int j = 0; j < 100; j++) {
				aa.push_back(*(ite)+*(ite3));
				ite3++;
			}
			ite++;
		}
		sort(aa.begin(), aa.end());
		cout << aa[p - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3876
#include<iostream>
using namespace std;
#include<string>
int main() {
           string s;
           getline(cin,s);
           for(int i=0;i<s.length();i++){
                   if(i==0){
                         cout<<s[0];
                          }
                   if(s[i]==' ') {
                          cout<<s[i+1];
                          }
}
} 

Measured memory_bytes: 256
import sys
#from collections import defaultdict
sys.setrecursionlimit(10**6)

def input():
	return sys.stdin.readline()[:-1]
n, l = map(int, input().split())
ss = [list(input())[::-1] for _ in range(n)]

def addTree(tree, sentence):
	if not sentence:
		return None   

	if sentence[-1] not in tree:
		tree[sentence[-1]] = {}

	p = sentence.pop()
	tree[p] = addTree(tree[p], sentence)

	return tree

def createTree(sentences):    
	tree = {}
	for sentence in sentences:
		tree = addTree(tree, sentence)

	return tree

tree = createTree(ss)
#print(tree)

grundy = 0
def dfs(cur, level):
	global grundy
	if cur is None:
		return
	elif len(cur) == 1:
		grundy ^= (l-level) & (-l+level)
	for k in cur.keys():
		dfs(cur[k], level+1)
	return
	
dfs(tree, 0)

if grundy == 0:
	print("Bob")
else:
	print("Alice")


Measured memory_bytes: 207128
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

H,W=get_i
s=array(H)
H.times do|i|
  s[i]=get_nsp
end
Direct=[[1,0],[0,1],[-1,0],[0,-1]]
def bfs(map,s)
  cost=array(W,-1,H)
  que=[]
  que.push(s)
  cost[s[1]][s[0]]=0
  until que==[]
    p=que.shift
    Direct.each do|x,y|
        nx=p[0]+x
        ny=p[1]+y
        next unless nx.between?(0,W-1) and ny.between?(0,H-1) and map[ny][nx]=="." and cost[ny][nx]==-1
        cost[ny][nx]=cost[p[1]][p[0]]+1
        que.push([nx,ny])
    end
  end  
  return cost.flatten.max
end
ans=0
H.times do|i|
    W.times do|j|
        if s[i][j]=="."
            val=bfs(s,[j,i])
            ans=val if ans<val
        end
    end
end
puts ans

Measured memory_bytes: 1916
#include<iostream>
#include<queue>
#include<algorithm>
#include<utility>
#include<cmath>
#include<string>
#include<tuple>
 
using namespace std;
 
const int maxn = 1e2 + 5;
const double eps = 1e-8;
int n, w, b[maxn];
pair<int, int> a[maxn];
int ans = 0;
 
double h(int idx, long long wt) {
	long long curw = wt;
	int curv = 0;
	for(int i = idx + 1; i <= n; i++) {
		long long diff = w - curw;
		if(diff >= a[i].first) {
			curv += a[i].second;
			curw += a[i].first;
		} else {
			curv += ((double) a[i].second) / a[i].first * diff;
			break;
		}
	}
	return curv;
}
 
int bab() {
	priority_queue< tuple<double, int, long long, int> > pq;
	pq.push({-1, 0, 0, 0});
	while(!pq.empty()) {
		auto e = pq.top();
		pq.pop();
		int ev = get<1>(e); long long ew = get<2>(e); int ei = get<3>(e);
		bool leaf = true;
		for(int i = ei + 1; i <= n; i++) {
			leaf = false;
			double cv = ev + a[i].second + h(i, ew + a[i].first);
			if(ew + a[i].first <= w && cv > ans) {
				pq.push({cv, ev + a[i].second, ew + a[i].first, i});
				ans = max(ans, ev + a[i].second);
			}
		}
		if(fabs(get<0>(e) - ev) < eps) break;
	}
	return ans;
}
 
bool cmp(pair<int, int> &i, pair<int, int> &j) {
	return ((double) i.second) / i.first > ((double) j.second) / j.first;
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> w;
	for(int i = 1; i <= n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a + 1, a + 1 + n, cmp);
    long long curw = 0; int curv = 0;
	for(int i = 1; i <= n; i++) {
		long long diff = w - curw;
		if(diff >= a[i].first) {
			curv += a[i].second;
			curw += a[i].first;
		} else {
			ans = max(curv, a[i].second);
			break;
		}
	}
    ans = max(ans, curv);
	cout << bab() << endl;
	return 0;
}

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


Arare = input().split()
#print(Arare)
#print(Arare.count('Y'))
print ('Four' if Arare.count('Y') > 0 else 'Three' )

def another():
    is_four = False
    for ai in Arare:
        if ai == 'Y':
            is_four = True
            break

    print( 'Four' if is_four else 'Three')

#another()

Measured memory_bytes: 3060