akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
void prina()
{
	printf("Alice\n");
}
void prinb()
{
	printf("Bob\n");
}
int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	while(1)
	{
	if(a == 1 && b != 1)
	{
		printf("Alice\n");
		break;
	}
		else if(b == 1 && a!= 1)
		{
			printf("Bob\n");
			break;
		}
			else if(a == b)
			{
				printf("Draw\n");
				break;			
			}
				a > b ? prina() : prinb();
				break;
	}
			
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;

using namespace std;

int a[N], b[N];

int main() 
{
	barnarnar
	int n, m, k;
	cin >> n >> m >> k;
	int mn1 = inf, mn2 = inf;
	forn1(i, n)	cin >> a[i], mn1 = min(mn1, a[i]);
	forn1(i, m)	cin >> b[i], mn2 = min(mn2, b[i]);
	int ans = mn1 + mn2;
	forn(i, k)
	{
		int n1, n2, d;
		cin >> n1 >> n2 >> d;
		ans = min(ans, a[n1] + b[n2] - d);
	}
	cout << ans;
	return 0;
}








Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

const ll INF = 1e15;

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++)
    cin >> a[i];
  ll answer=INF;
  ll sum=0;
  ll ans=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
    if(i%2==0 && sum<=0){
      ans+=abs(sum)+1;
      sum=1;
    }else if(i%2==1 && sum>=0){
      ans+=abs(sum)+1;
      sum=-1; 
    }
  }
  answer=min(answer, ans);
  ans=0;
  sum=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
    if(i%2==1 && sum<=0){
      ans+=abs(sum)+1;
      sum=1;
    }else if(i%2==0 && sum>=0){
      ans+=abs(sum)+1;
      sum=-1;
    }
  }
  answer=min(answer, ans);
  cout << answer << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

vector<int> primes(0);
void prime_number(int N){
    vector<int> tmp(N+1,1);
    tmp[0]=tmp[1]=0;
    for(int i=2; i<=N; i++){
        if(tmp[i]==1){
            primes.push_back(i);
        }
        for(long long j= (long long) i*i; j<=N; j+=i){
            tmp[j]=0;
        }
    }
}

long long bin_search(long long left, long long right, long long x){
    long long mid = (left+right)/2;
    if(mid==left){
        return mid+1;
    }
    if(mid*mid==x){
        return mid;
    }else if(mid*mid<x){
        return bin_search(mid, right, x);
    }else{
        return bin_search(left, mid, x);
    }
}

int main(){
    prime_number(100000);
    long long S;
    cin >> S;
    
    if (S<MOD-7){
        cout << "0 0 1 0 0 " << S << endl;
        return 0; 
    }

    long long X2 = bin_search(0, 1000000000, S);
    long long Y3 = X2;

    S=X2*Y3-S;

    if(S==0){
        cout << "0 0 " << X2 << " 0 0 " << Y3 << endl;
        return 0;
    }else if(S<=MOD-7){
        cout << "0 0 " << X2 << " " << 1 << " " << S << " " << Y3 << endl;
        return 0;
    }

    long long X3, Y2;

    for(int i=0; i<primes.size(); i++){
        if(S%primes[i]==0 && S/primes[i]<=MOD-7){
            X3=primes[i];
            Y2=S/primes[i];
        }
    }

    cout << "0 0 " << X2 << " " << Y2 << " " << X3 << " " << Y3 << endl;

}

Measured memory_bytes: 768
N,M = [int(x.strip()) for x in input().split()]
h_list = [int(x.strip()) for x in input().split()]
ok_list = [True] * N

for i in range(M):
    A,B = [int(x.strip()) for x in input().split()]
    if (h_list[A-1] == h_list[B-1]):
        ok_list[A-1] = False
        ok_list[B-1] = False
    elif (h_list[A-1] < h_list[B-1]):
        ok_list[A-1] = False
    else:
        ok_list[B-1] = False

ans = sum(v for v in ok_list)
print(ans)


Measured memory_bytes: 19992
from math import atan2, degrees

def calc(dx, dy, d, w, a):
    if dx**2 + dy**2 > a**2:
        return 0
    t = degrees(atan2(dy, dx))
    for i in range(2):
        if w - d/2 <= t + 360*i <= w + d/2:
            return 1
    return 0

while 1:
    H, R = map(int, input().split())
    if H == R == 0:
        break
    HS = [list(map(int, input().split())) for i in range(H)]
    U, M, S, du, dm, ds = map(int, input().split())
    US = [list(map(int, input().split())) for i in range(U)]
    MS = [list(map(int, input().split())) for i in range(M)]
    SS = [list(map(int, input().split())) for i in range(S)]
    ans = [0]*H
    for k in range(R):
        w, a = map(int, input().split())
        for i, (x, y) in enumerate(HS):
            if not calc(x, y, du, w, a):
                continue
            if (
                    any(calc(x - x0, y - y0, du, w, a) for x0, y0 in US) or
                    any(calc(x - x0, y - y0, dm, w, a) for x0, y0 in MS) or
                    any(calc(x - x0, y - y0, ds, w, a) for x0, y0 in SS)
                ):
                continue
            ans[i] += 1
    m = max(ans)
    if m:
        res = [i+1 for i in range(H) if m == ans[i]]
        print(*res)
    else:
        print("NA")



Measured memory_bytes: 5792
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int a, b; cin>>a>>b;
  int m = max(a-b, a+b);
  m = max(m,a*b);
  cout << m << endl;
  return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

const int MOD=1e9+7;
const char C[]={'A','C','G','T'};
const string nans[]={"AGC","GAC","ACG","ATGC","AGGC","AGAC","AGTC","AGGC"};
int D[100][64];
vector<string> F;

bool chk(const string &s)
{
	for(const auto &t: nans) if(s.find(t)!=string::npos) return false;
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, ans=0;
	cin>>N;
	for(int a=0;a<4;a++) for(int b=0;b<4;b++) for(int c=0;c<4;c++) F.push_back(string("")+C[a]+C[b]+C[c]);
	for(int i=0;i<64;i++) if(chk(F[i])) D[2][i]=1;
	for(int i=3;i<N;i++) {
		for(int j=0;j<64;j++) for(int k=0;k<4;k++) if(chk(F[j]+C[k])) {
			string temp(string(F[j].begin()+1,F[j].end())+C[k]);
			int n=lower_bound(F.begin(),F.end(),temp)-F.begin();
			D[i][n]=(D[i][n]+D[i-1][j])%MOD;
		}
	}
	for(int i=0;i<64;i++) ans=(ans+D[N-1][i])%MOD;
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>

using namespace std;
#define N 3
#define N2 9


struct Puzzle {
  int f[N2];
  int space;
  string path;


  
bool operator < (const Puzzle &p)const{
  for(int i=0;i<N2;i++){
    if(f[i] == p.f[i])continue;
    return f[i] > p.f[i];
  }
  return false;
}
};  

static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};



bool isTarget(Puzzle p){
  for(int i=0;i<N2;i++)
    if(p.f[i] != (i + 1))return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u,v;
  s.path = "";
  Q.push(s);
  V[s] = true;


  
  while(!Q.empty()){
    u = Q.front();
    Q.pop();
    if(isTarget(u))return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for(int r = 0;r<4;r++){
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if(tx < 0||ty<0||tx>=N||ty>=N)continue;
      v = u;
      swap(v.f[u.space],v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if(!V[v]){
	V[v] = true;
	v.path += dir[r];
	Q.push(v);
      }
    }
  }

  return "unsolvable";
}

int main(){
  Puzzle in;

  for(int i=0;i<N2;i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }

  
  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}




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

int main() {
    string s;
    cin >> s;
    int n=s.size();
    int ans=0;
    for(int i=0; i<n; i++){
        int j=i-1;
        while(j+1<n && (s[j+1]=='A' | s[j+1]=='T' | s[j+1]=='C' | s[j+1]=='G')) j++;
        ans = max(ans, j-i+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
ll n,a,b;
int main(){
    cin>>n>>a>>b;
    if(a>b)cout<<0<<endl;
    else if(n==1){
        if(a==b)cout<<1<<endl;
        else cout<<0<<endl;
    }
    else cout<<(n-2)*(b-a)+1<<endl;
    //system("pause");
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    a54(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a54(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (alice, bob) = args[0].split(" ").map { it.toInt() }
    val aliceForCmp = if (alice == 1) 14 else alice
    val bobForCmp = if (bob == 1) 14 else bob
    print(when {
        aliceForCmp - bobForCmp == 0 -> "Draw"
        aliceForCmp - bobForCmp > 0 -> "Alice"
        else -> "Bob"
    })
}


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

int main(){
    int P, Q, R;
    int ans;

    //input
    cin >> P >> Q >> R;

    ans = P + Q + R;

    if(ans > P + Q){
        ans = P + Q;
    }
    if(ans > P + R){
        ans = P + R;
    }
    if(ans > Q + R){
        ans = Q + R;
    }

    //output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()

int main(void){
    char order[3];
    int cnt_o = 0;
    int i;

    std::cin >> order;

    for(i=0; i<3; i++){
        if(order[i] == 'o')cnt_o++;
    }

    std::cout << 700+100*cnt_o << std::endl;
    return 0;
}

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

int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int h[105];
    vector<int> summit;
    vector<int> bottom;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 1; i < n-1; i++){
        if((h[i] - h[i-1]) > 0 && (h[i+1] - h[i]) <= 0){
            summit.push_back(h[i]);
        }else if((h[i] - h[i-1]) <= 0 && (h[i+1] - h[i]) > 0){
            bottom.push_back(h[i]);
        }
    }
    if(h[0] < h[1]){
        //bottom.push_back(h[0]);
    }else if(h[0] > h[1]){
        summit.push_back(h[0]);
    }
    if(h[n-1] > h[n-2]){
        summit.push_back(h[n-1]);
    }
    else if(h[n-1] < h[n-2]){
        //bottom.push_back(h[n-1]);
    }
    int ans = 0;
    for(int i = 0; i < summit.size(); i++){
        ans += summit[i];
    }
    for(int i = 0; i < bottom.size(); i++){
        ans -= bottom[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
l = [int(input()) for _ in range(N)]

M = max(l)
ind = l.index(M)
if ind==0:
    m = max(l[1:])
elif ind==N-1:
    m = max(l[:N-1])
else:
    m = max(max(l[0:ind]),max(l[ind+1:]))
for i in range(N):
    if i == ind:
        print(m)
    else:
        print(M)

Measured memory_bytes: 12972
#include <bits/stdc++.h>
const int MAXN = 1e5;
using namespace std;

char s[MAXN + 5];
int n, cnt[26];

void init() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  init();
  
  for (int i = 1; i <= n; ++i) {
    ++cnt[s[i] - 'a'];
    for (int j = i + 1; j <= min(i + 3, n); ++j) {
      ++cnt[s[j] - 'a'];
      if (cnt[s[j] - 'a'] * 2 > j - i + 1) {
        printf("%d %d\n", i, j);
        return 0;
      }
    }
    for (int j = i; j <= min(i + 3, n); ++j) {
      --cnt[s[j] - 'a'];
    }
  }
  
  
  puts("-1 -1");
  return 0;
}

Measured memory_bytes: 384
n = int(input())
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
p.sort(key = lambda x:x[2], reverse = True)
for i in range(101):
    for j in range(101):
        t = p[0][2] + abs(i - p[0][0]) + abs(j - p[0][1])
        if any([
            t != p[k][2] + abs(i - p[k][0]) + abs(j - p[k][1]) 
            if p[k][2] > 0 else t > abs(i - p[k][0]) + abs(j - p[k][1]) 
            for k in range(1, n)
        ]):
            continue
        else:
            print(i, j, t)
            break
    else:
        continue
    break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MAIN 200010
using namespace std;
int n,a[MAIN],b[MAIN],tmpa[MAIN],tmpb[MAIN];
int main()
{
    while(cin>>n)
    {
        int ans=0;
        for(int i=0; i<n; i++)
            cin>>a[i];
        for(int i=0; i<n; i++)
            cin>>b[i];
        for(int i=0; i<29; i++)
        {
            for(int j=0; j<n; j++)
            {
                tmpa[j]=a[j]%(1<<(i+1));
                tmpb[j]=b[j]%(1<<(i+1));
            }
            sort(tmpb,tmpb+n);
            int sum=0;
            for(int j=0; j<n; j++)
            {
                int a=lower_bound(tmpb,tmpb+n,(1<<i)-tmpa[j])-tmpb;
                int b=lower_bound(tmpb,tmpb+n,(1<<i)*2-tmpa[j])-tmpb;
                int c=lower_bound(tmpb,tmpb+n,(1<<i)*3-tmpa[j])-tmpb;
                int d=lower_bound(tmpb,tmpb+n,(1<<i)*4-tmpa[j])-tmpb;
                sum+=(b-a)+(d-c);
            }
            if(sum&1)
                ans+=(1<<i);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3328
use strict;
use warnings;

my $n = <STDIN>;
chomp $n;
my (@t, @x, @y);
{
    for (my $i=0; $i<$n; $i++)
    {
        my $in = <STDIN>;
        ($t[$i], $x[$i], $y[$i]) = split(" ", $in);
    }
}
my ($t0, $x0, $y0) = (0, 0, 0);
my $ans = "Yes";
for (my $i=0; $i<$n; $i++)
{
    my $x1 = $x[$i];
    my $y1 = $y[$i];
    my $diff = $x1 - $x0 + $y1 - $y0;
    my $ditt = $t[$i] - $t0;
    $ans = "No" if $diff>$ditt || ($diff%2)!=($ditt%2);
    last if $diff<$ditt || ($diff%2)!=($ditt%2);
    ($t0, $x0, $y0) = ($t[$i], $x[$i], $y[$i]);
}

print "$ans\n";

Measured memory_bytes: 26752
import bisect
N, Q = map(int, input().split())
S = input()
minians = []
for i in range(N-1):
    if S[i:i + 2] == "AC":
        minians.append(i)
# print(minians)
ans = [0]*Q
for i in range(Q):
    left, right = map(int, input().split())
    left -= 1
    right -= 1
    """print("\n", bisect.bisect_left(minians, right),
          bisect.bisect_left(minians, left))"""
    ans[i] = bisect.bisect_left(minians, right) - \
        bisect.bisect_left(minians, left)

    #ans[i] = sum(left <= mini < right for mini in minians)
    """for j in range(len(minians)):
        if left <= minians[j] and minians[j] < right:
            ans[i] += 1
        elif minians[j] >= right:
            break"""
print('\n'.join(map(str, ans)))


Measured memory_bytes: 65240
#!/usr/bin/env python3
import sys


def solve(S: str):
    sl = {'A', 'C', 'G', 'T'}

    T = list(S)
    c = 0
    ans = 0
    for i in range(len(T)):
        if(T[i] in sl):
            c += 1
            continue
        else:
            ans = max(ans,c)
            c = 0
    print(max(ans,c))
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

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

    bool ans = false;
    for(int y=0;y<=N/7;y++){
        for(int x=0;x<=N/4;x++){
            int p = y*7+x*4;
            if(p==N){
                ans = true;
                x = N;
                y = N;
                break;
            }
        }
    }

    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

int main ()
{
    int n;
    cin >> n;
    int d = ceil(n / 1.08);
    int ans = floor(d * 1.08);
    if (n == ans)
        cout << d << endl;
    else cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,pj,pm,pe;
	while(n){
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>pm>>pe>>pj;
			if(pm==100||pj==100||pe==100){
				cout<<"A"<<endl;
			}else if((pm+pe)/2>=90){
				cout<<"A"<<endl;
			}else if((pm+pe+pj)/3>=80){
				cout<<"A"<<endl;
			}else if((pm+pe+pj)/3>=70){
				cout<<"B"<<endl;
			}else if((pm+pe+pj)/3>=50&&pm>=80||pe>=80){
				cout<<"B"<<endl;
			}else{
				cout<<"C"<<endl;
			}
		}
	}
}

Measured memory_bytes: 1156
r, g, b, n = gets.chomp.split.map(&:to_i)
c = [r, g, b].sort.reverse
cnt = 0
for i in 0..(n/c[0])
  for j in 0..((n-i*c[0])/c[1])
    if ((n-i*c[0])-j*c[1]) % c[2] == 0
      cnt += 1
    end
  end
end
puts cnt


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (ll)(n); ++i)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	string s; cin >> s;
	int n=s.size();
	rep(i,n) {
		for(int j=i+1;j<n;j++) {
			if(s[i]==s[j]) {
				cout << "no" << endl;
				return 0;
			}
		}
	}
	cout << "yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
using namespace std;

int main()
{
long long n,c=0; cin>>n;
string s;cin>>s;
int k=s.size();
if(k%2==1) cout<<"No"<<endl;
else{
    for(int i=0;i<k;i++)
    {
       if(s[i]==s[k/2+i])
            c++;
    }    if(c==k/2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
}


Measured memory_bytes: 3592
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
const int N=200000+10,INF=0x3f3f3f3f;
int main()
{
    int n,m,x;
    while(~scanf("%d",&n)){
        map<int,int>m1;
        bool flag=1;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            m1[x]++;
        }
        scanf("%d",&m);
        for(int i=0;i<m;i++){
            scanf("%d",&x);
            if(flag&&m1[x]>0)
                m1[x]--;
            else flag=0;
        }
        if(flag) printf("YES\n");
        else printf("NO\n");

    }
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <assert.h>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> v(n+1);
        vector<int> a(n);
        for (auto &&i : v) scanf("%d", &i);
        int oo = 1;
        for (int i = 0; i < n; ++i) {
            if(v[i+1]-v[i] != v[1]-v[0]) oo = 0;
        }
        if(oo) exit(1);
        for (int i = 0; i <= n; ++i) {
            int cur = 0;
            for (int j = 0; j <= n; ++j) {
                if(i != j) a[cur++] = v[j];
            }
            int ok = 1;
            for (int j = 2; j < n; ++j) {
                if(a[j]-a[j-1] != a[1]-a[0]) ok = 0;
            }
            if(ok) {
                cout << v[i] << "\n";
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3144
//Author: gkashish

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <iomanip>

using namespace std;

#define mod 1000000007
#define x first
#define y second

map<pair<int, int>, int> store;

int poss(int a, int b) {
    if (a == 0 && b == 0)
        return 1;
    if (a <= 0 || b <= 0)
        return 0;
    if (abs(a - b) > min(a, b))
        return 0;
    if (store.find({min(a, b), max(a, b)}) != store.end())
        return store[{min(a, b), max(a, b)}];
    int val = poss(a - 1, b - 2) + poss(a - 2, b - 1);
    if (val >= mod)
        val -= mod;
    store[{min(a, b), max(a, b)}] = val;
    return val;
}
#define mx 1000005
int fact[mx];

void cal_fac() {
    static bool done = false;
    if (done)
        return;
    done = true;
    fact[0] = 1;
    for (int i = 1; i < mx; i++) {
        fact[i] = (long long) i * fact[i - 1] % mod;
    }
}
int power(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1) {
            res = (long long) res * x % mod;
        }
        y /= 2;
        x = (long long) x * x % mod;
    }
    return res;
}

int mod_inv(int x) {
    return power(x, mod - 2);
}

int comb(int n, int k) {
    cal_fac();
    return (long long) fact[n] * mod_inv(fact[n - k]) % mod * mod_inv(fact[k]) % mod;
}

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

    int a, b;
    cin>>a>>b;
    if((a+b)%3){
        cout<<"0";
        return 0;
    }
    int tot = (a+b)/3;
    int ext = abs(a-b);
    if(ext>tot){
        cout<<"0";
        return 0;
    }
    ext+=(tot-ext)/2;
    cout<<comb(tot, ext);
    return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll n; cin >> n;
  ll ans = 0;

  pf(n);
  for(auto v : prim) {
    //    cerr << v.first << " " << v.second << endl;

    ll e = v.second;
    ll e1 = 1;
    while(e > 0) {
      e = e - e1;
      ans ++;
      e1 ++;
    }
    if (e < 0) ans --;
    //cerr << "ans:" << ans << endl;
  }

  


  cout << ans << endl;

}

int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


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

using namespace std;
typedef long long unsigned int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int a; cin >> a;
    int p; cin >> p;
    cout << (3*a + p)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

struct RollingHash {
	static const long long int mul0 = 100019, mul1 = 10007;
	static const long long int add0 = 1000010007, add1 = 1003333331;
	string s; int l;
	vector<long long int> hash_, hash2_;
	static vector<long long int> pmo_, pmo2_;
	void init(string s) {
		this->s = s; l = s.size();
		hash_.resize(l + 1);
		hash2_.resize(l + 1);

		hash_[0] = 0;
		hash2_[0] = 0;

		if (pmo_.empty()) {
			pmo_.push_back(1), pmo2_.push_back(1);
		}
		while (pmo_.size() <= l) {
			pmo_.push_back(pmo_.back() * mul0);
			pmo2_.push_back(pmo2_.back() * mul1);
		}
		for (int i = 0; i < l; ++i) {
			hash_[i + 1] = (hash_[i] * mul0 + s[i]);
			hash2_[i + 1] = (hash2_[i] * mul1 + s[i]);
		}
	}
	pair<long long int, long long int >  hash(int l, int r) { // s[l..r]
		return make_pair(hash_[r + 1] - hash_[l] * pmo_[r + 1 - l],
			hash2_[r + 1] - hash2_[l] * pmo2_[r + 1 - l]);
	}
	pair<long long int, long long int >  hash() { // s[all]
		return hash(0, s.size() - 1);
	}

	//hashの結合　
	static pair<long long int, long long int> concat(pair<long long int, long long int> L, pair<long long int, long long int> R, int RLength) { // hash(L+R) 
		return make_pair((R.first + L.first*pmo_[RLength]), (R.second + L.second*pmo2_[RLength]));
	}
};
vector<long long int> RollingHash::pmo_;
vector<long long int> RollingHash::pmo2_;


int main() {
	


	int N, M; cin >> N >> M;
	string st; cin >> st;
	RollingHash rh;
	rh.init(st);

	int l = 0;
	int r = 0;
	set<pair<long long int, long long int>>aset;
	for (int i = 0; i < M; ++i) {
		string a; cin >> a;
		if (a == "R++") {
			r++;
		}
		else if (a == "R--") {
			r--;
		}
		else if (a == "L++") {
			l++;
		}
		else {
			l--;
		}
		
		aset.emplace(rh.hash(l, r));
		
	}
	cout << aset.size() << endl;
	return 0;
}

Measured memory_bytes: 31176
//abc168_b.cpp
//Sun May 17 20:36:56 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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


	if (s.length()<=k){
		cout << s << endl;
	}else {
		string x = s.substr(0,k);
		cout << x << "..." << endl;
	}

//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


ll a[16][16];
ll dp[1<<16];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

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

    int mm=(1<<n);
    int z[17];
    int k;
    for(k=0; k<mm; k++) {
        int siz=0;
        for(i=0; i<n; i++) {
            if(k & (1<<i)) z[siz++]=i;
        }

        dp[k]=0;
        for(i=0; i<siz; i++) {
            for(j=i+1; j<siz; j++) {
                dp[k] += a[z[i]][z[j]];
            }
        }
    }

    for(k=0; k<mm; k++) {
        ll max=0;
        for(i=0; i<k; i=(((i|~k)+1)&k)) {
            ll val = dp[i]+dp[k^i];
            max = MAX(max, val);
        }
        dp[k] = max;
    }
    printf("%lld\n", dp[mm-1]);

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    string s;
    vector<int> a(4,0);
    while(n--){
        cin>>s;
        if(s=="AC") a[0]++;
        else if(s=="WA") a[1]++;
        else if(s=="TLE") a[2]++;
        else a[3]++;
    }
    cout<<"AC x "<<a[0]<<'\n';
    cout<<"WA x "<<a[1]<<'\n';
    cout<<"TLE x "<<a[2]<<'\n';
    cout<<"RE x "<<a[3]<<'\n';
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    
    string res;
    if(a + b + c <= 21)
    {
        res = "win";
    }
    else res = "bust";

    cout << res << endl;

    return 0;    
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define f first

ll n;

double s;

int main()
{
    cin >> n;

    vector < double > a(n);

    for (auto &i:a) cin >> i, s+=1/i;

    printf("%.7f", 1/s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i++){
        int a; cin >> a;
        if(i%2==1 && a%2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <map>
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
#define ll long long
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return b % a ? gcd(b % a, a) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<ll, ll>;
using VI = vector<ll>;

VI exps = {1};

void hoge() {
    for (long p = 2; p <= 35; p++) {
        long q = p * p;
        while (q <= 1000) {
            exps.push_back(q);
            q *= p;
        }
    }
}

int main() {
    hoge();
    long x;
    cin >> x;
    long ans = 0;
    for (long e: exps) {
        if (e <= x) {
            ans = max(ans, e);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 1e6+6;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    bool pal = true;
    string ss = s;
    reverse(ss.begin(),ss.end());
    if(s!=ss)pal = false;
    int n = s.size();
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n/2-i-1])pal = false;
    }
    for(int i=1;i<=n/2;i++){
        if(s[n/2+i]!=s[n-i])pal = false;
    }
    if(pal)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,z;
    scanf("%d/%d/%d",&x,&y,&z);
    if(x<2019)  puts("Heisei");
    if(x>2019)  puts("TBD");
    if(x==2019){
        if(y<4) puts("Heisei");
        if(y>4) puts("TBD");
        if(y==4)
            puts("Heisei");        
    }
//    system("pause");
    return 0;
}

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

int n, m, i;
string a;
int main()
{
	cin >> n >> m;
	cin >> a;
	if (n + m + 1 == a.size()) {
		for (i = 0; i < a.size(); i++) {
			if (i == n && a[i] != '-') break;
			if (i != n && (a[i] - '0' < 0 || a[i] - '0' > 9)) break;
		}
		if (i == a.size()) cout << "Yes";
		else cout << "No";
	} else cout << "No";
//	for (i = 0; i < n; i++) {
//		scanf ("%d", &a[i]);
//		s += a[i];
//	}
//	cout << s'
//    cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans=0;
    ll height=a[0];
    for(ll i=1;i<n;i++){
        ll diff=0;
        if(a[i]<height){
            diff=height-a[i];
            ans+=diff;
        }
        height=a[i]+diff;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4752
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    void Calc()
    {
        cin = new Scanner();

        string n = cin.next();

        char[] ans = n.ToCharArray();

        for(int i = 0; i < 3; ++i)
        {
            if (ans[i] == '9')
            {
                ans[i] = '1';
            }
            else
            {
                ans[i] = '9';
            }
        }

        string ansStr = new string(ans);
        Console.WriteLine(ansStr);
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, cnt = 0, f, s;
  bool flag = 0;
  cin >> N;
  for(ll i = 0; i < N; i++) {
    cin >> f >> s;
    if(f == s) cnt++;
    else cnt = 0;
    if(cnt == 3) flag = 1;
  }
  if(flag == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
n,x = map(int,input().split())
X = list(map(int,input().split()))

X.append(x)
X = sorted(X)

import fractions
ans = X[1] - X[0]

for i in range(n-1):
    ans = fractions.gcd(ans,X[i+2]-X[i+1])
    
print(ans)

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

llong n;
int ans = 0;
vector<string> semi_753_num;
void dfs(llong x) {
    if (x > n) {
        return;
    }

    semi_753_num.push_back(to_string(x));
    dfs(x * 10 + 3);
    dfs(x * 10 + 5);
    dfs(x * 10 + 7);
}

bool check_753(string &s) {
    if (s.size() < 3) {
        return false;
    }

    int flag3 = 0, flag5 = 0, flag7 = 0;
    for (int i = 0; i < s.size() && (flag3 * flag5 * flag7) == 0; ++i) {
        if (s[i] == '3') ++flag3;
        else if (s[i] == '5') ++flag5;
        else ++flag7;
    }
    
    if (flag3 == 0 || flag5 == 0 || flag7 == 0) return false;
    else return true;
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;

    dfs(3);
    dfs(5);
    dfs(7);

    int ans = 0;
    for (auto itr = semi_753_num.begin(); itr != semi_753_num.end(); ++itr) {
        ans += check_753(*itr) == true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1916
from collections import Counter
from itertools import accumulate

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

a_cum = list(accumulate(a))
cnt = Counter(a_cum)

ans = 0
for k, v in cnt.items():
    if k == 0:
        ans += v + v*(v-1) // 2
    elif v > 0:
        ans += v*(v-1) // 2
        
print(ans)

Measured memory_bytes: 41728
# 解説と 13355391 を参考に実装予定


import math


def solve():
    N = int(input())
    ABs = [[int(i) for i in input().split()] for _ in range(N)]
    mod = 10 ** 9 + 7

    lonlieness = 0
    pairs = {}
    for AB in ABs:
        a, b = AB
        if a == 0 and b == 0:
            lonlieness += 1
            continue
        elif a == 0:
            a, b = -1, 0
            bad_a, bad_b = 0, 1
        elif b == 0:
            a, b = (0, 1)
            bad_a, bad_b = -1, 0
        else:
            _gcd = math.gcd(a, b)
            a //= _gcd
            b //= _gcd
            bad_a = -b
            bad_b = a
            if b < 0:
                a, b = -a, -b
            if bad_b < 0:
                bad_a, bad_b = -bad_a, -bad_b
        pairs.setdefault((a, b), 0)
        pairs.setdefault((bad_a, bad_b), 0)  # 仲の悪いグループも登録しておく
        pairs[(a, b)] += 1

    permutations = []
    for i, pair in enumerate(pairs.keys()):
        if i % 2 == 1:
            continue  # 仲の悪いグループは隣り合っているので飛び石で計算
        a, b = pair
        bad_a, bad_b = -b, a
        if bad_b < 0:
            bad_a, bad_b = -bad_a, -bad_b
        # gourp1 から1匹以上選ぶパターン + group2 から1匹以上選ぶパターン + どちらからも選ばないパターン計算する.
        # group1 と group2 は仲が悪いので同時に選ばれることはない.
        group_num = pow(2, pairs[(a, b)], mod) - 1
        badgroup_num = pow(2, pairs[(bad_a, bad_b)], mod) - 1
        permutations.append(group_num + badgroup_num + 1)

    result = 1
    for p in permutations:
        result = result * p % mod

    # 全員と仲が悪いイワシのパターンを足し, すべてのイワシを選ばないパターンを除外.
    result = (result + lonlieness - 1) % mod
    print(result)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 116124
import java.util.Scanner;

public class Main {

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

		int h = sc.nextInt();
		int w = sc.nextInt();
		String[][] table = new String[h][w];

		for (int i=0; i<h; i++) {
			String buf = sc.next();
			if (!buf.contains("#")) {
				buf = buf.replace(".", " ");
			}

			for (int j=0; j<w; j++) {
				table[i][j] = buf.substring(j, j+1);
			}
		}


		for (int j=0; j<w; j++) {
			boolean blackFlg = false;
			for (int i=0; i<h; i++) {
				if ("#".equals(table[i][j])) {
					blackFlg = true;
				}
			}
			if (!blackFlg) {
				for (int i=0; i<h; i++) {
					table[i][j] = " ";
				}
			}
		}

		for (int i=0; i<h; i++) {
			String buf = "";
			for (int j=0; j<w; j++) {
				if (!" ".equals(table[i][j])) {
					buf = buf + table[i][j];
				}
			}
			if (!buf.isEmpty()) {
				System.out.println(buf);
			}
		}

		sc.close();
	}

}


Measured memory_bytes: 28372
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int H; long long int N;
    cin>>H>>N;
    vector<int> A(N);
    vector<int> B(N);
    for(int i=0; i<N; ++i){
        cin>>A[i]>>B[i];
    }
    long long int dp[H+(*max_element(A.begin(), A.end()))];
    dp[0] = 0;
    long long int x = H+(*max_element(A.begin(), A.end()));
    for(int i=1; i<x; ++i){
        dp[i] = INT_MAX;
        for(int j=0; j<N; ++j){
            long long int current = B[j];
            if(A[j]<i) current += dp[i-A[j]];
            dp[i] = min(dp[i], current);
        }
    }
    long long int ans = INT_MAX;
    for(int i=H; i<x; ++i) ans = min(ans, dp[i]);
    cout<<ans<<endl;
}

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

public class Main {

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

        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        int alice = 0;
        int bob = 0;
        boolean isAlice = true;
        for (int i = a.length - 1; i != -1; i--) {
            if (isAlice) {
                alice += a[i];
            } else {
                bob += a[i];
            }
            isAlice = !isAlice;
        }

        System.out.println(alice - bob);
    }
}


Measured memory_bytes: 23764
N=input()
a=map(int,raw_input().split())
min_a=min(a)
max_a=max(a)

b=[]

for i in range(min_a,max_a+1):
	sum_a=0
	for j in a:
		sum_a+=(j-i)**2
	b.append(sum_a)

print min(b)



Measured memory_bytes: 2568
#include <bits/stdc++.h>
#include <queue>
// vectorの特徴:末尾への挿入・削除のみ高速	
int main(){
  int N,M;
  std::cin >> N >> M;
  if(N>=M){
    std::cout << "0" << std::endl;
    return 0;
  }
  std::vector<int> X;
  for(int i=0;i<M;i++){
    int input;
    std::cin >> input;
    X.push_back(input);
  }
  std::sort(X.begin(),X.end());
  std::vector <int> Diff;
  for(int i=0;i<M-1;i++){
    Diff.push_back(X[i+1] - X[i]);
  }
  std::sort(Diff.begin(),Diff.end());
  int sum;
  sum = std::accumulate(Diff.begin(),Diff.end()-N+1,0);
  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2
 
 
 
int main() {
	int n;
	cin >> n;
	vector<int>d(n);
	rep(i, 0, n)cin >> d[i];
	sort(all(d));
 
	int ans = 0;
	rep(i, 0, 101010) {
		int cnt1, cnt2;
		if (i > d[n-1]) {
			break;
		}
		else {
			cnt1 = lower_bound(all(d), i) - d.begin();
			cnt2 = n - cnt1;
		}
		if (cnt1 == cnt2) {
			ans++;
		}
	}
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll fr[200009];
int main()
{
    ll n,t;
    cin>>n;
     ll cum=0;
    for(ll i=1; i<=n; i++)
    {
        ll v;
        cin>>v;
        cum+=v;
        fr[v]++;
    }
    cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
        cum-=(a*fr[a]);
        cum+=b*fr[a];
        fr[b]+=fr[a];
        ll sv;
        fr[a]=0;
        cout<<cum<<endl;
    }
    return 0;
}


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

int main( int argc, char *argv[] )
{
int i;
int N;
int T;
int t;
//long long X;
long long Y;
long long iEnd;

	cin >> N;
	cin >> T;
	cin >> t;	// 0

//	X = 0;
	Y = 0;
	iEnd = T;
	for( i = 1; i < N; i++ )
	{
		cin >> t;
		if( iEnd < t ) Y += t - iEnd;

		iEnd = t + T;
	}

	cout << iEnd - Y << endl;

	return 0;
}


Measured memory_bytes: 256