akhauriyash/Code-Regression huggingface dataset:
/*
  I used a template program in C.
*/

#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){

  /*my code beginning*/
  while (x->left!=NIL){
    x=x->left;
  }
  return x;
  /*my code end*/

}
 
Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){

  /*my code beginning*/
  if (u==NIL || k==u->key){
    return u;
  }
  if (k < u->key){ 
    return treeSearch(u->left,k);
  } else { 
    return treeSearch(u->right,k);
  }
  /*my code end*/

}
 
Node treeSuccessor(Node x){

  /*my code beginning*/
  Node y;
  if (x->right!=NIL){ 
    return treeMinimum(x->right);
  }
  y=x->parent;
  while (y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
  /*my code end*/

}
 
Node treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  /*my code beginning*/
  if (z->left==NIL || z->right==NIL){ 
    y=z;
  } else {
    y= treeSuccessor(z);
  }
  if (y->left!=NIL){ 
    x=y->left;
  } else {
    x=y->right;
  }
  if (x!=NIL){ 
    x->parent=y->parent;
  }
  if (y->parent==NIL){ 
    root=x;
  } else if (y==y->parent->left){ 
    y->parent->left=x;
  } else {
    y->parent->right=x;
  }
  if (y!=z){
    z->key=y->key;
  }
  return y;
  /*my code end*/

}
 
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  /*my code beginning*/
  while (x!=NIL){
    y=x;
    if (z->key < x->key){ 
      x=x->left;
    } else{
      x=x->right;
    }
  }
  z->parent=y;
  if (y==NIL){ 
    root = z;
  } else if (z->key < y->key){
    y->left=z;
  } else {
    y->right=z;
  }
  /*my code end*/

}
 
void inorder(Node u){

  /*my code beginning*/
  if (u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
  /*my code end*/

}
void preorder(Node u){

  /*my code beginning*/
  if (u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
  /*my code end*/

}

Node find(Node u, int k){
  while ( u != NIL && k != u->key ){
    if (k < u->key ){
      u = u->left;
    } else {
      u = u->right;
    }
  }
  return u; 
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  /*my code beginning*/
  root=NIL;
  /*my code end*/

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}

Measured memory_bytes: 19364
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cstdio>
#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>

using namespace std;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
#define PB push_back
#define MP make_pair
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int memo[100][100];
vector<vector<PII> > graph;

int main(){
	while(1){
		int n,m,c;
		cin>>n>>m>>c;
		memset(memo, -1, sizeof(memo));
		if(n==0)return 0;
		graph = vector<vector<PII> >(n);
		REP(i,m){
			int x,y,r;
			scanf("%d%d%d", &x,&y,&r);
			x--, y--;
			graph[x].PB(MP(y,r));
		}
		priority_queue<TIII, vector<TIII>, greater<TIII> > q;
		q.push(MT(0, 0, 0));
		while(!q.empty()){
			TIII tmp = q.top();
			q.pop();
			if(memo[tmp.T3][tmp.T1]!=-1)continue;
			memo[tmp.T3][tmp.T1] = tmp.T2;
			if(tmp.T3 == n-1){
				cout << tmp.T1 << endl;
				break;
			}
			REP(i, graph[tmp.T3].size()){
				q.push(MT(tmp.T1+1, tmp.T2, graph[tmp.T3][i].first));
				if(tmp.T2+graph[tmp.T3][i].second <= c)q.push(MT(tmp.T1, tmp.T2+graph[tmp.T3][i].second, graph[tmp.T3][i].first));
			}
		}
	}
}

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

int main() {

    int K;
    string S;

    cin >> K >> S;

    if (S.size() <= K) {
        cout << S;
        return 0;
    }

    for (int i = 0; i < K; i++) {
        cout << S.at(i);
    }

    cout << "...";



}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.length();

    bool result = false;

    rep(i, n) {
        string temp = s.substr(n - i) + s.substr(0, n - i);
        if (temp == t)
            result = true;
    }

    if (result) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3528
#include <stdio.h>

int main(void) {

  long a,b,c;
  scanf("%ld %ld %ld", &a, &b, &c);
  long answer = a+b+1;
  if (answer > c) {
    answer = c;
  }
  answer += b;
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int main(void){
	int n,d,x;
	cin>>n>>d>>x;
		int p[d][n];
		for(int i=0;i<d;i++){
			for(int j=0;j<n;j++){
				cin>>p[i][j];
			}
		}
		int ans[d];//i日目の最大値
		int dp[100010]; //　その日の最大値
		int now = 0;
		memset(ans,0,sizeof(ans));
		ans[0] = x;
		memset(dp,0,sizeof(dp));
		for(int i=0;i<d-1;i++){
			now = ans[i];
			for(int j=0;j<x+1;j++)dp[j]=j;
			for(int j=0;j<n;j++){
				for(int k=0;k<x+1;k++){
					if(k>=p[i][j]){
						dp[k] = max(dp[k-p[i][j]]+p[i+1][j],dp[k]);
					}
				}
			}
			for(int j=0;j<x+1;j++)now=max(now,dp[j]);
			x=now;
		}
		cout<<x<<endl;
}



Measured memory_bytes: 3492
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int p[400010];

int main(){
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2*n-1) {
        cout << "No" << endl;
        return 0;
    }
    rep(i, 2*n-1) p[i] = i+1;
    rep(i, 2*n-1) p[2*n-1+i] = i+1;

    int s = x - n + 1;
    if(s <= 0) s += 2*n-1;
    s--;
    cout << "Yes" << endl;
    for(int i = s; i < 2*n+s-1; i++) cout << p[i] << endl;

    return 0;
}


Measured memory_bytes: 5188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N, X;
t3 T[100010];

int main() {
	scanf("%d%d", &N, &X);
	ll del = 0;
	for(int i=1;i<=N;i++) {
		int b, l, r;
		scanf("%d%d%d", &b, &l, &r);
		del += (ll)l*b;
		T[i] = t3(b, l, r);
	}
	if(del == 0) {
		puts("0");
		return 0;
	}
	sort(T+1, T+1+N, [&](t3 x, t3 y) {
		int bi, li, ri; tie(bi, li, ri) = x;
		int bj, lj, rj; tie(bj, lj, rj) = y;
		return (ll)ri * (X - bi) + (ll)li * bi > (ll)rj * (X - bj) + (ll)lj * bj;
	});
	ll sum = 0, ans = 0, rr = 1e18;
	for(int i=1;i<=N;i++) {
		int b, l, r;
		tie(b, l, r) = T[i];
		del += (r - l) * (ll)b;
		ll add = (ll) r * X;
		if(sum + add >= del) {
			ll v1 = 1e18;
			for(int j=i;j<=N;j++) {
				ll dd = del - (ll)(r-l) * b - sum;
				int B, L, R; tie(B, L, R) = T[j];
				v1 = min(v1, ans + (dd + L - 1) / L);
				dd += (R - L) * (ll)B;
				v1 = min(v1, ans + (dd + R - 1) / R);
			}
			rr = min(rr, v1);
			
			ll v2 = 1e18;
			for(int j=i;j;j--) {
				ll dd = (sum + add - del);
				int B, L, R; tie(B, L, R) = T[j];
				v2 = min(v2, ans + X - dd / R);
				dd -= (R - L) * (ll)(X - B);
				v2 = min(v2, ans + X - dd / L);
			}
			rr = min(rr, v2);
			break;
		}
		else {
			sum += add;
			ans += X;
		}
	}
	printf("%lld\n", rr);
	return 0;
}

Measured memory_bytes: 1408
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

// number一個取得
// eslint-disable-next-line no-unused-vars
const next = () => +cin[cid++];

// 文字列一個取得
// eslint-disable-next-line no-unused-vars
const nextstr = () => cin[cid++];

// BigInteger一個取得
// eslint-disable-next-line no-unused-vars
const nextbig = () => BigInt(cin[cid++]);

// 長さnの配列として取得。aは文字列フラグ
// eslint-disable-next-line no-unused-vars
const nexts = (n, a) =>
    a ? cin.slice(cid, (cid += n)) : cin.slice(cid, (cid += n)).map((a) => +a);

// w個ずつを組にして長さhの配列。aは文字列フラグ。
// eslint-disable-next-line no-unused-vars
const nextm = (h, w, a) => {
    var r = [],
        i = 0;
    if (a) for (; i < h; i++) r.push(cin.slice(cid, (cid += w)));
    else for (; i < h; i++) r.push(cin.slice(cid, (cid += w)).map((a) => +a));
    return r;
};
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
// eslint-disable-next-line no-unused-vars
const xArray = (...args) => {
    var a = args,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + a[0] + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
};

console.log(main());

function main() {
    let x = next();
    let y = next();
    let b = (y - 2 * x) / 2;
    let a = x - b;
    if (Number.isInteger(a) && Number.isInteger(b) && 0 <= a && 0 <= b)
        return "Yes";
    return "No";
}


Measured memory_bytes: 29636
#include<stdio.h>
#include<math.h>
#define pai 3.1415926535
int main(){
    double a,b,c,crad;
    
    scanf("%lf %lf %lf",&a,&b,&crad);
    crad*=pai/180;

    c=sin(crad)*b;
    printf("%lf\n",a*c/2);
    printf("%lf\n",a+b+pow (a*a+b*b-2*a*b*cos(crad),0.5) );
    printf("%lf\n",c);

    return 0;
}



Measured memory_bytes: 2144
import itertools

N, M = map(int, input().split())
k = []
for i in range(M):
    tmp = [int(j) for j in input().split()]
    k.append(tmp)

p = [int(i) for i in input().split()]

onoff = [0, 1]
kouho = list(itertools.product(onoff, repeat=N))

ans = 0
for li in kouho:
    flag = True
    for i in range(M):
        end = k[i][0]+1
        sum = 0
        for j in range(1, end):
            sum += li[k[i][j]-1]
        if sum % 2 != p[i]:
            flag = False
            break
    if flag == True:
        ans += 1

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <atcoder/convolution>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
#include <atcoder/math>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/modint>
#include <atcoder/scc>
#include <atcoder/segtree>
#include <atcoder/string>
#include <atcoder/twosat>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;


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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
using namespace atcoder;

void solve(){
	// ll t1,t2;
	// cin>>t1>>t2;
	// ll a1,a2,b1,b2;
	// cin>>a1>>a2>>b1>>b2;
	// if(a1*t1+a2*t2==b1*t1+b2*t2){
	// 	cout<<"infinity\n";
	// }
	// else if(a1*t1<b1*t1&&a2*t2<b2*t2){
	// 	cout<<0<<"\n";
	// }
	// else if(a1*t1>b1*t1&&a2*t2>b2*t2){
	// 	cout<<0<<"\n";
	// }
	// else{
	// 	ll ans=0;
	// 	ll x=abs(a1-b1)*t1;
	// 	ll y=abs(a1*t1+a2*t2-b1*t1-b2*t2);
	// 	ans+=x/y*2;
	// 	if(x<y)ans=1;
	// 	else if(x%y)++ans;
	// 	cout<<ans<<"\n";
	// }
	int n,q;
	cin>>n>>q;
	dsu tree(n);
	while(q--){
		int t,u,v;
		cin>>t>>u>>v;
		if(t==0)tree.merge(u,v);
		else{
			cout<<tree.same(u,v)<<"\n";
		}
	}
}

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


Measured memory_bytes: 3904
#ABC105-D Candy Distribution
"""
al~arの合計がmの倍数となる通り数を調べる。
愚直に累積和をとって判定するには、O(n(n+1)/2)で不十分
実は、al~arの合計がmの倍数になる条件は、累積和をbとして、
b(l-1),brのmod m が同値になることである。
よって、累積和のmod mの個数をdictで保存しておいて、
同じ値のnC2つまり、n(n-1)//2の合計が答えとなる。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,m = map(int,readline().split())
lst1 = list(map(int,readline().split()))
def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
lst2 = cumsum(lst1)

dic1 = dict()
for i in lst2:
    res = i%m
    if res in dic1:
        dic1[res] += 1
    else:
        dic1[res] = 1

ans = 0
for i in dic1.values():
    if i >= 2:
        ans += i*(i-1)//2

res = 0 if 0 not in dic1 else dic1[0]
print(ans+res)


Measured memory_bytes: 56816
package main

import "fmt"

func main() {
	var s string
	var k int
	fmt.Scan(&s, &k)

	same := true
	for i := 0; i < len(s)-1; i++ {
		if s[i] != s[i+1] {
			same = false
			break
		}
	}
	if same {
		fmt.Println(len(s) * k / 2)
		return
	}

	c1 := 0
	for i := 1; i < len(s); i++ {
		if s[i-1] == s[i] {
			c1++
			i++
		}
	}

	ss := s + s
	c2 := 0
	for i := 1; i < len(ss); i++ {
		if ss[i-1] == ss[i] {
			c2++
			i++
		}
	}

	fmt.Println(c1 + (c2-c1)*(k-1))
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
g = [[] for i in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

def dfs(v):
    if len(v) == n:
        return 1
    ret = 0
    for u in set(g[v[-1]]) - set(v):
        ret += dfs(v + [u])
    return ret

print(dfs([0]))


Measured memory_bytes: 3064
#include <stdio.h>
#include <ctype.h>
#include <string.h>

const char* character_list[38]={
	"a","b","c","d","e","f","g","h","i","j","k","l","m",
	"n","o","p","q","r","s","t","u","v","w","x","y","z",
	"ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"
};

int getnextcode(const char* str) {
	if(str[0]=='l' && str[1]=='d')return 27;
	if(str[0]=='m' && str[1]=='b')return 28;
	if(str[0]=='m' && str[1]=='p')return 29;
	if(str[0]=='n' && str[1]=='c')return 30;
	if(str[0]=='n' && str[1]=='d')return 31;
	if(str[0]=='n' && str[1]=='g')return 32;
	if(str[0]=='n' && str[1]=='t')return 33;
	if(str[0]=='n' && str[1]=='w')return 34;
	if(str[0]=='p' && str[1]=='s')return 35;
	if(str[0]=='q' && str[1]=='u')return 36;
	if(str[0]=='c' && str[1]=='w')return 37;
	if(str[0]=='t' && str[1]=='s')return 38;
	if(islower(str[0]))return str[0]-'a'+1;
	return 0;
}

int main(void) {
	char input[100];
	int table[39][39]={0};
	int n,i,j,length;
	int prev,now;
	int max,maxc;
	scanf("%d ",&n);
	for(i=0;i<n;i++) {
		fgets(input,sizeof(input),stdin);
		length=strlen(input);
		prev=0;
		for(j=0;j<length;) {
			now=getnextcode(&input[j]);
			table[prev][now]++;
			if(now>26)j+=2; else j++;
			prev=now;
		}
	}
	for(i=1;i<=38;i++) {
		max=0;
		maxc=1;
		for(j=1;j<=38;j++) {
			if(table[i][j]>max) {
				max=table[i][j];
				maxc=j;
			}
		}
		printf("%s %s %d\n",character_list[i-1],character_list[maxc-1],max);
	}
	return 0;
}

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

int main() {
  int H,N;
  cin>>H>>N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin>>A.at(i);
  }
  int ans =0;
  for(int j=0; j<N; j++){
    ans += A.at(j);
  }
  if(ans<H){
    cout<<"No"<<endl;
  }  
  else{
    cout << "Yes" <<endl;
  }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long l,r;

int main()
{
	cin>>l>>r;
	if((r/2019-l/2019)>0)
		cout<<0<<endl;
	else
	{
		long long ans=2020;
		for(long long i=l;i<=r;i++)
		{
			for(long long j=i+1;j<=r;j++)
			{
				ans=min(ans,(i*j%2019));
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
h = MAP()

dp = [MOD]*n
dp[0]=0

for i in range(n-1):
    dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
    if i<n-2:
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))

print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    double r;
    double a, b;
    cin >> r;
    a = r*r*3.141592653589;
    b = (r + r)*3.141592653589;
    cout << fixed << setprecision(6) << a << " " << fixed << setprecision(6) << b << "\n";
}



Measured memory_bytes: 3220
main=do
 s<-reverse<$>getLine
 putStrLn(if(f s)then"YES"else"NO")
  where f "" = True
        f s |(take 5 s)=="maerd"   = f (drop 5 s)
            |(take 7 s)=="remaerd" = f (drop 7 s)
            |(take 5 s)=="esare"   = f (drop 5 s)
            |(take 6 s)=="resare"  = f (drop 6 s)
            |otherwise             = False

Measured memory_bytes: 7548
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int R;
	cin>>R;
	
	if(R >= 2800)
		printf("AGC");
	else if(R < 1200)
		printf("ABC");
	else
		printf("ARC");
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n, k;
  cin >> n >> k;
  double ans = 0;
  for(int dice = 1; dice <= n; ++dice) {
    double res = 1.0/n;
    int point = dice;
    while(point < k) {
      res /= 2;
      point *= 2;
    }
    ans += res;
  }
  printf("%0.12f\n", ans);
}

Measured memory_bytes: 3668
#include <stdio.h>

int main(void)
{
  int n,i;
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    int a[n][3];
    for(i=0;i<n;i++){
      scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
    if(a[i][0]==100||a[i][1]==100||a[i][2]==100)
      puts("A");
    else if(((a[i][0]+a[i][1])/2)>=90)
      puts("A");
    else if(((a[i][0]+a[i][1]+a[i][2])/3)>=80)
      puts("A");
    else if(((a[i][0]+a[i][1]+a[i][2])/3)>=70)
      puts("B");
    else if(((a[i][0]+a[i][1]+a[i][2])/3)>=50&&(a[i][0]>=80||a[i][1]>=80))
      puts("B");
    else
      puts("C");
    }
  }
  return 0;
}

Measured memory_bytes: 580
#include<iostream>
using namespace std;
int main(){
  bool flag=false;
  char unko;
  cin>>unko;
  string ass="abcdefghijklmnopqrstuvwxyz";
  for(int i=0;i<26;i++)
    if(ass[i]==unko)flag=true;
  if(flag)cout<<"a\n";
  else cout<<"A\n";
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 
vector<int> pa[100005];
int dp[100005];
 
int dfs(int a){
  if(dp[a]>=0) return dp[a];
  if(pa[a].size()==0) return dp[a]=0;
  rep(i,pa[a].size()){
    dp[a]=max(dp[a],dfs(pa[a][i])+1);
  }
  return dp[a];
}

int main(){
  int n,m; cin >> n >> m;
  rep(i,m){
    int x,y; cin >> x >> y;
    pa[x].push_back(y);
  }
  rep(i,n+1){
    dp[i]=-1;
  }
  int ac=0;
  for(int i=1; i<=n; i++) ac=max(ac,dfs(i));
  cout << ac << endl;
return 0;
}

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

using namespace std;

#define MAXN 200010
#define INF 0x3f3f3f3f
#define mo 1000000007
typedef long long LL;

LL f[MAXN], two[MAXN];
char s[MAXN];

int main()
{
//#ifdef MYCP
//    freopen("data.in", "r", stdin);
//#endif // MYCP

    int n; LL sum = 0;
    scanf("%s", s);
    n = strlen(s);
    f[0] = 1; two[0] = 1;
    for(int i = 1, j = 1; i <= n; ++i, j = j * 10)
        f[i] = 2LL * f[i - 1] + 9LL * j,
        two[i] = 2LL * two[i - 1];
    for(int i = 0; i < n; ++i)
        sum = (sum + 1LL * f[n - i - 1] * two[i] * (s[i] - '0'));
    printf("%lld\n", sum);

	return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 M = 1000000007;

signed main() {
  i64 n, a, b, c;
  cin >> n >> a >> b >> c;
  i64 ans = 0;
  vector<i64> pa(n + 1);
  vector<i64> pb(n + 1);
  vector<i64> fact(n * 2 + 1);
  pa[0] = 1;
  pb[0] = 1;
  fact[0] = 1;
  i64 pa1 = a * inv(a + b, M) % M;
  i64 pb1 = b * inv(a + b, M) % M;
  REP(i, n - 1) {
    pa[i + 1] = pa[i] * pa1 % M;
    pb[i + 1] = pb[i] * pb1 % M;
  }
  REP(i, n * 2) {
    fact[i + 1] = fact[i] * (i + 1) % M;
  }
  REP(i, n) {
    ans += (n - 1 + i + 1) % M
        * pa[n - 1] % M
        * pb[i] % M
        * fact[n - 1 + i] % M
        * inv(fact[n - 1], M) % M
        * inv(fact[i], M) % M
        * pa1 % M;
    ans %= M;
    ans += (n - 1 + i + 1) % M
        * pb[n - 1] % M
        * pa[i] % M
        * fact[n - 1 + i] % M
        * inv(fact[n - 1], M) % M
        * inv(fact[i], M) % M
        * pb1 % M;
    ans %= M;
  }
  ans = ans * 100 % M * inv(a + b, M) % M;
  cout << ans << endl;
}


Measured memory_bytes: 3456
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

#define PT pair<ll, int>


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


	int N, M;
	cin >> N >> M;
	vector<PT> E[100001];
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		E[a].pb({ 1, b });
		E[b].pb({ 1, a });
	}

	ll D[100001];
	rep1(i, N) D[i] = 1e18;
	D[1] = 0;

	priority_queue<PT, vector<PT>, greater<PT>> que;

	que.push(mp(0, 1));
	while (que.size()) {
		PT p = que.top();
		que.pop();
		int i = p.second;
		if (D[i] != p.first) continue;
		for (PT p2 : E[i]) {
			int j = p2.second;
			ll d = D[i] + p2.first;
			if (D[j] > d) {
				D[j] = d;
				que.push(mp(d, j));
			}
		}
	}

	int kotae[100001];
	for (int i = 2; i <= N; i++) {

		ll d = D[i];
		for (PT p2 : E[i]) {
			int j = p2.second;
			if (D[j] == d - 1) {
				kotae[i] = j;
			}
		}
	}

	co("Yes");
	for (int i = 2; i <= N; i++) co(kotae[i]);


	Would you please return 0;
}

Measured memory_bytes: 18696
N = int(input())
ans = float('inf')
for i in range(1, N):
    j = N-i
    i_str = str(i)
    j_str = str(j)
    i_sum, j_sum = 0, 0
    for p in range(len(i_str)):
        i_sum += int(i_str[p])
    for q in range(len(j_str)):
        j_sum += int(j_str[q])
    ans = min(ans, i_sum+j_sum)

print(ans)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  map<ll,ll> cnt;

  ll sum = 0;
  rep(i, n) {
    ++cnt[sum];

    ll a; cin >> a;
    sum += a;
  }

  ++cnt[sum];

  ll ans = 0;
  for (auto e : cnt) ans += (e.se * (e.se - 1)) / 2;

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 16120
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


// binary-indexed-tree template
// note that BIT is 1-indexed
// arr -> a_0, a_1, ..., a_{n-1}
template< typename T >
struct FenwickTree {
    vector<T> a;

    FenwickTree (int size){
        a.assign(size + 1, 0);
    }

    // find the sum [0, t]
    T sum (int i){
        T ret = 0;
        while(i > 0){
            ret += a[i];
            i = i & (i-1);
        }
        return ret;
    }

    // find the sum [s, t]
    T sum_range (int s, int t){
        return sum(t) - sum(s-1);
    }

    // update a_i -> a_i + x
    void add (int i, T x){
        for (++i; i < (int)(a.size()); i += i & -i){
            a[i] += x;
        }
        return;
    }
};

int n, q;
vector<int> com, x, y;

void input(){
    cin >> n >> q;
    com.resize(q);
    x.resize(q);
    y.resize(q);
    REP(i, q){
        cin >> com[i] >> x[i] >> y[i];
    }
    return;
}

void solve(){
    FenwickTree<int> bit(n);
    REP(i, q){
        if(com[i] == 0){
            bit.add(--x[i], y[i]);
        }
        else if(com[i] == 1){
            cout << bit.sum_range(x[i], y[i]) << endl;
        }
    }
    return;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    input();
    solve();
    return 0;
}


Measured memory_bytes: 4368
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

#define MOD 1000000007

ll calcz(ll x, ll y){
  ll a = x, b = MOD;
  ll tmp;
  vector<ll> syo;
  while(a > 1){
    syo.push_back(b / a);
    tmp = b % a;
    b = a;
    a = tmp;
  }
  ll dp1 = 0, dp2 = 1;
  rrep(i, syo.size()){
    ll tmp = (dp2 * (-syo[i]) + dp1) % MOD;
    dp1 = dp2;
    dp2 = tmp;
  }
  y = (y + MOD) % MOD;
  dp2 = (dp2 + MOD) % MOD;
  return (y % 10000 * dp2 % MOD + (y / 10000) * dp2 % MOD * 10000) % MOD;
}

int main(){
  ll B, W;
  cin >> B >> W;

  ll p_bl = 0, p_wh = 0;
  ll btmp = 1, wtmp = 1;
  ll bunbo = 1;
  cout << 500000004 << endl;

  repi(i, 1, B + W){
    bunbo = bunbo * 2 % MOD;
    if(i >= B){
      p_bl = (p_bl * 2 + btmp) % MOD;
      btmp = calcz(i - B + 1, (btmp * i) % MOD);
    }
    if(i >= W){
      p_wh = (p_wh * 2 + wtmp) % MOD;
      wtmp = calcz(i - W + 1, (wtmp * i) % MOD);
    }
    ll bunshi =  (p_wh + (bunbo - p_bl)) % MOD;
    cout << calcz(bunbo * 2, bunshi) << endl;

  }
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n;
int a[100100];

signed main() {

    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    a[n] = 0;
    ll t  = 0, sum = 0;
    for(int i = 0; i <= n; i++) {
        if(a[i] > 0) t += a[i];
        else sum += t/2, t = 0;
    }
    
    cout << sum << endl;

  
    return 0;
}



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

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		int k = in.nextInt();
		if(k % 2 == 0) 
		{
			System.out.println(-1);
			return;
		}
		int a = 7;
		int count = 1;
		while(true)
		{
			if(a % k == 0) 
			{
				System.out.println(count);
				return;
			}
			if(count > k) {
				System.out.println(-1);
				return;
			}
			a = (a % k) * 10 + 7;
			count++;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}





Measured memory_bytes: 32804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  if(n%10==9){
    cout<<"Yes"<<endl;
    return 0;
  }
  n/=10;
  if(n%10==9){
    cout<<"Yes"<<endl;
    return 0;
  }  
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int[] a = new int[n];

		for(int i = 0;i < n; i++) {
			a[i] = s.charAt(i) - '0';
		}


		long ans = 0;

		for (int bit = 0; bit < 1 << (n-1); bit++){

			long num = 0;
			long sum = 0;

			for (int j = 0; j < n; j++){

				num = num * 10 + a[j];

				if ((bit >> j & 1) == 1){
					sum += num;
					num = 0;
				}

			}

			sum += num;
			ans += sum;

		}

		System.out.println(ans);

	}

}


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

using namespace std;

int main(){
    int n;
    int t,a;
    cin >> n;
    cin >> t >> a;
    int ans=100000000000000;
    int ans_count=-1;
    int d;
    for (int i=0;i<n;i++){
        int h;
        cin >>h;
        d =abs((1000*t- 6*h)-1000*a);
        if (ans>d){
            ans_count = i+1;
            ans = d;
        } 
    }
    cout << ans_count << endl;
    
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i); 
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  int A = 0;
  int B = 0;
  for(int i=0; i<N; i++){
    if(i % 2 == 0){
      A += a.at(i);
    }
    else{
      B += a.at(i);
    }
  }
  
  cout << A - B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

using namespace std;


int N, M;
vector<vector<int>> G;
int dp[100100] = {}, used[100100] = {};
int d(int v){
  if(used[v]) return dp[v];
  used[v] = 1;
  int tmp = 0;
  for(auto next_v:G[v]){
    chmax(tmp,d(next_v)+1);
  }
  return dp[v] = tmp;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  G.assign(N, vector<int>());
  REP(i,M){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
  }
  int ans = 0;
  REP(i,N) chmax(ans, d(i));
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//ld d;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

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

    cin >> n;
	vi b;
	for(ll i = -1000; i <1001; ++i) {
    	b.push_back(pow(i,5));
    }
	vi a(b);
	REP(ia,2001){
    	REP(ib,2001){
        	if(a[ia]-b[ib]==n){
            	m = ia-1000; k = ib-1000;
            	break;
            }
        }
    }
	cout<<m<<' '<<k;
}


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

int main () {
  int n;
  cin >> n;
  string ans = "No";
  if (n/100==7) {
    ans = "Yes";
  }
  n -= n/100*100;
  if (n/10==7) {
    ans = "Yes";
  }
  n -= n/10*10;
  if (n==7) {
    ans = " Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3540
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  string s;cin>>s;
  int K[n+1][2];
  K[0][0] = 0;
  K[0][1] = 0;
  for(int i = 0; n > i; i++){
    if(s[i] == '.'){
      K[i+1][0] = K[i][0]+1;
      K[i+1][1] = K[i][1];
    }else{
      K[i+1][1] = K[i][1]+1;
      K[i+1][0] = K[i][0];
    }
  }
  int ans = n;
  for(int i = 0; n >= i; i++){
    ans = min(ans,K[i][1]+(K[n][0]-K[i][0]));
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
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;}
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();
template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	for(int i=0;i<s;++i)v.push_back(init);
	for(int i=s;i<e;++i){cin>>x;v.push_back(x);}
	return v;
}
// vi P = inarr<int>(0,N,0);
// vi P = inarr<int>(1,N+1,INT_MAX);
// vs P = inarr<string>(0,N,"");
template<class T>void outarr(int s,int e,vector<T> &V){
	for(int i=s;i<e;i++)cout<<V[i]<<(i<e-1?" ":"\n");
}
// outarr<int>(0,V.size(),V);
// outarr<ll>(0,V.size(),V);

// #define MAX 1'000'000'000
ll A,B;

ll solve(){
	ll ans = 0;
	// ll a = A / 0.08;
	// ll b = B / 0.10;

	ll a = (A*100+8-1)/8;
	ll b = (B*100+10-1)/10;

	ll aa = a*0.08;
	ll ab = a*0.10;
	ll ba = b*0.08;
	ll bb = b*0.10;
	if(aa==A && ab==B){
		if(ba==A && bb==B){
			return min(a,b);
		}
		else{
			return a;
		}
	}
	else{
		if(ba==A && bb==B){
			return b;
		}
		else{
			return -1;
		}
	}
	return -1;
}

int main(){
	cin>>A>>B;
	cout<< solve() <<endl;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  int x = 0;
  int l = S.length();
  REP(i, l) {
    if (S.at(i) == 'I') {
      ++x;
    } else {
      --x;
    }
    ans = max(ans, x);
  }

  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double S;
    double A,B,C;
    double r;
    int x1,x2,x3,y1,y2,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    x2-=x1;
    x3-=x1;
    y2-=y1;
    y3-=y1;
    A=sqrt(pow(x2,2)+pow(y2,2));
    B=sqrt(pow(x2-x3,2)+pow(y2-y3,2));
    C=sqrt(pow(x3,2)+pow(y3,2));
    S=0.5*abs(x2*y3-x3*y2);
    r=2*S/(A+B+C);
    double M;
    M=max<double>(A,B);
    M=max<double>(M,C);
    double x;
    x=M*(r/(2*r+M));
    cout<<setprecision(10)<<x<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0,M = 0;
  cin >> N >> M;
  if(N == 1 || M == 1){
    cout << "1";
  }
  else{
    cout << (N * M + 1) / 2;
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long int ll;
#define test int testcase; cin>>testcase; while(testcase--)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deci(n) fixed << setprecision(n)
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define F first
#define S second
#define mp make_pair
#define pb push_back
int main()
{
    string s;
    cin>>s;
    if(s=="ABC")
    cout<<"ARC";
    else
    cout<<"ABC";
}

Measured memory_bytes: 3596
#include <stdio.h>
int main(){
	
	int n;
	scanf("%d", &n);
	long long sum=0;
	
	for (int i=1; i<=n; i++){
		if(i % 3 == 0 || i % 5 == 0){
			continue;
		}
		else sum += i;
	}
	printf("%lld", sum);
	
	return 0;
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
long long br[10007];
int main()
{
	int n,p;
	string s;
	cin>>n>>p>>s;
	br[0]=1;
	int ost=0,st=1;
	long long rez=0;
	if(p==2)
	{
		for(int i=0;i<n;i++) if((s[i]-'0')%2==0) rez+=((long long)i+1);
		cout<<rez; return 0;
	}
	if(p==5)
	{
		for(int i=0;i<n;i++) if((s[i]-'0')%5==0) rez+=((long long)i+1);
		cout<<rez; return 0;
	}
	long long mmi;
	while((mmi*10)%p!=1) mmi++;
	for(int i=0;i<n;i++)
	{
		ost=(ost*10+s[i]-'0')%p;
		st=(st*mmi)%p;
		rez+=br[(ost*st)%p];
		br[(ost*st)%p]++;
	}
	cout<<rez;
}

Measured memory_bytes: 644
s = input()

ans = float('inf')
for init in '01':
    t = 0
    x = init
    for ss in s:
        # print(ss, x)
        if ss != x:
            t += 1
        if x == '0':
            x = '1'
        else:
            x = '0'
    ans = min(ans, t)
print(ans)


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

using namespace std;

int main(void){
	int a, b;
	scanf("%d %d", &a, &b);
	int c = 0;
	for(int i = a;i <= b;++i){
		if(i / 10000 == i % 10 && (i % 10000)/1000 == (i % 100)/10){
			c++;
		}
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 256