akhauriyash/Code-Regression huggingface dataset:
// ------------------------------------
// Date:2018/ 3/ 3
// Problem:AOJ DPL Edit Distance (Levenshtein Distance) 1_E.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

// dp[s1の現在見ている文字][s2の現在見ている文字]
int dp[1010][1010]; // 1020100 Byte ≒ 10^6 Byte

int main()
{
  string s1, s2;
  cin >> s1 >> s2;
  REP(i, s1.size() + 1) {
    REP(j, s2.size() + 1) {
      dp[i][j] = 1e9+1;
    }
  }
  REP(i, s1.size() + 1) {
    dp[i][0] = i;
  }
  REP(j, s2.size() + 1) {
    dp[0][j] = j;
  }
  
  REP(i, s1.size()) {
    REP(j, s2.size()) {
      // insert or delete or replace
      dp[i + 1][j + 1] = min(dp[i][j],
                             min(dp[i + 1][j],
                                 dp[i][j + 1])) + 1;
      if (s1[i] == s2[j]) {
        dp[i + 1][j + 1] = min(dp[i][j],
                               dp[i + 1][j + 1]);
      }
    }
  }
  
  int ans = dp[s1.size()][s2.size()];
  
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 7200
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;


int main(void) {
	ll n; cin >> n;
	vint x(n+1),y(n);
	rep(i, n) {
		int m;
		cin >> m;
		x[m]++;
		y[i] = m;
	}
	ll sum=0;
	for (int i = 1; i <= n;i++) {
		sum += (x[i] * (x[i] - 1)) / 2;
	}

	rep(i, n) {
		cout << sum - x[y[i]] + 1 << endl;
	}

	return 0;
}



Measured memory_bytes: 5760
N, M = map(int, input().split())
X = list(map(int, input().split()))

if N > M:
    print(0)
    exit()

X.sort(reverse=True)

diff = []
for i in range(1, M):
    diff.append(X[i-1] - X[i])

diff.sort()

for _ in range(N-1):
    diff.pop()

print(sum(diff))



Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

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

typedef long long ll;

void dfs(const int &N,int &count,const  int &visiting,vector<int> visited,const vector<vector<int>> &G) {
    visited.push_back(visiting);
    if (visited.size()==N) {
        count++;
        return;
    }
    auto roots = G[visiting];
    vector<int> avails;
    for(const auto& root:roots) {
        auto it = find(ALL(visited),root);
        // iteratorのendは(最終要素の「次」)
        if (it != visited.end()) continue;
        else avails.push_back(root);
    }
    for(const auto& el:avails) {
        dfs(N,count,el,visited,G);
    }

}


int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>> G(N+1);
    REP(i,M) {
        int a,b;
        cin >> a >> b;
        G[b].push_back(a);
        G[a].push_back(b);
    }
    int ans=0;
    vector<int> dmy;
    dfs(N,ans,1,dmy,G);
    cout << ans << endl;



    return 0;
}


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

int main() {
  string w;
  cin >> w;
  
  bool good = 0;

for (int j = 0; j < w.size(); j++) { 
  if (w.size() == 1) break;
  int good_j = 1;
  for (int i = 0; i < w.size(); i++) {  
  	if (w.at(i) == w.at(j)) {
    good_j *= -1;
      //cout << good_j;
  	}
  	else continue; 
	}
  if ( good_j == -1) {
    good = 0;
  	break;
  }
  else if (good_j == 1) good = 1;
}
  if ( good == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

ll choose(ll n, ll k){
  return n * (n - 1) / 2;
}

int main(){
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  rep(i, N) a[i]--;

  map<int, ll> que;
  rep(i, N) que[a[i]]++;
  ll ans = 0;
  rep(i, N) ans += choose(que[i], 2);
  rep(i, N){
    cout << ans - choose(que[a[i]], 2) + choose(que[a[i]] - 1, 2) << endl;
  }
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int i = 0; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    char a = '0', b = '1';
    rep(h, H) rep(w, W){
        if(w == 0 && h == B) swap(a, b);
        cout << (w < A ? a : b);
        if(w == W-1) cout << "\n";
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	int P[8], Q[8], moto[8];
	for (int i = 0; i < n; ++i)
	{
		moto[i] = i + 1;
		cin >> P[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> Q[i];
	}
	int count = 1, pc = 0, qc = 0;
	bool ok;
	do
	{
		ok = 1;
		for (int i = 0; i < n; ++i)
		{
			ok *= (P[i] == moto[i]);
		}
		pc = (ok?count:pc);
		ok = 1;
		for (int i = 0; i < n; ++i)
		{
			ok *= (Q[i] == moto[i]);
		}
		qc = (ok?count:qc);
		++count;
	} while (next_permutation(moto, moto + n));
	cout << abs(pc - qc) << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
long long INF = 1e18;
const int mod = 1e9 + 7;

using namespace std;

int main(){
  long long n,m,ans=0;
  bool f=true;

  scanf("%lld",&n);

  while(true){
    m = n % 10;
    if(n /= 10) ans += 9;
    else if(f){
      ans += m;
      break;
    }else{
      ans += m - 1;
      break;
    }
    if(f) if(m!=9) f=false;
  }

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


Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    int K, T;
    cin >> K >> T;
    struct Cake {
        int id;
        int count;
    };
    auto comp = [](Cake lhs, Cake rhs) { return lhs.count < rhs.count; };
    priority_queue<Cake, vector<Cake>, decltype(comp)> queue(comp);
    for (int i = 0; i < T; i++) {
        int ai;
        cin >> ai;
        queue.push(Cake{i + 1, ai});
    }
    int cnt = 0;
    int prev_id = 0;
    while (!queue.empty()) {
        Cake a = queue.top();
        queue.pop();
        if (a.id != prev_id) {
            prev_id = a.id;
            a.count--;
            if (a.count > 0) {
                queue.push(a);
            }
        } else {
            if (queue.empty()) {
                prev_id = a.id;
                cnt++;
                a.count--;
                if (a.count > 0) {
                    queue.push(a);
                }
            } else {
                Cake b = queue.top();
                queue.pop();
                prev_id = b.id;
                b.count--;
                if (b.count > 0) {
                    queue.push(b);
                }
                queue.push(a);
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s,t;
	cin>>s>>t;
	int ls=s.size(),lt=t.size();
	bool val=true;
	for (int i=0;i<ls;++i)
	{
		char c=s[i];
		if (c!=t[i])
		{
			val=false;
			break;
		}
	}
	if (val)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3592
n = int(input())
B = list(map(int, input().split()))
A = []*n
ans = B[0]
curosr = B[0]
for b in B[1:]:
  if curosr < b:
    ans += curosr
  else:
    ans += b
  curosr = b
ans +=B[-1]
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
const int siz = 2*(2500 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}

signed main()
{
	
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		double n1 = (double) n ;
		n1 *= 2.0;
		n1 *= PI;
		std::cout << std::fixed;
    std::cout << std::setprecision(2);
    std::cout << n1;
}
}

Measured memory_bytes: 3792
#include <stdio.h>
#define MIN -1000000000
int heapsize=0,A[2000000001];
void maxHeapify(int );
void insert(int );
void helpIncreaseKey(int ,int );
int heapExtractMax(int );


int main(void){
  int key;
  char command[7];
  while(1){
    scanf("%s",command);
    if(command[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(command[0]=='e'){
      if(command[1]=='n')
        break;
      else if(command[1]=='x')
        printf("%d\n",helpExtractMax());
    }
  }
  
  return 0;
}

int helpExtractMax(int element){
  int max;
  if(heapsize<1)
    return ;
  max=A[1];
  A[1]=A[heapsize];
  heapsize--;
  maxHeapify(1);
  return max;
}

void helpIncreaseKey(int element,int key){
  int temp;
  if(key < A[element])return ;
  A[element]=key;
  while(element>1 && A[element/2] < A[element]){
    //compare parent's key with child's key
    temp=A[element];
    A[element]=A[element/2];
    A[element/2]=temp;
    element/=2;
  }
}

void insert(int key){
  heapsize++;
  A[heapsize]=MIN;
  //set key to A[heapsize]
  helpIncreaseKey(heapsize,key);
}
void maxHeapify(int parent){
  int left,right,maxnode,temp;
  left=2*parent;
  right=left+1;

  if(left<=heapsize && A[left] > A[parent])
    maxnode=left;
  else
    maxnode=parent;
  if(right<=heapsize && A[right] > A[maxnode])
    maxnode=right;

  if(maxnode!=parent){
    //need to swap node
    temp=A[maxnode];
    A[maxnode]=A[parent];
    A[parent]=temp;

    if(maxnode*2<=heapsize)
      //there is child of maxnode
      maxHeapify(maxnode);
  }
}


Measured memory_bytes: 5600
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		BigDecimal n = new BigDecimal(N);
		int binaryTarget = Integer.toBinaryString(K).length();
		String binaryLong = Integer.toBinaryString(K);
		int diff = N - K;
		BigDecimal ans = BigDecimal.ZERO;
		if (diff < 0) {
			for (int i = 1; i < N + 1; i++) {
				int a = Integer.toBinaryString(i).length();
				long a_bin = Long.parseLong(Integer.toBinaryString(i));
				long sub = Long.parseLong(binaryLong.substring(0, a));
				int b = binaryTarget - a;
				if (a_bin < sub) {
					b++;
				}
				if (a_bin == sub && binaryLong.substring(a, binaryTarget).contains("1")) {
					b++;
				}
				BigDecimal c = new BigDecimal(Math.pow(2, b)).multiply(n);
				ans = ans.add(BigDecimal.ONE.divide(c, 15, BigDecimal.ROUND_DOWN));
			}
		} else {
			for (int i = 1; i < K + 1; i++) {
				int a = Integer.toBinaryString(i).length();
				long a_bin = Long.parseLong(Integer.toBinaryString(i));
				long sub = Long.parseLong(binaryLong.substring(0, a));
				int b = binaryTarget - a;
				if (a_bin < sub) {
					b++;
				}
				if (a_bin == sub && binaryLong.substring(a, binaryTarget).contains("1")) {
					b++;
				}
				BigDecimal c = new BigDecimal(Math.pow(2, b)).multiply(n);
				ans = ans.add(BigDecimal.ONE.divide(c, 15, BigDecimal.ROUND_DOWN));
			}
			ans = ans.add(
					BigDecimal.ONE.multiply(new BigDecimal(diff)).divide(n, 15, BigDecimal.ROUND_DOWN));
		}
		System.out.println(ans);
	}
}


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

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }

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

    int size(int x) {
        return -par[find(x)];
    }
};

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

    int N, Q;
    cin >> N >> Q;
    UnionFind uf(N);
    for (int i = 0; i < Q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) uf.unite(u, v);
        else cout << uf.same(u, v) << "\n";
    }
}

Measured memory_bytes: 3836
#include <iostream>

using namespace std;

typedef long long ll;

ll a;

ll bp(ll a, ll n){
	if(n == 0) return 1ll;
  	if(n == 1) return a;
  	ll res = bp(a, n/2);
  	if(n & 1) 
    	return res * res * a;
  	else
    	return res * res;
}

int main(){
	ll a;
  	cin >> a;
  	cout << 3 * bp(a, 2ll);
  	return 0;
}

Measured memory_bytes: 256
N = int(input())
alphas = [ chr(i) for i in range(ord("a"), ord("z")+1)]

res = ""
while N != 0:
  ch = N % 26
  if ch==0:
    res += alphas[-1]
    N = N//26
    N -= 1
  else:
    res += alphas[ch-1]
    N = N//26

print(res[::-1])

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

int N;
int nextNum[114514];
int* nexts[114514];
int* henIndice[114514];

int answer[114514];

void asumikana(int idx, int pidx, int pcolor) {
	int i;
	int nextColor = 1;
	for (i = 0; i < nextNum[idx]; i++) {
		if (nexts[idx][i] != pidx) {
			int color;
			if (nextColor == pcolor) nextColor++;
			color = nextColor++;
			answer[henIndice[idx][i]] = color;
			asumikana(nexts[idx][i], idx, color);
		}
	}
}

int main() {
  int i,K;
  if(scanf("%d",&N)!=1)return 1;
  for(i=1;i<N;i++){
    int a,b;
    if(scanf("%d%d",&a,&b)!=2)return 1;

    nexts[a] = realloc(nexts[a], sizeof(int) * (nextNum[a] + 1));
		nexts[a][nextNum[a]] = b;
		henIndice[a] = realloc(henIndice[a], sizeof(int) * (nextNum[a] + 1));
		henIndice[a][nextNum[a]] = i;
		nextNum[a]++;

    nexts[b] = realloc(nexts[b],sizeof(int)*(nextNum[b]+1));
    nexts[b][nextNum[b]]=a;
    henIndice[b]=realloc(henIndice[b],sizeof(int)*(nextNum[b]+1));
    henIndice[b][nextNum[b]]=i;
    nextNum[b]++;
  }
  K=0;
  for(i=1;i<=N;i++){
    if(nextNum[i]>K)K=nextNum[i];
  }
  asumikana(1,0,0);

  printf("%d\n",K);
  for(i=1;i<N;i++){
    printf("%d\n",answer[i] );
  }

  for(i=1;i<=N;i++){
    free(nexts[i]);
    free(henIndice[i]);
  }
  return 0;
}


Measured memory_bytes: 9856
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[4];
    string tmp;
    cin >> tmp;
    A[0] = tmp[0] - '0';
    A[1] = tmp[1] - '0';
    A[2] = tmp[2] - '0';
    A[3] = tmp[3] - '0';

    for (int i = 0; i < 8; ++i) {
        int tmp_sum = A[0];
        int bit = 0;
        string ans = to_string(A[0]);
        while(bit < 3){
            if(i >> bit & 1) {
                // 足し算
                tmp_sum += A[bit+1];
                ans += "+" + to_string(A[bit+1]);
            }else{
                // 引き算
                tmp_sum -= A[bit+1];
                ans += "-" + to_string(A[bit+1]);
            }
            bit++;
        }
        if (tmp_sum == 7){
            ans += "=7";
            cout << ans << "\n";
            break;
        }
    }


    return 0;
}



Measured memory_bytes: 256
while 1:
    H,W=[int(i) for i in input().split()]
    if H==W==0:
        break
    else:
        for i in range(H):
            count=0
            for s in range(W):
                if i%2==0:
                    print('#',end='')
                    count=count+1
                    if count==W:
                        break
                    print('.',end='')
                    count=+count+1
                    if count==W:
                        break
                else:
                    print('.',end='')
                    count=+count+1
                    if count==W:
                        break
                    print('#',end='')
                    count=count+1
                    if count==W:
                        break
            print('')
    print('')

Measured memory_bytes: 9080
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N, M;	cin >> N >> M;
	vector<int> P(M), Y(M), yd[100001];
	rep(i, M) {
		cin >> P[i] >> Y[i];
		yd[P[i]].push_back(Y[i]);
	}
	rep(i, N)sort(yd[i + 1].begin(), yd[i + 1].end());
	rep(i, M)printf("%012lld\n", ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin() + 1));
	cin >> N;
}

Measured memory_bytes: 7808
S = input()
n = len(S) - 1
ans = 0

for i in range(2**n):
    A = [0] * n
    for j in range(n):
        if (i >> j) & 1 == 1:
            A[j] = 1
    a = 0
    for j in range(n):
        if A[j] == 1:
            ans += int(S[a: j+1])
            a = j+1
    ans += int(S[a:])
    a = 0
print(ans)







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

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"


int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif

	string s;
	cin >> s;
	int n = sz(s);
	for (char c = 'a'; c <= 'z'; ++c)
		if (find(all(s), c) == s.end()) {
			cout << s + c << endl;
			return 0;
		}

	string t = s;

	if (next_permutation(all(s))) {
		for (int i = 0; i < sz(s); ++i)
			if (s[i] != t[i]) {
				cout << s.substr(0, i + 1) << endl;
				return 0;
			}
		return 0;
	}

	puts("-1");

	return 0;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

ll gcd(ll a, ll b){
    ll tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    ll r = a%b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

ll kaisuu(ll a) {
    int i = 0;
    while(1) {
        if(a % 2 == 0) {
            i++;
            a /= 2;
        } else {
            break;
        }
    }

    return i;
}

set<ll> st;

int main() {
    ll n, m, ans = 0;
    cin >> n >> m;
    ll kobai, koyaku;

    REP(i, n) {
        ll tmp;
        cin >> tmp;
        tmp /= 2;
        st.insert(tmp);
    }

    koyaku = kobai = *st.begin();
    int idx = 0;
    for(auto a: st) {
        if(idx != 0) {
            koyaku = gcd(kobai, a);
            kobai = a * kobai / koyaku;
        }
        idx++;
    }

    //cout << kobai << endl;

    if(kobai > m) {
        cout << "0" << endl;
        return 0;
    }

    for(auto s: st) {
        if(kobai / s % 2 == 0) {
            cout << "0" << endl;
            return 0;
        }
    }

    ans = (m/kobai - 1) / 2 + 1;

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 384
import sys
import heapq as hq

mod = 10**9 + 7

readline = sys.stdin.buffer.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def dijkstra(G, s, t=None):
    dist = [-1]*len(G)
    fr = [0]*len(G)
    dist[s] = 0
    fr[s] = 1
    q = [(0, s)]
    while q:
        d, v = hq.heappop(q)
        if d > dist[v]: continue
        for x, c in G[v]:
            if dist[x] < 0 or dist[x] > d + c:
                dist[x] = d + c
                fr[x] = fr[v]
                hq.heappush(q, (d + c, x))
            elif dist[x] == d + c:
                fr[x] = (fr[x] + fr[v]) % mod
    return dist, fr


def solve():
  n, m = nm()
  s, t = nm()
  s -= 1; t -= 1
  G = [list() for _ in range(n)]
  for _ in range(m):
    u, v, d = nm()
    u -= 1; v -= 1
    G[u].append((v, d))
    G[v].append((u, d))
  diss, frs = dijkstra(G, s)
  dist, frt = dijkstra(G, t)
  cnt = frt[s] * frs[t] % mod
  for i in range(n):
    if diss[i] + dist[i] == dist[s] and diss[i] == dist[i]:
      # print(i)
      cnt = (cnt - (frs[i] * frt[i] % mod)**2 % mod) % mod
    for j, x in G[i]:
      if diss[i] + x + dist[j] == dist[s] and diss[i] < dist[i] and diss[j] > dist[j]:
        # print(i, j, (diss[i], diss[j]), (dist[i], dist[j]))
        cnt = (cnt - (frs[i] * frt[j] % mod)**2 % mod) % mod
  print(cnt)
  return

solve()


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

#define lint long long

typedef pair<int, int> P;

int main(){
    int N;
    cin >> N;
    
    vector<int> A(N), B(N), C(N);

    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    for(int i = 0; i < N; ++i){
        cin >> B[i];
    }
    for(int i = 0; i < N; ++i){
        cin >> C[i];
    }
    
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    
    lint cnt = 0;
    
    vector<lint> count(N);
    for(int i = 0; i < N; ++i){
        count[i] = distance(lower_bound(C.begin(), C.end(), B[i] + 1), C.end());
    }
    
    vector<lint> sum(N + 1);
    sum[N] = 0;
    sum[N - 1] = count[N - 1];
    for(int i = N - 1; i >= 0; --i){
        sum[i] = sum[i + 1] + count[i];
    }
    
    for(int i = 0; i < N; ++i){
        int pos = distance(B.begin(), lower_bound(B.begin(), B.end(), A[i] + 1));
        cnt += sum[pos];
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, s[100000];
int pop() {
  top--;
  return s[top+1];
}

void push(int t) {
  s[++top] = t;
}

int main() {
  int x, y, tmp;
  top = 0;
  char p[100];

  while(scanf("%s", p) != EOF){
    if (p[0]=='+'){
      x = pop();
      y = pop();
      push(x+y);
    } 

    else if(p[0]=='-'){
      y = pop();
      x = pop();
      tmp = x-y;
      push(x-y);
    }
 
    else if(p[0]=='*'){
      x = pop();
      y = pop();
      push(x*y);
    }
 
    else{
      push(atoi(p));
    }
  }

  printf("%d\n", pop());
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const ll MOD = 1000000007;

int main() {
    ll N, cnt = 0;
    cin >> N;
    vll A(N+2, 0), B(N+2, 0);
    REP(i, N+1)
        cin >> A[i];
    REP(i, N)
        cin >> B[i];
    REP(i, N) {
        if (A[i] >= B[i])
            cnt += B[i];
        else {
            cnt += A[i];
            B[i] -= A[i];
            if (A[i+1] >= B[i]) {
                cnt += B[i];
                A[i+1] -= B[i];
            }
            else {
                cnt += A[i+1];
                A[i+1] = 0;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
module Main where

import           Control.Monad
import           Debug.Trace
import qualified Data.Vector.Unboxed           as VU
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char
import           Data.Maybe
tuplify2 (x : y : _) = (x, y)
tuplify2 _           = undefined

getVUIntFromInputLineAtBSC8 :: IO (VU.Vector Int)
getVUIntFromInputLineAtBSC8 =
    VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
getVUIntListFromInputLineAtBSC8 =
    VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine

readInt = fst . fromJust . BSC8.readInt
readIntTuple = tuplify2 . map readInt . BSC8.words
readIntList = map readInt . BSC8.words

getInt = readInt <$> BSC8.getLine
getIntList = readIntList <$> BSC8.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BSC8.getLine
getIntMatrix = map readIntList . BSC8.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BSC8.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BSC8.getLine
getIntTuples = map readIntTuple . BSC8.lines <$> BSC8.getContents

main :: IO ()
main = do

    aK <- getInt

    let kLen = [1 .. 10 ^ 5]
    print $ makeRunrun 1 aK
--    print  $     scanRunrun [1..]  aK

makeRunrun :: Int -> Int -> Int
makeRunrun k 1 = k
makeRunrun k n =
    let
        digit = getDigit k 0
        num x y = div (mod x (10 ^ (y + 1))) (10 ^ (y))
        sa x y = (num x (y + 1)) - (num x y)
    in  
        --trace (show k) $
        makeRunrun
            (foldl
                (\acc x -> if acc == 0
                    then if x == digit
                        then if num k x == 9
                            then test 1 (x+1)
                            else test ((num k x) + 1) x
                        else if num k x == 9
                            then 0
                            else case sa k x of
                                1  -> hoge k (x + 1) + (test ((num k x) + 1) x)
                                0  -> hoge k (x + 1) + (test ((num k x) + 1) x)
                                -1 -> 0
                    else acc
                )
                0
                [0 .. digit]
            )
            (n - 1)

hoge :: Int -> Int -> Int
hoge x digit = let ret = x - (mod x (10 ^ digit)) in ret
test :: Int -> Int -> Int
test x digit =
    let ret = foldl (\acc y -> acc + (max (x - (digit - y)) 0) * (10 ^ y))
                    0
                    (reverse [0 .. digit])
    in  ret

scanRunrun :: [Int] -> Int -> Int
scanRunrun (x : xs) k = if (judgeRunrun x)
    then if k == 1 then x else scanRunrun xs (k - 1)
    else scanRunrun xs k


judgeRunrun :: Int -> Bool
judgeRunrun x =
    let digit = getDigit x 0
        num x y = div (mod x (10 ^ (y + 1))) (10 ^ (y))
    in  foldl (\acc y -> acc && ((abs ((num x (y + 1)) - (num x y))) <= 1))
              True
              (reverse [0 .. digit - 1])

getDigit x n = let y = (div x 10) in if y == 0 then n else getDigit y (n + 1)


Measured memory_bytes: 1020
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<vector>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

#define ld  long double
#define ll  long long int
#define ull unsigned long long int
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define endl "\n"

const ll INF = 1LL << 60;
const ld EPS = 1e-11;

//切り上げ整数除算
int divRoundUp(const int& a, const int& b) { return (a + b - 1) / b; }
//四捨五入
int roundOff(const double& a) { return (int)(a + 0.5); }
// r の(誤差付きの)符号に従って, -1, 0, 1 を返す.
int sgn(const ld& r) { return (r > EPS) - (r < -EPS); }
// a, b の(誤差付きの)大小比較の結果に従って, -1, 0, 1 を返す.
int sgn(const ld& a, const ld& b) { return sgn(a - 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; }

using namespace std;

inline void Main() {
	int n; cin >> n;
	string s; cin >> s;

	for (auto& c : s) {
		c = (c - 'A' + n) % 26 + 'A';
	}

	cout << s << endl;
}

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

	Main();

	return 0;
}

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

void p(const char c, int n) {
	int i;
	for (i = 0; i < n; i ++) {
		printf("%c", c);
	}
}

int main() {
	int sx, sy, tx, ty;
	int h, w;
	int i;
	scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
	
	h = ty - sy;
	w = tx - sx;

	p('U',h);
	p('R',w);
	p('D',h);
	p('L',w);
	p('L',1);
	p('U',h+1);
	p('R',w+1);
	p('D',1);
	p('R',1);
	p('D',h+1);
	p('L',w+1);
	p('U',1);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, a[2][100], ta=0, mu=0;

signed main() {
	cin >> n;
	rep(i, 2) {
		rep(j, n) {
			cin >> a[i][j];
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (i < j)ta += a[1][j];
			else if (i > j)ta += a[0][j];
			else {
				ta += a[0][j];
				ta += a[1][j];
			}
		}
		if (ta > mu)mu = ta;
		ta = 0;
	}
	cout << mu << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double ans = v.front();
  for (int i = 1; i < n; ++i) {
    ans = (ans + v[i]) / 2;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
a, b = map(int, input().split())
c = b - a + 1
if c % 2 == 0:
    if a % 2 == 0:
        print(c // 2 % 2)
    else:
        print((c - 2) // 2 % 2 ^ a ^ b)
else:
    if a % 2 == 0:
        print((c - 1) // 2 % 2 ^ b)
    else:
        print((c - 1) // 2 % 2 ^ a)


Measured memory_bytes: 3064
import java.util.Scanner;

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


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
const int INF = 0x3f3f3f3f;

int dp[100100];
int main() {
  int n;
  rep(i, 100100) dp[i] = INF;
  dp[0] = 0;
  rep(i, 100100) {
    for (int j = 1; i + j < 100100; j *= 6)
      dp[i + j] = min(dp[i + j], dp[i] + 1);
    for (int j = 1; i + j < 100100; j *= 9)
      dp[i + j] = min(dp[i + j], dp[i] + 1);
  }
  cin >> n;
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
s = input()
if s[0] == "A" and s[2:-1].count("C")==1:
    c = s[2:-1].index('C')
    if (s[1]+s[2:c+2]+s[c+3:]).islower():
        print('AC')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // LOCAL
    int a, b, c, d, k;
    cin >> a >> b >> c >> d >> k;
    if (c < a) c += 24;
    int aa = a * 60 + b;
    int cc = c * 60 + d;
    int diff = cc - aa;
    if (diff < k) puts("0");
    else {
        cout << diff - k << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int s(ll x) {
    int ans = 0;
    while(x > 0) {
        x /= 10;
        ans++;
    }
    return ans;
}
int f(ll a, ll b) {
    return max(s(a), s(b));
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    int ans = f(1, n);
    for(ll a = 1; a * a <= n; a++) {
        if(n % a == 0) {
            ans = min(ans, f(a, n / a));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll n,k;
    cin >> n >> k;
    vector <ll> v;
    for (ll i = 0;i<n;i++){
        ll h;
        cin >> h;
        v.push_back(h);
    }
    sort(v.begin(),v.end());
    ll ans = mop;
    for (ll i=k-1;i<v.size();i++){
        ll par = v[i] - v[i-k+1];
        if(ans > par){
            ans = par;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.InteropServices;
//素因数分解　
//p^e + p^e + ... + p^e = n!
//(e+1)(e+1)..(e+1)=75=5*5*5

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for(int i = 2; i <= n; i++)
            {
                CountPrime(i);
            }
            long ans = 0;
            var L = new List<int>();
            foreach(var r in res)
            {
                L.Add(r.Value+1);
            }
            int k = L.Count;
            if (n >= 2)
            {
                int t3 = 0, t5 = 0, t15 = 0, t25 = 0, t75=0;
                for(int i = 0; i < k; i++)
                {
                    if (L[i] >= 3) t3++;
                    if (L[i] >= 5) t5++;
                    if (L[i] >= 15) t15++;
                    if (L[i] >= 25) t25++;
                    if (L[i] >= 75) t75++;
                }
                if (t5 >= 2 && t3 >= 1) ans += t5 * (t5 - 1) / 2* ( t3 - 2 );
                if (t25 >= 1 && t3 >= 1) ans += t25 * (t3 - 1);
                if (t15 >= 1 && t5 >= 1) ans += t15 * (t5 - 1);
                if (t75 >= 1) ans += t75;
            }
            Console.WriteLine(ans);
        }
        static public Dictionary<long,int> res= new Dictionary<long, int>();
        public static void CountPrime(long n)
        {
            for (long i = 2; i <= n; i++)
            {
                if (n % i != 0) continue;
                while (n % i == 0)//ここで計算量減らす
                {
                    n /= i;
                    if (res.ContainsKey(i)) res[i]++;
                    else res[i] = 1;
                }
            }
            
        }
    }
}


Measured memory_bytes: 27764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

int n;

int main(void){
	cin>>n;
	reg(i,1,9){
		if(n%i==0){
			if(n/i<=9){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
typedef pair<ll,ll> P;
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  const ll inf=1e10;
  ll h,w,sx,sy,tmp=0,ans=0;cin>>h>>w;
  string s;
  char maze[20][20+1];
  vector<P> v;
  rep(i,h) {
    cin>>s;rep(j,w) {
      maze[i][j]=s[j];
      if(s[j]=='.') v.push_back(P(i,j));
    }
  }
  ll d[20][20],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

  for(ll pos=0;pos<v.size();++pos) {
    sx=v[pos].first;sy=v[pos].second;
    queue<P> que;
    rep(i,h) rep(j,w) d[i][j]=inf;
    que.push(P(sx,sy));d[sx][sy]=0;

    while(que.size()) {
      P p=que.front();que.pop();
      rep(i,4) {
        ll nx=p.first+dx[i],ny=p.second+dy[i];
        if(0<=nx&&nx<h&&0<=ny&&ny<w && maze[nx][ny]!='#'&&d[nx][ny]==inf) {
          que.push(P(nx,ny));
          d[nx][ny]=d[p.first][p.second]+1;
        }
      }
    }
    rep(i,h){
      rep(j,w) {
        tmp=d[i][j];
        if(tmp!=inf&&tmp>ans) ans=tmp;
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int n,flag,x[101],h[101],y[101],re_x,re_y,re_h;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d%d",&x[i],&y[i],&h[i]); 
        if(h[i]!=0)
		flag=i;
    }
    for(int j=0;j<=100;++j)
      for(int k=0;k<=100;++k)
        {
            re_x=j;
			re_y=k;
            re_h=h[flag]+abs(x[flag]-re_x)+abs(y[flag]-re_y);
            
            for(int i=1;i<=n;++i)
            {
                if(h[i]!=std::max(re_h-std::abs(x[i]-re_x)-std::abs(y[i]-re_y),0))
				break;
				
                if(i==n)
                {
                    printf("%d %d %d",re_x,re_y,re_h);
                    return 0;
                }
            }
        }
}

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

void change(int *label, char word)
{
	if (word == 'N')
	{
		int tmp = label[5];

		label[5] = label[1];
		label[1] = label[2];
		label[2] = label[6];
		label[6] = tmp;
	}
	else if (word == 'S')
	{
		int tmp = label[6];

		label[6] = label[2];
		label[2] = label[1];
		label[1] = label[5];
		label[5] = tmp;
	}
	else if (word == 'E')
	{
		int tmp = label[3];

		label[3] = label[1];
		label[1] = label[4];
		label[4] = label[6];
		label[6] = tmp;
	}
	else
	{
		int tmp = label[6];

		label[6] = label[4];
		label[4] = label[1];
		label[1] = label[3];
		label[3] = tmp;
	}
}

int main()
{
	int label[7];
	for (int i = 1; i < 7; i++) cin >> label[i];

	string S; 
	cin >> S;

	for (int i = 0; i < S.size(); i++)
	{
		change(label, S[i]);
	}

	cout << label[1] << endl;
}


Measured memory_bytes: 3172
input_line = []

while line = gets
  input_line << line.chomp
end

n = input_line.shift.to_i

A = input_line.shift.split(" ").map(&:to_i)

puts A.join(" ")
1.upto(A.length-1) do |i|
  key = A[i]
  j = i - 1
  while j >= 0 && A[j] > key do
    A[j+1] = A[j]
    j -= 1
    A[j+1] = key
  end
  puts A.join(" ")
end

Measured memory_bytes: 8780
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 100010
#define SZ 1010

typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
int N,M;
set<pair<int,int> > S;
vector<int> edges[SIZE];
int deg[SIZE];
int dp[SIZE];
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen(fi, "r", stdin);
    #endif */
    //freopen("route.in","r",stdin);
    //freopen("route.out","w",stdout);
    //cin.ignore();
    //cin.clear();
    boost;
    //cin.tie(0);
    //cout<<"Case "<<tt<<": ";
    cin>>N>>M;
    for(int i=1;i<=M;i++){
        int x,y;
        cin>>x>>y;
        edges[x].push_back(y);
        deg[y]++;
    }
    for(int i=1;i<=N;i++){
        S.insert(make_pair(deg[i],i));
    }
    while(S.size()){
        pair<int,int> which = *(S.begin());
        S.erase(S.begin());
        int ver = which.second;
        for(int i=0;i<edges[ver].size();i++){
            int okay = edges[ver][i];
            dp[okay] = max(dp[okay],dp[ver] + 1);
            S.erase(make_pair(deg[okay],okay));
            deg[okay]--;
            S.insert(make_pair(deg[okay],okay));
        }
    }
    int fans = 0;
    for(int i=1;i<=N;i++){
        fans = max(fans,dp[i]);
    }
    cout<<fans<<endl;
    return 0;
}

Measured memory_bytes: 11264
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {
    st s; cin >> s;
    if(s[Size(s) - 1] == 's') s += "es";
    else s += 's';
    cout << s << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main() {
  int h, w;
  int output[2];
  int temp;
  int length;
  int answer;
  int i, j;

  while(1) {
    scanf("%d %d", &h, &w);
    if(h == 0 && w == 0) break;

    length = h * h + w * w;

    output[0] = 150; 
    output[1] = 150;
    answer = 150 * 150 * 2;

    for(i = 1; i < 150; i++) {
      for(j = i + 1; j < 150; j++) {
	if(i == h && j == w) continue;
	temp = i * i + j * j;
	if(temp > length) {
	  if(answer > temp) {
	    answer = temp;
	    output[0] = i;
	    output[1] = j;
	  }
	} else if(temp == length) {
	  if(temp == answer) {
	    if(output[0] > i && h < i) {
	      answer = temp;
	      output[0] = i;
	      output[1] = j;
	    }
	  } else {
	    if(h < i) {
	      answer = temp;
	      output[0] = i;
	      output[1] = j;
	    }
	  }
	}
      }
    }
    printf("%d %d\n", output[0], output[1]);
  }

  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define maxn 100007
#define ll long long int
using namespace std;

char s[maxn],t[maxn];

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}

inline void writ(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) writ(x/10);
	putchar(x%10+'0');
}
inline void write(int x){writ(x);putchar('\n');}

int main()
{
	scanf("%s",s);
	scanf("%s",t);
	int l1=strlen(s),l2=strlen(t),l=l1;
	if (l1!=l2){puts("No");return 0;}
	for (int i=0;i<l;++i)
	{
		int d=1;
		for (int j=i;j<l;++j)
			if (s[j-i]!=t[j]) {d=0;break;}
		if (d)
			for (int j=0;j<i;++j)
				if (s[j+l-i]!=t[j]) {d=0;break;}
		if (d) {puts("Yes");return 0;}
	}
	puts("No");
	return 0;
}

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

#include<cstdio>
#include<cstring>
#include<string>

int main(){
  string s, s1, s2;
  int m, h;

  while(1){
    cin >> s;
    if (s=="-") break;
    cin >> m;
    for (int i=0; i<m; i++){
      cin >> h;
      s1=s.substr(0,h);
      s2=s.substr(h,s.size()-h);
      s=s2+s1;
    }
    cout << s << "\n";
  }

  return 0;
}

Measured memory_bytes: 3168
#include <math.h>
int main(){
    int i, count=0;
    int N;

    scanf("%d", &N);

    int a[N];
    
    for (i=0;i < N; i++){
        scanf("%d", &a[i]);
    }

    for (i=0;i < N; i++){
        while(a[i]%2 ==0){
            count++;
            a[i] /= 2;
        }
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/
#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long int            ll;
typedef long double              ld;
#define Faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi                 acos(-1);
#define test        int t; cin>>t; while(t--)
//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());
//cin.getline(array,size);
int main()
{
    ll b[4]={0};
    test
    {
        string a;
        cin>>a;
        if(a[0]=='A')
            b[0]++;
        if(a[0]=='W')
            b[1]++;
        if(a[0]=='T')
            b[2]++;
        if(a[0]=='R')
            b[3]++;
    }
    printf("AC x %lld\n",b[0]);
    printf("WA x %lld\n",b[1]);
    printf("TLE x %lld\n",b[2]);
    printf("RE x %lld\n",b[3]);
}


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

int main(void){
 
    int X,A,B;
    cin >> X >> A >> B;
    
    if(B-A <= 0){
        cout << "delicious" << endl;
    }
    else if(B-A <= X){
        cout << "safe" << endl;
    }
    else{
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 3572