akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<stack>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=410;
int N;
struct sqr{
	int a[4];
	sqr(int q=0,int w=0,int e=0,int r=0){
		a[0]=q,a[1]=w,a[2]=e,a[3]=r;
	}
	void rotate(){
		int t=a[0];
		for(int i=0;i<3;i++)
			a[i]=a[i+1];
		a[3]=t;
	}
	bool friend operator<(const sqr&A,const sqr&B){
		for(int i=0;i<4;i++)
			if(A.a[i]<B.a[i])
				return 1;
			else if(A.a[i]>B.a[i])
				return 0;
		return 0;
	}
}s[maxn];
map<sqr,int>mp;
inline void add(sqr A,int v){
	for(int i=0;i<4;i++){
		mp[A]+=v;
		A.rotate();
	}
}
int main(){
	//freopen("in","r",stdin);
	N=read();
	for(int i=1;i<=N;i++){
		for(int j=0;j<4;j++)
			s[i].a[j]=read();
		add(s[i],1);
	}
	long long ans=0;
	for(int i=1;i<=N;i++){
		add(s[i],-1);
		for(int j=i+1;j<=N;j++){
			add(s[j],-1);
			for(int k=0;k<4;k++){
				long long now=1;
				sqr tmp1(s[j].a[1],s[i].a[0],s[i].a[3],s[j].a[2]);
				sqr tmp2(s[i].a[1],s[j].a[0],s[j].a[3],s[i].a[2]);
				sqr tmp3(s[j].a[1],s[j].a[0],s[i].a[1],s[i].a[0]);
				sqr tmp4(s[i].a[3],s[i].a[2],s[j].a[3],s[j].a[2]);
				
				s[j].rotate();
				
				if(!(mp[tmp1]&&mp[tmp2]&&mp[tmp3]&&mp[tmp4]))
					continue;
				
				now*=mp[tmp1];add(tmp1,-1);
				now*=mp[tmp2];add(tmp2,-1);
				now*=mp[tmp3];add(tmp3,-1);
				now*=mp[tmp4];add(tmp4,-1);
				
				add(tmp1,1);
				add(tmp2,1);
				add(tmp3,1);
				add(tmp4,1);
				
				ans+=now;
			}
			add(s[j],1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 20352
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int main()
{
	ll a,b,n;
	cin>>a>>b>>n;
	ll ans=-1;
//	for(int i=1;i<=n;i++){
//		ll now=a*i/b-i/b*a;
//		if(now>ans) ans=now;
//		else if(now<ans)
//	}
	ll pos=b-1;
	if(n<pos) pos=n;
	ans=a*pos/b-pos/b*a; 
	cout<<ans;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N, R;
  cin >> N >> R;
  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + 100 * (10 - N) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#define M 100005
const int P=1000000007;
using namespace std;
int mark[M],A[M];
int ans[M];
int fac[M],inv[M],ifac[M];
void init(){
	fac[0]=ifac[0]=inv[1]=1;
	for(int i=1;i<M;++i)fac[i]=1ll*i*fac[i-1]%P;
	for(int i=2;i<M;++i)inv[i]=1ll*(P-P/i)*inv[P%i]%P;
	for(int i=1;i<M;++i)ifac[i]=1ll*inv[i]*ifac[i-1]%P;
}
int C(int n,int m){
	if(m<0||n<m)return 0;
	return (1ll*fac[n]*ifac[n-m]%P)*ifac[m]%P;
}
int main(){
	init();
	int n,p1,p2;
	scanf("%d",&n);
	n++;
	
	for(int i=1;i<=n;i++){
		scanf("%d",&A[i]);
		if(mark[A[i]])p2=i,p1=mark[A[i]];
		else mark[A[i]]=i;
	}
	p1=p1-1;
	p2=n-p2;
	
	ans[1]=n-1;
	for(int i=2;i<=n;i++)ans[i]=C(n,i);
	
	
	
	int t=p1+p2;
	for(int i=1;i<=t;i++){
		ans[i+1]=(ans[i+1]-C(t,i)+P)%P;
	}
	
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3584
n = int(input())
a_list = list(map(int, input().split())) 

break_cnt = 0
next_num = 1
for a in a_list:
    if a == next_num:
        next_num +=1
    else:
        break_cnt+=1

if break_cnt != n:
    print(break_cnt)
else:
    print(-1)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
typedef long long ll;
using namespace std;

int main() {
  int N,W; cin>>N>>W;
  int value[110],weight[110]; REP(i,N) cin>>value[i]>>weight[i];
  
  // dp[i+1][W] : i番目の品物まで、重さがWを超えないようにしながら選んだ時の価値の最大値
  int dp[110][10010];

  // 初期条件
  dp[0][0] = 0; REP1(i,W) dp[0][i] = 0;

  for(int i=0; i<N; i++) {
    for(int w=0; w<=W; w++) {
      if(w >= weight[i]) 
        dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
      else
        dp[i+1][w] = dp[i][w];
    }
  }

  cout<<dp[N][W]<<endl;
  return 0;
}


Measured memory_bytes: 7016
import java.io.*;
import java.util.*;
import java.lang.*;

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

    while(true){
      int m=Integer.parseInt(scan.next());
      int f=Integer.parseInt(scan.next());
      int r=Integer.parseInt(scan.next());
      if(m==-1 && f==-1 && r==-1)break;
      if((m==-1 || f==-1) || (m+f)<30){
        System.out.println('F');
      }else if((m+f)>=30 && (m+f)<50){
        if(r>=50){
          System.out.println('C');
        }else{
          System.out.println('D');
        }
      }else if((m+f)>=50 && (m+f)<65){
        System.out.println('C');
      }else if((m+f)>=65 && (m+f)<80){
        System.out.println('B');
      }else{
        System.out.println('A');
      }
    }
  }
}


Measured memory_bytes: 26248
#include <stdio.h>

int main(){
	
	int x ,y;
	while(	scanf("%d %d",&x,&y) != EOF){
		int z  = x+y;
		int digCnt = 1;
		while(z/10!=0){
			z/=10;
			digCnt++;
		}
		printf("%d\n",digCnt);
	}
	
	return 0;
}

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

typedef long long ll;

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

const ll INF = 1LL << 60;

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

    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0;i<n;i++) cin >> h[i];
    ll dp[100050];
    for(int i=0;i<100050;i++) dp[i] = INF;
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n) chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
const int MOD = 1000000007;
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  int n;
    cin>>n;
  vector<int> A(1100,1);
  for(int i=2;i<=n;i++){
    int now=i;
    int up=sqrt(now)+1;
      while(now%2==0){
        now/=2;
        A[2]++;
      }
    for(int j=3;j<=up;j+=2){
      while(now%j==0){
        now/=j;
        A[j]++;
      }
    }
      A[now]++;
  }

  long long ans=1;
  for(int i=2;i<=n;i++){
    ans*=A[i];
    ans%=MOD;
  }

  cout<<ans<<endl;
}

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

int main() {
    long long a;
    string b;
    cin >> a >> b;

    long long bll = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
    cout << a*bll/100 << endl;
}

Measured memory_bytes: 3596
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,p[25]={},ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> p[i];
  }
  for(int i=1; i<n-1; i++) {
    if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int x;
  cin >> x;
  int i;
  int f = 0;
  while(1){
    f = 0;
    for(i=2;i<x;i++){
      if(x%i==0) f=1;
    }
    if(f==1) x++;
    else{
      cout << x << "\n";
      return 0;
    }
  }
}

Measured memory_bytes: 3600
goal = ((1, 2, 3), (4, 5, 6), (7, 8, 0))

parents = {}
total = {}
flag = True

initial = []
position = []
for i in range(3):
	a, b, c = map(int, input().split())
	if a == 0:
		position.extend([i, 0])
	elif b == 0:
		position.extend([i, 1])
	elif c == 0:
 		position.extend([i, 2])
	initial.append( (a, b, c) )

parents[tuple(initial)] = position
total[tuple(initial)] = 1

count = 0

if tuple(initial) == goal:
	flag = False

while flag:
	count += 1
	children = {}
	for par_key in parents.keys():
		position = parents[par_key]

		if position[0] < 2:
			child = [list(par_key[0]), list(par_key[1]), list(par_key[2])]
			child[position[0]][position[1]] = child[position[0]+1][position[1]]
			child[position[0]+1][position[1]] = 0
			child_tuple = (tuple(child[0]), tuple(child[1]), tuple(child[2]))
			if child_tuple == goal:
				flag = False
				break
			elif child_tuple not in total:
				children[child_tuple] = [position[0]+1, position[1]]
				total[child_tuple] = 1

		if position[0] > 0:
			child = [list(par_key[0]), list(par_key[1]), list(par_key[2])]
			child[position[0]][position[1]] = child[position[0]-1][position[1]]
			child[position[0]-1][position[1]] = 0
			child_tuple = (tuple(child[0]), tuple(child[1]), tuple(child[2]))
			if child_tuple == goal:
				flag = False
				break
			elif child_tuple not in total:
				children[child_tuple] = [position[0]-1, position[1]]
				total[child_tuple] = 1

		if position[1] < 2:
			child = [list(par_key[0]), list(par_key[1]), list(par_key[2])]
			child[position[0]][position[1]] = child[position[0]][position[1]+1]
			child[position[0]][position[1]+1] = 0
			child_tuple = (tuple(child[0]), tuple(child[1]), tuple(child[2]))
			if child_tuple == goal:
				flag = False
				break
			elif child_tuple not in total:
				children[child_tuple] = [position[0], position[1]+1]
				total[child_tuple] = 1

		if position[1] > 0:
			child = [list(par_key[0]), list(par_key[1]), list(par_key[2])]
			child[position[0]][position[1]] = child[position[0]][position[1]-1]
			child[position[0]][position[1]-1] = 0
			child_tuple = (tuple(child[0]), tuple(child[1]), tuple(child[2]))
			if child_tuple == goal:
				flag = False
				break
			elif child_tuple not in total:
				children[child_tuple] = [position[0], position[1]-1]
				total[child_tuple] = 1

	parents = children

print(count)


Measured memory_bytes: 75588
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int a,b,h; cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    double N;
    cin >> N;
    if ((int)N & 1) {
        cout << setprecision(10) << (N + 1) / 2 / N << endl;
    } else {
        cout << 0.5 << endl;
    }
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

string rotate(string S)
{
  char C = S.at(0);
  S.erase(0, 1);
  S += C;
  return S;
}

int main()
{
  string S, T;
  cin >> S >> T;
  int N = S.size();
  
  string ans = "No";
  for (int i = 0; i < N; i++)
  {
    S = rotate(S);
    if (S == T) 
    {
      ans = "Yes";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

def erase(w, h, x, y):
    c[y][x] = '0'
    for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)):
        nx, ny = x + dx, y + dy
        if 0 <= nx <= w -1 and 0 <= ny <= h - 1:
            if c[ny][nx] == '1':
                erase(w, h, nx, ny)

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    c = [[i for i in input().split()] for _ in range(h)]
    ans = 0
    for y in range(h):
        for x in range(w):
            if c[y][x] == '1':
                ans += 1
                erase(w, h, x, y)
    print(ans)

Measured memory_bytes: 9560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  ll k; cin >> k;
  k--;
  rep(i, s.size()) {
    if(i == k) {
      cout << s[i] << endk;
      break;
    } else if(s[i] != '1') {
      cout << s[i] << endk;
      break;
    }
  }
  return 0;
}


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

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  
  int inf = pow(10, 9);

  for(int i = 0; i < n; i++){
    if(i < k) cout << s << " ";
    else{
      if(s < inf) cout << inf << " ";
      else cout << 1 << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <math.h>
#include <iostream>
#include<string>
#include<vector>
#include <algorithm>
#define REP(a,b) for (int i = a; i <= (b); i++)
using namespace std;
int main() {
  double a,b,c;
  cin>>a>>b;
  c=2*b-a;
  cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M =1000000007;
//MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
ll mpow(ll x, ll n){ //x^n(mod M) ????pow(x,n)?????????????mod??
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
int main (){
  int i,cnt=0;
  string s,t;
  cin>>s>>t;
  for(i=0;i<s.size();i++){
    if(s[i]==t[i]){
      cnt++;
    }
  }
  if(cnt==s.length()){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int k, s;
    cin >> k >> s;
    int res = 0;
    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j <= k; ++j) {
            int rest = s - i - j;
            if(rest >= 0 && rest <= k) res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num);
    vector<int> brr(num);
    cins(arr);
    cins(brr);

    int64_t as = 0;
    int64_t bs = 0;
    for(int i = 0; i < num; i++) {
        if(arr[i] < brr[i]) {
            bs += (brr[i] - arr[i])/2;
        } else {
            as += (arr[i] - brr[i]);
        }
    }
    debug("%ld <- %ld\n", bs, as);
    cout << (bs - as >= 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ll k;
  cin >> k;
  vl a(n);
  cin >> a;
  ll cr = 1LL<<39;
  ll x = 0;
  RREP(i,40){
    if(x+cr<=k){
      int ct = 0;
      REP(j,n){
        if(a[j]>>i&1) ct++;
      }
      if(2*ct<n) x += cr;
    }
    cr >>= 1;
  }
  ll ans = 0;
  REP(i,n) ans += x^a[i];
  cout << ans << endl;
}


Measured memory_bytes: 1024
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(A)
if N>=M:
  print(0)
else:
  a=M-N
  C=[0]*(M-1)
  for i in range(M-1):
    C[i]=B[i+1]-B[i]
  D=sorted(C)
  ans=sum(D[:a])
  print(ans)  

Measured memory_bytes: 13968
def main():
    N, K = (int(i) for i in input().split())
    H = [int(input()) for i in range(N)]
    H.sort()
    ans = 10**12
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 50264
import math
def is_prime(x):
    if x == 2:
        return True
    if (x % 2 == 0):
        return False
    m = math.ceil(math.sqrt(x))
    for i in range(3, m + 1):
        if x % i == 0:
            return False
    return True


n = int(input())

prime = 0
for i in range(n):
    x = int(input())
    if is_prime(x):
        prime += 1

print(prime)

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

int main(){
  int n;
  cin >> n;
  
  vector<int> attend(n);
  
  rep(i,n){
    int s;
    cin >> s;
    attend[s-1] = i + 1;
  }
  
  rep(i,n){
    cout << attend[i] << " ";
  }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i < n;i++)
using namespace std;
int main(){
	int k, n;
	cin>>k>>n;
	vector<int> a(n);

	rep(i,n) cin >> a[i];
	a.push_back(a[0]+k);
	int l = 0;
	rep(i, n) l = max(l, a[i+1]-a[i]);
	int ans = k - l;
	cout << ans;
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string s;
map<string,int> mp;
string ss[100005];
ll a[100010];
void init()
{
    a[1] = 0,a[2] = 1;
    for(int i=3;i<=100000;i++)
    {
        a[i] = 1ll*i*(i-1)/2;
    }
}
int main()
{
    int n,cnt = 0;
    init();
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        sort(s.begin(),s.end());
        if(mp[s]){
            mp[s] += 1;
        }
        else{
            ss[++cnt] = s;
            mp[s] = 1;
        }
    }
    ll ans = 0;
    for(int i=1;i<=cnt;i++)
    {
        ans += 1ll*a[mp[ss[i]]];
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 17408
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		Set<Integer> set = new HashSet<>(q);
		int count = 0;  //setの要素数

		for(int i = 0; i < q; i++) {
			int query = sc.nextInt();
			int x = sc.nextInt();

			if(query == 0) {
				if(set.add(x)) count++;
				System.out.println(count);
			}
			else {
				if(set.contains(x)) System.out.println(1);
				else System.out.println(0);
			}
		}
	}

}



Measured memory_bytes: 160680
// Aizu Vol-2 0268: Kongo Type
// 2017.8.17

#include <stdio.h>
#include <stdlib.h>

char *gets();
char buf[20], *p;

int frac[7] = { 78125, 156250, 312500, 625000, 1250000, 2500000, 5000000 };

int x2d(char c) { if (c <= '9') return c - '0'; return c - 'a' + 10; }

int main(void)
{
	int Q, i, d, f;

	gets(buf); Q = atoi(buf);
	while (Q-- > 0) {
		gets(p = buf);
		if (*p >= '8') putchar('-');
		d = x2d(*p++); if (d >= 8) d -= 8;
		for (i = 0; i < 5; i++) d = (d << 4) + x2d(*p++);
		d <<= 1;
		f = x2d(*p++);
		if (f >= 8) d |= 1;
		printf("%d.", d);
		f = (f << 4) + x2d(*p);
		for (d = i = 0; i < 7; i++, f >>= 1) if (f & 1) d += frac[i];
		sprintf(buf, "%07d", d);
		p = buf + 6;
		while (p > buf && *p == '0') p--;
		*(p + 1) = 0;
		puts(buf);
	}
	return 0;
}

Measured memory_bytes: 556
#include<iostream>
using namespace std;
int main(){
int N,M;
cin>>N>>M;
double arr[N];
for(int i=0;i<N;i++){
    cin>>arr[i];
}
double total=0;
for(int i=0;i<N;i++){
    total+=arr[i];
}
int count=0;
for(int i=0;i<N;i++){
    if(count==M){
        break;
    }
    else if(arr[i]>=((total)/(4*M))){
    count++;
    }
}
if(count==M){
cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}
}


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

int main(){
	char a, b;
	cin >> a >> b;
	if(a == 'H'){
		if(b == 'H') cout << 'H' << "\n";
		else cout << 'D' << "\n";
	} else{
		if(b == 'H') cout << 'D' << "\n";
		else cout << 'H' << "\n";
	}
	return 0;
}

Measured memory_bytes: 384
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int A, B;

int main() {
    cin >> A >> B;
    cout << (A <= 8 && B <= 8 ? "Yay!" : ":(") << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

S=list(input())
T=list(input())
F=1
for i in range(len(S)):
    if  not S[i]==T[i]:
        F=0

if not len(T)==len(S)+1:
    F=0

if F==1:
    print("Yes")

if F==0:
    print("No")

Measured memory_bytes: 9108
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(n)]
    #print(a)

    for k in range(n-1,-1,-1):
        for i in range(n-1,-1,-1):
            for j in range(n-1,-1,-1):            
                #print(k,i,j,a)
                if (i==j or k==i or k==j):
                    continue
                if (a[i][k]!=-1 and a[k][j]!=-1 and a[i][j] == a[i][k]+a[k][j]):
                    a[i][j] = -1
                elif (a[i][k]!=-1 and a[k][j]!=-1 and a[i][j] > a[i][k]+a[k][j]):
                    print(-1)
                    exit()
            
    #print(a)

    ans = 0
    for i in range(0,n-1):
        for j in range(i,n):
            if (a[i][j]!=-1):
                ans += a[i][j]
    print(ans)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 43740
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    ll sum = 0;
    for(int i=1; i<N+1; i++){
        if(i%3>0&&i%5>0){
            sum += i;
        }
    }
    cout << sum;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int used[(int)1e5 + 100];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,x,y;
	cin >> n >> x >> y;
	for(int i = 1;i <= n;i++){
		for(int j = i + 1;j <= n;j++){
			used[min(j - i, min(abs(x - i) + abs(y - j) + 1, abs(x - j) + abs(y - i) + 1))]++;
			
		}
	}
	for(int i = 1;i <= n - 1;i++)cout << used[i]  << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N, M;
    in2(N, M);

    vi P(M), Y(M);
    rep(i, M) in2(P[i], Y[i]);

    vvi X(N + 1);
    rep(i, M) X[P[i]].push_back(Y[i]);

    rep(i, N + 1) sort(all(X[i]));

    rep(i, M)
    {
        auto itr = lower_bound(all(X[P[i]]), Y[i]);

        int num = distance(X[P[i]].begin(), itr) + 1;

        cout << std::setw(6) << std::setfill('0') << P[i];
        cout << std::setw(6) << std::setfill('0') << num << endl;
    }

    return 0;
}


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

int main(){
  int n,a,d;
  cin>>n>>a>>d;
  
  vector<int> x,y,z;
  int m;
  
  cin>>m;

  x.resize(m);
  y.resize(m);
  z.resize(m);
  
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i]>>z[i];
  }
  
  int k;
  cin>>k;

  for(int i=m-1;i>=0;i--){
    if(x[i]==0){
      if(y[i]==k || z[i]==k){
        k=y[i]+z[i]-k;
      }
    }else{
      if(y[i]==k){
        k=z[i];
      }
      
    }
  }
  
  cout<<a+(k-1)*d<<endl;
  return 0;
}

Measured memory_bytes: 3124
n,m = map(int, input().split())
dat_a = map(int, input().split())
dat_a = list(dat_a)
dat_a.sort()
trade = []
for i in range(m):
    b, c = map(int, input().split())
    trade.append((b,c))
trade.sort(key=lambda x: -x[1])

cur_remain = 0
cur_num = 0
cur = -1
for i in range(n):
    if cur_remain == 0:
        cur += 1
        if cur >= len(trade):
            break
        cur_remain = trade[cur][0]
        cur_num = trade[cur][1]
    if dat_a[i] < cur_num:
        cur_remain -= 1
        dat_a[i] = cur_num
    else:
        break
print(sum(dat_a))

Measured memory_bytes: 25580
class Heap
  attr_accessor :id, :key, :pid, :lid, :rid
 
  def initialize(id, key, max)
    @id = id.to_i + 1
    @key = key
    set_parent unless @id == 1
    set_left if @id * 2 <= max
    set_right if @id * 2 + 1 <= max
  end
 
  def set_parent
    @pid = id / 2
  end 
 
  def set_left 
    @lid = id * 2
  end
 
  def set_right
    @rid = id * 2 + 1
  end 
 
end
 
n = gets.to_i
keys = gets.split
heap = Array.new(n)
n.times do |i|
  heap[i] = Heap.new(i,keys[i], n) 
end
n.times do |i|
  print "node ", heap[i].id, ": key = ", heap[i].key, ", "
  print "parent key = ", heap[heap[i].pid-1].key, ", " unless heap[i].pid.nil?
  print "left key = ", heap[heap[i].lid-1].key, ", " unless heap[i].lid.nil?
  print "right key = ", heap[heap[i].rid-1].key, ", " unless heap[i].rid.nil?
  puts
end

Measured memory_bytes: 8896
class SegmentTree:
    def __init__(self, lst, op, e):
        self.n = len(lst)
        self.N = 1 << ((self.n - 1).bit_length())
        self.op = op # operation
        self.e = e # identity element
        self.v = self._build(lst)
        
    def _build(self, lst):
        # construction of a tree
        # total 2 * self.N - 1 elements
        tree = [self.e] * (self.N - 1) + lst + [self.e] * (self.N - self.n)
        for i in range(self.N - 2, -1, -1):
            tree[i] = self.op(tree[2*i + 1], tree[2*i + 2])
        return tree
    
    def __getitem__(self, i):
        return self.v[i + self.N - 1]
    
    # update a_i to be x 
    def update(self, i, x):
        i += self.N - 1
        self.v[i] = x
        while i > 0:
            i -= 1; i >>= 1
            self.v[i] = self.op(self.v[2*i + 1], self.v[2*i + 2])
    
    # returns answer for the query interval [l, r)
    def query(self, l, r):
        left = l + self.N - 1
        right = r + self.N - 1
        L = self.e; R = self.e
        while left < right:
            if left & 1 == 0: # self.v[left] is the right child
                L = self.op(L, self.v[left])
                left += 1
            if right & 1 == 0: # self.v[right-1] is the left child
                right -= 1
                R = self.op(self.v[right], R)
            left -= 1; left >>= 1
            right >>= 1
        return self.op(L, R)

N = int(input())
S = input()
sg = SegmentTree([1 << (ord(s) - ord('a')) for s in S], lambda x, y: x | y, 0)
Q = int(input())
for _ in range(Q):
    t, a, b = input().split()
    t = int(t); a = int(a)
    if t == 1:
        sg.update(a-1, 1 << (ord(b) - ord('a')))
    else:
        b = int(b)
        x = sg.query(a-1, b)
        ans = 0
        for i in range(26):
            if (1 << i) & x: ans += 1
        print(ans)

Measured memory_bytes: 48080
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}


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

	ll a, b;
	cin >> a >> b;

	cout << max(0ll,a-2*b) << endl;



	return 0;
}

Measured memory_bytes: 256
int dou(int x, int a, int b, int c)
{
  int dp[51][51][51];
  int n = 0;
  int i, j, k;
  for ( i=0; i<=a; i++ ) {
    for ( j=0; j<=b; j++ ) {
      for ( k=0; k<=c; k++ ) {
        dp[i][j][k] = 500*i + 100*j + 50*k;
        if ( dp[i][j][k] == x ) { n++; }
      }
    }
  }
  return n;
}

int main(void)
{
  int n;
  int a, b, c;
  int x;
  int b5, c10, c2;
  scanf("%d %d %d", &a, &b, &c);
  scanf("%d", &x);

  n = dou(x, a, b, c);

  printf("%d\n", n);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
int n, a[2005];
bool dp[2005][200005];
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	dp[0][0] = 1;
	int lst = 0, tol = 0;
	for(int i = 1; i <= n; i++){
	    tol += a[i];
		for(int j = 0; j <= 100000; j++){
		    if(j < a[i]) dp[i][j] |= dp[i - 1][a[i] - j];
		    else dp[i][j] |= dp[i - 1][j - a[i]];
		    if(j + a[i] <= 100000) dp[i][j] |= dp[i - 1][j + a[i]];
		}
	}
	for(int i = 0; i <= 100000; i++){
		if(dp[n][i]){
			cout << (tol + i) / 2;
			return 0;
		}
	}
}

Measured memory_bytes: 206980
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
int main()
{
	ll n;
	cin>>n;
	map<ll,ll> m;
	ll x;
	ll sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>x;
		sum+=x;
		m[x]++;
	}
	ll q;
	cin>>q;
	ll b,c;
	while(q--)
	{
		cin>>b>>c;
		ll temp=m[b];
		sum-=(b*temp);
		sum+=(c*temp);
		m[c]+=temp;
		m[b]=0;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 9544
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int main(void){
  char x[11];
  cin>>x;
  if(strlen(x)<4)cout<<"No"<<endl;
  else{
      if(x[0]=='Y'&&x[1]=='A'&&x[2]=='K'&&x[3]=='I')cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
def resolve():
    s = input()

    deviders = ['resare', 'esare', 'remaerd', 'maerd']

    s = s[::-1]
    i = 0

    while i < len(s):

        flag = False

        for devider in deviders:

            if s[i:i + len(devider)] == devider:

                i += len(devider)
                flag = True
                break

        if not flag:
            print('NO')
            return

    print('YES')

    return
  
resolve()

Measured memory_bytes: 40560
import numpy as np
a = list(map(int,input().split()))

x = a[0]
n = a[1]

if (n == 0):
    print(x)
else:
    d = list(map(int,input().split()))
    min_int = d[np.argmin(d)]
    max_int = d[np.argmax(d)]
    if (x < min_int or max_int < x):
        print(x)
    else:
        p = []
        for var in range(min_int - 10,max_int + 10):
            if var not in d:
                p.append(var)
            else:
                continue
        ans = []
        for pp in p:
            ans.append(np.abs(pp - x))
        ans = np.array(ans)
        print(p[np.argmin(ans)])


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

void solve() {
	string s; cin >> s;
	if (s.size() == 2) {
		if (s[0] == s[1]) printf("1 2");
		else printf("-1 -1");
		return;
	}
	map<char, int> m;
	++m[s[0]]; ++m[s[1]];
	for (int i = 2; i < (int)s.size(); ++i) {
		++m[s[i]];
		if (m[s[i]] >= 2 || m[s[i-1]] >= 2 || m[s[i-2]] >= 2) {
			printf("%d %d", i-1, i+1);
			return;
		}
		--m[s[i-2]];
	}
	printf("-1 -1");
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
            using namespace std;
            int main(){
              int N;
              cin >> N;
              int d[N];
              for( int i=0;i<N;i++){
                cin >> d[i];
              }
              
              int c=0;
              for( int i=0;i<N;i++){
                for( int j=i+1;j<N;j++){
                  c+=d[i]*d[j];
                }
              } 
            cout << c << endl;}

Measured memory_bytes: 256
from math import gcd
from collections import defaultdict

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
MOD = 10**9 + 7


"""
愚直解
・全イワシの組み合わせを考える：2^N
・それぞれのイワシについて、仲が悪いかどうか確認する：nCk(2^x, 2)
間に合うはずがない

そもそも、仲の悪いイワシの条件が分かっているので、仲の悪いやつらをグループにする。で、仲の悪いやつの一方が選ばれるときは、もう一方は選ばれない、みたいにする。
(a,b)に対し、(-m*b, m*a)や(m*b, -m*a)は選べないので、これらを約分して、正の傾きと負の傾きで分けて数え上げる。
「正のグループから一つ以上選ぶ場合の数」＋「負のグループから一つ以上」＋「どちらも選ばない」が、このグループの選び方。
(a,0), (0,b)は約分できないので、分けて取る。
また、(0,0)は他のイワシと必ず仲が悪いのでこれは別に数える
最後に、何も選ばない場合を引いて終わり。

Fraction使ってやってみたが、間に合わない＆REでた。
gcdが間に合うのは意外だった（A,B <= |10**18|なので、きっと間に合わないと思ってた。）
"""

d = defaultdict(int)
cnt_00 = 0
cnt_0b = 0
cnt_a0 = 0
for a,b in AB:
    if a == b == 0:
        cnt_00 += 1
    elif a == 0:
        cnt_a0 += 1
    elif b == 0:
        cnt_0b += 1
    else:
        num_gcd = gcd(a,b)
        grad = 1 if a * b > 0 else -1
        a //= num_gcd
        b //= num_gcd
        d[(grad, abs(a), abs(b))] += 1



ans = 1
for k in d.keys():
    if d[k] == 0:
        continue
    
    grad, a, b = k[0], k[1], k[2]
    if (-grad, b, a) in d:
        
        # 傾き a/bのものを一つ以上選ぶ場合（-b/aは選ばない） + -b/aから一つ以上選ぶ場合（a/bは選ばない） + どちらからも選ばない場合
        ans *= (pow(2, d[(grad, a, b)], MOD)-1) + (pow(2, d[(-grad, b, a)], MOD)-1) + 1
        ans %= MOD
        d[(grad, a, b)] = 0
        d[(-grad, b, a)] = 0
    else:
        # a/bから0個以上選ぶ場合
        ans *= pow(2, d[(grad, a, b)], MOD)
        ans %= MOD
        d[(grad, a, b)] = 0

# a,bの一方のみ0の場合 + どちらからも選ばない場合
ans *= (pow(2, cnt_a0, MOD)-1) + (pow(2, cnt_0b, MOD)-1) + 1
ans %= MOD

# 0,0のみを１つだけ入れる場合
ans += cnt_00
# なにも選ばない場合を除く
ans -= 1

ans %= MOD

print(ans)

Measured memory_bytes: 160744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 1000000007

int main(void){
	int h, w, k;
	int s[] = {1, 1, 2, 3, 5, 8, 13, 21};
	cin >> h >> w >> k;
	long long ans = 0;
	long long dp[110][10];
	for(int i = 0; i < 110; ++i){
		for(int j = 0; j < 10; ++j){
			dp[i][j] = 0;
		}
	}
	dp[0][1] = 1;
	for(int i = 0; i < h; ++i){
		for(int j = 1; j <= w; ++j){
			dp[i+1][j+1] += dp[i][j] % MOD * s[w-(j+1)] % MOD * s[j-1] % MOD;
			dp[i+1][j-1] += dp[i][j] % MOD * s[w-j] % MOD * s[j-1-1] % MOD;
			dp[i+1][j] += dp[i][j] % MOD * s[w-j] % MOD * s[j-1] % MOD;
			//cout << dp[i+1][j-1] << " " << dp[i+1][j] << " " << dp[i+1][j+1] << endl;
		}
	}
	cout << dp[h][k] % MOD << endl;
	/*
	for(int i = 0; i <= h; ++i){
		for(int j = 1; j <= w; ++j){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 256
N,W=map(int,input().split())
weight=[0]*N
values=[0]*N
for i in range(N):
  weight[i],values[i]=map(int,input().split())

dp=[[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N):
  for w in range(W+1):
    if w>=weight[i]:
      dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+values[i])
    else:
      dp[i+1][w]=dp[i][w]
      
print(dp[N][W])


Measured memory_bytes: 171912
n=int(input())
a=list(map(int,input().split()))

a.sort()

x=a[-1]

dp=[0 for _ in range(x+1)]

for b in a:
  y=b
  while y<=x:
    dp[y]+=1
    y+=b

    
ans=0
for c in a:
  if dp[c]==1:
    ans+=1
    
print(ans)
    

Measured memory_bytes: 32176
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n,a,b = LI()
ans = (n//(a+b))*a
ans += min(n%(a+b), a)
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX / 2+2],R[MAX / 2+2];

void merge(struct Card A[],int n,int left, int mid, int right){
  int i,j,k;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;

  for(k=left;k<right;k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];//変数ミスした箇所
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right){
  int mid;
  if(left + 1 <right){
    mid = (left + right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r){
  int i,j;
  struct Card t,x;
  x = A[r];
  i = p - 1;
  for(j=p;j<r;j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r){
  int q;
  if(p<r){
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit != B[i].suit) stable = 0;
  }
  
  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n");
  
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  
  
  
  return 0;
}



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

using namespace std;


int main(){
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int dp[k+1];
	memset(dp, 0, sizeof dp);
	for (int i = 0; i < n; ++i){
		dp[a[i]] = 1;
	}
	for (int i = 0; i <= k; i++){
		for (int j = 0; j < n; ++j){
			if (i - a[j] >= 0 and !dp[i-a[j]]) dp[i] = 1;
		}
	}
	cout << (dp[k] ? "First": "Second") << '\n';
	return 0;
}

Measured memory_bytes: 640
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(i+1,n):
    sum=0
    for k in range(d):
      sum+=(x[i][k]-x[j][k])**2
    z=pow(sum,0.5)
    if math.ceil(z)==math.floor(z):
      cnt+=1
print(cnt)


Measured memory_bytes: 9292
#include <bits/stdc++.h>
using namespace std;
#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, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  VSORT(a);
  int m = 0;
  REP(i, n - 1){
    if(a[i + 1] == a[i]) m++;
  }

  ll cnt = (m + 1) / 2;
  cout << n - cnt * 2 << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    double L;
    cin >> L;
    cout << setprecision(10) << (L / 3) * (L / 3) * (L / 3);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main(void){
    // Your code here!
    int N , K , Q , a;
    cin >> N >> K >> Q;
    map<int,int> map;
    for(int i = 0;i < Q;i++){
        cin >> a;
        map[a-1] += 1;
    }
    
    for(int i = 0 ; i < N;i++){
        if( (K + map[i]) - Q > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 5376
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

$N = (int)input();
switch ($N) {
    case 1:
        echo "Hello World\n";
        break;
    case 2:
        $A = input();
        $B = input();
        echo ($A + $B) . "\n";
        break;
}
exit;

Measured memory_bytes: 4604
import collections
from collections import defaultdict

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

dict = defaultdict(int)
for i in l:
    dict[i]+=1

ans = 0
for v in dict.values():
    ans += int((v*(v-1)) // 2)

for k in l:
    print(ans - (dict[k] - 1))


Measured memory_bytes: 26780