akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 25

struct Tree{
  int id;
  int left,right;
  int p,s;
  int dep,deg;
  int h;
};

int main(){
  int in,n,i,s1,s2;
  int pa,pc,hc,he;

  struct Tree tree[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    tree[i].p=-1;
    tree[i].s=-1;
    tree[i].deg=0;
    tree[i].h=0;
  }

  for(i=0;i<n;i++){
    scanf("%d",&in);
    tree[in].id=in;
    scanf("%d %d",&tree[in].left,&tree[in].right);
    if(tree[in].left!=-1&&tree[in].right!=-1){
      tree[in].deg=2;
    }else if(tree[in].left!=-1||tree[in].right!=-1){
      tree[in].deg=1;
    }

    s1=tree[in].left;
    s2=tree[in].right;
    tree[s1].p=tree[in].id;
    tree[s2].p=tree[in].id;
    tree[s1].s=s2;
    tree[s2].s=s1;
  }

  for(i=0;i<n;i++){
    if(tree[i].p==-1){
      tree[i].dep=0;
    }else{
      pa=tree[i].p;
      pc=1;
    
      while(tree[pa].p!=-1){
	pc++;
	pa=tree[pa].p;
      }
      tree[i].dep=pc;
    }
  }



  for(i=0;i<n;i++){
    if(tree[i].deg==0){
      hc=0;
      tree[i].h=hc;
      pa=tree[i].p;

      while(pa!=-1){
	hc++;
	if(tree[pa].h<=hc){
	  tree[pa].h=hc;
	  pa=tree[pa].p;
	}
      }
    }
  }

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,",i,tree[i].p,tree[i].s,tree[i].deg,tree[i].dep,tree[i].h);
    if(tree[i].p==-1){
      printf(" root\n");
    }else if(tree[i].left==-1&&tree[i].right==-1){
      printf(" leaf\n");
    }else{
      printf(" internal node\n");
    }
  }

  return 0;
}

Measured memory_bytes: 612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    if((B-A)%2==0)cout<<"Alice"<<endl;
    else if((B-A)%2==1)cout<<"Borys"<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(void){
    int X;
    cin>>X;
    while(true){
        if(IsPrime(X)){
            cout<<X<<endl;
            break;
        }
        X++;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 200000

int max(int a,int b){return a>b ? a:b;}
int min(int a,int b){return a<b ? a:b;}

int main(void){
    int R[MAX],i,n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&R[i]);
    }
    
    int maxv=-2000000000;
    int minv=R[0];
    
    for(int i=1; i<n; i++){
        maxv = max(maxv,R[i]-minv);
        minv = min(minv,R[i]);
    }
    printf("%d\n",maxv);
    
    return 0;
}


Measured memory_bytes: 2624
#include <bits/stdc++.h>
#define ri register int
#define ll long long
using namespace std;

int read()
{
    int num=0;
    int flg=1;
    char c=getchar();
    while(!isdigit(c))
    {
        if(c=='-')
        {
            flg=-1;
        }
        c=getchar();
    }
    while(isdigit(c))
    {
        num=(num<<1)+(num<<3)+(c^48);
        c=getchar();
    }
    return num*flg;
}

int main()
{
    return 0&(int)puts(abs(read()-read())<=1?"Brown":"Alice");
}

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

template<typename T>
struct CumulativeSum2D {
    vector<vector<T>> acc;
    CumulativeSum2D(int h = 0, int w = 0) : acc(h + 1, vector<T>(w + 1)) { }
    void add(int i, int j, T x) { acc[i + 1][j + 1] += x; }
    void build() {
        int H = acc.size(), W = acc[0].size();
        for (int i = 1; i < H; i++) for (int j = 1; j < W; j++) {
            acc[i][j] += acc[i][j - 1] + acc[i - 1][j] - acc[i - 1][j - 1];
        }
    }
    T sum(int si, int sj, int ti, int tj) {     // [si, ti) x [sj, tj)
        return acc[ti][tj] - acc[si][tj] - acc[ti][sj] + acc[si][sj];
    }
};

template <typename T>
vector<T> uni(vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}

template<typename T>
int compressed(vector<T> &a) {
    vector<T> b = a;
    sort(begin(b), end(b)); b.erase(unique(begin(b), end(b)), end(b));
    for (T &ai: a) ai = lower_bound(begin(b), end(b), ai) - begin(b);
    return b.size();
}

int main() {
    int n, m; cin >> n >> m;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    auto numX = uni(x), numY = uni(y);
    int sx = compressed(x), sy = compressed(y);
    CumulativeSum2D<int> acc(sx, sy);
    for (int i = 0; i < n; i++) acc.add(x[i], y[i], 1);
    acc.build();
    for (int i = 0; i < m; i++) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        x1 = lower_bound(begin(numX), end(numX), x1) - begin(numX);
        y1 = lower_bound(begin(numY), end(numY), y1) - begin(numY);
        x2 = upper_bound(begin(numX), end(numX), x2) - begin(numX);
        y2 = upper_bound(begin(numY), end(numY), y2) - begin(numY);
        cout << acc.sum(x1, y1, x2, y2) << endl;
    }
    return 0;
}


Measured memory_bytes: 100764
h,w,k=map(int,input().split())

T=[]
for i in range(h):
    c=input()
    T.append(list(c))
    
ans=[[0 for i in range(w)]for q in range(h)]

flg=False
level=0
now=0
k=0
for i in range(h):
    now=0
    level+=1
    for q in range(w):
        if T[i][q]==".":
            ans[i][q]=level
        else:
            ans[i][q]=level
            level+=1
            now=q+1
    else:
        if now==0:
            if i==k:
                flg=True
                level-=1
                k+=1
            else:               
                for q in range(w):
                    ans[i][q]=ans[i-1][q]
                level-=1
        else:
            level-=1
            for q in range(now,w):
                ans[i][q]=level
                #print(i,q)
                
if flg:
    for i in range(k):
        for q in range(w):
            ans[i][q]=ans[k][q]

ans=[[str(ans[q][i]) for i in range(w)]for q in range(h)]

for i in range(h):
    print(" ".join(ans[i]))

Measured memory_bytes: 13172
package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	a := make([]int, n+1)
	for i := range a {
		a[i] = ri()
	}
	b := make([]int, n)
	for i := range b {
		b[i] = ri()
	}
	a = append(a, 0)
	b = append(b, 0)
	ct := 0
	for i := 0; i <= n; i++ {
		if b[i] <= a[i] {
			ct += b[i]
			b[i] = 0
		} else {
			ct += a[i]
			b[i] -= a[i]
			a[i] = 0
			if b[i] <= a[i+1] {
				ct += b[i]
				a[i+1] -= b[i]
			} else {
				ct += a[i+1]
				b[i] -= a[i+1]
				a[i+1] = 0
			}
		}
	}
	fmt.Println(ct)
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int A,B,C;
	cin>>A>>B>>C;
	lli K;
	cin>>K;
	if(K%2==0)cout<<A-B;
	else cout<<B-A;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;
using Graph = vector<vector<int>>;

// 難しいね
int main()
{
    // input
    int n;
    cin >> n;
    vector<queue<int>> q(n+1);
    rep2(i,1,n+1){
        int id, num;
        cin >> id >> num;
        rep(j,num){
            int temp;
            cin >> temp;
            q[i].push(temp);
        }
    }


    // solve
    vector<int> d(n+1), f(n+1);
    stack<int> place;
    place.push(1);
    int time = 0;
    while(place.size()){
        int now = place.top();
        if(!d[now]) d[now] = ++time;

        while(q[now].size()){
            if(!d[q[now].front()]){
                place.push(q[now].front());
                q[now].pop();
                break;
            }else{
                q[now].pop();
            }
        }
        if(now == place.top()){
            place.pop();
            f[now] = ++time;
        }
        if(place.size() == 0){
            rep2(i,1,n+1){
                if(d[i]==0){place.push(i); break;}
            }
        }
    }

    // output
    rep2(i,1,n+1) cout << i << " " << d[i] << " " << f[i] << endl;
    return 0;
}


Measured memory_bytes: 3180
#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>;

int f(int x) {
  int res = 0;
  while (x % 2 == 0) {
    x /= 2;
    ++res;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n) ans += f(a[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int x, a, ans = 10;

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> x >> a;
	if( x < a )
	{
		ans = 0;
	}
	cout << ans << "\n";	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// << fixed << setprecision
// --------------------------------------
string s;
int k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> k;
  REP(i, k) cout << "ACL";
  cout << endl;
}


Measured memory_bytes: 3588
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

// 約数の列挙 O(√n)
vector<ll> divisor(ll n) {
    vector<ll> res;

    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }

    return res;
}

int main() {
    INIT;
    ll S;
    cin >> S;

    if (S == 1000000000000000000LL) {
        cout << 0 << " " << 0 << " " << 1000000000LL << " " << 0 << " " << 0
             << " " << 1000000000LL << endl;
        return 0;
    }

    ll x2 = 1000000000LL;
    ll y3 = S / 1000000000LL + 1LL;
    ll xy = y3 * 1000000000LL - S;
    vector<ll> divs = divisor(xy);
    // repv(divs) { cout << *it << " "; }
    // cout << endl;

    ll x3 = divs[SZ(divs) - 1];
    ll y2 = xy / x3;
    cout << 0 << " " << 0 << " " << x2 << " " << y2 << " " << x3 << " " << y3
         << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int n, r;

struct U {
  int a[333333];
  U() {
    memset(a, -1, sizeof(a));
  }
  int root(int p) {
    return a[p] < 0 ? p : (a[p] = root(a[p]));
  }
  bool same(int p, int q) {
    return root(p) == root(q);
  }
  bool merge(int p, int q) {
    if (same(p, q)) return false;
    p = root(p);
    q = root(q);
    a[p] += a[q];
    a[q] = p;
    return true;
  }
  int sz(int p) {
    return -a[root(p)];
  }
};

U uni;
int cnt[333333];
bool used[333333];
int m;
int a[333333], b[333333];
int dp[333333];

int main(void) {
  scanf("%d%d", &n, &r);
  for (int i = 0; i < n; i++) {
    int x; scanf("%d", &x); --x;
    uni.merge(i, x);
  }

  for (int i = 0; i < n; i++) {
    int r = uni.root(i);
    if (!used[r]) {
      cnt[uni.sz(i)] += 1;
      used[r] = true;
    }
  }

  for (int i = 0; i < n; i++) {
    if (cnt[i]) {
      a[m] = i;
      b[m] = cnt[i];
      // printf("%d: %d %d\n", m, i, cnt[i]);
      ++m;
    }
  }

  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j <= r; j++) {
      if (dp[j] >= 0) dp[j] = b[i];
      else if (j < a[i] || dp[j - a[i]] <= 0) dp[j] = -1;
      else dp[j] = dp[j - a[i]] - 1;
    }
  }

  puts(dp[r] >= 0 ? "Yes" : "No");

  return 0;
}



Measured memory_bytes: 5536
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(void) {
    string s, t; cin >> s >> t;
    int count = 0;
    for (int i = 0; i < 3; i++)
        if(s[i] == t[i]) count++;
    cout << count << endl;
}

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

for i in range(0,N-1):
    if A[i+1] == A[i]+1:
        ans += C[A[i]-1]

print(ans)

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

constexpr int INF = 1e8;

int main() {
    int N, M; cin >> N >> M;
    vector<int> bridge(N+1, INF);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        bridge[a] = min(bridge[a], b-1);
    }
    int ans = 0;
    int right = INF;
    for (int i = 1; i <= N; i++) {
        right = min(right, bridge[i]);
        if (i == right) {
            ans++;
            right = INF;
        }
    }
    cout << ans << endl;
}


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

int main(){
    double bw,bh,sw,sh,x,y;
    cin >> bw >> bh >> sw >> sh >> x >> y;
    double midx = (x -sw/2 +min(x +sw/2, bw/2) ) /2;
    double midy = (y -sh/2 +min(y +sh/2, bh/2) ) /2;
    cout << fixed << setprecision(10);
    cout << midy /midx << endl;
    return 0;
}



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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    if(max(a,c)-min(a,c)<=d) cout<<"Yes"<<endl;
    else if(max(a,b)-min(a,b)<=d && max(b,c)-min(b,c)<=d) cout << "Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> Hi;
  rep(i,N){
    int tmpHi;
    cin >> tmpHi;
    Hi.push_back(tmpHi);
  }
  
  bool ans = true;
  reverse(Hi.begin(), Hi.end());
    
  int Hi_L = Hi.at(0);
  int Hi_R = Hi.at(0);
  rep(i,N-1){
    Hi_L = Hi.at(i);
    Hi_R = Hi.at(i+1);
 
    if(Hi_L >= Hi_R){
      //何もしない
    }else if(Hi_L == (Hi_R - 1)){
		Hi.at(i+1)--;
    }else{
      ans = false;
      break;
    }
  } 
  
  
  if(ans){
    cout << "Yes" << endl;     
  }else{
    cout << "No" << endl;    
  }

  return 0;
}



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

int fib(int n){
  int n1,n2,t;
  n1 = n2 = t = 1;
  for(int i = 1;i < n;i++){
    t = n1 + n2;
    n1 = n2;
    n2 = t;
  }

  return t;
}

int main(){
  int n;

  cin >> n;
  cout << fib(n) << endl;

  return 0;
}

  



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

using namespace std;

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

long long lcm(int a, int b)
{
	return 1LL * a / gcd(a, b) * b;
}

long long solve(int N, int M, const string &S, const string &T)
{
	const int g = gcd(N, M);
	for (int i = 0, j = 0; i < N && j < M; i += N / g, j += M / g) {
		if (S[i] != T[j]) {
			return -1;
		}
	}
	return lcm(N, M);
}

int main()
{
	int N, M;
	string S, T;
	cin >> N >> M >> S >> T;
	cout << solve(N, M, S, T) << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int r = read(), D = read(), x = read();
    for (int i = 0; i < 10; i++) {
        x = r * x - D;
        printf("%d\n", x);
    }
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

  int N; cin>>N;
  string S; cin>>S;

  // 解説を見て実装
  vector<ll> R,G,B;
  rep(i,N) {
    if(S[i]=='R') R.push_back(i);
    if(S[i]=='G') G.push_back(i);
    if(S[i]=='B') B.push_back(i);
  }

  ll res = R.size()*G.size()*B.size();

  rep(i,N) for(ll j=i+2; j<N; j+=2) {
    ll center = i + (j-i)/2;
    if(S[i]!=S[j] && S[i]!=S[center] && S[j]!=S[center]) --res;
  }

  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 3720
<?php
$n = intval(fgets(STDIN));
$str = trim(fgets(STDIN));
$Q = intval(fgets(STDIN));

$seg = new SegTree($n);
function op($a, $b){return $a | $b;}

for($i = 0; $i < $n; $i++){
  $seg->set($i, 1<<(ord($str[$i])-97));
}
while($Q--){
  list($q, $a, $b) = explode(" ", trim(fgets(STDIN)));
  if($q == "1"){
    $seg->set($a-1, 1<<(ord($b)-97));
  }else{
    $ret[] = popcount($seg->get($a-1, $b));
  }
}
echo implode("\n", $ret);


class SegTree{
  public $tree;
  public $bits;
  function __construct($n){
    $this->bits = max(1, ceil(log($n)/log(2)));
    for($i = 0; $i < $this->bits; ++$i){
      $this->tree[$i] = array_fill(0, 2**($this->bits-$i), 0);
    }
  }
  function set($i, $amount){
    $this->tree[0][$i] = $amount;
    for($j = 1, $J = $this->bits; $j < $J; ++$j){
      $this->tree[$j][$i>>$j] = $this->tree[$j-1][$i>>$j<<1] | $this->tree[$j-1][($i>>$j<<1) + 1];
    }
  }
  function get($f, $t){
    $sum = 0;
    $tree = $this->tree;
    $bits = $this->bits;
    $i = 0;
    while($f!=$t){
      $treei = $tree[$i];
      if(($f >> $i) & 1 == 1){
        $sum |= $treei[$f>>$i];
        $f+=1<<$i;
      }
      if(($t >> $i) & 1 == 1){
        $sum |= $treei[($t>>$i)-1];
        $t-=1<<$i;
      }
      ++$i;
    }
    return $sum;
  }
}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 39544
input = gets.to_i
num = gets.to_s.split(" ").map(&:to_i)
@count = []
@result = []
for i in 0..input-2 do
  if num[i] >= num[i+1]
      @count << 1
    else
      @count << 0
  end
end

i = 0
t = 0

  while @count[i] != nil do
    if @count[i] > 0
        t = t + 1
        @result << t
    end
    if @count[i] == 0
      t = 0
    end
    i += 1  
  end
    t = 0

if @result[0] == nil
  print 0
end

if @result != nil
  puts @result.max
end

Measured memory_bytes: 10252
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int a[maxn];

int main() {
    int n=read();
    for(int i=1; i<n; ++i) a[read()]++;
    for(int i=1; i<=n; ++i) printf("%d\n", a[i]);
}

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

int main()
{
    int n;
    int i, key,  ans = 0;
    
    cin >> n;
    
    int d[n];
    
    for(i = 0; i < n; i++) {
        cin >> d[i];
    }
    
    sort(d, d+n);
    
    for(i = 0; i < n; i++) {
        
        if(i == 0) {
            key = d[0];
            ans++;
        } else if(d[i] != key) {
            key = d[i];
            ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

pair<int, int> A, B, C, D, E;
pair<int, int> lists[5];

int main(){
    cin >> A.second >> B.second >> C.second >> D.second >> E.second;
    A.first =  -(A.second - 1) % 10;
    B.first =  -(B.second - 1)% 10;
    C.first =  -(C.second - 1)% 10;
    D.first =  -(D.second - 1)% 10;
    E.first =  -(E.second - 1)% 10;
    lists[0] = A;
    lists[1] = B;
    lists[2] = C;
    lists[3] = D;
    lists[4] = E;
    // for (int i = 0; i < 5; i++){
    //     cout << lists[i].first << endl;
    // }
    sort(lists, lists+5);
    // for (int i = 0; i < 5; i++){
    //     cout << lists[i].first << endl;
    // }
    int num = 0;
    for (int i = 0; i < 5; i++){
        // cout << lists[i].second << endl;
        if (i != 4){
            if (i != 4){
                if (lists[i].second % 10 == 0){
                    num += lists[i].second;
                }else{
                num += lists[i].second + (10 - lists[i].second % 10);
                }
            }
        }
        else{
            num += lists[i].second;
        }
        // cout << lists[i].second << endl;
        // cout << num << endl;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const double pi=3.1415926535;

int main(){
  ll n,m,a;
  cin>>n;
  vector<int> x(n);
  rep(i,0,n-1){
    cin>>a;
    x[a-1]++;
  }
  rep(i,0,n) co(x[i]);
  
  return 0;
}

Measured memory_bytes: 4004
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int,input().split()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

if n == 2:
    print(max(a))
else:
    list1 = make_divisors(a[0])
    list2 = make_divisors(a[1])
    list1.sort()
    list2.sort()
    flag1 = 0
    cand1 = 0
    for i in range(len(list1)):
        flag1 = 0
        for j in range(n):
            if a[j] % list1[i] != 0:
                flag1 += 1
        if flag1 <= 1:
            cand1 = list1[i]
    cand2 = 0
    for i in range(len(list2)):
        flag2 = 0
        for j in range(n):
            if a[j] % list2[i] != 0:
                flag2 += 1
        if flag2 <= 1:
            cand2 = list2[i]
    print(max(cand1,cand2))

Measured memory_bytes: 63856
#import time

def main():
    S = input()
    ans = "ABC" if S == "ARC" else "ARC"
    return ans

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()

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

  vector<double> a(n);
  rep(i, n) cin >> a.at(i);
  
  double ans = 0;
  rep(i, n)
    ans += 1/a.at(i);
  
  cout << setprecision(15) << 1/ans << "\n";

}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null&&line.length()!=0) {
            	String[] str=line.split(" ");
            	int sum=Integer.parseInt(str[0])+Integer.parseInt(str[1]);
            	int i=0;
            	while(sum>0){
            		sum=sum/10;
            		i++;
            	}
            	System.out.println(i);
            }
         }
	}
}

Measured memory_bytes: 24280
import java.util.Scanner;
class Main {
  public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
for(;;) {
	int H=sc.nextInt();
	int W=sc.nextInt();
	if(H==0&&W==0)break;
	else {
		for(int a=0;a<H;a++) {
			for(int s=0;s<W;s++) {
				if((a+s)%2==0) {
					System.out.print("#");
				}
				else {
					System.out.print(".");
				}
			}System.out.println();
		}
	}System.out.println();
}
sc.close();
  }
}






Measured memory_bytes: 34456
#include<bits/stdc++.h>                          
using namespace std;
int asd(long long a,long long b)
{
	if(a==0) return b;
	else asd(b%a,a);
}
long long x[100005],a,n,ans,c[100005];
int main(){
	cin>>n>>a;
	for(int i=1;i<=n;i++)
	    cin>>x[i],c[i]=abs(x[i]-a);
	ans=c[1];
	for(int i=2;i<=n;i++)
	    ans=asd(ans,c[i]);
	cout<<ans;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int t = N;
  int c = 0;
  
  while(t > 0){
    c+=t%10,t/=10;
  }
  
  if(N%c == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int i,j,n,a,b,d=1,c,z=0;
	cin>>n>>a>>b;
	string x="1";
	d=stoi(x);
	for(i=1;i<=n;i++)
	{
		int k=0,s=0;
		
		x=to_string(d);
		c=x.size();
		for(j=0;j<c;j++)
		{
			k=x[j]-'0';
			s=s+k;
			
		}
		if(s>=a && s<=b)
		{
			z=z+d;	
		}
		d=stoi(x)+1;
	}
	cout<<z<<endl;
}

Measured memory_bytes: 3668
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		string[] s = Console.ReadLine().Split(' ');
		var a = int.Parse(s[0]);
		var b = int.Parse(s[1]);
		if(a < b) Console.WriteLine("a < b");
		if(a > b) Console.WriteLine("a > b");
		if(a == b) Console.WriteLine("a == b");
	}
}

Measured memory_bytes: 8900
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n, q;
	cin >> n >> q;
	
	vector<char> v(n + 1);
	for(int i = 1; i <= n; i++)
		cin >> v[i];
	
	vector<int> dp(n + 1);
	
	for(int i = 2; i <= n; i++){
		if(v[i] == 'C' && v[i - 1] == 'A')
			dp[i] = 1;
		dp[i] += dp[i - 1];
	}
	
	while(q--){
		int l, r;
		cin >> l >> r;
		int ans = dp[r] - dp[l - 1];
		if(l != 1 && v[l] == 'C' && v[l - 1] == 'A')
			ans--;
		
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 1408
def main():
    n = int(input())
    f = [list(map(int,input().split())) for i in range(n)]
    p = [list(map(int,input().split())) for i in range(n)]
    bit = 1<<10
    res = -10**10
    for i in range(1,bit):
        chk = [0]*n
        cnt = 0
        for j in range(10):
            if (i>>j)&1:
                for k in range(n):
                    if f[k][j] == 1:
                        chk[k] += 1
        for l in range(n):
            cnt += p[l][chk[l]]
        res = max(res,cnt)
    print(res)

if __name__ == '__main__':
    main()



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

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;

#define fr first
#define sc second
#define mp1(a,b,c) P1(a,P(b,c))
#define mp2(a,b,c,d) P2(P(a,b),P(c,d))

const ll MOD = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= MOD;
	if(k%2 == 1){
		ret *= x; ret %= MOD;
	}
	return ret;
}

template <int N = 1010>
struct UF{
	int par[N],r[N];
	UF(){
		for(int i = 0 ; i < N ; i ++){
			par[i] = i;
			r[i] = 0;
		}
	}
	void init(){
		for(int i = 0 ; i < N ; i ++){
			par[i] = i;
			r[i] = 0;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
	void unit(int x,int y){
		if(same(x,y))return;
		x = find(x);
		y = find(y);
		if(r[x] < r[y]){
			par[x] = y;
		}
		else {
			par[y] = x;
			if(r[x] == r[y]){
				r[x] ++;
			}
		}
	}
};

template <int N = 1010>
struct MST{
	vector<P2> G;
	void add_edge(int u,int v,int w,int id){
		G.push_back(mp2(w,id,u,v));
	}
	UF<N> uf;
	ll run(){
		ll ret = 0;
		//sort(G.begin(),G.end());
		for(int i = 0 ; i < G.size() ; i ++){
			if(uf.same(G[i].sc.fr,G[i].sc.sc))continue;
			ret += G[i].fr.fr;
			uf.unit(G[i].sc.fr,G[i].sc.sc);
		}
		return ret;
	}
	/*vector<int> run(){
		vector<int> ret;
		UF<N> uf;
		sort(G.begin(),G.end());
		for(int i = 0 ; i < G.size() ; i ++){
			if(uf.same(G[i].sc.fr,G[i].sc.sc))continue;
			ret.push_back(G[i].fr.sc);
			uf.unit(G[i].sc.fr,G[i].sc.sc);
		}
		return ret;
	}*/
};

int main(){
	static ll n,m;
	static ll x;
	static ll u[2002],v[2002],w[2002];
	scanf("%lld%lld%lld",&n,&m,&x);
	for(int i = 0 ; i < m ; i ++){
		scanf("%lld%lld%lld",&u[i],&v[i],&w[i]);
	}
	
	MST<1010> mst;
	for(int i = 0 ; i < m ; i ++){
		mst.add_edge(u[i],v[i],w[i],i);
	}
	sort(mst.G.begin(),mst.G.end());
	static int cnt[3] = {};
	for(int i = 0 ; i < m ; i ++){
		mst.uf.init();
		mst.uf.unit(u[i],v[i]);
		ll y = mst.run() + w[i];
		//cout << i << " " << y << endl;
		if(y < x)cnt[0] ++;
		else if(y == x)cnt[1] ++;
		else cnt[2] ++;
	}
	
	mst.uf.init();
	ll r = mst.run();
	
	ll ret;
	if(r < x)ret = 2*(modpow(2,cnt[1])-1)*(modpow(2,cnt[2]));
	else if(r == x)ret = (modpow(2,cnt[1])-2)*(modpow(2,cnt[2]));
	else ret = 0;
	cout << ret%MOD << endl;
}



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

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

    string s;
    cin >> s;

    int64_t ans = 0;
    if(p == 2 || p == 5) {
        for(int i = 0; i < n; i++) {
            if((s[i] - '0') % p == 0) ans += i + 1;
        }
    } else {
        vector<int64_t> r_num(p, 0);
        int64_t ten_mod = 1;
        int64_t r = 0;
        r_num[r]++;
        for(int i = n - 1; i >= 0; i--) {
            r = (r + (s[i] - '0') * ten_mod) % p;
            ten_mod = (ten_mod * 10) % p;
            r_num[r]++;
        }
        for(int i = 0; i < p; i++) {
            if(r_num[i] >= 2) ans += r_num[i] * (r_num[i] - 1) / 2;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

    string s;

    cin >> s;

    if(s.size() & 1)
        s.pop_back();
    else{
        s.pop_back();
        s.pop_back();
    }

    while(true){
        int size = s.size();
        string s1 = s.substr(0, size / 2);
        string s2 = s.substr(size / 2, size / 2);
        if (s1 == s2)
        {
            cout << size << endl;
            break;
        }
        s.pop_back();
        s.pop_back();
    }

    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if ((a + b) > (c + d)){
    cout << "Left" << endl;
  }
  else if ((a + b) < (c + d)){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])

ans = 0
for d in ab:
    if d[1] < m:
        ans += d[0] * d[1]
        m -= d[1]
    else:
        ans += d[0] * m
        break
print(ans)


Measured memory_bytes: 28652
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

long long modpow(long long n, long long r) {
    n %= mod, r %= (mod-1);
    if (!n) return 0;
    long long ret = 1; long long tmp = n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    vector<long long> v(k+1, 0);
    vector<long long> w(k+1, 0);
    for (int i = 1; i <= k; i++) v[i] = modpow(k / i, n), w[i] = i;
    for (int i = 1; i <= k; i++) {
        for (int j = 2*i; j <= k; j += i) {
            w[j] = (w[j] - w[i] + mod) % mod;
        }
    }
    long long ans = 0;
    for (int i = 1; i <= k; i++) {
        ans += v[i] * w[i] % mod;
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4744
// I - Coins
// O(n^2)
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
 
typedef long long ll;
typedef pair<int, int> pii;
 
const ll inf = 1e15L;
const int maxn = 3010;
double p[maxn];
double dp[maxn][maxn];
 
int main(){
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0); 
    int n;
    cin >> n;
    memset(p, 0, sizeof(p));
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1.;
    for (int i = 1; i <= n; ++i)
    {
         cin >> p[i];
         dp[i][0] = dp[i-1][0] * (1-p[i]);
         //dp[i][i] = dp[i-1][i-1] * p[i];  it doesn't matter whether setting these values
    }
    
    //dp[i][j] - i is the number of current coins, j is the number fo heads
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= i; ++j){
            dp[i][j] = p[i] * dp[i-1][j-1] + (1 - p[i]) * dp[i-1][j];
        }
    }
    double res = 0.;
    for (int head = 1; head <= n; ++head)
    {
        int tail = n - head;
        if(head > tail)res = res + dp[n][head];
    }
    cout << std::fixed << setprecision(10) << res << endl;
    return 0;
}

Measured memory_bytes: 71040
#include <stdio.h>
int a[1010];
int main()
{
    int n;
    while (scanf("%d", &n), n)
    {
        double s = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", a + i);
            s += a[i];
        }
        s = s / n;
        double ans = 0;
        for (int i = 0; i < n; i++)
            ans = ans + (a[i] - s) * (a[i] - s);
        printf("%f\n", sqrt(ans / n));
    }
}



Measured memory_bytes: 2040
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007

int pow_mod(long long x, long long y) {
	int res = 1;
	while (y) {
		if (y & 1)res = (res*x) % MOD;
		y >>= 1;
		x = (x*x) % MOD;
	}
	return res;
}


int po[401][401];
int p[400][401];


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, c;
	int a[400], b[400];
	cin >> n >> c;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];

	for (int i = 1; i <= 400;i++) {
		long long a = 1;
		rep(j,401) {
			po[i][j] = a;
			(a *= i) %= MOD;
		}
	}

	rep(i,n) {
		rep(j, c + 1) {
			int s = 0;
			for (int x = a[i]; x <= b[i]; x++) {
				s += po[x][j];
				s %= MOD;
			}
			p[i][j] = s;
		}
	}

	int dp[401][401];
	memset(dp, 0, sizeof(dp));
	rep(i,c+1) {
		dp[0][i] = p[0][i];
	}
	for (int i = 1; i < n;i++) {
		for (int j = 0; j <= c;j++) {
			rep(k,j+1) {
				(dp[i][j] += (long long)dp[i - 1][j - k] * p[i][k] % MOD) %= MOD;
			}
		}
	}
	cout << dp[n - 1][c] << endl;

	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long ll;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    int i;
    std::cin >> i;
    std::cout << i+i*i+i*i*i << std::endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
  int i,n,x;
  int min=0,max=0;
  long sum=0;
  scanf("%d",&n);
  scanf("%d",&x);
  min=max=sum=x;
  for(i=1;i<n;i++)
    {
      scanf("%d",&x);
      if(min>x) min=x;
      if(max<x) max=x;
      sum+=x;
    }
  printf("%d %d %ld\n",min,max,sum);
  return 0;
}



Measured memory_bytes: 2124
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    int x[100010], y[100010];
    vector<ll> tree[100010];
    int cnt[100010] = {};
    rep(i,0,M){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        tree[x[i]].push_back(y[i]);
        cnt[y[i]]++;
    }
    queue<int> que;
    rep(i,0,N){
        if(cnt[i] == 0) que.push(i);
    }
    vector<int> topo;
    while(not que.empty()){
        int p1 = que.front();
        que.pop();
        topo.push_back(p1);
        for(auto &e: tree[p1]){
            cnt[e]--;
            if(cnt[e] == 0) que.push(e);
        }
    }
    ll dp[100010] = {};
    rep(i,0,N){
        for(auto &e: tree[topo[i]]){
            dp[e] = max(dp[e], dp[topo[i]]+1);
        }
    }
    ll ans = 0;
    rep(i,0,N) ans = max(ans, dp[i]);
    print(ans);



    

}

Measured memory_bytes: 8184
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    int n; cin >> n;
    vector<ll> v(n);
    map<ll, ll> m;
    ll sum = 0;
    rep(i, n) {
        cin >> v[i];
        sum += v[i];
        m[v[i]]++;
    }
    vector<ll> z;
    int q; cin >> q;
    rep(i, q){
        ll a, b; cin >> a >> b;
        ll d = b-a;
        sum += d * m[a];
        m[b] += m[a];
        m[a] = 0;
        cout << sum << endl;
    }
    system("pause");
}

//https://www.geisya.or.jp/~mwm48961/kou3/base2.htm
//https://math.nakaken88.com/textbook/basic-base-conversion-of-integers/
/*ll n; cin >> n;
    vector<char> ans(100, 'Z');
    int cnt = 0;
    while(n > 0){
        ll k = n % 26;
        ans[cnt++] = 'a'+k-1;
        n /= 26;
    }
    int i = 0;
    while(ans[i] != 'Z'){
        cout << ans[i++];
    }
    cout << endl;*/

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

int ans[100],cor = 0;
int amode[100];
int k[10000];

int main(){
	int i,n;
	while(cin >> n){
		if(n == 0)
			break;
		for(i = 0;i < n;i++)
			cin >> k[i];
		int sum,mmax;
		sum = 0;mmax = 0;
		for(i = 0;i < n;i++){
			if(k[i] > 0)
				sum++;
			if(mmax < k[i])
				mmax = k[i];
		}
		sum++;
		//cout << mmax << endl;
		ans[cor] = sum;
		if(mmax < 2)
			amode[cor] = 1;
		cor++;
	}
	for(i = 0;i < cor;i++){
		if(amode[i] == 0)
			cout << ans[i] << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
int main(void){
	
	int a,b,c,count=0;
	scanf ("%d %d %d",&a,&b,&c);
	while(a<=b){
		if (c % a == 0){
			count++;
		}
		a++;
	}
	printf ("%d\n",count);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;

int in[N], dp[N], ans;
vector<int> v[N];
queue<int> q;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	while (m--)
	{
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		in[y]++;
	}
	for (int i = 1; i <= n; i++)
		if (!in[i])	q.push(i);
	while (!q.empty())
	{
		int t =  q.front(); q.pop();
		for (int& x: v[t])
		{
			in[x]--;
			dp[x] = max(dp[x], dp[t] + 1);
			ans = max(dp[x], ans);
			if (!in[x])	q.push(x);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 6528
N,Y = map(int,input().split())
for a in range(N+1):
    for b in range(N+1):
        if Y== 10000*a+5000*b+1000*(N-a-b) and N-a-b>=0:
            print(str(a)+' '+str(b)+' '+str(N-a-b))
            exit()            
print('-1 -1 -1')

Measured memory_bytes: 3060
//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define si(x) scanf("%d",&x)
#define sii(a,b) scanf("%d%d",&a,&b)
#define siii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define siiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define sl(x) scanf("%lld",&x)
#define sll(a,b) scanf("%lld%lld",&a,&b)
#define slll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sllll(a,b,c,d) scanf("%lld%lld%lld%lld",&a,&b,&c,&d)
#define ss(x) scanf("%s",x+1)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define piiii(a,b,c,d) printf("%d %d %d %d",a,b,c,d)
#define Pi(x) printf("%d\n",x)
#define Pii(x,y) printf("%d %d\n",x,y)
#define Piii(a,b,c) printf("%d %d %d\n",a,b,c)
#define Piiii(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(a,b,c) printf("%lld %lld %lld",a,b,c)
#define pllll(a,b,c,d) printf("%lld %lld %lld %lld",a,b,c,d)
#define Pl(x) printf("%lld\n",x)
#define Pll(x,y) printf("%lld %lld\n",x,y)
#define Plll(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define Pllll(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define ps(x) printf("%s",x+1)
#define space putchar(' ')
#define enter putchar('\n')
using namespace std;typedef long long LL;typedef long double LD;const LL pp=1e9+7;const LD eps=1e-8;
inline LL ksm(LL x,LL y=pp-2){x=(x%pp+pp)%pp;LL ans=1;while (y){if (y&1) ans=ans*x%pp;x=x*x%pp;y>>=1;}return ans;}
inline LL gcd(LL x,LL y){return y?gcd(y,x%y):x;}
inline void reads(char s[],int &n){n=0;char ch=getchar();while (ch==' ' || ch=='\n' || ch=='\r') ch=getchar();
while (ch!=' ' && ch!='\n' && ch!='\r' && ch!=EOF) s[++n]=ch,ch=getchar();}
//========================    C    ========================    N    ==================================
int n,len,F=20;
LL A,B,d,ans=0,num,x,y;
char str[1009];
LL c[89][89];
int main()
{
	//freopen("r.txt","r",stdin);
	//freopen("w1.txt","w",stdout);
	si(n);
	for (int i=1;i<=n;i++)
	{
		reads(str,len);
		num=0;
		while (str[len]=='0')
			num++,len--;
		A=d=0;
		for (int j=1;j<=len;j++)
			if (str[j]=='.')
			{
				d=len-j;
				for (int k=1;k<j;k++)
					A=A*10+str[k]-'0';
				for (int k=j+1;k<=len;k++)
					A=A*10+str[k]-'0';
				break;
			}
		if (!A)
		{
			for (int j=1;j<=len;j++)
				A=A*10+str[j]-'0';
			while (num--)
				A*=10ll;
		}
		x=y=0;
		while (A%2==0ll)
			A/=2ll,x++;
		while (A%5==0ll)
			A/=5ll,y++;
		x-=d,y-=d;
		c[x+F][y+F]++;
		//Pll(x,y);
		if (x>=0ll && y>=0ll)
			ans--;
	}
	for (int i=1;i<=80;i++)
		for (int j=1;j<=80;j++)
			for (int k=1;k<=80;k++)
				for (int l=1;l<=80;l++)
				{
					if (i+j-2*F>=0 && k+l-2*F>=0)
						ans+=1ll*c[i][k]*c[j][l];
				}
	Pl(ans>>1ll);
	return 0;
}

Measured memory_bytes: 1720
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <regex>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}


int main() {
	int ans = 0;
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	for (int r = 0; r*R <= N; r++) {
		for (int g = 0; r * R + g * G <= N; g++) {
			int rest = N - r * R - g * G;
			if (rest >= 0 && rest % B == 0) ans++;
		}
	}
	print(ans);
}

Measured memory_bytes: 3568
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

int main()
{
    string s;
    cin >> s;
    const string expected = "CODEFESTIVAL2016";
    int sum = 0;
    for(int i = 0;i < expected.length();i++)
    {
        if(s[i] != expected[i])
        {
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
    
}

Measured memory_bytes: 256
#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<ll, ll>;

int main( void )
{
	ll s, w;

	cin >> s >> w;

	if ( w >= s ) {
		cout << "unsafe\n";
	}
	else {
		cout << "safe\n";
	}

	return 0;
}


Measured memory_bytes: 3620