akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head
using T = tuple<ll, ll, ll>;

vector<ll> get(vector<ll> a){
  ll n = SZ(a);
  vector<ll> res(0);
  stack<T> st;
  ll cnt = 0;
  res.pb(0);
  REP(i, n){
    ll last = a[i];
    ll csz = 1;
    while(!st.empty()){
      ll x, y, sz;
      tie(x, y, sz) = st.top();
      if(y >= last){
        break;
      }
      st.pop();
      while(y < last){
        x *= 4;
        y *= 4;
        cnt += sz;
      }
      csz += sz;
      last = x;
    }
    st.emplace(last, a[i], csz);
    res.pb(cnt);
  }
  return res;
}

int main(){

  ll n = in();
  vector<ll> a(n);
  REP(i, n){
    a[i] = in();
  }

  reverse(a.begin(), a.end());
  vector<ll> f = get(a);
  REP(i, n){
    a[i] = a[i] * 2;
  }
  reverse(a.begin(), a.end());
  vector<ll> g = get(a);

  // cout << a << endl;
  // cout << f << endl;
  // cout << g << endl;

  ll ans = INFLL;
  REP(i, n+1){
    chmin(ans, (f[i] + g[n-i]) * 2 + n-i);
  }

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


Measured memory_bytes: 11476
import numpy as np
N = int(input())
MOD = 10**9+7
dp = np.zeros(64,np.int64)
pdp = np.ones(64,np.int64)
a = 16
b = 4
pdp[0*a+2*b+1] = 0
pdp[0*a+1*b+2] = 0
pdp[2*a+0*b+1] = 0
dic = {}
dic[0] = 'A'
dic[1] = 'C'
dic[2] = 'G'
dic[3] = 'T'
for i in range(N-3):
  for j in range(64):
    x = j//16
    y = (j-x*16)//4
    z = j%4
    m = 16*y+4*z
    if y==2 and z==0:
      for h in range(4):
        if h==1:
          continue
        dp[m+h] += pdp[j]
    elif y==0 and z==2:
      for h in range(4):
        if h==1:
          continue
        dp[m+h] += pdp[j]
    elif y==0 and z==1:
      for h in range(4):
        if h==2:
          continue
        dp[m+h] += pdp[j]
    elif x==0 and y==2:
      for h in range(4):
        if h==1:
          continue
        dp[m+h] += pdp[j]
    elif x==0 and z==2:
      for h in range(4):
        if h==1:
          continue
        dp[m+h] += pdp[j]
    else:
      for h in range(4):
        dp[m+h] += pdp[j]
  dp %= MOD
  pdp = np.copy(dp)
  dp = np.zeros(64,np.int64)
print(pdp.sum()%MOD)

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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
typedef pair<string,ll> psi;
typedef pair<psi,ll> pl;

ll N, M, P, Q, R, A, B, C, X, Y, Z, arr[100005];

string s;

vector<pl> v;

bool cmp(pl AA, pl BB){
	return AA.first.first < BB.first.first || (AA.first.first == BB.first.first && AA.first.second > BB.first.second);
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; ++i){
		cin >> s >> P;
		v.push_back(pl(psi(s,P),i));
	}
	sort(v.begin(),v.end(),cmp);
	for (int i = 0; i < v.size(); ++i){
		cout << v[i].second << '\n';
	}
}

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

int main() {
  long N;
  cin >> N;
  string ans = "Three";
  char s;
  
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s == 'Y'){
      ans = "Four";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdlib>
#include <cstring>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)

using namespace std;

char s[100005];


int main(void) {

	
    scanf("%s", s);

    int zero = 0;
    int now = 0;
    REP(i, 0, (int)strlen(s)) {

    	if ( (s[i] - '0') == now ) zero++;
    	now ^= 1;
    }
    
    printf("%d\n", min(zero, (int)strlen(s) - zero));

	return 0;
}


Measured memory_bytes: 384
import Control.Applicative
import Data.List

main = do
  contents <- fmap (read :: String -> Int) . lines <$> getContents
  let primes = seive [2..999999] 999999
  mapM_ (solve primes) contents

seive :: [Int] -> Int -> [Int]
seive [] _ = []
seive all@(x:xs) n
  | x^2 > n = all
  | otherwise = x : (seive [a | a <- xs, mod a x > 0] n)

solve :: [Int] -> Int -> IO ()
solve primes n = putStrLn $ show $ length $ takeWhile (<= n) primes

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

int main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    REP(j,n){if(j!=0)cout<<" ";cout<<a[j];}cout<<endl;
    rep(i,1,n)
    {
        int now=i;
        int front=i-1;
        while(a[front]>a[now]&&front>=0)
        {
            swap(a[front],a[now]);
            now--;
            front--;
            
        }
        REP(j,n){if(j!=0)cout<<" ";cout<<a[j];}cout<<endl;
    }
}



Measured memory_bytes: 3096
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            int N = Integer.valueOf(args.get(0));
            System.out.println((N - 2) * 180);
        };
    }

}


Measured memory_bytes: 28500
import java.util.*;
class Main{
  public static void main(String[]a){
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int i=s.nextInt();
    a=new String[n];
    for(i=0;i<n;i++)a[i]=s.next();
    Arrays.sort(a);
    for(i=0;i<n;i++)System.out.print(a[i]);
  }
}

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

int main(){
	cout << setprecision(3) << setiosflags(ios::fixed);
	double a,b,c,d,e,f;
	double x,y;
	while(cin >> a >> b >> c >> d >> e >> f){

		x = (c*e-b*f)/(a*e-b*d);
		if (x == 0.000) x += 0.000;
		y = (c*d-f*a)/(b*d-a*e);
		if (y == 0.000 )y += 0.000;

		cout << x << ' ' << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  string s; cin >> s;
  int a[4];
  for ( int i = 0; i < 4; i++ ) a[i] = s[i] -'0';
  string ans;
  int sum;
  for ( int bit = 0; bit < (1<<3); bit++ ) {
    sum = a[0];
    ans = a[0]+'0';
    for ( int i = 0; i < 3; i++ ) {
      if ( bit & (1<<i) ) {
	sum += a[i+1];
	ans += '+';
	ans += a[i+1] + '0';
      } else {
	sum -= a[i+1];
	ans += '-';
	ans += a[i+1] + '0';	
      }
    }
    if ( sum == 7 ) {
      cout << ans << "=7" <<endl;
      return 0;
    }
  }
  return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

ll gcd(ll x,ll y){
  if(!(x%y))return y;
  else return gcd(y,x%y);
}

int main() {
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n)cin >> a[i];
  sort(ALL(a));
  ll g=a[0];
  for(auto x:a)g=gcd(g,x);
  cout <<(g==1?1:g);
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000009;





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

	int n;
	cin >> n;
	VI a(n);
	REP(i, n)cin >> a[i];

	sort(ALL(a));
	if (n == 2) {
		cout << "Yes" << endl;
		return 0;
	}
	if (n == 3) {
		if (a[2] == 1)cout << "Yes" << endl;
		else if (a[1] == 1)cout << "No" << endl;
		else cout << "Yes" << endl;
		return 0;
	}

	if (a[n - 1] - a[0] > 1) {
		cout << "No" << endl;
		return 0;
	}
	int c = count(ALL(a), a[0]);

	if (a[n - 1] == a[0]) {
		if (a[0] + a[0] <= n || a[0] == n - 1) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
		return 0;
	}
	if (a[n - 1] != a[n - 2]) {
		cout << "No" << endl;
		return 0;
	}

	


	if (c == a[0]) {
		cout << "Yes" << endl;
		return 0;
	}


	int d = n - c;

	if (c < a[0]+1 && (a[0]+1 - c) * 2 <= d) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	double n;
    cin>>n;
    cout<<(int)3*n*n<<endl;

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int ans = 0;
  int count = 0;
  while (count < N) {
    count += max(H, W);
    ++ans;
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long int ll;
using namespace std;

bool compare(vector <int> A, vector <int> B){
    return A[0]< B[0];
}

void printVec(vector <int> A){
    for(int i =0;i< A.size();i++){
        cout<<A[i]<<' ';
    }
    cout<<endl;
    return ;
}


int main(){
    ll n, k;
    cin>>n>>k;
    vector<int> town(n, 0);
    for(int i = 0;i< n;i++){
        cin>>town[i];
        town[i]--;
    }
    // k = k%n;
    // int getPeriod = 0;
    // getPeriod++;
    vector<int> soln;
    vector<bool> vis(n, false);
    int currPos=  0;
    while(vis[currPos] == false){
        soln.push_back(currPos);
        vis[currPos] = true;
        currPos = town[currPos];
    }
    ll repeat = currPos;
    ll first = 0;
    for(int i = 0;i< soln.size();i++){
        if(soln[i] == currPos){
            first = i;
            break;
        }
    }
    // for(int i =0;i< soln.size();i++){
    //     cout<<soln[i]<<" ";
    // }
    // cout<<endl;
    // cout<<first<<endl;
    ll period = soln.size() - first;
    // cout<<period<<endl
    if(k <= first){
        cout<<soln[k]+1<<endl;
        return 0;
    }
    // cout<<first<<endl;
    k = k- first;
    // cout<<k<<endl;
    k = k%period;
    // cout<<k<<endl;
    cout<<soln[first + k]+1<<endl; 
    return 0;
}

Measured memory_bytes: 5072
import sys
from collections import deque

n, m = map(int, sys.stdin.readline().split())

to = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    to[a].append(b)
    to[b].append(a)
INF = float("inf")

dist = [INF] * (n + 1)
dist[1] = 0
pre = [0] * (n + 1)
que = deque([])
que.append(1)

while que:
    p = que.popleft()
    for i in to[p]:
        if dist[i] > dist[p] + 1:
            dist[i] = dist[p] + 1
            pre[i] = p
            que.append(i)

print("Yes")
for i in range(2, n + 1):
    print(pre[i])

Measured memory_bytes: 34684
<?php
while(true) {
    $stdin = trim(fgets(STDIN));
    if ($stdin == 0) {
        break;
    }
    $a_pnt = 0;
    $b_pnt = 0;
    for ($i = 0;$i < $stdin;$i++) {
        $cards = trim(fgets(STDIN));
        list($a,$b) = explode(" ",$cards);
        if ($a > $b) {
            $a_pnt += $a + $b;
        } elseif ($a < $b) {
            $b_pnt += $a + $b;
        } else {
            $a_pnt += $a;
            $b_pnt += $b;
        }
    }
    echo $a_pnt." ".$b_pnt.PHP_EOL;
}
?>


Measured memory_bytes: 9256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        int n = in.intNext();
        int m = in.intNext();
        long[] heights = in.nextLongArray(n);
        int[] goodOnes = new int[n];

        for (int i = 0; i < m; i++) {
            int a = in.intNext() - 1;
            int b = in.intNext() - 1;

            if (heights[a] <= heights[b]) goodOnes[a] = -1;
            if (heights[b] <= heights[a]) goodOnes[b] = -1;
        }

        int count = 0;
        for (int num: goodOnes) if (num != -1) count++;
        out.println(count);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 56188
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

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



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;




int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<int> p;
    rep(i,n){
        int a;
        cin>>a;
        p.push(a);
    }
    rep(i,m){
        int a=p.top();p.pop();
        p.push(a/2);
    }
    ll ans=0;
    while(p.empty()==0){
        int a=p.top();p.pop();
        ans+=a;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
using namespace std;
int main () {
int k , e =0,o=0;
cin >> k;
for (int i=1; i<=k; i++){
    if (i%2 == 0){
        e++;
    }
    else {
        o++;
    }
}
cout << (e*o) <<endl;
 }



Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

int main(int argc, const char* argv[]) {
  string s;
  cin >> s;
  
  u64 ret = 0;
  u64 tmp = 0;
  for(u64 i = 0; i < s.length(); ++i) {
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      ++tmp;
    } else {
      ret = max(tmp, ret);
      tmp = 0;
    }
  }
  
  ret = max(tmp, ret);
  cout << ret;
  return 0;
}

Measured memory_bytes: 256
INF = 10 ** 20

def search(rest, now, goal, dp, edges):
  if now == goal:
    return 0
  if rest == ():
    if now == goal:
      return 0
    else:
      return INF

  if (rest, now) in dp:
    return dp[(rest, now)]

  ret = INF
  for i, t in enumerate(rest):
    for dist, to in edges[now]:
      tmp = search(tuple(v for j, v in enumerate(rest) if i != j), to, goal, dp, edges) + dist / t
      if ret > tmp:
        ret = tmp
  dp[(rest, now)] = ret
  return ret

def main():
  while True:
    n, m, p, a, b = map(int, input().split())
    if n == 0:
      break
    a -= 1
    b -= 1
    tlst = list(map(int, input().split()))
    edges = [[] for _ in range(m)]
    for _ in range(p):
      x, y, z = map(int, input().split())
      x -= 1
      y -= 1
      edges[x].append((z, y))
      edges[y].append((z, x))
    tlst.sort()
    rest = tuple(tlst)
    dp = {}
    ans = search(rest, a, b, dp, edges)
    if ans == INF:
      print("Impossible")
    else:
      print(ans)
main() 


Measured memory_bytes: 7512
n = int(input())
ans = 0
a =[]
for i in range(1,n+1):
  if i%2 == 1:
    a.append(i)
for i in a:
  cnt = 0
  for j in range(1,max(a)+1):
    if i%j == 0:
      cnt +=1
  if cnt == 8:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007

using namespace std;
typedef long long ll;

int num, m;

ll Inverse(ll a) {
	int d = MOD - 2;
	ll ans = 1;
	while (d > 0) {
		if (d & 1)
			ans = ans * a % MOD;
		a = a * a % MOD;
		d >>= 1;
	}
	return ans;
}

ll Combi(int n, int k, vector<ll> &a) {
	if (n == k || k == 0)
		return 1;
	ll ans = a[n];
	ans *= Inverse((a[k] * a[n - k]) % MOD);
	ans %= MOD;
	return ans;
}

void Ini(vector<ll> &a) {
	ll d = 1;
	for (int i = 1; i < a.size(); i++) {
		d *= i;
		d %= MOD;
		a[i] = d;
	}
	return;
}

ll Search(int s, int g, vector<ll> &k) {
	if (s > g)
		return 0;
	if (s == g)
		return 1;
	int x = (g - s) & 1, y = (g - s) >> 1;
	ll ans = 0;
	while (y >= 0) {
		ans += Combi(x + y, y, k);
		ans %= MOD;
		x += 2;
		y--;
	}
	return ans;
}

int main(void) {
	int i, a = -1, b;
	ll ans = 1;
	cin >> num >> m;
	vector<ll> k(num + 1);
	Ini(k);
	for (i = 0; i < m; i++) {
		scanf("%d", &b);
		if (a == b)
			continue;
		ans *= Search(a + 1, b - 1, k);
		ans %= MOD;
		a = b;
	}
	ans *= Search(a + 1, num, k);
	ans %= MOD;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;
int keta(llint a){
	llint d=1,ans=0;
	while(d<=a){
		ans++;
		d*=10;
	}
	return ans;
}
int main(void){
	llint N,a,b,ans=999,it=0;
	scanf("%lld",&N);
	for(a=1;a*a<=N;a++){
		if(N%a!=(llint)(0)){
			continue;
		}
		b=N/a;
		it=max(keta(a),keta(b));
		ans=min(it,ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}



int main() {
   fast();
   long long int N=100000;
   vector<long long int> prime(N+1);
   for(long long int i=0;i<=N;i++){
       prime[i]=1;
   }
   
   prime[0]=0;
   prime[1]=0;
   for(long long int i=2;i<=N;i++){
    if(prime[i]){
      for(long long int j=i*i;j<=N;j+=i){
        prime[j]=0;
      }
    }
   }
   int odd[N+1];
   for(int i=0;i<=N;i++){
    if(prime[i] && prime[(i+1)/2]){
      odd[i]=1;
    }else{
      odd[i]=0;
    }
   }
   //cout<<prime[3]<<"\n";
   for(int i=1;i<=N;i++){
    odd[i]+=odd[i-1];
   }
   int q;
   cin>>q;
   while(q--){
    int l,r;
    cin>>l>>r;
    cout<<odd[r]-odd[l-1]<<"\n";
   }

}


Measured memory_bytes: 4464
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

string s[3];

int main()
{
    cin >> s[0] >> s[1] >> s[2];
    vi v[3];
    rep(i,3){
        rep(j,s[i].size()){
            if(s[i][j] == 'a') v[i].pb(0);
            else if(s[i][j] == 'b') v[i].pb(1);
            else if(s[i][j] == 'c') v[i].pb(2);
        }
    }
    int now = 0;
    while(1){
        if(v[now].size() == 0){
            if(now == 0) cout << 'A' << endl;
            else if(now == 1) cout << 'B' << endl;
            else cout << 'C' << endl;
            return 0;
        }
        int tugi = v[now][0];
        v[now].erase(v[now].begin());
        now = tugi;
    }
}



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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        long l = Long.parseLong(st.nextToken());
        long r = Long.parseLong(st.nextToken());
        if (r - l > 2039) {
            System.out.println("0");
            return;
        }
        long res = Integer.MAX_VALUE;
        for (long i = l; i <= r; i++) {
            for (long j = l; j <= r; j++) {
                if (i != j) {
                    long x = (i * j) % 2019;
                    if (x < res) {
                        res = x;
                    }
                }
            }
        }
        System.out.println(res);
    }

}
/*

 */

Measured memory_bytes: 22484
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k;
  int a[200],b[50],n,p;
  bool c[1000000],d[1000000];
  a[0]=b[0]=0;
  p=0;
  j=1;
  for(i=1;a[i-1]<1000000;i++){
    p+=i;
    a[i]=a[i-1]+p;
    if(a[i]%2){
      b[j]=a[i];
      j++;
    }
  }
  while(cin>>n&&n){
    memset(c,0,n);
    c[0]=1;
    for(i=1;;i++){
      memset(d,0,n);
      for(j=0;j<n;j++){
	if(c[j]){
	  for(k=0;j+a[k]<n;k++)
	    d[j+a[k]]=1;
	  if(j+a[k]==n)
	    break;
	}
      }
      if(j!=n)
	break;
      memcpy(c,d,n);
    }
    cout<<i<<" ";
    memset(c,0,n);
    c[0]=1;
    for(i=1;;i++){
      memset(d,0,n);
      for(j=0;j<n;j++){
	if(c[j]){
	  for(k=0;j+b[k]<n;k++)
	    d[j+b[k]]=1;
	  if(j+b[k]==n)
	    break;
	}
      }
      if(j!=n)
	break;
      memcpy(c,d,n);
    }
    cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	ll N, M;
	cin >> N >> M;

	for (ll i = 0; i < (M + 1) / 2; ++i) {
		cout << 1 + i << " " << ((M + 1) / 2) * 2 - i << endl;
	}
	for (ll i = 0; i < M / 2; ++i) {
		cout << ((M + 1) / 2) * 2 + 1 + i << " " << ((M + 1) / 2) * 2 + 1 + (M / 2) * 2 - i << endl;
	}

	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int K = in();
    ll sum = 0;
    REPS(i,K){
        REPS(l,K){
            REPS(j,K){
                sum += gcdx(l,gcdx(i,j));
            }
        }
    }
    cout << sum << "\n";
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int a,b,k;
cin>>a>>b>>k;
  if(a<k)
  {
    if(k-a>=b)
      b=0;
    else 
      b=b-(k-a);
     
    a=0;
  }
  else 
    a=a-k;
  
  cout<<a<<" "<<b;
}

Measured memory_bytes: 256
const s_list = require('fs').readFileSync('/dev/stdin', 'utf8').split(' ');
const n_list = s_list.map(s => parseInt(s, 10));
const n = n_list[0];
const m = n_list[1];

const ans_n = n > 1 ? n * (n - 1) / 2 : 0
const ans_m = m > 1 ? m * (m - 1) / 2 : 0
const ans = ans_n + ans_m
console.log(ans)

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;
 
int main()
{
    ll a;
    double b;
    cin>>a>>b;
    ll ib=b*100+0.5;
    a*=ib;
    a/=100;
    cout<<a;
}

Measured memory_bytes: 3720
import sys
input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input())

n = aint()
a, b, c = int(n/3), int(n/5), int(n/15)
print(int(0.5*(n*(n+1)-3*a*(a+1)-5*b*(b+1)+15*c*(c+1))))

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

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
  	for(int i=0; i<N; i++) cin >> h[i];
	sort(h.rbegin(), h.rend());
  	int l=-1, r=N, ans=-1;
	while(r-l>1){
		int mid = l + (r-l)/2;
		if(h[mid] < K){
			r = mid;
		}else{
			l = mid;
			ans = mid;
		}
	}
	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
long long digits(long long n){
    long long result = 0;
    while(n > 0) {
        result++;
        n /= 10;
    }
    return result;
}
int main() {
string s;
cin >> s;
ll st = stoll(s);
ll dig = digits(st);
bool flag = true;
for (ll i = 1; i < s.size();i++){
    if (s[i] != '9') flag = false;
}
ll ans = 0;
ans = (s[0] - '0') + 9 * (dig - 1);
if (!flag) ans--;
cout << ans << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = ReadIntArray();

            IList<int[]> pairs = new List<int[]>();
            for (int i = 0; i < nm[1]; i++)
            {
                var r = ReadIntArray();
                pairs.Add(new int[]{r[0],r[1]});
            }

            for (int i = 0; i < 1000; i++)
            {
                if (i.ToString().Length < nm[0])
                {
                    continue;
                }
                if (pairs.All(item => i.ToString()[item[0] - 1].ToString() == item[1].ToString()))
                {
                    Console.WriteLine(i.ToString());
                    return;
                }
            }

            Console.WriteLine(-1);
        }
        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13396
S = input()

def dfs(a,s,n): #a:今まで計算した分、s:数字(文字)、n:左から何番目の位置に+を入れるか入れないか
    if(len(s) == 1):
        return int(s)
    elif(len(s) == n+1):
        return int(s[len(s)-1]) + int(s[:len(s)-1]) + int(s) + 2*a
    else:
        return dfs(a,s,n+1) + dfs(a+int(s[:n]),s[n:],1)

print(dfs(0,S,1))

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

long long data[9];
int main(){
	int S;
	cin >> S;
	while(S--){
		for(int i = 0; i < 9; i++){
			string str;
			cin >> str;
			data[i] = stoll(str, nullptr, 16);
		}
		int K = 0;
		int prev = 0;
		for(int i = 0; i <= 32; i++){
			int sum = prev;
			for(int j = 0; j < 8; j++){
				sum += (data[j] >> i) & 1;
			}
			if((sum & 1) == ((data[8] >> i) & 1)){
				prev = sum / 2;
			}else{
				K |= (1ll << i);
				sum = prev;
				for(int j = 0; j < 8; j++){
					sum += (~(data[j] >> i)) & 1;
				}
				
				prev = sum/2;
			}
		}
		printf("%x\n", K);
	}
}

Measured memory_bytes: 3216
t1,t2,t3=0,0,0
while 1:
    a=list(map(int,input().split()))
    a.sort()
    if a[0]+a[1]<=a[2]:break
    elif a[0]**2+a[1]**2<a[2]**2:t3+=1
    elif a[0]**2+a[1]**2==a[2]**2:t1+=1
    else:t2+=1
print(t1+t2+t3,t1,t2,t3)


Measured memory_bytes: 5600
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    cin >> N;
    ll a[N];
    ll sum = 0;
    ll s[N];
    rep(i,N){
        cin >> a[i];
        sum += a[i];
        s[i] = sum;
    }
    ll out = abs(sum-2*s[0]);
    rep(i,N-1){
        if(abs(sum-2*s[i])<out) out = abs(sum-2*s[i]);
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void WarshallFloyd(Graph& G, Matrix& d) {//O(V^3)
	d.resize(G.size());
	REP(i, d.size())d[i].resize(G.size());
	REP(i, d.size()) {
		REP(j, d[i].size()) {
			d[i][j] = INF;
		}
	}
	REP(i, G.size()) {
		REP(j, G[i].size()) {
			d[i][G[i][j].to] = G[i][j].cap;
		}
	}
	REP(i, G.size()) {
		REP(j, G.size()) {
			REP(k, G.size()) {
				chmin(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
}

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

	ll n, m, rr;
	cin >> n >> m >> rr;
	Array r(rr, 0);
	REP(i, rr) {
		cin >> r[i];
		r[i]--;
	}
	Graph g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		add_edge(g, a, b, c, true, c);
	}
	Matrix d;
	WarshallFloyd(g, d);

	ll ans = INF;

	sort(all(r));

	do {
		ll sum = 0;
		REP(i, r.size() - 1) {
			sum += d[r[i]][r[i + 1]];
		}
		chmin(ans, sum);
	} while (next_permutation(all(r)));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e18;
const int md=1e9+7;
int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n;
	string st;
	cin >> n;
	if(n<3){
		cout << -1;
		return 0;
	}
	if(n==3){
		cout << "aa.\n..a\n..a\n";
		return 0;
	}
	for(int i=0;i<n-n%4-4;i++){
		int k=i-i%4;
		for(int j=0;j<k;j++)
			cout << '.';
		if(i%4==0)cout << "aabc";
		if(i%4==1)cout << "ddbc";
		if(i%4==2)cout << "bcaa";
		if(i%4==3)cout << "bcdd";
		for(int j=k+4;j<n;j++)
			cout << '.';
		cout << "\n";
		st.push_back('.');
	}
	if(n%4==0){
		cout << st << "aabc\n";
		cout << st << "ddbc\n";
		cout << st << "bcaa\n";
		cout << st << "bcdd\n";
	}
	else if(n%4==1){
		cout << st << "aabba\n";
		cout << st << "bcc.a\n";
		cout << st << "b..cb\n";
		cout << st << "a..cb\n";
		cout << st << "abbaa\n";
	}
	else if(n%4==2){
		cout << st << "aabc..\n";
		cout << st << "ddbc..\n";
		cout << st << "..aabc\n";
		cout << st << "..ddbc\n";
		cout << st << "bc..aa\n";
		cout << st << "bc..dd\n";
	}
	else{
		cout << st << "aabbcc.\n";
		cout << st << "dd.dd.a\n";
		cout << st << "..d..da\n";
		cout << st << "..d..db\n";
		cout << st << "dd.dd.b\n";
		cout << st << "..d..dc\n";
		cout << st << "..d..dc\n";
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        ll a,v,b,w;cin>>a>>v>>b>>w;
        ll t;cin>>t;
        if(v<=w){
            cout<<"NO";
        }
        else{
            if((t*(v-w))>=(abs(a-b))){
                cout<<"YES";
            }
            else{
                cout<<"NO";
            }
        }
    }   
    timecalculater();
    return 0;   
} 

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, m; read(n, m);
	vector<vi> g(n + 1), gr(n + 1);
	vi indeg(n + 1), io;
	queue<int> q;

	rep(i, 0, m) {
		int a, b; read(a, b);
		g[a].push_back(b);
		gr[b].push_back(a);
		indeg[b]++;
	}
	rep(i, 1, n + 1) if (!indeg[i]) q.push(i), io.push_back(i);
	while (!q.empty()) {
		int n = q.front(); q.pop();
		for (int h : g[n]) {
			indeg[h]--;
			if (!indeg[h]) q.push(h), io.push_back(h);
		}
	}

	vi dist(n + 1);
	int ans = 0;
	for (int n : io) {
		for (int h : gr[n]) {
			dist[n] = max(dist[n], dist[h] + 1);
			chmax(ans, dist[n]);
		}
	}

	die(ans);
}


Measured memory_bytes: 12540
# Fast IO (be careful about bytestring)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from collections import deque

movable = 46
blocked = 35
MAXDist = 1 << 31

def isMovable(p,q):
    if p < 0 or q < 0 or p >= H or q >= W:
        return False
    if maze[p][q] == blocked:
        return False
    return True

H,W = map(int,input().split())
sH,sW = map(int,input().split())
eH,eW = map(int,input().split())

maze = []
distance = []
for _ in range(H):
    maze.append(input())
    distance.append([MAXDist] * W)

distance[sH - 1][sW - 1] = 0
deq = deque()
deq.append((sH - 1, sW - 1, 0))

while len(deq):
    h,w,dist = deq.popleft()
    if dist > distance[h][w]:
        continue
    # no spell movement
    if isMovable(h - 1,w) and distance[h-1][w] > dist:
        distance[h-1][w] = dist
        deq.appendleft((h-1,w,dist))
    if isMovable(h + 1,w) and distance[h+1][w] > dist:
        distance[h + 1][w] = dist
        deq.appendleft((h + 1,w,dist))
    if isMovable(h,w - 1) and distance[h][w - 1] > dist:
        distance[h][w - 1] = dist
        deq.appendleft((h,w - 1,dist))
    if isMovable(h,w + 1) and distance[h][w + 1] > dist:
        distance[h][w + 1] = dist
        deq.appendleft((h,w + 1,dist))

    # spell movement
    for i in range(h - 2,h + 3):
        for j in range(w - 2, w + 3):
            if isMovable(i,j) and distance[i][j] > dist + 1:
                distance[i][j] = dist + 1
                deq.append((i,j,dist + 1))

print(distance[eH - 1][eW - 1] if distance[eH - 1][eW - 1] != MAXDist else -1)


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

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

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    int res1=0, res4=0;
    rep(i, N){
        ll a; cin >> a;
        if(a%2) res1++;
        if(a%4 == 0) res4++;
    }
    if(res4 == 0 && res1 > 0) cout << "No" << endl;
    else if(res1+res4==N && res1 <= res4+1) cout << "Yes" << endl;
    else if(res1 > res4) cout << "No" << endl;
    else cout << "Yes" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
using namespace std;

long long int lunlunBFS(int count){
  if(count < 10){
    return count;
  }
  
  queue<std::vector<int>> q;
  for(int i=1; i<=9; i++){
    std::vector<int> tmp;
    tmp.push_back(i);
    q.push(tmp);
  }
  std::vector<int> vec;
  while(count!=0){
    vec = q.front();
    q.pop();
    count--;
    
    auto newVec = vec;
    if(vec.back()-1 >=0){
      newVec.push_back(vec.back()-1);
      q.push(newVec);
    }
      newVec = vec;
      newVec.push_back(vec.back());
      q.push(newVec);
    if(vec.back()+1 <=9){
      newVec = vec;
      newVec.push_back(vec.back()+1);
      q.push(newVec);
    }
  }
  long long int lunNum = 0;
  for(int i=0;i<vec.size();i++){
    lunNum += vec[vec.size() - 1 - i] * std::pow(10,i);
    //cout << vec[i] << endl;
  }
  return lunNum;
}

int main(){
  int K;
  cin >> K;
  
  int numSize = 1;
  
  vector<int> vec(64);
  for(int i=0; i<64; i++){
    vec[i] = -1;
  }
  vec[0] = 1;
  
  long long int lunNum = lunlunBFS(K);
    
  cout << lunNum << endl;
}


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

int main(){
  int N,i,ans=0;
  int x[20];
  cin >> N;
  
  for(i=0; i<N; i++){
    cin >> x[i];
  }
  
  for(i=1; i<(N-1); i++){
    if(x[i-1] > x[i] && x[i] > x[i+1]){ 
      ans+=1;
    }else if(x[i-1] < x[i] && x[i] < x[i+1]){
      ans+=1;
    }
  }
  
  cout << ans << endl;
}
    
    

Measured memory_bytes: 256