akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int i,N,j,div,mod,k;
        N=sc.nextInt();
        for(i=1;i<=N;i++){
            if(i%3==0){
                System.out.print(" "+i);
            }else{
                k=i;
                for(j=0; ;j++){
                    div=k/10;
                    mod=k%10;
                    if((div==3)||(mod==3)){
                        System.out.print(" "+i);
                        break;
                    }
                    k=div;
                    if(div==0){
                        break;
                    }
                }
            }               
        }
        System.out.println();   
    }
}


Measured memory_bytes: 28996
#include<bits/stdc++.h>
using namespace std;
// #define LOCAL
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
int const nax = 3e5 + 10, mod = 1e9 + 7;
void plusle(int &a,int b){a+=b;if(a>=mod)a-=mod; return;}
void minun(int &a,int b){a-=b; if(a<0)a+=mod; return;}
int add(int a,int b) {a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b) {a-=b;return a<0?a+mod:a;}
int mul(int a,int b) {return (int)((long long)a*b%mod);}
int power(int a,int b) {int res=1;while (b>0) {if (b&1) {res=mul(res,a);}a=mul(a,a);b>>=1;}return res;}

int const Mx = 3000;
int fac[Mx],invf[Mx];
void prefact(){
    fac[0]=1;
    for(int i=1;i< Mx;i++)
        fac[i]=mul(fac[i-1],i);
    invf[Mx-1]=power(fac[Mx -1],mod-2);
    for(int i=Mx -2 ;i>=0;i--){
        invf[i]=mul(invf[i+1],i+1);
    }

}
int ncr(int N,int R){
    if(N < 0) return 0;
    if(R > N || R < 0) return 0;
    if(N == 0 || N == R)
        return 1;
    return mul(fac[N],mul(invf[N-R],invf[R]));
}
int n, k, a[nax];
int f[22][1050];

int main(){
    prefact();
    scanf("%d %d", &n, &k);
    for(int i = 1 ;i <= k ;i ++) {
        scanf("%d", a  + i);
    }
    for (int i = 0 ; i <= n ; ++ i) {
        f[1][i] = mul(ncr(n , i), ncr(n - i, a[1] - i));
    }
    for (int j = 2 ; j <= k ; ++ j) {
        for (int i = 0 ; i <= n ; ++ i) {
            for (int from = 0 ; from <= n - i ; ++ from) {
                int toAdd = mul(f[j - 1][from], mul(ncr(n - from, i), ncr(n - i, a[j] - i)));
                plusle(f[j][from + i] , toAdd);
            }
        }
    }
    printf("%d\n", f[k][n]);
}
/*
    Good Luck
        -Lucina
*/


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 10000000

int main()
{
  int n;cin>>n;
  vector<int> p(n);
  int i;
  rep(i,n)cin>>p[i];
  vector<int> fvisit(n,-1);
  vector<int> jumpfrom(n);
  iota(all(jumpfrom),0);
  rep(i,n)
  {
    if(fvisit[i]!=-1)
    {
      jumpfrom[i]=jumpfrom[fvisit[i]];
      continue;
    }
    fvisit[i]=i;
    int now=i;
    bool br=false;
    while(p[now]!=0)
    {
      now+=p[now];
      if(fvisit[now]==i)
      {
        jumpfrom[i]=INF;
        br=true;
        break;
      }
      if(fvisit[now]!=-1)
      {
        jumpfrom[i]=jumpfrom[fvisit[now]];
        br=true;
        break;
      }
      fvisit[now]=i;
    }
    if(!br)jumpfrom[i]=now;
  }
  vector<int> minsteps(n,INF);
  minsteps[0]=0;
  int steps=0;
  queue<int> q1;
  queue<int> q2;
  q1.push(0);
  while(!q1.empty())
  {
    while(!q1.empty())
    {
      int tops=q1.front();
      q1.pop();
      for(i=1;i<=6;i++)
      {
        int next=tops+i;
        if(next>n-1)next=n-1;
        int to=jumpfrom[next];
        if(to==INF)continue;
        if(minsteps[to]==INF)
        {
          minsteps[to]=steps+1;
          q2.push(to);
        }
      }
    }
    while(!q2.empty())
    {
      q1.push(q2.front());
      q2.pop();
    }
    steps++;
  }
  cout<<minsteps[n-1]<<endl;
}




Measured memory_bytes: 4436
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 12

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	cout << fixed;
	cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n, m;
	cin >> n >> m;
	
	int sides[n][n];
	for (int i = 0; i < n; i ++)
	{
		for (int j = 0; j < n; j++)
		{
			sides[i][j] = false;
		}
	}
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		sides[a][b] = sides[b][a] = true;
	}
	
	vector<int> vertexes;
	for (int i = 0; i < n; i++)
	{
		vertexes.push_back(i);
	}
	
	int counter = 0;
	do
	{
		if (vertexes[0] != 0)
		{
			continue;
		}
		
		bool ok = true;
		for (int i = 0; i < n - 1; i++)
		{
			//cout << vertexes[i] << " " << vertexes[i+ 1] << endl;
			//cout << sides[vertexes[i]][vertexes[i + 1]] << endl;
			if (sides[vertexes[i]][vertexes[i + 1]] == false)
			{
				ok = false;
				break;
			}
		}
		
		if (ok == true)
		{
			counter++;
		}
	}
	while (next_permutation(vertexes.begin(), vertexes.end()));
	
	cout << counter << endl;

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 3644
/*"for if God is with them who can be against them."
   it's beter to die struggling than to abandon the effort where there is still
   a chance of accomlishing something more..NEVER GIVE UP.
   */

/* "IF THERE IS NO WAY OUT LOOK AT THE BOTTOM". */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
void solve() {
	ll n;
	cin >> n;
	ll ans = 0;
	ll a[n];
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (ll i = 1; i < n; i++) {
		if (a[i - 1] > a[i]) {
			ans += (a[i - 1] - a[i]);
			a[i] += (a[i - 1] - a[i]);
		}
	}
	cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
	/*TRY AGAIN, NO MATTER HOW MANY TIMES YOU FAILED ALWAYS TRY ONCE MORE*/
}

Measured memory_bytes: 5212
N,M=map(int,input().split())
scan=[]
gcan=[]
flag=0
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        scan.append(b)
    if b==N:
        gcan.append(a)
if set(scan)&set(gcan):
    flag=1
if flag==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 21836
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e12;
int N = 5 + 1e5;


int main()
{
	int n;
	cin >> n;
	vector<int> cnt(N);
	for (int i = 1;i < sqrt(n);i++) {
		for (int j = 1;j < sqrt(n);j++) {
			for (int q = 1;q < sqrt(n);q++) {
					ll ans = i * i + j * j + q * q + i * j + i * q + q * j;
					cnt[ans-1]++;
			}
		}
	}
	rep(i, n) cout << cnt[i] << endl;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int h;
		cin >> h;
		if (h >= k)
			ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
//Md Fahad
// CSE 18

#include<bits/stdc++.h>

using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int dx[] = {+1,-1,+0,+0};                         // 4 X directions
const int dy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int dx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int dy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int           ll;
typedef unsigned long long int  llu;

int main(void)
{

    string a;
    cin >> a;

    for(int i=0;i<a.size();i++)
        cout << "x";
        cout << endl;


    return 0;
}




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

int main()
{
 int a,i,b,c,j;
 char n;
 char moji[1000],shiji[8],rep[1000];
 scanf("%s",&moji);
 scanf("%d",&a);
 for(i=0;i<a;i++){
                     scanf("%s",&shiji);
                     if(strcmp(shiji,"replace")==0){
                                                     scanf("%d%d%s",&b,&c,&rep);
                                                     for(j=0;j<c-b+1;j++){
                                                                          moji[b+j]=rep[j];
                                                                          }
                                                    }
                     if(strcmp(shiji,"reverse")==0){
                                                   scanf("%d%d",&b,&c);
                                                   for(;b<c;){
                                                              n=moji[b];
                                                              moji[b]=moji[c];
                                                              moji[c]=n;
                                                              b++;
                                                              c--;
                                                              }    
                                                     }         
                           
                     if(strcmp(shiji,"print")==0){         
                                                  scanf("%d%d",&b,&c);
                                                  for(j=b;j<c+1;j++){
                                                  printf("%c",moji[j]);
                                                                    }
                                                  printf("\n");
                                                  }

                     }
   return 0;

}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int inf = 1e9;

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

int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

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

    int a, b;
    while (cin >> a >> b) {
        cout << gcd(a, b) << " " << lcm(a, b) << endl;
    }
}

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

int main(){
    ll x, k, d; cin >> x >> k >> d;
    if(x < 0) x *= -1;

    ll tmp1 = x%d, tmp2 = d - x%d;
    ll k2 = (x - tmp1)/d;
    ll minx = tmp1;
    if(tmp2 < tmp1) {
        k2++;
        minx = tmp2;
    }
    if(k2 >= k) {
        ll ans = x - d*k;
        if(ans < 0) ans *= -1;
        cout << ans << endl;
        return 0;
    } else {
        ll dk = k - k2;
        if(dk%2 == 0) {
            cout << minx << endl;
            return 0;
        } else {
            ll tmp3 = minx + d, tmp4 = minx - d;
            if(tmp3 < 0) tmp3 *= -1;
            if(tmp4 < 0 ) tmp4 *= -1;
            cout << ((tmp3 < tmp4)?tmp3:tmp4) << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
//const int MAX=1;

int main(){
	string S;
	cin>>S;
	int a=S[5]-'0';
	int b=S[6]-'0';
	int m=10*a+b;
	if(m<=4)cout<<"Heisei";
	else cout<<"TBD";
}

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    string s1, s2; cin >> s1 >> s2;
    cout << s2 + s1 << '\n';
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n;  cin >> n;
    vector<int>c(n);
    vector<int>s(n);
    vector<int>f(n);
    rep(i, n-1)   cin >> c[i] >> s[i] >> f[i];
    vector<vector<int> >dp(n+1, vector<int>(n+1));
    for(int i = 1; i <= n; i++){
        for(int j = i; j < n; j++){
            if(dp[i][j] < s[j-1]){
                dp[i][j+1] = s[j-1] + c[j-1];
            }else{
                if(dp[i][j] % f[j-1] == 0){
                    dp[i][j+1] = dp[i][j] + c[j-1];
                }else{
                    dp[i][j+1] = (dp[i][j]/f[j-1] + 1)*f[j-1] + c[j-1];
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << dp[i][n] << endl;
    }
}


Measured memory_bytes: 1280
#include<stdio.h>
int main()
{
    int x=0,sum=0,a=0,b=0;
    scanf("%d,%d,%d",&a,&x,&b); 
    while (x<a) 
	 x=x+1;
	  b=x;
	  sum=(b+1)*b/2;
	 printf("%d\n",sum);
 } 

Measured memory_bytes: 128
from sys import stdin
lines = stdin.readlines()
 
N = int(lines[0])
S = lines[1]

cnt = 0
for num in range(N - 2):
  if S[num] == 'A' and S[num + 1] == 'B' and S[num + 2] == 'C':
    cnt += 1

print(cnt)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return

        if x<y:
            self.par[y] = x
        else:
            self.par[x] = y
    def same(self, x, y):
        return self.find(x) == self.find(y)


n,k,l = map(int, input().split())
pq = UnionFind(n)
for _ in range(k):
    p,q = map(int, input().split())
    pq.unite(p-1,q-1)
rs = UnionFind(n)
for _ in range(l):
    r,s = map(int, input().split())
    rs.unite(r-1,s-1)

# print(pq.par)
# print(rs.par)
d = {}
for x in range(n):
    a = pq.find(x)
    b = rs.find(x)
    if (a,b) not in d:
        d[(a,b)] = 0
    d[(a,b)] += 1
# print(d)
ret = []
for x in range(n):
    a = pq.find(x)
    b = rs.find(x)
    ret.append(str(d[(a,b)]))

print(" ".join(ret  ))


Measured memory_bytes: 61044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  int n = s.size();
  
  stack<char> st;
  st.push(s[0]);
  rep(i, 1, n) {
    if(!(st.empty())) {
      if(s[i] != st.top()) 
        st.pop();
      else 
        st.push(s[i]);
    }
    else st.push(s[i]);
  }
  cout << n-(int)st.size() << "\n";
}

Measured memory_bytes: 512
N = int(input())
S = input()

forward_cost = []

cost = 0
for i in range(len(S)):
  if S[i] == "W":
    cost = cost + 1
  forward_cost.append(cost)

cost = 0
SR = S[::-1]
for i in range(len(S)):
  if SR[i] == "E":
    cost = cost + 1
  forward_cost[len(S)-i-1] = forward_cost[len(S)-i-1] + cost

#print(forward_cost)
print(min(forward_cost)-1)

Measured memory_bytes: 15520
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d=0,e=1;
cin>>a;
  for(int i=1;i<=a;i++){
    b=i,c=0;
    while(true){
      if(b%2!=0) break;
      b/=2;
      c++;
    }
    d=max(d,c);
  }
  e=e<<d;
  cout<<e<<"\n";
}
     

Measured memory_bytes: 256
import copy
n, m =map(int, input().split())  #複数数値入力
list_h=list(map(int, input().split()))  #リスト入力
# 繰り返しリスト入力
a = []
for i in range(m):
    ai = list(map(int, input().split()))  #リスト入力
    a.append(ai)

for i in a:
    i.sort()
a = list(map(list, set(map(tuple, a))))

booler = [True] * n
for j in a:
    if list_h[j[0]-1] < list_h[j[1]-1]:
        booler[j[0]-1] = False
    elif list_h[j[0]-1] > list_h[j[1]-1]:
        booler[j[1]-1] = False
    else :
        booler[j[0]-1] = False
        booler[j[1]-1] = False
print(booler.count(True))

Measured memory_bytes: 50484
#define _CRT_SECURE_NO_WARNINGS
#define TASK "C-large"
#pragma comment(linker, "/STACK:171088640")
#include <stdio.h>
#include <iostream>
#include <iomanip> 
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <assert.h>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000007;
const long double EPS = 1e-6;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(1);

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
#endif

	const int n = 50;
	long long k, ans[51];
	scanf("%lld", &k);
	long long foo = (k + n - 1) / n;
	for (int i = 1; i <= n; ++i) {
		ans[i] = n - 1 + foo;
	}
	for (long long iter = 0; iter < foo*n - k; ++iter) {
		int pos = 1;
		for (int i = 2; i <= n; ++i) {
			if (ans[i] > ans[pos]) {
				pos = i;
			}
		}
		for (int i = 1; i <= n; ++i) {
			++ans[i];
		}
		ans[pos] -= n + 1;
	}
	printf("%d\n", n);
	for (int i = 1; i <= n; ++i) {
		printf("%lld ", ans[i]);
	}
	printf("\n");

	my_return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vi a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  ll t = 0;
  rep(i, m) t += b[i];
  int j = m;
  int ans = 0;
  rep(i, n+1) {
    while (t > k && j > 0) {
      --j;
      t -= b[j];
    }
    if (t > k) break;
    ans = max(ans, i+j);
    if (i == n) break;
    t += a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4820
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<int,int>> v(n);
        for(int i = 0; i < n; i++)  cin >> v[i].first >> v[i].second;
        sort(v.begin(), v.end());
        int sum = 0;
        for(int i = 0; i < n-1; i++)    sum += v[i].first;
        int ans = sum + v[n-1].first;
        for(int i = 0; i < n; i++)  ans += v[i].second;
        if(sum < v[n-1].first){
            int res = v[n-1].first - sum;
            bool dp[1001] = {};
            dp[0] = true;
            for(int i = 0; i < n-1; i++){
                for(int j = res; j >= v[i].second; j--){
                    dp[j] |= dp[j-v[i].second];
                }
            }
            int ma;
            for(ma = res; ma >= 0; ma--){
                if(dp[ma])  break;
            }
            cout << ans + res-ma << endl;
        }else{
            cout << ans << endl;
        }
    }
    return 0;
}


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

const int INF = 1<<30;

int main() 
{
    int n;
    cin >> n;
    vector<int> V(n);
    vector<int> C(n);
    rep(i,n) cin >> V[i];
    rep(i,n) cin >> C[i];

    vector<pair<int,int>> a;
    rep(i,n) {
        a.push_back(make_pair(V[i], C[i]));
    }

    int ans = -INF;
    rep(i,1<<n) {
        int totx = 0;
        int totc = 0;
        for (int j=0; j<n; j++) {
            if (i>>j&1) {
                totx += V[j];
                totc += C[j];
            }
        }
        ans = max(ans, totx-totc);
    }

    cout << ans << endl;   


    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    int factor_count = 0;
    for (int i = a; i <= b; i++) {
        if ((c % i) == 0) {
            factor_count++;
        }
    }
    std::cout << factor_count << std::endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int N;
vp pairs;

signed main(void) {
    cin>>N;
    vp ans;
    if (N%2==0) { //N偶数
        REP(i, 1, N/2) {
            pairs.pb(mp(i, N + 1 - i));
        }
        rep(i, pairs.size()) {
            rep(j, pairs.size()) {
                if (i==j) continue;
                if (pairs[i].fi < pairs[j].fi) ans.pb(mp(pairs[i].fi, pairs[j].fi));
                if (pairs[i].fi < pairs[j].se) ans.pb(mp(pairs[i].fi, pairs[j].se));
                if (pairs[i].se < pairs[j].fi) ans.pb(mp(pairs[i].se, pairs[j].fi));
                if (pairs[i].se < pairs[j].se) ans.pb(mp(pairs[i].se, pairs[j].se));
            }
        }
    } else { //N奇数
        REP(i, 1, N/2) {
            pairs.pb(mp(i, N - i));
        }
        rep(i, pairs.size()) {
            rep(j, pairs.size()) {
                if (i==j) continue;
                if (pairs[i].fi < pairs[j].fi) ans.pb(mp(pairs[i].fi, pairs[j].fi));
                if (pairs[i].fi < pairs[j].se) ans.pb(mp(pairs[i].fi, pairs[j].se));
                if (pairs[i].se < pairs[j].fi) ans.pb(mp(pairs[i].se, pairs[j].fi));
                if (pairs[i].se < pairs[j].se) ans.pb(mp(pairs[i].se, pairs[j].se));
            }
            ans.pb(mp(pairs[i].fi, N));
            ans.pb(mp(pairs[i].se, N));
        }
    }
    cout << ans.size() <<endl;
    for(auto e : ans) {
        cout << e.fi << " " << e.se << endl;
    }
    return 0;
}

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

int main()
{
	long long a,v,b,w;
	cin>>a>>v>>b>>w;
	long long t;
	cin>>t;

	long long dist = abs(a-b);
	if(dist==0)
	{
		printf("YES\n");
		return 0;
	}
	long long speed = v-w;
	if(speed*t<dist)
	{
		printf("NO\n");
	}
	else
	{
		printf("YES\n");
	}

	
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

ll to(ll in){
  ll ret=0;
  ll base=1;
  while(in){
    ll syo=in/-10;
    if(in<0 && syo*-10!=in)syo++;
    ll amari=in-syo*-10;
    ret+=base*amari;
    base*=10;
    in=syo;
  }
  return ret;
}


main(){

  ll n;
  while(cin>>n,n){
    cout<<to(n)<<endl;
  }
}

Measured memory_bytes: 0
#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSString*)stringFromStdIn; // 標準入力から NSString を得る
+(void)printf:(NSString*)format, ...; // 標準出力へ出力
@end

@implementation StdIO
+(NSString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    NSUInteger length = [result length];
    if (length >= 1 && [result characterAtIndex:length-1] == '\n') { // 入力末尾に改行文字があれば削除
        [result deleteCharactersInRange:NSMakeRange(length-1,1)];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat:format arguments:arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
    va_end(arguments);
}
@end
  
int main() {
    @autoreleasepool {
        NSString *input = [StdIO stringFromStdIn];
        NSArray *numbers = [(NSString*)[[input componentsSeparatedByString:@"\n"]
                                       objectAtIndex:1]
                            componentsSeparatedByString:@" "];
        NSInteger min = NSIntegerMax;
        for (NSNumber *number in numbers) {
            NSInteger i = [number integerValue];
            NSInteger count = 0;
            while (i%2 == 0) {
                i >>= 1;
                count++;
            }
            min = MIN(min, count);
        }
        [StdIO printf: @"%ld", min];
    }
    return 0;
}


Measured memory_bytes: 9492
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>

#define numof(array) (sizeof (array) / sizeof *(array))
using namespace std;

int A[10] = {};
int B[10] = {0};
int C[10] = {0};



bool check(void)
{
    for (int i = 1; B[i] != 0; i++) {
        if (B[i-1] > B[i]) return false;
    } 
    
    for (int i = 1; C[i] != 0; i++) {
        if (C[i-1] > C[i]) return false;
    } 

    return true;
}

bool dfs(int i, int b)
{
    if (i == 10) return check();

    //Bにいれる
    B[b] = A[i];
    if (dfs(i+1, b+1)) return true;
    B[b] = 0;

    //Cに入れる
    C[i-b] = A[i];
    if (dfs(i+1, b)) return true; 
    C[i-b] = 0;

    return false;
}

int main(void)
{
    int N;
    cin >> N;
    while (N--) {
        for (int i = 0; i < 10; i++) {
            cin >> A[i];
        }    
        if (dfs(0,0)) cout << "YES" << endl;
        else cout << "NO" << endl;

    }
	return 0;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

A, B = mi()

print(A / B)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}

const ll MOD = 1e9+7;

void solve(){
  string s; cin >> s;
  if(s == "RRR") {
    cout << 3 << endl;
    return ;
  }
  if(s == "SRR" || s == "RRS") cout << 2 << endl;
  else if(s == "RSR" || s == "SSR" ||s == "RSS" || s == "SRS") cout << 1 << endl;
  else cout << 0 << endl;

}

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


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
vector<ll> lun;
void dfs(ll i){
	if(i>3234566667){
		re;
	}
	lun.pb(i);
	dfs(i*10+i%10);
	if(i%10!=9){
		dfs(i*10+i%10+1);
	}
	if(i%10!=0){
		dfs(i*10+i%10-1);
	}
	re;
}
int main(){
	int k;
	cin>>k;
	for(int i=1;i<=9;i++){
		dfs(i);
	}
	sort(all(lun));
	cout<<lun[k-1];
	re 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N;
   cin >> N;
   vector<int> ans;
   if(N==3){
      cout << "2 5 63" << endl;
      return 0;
   }
   ll sum = 0;
   for(int j = 1; j <= N; j++){
      ans.push_back(2*j);
      sum += 2*j;
      if((N-j)%2==0 && N-j <= 5000 && sum%3==0){
         N-=j;
         break;
      } 
   }
   int t = 3;
   for(int j = 0 ; j < N; j++){
      ans.push_back(t);
      t+=6;
   }
   sort(ans.begin(),ans.end());
   for(int a: ans ) cout << a << " ";
   cout << endl;
   return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    fp(n <= m,"unsafe","safe");
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string s;
    cin>>s;
    int N = s.length();
    vector<int>cnt(26);
    ll ans = 1;
    for(int i=N-1;i>=0;i--){
        for(int j=0;j<26;j++){
            if(j != s[i] - 'a'){
                ans += cnt[j];
            }
        }
        cnt[s[i] - 'a']++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int[] T = new int[H];
		for(int i = 0; i < H; i++) {
			T[i] = sc.nextInt();
		}
		int M = sc.nextInt();
		int[][] P = new int[M][H];
		for(int i = 0; i < M; i++) {
			System.arraycopy(T, 0, P[i], 0, T.length);
		}
		int tmp = 0;
		int[] sum = new int[M];
		for(int i = 0; i < M; i++) {
			tmp = sc.nextInt();
			P[i][tmp-1] = sc.nextInt();
			for(int tmp1: P[i]) {
				sum[i] += tmp1;
			}
		}

		for(int i = 0; i < M; i++) {
			System.out.println(sum[i]);
		}

		}
}

Measured memory_bytes: 23892
#include  <bits/stdc++.h>
using namespace std;
//vector<int> vec(N,0);
int main() {
  string s;
  cin >>s;
  int N=s.size();
  int count=0;
  for(int i=0;i<N-1;i++){
    if(s.at(i) != s.at(i+1)){
      count++;
    }
  }
cout << count <<endl;
}

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

int main(void) {
    int N,M;cin>>N>>M;
    int A[N+1];
    A[0] = 0;
    for (int i = 1; i <= N; i++) cin>>A[i];
    for (int k = 1; k <= M; k++) {
        for (int i = 1; i <= N; i++) {
            if (i < N) {
                if (A[i] % k > A[i + 1] % k) swap(A[i],A[i+1]);
            }
        }
    }
    for (int i = 1; i <= N; i++) cout << A[i] << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define MOD 1000000007
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 3005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unordered_map<int,int> umii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int dp[MAXN][MAXN];
pii par[MAXN][MAXN];
bool match[MAXN][MAXN];
pair<int,pii> best;
string first,second,res;

int solve(int a, int b){
    if(a == -1 || b == -1) return 0;
    if(dp[a][b] != -1) return dp[a][b];
    int ans = 0;
    if(first[a] == second[b]){
        match[a][b] = true;
        par[a][b] = mp(a-1,b-1);
        ans = 1+solve(a-1,b-1);
    }else{
        int first = solve(a-1,b), second = solve(a,b-1);
        ans = max(first,second);
        if(first > second) par[a][b] = mp(a-1,b);
        else par[a][b] = mp(a,b-1);
    }
    best = max(best,mp(ans,mp(a,b)));
    return dp[a][b] = ans;
}

int main(){
    fastio; cin>>first>>second;
    memset(dp,-1,sizeof dp);
    memset(par,-1,sizeof par);
    solve(first.length()-1,second.length()-1);
    int a = best.second.first, b = best.second.second;
    while(a != -1 && b != -1){
        int na = par[a][b].first, nb = par[a][b].second;
        if(match[a][b]) res = string(1,first[a])+res;
        a = na, b = nb;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 115328
def com(N,K,mod):
    n=N
    K=min(K,N-K)
    k=K
    X=1  #分子
    Y=1  #分母
    for _ in range(K):
        X*=n
        X%=mod
        n-=1
    for _ in range(K):
        Y*=k
        Y%=mod
        k-=1
    Y=loop_pow(Y,mod-2,mod)  #Y**(mod-2) mod(mod)
    return X*Y%mod  #nCk mod(mod)

def loop_pow(x,n,mod):
    if n==0:
        return 1
    if n%2==0:
        t=loop_pow(x,n//2,mod)
        return (t*t)%mod
    return x*loop_pow(x,n-1,mod)%mod

def main():
    X,Y=map(int,input().split())
    if (X+Y)%3!=0:
        print(0)
    else:
        n=(2*Y-X)//3
        m=(2*X-Y)//3
        if n<0 or m<0:
            print(0)
        else:
            mod=10**9+7
            print(com(n+m,n,mod))

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
def acinput():
    return list(map(int, input().split(" ")))


N,K,Q=acinput()
a=[]
for i in range(Q):
    a.append(int(input()))

score=[K-Q for i in range(N)]

for i in range(Q):
    score[a[i]-1]+=1

for i in range(N):
    if score[i]<=0:
        print("No")
    else:
        print("Yes")



Measured memory_bytes: 11780
N = int(input())
d = [input() for i in range(N)]

d.sort(reverse = True) #降順にソート
counter = 0

for i in range(N):
	if  i < N-1 and d[i] > d[i+1]:
		counter += 1
	elif i == N-1:
		counter += 1

print(counter)

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

def gcd(x, y):
    x = abs(x)
    y = abs(y)

    if x < y:
        x, y = y, x

    while y:
        x, y = y, x%y
        
    return x

N = int(input())
seen = dict()
zeroes = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeroes += 1
        continue
    
    if a < 0 or a == 0 and b < 0:
        a, b = -a,-b
    if b <= 0:
        a, b = -b, a
        flip = 1
    else:
        flip = 0
    g = gcd(a,b)
    a//=g
    b//=g
    if (a,b) not in seen:
        seen[(a,b)] = [0,0]
    
    seen[(a,b)][flip] += 1

MOD = 10 ** 9 + 7
    
out = 1
for v in seen:
    a, b = seen[v]
    out *= (pow(2,a,MOD) + pow(2,b,MOD) - 1)
    out %= MOD
out -= 1

out += zeroes
out %= MOD
print(out)


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

double fx (double d, double x) 
{
	if (x == 0) return 0;
	else return d * x * x + fx(d, x - d);
}

int main(void)
{
	double d, x;
	while (cin >> d) {
		x = 600;
		printf("%.0f\n", fx(d, x - d));
	}
	
	return 0;
}

Measured memory_bytes: 1248
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll lcm(ll a, ll b){
	return (ll)((a / gcd(a, b)) * b);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	ll l = 1;
	rep(i, n){
		ll x;
		cin >> x;
		l = lcm(x, l);
	}
	cout << l << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
#include<numeric>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

int dist[550][550];
Int ans = 0;
bool done[550][550];
int xs[] = {0, 1, 0, -1};
int ys[] = {1, 0, -1, 0};
int n;

void bfs(int x, int y){
    deque<P> q;
    q.push_back(P(x,y));
    while(!q.empty()){
        P tmp = q.front();q.pop_front();
        int x = tmp.first, y = tmp.second;
        int d = dist[x][y];
        for(int dir = 0;dir < 4;dir++){
            int nx = x + xs[dir];
            int ny = y + ys[dir];
            if(nx < 0 || ny < 0 || nx >= n || ny >= n)continue;
            if(!done[nx][ny] && dist[nx][ny] > d + 1){
                q.push_back(P(nx,ny));
                dist[nx][ny] = d + 1;
            }
            if(done[nx][ny] && dist[nx][ny] > d){
                dist[nx][ny] = d;
                q.push_front(P(nx,ny));
            }
        }        
    }
}

int main(){

    cin >> n;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            dist[i][j] = min({i, j, n-1-i, n-1-j}) + 1;
        }
    }
    for(int i = 0;i < n * n;i++){
        int p;
        cin >> p;p--;
        int x = p / n, y = p % n;
        done[x][y] = true;
        ans += dist[x][y]-1;
        dist[x][y]--;
        done[x][y] = true;
        bfs(x,y);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6152
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	ll a,b,c; cin>>a>>b>>c;
	ll n; cin>>n;
	ll ans=0;
	rep(i,0,n+1){
		rep(j,0,n+1){
			ll k=a*i+b*j;
			if(n-k==0){
				ans++;
				//cout<<i<<" "<<j<<" "<<endl;
			}
			else if(n-k>=0 && (n-k)%c==0){
				ans++;
				//cout<<i<<" "<<j<<" "<<endl;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
	ll cnt=0;
	rep(i,0,n+1){
		rep(j,0,n+1){
			rep(k,0,n+1){
				if(a*i+b*j+c*k==n)cnt++;
			}
		}
	}
	//cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>

int main()
{
	unsigned int n;
	double x1,y1,x2,y2,x3,y3;
	double xp,yp,r;
	scanf("%d",&n);
	while(n--){
	scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
	xp=((y1-y3)*(y1*y1-y2*y2+x1*x1-x2*x2)-(y1-y2)*(y1*y1-y3*y3+x1*x1-x3*x3))/(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
	yp=((x1-x3)*(x1*x1-x2*x2+y1*y1-y2*y2)-(x1-x2)*(x1*x1-x3*x3+y1*y1-y3*y3))/(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
	r=sqrt((x1-xp)*(x1-xp)+(y1-yp)*(y1-yp));
	printf("%.3f %.3f %.3f\n", xp, yp, r);
	}
	return 0;
}

Measured memory_bytes: 656
#include <iostream>

using namespace std;

const int MAX = 1000000;
bool p[MAX];
int num[MAX];

void prepare() {
    for (int i=0; i<MAX; ++i) p[i] = true;
    p[0] = p[1] = false;
    for (int i=2; i*i<MAX; ++i) {
        if ( ! p[i]) continue;
        for (int j=i*i; j<MAX; j+=i) {
            p[j] = false;
        }
    }
    int sum = 0;
    for (int i=0; i<MAX; ++i) {
        if (p[i]) sum ++;
        num[i] = sum;
    }
}

int main() {
    prepare();
    int n;
    while (cin >> n) {
        cout << num[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 6044
#include <iostream>
#include <map>

using namespace std;

int main()
{
	map<int,int > m;

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

	if (m.count(1) && m.count(9) && m.count(7) && m.count(4)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
s = input()
t = input()

counta={}
countb={}

for i in s:
    if i in counta:
        counta[i] += 1
    else:
        counta[i] = 1

for y in t:
    if y in countb:
        countb[y] += 1
    else:
        countb[y] = 1

if sorted(counta.values())  == sorted(countb.values()):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3632
def check_paint(s,h,w):
    
    List = [s[h-1][w]
            ,s[h][w-1]
            ,s[h][w]
            ,s[h][w+1]
            ,s[h+1][w]]
    
    count = 0
    
    for i in range(5):
        if List[i]=="#":
            count+=1
            
    return count
            
H,W = map(int,input().split(" "))
Paint = [""]*(H+2)
#上下の場外
Paint[0] = "0"*(W+2)
Paint[-1] = "0"*(W+2)
for i in range(1,H+1):
    Paint[i] = "0"+input()+"0"

flag = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        # 空白箇所は無視
        if Paint[i][j]==".":
            continue
        else:
            c = check_paint(Paint,i,j)
            # 自分を含め上下左右で'#'が2つ以上あれば塗れる
            if c<2:
                # 塗れない場合はその時点で終了
                print("No")
                flag=1
                break
    if flag==1:
        break
        
if flag==0:
    print("Yes")

Measured memory_bytes: 3064