akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Easy Linear Programming
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    int ret = 0;
    
    int change = min(k, a);
    ret += change;
    k -= change;
    
    change = min(k, b);
    k -= change;
    
    change = min(k, c);
    ret -= change;
    
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define mp make_pair
using namespace std;
string s[1000];
int dis[805][805];
int vis[805][805];
int main(){
	int n, m, k;
	cin >> n >> m >> k;
	int sx, sy;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		for(int j = 0; j < m; j++){
			if(s[i][j] == 'S')sx = i, sy = j;
			dis[i][j] = 1e9;
			vis[i][j] = 0;
		}
	}
	int ans = 1e9;
	queue<pair<int,int> > q;
	q.push(make_pair(sx, sy));
	dis[sx][sy] = 0;
	int xx[4] = {0, 0, 1, -1};
	int yy[4] = {1, -1, 0 ,0};
	while(!q.empty()){
		int x = q.front().first, y = q.front().second;
		q.pop();
		if(vis[x][y] != 0)continue;
		if(dis[x][y] > k)continue;
		ans = min(ans, 1 + (x+k-1)/k);
		ans = min(ans, 1 + (y+k-1)/k);
		ans = min(ans, 1 + (n-x+k-2)/k);
		ans = min(ans, 1 + (m-y+k-2)/k);
		for(int i = 0; i < 4; i++){
			int xxx = x + xx[i], yyy = y + yy[i];
			if(xxx >= 0 && xxx < n && yyy >= 0 && yyy < m && s[xxx][yyy] != '#' && dis[xxx][yyy] > dis[x][y]+1 && vis[xxx][yyy] == 0){
				dis[xxx][yyy] = dis[x][y]+1;
				q.push(mp(xxx,yyy));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
	*this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

template<typename T>
void dump(const T& arr){
  std::cout << "[";
  for(const auto& elem: arr){
    std::cout << elem << ", ";
  }
  std::cout << "]" << std::endl;
}

template<typename T>
T sum(const std::vector<T> &arr, int st, int ed){
  T ret = 0;
  for(int i=st; i<ed; i++){
    ret += arr[i];
  }
  return ret;
}

void update_memory(const std::vector<modint<998244353> > &masu,
		   const std::vector<std::array<int, 2> > &lr,
		   std::vector<modint<998244353> > &memory,
		   int target){
  for(int i=0; i<lr.size(); i++){
    const auto& elem = lr[i];
    if(elem[0] <= target)
      memory[i] += masu[target - elem[0]];
    if(elem[1] <  target)
      memory[i] -= masu[target - elem[1] - 1];
  }

  //std::cout << "memory:[" << target << "]";
  //for(const auto& elem: memory){
  //  std::cout << elem.a << ",";
  //}
  //std::cout << std::endl;
}
		   

void solve(void){
  int n, k;
  std::cin >> n >> k;
  std::vector<std::array<int, 2> > lr(k);
  for(int i=0; i<k; i++){
    std::cin >> lr[i][0] >> lr[i][1];
  }
  
  std::vector<modint<998244353> > memory(k);
  std::vector<modint<998244353> > masu(n);
  masu[0] = 1;
  for(int i=1; i<n; i++){
    update_memory(masu, lr, memory, i);
    masu[i] = sum(memory, 0, memory.size());
  }
  std::cout << masu[n-1].a << std::endl;

  //for(const auto& elem: masu){
  //  std::cout << elem.a << " ";
  //}
  //std::cout << std::endl;
  
  return;

}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 4776
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
  int m, n, a[1000], sum = 0, cnt = 0;
  ;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  for (int i = 0; i < n; i++) {
    if (sum % (4 * m) == 0 && a[i] >= sum / (4 * m)) {
      cnt++;
    } else if (sum % (4 * m) && a[i] > sum / (4 * m)) {
      cnt++;
    }
  }
  if (cnt >= m) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 128
// DFS
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int N;
int P[8], Q[8];

int a, b;

void check_permutation(vector<int> permutation, const int n) {
    bool flg_P = true, flg_Q = true;
    REP (i, N) {
        if (permutation.at(i) != P[i]) {
            flg_P = false;
        }
        if (permutation.at(i) != Q[i]) {
            flg_Q = false;
        }
    }
    if (flg_P) {
        a = n;
    }
    if (flg_Q) {
        b = n;
    }
}

int cnt = 0;
vector<int> permutation;
void dfs(int depth, const int N) {
    if (depth == N) {
        cnt++;
        check_permutation(permutation, cnt);
    }
    else {
        REP (i, N) {
            bool ok = true;
            if (depth != 0) {
                REP (j, depth) {
                    // 重複する数字を持つ順列を除外
                    if (i == permutation.at(j)) {
                        ok = false;
                    }
                }
            }
            if (ok) {
                permutation.push_back(i);
                dfs(depth+1, N);
            }
        }
    }
    permutation.pop_back();
}

int main(void) {
    cin >> N;
    REP (i, N) {
        cin >> P[i];
        P[i]--;
    }
    REP (i, N) {
        cin >> Q[i];
        Q[i]--;
    }

    dfs(0, N);

    cout << abs(a-b) << endl;
}

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


int main(){
  int w,n,h,i;
  
  scanf("%d\n",&w);
  scanf("%d\n",&n);

  int a[30],b[30];
  int c[30];

  for(i=0;n>i;++i){
    scanf("%d,%d\n",&a[i],&b[i]);
    --a[i];
    --b[i];
}
  
  for(i=0;w>i;++i){
    c[i]=i;
  }
   
  for(i=0;n>i;++i){
    h=c[b[i]];
    c[b[i]]=c[a[i]];
    c[a[i]]=h;
  }
  for(i=0;w>i;++i){
    ++c[i];
    printf("%d\n",c[i]);
  }

  
  return 0;
}

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

int N;

void dfs(string s) {
  if (s.size() == N) {
    cout << s << "\n";
    return;
  }
  char mx = *max_element(s.begin(), s.end());
  for (char c = 'a'; c <= mx + 1; c++) dfs(s + c);
}

int main() {
  cin >> N;
  dfs("a");
}


Measured memory_bytes: 1536
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n = inp()
    p = inpl()
    ans = 0
    m = 10**6
    for i in range(n):
        if m > p[i]:
            m = p[i]
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> v;
    for(int i = 0; i < m; ++i){
        int tmp;
        cin>>tmp;
        v.push_back(tmp);
    }

    int ans1=0;
    for(auto val : v){
        if(val<x)
            ++ans1;
        else
            break;
    }
    int ans2=0;
    reverse(v.begin(), v.end());
    for(auto val : v) {
        if(val>x)
            ++ans2;
        else
            break;
    }

    cout<<min(ans1,ans2)<<endl;



    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<int,int> P;
 #include <boost/multiprecision/cpp_int.hpp>

using bint = boost::multiprecision::cpp_int;
 
pair<int,int> f(int x){
    int a = x%10;
    int b = x;
    while(b>=10){
        b /= 10;
    }
    rn mp(b,a);
}
 
int main(){
    int n;
    cin >> n;
    map<P,int> freq;
    rep(i,n+1){
        freq[f(i)]++;
    }
    bint ans = 0;
    rep(i,n+1){
        ans += freq[mp(f(i).se,f(i).fi)];
    }
    cout << ans -1;
    
}

Measured memory_bytes: 256
# Your code here!

a,b=gets.split().map(&:to_i)

g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]

flag = false

if(g1.include?(a)&&g1.include?(b))
    flag = true
end

if(g2.include?(a)&&g2.include?(b))
    flag = true
end

puts (flag ? "Yes":"No")

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

int col, row;
vector<vector<char>> field;

bool is_in_field(const pii p) {
  const int c = p.second;
  const int r = p.first;
  return (0 <= c && c < col) && (0 <= r && r < row);
}

int wfs(const pii start, const pii goal) {
  vector<vi> memo;
  for (int i = 0; i < row; ++i) {
    vi v(col, 0);
    memo.push_back(v);
  }

  const pii points[] = {
      {-1, 0},
      {1, 0},
      {0, -1},
      {0, 1},
  };

  queue<pii> q;
  q.push(start);

  while (!q.empty()) {
    pii cur = q.front();
    q.pop();

    if (cur == goal) {
      return memo[cur.first][cur.second];
    }

    for (const auto p : points) {
      pii next = cur;
      next.first += p.first;
      next.second += p.second;
      if (is_in_field(next)) {
        const char s = field[next.first][next.second];
        if (s == '.' || s == 'g') {
          if (memo[next.first][next.second] == 0) {
            q.push(next);
            memo[next.first][next.second] = memo[cur.first][cur.second] + 1;
          }
        }
      }
    }
  }
  return -1;
}

void solve() {
  cin >> row >> col;
  vector<vector<char>> tmp;
  for (int i = 0; i < row; ++i) {
    vector<char> v(col, 0);
    for (int j = 0; j < col; ++j) {
      cin >> v[j];
    }
    tmp.push_back(v);
  }

  int ans = 0;
  for (int i = 0; i < row; ++i) {
    for (int j = 0; j < col; ++j) {
      if (tmp[i][j] == '.') {
        field = tmp;
        for (int k = 0; k < row; ++k) {
          for (int l = 0; l < col; ++l) {
            if ((k != i || l != j) && tmp[k][l] == '.') {
              field[k][l] = 'g';
              pii start = make_pair(i, j);
              pii goal = make_pair(k, l);
              ans = max(ans, wfs(start, goal));
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
 
int N,S,M;
int X[101010];
ll P[101010];
ll ret;

void dfs(int L,int R,int pre) {
	if(L==M) {
		ret+=X[R]-X[M];
		if(pre>=0) ret+=abs(X[R]-X[pre]);
		return;
	}
	if(R==M) {
		ret+=X[M]-X[L];
		if(pre>=0) ret+=abs(X[L]-X[pre]);
		return;
	}
	if(P[L]>=P[R]) {
		P[L]+=P[R];
		if(pre>=0) ret+=abs(X[pre]-X[R]);
		dfs(L,R-1,R);
	}
	else {
		P[R]+=P[L];
		if(pre>=0) ret+=abs(X[pre]-X[L]);
		dfs(L+1,R,L);
		
	}
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	int first=1;
	FOR(i,N) {
		cin>>X[i]>>P[i];
		if(first&&X[i]>S) {
			first=0;
			M=i;
			N++;
			X[i+1]=X[i];
			P[i+1]=P[i];
			X[i]=S;
			P[i]=0;
			i++;
		}
	}
	if(first) X[N]=S,P[N]=0,N++;
	dfs(0,N-1,-1);
	
	cout<<ret<<endl;
	
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
 int main(){
 	double f,x,y;
 	int d,R,a,b;
 	scanf("%d %d",&a,&b);
 	d = a/b;
 	R = a%b;
 	x = a;
 	y = b;
 	f = x/y;
  	printf("%d %d %f\n",d,R,f);
 	return 0;
 }

Measured memory_bytes: 1808
#include<iostream>
using namespace std;
int main()
{
	int a[200]={0},n,i;
	cin>>n;
	for(i=0;i<n;i++)  cin>>a[i]; 
	int flag=1,count=0;
	while(flag)
	{
		flag=0;
		for(i=n-1;i>0;i--)
		{
			if(a[i]<a[i-1])
			{
				int h=a[i];
				a[i]=a[i-1];
				a[i-1]=h;
				flag=1;
				count++;
			} 	
		} 
	}
	for(i=0;i<n-1;i++) cout<<a[i]<<" ";
	cout<<a[n-1]<<endl;
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main(void){
    int n;
    std::cin >> n;
    char s[100];
    bool flag=false;
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
        if(s[i]=='Y')flag=true;
    }
    if(flag){
        std::cout << "Four" << std::endl;
    }else{
        std::cout << "Three" << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1000000000
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 100001

using namespace std;

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

int main() {
  int N;
  ll x, a[MAX_N];
  cin >> N >> x;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  ll d;
  ll score = 0;
  for (int i = 0; i < N-1; i++) {
    d = a[i] + a[i+1] - x;
    if (d > 0) {
      if (a[i+1] >= d)
        a[i+1] -= d;
      else {
        a[i] -= (d - a[i+1]);
        a[i+1] = 0;
      }
      score += d;
    }
  }

  cout << score << endl;

  return 0;
}


Measured memory_bytes: 1024
import math
import collections
import itertools

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

    N=int(input())
    maxzoro=0
    zoro=0
    for i in range(N):
        D1,D2=map(int,input().split())
        if(D1==D2):
            zoro+=1
        else:
            zoro=0
        maxzoro=max(maxzoro,zoro)
    YesNo(maxzoro>=3)

resolve()


Measured memory_bytes: 9468
h,w=map(int,input().split())
if h ==1 or w==1:
    print(1)
else:
    if h%2==0:
        hk=h//2
        hg=h//2
    else:
        hk=h//2+1
        hg=h//2
    if w%2==0:
        wk=w//2
        wg=w//2
    else:
        wk=w//2+1
        wg=w//2
    print((hk*wk)+(hg*wg))

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

namespace abc134_e
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().ToInteger();
            var a = new int[n];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = Console.ReadLine().ToInteger();
            }

            // 各色の最大値(最後の値)を小さい順に入れて置く
            var colors = new List<int>();
            colors.Plus(0, a[0]);
            for (int i = 1; i < a.Length; i++)
            {
                // 各色の最後の値より大きいものの中で、最大の値を採用
                // どの色の最後の値よりも小さかったら、色を足す。
                var color = colors.Smaller(a[i] - 1);
                colors.Minus(color);
                colors.Plus(color, a[i]);
            }

            Console.WriteLine($"{colors.Count}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int Smaller(this List<int> list, int key)
        {
            // 開始位置
            var first = 0;
            // 終了位置+1
            var last = list.Count;
            while (first < last)
            {
                // 中央位置
                var middle = (last + first) / 2;
                // 中央位置を比較して、範囲を狭めていく
                if (list[middle] < key)
                {
                    first = middle + 1;
                }
                else
                {
                    last = middle;
                }
                if (list[middle] == key)
                {
                    first = middle;
                    last = middle;
                    break;
                }
            }

            if (first < 0)
            {
                first = 0;
            }

            if (first >= list.Count)
            {
                first = list.Count - 1;
            }

            if (list[first] > key)
            {
                first -= 1;
            }

            return first;
        }

        static int Larger(this List<int> list, int start, int key)
        {
            var ret = -1;

            if (start < 0)
            {
                start = 0;
            }

            var count = list.Count;
            for (int i = start; i < count; i++)
            {
                if (list[i] >= key)
                {
                    ret = i;
                    break;
                }
            }

            return ret;
        }

        static void Plus(this List<int> list, int later, int key)
        {
            var index = list.Larger(later, key);
            if (index >= 0)
            {
                list.Insert(index, key);
            }
            else
            {
                list.Add(key);
            }
        }

        static void Minus(this List<int> list, int index)
        {
            if (index >= 0)
            {
                list.RemoveAt(index);
            }
        }

    }
}


Measured memory_bytes: 18524
#coding:utf-8
import sys

L = list(map(int,input().split()))
N = int(L[0])
Y = int(L[1])

for i in range(N+1):
    for j in range(N-i+1):
        k = N - i - j

        if 10000*i+5000*j+1000*k==Y:
            print(i,j,k)
            sys.exit()


print("-1 -1 -1")


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll x,y;
cin>>x>>y;
ll res;
if(x>y){
    if(abs(x)<abs(y)){
        if(x<0&&y<0){
            res=abs(y)-abs(x)+2;
        }
        else if(y<0){
            res=abs(y)-abs(x)+1;
        }
        else{
            res = -y+x;
        }
    }
    else{
        if(x>0&&y>0){
            res=x-y+2;
        }
        else{
            res=y+x+1;
        }
    }
}
else{
    if(abs(x)<abs(y)){
        if(x<0){
            res=abs(y)-abs(x)+1;
        }
        else{
            res=abs(y)-abs(x);
        }
    }
    else{
        if(x<0&&y>0){
            res=abs(x)-abs(y)+1;
        }
        else{
            res=abs(x)-abs(y);
        }
    }
}
cout<<res<<endl;

return 0;
}

Measured memory_bytes: 3636
package main

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

var N, K, cnt int

func main() {
	fmt.Scan(&N, &K)
	reader := bufio.NewScanner(os.Stdin)
	reader.Split(bufio.ScanWords)

	x := make(SortBy, N)
	for i := 0; i < N; i++ {
		x[i] = make([]int, 2)
	}

	for i := 0; i < N; i++ {
		reader.Scan()
		a, _ := strconv.Atoi(reader.Text())
		reader.Scan()
		b, _ := strconv.Atoi(reader.Text())

		x[i] = []int{a, b}
	}

	sort.Sort(x)

	var a_bef int
	for _, m := range x {
		a := m[0]
		b := m[1]

		if K <= cnt {
			fmt.Println(a_bef)
			return
		} else {
			cnt += b
		}
		a_bef = a
	}

	fmt.Println(x[len(x)-1][0])
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy [][]int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i][0] < a[j][0] }


Measured memory_bytes: 7936
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int b = N / 1000;
		b += N % 1000 == 0 ? 0 : 1;
		Console.WriteLine(1000 * b - N);
	}
}

Measured memory_bytes: 27540
#include <bits/stdc++.h>
using namespace std;
string S;
char s[100],t[100];
int n,m;
int main(){
    cin>>S;
    n=S.size();
    for(int i=0;i<n/2;i++){
        s[i]=S[i];
        t[i]=S[n-i-1];
        if(S[i]!=S[n-i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(n%4==1)m=(n+1)/2;
    else m=(n-1)/2;
    for(int i=0;i<m;i++){
        if(s[i]!=s[(n-1)/2-i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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

a = list(map(int, input().split()))

a.sort(reverse=True)

l = len(a) - 1
ans = a[0]
a = a[1:]
l -= 1
h = l//2
ans += sum(a[:h]) * 2
if l - h*2 > 0:
    ans += a[h]
print(ans)


Measured memory_bytes: 31500
/* 
 * Project: AtCoder Beginner contest 070 B - Two Switches
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/03/11
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <iostream>
#include <algorithm>
using namespace std;

int a, b;
int c, d;

void solve() {
    bool alice_on = false;
    bool bob_on = false;
    int cnt = 0;
    for (int i=0;i<max(b,d);i++) {
        if (i == a)
            alice_on = true;
        if (i == c)
            bob_on = true;
        if (i == b)
            alice_on = false;
        if (i == d)
            bob_on = false;
        if (alice_on && bob_on)
            cnt++;
    }
    cout << cnt << endl;
}

int main() {

    cin >> a >> b >> c >> d;
    solve();

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int x = sc.nextInt();
    int m = x / 100;
    if (100 * m <= x && x <= 105 * m) {
      System.out.println(1);
    } else {
      System.out.println(0);
    }
  }
}

Measured memory_bytes: 32608
N=int(input())
lst=[int(i) for i in input().split()]
lst.append(10e4)
def ans(A):
  return A//2
a=1
A=0
for i in range(N):
  if lst[i]==lst[i+1]:
    a+=1
  else:
    A+=ans(a)
    a=1
print(A)
    
    
    
    

Measured memory_bytes: 3060
using System;

public class Program {
  public static void Main() {
    const int INIT_DEBT = 100000;
    const double INTEREST_PERCENT = 1.05;
    int debt = INIT_DEBT;
    int weeks = int.Parse(Console.ReadLine());
    for (int i = 0; i < weeks; i++) {
      debt = Ceiling(debt * INTEREST_PERCENT);
    }
    Console.WriteLine(debt);
  }

  private static int Ceiling(double value) {
    return (int)(Math.Ceiling(value / 1000) * 1000);
  }
}

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  char a[n][n];
  rep(i, n) rep(j, n) cin >> a[i][j];
  char b[m][m];
  rep(i, m) rep(j, m) cin >> b[i][j];
  bool ans = false;
  for (int i = 0; i < n - m + 1; ++i) {
    for (int j = 0; j < n - m + 1; ++j) {
//      ^ where to start
      bool doesMatch = true;
      for (int k = 0; k < m; ++k) {
        for (int l = 0; l < m; ++l) {
          if (a[i + k][j + l] != b[k][l]) {
            doesMatch = false;
            break;
          }
        }
        if (!doesMatch) break;
      }
      if (doesMatch) {
        ans = true;
        break;
      }
    }
  }
  
  if (ans) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}


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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;

int main() {
    int n;
    cin >> n;
    vector<int> nums(n);
    double avg = 0.0;
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
        avg += nums[i];
    }
    avg /= n;
    double dis = 1e9;
    int index = 0;
    for (int i = 0; i < n; ++i) {
        if (fabs(nums[i] - avg) < dis) {
            index = i;
            dis = fabs(nums[i] - avg);
        }
    }
    cout << index << endl;
    return 0;
}


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

int main(){
  string a, b, c;
  bool flag = false;
  char cur = 'a', ans = 'A';
  cin >> a >> b >> c;
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  reverse(c.begin(), c.end());
  while(!flag){
    if(cur == 'a'){
      if(a.empty()){
        flag = true;
        ans = 'A';
        break;
      }
      cur = a.back(); a.pop_back();
    }else if(cur == 'b'){
      if(b.empty()){
        flag = true;
        ans = 'B';
        break;
      }
      cur = b.back(); b.pop_back();
    }else if(cur == 'c'){
      if(c.empty()){
        flag = true;
        ans = 'C';
        break;
      }
      cur = c.back(); c.pop_back();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
    int sx, sy, tx, ty, i;
    cin>>sx>>sy>>tx>>ty;
    int y = ty-sy;
    int x = tx-sx;
    for(i = 1; i<=y; i++)
        cout<<"U";
    for(i = 1; i<=x; i++)
        cout<<"R";
    for(i = 1; i<=y; i++)
        cout<<"D";
    for(i = 0; i<=x; i++)
        cout<<"L";
    for(i = 0; i<=y; i++)
        cout<<"U";
    for(i = 0; i<=x; i++)
        cout<<"R";
    cout<<"DR";
    for(i = 0; i<=y; i++)
        cout<<"D";
    for(i = 0; i<=x; i++)
        cout<<"L";
    cout<<"U"<<endl;
    return 0;
}

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

using namespace std;

int main() {
    long h;
    long w;
    cin >> h >> w;
    if (min(h,w)==1) {
        cout << 1 << endl;
    } else {
        long ans = h * w / 2;
        if (h * w % 2 == 1) ans++;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <unordered_map>

const int MOD = pow(10,9)+7;
typedef long long ll;

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}


int ans = 0;

void dfs(int *visited, int cur, vector<int> *links, int N){
    
    int sum=0;
    for(auto i = 1; i <= N ; i++){
        sum+=visited[i];
    }
    
    if(sum == N){
        ans ++;
        return;
    }

    for(auto next : links[cur]){
        
        if (visited[next] == 1){
            continue;
        }
        
        visited[next] = 1;
        dfs(visited,next,links,N);
        visited[next] = 0;
    }
    
    return;
    
}



int main() {

    int N = in(); int M = in();
    
    typedef pair<int, int> P;
    
    vector<int> links[N+1];
    
    P temp;
    for(auto i = 0; i<M; i++){
        cin >> temp.first >> temp.second;
        links[temp.first].push_back(temp.second);
        links[temp.second].push_back(temp.first);
    }
    
    
    int visited[N+1];
    for(auto i = 1; i <=N; i++){
        visited[i] = 0;
    }
    
    visited[1] = 1;
    
    dfs(visited,1,links,N);
    
    cout << ans << endl;
    
    return 0;
    
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

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

  int sum=0;
  rep(i,s.size()){
    sum+=s[i]-'0';
  }
  
  if(sum%9) puts("No");
  else puts("Yes");
  return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N,H;
    cin >> N >> H;
    vector<pair<ll,ll>> sword(N);
    vector<pair<ll,ll>> ss(N);
    REP(i,N){
        cin >> sword[i].S >> sword[i].F;
        ss[i].F = sword[i].S;
        ss[i].S = sword[i].F;
    }
    sort(ALL(ss),greater<>());
    ll zan = ss[0].F;
    ll chinpo = ss[0].S;
    REP(i,N){
        if(ss[0].F == ss[i].F)chmin(chinpo,ss[i].S);
    }
    REP(i,N){
        if(sword[i].S == zan&&sword[i].F == chinpo){
            sword[i].F = 0;
            sword[i].S = 0;
            break;
        }
    }
    ll count = 1;
    ll last = max(zan,chinpo);
    sort(ALL(sword),greater<>());
    ll inq = 0;
    while(H > last){
        if(inq < N){
            H -= max(sword[inq].F,zan);
            if(H <= 0)count--;
        }else{
            H -= zan;
            // ll cc = 0;
            // cc = (H - last+zan-1)/zan;
            // if(H - cc*zan > 0){
            //     count += cc;
            // }else{
            //     count += cc-1;
            // }
            // break;
        }
        count++;
        inq++;
    }
    cout << count << "\n";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

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

    ll kakeru = x/11;
    ll amari = x%11;

    if(amari >6) amari = 2;
    else if(amari > 0) amari = 1;
    else amari = 0;

    cout << kakeru * 2 + amari << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int con(char c)
{
	if(c == 'i') return 1;
	if(c == 'x') return 10;
	if(c == 'c') return 100;
	if(c == 'm') return 1000;
	if(c == 1)   return 'i';
	if(c == 2)	 return 'x';
	if(c == 3)   return 'c';
	if(c == 4)   return 'm';
}

int f(string num)
{
	int res = 0;
	rep(i, num.size())
	{
		if(!('1' < num[i] && num[i] <= '9')) 
		{
			if(i - 1 < 0 || !('1' < num[i-1] && num[i-1] <= '9'))
				res += con(num[i]);
			else
				res += con(num[i]) * (num[i-1] - '0');
		}
	}

	return res;
}

string F(int num)
{
	char cnum[16];
	sprintf(cnum, "%d", num);

	string res;
	rep(i, strlen(cnum))
	{
		if(cnum[i] == '0') continue;
		if(cnum[i] == '1')
			res += con(strlen(cnum) - i);
		else
		{
			res += cnum[i];
			res += con(strlen(cnum) - i);
		}
	}

	return res;
}

int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		string s1, s2;
		cin >> s1 >> s2;

		cout << F(f(s1) + f(s2)) << endl;
	}
}

Measured memory_bytes: 0
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int main ()
{
	vector<vector<int>>data;
	int A , B , N;
	while( cin >> A >> B ,A||B)
	{
		cin >> N;
		data.resize ( A + 1 );
		for( size_t i = 0; i < A + 1; i++ )
		{
			data[i].resize ( B + 1 );
		}
		for( size_t i = 0; i < N; i++ )
		{
			int a , b;
			cin >> a >> b;
			data[a][b] = -1;
		}
		data[0][1] = 1;
		for( size_t i = 1; i < A + 1; i++ )
		{
			for( size_t j = 1; j < B + 1; j++ )
			{
				if( data[i][j] != -1 )
				data[i][j] = max ( data[i][j - 1] , 0 ) + max ( data[i - 1][j] , 0 );
			}
		}
		cout << data[A][B] << endl;
		data.clear ();
	}
	return 0;
}

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

int main(){
  int N,K,d;
  cin >> N;
  cin >> K;
  vector<int> count(N);
  for(int j=0;j<K;j++){
    cin >> d;
    for(int i=0;i<d;i++){
  	  int tmp;
      cin >> tmp;
      count.at(tmp-1)++;
    }
  }
  int c=0;
  for(int i=0;i<N;i++){
  	if(count.at(i)==0){
      c++;
    }
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

const long long MOD = 1e9 + 7;

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

	int N, M;
	cin >> N >> M;

	if (abs(N - M) >= 2)
	{
		cout << 0;
		return 0;
	}

	long long Fact = 1;
	for (int i = 1; i <= N; i++)
	{
		Fact *= i;
		Fact %= MOD;
	}

	for (int i = 1; i <= M; i++)
	{
		Fact *= i;
		Fact %= MOD;
	}

	if (N == M)
	{
		cout << (Fact * 2) % MOD;
	}
	else
	{
		cout << Fact;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

using pll = pair<ll, ll>;
constexpr ll MOD = 1000000007;
map<pll, pll> mp;
ll pw(ll a){
	ll b = 1;
	REP(i, a) b = b * 2 % MOD;
	return b;
}

int main(){
	int n; scanf("%d", &n);
	ll cnt = 0;
	REP(i, n){
		ll a, b; scanf("%lld%lld", &a, &b);
		if(a == 0 && b == 0){
			cnt++;
			continue;
		}
		ll g = gcd(a, b);
		a /= g; b /= g;
		ll c = a, d = b;
		while(!(c > 0 && d >= 0)){
			swap(c, d);
			c *= -1;
		}
		if((a > 0 && b >= 0) || (a < 0 && b <= 0)){
			mp[MP(c, d)].first++;
		} else {
			mp[MP(c, d)].second++;
		}
	}
	ll ans = 1;
	for(auto [p, q] : mp){
		ans *= pw(q.first) + pw(q.second) - 1;
		ans %= MOD;
	}
	ans = (ans + cnt + MOD - 1) % MOD;
	printf("%lld\n", ans);
}





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

vector<int>V;
double x[20], y[20];

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

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

    for(int i = 0; i < n; i++)V.push_back(i);

    double ans = 0.0;
    double res;
    do
    {
        res = 0.0;
        for(int i = 1; i < n; i++)
        {
            res = (x[V[i-1]] - x[V[i]]) * (x[V[i-1]] - x[V[i]]) + (y[V[i-1]] - y[V[i]]) * (y[V[i-1]] - y[V[i]]);
            res = sqrt(res);
            ans += res;
        }
    }
    while(next_permutation(V.begin(), V.end()));
    ans = ans/tot;
    printf("%.10f\n",ans);
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  string a,b;
  cin >> a >> b;
  int sqrtNum = toInt(a+b);
  int s = (int)sqrt(sqrtNum);
  if(s*s == sqrtNum) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int n, m;
int[] a;

void main() {
    scan(n, m);
    a = readln.split.to!(int[]);

    auto imos0 = new long[](m + 2);
    auto imos1 = new long[](m + 2);

    foreach (i ; 0 .. n - 1) {
        int s = a[i], t = a[i + 1];

        if (s < t) {
            imos0[1] += t - s;
            imos0[s + 1] -= t - s;

            imos0[s + 1] += t + 1;
            imos0[t + 1] -= t + 1;
            imos1[s + 1] -= 1;
            imos1[t + 1] += 1;

            imos0[t + 1] += t - s;
        }
        else {
            imos0[1] += t + 1;
            imos0[t + 1] -= t + 1;
            imos1[1] -= 1;
            imos1[t + 1] += 1;

            imos0[t + 1] += m - s + t;
            imos0[s + 1] -= m - s + t;

            imos0[s + 1] += t + m + 1;
            imos1[s + 1] -= 1;
        }

        debug {
            writeln("imos0:", imos0);
            writeln("imos1:", imos1);
        }
    }

    foreach (i ; 0 .. m) {
        imos0[i + 1] += imos0[i];
        imos1[i + 1] += imos1[i];
    }

    debug {
        writeln("imos0:", imos0);
        writeln("imos1:", imos1);
    }

    long ans = 1L * m * n;

    foreach (i ; 1 .. m + 1) {
        ans = min(ans, imos0[i] + imos1[i] * i);
    }

    writeln(ans);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 6076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

ll dp[2010][2010];
ll sum[2010][2010];

void solve() {
  int n,m;
  cin >> n >> m;
  int s[n], t[m];
  REP(i,n) {
    cin >> s[i];
  }
  REP(i,m) {
    cin >> t[i];
  }
  REP(i,2010) {
    memset(dp[i],0,sizeof(dp[i]));
    memset(sum[i],0,sizeof(sum[i]));
  }
  REP(i,n) {
    REP(j,m) {
      if (s[i] == t[j]) {
        dp[i+1][j+1] = sum[i][j] + 1;
      } else {
        dp[i+1][j+1] = 0;
      }
      while (dp[i+1][j+1] < 0) {
        dp[i+1][j+1] += MOD;
      }
      dp[i+1][j+1] %= MOD;
      sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + dp[i+1][j+1];
      while (sum[i+1][j+1] < 0) {
        sum[i+1][j+1] += MOD;
      }
      sum[i+1][j+1] %= MOD;
    }
  }
  cout << sum[n][m]+1 << endl;
}

int main(int argc, char *argv[]){

  /*Regular*/
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }

  // /*ICPC*/
  // while (cin >> t >> d >> l, t) {
  //   solve();
  // }

  //solve();
  return 0;
}

Measured memory_bytes: 63360