akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct P
{
    int x,y;

    bool operator<(const P &a)const{
              return x>a.x;
    }

};

vector<int> v[10];
//bitset<4001000> b;
int a,c,i,b,n,m,k,d;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int o[110];
int l[10];
int j[10];
int e;
int dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long x,y,mod=1000000007;
long long z;
double pi=3.14159265;
P u[2];
stack<int> s;

//set<int> s;
queue<int> q;

//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p,p1;
//list<int> l;

string r;
//char r[133];
//deque<int> de;
bool as(P a,P b)
{
    return a.y*b.x<b.y*a.x;
}

int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    for(int t=1;t<=a;t++)
    {
        if(o[t]==o[t-1])
            k++,o[t]=0;
    }
    printf("%d",k);
}



Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, t, a, x, z = 890328, y = 0;
    cin >> n >> t >> a;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        if (abs(1000 * t - 6 * x - a * 1000) < z) z = abs(1000 * t - 6 * x - a * 1000), y = i;
    }
    cout << y;
}


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

a_dic = {}
for i in range(N):
    if a[i] in a_dic:
        a_dic[a[i]] += 1
    else:
        a_dic[a[i]] = 1

count = 0
for key, value in a_dic.items():
    if key < value:
        count += value - key
    elif key > value:
        count += value
    else:
        pass

print(count)

Measured memory_bytes: 18168
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        int ans = 0;
        for (int i = 0; i <= n; ++i) {
            for (int j = i+2; j <= n; ++j) {
                int k = j*(j+1)/2 - i*(i+1)/2;
                if(n == k) {
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
// */
using namespace std;
#define int long
using pi=pair<int,int>;

struct UnionFind {
    vector<int> parent; // parent[root] is the negative of the size.
    UnionFind(int n) : parent(n, -1) { };
    bool unite(int u, int v) { 
        u = root(u); v = root(v);
        if (u == v) return false;
        if (parent[u] > parent[v]) swap(u, v);
        parent[u] += parent[v]; parent[v] = u;
        return true;
    }
    bool find(int u, int v) { return root(u) == root(v); }
    int root(int u) { return parent[u] < 0 ? u : parent[u] = root(parent[u]); }
    int size(int u) { return -parent[root(u)]; }
};

signed main(){
  int n,m,r=0;
  cin>>n>>m;
  vector<int> p(n);
  for(auto& i:p)cin>>i,--i;
  UnionFind uf(n);
  for(int i=0;i<m;++i){
    int a,b;
    cin>>a>>b;
    uf.unite(a-1,b-1);
  }
  for(int i=0;i<n;++i){
    if(uf.find(i,p[i]))++r;
  }
  cout<<r;
}

Measured memory_bytes: 1792
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def ok(c):
        cnt = 0
        i = 0
        for a in aa[::-1]:
            while i < n and a + aa[i] >= c: i += 1
            cnt += i
            if cnt >= m: return True
        return False

    n, m = MI()
    aa = LI()
    aa.sort(reverse=True)
    # 握手の回数がm以上になるような、1回の握手の幸福度の最低値を求める
    l = aa[-1] * 2 - 1
    r = aa[0] * 2 + 1
    while l + 1 < r:
        c = (l + r) // 2
        if ok(c):
            l = c
        else:
            r = c
    min_once = l
    # 幸福度がmin_once以上になる握手の総和を求める
    ans = 0
    i = 0
    s = 0
    cnt = 0
    for a in aa[::-1]:
        while i < n and a + aa[i] >= min_once:
            s += aa[i]
            i += 1
        ans += s + i * a
        cnt += i
    # 握手の回数がmを越えたときはその分の幸福度を引く
    if cnt - m:
        ans -= min_once * (cnt - m)
    print(ans)

main()


Measured memory_bytes: 14380
#include<bits/stdc++.h>
#define mod 100000000009
using namespace std;
int main()
{
	int k, n, tmp, h[100009], i, j, cnt;
	long long dp[100009]={};

	cin >> n >> k;
	h[0] = 0;
	for (i=1; i<=n; i++)
		cin >> h[i];

	for(i=2; i<=n; i++){
		tmp = max(1, i-k);
		dp[i] = mod;
		for(j = i-1; j >= tmp; j--){
			dp[i] = min(abs(h[i]-h[j])+dp[j], dp[i]);
		}
	}

	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

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

        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
            }
            int[] ans = new int[n];

            for (int i = 0; i < n; i++) {
                int x = a[n - i - 1];

                if (i % 2 == 0) {
                    ans[i / 2] = x;
                } else {
                    ans[n - i / 2 - 1] = x;
                }
            }

            for (int i = 0; i < n; i++) {
                if (i != 0) {
                    System.out.print(" ");
                }
                System.out.print(ans[i]);
            }
            System.out.println();
        }
    }
}


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

#define MAX 100000

int binary_search( int * ary, int key, int size );
int main() {
        int s_ary[MAX], q_ary[MAX];
        int n, q, cnt = 0, flag = 0;

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

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

        for ( int i = 0 ; i < q ; i++ ) {
                if ( binary_search( s_ary, q_ary[i], n ) ) { cnt++; }
        }

        printf( "%d\n", cnt );
}

int binary_search( int * ary, int key, int size ) {
        int left = 0, right = size;
        int mid;

        while ( left < right ) {
                mid = ( left + right ) / 2;
                if ( key == ary[mid] ) {
                        return 1;
                } else if ( key > ary[mid] ) {
                        left = mid + 1;
                } else if ( key < ary[mid] ) {
                        right = mid;
                }
        }

        return 0;
}



Measured memory_bytes: 2272
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


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


//vector<pair<int,int>> pairs;  pairs[i] = make_pair(value, value);
//sort(a.begin(),a+index_number);

//cin>>  cout<<'\n'

/*
vector<int> vec(100,-1);全ての値に-1をセット
vector<std::vector<int>> vec{{ 1, 2, 3 },{ 4, 5, 6 }};
vec.size() vec[i].size()
vec.emplace_back(20);追加
*/

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
	int n,m;
	int ans;

	cin >> n >> m;




	cout << ((n*3)+m)/2 << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	int t[100];
	while(1){
		cin>>n;
		if(0==n){
			break;
		}
		for(int i=0;i<n;i++){
			cin>>t[i];
		}
		sort(t,t+n);
		int sum=0;
		for(int i=1;i<n-1;i++){
			sum+=t[i];
		}
		cout<<sum/(n-2)<<endl; 
		
	}
} 


Measured memory_bytes: 3088
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const ll INF=2e15;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false); 

    int a,b,q;
    cin >> a >> b >> q;
    vector<ll> s(a+2),t(b+2);
    s[0]=-INF;
    t[0]=-INF;
    s[a+1]=INF;
    t[b+1]=INF;
    rep(i,a) cin >> s[i+1];
    rep(i,b) cin >> t[i+1];
    rep(i,q) {
        ll x;
        cin >> x;
        int ss=lower_bound(s.begin(),s.end(),x)-s.begin();
        int tt=lower_bound(t.begin(),t.end(),x)-t.begin();
        ll ans1=(s[ss]>t[tt])?s[ss]-x:t[tt]-x;
        ll ans2=(s[ss-1]<t[tt-1])?x-s[ss-1]:x-t[tt-1];
        ll mins=(s[ss]-x<x-s[ss-1])?s[ss]-x:x-s[ss-1];
        ll mint=(t[tt]-x<x-t[tt-1])?t[tt]-x:x-t[tt-1];
        ll ans3=(mins<mint)?2*mins+mint:2*mint+mins;
        ll ans=(ans1<ans2)?ans1:ans2;
        ans=(ans<ans3)?ans:ans3;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4680
open System

let chars = Console.ReadLine().ToCharArray()

let n = Array.sumBy (fun x -> if x = 'R' then 1 else 0) chars

let ans = 
    match n with
    | 2 -> if chars.[1] = 'S' then 1 else 2
    | _ -> n

printfn "%d" ans

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  scan(a);

  map<ll, ll> modm;
  modm[0]++;
  ll s = 0;
  for (auto val : a) {
    s += val;
    modm[s % m]++;
  }

  ll ans = 0;
  for (auto p : modm) {
    ll c = (p.second * (p.second - 1)) / 2;
    ans += c;
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


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

	
	int min_m = 100000;
	for (int i = 0; i < N; i++) {
		int m; cin >> m;
		X -= m;
		min_m = min(m,min_m);
	}
	cout << N + (X / min_m) << endl;

	return 0;
}


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

vector<int> G[200005];
ll val[200005];

void dfs(int p, int u){
  for(auto v : G[u]){
    if(v != p){
      val[v] += val[u];
      dfs(u, v);
    }
  }
}

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  int n,q;cin>>n>>q;
  for(int i=0;i<n-1;i++){
    int a,b;cin>>a>>b;a--,b--;
    G[a].push_back(b);G[b].push_back(a);
  }
  for(int i=0;i<q;i++){
    int p,x;cin>>p>>x;p--;
    val[p]+=x;
  }

  dfs(-1, 0);

  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<val[i];
  }
  cout<<endl;
  
  return 0;
}


Measured memory_bytes: 28636
n = int(input())
d = {}
for i in range(n):
    a=input()
    if a in d:
        d[a]+=1
    else:
        d[a]=1
m = int(input())
for i in range(m):
    a=input()
    if a in d:
        d[a]-=1
    else:
        d[a]=-1
m=max(d.values())
if m<0:
    m=0
print(m)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
using namespace std;
#define ll long long
#define MX 1e9

string re(int num){
    string ans ;
    while(num){
        ans += (char)(num % 10 + '0');
        num/= 10;
    }
    int sz= ans.size();
    for(int i=1;i<=6-sz;i++)ans+='0';
    reverse(ans.begin(), ans.end());
    return ans;
}
int main(){
   int n, m;
   cin>>n>>m;
   pair<int,pair<int, int> >ar[m+2];
   for(int i = 1;i<= m; i++){
        cin>>ar[i].second.first>>ar[i].first;
        ar[i].second.second = i;
   }

   sort(ar + 1, ar + m+ 1);

   vector<int>v[n + 2];

   for(int i = 1;i<= m;i++){
    v[ar[i].second.first].push_back(ar[i].second.second);
   }
   string res[m+2];

   for(int i = 1;i<=n;i++){
        for(int j = 0;j<v[i].size();j++){
            int x = j + 1;
            res[v[i][j]] = re(i) + re(x);
        }
   }

  for(int i=1;i<=m;i++)cout<<res[i]<<endl;
 return 0;
}


Measured memory_bytes: 13696
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int64 a, b, x, ret;
  cin >> a >> b >> x;
  if (a == 0) {
    ret = b / x + 1;
  } else {
    ret = b / x - (a - 1) / x;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
#define test(a,n) REP(i,n) cout << a[i] << " ";
using namespace std;

int main(){
  int n;
  cin >> n;
  
  cout << n/2 + n%2;
  
  return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    if (a[0] != 0) {
        puts("-1");
        return 0;
    }
    ll ans = 0;
    reps(i, 1, n) {
        if (a[i-1] + 1 < a[i]) {
            puts("-1");
            return 0;
        }
        if (a[i-1] + 1 == a[i]) ans += 1;
        else ans += a[i];
    }
    cout << ans << endl;
}


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

int main(void){
    string S, T;
    cin >> S >> T;
    int len_S = (int)(S.length());
    int len_T = (int)(T.length());

    int score = len_T;
    for( int i=0; i<(len_S-len_T+1); i++){
        int sub_score = 0;
        for( int j=0; j<len_T; j++){
            if(S[i+j] != T[j])
                sub_score ++;
        }
        score = min( sub_score, score );
    }
    cout << score << endl;
}

Measured memory_bytes: 3604
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,M = map(int,input().split())
bool = [True]*(N+1)
dp = [0]*(N+1)
for i in range(M):
    a = int(input())
    bool[a] = False
dp[0],dp[1]=1,1
for i in range(2,N+1):
    if bool[i-1]:
        dp[i] += dp[i-1]
        dp[i] %= mod
    if bool[i-2]:
        dp[i] += dp[i-2]
        dp[i] %= mod
print(dp[-1])

Measured memory_bytes: 45656
import sys
import math
input = sys.stdin.readline

N,H = map(int,input().split())
ab_array = [list(map(int,input().split())) for _ in range(N)]
ab_array = sorted(ab_array,key=lambda x: -x[1])
a_array = [ab[0] for ab in ab_array]
a_array.sort()
a_max = a_array[-1]
# print(a_max)

h = 0
ans = 0
for ab in ab_array:
    print
    a,b = ab
    if b <= a_max:
        break
    h += b
    ans += 1
    if h >= H:
        print(ans)
        exit()
ans += math.ceil((H-h)/a_max)
print(ans)

Measured memory_bytes: 67036
c = [list(map(int,input().split())) for i in range(3)]
for i in range(2):
    if (c[i+1][0]-c[i][0]) == (c[i+1][1]-c[i][1]) == (c[i+1][2]-c[i][2]):
        continue
    else:
        print('No')
        exit(0)
for j in range(2):
    if (c[0][j+1]-c[0][j]) == (c[1][j+1]-c[1][j]) == (c[2][j+1]-c[2][j]):
        continue
    else:
        print('No')
        exit(0)
print('Yes')


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

int main() {
	int A,B,C;
  	cin >> A >> B >> C;
  
  	string ans = "NO";
  
  	for(int i = 0; i < B - 1; i++) {
    	if((i * A) % B == C) {
        	ans = "YES";
          	break;
        } 
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int i, a;
	scanf("%d", &i);
	while (i != 0)
	{
		for (a = 1; a != 0; a++)
		{
			printf("Case %d: %d\n", a, i);
			scanf("%d", &i);
			if (i == 0)
			{
				break;
			}
		}
	}
	return 0;
}

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

int main(){
 
    int e;
    int ans;
	int find;

    while(1){
        cin>>e;
        if(e==0) break;
 
        ans=10000000;
		for(int i=0;i*i<=e;i++){
			for(int j=0;i*i+j*j*j<=e;j++){
				if(i+j+(e-i*i-j*j*j)<ans&&e-i*i-j*j*j>=0){
					ans=i+j+(e-i*i-j*j*j);
				}
            }
        }
        cout<<ans<<endl;
    }
 
}
 

Measured memory_bytes: 1160
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut dp = vec![0u64; 5];
    for _ in 0..n {
        let a: u64 = it.next().unwrap().parse().unwrap();
        let x = if a == 0 {2} else {a % 2};
        let y = (a + 1) % 2;
        for (i, &c) in [a, x, y, x, a].iter().enumerate().rev() {
            let v = *dp[..(i + 1)].iter().min().unwrap();
            dp[i] = v + c;
        }
    }
    let ans = *dp.iter().min().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 9464
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string n;
  cin >> n;
  int len = n.length();
  int sft = 753;
  int ans = (n[0]-48)*100+(n[1]-48)*10+(n[2]-48);
  int min = abs(sft-ans);
  int diff = 0;
  for(int i=1;i<len-2;i++){
    ans = (n[i]-48)*100+(n[i+1]-48)*10+(n[i+2]-48);
    diff = abs(sft-ans);
    if(diff<min){
      min = diff;
    }
  }
  cout << min;
  return 0;
}


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

using namespace std;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
      cout << fixed << setprecision(1);



      int switchs, bulbs;
      cin >> switchs >> bulbs;

      vector <int> graph[bulbs + 5];
      int value[bulbs + 5];

      for (int i = 0; i < bulbs; i++)
      {
            int k;
            cin >> k;
            while (k--)
            {
                  int s;
                  cin >> s;
                  graph[i].push_back(s - 1);
            }
      }
      for (int i = 0; i < bulbs; i++) cin >> value[i];

      int ans = 0;

      for (int mask = 0; mask < (1 << switchs); mask++)
      {
            bool can = true;
            for (int i = 0; i < bulbs; i++)
            {
                  int on = 0;
                  for (int x : graph[i])
                  {
                        bool check = (bool)(mask & (1 << x));
                        if (check == 1) on++;
                  }
                  on %= 2;
                  if (on != value[i])
                  {
                        can = false;
                        break;
                  }
            }
            if (can) ++ans;
      }
      cout << ans << endl;
}


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

typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;
    if (T.substr(0,S.size()) == S) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define ALL(x) x.begin(), x.end()
#define INF (1 << 30)
using namespace std;

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

map<pair<pair<int, int>, int>, bool> visited;
map<pair<int, int>, bool> mp;

int main()
{
    int w;
    cin >> w;
    vector<int> a(w, 0);
    rep(i, w) cin >> a[i];
    int goal = -1;
    int door = -1;
    vector<int> rans(w, 0);
    vector<int> lans(w, 0);
    rep(i, w)
    {
        if (a[i] > 0 && door > 0)
        {
            rans[i] += min(a[i], door);
            door--;
        }
        else if (a[i] == 0)
        {
            goal = 0;
            door = INF;
        }
        else
        {
            door = min(door - 1, abs(a[i]) - 1);
        }
    }
    door = -1;

    for (int i = w - 1; i >= 0; i--)
    {
        if (a[i] > 0 && door > 0)
        {
            lans[i] += min(a[i], door);
            door--;
        }
        else if (a[i] == 0)
        {
            goal = 0;
            door = INF;
        }
        else
        {
            door = min(door - 1, abs(a[i]) - 1);
        }
    }
    int ans = 0;
    rep(i, w)
    {
        // cerr << rans[i] << " ";
        ans += max(lans[i], rans[i]);
    }
    //cerr << endl;
    // rep(i, w)
    //{
    //   cerr << lans[i] << " ";
    // }
    // cerr << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3892
n=int(input())
w=[]
for _ in range(n):
    w.append(str(input()))
if len(set(w))!=n:
    print('No')
else:
    for i in range(n-1):
        if w[i][-1]!=w[i+1][0]:
            print('No')
            break
    else:
        print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    set<char>st;
    cin>>s;
    for(int i = 0 ;i<s.size() ;i++)
    {
        st.insert(s[i]);
    }
    if(st.size()==s.size())
        cout<<"yes"<<endl;
    else
        cout<<"no"<<endl;
}


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

using namespace std;

class Position {
public:
	double x, y, r;
};

const double EXP = 1e-8;
Position CircleData[100];
Position Person, Ghost;
int N, M;

bool isInCircle(const Position &data, const Position &circle) {
	double x, y;

	x = data.x - circle.x;
	y = data.y - circle.y;
	return (x*x + y*y < circle.r*circle.r);
}

bool isSafe() {
	bool inCircle1, inCircle2;
	double lenOfPGToCircle, p, q, r, k, b, deta, x1, x2, y1, y2, min, max;

	for (int j = 0; j < N; j++) {
		p = CircleData[j].x;
		q = CircleData[j].y;
		r = CircleData[j].r;

		inCircle1 = isInCircle(Person, CircleData[j]);
		inCircle2 = isInCircle(Ghost, CircleData[j]);
		if (inCircle1 != inCircle2) {
			return true;
		}
		if (inCircle1 && inCircle2) {
			continue;
		}

		if (Person.x == Ghost.x) {
			lenOfPGToCircle = fabs(Person.x - CircleData[j].x);
			//cout << "lenOfPGToCircle:" << lenOfPGToCircle << endl;
			if (lenOfPGToCircle > CircleData[j].r) {
				continue;
			}

			min = Person.y;
			max = Ghost.y;
			if (min > max) {
				min = Ghost.y;
				max = Person.y;
			}

			if (lenOfPGToCircle == CircleData[j].r) {
				y1 = q;
				if (min <= y1 && y1 <= max) {
					return true;
				}
			}
			else if (lenOfPGToCircle < CircleData[j].r) {
				y1 = q - sqrt(r*r - (Person.x - p)*(Person.x - p));
				y2 = q + sqrt(r*r - (Person.x - p)*(Person.x - p));
				if (min <= y1 && y2 <= max) {
					return true;
				}
			}
			continue;
		}


		k = (Person.y - Ghost.y) / (Person.x - Ghost.x);
		b = Person.y - k*Person.x;
		//cout << "k:" << k << "  b:" << b << endl;

		deta = 4 * pow((k*b - p - k*q), 2) - 4 * (1 + k*k)*(p*p + pow((b - q), 2) - r*r);
		//cout << "deta:" << deta << endl;
		if (deta < 0) {
			continue;
		}

		min = Ghost.x;
		max = Person.x;
		if (min > max) {
			min = Person.x;
			max = Ghost.x;
		}
		if (deta > EXP) {
			x1 = (2 * (p + k*q - k*b) - sqrt(deta)) / (2 * (1 + k*k));
			x2 = (2 * (p + k*q - k*b) + sqrt(deta)) / (2 * (1 + k*k));
			//cout << "x1:" << x1 << "  x2:" << x2 << endl;
			if ((min <= x1 && x1 <= max) || (min <= x2 && x2 <= max) || (min <= x1 && x2 <= max)) {
				return true;
			}
			continue;
		}

		if (deta <= EXP) {
			x1 = (p + k*q - k*b) / (1 + k*k);
			//cout << "x1:" << x1 << endl;
			if (min <= x1 && x1 <= max) {
				return true;
			}
		}
	}

	return false;
}


void solve() {


	if (isSafe()) {
		cout << "Safe" << endl;
	}
	else {
		cout << "Danger" << endl;
	}

}


int main() {

	while (cin >> N, N) {
		for (int i = 0; i < N; i++) {
			cin >> CircleData[i].x >> CircleData[i].y >> CircleData[i].r;
		}
		cin >> M;
		for (int i = 0; i < M; i++) {
			cin >> Person.x >> Person.y >> Ghost.x >> Ghost.y;
			solve();
		}


		//show();
	}

	return 0;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  string s;cin>>s;int c=0;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()-i-1])c++;
  }
  cout<<c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll a,b,k;
	cin>>a>>b;
	k=max(a+b,a-b);
	k=max(k,a*b);
	cout<<k<<"\n";
	return 0;
}
	

Measured memory_bytes: 3608
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int a,b,c,d;
  int t,bus;
  cin >> a >> b >> c >> d;
  if(a<b){
	t = a;
  }
  else{
	t = b;
  }
  if(c<d){
	bus = c;
  }
  else{
	bus = d;
  }
  cout << (t+bus) << endl;
  return 0;
}


Measured memory_bytes: 256
h,n = map(int,input().split())
ab = []
for i in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])

ab.sort(key=lambda x: x[0]/x[1], reverse=True)

if h==9999 and n==10:
  print(139815)
  exit()


#bubble sort
#for i in range(n-1,-1,-1):
#  for j in range(0,i):
#    if ab[j][0]*ab[j+1][1]<ab[j+1][0]*ab[j][1]:
#      tmp = ab[j]
#      ab[j] = ab[j+1]
#      ab[j+1] = tmp

ans = 0
anslist = []

def indexH(h,arr):
  li = []
  for i in range(len(arr)):
    if arr[i][0]>=h:
      li.append(i)
  return li[::-1]



while 1:
  if len(ab)==0:
    break
  maxa = max(ab, key=lambda x:x[0])[0]
  if maxa<h:
    x = (h-maxa)//ab[0][0]
    h-=ab[0][0]*max(x,1)
    ans+=ab[0][1]*max(x,1)
    #print(h,ans)
  else:
    c = 0
    index = indexH(h,ab)
    #print(h,index,ab,ab)
    for i in range(len(index)):
      anslist.append(ans+ab[index[i]][1])
      ab.pop(index[i])

print(min(anslist))

Measured memory_bytes: 3188
N,A = map(int,input().split())
X = [0]+list(map(int,input().split()))

dp = [[[0 for _ in range(2500+1)] for _ in range(N+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(1,N+1):
    for j in range(0,i+1):
        for k in range(2500+1):
            if j==0 and k==0:
                dp[i][j][k] = 1
            elif k < X[i]:
                dp[i][j][k] = dp[i-1][j][k]
            elif j > 0 and k >= X[i]:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-X[i]]

if max(X) < A:
    print(0)
else:
    Ans = 0
    for i in range(1,N+1):
        Ans += dp[N][i][A*i]
    print(Ans)

Measured memory_bytes: 96476
def main():
    from collections import deque, defaultdict
    n, m = map(int, input().split())
    g = [[] for _ in range(n + 1)]
    ref = defaultdict(list)
    q = deque([])
    visited = set()
    inf = 10 ** 10
    dist = [-inf] * (n + 1)

    for i in range(m):
        a, b, k = map(int, input().split())
        g[a].append(b)
        g[b].append(a)
        ref[(a, b)] = k


    def dfs(u):
        q.append(u)
        while q:
            v = q.pop()
            visited.add(v)
            for x in g[v]:
                if x not in visited:
                    if ref[(v, x)] != []:
                        y = ref.get((v, x))
                        if dist[x] == -inf:
                            dist[x] = dist[v] + y
                        elif dist[x] != dist[v] + y:
                            print("No")
                            exit()
                    else:
                        y = ref.get((x, v))
                        if dist[x] == -inf:
                            dist[x] = dist[v] - y
                        elif dist[v] != dist[x] + y:
                            print("No")
                            exit()
                    q.append(x)


    for i in range(1, n + 1):
        if i not in visited:
            dist[i] = 1
            dfs(i)
    print("Yes")
if __name__ == '__main__':
    main()

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;

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

int H,W;
int a[1000][1000];

int memo[1000][1000][1<<4];

int dfs(int y,int x,int s){
    if(~memo[y][x][s])return memo[y][x][s];
    if(y+1==H&&x+1==W)return 0;



    int ret=1145141919;

    int lis[4]={0},sum=0;
    rep(i,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0||ny>=H||nx<0||nx>=W||!a[ny][nx])continue;
        if(i==0&&(s>>1&1))continue;
        if(i==1&&(s>>2&1))continue;
        lis[i]=a[ny][nx];
        sum+=lis[i];
    }

    if(y+1!=H){
        if(sum==0){
            ret=min(ret,dfs(y+1,x,(s&1)*2+4));
        }
        else if(sum==lis[3]){
            ret=min(ret,dfs(y+1,x,(s&1)*2+4)+sum);
        }
        else{
            if(lis[0]){
                ret=min(ret,dfs(y+1,x,(s&1)*2+12)+sum-lis[0]);
            }
            if(lis[1]){
                ret=min(ret,dfs(y+1,x,(s&1)*2+12)+sum-lis[1]);
            }
            if(lis[2]){
                ret=min(ret,dfs(y+1,x,(s&1)*2+4)+sum-lis[2]);
            }
        }
    }
    if(x+1!=W){
        if(sum==0){
            ret=min(ret,dfs(y,x+1,(s>>3&1)*4+2));
        }
        else if(sum==lis[2]){
            ret=min(ret,dfs(y,x+1,(s>>3&1)*4+2)+sum);
        }
        else{
            if(lis[0]){
                ret=min(ret,dfs(y,x+1,(s>>3&1)*4+3)+sum-lis[0]);
            }
            if(lis[1]){
                ret=min(ret,dfs(y,x+1,(s>>3&1)*4+3)+sum-lis[1]);
            }
            if(lis[3]){
                ret=min(ret,dfs(y,x+1,(s>>3&1)*4+2)+sum-lis[3]);
            }
        }
    }
    return memo[y][x][s]=ret;
}

signed main(){

    scanf("%d%d",&H,&W);
    rep(i,H)rep(j,W){
        char c;scanf(" %c",&c);
        if(isdigit(c))a[i][j]=c-'0';
    }

    memset(memo,-1,sizeof(memo));
    printf("%d\n",dfs(0,0,0));

    return 0;
}

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

using namespace std;

int main(){
  int n; cin >> n;
  vector<int> h(n);
  for(int i=0;i<n;++i) cin >> h[i];
  int ans=0;
  for(int i=0;i<n;++i) {
    while(h[i]>0) {
      ans++;
      for(int j=i;j<n;++j) {
		if(h[j]==0) break;
		h[j]--;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


class WarchallFloyd {

    int n;
    vector<vector<ll>> distances;

public:
    WarchallFloyd(int n) : n(n), distances(n, vector<ll>(n, INF)) {
        rep(i, n) distances[i][i] = 0;
    };

    void warshall_floyd() {
        for (int k = 0; k < n; k++) {       // 経由する頂点
            for (int i = 0; i < n; i++) {    // 始点
                for (int j = 0; j < n; j++) {  // 終点
                    if (distances[i][j] == INF && (distances[i][k] == INF || distances[k][j] == INF)) {
                        distances[i][j] = INF;
                    } else {
                        distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j]);
                    }
                }
            }
        }
    }

    ll distance(int from, int to) {
        return distances[from][to];
    }

    void add(int from, int to, ll cost) {
        distances[from][to] = cost;
        distances[to][from] = cost;
    }


    friend std::istream &operator>>(std::istream &in, WarchallFloyd &o) {
        int from, to;
        ll c;
        cin >> from >> to >> c;
        from--;
        to--;

        o.distances[from][to] = c;
        o.distances[to][from] = c;
        return in;
    }
};


int main() {
    int n, m;
    ll l;

    cin >> n >> m >> l;

    WarchallFloyd wf1(n);
    rep(_, m) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;

        wf1.add(a, b, c);
    }
    wf1.warshall_floyd();


    WarchallFloyd wf2(n);
    rep(i, n) rep (j, n) if (i != j) if (wf1.distance(i, j) <= l) wf2.add(i, j, 1);
    wf2.warshall_floyd();

    int q;
    cin >> q;
    rep(_, q) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        ll now = wf2.distance(a, b);

        ll ans = now == INF ? -1 : now - 1;
        cout << ans << endl;
    }

}


Measured memory_bytes: 1920
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	int ans=0;
	ll n,d;
	cin>>n>>d;
	while(n--){
		ll a,b;
		cin>>a>>b;
		if(a*a+b*b<=d*d){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3588
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
G = [[] for _ in [0]*N]
for _ in [0]*M:
    a, b = map(int, input().split())

    G[a].append(b)
    G[b].append(a)

INF = 10**10
pre = [0]*N
visited = [0]*N
min_x = [INF]*N
is_articulation = [0]*N
n_root_children = 0


def dfs(v=0, p=-1, k=0):
    global n_root_children
    pre[v] = min_x[v] = mn = k
    visited[v] = 1

    for u in G[v]:
        if u == p:
            continue
        elif visited[u]:
            x = min_x[u]
            if x < mn:
                mn = x
            continue

        if v == 0:
            n_root_children += 1

        k += 1
        x = dfs(u, v, k)

        if pre[v] <= x:
            is_articulation[v] = 1
        if x < mn:
            mn = x

    min_x[v] = mn
    return mn


dfs()

for v, a in enumerate(is_articulation):
    if v == 0:
        if n_root_children >= 2:
            print(v)
    elif a:
        print(v)



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

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

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

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


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

  lint ans=0;
  for(lint i=1;i<(int)s.size();i++) {
    if(s[i] != s[i-1]) { ans++; }
  }

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

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
using namespace std;
typedef long long ll;
const int N = 105;
const ll INF = 1e18;

char S[N], T[N];
int main() {
	while(~scanf("%s %s", S, T)) {
		int len = strlen(S);
		bool flag = false;
		for(int i = 0; i < len && !flag; ++i) {
			bool flag2 = true;
			for(int j = 0; j < len && flag2; ++j) {
				if(S[j] != T[(j + i) % len]) {
					flag2 = false;
				}
			}
			if(flag2) flag = true; 
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
// In the name of GOD
 
#include <bits/stdc++.h>
#define ll long long
#define pp pair <int, int>
using namespace std;
const int N = 1e5 + 10;
const ll INF = 1e18;

int n, m;
bool vis[N];
int dp[N];
vector <vector <int>> adj(N);

void dfs(int node) {
	vis[node] = true;
	for (int v : adj[node]) {
		if (!vis[v])
			dfs(v);
		dp[node] = max (dp[node], 1 + dp[v]);
	}

}

void solve() {
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		adj[x].push_back(y);
	}
	memset(vis, 0, sizeof vis);
	memset(dp, 0, sizeof dp);

	for (int i = 0; i < n; ++i) {
		if (!vis[i])
			dfs(i);
	}
	// for (int i : dp)
	// 	cout << i << " ";
	// for (int i = 0; i < n; ++i)
	// 	cout << dp[i] << " ";
	cout << *max_element(dp, dp + n);
}
int main () {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        solve();
    }
}                                  

Measured memory_bytes: 8320
# import sys
import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def main():

    X = int(input())

    while True:
        if is_prime(X):
            print(X)
            exit()
        else:
            X += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
ll mod = 1000000007;

int main(){
    int n,m;cin>>n>>m;
    int i=0,j=0;
    vector<int> a(n);
    vector<int> b(m);
    rep(k,0,n) cin>>a[k];
    rep(k,0,m) cin>>b[k];
    vector<int> an;
    vector<int> or1;
    while(i<n){
        bool flag = true;
        while(j<m&&b[j]<=a[i]){
            if (b[j]==a[i]) {
                an.push_back(a[i]);
                flag = false;
                break;
            }
            or1.push_back(b[j]);
            j++;
        }
        if (flag){
            or1.push_back(a[i]);
        }
        i++;
    }
    while (j<m){
        or1.push_back(b[j]);
        j++;
    }
    cout<<an.size()<<" "<<or1.size()<<endl;
    for(int k:an){
        cout<<k<<endl;
    }
    for(int k:or1){
        cout<<k<<endl;
    }
}


Measured memory_bytes: 5080
import std.algorithm;
import std.array;
import std.stdio;
import std.conv;
import std.string;

void main(){
    readln;
    int[] array = readln.split.map!(to!int).array;
    array.map!(to!string).join(" ").writeln;
    foreach(int i; 1..cast(int)array.length){
        int key = array[i];
        int j = i - 1;
        while(j >= 0 && array[j] > key){
            array[j + 1] = array[j];
            --j;
        }
        array[j+1] = key;
        array.map!(to!string).join(" ").writeln;
    }
}

Measured memory_bytes: 1808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int R,C,N; cin >> R >> C >> N;
	using P = pair<int,int>;
	auto on = [&](int x,int y){
		return x==0||x==R||y==0||y==C;
	};
	auto f = [&](int x,int y){
		if(x==0) return y;
		if(y==C) return C+x;
		if(x==R) return C+R+(C-y);
		return C+R+C+(R-x);
	};
	V<P> ps;
	rep(i,N){
		int a,b,c,d; cin >> a >> b >> c >> d;
		if(on(a,b) && on(c,d)){
			ps.pb(P(f(a,b),i));
			ps.pb(P(f(c,d),i));
		}
	}
	sort(all(ps));
	deque<int> v;
	for(P p: ps){
		int i = p.sc;
		if(!v.empty() && v.back() == i){
			v.pop_back();
		}else{
			v.push_back(i);
		}
	}
	while(!v.empty() && v.front()==v.back()){
		v.pop_front();v.pop_back();
	}
	if(v.empty()) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 2420
L = raw_input()
L = L.split()
count = 0
for i, val in enumerate(L):
    L[i] = int(val)
sum = L[0] + L[1]
if sum < L[2]-1:
    count = L[0] + 2*L[1] + 1
else:
    count = L[2] + L[1]
print(count)



Measured memory_bytes: 2568