akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

struct SCC{
  int n;
  vector<vector<int> > G,rG,T,C;
  vector<int> vs,used,belong;
  SCC(){}
  SCC(int sz):n(sz),G(sz),rG(sz),used(sz),belong(sz){}
  
  void add_edge(int from,int to){
    G[from].push_back(to);
    rG[to].push_back(from);
  }
  
  void input(int m,int offset=0){
    int a,b;
    for(int i=0;i<m;i++){
      cin>>a>>b;
      add_edge(a+offset,b+offset);
    }
  }
  
  void dfs(int v){
    used[v]=1;
    for(int i=0;i<(int)G[v].size();i++){
      if(!used[G[v][i]]) dfs(G[v][i]);
    }
    vs.push_back(v);
  }
  
  void rdfs(int v,int k){
    used[v]=1;
    belong[v]=k;
    C[k].push_back(v);
    for(int i=0;i<(int)rG[v].size();i++){
      if(!used[rG[v][i]]) rdfs(rG[v][i],k);
    }
  }
  
  int build(){
    fill(used.begin(),used.end(),0);
    vs.clear();
    for(int v=0;v<n;v++){
      if(!used[v]) dfs(v);
    }
    fill(used.begin(),used.end(),0);
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
      if(!used[vs[i]]){
	T.push_back(vector<int>());
	C.push_back(vector<int>());
	rdfs(vs[i],k++);
      }
    }
    for(int i=0;i<n;i++)
      for(int u:G[i])
	if(belong[i]!=belong[u])
	  T[belong[i]].push_back(belong[u]);
    for(int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }
};

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<vector<int> > G(n);
  SCC scc(n);
  for(int i=0;i<n;i++){
    int c;
    cin>>c;
    G[i].resize(c);
    for(int j=0;j<c;j++) cin>>G[i][j],G[i][j]--;
    for(auto j:G[i]) scc.add_edge(j,i);
  }
  scc.build();
  auto &b=scc.belong;
  int ans=0,lst=-1;
  for(int v=0;v<n;v++){
    for(int u:G[v]){
      if(b[u]!=b[v]) continue;
      if(u==v+1) continue;
      if(u<=lst) continue;
      lst=v;ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 24360
n = int(input())
p = [int(i) for i in input().split()]
s = 0
for i in range(1,n-1):
  l1 = p[i-1:i+2]
  l2 = l1.copy()
  l2.sort()
  if l1[1] == l2[1]:
    s += 1
print(s)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        300005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
 
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}  
void solve(){
    int a,b;
    cin >> a >> b;
    cout << a*b;
}      

 
signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

Measured memory_bytes: 3612
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let delete x t =
  let rec dudu = function
    | Nil -> assert false
    | Node (x, Nil, _) -> x
    | Node (_, l, _) -> dudu l in
  let rec wa = function
    | Nil -> assert false
    | Node (_, Nil, r) -> r
    | Node (x, l, r) -> Node (x, wa l, r) in
  let rec doit = function
    | Nil -> assert false
    | Node (y, l, r) ->
      if x = y then
        if l = Nil then r
        else if r = Nil then l
        else Node (dudu r, l, wa r)
      else if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | ["delete"; n] -> t := delete (int_of_string n) !t
    | _ -> print !t
  done

Measured memory_bytes: 25236
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	ll ans = 0;
	rep(i, n) ans += n / (i + 1) - (n % (i + 1) == 0 ? 1 : 0);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3688
//#include <climits>
#include <vector>
#include <iostream>
using namespace std;

void swap(int *x, int *y) {
    int tmp = *x;
    *x = *y;
    *y = tmp;
}

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

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

    //バブルソート
    int count = 0;
    for (int i = 0; i < N-1; ++i) //i番目までソートが完了する
    {
        for (int j = N-1; j > i; --j)
        {
            if(A[j-1] > A[j]) {
                swap(A[j-1], A[j]);
                count++; //交換回数
            }
        }
    }

    //ソート後の配列を出力
    for (int i = 0; i < N; ++i)
    {
        cout << A[i];
        if(i < N-1) {
            cout << " ";
        }
    }
    cout << endl;

    //交換回数を出力
    cout << count << endl;
   
    return 0;
}


Measured memory_bytes: 3116
int main(void){
    int w, a, b;
    scanf("%d%d%d", &w, &a, &b);
    if (w + a < b) {
        printf("%d\n", b - (a + w));
        goto end;
    }
    if (b + w < a) {
        printf("%d\n", a - (b + w));
        goto end;
    }
    puts("0");
end:
    return 0;
}


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

table = [[] for _ in range(h)]
skiph = []
skipw = []
for i in range(h):
    table[i] = list(input())
    if len(set(table[i])) == 1:
        if table[i][0] == ".":
            skiph.append(i)

for i in range(w):
    if table[0][i] == ".":
        for j in range(h):
            if table[j][i] != ".":
                break
        else:
            skipw.append(i)

for i in range(h):
    if i in skiph:
        continue
    for j in range(w):
        if j in skipw:
            continue
        else:
            print(table[i][j], end="")
    print()


Measured memory_bytes: 4596
A,B =map(int,input().split())
plug_count=0
ext_count=0 
if B ==1:
    print(0)
else:
    plug_count+=A
    ext_count+=1
    while True:
        if plug_count>=B:
            break
        plug_count+=A-1
        ext_count+=1
    print(ext_count)

Measured memory_bytes: 2940
a,b=map(int,input().split())

A={}
B={}
num=2
out=1

while True:
    if a==1 and b==1:
        break
    if a%num==0:
        A.setdefault(num,0)
        A[num]+=1
        a=a/num
    elif b%num==0:
        B.setdefault(num,0)
        B[num]+=1
        b=b/num
    else:
        num+=1

for i in A.keys():
    if i in B.keys() and A[i]<=B[i]:
        out=out*i**B[i]
    else:
        out=out*i**A[i]
for i in B.keys():
    if i not in A.keys():
        out=out*i**B[i]

print(out)


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

#define N 10001
#define INF 10000000
#define NIL -1
#define BLACK 1

struct node{
  int weight;
  int key;
  struct node *next;
};
typedef struct node* NodePointer;

//int G[N][N];

NodePointer G[N];

int d[N],pi[N],color[N];

int num;

void initialize(int);
void dij(int);

int main(){
  int i,j;
  int k,u;
  int start=0;
  int v,ci;
  NodePointer x;

  scanf("%d",&num);

  /* for(i=0;i<num;i++){
     for(j=0;j<num;j++){
     G[i][j] = NIL;
     }
     }
  */
  

  for(i=0;i<num;i++){
    scanf("%d%d",&u,&k);
    G[u] = malloc(sizeof(struct node));
    G[u]->next = NULL;
    x = G[u];
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&ci);
      x->next = malloc(sizeof (struct node));
      x->next->key = v;
      x->next->weight = ci;
      x->next->next=NULL;
      x = x->next;
    }
  }

  dij(start);

  /*for(i=0;i<num;i++){
    for(j=0;j<num;j++){
    printf("%d ",G[i][j]);
    }
    printf("\n");
    }
  */

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

}

void initialize(int s){
  int v;
  for(v=0;v<num;v++){
    d[v] = INF;
    pi[v] = NIL;
  }

  d[s] = 0;
}

void dij(int s){
  int mincost;
  int i,v,u;
  NodePointer cur;
  
  initialize(s);

  while(1){
    
    mincost = INF;

    for(i=0;i<num;i++){
      
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;

      }
    }

    //printf("u=%d\n", u);
    if(mincost == INF) break;

    color[u] = BLACK;
    /*
      for(v=0;v<num;v++){
      
      if(G[u][v] == -1) continue;
      if(color[v] != BLACK && d[u] + G[u][v] < d[v]){
      pi[v]= u;
      d[v] = d[u] + G[u][v];
      }
      }
    */

    cur = G[u]->next;
    
    while(cur != NULL){
      v = cur->key;

      if(color[v] != BLACK && d[u] + cur->weight < d[v]){
	pi[v]= u;
	d[v] = d[u] + cur->weight;
      }
      cur = cur->next;
    }
  }

}



Measured memory_bytes: 17352
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
// use std::collections::VecDeque;
// use std::cmp::max;
// use std::cmp::min;


fn main() {
    input! {
        N: usize,
        M: usize,
        Hs: [i64; N],
        mut ABs: [(usize, usize); M],
    }

    // 0-origin
    for (a, b) in ABs.iter_mut() {
        *a -= 1;
        *b -= 1;
    }

    let mut neibours_map: HashMap<usize, Vec<usize>> = HashMap::new();
    for i in 0..N {
        neibours_map.insert(i, Vec::new());
    }

    for &(a, b) in ABs.iter() {
        neibours_map.get_mut(&a).unwrap().push(b);
        neibours_map.get_mut(&b).unwrap().push(a);
    }

    let mut ans = 0;
    for i in 0..N {
        let vec: &Vec<usize> = neibours_map.get(&i).unwrap();
        let cnt = vec.iter().filter(|&&neibour| Hs[neibour] >= Hs[i]).count();
        if cnt == 0 {
            ans += 1;
        }
    }

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


Measured memory_bytes: 14064
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;


public class Main {
    static final int UNCALC = -1;
    static final long INF = (long) 1e18;
    static int n, w[], v[];
    static long memo[][];

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        int W = sc.nextInt() + 1;
        v = new int[n];
        w = new int[n];
        memo = new long[W + 1][n+1];
        Arrays.fill(memo[0], -INF);
        for (int i = 0 ; i< n ; i++){
            w[i]= sc.nextInt();
            v[i]= sc.nextInt();
        }
        for (int i = n - 1; i >= 0; i--)
            for (int rem = W; rem >= 0; rem--)
                memo[rem][i] = Math.max(v[i] + memo[Math.max(0, rem - w[i])][i + 1], memo[rem][i + 1]);
        out.println(memo[W][0]);
        out.flush();
        out.close();
    }


    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }


    }

}

Measured memory_bytes: 133192
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    long[] A = new long[N];
    for (int i = 0; i < N; i++) A[i] = scanner.nextLong();

    long count = 0;
    long[] c = new long[N];
    while (!done(A, N)) {
      long sum = 0;
      Arrays.fill(c, 0);
      for (int i = 0; i < N; i++) {
        c[i] = A[i] / N;
        count += c[i];
        sum += c[i];
        A[i] -= c[i] * N;
      }
      for (int i = 0; i < N; i++) {
        A[i] += sum - c[i];
      }
    }
    System.out.println(count);
  }

  private static boolean done(long[] A, int N) {
    for (long a : A) if (a >= N) return false;
    return true;
  }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)
#define mp make_pair
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define scfl(xx) scanf("%I64d",&xx)
#define All(a) a.begin(), a.end()


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, ll> ii;
typedef long double ld;



vector<ii> sol;
bool solve1(vi v){
	sol.clear();
	set<ii> st;
	rep(i, v.size())st.insert(mp(v[i], i));
	set<ii>::iterator it;
	for (int i = 1; i < v.size(); i++){
		if (v[i] >= v[i - 1])continue;
		if (v[i] + st.rbegin()->first <= v[i])
			return false;
		while (v[i] < v[i - 1]){
			it = st.lower_bound(mp(v[i - 1] - v[i], -1));
			if (it == st.end())it--;
			ii p = *it;
			st.erase(mp(v[i], i));
			v[i] += p.first;
			sol.push_back(mp(p.second + 1, i + 1));
			if (sol.size() > 2 * v.size()) return false;
			st.insert(mp(v[i], i));
		}
	}
	return true;
}

bool solve2(vi v){
	sol.clear();
	set<ii> st;
	set<ii>::iterator it;
	rep(i, v.size())st.insert(mp(v[i], i));
	for (int i = v.size() - 2;i >= 0; i--){
		if (v[i] <= v[i + 1])continue;
		if (v[i] + st.begin()->first >= v[i])
			return false;
		while (v[i] > v[i + 1]){
			int diff = v[i + 1] - v[i];
			it = st.upper_bound(mp(diff, -1));
			if (it != st.begin()) it--;

			ii p = *it;
			st.erase(mp(v[i], i));
			v[i] += p.first;
			sol.push_back(mp(p.second + 1, i + 1));
			if (sol.size() > 2 * v.size()) return false;
			st.insert(mp(v[i], i));
		}
	}
	return true;
}
int main(){	
	fastIO;
	//write; read;
	int n;
	vi v;
	cin >> n;
	v.resize(n);
	rep(i, n)cin >> v[i];
	if (solve1(v) == false)
		solve2(v);
	assert(sol.size() <= 2 * n);
	cout << sol.size() << endl;
	rep(i, sol.size())
		cout << sol[i].first << " " << sol[i].second << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int abcd[] = new int [4];
    for(int i = 0;i < 4;i++){
      abcd[i] = sc.nextInt();
    }
    if(Math.abs(abcd[0] - abcd[2]) <= abcd[3] || (Math.abs(abcd[0] - abcd[1]) <= abcd[3] && Math.abs(abcd[1] - abcd[2]) <= abcd[3])){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0;
using namespace std;
string s;
int d;
int dp[10010][110][2];
signed main(){
    cin>>s>>d;
    dp[0][0][1]=1;
    rep(i,s.size()){
        rep(j,d){
            rep(k,10){
                if(s[i]==k+'0')dp[i+1][(j+k)%d][1]+=dp[i][j][1];
                else if(s[i]>k+'0')dp[i+1][(j+k)%d][0]+=dp[i][j][1];
                dp[i+1][(j+k)%d][0]+=dp[i][j][0];
                dp[i+1][(j+k)%d][0]%=moder;
                dp[i+1][(j+k)%d][1]%=moder;
            }
        }
    }
    cout<<(dp[s.size()][0][0]+dp[s.size()][0][1]-1+moder)%moder<<endl;
    ggr;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n;
    string s;
    cin >> n >> s;

    int maxN = 0,sum = 0;
    for (int i = 0; i < n; i++){
        if (s[i] == 'I'){
            sum++;
        } else {
            sum--;
        }
        maxN = max(maxN, sum);
    }
    cout << maxN << endl;

    return 0;
}


Measured memory_bytes: 256
x, y, z = input()
a = 0
if x == 'R':
  a += 1
  if y == 'R':
    a += 1
    if z == 'R':
      a += 1
else:
  if y == 'R':
    a += 1
    if z == 'R':
      a += 1
  else:
    if z == 'R':
      a += 1
print(a)

Measured memory_bytes: 9036
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main(int argc , char **argv)
{
	(void)argc;
	(void)argv;

	char S[101]={};
	int N;
	cin >> N;
	cin >> S;

	// -> -> -> ペアのない '(' を数える
	int cL = 0;
	for(int i=0;i<N;i++){
		if (S[i]=='(' ){cL++;}
		else if ((S[i]==')')&&(0 < cL)){cL--;}
	}

	// <- <- <- ペアのない ')' を数える
	int cR=0;
	for(int i=N-1;0<=i;i--){
		if(S[i]==')' ){cR++;}
		else if((S[i]=='(')&&(0 < cR)){cR--;}
	}

	for(int i=0;i<cR;i++){ printf("("); }
	printf("%s",S);
	for(int i=0;i<cL;i++){ printf(")"); }
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
program disjoint_set_of_common_divisors
  implicit none
  integer(8) :: a, b, g, p
  integer :: n, i, m = 1
  read(*,*) a, b
  g = gcd(a,b)
  n = ceiling(sqrt(real(g,8)+0.5d0))
  do i = 2, n
    p = int(i,8)
    if (mod(g,p) /= 0_8) cycle
    m = m+1
    do while (mod(g,p) == 0_8)
      g = g/p
    end do
  end do
  if (g /= 1_8) m = m+1
  write(*,'(i0)') m
contains
  integer(8) function gcd(a,b)
    integer(8), intent(in) :: a, b
    integer(8) :: x, y
    x = max(a,b)
    y = min(a,b)
    do while (y > 0_8)
      gcd = y
      y = mod(x,y)
      x = gcd
    end do
  end
end program disjoint_set_of_common_divisors

Measured memory_bytes: 256
import java.util.*;

public class Main {


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

        int a = Integer.parseInt(s);
        int[][] aaa = new int[a][a];
        for(int i = 0; i < a; i++){
            for(int j = 0; j < a; j++){
                aaa[i][j] = 0;
            }
        }
        for(int i = 0; i < a; i++){
            int a1 = sc.nextInt();
            int a2 = sc.nextInt();
            for(int j = 0; j < a2; j++){
                int a3 = sc.nextInt();
                aaa[a1-1][a3-1] = 1;
            }
        }

        for(int i = 0; i < a; i++){
            for(int j = 0; j < a; j++){
                if(j == a - 1) {
                    System.out.print(aaa[i][j]);
                }
                else
                System.out.print(aaa[i][j] + " ");

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





Measured memory_bytes: 31612
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}




int main() {
  int H,W;
  cin >> H >> W;
  vector<string> A(H);
  vector<vector<int>> grid(H,vector<int>(W,-1));
  queue<vector<int>> q;
  rep(i,H) {
    cin >> A[i];
    rep(j,W) if (A[i][j]=='#') {
      grid[i][j]=0;
      q.push({i,j,0});
    }
  }

  int res = 0;
  while (!q.empty()) {
    auto t = q.front();
    int y = t[0],x = t[1];
    q.pop();
    if (x>0) if (grid[y][x-1]==-1) {
      grid[y][x-1] = t[2]+1;
      q.push({y,x-1,t[2]+1});
    }
    if (y>0) if (grid[y-1][x]==-1) {
      grid[y-1][x] = t[2]+1;
      q.push({y-1,x,t[2]+1});
    }
    if (x<W-1) if (grid[y][x+1]==-1) {
      grid[y][x+1] = t[2] + 1;
      q.push({y,x+1,t[2]+1});
    }
    if (y<H-1) if (grid[y+1][x]==-1) {
      grid[y+1][x] = t[2] + 1;
      q.push({y+1,x,t[2]+1});
    }
    chmax(res,t[2]);
  }
  cout << res << endl;
}

Measured memory_bytes: 60724
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    vector<int> a(m);
        rep(i,m) cin>>a.at(i);
    int sum=0;
    rep(i,m) sum +=a[i];
    int ans=n-sum;
    if(ans<0) cout<<-1<<endl;
    else cout<<ans<<endl;
}/*
./problem.exe
*/

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


int main(){
	int n,a;
	cin >> n >> a;
	for(int i=0;i<a;i++){
		int b;
		cin >> b;
		n=n-b;
	}
	if(n<0){
		cout << -1 << endl;
	}else{
		cout << n << endl;
	}
}

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

using namespace std;

int main() {
    string s;
    cin >> s;

    long long sum = 0;
    for(int i = 0; i < s.size(); i++) {
        sum += s[i] - '0';
    }

    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3696
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 17:18:46 2019
ABC122B
@author: maezawa
"""

s = input()
n = len(s)
cnt = 0
atcgset = set(['A','T','C','G'])
for i in range(n):
    for j in range(i,n):
        subs = s[i:j+1]
        #print(s[i:j+1])
        sset = set(s[i:j+1])
        if atcgset >= sset:
            #print(s[i:j])
            if len(subs) > cnt:
                cnt = len(subs)
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    int ans;
    priority_queue<int>pq;
    rep(i,N){
        int a;
        cin>>a;
        pq.push(a);
    }
    while(1){
        int num1,num2;        
        if(pq.size()==1){
            ans=pq.top();
            pq.pop();
            cout<<ans<<endl;
            break;
        }else{
            num1=pq.top();
            pq.pop();
            num2=pq.top();
            pq.pop();
        }
        while(num1>=num2){
            num1-=num2;
        }
        if(num1>0){
            pq.push(num1);
        }
        pq.push(num2);
    }
}

Measured memory_bytes: 3916
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
D=sum([A[i]-1 for i in A if A[i]>=2])
print(N-(D+D%2))
#print(sorted([[i,A[i]-1] for i in A if A[i]>=2],key=lambda x:x[0]))


Measured memory_bytes: 62124
import functools

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
n,x = map(int,input().split())
list_x = list(map(int,input().split()))

diff=[None]*n
for i in range(n):
  diff[i] = abs(list_x[i] - x)


ans = functools.reduce(gcd, diff)
  
print(ans)

Measured memory_bytes: 14748
D=60
f=lambda:[*map(int,input().split())]
n,k=f()
l=f()
t=[[0]*n for _ in range(D)]
for i in range(n):
  t[0][i]=l[i]-1
for i in range(D-1):
  for j in range(n):
    t[i+1][j]=t[i][t[i][j]]
a=0
for i in range(D):
  if k%2: a=t[i][a]
  k//=2
print(a+1)

Measured memory_bytes: 182380
#include<stdio.h>

int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	if(b>c){
		d=b;
		b=c;
		c=d;
	}
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/

signed main()/*Check flow ---question galat mat padhna */
{
    fast;
    ll a;
    ld b;
    cin>>a>>b;
    ld ans=(a*b);
    ll ans1=(a*b);
    cout<<ans1<<endl;
}   

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	multiset<int> small, large;
	ll sum = 0, m = -inf, ans = 0;
	rep(_, n) {
		int type;
		cin >> type;
		if (type == 1) {
			int a, b;
			cin >> a >> b;
			sum += b;
			if (small.size() == large.size()) {
				if (large.size() == 0 || a <= *large.begin()) small.insert(-a);
				else {
					large.insert(a);
					small.insert(-*large.begin());
					large.begin() = large.erase(large.begin());
				}
			}
			else {
				if (-*small.begin() <= a) large.insert(a);
				else {
					small.insert(-a);
					large.insert(-*small.begin());
					small.begin() = small.erase(small.begin());
				}
			}
			int d = -*small.begin();
			if (m > d) ans += m - d;
			m = d;
			ans += abs(m - a);
		}
		else if (type == 2) cout << m << ' ' << ans + sum << '\n';
	}
}

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>



void solve() {
    int n;
    string s;
    cin >> n >> s;
    int r = 0, w = 0;
    for (int i = 0; i < n; i++)
        (s[i] == 'R' ? r : w)++;
    int ans = w;
    for (int i = n - 1; i >= 0; i--)
        if (n - 1 - i < w && s[i] == 'W')
            ans--;
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

    // 左, 右それぞれの累積和
    ll l_sum[n+1], r_sum[n+1];
    ll l_tot = 0;
    rep(i,n+1) {
      l_tot += i;
      l_sum[i] =l_tot;
    } 
    ll r_tot = 0;
    for (int i=n; i>=0; i--) {
      r_tot += i;
      r_sum[n-i] =r_tot;
    }

    mint ans = 0;
    for (int i=k; i<=n+1; i++) {
      mint x = 0;
      x += r_sum[i-1];
      x -= l_sum[i-1];
      x += 1;
      ans += x;
    }

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


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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    pair <pair<int,int>,int> a[n];
    int x2[n];
    int y2[n];
    for(int i=0;i<n;++i)
    {
        cin>>a[i].first.first>>a[i].first.second>>a[i].second;
        x2[i]=a[i].first.first;y2[i]=a[i].first.second;
    }
    int ans[n+1];
    for(int i=0;i<=n;++i) ans[i]=1e18;
    int sz=(1<<n);
    vector <int> x3[sz];vector <int> y3[sz];
    for(int mask=0;mask<sz;++mask)
    {
        for(int i=0;i<n;++i)
        {
            if(mask & (1<<i))
            {
                x3[mask].push_back(x2[i]);
                y3[mask].push_back(y2[i]);
            }
        }
        x3[mask].push_back(0);y3[mask].push_back(0);
        x3[mask].push_back(-1e9);x3[mask].push_back(1e9);y3[mask].push_back(-1e9);y3[mask].push_back(1e9);
        sort(x3[mask].begin(),x3[mask].end());sort(y3[mask].begin(),y3[mask].end());
    }
    for(int mask1=0;mask1<sz;++mask1)
    {
        for(int mask2=mask1;;mask2=(mask2-1) & mask1)
        {
            int mask=(sz-1-mask1);
            int sum=0;
            for(int i=0;i<n;++i)
            {
                int o1=x2[i];
                int o2=y2[i];
                vector <int>::iterator it=lower_bound(x3[mask].begin(),x3[mask].end(),o1);
                int res1=(*it-o1);it--;res1=min(res1,o1-*it);
                if(!res1) continue;
                it=lower_bound(y3[mask2].begin(),y3[mask2].end(),o2);
                int res2=(*it-o2);it--;res2=min(res2,o2-*it);
                sum+=min(res1,res2)*a[i].second;
            }
            int curr=__builtin_popcount(mask)+__builtin_popcount(mask2);
            ans[curr]=min(ans[curr],sum);
            if(mask2==0)
            {
                break;
            }
        }
    }
    for(int i=0;i<=n;++i)
    {
        cout<<ans[i]<<' ';
    }
    return 0;
}


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

using namespace std;


signed main(){
    int N;cin >> N;
    vector<int> vec;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        vec.push_back(b);
    }
    for(int i = 0;i < N-1;i++){
        for(int j = i + 1;j < N;j++){
            if(abs(vec.at(i) - vec.at(j)) % (N-1) == 0){
                cout<<vec.at(i)<<" "<<vec.at(j)<<endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
int n; cin>>n;
map<string,int> m;
 forn(i,n){
 	string s; cin>>s;
 	m[s]++;
 } 
  int ma = -1;
  for(auto i:m){
  	ma = max(ma, i.se);
  }
  set<string> s;
  for(auto i:m){
  	if(i.se==ma) s.insert(i.fi);
  }
  for(auto i:s) cout<<i<<endl;
  	
  return 0;
}

Measured memory_bytes: 33280
#include<stdio.h>

int main(void)
{
    int i, j, k, n, b, f, r, v, house[4][3][10]={0};
    
    scanf("%d", &n);
    
    for(i=0; i<n; i++){
        scanf("%d %d %d %d", &b, &f, &r, &v);
        house[b-1][f-1][r-1]+=v;
    }
    
    for(i=0; i<4; i++){
        for(j=0; j<3; j++){
            for(k=0; k<10; k++){
                printf(" %d", house[i][j][k]);
            }
            putchar('\n');
        }
        if(i!=3){
            printf("####################\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2108
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000


def main():
    # ------ 入力 ------#
    # 1行入力
    a = input()     # 文字列

    # ------ 出力 ------#
    if a[-1] == "s":
        print("{}".format(a + "es"))
    else:
        print("{}".format(a + "s"))

if __name__ == '__main__':
    main()


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



//UnionFind Template
template <class T>
struct UnionFind{ //構造体の定義
    vector<T> d; //メンバ変数
    UnionFind(T n=0): d(n,-1) {} //コンストラクタ（構造体が呼ばれたときにすぐに実行される処理）
    T find(T x){
        if(d[x]<0) return x;
        return d[x]=find(d[x]);
    }
    bool unite(T x, T y){
        x=find(x); y=find(y);
        if(x==y) return false;
        if(d[x]<d[y]) swap(x,y);//d[x] is smaller. Then, connect d[x] to d[y].
        d[y]+=d[x];
        d[x]=y;
        return true;
    }
    bool same(T x, T y){
        return find(x)==find(y);
    }
    T size(T x){
        return -(d[find(x)]);   
    }
};



int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> fr(100005);
    vector<int> bl[100005];
    UnionFind<int> uf(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        --a; --b;
        fr[a]++; fr[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int a,b;
        cin>>a>>b;
        --a; --b;
        bl[a].push_back(b);
        bl[b].push_back(a);
    }
    rep(i,n){
        int ans;
        ans=uf.size(i)-1-fr[i];
        for(int a : bl[i]){
            if(uf.same(i,a)) ans--;
        }
        cout<<ans<<" ";
    }
    return 0;
}

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i,n) {
        int ai; cin >> ai;
        ai = abs(ai-x);
        a[i] = ai;
    }
    
    int ans = a[0];
    rep(i,n){
        ans = __gcd(ans,a[i]);
    }
    cout << ans << endl;
}


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

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

bool is_triangle(int a, int b, int c){
    return (a < b + c && b < a + c && c < a + b);
}
bool is_right(int a, int b, int c){
    return a * a + b * b == c * c;
}
int get_type(int a, int b, int c){
    if (is_right(a, b, c) || is_right(b, c, a) || is_right(a, c, b)){
        return 1;
    }
    if (is_triangle(a * a, b * b, c * c)){
        return 2;
    }
    return 3;
}
int main()
{
    int bucket[4] = {};
    int a, b, c;
    while (~scanf("%d %d %d", &a, &b, &c)){
        if (is_triangle(a, b, c)){
            bucket[0]++;
            bucket[get_type(a, b, c)]++;
        }
        else break;
    }
    show_a(bucket, 4);
    return (0);
}

Measured memory_bytes: 1204
N = int(input())

T = list(map(int,input().split()))
A = list(map(int,input().split()))

X = [[T[0], 1]]
Y = [[A[N-1], 1]]

for i in range(1,N) :
    pv,pf = X[i-1]
    nv = T[i]
    
    if nv == 1 :
        X.append([nv, 1])
    elif pv >= nv :
        X.append([nv, 0])
    else :
        X.append([nv, 1])
    
    pv,pf = Y[i-1]
    nv = A[N-1-i]
    
    if nv == 1 :
        Y.append([nv, 1])
    elif pv >= nv :
        Y.append([nv, 0])
    else :
        Y.append([nv, 1])

Y = Y[::-1]

ans = 1

mat = 0
maa = 0

for i in range(N) :
    tv,tf = X[i]
    av,af = Y[i]
    
    mat = max(mat, tv)
    maa = max(maa, av)
    
    if tf == 1 and af == 0 :
        if tv > maa :
            ans = 0
            break
    elif tf == 0 and af == 1 :
        if av > mat :
            ans = 0
            break
    elif tf == 1 and af == 1 :
        if tv != av :
            ans = 0
            break
    else :
        ans *= min(tv,av)
        ans %= (10**9+7)
        
print(ans)


Measured memory_bytes: 33732
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

int MAXX = 54000;
int main() {
  int n;
  cin >> n;
  int x = -1;
  rep(i, MAXX + 1) {
    if(i * 108 / 100 == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 384
from math import gcd
n=int(input())
a=list(map(int,input().split()))
dic={}
for i,v in enumerate(a):
    dic[i+1]=v
#print(dic)
dic_sorted = list(sorted(dic.items(), key=lambda x:x[1]))
for i in range(n):
    if i!=n-1:
        print(dic_sorted[i][0],end=' ')
    else:
        print(dic_sorted[i][0])


Measured memory_bytes: 30260
#define _USE_MATH_DEFINES
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>
#include <iomanip>
#include <cmath>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
  ll n;
  cin >> n;
  ll mod = 1e9+7;
  ll z = mod - 1;
  map<pair<ll, ll>, pair<ll, ll>> pairs;
  loop(i, n){
    ll a, b;
    cin >> a >> b;
    if(a == 0 && b == 0) { 
      z++; 
      continue;
    }else if(make_pair(a, b) < make_pair(0ll, 0ll)){
      a = -a, b = -b;
    }
    ll g = gcd(abs(a), abs(b));
    a = a/g;
    b = b/g;
    if(b > 0) pairs[{a, b}].first++;
    else pairs[{-b, a}].second++;
  }

  ll pw[200200] = {1};

  for (ll i = 1; i < 200200; i++) {
    pw[i] = (pw[i - 1] * 2) % mod;
  }
  ll ans = 1;
  for(auto p: pairs){
    ans = ans*(pw[p.second.first] + pw[p.second.second]-1)%mod;
  }

  cout << (z+ans)%mod << endl;
}    
  




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

using namespace std;


#define MAXN 2001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, z, w, a[MAXN];
  cin >> n >> z >> w;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cout << max(abs(a[n-1]-w), abs(a[n-2]-a[n-1])) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

void solve(){
    ll n; cin>>n;

    ll a[n];
    FOR(i,0,n-1){
        ll x; cin>>x;
        a[i] = x;
    }

    FOR(i,0,n-1){
        ll x; cin>>x;
        a[i] -= x;
    }

    sort(a,a+n);
    reverse(a,a+n);
    ll sum = 0;
    ll ans = 0;
    FOR(i,0,n-1){   
        sum += a[i];
        ans = max(ans,sum);
    }
    cout<<ans<<endl;
}   

signed main(){

 
    FastRead;    

    ll t;
    t = 1; 
    // cin>>t;
    while(t--) solve();
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  998244353;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  ll n, m ,q;
  cin >> n >> m >> q;
  vector<vector<int>> g(n, vector<int>(n));
  REP(i, m) {
    int l, r;
    cin >> l >> r;
    l--;r--;
    g[l][r]++;
  }
  vector<vector<int>> cum(n+1, vector<int>(n+1));
  REP(y, n) {
    REP(x, n) {
      cum[x+1][y+1] = cum[x+1][y] + cum[x][y+1] + g[x][y] - cum[x][y];
    }
  }
  vector<int> ans;
  REP(i, q) {
    int p, q;
    cin >> p >> q;
    p--;q--;
    cout << cum[q+1][q+1] - cum[p][q+1] - cum[q+1][p] + cum[p][p] << endl;;
  }
  // REP(y, n+1) {
  //   REP(x, n+1) {
  //     cout << cum[x][y] << " ";
  //   }
  //   cout << endl;
  // }
    return 0; 
}


Measured memory_bytes: 2944