akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
using namespace std;

#define MAGIC 100000

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, a[MAGIC], b[MAGIC], c[MAGIC];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];
    int A[MAGIC], B[MAGIC], C[MAGIC];
    A[0] = a[0];
    B[0] = b[0];
    C[0] = c[0];
    for (int i = 1; i < n; ++i) {
        A[i] = max(B[i - 1], C[i - 1]) + a[i];
        B[i] = max(A[i - 1], C[i - 1]) + b[i];
        C[i] = max(A[i - 1], B[i - 1]) + c[i];
    }
    cout << max(A[n - 1], max(B[n - 1], C[n - 1])) << '\n';
    return 0;
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    tx-=sx;
    ty-=sy;
    sx=0;
    sy=0;
    rp(i,tx){
        cout << 'R';
    }
    rp(i,ty){
        cout << 'U';
    }
    rp(i,tx){
        cout << 'L';
    }
    rp(i,ty+1){
        cout << 'D';
    }
    rp(i,tx+1){
        cout << 'R';
    }
    rp(i,ty+1){
        cout << 'U';
    }
    cout << "LU";
    rp(i,tx+1){
        cout << 'L';
    }
    rp(i,ty+1){
        cout << 'D';
    }
    cout << 'R' << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
bool check(ll t,ll a[]);
    int32_t main()
    {
        ll i,j,k,l,n,m,q,s,t,sum=0,Connectedcomponents=0,b;
        ll a[10]={0};
        cin>>n>>k;
        for(i=0;i<k;i++)
        {
            cin>>b;
            a[b]=1;
        }
        while(1){

        if(!(check(n,a)))
        {
            cout<<n;
            return 0;
        }
         n++;
        }

       return 0;
    }
    bool check(ll t,ll a[])
    {
       ll flag=0;
        while(t>0)
        {
            if(a[t%10]==1)
            {
                flag=1;
            }
            t=t/10;
        }
        if(flag==1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }





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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll n, q;
  cin >> n >> q;
  vll BIT(n + 1, 0);  // 1-indexed
  auto badd = [&](ll i, ll x) {
    while (i <= n) {
      BIT[i] += x;
      i += i & -i;
    }
  };
  auto bsum = [&](ll i) {
    ll ret = 0;
    while (i > 0) {
      ret += BIT[i];
      i -= i & -i;
    }
    return ret;
  };
  rep(i, q) {
    ll c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      badd(x, y);
    } else {
      ll ans = max(0LL, (bsum(y) - bsum(x - 1)));
      cout << ans << endl;
    }
  } //i 

  return 0;
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if(K <= A)
  {
    cout << K << endl;
  }
  else if((K - A) <= B)
  {
    cout << A << endl;
  }
  else
  {
    cout << A - (K - (A + B));
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int X;
    cin >> X;
    int keta = X / 100;
    int m = X % 100;
    int num[] = {5, 4, 3, 2, 1};
    int cnt = 0;
    rep(i, 5) {
        cnt += m / num[i];
        m -= num[i] * (m / num[i]);
        //cout << m << " " << cnt << endl;
        if (m <= 0) break;
    }

    if (keta >= cnt && X >= 100) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
	
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	int n,k; cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int dp[n];
	for(int i=1;i<n;i++) dp[i]=1e9+5;
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
	    for(int j=i+1;j<=i+k;j++){
	       if(j<n)
	       dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i])); 
	    }
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

int main(void){
    
    bool isFirst = true;
    char midC;
    while(true){
        
        int H,W;
        cin >> H >> W;
        
        if (H==0 && W == 0) break;
        
        if (isFirst) isFirst = false;
        else cout << endl;
        
        for(int r = 0; r < H; r++){
            if (r == 0 || r == H-1) midC = '#';
            else midC = '.';
            cout << '#';
            for(int c = 1; c < W-1; c++){
                    cout << midC;
            }
            cout << '#' << endl;
        }
    }
    cout << endl;
    return 0;
}


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

#define N_MAX 100002

using namespace std;

int n;

int a[N_MAX], b[N_MAX], c[N_MAX];

int dp[N_MAX][4];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i] >> b[i] >> c[i];
    for(int i = 1; i <= n; i++)
    {
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][3]) + a[i];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][3]) + b[i];
        dp[i][3] = max(dp[i - 1][1], dp[i - 1][2]) + c[i];
    }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << "\n";
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n,m,x,y; cin >> n >> m >> x  >> y;
    int _x = -INF,_y = INF;
    rep(i,n+m){
        int t; cin >> t;
        if(i<n)cmax(_x,t); else cmin(_y,t);
    }
    cout << (_x < _y  and x < _y and _y <= y? "No War":"War") << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define REP(i, k, n) for (signed long long int i = (signed long long int)(k); i < (signed long long int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (signed long long int i = (signed long long int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end());
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp std::make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";
        std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});
        os<<"}\n";
    }
}
using std::cin;
using std::cout;
using std::string;
using std::min;
using std::next_permutation;
using LL = signed long long int;
using VL = V<LL>;
using VVL = V<VL>;
const int INF = INT_MAX, MOD = 1e9 + 7;
const LL LLINF = LLONG_MAX;
const double PI = M_PI;

void Main(){
    cill(a);
    cill(v);
    cill(b);
    cill(w);
    cill(t);
    LL dis = std::abs(b-a);
    LL vw = v - w;
    if (vw<=0){
        co("NO");
        return;
    }
    if (dis <= t * vw){
        co("YES");
    }else{
        co("NO");
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3652
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        //Compute c1 = new Compute();//calc
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        //input
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();

        int ans = a-b*2;
        if (ans < 0)
        {
            ans = 0;
        }
        System.out.println(ans);

        sc.close();
    }
}


Measured memory_bytes: 21972
import math
T_Tairyoku,T_Atack,A_Tairyoku,A_Atack=map(int,input().split())
T=(math.ceil(A_Tairyoku/T_Atack))
A=(math.ceil(T_Tairyoku/A_Atack))

if T==A:
  print('Yes')
elif T>A:
  print('No')
elif A>T:
  print('Yes')

Measured memory_bytes: 9184
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;
    if(A >= B && A >= C){
        A <<= K;
    }
    else if(B >= A && B >= C){
        B <<= K;
    }
    else{
        C <<= K;
    }
    cout << (A+B+C) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define ld long double
#define si(x) (ll)((x).size())
#define pb push_back
#define F first
#define S second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
#define all(x) (x).begin(), (x).end()
#define make_unique(x) (x).resize(unique(all(x))-(x).begin())
#define pr_vec(v) for(ll _=0;_<v.size();_++) cout << v[_] << " " ;
const int N = 1e6 + 7;
ll m = 998244353;


void solve()
{
    ll n1, n2, w, x, y;
    string a, b;
    cin >> a >> b;
    n1 = si(a), n2 = si(b);
    ll dp[n1 + 1][n2 + 1];
    memset(dp, 0, sizeof dp);

    for(ll i = 1; i <= n1; i++)
        for(ll j = 1; j <= n2; j++)
            dp[i][j] = (a[i - 1] == b[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]));

    string ans = "";
    ll i = n1, j = n2;
    while(i and j)
    {
        if(a[i - 1] == b[j - 1])
            ans += a[i-1], i--, j--;
        else if(dp[i - 1][j] > dp[i][j - 1])
            i--;
        else
            j--;

    }
    reverse(all(ans));
    cout << ans;
}




int main()
{



    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    // cin >> t;


    rep1(i, t)
    {
        // cout << "Case #" << i << ": ";
        solve();
        cout << endl;
    }


}

Measured memory_bytes: 70656
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);

  for(i=2; i<=n; i++){
    key = A[i];
    j=i-1;

    while(j>=0 && A[j] >key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    trace(A, n);
  }

  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n, t, a;
	vector<int> T, A;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t >> a;
		T.push_back(t);
		A.push_back(a);
	}
	long long tmpT, tmpA, ansT, ansA;
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			tmpT = T[0]; tmpA = A[0];
			ansT = tmpT; ansA = tmpA;
		}
		if (T[i] >= tmpT && A[i] >= tmpA) {
			ansT = T[i]; ansA = A[i];
			tmpT = T[i]; tmpA = A[i];
			continue;
		}
		long long T2, A2;
		T2 = (tmpT - 1) / T[i] + 1; A2 = (tmpA - 1) / A[i] + 1;
		T2 = max(T2, A2);
		tmpT = T[i] * T2; tmpA = A[i] * T2;
		ansT = tmpT; ansA = tmpA;
	}
	cout << ansT + ansA << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int S = 1 << 21;
char p0[S],*p1,*p2;
#ifndef ZXY
#define getchar() (p2 == p1 && (p2 = (p1 = p0) + fread(p0,1,S,stdin)) == p1 ? EOF : *p1++)
#endif
inline int read() {
	static int x,c;x = 0;
	do{c = getchar();}while(!isdigit(c));
	do{x = (x << 3) + (x << 1) + (c & 15);c = getchar();}while(isdigit(c));
	return x;
}
const int N = 2e5 + 5;
int n,k,a[N];
long long b[N];
int main() {
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;++i)
		scanf("%d",a+i);
	b[1] = 1;
	for(int i = 1;i <= k;++i)
		b[1] *= a[i];
	for(int i = 1;i <= n-k;++i)
		if(a[i] >= a[i+k]) puts("No");
		else puts("Yes");
	return 0;
}


Measured memory_bytes: 4532
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[110000];

int main(){
  int N,pre,h,count=0,ans=0;
  cin>>N;
  cin>>pre;
  for(int i=0;i<N-1;i++){
    cin>>h;
    if(pre>=h) count++;
    else count=0;
    ans=max(ans,count);
    pre=h;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import heapq
 
heap=[]
N = int(input())
for i in range(1,10):
  heapq.heappush(heap,i)
for i in range(N):
  x = heapq.heappop(heap)
  if x%10!=0:
    heapq.heappush(heap,10*x+(x%10)-1)
  heapq.heappush(heap,10*x+(x%10))
  if x%10!=9:
    heapq.heappush(heap,10*x+(x%10)+1)
  
print(x)

Measured memory_bytes: 11728
import sys

def main():
    for line in iter(sys.stdin.readline, ""):
        a = line.rstrip("\n").split(" ")
        b = int(a[0])
        c = int(a[1])
        print (str(b*c) + " " + str(2*b+2*c))
     
if __name__ == "__main__":
    main()

Measured memory_bytes: 6720
n,m = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(m)]

ball = [1] * (n+1)
red = [0] * (n+1)
red[1] = 1

for x,y in xy:
    ball[x] -= 1
    ball[y] += 1
    if red[x] == 1:
        red[y] = 1
        if ball[x] == 0:
            red[x] = 0
print(sum(red))

Measured memory_bytes: 28600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
struct grid  {int y; int x; int time;};
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//finding the number of the white blocks you need for 
//reaching the goal(min), then ,substract from the number of 
//white blocks. 
int main(){
    int h, w;
    cin >> h >> w;
    int seen[h][w];
    memset(seen, -1, sizeof(seen));
    vector<string> field(h);
    rep(i,h) cin >> field[i];
    int all = 0;
    rep(i,h){
        rep(j,w){
            if(field[i][j]=='.') ++all;
        }
    }
    bool ok = false;
    queue<grid> q;
    grid start = {0, 0, 0};
    q.emplace(start);
    int r = 0;
    while(!q.empty()){
        grid now = q.front();
        q.pop();
        rep(i,4){
            grid next = {now.y + dy[i], now.x + dx[i], now.time + 1};
            if(next.x < 0 || next. x >= w || next.y < 0 || next.y >= h) continue;
            if(field[next.y][next.x]=='#') continue;
            if(seen[next.y][next.x]!=-1) continue;
            seen[next.y][next.x] = 0;
            if((next.y == h-1) && (next.x == w - 1)){
                r = next.time;
                ok = true;
                break;
            }
            q.push(next);

        }
    }
     
    if(ok)cout << all - 1 - r << endl;
    else cout << -1 << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

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

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

Measured memory_bytes: 3916
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}

typedef struct{
  long long xz;
  long long yz;
}point;

point vector_plus(point a,point b){
  point r;
  r.xz=a.xz+b.xz;
  r.yz=a.yz+b.yz;
  return r;
}

point vector_minus(point a,point b){
  point r;
  r.xz=a.xz-b.xz;
  r.yz=a.yz-b.yz;
  return r;
}

//naiseki
long long dotproduct(point a,point b){
  return a.xz*b.xz+a.yz*b.yz;
}

//gaiseki
long long crossproduct(point a,point b){
  return a.xz*b.yz-a.yz*b.xz;
}

long long basedist(point a,point b){
  double x,y;
  x=b.xz-a.xz;
  y=b.yz-a.yz;
  return x*x+y*y;
}

double baselen(point a){
  return sqrt(a.xz*a.xz+a.yz*a.yz);
}

point base;

int vecsortfnc(const void *a,const void *b){
  double pa,pb;
  point va,vb;
  va.xz=(((point*)a)->xz);
  va.yz=(((point*)a)->yz);
  vb.xz=(((point*)b)->xz);
  vb.yz=(((point*)b)->yz);
  pa=crossproduct(base,va);
  pb=crossproduct(base,vb);
  if(pa>0&&pb<0){
    //printf("%lld %lld < %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
    return -1;
  }
  if(pa<0&&pb>0){
    //printf("%lld %lld > %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
    return 1;
  }
  if(pa>0){
    pa=dotproduct(base,va)*baselen(vb);
    pb=dotproduct(base,vb)*baselen(va);
    //printf("<%lld %lld>\n",pa,pb);
    if(pa>pb){
      //printf("%lld %lld < %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
      return -1;
    }
    if(pa<pb){
      //printf("%lld %lld > %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
      return 1;
    }
    //printf("%lld %lld == %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
    return 0;
  }
  else{
    pa=dotproduct(base,va)*baselen(vb);
    pb=dotproduct(base,vb)*baselen(va);
    //printf("[%lld %lld]\n",pa,pb);
    if(pa>pb){
      //printf("%lld %lld > %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
      return 1;
    }
    if(pa<pb){
      //printf("%lld %lld < %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
      return -1;
    }
    //printf("%lld %lld == %lld %lld\n",va.xz,va.yz,vb.xz,vb.yz);
    return 0;
  }
}

int main(void){
  long long i,j,n,m,k,a,b,c,h,w,r=0,l,t,st,fi;
  double res=0.0;
  point pts[2048],mp[2048];
  scanf("%lld",&n);
  c=0;
  for(i=0;i<n;i++){
    scanf("%lld%lld",&pts[c].xz,&pts[c].yz);
    mp[c]=pts[c];
    if(pts[c].xz==0 && pts[c].yz==0){c--;}
    c++;
  }
  base.xz=10000000;
  base.yz=0;
  if(c==0){printf("%.12lf\n",0.0);return 0;}
  for(t=0;t<c;t++){
    base=mp[t];
    qsort(pts,c,sizeof(pts[0]),vecsortfnc);
    for(i=0;i<c;i++){
      a=0;b=0;
      for(j=0;j<c;j++){
        a+=pts[(i+j)%c].xz;
        b+=pts[(i+j)%c].yz;
        res=dbmax(sqrt(a*a+b*b),res);
      }
    }
  }
  printf("%.12lf\n",res);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e15;
constexpr const ll MOD = 1000000007;
constexpr const ll MAX = 1e9;
constexpr ll nx[4] = {1,0,-1,0};
constexpr ll ny[4] = {0,1,0,-1};
typedef pair<ll,ll> P;
vector<int> t_sort(vector<vector<int>> &g){
    vector<int> res,cnt(g.size(),0);
    queue<int> q;
    rep(i,g.size()){
        for (int e:g[i]){
            cnt[e]++;
        }
    }
    rep(i,g.size()){
        if (cnt[i] == 0) q.push(i);
    }
    while(!q.empty()){
        int v = q.front();q.pop();
        res.push_back(v);
        for (int u:g[v]){
            cnt[u]--;
            if (cnt[u] == 0){
                q.push(u);
            }
        }
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v,e,s,t;
    cin >> v >> e;
    vector<vector<int>> g(v);
    rep(i,e){
        cin >> s >> t;
        g[s].push_back(t);
    }
    vector<int> k = t_sort(g);
    rep(i,v){
        PRINT(k[i]);
    }
}



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

int main(){
    int n;
    cin >>n;
    bool ans=false;
    int buf,max,sum=0;
    max = 0;
    for(int i=0;i<n;i++){
        cin>>buf;
        sum += buf;
        if(max<buf){
            max = buf;
        }
    }
    if(sum>max*2){
        ans = true;
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{

        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def solve():

    A, B, K = map(int, input().split())

    list = []

    for i in range(1, min(A, B) + 1):
        if A % i == 0 and B % i == 0:
            list.append(i)
    print(list[len(list)-K])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <functional>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using string_view = boost::string_ref;

#include <boost/function_output_iterator.hpp>

using namespace std;

struct edge_t {
    int a,b;
};

vector<int> neighbour(const vector<edge_t>& edges, int k)
{
    vector<int> neighbour_k;
    neighbour_k.reserve(edges.size());
    
    for(const auto& e : edges)
    {
        if(e.a == k) neighbour_k.push_back(e.b);
        else if(e.b == k) neighbour_k.push_back(e.a);
    }
    
    sort(begin(neighbour_k), end(neighbour_k));
    
    return neighbour_k;
}

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

    int n,m;
    cin >> n >> m;
    
    vector<edge_t> edges(m);
    for(auto& e : edges) cin >> e.a >> e.b;
    
    const auto neighbour_1 = neighbour(edges, 1);
    const auto neighbour_n = neighbour(edges, n);
    
    size_t count = 0;
    
    set_intersection(
        begin(neighbour_1), end(neighbour_1),
        begin(neighbour_n), end(neighbour_n),
        boost::make_function_output_iterator([&](const auto){ count++; }));
    
    if(count == 0)
    {
        cout << "IMPOSSIBLE\n";
    }
    else
    {
        cout << "POSSIBLE\n";
    }

    return 0;
}



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

using namespace std;

typedef long long 		ll;
typedef vector<ll> 		vll;
typedef pair<ll,ll> 	pll;
typedef vector<pll> 	vpll;
typedef vector<int> 	vi;
typedef pair<int,int> 	pii;
typedef vector<pii> 	vpii;

#define fi				first
#define se 				second
#define pb 				push_back
#define mp 				make_pair
#define all(v)			v.begin(),v.end()
#define sz(v)			s.size()
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define per(i,a,b) 		for(int i=a;i>=b;i--)
#define fill(a,v)		memset(a,v,sizeof(a))
#define tc				int T;cin>>T;while(T--)
#define nl				printf("\n")
#define aya				printf("yaha aya\n")
#define debug(x,y)		printf("%d %d\n",x,y)
#define fast_io			ios_base::sync_with_stdio(false);cin.tie(NULL);
#define grt				greater<int>()

const int mod = 1e9+7;
const int mod2= 1e9+9;

inline int pow_(ll a, int n, int p=mod){
	int r=1;while(n){if(n&1)r=r*a%p;n>>=1;a=a*a%p;}return r;
}

int main(void)
{
	int n;cin>>n;
	double p[n];
	rep(i,0,n-1) cin>>p[i];
	double dp[n+2][n+10];
	fill(dp,0);
	dp[0][0] = p[0];
	dp[0][1] = 1 - p[0];

	rep(i,1,n-1)
	{
		double prob = p[i];
		double prob_not = 1 - prob;

		rep(j,0,n)
		{
			dp[i][j] = dp[i-1][j]*prob + (j>0 ? dp[i-1][j-1]*prob_not : 0);
		}
	}
	double ans = 0;
	rep(i,0,n/2) ans += dp[n-1][i];

	cout<<fixed<<setprecision(10)<<ans;
}

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

int main() {
	int x_1,x_2,y_1,y_2;
	cin >> x_1 >> y_1 >> x_2 >> y_2;
	int temp1 = x_2 - x_1;
	int temp2 = y_2 - y_1;
	int x_3,y_3,x_4,y_4;
	y_4 = y_1 + temp1;
	x_4 = x_1 - temp2;
	y_3 = y_2 + temp1;
	x_3 = x_2 - temp2;
	cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl;
	return 0;
}


Measured memory_bytes: 256
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0]*2 for _ in range(N+1)]

for i in range(N-1, -1, -1):
    Y = W if i==0 else a[i-1]
    dp[i][0] = abs(a[N-1]-Y)
    
    for j in range(i+1, N):
        dp[i][0] = max(dp[i][0], dp[j][1])
    
    X = Z if i==0 else a[i-1]
    dp[i][1] = abs(a[N-1]-X)
    
    for j in range(i+1, N):
        dp[i][1] = min(dp[i][1], dp[j][0])

print(dp[0][0])

Measured memory_bytes: 45092
#include <stdio.h>

int main(int argc,char *args[]){
    int i,j,h,w;

    while(1){
        scanf("%d %d",&h,&w);
        if(h==0 && w==0) break;
        //first border
        for(i=0;i<w;i++) printf("#");
        printf("\n");

        for(i=0;i<h-2;i++){
            printf("#");
            for(j=0;j<w-2;j++){
                printf(".");
            }
            printf("#\n");
        }

        //last border
        for(i=0;i<w;i++) printf("#");
        printf("\n\n");
    }
    return 0;
}



Measured memory_bytes: 2104
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, A: "List[int]", B: "List[int]"):
    res = 0
    for i in range(N-1, -1, -1):
        A[i] += res
        res += B[i]*math.ceil(A[i]/B[i]) - A[i]
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16956
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if ((a+b)>(c+d))
            System.out.println("Left");
        else if((a+b)<(c+d))
            System.out.println("Right");
        else
            System.out.println("Balanced");
    }
}


Measured memory_bytes: 35552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
vector<int> to[100010];
ll cal(ll a){
    return a*a*a*a*a;
}
int main(void){
    ll x;
    cin>>x;
    ll v[2001];
    for(ll i=0;i<=2000;i++){
        v[i]=cal(i);
    }
    bool ok=false;
    for(ll b=0;v[b]<=x;b++){
        ll y=x-v[b];
        for(ll i=0;i<=2000;i++){
            if(v[i]==y){
                cout<<i<<" "<<-b<<endl;
                return 0;
            }
        }
    }
    for(ll i=0;i<=2000;i++){
        for(ll j=i;j<=2000;j++){
            if(v[j]-v[i]==x){
                cout<<j<<" "<<i<<endl;
                return 0;
            }
        }
    }
}

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

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

	int tmp = 0;
	int maxValue;
	int maxIndex;
	vector<int> a(n); for (int i = 0; i < n; i++) { 
		
		cin >> a[i]; 
		
		if (tmp < a[i]) {
			tmp = a[i];
			maxIndex = i;
		}
	
	}

	tmp = 0;
	int secondMaxIndex;
	for (int i = 0; i < n; i++) {

		if (i == maxIndex) continue;

		if (tmp < a[i]) {
				tmp = a[i];
				secondMaxIndex = i;
		}
	}
	
	for (int i = 0; i < n; i++) {

		if (i == maxIndex) {
			cout << a[secondMaxIndex] << endl;
		}
		else { // i != maxIndex
			cout << a[maxIndex] << endl;
		}	

	}

	return 0;
}

Measured memory_bytes: 2432
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func pow(x, y int) int {
	ret := 1
	for i := 0; i < y; i++ {
		ret *= x
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	fmt.Println(pow(nextInt(), 3))
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int mod = 1e6+2;

main(){
    int n;cin>>n;
    if(n==1){
        cout<<"1";
        exit(0);
    }
    int a[n];
    int countof[mod] = {0};
    int flag = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        countof[a[i]]++;
        if(a[i] == 1) flag++;
    }
    if(flag==1){
        cout<<"1";
    }
    else if(flag>1){
        cout<<"0";
    }
    else{
        int value,temp = 2;
        int maxi = *max_element(a,a+n);
        int mark[mod] = {0};
        sort(a,a+n);
        for(int i =0;i<n;i++){
            value = a[i]*2;
            while(value <= maxi){
                mark[value] = 1;
                value+= a[i];
            }
        }
        int count = 0;
        for(int i=0;i<n;i++){
            if(mark[a[i]] == 0 && (countof[a[i]] == 1)) count++;
        }
        cout<<count;
    }
}

Measured memory_bytes: 12072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
// map<int,int> mp;

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

  vector<int> A(N), B(N), C(N);
  REP(i, N) cin >> A.at(i);

  REP(i, N) cin >> B.at(i);
  REP(i, N) cin >> C.at(i);

 int ans=B[A[0]-1];
 
for(int i = 1; i < N; i++) {
  ans += B[A[i]-1];
  if(A[i]-A[i-1]==1){
    
    ans +=C[A[i]-2];

  }

  }

  cout << ans << endl;
}




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

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

    std::cout<<(n % [](int k) -> int {
            int res = 0;
            while(k > 0){
                res += k % 10;
                k /= 10;
            }
            return res;
    }(n) == 0 ? "Yes" : "No")<<std::endl;
    return 0;
}

Measured memory_bytes: 256
// Last Change: 06/17/2019 19:02:50.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int X, A;
  cin >> X >> A;
  if (X < A) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 888
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  string A;
  cin >>A;
  if(A =="ABC"){
    cout <<"ARC";
  }
  else{
    cout <<"ABC";
  }
}

Measured memory_bytes: 3596
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
int dy[] = {0, -1, 0, 1};
int dx[] = {1, 0, -1, 0};

llong h, w, black = 0, white = 0;
char field[401][401];
bool visited[401][401];

llong dfs_b(llong i, llong j, llong n) {
    ++n;
    visited[i][j] = true;

    if (n % 2) {
        rep(k, 4) {
            if (0 <= i + dx[k] && i + dx[k] <= h - 1 && 0 <= j + dy[k] && j + dy[k] <= w - 1 && field[i + dx[k]][j + dy[k]] == '.' && visited[i + dx[k]][j + dy[k]] == false) {
                ++white;
                dfs_b(i + dx[k], j + dy[k], n);
            }
        }
    } else {
        rep(k, 4) {
            if (0 <= i + dx[k] && i + dx[k] <= h - 1 && 0 <= j + dy[k] && j + dy[k] <= w - 1 && field[i + dx[k]][j + dy[k]] == '#' && visited[i + dx[k]][j + dy[k]] == false) {
                ++black;
                dfs_b(i + dx[k], j + dy[k], n);
            }
        }
    }
    return (black + 1) * white;
}

llong dfs_w(llong i, llong j, llong n) {
    ++n;
    visited[i][j] = true;

    if (n % 2) {
        rep(k, 4) {
            if (0 <= i + dx[k] && i + dx[k] <= h - 1 && 0 <= j + dy[k] && j + dy[k] <= w - 1 && field[i + dx[k]][j + dy[k]] == '#' && visited[i + dx[k]][j + dy[k]] == false) {
                ++black;
                dfs_w(i + dx[k], j + dy[k], n);
            }
        }
    } else {
        rep(k, 4) {
            if (0 <= i + dx[k] && i + dx[k] <= h - 1 && 0 <= j + dy[k] && j + dy[k] <= w - 1 && field[i + dx[k]][j + dy[k]] == '.' && visited[i + dx[k]][j + dy[k]] == false) {
                ++white;
                dfs_w(i + dx[k], j + dy[k], n);
            }
        }
    }
    return black * (white + 1);
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> h >> w;
    rep (i, h) {
        string s;
        cin >> s;
        rep (j, s.size()) {
            field[i][j] = s[j];
        }
    }

    llong ans = 0;
    memset(visited, false, sizeof(visited));
    rep(i, h) {
        rep(j, w) {
            if (visited[i][j]) continue;
            if (field[i][j] == '.') {
                ans += dfs_w(i, j, 0);
            } else {
                ans += dfs_b(i, j, 0);
            }
            black = 0, white = 0;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int N, M;
vector<vector<int>> G(100000);
vector<int> dp(100000, -1);

int rec(int v) {
  if (dp[v] != -1) return dp[v];

  int res = 0;
  for (auto nv : G[v]) res = max(res, rec(nv) + 1);
  return dp[v] = res;
}

int main() {
  cin >> N >> M;
  // G.assign(N, vector<int>());

  int x, y;
  REP(i,M) {
    cin >> x >> y;
    G[x-1].push_back(y-1);
  }

  int res = 0;
  REP(i,N) res = max(res, rec(i));
  cout << res << endl;
}

Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long n = array[0];
			long m = array[1];
			long count = 0;
			if (n == 1 && m == 1) {
				count = 1;
			} else if (n == 1) {
				count = m - 2;
			} else if (m == 1) {
				count = n - 2;
			} else {
				count = (n - 2) * (m - 2);
			}

			Console.WriteLine($"{count}");

			Console.ReadLine();
		}
	}
}

Measured memory_bytes: 13396
N=int(input())
S=[]
for i in range(N):
    S.append(input())
M=int(input())
T=[]
for i in range(M):
    T.append(input())
K=[0]
for i in S:
    K.append(S.count(i)-T.count(i))

    
print(max(K))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<pair<pair<string,int>,int>> a(n);
    for (int i=0;i<n;i++){
        cin >> a.at(i).first.first >> a.at(i).first.second;
        a.at(i).first.second*=(-1);
        a.at(i).second=i;
    }
    sort(a.begin(),a.end());
    for (int i=0;i<n;i++){
        cout << a.at(i).second+1 << endl;
    }
}


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

int main(){
  int n; cin>>n;
  vector<int>v(2*n);
  for(int i=0;i<2*n;i++) cin>>v[i];
  sort(v.begin(),v.end());
  int ans=0;
  for(int i=0;i<2*n;i+=2) ans+=v[i];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll X;
  cin >> X;
  vector<ll> v;
  v.pb(0);
  for(ll i=1;;i++){
    ll div = i;
    v.pb(div+v[i-1]);
    if(v[i]>1000000000) break;
  }
  for(int i=0;i<(int)v.size(); i++){
    if(v[i]>=X) {cout << i << endl; return 0;}
  }
  return 0;
}


Measured memory_bytes: 892
primes = 2 : 3 : 5 : primes'
  where
    isPrime (p:ps) n = p*p > n || n `rem` p /= 0 && isPrime ps n
    primes' = 7 : filter (isPrime primes') (scanl (+) 11 $ cycle [2,4,2,4,6,2,6,4])

decomp 1 _ = []
decomp n (p:ps) = 
    if n < p*p
    then [n]
    else if r == 0
         then p:(decomp n' (p:ps))
         else decomp n ps
    where
        r = n `mod` p
        n' = n `div` p

ans n = 
     let d = decomp n primes
     in
         (show n) ++ ": " ++ (unwords $ map show d)

main = do
    n <- getLine
    let i = read n :: Int
        o = ans i
    putStrLn o




Measured memory_bytes: 4272
#include <stdio.h>
#define MIN(x,y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))

int main() {
  int n;
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 5 != 0 && i % 3 != 0) {
      sum += i;
    }
  }
  printf("%lld", sum);
  return 0;
}

Measured memory_bytes: 2152
#include<cstdio>
#include<iostream>
#define MAX 10000
#define NIL -1
using namespace std;

struct N{
  int p , l, r;
};

N T[MAX];
int n,D[MAX],H[MAX];

/////// 再帰的に深さを求める　//////////////////////////////////
int setDepth(int r,int p){
  D[r]= p;
  if(T[r].l !=NIL){
    setDepth(T[r].l,p+1);
  }
  if(T[r].r != NIL){
    setDepth(T[r].r,p+1);
  }
}
/////////////////////////////////////////////////////////////

int setHeight(int u){
  int h1 = 0 , h2=0;
  if(T[u].r !=NIL){
    h1=setHeight(T[u].r)+1;
  }
  if(T[u].l !=NIL){
    h2 =setHeight(T[u].l)+1;
  }
  return H[u] = max(h1,h2);
}
//////////////////////////////////////////////////////////////

int getSibling(int u){
  if(T[u].p== NIL){
    return NIL;
  }
  if(T[T[u].p].l != u && T[T[u].p].l != NIL){
    return T[T[u].p].l;
  }
  if(T[T[u].p].r != u && T[T[u].p].r != NIL){
    return T[T[u].p].r;
  }
  return NIL;
}
//////////////////////////////////////////////////////////

void print(int u){
  cout << "node " << u << ": "<< "parent = " << T[u].p << ", "<<"sibling = "<<getSibling(u)<<", ";
  int d = 0;
  if(T[u].l != NIL) d++;
  if(T[u].r != NIL) d++;
  cout<<"degree = "<< d <<", "<< "depth = "<<D[u]<<", "<<"height = "<<H[u]<<", ";

  if(T[u].p== NIL) cout<<"root"<<endl;
  else if(T[u].l==NIL && T[u].r== NIL) cout<< "leaf"<<endl;
  else cout<<"internal node"<<endl;
}
///////////////////////////////////////////////

int main(){
  int n,a,b,c;
  int root=0;
  cin >> n;
  for(int i=0; i<n ; i++){
    T[i].p= NIL;
  }

  for(int i=0;i<n;i++){
  cin>> a >> b >> c;
  T[a].l=b;
  T[a].r=c;
  if(b != NIL) T[b].p=a;
  if(c != NIL) T[c].p=a;
  }

  for(int i=0 ; i <n ;i++){
    if(T[i].p == NIL){
      root = i ;
    }
  }
  setDepth(root,0);
  setHeight(root);
  for(int i=0; i<n ; i++){
    print(i);
  }

  return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,a,b,c,d;
  scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
  printf("%d\n",n-MAX((a-1)/c,(b-1)/d)-1);
  return 0;
}
  

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#ifdef _MSC_VER
inline unsigned int __builtin_popcount(unsigned int x) { return __popcnt(x); }
#endif // _MSC_VER
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
string X;
int cnt[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> X;

	if (N == 1) {
		if (X == "0") cout << 1 << endl;
		else cout << 0 << endl;
		return;
	}

	reverse(all(X));
	rep(i, 1, 201010) {
		int pp = __builtin_popcount(i);
		cnt[i] = cnt[i % pp] + 1;
	}

	int cn = 0;
	rep(i, 0, N) if (X[i] == '1') cn++;

	if (cn == 0) {
		rep(i, 0, N) printf("1\n");
	}
	else if (cn == N) {
		int tot = 0, p = 1;
		rep(i, 0, N) {
			if (X[i] == '1') tot = (tot + p) % (N - 1);
			p = (p * 2) % (N - 1);
		}
		rep(i, 0, N) printf("%d\n", cnt[tot] + 1);
	}
	else if (cn == 1) {
		vector<int> ans;
		int tot1 = 0, p1 = 1;
		rep(i, 0, N) {
			if (X[i] == '1') tot1 = (tot1 + p1) % (cn + 1);
			p1 = (p1 * 2) % (cn + 1);
		}

		p1 = 1;
		rep(i, 0, N) {
			if (X[i] == '1') {
				ans.push_back(0);
			}
			else {
				int x = (tot1 + p1 + cn + 1) % (cn + 1);
				ans.push_back(cnt[x] + 1);
			}
			p1 = (p1 * 2) % (cn + 1);
		}

		reverse(all(ans));
		rep(i, 0, N) printf("%d\n", ans[i]);
	}
	else {
		vector<int> ans;
		int tot1 = 0, p1 = 1;
		int tot2 = 0, p2 = 1;
		rep(i, 0, N) {
			if (X[i] == '1') tot1 = (tot1 + p1) % (cn + 1);
			p1 = (p1 * 2) % (cn + 1);

			if (X[i] == '1') tot2 = (tot2 + p2) % (cn - 1);
			p2 = (p2 * 2) % (cn - 1);
		}

		p1 = 1;
		p2 = 1;
		rep(i, 0, N) {
			if (X[i] == '1') {
				int x = (tot2 - p2 + cn - 1) % (cn - 1);
				ans.push_back(cnt[x] + 1);
			}
			else {
				int x = (tot1 + p1 + cn + 1) % (cn + 1);
				ans.push_back(cnt[x] + 1);
			}
			p1 = (p1 * 2) % (cn + 1);
			p2 = (p2 * 2) % (cn - 1);
		}

		reverse(all(ans));
		rep(i, 0, N) printf("%d\n", ans[i]);
	}
}







Measured memory_bytes: 5216