akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    ll H,W;
    cin >> H >> W;
    if(H % 3 == 0 || W % 3 == 0){
        cout << 0 << endl;
        return 0;
    }
    ll mindif = INF;
    for(int i = 1;i < H;i++){
        ll s = W * i;
        ll h = H - i;
        ll s2 = (h / 2) * W,s3 = (h + 1) / 2 * W;
        mindif = min(mindif,max({s,s2,s3}) - min({s,s2,s3}));
        s2 = h * (W / 2),s3 = (W + 1) / 2 * h;
        mindif = min(mindif,max({s,s2,s3}) - min({s,s2,s3}));
    }
    for(int i = 1;i < W;i++){
        ll s = H * i;
        ll w = W - i;
        ll s2 = (w / 2) * H,s3 = (w + 1) / 2 * H;
        mindif = min(mindif,max({s,s2,s3}) - min({s,s2,s3}));
        s2 = w * (H / 2),s3 = (H + 1) / 2 * w;
        mindif = min(mindif,max({s,s2,s3}) - min({s,s2,s3}));
    }
    cout << mindif << endl;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main(){
    fast;
    ll a,k,z; cin>>a>>k>>z;
    vec<ll> m(a,0);
    for(int q=0; q<z; q++){
        int x; cin>>x; x--;
        m[x]++;
    }
    for(int q=0; q<a; q++) cout<<(k-(z-m[q])>0 ? "Yes" : "No")<<"\n";
}

Measured memory_bytes: 1536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

const int MAX_N = 100;
int d[MAX_N + 1];
int N;
vector<vector<int>> g(MAX_N + 1);

void bfs() {
  queue<P> q;
  q.push(make_pair(1, 0));

  while (!q.empty()) {
    P p = q.front(); q.pop();
    int node = p.first;
    int dist = p.second;

    if (d[node] >= 0) continue;

    d[node] = dist;
    for (int i = 0; i < g[node].size(); i++) {
      q.push(make_pair(g[node][i], dist + 1));
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  cin >> N;
  for (int i = 0; i < N; i++) {
    int u; cin >> u;
    int k; cin >> k;
    for (int ki = 0; ki < k; ki++) {
      int tmp; cin >> tmp;
      g[u].push_back(tmp);
    }
    sort(g[u])
  }
  memset(d, -1, sizeof(d));

  bfs();

  for (int i = 1; i <= N; i++) {
    cout << i << " " << d[i] << endl;
  }
}



Measured memory_bytes: 3192
@pak_num_n, @trk_num_k = gets.split.map(&:to_i)
@pak_weight = readlines(chomp: true).map(&:to_i)

def check(max_sum_wgt_p) # 仮定した最大積載量で、トラックに積み込めるかチェック
  pak_w_idx = 0 # 加算する荷物の重さインデックス

  @trk_num_k.times do | truck | # トラックの数、次のトラックへ
    sum_wgt = 0
    # 仮定した最大積載量より、合計した荷物の重さが、小さい場合、繰り返す。大きい場合積み込めないので次のトラックへ
    while (sum_wgt += @pak_weight[pak_w_idx]) <= max_sum_wgt_p

      pak_w_idx += 1 # 加算する荷物の重さインデックスを一つ進める
      # 荷物の重さインデックスが、荷物の個数と同じになった場合
      if pak_w_idx == @pak_num_n
        return @pak_num_n # 荷物をすべて積み込めたとみなして荷物の個数を返す
      end
    end
  end
  pak_w_idx # 積み込めなかった場合、限界まで積み込めた個数を返す
end

def slove()
  left = 0 # 二分探索で使う左
  right = 100_000 * 10_000 # 荷物の数 * 荷物の重さ = 最大積載量を仮定
  # right = 30
  
  while (right - left) > 1 
    mid = (left +  right) / 2 # 中央値を決める
    stk_pak_num_v = check(mid) # 最大積載量を中央値で仮定し、チェックした後、個数を

    if stk_pak_num_v >= @pak_num_n # 仮定した最大積載量で積み込めた荷物の個数が、荷物の個数以上の場合
      right = mid # 仮定する最大積載量を小さくしていく
    else
      left = mid # 仮定した最大積載量で積み込めた無かった場合、仮定する最大積載量を大きくしていく
    end
  end
  right
end

puts slove()


Measured memory_bytes: 12604
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int H, W;

int main() {
#ifdef __APPLE__
    freopen("input3.txt", "r", stdin);
#endif
    cin >> H >> W;
    int c[10][10];

    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> c[i][j];
        }
    }

    vector<vector<int>> A;
    int Aij;

    for (int k = 0; k < H; ++k) {
        vector<int> Ak;
        for (int i = 0; i < W; ++i) {
            cin >> Aij;
            Ak.push_back(Aij);
        }
        A.push_back(Ak);
    }

    int min_cost[10] = {0};

    for (int start = 0; start < 10; ++start) {
        if (start == 1) continue;

        set<pair<int, int>> frontier; // cost,number
        frontier.insert({0, start});

        while (true) {
            int cheapest_number = frontier.begin()->second;
            int cheapest_cost = frontier.begin()->first;
            if (cheapest_number == 1) {
                min_cost[start] = cheapest_cost;
                break;
            }

            frontier.erase({cheapest_cost, cheapest_number});

            for (int i = 0; i < 10; ++i) {
                if (i == cheapest_number) continue;
                frontier.insert({c[cheapest_number][i] + cheapest_cost, i});
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int num = A[i][j];
            if (num == -1) continue;
            ans += min_cost[num];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
def resolve():
    N = int(input())
    S = input()

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for i in range(N - 1, -1, -1):
        for j in range(N - 1, -1, -1):
            if S[i] != S[j]:
                dp[i][j] = 0
            else:
                dp[i][j] = dp[i + 1][j + 1] + 1

    ans = 0
    for i in range(N):
        for j in range(N):
            now = min(dp[i][j], j - i)
            ans = max(ans, now)
    print(ans)


if __name__ == "__main__":
    resolve()


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

int check(int a,int b);

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >>X >> Y ;
    long long ans = X * A + Y * B ;
    for(int i = 0;  i <= 2 * max(X,Y); i+=2){
        long long p = C * i + A * check(X,i) + B * check(Y,i);
        if(p < ans) ans = p ;
    }
    cout << ans << endl ;


}

int check(int a, int b){
    if((a - b / 2) < 0) return 0;
    else return (a - b / 2) ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
using namespace std;
int main()

{
    
	
	int  n,m;
	int i;
	cin>>n>>m;
	string s1="",s2="";
	for(i=0;i<n;i++)
	{
		s1+=m+'0';
	}
	for(i=0;i<m;i++)
	{
		s2+=n+'0';
	}
	if (s1<s2)
	cout<<s1<<endl;
	else
	cout<<s2<<endl;
	
	
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n%2==0){
            System.out.println("0.5");
        }else{
            System.out.println((double) (n+1)/(2*n));
        }
    }
}

Measured memory_bytes: 21844
n=gets.to_i
as=gets.split.map(&:to_i).sort
color=[0]*8
over=0
as.each do |rate|
  if rate<400
    color[0]=1
  elsif rate<800
    color[1]=1
  elsif rate<1200
    color[2]=1
  elsif rate<1600
    color[3]=1
  elsif rate<2000
    color[4]=1
  elsif rate<2400
    color[5]=1
  elsif rate<2800
    color[6]=1
  elsif rate<3200
    color[7]=1
  else
    over+=1
  end
end

cnum=color.inject(:+)
if cnum>0
  puts [cnum,cnum+over].join(" ")
else
  puts [1,over].join(" ")
end


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N;
    string S;
    cin >> N;
    cin >> S;


    ll ans = 0 ;
    rep(i, N){
        if(i == 0 ) continue;
        string a = S.substr(0, i);
        string b = S.substr(i, N-i);
        rmsame(a);
        rmsame(b);
        string c = a + b;
        rmsame(c);
        ans = max(ans, (ll)(a.size()+b.size()-c.size()));
    }
    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inchar			getchar
#define outchar(x)		putchar(x)
#define ll long long int
#define all(v) v.begin(), v.end()
#define SP outchar(' ')
#define LN outchar('\n')
using namespace std;

template<typename T> void inpos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=0; if(c=='-')neg=1;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
template<typename T> void outpos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do{snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);}
inline void instr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while(c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}

// DP for weights
// ith weights ke liye maximum value kya hai



int main ( ){
	int n;
	vector <ll> dp(int(1e5)+5, 0);
	int w;
	inpos(n); inpos(w);
	int val[n]; int Wt[n];
	for (int i = 0; i<n;i++) {
		inpos(Wt[i]);
		inpos(val[i]);
	}
	for (int i = 0; i<n;i++) {
		//
		for (int j = 1e5 ; j - Wt[i]>=0 ; j--) {
			dp[j] = max( dp[j] ,dp[j-Wt[i]] + val[i]); //max value 
		} 

	} // item me iterate karo
	// 
	// for(int i = 0 ; i< 100 ; i++) {
	// 	cout << dp[i] << endl;
	// }
	// outpos(wt);
	outpos(dp[w]);LN;
}

Measured memory_bytes: 1024
def wa(n,a,b):
  hoge=0
  ans=0
  for i in range(1,n+1):
    s=str(i)
    hoge=0
    for ii in s:
      hoge+=int(ii)
    if a<=hoge<=b:
      ans+=i
  return ans
n,a,b=map(int,input().split())
print(wa(n,a,b))  

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

int main(){
    long long int a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
    long long int ans1,ans2;
    if(a<b){
        ans1=a+v*t;
        ans2=b+w*t;
        if(ans1>=ans2){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }else{
        ans1=a-v*t;
        ans2=b-w*t;
        if(ans1<=ans2){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N, M;
  while(cin>>N>>M && N){
    map<int, int> cnt;
    deque<int> que;
    set<int> cache;
    REP(i, N){
      int t; scanf("%d", &t);
      cnt[t] += 1;
      que.push_back(t);
      cache.insert(t);
      if(cache.size() <= M) continue;
      while(true){
        t = que.front(); que.pop_front();
        if(--cnt[t] == 0){
          cache.erase(t);
          break;
        }
      }
    }
    while(!que.empty()){
      int t = que.back(); que.pop_back();
      if(cache.count(t)){
        cache.erase(t);
        printf("%d\n", t);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 6808
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int a[205], k[205];
int gr[205];
signed main() {
	int n; cin >> n;
	rep(i, n) {
		cin >> a[i] >> k[i];
		while (a[i] % k[i]&&a[i]>=k[i]) {
			int d = a[i] / k[i] + 1;
			a[i] -= ((a[i]%k[i])+d-1)/d*d;
		}
		if (a[i] < k[i])a[i] = 0;
		gr[i] = a[i] / k[i];
	}
	int ans = 0;
	rep(i, n)ans ^= gr[i];
	if (ans)puts("Takahashi");
	else puts("Aoki");
}


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


int main(){
	    string S; cin >> S;
        if(S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
        else cout << "No" << endl;
}


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

int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=9;i++)
  {
    int j=n/i;
    if(j*i==n)
      if(j>=1&&j<=9)
      {
        cout<<"Yes\n";
        return 0;
      }
  }
  cout<<"No\n";
  
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;

public class Main {
    static int gcd(int a,int b){
        if(b==0)
            return a;
        return gcd(b,a%b);
    }
    public static void main(String[] args)throws Exception {
        FastReader in = new FastReader(System.in);
        StringBuilder sb = new StringBuilder();
        int i,j;
        int n=in.nextInt();
        char arr[]=in.next().toCharArray();

        int pre[][]=new int[n+1][3];
        pre[n][0]=pre[n][1]=pre[n][2]=0;
        int val[]=new int[n];
        for(i=0;i<n;i++){
            if(arr[i]=='R')
                val[i]=0;
            else if(arr[i]=='G')
                val[i]=1;
            else
                val[i]=2;
        }
        for(i=n-1;i>=0;i--){
            for(j=0;j<3;j++) {
                pre[i][j] = pre[i + 1][j];
                if (val[i]==j)
                    pre[i][j]++;
            }
        }
        long ans=0;
        for(i=0;i<n-2;i++){
            for(j=i+1;j<n-1;j++){
                if(val[i]!=val[j]){
                    int z=3-(val[i]+val[j]);
                    ans+=pre[j+1][z];
                    if(2*j-i<n && val[2*j-i]==z)
                        ans--;
                }
            }
        }
        System.out.println(ans);

    }
}

class FastReader {

    byte[] buf = new byte[2048];
    int index, total;
    InputStream in;

    FastReader(InputStream is) {
        in = is;
    }

    int scan() throws IOException {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0) {
                return -1;
            }
        }
        return buf[index++];
    }

    String next() throws IOException {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan()) {
            sb.append((char) c);
        }
        return sb.toString();
    }

    int nextInt() throws IOException {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }

    long nextLong() throws IOException {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+') {
            c = scan();
        }
        for (; c >= '0' && c <= '9'; c = scan()) {
            val = (val << 3) + (val << 1) + (c & 15);
        }
        return neg ? -val : val;
    }
}





Measured memory_bytes: 32588
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		char[] c = S.toCharArray();
		sc.close();

		// 一周してRGBが何個あるかを判定
		long R = 0;
		long G = 0;
		long B = 0;

		for (int i = 0; i < N; i++) {
			if (c[i] == 'R') {
				R++;
			} else if (c[i] == 'G') {
				G++;
			} else {
				B++;
			}
		}

		// NGを判定する
		long ng = 0;
		for (int i = 0; i < N - 2; i++) {
			char first = c[i];

			for (int j = i + 1; j < N - 1; j++) {
				if (c[j] == first) {
					continue;
				}
				char second = c[j];
				int d = j - i;

				if (j + d < N && c[j + d] != first && c[j + d] != second) {
					ng++;
				}
			}
		}

		long ans = R * G * B - ng;
		System.out.println(ans);
	}
}


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

int main(){

    int A,B;cin >> A >> B;

    if(A==1){
        if(B==2)cout<<3<<endl;
        else if(B==3)cout<<2<<endl;
    }else if(A==2){
        if(B==1)cout<<3<<endl;
        else if(B==3)cout<<1<<endl;
    }else{
        if(B==1)cout<<2<<endl;
        else if(B==2)cout<<1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define INF 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
 
template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }

int main()
{
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
 
    vector<ll> dp(N+100,INF);
    dp[0] = 0;
 
    REP(i, 1, N)
    {
        chmin( dp[i], dp[i-1] + abs(h[i]-h[i-1]) );
        if( i > 1 ) chmin( dp[i], dp[i-2] + abs(h[i]-h[i-2]) );
    }
 
    cout << dp[N-1] << endl;
}



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

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

int n,a,b;
cin >> n >> a >> b;
if(n*a>=b){
    cout << b << endl;
}else{
    cout << n*a << endl;
}

//////////////////////////////////////////////////////
return 0;}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    cout << (int)ceil((-1 + sqrt(1 + 8 * (double)x)) / 2);
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {ll l,r;
	cin>>l>>r;
	if(r-l>=2019)
	{
		cout<<0;
		exit(0);
	}
	ll ans=2018;
	for(ll i=l;i<=r;i++)
	{
		for(ll j=i+1;j<=r;j++)
			ans=min(ans,((i*j)%2019));
	}
	cout<<ans;
    } 
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

bool check[3001];
int n,x,y,w[3001];
vector<int> point[3001];

bool dfs(int u,int f){
	check[u]=false;
	for(int v:point[u])if(v!=f&&w[v]<w[u]){dfs(v,u);if(!check[v]){check[u]=true;break;}}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",w+i);
	for(int i=1;i<n;++i)scanf("%d%d",&x,&y),point[x].push_back(y),point[y].push_back(x);
	for(int i=1;i<=n;++i){dfs(i,0);if(check[i])printf("%d ",i);}
}

Measured memory_bytes: 512
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    println(problem064c(n, a))
}

fun problem064c(n: Int, a: List<Int>): String {
    var lowCount = 0
    var proCount = 0
    val set = hashSetOf<Int>()
    for (i in 0 until n) {
        val rate = a[i]
        if (rate < 3200) {
            if (!set.contains(rate / 400)) {
                set.add(rate / 400)
                lowCount++
            }
        } else {
            proCount++
        }
    }
    val min = if (lowCount != 0) lowCount else 1
    return "$min ${lowCount + proCount}"
}

Measured memory_bytes: 36036
#include<iostream>
using namespace std;
int n,f,l,m;
string s,t;
int main(){
	cin>>n;
	l=n;
	cout<<0<<endl;
	cin>>s;
	if(s=="Vacant")return 0;
	while(t!="Vacant"){
		m=(f+l)/2;
		cout<<m<<endl;
		cin>>t;
		if(m%2^s==t)f=m;//謎
		else l=m;
	}
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    int n;
    cin >> n;
    vector<ll> v(n+1), pre(n+1, 0);
    for(int j = 1; j <= n; j++) cin >> v[j], pre[j] = pre[j-1]+v[j];

    vector< vector<ll> > dp(n+2, vector<ll>(n+2, 0));
    for(int j = 1; j <= n; j++){
        for(int k = j; k > 0; k --)
            dp[k][j] = max(v[k] + (pre[j] - pre[k-1] - v[k] - dp[k+1][j]), v[j] + (pre[j] - pre[k-1] - v[j] - dp[k][j-1]));
    }
    cout << (dp[1][n] - (pre[n] - dp[1][n]));
    return 0;
}

Measured memory_bytes: 70912
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

struct uf {
private:
	vector<int> par, ran;
public:
	void init(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

vector<int> vx[1 << 17], vy[1 << 17];
vector<int> G[1 << 17];
void solve() {
	int n; cin >> n;
	uf u; u.init(n);
	vector<P> v;
	rep(i, n) {
		int x, y; cin >> x >> y;
		vx[x].push_back(i);
		vy[y].push_back(i);
		v.push_back({ x,y });
	}
	rep(i, (1 << 17)) {
		rep(j, (int)vx[i].size()-1) {
			int le = vx[i][j], ri = vx[i][j + 1];
			u.unite(le, ri);
			G[le].push_back(ri);
			G[ri].push_back(le);
		}
		rep(j, (int)vy[i].size() - 1) {
			int le = vy[i][j], ri = vy[i][j + 1];
			u.unite(le, ri);
			G[le].push_back(ri);
			G[ri].push_back(le);
		}
	}
	vector<bool> used(n, false);
	ll ans = 0;
	rep(i, n) {
		if (used[i])continue;
		queue<int> q; q.push(i); used[i] = true;
		vector<int> cx, cy;
		while (!q.empty()) {
			int id = q.front(); q.pop();
			cx.push_back(v[id].first);
			cy.push_back(v[id].second);
			rep(j, G[id].size()) {
				int to = G[id][j];
				if (used[to])continue;
				used[to] = true;
				q.push(to);
			}
		}
		sort(cx.begin(), cx.end());
		sort(cy.begin(), cy.end());
		ll lx = unique(cx.begin(), cx.end()) - cx.begin();
		ll ly = unique(cy.begin(), cy.end()) - cy.begin();
		ans += lx * ly;
	}
	ans -= n;
	cout << ans << endl;
}

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

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 18932
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int K, X; cin >> K >> X;
  for(int i = X-K+1; i <= X+K-1; i++){
    cout << i << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 256
n,m,x=[int(i) for i in input().split()]
c=[]
arr=[[] for i in range(n)]
for i in range(n):
    l=[int(i) for i in input().split()]
    c.append(l[0])
    arr[i]=l[1:]

inf=10**18
ans=inf

limit=2**n
for bit in range(1,limit):
    sum=[0 for i in range(m)]
    cost=0
    for i in range(n):
        if (1<<i & bit):
            cost+=c[i]
            for j in range(m):
                sum[j]+=arr[i][j]
    flag=1
    for i in range(m):
        if sum[i]<x:
            flag=0
            break
    if flag==0:
        continue
    ans=min(ans,cost)
if ans!=inf:
    print(ans)
else:
    print(-1)


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

int main(void) {

	int a,b,c,x;

	scanf("%d%d%d",&a,&b,&c);

	if(a>c){
		x=a;
		a=c;
		c=x;
	}
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	printf("%d %d %d\n",a,b,c);

	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main() {
    int N;
    cin >> N;
    vi A(N-1);
    
    REP(i,N-1){
        cin >> A[i];
    }
    
    vi buka(N,0);
    
    REP(i,N-1){
        buka[A[i]-1] ++;
    }
    
    REP(i,N){
        cout << buka[i] << endl;
    }
}


Measured memory_bytes: 4768
from functools import reduce

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

ans = 0
for i in range(N):
    A = list(map(int,input().split()))
    if reduce(lambda x, y:x + y[0] * y[1], zip(A, B), 0) + C > 0: ans += 1
print(ans)


Measured memory_bytes: 3572
io = STDIN
n=io.gets.to_i
a=io.gets.split.map(&:to_i)
lar=Array.new(n) #left gcd累計
rar=Array.new(n) #right gcd累計
lar[0]=a[0]
(1...n).each do |i|
  lar[i]=lar[i-1].gcd(a[i])
end
rar[-1] = a[-1]
(n-2).downto(0).each do |i|
  rar[i]=a[i].gcd(rar[i+1])
end
ar= [
lar[-2],
(1..n-2).map{ |i|lar[i-1].gcd(rar[i+1])},
rar[1]
]
p ar.flatten.max


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<long long> hs(N);
    for (auto& h : hs) {
        cin >> h;
    }
    hs.push_back(0);
    vector<vector<long long>> best(N+2-K, vector<long long>(N+1));
    for (int p = 0; p <= N; ++p) {
        best[1][p] = hs[p];
    }
    for (int k = 2; k <= N+1-K; ++k) {
        for (int p = k-1; p <= N; ++p) {
            long long tmp = best[k-1][p-1] + abs(hs[p] - hs[p-1]);
            for (int t = k-2; t < p; ++t) {
                tmp = min(tmp, best[k-1][t] + abs(hs[p] - hs[t]));
            }
            best[k][p] = tmp;
        }
    }
    cout << best[N+1-K][N] / 2 << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		
		// 計算
		String result = "No";
		for(int i = 0; i < k; i++){
		    if(a >= b){
		        b *= 2;
		    }else if(b >= c){
		        c *= 2;
		    }
		}
		if(a < b && b < c) result = "Yes";
		
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 25404
#include<stdio.h>

int main(void){
    int a[3],i,j,k;

    for(i = 0;i < 3;i++)
        scanf("%d",&a[i]);

    for(i = 0;i < 3;i++)
        for(j = i + 1;j < 3;j++)
            if(a[i] > a[j]){
                k = a[i];a[i] = a[j];a[j] = k;
            }

    for(i = 0;i < 3;i++){
        printf("%d",a[i]);
        if(i != 2)
            printf(" ");
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
	int a[5], i, b[5], x, y;
	while (~scanf ("%d", a))
	{
		int has[10] = {0};
		has[a[0]] = 1;
		for (i = 1; i < 4; i++) scanf ("%d", a+i), has[a[i]] = 1;
		for (i = 0; i < 4; i++) scanf ("%d", b+i);
		x = y = 0;
		for (i = 0; i < 4; i++) if (a[i] == b[i]) ++x;
		for (i = 0; i < 4; i++) if (has[b[i]]) ++y;
		printf ("%d %d\n", x, y-x);
	}
	return 0;
}

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

/* -128 ~ 127 */
using i8  = int8_t;
/* 0 ~ 255 */
using u8  = uint8_t;
/* -32,768 ~ 32,767 */
using i16 = int16_t;
/* 0 ~ 65,535 */
using u16 = uint16_t;
/* -2,147,483,648 ~ 2,147,483,647 */
using i32 = int32_t;
/* 0 ~ 4,294,967,295 */
using u32 = uint32_t;
/* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using i64 = int64_t;
/* 0 ~ 18,446,744,073,709,551,615 */
using u64 = uint64_t;
/* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f32 = float;
/* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f64 = double;
using f80 = __float80;

template <class T>
using Vec = vector<T>;

template <typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

/* 定数 */
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;

#define fn auto
#define ALL(v) v.begin(), v.end()

#define GCD(a, b) __gcd(a, b) // 最大公約数
#define LCM(a, b) a / __gcd(a, b) * b // 最小公倍数

fn Main() {
    i32 N;
    cin >> N;
    i64 sum = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 3 != 0 && i % 5 != 0)
            sum += i;
    }
    cout << sum << endl;
}

fn main() -> int {
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  string s;
  cin >> s;
  int K;
  cin >> K;
  int N = s.size();
  REP(i, N)
  {
    int t = (26 - (s[i] - 'a')) % 26;
    if (t <= K)
    {
      s[i] = 'a';
      K -= t;
    }
  }
  K %= 26;
  int last = s[N - 1] - 'a';
  last = (last + K) % 26;
  s[N - 1] = (char)(last + 'a');
  cout << s << endl;
  return 0;
}

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

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

    int ans = 1;
{
    int one = 1;
    for(auto p:A){
        if(p == 1) one++;
        if(ans < one) ans = one;
        if(p == 0) one = 1;
    }
}

    cout<<ans<<endl;
}



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

int n,a,b,c;

int next(int x){
	return ( (a*x+b) % c );
}

int main(){
	int x;
	
	while( cin >> n >> a >> b >> c >> x , n||a||b||c||x ){
		int y[101] = {0};
		int cnt=0;
		
		for(int i=0 ; i<n ; i++ ){
			cin >> y[i];
		}
		for(int i=0 ; cnt <= 10000 && i < n ; ){
			if( y[i] == x ){
				i++;
				if( i == n ) break;
			}
			x = next(x);
			cnt++;
		}
		cout << ( (cnt>10000)? -1 : cnt ) << endl;
	}
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;


using Graph = vector<vector<int>>;//グラフ型
void dfs(const Graph& G, int v/*根*/, vector<bool>& seen) {
	seen[v] = true;  //vを訪問済にする
	for (auto next_v : G[v]) { //訪問済にしたvとつながっている場所を順番に探す
		if (seen[next_v]) continue; //もし探索済みならスルー
		dfs(G, next_v, seen); //再帰的に探索
	}
}

void bfs(const Graph& G, queue<int>& que/*発見したが訪問はしていない*/, vector<int>& dist/*開始地点からの距離*/) {

	while (!que.empty()) {
		int v = que.front();//queのうち先頭のものからスタート
		que.pop();//先頭を削除

		for (int nv : G[v]) {//vとつながっている点を列挙
			if (dist[nv] != -1) continue;//発見済(=距離が格納されている)であればスルー
			dist[nv] = dist[v] + 1;//vとつながっている点に距離の情報を追加
			que.push(nv);//vとつながっている点を発見済にする
		}
	}
}

template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}


template<typename T>
bool same(T x_b, T x_e, T y_b, T y_e) {
	for (auto i = x_b, j = y_b; i != x_e && j != y_e; ++i, ++j) {
		if (*i != *j) {
			return false;
		}
	}
	return true;
}


int main(void) {
	map<string, int>s;
	ll n;
	string s_;
	cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> s_;
		if (s[s_] == 0) {
			s[s_] = 1;
			++ans;
		}
	}
	cout << ans;

}

/*

*/


Measured memory_bytes: 19232
package main

import "fmt"

func main() {
	var q int
	var x string
	fmt.Scan(&x, &q)
	s := []byte(x)

	for i := 0; i < q; i++ {
		var cmd string
		var a, b int
		fmt.Scan(&cmd, &a, &b)
		switch cmd {
		case "print":
			fmt.Println(string(s[a : b+1]))
		case "reverse":
			for i := a; i <= (a+b)/2; i++ {
				s[i], s[b+a-i] = s[b+a-i], s[i]
			}
		case "replace":
			var p string
			fmt.Scan(&p)
			copy(s[a:b+1], []byte(p))
		}
	}
}



Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;


int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> connect(N);
  for (ll i = 0; i < N - 1; ++i)
  {
    ll a, b;
    cin >> a >> b;
    connect.at(a - 1).push_back(b - 1);
    connect.at(b - 1).push_back(a - 1);
  }
  // for (ll i = 0; i < N; ++i)
  // {
  //   for (ll j = 0; j < connect.at(i).size(); ++j)
  //   {
  //     cout << connect.at(i).at(j) << ' ';
  //   }
  //   cout << endl;
  // }
  vector<bool> colored(N, false);
  colored.at(0) = true;
  colored.at(N - 1) = true;
  queue<ll> fennec;//node
  queue<ll> snuke;//node
  fennec.push(0);
  snuke.push(N - 1);
  ll snuke_point = 1, fennec_point = 1;
  while (!fennec.empty() || !snuke.empty())
  {
    ll now;
    if (!fennec.empty())
    {
      ll fennec_size = fennec.size();
      for (ll j = 0; j < fennec_size; ++j)
      {
        now = fennec.front();
        fennec.pop();
        for (ll i = 0; i < connect.at(now).size(); ++i)
        {
          if (colored.at(connect.at(now).at(i)))
          {
            continue;
          }
          colored.at(connect.at(now).at(i)) = true;
          fennec.push(connect.at(now).at(i));
          fennec_point += 1;
        }
      }
    }

    if (!snuke.empty())
    {
      ll snuke_size = snuke.size();
      for (ll j = 0; j < snuke_size; ++j)
      {
        now = snuke.front();
        snuke.pop();
        for (ll i = 0; i < connect.at(now).size(); ++i)
        {
          if (colored.at(connect.at(now).at(i)))
          {
            continue;
          }
          colored.at(connect.at(now).at(i)) = true;
          snuke.push(connect.at(now).at(i));
          snuke_point += 1;
        }
      }
    }
  }
  // cout << fennec_point << ' ' << snuke_point << endl;
  if (snuke_point < fennec_point)
  {
    cout << "Fennec" << endl;
  }
  else
  {
    cout << "Snuke" << endl;
  }
}


Measured memory_bytes: 6400
#include <stdio.h>

int main(void)
{
	int x,y,z,c,d,a[100][100],b[100][100];
	scanf("%d %d",&c,&d);
	char i[100];
	for(x=0;x<c;x++) for(y=0;y<d;y++) b[x][y] = 0;
	for(x=0;x<c;x++)
	{
		scanf("%s",i);
		for(y = 0;y<d;y++)
		{
			if (i[y] == '#') a[x][y] = 1;
			else a[x][y] = 0;
		}
	}
	for(x=0;x<c;x++)
	{
		for(y = 0;y<d;y++)
		{
			if (a[x][y] == 1) 
			{
				for(z=0;z<d;z++) b[x][z] = 1;
				y = d;
			}
		}
		
	}
	for(y = 0;y<d;y++)
	{
		for(x=0;x<c;x++)
		{
			if (a[x][y] == 1)break;
		}
		if (x==c)
		{
			for(z=0;z<c;z++) b[z][y] = 0;
		}
	}
	int ind;
	for(x=0;x<c;x++) 
	{
		ind = 0;
		for(y=0;y<d;y++) {
			if (b[x][y]) 
			{
				if(a[x][y]) printf("#"); 
				else printf(".");
				ind = 1;
			}
		}
		if (ind) puts("");
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int W,H,x,y,r;
 /* ????????°a ?????¢?????¬?????????????????¢?????¨?????¢?????\?????????????????´??°????????????????´???????????????????????????????*/
      scanf("%d%d%d%d%d", &W,&H,&x,&y,&r);
      if((x-r)<0||(y-r)<0||(x+r)>W||(y+r)>H)
  {
    printf("No\n");
  }
else
{
printf("Yes\n");
};
    return 0;
}

Measured memory_bytes: 1012
run (function * (write, gets) {
	var white = +(yield) - 1;
	var black = +(yield) - 1;
	var lines = [];
	do {
		var line0 = "", line1 = "";
		for (var i = 0; i < 100; i += 2) {
			if (0 < white) {
				line0 += ".#";
				line1 += "##";
				--white;
			} else {
				line0 += "##";
				line1 += "##";
			}
		}
		lines.push(line0, line1);
	} while (0 < white);
	do {
		var line0 = "", line1 = "";
		for (var i = 0; i < 100; i += 2) {
			if (0 < black) {
				line0 += "..";
				line1 += "#.";
				--black;
			} else {
				line0 += "..";
				line1 += "..";
			}
		}
		lines.push(line0, line1);
	} while (0 < black);
	write(`${lines.length} 100`);
	for (var i = 0; i < lines.length; ++i) {
		write(lines[i]);
	}
});

/**
 * @param {(write: (line: string, end?: string) => void, gets: () => IterableIterator<string|null>) => IterableIterator<any>} main 
 */
function run (main) {
	var istream = process.stdin;
	var ostream = process.stdout;

	/**
	 * @type {[string|null]}
	 */
	var words = [];
	/**
	 * @type {[string]}
	 */
	var lines = [];
	var rest = "";
	var ended = false;
	var INPUT_MODE_LINE = 0;
	var INPUT_MODE_WORD = 1;
	var input_mode = INPUT_MODE_WORD;

	/**
	 * @param {string} line 
	 * @param {string} [end] 
	 */
	function write (line, end) {
		ostream.write(line + (undefined === end ? os.EOL : end));
	}
	function *gets () {
		if (0 < lines.length) {
			return lines.shift();
		} else {
			input_mode = INPUT_MODE_LINE;
			/**
			 * @type {string}
			 */
			var line = yield;
			input_mode = INPUT_MODE_WORD;
			return line;
		}
	}

	var main_itr = main(write, gets);

	/**
	 * @param {string|null} chunk 
	 */
	function get_chunk (chunk) {
		istream.pause();
		if (null === chunk) {
			lines.push(null);
		} else {
			rest += chunk;
			var line_exp = /.*(\r?\n|\r)/g;
			var line_match, lastIndex = 0;
			while (null !== (line_match = line_exp.exec(rest))) {
				lastIndex = line_exp.lastIndex;
				lines.push(line_match[0]);
			}
			rest = rest.substring(lastIndex);
		}
		loop();
	}

	function loop () {
		while (0 < lines.length) {
			switch (input_mode) {
				case INPUT_MODE_LINE:
				{
					words.push(lines.shift());
				}
				break;
				case INPUT_MODE_WORD:
				{
					if (null === lines[0]) {
						words.push(lines.shift());
					} else {
						var word_exp = /[^\s]+/g;
						var line_match;
						if (null !== (line_match = word_exp.exec(lines[0]))) {
							words.push(line_match[0]);
							lines[0] = lines[0].substring(word_exp.lastIndex);
						} else {
							lines.shift();
						}
					}
				}
				break;
			}

			while (0 < words.length) {
				var result = main_itr.next(words.shift());
				if (undefined !== result.value) {
					if ('string' === typeof result.value) {
						write(result.value, "");
					} else {
						write(`${result.value}`, "");
					}
				}
				if (result.done) return;
			}
		}

		ended ? setTimeout(get_chunk, 0, null) : istream.resume();
	}
	istream.on('data', get_chunk);
	istream.on('end', function () {
		ended = true;
		get_chunk(null);
	});

	istream.setEncoding('utf8');
	get_chunk(null);
};

var os = require('os');


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

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, int> pli;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 200010;

int N;
int P[MN];
int len[MN];

int main() {
	cin >> N;

	rep(i, N) {
		cin >> P[i];
		--P[i];
	}

	memset(len, -1, sizeof(len));

	rep(i, N) {
		len[P[i]] = 1;
		if (P[i] > 0 && len[P[i] - 1] != -1) {
			len[P[i]] = len[P[i] - 1] + 1;
		}
	}

	cout << N - *max_element(len, len + MN) << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin() (x).end()
#define rall(x) (x).rbegin() (x).rend()
typedef long long ll;

int main(){
	fastIO;
	int x;
    cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using i64 = int64_t;

struct Hand{
    int lose, win, tie, num;
    bool operator<(const Hand &rhs)const{
        if(lose == rhs.lose)return win > rhs.win;
        return lose < rhs.lose;
    }
};

int main(){
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(n));
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            char c;
            cin >> c;
            if(c == '-')v[i][j] = 0;
            else if(c == 'o')v[i][j] = 1;
            else v[i][j] = -1;
        }
    }
    vector<Hand> hands;
    for(int i=0;i<n;++i){
        Hand h({0, 0, 0, 0});
        h.num = i + 1;
        for(int j=0;j<n;++j){
            if(v[i][j] == -1)h.lose++;
            else if(v[i][j] == 0)h.tie++;
            else h.win++;
        }
        hands.push_back(h);
    }
    sort(hands.begin(), hands.end());
    /*
    for(auto e: hands){
        cout << e.num << " " << e.win << " " << e.tie << " " << e.lose << endl;
    }
    */
    vector<int> ans;
    ans.push_back(hands[0].num);
    for(int i=1;i<n;++i){
        if(hands[i].lose == hands[0].lose)ans.push_back(hands[0].num);
        else break;
    }
    int win = 0, tie = 0, lose = 0;
    random_device rnd;
    for(int i=0;i<1000;++i){
        int ai_hand;
        int my_hand;
        if(lose < 500){
            int idx = rnd() % (int)(ans.size());
            my_hand = ans[idx];
        }else{
            my_hand = rnd() % n + 1;
        }
        cout << my_hand << endl;
        cin >> ai_hand;
        if(v[my_hand-1][ai_hand-1] == -1)lose++;
        else if(v[my_hand-1][ai_hand-1] == 0)tie++;
        else win++;
    }

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    string scores[N];
    for(int i = 0; i < N; i++){
        cin >> scores[i];
    }

    int AC = 0;
    int WA = 0;
    int TLE = 0;
    int RE = 0;

    for(int t = 0; t < N; t++)
    {
        if(scores[t] == "AC")
            AC++;
        else if(scores[t] == "WA")
            WA++;
        else if(scores[t] == "TLE")
            TLE++;
        else if(scores[t] == "RE")
            RE++;
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE<< endl;
}

Measured memory_bytes: 6712