akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295
#define equals(a,b)(fabs((a)-(b))<EPS)

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef complex<double> comp;
typedef vector<complex<double>> vcomp;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef string::const_iterator State;
class ParseError {};
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;



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

	int N;
	cin >> N;
	vi p(N);
	rep(i, N) {
		cin >> p[i];
		p[i]--;
	}
	int ans = 0;
	rep(i, N) {
		if (p[i] == i) {
			ans++;
			if (i < N - 1 && p[i + 1] == i + 1) {
				i++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

vll z_algorithm(string S){
    if(S.size()==0) return vll(0);
    vll ret(S.size());
    ret[0] = S.size();
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) j++;
        ret[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < S.size() && k+ret[k] < j) {
            ret[i+k] = ret[k];
            k++;
        }
        i += k; j -= k;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    string S;
    cin>>N>>S;
    
    ll ans=0;
    for(int i=0;i<N;i++){
        vll A=z_algorithm(S.substr(i));
        for(int j=0;j<A.size();j++){
            ans=max(ans,min(A[j],(ll)j));
        }
    }
    cout<<ans<<endl;
        
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
int i;
#define rep2(i, a, b) for(i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
using namespace std;
// _________コーディングはここから！！___________
template <const int sz = 5 * 10000000, typename T = long long> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO io;
inline int read() { return io.read(); }
inline void write(int x) { io.write(x); }
inline void write(int x, char c) { io.write(x, c); }
constexpr int N = 500003;
int c[N];
struct T {
    int l, r, idx;
    constexpr bool operator<(const T &rhs) const noexcept { return r < rhs.r; }
} q[N];
int ans[N], last[N], dat[N];

inline void dec(int k) {
    for(++k; k < N; k += k & -k) --dat[k];
}
inline int sum(int k) {
    int res = 0;
    for(++k; k > 0; k -= k & -k) res += dat[k];
    return res;
}
int n, Q, now = 1;

// 頑張れ！！
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("unroll-loops")
// 頑張れ！！

main() {
    n = read(), Q = read();
    rep2(i, 1, n) c[i] = read();
    rep(i, Q) q[i].l = read(), q[i].r = read() + 1, q[i].idx = i;
    sort(q, q + Q);
    rep(i, Q) {
        for(; now < q[i].r; ++now) {
            if(last[c[now]]) dec(last[c[now]]);
            last[c[now]] = now;
        }
        ans[q[i].idx] = sum(q[i].r - 1) - sum(q[i].l - 1) + q[i].r - q[i].l;
    }
    rep(i, Q) write(ans[i], '\n');
}


Measured memory_bytes: 26784
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  string s;
  cin >> s;
  int n=s.size();
  
  int cnt=0;
  rep(i,n){
    if(s[i]=='o')cnt++;
  }
  
  cout << (cnt+15-n>=8?"YES":"NO") << endl;
  
}

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

//+=を=+と打っても動作するが意味が違う

const int INF = 1001000000;
/*
int main(){
  int n,d[200],res=0;
  cin >> n ;
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d,d+n);
  for(int j=1;j<n;j++){
    if(d[j]!=d[j-1]){
      res++;
    }
  }
  cout << res+1 << endl;//最初の一枚をたす
}
*/
int main(){
  int n,d[200];
  cin >> n;
  for(int i=0;i<n;++i){
    cin >> d[i];
  }
  int a[200]={0};
  for(int j=0;j<n;j++){
    a[d[j]]=1;
  }
  int res=0;
  for(int k=0;k<200;k++){
    if(a[k]==1)res++;
  }
  cout << res << endl;
}


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

int main() {
  int n,k,r,s,p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;
  vector<char>hand(k);
  int ans=0;
  for(int i=0;i<k;i++) hand[i]='a';
  for(int i=0;i<n;i++){
    if(t[i]=='r'){
      if(hand[i%k]=='p') hand[i%k]='a';
      else{
        ans+=p;
        hand[i%k]='p';
      }
    }
    if(t[i]=='s'){
      if(hand[i%k]=='r') hand[i%k]='a';
      else{
        ans+=r;
        hand[i%k]='r';
      }
    }
    if(t[i]=='p'){
      if(hand[i%k]=='s') hand[i%k]='a';
      else{
        ans+=s;
        hand[i%k]='s';
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
using namespace std; void solve();
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cout << #v << " = "; array_out(v , N);cout << endl;} while(0)
  int main(){solve_dbg();}
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<int,int>;
constexpr int MOD = 1000000007;
random_device seed_gen; mt19937_64 mtrand(seed_gen());

//////////////////////////////////////////

void solve(){
  ini(N);
  vvi v(N , vi(N , -1));
  rep(i , N) rep(j , N){
    v[i][j] = __builtin_ffs(i ^ j);
  }

  rep(i , N) {
    for(int j = i + 1; j < N ; j++){
      cout << (j==i+1?"":" ") << v[i][j];
    }
    out();
  }
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) P("Draw");
  else if (a == 1) P("Alice");
  else if (b == 1) P("Bob");
  else if (a > b) P("Alice");
  else P("Bob");
  return 0;
}

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

typedef long long ll;

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

	if (n % 2) {
		int dif = 1;
		int pivot = n / 2;
		for (int i = 0; i < m; i++) {
			cout << pivot << " " << pivot + dif << endl;
			pivot--;
			dif += 2;
		}
	}
	else {
		int dif = 1;
		int pivot = n / 2;
		int i = 0;
		for (; i < m; i++) {
			if (i >= n / 4) break;
			cout << pivot << " " << pivot + dif << endl;
			pivot--;
			dif += 2;
		}
		dif++;
		for (; i < m; i++) {
			cout << pivot << " " << pivot + dif << endl;
			pivot--;
			dif += 2;
		}
	}

	return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
    int a1,a2,a3;
    scanf("%d", &a1);
    scanf("%d", &a2);
    scanf("%d", &a3);
    if(a1 + a2 + a3 <= 21){
        printf("win\n");
    }
    else{
        printf("bust\n");
    }
    return 0;
}

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

using namespace std;

int main ( void )
{
	int n, m, room[101], cost[101];
	
	while (cin >> n >> m)
	{
		fill(room, room+101, -1);
		fill(cost, cost+101, -1);
		
		for (int i = 0, a, b; i < m; ++i)
		{
			cin >> a >> b;
			cost[a-1] = max(cost[a-1], b);
		}
		
		for (int i = 0; i < n; ++i)
		{
			if (cost[i] <= -1)
				continue;
				
			int idx;
			for (idx = i; idx < cost[i]; ++idx)
				room[idx] = i;
			
			for (int j = i+1; j <= idx; ++j)
				cost[idx] = max(cost[idx], cost[j]);
			
			if (idx != i)
				i = idx - 1;
		}
		
		int ans = 1;

		for (int i = 0, val = room[0]; i < n; ++i)
		{
			if (room[i] == -1)
			{
				ans = -1;
				break;
			}
			if (room[i] != val)
			{
				++ans;
				val = room[i];
			}
		}
	
		if (ans == -1)
			cout << "Impossible" << endl;
		else
			cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2==0){
        cout << (b-a)/2 << endl;
    }else{
        ll ans=min(a-1,n-b);
        ans+=(b-a)/2+1;
        cout << ans << endl;
    }
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
char fld[333][333];

signed main(){
    cin>>N;
    rep(i,N)cin>>fld[i];

    int ans=0;
    for(int x=-(N-1);x<=N-1;x++){
        bool flag=true;
        rep(i,N)rep(j,N)if(fld[i][(j+x+N)%N]!=fld[j][(i+x+N)%N])flag=false;
        if(!flag)continue;
        ans+=N-abs(x);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
	int N, Q, q;
	cin >> N >> Q;
	vector<int> c(N);
	for (int i = 0; i < N; i++) {
		cin >> c[i];
	}
	sort(c.begin(), c.end());
	vector<int> res(300001);
	for (int i = 2; i <= 300000; i++) {
		for (int j = i; j <= 300000; j += i) {
			if (c.front() >= j) continue;
			res[i] = max(res[i], *(lower_bound(c.begin(), c.end(), j) - 1) % i);
		}
	}
	while (Q--) {
		cin >> q;
		cout << res[q] << endl;
	}
	return 0;
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int k,x;
    cin >> k >> x;
    int a = k-1;
    for(int i=x-a;i<=x+k-1;i++){
        cout << i;
        cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3620
<?php
list($N,$M) = explode(" ",trim(fgets(STDIN)));
for($i = 0;$i < $M;$i++){
    $in = explode(" ",trim(fgets(STDIN)));
    $x[] = $in[0];
    $y[] = $in[1];
}
for($i = 1;$i <= $N;$i++){
    $box[$i] = 1;
    $ans[$i] = 0;
}
$ans[1] = 1;
foreach($x as $key => $val){
    $box[$val]--;
    $box[$y[$key]]++;
    if($ans[$val] == 1){
        if($box[$val] == 0){
            $ans[$val] = 0;
        }
        $ans[$y[$key]] = 1;
    }
}
echo array_sum($ans);

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

const int MAX = 1000001;

unordered_set<int> primer;
vector<int> eratos(MAX);

bool divisor(int n){
  while(n > 1){
    if(primer.count(eratos[n])){
      return false; 
    } else{
      primer.insert(eratos[n]);
      int x = eratos[n];
      while(n % x == 0){
        n /= x;
      }
    }
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  long long N;
  cin >> N;
  bool setwise = false, pairwise = true;
  vector<int> A(N);
  bool allone = true;

  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  //gcd of all
  int Gcd = A[0];
  for(int i = 1; i < N; i++){
    Gcd = __gcd(A[i], Gcd);
  }
  if(Gcd == 1){
    setwise = true;
  }

  //eratos
  eratos[1] = 1;
  for(int i = 2; i < MAX; i++){
    for(int j = 2; j * j <= i; j++){
      if(i % j == 0){
        eratos[i] = j;
        break;
      }
    }
    if(eratos[i] == 0){
      eratos[i] = i;
    }
  }

  //for(int i = 1; i < 100; i++) cout << i << " " << eratos[i] <<endl;

  for(int i = 0; i < N; i++){
    if(!divisor(A[i])){
      pairwise = false;
      break;
    }
  }

  if(pairwise) cout << "pairwise coprime" <<endl;
  else if(setwise) cout << "setwise coprime" <<endl;
  else cout << "not coprime"<<endl;
}



Measured memory_bytes: 11088
import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();
		int m = in.nextInt();
		int[][] a = new int[n][m];
		int[] b = new int[m];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				a[i][j] = in.nextInt();
			}
		}
		for(int i = 0; i < m; i++) {
			b[i] = in.nextInt();
		}
		for(int i = 0; i < n; i++) {
			long sum = 0;
			for(int j = 0; j < m; j++) {
				sum += a[i][j] * b[j];
			}
			out.println(sum);
		}
	}
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

void ndfs(int pos, int d);
void odfs(int pos, int d);

vector<int> tree[SIZE];

int ndist[SIZE], odist[SIZE];
bool visit[SIZE];

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

    int n;
    cin >> n;
    for(int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        tree[a].pb(b);
        tree[b].pb(a);

    }

    ndfs(n, 0);
    for(int i = 1; i <= n; ++i) visit[i] = false;
    odfs(1, 0);

    int c1, c2;
    c1 = c2 = 0;
    for(int i = 1; i <= n; ++i) {
        if(odist[i] <= ndist[i]) ++c1;

    }

    for(int i = 1; i <= n; ++i) {
        if(ndist[i] < odist[i]) ++c2;

    }
    if(c1 > c2) cout << "Fennec";
    else cout << "Snuke";
    cout << endl;

    return 0;
}

void ndfs(int pos, int d) {
    if(visit[pos]) return;
    visit[pos] = true;
    ndist[pos] = d;

    for(int i = 0; i < tree[pos].size(); ++i) {
        ndfs(tree[pos][i], ndist[pos] + 1);

    }
    return;
}

void odfs(int pos, int d) {
    if(visit[pos]) return;
    visit[pos] = true;
    odist[pos] = d;

    for(int i = 0; i < tree[pos].size(); ++i) {
        odfs(tree[pos][i], odist[pos] + 1);

    }
    return;
}


Measured memory_bytes: 13696
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int a,b,c; cin>>a>>b>>c;
  int ans;
  if(a + b < c - 1) {
    ans = a + b + 1 + b;
  } else {
    ans = b + c;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<map>
#include<functional>
using namespace std;
typedef long long int llint;
typedef bool izryt;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int big=1e9;
const int mod=1e9 + 7;
int main(void){
	llint n,m,i,j,k,ans=1,gen=0;cin>>n>>m;
	if(n<m){swap(n,m);}
	if(n>m+1){cout<<0<<endl;return 0;}
	for(i=1;i<=n;i++){
		ans*=i;
		ans%=mod;
	}
	for(i=1;i<=m;i++){
		ans*=i;
		ans%=mod;
	}
	if(n==m){ans*=2;ans%=mod;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	char c;

	cin >> c;

	c++;

	cout << c << endl;




	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int k;
    cin >> k;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int c[n];
    fill(c, c + n, 0);
    for (int i = 0; i < n; i++) {
        c[a[i] - 1]++;
    }
    sort(c, c + n);
    reverse(c, c + n);
    int res = n;
    for (int i = 0; i < k; i++) {
        res -= c[i];
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

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

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

signed main() {
  init();
  ll N;
  cin >> N;
  if (N == 0) {
    COUT(1);
  } else {
    COUT(0);
  }
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  string S;
  cin >> S;
  if( S == "ABC" ) cout << "ARC" << endl;
  else cout << "ABC" << endl;
  
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int X, Y, Z;
  
  cin >> X >> Y >> Z;
  
  int x1, y1, z1;
  x1 = Y;
  y1 = X;
  z1 = Z;
  
  int x2, y2, z2;
  x2 = z1;
  y2 = y1;
  z2 = x1;
  
  cout << x2 << " " << y2 << " " << z2 << endl;
}

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

int main()
{
    float n,x,t;
    cin>>n>>x>>t;
    if(n<=x)
    {
        cout<<t;
    }
    else
    {

        float k=ceil(n/x);
        cout<<int(k*t);
    }
    return 0;
}



Measured memory_bytes: 3792
#include <stdio.h>

int main(){
	int T,D,L;
	for(;~scanf("%d%d%d",&T,&D,&L)&&T&&D&&L;){
		int r=0;
		for(int i=0,x,y=0;i<T;i++){
			if(--y>=0)r++;
			scanf("%d",&x);
			if(x>=L)y=D;
		}
		printf("%d\n",r);
	}
}

Measured memory_bytes: 2732
//#define _XCODE_DEBUG

#include <iostream>
#include <vector>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main(int argc, const char * argv[]) {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    
    int N, a;
    std::cin >> N;
    std::vector<int> vec_a(N, 0);
    
    for(int i=0; i<N-1; ++i) {
        std::cin >> a;
        vec_a[a-1] += 1;
    }
    for (int i=0; i<N; ++i) {
        std::cout << vec_a[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3680
// NTL_1_A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

int n;
vector<int> soinsu;
void bunkai(int x){
    int now=x;
    for(int i=2;i*i<=n;i++){
        while(true){
            if(now%i!=0) break;
            soinsu.e_b(i);
            now/=i;
        }
    }
    if(now!=1) soinsu.e_b(now);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    cin>>n;
    bunkai(n);
    cout<<n<<":";
    rep(i,sz(soinsu)){
        cout<<" "<<soinsu[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3212
n, y = gets.strip.split.map(&:to_i)
_i, _j, _k = -1, -1, -1

(0..n).each do |i|
    (0..n-i).each do |j|
       if i * 10000 + j * 5000 + (n - i - j) * 1000 == y
           _i, _j, _k = i, j, n - i - j
       end
    end
end

puts "#{_i} #{_j} #{_k}"

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

using namespace std;

void solve()
{
	long H, W, N;
	cin >> H >> W >> N;
	vector<long> walls[W];
	map<long, bool> iswall;
	while (N--)
	{
		long h, w;
		cin >> h >> w;
		walls[w-1].push_back(h-1);
		iswall[W*(h-1)+w-1] = 1;
	}

	for (long w = 0; w < W; w++)
	{
		walls[w].push_back(H);
		iswall[H*W+w] = 1;
		sort(walls[w].begin(), walls[w].end());
	}

	long ans = *lower_bound(walls[0].begin(), walls[0].end(), 0);
	long nh = 0, nw = 0;

	while (nw < W-2)
	{
		bool f = 0;

		while(!iswall[(nh+1)*W+nw])
		{
			f = 1;
			nh++;
			if (!iswall[nh*W+nw+1])
			{
				nw++;
				break;
			}
		}

		if (!f) break;

		ans = min(*lower_bound(walls[nw].begin(), walls[nw].end(), nh), ans);

		//cout << nw << ' ' << nh << ' ' << ans << endl;
	}

	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

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

int main(){
  int n, m;
  const int max = 1e5;
  vector<int> p(max+1);
  vector<string> s(max+1);
  // vector<vector<bool>> res(max+1);
  // map<int, bool> res;
  // map<int,int> ac;
  bool res[max+1];
  int pena[max+1];


  int sum_pena = 0;
  int ans = 0;

  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    cin >> p[i] >> s[i];
    p[i] --;
    res[p[i]] = false;
    pena[p[i]] = 0;
  }

  for(int i = 0; i < m; i++){
    if(res[p[i]] == false && s[i] == "WA") {
      pena[p[i]] ++;
    }
    if(res[p[i]] == false && s[i] == "AC") {
      res[p[i]] = true;
      ans ++;
    }
  }

  for(int i = 0; i < n; i++){
    // cout << res[i] << endl;
    // cout << pena[i] << endl;
    if(res[i] == false) pena[i] = 0;
    sum_pena += pena[i];
  }

  cout << ans << " " << sum_pena << endl;


  return 0;
}

Measured memory_bytes: 6528
/**
 	Template created by Danel Batyrbek
 	All rights are reserved 2017 (lol)
*/

#include <bits/stdc++.h>

#define speed_up ios_base :: sync_with_stdio(0);cin.tie(0)
#define fr first
#define sc second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << x << '\n';
#define YES "YES"
#define NO "NO"
#define skip continue
#define left(x) x << 1
#define rght(x) x << 1 | 1
#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define for1(x, y, z) for(int x = y; x >= z; -- x)
#define fname ""
using namespace std;

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

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const ll LINF = 2e18;

string s;
ll total, cnt[26];

int main(){
#ifndef DEBUG
	if(fname != ""){
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	}
#endif
	cin >> s;
	ll n = (ll)s.size() - 1;
	total = (n + 1) * n / 2 + 1;
	forn(i, 0, n){
		int ch = s[i] - 'a';
		cnt[ch] ++;
	}
	forn(i, 0, 25){
		if(cnt[i] < 2) skip;
		total -= (cnt[i] - 1) * cnt[i] / 2;
	}
	cout << total;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string s;
  cin >> s;
  ll ans = 0;

  for (ll i=1; i<=ll(s.size()/2); i++) {
    // cout << i << " " << s.substr(0, s.size()/2 - i) << " " << s.substr(s.size()/2 - i, s.size()/2 - i) << endl;
    if (s.substr(0, s.size()/2 - i) == s.substr(s.size()/2 - i, s.size()/2 - i)) {
      ans = s.size() - 2 * i;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vector<bool> used(n, false);
    for(int i = 0; i < n; i++){
        used[s[i] - 'a'] = true;
    }
    if(n < 26){
        for(int i = 0; i < 26; i++){
            if(!used[i]){
                cout << s << (char)('a'+i) << endl;
                break;
            }
        }
    }else{
        int id = -1;
		for(int i = n - 2; i >= 0; i--){
            if(s[i] < s[i+1]){
                id = i;
                break;
            }
        }

		if(id == -1){
            cout << -1 << endl;
        }else{
            string t = s.substr(0,id);
            int idx2 = id + 1;
            for(int i = idx2; i < n; i++){
                if(s[i] < s[idx2] && s[i] > s[id]) idx2 = i;
            }
            t += s[idx2];
            cout << t << endl;
        }
    }
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pii> v;
		rep(i,n){
			vector<pii> tt;
			int id;
			cin>>id;
			int t;
			int cnt=1;
			while(1){
				cin>>t;
				if(cnt==10){
					int a=t;
					if(a==10){
						tt.PB(mkp(a,cnt));
						cin>>t;
						tt.PB(mkp(t,cnt));
						cin>>t;
						tt.PB(mkp(t,cnt));
						break;
					}
					else{
						tt.PB(mkp(t,cnt));
						cin>>t;
						tt.PB(mkp(t,cnt));
						if(a+t==10){
							cin>>t;
							tt.PB(mkp(t,cnt));	
						}
						break;
						
					}
				}
				else if(t==10){
					tt.PB(mkp(t,cnt));
				}
				else{
					tt.PB(mkp(t,cnt));
					cin>>t;
					tt.PB(mkp(t,cnt));
				}
				cnt++;
			}
			int tmp=0;
			// cout<<"id = "<<id<<endl;
			// rep(i,tt.size()){
				// cout<<tt[i].F<<" "<<tt[i].S<<endl;
			// }
			// cout<<endl;
			rep(i,tt.size()){
				if(tt[i].S==10){
					tmp+=tt[i].F;
					continue;
				}
				if(tt[i].F==10){
					tmp+=10+tt[i+1].F+tt[i+2].F;
					continue;
				}
				if(tt[i].F+tt[i+1].F==10){
					tmp+=10+tt[i+2].F;
					i++;
				}
				else{
					tmp+=tt[i].F+tt[i+1].F;
					i++;
				}
			}
			v.PB(mkp(-tmp,id));
		}
		sort(ALL(v));
		rep(i,n) cout<<v[i].S<<" "<<-v[i].F<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1200
N=int(input())
a=list(map(int,input().split()))
a=sorted(a)
n=a[-1]
r=a[0]
r_max=a[0]
if n//2<r:
    r_max=n-a[0]
for i in range(N-1):
    r_kari=a[i]
    r_=r_kari
    if n//2<r_:
        r_=n-r_
    if r_max<r_:
        r_max=r_
        r=r_kari
    #print(r_max)
print(str(n)+" "+str(r))

Measured memory_bytes: 62704
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, AB):
    AB.sort()
    ans = 0

    for a, b in AB:
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += a * M
            M -= M
            break

    return ans


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 30280
N = int(input())
num = int(10e10)
ans = 0
for i in range(N):
  tmp = int(input())
  if tmp%10!=0:
    num = min(num,tmp)
  ans += tmp
  
if ans%10==0 and num==int(10e10):
  print(0)
elif ans%10!=0:
  print(ans)
else:
  print(ans-num)

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

vec<vi> dp;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(30);

    string s,t,ans; cin >> s >> t;
    dp.resize(s.size()+1, vi(t.size()+1));

    for(int i = 0; i < s.size(); ++i) {
        for(int j = 0; j < t.size(); ++j) {
            if(s[i]==t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

// 復元
    int i = (int)s.size()-1;
    int j = (int)t.size()-1;
    while(i>=0&&j>=0) {
        if(dp[i+1][j+1] == dp[i+1][j]) --j;
        else if(dp[i+1][j+1] == dp[i][j+1]) --i;
        else if(dp[i+1][j+1] == dp[i][j] + 1) {
            ans = s[i] + ans;
            --i; --j;
        }
    }
    cout << ans << '\n';
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

long long near(long long pos, set<long long> &S) {
    auto it1 = *S.lower_bound(pos);
    auto it2 = *--S.lower_bound(pos);
    return min(abs(it1 - pos), abs(it2 - pos));
}

void solve(long long A, long long B, long long Q, std::vector<long long> s,
           std::vector<long long> t, std::vector<long long> x) {
    set<long long> X[2];
    X[0] = set<long long>(s.begin(), s.end());
    X[1] = set<long long>(t.begin(), t.end());

    for (int i = 0; i < 2; i++) {
        X[i].insert(-1e18);
        X[i].insert(1e18);
    }

    set<pair<long long, int>> Z;
    for (auto i : X[0]) {
        Z.insert({i, 0});
    }
    for (auto i : X[1]) {
        Z.insert({i, 1});
    }

    for (auto q : x) {
        auto it1 = *Z.lower_bound({q, -1});
        auto it2 = *--Z.lower_bound({q, -1});
        long long bst = 1e18;

        for( auto i : {it1, it2}){
            if( abs(i.first) > 1e15 ) continue;
            bst = min(bst, abs(i.first-q) + near(i.first, X[!i.second]));
        }
        cout << bst << endl;
    }

}

int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> s(A);
    for (int i = 0; i < A; i++) {
        scanf("%lld", &s[i]);
    }
    std::vector<long long> t(B);
    for (int i = 0; i < B; i++) {
        scanf("%lld", &t[i]);
    }
    std::vector<long long> x(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &x[i]);
    }
    solve(A, B, Q, std::move(s), std::move(t), std::move(x));
    return 0;
}


Measured memory_bytes: 25600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  pb push_back
#define f first
#define s second

///shortcuts
///ctr+alr+T
ll my_max(ll a, ll b)
{
    return a>b? a: b;
}

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

    int n , w; cin>>n>>w;
    vector< pair<ll,ll> > v;
    v.pb({0,0});
    for (int i = 0; i < n; ++i) {
        ll ww;
        ll  vv;
        cin>>ww>>vv;
        v.pb({ww,vv});
    }

    ll dp[n+1][w+1];
    //sort(v.begin(),v.end());
   /* for(auto itr : v)
        cout<<itr.f<<" ";
    cout<<endl;
    for(auto itr : v)
        cout<<itr.s<<" ";
    cout<<endl;*/

    ll mx  = 0;
   // cout<<"haha"<<endl;
    for (int item = 0; item <= n ; item++) {
        for (int weight = 0; weight <= w; weight++)
        {
            if (item == 0 || weight == 0) {
                dp[item][weight] = 0;
            }
            else if (v[item].f <= weight) {
               // cout<<"haha"<<endl;
             //   cout<<v[item].f <<" "<<v[item].s<<endl;
                dp[item][weight] = my_max(v[item].s + dp[item - 1][weight - v[item].f],dp[item - 1][weight]);
               // cout<<"haha"<<endl;
            }
            else {
                dp[item][weight] = dp[item - 1][weight];
            }
           // cout<<dp[item][weight]<<" ";
            mx = my_max(mx  ,dp[item][weight]);
        }
       // cout<<endl;
    }
   cout<<mx<<endl;


}

Measured memory_bytes: 79232
S,T = input().split(" ")
S_num, T_num = input().split(" ")
S_num = int(S_num)
T_num = int(T_num)
U = input()
if S == U:
  print(str(S_num-1)+ " "+str(T_num) )
if T == U:
  print(str(S_num)+ " "+str(T_num-1) )

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<int>a(n),b(n);
    vector<int> memo(n,0);
    for(int i=0;i<m;i++){
        int aj,bj;
        cin>>aj>>bj;
        aj--;bj--;
        if(h[aj]<h[bj]){
            memo[aj]++;
        }else if(h[aj]>h[bj]){
            memo[bj]++;
        }else{
            memo[aj]++;
            memo[bj]++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(0==memo[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4768
#include <cstdio>
#include <vector>

using namespace std;

static int f(const vector<int>& ws, int P, int k) {
  int v = 0;
  int c = 0;
  int ntrack = 0;
  for (size_t i = 0; i < ws.size(); ++i) {
    if (c > 0 && P > 0 && c + ws[i] > P) {
      c = 0;
      ntrack++;
    }
    if (ntrack == k) {
      break;
    }

    if (c + ws[i] <= P) {
      c += ws[i];
      v++;
    }
  }
  return v;
}

int main() {
  int n, k;

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

  vector<int> ws(n);
  int max = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &ws[i]);
    max += ws[i];
  }

  int min = 1;
  int P = (min + max) / 2;
  while (min <= max) {
    const int v = f(ws, P, k);
    if (v >= n) {
      max = P - 1;
    } else { // v < n
      min = P + 1;
    }
    P = (min + max) / 2;
  }

  printf("%d\n", P+1);
  return 0;
}

Measured memory_bytes: 1268
#include <functional>
#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;

template <typename S>   //semi group
struct UnionFind
{
    using F = function<S(S, S)>;
    
    const F f;
    
    vector<int> par, rank;
    vector<S> dat;
    
    UnionFind(int n, const F f = [](S a, S b){return a + b;}, const S e = 1) : f(f){
        par.resize(n);
        rank.resize(n);
        dat.assign(n, e);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int i){
        if(i == par[i]) return i;
        return par[i] = find(par[i]);
    }
    
    bool same(int i, int j){
        return find(i) == find(j);
    }
    
    void unite(int i, int j){
        if(same(i, j)) return;
        i = find(i), j = find(j);
        if(rank[i] < rank[j]){
            par[i] = j;
            dat[j] = f(dat[i], dat[j]);
        }
        else{
            par[j] = i;
            dat[i] = f(dat[i], dat[j]);
            if(rank[i] == rank[j]) rank[i]++;
        }
    }
    
    S query(int i){
        return dat[find(i)];
    }
};

int main()
{
    int n;
    cin >> n;
    int x[200005], y[200005];
    PP pp[200005];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        pp[i] = PP(P(x[i], y[i]), i);
    }
    sort(pp, pp + n);
    stack<int> st;
    st.push(pp[0].second);
    UnionFind<int> uf(n);
    for(int i = 0; i < n; i++){
        if(y[st.top()] > y[pp[i].second]){
            st.push(pp[i].second);
            continue;
        }
        int l = st.top();
        while(st.size()){
            if(y[st.top()] < y[pp[i].second]){
                uf.unite(st.top(), pp[i].second);
                st.pop();
            }
            else break;
        }
        st.push(l);
    }
    for(int i = 0; i < n; i++) cout << uf.query(i) << endl;
}


Measured memory_bytes: 9560
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int n,l;
	string s[100];

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

	sort(s,s+n);

	for(int i = 0; i < n; i++)
	{
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256