akhauriyash/Code-Regression huggingface dataset:
from itertools import count, takewhile

def dfs(n:int, d={}) -> int:
    if n<6:
        return n
    
    if n in d:
        return d[n]
    
    max9 = max(takewhile(lambda x: x<=n, (9**i for i in count())))
    max6 = max(takewhile(lambda x: x<=n, (6**i for i in count())))
    
    d[n] = min(dfs(n-max9), dfs(n-max6))+1
    
    return d[n]

print(dfs(int(input())))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
 int n,k;
  cin >> n >> k;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  
  sort(a,a+n,greater<int>());
  
  int res=0;
  for(int i=0;i<k;i++) res+=a[i]; 
 
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.size()&1){
		cout<<"No"<<endl;
		return 0;
	}else{
		for(int i=0;i<s.size();i+=2){
			if(s[i]!='h'||s[i+1]!='i'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=15;
const int maxa=1<<15;
const int inf=0x3f3f3f3f;
int n,m,f[maxn][maxa],g[maxa],e[maxn][maxn];
int main()
{
	scanf("%d%d",&n,&m);
	int x,y,w,sum=0;
	for(int i=0;i<m;i++)
		scanf("%d%d%d",&x,&y,&w),x--,y--,e[x][y]=e[y][x]=w,sum+=w;
	memset(g,inf,sizeof(g));
	g[0]=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<(1<<n);j++)
			if(g[j]!=inf && !(j&(1<<i)))
			{
				int val=0;
				for(int k=0;k<n;k++)
					if(j&(1<<k)) val+=e[i][k];
				g[j|(1<<i)]=g[j]+val;
			}
	memset(f,-1,sizeof(f));
	for(int i=0;i<(1<<n);i++)
		if(i&1) f[0][i]=g[i];
	for(int i=1;i<(1<<n);i++)
		for(int j=0;j<n;j++)
			if(i&(1<<j) && f[j][i]!=-1)
				for(int k=i^((1<<n)-1),t=k;k>=0;k=k?(k-1)&t:-1)
					for(int l=0;l<n;l++)
						if(!(i&(1<<l)) && (k&(1<<l)) && e[j][l])
							f[l][i|k]=max(f[l][i|k],f[j][i]+g[k]+e[j][l]);
	printf("%d\n",sum-f[n-1][(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 5824
import sys
input = sys.stdin.readline
N = int(input())

full = 0
for x in range(1, N+1):
	full += x * (N-x+1)

for _ in range(N-1):
	a, b = map(lambda s: int(s)-1, input().split())
	if b < a: a, b = b, a

	full -= (a+1) * (N-b)

print(full)


Measured memory_bytes: 68524
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int n,t=0,x=0,y=0,tt,tx,ty,flag=0;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d%d",&tt,&tx,&ty);
        if(abs(tx-x)+abs(ty-y)>(tt-t)||abs((abs(tx-x)+abs(ty-y))-(tt-t))%2!=0)
            flag=1;
        t=tt,x=tx,y=ty;
    }
    if(flag)printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool isLeap(int y){
	if(y % 400 == 0) return true;
	if(y % 100 == 0) return false;
	if(y % 4 == 0) return true;
	return false;
}

int main(){
	int a, b;
	bool f = false;
	while(true){
		cin >> a >> b ;
		if(a == 0 && b == 0) return 0;

		if(f) { cout << endl; }
		f = false;
		for (int i = a; i < b + 1; i++){
			if(isLeap(i)) {
				cout << i << endl;
				f = true;
			}
		}
		if(!f) { cout << "NA" << endl; f = true;}
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
//import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
//		int i,j;
		Scanner sc = new Scanner(in);
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		sc.close();
		out.println(a[a.length-1]==b[0]&&b[b.length-1]==c[0]?"YES":"NO");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
   ll A,B,C,X,Y;
   cin>>A>>B>>C>>X>>Y;
   ll ans=0;
   if(C*2<A+B){
       if(Y<X){
           ans+=C*2*Y;
           ans+=min(A,C*2)*(X-Y);
       }
       else{
           ans+=C*2*X;
           ans+=min(C*2,B)*(Y-X);
       }
   }
   else{
       ans=A*X+B*Y;
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

vi to[MX];

vi dp[MX];
void dfs(int v, int p=-1) {
  if (sz(to[v]) == 1) {
    dp[v][0] = 0;
    dp[v][1] = dp[v][2] = 1;
    return;
  }
  int s0 = 0;
  int s1 = 0;
  int s2 = 0;
  int cnt = 0;
  int mx = 0;
  rep(i,sz(to[v])) {
    int u = to[v][i];
    if (u == p) continue;
    dfs(u,v);
    s0 += dp[u][0];
    s1 += dp[u][1];
    s2 += dp[u][2];
    maxs(mx, dp[u][1]-dp[u][0]);
    cnt++;
  }
  // cout<<v<<" "<<s0<<" "<<s1<<" "<<s2<<endl;
  if (cnt == 1) {
    dp[v][0] = s0;
    dp[v][1] = min(s0+1, s1);
    dp[v][2] = min(s0+1, s2);
  } else {
    dp[v][2] = min(s1+1, s2);
    dp[v][1] = min(dp[v][2], s1-mx);
    dp[v][0] = dp[v][1];
  }
  // cout<<v<<" "<<dp[v]<<endl;
}

int main() {
  int n;
  scanf("%d",&n);
  rep(i,n-1) {
    int a,b;
    scanf("%d%d",&a,&b);
    to[a].pb(b);
    to[b].pb(a);
  }
  rep(i,n) dp[i] = vi(3,INF);
  int root = -1;
  rep(i,n) if (sz(to[i]) > 2) root = i;
  if (root == -1) {
    cout<<1<<endl;
    return 0;
  }
  dfs(root);
  int ans = dp[root][1];
  cout<<ans<<endl;
  return 0;
}






















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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

ll a,b,c;
ll ans;

void input(){
	cin>>a>>b>>c;
	return;
}

void solve(){
	if(a+b>=c)cout<<b+c<<endl;
	else {
		ll sum=a+b*2;
		if(c-a-b>0)sum++;
		cout<<sum<<endl;
	}
	return;
}

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

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

using namespace std;

int main(){
    int i,j,ans;
    ans = 1e5;//100000
    string s,t;
    cin>>s>>t;
    int flag = 0;
    for(i = 0; i < (int)s.size(); i++){
            int count = 0;
           for(j=0; j < (int)t.size();j++){ 
                if(i+j >= (int)s.size()){
                    flag = 1;
                    break;
                } 
                if(t[j] != s[i+j])count++;
            }
            if(flag == 1)
                break;
            ans = min(ans,count);
            
        }
    cout<<ans;

}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1e9+7;

int main(){
    string s;
    cin >>s;
    int n = s.size();

    vector<ll> pw(n+1);
    pw[0] = 1;
    rep(i,n) pw[i+1] = pw[i]*3%mod;

    int q = 0;
    rep(i,n) q += (s[i]=='?');

    // 0:CHAR, 1:'?' (A:pre, C:suf)
    ll a[2]={0,0}, c[2]={0,q};
    rep(i,n) c[0] += (s[i]=='C');

    ll ans = 0;
    rep(i,n){
        if(s[i]=='?') --c[1];
        if(s[i]=='C') --c[0];

        if(s[i]=='B' || s[i]=='?'){
            rep(j,2)rep(k,2){
                int qq = q-j-k-(s[i]=='?');
                if(qq<0) continue;

                ll add = a[j]*c[k]%mod;
                (add *= pw[qq]) %= mod;
                (ans += add) %= mod;
            }
        }

        if(s[i]=='?') ++a[1];
        if(s[i]=='A') ++a[0];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    if(len(s) < len(t)){
        cout << "UNRESTORABLE\n";
        return 0;
    }
    rrep(i,len(s)-len(t)+1){
        bool flag = true;
        rep(j,len(t)){
            if(s[i+j] != '?' && s[i+j] != t[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            rep(j,i){
                if(s[j] == '?'){
                    s[j] = 'a';
                }
            }
            rep(j,len(t)){
                s[i+j] = t[j];
            }
            srep(j,i+len(t),len(s)){
                if(s[j] == '?'){
                    s[j] = 'a';
                }
            }
            cout << s << "\n";
            return 0;
        }
    }
    cout << "UNRESTORABLE\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

int main() {
  string S; cin>>S;
  if(S=="SUN"){
    cout<<"7"<<endl;
  }
  if(S=="MON"){
    cout<<"6"<<endl;
  }
  if(S=="TUE"){
    cout<<"5"<<endl;
  }
  if(S=="WED"){
    cout<<"4"<<endl;
  }
  if(S=="THU"){
    cout<<"3"<<endl;
  }
  if(S=="FRI"){
    cout<<"2"<<endl;
  }
  if(S=="SAT"){
    cout<<"1"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)


int main() {
    int N, H[110000];
    cin >> N;
    rep(i,N) cin >> H[i];

    int count = 0;
    int maxcnt = 0;
    rep(i,N-1) {
        if (H[i] >= H[i+1]) {
            ++count;
            if (count > maxcnt) {
                maxcnt = count;
            }
        } else {
            count = 0;
        }
    }

    cout << maxcnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k;
int a,b,fn(0);
cin>>k>>a>>b;
for(int i=a; i<=b; ++i)
{
if(i%k==0)
{
fn=1;
break;
}
}
if(fn)
cout<<"OK";
else
cout<<"NG";
}


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

using namespace std;

using ll = long long;

struct Seg {
private:
    int n;
    vector<ll> tree, lazy; 

    inline void flush(int no, int l, int r) {
        if (l != r) {
            lazy[no*2] += lazy[no];
            lazy[no*2+1] += lazy[no];
        }
        tree[no] += lazy[no];
        lazy[no] = 0;
    }

    void upd(int no, int l, int r, int a, int b, ll val) {
        flush(no, l, r);
        if (a <= l and r <= b) {
            lazy[no] += val;
            return;
        }

        int m = (l+r)/2;

        if (a <= m) upd(no*2, l, m, a, b, val);
        if (b > m) upd(no*2+1, m+1, r, a, b, val);

        flush(no*2, l, m);
        flush(no*2+1, m+1, r);

        tree[no] = max(tree[no*2], tree[no*2+1]);
    }

    ll get(int no, int l, int r, int a, int b) {
        flush(no, l, r);
        if (a <= l and r <= b) {
            return tree[no];
        }

        int m = (l+r)/2;

        if (b <= m) return get(no*2, l, m, a, b);
        if (a > m) return get(no*2+1, m+1, r, a, b);

        return max(
            get(no*2, l, m, a, b),
            get(no*2+1, m+1, r, a, b)
        );
    }

public:
    Seg(int n) : n(n), tree(n*4), lazy(n*4) {};

    void upd(int a, int b, ll val) {
        upd(1, 1, n, a, b, val);
    }

    ll get(int a, int b) {
        return get(1, 1, n, a, b);
    }
};

struct Interval {
    int l, r, w;

    bool operator<(Interval const& rhs) const {
        return l < rhs.l;
    }
};

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;

    vector<Interval> v(m);

    for (auto& i : v) {
        cin >> i.l >> i.r >> i.w;
    }

    sort(v.begin(), v.end());

    int at = m-1;
    vector<ll> dp(n+1);
    Seg seg(n+1);

    for (int i = n; i >= 0; i--) {
        dp[i] = seg.get(i+1, n+1);

        if (i != 0) {
            seg.upd(i, i, dp[i]);
        }

        while (at >= 0 and v[at].l >= i) {
            seg.upd(v[at].l, v[at].r, v[at].w);
            at--;
        }
    }

    cout << dp[0] << "\n";
}

Measured memory_bytes: 16640
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
c = gets.chomp.split(" ").map(&:to_i)

sum = 0
past_number = n + 1
a.each do |number|
  sum += b[number - 1]
  sum += c[number - 2] if number - past_number == 1
  past_number = number
end

puts sum

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <set>

using namespace std;

void failure () {
  cout << "No" << endl;
  exit(0);
}

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

  set<char> cs;
  for (char c : s) {
    cs.insert(c);
  }

  if (!!cs.count('N') != !!cs.count('S')) failure();
  if (!!cs.count('E') != !!cs.count('W')) failure();
  cout << "Yes" << endl;
}


Measured memory_bytes: 3616
N,M,V,P=map(int, input().split())
*A,=map(int, input().split())

A.sort()
Ax = A[-P]  #上位Pの中の最下位

def f(i):
    mine = A[i] + M #自分に全力で投票
    if mine < Ax: return False #逆転不能
    votes = M*V
    votes -= M #自分への票
    votes -= min(P-1, V) * M #上位陣のx以外に全力で投票
    votes -= sum([min(mine - A[j], M) for j in range(N-P+1) if i!=j]) #逆転されない程度に下位陣に投票
    if votes > 0 : return False #再逆転される
    return True

under = -1
r = N-P
while r-under>1:
    m = (r+under)//2
    if f(m): r=m
    else: under=m

print(N-r)


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

int main(){
	int n;
	while( scanf(" %d", &n) != EOF ){
		int use[10]={0};
		int count=0, m=0;
		for(int i=9; i>=0; --i){
			if(n >= (int)pow(2.0, i)){
				use[i]=1;
				n-=(int)pow(2.0, i);
				++count;
			}
		}
				
		for(int i=0; i<10; ++i){
			if(use[i]==1){
				printf("%d", (int)pow(2.0, i));
				if(m<count-1){
					printf(" ");
					++m;
				}
			}
		} 
	
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1196
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: i32 = itr.next().unwrap().parse().unwrap();
    let b: i32 = itr.next().unwrap().parse().unwrap();
    println!("{}", max(a + b, max(a - b, a * b)))
}


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

int main(void)
{
  double max = 0;
  double min = 10000000000000;
  
  while (true)
  {
    double height;
    cin >> height;
    if ( cin.eof() ) break;

    if (max < height)
    {
      max = height;
    }
    if (min > height)
    {
      min = height;
    }
  }
  cout << max - min << endl;
}

Measured memory_bytes: 1280
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    double xs, ys, xt, yt;
    ll N;
    cin >> xs >> ys >> xt >> yt >> N;

    N += 2;

    vector<double> x(N), y(N), r(N);
    for (ll i = 0; i < N - 2; i++) {
        cin >> x[i] >> y[i] >> r[i];
    }
    x[N - 2] = xs;
    y[N - 2] = ys;
    x[N - 1] = xt;
    y[N - 1] = yt;
    r[N - 2] = r[N - 1] = 0.0;

    constexpr double INF = 1e10;
    vector<vector<double>> edges(N, vector<double>(N, INF));
    for (ll i = 0; i < N; i++) {
        for (ll j = i; j < N; j++) {
            double d = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
            edges[i][j] = edges[j][i] = max(d - r[i] - r[j], 0.0);
        }
    }

    //ダイクストラ
    vector<double> cost(N, INF);
    struct Element {
        ll node;
        double cost;
        bool operator<(const Element& rhs) const {
            return cost < rhs.cost;
        }
        bool operator>(const Element& rhs) const {
            return cost > rhs.cost;
        }
    };
    priority_queue<Element, vector<Element>, greater<Element>> pq;

    cost[N - 2] = 0;
    pq.push({ N - 2, 0.0 });
    while (!pq.empty()) {
        Element t = pq.top();
        pq.pop();
        if (t.cost > cost[t.node]) {
            continue;
        }

        for (ll i = 0; i < N; i++) {
            double new_cost = t.cost + edges[t.node][i];
            if (new_cost < cost[i]) {
                cost[i] = new_cost;
                pq.push({ i, new_cost });
            }
        }
    }

    printf("%.10f\n", cost[N - 1]);
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int a;cin>>a;

    cout<<(ceil(a/2.0))/a<<endl;
	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
int main(){
       
    cin.tie(0);
    ios::sync_with_stdio(false);
       
    int n;
    cin >> n;
      
    REP(i, n){
        vector<int> vc(3);
        for(auto &x : vc){
            cin >> x;
        }
        sort(vc.begin(), vc.end());
        cout << ( vc[0]*vc[0] + vc[1]*vc[1] == vc[2]*vc[2] ? "YES" : "NO" ) << endl;
    }
    return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i, M) {
        int A, B; cin >> A >> B;
        A--, B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    for (auto v : G) {
        cout << v.size() << endl;
    }
}

Measured memory_bytes: 256
n, b = map(int,input().split())
for i in range(1<<n):
    ans = []
    _i = i
    cnt = 0
    _cnt = 0
    while i and _cnt < b+1:
        if i&1:
            ans.append(cnt)
            _cnt += 1
        cnt += 1
        i=i>>1
    if _cnt == b:
         
        print(f'{_i}:',end = '')
        if _i == 0:
            print()
        else:print("",*ans)


Measured memory_bytes: 6208
#include<iostream>
#include<vector>

using namespace std;

struct my_pair
{
	int a;
	int b;
};

int main(void){
	vector<my_pair> input;

	while (1){
		int a,b;
		cin >> a>>b;

		if (a!=0||b!=0){
			my_pair mp;
			if (a < b){
				mp.a = a;
				mp.b = b;
			}
			else{
				mp.a = b;
				mp.b = a;
			}
			input.push_back(mp);
		}
		else{
			break;
		}
	}

	for (int i = 0; i < input.size(); i++){
		cout << input[i].a << " " << input[i].b << endl;
	}

	return 0;
}

Measured memory_bytes: 1244
#include<stdio.h>
int main()
{
	int t,i,j,a,b,c;
	double l,d,n,ls,ds,ns;
	while(scanf("%d",&t)&&t)
	{
		ls=ds=ns=l=d=n=0.0;
		for(i=0;i<t;i++)
		{
			scanf("%d%*c%d%d",&a,&b,&c);
			if(a>=11&&a<15)
			{
				l++;
				if(c<b)c+=60;
				if(c-b<9)ls++;
			}
			if(a>=18&&a<21)
			{
				d++;
				if(c<b)c+=60;
				if(c-b<9)ds++;
			}
			if((a>=21&&a<=24)||(a>=0&&a<2))
			{
				n++;
				if(c<b)c+=60;
				if(c-b<9)ns++;
			}
		}	
		if(l==0)printf("lunch no guest\n");
		else printf("lunch %d\n",(int)((ls/l)*100));
		if(d==0)printf("dinner no guest\n");
		else printf("dinner %d\n",(int)((ds/d)*100));
		if(n==0)printf("midnight no guest\n");
		else printf("midnight %d\n",(int)((ns/n)*100));
	}
}

Measured memory_bytes: 1040
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	ArrayList<Integer>[] g;

	void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int[][] ne = new int[s.length()][26];
		for (int i = 0; i < ne.length; ++i)
			for (int j = 0; j < 26; ++j)
				ne[i][j] = Integer.MAX_VALUE / 3;
		int n = s.length();
		for (int i = n - 1; i >= 0; --i) {
			for (int j = 0; j < 26; ++j) {
				if (i + 1 < n)
					ne[i][j] = Math.min(ne[i][j], ne[i + 1][j] + 1);
			}
			ne[i][s.charAt(i) - 'a'] = 0;
		}
		long cur = 0;
		for (int i = 0; i < t.length(); ++i) {
			if (ne[(int) (cur % n)][t.charAt(i) - 'a'] == Integer.MAX_VALUE / 3)
				cur = cur + (n - cur % n);
			if (ne[(int) (cur % n)][t.charAt(i) - 'a'] == Integer.MAX_VALUE / 3) {
				System.out.println(-1);
				return;
			}
			cur = cur + 1 + ne[(int) (cur % n)][t.charAt(i) - 'a'];
		}
		System.out.println(cur);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 41348
s=str(input())
s=list(s)
q=int(input())
sb=[0]*(q+1)
sa=[0]*(q+1)
sbi=0
sai=0
ta=0
for i in range(q):
  temp=str(input())
  temp=list(temp)
  if temp[0]=="1":
    ta=ta+1
  else:
    if (temp[2]=="1" and ta%2==0) or (temp[2]=="2" and ta%2!=0):
      sb[sbi]=temp[4]
      sbi=sbi+1
    else:
      sa[sai]=temp[4]
      sai=sai+1
lsb=sb.index(0)
lsa=sa.index(0)
sb.reverse()
ans=sb[len(sb)-lsb:len(sb)]+s+sa[0:lsa]
if ta%2!=0:
  ans.reverse()
print("".join(ans))

Measured memory_bytes: 17512
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N,M = map(int,input().split())
lisH = [0] + list(map(int,input().split()))
lisAB = lisH.copy()
for i in range(M):
    A,B = map(int,input().split())
    if lisH[A] > lisH[B]:
        lisAB[B] = 0
    elif lisH[A] < lisH[B]:
        lisAB[A] = 0
    else:
        lisAB[A] = 0
        lisAB[B] = 0
        
ans = 0
for i in range(1,N+1):
    if lisH[i] == lisAB[i]:
        ans += 1

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 38496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> s(M, vector<int>(10, -1));
    vector<int> p(M), count(M, 0);
    rep(i, 0, M)
    {
        int k;
        cin >> k;
        rep(j, 0, k)
        {
            cin >> s.at(i).at(j);
        }
    }
    rep(i, 0, M)
    {
        cin >> p.at(i);
    }
    ll ans = 0;
    bool f = true;
    for (int tmp = 0; tmp < (1 << N); tmp++)
    {
        bitset<10> bit(tmp);
        rep(i, 0, M)
        {
            rep(j, 0, 10)
            {
                if (s.at(i).at(j) != -1)
                {
                    if (bit.test(s.at(i).at(j) - 1))
                    {
                        count.at(i)++;
                    }
                }
            }
            if (count.at(i) % 2 != p.at(i))
            {
                f = false;
            }
            count.at(i) = 0;
        }
        if (f)
        {
            ans++;
        }
        else
        {
            f = true;
        }
    }
    cout << ans << endl;
}

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

#define WHITE 0
#define GRAY -1
#define BLACK 1

int *u, *k, **v, *color, *d, *f;
int n, time;

void init() {
	int i, j;

	u = (int *)malloc(sizeof(int) * (n + 1));
	k = (int *)malloc(sizeof(int) * (n + 1));
	color = (int *)malloc(sizeof(int) * (n + 1));
	d = (int *)malloc(sizeof(int) * (n + 1));
	f = (int *)malloc(sizeof(int) * (n + 1));
	v = (int **)malloc(sizeof(int *) * (n + 1));

}

void input() {
	int i, j;

	scanf("%d", &n);
	init();

	for (i = 1; i <= n; i++) {
		scanf("%d%d", &u[i], &k[i]);
		v[i] = (int *)malloc(sizeof(int) * (k[i] + 1));
		for (j = 1; j <= k[i]; j++) {
			scanf("%d", &v[i][j]);
		}
	}
}

void DFSVisit(int u) {
	int i;

	color[u] = GRAY;
	d[u] = ++time;

	for (i = 1; i <= k[u]; i++) {
		if (color[v[u][i]] == WHITE) DFSVisit(v[u][i]);
	}
	color[u] = BLACK;
	f[u] = ++time;
}

void DFS() {
	int i;

	for (i = 1; i <= n; i++) {
		color[u[i]] = WHITE;
	}

	for (i = 1; i <= n; i++) {
		if (color[u[i]] == WHITE) DFSVisit(i);
	}
}

void output() {
	int i;

	for (i = 1; i <= n; i++) {
		printf("%d %d %d\n", u[i], d[i], f[i]);
		free(v[i]);
	}
	free(u);
	free(k);
	free(v);
	free(color);
}

main () {
	input();
	DFS();
	output();
	return 0;
}

Measured memory_bytes: 600
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))

#全要素に-1かける
for i in range(len(A)):
    A[i] *= -1 

heapq.heapify(A) 
for _ in range(M):
    x = heapq.heappop(A)
    heapq.heappush(A, (-x//2)*(-1))

print(-sum(A))

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

int main(){
  vector<int> a ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a.at(k-1) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

        int n = 3;
        int a[n];

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

        int five_cnt = 0;
        int seven_cnt = 0;
        for (int i = 0; i < n; ++i) {

                if (a[i] == 5) {
                        ++five_cnt;
                }
                else if (a[i] == 7) {
                        ++seven_cnt;
                }
        }

        if (five_cnt == 2 && seven_cnt == 1) {
                cout << "YES" << endl;
        }
        else {
                cout << "NO" << endl;
        }





        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){

int x,y;
string str;

while(true){
cin >> x >> str >>y;

if(str == "?")break;
if(str == "+")cout << x + y << endl;
if(str == "-")cout << x - y << endl;
if(str == "*")cout << x * y << endl;
if(str == "/")cout << x / y << endl;
}


}

Measured memory_bytes: 1208
// Last Change: 05/23/2019 19:15:46.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll n;
  const ll dayTime = 60 * 60 * 24 + 5;

  while (cin >> n and n > 0) {
    vector<ll> time(dayTime, 0);
    string ipt;
    int h, m, s;
    for (ll i = 0; i < n; ++i) {
      cin >> ipt;
      h = stoi(ipt.substr(0, 2));
      m = stoi(ipt.substr(3, 2));
      s = stoi(ipt.substr(6, 2));
      ++time[h * 60 * 60 + m * 60 + s];
      cin >> ipt;
      h = stoi(ipt.substr(0, 2));
      m = stoi(ipt.substr(3, 2));
      s = stoi(ipt.substr(6, 2));
      --time[h * 60 * 60 + m * 60 + s];
    }

    ll tmp = 0, ans = 0;
    for (ll i = 0; i < dayTime; ++i) {
      tmp += time[i];
      ans = max(ans, tmp);
    }
    cout << ans << endl;
  }

  //NS::LoopUntilZeroInpput();
}



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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int a,b;
	cin>>a>>b;
	if(a<10&&b<10)cout<<a*b<<endl;
	else cout<<-1<<endl;
	return 0;
}

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

using namespace std;

int main(){
    int N, tt;
    cin >> N ;
    vector<int> tako(0);
    vector<int> tako2(0);
    for (int i = 0 ; i < N; ++i){
        cin >> tt;
        tako.push_back(tt);
        tako2.push_back(tt *tt);
    }
    int s = accumulate(tako.begin(), tako.end(),0)* accumulate(tako.begin(), tako.end(),0) -accumulate(tako2.begin(), tako2.end(), 0) ;
    cout << s/2;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	int a;
	int x = 0;
	int y = 0;
	for (int i = 0; i < N; i++) {
      	cin>>a;
		if (a% 4 == 0)
			x++;
		if (a% 4 == 2)
			y++;
	}
	 if (x+y/2>=N/2)
		cout << "Yes" << endl;
	 else
		cout << "No" << endl;
}








Measured memory_bytes: 256
#include <iostream>

int total(int k);

using namespace std;
int main() {
  int n, m, i, j, sum, squares;
  while(cin >> n >> m){
    if(n==0 && m==0){break;}
    int h[n], w[m];
    for(i=0; i<n; i++){
      cin >> h[i];
    }
    for(i=0; i<m; i++){
      cin >> w[i];
    }
    int array[1500001];
    for (i = 0; i < 1500001; ++i){
      array[i] = 0;
    }
    for (i = 0; i < n; ++i){
        sum = 0;
      for (j = 0; j < n-i; ++j){
        sum += h[i+j];
        array[sum]++;
      }
    }

    squares = 0;
    for (i = 0; i < m; ++i){
        sum = 0;
      for (j = 0; j < m-i; ++j){
        sum += w[i+j];
        squares += array[sum];
      }
    }
    cout << squares <<endl;
  }

}


int total(int k){
  int i, sum;
  sum = 0;
  for (i = 0; i < k; ++i){
    sum += (k-i);
  }
  return sum;
}

Measured memory_bytes: 7024
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[105][105];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int w, h, n;
    cin >> w >> h >> n;
    for (int i = 0; i < n; ++i)
    {
        int x, y, e;
        cin >> x >> y >> e;
        if (e == 1)
        {
            for (int i = 1; i <= x; ++i)
                for (int j = 1; j <= h; ++j)
                    a[i][j] = 1;
        }
        else if (e == 2)
        {
            for (int i = x + 1; i <= w; ++i)
                for (int j = 1; j <= h; ++j)
                    a[i][j] = 1;
        }
        else if (e == 3)
        {
            for (int i = 1; i <= w; ++i)
                for (int j = 1; j <= y; ++j)
                    a[i][j] = 1;
        }
        else
        {
            for (int i = 1; i <= w; ++i)
                for (int j = y + 1; j <= h; ++j)
                    a[i][j] = 1;
        }
    }
    int sol = 0;
    for (int i = 1; i <= w; ++i)
        for (int j = 1; j <= h; ++j)
            if (!a[i][j])
                sol++;
    cout << sol;
}


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

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) cout << "Left" << endl;
	else if (a + b < c + d) cout << "Right" << endl;
	else cout << "Balanced" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import decimal

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
a, b, c = [int(x) for x in input().strip().split()]
if decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() < decimal.Decimal(c).sqrt():
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5588
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    int n, sum=1;
    string s;
    cin >> n;
    cin >> s;
    rep(i, n-1){
        if(s[i] != s[i+1]) sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3752
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp                       __builtin_popcount

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    int n,x;
    cin>>n;
    int d[n+1];
    f(i,1,n)
        d[i]=0;
    f(i,1,n-1)
    {
        cin>>x;
        d[x]++;
    }
    f(i,1,n)
        cout<<d[i]<<endl;
}

Measured memory_bytes: 5204
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = [0] + A
c = {}
c[1] = 0
n = 0
k = 1
while c.get(A[k]) is None or c[A[k]] != 2:
    if c.get(A[k]) is None:
        c[A[k]] = 0
    else:
        c[A[k]] += 1
    n += 1
    k = A[k]

from collections import Counter
if n <= K:
    num = Counter(c.values())[2]
    sa = len(c)-num
    bbb = K - sa
    m = bbb % num
    abc = list(c.keys())
    abc = abc[sa:len(c)]
    print(abc[m])
else:
    a = 1
    for i in range(K):
        a = A[a]
    print(a)

Measured memory_bytes: 120780
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
    int N;
    scanf("%d", &N);

    vector<pair<long, long> > vec;
    for (int i=0; i<N; i++)
    {
        long a, b;
        scanf("%ld %ld", &a, &b);
        vec.push_back({b, a});
    }

    sort(vec.begin(), vec.end());

    //for (int i=0; i<N; i++) printf("%ld %ld\n", vec[i].second, vec[i].first);

    long n=0;

    for (int i=0; i<N; i++)
    {
        n += vec[i].second;
        if (n <= vec[i].first)
        {
            
            continue;
        }
        else 
        {
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");


    return 0;
}

Measured memory_bytes: 6384
def fact(x):
    if x==0:
        return 1
    else:
        return x*fact(x-1)


def sea(n,a):
    k=list(range(1,n+1))
    s=0
    for c in range(n):
        j=k.index(a[c])
        s+=j*fact(n-c-1)
        k.remove(a[c])
    return s


n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
print(abs(sea(n,b)-sea(n,a)))

Measured memory_bytes: 3064
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 1e5 + 5;
const ll OO = 1e9 + 7;
using namespace std;
int n, m;
int dp[3005][3005];
string s, ss;
int solve(int i, int j) {
    if (i == 0 || j == 0) re 0;
    int &ret = dp[i - 1][j - 1];
    if (~ret) re ret;
    if (s[i - 1] == ss[j - 1]) re ret = 1 + solve(i - 1, j - 1);
    else
        re ret = max(solve(i - 1, j), solve(i, j - 1));
}

int main() {
    IO;
    cin >> s >> ss;
    int n = (int)s.size(), m = (int)ss.size();
    memset(dp, -1, sizeof(dp));
    forr(i, 0, n) {
        forr(j, 0, m) {
            if (i == 0 || j == 0)
                dp[i][j] = 0;

            else if (s[i - 1] == ss[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;

            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    int len = dp[n][m];
    char lcs[len + 1];
    lcs[len] = '\0';
    int i = n, j = m;
    while (i > 0 && j > 0) {
        if (s[i - 1] == ss[j - 1]) {
            lcs[len - 1] = s[i - 1];
            i--;
            j--;
            len--;
        } else if (dp[i - 1][j] > dp[i][j - 1])
            i--;
        else
            j--;
    }
    cout << lcs;

}

Measured memory_bytes: 35584
// ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//


#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <sstream>

#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for (long long i=(b)-1;i>=(a);i--)
#define REP(i,n) for (unsigned long long i=0;i<(n);i++)
#define RREP(i,n) for (long long i=(n)-1;i>=0;i--)

#define inf INT_MAX/3
#define INF INT_MAX/3
#define llinf LLONG_MAX/3
#define LLINF LLONG_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VL vector<long long>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SCD second

using namespace std;

signed main()
{
	LL A, B, C;
	cin >> A >> B >> C;

	LL n = 0;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
		n = 0;
	}
	else {
		LL* max_abc = &A;
		max_abc = *max_abc < B ? &B : max_abc;
		max_abc = *max_abc < C ? &C : max_abc;
		if (&A == max_abc) {
			n = B * C;
		}
		else if (&B == max_abc) {
			n = A * C;
		}
		else if (&C == max_abc) {
			n = B * A;
		}
	}

	cout << n;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define A first
#define B second
#define db double
#define lowbit(p) (p&(-p))
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}

map< pii,int >id;
#define M 100005
struct ed{
	int x,l,nx;
}e[M*12];
int nx[6*M],dis[6*M],n,m,ecnt=1;
bool mark[6*M];
priority_queue< pii >Q;
void add(int x,int y,int l){
	e[ecnt]=(ed){y,l,nx[x]};
	nx[x]=ecnt++;
}
void dij(int s,int t){
	memset(dis,63,sizeof(dis));
	Q.push(mp(dis[s]=0,s));
	int x;
	for (;!Q.empty();){
		x=Q.top().B; Q.pop();
		if (mark[x])continue;
		mark[x]=1;
		if (x==t)break;
		for (int i=nx[x];i;i=e[i].nx){
			if (dis[x]+e[i].l<dis[e[i].x]){
				dis[e[i].x]=dis[x]+e[i].l;
				Q.push(mp(-dis[e[i].x],e[i].x));
			}
		}
	}
	if (mark[t]){
		printf("%d\n",dis[t]);
	}
	else {
		printf("-1\n");
	}
}
int tot;
int cal(int x,int col){
	int &res=id[mp(x,col)];
	if (res)return res;
	res=++tot;
	add(x,res,1);
	add(res,x,0);
	return res; 
}
int main(){
	int Caseid;
// 	freopen("4.in","r",stdin);
//	read(Caseid);
	read(n); read(m);	
	int i,x,y,c;
	tot=n;
	for (i=1;i<=m;i++){
		read(x); read(y); read(c);
		x=cal(x,c);
		y=cal(y,c);
		
		add(x,y,0);
		add(y,x,0);
	}
	dij(1,n);
	return 0;
}

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

using namespace std;

int main()
{
	pair<int, pair<int, int>> d1, d2;
	cin >> d1.first >> d1.second.first >> d1.second.second >> d2.first >> d2.second.first >> d2.second.second;
	if (d1 > d2)
		swap(d1, d2);
	int y = d2.first - d1.first;
	if (d1.second >= d2.second)
		cout << y << endl;
	else
		cout << y + 1 << endl;

	return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define ll long long
using namespace std;
int main(){
ll N,count=0;
cin>>N;
while(1){
  if(N%10==2){
    count++;
  }
  N=int(N*0.1);
  if(N==0)
  break;
}

printf("%lld",count);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    vec x0(N);
    vector<Pii> x(N);
    vec ans(N * N, INF);
    REP(i, N){
        cin >> x0[i];
        x0[i]--;
        x[i] = Pii(x0[i], i);
        ans[x0[i]] = i;
    }
    SORT(x);
    int i0 = 0;
    REP(i, N){
        int n = x[i].second;
        //ans[x[i].first] = n;
        REP(i, n){
            while(ans[i0] < INF) i0++;
            ans[i0] = n;
        }
    }
    REP(i, N){
        int n = x[i].second;
        REP(i, N - n - 1){
            while(ans[i0] < INF) i0++;
            ans[i0] = n;
        }
    }

    bool f = true;
    vec cnt(N, 0);
    REP(i, N * N){
        cnt[ans[i]]++;
        if(cnt[ans[i]] == ans[i] + 1) if(x0[ans[i]] != i) f = false;
    }

    if(f){
        cout << "Yes" << endl;
        REP(i, N * N) cout << ans[i] + 1 << " ";
    }else cout << "No" << endl;

    
    return 0;
}

Measured memory_bytes: 3200