jiahuimbzuai/CoQuIR huggingface dataset:
//  [c]
#include <stdio.h>
#include <math.h>
#define MAX_NUM 100000
#define NUM_MAX 1000000008
 
int main(void){
	int i, j, N;
	long tmp;
	char A[NUM_MAX/8] = {0};
	int count;
 
	scanf("%d", &N);
 
	for(i=0; i<N; i++){
		scanf("%ld", &tmp);
		switch(tmp%8){
			case 0: A[tmp/8] = A[tmp/8]^1; break;
			case 1: A[tmp/8] = A[tmp/8]^2; break;
			case 2: A[tmp/8] = A[tmp/8]^4; break;
			case 3: A[tmp/8] = A[tmp/8]^8; break;
			case 4: A[tmp/8] = A[tmp/8]^16; break;
			case 5: A[tmp/8] = A[tmp/8]^32; break;
			case 6: A[tmp/8] = A[tmp/8]^64; break;
			case 7: A[tmp/8] = A[tmp/8]^128; break;
		}
	}
 
	count = 0;
	for(i=0; i<NUM_MAX/8; i++){
		for(j=0; j<8; j++){
			if((A[i] >> j) & 1)
				count++;
		}
	}
 
	printf("%d", count);
 
	return 0;
}
//  [javascript]
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var n = parseInt(input[0], 10);
    var a = new Array(n);
    for (var i = 0; i < n; i++) {
        a[i] = parseInt(input[i + 1], 10);
    }

    var num = {};
    var numCount = 0;
    for (var i = 0; i < n; i++) {
        if (num[a[i]]) {
            num[a[i]] = false;
            numCount--;
        }
        else {
            num[a[i]] = true;
            numCount++;
        }
    }

    console.log(numCount);

    return 0;
}
//  [javascript]
log = console.log;

var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = lines[0].split(" ").map(Number)[0];
var A = lines
  .slice(1)
  .filter(v => v !== "");

A.sort((a,b)=> a-b)

var count = 0;
var tmp = false;
A.forEach((v,i,a)=>{
    if(i===0) return
    if(a[i] === a[i-1]){
      tmp = !tmp
    }else {
      if(!tmp) count += 1
      tmp = false
    }
})
if(!tmp) count += 1

log(count)
//  [javascript]
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8"))},function(e,r){e.exports=function(e){for(var r=e.split("\n"),t=Number(r[0]),n={},o=0;o<t;o++){var u=Number(r[o+1]);n[u]?n[u]=!n[u]:n[u]=!0}var i=0;for(var f in n)n[f]&&(i+=1);console.log(i)}},function(e,r){e.exports=require("fs")}]);
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	nums := map[int]struct{}{}
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)
		if _, ok := nums[a]; ok {
			delete(nums, a)
		} else {
			nums[a] = struct{}{}
		}
	}

	fmt.Printf("%d\n", len(nums))
}
//  [go]
package main

import "fmt"

func main() {
	var n, a int
	fmt.Scanf("%d\n", &n)

	dic := map[int]int{}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &a)
		dic[a]++
	}

	total := 0
	for key := range dic {
		if dic[key]%2 == 1 {
			total++
		}
	}

	fmt.Println(total)

}
//  [go]
package main

import "fmt"

func main() {

  var n int
  fmt.Scan(&n)
  mp := map[int]struct{}{}

  for i := 0; i < n; i++ {
    var a int
    fmt.Scan(&a)

    if _, ok := mp[a]; ok {
      delete(mp, a)
    } else {
      mp[a] = struct{}{}
    }
  }

  fmt.Println(len(mp))
}
//  [ruby]
n = gets.to_i
input = []
result = 0
for i in 0..n-1
	input.push(gets.to_i)
end
input.sort!

for i in 0..n-1
	if input[i] == input[i+1]
		input.delete_at(i+1)
	else
		result += 1
	end
end
puts result
//  [ruby]
n =gets.chomp.to_i
d = 0
c = []
while s = gets
  c.push(s.split.map(&:to_i))
end
c.sort!
i = 0
t = 0
cnt = 0
while i < n do
  j = 0
  while c[i+j]==c[i] do
  j += 1
  end
  cnt += j%2
  i +=j
end
puts cnt
//  [ruby]
N=gets.to_i
S={}
for i in 1..N do
    A=gets.to_i
    if !S.has_key?(A) then S[A]=1
    else S.delete(A) end
end
p S.size
//  [rust]
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

    a.sort();
    a.push(0);
    debug!(a);
    let mut b: Vec<usize> = Vec::new();
    let mut cnt = 0;
    for i in 0..n {
        let now = a[i];
        let next= a[i+1];
        if now==next {
            cnt += 1;
        } else {
            cnt += 1;
            b.push(cnt);
            cnt = 0;
        }
    }
    debug!(b);
    let mut ans = 0;
    for i in b {
        if i%2!=0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}
//  [rust]
use std::io::*;
use std::str::*;
use std::collections::HashSet;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let mut hs = HashSet::new();

    for _ in 0..n {
        let x: usize = read().unwrap();
        if hs.contains(&x) {
            hs.remove(&x);
        } else {
            hs.insert(x);
        }
    }
    println!("{}", hs.len());
}
//  [rust]
use std::io::*;
use std::str::*;
use std::collections::HashSet;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let mut paper = HashSet::new();
    for _ in 0..n {
        let n: usize = read().unwrap();
        if !paper.contains(&n) {
            paper.insert(n);
        } else {
            paper.remove(&n);
        }
    }
    println!("{}", paper.len());
}
//  [python]
import sys 

readline = sys.stdin.buffer.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    cnt = 0
    i = 1
    for a in A:
        if a == i:
            i += 1
        else:
            cnt += 1

    print(cnt if cnt != N else -1)


main()
//  [python]
def solve(string):
    n, *a = map(int, string.split())
    c = 1
    for _a in a:
        if c == _a:
            c += 1
    return str(-1 if c == 1 else n - c + 1)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
//  [python]
import sys

def main():
    N = int(input())
    a = list(map(int,input().split()))
    num = 1

    for i in a:
        if(i==num):
            num += 1

    if(num!=1):
        print(len(a) - num + 1)
    else:
        print('-1')

main()
//  [python]
import numpy as np
n=int(input())
a=input().split()
a=np.array(a,dtype='int32')
k=0
x=0
for i in range(n):
	if a[i]==x+1:
		x+=1
	else:
		k+=1
if k>=n:
	print('-1')
else:
	print(k)
//  [python]
# 21:19
from collections import deque
n = int(input())
a = deque(list(map(int,input().split())))
ans = 0
count = 1
i = 0
while True:
    if a[i] != count:
        ans += 1
        a.popleft()
    else:
        count += 1
        i += 1
    if n == ans + i:
        break
if len(a) == 0:
    print(-1)
else:
    print(ans)
//  [python]
from collections import deque
n = int(input())
r = deque(map(int, input().split()))
i=0
while True:
    if max(len(r),i)==i:
        break
    if r[i]!=i+1:
        r.popleft()
    else:
        i+=1
print('-1' if len(r)==0 else n-len(r))
//  [java]
import java.io.*;
import java.util.*;
public class Main {
	public static class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
	}

	public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
	public static long lcm(long a, long b) { return a * b / gcd(a, b); }
	public static int abs(int x) { if (x < 0) return -x; return x; }

	public static void main(String[] args) {
		FS in = new FS();

		HashMap<Integer, TreeSet<Integer>> map;
		map = new HashMap<>();

		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			map.putIfAbsent(a, new TreeSet<>());
			map.get(a).add(i);
			map.get(a).add(n + 1);
		}

		int k = 0, l = -1;
		while (true) {
			if (!map.containsKey(k + 1))
				break;
			if (map.get(k + 1).higher(l) != (n + 1)) {
				l = map.get(k + 1).higher(l);
				k++;
			}
			else
				break;
		}
	
		int ans = n - k;
		if (l == -1)
			ans = l;

		System.out.println(ans);
	}
}
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        HashMap<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            map.put(i, new ArrayList<>());
        }
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
            List<Integer> list = map.get(a[i]);
            list.add(i);
        }
        if (map.get(1).isEmpty()) {
            System.out.println(-1);
            return;
        }
        int current = -1;
        int count = 0;
        Comparator<Integer> comparator = new UpperBoundComparator<>();
        for (int i = 1; i <= N; i++) {
            List<Integer> list = map.get(i);
            if (list.isEmpty()) {
                break;
            }
            int x = ~Collections.binarySearch(list,  current, comparator);
            if (list.size() <= x) {
                break;
            }
            current = list.get(x);
            count += 1;
        }
        System.out.println(N-count);
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T> {
        public int compare(T x, T y) {
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
}
//  [java]
import java.util.*;
 
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ary = new int[n];
		for(int i=0; i<n; i++){
			ary[i] = sc.nextInt();
		}
		int ans = 0;
		int count = 1;
		for(int i=0; i<n; i++){
			if(ary[i] != count){
				ans++;
			} else {
				count++;
			}
		}
		Arrays.sort(ary);
		int tmp = Arrays.binarySearch(ary,1);
		if(tmp != -1){
			System.out.println(ans);
		} else {
			ans = -1;
			System.out.println(ans);
		}
	}
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int k = 1;
	rep(i, N) if (getint() == k) k++;

	if (k != 1) printf("%d", N - k + 1);
	else printf("-1");

	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int k = 1;
	rep(i, N >> 1) {
		k += getint() == k;
		k += getint() == k;
	}
	if (N & 1) k += getint() == k;

	if (k != 1) printf("%d", N - k + 1);
	else printf("-1");

	Would you please return 0;
}
//  [cpp]
#include <bits/stdc++.h>


using ll = long long int;

using namespace std;

bool has_digit(string a, string d)
{
    /*
    bool ans = false;
    while(a)
    {
        ans = ans || ((a % 10) == d);
        a /= 10;
    }
    return ans;*/
    //bool res = (a.find(d) != std::string::npos);
    bool res = a == d;
    return res;

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int i, j, n, d, k;
    
    cin >> n;
    
    
    vector<string> a(n);
    
    int l, r, m;
    l = 0;
    r = n;
    
    for(i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    
    
    
    while (l < r)
    {
         vector<char> destroyed(n);
         m = (l + r) / 2;
         k = 0;
         d = 1;
         
         if (m != k)
         {
             for(i = 0; i < n; ++i)
             {
                 if (has_digit(a[i], to_string(d)))
                 {
                     ++d;
                 }
                 else
                 {
                     destroyed[i] = 1;
                     ++k;
                 }
                 if (m == k)
                     break;
             }
         }
             
         bool flag = (m >= k); //true;
         d = 1;
         
         for(i = 0; i < n; ++i)
         {
             if (!destroyed[i])
             {
                 if (!has_digit(a[i], to_string(d)))
                 {
                     flag = false;
                     break;
                 }
                 ++d;
             }
         }
         
         if (flag)
         {
             r = m;
         }
         else
         {
             l = m + 1;
         }

    }
    
    int ans = r;
    if (ans == n)
        ans = -1;
    
    cout << ans;
    
    return 0;
}
//  [cpp]
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<int> a(n);
    for(auto &x:a)cin >> x;

    int count=0;
    for(int i=0;i<a.size();i++){
        if(a[i]!=i+1){
            a.erase(a.begin()+i);
            count++;
            i--;
        }
    }

    if(a.size())cout << count << endl;
    else cout << -1 << endl;

    return 0;
}
//  [cpp]
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> arr;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		arr.push_back(a);
	}
	if (n == 1) {
		cout << 0;
		return 0;
	}int i = 0;
	int j = 1;
	int ans = 0;
	while (i < arr.size()) {
		if (arr.at(i) != j) {
			arr.erase(arr.begin() + i);
			ans++;
		}
		else {
			i++;
			j++;
		}
	}if (n == ans) {
		ans = -1;
	}
	cout << ans;
	return 0;
}
//  [c]
char buf[2000000];
unsigned sz;
char out[9];
main()
{
	read(0,buf,2000000);
	unsigned N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	unsigned now=1;
	for(unsigned i=0;i<N;i++)
	{
		unsigned A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		now+=A==now;
	}
	out[8]='\n';
	unsigned outsz=8;
	if(now==1)
	{
		out[7]='1';
		out[6]='-';
		outsz=6;
	}
	else
	{
		N-=now-1;
		do{
			out[--outsz]=N%10+'0';
		}while(N/=10);
	}
	write(1,out+outsz,9-outsz);
}
//  [c]
char buf[2000000];
sz;
main()
{
	read(0,buf,2000000);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	int now=1;
	for(int i=0;i<N;i++)
	{
		int A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		now+=A==now;
	}
	printf("%d\n",now==1?-1:N-now+1);
}
//  [c]
char buf[2000000];
sz;
main()
{
	read(0,buf,2000000);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	int now=1;
	for(int i=0;i<N;i++)
	{
		int A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		if(A==now)now++;
	}
	printf("%d\n",now==1?-1:N-now+1);
}
//  [c]
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int a;
  int S=0;
  for(int i=1;i<=N;i++){
    scanf("%d",&a);
    if(a==S+1) S++;
  }
  if(S==0) printf("-1\n");
  else printf("%d\n",N-S);
  return 0;
}
//  [c]
#include <stdio.h>
int main(){
	int n,b=1,i;
	scanf("%d", &n);
	int x[n];
	for(i=0;i<n;i++) {
		scanf("%d", &x[i]);
	}
	for(i=0;i<n;i++) {
		if(x[i]==b){
			b++;
		}
	}
	if(b==1) b=n+2;
	printf("%d\n", n-b+1);
	return 0;
}
//  [c]
#include <stdio.h>

int main(void){
	int num;
	scanf("%d", &num);

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

	int Break = 1;
	for(int i=0; i<num; i++) {
		if(brick[i] == Break){
			Break++;
		}
	}

	if(Break == 1) Break = num + 2;

	printf("%d\n", num-Break+1);

	return 0;
}
//  [javascript]
function Main(input) {
    input = input.split("\n");
    
    var n = Number(input[0]);
    var rengaArr = input[1].split(" ");
    
    var res = 0;
    var ord = 1;
    for(var i=0; i<n; i++){
        if(Number(rengaArr[i])==ord){
            ord++;
        }else{
            res++;
        }
    }
    if(ord == 1){
        console.log(-1);
    }else{
        console.log(res);
    }
    
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
    input[1] = input[1].split(" ");
	var n = parseInt(input[0], 10);
    var b = new Array(n);
    for(var i=0; i<n; i++){
      input[1][i] = parseInt(input[1][i], 10);
    }
    var count = 1;
    var anser = 0;
  	for(var i=0; i<n; i++){
      if(count == input[1][i]){
        count++;
      }else{
        anser++;
      }
    }
  if(count == 1){
  console.log(-1);
  }else{
    console.log(anser);
}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
// inputに入力データ全体が入る
function Main(input) {

    input = input.split("\n");
   var n= parseInt(input[0], 10);

 var tmp = input[1].split(" ");
    var i = 0;
  var a = [];
for (var i = 0; i < n ; i++){
 var r= parseInt(tmp[i], 10);

 a[i] = r;}
// console.log(a);
var i = 1;
 for(f=0;f<n;f++){
 //  console.log(f,i);
   if(a[f]==i){var i=i+1};}
//  console.log(i,f);

if (n==1&&a[0]==1){console.log('0');}
  else{if(i===1){console.log('-1')}
  else{console.log(n-i+1);}};
                   
  
        }    //    1    
    
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [javascript]
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var ans = 0, x = 1;
  for(var i = 0; i < n; i++){
    if(a[i] === x)x++;
    else ans++;
  }
  return ans === n? -1:ans;
}
//  [javascript]
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=new Array(e),n=0;n<e;n++)r[n]=t.in();for(var i=0,o=0,s=0;s<e;s++)r[s]==o+1?o++:i++;0!=o?console.log(i):console.log(-1)}}]);
//  [javascript]


function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const a=input[1].split(' ').map(e=>{
    return e-0;
  });
  var next=1;
  a.forEach(e=>{
    if(next===e){
      next++;
    }
  });
  console.log(next===1?-1:N+1-next);


}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [go]
package main

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

const (
	BUFSIZE   = 10000000
	MOD       = 1000000007
	INF_INT   = math.MaxInt32
	INF_INT64 = math.MaxInt64
)

var rdr *bufio.Reader

func main() {
	rdr = bufio.NewReaderSize(os.Stdin, BUFSIZE)
	solve()
}

func solve() {
	N := readint()
	A := readIntSlice(N)
	ans := 0
	now := 1
	for _, v := range A {
		if v != now {
			ans += 1
		} else {
			now += 1
		}
	}

	if ans == N {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func readline() string {
	buf := make([]byte, 0, BUFSIZE)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			fmt.Println(e.Error())
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readIntSlice(size int) []int {
	slice := make([]int, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i(v)
	}
	return slice
}

func readInt64Slice(size int) []int64 {
	slice := make([]int64, size)
	lines := strings.Split(readline(), " ")
	for i, v := range lines {
		slice[i] = s2i64(v)
	}
	return slice
}

func readint() int {
	return s2i(readline())
}

func readint64() int64 {
	return s2i64(readline())
}

// For int64
func b2i64(b bool) int64 {
	if b {
		return 1
	}
	return 0
}

func abs64(v int64) int64 {
	if v < 0 {
		return -v
	}
	return v
}

func min64(values ...int64) int64 {
	ret := int64(INF_INT64)
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max64(values ...int64) int64 {
	ret := -int64(INF_INT64)
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i64(s string) int64 {
	v, ok := strconv.ParseInt(s, 10, 64)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int64")
	}
	return v
}

// For int
func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

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

func min(values ...int) int {
	ret := INF_INT
	for _, v := range values {
		if ret > v {
			ret = v
		}
	}
	return ret
}

func max(values ...int) int {
	ret := -INF_INT
	for _, v := range values {
		if ret < v {
			ret = v
		}
	}
	return ret
}

func s2i(s string) int {
	v, ok := strconv.Atoi(s)
	if ok != nil {
		panic("Faild : " + s + " can't convert to int")
	}
	return v
}

func lcm(v1, v2 int) int {
	if v1 > v2 {
		v1, v2 = v2, v1
	}
	for v1 != 0 {
		v1, v2 = v2%v1, v1
	}
	return v2
}

func gcd(v1, v2 int) int {
	return v1 * v2 / lcm(v1, v2)
}

/* ------------------------------------------------ */
/* Data stracture                                   */
/* ------------------------------------------------ */
type IntHeap []int

func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
//  [go]
package main

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

func brickBreak(n int, a []int) int {
	c, j := 0, 1
	for i := 0; i < n; i++ {
		if a[i] != j {
			c++
		} else {
			j++
		}
	}
	if c == n {
		return -1
	}
	return c
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 10240*10240)

	n, err := strconv.Atoi(readLine(reader))
	checkError(err)
	a := make([]int, n)
	ss := strings.Split(readLine(reader), " ")
	for i := range ss {
		a[i], err = strconv.Atoi(ss[i])
		checkError(err)
	}
	fmt.Println(brickBreak(n, a))
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}
	cnt := 0
	t := 1
	for _, a := range as {
		if a == t {
			cnt++
			t += 1
		}
	}

	if cnt == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(n - cnt)
	}
}
//  [go]
package main

import "fmt"

func main() {
	var n, tmp, last int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		if tmp == last+1 {
			last += 1
		}
	}
	if last == 0 {
		fmt.Printf("%d", -1)
	} else {
		fmt.Printf("%d", n-last)
	}
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n int64
	fmt.Scan(&n)
	aArray := scanNums(n)

	// n-k個のレンガを砕いた結果、1,2,3,...,kとなればよい
	// 1が見つからない...-1
	// 1が見つかる...それより左は全部砕く
	// 1より右で2を見つけるまで砕く
	// 2より右で3を見つけるまで砕く
	// 以下繰り返し O(n)
	// 最初に見つかった1より右にある1から始めた方がいい場合はない
	var ans int64 = 0
	var notFound bool = true
	var lastFoundIdx int64 = -1
	var finding int64 = 1
	var idx int64
	for idx = 0; idx < n; idx++ {
		if aArray[idx] == finding {
			ans += idx - lastFoundIdx - 1
			lastFoundIdx = idx
			finding++
			notFound = false
		}
	}
	if lastFoundIdx != n-1 {
		ans += n - 1 - lastFoundIdx
	}
	if notFound {
		ans = -1
	}

	fmt.Println(ans)
}

func scanNums(len int64) (nums []int64) {
	var num int64
	var i int64
	for i = 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
//  [ruby]
n = gets.to_i
a = 1

gets.split.each do |e|
    e = e.to_i
    a += 1 if a == e
end

puts a == 1 ? -1 :  n - a + 1
//  [ruby]
n = gets.to_i
a = 1

gets.split.each do |block|
  block = block.to_i
  a += 1 if a == block
end

puts a == 1 ? -1 :  n - a + 1
//  [ruby]
n = gets.to_i
a = gets.to_s

index = 1
count = 0

a.split(' ').each do |s|
  if s.to_i == index
    index += 1
  else
    count += 1
  end
end
count = -1 if count == n
puts count
//  [ruby]
n = gets.to_i
as = gets.split.map &:to_i

m = {}

as.each_with_index{ |a, i|
	if m[a] == nil then
		m[a] = []
	end
	
	m[a] << i
}

ind = -1

res = -1

(1..n).each{ |i|
	if m[i] != nil then
		c_ind = m[i].index{ |x| x > ind } 
		if c_ind != nil then
			ind = m[i][c_ind]
		else
			res = i
			break
		end
	else
		res = i
		break
	end
}

if res == -1 then
	puts 0
elsif res == 1 then
	puts -1
else
	puts n - res + 1
end
//  [ruby]
N = gets.to_i
A = gets.split.map(&:to_i)

last_index = 0
n_ = (1 .. N + 1).find do |n|
  found = (last_index ... N).find{|i| A[i] == n }
  last_index = found if found
  !found
end
puts n_ == 1 ? -1 : N - (n_ - 1)
//  [ruby]
n = gets.chomp.to_i
as =  gets.chomp.split.map(&:to_i)

as_length = as.length

array = (1..n).to_a.sort

if array == as
  p 0
  exit
end

counter = 0
(0..n).each do |i|
  finder = as.find_index(i+1)
  if i == 0 && finder == nil
    p -1
    exit
  elsif finder == nil
    p as_length - counter
    exit
  elsif finder + 1 == as_length
    p as_length - counter
    exit
  elsif 
    as = as[finder..-1]
    counter = counter + 1
  end
end
//  [rust]
use text_io::*;
use std::process::exit;
use im_rc::HashMap;
use std::cmp::min;

fn main(){
    let mut a:usize = read!();
    let mut n:usize = 1;
    for i in 0..a {
        let x:usize = read!();
        if x==n {
            n+=1;
        }
    }
    if n==1 {
        println!("-1");
        exit(0);
    }
    println!("{}",a+1-n);
}
//  [rust]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

fn main() {
    let n: usize = read();
    let a: Vec<i64> = read_n(n);

    let mut current = 1;
    for i in a {
        if i == current {
            current += 1;
        }
    }
    if current != 1 {
        println!("{}", n as i64 - current + 1);
    } else {
        println!("{}", -1);
    }
}
//  [swift]

import Foundation

func main(){
   let n = Int(readLine()!)!
   let array = readLine()!.split(separator: " ")

   var j = 1
   var answer = 0
   for i in 0..<n {
      let curInt = Int(array[i])!
      if curInt == j {
         j += 1
      } else {
         answer += 1
      }
   }
   print(answer == n ? -1 :answer)
}
main()
//  [swift]
let n=Int(readLine()!)!
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var i = 0
var b = 0
var f = 0
for i in 0..<n {
  if( arr[i] != i - b + 1 ) {
    b += 1
  } else {
    f += 1
  }
}

if( f == 0 ) {
  b = -1
}

print(b)
//  [typescript]
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};
const main=()=>{
  let n=tn(),s=tnn(n),target=1,ans=0
  for(let i=0;i<n;i++){
    if(target==s[i]){
      target++
    }else ans++
  }
  if(target==1)to(-1)
  else to(ans)
}
main()
//  [typescript]
{
  const main = (input: string): void | string | number => {
    const r = _reader(input)
    const [N] = r.nn()
    const a = r.nn()

    let k = 1
    let t = 0

    for (let i = 0; i < N; i++) {
      if (a[i] !== k) {
        t++
      } else {
        k++
      }
    }

    return k === 1 ? -1 : t
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
}
//  [typescript]
const main = (input) => {
  input = input.trim().split('\n')
  const n = Number(input[0])
  const as = input[1].split(' ').map(n => Number(n))
  let cnt = 1;
  let result = 0;
  for (let i = 0; i < n; i++) {
    const a = as[i]
    if (a !== cnt) {
      result++
      continue;
    }
    cnt++
  }
  if (cnt === 1) {
    result = -1
  }
  console.log(result)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [typescript]

function Main(input: string) {
    let lines = input.split('\n');
    let bricks = lines[1].split(' ').map(v => parseInt(v));

    let targetIndex = 0;
    let count = 0;
    bricks.forEach((value) => {
        if (value === targetIndex + 1) {
            targetIndex++;
        } else {
            count++;
        }
    })
    console.log(targetIndex === 0 ? -1 : count);

}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//  [typescript]
function Main(input) {
	const lines = input.split('\n');
	const bricks = lines[1].split(' ').map(v => v*1);

	let idx = 0, cnt = 0;
	bricks.forEach((a) => {
		if (a === idx + 1) idx++;
		else cnt++;
	});

	console.log(idx == 0 ? -1: cnt );
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  [python]
import sys
from functools import cmp_to_key

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

mod = 1000000007
n = ni()
co = []
z = 0
for i in range(n):
    x = na()
    if x[0] == 0 and x[1] == 0:
        z += 1
    else:
        co.append(x)
n = len(co)

for c in co:
    if c[1] < 0 or c[1] == 0 and c[0] < 0:
        c[1] = -c[1]
        c[0] = -c[0]

mod = 1000000007
ans = 1

co.sort(key=cmp_to_key(lambda x,y: -(x[0]*y[1]-y[0]*x[1])))

p = 0
while p < n and co[p][0] > 0:
    p += 1

col = []
i = 0
rem = n
while i < n:
    if co[i][0] <= 0:
        break
    while p < n and co[i][0]*co[p][0]+co[i][1]*co[p][1] > 0:
        p += 1

    op = p
    while p < n and co[i][0]*co[p][0]+co[i][1]*co[p][1] == 0:
        p += 1

    oi = i
    while i < n and co[i][0]*co[oi][1]-co[i][1]*co[oi][0] == 0:
        i += 1

    if p-op > 0:
        ans = ans * (pow(2, i-oi, mod) + pow(2, p-op, mod) - 1) % mod
        rem -= (p-op) + (i-oi)

ans = ans * pow(2, rem, mod) % mod
print((ans+z+mod-1)%mod)
//  [python]
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from math import gcd
from collections import Counter
from fractions import Fraction

def resolve():
    n = int(input())
    zero = 0
    counter = Counter()
    for _ in range(n):
        x, y = map(int, input().split())
        if x == 0 and y == 0:
            zero += 1
            continue

        g = gcd(x, y)
        x //= g
        y //= g

        if x == 0:
            x, y = 0, 1
        elif x < 0:
            x, y = -x, -y
        counter[x, y] += 1

    C = list(counter.items())
    C.sort(key = lambda p: Fraction(p[0][1], p[0][0]) if p[0][0] != 0 else -float("inf"))

    k = len(C)
    dp = [0] * (k + 1)
    dp[0] = 1
    for i in range(k):
        x, y = C[i][0]
        dp[i + 1] += dp[i]
        dp[i + 1] += (pow(2, counter[x, y], MOD) - 1) * dp[i] * pow(2, -counter[y, -x] % (MOD - 1), MOD)
        dp[i + 1] %= MOD

    res = dp[k]
    res -= 1
    res += zero
    print(res % MOD)
resolve()
//  [python]
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

mod = 1000000007

from fractions import gcd

ratios = []
nzero = 0
for a, b in ab:
    if a != 0 and b != 0:
        g = gcd(a, b)
        ratios.append((a // g, b // g))
    elif a == 0 and b == 0:
        nzero += 1
    elif a == 0:
        ratios.append((0, 1))
    else:
        ratios.append((1, 0))

twos = [1]
for i in range(2 * 10 ** 5):
    tmp = twos[-1] * 2
    tmp %= mod
    twos.append(tmp)


from collections import Counter, defaultdict
c = Counter(ratios)
seen = Counter()

targets = []
for key in c:
    x, y = key
    xx = c[key]
    if y != 0:
        yy = seen[(-y, x)] + seen[(y, -x)]
    else:
        yy = seen[(-y, x)]
    if xx != 0 and yy != 0:
        targets.append((xx, yy))
    seen[key] = c[key]

n_frees = 0
for i, (x, y) in enumerate(ratios):
    n_bads = c[(-y, x)] + c[(y, -x)]
    if n_bads == 0:
        n_frees += 1

ans = twos[n_frees]

for x, y in targets:
    ans *= (twos[x] + twos[y] - 1) % mod
    ans %= mod

print((ans - 1 + nzero) % mod)
//  [java]


import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int mod = 1000000007;

//		fact[0] = 1;
//		factInv[0] = 1;
//		for(int i = 0; i < fact.length - 1; i++){
//			fact[i+1] = fact[i]*(i+1) % mod; // n!(mod M)
//	        factInv[i+1] = (int)(factInv[i]*repeatablePow(i+1, mod-2, mod) % mod);
//		}

		long a[] = new long[n];
		long b[] = new long[n];

		int zeros = 0;
		HashMap<String, Integer> map = new HashMap<>();
		for(int i = 0; i < n; i++){
			a[i] = sc.nextLong();
			b[i] = sc.nextLong();

//			System.out.println("i = " + i+ " " +a[i] + " " + b[i]);

			if(a[i] == 0 && b[i] == 0){
				zeros++;
				continue;
			}
			if(a[i] == 0 && b[i] != 0){
				b[i] = 1;
			}
			if(a[i] != 0 && b[i] == 0){
				a[i] = 1;
			}
			if(a[i] != 0 && b[i] != 0){
				long gcd = gcd(a[i], b[i]);
				a[i] /= gcd;
				b[i] /= gcd;
			}

			if(a[i] < 0){
				a[i] *= -1;
				b[i] *= -1;
			}

			String tmpStr = a[i] + "," +b[i];

			if(!map.containsKey(tmpStr)){
				map.put(tmpStr, 1);
			}
			else {
				map.put(tmpStr, map.get(tmpStr) + 1);
			}
		}

		Iterator<String> it = map.keySet().iterator();

		HashSet<String> used = new HashSet<String>();
		long result = 1;
		while(it.hasNext()){
			String tmpStr = it.next();
//			System.out.println(tmpStr);

			if(used.contains(tmpStr)){
				continue;
			}
			String tmpArray[] = tmpStr.split(",");

			long tmpA = Long.parseLong(tmpArray[0]);
			long tmpB = Long.parseLong(tmpArray[1]);

//			if(tmpB == 0){
//				continue;
//			}

			String counterStr = "";
			if(tmpA == 0 && tmpB == 1){
				counterStr = "1,0";
			}
			else if(tmpA == 1 && tmpB == 0){
				counterStr = "0,1";
			}
			else {
				if(tmpB > 0){
					counterStr = tmpB + "," + (-tmpA);
				}
				else {
					counterStr = -tmpB + "," + tmpA;
				}
			}

			if(map.containsKey(counterStr)){
				result *= (repeatablePow(2, map.get(tmpStr), mod) + repeatablePow(2, map.get(counterStr), mod) + mod - 1)%mod;
			}
			else {
				result *= repeatablePow(2, map.get(tmpStr), mod)%mod;
			}
			result %= mod;
			used.add(counterStr);
//			System.out.println("str "+tmpStr + " counter "+counterStr+" result" + result);
		}

		result += zeros ;
		result += mod - 1;
		result %= mod;

		System.out.println(result);
	}

	static long gcd(long a, long b){
        long tmp;

        while (a % b != 0)
        {
            tmp = b;
            b = a % b;
            a = tmp;
        }
        return b;
    }
	static long repeatablePow(int x, int n, int mod){
		if(n == 0){
			return 1;
		}
		long result = repeatablePow((int)((long)x*x%mod), n/2, mod);
		if(n % 2 == 1){
			result = result*x%mod;
		}
		return result;
	}

//	static long combination(int a, int b, int mod){ //aCbをmod計算
//	    if(a == 0 && b == 0)return 1;
//	    if(a < b || a < 0)return 0;
//
//	    long tmp = factInv[a - b]* factInv[b] % mod;
//	    return tmp * fact[a] % mod;
//	}

//	static long fact[] = new long[2000002];
//	static long factInv[] = new long[2000002];

}
//  [java]
import java.util.*;
public class Main {
	
	static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	
	static String rev(String S) {
		if(S.equals("1,0"))
			return "0,1";
		else if(S.equals("0,1"))
			return "1,0";
		String[] s = S.split(",");
		if(s[0].charAt(0) == '-')
			return s[1] + "," + s[0].substring(1);
		else
			return "-" + s[1] + "," + s[0];
	}
	
	public static void main(String[] args) {
		int MOD = 1000000007;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String C;
		Map<String, Integer> m1 = new HashMap<>();
		Map<String, Integer> m2 = new HashMap<>();
		int zero = 0;
		for(int i = 0; i  < N; i++) {
			long A = sc.nextLong();
			long B = sc.nextLong();
			if(A == 0 && B == 0) {
				zero++;
				continue;
			}
			long gcd = gcd(A, B);
			A /= gcd;
			B /= gcd;
			if(B < 0) {
				A = -A;
				B = -B;
			}
			if(B == 0)
				C = "1,0";
			else if(A == 0)
				C = "0,1";
			else
				C = A + "," + B;
			if(A >= 0 && B != 0)
				m1.put(C, m1.getOrDefault(C, 0)+1);
			else 
				m2.put(C, m2.getOrDefault(C, 0)+1);		
		}
		long ans = 1;
		long[] pow2 = new long[N+1];
		pow2[0] = 1;
		for(int i = 1; i <= N; i++)
			pow2[i] = pow2[i-1] * 2 % MOD;
		for(String s : m1.keySet()) {
			int a = m1.get(s), b = m2.getOrDefault(rev(s), 0);
			ans = ans * (pow2[a] + pow2[b] - 1) % MOD;
		}
		for(String s : m2.keySet())
			if(!m1.containsKey(rev(s)))
				ans = ans * pow2[m2.get(s)] % MOD;
		System.out.println((ans + zero - 1 + MOD) % MOD);
	}

}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

lnt powmod(lnt a, lnt p, lnt m){
	lnt res = 1, tmp = a;
	while(p != 0){
		if(p % 2) res = (res*tmp) % m;
		tmp = (tmp*tmp) % m;
		p /= 2;
	}
	return res;
}

int main(){
	summon_tourist;

	lnt N, A, B; cin >> N;
	lnt ans = 0;

	map<plnt, lnt> mpa, mpb;
	vector<plnt> vec;
	map<plnt, bool> check;

	REP(i, N){
		cin >> A >> B;
		if(A == 0 and B == 0) ans++;
		else {
			lnt g = __gcd(A, B);
			A /= g; B /= g;
			if(A == 0 and B != 0){
				mpb[{A, B}]++;
			} else if(A != 0 and B == 0){
				mpa[{A, B}]++;
				vec.eb(A, B);
			} else {
				if((A>0) xor (B>0)){
					mpb[{A, B}]++;
				} else {
					mpa[{A, B}]++;
				}
			}
			vec.eb(A, B);
		}
	}

	lnt plus = 1;
	for(auto p: vec){
		if(check[p]) continue;

		check[p] = 1; check[{-p.first, -p.second}] = 1;
		check[{p.second, -p.first}] = 1; check[{-p.second, p.first}] = 1;
		lnt num = 1;

		if(mpa.count(p)){
			lnt a = mpa[p] + mpa[{-p.first, -p.second}];
			lnt b = mpb[{p.second, -p.first}] + mpb[{-p.second, p.first}];
			num = (powmod(2, a, MOD) + powmod(2, b, MOD) - 1) % MOD;
		} else if(mpb.count(p)){
			lnt a = mpb[p] + mpb[{-p.first, -p.second}];
			lnt b = mpa[{p.second, -p.first}] + mpa[{-p.second, p.first}];
			num = (powmod(2, a, MOD) + powmod(2, b, MOD) - 1) % MOD;
		}
		plus *= num; plus %= MOD;
	}

	ans += plus; ans %= MOD;
	ans = (ans-1+MOD) % MOD;
	
	cout << ans << ln;
}
//  [c]
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
const long mod = 1000000007l;
long gcd(long a, long b){return b?gcd(b,a%b):a;}
long modpow(long x, long y, long m){
	long res = 1, tmp = x;
	while(y){
		if(y&1)res = res * tmp % m;
		tmp = tmp * tmp % m;
		y >>= 1;
	}
	return res;
}
long pom(long x, long y){return modpow(x, y, mod);}
typedef struct{
	long x, y;
}cor;
bool lt(cor u, cor v){
	if(u.x < v.x)return true;
	if(u.x == v.x && u.y < v.y)return true;
	return false;
}
bool eq(cor u, cor v){
	return u.x == v.x && u.y == v.y;
}
bool gt(cor u, cor v){
	return !lt(u, v) && !eq(u, v);
}
int cmp(const void *a, const void *b){
	cor u = *(cor*)a, v = *(cor*)b;
	if(lt(u, v))return 1;
	if(eq(u, v))return 0;
	return -1;
}
int N, sz=0, cnt_zero = mod - 1;
long ans = 1;
cor A[1<<18];
int lower_bound(cor u){
	int l = -1, r = sz;
	while(r - l > 1){
		int mid = (r + l) / 2;
		if(gt(A[mid], u))l = mid;
		else r = mid;
	}
	return r;
}
int upper_bound(cor u){
	int l = -1, r = sz;
	while(r - l > 1){
		int mid = (r + l) / 2;
		if(lt(A[mid], u))r = mid;
		else l = mid;
	}
	return r;
}
cor m(long s, long t){
	cor res;
	if(s == 0){
		if(t != 0)t = 1;
	}else if(t == 0){
		s = 1;
	}else {
		long x = gcd(labs(s), labs(t));
		s /= x;
		t /= x;
		if(t < 0){
			s *= -1;
			t *= -1;
		}
	}
	res.x = s;
	res.y = t;
	return res;
}
int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		long s, t;
		scanf("%ld%ld", &s, &t);
		cor tmp = m(s, t);
		if(tmp.x == 0 && tmp.y == 0){
			cnt_zero++;
		}else{
			A[sz++] = tmp;
		}
	}
	qsort(A, sz, sizeof(cor), cmp);
	int cnt = 1;
	for(int i=1; i<=sz; i++){
		if(i<sz && eq(A[i-1], A[i]))cnt++;
		else {
			cor tmp = m(A[i-1].y, -A[i-1].x);
			int l = lower_bound(tmp), r = upper_bound(tmp);
			if(l==r){
				ans *= pom(2, cnt);
				ans %= mod;
			}else{
				if(gt(A[i-1], tmp)){
					ans *= (pom(2, cnt) + pom(2, r-l) - 1);
					ans %= mod;
				}
			}
			cnt = 1;
		}
	}
	printf("%ld\n", (ans + cnt_zero) % mod);
	return 0;
}