akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <algorithm>
#include <cstdio>

using std::min;
const int N = 200010;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
int _w;

int fpow( int a, int b ) {
	int c = 1;
	while(b) {
		if( b & 1 ) c = int(1LL * c * a % MOD);
		a = int(1LL * a * a % MOD);
		b >>= 1;
	}
	return c;
}
int inv( int x ) {
	return fpow(x, MOD-2);
}

int n, x, y, c[N], w[N];
int cmin[N], cnt[N];
int pfmin[N], sfmin[N];

int fac[N];
void prelude() {
	fac[0] = 1;
	for( int i = 1; i < N; ++i )
		fac[i] = int(1LL * fac[i-1] * i % MOD);
}

int main() {
	_w = scanf( "%d%d%d", &n, &x, &y );
	memset(cmin, 0x3f, sizeof cmin);
	memset(pfmin, 0x3f, sizeof pfmin);
	memset(sfmin, 0x3f, sizeof sfmin);
	for( int i = 1; i <= n; ++i ) {
		_w = scanf( "%d%d", c+i, w+i );
		cmin[c[i]] = min( cmin[c[i]], w[i] );
		++cnt[c[i]];
	}
	for( int i = 1; i <= n; ++i )
		pfmin[i] = min( pfmin[i-1], cmin[i] );
	for( int i = n; i >= 1; --i )
		sfmin[i] = min( sfmin[i+1], cmin[i] );
	for( int i = 1; i <= n; ++i ) {
		int t = min( pfmin[c[i]-1], sfmin[c[i]+1] );
		if( t + w[i] > y && w[i] + cmin[c[i]] > x )
			--cnt[c[i]];
	}
	for( int i = 1; i <= n; ++i ) {
		int t = min( pfmin[i-1], sfmin[i+1] );
		if( t + cmin[i] > y ) cnt[i] = 0;
	}
	prelude();
	int ans = 1, tot = 0;
	for( int i = 1; i <= n; ++i ) {
		ans = int(1LL * ans * inv( fac[cnt[i]] ) % MOD);
		tot += cnt[i];
	}
	ans = int(1LL * ans * fac[tot] % MOD);
	printf( "%d\n", ans );
	return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define mo 1000000007
#define MAX 1000004
#define fast_io ios::sync_with_stdio(false)
int pr[1004];
ll fac[1004];
int main()
{
	fast_io;
	int n;
	cin >> n;
	pr[1]=1;
	for(int i=2;i<=50;i++)
		if(!pr[i])
			for(int j=i*i;j<=1000;j+=i)
				pr[j]=1;

	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<=i;j++)
		{
			if(!pr[j])
			{
				int temp=i;
				while(temp%j==0)
				{
					fac[j]++;
					temp/=j;
				}
			}

		}

	}
	ll ans=1;
	for(int i=1;i<=1000;i++)
		ans=(1LL*ans*(fac[i]+1))%mo;
	cout << ans;
	return 0;
}

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

int main(){
  int A, B; cin >> A >> B;
  if(A!=1 && B!=1){
    cout << 1 << endl;
    return 0;
  }
  if(A!=2 && B!=2){
    cout << 2 << endl;
    return 0;
  }
  if(A!=3 && B!=3){
    cout << 3 << endl;
    return 0;
  }
}

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

int gcd(int x, int y){
    int r;
    if(x < y){
        std::swap(x, y);
    }
    while(y > 0){
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(void){
    int num;
    std::cin >> num;
    int tmp;
    long long int sum;
    sum = 0;
    for(int i = 1; i <= num; i++){
        for(int j = 1; j <= num; j++){
            for(int k = 1; k <= num; k++){
                tmp = gcd(i, j);
                tmp = gcd(tmp, k);
                sum += tmp;
            }
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> s[M];
    for (int i = 0; i < M; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int a; cin >> a;
            s[i].push_back(a-1);
        }
    }
    int p[N];
    for (int i = 0; i < M; i++) cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        int flag = 0;
        for (int i = 0; i < M; i++) {
            int sum = 0;
            for (int j: s[i]) {
                if ((bit >> j) & 1) sum++;
            }
            if (sum % 2 == p[i]) flag++;
        }
        if (flag == M) ans++;
    } 
    cout << ans << endl;
}

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

inline void read(int &X)
{
    X=0;int w=0;char ch=0;
    while(!isdigit(ch))w|=ch=='-',ch=getchar();
    while( isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=w?-X:X;
}

char a[N];
int ok1,ok2;

signed main()
{
    scanf("%s",a+1);
    int n=strlen(a+1);
    for(int i=1;i<=n;i++)
      if(a[i]=='C')
      {
        for(int j=i+1;j<=n;j++)
          if(a[j]=='F')
            {puts("Yes");return 0;}
      }
    puts("No");

    return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val B = List.fill(sc.nextInt() - 1)(sc.nextInt())
  val (_, sum) =
    (B :+ B.last).foldLeft(B.head -> 0) { case ((b, sum), i) => (i, sum + b.min(i)) }
  println(sum)
}


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

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    cout << (B/A < C ? B/A : C) << endl;
}


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

using namespace std;

int n;

void solve(){
    int i,j;
    string str;
    cin >> n;
    vector<int> a(n+1), b(n);
    for(i = 0;i < n+1;i++){
        cin >> a[i];
    }
    long long ans = 0;
    for(i = 0;i < n;i++){
        cin >> b[i];
        if(a[i] >= b[i]){
            ans += b[i];
        }
        else{
            ans += a[i];
            b[i] -= a[i];
            if(a[i+1] >= b[i]){
                ans += b[i];
                a[i+1] -= b[i];
            }
            else{
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 1024
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n;
    scanf("%d", &n);
    map<int, int> z;
    int i;
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);
        z[tmp]++;
    }

    int found = 0;
    ll ans = 0;
    ll curr = 0;
    auto it = z.rbegin();
    for (; it != z.rend(); ++it) {
        ll aa = it->first;
        if (it->second < 2) continue;
        if (it->second < 4) {
            if (curr == 0) {
                curr = aa;
            }
            else {
                ans = curr * aa;
                break;
            }
        }
        else {
            if (curr == 0) {
                ans = aa * aa;
                break;
            }
            else {
                ans = curr * aa;
                break;
            }
        }

    }
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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

#define int  long long
#define pb emplace_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int a,b;
	cin >> a >> b;
	int cost = 0;
	if(a>= 13)  cost = b;
	if(a >= 6 && a <=12)    cost = b/2;
	
	cout << cost;

}







Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

ll read_long() {
    ll ans = 0;
    char c;
    bool started = false;
    bool is_negative = false;
    while (true) {
        c = getchar();
        if ((c < '0' || c > '9') && c != '-' && !started) continue;
        if ((c < '0' || c > '9') && c != '-' && started) break;
        if (started) {
            ans = ans * 10;
        }
        started = true;
        if (c == '-') is_negative = true;
        else ans += c - '0';
    }
    if (is_negative) ans *= -1;
    return ans;
}

int n, x;
int a[111];

int main(){

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

    sort(a, a + n);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        x -= a[i];
        if (x >= 0) ans = i + 1;
        else break;
    }

    if (ans == n && x > 0) ans = n - 1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n;
vector<int> G[MAXN];
int sg[MAXN];
void dfs(int v,int p)
{
    for(auto to:G[v])
    {
        if(to==p) continue;
        dfs(to,v);
        sg[v]^=(sg[to]+1);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);G[v].push_back(u);
    }
    dfs(1,0);
    if(sg[1]) puts("Alice"); else puts("Bob");
    return 0;
}



Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S, T;
	cin >> S >> T;

	Int ans = 0;
	for (Int i = 0; i < 3; i++) {
		if (S[i] == T[i])ans++;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define set setprecision　//小数点以下何位まで知りたいか
#define mod 1000000007
#define pi 3.14159265
#include<numeric>
using namespace std;
int gcd(int a, int b)//最大公約数
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)//最小公倍数
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);
}
int main() {
	ll x;
	cin >> x;
	ll s = 100;
  ll p = 0;
 while(s<x){
   s += s/100;
   p++;
 }
  cout << p << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vec> vec2;
typedef map<ll,ll> MPll;
typedef set<ll> setl;

template <typename T>
struct UnionFindTree{

    vector<T> par;

    UnionFindTree(T n) : par(n+1){
        for (int i = 1; i <= n; ++i) {
            par[i] = i;
        }
    }

    T root(T x){
        if(par[x] == x) return x;
        else  return par[x] = root(par[x]);
    }

    void unite(T x,T y){
        if(!same(x,y)) par[root(x)] = root(par[y]);
    }

    T same(T x,T y){
        return root(x) == root(y);
    }

};

signed main(){
    ll N,M;
    cin >>N>>M;
    ll p[N+1];

    UnionFindTree<ll> t(N);

    for (int i = 1; i <= N; ++i) {
        cin >> p[i];
    }

    for (int j = 0; j < M; ++j) {
        ll x,y;
        cin >>x>>y;
        t.unite(x,y);
    }

    ll ans = 0;

    for (int k = 1; k <= N; ++k) {
        if(t.same(p[k],k)) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
using System;

namespace DebtHell
{
    class Program
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());
            double SumMoney = 100000;
            for (int i = 0; i < input; i++)
            {
                SumMoney *= 1.05;
                SumMoney = Math.Ceiling(SumMoney / 1000) * 1000;
            }
            
            Console.WriteLine(SumMoney);
            Console.Read();
        }
    }
}



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

int main() {
    int n;
    char c[20];
    int m;
    list<int> lst;

    scanf("%d", &n);

    rep(i, n) {
        scanf("%s", c);

        if(c[0] == 'd' && strlen(c) == 6) {
            scanf("%d", &m);
            for(list<int>::iterator itr = lst.begin(); itr != lst.end(); itr++) {
                if(*itr == m) {
                    lst.erase(itr);
                    break;
                }
            }
        }
        else if(c[0] == 'i') {
            scanf("%d", &m);
            lst.push_front(m);
        }
        else if(c[0] == 'd' && strlen(c) == 11) {
            lst.pop_front();
        }
        else if(c[0] == 'd' && strlen(c) == 10) {
            lst.pop_back();
        }

    }

    int cnt = 0;

    for(list<int>::iterator itr = lst.begin(); itr != lst.end(); itr++) {
        if(cnt++) printf(" ");
        printf("%d", *itr);
        cnt++;
    }

    printf("\n");

    return 0;
}


Measured memory_bytes: 34392
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	factors := Factorization(M)
	ans := 1
	for i := 0; i < len(factors); i++ {
		p := factors[i][1]
		ans *= ModCombination(N-1+p, p)
		ans %= Mod
	}
	fmt.Println(ans)
}

func Factorization(n int) [][]int {
	res := [][]int{}
	for i := 2; i*i <= n; i++ {
		if n%i != 0 {
			continue
		}
		cnt := 0
		for n%i == 0 {
			n /= i
			cnt++
		}
		res = append(res, []int{i, cnt})
	}
	if n != 1 {
		res = append(res, []int{n, 1})
	}
	return res
}

const Mod = int(1e9) + 7

func ModFactorial(n int) int      { return fac[n] }
func ModPermutation(n, r int) int { return fac[n] * finv[n-r] % Mod }
func ModCombination(n, k int) int { return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod }

var fac, finv, inv []int

func init() {
	const MAX = 5 * 1e5
	fac, finv, inv = make([]int, MAX+1), make([]int, MAX+1), make([]int, MAX+1)
	fac[0], fac[1], finv[0], finv[1], inv[1] = 1, 1, 1, 1, 1
	for i := 2; i <= MAX; i++ {
		fac[i] = fac[i-1] * i % Mod
		inv[i] = Mod - inv[Mod%i]*(Mod/i)%Mod
		finv[i] = finv[i-1] * inv[i] % Mod
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 14036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
using namespace std;
using ll = long long int;
int main()
{
    int n;
    cin >> n;
    vector<int> slime(n);
    for (size_t i = 0; i < n; i++)
    {
        int ai;
        cin >> ai;
        slime[i] = ai;
    }

    int ans = 0;
    for (size_t i = 1; i < n; i++)
    {
        if (slime[i-1] == slime[i]) {
            ans++;
            slime[i] = 0;
        }
    }
    cout << ans << endl;
        
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long ;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a.at(i);
    bool f=true;
    for(int i=0;i<n;i++){
        if(a.at(i)%2==0){
            if(a.at(i)%3!=0&&a.at(i)%5!=0)
            f=false;
        }
    }
    if(f)cout << "APPROVED"<<endl;
    else cout << "DENIED" <<endl;

    return 0;
}

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

typedef long long ll;

//#define DMY_IN

int main() {
  int N;
#ifdef DMY_IN
  N = 18;
#else
  cin >> N;
#endif
  int smax = 1 << N;
  multiset<ll> S;
  vector<ll> SO;
  vector<ll> SO_add;

//  std::chrono::system_clock::time_point  start, end; // 型は auto で可
//  start = std::chrono::system_clock::now(); // 計測開始時間

  REP(i,smax) {
    ll sin;
#ifdef DMY_IN
    if ( i==0 ) {
      S.emplace(1000000000);
    } else if ( i < ((1<<17)) ) {
      S.emplace(1000000000 - 1);
    } else {
      S.emplace(i);
    }
#else
    cin >> sin;
    S.emplace(sin);
#endif
  }
  // 末尾が最大なので、まずはそれを生成済み配列に移す
  SO.emplace_back( *(S.rbegin()) );
  // erase() の引数に指定するには、リバースイテレータは使えず、普通のイテレータのみ
  // らしいので、end() からデクリメントして末尾を指定している
  multiset<ll>::const_iterator sit = S.end();
  sit--;	// 末尾 = 最大値の箇所
  S.erase(sit);

  sort( SO.begin(), SO.end(), greater<ll>() );

  for (int i=0; i<N; i++ ) {
//    for ( auto x: SO) cout << x << " ";
//    cout << endl;
//    cout << i << endl;
    
    for ( auto oya : SO ) {
      if ( S.empty() ) {
        cout << "No" << endl;
        return 0;
      }
      auto sit = S.lower_bound(oya);	// S[*] >= oya を満たす最小の要素を指す
      if ( sit == S.begin() ) {
        cout << "No" << endl; return 0;
      }
      sit--;
//      cout << "  o " << oya << " " <<  *sit << endl;
      SO_add.emplace_back( *sit );
      sit = S.erase(sit);
    }
    for( auto x: SO_add ) {
      SO.emplace_back( x );
    }
    sort( SO.begin(), SO.end(), greater<ll>() );
    SO_add.clear();
  }
  cout << "Yes" << endl;

//  end = std::chrono::system_clock::now();  // 計測終了時間
//  double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count(); //処理に要した時間をミリ秒に変換
//  std::cout << elapsed << " ms" << std::endl;
  
}




Measured memory_bytes: 14832
N,M=map(int,input().split())
if M==0:
    if N==1:
        print(0)
    else:
        print(10**(N-1))
else:
    S=[]
    C=[]
    for i in range(M):
        s,c=map(int,input().split())
        S.append(s)
        C.append(c)
    if N==1:
        o=0
    else:
        o=10**(N-1)
    for i in range(o,10**N):
        flag=True
        I=str(i)
        for j in range(M):
            if N<S[j]:
                flag=False
            else:
                if I[S[j]-1]!=str(C[j]):
                    flag=False
        if flag==True:
            print(i)
            exit()
    print(-1)


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

long long gcd(long long x, long long y) {
    if (x % y == 0) {
        return y;
    } else {
        return gcd(y, x % y);
    }
}

long long lcm(long long x, long long y) { 
    //return x * y / gcd(x, y);
    return x / gcd(x, y) * y;
}

int main() {
    //
    long long num;
    long long tmp1;
    long long kekka=1;

    cin >> num;

    vector<long long> vec(num);

    for (int i = 0; i < num; i++) {
        cin >> tmp1;
        kekka = lcm(kekka, tmp1);
    }

    cout << kekka;
    //
}


Measured memory_bytes: 3612
main :: IO ()
main = do
  [h, w] <- map toInt . words <$> getLine
  input <- mapM (const getLine) [1..h] :: IO [String]
  let sharpline = replicate (w + 2) '#'
  putStrLn sharpline
  mapM_ (putStrLn . (\s -> "#" ++ s ++ "#")) input
  putStrLn sharpline

toInt :: String -> Int
toInt = read

Measured memory_bytes: 1404
#include <stdio.h>

char map[8][9];

void dfs(int tx, int ty)
{
	int i, j;
	
	if (0 > ty || ty >= 8 || 0 > tx || tx >= 8 || map[ty][tx] == '0') return;
	
	map[ty][tx] = '0';
	
	for (i = -3; i <= 3; i++){
		for (j = -3; j <= 3; j++){
			if ((i == 0 || j == 0) && i + j){
				dfs(tx + i, ty + j);
			}
		}
	}
	return;
}

int main(void)
{
	int n, t;
	int i;
	int sx, sy;
	
	scanf("%d", &n);
	
	t = 0;
	while (n--){
		for (i = 0; i < 8; i++){
			scanf("%s", map[i]);
		}
		
		scanf("%d %d", &sx, &sy);
		
		dfs(--sx, --sy);
		
		printf("Data %d:\n", ++t);
		for (i = 0; i < 8; i++){
			printf("%s\n", map[i]);
		}
	}
	
	return (0);
}

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

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

	bool correct = true;

	char checkw = W[0].back();
	for (int i = 1;i < N;i++) {
		if (checkw == W[i].front()) {
			checkw = W[i].back();
		}
		else {
			correct = false;
			break;
		}
	}
	
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < i;j++) {
			if (W[j] == W[i]) {
				correct = false;
				goto Exit;
			}
		}

	}

	Exit:
	if (correct) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}

Measured memory_bytes: 256
def main():
    n = int(input())
    ps = [int(x) for x in input().split()]
    ps.sort()
    a = 1
    for p in ps:
        a *= p
        if a == 0:
            print(0)
            return
        if a > 10 ** 18:
            print(-1)
            return
        
    print(a)

    
main()


Measured memory_bytes: 21648
#include <stdio.h>
char a[110][110];

int main() {
    for (int i = 0; i < 110; i++){
        for (int j = 0; j < 110; j++){
            a[i][j] = '#';
        }
    }
    int h, w;
    scanf("%d %d", &h, &w);
    for (int i = 1; i < h + 1; i++){
        for (int j = 1; j < w + 1; j++){
            scanf(" %c", &a[i][j]);
        }
    }

    for (int i = 0; i < h+2; i++){
        for (int j = 0; j < w+2; j++){
            printf("%c", a[i][j]);
        }
        printf("\n");
    }


    return 0;

};

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

int main()
{
    int x, y;
    cin >> x >> y;

    int a = 0, B = 0;

    B = y - 2 * x;
    if (B < 0 || B % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    a = x - B / 2;
    if (a >= 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
ans = 0
tmp = 0

for i in range(40, -1, -1):
    onenum = 0
    for j in A:
        if 2**i & j == 2**i:
            onenum += 1
    
    zeronum = N - onenum
    
    if tmp + 2**i > K:
        ans += onenum * 2**i
    else:
        if onenum > zeronum:
            ans += onenum * 2**i
        else:
            ans += zeronum * 2**i
            tmp += 2**i

print(ans)

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

int main(){
   int H, W;
   std::cin >> H >> W;

   std::vector<std::string> S(H);
   for(int i=0; i<H; ++i)
      std::cin >> S[i];

   int ans = 0;
   std::vector<int> nv(W,-1);
   for(int i=0; i<H; ++i){
      int nh = -1;
      for(int j=0; j<W; ++j){
	 if(S[i][j]=='#'){
	    nv[j] = -1;
	    nh = -1;
	    continue;
	 }
	 int n = 1;
	 if(nh<0){
	    nh = 0;
	    for(int k=j-1; k>=0; --k){
	       if(S[i][k]=='#') break;
	       ++nh;
	    }
	    for(int k=j+1; k<W; ++k){
	       if(S[i][k]=='#') break;
	       ++nh;
	    }
	 }
	 n += nh;
	 if(nv[j]<0){
	    nv[j] = 0;
	    for(int k=i-1; k>=0; --k){
	       if(S[k][j]=='#') break;
	       ++nv[j];
	    }
	    for(int k=i+1; k<H; ++k){
	       if(S[k][j]=='#') break;
	       ++nv[j];
	    }
	 }
	 n += nv[j];
	 ans = std::max(ans,n);
      }
   }
   std::cout << ans << std::endl;

   return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 X, Y, Z;
  cin >> X >> Y >> Z;

  cout << Z << " " << X <<" " << Y << "\n";
  
}

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

Measured memory_bytes: 256
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

func bitCount(n uint) int {

        x := uint64(n)

        const m = 1<<64 - 1
        const m0 = 0x5555555555555555
        const m1 = 0x3333333333333333
        const m2 = 0x0f0f0f0f0f0f0f0f

        x = x>>1&(m0&m) + x&(m0&m)
        x = x>>2&(m1&m) + x&(m1&m)
        x = (x>>4 + x) & (m2 & m)
        x += x >> 8
        x += x >> 16
        x += x >> 32

        return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
        return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////
func chmax(dp [][]int64, idx, dir int, dn int64) {
        if dp[idx][dir] < dn {
                dp[idx][dir] = dn
        }
}

func main() {
        line := nextLine()
        spl := intSprit(line)
        N := spl[0]
        W := spl[1]

        dp := make([][]int64, N+1000)
        for i := 0; i < N+1000; i++ {
                dp[i] = make([]int64, W+10)
        }

        for i := 0; i < N; i++ {
                s := intSprit(nextLine())
                w, v := s[0], s[1]
                for j := 0; j <= W; j++ {
                        if j-w >= 0 {
                                chmax(dp, i+1, j, dp[i][j-w]+int64(v))
                        }
                        chmax(dp, i+1, j, dp[i][j])
                }
        }
        fmt.Println(dp[N][W])
}


Measured memory_bytes: 108544
use proconio::input;

fn main() {
    input!(x: i64, k: i64, d: i64);
    let x = x.abs();
    let t = x / d;
    let t = if t % 2 == k % 2 { t } else { t + 1 };
    let t = t.min(k);
    let ans = (x - t * d).abs();
    println!("{}", ans);
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    string S;
    cin >> S;
    int x = 0;
    for (int i = 0; i < sz(S); i++) {
        x += S[i] - '0';        
    }
    bool bl = (x % 9 == 0);
    puts(bl ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3712
#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 RREP(i, n) for(int i = (n)-1; i >= 0; --i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

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

// typedef int_fast64_t ll;
#define int int_fast64_t

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

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

int dp[3010][3010];

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

  int N, T; cin >> N >> T;
  vector<INTP> AB(N);
  REP(i, N) cin >> AB[i].first >> AB[i].second;
  sort(ALL(AB));

  int ans = 0;
  for(int i = 1; i <= N; i++){
    REP(j, T){
      dp[i][j] = dp[i-1][j];
      chmax(ans, dp[i-1][j]+AB[i-1].second);
      if(j - AB[i-1].first >= 0)
        chmax(dp[i][j], dp[i-1][j-AB[i-1].first] + AB[i-1].second);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 70912
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    ll n, m, d;
    cin >> n >> m >> d;
    double p;
    if(d == 0){
        p = (double) (m-1) / (double) n;
    } else {
        p = ((double) 2 * (double) (m-1) / (double) n);
    }
    p *= (double) (n-d) / (double) n;
    cout << fixed;
    cout << setprecision(8) << p << endl;
    return 0;
}




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

int main() {
  int n;
  cin >> n;
  
  vector<long> A(n);
  vector<long> B(n);
  long sum=0;
  for(int i=0;i<n;i++){
    cin >> A[i];
    sum-=A[i];
  }
  for(int i=0;i<n;i++){
    cin >> B[i];
    sum+=B[i];
  }
  
  long An=0,Bn=0;
  for(int i=0;i<n;i++){
    if(A[i]>B[i]){
      Bn+=A[i]-B[i];
    }
    else{ 
      An+=(B[i]-A[i]+1)/2;
    }
  }
  if(An > sum || Bn > sum){
    cout << "No";
  }
  else{
    cout << "Yes";
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,p,m;
char s[1001];
while(cin>>s){
m=strlen(s);
j=0;
k=0; n=1000000;
for(i=0;i<=m-3;i++){ k=0;
    for(j=i;j<i+3;j++) {k*=10;
    k+=(s[j]-48);

    }
    if(abs(753-k)<n) n=abs(753-k);

}
cout<<n<<endl;
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;
void solve(){
    int a,b,c,d,e,f,w1,w2,s1,s2,ans1=0,ans2=0;
    double temp1=0.0,temp2;
    cin >>a>>b>>c>>d>>e>>f;
    vector<int>x,y;
    for(int i=0;100*a*i<=f;i++){
        w1 = 100*a*i;
        for(int j=0;100*b*j<=f;j++){
            w2 = 100*b*j;
            if(w1+w2<=f) x.push_back(w1+w2);
        }
    }
    for(int i=0;c*i<=f;i++){
        s1 = c*i;
        for(int j=0;d*j<=f;j++){
            s2 = d*j;
            if (s1+s2<=f) y.push_back(s1+s2);
        }
    }
    int n=x.size(),m=y.size();
    fol(i,n){
        w1 = x[i];
        fol(j,m){
            s1=y[j];
            temp2 = w1+s1==0 ? 0.0 :(double)s1/(double)(w1+s1);
            if (w1+s1<=f&&temp2>=temp1&&s1<=w1/100*e){
                temp1 = temp2;
                ans1 = w1 + s1,ans2 = s1;
            }
        }
    }
    cout << ans1 << " " <<ans2 <<endl;

}

int main(){
/*/Debug by file input
    ifstream fin("input");
    cin.rdbuf(fin.rdbuf());// */
    solve();
    return 0;
}


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

"""
・nCr(R+1, i)
　R+1箇所の赤の間(両端含む)のうち、どこに青のグループを置くか
・nCr(B-1, i-1)
　B-1箇所の青の間(両端なし)のうち、i-1箇所で切ればi個のグループになる。
"""

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def init_fact_inv(MAX: int) -> list:
    """ 階乗たくさん使う時用のテーブル準備

    Params
    ------
        MAX：階乗に使う数値の最大以上まで作る
    Returns
    -------
        List, List
    """
    MAX += 1
    # 階乗テーブル
    factorial = [1] * MAX
    factorial[0] = factorial[1] = 1
    for i in range(2, MAX):
        factorial[i] = factorial[i-1] * i % MOD
    # 階乗の逆元テーブル
    inverse = [1] * MAX
    # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
    inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
    for i in range(MAX-2, 0, -1):
        # 最後から戻っていくこのループならMAX回powするより処理が速い
        inverse[i] = inverse[i+1] * (i+1) % MOD
    return factorial, inverse

def nCr(n, r, factorial, inverse):
    """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """
    if n < r: return 0
    # 10C7 = 10C3
    r = min(r, n-r)
    # 分子の計算
    numerator = factorial[n]
    # 分母の計算
    denominator = inverse[r] * inverse[n-r] % MOD
    return numerator * denominator % MOD

N,K=MAP()
R=N-K
B=K

fact, inv = init_fact_inv(N)

for i in range(1, K+1):
    print(nCr(R+1, i, fact, inv) * nCr(B-1, i-1, fact, inv) % MOD)


Measured memory_bytes: 3444
a = gets.chomp.chars
b = gets.chomp.chars
c = gets.chomp.chars

n = a
winner = 0
while winner.zero?
  n = case n.shift
  when "a"; a
  when "b"; b
  when "c"; c
  end
  winner = n.object_id if n.empty?
end

puts winner == a.object_id ? "A" : winner == b.object_id ? "B" : "C"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
 
int n, m;
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	map<int, int> mp1, mp2;
	FOR(i, n) {
		int x;
		cin >> x;
		mp1[x]++;
	}
	cin >> m;
	FOR(i, m) {
		int x;
		cin >> x;
		mp2[x]++;
	}
	bool ok = true;
	for (auto itr = mp2.begin(); itr != mp2.end(); itr++) {
		if (itr->second > mp1[itr->first]) ok = false;
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}

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

int main(){ 
  string s; cin >> s;
  int n = s.size();
  
  if( s.front() == '0' || s.back() == '1'){ 
    cout << -1 << endl; return 0;
  }

  for(int i = 0; i < n-1; i++){
    
    if( s[i] != s[n-2-i]){ cout << -1 << endl; return 0;
                         }
  }

  int top = 0;
  
  vector<pair<int,int>> ans;
  
  for(int i = 0; i < n-1 ;i++){ 
    ans.push_back({top,i+1});
    if( s[i] == '1'){ top = i+1;} //先頭移動
    
  }
  
  for(auto ne : ans ){ 
    
    cout << ne.first+1 << " " << ne.second+1 << endl;
    
  }

  return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

vector<vector<int>> g(100010);
int dp[100010];

int rec(int x) {
  if (dp[x] != -1) return dp[x];
  dp[x] = 0;
  for (auto y : g[x]) {
    dp[x] = max(dp[x], rec(y)+1);
  }
  return dp[x];
}

int main() {
  int n, m; cin>>n>>m;
  rep(i, 100010) dp[i] = -1;
  rep(i, m) {
    int x, y; cin>>x>>y;
    g[x].push_back(y);
  }
  int ans = 0;
  rep(i, 100010) ans = max(ans, rec(i));
  print(ans);

  return 0;
}


Measured memory_bytes: 7424
#include<stdio.h>
#include<stdint.h>
#define X 1000000007
int main(){
    long long int N,K,A[2000];
    long long int i,j;
    long long int inv=0,temp;
    scanf("%lld %lld",&N,&K);
    for(i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    for(i = 0 ; i < N  ; i++){
        long long int a=0,b=0;
        for(j = i+1 ; j < N ; j++){
            if(A[i] > A[j]){
                a++;
            }
        }
        for(j = 0 ; j < i+1 ; j++){
            if(A[i] > A[j]){
                b++;
            }
        }
        inv = (inv + (a*(((K + 1)*K/2)%X))%X + (b*((K - 1)*K/2%X))%X)%X;

    
    }
    printf("%lld",inv);
    return 0;
}



Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T>
struct Compress {
  vector<T> xs;

  Compress() = default;

  Compress(const vector<T> &vs) {
    add(vs);
  }

  Compress(const initializer_list<vector<T>> &vs) {
    for(auto &p : vs) add(p);
  }

  void add(const vector<T> &vs) {
    copy(begin(vs), end(vs), back_inserter(xs));
  }

  void add(const T &x) {
    xs.emplace_back(x);
  }

  void build() {
    sort(begin(xs), end(xs));
    xs.erase(unique(begin(xs), end(xs)), end(xs));
  }

  vector<int> get(const vector<T> &vs) const {
    vector<int> ret;
    transform(begin(vs), end(vs), back_inserter(ret), [&](const T &x) {
      return lower_bound(begin(xs), end(xs), x) - begin(xs);
    });
    return ret;
  }

  int get(const T &x) const {
    return lower_bound(begin(xs), end(xs), x) - begin(xs);
  }

  const T &operator[](int k) const {
    return xs[k];
  }
};

template<typename T>
struct BinaryIndexedTree {
    vector<T> data;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for(; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    T sum(int l, int r) {
        T vl = sum(l);
        T vr = sum(r);
        return vr - vl;
    }

    void add(int k, T x) {
        for(++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    Compress<ll> CM(A);
    CM.build();
    auto CA = CM.get(A);

    BinaryIndexedTree<ll> BIT(N);
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ans += (i - BIT.sum(CA[i]+1LL));
        BIT.add(CA[i],1LL);
    }

    cout << ans << endl;
}


Measured memory_bytes: 9368
X,Y,Z,K=map(int,input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
AB=[]
for a in A:
	for b in B:
		AB.append(a+b)
ABC=[]
for ab in sorted(AB, reverse=True)[:K]:
	for c in C:
		ABC.append(ab+c)
for abc in sorted(ABC, reverse=True)[:K]:
	print(abc)


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

typedef pair<int,int> P;

const int MAX = 201;

class UnionFind{
private:
  int par[MAX];
  int rank[MAX];

public:
  UnionFind(int n){
    for(int i=0;i<n;i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  void init(int n){
    for(int i=0;i<n;i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  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(rank[x] < rank[y]) par[x] = y;
    else{
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y){ return find(x) == find(y);}
};

struct edge{
  int u,v,cost;
  edge(int u=0, int v=0, int c=0):u(u),v(v),cost(c){}
  bool operator < (const edge &e) const {
    return cost < e.cost;
  }
};

int n,m;
P h[MAX];
vector<edge> G;

void solve(){
  UnionFind uf(n), uf_cnt(n);
  int ans = 0;
  bool f[MAX];
  fill(f,f+MAX,false);
  sort(h,h+n);
  sort(G.begin(),G.end());

  f[h[0].second] = true;
  for(int i=1;i<n;i++){
    f[h[i].second] = true;
    if(i < n - 1 && h[i].first == h[i+1].first) continue;

    for(int j=0;j<m;j++){
      if(f[G[j].u] && f[G[j].v]) uf_cnt.unite(G[j].u,G[j].v);
    }

    bool f2 = false;
    for(int j=0;j<n;j++){
      if(f[j] && !uf_cnt.same(j, h[0].second)){
        f2 = true;
        break;
      }
    }
    if(f2){
      ans = 0;
      uf.init(n);
      continue;
    }

    for(int j=0;j<m;j++){
      if(f[G[j].u] && f[G[j].v] && !uf.same(G[j].u,G[j].v)){
        uf.unite(G[j].u, G[j].v);
        ans += G[j].cost;
      }
    }
  }

  cout << ans << endl;
}

int main(){
  while(cin >> n >> m && (n|m)){
    G.clear();
    for(int i=0;i<n;i++){
      int a;
      cin >> a;
      h[i] = P(-a,i);
    }
    for(int i=0;i<m;i++){
      int a,b,c;
      cin >> a >> b >> c;
      a--;
      b--;
      G.push_back(edge(a,b,c));
    }
    solve();
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    G.at(--a).push_back(--b), G.at(b).push_back(a);
  }
  vector<int> P(N);
  for (int i = 0; i < N; i++) P.at(i) = i;
  int ans = 0;
  do {
    if (P.at(0) != 0) continue;
    int now = 0;
    for (; now < N - 1;) {
      bool next = false;
      for (auto g : G.at(P.at(now))) if (g == P.at(now + 1)) next = true;
      if (next) {
        now++;
        if (now == N - 1) ans++;
      } else {
        break;
      }
    }
  } while (next_permutation(P.begin(), P.end()));
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int mod = (int)1e9 + 7;
const int inf = 2*mod;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 1e6 + 10;

int n, dp[N][2];
string s;

int solve(int idx, int extra){
   if(idx >= n){
      return extra;
   }
   int &ans = dp[idx][extra];
   if(ans != -1)
      return ans;
   ans = inf;
   int curr = extra + s[idx] - '0';
   smin(ans, min(curr + solve(idx+1, 0), 10 - curr + solve(idx+1, 1)));//we
   return ans;
}

void solve(){
   cin >> s;
   n = (int)(s.size());

   memset(dp, -1, sizeof dp);

   reverse(s.begin(), s.end());
   cout<<solve(0, 0);
}

int32_t main(){_
   
   int t = 1;
   //cin >> t;

   while(t--){
     solve();
     cout << endl;
   }
   
   return 0;
}

Measured memory_bytes: 56092