akhauriyash/Code-Regression huggingface dataset:
N = int(input())
strN = str(N)
#print(N)
sum=0

if(len(strN)%2==1):
    sum+=N-10**(len(strN)-1)+1
    #print(sum)

for i in range(len(strN)-1,0,-1):
    #print(i)
    if(i%2==1):
        sum+=10**(i-1)*9
        #print(sum)
if(len(strN)==1):
    sum=N

print(sum)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define pb push_back
#define mod 1000000007

ll power(ll a,ll b){
    ll res=1ll;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res%mod;
}
ll ncr(ll n,ll k){
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro)%mod;
}

void swap(ll *a,ll *b) {
    ll temp=*a;
    *a=*b;
    *b=temp;
}
vector<ll> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
vector<ll> parent;
ll find(ll p) {
    if(parent[p]==p) return parent[p];
    return parent[p]=find(parent[p]); 
}
void unun(ll a,ll b) {
    ll r1=find(a);
    ll r2=find(b);
    if(r1!=r2) parent[r2]=r1;
}
void solve() {
    string str,t;
    cin>>str>>t;
    for(char i='a';i<='z';i++) {
        string s=str;
        s+=i;
        if(s==t) {
            cout<<"Yes";
            return ;
        }
    }
    cout<<"No";
}   


int main(void){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        cout<<endl;
    }
    return 0; 

}


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = (int)1e5 + 9;
vector<int> T[N];
bool is[N];

void dfs(int u){
  is[u]=true;
  for(auto x : T[u]){
    if(!is[x]){
      is[x]=true;
      dfs(x);
    }
  }
}

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  int x, y, z;
  for(int i = 0 ;i < m ; i ++ ){
    cin >> x >> y >> z;
    T[x].push_back(y);
    T[y].push_back(x);
  }
  int ans = 0;
  for(int i = 1; i <= n; i ++ ){
    if(!is[i]){
      dfs(i);
      ans ++ ;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;
using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
 
bool vector_find(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) {
        return true;
    }
    else {
        return false;
    }
}
 
int main(){
  	int A,B,T;
  	cin >> A >> B >> T;
  	
  	cout << (T/A)*B;
  
    return 0;
}

Measured memory_bytes: 256
let rec for_iter f a b = if a > b then [] else let x = f a in x :: for_iter f (a+1) b
let () =
  Scanf.scanf "%d %d" (for_iter @@ fun i ->
    let s = string_of_int i in
    if s.[0] = s.[4] && s.[1] = s.[3] then 1 else 0)
  |> List.fold_left (+) 0 |> Printf.printf "%d\n"

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros
template <long long Mod>
struct modint {
    ll n;
    modint(ll x = 0) : n((x + Mod) % Mod) {
    }

    modint operator+(const modint &r) const { return modint(*this) += r; }
    modint operator-(const modint &r) const { return modint(*this) -= r; }
    modint operator*(const modint &r) const { return modint(*this) *= r; }
    modint operator/(const modint &r) const { return modint(*this) /= r; }
    modint operator+=(const modint &r) {
        n += r.n;
        n %= Mod;
        return *this;
    }
    modint operator-=(const modint &r) {
        n -= r.n;
        n += Mod;
        n %= Mod;
        return *this;
    }
    modint operator*=(const modint &r) {
        n *= r.n;
        n %= Mod;
        return *this;
    }
    modint operator/=(const modint &r) {
        *this *= modint(r).inv();
        return *this;
    }

    modint operator=(const modint &r) { return n = r.n; }
    modint operator==(const modint &r) const { return n == r.n; }
    modint operator!=(const modint &r) const { return n != r.n; }

    modint inv() const { return pow(Mod - 2); }

    modint pow(const ll x) const {
        modint a = modint(*this);
        ll t = x;
        while (t > 1) {
            a *= a;
            t /= 2;
        }
        if (x % 2 == 1)
            a *= n;

        return a;
    }

    friend ostream &operator<<(ostream &os, const modint &x) { return os << x.n; }
    friend istream &operator>>(istream &is, modint &x) { return is >> x.n; }
};
int main()
{
    int N;
    ll K;

    ll mod = 10e9 + 7;

    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<modint<1000000007>> b(N); // iより左にある転倒数の数
    vector<modint<1000000007>> c(N); // A全体の転倒数の数

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(A[i] > A[j]) {
                if(i>j) b[i]+=1;
                c[i]+=1;
            }
        }
    }

    cerr << join(b) << endl;
    cerr << join(c) << endl;

    modint<1000000007> ans;

    rep(i,N){
        ans += c[i]*(((1+K)*K)/2);
    }

    rep(i, N) {
        ans -= b[i]*K;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        a: [[i64;3];3],
        n: usize,
        b: [i64;n],
    }
    let mut hole = vec![vec![0;3];3];
    for i in 0..n {
        for t in 0..3 {
            for s in 0..3 {
                if b[i] == a[t][s] {
                    hole[t][s] = 1;
                }
            }
        }
    }
    // println!("{:?}", hole);
    let ans = if hole[0][0]*hole[0][1]*hole[0][2] == 1 || hole[1][0]*hole[1][1]*hole[1][2] == 1 || hole[2][0]*hole[2][1]*hole[2][2] == 1 || hole[0][0]*hole[1][0]*hole[2][0] == 1 || hole[0][1]*hole[1][1]*hole[2][1] == 1 || hole[0][2]*hole[1][2]*hole[2][2] == 1 || hole[0][0]*hole[1][1]*hole[2][2] == 1 || hole[2][0]*hole[1][1]*hole[0][2] == 1 {
        "Yes"
    }else{
        "No"
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
<?php
fscanf(STDIN, "%d", $n);
$Tarray = explode(' ', trim(fgets(STDIN)));
fscanf(STDIN, "%d", $m);
for($i=0; $i<$m; $i++){
    fscanf(STDIN, "%d %d", $p, $x);
    $t = $Tarray[$p-1];
    $Tarray[$p-1] = $x;
    print array_sum($Tarray);
    print "\n";
    $Tarray[$p-1] = $t;
}


Measured memory_bytes: 4604
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  LL N, T; std::cin >> N >> T;
  LL total = 0;
  LL last = -1;
  for (int n = 0; n < N; ++n) {
    LL t; std::cin >> t;
    if (last < t) {
      total += T;
    } else {
      total += T - (last - t);
    }

    last = t + T;
  }
  std::cout << total << std::endl;
}


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

int main()
{
	int data,n,
		list[10],		/*2Ìnæ[g]ÌªºðgÁ½©Û©*/
		i,j;
	
	while(scanf("%d",&data)!=EOF){
		for(i=0;i<=9;i++) list[i]=0;				/*true(1) or falth(0)Ìlistðú»*/
		while(n=0,data>0){
			for(n=0;pow(2.,n)<=data;n++);n--;		/*n--Í²®*/
			data-=(int)pow(2.,n);					/*å«¢Ù¤©ç¸çµÄ¢­*/
			list[n]=1;
		}
		for(i=0;i<10;i++){
			if(list[i]==1){
				printf("%d",(int)pow(2.,i));

				for(j=i+1;j<10;j++){
					if(list[j]==1){		/*ÔÉXy[Xðüêé½ßBvé©È H*/
						printf(" ");
						break;
					}
				}
			}
		}
		printf("\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    string s;
    cin >> s;
    
    string t;
    cin >> t;
    
    int ans = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == t[i]) {
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

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

    auto r = irange(0L, 200002L);
    auto k = *partition_point(r.begin(), r.end(), [&](int64_t k) {
        int64_t num = 0;
        for (auto aa : a) {
            num += a.end() - lower_bound(a.begin(), a.end(), k - aa);
        }

        return num > m;
    });

    vector<int64_t> s(n + 1);
    for (auto i : irange(0L, n)) {
        s[i + 1] = s[i] + a[i];
    }

    int64_t ans = 0, num = 0;
    for (auto aa : a) {
        auto idx = lower_bound(a.begin(), a.end(), k - aa) - a.begin();
        // cerr << aa << "," << (idx < n ? a[idx] : 1000) << "," << idx << endl;
        ans += s[n] - s[idx] + (n - idx) * aa;
        num += n - idx;
    }

    ans += (m - num) * (k - 1);

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std; int main(){ int H, W; cin >> H >> W; map<int, int64_t> mp; multiset<int64_t> values; for(int i=1; i<=W; i++){ mp[i] = 0; values.insert(0); }for(int i=1; i<=H; i++){ int l, r; cin >> l >> r; if(r != W){ auto it = mp.upper_bound(r+1); if(it != mp.begin()){ it--; if(it->first != r+1){ int64_t v = it->second + (r+1-it->first); mp[r+1] = v; values.insert(v); } } }auto it = mp.lower_bound(l); while(it != mp.end() && it->first <= r){ values.erase(values.find(it->second)); it = mp.erase(it); }if(values.size()){ cout << i + *values.begin() << endl; }else{cout << -1 << endl; } }return 0; }

Measured memory_bytes: 25444
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  map<string,int> m;
  long long ans = 0;
  for(int i = 0;i<n;i++){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    ans += m[s];
    m[s]++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

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

    if (S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    bool isC = false;
    for (int i = 1; i < S.length(); i++) {
        if (S[i] == 'C' && i > 1 && i < S.length() - 1 && !isC) isC = true;
        else if (S[i] >= 'A' && S[i] <= 'Z') {
            cout << "WA" << endl;
            return 0;
        }
    }

    if (isC) cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        if(N<1200){
            System.out.println("ABC");
        }else if(N<2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 35688
package main

import (
	"fmt"
	"sort"
)

type num []int
type nums [][]int

func (n nums) Len() int{
	return len(n)
}

func (n nums) Swap(i, j int) {
	n[i], n[j] = n[j], n[i]
}

func (n nums) Less(i, j int) bool {
	ni := n[i][1]
	nj := n[j][1]
	return ni > nj
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make(nums, n)
	for i := range a {
		a[i] = make(num, 2)
		a[i][1] = i
		fmt.Scan(&a[i][0])
	}
	// fmt.Println(a)
	sort.Sort(a)
	// fmt.Println(a)

	for i, v := range a {
		if i == 0 {
			fmt.Printf("%d", v[0])
		} else {
			fmt.Printf(" %d", v[0])
		}
		if i == n - 1 {
			fmt.Print("\n")
		}
	}
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

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

    vector<int> A = {1, 3, 5, 7, 8, 10, 12};

    bool flag_x = false;
    bool flag_y = false;
    if(x == 2 || y == 2) {
        cout << "No" << endl;
    } else {
        REP(i, A.size()) {
            if(A[i] == x) flag_x = true;
            if(A[i] == y) flag_y = true;
        }

        if((flag_x == true && flag_y == true) || (flag_x == false && flag_y == false) ) cout << "Yes" << endl; 
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
const int mxN=1e4+10,mxA=1e6+10,M=1e9+7;
int mod(int a,int M){int ret=a%M;if(ret<0)ret+=M;return ret;}
int exp(int a,int b,int M){
    if(b==0LL)return 1LL;
    if(b==1LL)return mod(a,M);

    int t=exp(a,b/2,M);
    if(b&1)return mod(a*mod(t*t,M),M);
    return mod(t*t,M);
}

int n,x;
int v[mxN],p[mxA];
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i];
        x=v[i];
        for(int i=2;i*i<=x;i++){
            int cnt=0;
            if(x%i==0){
                while(x%i==0){
                    cnt++;
                    x/=i;
                }
                p[i]=max(p[i],cnt);
            }
        }
        if(x>1)p[x]=max(p[x],1LL);
    }
    int k=1LL;
    for(int i=2;i<=mxA;i++){
        k=mod(k*exp(i,p[i],M),M);
    }
    int ans=0LL;
    for(int i=0;i<n;i++){
        ans=mod(ans+k*exp(v[i],M-2,M),M);
    }
    cout<<ans;

}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d=0,e=0;
	char f;
	while(cin>>a>>f>>b>>f>>c){
		if(a*a+b*b==c*c){
			d++;
		}
		if(a==b){
			e++;
		}
	}
	cout<<d<<endl<<e<<endl;
	return 0;
}



Measured memory_bytes: 3004
#include<stdio.h>
int main(){
	int i,n,N[10000],b,count=0,flag=1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&N[i]);
	}
	while(flag){
		flag=0;
		for(i=n-1;i>=0;i--){
			if(N[i]<N[i-1]){
				b=N[i];
				N[i]=N[i-1];
				N[i-1]=b;
				count++;
				flag=1;
			}
		}
	}
	for(i=0;i<n-1;i++){
		printf("%d ",N[i]);
	}
	printf("%d\n",N[n-1]);
	printf("%d\n",count);
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  double a; cin>>a;
  double ans=2*a*3.1415926;
  cout<<std::setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 3804
#include <stdio.h>

int main(void)
{
	int i,n,b,f,r,v;
	int house[4][3][10] = {0};
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d %d %d %d",&b,&f,&r,&v);
		house[b-1][f-1][r-1] += v;
	}
	for (b=0; b<4; b++) {
		for (f=0; f<3; f++) {
			for (r=0; r<10; r++) {
				printf(" %d",house[b][f][r]);
			}
		printf("\n");
		}	
	if(b != 3) printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 612
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


int N, M;
int[] X, Y;

int[][] G;
int[] dp;

void solve(int u) {
  if (dp[u] == -1) {
    foreach (v; G[u]) {
      solve(v);
    }
    dp[u] = 0;
    foreach (v; G[u]) {
      chmax(dp[u], 1 + dp[v]);
    }
  }
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      X = new int[M];
      Y = new int[M];
      foreach (i; 0 .. M) {
        X[i] = readInt() - 1;
        Y[i] = readInt() - 1;
      }
      G = new int[][N];
      foreach (i; 0 .. M) {
        G[X[i]] ~= Y[i];
      }
      dp = new int[N];
      dp[] = -1;
      foreach (u; 0 .. N) {
        solve(u);
      }
      int ans;
      foreach (u; 0 .. N) {
        chmax(ans, dp[u]);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 10236
#include <stdio.h>
int tgt[100];

int main(){
  int n,i,num=0;
  scanf("%d",&n);
  while(n--) tgt[n]=1;
  scanf("%d",&n);
  while(n--) {scanf("%d",&i); tgt[i-1]=0;}
  scanf("%d",&n);
  while(n--) {scanf("%d",&i); tgt[i-1]=1;}
  scanf("%d",&n);
  while(n--) {scanf("%d",&i); if(tgt[i-1]) num++;}
  printf("%d\n",num);
  return 0;
}



Measured memory_bytes: 2064
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;
ll dx[] = { 1,1,0,-1,-1,-1,0,1 };
ll dy[] = { 0,1,1,1,0,-1,-1,-1 };
ll prime(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;
}
ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}

ll MOD = 1000000007;
int main() {
	string S;
  	cin>>S;
  	cout<<S.substr(0,4)<<" "<<S.substr(4,8)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using vi=vector<int>;
int main(){
  int n,m;
  bool dpl=false;
  cin>>n>>m;
  vi fig(n,-1);
  for(int i=0;i<m;i++){
    int s,c;
    cin>>s>>c;
    if(fig[s-1]==-1||fig[s-1]==c){
      fig[s-1]=c;
    }else{
      dpl=true;
    }
  }for(int i=0;i<n;i++){
    if(fig[i]==-1){
      if(i==0&&n!=1){
        fig[i]=1;
      }else{
      fig[i]=0;
      }
    }
  }if(n!=1&&fig[0]==0){
    cout<<-1<<endl;
  }else if(dpl){
    cout<<-1<<endl;
  }else{
    for(int i=0;i<n;i++){
      cout<<fig[i];
    }
    cout<<endl;
  }
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> d(k);
  for(int i=0;i<k;i++){
    cin >> d[i];
  }
  bool b=false;
  for(int i=n;!b;i++){
    int t=i;
    b=true;
    for(int j=0;t!=0;j++){
      for(int l=0;l<k;l++){
        if(t%10==d[l]){
          b=false;
          break;
        }
      }
      t/=10;
    }
    if(b){
      cout << i << endl;
    }
  }
}

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

int main()
{
	char c[3] = "CF";
	int k = 0;
	char s[1001];
	cin>>s;
	int l = strlen(s);
	for(int i=0;i<l;i++)
	{
		if(k == 2)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		if(s[i] == c[k]) ++k;
	}
	if(k == 2)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main() {
    int N;          //餅の個数
    cin >> N;       //餅の個数を入力
    int d[N];       //餅の直径
    int X = 0;      //求める最大の段数

    //餅の直径を入力
    for(int i = 0; i < N; i++) {
        cin >> d[i];
    }

    //配列dを昇順にソート
    sort(d, d+N);

    int t = 0;
    for(int i = 0; i < N; i++) {
        if(t < d[i]) {
            t = d[i];
            ++X;
        }
    }
    
    cout << X << endl;

    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a>b)
        cout << "a > b" << endl;
    else if(a<b)
        cout << "a < b" << endl;
    else
        cout << "a == b" << endl;
    return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int n = scanner.nextInt();
        int result = 0;
        int x = 0;
        while (n > x) {
            int s = scanner.nextInt();
            int f = scanner.nextInt();
            if( !(a >= f || b <= s) ){
                result = 1;
            }
            x++;
        }
        System.out.println(result);
    }
}



Measured memory_bytes: 26428
//
// Created by Myabu on 2020/01/29.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    string S;
    cin>>S;

    sort(S.begin(), S.end());
    if(S=="abc"){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}

Measured memory_bytes: 888
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
    cout.flush();
    cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T>
void update_max(T& x, T y) { x = max(x, y); }
template <typename T>
void update_min(T& x, T y) { x = min(x, y); }

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }






int main() {
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    cin >> n;
    vl a(n);
    ll sum = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    vl kek;
    kek.pb(sum / 2);
    kek.pb((sum + 1) / 2);
    ll ans = 2020202020 * 1e6;
    // cerr << kek << endl;
    for (ll k : kek) {
        ll x = 0;
        for (ll i = 0; i < n; ++i) {
            if (x + a[i] >= k) {
                update_min(ans, abs(x - (sum - x)));
                update_min(ans, abs(x + a[i] - (sum - x - a[i])));
                break;
            }
            x += a[i];
        }
    }
    cout << ans;

    print_time();
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define REP(i,a,b) for(int i = (int)(a); (i) < (int)(b); i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;

int main(){
  int n;
  cin >> n;
  ll lu[n+1];
  rep(i,n){ lu[i] = 0; }
  
  lu[0] = 2;
  lu[1] = 1;
  REP(j,2,n+1){ lu[j] = lu[j-1] + lu[j-2]; }
  cout << lu[n] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

ll solveSpecial(const vector<int>& S, int P) {
  ll res = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] % P == 0) {
      res += i + 1;
    } 
  }
  return res;
}

ll solve(const vector<int>& S, int B, int P) {
  map<int, int> mp;
  ++mp[0];
  ll res = 0;
  int acc = 0, pw = 1;
  for (int i = S.size() - 1; i >= 0; i--) {
    acc += pw * S[i] % P;
    acc %= P; 
    res += mp[acc];
    ++mp[acc];
    pw = pw * B % P;
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, P;
  string S;
  while (cin >> N >> P >> S) {
    int B = 10;
    vector<int> X(N);
    for (int i = 0; i < N; i++) X[i] = S[i] - '0';
    ll res;
    if (B % P == 0) {
      res = solveSpecial(X, P);
    } else {
      res = solve(X, B, P);
    }
    cout << res << endl;
  }
  return 0;
}


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

int main(){
  string S;
  cin >> S;
  sort(S.begin(), S.end());
  if(S.at(0)==S.at(1)&&S.at(2)==S.at(3)&&S.at(1)!=S.at(2)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

struct SegT {
private:
	int sz; vector<P> node;
	const P init_c = { mod,-mod };
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	SegT(vector<P> &v) {
		int n = v.size();
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
		rep(i, n) {
			node[i + sz - 1] = v[i];
		}
		per(i, sz - 1) {
			node[i] = f(node[2 * i + 1], node[2 * i + 2]);
		}
	}
	void update(int k, P a) {
		k += sz - 1;
		node[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[2 * k + 1], node[2 * k + 2]);
		}
	}
	P f(P a, P b) {
		int le = min(a.first, b.first);
		int ri = max(a.second, b.second);
		return P{ le,ri };
	}
	P query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			P vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			P vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};
typedef pair<int, P> speP;
void solve() {
	int n, q; cin >> n >> q;
	vector<speP> v(n);
	rep(i, n) {
		cin >> v[i].second.first >> v[i].second.second >> v[i].first;
	}
	sort(v.begin(), v.end());
	vector<P> u;
	rep(i, n) {
		v[i].second.first -= v[i].first; v[i].second.second -= v[i].first;
		u.push_back(v[i].second);
	}

	vector<speP> z;
	rep(i, n) {
		z.push_back({ v[i].second.first,{1,i} });
		z.push_back({ v[i].second.second,{0,i} });
	}
	sort(z.begin(), z.end());
	int loc = 0;
	SegT st(n);
	rep(i, q) {
		int d; cin >> d;
		while (loc < z.size() && z[loc].first <= d) {
			int id = z[loc].second.second;
			if (z[loc].second.first) {
				st.update(id, u[id]);
			}
			else {
				st.update(id, { mod,-mod });
			}
			loc++;
		}
		int le = 0, ri = n + 1;
		while (ri - le > 1) {
			int mid = (ri + le) / 2;
			P z = st.query(0, mid);
			if (z.first <= d && d < z.second) {
				ri = mid;
			}
			else {
				le = mid;
			}
		}
		if (ri == n+1)ri = -1;
		else ri = v[ri-1].first;
		//cout << "ans is ";
		cout << ri << endl;
	}
}

int main() {
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 16488
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <stack>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <map>

using namespace std;

typedef pair<int,int> pii;

main(){
    int size; cin >> size;
    string str;
    stack<char> stack;
    cin >> str;
    int cPar, aPar;
    stack.push(str[0]);
    for(int i=1;i<str.size();++i){
        if(!stack.empty() and str[i]==')'){
            char temp = stack.top();
            if(temp=='(') stack.pop();
            else stack.push(str[i]);
        }else stack.push(str[i]);
    }
    while(!stack.empty()){
        char temp = stack.top(); stack.pop();
        if(temp==')') str.insert(0,"(");
        else str.insert(str.size(),")");
    }
    cout << str;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define lli unsigned long long int
using namespace std;
#define S second
#define F first
#define pb push_back
#define M1 1000000007
#define M2 998244353
#define pint pair<int,int>
#define setit set<int>::iterator seti
#define mapit map<int,int> ::iterator mapi
#define MP make_pair
#define MT make_tuple
#define PI 3.14159265358979323846
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define mini(x,y) (y + ((x - y) & ((x - y) >>(sizeof(int) * CHAR_BIT - 1))))
#define maxi(x,y) (x - ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1))))
#define fr(j,a,b) for(j=a;j<b;j++)

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

int main()
{/*
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
*/
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t, n, g, b, i, x, j;
    cin >> n;
    n--;
    n = (n * (n + 1)) / 2;
    cout << n;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>;

signed main() {
    ll n, k;
    cin >>n>>k;
    ll r;
    // if(n>k) {
        r = n % k;
        r = min(r, k - r);
    // }
    // else {
    //     r = k % n;
    //     r = min(r, n - r);
    // }
    cout << r;

    return 0;
}

Measured memory_bytes: 256
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
b = [int(input()) for i in range(N)] 

Bingo = [[A11, A12, A13], [A21, A22, A23], [A31, A32, A33], \
         [A11, A21, A31], [A12, A22, A32], [A13, A23, A33], \
         [A11, A22, A33], [A13, A22, A31]]

for j in Bingo:
  if set(j).issubset(b):
    print('Yes')
    exit()

print('No')


Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = K;

		for(int i=1; i<N; i++){
			ans *= K-1;
        }
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
S = input()
N = len(S)


S1 = S[0:((N-1)//2)]
S2 = S[((N+3)//2)-1:((N+3)//2)-1+N]

if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1]:
    print("Yes")
else:print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main(void)
{
    int x,y;
    cin >> x >> y;
    if(x % y == 0){cout << "-1" << endl;}
    else{cout << x << endl;}
    return 0;
}

Measured memory_bytes: 256
import math
while True:
    try:
        n=int(input())
        num=list(range(n+1))
        num[1]=0
        for i in range(n):
            if num[i]>pow(n,0.5):
                break
            if num[i]==0:
                continue
            for j in range(num[i]*2, n+1, num[i]):
                num[j]=0
        print(n+1-num.count(0))
    except:
        break


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int a, b;
    cin >> a >> b;

    if (a >= 10 or b >= 10) {
        cout << -1 << endl;
    } else {
        cout << a * b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int K,l,r;
double P,E,T,ans=0;
void dfs(double l,double r,double p,int k){
	double m=(l+r)/2;
	if(k==K){
		if(abs(m-T)<=E){
			ans+=p;
		}
		return;
	}
	if(T-E<=l&&r<T+E){
		ans+=p;
		return;
	}
	if(r<T-E||T+E<l){
		return;
	}
	if(m>=T){
		dfs(l,m,p*(1-P),k+1);
		dfs(m,r,p*P,k+1);
	}else{
		dfs(m,r,p*(1-P),k+1);
		dfs(l,m,p*P,k+1);
	}
}
int main(){
	cin>>K>>l>>r>>P>>E>>T;
	dfs(l,r,1,0);
	printf("%.12f\n",ans);
}

Measured memory_bytes: 1248
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mp make_pair
#define pi pair<int,int>
#define pl pair<long long int,long long int>
#define pb push_back
#define fi first
#define se second
#define len(a) (int)(a).length()
#define sz(a) (int)(a).size()

using namespace std;

const int N = 1e5+5;
int n, m, x, y, dp[N] = {0}, ans = -1;
vector <int> adj[N];
bool vis[N];

void dfs (int x) {
	vis[x] = true;
	for (int i=0; i<sz(adj[x]); ++i) {
		if (!vis[adj[x][i]])
			dfs(adj[x][i]);
		dp[x] = max(dp[x], 1 + dp[adj[x][i]]);
		ans = max(ans, dp[x]);
	}
}

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> m;
	for (int i=0; i<m; ++i){
		cin >> x >> y;
		adj[x].pb(y);
	}
	for (int i=1; i<=n; ++i)
		vis[i] = false;
	for (int i=1; i<=n; ++i)	
		if (!vis[i])
			dfs(i);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
#define lint int64_t


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

    int zero = 0;
    int one = 0;
    rep(i,S.size()){
        if(S.at(i) == '0') zero++;
        else one++;
    }

    int ans = min(zero,one) * 2;

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


Measured memory_bytes: 512
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) a.begin(),a.end()
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * b / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    string s;
    char now;

    cin >> s;

    now = s[0];

    for (int i = 1; i < s.size(); i++) {
        if (now == s[i]) {
            cout << "Bad" << endl;
            return (0);
        }
        now = s[i];
    }

    cout << "Good" << endl;

}


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

using namespace std;

int main()
{
	int w, n, b, c, p;
	int a[31];

	cin >> w >> n;

	for (int i = 1; i <= w; i++){
		a[i] = i + 1;
	}
	
	for (int i = 1; i <= n; i++){
		scanf("%d,%d", &b, &c);
		p = a[b];
		a[b] = a[c];
		a[c] = p;
	}

	for (int i = 1; i <= w; i++){
		printf("%d\n", a[i] - 1);
	}
}

Measured memory_bytes: 3108
#include <iostream>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    
    if(N%2){
        cout << 0 << endl;
        return 0;
    }
    
    long long sum = 0;
    N /=10;
    sum += N;
    while(N){
        N /=5;
        sum +=N;
    }
    
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
    ll N;
    cin >> N ;
    vector<ll> a(N,0);// 
    cin >> a;
    vector<ll> dig = vector<ll>(70);

    for (ll j = 0; j < 70; j++){
        dig[j] = 0;
    }
    

    for(int i=1;i< a.size();i++){
        for (ll j = 0; j < 62; j++){
            if ( (a[i] >> j)& 1){
                dig[j]++;//1 no kazu
            }
        }
    }


    

    for (ll j = 0; j < 70; j++){
        cerr << j << "  ; dig : " << dig[j] <<endl;
    }
    
    

    ll ans = 0;

    // a ^ b :排他的論理和
    for (ll i = 0; i < N-1; i++){


        cerr << "a " << a[i] <<endl;

        ll num = N-1 -i; //何このわか
        for (ll j = 0; j < 61; j++){
            ll q = 1;
            for(int k=0;k<j;k++)q*=2;

            if ( (a[i] >> j) & 1  ){
                ans +=(num - dig[j]) * (q % mod);
                ans %= mod;
            }else{
                ans +=dig[j] * (q % mod);
                ans %= mod;
            }
        }

        for (ll j = 0; j < 61; j++){
            if ( (a[i+1] >> j) & 1){
                dig[j]--;
            }
        }
        

    }

    
    cout << (ans % mod) <<endl;
    
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
using namespace std;
set<int>p, q;
set<int>::iterator pit;
set<int>::iterator qit;
int main(){
    int n, m;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        int a;
        scanf("%d", &a);
        p.insert(a);
    }
    scanf("%d", &m);
    for(int i = 0; i < m; i++){
        int b;
        scanf("%d", &b);
        q.insert(b);
    }

    int cnt = 0;
    for(pit=p.begin(); pit!=p.end(); pit++){
        for(qit=q.begin(); qit!=q.end(); qit++){
            if(*pit == *qit){
                cnt++;
                break;
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    P a[n];
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a, a + n);
    reverse(a, a + n);
    rep(i, n){
        if(i != a[0].second) cout << a[0].first << endl;
        else cout << a[1].first << endl;
    }


}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int K;
int X[100000];
int main(){
  int i, res=1073709056;
  rd(N);
  rd(K);K += (-1);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
    }
  }
  for(i=K;i<N;i++){
    chmin(res,min_L(abs(X[i]), abs(X[i-K]))+ X[i] - X[i-K]);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, K, X[1d5];
// {
//   int i, res = int_inf;
//   rd(N,K--,X(N));
//   rep(i,K,N) res <?= min(abs(X[i]), abs(X[i-K])) + X[i] - X[i-K];
//   wt(res);
// }


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="Sunny")
    cout<<"Cloudy"<<endl;
  else if(s=="Cloudy")
    cout<<"Rainy"<<endl;
  else if(s=="Rainy")
    cout<<"Sunny"<<endl;
}

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

int main() {
	int k;
	while (cin >> k, k) {
		int sum = 0;
		for (int i = 0;i < k*(k - 1) / 2;i++) {
			int a;
			cin >> a;
			sum += a;
		}

		cout << sum / (k - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3080