akhauriyash/Code-Regression huggingface dataset:
N,X=map(int,input().split())
P=[1]
A=[1]
for i in range(N):
  P.append(1+2*P[i])
  A.append(3+2*A[i])
def f(n,x):
  if n==0:
    return 1
  else:
    if x==1:
      return 0
    if 1<x<2+A[n-1]:
      return f(n-1,x-1)
    if x==2+A[n-1]:
      return 1+P[n-1]
    if 2+A[n-1]<x<3+2*A[n-1]:
      return 1+P[n-1]+f(n-1,x-(2+A[n-1]))
    if x==3+2*A[n-1]:
      return 1+2*P[n-1]
print(f(N,X))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long arr[100005];
vector<long long>v,rs;
main()
{
	int m,n;
    long long re;
    scanf("%d%d",&m,&n);
    for(int i = 0;i < m;i++)
    {
        scanf("%lld",&re);
        rs.push_back(re);
    }
    long long sm=0;
    for(int i = 0;i < n;i++)
    {
        scanf("%lld",&re);
        v.push_back(re);
        if(i>0)
        arr[i]=v[i]-v[i-1];
        arr[i]*=(n-i);
        arr[i]%=1000000007;
        arr[i]*=(i);
        arr[i]%=1000000007;
        sm+=arr[i];
        sm%=1000000007;
    }
    // printf("-->%lld\n",sm);
    long long cal=0;
    for(int i = 1;i < m;i++)
    {
        long long pls=sm*i;
        // printf("%d\n",sm*(n-i)*i);
        pls%=1000000007;
        pls*=(m-i);
        pls%=1000000007;
        pls*=(rs[i]-rs[i-1]);
        pls%=1000000007;
        cal+=pls;
        cal%=1000000007;
    }
    printf("%lld",cal);
}


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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 ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int euclid(int a, int b){
   int ta = max(a, b);
   int tb = min(a, b);
   int t = INF;
   while(t != 0){
     t = ta % tb;
     ta = tb;
     if(t != 0) tb = t;
   }
   return tb;
}

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

  int n, x;
  cin >> n >> x;

  vector<int> a(n + 1);
  REP(i,n) cin >> a[i];
  a[n] = x;

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

  vec b(n);
  REP(i, n) {
    b[i] = a[i + 1] - a[i];
  }

  int ans = b[0];
  REP(i, b.size() - 1){
    ans = euclid(ans, b[i + 1]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int 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>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	ll ans = 0;
	REP(i, n)
	{
		int a; cin >> a;
		int cnt = 0;
		while (a % 2 == 0)
		{
			a /= 2;
			cnt++;
		}
		ans += cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long shoki, hiku;
   cin >> shoki >> hiku;
   
   long kekkaichi;
   kekkaichi = shoki % hiku;
   
   long kekkani;
   kekkani = kekkaichi - hiku;
   kekkani = abs(kekkani);
 
   if(shoki <= kekkaichi && shoki <= kekkani){
   cout <<shoki << endl;
   }
   else if (kekkaichi <= shoki && kekkaichi <= kekkani){
   cout << kekkaichi << endl;
   }
   else{
   cout << kekkani << endl;} 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
int main()
{ 
    cool;
    int n,k;
    cin>>n>>k;
    int a[n+1]={0};
    while(k--){
    	int d;
    	cin>>d;
    	while(d--){
    		int x;
    		cin>>x;
    		a[x]++;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			cnt++;
		}
	}
	cout<<cnt;
    return 0;
}


Measured memory_bytes: 3652
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n, q;
    cin >> n >> q;
    string str;
    cin >> str;
    vi s(n+1,0);
    rep(i,n-1)
    {
        if(str[i]=='A'&&str[i+1]=='C')
        {
            s[i+1]=s[i]+1;
        }
        else
        {
            s[i+1]=s[i];
        }
    }

    rep(i,q)
    {
        int l,r;
        cin >> l >> r;
        cout << s[r-1] - s[l-1] << endl;
    }
}


Measured memory_bytes: 1872
# coding: utf-8


def solve(*args: str) -> str:
    n, m, q = map(int, args[0].split())
    ABCD = [tuple(map(int, abcd.split())) for abcd in args[1:]]

    ret = 0
    stack = [(i, '') for i in range(10)]
    while stack:
        t, s = stack.pop()
        S = s+str(t)
        if len(S) == n:
            ret = max(
                ret,
                sum([d for a, b, c, d in ABCD if int(S[b-1])-int(S[a-1]) == c])
            )
            continue

        for i in range(t, m):
            stack.append((i, S))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9268
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    long long int N,M,ans=0;
    cin >> N >> M;
    if(N>=2&&M>=2)    ans+=(M-2)*2+N*2;
    if(N==1&&M==1)  ans=0;
    else if(N==1||M==1)  ans=2;
    cout << N*M-ans << endl;
}

Measured memory_bytes: 256
H, W, K = [int(_) for _ in input().split()]

c = [input() for _ in range(H)]

ans = 0
for h in range(1 << H):
    for w in range(1 << W):
        k = 0
        for i in [i for i in range(H) if not h & (1 << i)]:
            for j in [j for j in range(W) if not w & (1 << j)]:
                if c[i][j] == "#":
                    k += 1
        if k == K:
            ans += 1
print(ans)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

string b[32];
int H, W, n;

bool can_clear(int h, int w) {
  int cnt_h = 1;
  int hi = h+1;
  while (hi < H && b[hi][w] == b[h][w]) hi++, cnt_h++;
  hi = h-1;
  while (0 <= hi && b[hi][w] == b[h][w]) hi--, cnt_h++;

  int cnt_w = 1;
  int wi = w+1;
  while (wi < W && b[h][wi] == b[h][w]) wi++, cnt_w++;
  wi = w-1;
  while (0 <= wi && b[h][wi] == b[h][w]) wi--, cnt_w++;

  return max(cnt_h, cnt_w) >= n;
}

void drop() {
  for (int i = H-2; i >= 0; i--) {
    for (int j = W-1; j >= 0; j--) {
      if (b[i][j] != '.') {
	int ni = i+1;
	while (ni < H && b[ni][j] == '.') ni++;
	ni--;
	swap(b[ni][j], b[i][j]);
      }
    }
  }
}

bool can_all_clear() {
  drop();  
  bool do_clear[32][32];
  bool flag = true;
  while (flag) {
    flag = false;
    REP(i, H) REP(j, W)
      do_clear[i][j] = b[i][j] != '.' && can_clear(i, j);
    REP(i, H) REP(j, W) {
      if (do_clear[i][j]) {
	b[i][j] = '.';
	flag = true;
      }
    }
    drop();
  }
  REP(i, H) REP(j, W) {
    if (b[i][j] != '.') return false;
  }
  return true;
}

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

  cin >> H >> W >> n;
  string board[32];
  REP(i, H) cin >> board[i];
  REP(i, H) REP(j, W-1) {
    REP(l, H) b[l] = board[l];
    swap(b[i][j], b[i][j+1]);
    if (can_all_clear()) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

void solve()
{
	int a;
	cin>>a;
	int ans = a + a*a + a*a*a;
	cout << ans << "\n";
}

int main()
{
	fastIO;
	int t=1;
	// cin>>t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const ll MAXN = 1e5 + 5;
const ll MAXD = 1e4 + 5;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-4;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}



int main(){

        ios::sync_with_stdio(0);
        cin.tie(0);
        

        int a[6];
        for(int i = 1 ; i <= 5 ; i++)
        {
             cin >> a[i];
             if(a[i] == 0)
             {
                cout << i ;
                return 0;
             }
        }
   
   
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


int main() {
  int H,W,D;
  cin>>H>>W>>D; 
  vector<vector<int>>a(H,vector<int>(W));
  rep(i,H){
    rep(j,W){
      cin>>a.at(i).at(j);
      a.at(i).at(j)--;
    }
  }
  int Q;
  cin>>Q;
  vector<int> l(Q),r(Q);
  rep(i,Q){
    cin>>l.at(i)>>r.at(i);
    l.at(i)--;
    r.at(i)--;
  }
  
  vector<vector<int>> dist(H*W, vector<int>(2));
  rep(i,H){  
    rep(j,W){
    dist.at(a.at(i).at(j)).at(0)=i;
    dist.at(a.at(i).at(j)).at(1)=j;
    }
  }

  vector<vector<int>>data(D,vector<int>(H*W/D+1));
  rep(i,D){
    for(int j=1;j<=(H*W-1)/D;j++){
      if(j*D+i>=H*W){
        data.at(i).at(j)=0;
      }
      else{
      data.at(i).at(j)=data.at(i).at(j-1)+abs(dist.at(i+j*D).at(0)-dist.at(i+(j-1)*D).at(0));
      data.at(i).at(j)+=abs(dist.at(i+j*D).at(1)-dist.at(i+(j-1)*D).at(1));
      }
    }
  }
  rep(i,Q){
    cout << data.at(l.at(i)%D).at(r.at(i)/D)-data.at(l.at(i)%D).at(l.at(i)/D)<< endl;
  }
}

Measured memory_bytes: 11392
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
    int N,A,B;
    cin >>N;
    if(N==1){
      cout <<"Hello World";
    }else{
      cin >> A >> B;
      cout << A+B;
    }
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

const long double eps = 1e-10;

ll lgput(ll a, ll b) {
    ll ret = 1;

    while(b) {
        if(b&1) ret *= a;
        b >>= 1;
        a *= a;
    }

    return ret;
}

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

    int maxx = -1e9;
    int minn = 1e9;

    int n;
    cin >> n;

    vector< ll > v(n + 10);

    for(int i = 1; i <= n; ++i) {
        cin >> v[i];
        v[i] -= i;
    }

    sort(v.begin() + 1, v.begin() + n + 1);

    ll add = -v[(n + 1)/2];

    ll total = 0;
    for(int i = 1; i <= n; ++i) {
        v[i] += add;
        total += abs(v[i]);
    }

    cout << total;
}


Measured memory_bytes: 1792
#! -*- coding:utf-8 -*-

n = int(input())

n = str(n)
n = list(n)

flag = 0
for i in range(len(n)//2):
    if n[i] == n[-(i+1)]:
        pass
    else:
        flag = 1

if flag == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin>>n;
    int p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int q[n];
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    int r[n];
    for(int i=0;i<n;i++){
        r[i]=i+1;
    }
    int cnt=0;
    int a,b;
    do{
        cnt++;
        bool flag=true;
        for(int i=0;i<n;i++){
            if(r[i]!=p[i]){
                flag=false;
            }
        }
        if(flag)a=cnt;
        flag=true;
        for(int i=0;i<n;i++){
            if(r[i]!=q[i]){
                flag=false;
            }
        }
        if(flag)b=cnt;
    }while(next_permutation(r,r+n));
    cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    string s,t; cin >> s >> t;
    ll n = sz(s), mm = sz(t);
    set<char> S, T;
    rep(i, 0, n){
        S.insert(s[i]);
    }
    rep(i, 0, mm){
        T.insert(t[i]);
    }
    bool b = true;
    for(auto x: T){
        if(S.find(x) == S.end()){
            b = false;
        }
    }
    if(!b){
        prtl(-1);
    }else{
        map<char, vll> m;
        rep(i, 0, n){
            if(m.find(s[i]) == m.end()){
                vll h(0);
                h.emplace_back(i);
                m[s[i]] = h;
            }else{
                m[s[i]].emplace_back(i);
            }
        }
        ll p = -1;
        ll c = 0;
        rep(i, 0, mm){
            char k = t[i];
            if(upper_bound(m[k].begin(), m[k].end(), p) == m[k].end()){
                p = m[k][0];
                c++;
            }else{
                p = *upper_bound(m[k].begin(), m[k].end(), p);
            }
        }
        prtl(n*c+p+1);
    }   
}



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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define fst first
#define scd second

using vi=vector<int>;

vi tr[2020];
int d[2020];

int main()
{
    int N, K; cin >> N >> K;

    vector<pair<int, int>> edges;

    rep(i, N - 1) {
        int a, b; cin >> a >> b;
        --a, --b;
        tr[a].push_back(b);
        tr[b].push_back(a);
        edges.push_back(make_pair(a, b));
    }

    if (K & 1) {
        int mi = 1e9;

        rep(i, N - 1) {
            auto edge = edges[i];

            queue<int> q;
            fill_n(d, N, N+5);
            q.push(edge.fst);
            q.push(edge.scd);
            d[edge.fst] = d[edge.scd] = 0;

            while (q.size()) {
                int v = q.front(); q.pop();

                for (int u : tr[v]) {
                    if (d[u] > d[v] + 1) {
                        d[u] = d[v] + 1;
                        q.push(u);
                    }
                }
            }

            int cnt = 0;
            rep(i, N) {
                if (d[i] > K / 2) cnt++;
            }

            mi = min(mi, cnt);
        }

        cout << mi << endl;
    } else {
        int mi = 1e9;

        rep(i, N) {
            queue<int> q;
            q.push(i);
            fill_n(d, N, N+5);
            d[i] = 0;

            while (q.size()) {
                int v = q.front(); q.pop();

                for (int u : tr[v]) {
                    if (d[u] > d[v] + 1) {
                        d[u] = d[v] + 1;
                        q.push(u);
                    }
                }
            }

            int cnt = 0;
            rep(i, N) {
                if (d[i] > K / 2) cnt++;
            }

            mi = min(mi, cnt);
        }

        cout << mi << endl;
    }
}


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

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> x(N);
	for (Int i = 0; i < N; i++) {
		cin >> x[i];
	}

	vector<Int> temp(N);
	temp = x;
	sort(temp.begin(), temp.end());

	Int temp_M = temp[N / 2];

	/*for (Int i = 0; i < N; i++) {
		if (x[i] >= temp_M) {
			cout << temp[N / 2 - 1] << endl;
		}
		else {
			cout << temp_M << endl;
		}
	}*/


	for (Int i = 0; i < N; i++) {
		if (x[i] >= temp_M) {
			//cout << temp[N / 2 - 1] << endl;
			printf("%lld\n", temp[N / 2 - 1]);
		}
		else {
			//cout << temp_M << endl;
			printf("%lld\n", temp_M);
		}
	}

}

Measured memory_bytes: 5376
n, m, x = map(int, input().split())

c = []
a = []


def inc(l):
    if l[-1] == 0:
        l[-1] = 1
        return l
    else:
        l[-1] = 0
        return inc(l[:-1]) + [0]


def buy(a, l):
    sum_ = 0
    exps = [0] * m

    for i in range(n):
        if l[i] == 0:
            continue
        else:
            for j in range(m):
                exps[j] += a[i][j]
            sum_ += c[i]

    good = True

    for i in range(m):
        if exps[i] < x:
            good = False
            break

    return sum_, good


for i in range(n):
    line = list(map(int, input().split()))
    c.append(line[0])
    a.append(line[1:])

min_ = 99999999999999

selected = [0] * n

for i in range(2**n):
    try:
        sum_, good = buy(a, selected)

        if good and sum_ < min_:
            min_ = sum_

        selected = inc(selected)

    except:
        if min_ == 99999999999999:
            print(-1)
        else:
            print(min_)




Measured memory_bytes: 69984
#include<iostream>
using namespace std;
int main()
{
    char s[5],a,b,c,d;
    cin>>s;
    if(s[0]=='+'){
        a=1;
    }
    else{
        a=-1;
    }
    if(s[1]=='+'){
        b=1;
    }
    else{
        b=-1;
    }
    if(s[2]=='+'){
        c=1;
    }
    else{
        c=-1;
    }
    if(s[3]=='+'){
        d=1;
    }
    else{
        d=-1;
    }
    cout<<a+b+c+d<<endl;
    return 0;

}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long a, b, c, d, x;
    cin >> n >> a >> b >> c >> d;
    x = abs(a-b);
    n--;
    if(x > n*d){
        cout << "NO" << endl;
        return 0;
    }
    long long m = (x+n*d) / (c+d);
    if(x <= m*d - (n-m)*c){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    if (max(a)-min(a) >= 2):
        print("No")
    else:
        count = [0,0]
        t = min(a)
        for num in a:
            if num == t:
                count[0] += 1
            else:
                count[1] += 1
        if (count[0]*count[1] == 0):
            if (2*a[0] <= N or a[0] == N-1):
                print("Yes")
            else:
                print("No")
        else:
            if (count[0] < t+1 and 2*(t+1-count[0]) <= count[1]):
                print("Yes")
            else:
                print("No")

if __name__ == "__main__":
    main()


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

#define endl '\n'



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

    int n, y;
    cin >> n >> y;
    y /= 1000;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            if(i + j > n)
                break;
            int k = n - (i + j);
            if(i * 10 + 5 * j + k == y) {
                cout << i << " " << j << " " << k;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1";

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

# Aに0が含まれていたら、積も0とする
# Aに0が含まれていなければ、順に積を取り、10^18を超えたら終了する
ans = 0
if 0 not in A:
  ans = 1
  for a in A:
    ans *= a
    if ans > 10**18:
      ans = '-1'
      break

print(ans)

Measured memory_bytes: 21524
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.ArrayDeque;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();
        String T = sc.next();
        int l = T.length();
        if(S.equals(T.substring(0, l-1))){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35700
#include <atcoder/dsu>
#include <iostream>
using namespace std;
using namespace atcoder;
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, Q;
    cin >> N >> Q;
    dsu U(N);
    for(int i = 0; i < Q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0) U.merge(u, v);
        else{
            cout << (int)U.same(u, v) << endl;
        }
    }
}


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

int main()
{
 map<string,int> mp;
  int n;
  int max=0;
  cin>>n;
  string str[n];
  for(int i=0;i<n;i++)
    cin>>str[i];
  for(int i=0;i<n;i++)
    mp[str[i]]++;
  for(auto it=mp.begin();it!=mp.end();it++)
  {
    if(it->second > max)
      max=it->second;
  }
  for(auto i=mp.begin();i!=mp.end();i++)
  {
    if(i->second >=max)
       cout<<i->first<<endl;
  }
  return 0;
}
    
    
    
    

Measured memory_bytes: 26752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner in = new Scanner(System.in);

		int time = in.nextInt();
		int hours;
		int minuts;
		int second;

		hours = time/3600;
		minuts = (time%3600)/60;
		second = time%60;

		System.out.println(hours + ":" + minuts + ":" + second);






	}

}



Measured memory_bytes: 26208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	ll N;cin>>N;
  vi z(5);
  rep(i,5)cin>>z[i];

  ll neck = distance(z.begin(), min_element(all(z)));

  //DEBUG(neck);

  ll ans = 0;
  ans += 4;
  ans += (N+z[neck]-1)/z[neck];

  cout<<ans<<endl;
}

Measured memory_bytes: 3580
n,m = map(int,input().split())
graph = [[float("inf")]*(n+1) for _ in range(n+1)]
for i in range(m):
  a,b,c = map(int,input().split())
  graph[a][b] = c
  graph[b][a] = c

    

def dijkstra(s,cost):
  d = [float("inf")]*(n+1)
  used = [False]*(n+1)
  d[s] = 0
  
  while True:
    v = -1
    for i in range(1,n+1):
      if (not used[i]) and (v == -1):
        v = i
      elif (not used[i]) and d[i] < d[v]:
        v = i
    if v == -1:
      break
    used[v] = True
               
    for j in range(1,n+1):
      d[j] = min(d[j],d[v]+cost[v][j])
  return d

ans = 0
for i in range(1,n):
  d = dijkstra(i,graph)
  for j in range(i+1,n+1):
    if i == j:
      continue
    if graph[i][j] != float("inf") and graph[i][j] > d[j]:
      ans += 1
print(ans)

Measured memory_bytes: 3188
# C - Typical Stairs
N,M = map(int,input().split())
A = [int(input()) for _ in range(M)]
A = set(A)

# dp[i]: i 段目まで来た時の移動方法の総数
dp = [0]*(N+1)

# 初期条件
dp[0] = 1

for v in range(1,N+1):
    if v in A:
        continue
    dp[v] = (dp[v] + dp[v-1])%(1000000007)
    if v > 1:
        dp[v] = (dp[v] + dp[v-2])%(1000000007)
print(dp[N])

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

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;

int main(){
	int N;
	cin >> N;
	int a,b;
	vector<vector<int> > lst(N);
	vector<int> deg(N,0);
	rep(i,N-1){
		scanf("%d %d",&a,&b);
		lst[a].push_back(b);
		lst[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}
	vector<int> stack;
	vector<int> oya(N);
	vector<int> kazu(N,0);
	vector<int> flag(N,0);
	vector<int> group(N,-1);
	int p,i,f,d;
	rep(i,N){
		if(deg[i]==1){
			stack.push_back(i);
			oya[i]=i;
			flag[i]=1;
			break;
		}
	}
	f=-1;
	d=0;
	while(stack.empty()==false){
		p = stack.back();
		stack.pop_back();
		if(f>=1)f=-2;
		for(auto itr=lst[p].begin();itr!=lst[p].end();itr++){
			i = *itr;
			if(flag[i]==0){
				flag[i]=1;
				if(f>=0){
					group[i]=f;
					f++;
				}
				if(deg[i]==1){
					kazu[oya[p]]++;
				}
				else if(deg[i]==2){
					stack.push_back(i);
					oya[i]=oya[p];
					if(f==-2) group[i]=group[p];
				}
				else{
					if(f==-1){
						f=0;
						stack.push_back(i);
						oya[i]=i;
						d=deg[i]-1;
					}
					else{
						stack.push_back(i);
						oya[i]=i;
						if(f==-2) group[i]=group[p];
					}
				}
			}
		}
	}
	int sum=1;
	if(d>=2){
		vector<int> gflag(d,0);
		rep(i,N){
			if(kazu[i]>1){
				sum+=kazu[i]-1;
				if(group[i]>=0)gflag[group[i]]=1;
			}
		}
		int tmp=0;
		rep(i,d){
			tmp+=gflag[i];
		}
		if(tmp==d) sum--;
	}
	cout << sum << endl;
}


Measured memory_bytes: 8440
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[20];
int op[20];
char s[20];
int len;
ll js(int l,int r){
	ll t=0;
	for(int i=l;i<=r;i++){
		t=t*10+a[i];
	}
	return t;
}
ll cl(){
	int l=1,r=1;
	ll ans=0;
	for(int i=1;i<len;i++){
		if(op[i])ans+=js(l,r),l=r=i+1;
		else r++;
	}
	ans+=js(l,r);
	return ans;
}
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	scanf("%s",s+1);
	len=strlen(s+1);
	for(int i=1;i<=len;i++)a[i]=s[i]-'0';
	ll ans=0;
	int mx=(1<<(len-1));
	for(int i=0;i<mx;i++){
		for(int j=0;j<len-1;j++){
			if((i>>j)&1)op[j+1]=1;
			else op[j+1]=0;
		}
		//for(int j=1;j<=len-1;j++)cout<<op[j]<<" ";
		//puts("");
		ans+=cl();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
  char s[11] = {};
  cin >> s;
  int ptr = 0;
  bool c = false;
  int len = 0, m = 0;
  for (int ptr = 0; ptr < 10; ptr++) {
    if (s[ptr] == 'A' || s[ptr] == 'T' ||s[ptr] == 'G' ||s[ptr] == 'C') {
      len++;
    } else {
      if (len > m) m = len;
      len = 0;
    }
  }
      if (len > m) m = len;
      len = 0;
  cout << m << endl;
    
 
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <string>
using namespace std;
int judge(char,char);
int main(){
    vector<int> abc(3);
    for(int i = 0;i < 3;i ++){
        cin >> abc.at(i);
    } 
    int K;
    cin >> K;
    sort(abc.begin(),abc.end());
    for(int i = 0;i < K;i ++){
        abc.at(2) *= 2;
    }
    cout << abc.at(0) + abc.at(1) + abc.at(2) << endl;
}

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

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

ll ans = {};

void solve(){
  // main algorithm
  for (ll i = 1; i*i <= N; ++i)
  {
    ans = i * i;
  }
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N;
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,X[100],t[100];
int dp[100][4];

int main()
{
	while(cin>>n,n){
		rep(i,n)cin>>X[i+1]>>t[i+1];
		
		rep(i,n+1)rep(k,4)dp[i][k]=1e9;
		dp[0][0]=0;
		
		rep(i,n)rep(k,4){
			if(k<3&&abs(X[i+1]-X[i])*(k+1)<=t[i+1]-t[i])
			dp[i+1][k+1]=min(dp[i+1][k+1],dp[i][k]+abs(X[i+1]-X[i]));
			if(X[i]*(k+1)+X[i+1]<=t[i+1]-t[i])
			dp[i+1][1]=min(dp[i+1][1],dp[i][k]+X[i]+X[i+1]);
		}
		int ans=1e9,mx;
		rep(k,4)ans=min(ans,dp[n][k]+X[n]);
		if(ans>=1e9){
			rep(i,n)rep(k,4)if(dp[i][k]<1e9)mx=i;
			cout<<"NG "<<mx+1<<endl;
			continue;
		}
		cout<<"OK "<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

const int Nmax = 2e5 + 10;
const int Mod = 1e9 + 7;
const int oo = 1e9;

int n, m, cost[Nmax];
bitset <Nmax> viz;

int main()
{
/**
    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");

    #endif // ONLINE_JUDGE
*/

    cin >> n >> m;

    for(int i = 1; i <= n; i++)
        cin >> cost[i];


    int x, y;
    for(int i = 1; i <= m; i++)
    {
        cin >> x >> y;
        if(cost[x] > cost[y]) viz[y] = 1;
        else if(cost[y] > cost[x]) viz[x] = 1;
        else if(cost[x] == cost[y]) viz[x] = viz[y] = 1;
    }

    cout << n - viz.count();
    return 0;
}


Measured memory_bytes: 4032
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define mod 1000000007

const int N = 200010;
ll fact[N], invf[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
	if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
	if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

int main() {
	int n;
	cin >> n;
	VI a(n+1);
	REP(i,n+1){
		scanf("%d", &a[i]);
		a[i]--;
	}

	int db;
	VI ex(n+1);
	REP(i,n+1){
		ex[a[i]]++;
		if (ex[a[i]] == 2){
			db = a[i];
		}
	}

	int fi = -1, sc;
	REP(i,n+1){
		if (a[i] == db){
			if (fi == -1) fi = i;
			else sc = i;
		}
	}

	fact[0] = invf[0] = 1;
	FOR(i,1,N-1){
		fact[i] = (fact[i-1] * i) % mod;
		invf[i] = divll(invf[i-1], i);
	}

	VL ans(n+1);
	for (ll i = 1; i <= n+1; i++){
		ans[i-1] = (nCr(n+1, i) - nCr(fi+n-sc, i-1) + mod) % mod;
	}

	REP(i,n+1){
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 5888
#include <iostream>
#include <string>


using namespace std;



int main(void) {

	string a, b, c;
	int x, y;

	cin >> a;
	cin >> b;
	cin >> x;
	cin >> y;
	cin >> c;

	if (c == a) {
		x--;
	}
	if (c == b) {
		y--;
	}
	cout << x <<" "<<y<<endl;
	return 0;

}

Measured memory_bytes: 256
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntArray1Dr :: Int -> IO (UArray Int Int)
getAsIntArray1Dr n = U.listArray (1,n) <$> getAsInt

main :: IO ()
main = main1

main1 :: IO ()
main1 = do
  n <- readLn :: IO Int
  hs <- getAsIntArray1Dr n
  let solve = solve2
  print $ solve hs n U.! n

-- 貰うDP
solve1 :: UArray Int Int -> Int -> UArray Int Int
solve1 hs n = runSTUArray $ do
  dp <- newArray (1,n) 0
  forM_ [2..n] $ \x ->
    if x == 2
    then writeArray dp 2 . abs $ (hs U.! 2) - (hs U.! 1)
    else do
      a <- liftM2 (+) (readArray dp (x-1)) (return . abs $ hs U.! x - hs U.! (x-1))
      b <- liftM2 (+) (readArray dp (x-2)) (return . abs $ hs U.! x - hs U.! (x-2))
      writeArray dp x $ min a b
  return dp

-- 配るDP
solve2 :: UArray Int Int -> Int -> UArray Int Int
solve2 hs n = runSTUArray $ do
  dp <- newArray (1,n) maxBound
  writeArray dp 1 0
  forM_ [1..(n-1)] $ \x ->
    if x == n-1
    then do
      a <- liftM2 (+) (readArray dp x) (return . abs $ hs U.! x - hs U.! (x+1))
      readArray dp n >>= writeArray dp n . min a
    else do
      a <- liftM2 (+) (readArray dp x) (return . abs $ hs U.! x - hs U.! (x+1))
      b <- liftM2 (+) (readArray dp x) (return . abs $ hs U.! x - hs U.! (x+2))
      readArray dp (x+1) >>= writeArray dp (x+1) . min a
      readArray dp (x+2) >>= writeArray dp (x+2) . min b
  return dp


Measured memory_bytes: 3580
#include<stdio.h>
int main(){
  char b[2];
  scanf("%s",b);
  if(b[0]=='A')
     printf("T");
  if(b[0]=='T')
     printf("A");
  if(b[0]=='C')
     printf("G");
  if(b[0]=='G')
     printf("C");
  return 0; 
}

Measured memory_bytes: 128
from collections import deque
deq = deque(input())
rev = False
for _ in range(int(input())):
    query = input().split()
    if query[0] == '1':
        rev = not rev
    else:
        if (query[1] == '1') ^ rev:
            deq.appendleft(query[2])
        else:
            deq.append(query[2])
if rev:
    deq.reverse()
print(''.join(deq))

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

int dp[100001];
vector<int> G[100001];

int solve(int s){
	if(dp[s] != -1) return dp[s];
	dp[s] = 0;
	for(int i=0; i<G[s].size(); i++){
		if(dp[s] < solve(G[s][i]) + 1) dp[s] = solve(G[s][i]) + 1;
	}
	return dp[s];
}

int main(){
	int N, M; cin >> N >> M;
	for(int i=0; i<M; i++){
		int x, y; cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
	}
	for(int i=0; i<N; i++) dp[i] = -1;
	int ans = 0;
	for(int i=0; i<N; i++){
		if(solve(i) > ans) ans = solve(i);
	}
	cout << ans << "\n";
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int d[N];
  // read
  for (int i=0; i < N; ++i) cin >> d[i];
  // sort
  sort(d, d + N, greater<int>());
  int ret = 0, cnt = 1;
  for (int i=0; i < N; ++i) {
//    cout << "d[i]:" << d[i] << " ret:" << ret << " cnt:" << cnt << endl;
    if (ret > d[i]) ++cnt;
    ret = d[i];
  }
    cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    class SegmentTree:
        def __init__(self, size, default, op = min):
            self.size = 2**size.bit_length()
            self.dat = [default]*(self.size*2)
            self.op = op

        def update(self, i, x):
            i += self.size
            self.dat[i] = x
            while i > 0:
                i >>= 1
                self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])

        def add(self, i, x):
            i += self.size
            self.dat[i] = self.op(self.dat[i], x)
            while i > 0:
                i >>= 1
                self.dat[i] = self.op(self.dat[i], x)

        def get(self, a, b = None):
            if b is None:
                b = a + 1
            l, r = a + self.size, b + self.size
            res = None
            while l < r:
                if l & 1:
                    if res is None:
                        res = self.dat[l]
                    else:
                        res = self.op(res, self.dat[l])
                    l += 1

                if r & 1:
                    r -= 1
                    if res is None:
                        res = self.dat[r]
                    else:
                        res = self.op(res, self.dat[r])
                l >>= 1
                r >>= 1
            return res
    n,m = LI()
    v = LIR(m)
    v.sort()
    d = SegmentTree(n,float("inf"))
    d.update(0,0)
    for l,r,c in v:
        l -= 1
        r -= 1
        m = d.get(l,r+1)
        nd = min(d.get(r),m+c)
        d.update(r,nd)
    ans = d.get(n-1)
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n, k;
int d[101][10001];

inline void modAdd(int &x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

int main() {
    cin >> n >> k;
    d[n][0] = 1;
    for (int i = n; i > 0; --i) {
        forn(j, n * k + 1) if (d[i][j]) {
            modAdd(d[i - 1][j], (LL)d[i][j] * max(0, k - i) % MOD);
            forn(p, min(k, i) + 1) {
                int cnt = (p + j) / i;
                modAdd(d[i - 1][j + cnt], d[i][j]);
            }
        }
    }
    int ans = (LL)k * (k + 1) / 2 % MOD * n % MOD;
    forn(i, n - 1) ans = (LL)ans * (k + 1) % MOD;
    forn(i, n * k + 1) ans = (ans - (LL)d[0][i] * i) % MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
}


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

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

	string s;
	cin>>s;

	int rsume=0,rsumw=0,lsume=0,lsumw=0;
	for(int i=0;i<n;i++){
		if(s[i]=='W'){rsumw++;}
		else{rsume++;}
	}

	int ans = n+1;
	for(int i=0;i<n;i++){
		if(s[i]=='W'){rsumw--;}
		else{
			rsume--;
		}
		ans = min(ans,lsumw+rsume);
		if(s[i]=='W'){lsumw++;}
		else{lsume++;}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int maxn=2e5+9;
struct edge{
    int to,nex;
}edges[maxn<<1];
bool mark[maxn];
int head;
void addedge(int to,int no){
    edges[no].to=to;
    edges[no].nex=head;
    head=no;
}
int main(){
    int n,m;
    ios::sync_with_stdio(0);
    while(cin>>n>>m){
        head=-1;
        int e,f;
        int no=0;
        memset(mark,0,sizeof(mark));
        for(int i=1;i<=m;i++){
            cin>>e>>f;
            if(e>f)swap(e,f);
            if(f==n){
                mark[e]=1;
            }
            if(e==1){
                addedge(f,i);
            }
        }
        bool t=0;
        for(int i=head;~i;i=edges[i].nex){
            //cout<<i<<endl;
            e=edges[i].to;
            if(mark[e]){
                t=1;break;
            }
        }
        if(t){
            cout<<"POSSIBLE"<<endl;
        }
        else{
            cout<<"IMPOSSIBLE"<<endl;
        }
    }
}

Measured memory_bytes: 2048
import math

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

div = []
for t in [a,b,c,d,e]:
  div.append(math.ceil(t/10)*10)

m = []
for t in [a,b,c,d,e]:
  if 0 < (t % 10):
    m.append(t%10)

if len(m) == 0:
  print(sum(div))
else:
  print(sum(div)-(10-min(m)))
  

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

int main()
{
    long long C[1000000];
    long long N, n;
    cin >> N;
    for (int i = 0; i < N-1; i++)
    {
        cin >> n;
        C[n-1] += 1;
    }
    for (int i = 0; i < N; i++)
        cout << C[i] << endl;
}

Measured memory_bytes: 5084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll r;
  cin >> r;
  cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = 0;
		int min = 9999;
		int N = sc.nextInt();
		int i = 0;
		int tmp = 0;
		while(i<N){
			tmp = sc.nextInt();
			if(max<tmp){
				max = tmp;
			}
			if(tmp<min){
				min = tmp;
			}
			i++;
		}
		
		System.out.println(Math.abs(max-min));
	}

}


Measured memory_bytes: 21844