akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int L[300];
int N;

struct LCG {
    int val;
    int s,a,c;
    int m;
    LCG(int s=0,int a=0, int c=0, int m=1) :
        val(s), s(s),a(a),c(c), m(m) {}
    int next() {
        val = (val*a+c) % m;
        return val;
    }
    bool operator< (const LCG& l) const {
        if(this->s < l.s) return true;
        else if(this->s > l.s) return false;
        else {
            if(this->a < l.a) return true;
            else if(this->a > l.a) return false;
            else {
                if(this->c < l.c) return true;
                else if(this->c >= l.c) return false;
            }
        }
        return false;
        /*
        return
            this->s < l.s ||
            this->a < l.a ||
            this->c < l.c;
*/
    }
};


double func(int s,int a, int c) {
    int ary[256]={};
    double res=0.0;
    LCG lcg(s,a,c,256);

    rep(i,N) {
        ary[(L[i]+lcg.next())%256]++;
    }

    rep(i,256) {
        if(ary[i]!=0) res+=(1.0*ary[i]/N)*log2(1.0*ary[i]/N);
    }
    return abs(res);
}

void solve() {
    double mini=INF;
    vector<pair<double,LCG> > ans;
    rep(i,N) cin>>L[i];
    rep(s,16) rep(a,16) rep(c,16) {
        double t = func(s,a,c);
        // if(t==0) printf("%f : %d,%d,%d\n", t, s, a, c);
        ans.pb(mp(t,LCG(s,a,c)));
    }
    sort(all(ans));
    cout<<ans[0].sc.s<<" "<<ans[0].sc.a<<" "<<ans[0].sc.c<<endl;
}

int main() {
    while(cin>>N) {
        if(N==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1352
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

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

		int inputNum = sc.nextInt();

		for (int i = 0; i < inputNum; i++) {

			while (sc.hasNext()) {
				BigInteger a = sc.nextBigInteger();
				BigInteger b = sc.nextBigInteger();
				BigInteger sum = a.add(b);
				// 80?????\?????????80????????\??????overflow ??¨??¨????????????
				if (sum.toString().length() > 80) {
					System.out.println("overflow");
				} else {
					System.out.println(sum);
				}
			}
		}

	}

}

Measured memory_bytes: 26788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String line = br.readLine();
            final int index = line.indexOf(" ");
            final int x = Integer.parseInt(line.substring(0, index));
            final int y = Integer.parseInt(line.substring(index+1, line.length()));
            if (x == 0 && y == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 22788
function main(input) {
  var nums = input.split('\n')[1].split(' ').map((n) => parseInt(n));
  var cnt = 0;
  while (nums.every((n) => n%2 === 0)) {
    ++cnt;
    nums = nums.map((n) => n/2);
  }
  console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
#何も考えずに全探索したらO(N^2)で間に合わない

N, K = map(int, input().split())
S = list(input())

#左端の文字は前の文字と変わった直後のみが候補
lst = [0]
for i in range(0, N-1):
    if S[i] != S[i+1]:
        lst += [i+1]

ans = 0
roop = len(lst)
lst = lst + [N]*(N+10**5)
# print (lst)
# print ('roop', roop)
for i in range(roop):
    if S[lst[i]] == '0':
        # print ('A', lst[i+2*K]- lst[i])
        ans = max(ans, lst[i+2*K]- lst[i])
    if S[lst[i]] == '1':
        # print ('B', lst[i+2*K +1]- lst[i])
        ans = max(ans, lst[i+2*K +1]- lst[i])
print (ans)

Measured memory_bytes: 11688
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n;
vector<int> d;

void input(){
    cin >> n;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        d.push_back(x);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    cout << d.size() << endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vll divisor(ll x){
    vll res;
    for(ll i = 1; i * i <= x; i++){
        if(x%i == 0) {
            res.pb(i);
            if(i * i != x) res.pb(x/i);
        }
    }
    return res;
}

void Main(){
    const ll INF = 1e18;
    int n, k; cin >> n >> k;
    vi a(n);
    ll tot = 0;
    rep(i, n){
        cin >> a[i];
        tot += a[i];
    }
    vll d = divisor(tot);
    sort(rall(d));
    for(ll rem : d) {
        // cout << "[" << rem << "]" << endl;
        vll v;
        rep(i, n){
            v.pb(a[i] % rem);
        }
        sort(all(v));
        vll l(n+1), r(n+1);
        rep(i, n) {
            l[i+1] = l[i] + v[i];
            r[i+1] = r[i] + (rem - v[n-1-i]);
        }
        /*
        rep(i, n){
            cout << v[i] << " ";
        }
        cout << endl;
        rep(i, n+1){
            cout << l[i] << " ";
        }
        cout << endl;
        rep(i, n+1){
            cout << r[i] << " ";
        }
        cout << endl;
        //*/
        ll ans = INF;
        rep(i, n+1){
            ll tmp = (l[i] == r[n-i]) ? l[i] : max(l[i], r[n-i]);
            ans = min(ans, tmp);
        }
        // cout << ans << endl;
        if(ans <= k) {
            cout << rem << endl;
            return;
        }
    }
    
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <cstring>
#include <climits>
using namespace std;

int memoTable[100000];

int minCost(int index, int* stoneHeight, int nStones){

    if(index == nStones-1){
        return 0;
    }

    if(memoTable[index] != -1){
        return memoTable[index];
    }


    int op1 = minCost(index+1, stoneHeight, nStones)  + abs(stoneHeight[index] -  stoneHeight[index+1]);
    int op2 = INT_MAX;
    if(index+2 < nStones){
        op2 = minCost(index+2, stoneHeight, nStones)  + abs(stoneHeight[index] -  stoneHeight[index+2]);
    }

    memoTable[index] = min(op1, op2);
    return memoTable[index];
}

int main(){

    int nStones;
    cin >> nStones;

    int stoneHeight[100000];
    for(int i=0; i<nStones; ++i){
        cin >> stoneHeight[i];
    }

    memset(memoTable, -1, sizeof(int) * 100000);
    cout<<minCost(0, stoneHeight, nStones);

    return 0;
}

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

int node[1 << 21] = {};
int SIZE;
void segtree(int size) {
  SIZE = 1;
  while(SIZE <= size) SIZE <<= 1;
}
inline int parent(int i) {return i ? (i - 1) >> 1 : 0;}
inline int lchild(int i) {return (i << 1) + 1;}
inline int rchild(int i) {return (i << 1) + 2;}
int add(int i, int v) {
  i += SIZE - 1;
  node[i] += v;
  while(i = parent(i)) node[i] = max(node[lchild(i)], node[rchild(i)]);
}
int find(int a, int b, int i = 0, int l = 0, int r = SIZE) {
  if(b <= l || r <= a) return 0;
  if(a <= l && r <= b) return node[i];
  return max(find(a, b, lchild(i), l, (l+r)/2), find(a, b, rchild(i), (l+r)/2, r));
}

int N, M;
int C[1000000];

int L[2000000];
int be[2000000];
int en[2000000];
void migrant(auto flag) {
  for(auto i = 0; i < 2 * N; ++i) {
    L[i] = 0;
    en[i] = be[i];
  }
  if(flag) L[en[C[0]]++] = C[0];
  for(auto i = 1 + flag; i < N; i += 2) {
    L[en[C[i-1]]++] = C[i-1];
    L[en[C[i-1]]++] = C[i];
    if(C[i] == C[i-1]) continue;
    L[en[C[i]]++] = C[i-1];
    L[en[C[i]]++] = C[i];
  }
  if((N - flag) & 1) L[en[C[N-1]]++] = C[N-1];
}

vector<int> solve() {
  vector<int> res(M, 1e9);

  segtree(M);
  for(auto i = 0; i < N; ++i) add(C[i], 1);
  for(auto i = 1; i < M; ++i) be[i] = be[i-1] + 2 * find(i-1, i);

  for(auto i: {0, 1}) {
    migrant(i);
    for(auto c = 0; c < M; ++c) {
      int cost = (en[c] - be[c]) - find(c, c+1);
      for(auto i = be[c]; i < en[c]; ++i) add(L[i], -1);
      cost += N - (en[c] - be[c]) - find(0, M);
      for(auto i = be[c]; i < en[c]; ++i) add(L[i], 1);
      res[c] = min(res[c], cost);
    }
  }

  return res;
}

int main() {
  cin >> N >> M;
  for(auto i = 0; i < N; ++i) cin >> C[i];
  for(auto i = 0; i < N; ++i) --C[i];

  for(auto i: solve()) cout << i << "\n";
}

Measured memory_bytes: 38008
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pt;

#define fi first
#define se second
#define lson (p<<1)+1
#define rson (p<<1)+2
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll n;
string s, s1, r;

int main () {
    fastIO;
    cin >> n >> s >> s1;
    r = "";
    for(li i = 0; i < n; i ++) {
        r = r + s[i] + s1[i];
    }
    cout << r;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a < b){
		if (b < c)
			printf("Yes\n");
		else
			printf("No\n");
	}
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll h,w,a,b;
  cin >> h >> w >> a >> b;
  cout << (h-a)*(w-b) << endl;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]

nodes = {}

for a, b in ab:
    if a in nodes:
        nodes[a].append(b)
    else:
        nodes[a] = [b]
    if b in nodes:
        nodes[b].append(a)
    else:
        nodes[b] = [a]

def dfs(s, nodes, visited):
    visited[s-1] = True
    q = []
    q.extend(nodes[s])
    
    while q:
        v = q.pop()
        if visited[v-1]:
            continue
        else:
            dfs(v, nodes, visited)
    
    return all(visited)

ans = 0

for a,b in ab:
    nodes[a].remove(b)
    nodes[b].remove(a)

    visited = [False for _ in range(N)]
    if not dfs(1,nodes,visited):
        ans += 1

    if a in nodes:
        nodes[a].append(b)
    else:
        nodes[a] = [b]
    if b in nodes:
        nodes[b].append(a)
    else:
        nodes[b] = [a]
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
int main(){ 
int a,b;
cin>>a>>b;
if((a==1&&b==2)||(a==2&&b==1))
cout<<3<<endl;
else if((a==2&&b==3)||(a==3&&b==2))
cout<<1<<endl;
else
cout<<2<<endl;  
}


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

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main()
{
	int N;
	cin >> N;
	vector<int>U(N), D(N);
	for (int i = 0; i < N; i++) {
		cin >> U[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> D[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int solve = 0;
		for (int j = 0; j < N; j++) {
			if (j <= i) {
				solve += U[j];
			}
			if (j >= i) {
				solve += D[j];
			}
		}
		ans = max(ans, solve);
	}
	cout << ans << endl;
}



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

typedef long long ll;

int main() {
    int d; cin >> d;
    ll g; cin >> g;
    g/=100;
    vector<pair<ll, ll>> info(d);
    for (int i=0; i<d; ++i) {
        cin >> info[i].first >> info[i].second;
    }
    ll ans=1e9;
    for (ll i=0; i<(1<<d); ++i) {
        ll cur=0;
        ll c=0;
        ll largest_unsolved=0;
        for (ll k=0; k<d; ++k) {
            if ((i>>k)&1) {
                cur+=(k+1)*info[k].first+info[k].second/100;
                c+=info[k].first;
            } else {
                largest_unsolved=k+1;
            }
        }
        ll rest=g-cur;
        if (rest<=0) {
            ans=min(ans, c);
            continue;
        }
        ll cnt=(rest+largest_unsolved-1)/largest_unsolved;
        if (cnt<info[largest_unsolved-1].first) {
            c+=cnt;
            ans=min(ans, c);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std; 
typedef pair<int,int> pii;
int square(int x) {
  return x*x;
}
bool cmp(const pii &a, const pii &b) {
  const int sqa = square(a.first)+square(a.second);
  const int sqb = square(b.first)+square(b.second);
  if (sqa != sqb) return (sqa < sqb);
  return (a.first < b.first);
}
int main() {
  vector<pii> memo;
  for (int i=0;i<150;i++) {
    for (int j=0;j<i;j++) {
      memo.push_back(pii(j+1, i+1));
    }
  }
  sort(memo.begin(), memo.end(), cmp);
  while (true) {
    int h, w;
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0) break;
    vector<pii>::iterator p = find(memo.begin(), memo.end(), pii(h, w))+1;
    printf("%d %d\n", p->first, p->second);
  }
}


Measured memory_bytes: 2776
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
vi pre(N), prn(N);
signed main(){
    speed;
    int t;
    cin>>t;
    prn[1]=1;
    set<int>s;
    map<int, int>pos;
    int id=0;
    for(int i = 2; i <= N; i++){
        pre[i]+=pre[i-1];
        if(!prn[i]){
            if(i*1ll*i<=N){
                for(int j = i*i; j <= N; j+=i)prn[j]++;
            }
            int d = (i+1)/2;
            if(!prn[d])pre[i]++;
        }
    }
    while(t--){
        int l, r;
        cin>>l>>r;
        cout<<pre[r]-pre[l-1]<<"\n";
    }
}


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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
ll inf = 1e18;
double a[3003];
double dp[3003][3003];
ll n;
double fun(ll tot, ll h){
    double &ans = dp[tot][h];
    if(ans!=-1){
        //cout<<"F\n";
        return ans;
    }
    ans = 0.0;
    if(tot>=n){
        if(h>tot/2){
    //        cout<<"F "<<tot<<" "<<h<<"->"<<ans<<endl<<endl;
            return ans =1.0;
        }
        else
            return ans =0.0;
    }

    ans = a[tot+1]*fun(tot+1,h+1);
    //cout<<tot<<" "<<h<<"->"<<ans<<endl;
    ans += (1-a[tot+1])*fun(tot+1,h);
    //cout<<"_"<<tot<<" "<<h<<"->"<<ans<<endl;
    return ans;
}
int main(){
    fast;
    //cout<<(1>0)*dp[-1][-1];
    cin>>n;
    for(ll i=1;i<=n;++i){
        cin>>a[i];
    }
    //memset(dp,-1.0,sizeof(dp));
    for(ll i=0;i<3003;++i){
        for(ll j=0;j<3003;++j){
            dp[i][j] = -1.00;
        }    
    }
    //dp[0][0] = 1.0;
    /*for(ll i=0;i<=n;++i){
        for(ll j=0;j<=n-i;++j){
            //dp[i+1][j] = a[i]*dp[i][j] + (j-1>=0)?(1-a[i])*dp[i+1][j-1]:0.0;
            //dp[i][j+1] = (1 - a[i])*dp[i][j] + (i-1>=0)?a[i]*dp[i-1][j+1]:0.0;
           
            //cout<<i+1<<" "<<j<<endl<<i<<" "<<j+1<<endl;

        }
    }*/
    
    double ans = fun(0,0);
    cout<<fixed<<setprecision(9)<<ans;
    return 0;
}










Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

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

    

    cout << 180*(n-2)<< endl;

}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

X,A,B = map(int,input().split())

if B-A <= 0:
	print('delicious')
elif B-A <= X:
	print('safe')
else:
	print('dangerous')

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  while (!s.empty()) {
	s.pop_back();
	string t = s.substr(0, s.size() / 2);
	string p = s.substr(s.size() / 2 , s.size() - 1);
	if ( t ==p && s.size()%2 == 0) {
	  cout << s.size() << endl;
	  return 0;
	}
  }
  cout << 0 << endl;
  return 0;
}



Measured memory_bytes: 256
package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n, t, a int
	fmt.Scan(&n, &t, &a)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var x int
	min := 1000000000
	minIndex := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		x, _ = strconv.Atoi(sc.Text())
		if v := abs(a*1000 - t*1000 + x*6); v < min {
			min = v
			minIndex = i + 1
		}
	}
	fmt.Println(minIndex)
}


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




int main(){
  int n;
  cin >> n;
  vector<vector<int> > G(n, vector<int>(n,0));
  for (int i=0;i<n;i++){
    int u,k;
    cin >> u >> k;
    for (int j=0;j<k;j++){
      int v;
      cin >> v;
      G[u-1][v-1] = 1;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j)  cout << " ";
      cout << G[i][j];
    }
    cout << endl;
  }
}


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

int main() {
    map<int,int> cnts;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int a_i; cin >> a_i;
        if (cnts.count(a_i)) cnts[a_i]++;
        else cnts[a_i] = 1;
    }

    int ans = 0;
    for (auto it = cnts.begin(); it != cnts.end(); it++) {
        int num = it->second;
        if (it != cnts.begin() && prev(it)->first+1 == it->first)
            num += prev(it)->second;
        if (next(it) != cnts.end() && next(it)->first-1 == it->first)
            num += next(it)->second;
        ans = max(num, ans);
    }
    cout << ans << endl;
}


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

import sys
import os
import math

def cross(a, b):
    ax = a[0]
    ay = a[1]
    bx = b[0]
    by = b[1]
    return ax * by - ay * bx


for s in sys.stdin:
    s = s.strip()
    ax, ay, bx, by, cx, cy, px, py = map(float, s.split())
    # point A, B, C, P
    AP = (px - ax, py - ay)
    BP = (px - bx, py - by)
    CP = (px - cx, py - cy)

    BA = (ax - bx, ay - by)
    AC = (cx - ax, cy - ay)
    CB = (bx - cx, by - cy)

    v0 = cross(BP, BA)
    v1 = cross(CP, CB)
    v2 = cross(AP, AC)

    if v0 > 0 and v1 > 0 and v2 > 0:
        print('YES')
    elif v0 < 0 and v1 < 0 and v2 < 0:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7516
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 507;
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    cout << n + n*n + n*n*n;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int a, b;
int main() {
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int N,max=0;
    int i,j,k=-1;
    int sum[120];
    memset(sum,0,sizeof(sum));
    int a[2][120];
    memset(a,0,sizeof(a));
    scanf("%d",&N);
    for(i=0;i<2;i++)
        for(j=0;j<N;j++)
        scanf("%d",&a[i][j]);
        for(i=0;i<N;i++)
        {
            k+=1;
            for(j=0;j<=i;j++)
            sum[k]+=a[0][j];
        }
        k=-1;
        for(i=0;i<N;i++)
        {
            k+=1;
            for(j=i;j<N;j++)
                sum[k]+=a[1][j];
        }
        max=sum[0];
        for(i=0;i<N;i++)
            if(max<sum[i])
            max=sum[i];
        printf("%d",max);
    return 0;
}


Measured memory_bytes: 128
import typing
class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))
    
n, m = map(int, input().split())
dsu = DSU(n)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    dsu.merge(a, b)

print(len(dsu.groups())-1)

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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var cards = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
            cards = cards.OrderByDescending(s => s).ToList();

            int alice = 0;
            int bob = 0;
            for (int i = 0; i < N; i++)
            {
                if (i % 2 == 0) alice += cards[i];
                else bob += cards[i];
            }
            Console.WriteLine(alice - bob);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int res=0;
    for(i=0;i<n;i++)
    {
        if(a[i]-a[i+1]==0)
        {
            res=1;
            break;
        }
    }
    if(res==0)
        cout<<"YES";
    if(res==1)
        cout<<"NO";

}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
#define INF (1 <<29)
int N, M, R;
int d[201][201];
int r[9];
int A, B, C;
int res;
bool used[9];

void dfs(int c, int las, int dist)
{
	if (c == R + 1) {
		if (res > dist) res = dist;
		return;
	}
	for (int i = 1; i <= R; i++) if (!used[i]) {
		used[i] = true;
		if (las == -1) dfs(c + 1, i, 0);
		else dfs(c + 1, i, dist + d[r[las]][r[i]]);
		used[i] = false;
	}
}
int main()
{
	scanf(" %d %d %d ", &N, &M, &R);
	for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) if (i != j) d[i][j] = INF;
	for (int i = 1; i <= R; i++) scanf(" %d ", &r[i]);
	for (int i = 1; i <= M; i++) {
		scanf(" %d %d %d ", &A, &B, &C);
		if (d[A][B] > C) d[A][B] = d[B][A] = C;
	}
	for (int k = 1; k <= N; k++)
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++)
				if (d[i][j] > d[i][k] + d[k][j])
					d[i][j] = d[i][k] + d[k][j];
	res = INF;
	dfs(1, -1, 0);
	printf(" %d \n ", res);
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll A[3];
	ll ans = 0;

	rep(i, 3) cin >> A[i];

	if (A[0] % 2 == 0 || A[1] % 2 == 0 || A[2] % 2 == 0) ans = 0;
	else {
		sort(A, A + 3);
		ans = A[0] * A[1];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
#define maxn 0x3f3f3f3f
int main()
    {
        int a,b,n;
        while (~scanf("%d",&n))
            {
                int ans=maxn;
                for (int i=1;i<n;i++)
                    {
                        int res=0;
                        a=i;
                        b=n-i;
                        while (a)
                            {
                                res+=a%10;
                                a/=10;
                            }
                        while (b)
                            {
                                res+=b%10;
                                b/=10;
                            }
                        ans=min(res,ans);
                    }
                printf("%d\n",ans);
            }
        return 0;
    }


Measured memory_bytes: 128
#include <stdio.h>
int main(){
  int a,b,c,n,res,x;
  res=0;

  for(;;){
    scanf("%d%d",&n,&x);
    if(n==0&&x==0){break;}

    for(a=1;a<=n;a++){

      for(b=a+1;b<=n;b++){
	
	for(c=b+1;c<=n;c++){
	  if(a+b+c==x){res+=1;}    
	}
      }
    }
    
    printf("%d\n",res);
    res=0;
  }
  return 0;
}  

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  string s;
  cin>>s;
  for(int i=0;i<s.length()-1;i++){
  	for(int j=i;j<s.length();j++){
  		string test = s;
  		test.erase(test.begin()+i,test.begin()+j);
  		if(test=="keyence"){
  			cout<<"YES"<<endl;
  			return 0;
  		}
  	}
  }
  cout<<"NO"<<endl;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<61)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int W, a, b;
  cin >> W >> a >> b;

  if ((a <= b && b <= a + W) || (b <= a && a <= b + W)) {
    cout << 0 << endl;
    return 0;
  }

  int d1 = abs(b-a-W);
  int d2 = abs(a-b-W);

  if (d1 > d2) cout << d2 << endl;
  else cout << d1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;
// 変数初期化
vector<ll> bsv; // binary_search用のvector
ll a,b,c,n,m;
typedef pair<ll, ll> Pll;
vector<Pll> facts; // 素因数分解の結果格納用(基数:乗数)
vector<vector<ll> > bit_search_v; //nit全探索の結果格納用

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (bsv[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(int key) {
    int ng = -1;
    int ok = (ll)bsv.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    // OK(key以上となる)のindex番号を返す
    return ok;
}

// 最大公約数
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

// 最小公倍数
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

//　素因数分解
void prime_fact(ll target){
    ll base=2, exp=0;
    while (base*base<=target) {
        while (target%base==0) {
            target /= base; exp++;
        }
        if (exp>0) {
            facts.push_back(make_pair(base, exp));
        }
        base++; exp=0;
    }
    if (target>1) facts.push_back(make_pair(target,1));
}
// prime_factの結果の確認用
void print_facts(){
    for (int i=0; i<facts.size(); i++) {
        cout << facts[i].first << " " << facts[i].second << endl;
    }
}

// bit全探索
void bit_search(ll target){
    for (ll i=0; i<(1<<target); ++i) {
        if (i==0) continue;
        vector<ll> v;
        for (ll j=0; j<target; ++j) {
            if (i&(1<<j)) v.push_back(j);
            if (i&(1<<j)) cout << i << "  :  " << j << endl;
        }
        bit_search_v.push_back(v);
    }
}
// bit全探索の結果確認用
void print_bit_search(){
    for (ll i=0; i<bit_search_v.size(); ++i) {
        for (ll j=0; j<bit_search_v[i].size(); ++j) {
            cout << bit_search_v[i][j] << " ";
        }
        cout << endl;
    }
}



int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> a >> b >> c;

    int k;
    cin >> k;

    if(k <= a){
        cout << k << endl;
    }else if (k <= a+b){
        cout << a << endl;
    }else if(k > a+b) {
        cout << a-(k-(a+b)) << endl;
    }

    

    return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 2e5 + 10;
vector<int> E[max_N], E2[max_N];
int vis[max_N], vis2[max_N];
int comp[max_N], comp2[max_N];
int done[max_N], ans[max_N];
set<int> comps[max_N], comps2[max_N];

void dfs(vector<int> E[max_N], int comp[max_N], int vis[max_N], int node, int cid);

int main()
{
	fast_cin();
	int N, K, L;
	cin >> N >> K >> L;
	for (int i = 1; i <= K; ++i) {
		int x, y;
		cin >> x >> y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	int cid = 1;
	for (int i = 1; i <= N; ++i) {
		if (!vis[i]) {
			dfs(E, comp, vis, i, cid++);
		}
		comps[comp[i]].insert(i);
	}
	for (int i = 1; i <= L; ++i) {
		int x, y;
		cin >> x >> y;
		E2[x].push_back(y);
		E2[y].push_back(x);
	}
	cid = 1;
	for (int i = 1; i <= N; ++i) {
		if (!vis2[i]) {
			dfs(E2, comp2, vis2, i, cid++);
		}
		comps2[comp2[i]].insert(i);
	}
	for (int i = 1; i <= N; ++i) {
		if (!done[i]) {
			map< int, int > cnt;
			for (auto &x : comps[comp[i]]) {
				cnt[comp2[x]]++;
			}
			for (auto &x : comps[comp[i]]) {
				done[x] = 1;
				ans[x] = cnt[comp2[x]];
			}
		}
		cout << ans[i] << ' ';
	}
	cout << endl;
}

void dfs(vector<int> E[max_N], int comp[max_N], int vis[max_N], int node, int cid)
{
	vis[node] = 1;
	comp[node] = cid;
	for (auto &v : E[node]) {
		if (!vis[v]) {
			dfs(E, comp, vis, v, cid);
		}
	}
}


Measured memory_bytes: 60160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int N;
Int C, X[100050], V[100050], M[100050];

Int solve() {
  Int res = 0, cal = 0;
  for (int i = 0; i < N; ++i) {
    cal += V[i];
    M[i] = cal - X[i];
    chmax(res, M[i]);
  }
  for (int i = 1; i < N; ++i) {
    chmax(M[i], M[i - 1]);
  }

  cal = 0;
  for (int i = N - 1; i > 0; --i) {
    cal += V[i];
    chmax(res, cal - 2 * (C - X[i]) + M[i - 1]);
  }

  return res;
}

int main() {
  N = in();
  C = lin();
  for (int i = 0; i < N; ++i) {
    X[i] = lin();
    V[i] = lin();
  }
  
  Int res = 0;
  chmax(res, solve());
  
  for (int i = 0; i < N; ++i) {
    X[i] = C - X[i];
  }
  reverse(X, X + N);
  reverse(V, V + N);
  chmax(res, solve());

  printf("%lld\n", res);

  return 0;
}

Measured memory_bytes: 2560
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
#define DEBUG_VIS(x) cerr<<"vis "<<x<<endl;
#define DEBUG_REACH cerr<<"reach here"<<endl;
#define DEBUG_SEQ(x) cerr<<x<<" ";
#define SET_ZERO(x) memset(x,0,sizeof(x));
#define SET_NEGONE(x) memset(x,-1,sizeof(x));
#define SET_INF(x) memset(x,127,sizeof(x));
#define SET_NEGINF(x) memset(x,128,sizeof(x));
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
typedef unsigned int uint;
const int maxn = 4e3 + 10;
template <class T> T mymin(const T a,const T b){return a < b ? a : b;}
template <class T> T mymax(const T a,const T b){return a > b ? a : b;}
int N,dp[maxn][maxn],costb[maxn][maxn],costw[maxn][maxn];
int ball[maxn][2],pos[maxn][maxn];

int main(){
    FAST_IO
    cin>>N;
    N *= 2;
    for(int i = 1; i <= N; i++){
        char c;
        int id;
        cin>>c>>id;
        ball[i][0] = (c == 'B');
        ball[i][1] = id;
        pos[ball[i][0]][ball[i][1]] = i;
    }
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= N / 2; j++){
            costb[i][j] = costb[i - 1][j];
            costw[i][j] = costw[i - 1][j];
            if(ball[i - 1][1] > j) ball[i - 1][0] == 0 ? costw[i][j]++ : costb[i][j]++;
        }
    }
    SET_INF(dp);
    dp[0][0] = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            int u = pos[0][i + 1],v = pos[1][j + 1];
            dp[i + 1][j] = min(dp[i + 1][j],dp[i][j] + costw[u][i + 1] + costb[u][j]);
            dp[i][j + 1] = min(dp[i][j + 1],dp[i][j] + costw[v][i] + costb[v][j + 1]);
        }
    }
    cout<<dp[N][N]<<endl;
    return 0;
}


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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int n;
  long long int r = 0;
  int d[50];
  cin >> n;
  rep(i, n) cin >> d[i];

  rep(i, n) {
    repi(j, i+1, n) {
      r += d[i] * d[j];
    }
  }

  cout << r << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._
object Main extends App {
  val n = readInt()
  var a, b = new Array[Int](n)
  for (i <- Range(0, n)) {
    val k = readLine().split(" ").map(_.toInt)
    a(i) = k(0)
    b(i) = k(1)
  }
  a = a.sorted
  b = b.sorted
  if (n % 2 == 1) {
    println(b(n / 2) - a(n / 2) + 1)
  } else {
    println(b(n / 2) + b(n / 2 - 1) - a(n / 2) - a(n / 2 - 1) + 1)
  }
}


Measured memory_bytes: 60432
import java.util.Scanner;

public class Main {

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

        final char[] S = sc.next().toCharArray();

        if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
            System.out.println("Bad");
        } else {
            System.out.println("Good");
        }
    }
}


Measured memory_bytes: 21588
#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(string L) {
    vector<ll> answers(100002);
    answers[0] = 1;
    answers[1] = 3;
    REP(i,2,100003) {
        answers[i] = answers[i-1] * 3 % MOD;
    }

    ll answer = 0;
    ll doubles = 1;
    REP(i,0,L.size()) {
        if (L[i] == '1') {
            const int digitIndex = L.size()-i;
            answer = (answer + answers[digitIndex-1] * doubles) % MOD;
            doubles = doubles * 2 % MOD;
        }
    }
    answer = (answer + doubles) % MOD;

	stringstream ss;
    ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    string L;
    cin >> L;
    
    solve(L);

    return 0;
}



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

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
ll gcd(ll a, ll b) {
    if(a < b)
        gcd(b, a);
    ll r = 1;
    while(r != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll sign(ll n) {
    if(n >= 0) {
        return 1;
    } else {
        return -1;
    }
}
int main() {
    int n;
    cin >> n;
    map<pair<ll, ll>, ll> cnt;
    for(int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) {
            cnt[make_pair(0, 0)]++;
        } else if(a == 0 && b != 0) {
            cnt[make_pair(0, 1)]++;
        } else if(a != 0 && b == 0) {
            cnt[make_pair(1, 0)]++;
        } else {
            ll g = gcd(abs(a), abs(b));
            ll sig = sign(a)*sign(b);
            cnt[make_pair(sig * abs(a) / g, abs(b) / g)]++;
        }
    }
    ll ans = 1;
    for(auto e : cnt) {
        if(e.second == 0) {
            continue;
        }
        if(e.first == make_pair(0LL, 0LL)) {
            continue;
        }
        pair<ll,ll> ort;
        if(e.first == make_pair(0LL, 1LL)) {
            ort = make_pair(1, 0);
        } else if(e.first == make_pair(1LL, 0LL)) {
            ort = make_pair(0, 1);
        } else {
            ort = make_pair(-sign(e.first.first) * abs(e.first.second),
                            abs(e.first.first));
            ;
        }
        ans *= modpow(2, e.second) + modpow(2, cnt[ort]) - 1;
        ans %= MOD;
        cnt[ort] = 0;
        cnt[e.first] = 0;
    }
    cout << (cnt[make_pair(0, 0)] + ans - 1 + MOD) % MOD << endl;
}


Measured memory_bytes: 28532
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

int vector_finder(std::vector<char> vec, char char_n) {
    auto itr = std::find(vec.begin(), vec.end(), char_n);
    size_t index = std::distance(vec.begin(), itr);
    if (index != vec.size()) {  // 発見できたとき
        return 1;
    } else {  // 発見できなかったとき
        return 0;
    }
}

int counter = 0;
int dfs(ll current, char num, int N) {
    string current_str = to_string(current);
    int len = to_string(current).length();
    vector<char> v(len);
    rep(i, len) { v[i] = current_str[i]; }
    v.push_back(num);

    string s;
    rep(i, v.size()) {
        if (v[i] != '\0') {  //空文字判定
            s += v[i];
        }
    }
    current = stol(s);
    if (current > N) {
        return 0;
    }

    if (vector_finder(v, '3') + vector_finder(v, '5') + vector_finder(v, '7') ==
        3) {
        counter++;
    }
    debug(current, v, s, current, counter);
    dfs(current, '3', N);
    dfs(current, '5', N);
    dfs(current, '7', N);
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    ll cand[3]={3,5,7};
    rep(i, 3){
        rep(j, 3){
            dfs(cand[i], (char)cand[j]+'0', N);
        }
    }
    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
char s[maxn],buf[5];
int q;
vector<char> f[2];
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	scanf("%d",&q);
	int bg=0,ed=1;
	while(q--)
	{
		int t;
		scanf("%d",&t);
		if(t==1)
		{
			swap(bg,ed);
		}
		else
		{
			int ff;
			scanf("%d",&ff);
			scanf("%s",buf);
			if(ff==1)f[bg].push_back(buf[0]);
			else f[ed].push_back(buf[0]);
		}
	}
	if(bg==1)
	{
		reverse(s,s+n);
	}
	reverse(f[bg].begin(),f[bg].end());
	for(int i=0;i<f[bg].size();i++)printf("%c",f[bg][i]);
	printf("%s",s);
	for(int i=0;i<f[ed].size();i++)printf("%c",f[ed][i]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(x,y) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;
typedef pair<int, int> P;

int ans[1000] = {};

int main() {
	FAST;

	int N;

	cin >> N;

	vector<int> f, s;
	int tmp = 0;
	while (tmp<=100) {
		f.push_back(tmp);
		// cout << tmp << "\n";
		tmp += 4;
	}
	tmp=0;
	while (tmp<=100) {
		s.push_back(tmp);
		// cout << tmp << "\n";
		tmp+=7;
	}

	rep(i, f.size()) {
		rep(j, s.size()) {
			ans[f[i]+s[j]] = 1;
		}
	}

	if (ans[N] == 1) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
l = [0 for i in range(0, 201)]

for i in range(1, 201):
    for j in range(i, 201):
        if j/i == int(j/ i):
            l[j] += 1

l = np.array(l[1:n+1:2])>=8
print(sum(l))

Measured memory_bytes: 12496
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M);
    for(int i = 0; i < M; i++){
        cin >> L.at(i) >> R.at(i);
    }
    sort(L.begin(), L.end());
    sort(R.begin(), R.end());
    if(R.at(0) - L.at(M - 1) + 1 > 0){
        cout << R.at(0) - L.at(M - 1) + 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;

    priority_queue<pair<int, int>> cards;
    for (int i = 0; i < N; i++)
    {
        int val;
        cin >> val;
        cards.emplace(val, 1);
    }
    for (int i = 0; i < M; i++)
    {
        int count, val;
        cin >> count >> val;
        cards.emplace(val, count);
    }
    long sum = 0;
    for (int i = 0; i < N;)
    {
        auto p = cards.top();
        cards.pop();
        for (int j = 0; j < p.second; j++)
        {
            if (i >= N)
                goto result;
            sum += p.first;
            i++;
        }
    }
result:
    cout << sum << endl;
}


Measured memory_bytes: 2420