akhauriyash/Code-Regression huggingface dataset:
q=Array.new n=gets.to_i
g=$<.map{|l|i,k,*c=l.split.map &:to_i
c.map{|j|q[j]=i}
[i,c]}.sort
d=->f,i,x{g[i][2]=x
g[i][1].map{|j|f[f,j,x+1]}}
d[d,q.index(p),0]
g.map{|v|i,c,d=v
[i,p=q[i]||-1,d,p<0?:root:c[0]?"internal node": :leaf,c]}.map{|v|puts"node %d: parent = %d, depth = %d, %s, %s"%v}

Measured memory_bytes: 64020
def main():
    N, M = map(int, input().split())
    a = [int(input()) for _ in range(M)]
    b = set(a)
    dp = [1] * N
    if 1 in a:
        dp[0] = 0
        for i in range(1, N):
            if i+1 in b:
                dp[i] = 0
            else:
                dp[i] = dp[i-1] + dp[i-2]
        print(dp[N-1] % (10**9+7))
    else:
        for i in range(1, N):
            if i+1 in b:
                dp[i] = 0
            else:
                dp[i] = dp[i-1] + dp[i-2]
        print(dp[N-1] % (10**9+7))


if __name__ == '__main__':
    main()


Measured memory_bytes: 460020
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

int W, H, N;
int x[100], y[100], a[100];


int x_1, x_2, y_1, y_2;
int max(int a,int b) {
	return (a < b) ? b : a;
}
int min(int a, int b) {
	return (a > b) ? b : a;
}
int main() {
	cin >> W >> H >> N;
	x_1 = 0;
	y_1 = 0;
	x_2 = W;
	y_2 = H;
	for (int i = 0; i < N;i++) {
		cin >> x[i] >> y[i] >> a[i];
	}
	for (int i = 0; i< N;i++) {
		switch (a[i]) {
		case 1:
			x_1 = max(x[i], x_1);
			break;
		case 2:
			x_2 = min(x[i], x_2);
			break;
		case 3:
			y_1 = max(y[i], y_1);
			break;
		case 4:
			y_2 = min(y[i], y_2);
			break;
		}
	}

	int ans = (y_2 - y_1)*(x_2 - x_1);
	if (ans < 0 || (y_2 - y_1) <= 0|| (x_2 - x_1) <= 0 ) {
		ans = 0;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
object Main extends App {
	val N = scala.io.StdIn.readInt
	var sum = 0
	for(i<-0 until N){
		val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		sum = sum + temp(1) - temp(0) + 1
	}

	println(sum)
}


Measured memory_bytes: 26412
/* ***************************************
Author        :Scau.ion
Created Time  :2016/09/24 20:56:18 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

const int maxn=100010;

int seat[maxn],a[maxn],sum[maxn],num[maxn];
bool finish[maxn];

int main()
{
	int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    for (int j=1;j<=q;++j)
    {
        scanf("%d",&a[j]);
    }
    bool flag=1;
    int last=0;
    for (int j=q;j>0;--j)
    {
        if (a[j]>last)
        {
            if (a[j]==last+1) ++last;
            else
            {
                flag=0;
                break;
            }
        }
    }
    if (flag)
    {
        printf("Yes\n");
        return 0;
    }
    int cnt=0;
    for (int j=q;j>0;--j)
    {
        int tis=a[j];
        if (seat[tis]==0)
        {
            ++cnt;
            seat[tis]=cnt;
            sum[cnt]=1;
            num[cnt]=tis;
        }
        else
        {
            if (finish[tis]) continue;
            int st=seat[tis];
            ++sum[st];
            if (st>1&&sum[st]>sum[st-1]) --sum[st];
            if (sum[st]==n)
            {
                finish[tis]=1;
                continue;
            }
        }
    }
    if (flag)
    {
        printf("No\n");
        return 0;
    }
    int nx=1;
    while (nx<=m&&finish[nx]) ++nx;
    for (int j=1;j<=cnt;++j)
    {
        if (sum[j]<n)
        {
            if (num[j]!=nx)
            {
                flag=1;
                break;
            }
            else
            {
                ++nx;
                while (nx<=m&&finish[nx]) ++nx;
            }
        }
    }
    if (flag) printf("No\n");
    else printf("Yes\n");
	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll INF=1000000007;
int main()
{
   ll n,i,j;
   cin>>n;
   ll arr[n+1][3],dp[n+1][3];
   for(i=1;i<=n;i++)
   {
       cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
   }
   dp[1][0]=arr[1][0],dp[1][1]=arr[1][1],dp[1][2]=arr[1][2];
   for(i=2;i<=n;i++)
   {
      dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
      dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
      dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
   }
   cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}


Measured memory_bytes: 8236
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
int t[5000];
int A,B,C,n;
int ans=inf;
void bfs(int l,int a,int b,int c,int mp)
{
    if(l==n)
    {
        if(a==A||b==B||c==C)
        {
            return ;
        }
        else
        {
            ans=min(ans,abs(a)+abs(b)+abs(c)+mp);
            return ;
        }
    }
    bfs(l+1,a-t[l],b,c,mp+(a==A?0:10));
    bfs(l+1,a,b-t[l],c,mp+(b==B?0:10));
    bfs(l+1,a,b,c-t[l],mp+(c==C?0:10));
    bfs(l+1,a,b,c,mp);
}

int main()
{
    cin>>n>>A>>B>>C;
    for(int i=0;i<n;i++)
    {
        cin>>t[i];
    }
    bfs(0,A,B,C,0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict

def Com(n, k):
    p, q = 1, 1
    for i in range(n-k+1, n+1):
        p *= i
    for i in range(2, k+1):
        q *= i
    return p//q

N = int(input())
b = 10**9
A = [int(round(float(input())*b)) for i in range(N)]
dic = defaultdict(int)
for a in A:
    c2, c5 = 0, 0
    while a % 2 == 0:
        c2 += 1
        a //= 2
    while a % 5 == 0:
        c5 += 1
        a //= 5
    dic[(c2, c5)] += 1
ans = 0
for i in range(50):
    for j in range(25):
        for k in range(i, 50):
            for l in range(25):
                if not (i==k and j>=l) and i+k >= 18 and j+l >= 18:
                    ans += dic[(i, j)] * dic[(k, l)]
for i in range(50):
    for j in range(25):
        if i+i >= 18 and j+j >= 18 and dic[(i, j)] > 1:
            ans += Com(dic[(i, j)], 2)
print(ans)


Measured memory_bytes: 88536
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int s[][]= new int[M][N];
    int tmp=0;
    int p[] = new int[M];
    for(int i=0;i<M;i++){
      tmp=sc.nextInt();
      for(int j=0;j<tmp;j++){
        s[i][j]=sc.nextInt();
      }
    }
    for(int i=0;i<M;i++){
      p[i]=sc.nextInt();
    }
    int answer =0;
    int tmps=0;
    boolean allRight=true;
    boolean r[] = new boolean[M];
    for(int i=0;i<M;i++){
      r[i]=false;
    }
    for(int i=0;i<(1<<N);i++){
      for(int j=0;j<M;j++){
        for(int k=0;k<N;k++){
          if((i>>s[j][k])%2==1){//s[j][k]のスイッチが今おささってるか判定
            tmps++;
          }
        }
        if(tmps%2==p[j]){//j番目の電球はOK
          r[j]=true;
          tmps=0;
        }
      }
      //電球なめて全部光ってたら答えをインクリメント
      for(int l=0;l<M;l++){
        if(!r[l]){
          allRight=false;
          break;
        }
      }
 //     System.out.println(i);
 //     System.out.println(allRight);
      if(allRight){
      answer++;
      }
      allRight=true;
      for(int m=0;m<M;m++){//それぞれ初期値に戻す
        r[m]=false;
      }
      tmps=0;
    }

    System.out.println(answer);
  }
  


  
}


Measured memory_bytes: 21972
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <string>

int main() {
  char buf[16];
  scanf("%s", buf);
  std::string s = buf;
  scanf("%s", buf);
  std::string t = buf;
  int a, b;
  scanf("%d %d", &a, &b);
  scanf("%s", buf);
  std::string u = buf;

  if (u == s) --a;
  if (u == t) --b;
  printf("%d %d\n", a, b);
}


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

const int N = 1e5 + 10;

long long n, W, w, v;
long long d[N], use[N];
int main ()
{
    cin >>n >>W;
    use[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        d[i] = 1e12;
    }
    for (int i = 1; i<=n; i++)
    {
        cin >>w >>v;
        for (int u = 1e5 + 10; u >= 0; u--)
        {
            if (use[u] == 1)
            {
                d[u + v] = min(d[u + v], d[u] + w);
                use[u + v] = 1;
            }
        }
    }
    for (int i = N; i >= 0; i--)
    {
        if (use[i] == 1)
        {
            if (d[i] <= W)
            {
                cout <<i;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1792
use proconio::input;

fn main() {
    input! {
        n: usize,
    }
    let m = 1000000007;
    let mut dp = vec![vec![vec![0usize; 2]; 2]; n + 1];
    dp[0][0][0] = 1;

    for i in 1..=n {
        dp[i][0][0] = dp[i - 1][0][0] * 8 % m;
        dp[i][0][1] = (dp[i - 1][0][0] + dp[i - 1][1][0]) % m + dp[i - 1][0][1] * 8 % m;
        dp[i][1][0] = (dp[i - 1][0][0] + dp[i - 1][0][1]) % m + dp[i - 1][1][0] * 8 % m;
        dp[i][1][1] = (dp[i - 1][0][1] + dp[i - 1][1][0]) % m + dp[i-1][1][1] * 10 % m;

        dp[i][0][0] %= m;
        dp[i][0][1] %= m;
        dp[i][1][0] %= m;
        dp[i][1][1] %= m;
    }

    println!("{}", dp[n][1][1]);
}


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

int N, p[100009]; string S; vector<pair<int, int>>G;

int main() {
	cin >> S; N = S.size();
	for (int i = 1; i <= N; i++) { if (S[i - 1] == '1') p[i] = 1; }

	bool flag = false;
	for (int i = 1; i <= N; i++) {
		if (p[i] != p[N - i]) flag = true;
	}
	if (p[1] == 0) flag = true;
	if (flag == true) {
		cout << "-1" << endl;
		return 0;
	}

	vector<int>vec;
	for (int i = 1; i <= N / 2; i++) { if (p[i] == 1) vec.push_back(i); }
	vec.push_back(N);
	for (int i = 1; i < vec.size(); i++) {
		for (int j = vec[i - 1]; j < vec[i]; j++) G.push_back(make_pair(vec[i], j));
	}
	for (int i = 0; i < G.size(); i++) cout << G[i].first << " " << G[i].second << endl;
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int p[100005];
int main()
{
  string s;
  cin >> s;
  if(s == "ABC")
    cout << "ARC";
  else
  {
    cout << "ABC";
  }
  
}


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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

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

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> vals;
  int tmp = 1;
  while (tmp <= n){
    tmp *= 2;
  }
  cout << tmp/2 << endl;
  return 0;
}



Measured memory_bytes: 3656
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,m = mi()
av = li()
bv = li()

avs = av.copy()
bvs = bv.copy()
avs.sort()
bvs.sort()

ans = avs[0] + bvs[0]

for i in range(m):
    q = li()
    tmp = av[q[0]-1] + bv[q[1]-1] - q[2]
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    
    int x; cin >> x;
    if(x<600) cout<<8<<endl;
    else if(x<800)cout<<7<<endl;
    else if(x<1000)cout<<6<<endl;
    else if(x<1200)cout<<5<<endl;
    else if(x<1400)cout<<4<<endl;
    else if(x<1600)cout<<3<<endl;
    else if(x<1800)cout<<2<<endl;
    else cout<<1<<endl;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[m];
        boolean ab[] = new boolean[n+10];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            ab[a[i]] = true;
        }
        final long MOD = 1000000007L;
        long dp[] = new long[n+10];
        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            if(ab[i]) {
                dp[i] = 0;
            } else {
                dp[i] = dp[i-1];
                if(i> 1) dp[i] += dp[i-2];
                dp[i] %= MOD;
            }
        }
        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 48804
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <set>
#include <algorithm>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

inline int max(int a, int b) {
	if (b > a) swap(a, b);
	return a;
}

inline int min(int a, int b) {
	if (a > b) swap(a, b);
	return a;
}

int check(vector<int> &s, int p, int i) {
	int sum = 0;
	for (auto a : s) {
		sum += (((int)pow(2, a - 1) & i) != 0);
	}
	return (sum % 2) == p;
}


int main() {
	int n, m;
	int count = 0;
	cin >> n >> m;
	vector<vector<int>> sw(m);
	vector<int> p(m);

	rep(i, m) {
		int k;
		cin >> k;
		rep(j, k) {
			int s;
			cin >> s;
			sw[i].emplace_back(s);
		}
	}

	rep(i, m) {
		cin >> p[i];
	}

	for (int i = 0; i < (int)pow(2, n); i++) {
		int sum = 0;
		rep(j, m) {
			sum += check(sw[j], p[j], i);
		}
		if (sum == m) {
			count++;
		}
	}
	cout << count << endl;


	return 0;
}


Measured memory_bytes: 256
using System;
 
class Program {
    private static int Main() {
        var input = Console.ReadLine();
        var values = input.Split( ' ' );
 
        int a = int.Parse( values[ 0 ] );
        int b = int.Parse( values[ 1 ] );
 
        int d = a / b;
        int r = a % b;
        decimal f = (decimal)a / b;
 
        var output = string.Format( "{0} {1} {2}", d, r, f );
        Console.WriteLine( output );
 
        return 0;
    }
}

Measured memory_bytes: 5676
sx, sy, tx, ty = list(map(int, input().split()))

dx, dy = tx - sx, ty - sy

sx = 'R' if dx >= 0 else 'L'
sy = 'U' if dy >= 0 else 'D'

first = sx * abs(dx) + sy * abs(dy)

trans = str.maketrans('UDRL', 'DULR')
def rev(s):
    return s.translate(trans)


print(first, end='')

if dx != 0 and dy != 0:
    print(rev(first), end='')
    d = 'R' if dx > 0 else 'L'
    d2 = 'D' if dy > 0 else 'U'
    second = d2 + d + first + rev(d2) + rev(d)
    print(second, end='')
    print(rev(second), end='')
    
else:
    d = 'R' if dx is 0 else 'U'
    second = d + rev(first) + rev(d)
    print(second, end='')
    
    print(rev(second), end='')
    d2 = first[0]
    print(d2, d * 2, rev(d2), rev(first), rev(d2), rev(d) * 2, rev(d2), sep='', end='')

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin>>n;
    int d[13]={};
    d[0]++;
    rep(i,n){
        int tmp;cin>>tmp;
        d[tmp]++;
    }
    rep(i,13){
        if(d[i]>=3||d[0]>1){
            cout << 0 << endl;
            return 0;
        }
    }
    DEBUG{cout << "main" << endl;}
    int res=0;
    rep(i,1<<14){
        int restmp=1<<28;
        vector<int> times;
        times.push_back(0);
        times.push_back(24);
        rep(j,13){
            if(j==0){continue;}
            if(d[j]==2){
                times.push_back(j);
                times.push_back(24-j);
            }
            else if(d[j]==1){
                if(i>>j&1){
                    times.push_back(j);
                }else{
                    times.push_back(24-j);
                }
            }
        } 
        sort(times.begin(),times.end());
        rep(j,times.size()-1){
            restmp = min(restmp, times[j+1]-times[j]);
        }
        times.clear();
        res = max(res,restmp);
    }
    cout << res << endl;
    return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n);
    rep(i,0,n){
        cin>>a.at(i);
    }
    sort(all(a));
    ll ng=-INF;
    ll ok=INF;
    while(ok-ng>1){
        ll x=(ok+ng)/2;
        ll s=0, t=0;
        rep(i,0,n){
            if(a.at(i)>0){
                int ng2=-1, ok2=n;
                while(ok2-ng2>1){
                    int m=(ok2+ng2)/2;
                    if(a.at(i)*a.at(m)<=x)ng2=m;
                    else ok2=m;
                }
                s+=ok2;
            }
            else if(a.at(i)<0){
                int ng2=-1, ok2=n;
                while(ok2-ng2>1){
                    int m=(ok2+ng2)/2;
                    if(a.at(i)*a.at(m)<=x)ok2=m;
                    else ng2=m;
                }
                s+=n-ok2;
            }
            else if(x>=0)s+=n;
            if(a.at(i)*a.at(i)<=x)t++;
        }
        ll num=(s-t)/2;
        if(num>=k)ok=x;
        else ng=x;
    }
    cout<<ok<<endl;
return 0;
}

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

int main(){
	string S,T;
	cin >> S >> T;
	for(int i=0;i<S.size();i++){
		if(S[i]!=T[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3624
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}
bool check(string s)
{
   string t;
   t=s;
   reverse(all(t));
   if(t==s) return true;
   else return false;
}
int32_t main()
{   
     IOS;
     
     ld a;
     cin>>a;
     ld ans=(a*a*a)/(ld)27;
     cout<<fixed<<setprecision(10)<<ans;
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long var265;const int var272=1039074182;using namespace std;int main(){int var296;cin>>var296;pii a[55];for(int var317=0;var317<var296;var317++){cin>>a[var317].first>>a[var317].second;}vector <pii> var359;for(int var317=0;var317<var296;var317++){for(int var385=0;var385<var296;var385++){if(var317==var385) continue;var359.push_back(mp(a[var317].first-a[var385].first,a[var317].second-a[var385].second));}}sort(all(var359));int var463=0;for(int var317=0,var385=0;var317<var296*(var296-1);var317=var385){int var499=0;for(var385=var317;var385<var296*(var296-1);var385++){if(var359[var385]==var359[var317]) var499++;else break;}var463=max(var499,var463);}cout<<var296-var463<<endl;return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <climits>
#include <string>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <numeric>
#include <random>
#include <memory>
#include <chrono>
#include <iterator>
#include <functional>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif
//#pragma GCC optimize("Ofast")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define mp make_pair
#define pb push_back
#define sz(x) int((x).size())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 7;
const int inf = INT_MAX / 2;
const ll INF = LLONG_MAX / 3;
const int MOD = 998244353;
const ld eps = 1e-6;
const string cars[] = {"🚗", "🚕", "🚙"};

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(3);
    cin.tie();
    cout.tie();

    ll n;
    cin >> n;

    cout << n * (n - 1) / 2;

    return 0;
}

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


int main(){
  
  int i;
  string S;
  vector<int>  Num(100000), LRPos(100000);
  cin>>S;
  
  int ix=0; char sr_=S[0];
  for(int i=1; i<S.size(); i++){

    if(sr_=='R' && S[i]=='L'){
      LRPos[ix]=i-1; ix++;
      Num[i-1]++; Num[i]++;
    }
    sr_=S[i];
  }
  
  ix=0;
  for(i=0; i<S.size(); i++){
    
    if(LRPos[ix]==i){
      i++; ix++;
      continue;
    }
    
    if(S[i]=='R'){
      Num[LRPos[ix]+(LRPos[ix]-i)%2]++;
    }else{
      Num[LRPos[ix-1]+(i-LRPos[ix-1])%2]++;
    }
  }
  for(i=0; i<S.size(); i++){
    cout<<Num[i]<<" ";
  }
  return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int n, h;
	cin >> n >> h;
	vector<int> a(n);
	vector<int> b(n);
	int lim = 0;
	rep(i, n) {
		cin >> a[i] >> b[i];
		chmax(lim, a[i]);
	}

	sort(all(b), greater<int>());
	int i;
	for(i = 0; b[i] >= lim; i++) {
		h -= b[i];
		if(h <= 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	
	while(1) {
		h -= lim;
		i++;
		if(h <= 0) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
from collections import deque

h, w = map(int, input().split())
cy, cx = map(lambda x:int(x)-1, input().split())
gy, gx = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(h)]
seen = [[-1]*w for _ in range(h)]
def f(sy, sx, cnt):
    que = []
    que.append((sy, sx))
    seen[sy][sx] = cnt
    while que:
        y, x = que.pop()
        for dy, dx in ((-1,0),(0,-1),(1,0),(0,1)):
            ny, nx = y+dy, x+dx
            if 0 <= ny < h and 0 <= nx < w:
                if seen[ny][nx] != -1:
                    continue
                if S[ny][nx] == "#":
                    continue
                seen[ny][nx] = cnt
                que.append((ny, nx))
cnt = 0
for i in range(h):
  for j in range(w):
    if S[i][j] == "." and seen[i][j] == -1:
      f(i, j, cnt)
      cnt += 1
G = [set() for _ in range(cnt+1)]
for i in range(h):
  for j in range(w):
    for dy in range(-2, 3):
      for dx in range(-2, 3):
        y, x = i+dy, j+dx
        if 0 <= y < h and 0 <= x < w:
          if S[i][j] == "#":
            continue
          if S[y][x] == "#":
            continue
          G[seen[i][j]].add(seen[y][x])
          G[seen[y][x]].add(seen[i][j])
s = seen[cy][cx]
g = seen[gy][gx]
dist = [-1]*(cnt+1)
dist[s] = 0
que = deque()
que.append(s)
while que:
  v = que.popleft()
  if g == v:
    print(dist[g])
    exit()
  for i in G[v]:
    if dist[i] != -1:
      continue
    dist[i] = dist[v]+1
    que.append(i)
print(-1)

Measured memory_bytes: 132888
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

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

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {
	SpeedForce;
	cin >> n >> m;
	if (n < 6) cout << 0;
	else if (n < 13) cout << m / 2;
	else cout << m;

	return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	int n;
	cin >> n;
	ll a[100005];
	ll count[100005] = {0};
	bool flag[100005] = {false};
	for(int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		count[a[i]]++;
		flag[a[i]] = true;
	}
	ll maxl = 1;
	for(int i = 0; i < 100005; i++){
		maxl = max(maxl, count[i]);
		ll tmax;
		if(flag[i] && flag[i + 1] && flag[i + 2]){
			tmax = count[i] + count[i + 1] + count[i + 2];
			maxl = max(tmax, maxl);
		}
		if(flag[i] && flag[i + 1]){
			tmax = count[i] + count[i + 1];
			maxl = max(tmax, maxl);
		}
		if(flag[i] && flag[i + 2]){
			tmax = count[i] + count[i + 2];
			maxl = max(tmax, maxl);
		}
	}
	cout << maxl << endl;
	return 0;
}

Measured memory_bytes: 5308
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

int n, m, r;
vector< int > city;
int d[201][201];

bool isVisited(int v) {
    for(int i = 0; i < r; i++) {
        if(!(v >> i & 1)) return false;
    }
    return true;
}

int dp[201][1 << 9];
int rec(int now, int visited) {
    if(isVisited(visited)) return 0;

    if(dp[now][visited]) return dp[now][visited];
    int ret = 1e+8;
    for(int i = 0; i < r; i++) {
        if(!(visited >> i & 1))
        ret = min(ret, rec(city[i], visited | (1 << i)) + d[now][city[i]]);
    }
    return dp[now][visited] = ret;
}

int main() {

    cin >> n >> m >> r;
    city.resize(r);
    fill_n(*d, 201 * 201, 1e+8);

    for(int i = 0; i < r; i++)
        cin >> city[i];

    for(int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c;
        d[a][b] = d[b][a] = c;
    }

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            for(int k = 1; k <= n; k++) {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }

    int mini = 1e+8;
    for(int i = 0; i < r; i++) {
        mini = min(mini, rec(city[i], 1 << i));
    }
    cout << mini << endl;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

#define x(p) real(p)
#define y(p) imag(p)

const double eps=1e-10;
const double inf=1e12;
const double PI=acos(-1);
typedef complex<double> P;

namespace std{
  bool operator<(const P& a,const P& b){
    return x(a)==x(b)?y(a)<y(b):x(a)<x(b);
  }
}
double cross(const P& a,const P& b){
  return y(conj(a)*b);
}
double dot(const P& a,const P& b){
  return x(conj(a)*b);
}
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

//// move point
P projection(const L& l,const P& p){
  P b=l[1]-l[0],c=p-l[0];
  return l[0]+b*x(c/b);
}
P reflection(const L& l,const P& p) {
  return p+2.0*(projection(l,p)-p);
}
P rotation(const P& a,double r){
  return P(x(a)*cos(r)-y(a)*sin(r),x(a)*sin(r)+y(a)*cos(r));
}
//// intersect
bool intersectLL(const L& l,const L& m){
  return abs(cross(l[1]-l[0],m[1]-m[0]))>eps||abs(cross(l[1]-l[0],m[0]-l[0]))<eps;
}
bool intersectLS(const L& l,const L& s){
  return cross(l[1]-l[0],s[0]-l[0])*cross(l[1]-l[0],s[1]-l[0])<eps;
}
bool intersectLP(const L& l,const P& p){
  return abs(cross(l[1]-p,l[0]-p))<eps;
}
bool intersectSP(const L& s,const P& p){
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0])<eps;
}
//// distance
double distanceLP(const L& l,const P& p) {
  return abs(p-projection(l,p));
}
double distanceLL(const L& l,const L& m) {
  return intersectLL(l,m)?0:distanceLP(l,m[0]);
}
double distanceLS(const L& l,const L& s) {
  return intersectLS(l,s)?0:min(distanceLP(l,s[0]),distanceLP(l,s[1]));
}
double distanceSP(const L& s,const P& p) {
  const P r=projection(s,p);
  return intersectSP(s,r)?abs(r-p):min(abs(s[0]-p),abs(s[1]-p));
}
struct C{
  P p;
  double r;
  C(const P& p,double r):p(p),r(r){}
};

int n;
P ps[505];

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>n;
    if(n==0)break;
    double x,y;
    rep(i,n){
      cin>>x>>y;
      ps[i]=P(x,y);
    }
    int res=1;
    rep(i,n)rep(j,i){
      P mp=(ps[i]+ps[j])*0.5;
      P nv=P(-y(ps[i]-ps[j]),x(ps[i]-ps[j]));
      nv=nv*(1.0/abs(nv));
      double h=pow(abs(mp-ps[i]),2);
      if(1-h<eps)continue;
      double len=sqrt(1-h);
      {
        C nc(P(mp+nv*len),1.0);
        int cnt=0;
        rep(k,n){
          if(abs(nc.p-ps[k])*abs(nc.p-ps[k])<1.0+eps){
            cnt++;
          }
        }
        maxch(res,cnt);
      }
      {
        C nc(P(mp-nv*len),1.0);
        int cnt=0;
        rep(k,n){
          if(abs(nc.p-ps[k])*abs(nc.p-ps[k])<1.0+eps){
            cnt++;
          }
        }
        maxch(res,cnt);
      }
    }
    cout<<res<<endl;
  }
	return 0;
}

Measured memory_bytes: 3340
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
#include<map>
#include<bitset>
#include<array>
#include<cmath>
#include<functional>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
const llint big=2e18+100000;
const int mod=1e9+7;
const lldo eps=1e-7;
const long double pai=3.141592653589793238462643383279502884197;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
#define dme(in) cout<<in<<endl;return 0
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int val[524288];//そうでないと壊れる
class seg_tree{
	//131072
public:
	//RMQ配列セグ木は配列O(1)
	
	seg_tree(void){for(int i=0;i<524288;i++){val[i]=mod;}}
	int seg_ask(int index){
		//index以下のmin
		index+=262144;
		int ans=val[index];
		while(index>1){
			if(index%2==1){mineq(ans,val[index-1]);}
			index/=2;
		}
		return ans;
	}
	void seg_kou(int index,int in){
		//valを更新する
		index+=262144;
		val[index]=in;index/=2;
		while(index>0){val[index]=min(val[index+index],val[index+index+1]);index/=2;}
	}
	int seg_hai(int index){return val[index+262144];}
};
int main(void){
	//NRE
	//RMQのみ
	int n,m,i,j;cin>>n;
	int ans=0;
	vector<int>b(n+1);
	for(i=0;i<n;i++){cin>>b[i];if(b[i]==0){ans++;}}
	cin>>m;
	vector<pair<int,int>>suu(m+1);
	for(i=0;i<m;i++){cin>>suu[i].fir>>suu[i].sec;suu[i].fir--;}
	suu[m]=mp(n,n);//なにもしない
	sort(suu.begin(),suu.end());
	seg_tree ki;
	ki.seg_kou(0,0);
	int bas=0;
	for(i=0;i<=m;i++){
		while(bas<suu[i].fir){
			int nex=ki.seg_hai(bas);
			if(b[bas]==0){nex--;}else{nex++;}
			mineq(nex,ki.seg_hai(bas+1));
			ki.seg_kou(bas+1,nex);
			ki.seg_kou(bas,mod);
			bas++;
		}
		ki.seg_kou(suu[i].sec,ki.seg_ask(suu[i].sec));
	}
	cout<<ans+ki.seg_hai(n)<<endl;
	return 0;
}

Measured memory_bytes: 4608
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n,k = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

sum = 0
h.each do |x|
  if x >= k
    sum += 1
  end
end

puts sum

Measured memory_bytes: 20168
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

type greater []int

func (g greater) Len() int           { return len(g) }
func (g greater) Less(i, j int) bool { return g[i] > g[j] }
func (g greater) Swap(i, j int)      { g[i], g[j] = g[j], g[i] }

func (con *contest) main() error {
	var N, A, B int
	con.Scan(&N, &A, &B)
	h := make([]int, N)
	hi := 0
	lo := 1
	for i := 0; i < N; i++ {
		con.Scan(&h[i])
		hi += (h[i] + A - 1) / A
	}
	sort.Sort(greater(h))
	for hi > lo {
		mi := (hi + lo) / 2
		a := 0
		for _, x := range h {
			// A*a + B*b > x
			// a + b = mi
			// (A - B) * a > x - B * mi
			x -= B * mi
			if x < 0 {
				break
			}
			x += A - B - 1
			x /= A - B
			a += x
		}
		if a > mi {
			if lo == mi {
				lo++
			} else {
				lo = mi
			}
		} else {
			hi = mi
		}
	}
	con.Println(lo)
	return nil
}


Measured memory_bytes: 3072
/*input
3
28 27 24
*/

#include <bits/stdc++.h>
 
using namespace std;
const long long MOD = 1e9+7;
vector<int> prime;
const int MAX = 100;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    bool flag = true;
    int x;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x;
        if(x%2==0){
            if(x%3==0 || x%5==0)
                continue;
            else
                flag = false;
        }
    }
    if(flag)
        cout << "APPROVED";
    else
        cout << "DENIED";


}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

vector<vector<char>> board;

int solve(const int all_bk, const int H, const int W, const int K) {
    int ans = 0;

    for (int h_bits = 0; h_bits < (1 << H); h_bits++) {
        for (int w_bits = 0; w_bits < (1 << W); w_bits++) {
            int cnt = 0;
            for (int h = 0; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    if (board[h][w] == '#') {
                        if ((h_bits & (1 << h)) || (w_bits & (1 << w))) {
                            cnt++;
                        }
                    }
                }
            }

            if (all_bk - cnt == K) {
                ans++;
            }
        }
    }

    return ans;
}

int main(void) {
    int H, W, K;
    cin >>  H >> W >> K;

    int all_bk = 0;

    board.resize(H, vector<char>(W));
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            char c;
            cin >> c;
            board[h][w] = c;
            if (c == '#') {
                all_bk++;
            }
        }
    }

    cout << solve(all_bk, H, W, K) << endl;

    return 0;
}


Measured memory_bytes: 3632
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    s = inputs[0]
    t = inputs[1]
    s_list = list(s)
    t_list = list(t)
    s_list.sort()
    t_list.sort(reverse=True)
    s_ret = ''.join(s_list)
    t_ret = ''.join(t_list)

    return 'Yes' if s_ret < t_ret else 'No'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 3812
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MOD 1000000007
#define inv2 500000004
#define MAX 200200
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int fpow(int a,int b){int s=1;while(b){if(b&1)s=1ll*s*a%MOD;a=1ll*a*a%MOD;b>>=1;}return s;}
int n,B,W,jc[MAX],jv[MAX],inv[MAX];
int C(int n,int m){if(n<m||m<0||n<0)return 0;return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int pw[MAX],pb[MAX],sum[MAX];
int bin[MAX];
int main()
{
	B=read();W=read();n=B+W;
	jc[0]=jv[0]=inv[0]=inv[1]=1; 
	for(int i=2;i<=n;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for(int i=1;i<=n;++i)jc[i]=1ll*jc[i-1]*i%MOD;
	for(int i=1;i<=n;++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
	bin[0]=1;for(int i=1;i<=n;++i)bin[i]=1ll*bin[i-1]*inv2%MOD;
	for(int i=1;i<=n;++i)pw[i]=(pw[i-1]+1ll*C(i-1,W-1)*bin[i])%MOD;
	for(int i=1;i<=n;++i)pb[i]=(pb[i-1]+1ll*C(i-1,B-1)*bin[i])%MOD;
	for(int i=1;i<=n;++i)
	{
		int ans=(1ll*(1ll+MOD-pw[i-1]+MOD-pb[i-1])%MOD*inv2%MOD+pw[i-1])%MOD;
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 6912
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10;
int n, m;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    cin >> n >> m;
    priority_queue<int> q;
    for (int i = 0; i < n; ++i){
        int temp;
        cin >> temp;
        q.push(temp);
    }

    while (m--){
        int t = q.top();
        q.pop();
        t >>= 1;
        q.push(t);
    }
    
    ll ans = 0;
    while (!q.empty()){
        ans += q.top();
        q.pop();
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 892
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	long long r, n,en;
	cin >> n >> r;
	if (n >= 10)
		en = r;
	else
		en = r + (10 - n) * 100;
	cout << en << endl;
}
 
 

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,k;
  while(1){
    scanf("%d %d",&i,&j);
    if(i==0 && j==0){
      break;
    }
    else if(i>j){
      k=i;
      i=j;
      j=k;
      printf("%d %d\n",i,j);
    }
    else{
      printf("%d %d\n",i,j);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

bool add_queue(const int s1, queue<P>& q, vector<int>& s) {
    auto it = lower_bound(s.begin(), s.end(), s1);
    if (it == s.begin()) return false;
    it--;
    // cout << s1 << " " << *it << endl;
    q.push(P(s1, *it));
    s.erase(it);
    return true;
}

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

    int ns = pow(2, n);
    vector<int> s(ns);
    for (int i=0; i<ns; i++) cin >> s[i];
    sort(s.begin(), s.end());

    int s1, s2;
    s2 = s.back();
    s.pop_back();
    s1 = s.back();
    s.pop_back();
    
    bool ans = true;
    queue<P> q;
    if (s1 < s2) q.push(P(s1, s2));
    else ans = false;

    int day = 0;
    while (true) {
        if (q.empty()) break;
        queue<P> next_q;
        day++;
        while (!q.empty()) {
            P p = q.front();
            q.pop();
            s1 = p.first;
            s2 = p.second;

            // if (!add_queue(s1, q, s) && !add_queue(s2, q, s)) break;
            add_queue(s1, next_q, s);
            add_queue(s2, next_q, s);
        }
        q = next_q;
    }

    ans = ans && q.empty() && s.size()<=0 && day <= n;
    cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 3328
import std.stdio;
import std.algorithm;

int[8][8] cost;
int[8][8] d;

void main(){
	int a, b, h1, m1, h2, m2, s1, s2, ans;
	cost[1][2..8] = [300, 500, 600, 700, 1350, 1650];
	cost[2][3..8] = [350, 450, 600, 1150, 1500];
	cost[3][4..8] = [250, 400, 1000, 1350];
	cost[4][5..8] = [250, 850, 1300];
	cost[5][6..8] = [600, 1150];
	cost[6][7..8] = [500];
	d[2][1..2] = [6];
	d[3][1..3] = [13, 7];
	d[4][1..4] = [18, 12, 5];
	d[5][1..5] = [23, 17, 10, 5];
	d[6][1..6] = [43, 37, 30, 25, 20];
	d[7][1..7] = [58, 52, 45, 40, 35, 15];
	while (readf("%d\n", &a), a) {
		readf("%d %d\n", &h1, &m1);
		readf("%d\n", &b);
		readf("%d %d\n", &h2, &m2);
		s1 = h1*60+m1;
		s2 = h2*60+m2;
		if (a > b) swap(a, b);
		ans = cost[a][b];
		if (d[b][a] <= 40 && ((s1 >= 17*60+30 && s1 <= 19*60+30) || (s2 >= 17*60+30 && s2 <= 19*60+30))) {
			ans /= 2;
			if (ans%50 != 0) ans = ans/50*50+50;
		}
		writeln(ans);
	}
}

Measured memory_bytes: 992
#include <stdio.h>
int isprime2(int n){
	int i;
	for(i = 2; i * i <= n; i++){
		if(n % i == 0) return 0;
	}
	return 1;
}
int main() {
	int n, p, q, i;
	scanf("%d", &n);
	while(1){
		if(n == 0) break;
		for(i = n; n >= 5; i--){
			if(isprime2(i) == 1 && isprime2(i-2) == 1){
				p = i-2;
				q = i;
				break;
			}
		}
		printf("%d %d\n", p, q );
		scanf("%d", &n);
	}
	return 0;
}

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

int main(){
  ll n;
  cin >> n;
  string c;
  cin >> c;
  ll ans = 0;
  ll k = 0;
  int flag = 0;
  rep(i,0,n){
    if(c[i]=='R'){
      continue;
    }
    k++;
    while(1){
      if(n-k<=i){
        flag = 1;
        break;
      }
      else if(c[n-k]=='W'){
        k++;
        continue;
      }
      else{
        ans++;
        break;
      }
    }
    if(flag==1) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3740
from operator import itemgetter

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1, 0))

now = 0
for a, b in AB:
    now += a
    if now > b:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 66348
S = input()
s = list(S)
size = len(S)
stack = []
for i in range(size):
    if len(stack) == 0 :
        stack.append(s[i])
    else :
        if stack[-1] != s[i] :
            stack.pop(-1)
        else :
            stack.append(s[i])

print("{}".format(size-len(stack)))

Measured memory_bytes: 4724