akhauriyash/Code-Regression huggingface dataset:
INF = 10 ** 9 + 7
n, m = gets.split.map(&:to_i)
gap = (n - m).abs
factorial = [1]
(1..[n, m].max).each do |index|
  factorial[index] = index * factorial[index - 1] % INF
end
if gap > 1
  ans = 0
elsif gap == 1
  ans = factorial[n] * factorial[m] % INF
else
  ans = factorial[n] * factorial[m] * 2 % (INF)
end
puts ans


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

  vector<int> b(n,0);
  int i=0;
  int cnt = 0;
  bool end = true;
  while(1){
    cnt++;
    i = a.at(i)-1;
    b.at(i)++;
    if(i == 1)
      break;
    if(b.at(i)>1){
      end = false;
      break;
    }
  }

  if(end)
    cout << cnt << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int ng[200010];

int main(){
  int n,q; cin >> n >> q;
  priority_queue<tiii, vector<tiii>, greater<tiii>> que;
  rep(i,n){
    int s,t,x; cin >> s >> t >> x;
    que.push(tiii(x,s-x,t-x));
  }
  set<int> st;
  rep(i,q){
    int a; cin >> a;
    st.insert(a);
  }
  vector<pii> ans(0);
  while(st.size()&&que.size()){
    int a,b,x;
    tie(x,a,b)=que.top();
    if(st.lower_bound(a)==st.end()){
      que.pop();
    }
    else if(*st.lower_bound(a)<b){
      ans.push_back(pii(*st.lower_bound(a),x));
      st.erase(*st.lower_bound(a));
    }
    else que.pop();
  }
  for(auto c:st){
    ans.push_back(pii(c,-1));
  }
  sort(all(ans));
  rep(i,ans.size()){
    cout << ans[i].second << endl;
  }
}

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

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

    set<char> c;
    rep(i, s.size()) c.insert(s[i]);

    if (s.size() == c.size())
        cout << "yes" << endl;
    else
        cout << "no" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc145/abc145_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  cout << N * N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a,b,ans=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		ans=ans+b-a+1; 
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using u128 = __uint128_t;
using u64 = unsigned long long int;
using s64 = long long int;
using u32 = unsigned int;

constexpr u32 mod = 1000000007;

int n;

u32 pow2[200001];

int main(){

  scanf("%d", &n);
  pow2[0] = 1;
  for(int i = 1; i <= n; i++){
    pow2[i] = 2 * pow2[i-1];
    if(pow2[i] >= mod) pow2[i] -= mod;
  }

  using quot = std::pair<u64, u64>;
  std::vector<quot> vp, vn;
  int zero2 = 0;

  for(int i = 0; i < n; i++){
    s64 a, b;
    scanf("%lld%lld", &a, &b);
    if(a == 0 && b == 0) zero2++;
    else if(b != 0 && (a == 0 || (a^b) >= 0)){
      vp.emplace_back(std::abs(a), std::abs(b));
    }
    else {
      vn.emplace_back(std::abs(b), std::abs(a));
    }
  }

  auto comp = [](const quot &a, const quot &b){ return (u128) a.first * b.second < (u128) b.first * a.second; };
  
  std::sort(vp.begin(), vp.end(), comp);
  std::sort(vn.begin(), vn.end(), comp);

  auto equiv = [](const quot &a, const quot &b){ return (u128) a.first * b.second == (u128) b.first * a.second; };


  std::vector<std::pair<quot, u32> > vpp, vnn;
  quot prev = {1, -1};
  for(auto const &x: vp){
    if(equiv(x, prev)) vpp.back().second++;
    else{
      vpp.emplace_back(quot(x.first, x.second), 1);
      prev = x;
    }
  }
  prev = {1, -1};
  for(auto const &x: vn){
    if(equiv(x, prev)) vnn.back().second++;
    else{
      vnn.emplace_back(quot(x.first, x.second), 1);
      prev = x;
    }
  }

  u64 ans = 1;
  auto ip = vpp.begin(), in = vnn.begin();
  while(ip != vpp.end() && in != vnn.end()){
    if(equiv(ip->first, in->first)){
      ans = ans * (pow2[ip->second] + pow2[in->second] + mod - 1) % mod;
      ++ip, ++in;
    }
    else if(comp(ip->first, in->first)){
      ans = ans * pow2[ip->second] % mod;
      ++ip;
    }
    else {
      ans = ans * pow2[in->second] % mod;
      ++in;
    }
  }
  while(in != vnn.end()){ ans = ans * pow2[in->second] % mod; ++in; }
  while(ip != vpp.end()){ ans = ans * pow2[ip->second] % mod; ++ip; }

  ans = (ans + zero2 + mod - 1) % mod;
  printf("%llu\n", ans);

  return 0;
}


Measured memory_bytes: 13392
let [|N;M;P|] =
    stdin.ReadLine().Split()
    |> Array.map int
let edges =
    [|1..M|]
    |> Array.map (fun _ ->
        stdin.ReadLine().Split()
        |> Array.map int)
let INF = 1001001001

let edges' =
    edges
    |> Array.map (fun [|from;b;cost|] -> (from-1, b-1, P-cost))

let toMap =
    edges'
    |> Array.groupBy (fun (from,_,_) -> from)
    |> Map.ofArray
let rtoMap =
    edges'
    |> Array.groupBy (fun (_,b,_) -> b)
    |> Map.ofArray

let rec dfs1 (state:bool[]) i =
    if state.[i] then state
    else
        Array.set state i true
        if Map.containsKey i toMap then
            toMap.[i]
            |> Array.fold (fun s (_,b,_) -> dfs1 s b) state
        else state

let ok1 = dfs1 (Array.create N false) 0

let rec dfsN (state:bool[]) i =
    if state.[i] then state
    else
        Array.set state i true
        if Map.containsKey i rtoMap then
            rtoMap.[i]
            |> Array.fold (fun s (from,_,_) -> dfsN s from) state
        else state

let okN = dfsN (Array.create N false) (N-1)

let ok = Array.map2 (&&) ok1 okN

let intialState = Array.create N INF
Array.set intialState 0 0

[|1..N|]
|> Array.fold (fun (state:int[], _) i ->
    edges'
    |> Array.fold (fun (s, loop) (from,b,cost) ->
        if ok.[b] && ok.[from] && s.[b] > s.[from] + cost then
            Array.set s b (s.[from] + cost)
            if i=N then (s, true)
            else (s, loop)
        else (s, loop)) (state,false)) (intialState,false)
|> (fun (arr,loop) ->
    if loop then -1
    else max (-arr.[N-1]) 0)
|> stdout.WriteLine

Measured memory_bytes: 50904
def resolve():
    N = int(input())
    H = list(map(int, input().split()))
    lower = True
    for i in range(N-1):
        if H[i] > H[i+1]:
            if H[i] - H[i+1] == 1 and lower is True:
                lower = False
            else:
                print("No")
                return
        elif H[i] == H[i+1]:
            pass
        else:
            lower = True

    print("Yes")


    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 84432
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
  int count5=0,count7=0;
  int a;
  for(int i=0;i<3;i++){
    cin>>a;
    if(a==5) count5++;
    if(a==7) count7++;
  }
  if(count5==2 && count7==1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  

}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}
// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  // ここでストリームに obj を書き込みます。
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << "\n";
  }
  return os;
}


int operator<(vector<int> v1,vector<int> v2){
  rep(i,v1.size())
    if(v1[i]>v2[i]) return 0;
  return 1;
}


string key="keyence";

int main(){
  string s; cin >>s;
  int f=-1;
  rep(i,7){
    if(s[i]!=key[i]){
      f=i;break;
    }
  }
  if(f==-1){
    print("YES");
    return 0;
  }
  int n=s.size();
  //  print(f);
  repa(i,f,7){
    if(s[n-7+i]!=key[i]){
      //      print(s[n-7+i],key[i]);
      f=-1;break;
    }
  }
  if(f==-1){
    print("NO");
    return 0;
  }
  print("YES");
}





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

int main () {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[a.size() - 1] - a[0] << endl;
}

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

def ans() :

    # 整数の入力
    n = int(input())

    b = [int(x) for x in input().split()]

    ans = b[0]

    for i in range(1, n - 1):
        ans += min(b[i - 1], b[i])

    ans += b[-1]
    print(ans)

if __name__ == '__main__':
    ans()

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

using namespace std;

#define REPR(i, n) for(int i = n; i >= 0; i--)

int main() {
    string s;
    cin >> s;
    REPR(i, s.size() - 1) cout << s[i];
    cout << endl;
    return 0;
}

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

int main(int argc, const char * argv[]) {
    ll n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n << endl;
    }else{
        cout << n * 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
a-=1
e=c
f=d
while f>0:
  e,f=f,e%f
x=b//c+b//d-b//(c*d//e)
y=a//c+a//d-a//(c*d//e)
print(b-x-a+y)

Measured memory_bytes: 3060
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

int main()
{
  int N, R, p, c;
  // ???????????????????????¨???????????????                                                                                         
  while(cin >> N >> R && N){
    // ?±±?????????                                                                                                         
    array<int, 50> A;
    for(int i=0; i<N; i++){
      A[i] = N - i;
    }
    // ?????£?????????                                                                                                       
    for(int i=0; i<R; i++){
      cin >> p >> c;
      if(p == 1) continue;
      rotate(begin(A), begin(A) + p - 1, begin(A) + p + c - 1);
    }
    cout << A[0] << endl;
  }
}

Measured memory_bytes: 3084
package main

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

var si = bufio.NewScanner(os.Stdin)

func readInt() int {
        si.Scan()
        r, _ := strconv.Atoi(si.Text())
        return r
}

func main() {
        si.Split(bufio.ScanWords)
        si.Buffer(make([]byte, 0), 10000000)
        N := readInt()
        A := [300][300]int{}
        for i := 0; i < N; i++ {
                for j := 0; j < N; j++ {
                        A[i][j] = readInt()
                }
        }
        B := [300][300]int{}
        ret := 0
        for i := 0; i < N; i++ {
                for j := 0; j < N; j++ {
                        B[i][j] = A[i][j]
                        ret += B[i][j]
                }
        }
        M := [300][300]bool{}
        for k := 0; k < N; k++ {
                for i := 0; i < N; i++ {
                        for j := 0; j < N; j++ {
                                if B[i][j] > B[i][k]+B[k][j] {
                                        fmt.Println(-1)
                                        return
                                }
                                if !M[i][j] && i != k && j != k && B[i][j] == B[i][k]+B[k][j] {
                                        ret -= B[i][j]
                                        M[i][j] = true
                                }
                        }
                }
        }
        fmt.Println(ret / 2)
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll n, y;
	cin >> n >> y;
	if (n * 10000 < y || n * 1000 > y) {
		cout << "-1 -1 -1" << endl;
		return 0;
	}
	ll a, b, c;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			ll k = n - i - j;
			if (k < 0)break;
			a = i * 10000, b = j * 5000, c = k * 1000;
			if (a + b + c == y) {
				cout << i << ' ' << j << ' ' << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}


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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		if(!n)
		cout<<1;
		else
		cout<<0;		
    }
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int count;
    if (s[0] == '1') count = count + 1;
    if (s[1] == '1') count = count + 1;
    if (s[2] == '1') count = count + 1;

    cout << count;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long LL;
const int N=6e3,inf=1e9;
struct edge{
    int to,nxt,cap,cost;
}e[N*10];
int n,cnt=1,head[N],T,iter[N];
LL dist[N],ans;
bool vis[N];
queue<int>q;
inline void addedge(int u,int v,int cost,int cap){
    e[++cnt]=(edge){v,head[u],cap,cost},head[u]=cnt;
    e[++cnt]=(edge){u,head[v],0,-cost},head[v]=cnt;
}
int dfs(int u,int f){
    if(u==T||!f)return f;
    vis[u]=1;
    int ret=0;
    for(int&i=iter[u];i;i=e[i].nxt)
    if(e[i].cap&&!vis[e[i].to]&&dist[e[i].to]==dist[u]+e[i].cost){
        int d=dfs(e[i].to,min(f,e[i].cap));
        e[i].cap-=d,e[i^1].cap+=d,f-=d,ret+=d;
        if(!f)break;
    }
    vis[u]=0;
    return ret;
}
bool MCMF(){
    for(int i=1;i<=T;++i)dist[i]=-1e18;
    for(q.push(0);!q.empty();){
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(int i=head[u];i;i=e[i].nxt)
        if(e[i].cap&&dist[e[i].to]<dist[u]+e[i].cost){
            dist[e[i].to]=dist[u]+e[i].cost;
            if(!vis[e[i].to])
            vis[e[i].to]=1,q.push(e[i].to);
        }
    }
    if(dist[T]<-1e17)return 0;
    memcpy(iter,head,sizeof(int)*(T+2));
    while(int f=dfs(0,inf))ans+=dist[T]*f;
    return 1;
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    T=2*n+9;
    for(int i=1;i<=n;++i){
        int x,y,c;
        cin>>x>>y>>c;
        addedge(0,i,0,c);
        addedge(i,2*n+1,x+y,c);
        addedge(i,2*n+2,x-y,c);
        addedge(i,2*n+3,y-x,c);
        addedge(i,2*n+4,-x-y,c);
    }
    for(int i=n+1;i<=2*n;++i){
        int x,y,c;
        cin>>x>>y>>c;
        addedge(i,T,0,c);
        addedge(2*n+5,i,x+y,c);
        addedge(2*n+6,i,x-y,c);
        addedge(2*n+7,i,y-x,c);
        addedge(2*n+8,i,-x-y,c);
    }
    addedge(2*n+1,2*n+8,0,inf);
    addedge(2*n+2,2*n+7,0,inf);
    addedge(2*n+3,2*n+6,0,inf);
    addedge(2*n+4,2*n+5,0,inf);
    while(MCMF());
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;
 
ll a[202345];
 
int main(){
	int n;
	
	cin >> n;
	
	ll sum = 0;
	
	REP(i,n){
		cin >> a[i];
		
		sum += a[i];
	}
	
	ll ans = INF;
	
	ll x = 0;
	
	REP(i,n){
		x += a[i];
		if (i+1 < n)ans = min( ans, abs(sum - 2*x));
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
lst = list(map(int, input().split()))

flag = 0
tmp = 0
for i in range(1, n + 1):
    if i != lst[i-1]:
        tmp = lst[i-1]
        flag += 1
        if flag > 2:
            print("NO")
            exit()
    

print("YES")
    


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    vector<queue<ll>>que(3);

    vector<string>S(3);
    rep(i,3){
        char c;
        cin>>S[i];
        rep(j,S[i].size()){
            que[i].push(S[i][j]-'a');
        }
       // cout<<que[i].size()<<endl;
    }
    

    ll now=que[0].front();
    que[0].pop();
    while(1){
        //cout<<now<<" "<<que[now].size()<<endl;
        if(que[now].empty()){
            cout<<(char)(now+'A')<<endl;
            return 0;
        }else{
            //cout<<now<<endl;
            ll tmp;
            tmp=que[now].front();
            que[now].pop();
            now=tmp;
            
            
        }
    }
    


    return 0;
    

}

Measured memory_bytes: 3632
import sys

l = []
for input in sys.stdin:
    l.append(input.split())
l = sorted(l)
for i in range(0,len(l)-1):
    for j in range(i+1,len(l)):
        if(l[i][0] == l[j][0]):
            l[i].append(l[j][1])
res = []
for i in range(0,len(l)):
    if(l[i][0] == l[i-1][0]):
        continue
    res.append(l[i])
for i in range(0,len(res)):
    print res[i][0]
    temp = []
    for j in range(1,len(res[i])):
        temp.append(int(res[i][j]))
    temp = sorted(temp)
    for j in range(0,len(temp)):
        print temp[j],
    print



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

int main()
{
  int n;
  scanf("%d", &n);
  n = n % 10;
  if(n == 3)
    printf("bon\n");
  else if((n == 1) || (n == 0) || (n == 6) || (n == 8))
    printf("pon\n");
  else
    printf("hon\n");
  return 0;
}

Measured memory_bytes: 3760
//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    while(a >= b)
    {
        b*=2;
        ans++;
    }
    while(b >= c)
    {
        c*=2;
        ans++;
    }
    if(ans > k)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3632
n = int(input())

arr = list(map(int, input().split()))

all_xor = arr[0]

for i in range(1, n):
	all_xor ^= arr[i]

res = [0 for i in range(n)]

for i in range(n):
	res[i] = all_xor ^ arr[i]

print(" ".join(list(map(str, res))))

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

typedef pair <int, int> ii;

const int Maxn = 100005;

int n, k;
string s;
vector <ii> seq;
int cur, len;
int res;

int main()
{
    scanf("%d %d", &n, &k);
    cin >> s;
    for (int i = 0, j; i < n; i = j) {
        j = i;
        while (j < n && s[i] == s[j]) j++;
        seq.push_back(ii(s[i] - '0', j - i));
    }
    int lef = 0;
    for (int rig = 0; rig < seq.size(); rig++) {
        cur += !seq[rig].first; len += seq[rig].second;
        while (cur > k) {
            cur -= !seq[lef].first; len -= seq[lef].second;
            lef++;
        }
        res = max(res, len);
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 1528
def main():
    X, N = map(int, input().split())
    *P, = map(int, input().split())

    B = [0] * (400 + 1)
    for i in P:
        B[i] += 1

    d = 0
    while True:
        if not B[X - d]:
            print(X - d)
            return

        if not B[X + d]:
            print(X + d)
            return

        d += 1


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9184
module Main where

import Data.List

main = putStrLn =<< solve <$> readInts

readInts :: IO [Int]
readInts = (sort . (map read) . words) <$> getLine

solve :: [Int] -> String
solve [a, b, c]
    | a /= b && b /= c = "No"
    | a == c = "No"
    | otherwise = "Yes"


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    REP(i, H) cin >> S[i];

    int N = H*W;
    vector<vector<int>> D(N, vector<int>(N, 1<<20));
    REP(i, N) D[i][i] = 0;

    REP(i, H) REP(j, W) REP(k, 4) {
        if(S[i][j] == '#') continue;
        int y = i + dy[k];
        int x = j + dx[k];
        if(y < 0 || H <= y) continue;
        if(x < 0 || W <= x) continue;
        if(S[y][x] == '#') continue;

        int z0 = W*i+j;
        int z1 = W*y+x;
        D[z0][z1] = D[z1][z0] = 1;
    }
    REP(k, N) REP(i, N) REP(j, N)
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);

    int ans = 0;
    REP(i, N) REP(j, N)
        if(D[i][j] < (1<<20))
            ans = max(ans, D[i][j]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9 + 7);

int ok1[100000];
ll h1[100000];
int ok2[100000];
ll h2[100000];


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

	int N;
	cin >> N;
	vector<int> T(N), A(N);
	for(int i = 0; i < N; i++) {
		cin >> T[i];
	}
	for(int i = 0; i < N; i++) {
		cin >> A[i];
	}

	fill(h1, h1 + N, (ll)1e9 + 10);
	fill(h2, h2 + N, (ll)1e9 + 10);

	ll x = 0;
	for(int i = 0; i < N; i++) {
		if(x < T[i]) {
			x = T[i];
			ok1[i] = 1;
			h1[i] = x;
		}
		else if(x > T[i]) {
			cout << 0 << endl;
			return 0;
		}
		else {
			h1[i] = min(h1[i], x);
		}
	}
	x = 0;
	for(int i = N - 1; i >= 0; i--) {
		if(x < A[i]) {
			x = A[i];
			ok2[i] = 1;
			h2[i] = x;
		}
		else if(x > A[i]) {
			cout << 0 << endl;
			return 0;
		}
		else {
			h2[i] = min(h2[i], x);
		}
	}

	ll ans = 1;
	for(int i = 0; i < N; i++) {
		if(ok1[i] && ok2[i]) {
			if(h1[i] != h2[i]) {
				ans = 0;
				break;
			}
		}
		else if(ok1[i] && !ok2[i]) {
			if(h1[i] > h2[i]) {
				ans = 0;
				break;
			}
		}
		else if(!ok1[i] && ok2[i]) {
			if(h2[i] > h1[i]) {
				ans = 0;
				break;
			}
		}
		else {
			ans = ans * min(h1[i], h2[i]) % MOD;
		}
	}
	cout << ans << endl;
}

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

int main(int argc, char **argv)
{
	string str; cin >> str;
	int N = str.size();
	int c0{0}, c1{0};
	for (int i = 0; i < N; ++i)
	{
		if (str[i] == '0')
			++c0;
		else
			++c1;
	}
	std::cout << 2*min(c0, c1) << std::endl;
}

Measured memory_bytes: 512
N,M = map(int,input().split())
# 問題はM//N>xを満たすようなMの約数xの中で最小のものと読み替えられる。
bdr = M//N
ans = 1

for i in range(1,int(M**0.5+1)):
    if M%i==0:
        yakusu = M//i
        if yakusu<=bdr:
            ans = yakusu
            break
        elif i <= bdr:
            ans = i
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <utility>
using namespace std;
using ll = long long;

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

  bool f = false;
  for(int i=0; 4 * i <= n; i++){
    if((n-4 * i) % 7 == 0){
      f = true;
    }
  }

  cout << (f? "Yes" : "No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))



int main(){
  int sum = 0, mx = 0, n, a[2160];
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    sum += a[i];
    mx = max(a[i], mx);
  }
  bitset<2160000> bs;
  bs.set(0);

  for(int i = 0;i < n;i++){
    bs |= bs << a[i];
  }

  for(int i = sum / 2 + sum % 2;;i++){
    if(bs[i]){
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  vector<pair<int, int>> q(m);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    b[i] = a[i];
  for (int i = 0; i < m; i++)
    cin >> q[i].first >> q[i].second;
  for (int i = 0; i < m; i++) {
    int pos = q[i].first - 1;
    q[i].first = b[pos];
    b[pos] = q[i].second;
    q[i].first--;
    q[i].second--;
  }
  vector<int> v(n), w(n);
  for (int i = 0; i < n; i++) {
    v[a[i] - 1]++;
    if (a[i] - v[a[i] - 1] >= 0)
      w[a[i] - v[a[i] - 1]]++;
  }

  int moves = 0;
  for (int i = 0; i < n; i++)
    if (w[i] == 0)
      moves++;

  for (int i = 0; i < m; i++) {
    int bef = q[i].first, aft = q[i].second;
    if (bef - v[bef] + 1 >= 0) {
      w[bef - v[bef] + 1]--;
      if (w[bef - v[bef] + 1] == 0) {
        moves++;
      }
    }
    v[bef]--;
    v[aft]++;
    if (aft - v[aft] + 1 >= 0) {
      w[aft - v[aft] + 1]++;
      if (w[aft - v[aft] + 1] == 1) {
        moves--;
      }
    }
    cout << moves << endl;
  }
  return 0;
}


Measured memory_bytes: 6144
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int ans = h * w;
        ans -= x * w;
        ans -= (h - x) * y;
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

  sort(all(a));
  int a1 = a.back(), a2 = a1 - a.front();
  int x = a1 / 2;
  for (int i = 0; i < n - 1; i ++) {
    if (abs(x - a[i]) <= abs(x - a2)) a2 = a[i];
  }

  cout << a1 << " " << a2 << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1000000000)
mod = 10**9+7
N, K = map(int, input().split())
edge = [[] for _ in range(N)]
flag = [False]*N
flag[0] = True
for i in range(N-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
P = [1]*(K+10)
T = [1]*(K+10)
for i in range(1, K+10):
    P[i] = (P[i-1]*(K-i))%mod
    T[i] = T[i-1]*(K-i-1)%mod
def count(x):
    flag[x]=True
    res = 1
    l = len(edge[x])-1
        
    for e in edge[x]:
        if flag[e]:
            continue
        res*=count(e)
    if x==0:
        if l+1> K-1:
            return 0
        return res*K*P[l+1]%mod
    if l>K-2:
        return 0
    return res*T[l]%mod
print(count(0))


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	for(int i=1;i<=600;i++){
		int v=i*n;
		if(v%360==0){
			cout << i << "\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x;
  cin>>a>>b>>x;
  int v=a*a*b/2;
  double te;
  if(x>=v){
    te=atan(double(2*(a*a*b-x))/(a*a*a));
  }else{
    te=atan(double(a*b*b)/(2*x));
  }
  cout<<setprecision(10)<<double(te*180)/M_PI<<endl;
}

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

int main()
{
	int n;
	cin >> n;
	string ans = "APPROVED";
	for (int i=0; i<n; i++)
	{
		int in;
		cin >> in;
		if (in % 2 == 0)
		{
			if (in % 3 != 0 && in % 5 != 0)
			{
				ans = "DENIED";
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

vector<bool> IsPrime;

void PrimeTable(int N){
    IsPrime = vector<bool>(N+1, true);
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(int i=2; i*i<=N; ++i){
        if(IsPrime[i]){
            for(int j=2; i*j<=N; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

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

    int N;
    cin >> N;
    PrimeTable(55555);
    int ct = 0;
    FOR(i, 1, 55556){
        if(IsPrime[i] && i%5 == 1){
            cout << i;
            if(++ct == N){
                cout << "\n";
                break;
            }else{
                cout << " ";
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	ll ans=0;
	ll n; cin>>n;
	rep(i,0,n){
		ll a; cin>>a;
		if(a%2==0){
			ll cnt=0;
			while(a%2==0){
				a/=2;
				cnt++;
			}
			ans+=cnt;
		}
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
 
#include <stdio.h>
#include <string.h>
 
 
using namespace std;
 
int main(int argc, char* argv[])
{

	int A,B;

	cin >> A >> B;

	cout << (A+B < 10 ? to_string(A+B) : "error") << endl;

	return 0;

}


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

int main() {
  int a,b,c;
  cin >> a>> b >> c;
  if(a==b&&a!=c)cout<<"Yes"<<endl;
  else if(b==c&&a!=c)cout<<"Yes"<<endl;
  else if(a==c&&a!=b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
struct P{
    int a;
    long long b;
    P(){}
    P(int a, long long b) : a(a), b(b){}
};
int m;
P mem[10][11];
vector<int> rem;
P f(int x, int y){
    if(y == 1) return P(x, 0);
    if(mem[x][y].a != -1) return mem[x][y];
    P res = f(x, y-1);
    res.a += x;
    res.b++;
    if(res.a >= 10){
        res.a -= 9;
        res.b++;
    }
    return mem[x][y] = res;
}

P add(P x, P y){
    P res = x;
    res.a += y.a;
    res.b += y.b;
    res.b++;
    if(res.a >= 10){
        res.a -= 9;
        res.b++;
    }
    return res;
}

P g(int x, long long y){
    if(y <= 10) return f(x, y);
    P v = f(x, 10);
    P res = g(v.a , y/10);
    res.b += v.b * (y/10);
    if(y%10 > 0){
        res = add(res, f(x, y%10));
    }

    return res;
}



int main(void){
    cin >> m;
    for(int i=0;i<10;i++){
        for(int j=0;j<11;j++){
            mem[i][j] = P(-1, -1);
        }
    }
    for(int i=1;i<10;i++){
        for(int j=1;j<11;j++){
            P v = f(i, j);
            //cout << i << ", " << j << " : " << v.a << " " << v.b << endl;

        }
    }

    int d;
    long long c;
    cin >> d >> c;
    P ans = g(d, c);
    for(int i=1;i<m;i++){
        cin >> d >> c;
        if(d == 0){
            ans.b += c;
            continue;
        }
        P p = g(d, c);
        ans = add(ans, p);
    }

    cout << ans.b << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int input;

    while (cin >> input) {
        for (int i = 0; i < 10; i++) {
            if (input & 1) {
                cout << (1 << i);
                if (input >> 1)
                    cout << " ";
            }
            input >>= 1;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
// by DenyTianly
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>

using namespace std;

#define iScf(n) scanf("%d", &n)
#define dug() printf("ok!\n")
#define iNxtL() puts("")
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define nrep(i, val, n) for(int i = val; i < n; i++)
#define ipq priority_queue
typedef long long LL;
typedef unsigned long long ULL;

const int inf = 1 << 26;
const LL INF = 1LL << 60;

inline void quick_IO() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); }
inline int read(){
	int x = 0, f = 1;
	char ch = getchar();

	for(; ch < '0' || ch > '9'; ch = getchar())
		if(ch == '-') f = -f;

	for(; ch >= '0' && ch <= '9'; ch = getchar())
		x = x*10+ch-'0';

	return x*f;
}

// Don't hack me, please ~
// #define _Isopen_File_
// #define _Is_Close_STD_

int main(){

#ifdef _Isopen_File_
	freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
#endif

#ifdef _Is_Close_STD_
	ios::sync_with_stdio(false);
	cin.tie(0);
#endif

	int a, b;
	scanf("%d %d", &a, &b);
	if(a!=1&&b!=1){
		if(a==b)puts("Draw");
		if(a<b) puts("Bob");
		if(a>b) puts("Alice");
	} else {
		if(a==1){
			if(b!=1) puts("Alice");
			if(b==1) puts("Draw");
		}else if(b==1){
			if(a!=1) puts("Bob");
			else puts("Draw");
		}
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a > b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        System.out.println(Math.max(b - a - w, 0));
    }
}

Measured memory_bytes: 21716
//Register Phase
#include <iostream>

using namespace std;

int main(){
	char pass[21];
	bool IsEnough = true;
	bool ENum = false, ECap = false, ESml = false;

	cin >> pass;
	for (int i = 0; i < 21; ++i){
		if (pass[i] == '\0'){
			if (i < 6)IsEnough = false;
			break;
		} else{
			if ('0' <= pass[i] && pass[i] <= '9')ENum = true;
			if ('A' <= pass[i] && pass[i] <= 'Z')ECap = true;
			if ('a' <= pass[i] && pass[i] <= 'z')ESml = true;
		}
	}
	cout << ((IsEnough && ENum && ECap && ESml) ? "VALID" : "INVALID") << endl;

	return 0;
}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
#define mx 100000
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll a,b;
    while(cin>>a){
    cout<<pow(a,3)<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;


int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	unordered_map<int, unordered_map<int, int>> um;
	for (int i = 1; i <= n; i++) {
		string s = to_string(i);
		um[s[0] - '0'][s[s.size() - 1] - '0']++;
	}

	long long int res = 0;
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			res += um[i][j] * um[j][i];
		}
	}
	cout << res << endl;
}









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

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

   vector<ll> x(N + 1);
   rep(i, 0, N) cin >> x.at(i + 1);

   int r, l;
   ll ans = 10000000000;

   for (l = 1; l + K - 1 <= N; l++) {
     ans = min(ans, min(abs(x.at(l)), abs(x.at(l + K - 1))) + abs(x.at(l + K - 1) - x.at(l)));
   }

   cout << ans << endl;
 }


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;

long long F(long long  A, long long B){
    long ta = A, tb = B;
    long ca = 0, cb = 0;
    for(long i = 0; i < 10; i++){
        if(ta != 0) ca++;
        if(tb != 0) cb++;
        ta /= 10;
        tb /= 10;
    }
    return ca > cb ? ca : cb;
}

int main() {
    long long N;
    cin >> N;
    long long ans = 10;
    for(long long i = 1; i <= sqrt(N); i++){
        if(N % i == 0) {
            ans = min(ans, F(i, N/i));
        }
    }
    cout << ans << endl;
}







Measured memory_bytes: 3684
#include <iostream>
#include <cmath>
using namespace std;
int n;
int num[10000];

bool isprime(int x) {
	if (x == 2) return true;		//2????´???°
	if (x < 2 || x % 2 == 0) return false;	//????????°
	int i = 3;
	while (i <= (int)sqrt((int)x)) {
		if (x % i == 0) return false;
		i = i + 2;
	}
	return true;
}

int main() {
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> num[i];
	for (int i = 0; i < n; i++) {
		if (isprime(num[i])) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

//block linked list
#define Bsize 700 /*2sqrt(n)*/
typedef struct block{
	int cnt;
	ll a[Bsize+1];
	struct block*pre;
	struct block*nxt;
}block;
void Bpush(block*b,ll x){
	//リストにxを追加する
	if((*b).nxt&&(*(*b).nxt).a[0]<x){
		//次へ
		Bpush((*b).nxt,x);
		return;
	}
	int i=(*b).cnt;
	for(;i>0&&(*b).a[i-1]>x;i--)(*b).a[i]=(*b).a[i-1];
	(*b).a[i]=x;
	(*b).cnt++;
	if((*b).cnt>=Bsize){
		//分割
		block*nn=(block*)malloc(sizeof(block));
		(*nn).cnt=Bsize-Bsize/2;
		rep(i,0,Bsize-Bsize/2)(*nn).a[i]=(*b).a[i+Bsize/2];
		(*nn).pre=b;
		(*nn).nxt=(*b).nxt;
		if((*b).nxt)(*(*b).nxt).pre=nn;
		(*b).cnt=Bsize/2;
		(*b).nxt=nn;
	}
}
void con(block*p,block*q){
	//qをpにマージしてqを消す
	rep(i,0,(*q).cnt)(*p).a[(*p).cnt+i]=(*q).a[i];
	(*p).cnt+=(*q).cnt;
	(*p).nxt=(*q).nxt;
	if((*q).nxt)(*(*q).nxt).pre=p;
	free(q);
}
void Bdel(block*b,int idx){
	//idx番目を削除する(必ずidx個以上ある)
	for(;idx<(*b).cnt-1;idx++)(*b).a[idx]=(*b).a[idx+1];
	(*b).cnt--;
	 
	if((*b).cnt==0&&(*b).pre)con((*b).pre,b);
	else if((*b).pre&&(*(*b).pre).cnt+(*b).cnt<Bsize/4)con((*b).pre,b);
	else if((*b).nxt&&(*(*b).nxt).cnt+(*b).cnt<Bsize/4)con(b,(*b).nxt);
}

ll Bans(block*b,int k,int flag){
	//リストのk番目を返す
	//リストにk個未満しかなければ適当に返す
	//flagがtrueなら削除する
	if((*b).cnt<=k){
		if((*b).nxt)return Bans((*b).nxt,k-(*b).cnt,flag);
		else return -1;//<-例外
	}
	ll ans=(*b).a[k];
	if(flag)Bdel(b,k);
	return ans;
}
int Bfind(block*b,ll k,int flag){
	//リストにkが存在すれか答える
	//flagがtrueなら削除する
	if((*b).cnt==0||(*b).a[(*b).cnt-1]<k){
		if((*b).nxt)return Bfind((*b).nxt,k,flag);
		else return 0;
	}
	int i=0;
	for(;(*b).a[i]<k;i++);
	if((*b).a[i]!=k)return 0;
	if(flag)Bdel(b,i);
	return 1;
}
void Bdump(block*b,ll l,ll r){
	if((*b).cnt==0){
		if((*b).nxt)Bdump((*b).nxt,l,r);
	}else if((*b).a[0]>r)return;
	else if((*b).a[(*b).cnt-1]<l){
		if((*b).nxt)Bdump((*b).nxt,l,r);
	}
	else{
		rep(i,0,(*b).cnt)if(l<=(*b).a[i]&&(*b).a[i]<=r)printf("%lld\n",(*b).a[i]);
		if((*b).a[(*b).cnt-1]<=r&&(*b).nxt)Bdump((*b).nxt,l,r);
	}
}
#undef Bsize


block*b;
int main(){
	b=calloc(1,sizeof(block));
	int q;
	scanf("%d",&q);
	int cnt=0;
	while(q--){
		int t,x;
		scanf("%d%d",&t,&x);
		if(t==0){
			if(!Bfind(b,x,0)){
				Bpush(b,x);
				cnt++;
			}
			printf("%d\n",cnt);
		}else if(t==1){
			printf("%d\n",Bfind(b,x,0));
		}else if(t==2){
			if(Bfind(b,x,1))cnt--;
		}else{
			int y;
			scanf("%d",&y);
			Bdump(b,x,y);
		}
	}
}


Measured memory_bytes: 4888
# AOJ 0567: Best Pizza
# Python3 2018.6.30 bal4u

n = int(input())
a, b = map(int, input().split())
c = int(input())
ans, p = c/a, a
d = [int(input()) for i in range(n)]
d.sort(reverse=True)
for i in range(n):
	t = (c+d[i])/(p+b)
	if t > ans:
		ans = t
		c += d[i]
		p += b
	else: break;
print(int(ans))


Measured memory_bytes: 5604
// grid-1.rs --- Grid-1
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

pub struct Combination {
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
    modulo: usize,
}

impl Combination {
    pub fn new(max: usize, modulo: usize) -> Combination {
        let mut inv = vec![0; max + 1];
        let mut fact = vec![0; max + 1];
        let mut inv_fact = vec![0; max + 1];
        inv[1] = 1;
        for i in 2..(max + 1) {
            inv[i] = inv[modulo % i] * (modulo - modulo / i) % modulo;
        }
        fact[0] = 1;
        inv_fact[0] = 1;
        for i in 0..max {
            fact[i + 1] = fact[i] * (i + 1) % modulo;
        }
        for i in 0..max {
            inv_fact[i + 1] = inv_fact[i] * inv[i + 1] % modulo;
        }
        Combination {
            fact: fact,
            inv_fact: inv_fact,
            modulo: modulo,
        }
    }

    pub fn get(&self, x: usize, y: usize) -> usize {
        assert!(x >= y);
        self.fact[x] * self.inv_fact[y] % self.modulo * self.inv_fact[x - y] % self.modulo
    }

    pub fn h(&self, n: usize, r: usize) -> usize {
        self.get(n + r - 1, r)
    }
}

fn main() {
    input! {
        h: usize,
        w: usize,
        map: [chars; h],
    };

    let mut dp = vec![vec![0; w + 1]; h + 1];

    for i in (0..h).rev() {
        for j in (0..w).rev() {
            dp[i][j] = if i == h - 1 && j == w - 1 {
                1u64
            } else if map[i][j] == '#' {
                0u64
            } else {
                (dp[i + 1][j] + dp[i][j + 1]) % 1_000_000_007
            }
        }
    }

    let ans = dp[0][0];
    println!("{}", ans);
}


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

int k,s,cnt=0;

int main()
{
    cin>>k>>s;
    for(int x=0;x<=k;x++)
    {
        for(int y=0;y<=k;y++)
        {
            if(s-x-y>=0&&s-x-y<=k) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui A{}, B{}, C{}; cin >> A >> B >> C;
  bool res{0};
  for(ui n = 1; n < B; ++n)
  {
    if(A * n % B == C) res = true;
  }
  cout << (res ? "YES" : "NO") << CRLF;

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256