akhauriyash/Code-Regression huggingface dataset:
x,k,d = map(int,input().split())

if k * d <= abs(x):
    if x > 0:
        ans = x - (k*d)
    elif x < 0:
        ans = x + (k*d)
elif k % 2 == 0:
    t = x // d
    if t % 2 == 1:
        t += 1
    ans = abs(x - t * d)
elif k % 2 == 1:
    t = x // d
    if t % 2 == 0:
        t += 1
    ans = abs(x - t * d)

print(abs(ans))


Measured memory_bytes: 61876
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  string s; cin >> s;
  vector<int> v;
  for(int i = 0; i < s.length(); i++) v.push_back((int)s[i] - 48);
  int ans = 0;
  for(int i = 0; i < (int)v.size() - 1; i++){
    //cout << "i:" << i << " size:" << v.size() << endl;
    if(v[i] != v[i + 1]){
      v.erase(v.begin() + i);
      v.erase(v.begin() + i);
      ans += 2;
      i = -1;
      //for(int i = 0; i < v.size(); i++) cout << v[i]; cout << endl;
    }
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1020
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main = panaA

panaA = do
    let sequence = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    [k] <- getIntList
    print $ sequence!!(fromIntegral k - 1)
  

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

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

int main(){
    int n;
    cin>>n;
    double p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    double dp[n+1]={1.0};
    for(int i=0;i<n;i++){
        for(int j=n;j>=1;j--){
            dp[j]=(1-p[i])*dp[j]+p[i]*dp[j-1];
        }
        dp[0]=(1-p[i])*dp[0];
    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[i];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	double xa , ya , ra , xb , yb , rb;
	double ab;
	int n;
	cin >> n;
	for(int i=0 ; i<n ; ++i){
		cin>> xa >> ya >> ra >> xb >> yb >> rb;
	ab=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
	if(ra-ab>rb) cout << 2 << endl;
	else if (rb-ab>ra) cout << -2 << endl;
	else if (ab>(ra+rb)) cout << 0 << endl;
	else cout << 1 << endl; 
	}
	return 0; 
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    ll place[N + 1];
    for (int i = 1; i <= N; i++) {
        ll a;
        cin >> a;
        place[a] = i;
    }
    ll ans = 0;
    set<ll> used = {0, N + 1};
    for (int i = 1; i <= N; i++) {
        ll r, l;
        auto itr = used.lower_bound(place[i]);
        r = *itr;
        l = *(--itr);
        ans += i * (place[i] - l) * (r - place[i]);
        used.insert(place[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
#include<bitset>
using namespace std;
typedef	long long int ll;

int main(){
    int l;
    cin >> l;
    vector<int> v;
    bitset<20> bit(l);
    for(int i=0; i<20; i++){
        if(bit[i]==1){
            v.push_back(i);
        }
    }
    int n = v[v.size()-1]+1;
    int m = 2*(n-1)+v.size()-1;
    cout << n << ' ' << m << endl;
    for(int i = 1; i < n; i++){
        cout << i << ' ' << i+1 << ' ' << pow(2, n-i-1) << endl;
        cout << i << ' ' << i+1 << ' ' << 0 << endl;
    }
    int total = pow(2, n-1);
    for(int i = 0; i < v.size()-1; i++){
        cout << 1 << ' ' << n-v[i] << ' ' << total << endl;
        total += pow(2, v[i]);
    }
    return 0;
}

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

#define M 1046527
#define Nil (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch=='A')return 1;
  else if(ch=='C')return 2;
  else if(ch=='G')return 3;
  else if(ch=='T')return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum=0,p=1,i;

  for(i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key%M;
}
int h2(int key){
  return 1+(key%(M-1));
}

int find(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}
int insert(char str[]){
  long long key,i,h;
  key=getKey(str);

  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
    }
  return 0;
}

int main(){
  int i,n,h;
  char str[L],com[9];

  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    if(com[0]=='i'){
      insert(str);
    }else{
      if(find(str)){
        printf("yes\n");
      }else{
        printf("no\n");
      }
    }
  }
return 0;
}


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

int main(){
  cout << fixed << setprecision(12);
  int a, b ,d ,r;
  double f;
  cin>>a>>b;
  d = a / b;
  r = a % b;
  f = (double) a / b;
  cout << d << " "<< r << " "<< f << endl;
 return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for (int i=1; i<=(n); ++i)
#define drep(i,n) for (int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)ß
#define pi (acos(-1))
//#define pii pair<int,int>
//#define pll pair<ll,ll>
//#define vec vector
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;
}
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> P;
const int INF = 1001001001;
ll gcd (ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}
ll lcm (ll a, ll b) {
  return a/gcd(a,b)*b;
}

int main(void) {
	int l,r,d;
	cin >> l >> r >> d;
	int ans = 0;
	for(int i=l; i<=r; i++) {
		if (i%d == 0) {
			ans++;
		}
	}	
	cout << ans << endl;
	return 0;
}
	





  



Measured memory_bytes: 3628
#include <iomanip>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

#if __has_include("debugger.cpp")
  #include "debugger.cpp"
#else
void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) > 0) cout << " ";
  print(std::forward<Tail>(tail)...);
}
# endif

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

ll n, k;
vector<double> table;
#define DP table[x]
double p(ll x) {
  if (x >= k) return 1;
  if (DP != -1) return DP;
  return DP = p(x * 2) * 0.5;
}

int main() {
  cin >> n >> k;
  table = vector<double>(k + 1, -1);
  double ans = 0;
  FOR(i, 1, n) {
    ans += (1. / n) * p(i);
  }
  cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 4000
n = int(input())

p = []
for i in range(n):
    p.append(int(input()))


q = [0 for i in range(n)]
for i in range(n):
    q[p[i] - 1] = i

result = 1
temp = 1
for i in range(1, n):
    if q[i] < q[i-1]:
        if temp > result:
            result = temp
        temp = 1
    else:
        temp += 1

if temp == n:
    result = temp

print(n - result)

Measured memory_bytes: 18888
#include<iostream>
using namespace std;
long mod=1e9+7;
long dp[64][2][2];
long L,R;
main()
{
	cin>>L>>R;
	long ans=0;
	for(int k=1;k<=62;k++)
	{
		if(1L<<k<=L||R<1L<<k-1)continue;
		for(int i=0;i<64;i++)for(int j=0;j<2;j++)for(int l=0;l<2;l++)dp[i][j][l]=0;
		dp[0][L<=1L<<k-1][(1L<<k)-1<=R]=1;
	for(int i=0;i<=k-2;i++)
	{
		int x=L>>k-2-i&1;
		int y=R>>k-2-i&1;
		for(int xl=0;xl<2;xl++)for(int yl=0;yl<2;yl++)
		{
			int limx=xl?0:x;
			int limy=yl?1:y;
			for(int yy=0;yy<=limy;yy++)for(int xx=limx;xx<=yy;xx++)
			{
				(dp[i+1][xl||xx>limx][yl||yy<limy]+=dp[i][xl][yl])%=mod;
			}
		}
	}
	for(int i=0;i<4;i++)(ans+=dp[k-1][i/2][i%2])%=mod;
	}
	cout<<ans<<endl;
}


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

#define F first
#define S second
#define int long long
#define inf 1000000000

using namespace std;

vector<int> dist(const int& n, const int& x, const int& y){
    vector<int> d(n, inf);
    d[x] = 0;
    queue<int> q;
    q.push(x);
    while (!q.empty()){
        int cur = q.front();
        q.pop();
        if (cur > 0 && d[cur-1] == inf){
            q.push(cur-1);
            d[cur-1] = d[cur]+1;
        }
        if (cur < n-1 && d[cur+1] == inf){
            q.push(cur+1);
            d[cur+1] = d[cur]+1;
        }
        if (cur == x && d[y] == inf){
            q.push(y);
            d[y] = d[cur]+1;
        }
        if (cur == y && d[x] == inf){
            q.push(x);
            d[x] = d[cur]+1;
        }
    }
    return d;
}

signed main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> res(n, 0);
    vector<int> xdist = dist(n, x, y);
    vector<int> ydist = dist(n, y, x);
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            int dst = inf;
            dst = min(dst, j-i);
            dst = min(dst, xdist[j]+ydist[i]+1);
            dst = min(dst, xdist[i]+ydist[j]+1);
            res[dst]++;
        }
    }
    for (int i = 1; i < n; i++){
        cout << res[i] << endl;
    }
    return 0;
}























Measured memory_bytes: 3684
var
	x,y,ans:Longint;
begin
	read(x,y);
	if x=1 then inc(ans,3)else if x=2 then inc(ans,2)else if x=3 then inc(ans,1);
	if y=1 then inc(ans,3)else if y=2 then inc(ans,2)else if y=3 then inc(ans,1);
	if(x=1)and(y=1)then inc(ans,4);
	writeln(ans*100000);
end.


Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N; cin >> N;
    string S; cin >> S;

    vector<ll > E(N + 1, 0);
    vector<ll > W(N + 1, 0);

    for(ll i = 1; i < N + 1; i++){
        if(S[i - 1] == 'E'){
            E[i] += E[i - 1] + 1;
        }else{
            E[i] = E[i -1];
        }

        if(S[i - 1] == 'W'){
            W[i] += W[i - 1] + 1;
        }else{
            W[i] = W[i -1];
        }
    }

    ll ans = INFINITY;
    for(ll i = 0; i < N; i++){
        ll t_ans = 0;
        //cout << W[i+1] << " " << E[N] - E[i+1] << endl;
        t_ans += E[N] - E[i+1];
        t_ans += W[i];
        //cout << i << " " << t_ans << endl;
        ans = min(ans, t_ans);

    }

    cout << ans << endl;

}

Measured memory_bytes: 5380
#include <stdio.h>

typedef struct Bomb
{
	int map[8][8];
	int x, y;
} BOMB;

int x_cnt, y_cnt;

BOMB* explode(BOMB*);

int main()
{
    int input_times, input_cnt;
    char dump;
    BOMB input[50];
    
    scanf("%d", &input_times);
    
    /*printf("%d\n", input_times);*/
    
    input_cnt = 0;
    while(input_cnt < input_times)
    {
		/*Read input*/
		dump = getchar();
		for(y_cnt = 0; y_cnt < 8; y_cnt++)
		{
			dump = getchar();
			for(x_cnt = 0; x_cnt < 8; x_cnt++)
			{
				input[input_cnt].map[x_cnt][y_cnt] = getchar() - 48;
			}
		}
		scanf("%d", &(input[input_cnt].x));
		/*printf("%d", input[input_cnt].x);*/
		scanf("%d", &(input[input_cnt].y));
		/*printf("%d", input[input_cnt].y);*/
		
		/*Process*/
		input[input_cnt].map[(input[input_cnt].x) - 1][(input[input_cnt].y) - 1] = 2;
		explode(&input[input_cnt]);
		
		input_cnt++;
	}
    
    input_cnt = 0;
    while(input_cnt < input_times)
    {
    	printf("Data %d:\n", input_cnt + 1);
    	for(y_cnt = 0; y_cnt < 8; y_cnt++)
		{
			for(x_cnt = 0; x_cnt < 8; x_cnt++)
			{
				printf("%d", input[input_cnt].map[x_cnt][y_cnt]);
			}
			printf("\n");
		}
    	input_cnt++;
	}
    return 0;
} 

BOMB* explode(BOMB* bombmap)
{
	int explode_cnt;
	for(y_cnt = 0; y_cnt < 8; y_cnt++)
	{
		for(x_cnt = 0; x_cnt < 8; x_cnt++)
		{
			if(bombmap->map[x_cnt][y_cnt] == 2)
			{
				bombmap->map[x_cnt][y_cnt] = 0;
				
				explode_cnt = 1;
				while((x_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
				{
					if((bombmap->map[x_cnt - explode_cnt][y_cnt]) == 1)
					{
						(bombmap->map[x_cnt - explode_cnt][y_cnt]) = 2;
					}
					explode_cnt++;
				}
				
				explode_cnt = 1;
				while((x_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
				{
					if((bombmap->map[x_cnt + explode_cnt][y_cnt]) == 1)
					{
						(bombmap->map[x_cnt + explode_cnt][y_cnt]) = 2;
					}
					explode_cnt++;
				}
				
				explode_cnt = 1;
				while((y_cnt - explode_cnt) >= 0 && explode_cnt <= 3)
				{
					if((bombmap->map[x_cnt][y_cnt - explode_cnt]) == 1)
					{
						(bombmap->map[x_cnt][y_cnt - explode_cnt]) = 2;
					}
					explode_cnt++;
				}
				
				explode_cnt = 1;
				while((y_cnt + explode_cnt) <= 7 && explode_cnt <= 3)
				{
					if((bombmap->map[x_cnt][y_cnt + explode_cnt]) == 1)
					{
						(bombmap->map[x_cnt][y_cnt + explode_cnt]) = 2;
					}
					explode_cnt++;
				}
				return explode(bombmap);
			}
		}
	}
	
	return bombmap;
}

Measured memory_bytes: 612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  long long int s;
  scanf("%lld",&s);
  long long int d[10];
  long long int i,j,n;
  for(i=9;i>-1;i--) {
    d[i] = s%10;
    s = s/10;
  }
  //for(i=0;i<10;i++) {
  //  printf("%lld\n",d[i]);
  //}
  long long int diff = 99999999999;
  for(n=3;n<4;n++) {
    for(i=0;i<10-n+1;i++) {
      long long int temp = 0;
      for(j=0;j<n;j++) {
        temp = temp * 10 + d[i+j];
      }
      long long int res = temp - 753;
      if (res < 0) {
        res = - res;
      }
      if(diff>res) {
        diff = res;
      }
    }
  }
  printf("%lld\n",diff);
  return 0;
}


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

int main(){
  int i,j,num;
  int judge=1;
  int count=0;

  scanf("%d",&num);
  int A[num];

  for(i=0; i<num; i++){
      scanf("%d",&A[i]);
    }

  for(i=0; i<num; i++){
    judge = 0;
    //printf("\n");
    if(A[i]==2) {
      judge=0;
    }

    else if(A[i]%2==0) judge=1;

    else if(A[i]%2!=0){
      for(j=3; j<=sqrt(A[i]); j+=2){
        if(A[i]%j==0){
        judge = 1;
        break;
        }
      }
    }

    if(judge==0) count++;


  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
# import numpy as np


def main():
    N = int(input())
    P = list(map(int, input().split()))

    count = 0
    min_P = 200000
    for i in range(N):
        if min_P > P[i]:
            min_P = P[i]
        if min_P == P[i]:
            count += 1
    print(count)

if __name__ == '__main__':
    main()


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int count5, count7;
  count5 = count7 = 0;
  if(a==5)count5++;
  if(a==7)count7++;
    if(b==5)count5++;
  if(b==7)count7++;
      if(c==5)count5++;
  if(c==7)count7++;
   
    if(count5==2&&count7==1){cout << "YES" << endl;
                             return 0;}
  else{cout << "NO" << endl;return 0;}}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll a,b;cin>>a>>b;cout<<a*b/(__gcd(a,b))<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> mat(n, vector<int>(m));
    vector<int> v(m);
    rep(i, n) {
        for (auto &e : mat[i]) {
            cin >> e;
        }
    }
    for (auto &e : v) {
        cin >> e;
    }
    rep(i, n) {
        int cur = 0;
        rep(j, m) { cur += mat.at(i).at(j) * v.at(j); }
        cout << cur << "\n";
    }
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

#define LL long long
#define LD long double
#define INF 1000000000
#define PR pair<int,int>
#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define pb push_back
#define mp make_pair

LL N, W, V;
LL w[105];
LL v[105];
LL dp[105][1000005];


int main() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> w[i] >> v[i];
		V += v[i];
	}

	dp[0][0] = 0;
	for (int i = 1; i <= V; i++) {
		dp[0][i] = INF;
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= V; j++) {
			dp[i][j] = dp[i-1][j];
			if (j >= v[i])
				dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
		}
	}

	for (int i = V; i >= 0; i--) {
		if (dp[N][i] <= W) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 289792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
 
int main(int argc, char* argv[])
{
    long n, m;
    scanf("%ld %ld", &n, &m);

    std::vector<long> a(n+1);
    a[0] = 0;
    long i, j;
    for(i=1; i<=n; i++) {
        scanf("%ld", &(a[i]) );
        a[i] = (a[i-1] + a[i]) % m;
    }
    std::sort( a.begin(), a.end());

    long long num = 0;
    for(i=0; i<n+1; i) {
        long curr = a[i];
        long count = 0;
        for(j=i; j<n+1 && curr==a[j]; j++) {
            count ++;
        }
        if(count>1) {
            num += (long long)count * (count-1) / 2;
        }
        i = j;
    }

    printf("%lld\n", num);

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef int32_t edge_weight;

typedef struct directed_edge {
  int32_t vertex;
  int32_t next;
  edge_weight cost;
} graph_edge;

typedef struct directedGraph {
  graph_edge *edge;
  int32_t *start;
  int32_t pointer;
  int32_t vertex_num;
  int32_t edge_max_size;
} graph;

graph* new_graph (const int vertex_num) {
  graph *g = (graph *) calloc (1, sizeof (graph));
  g->edge = (graph_edge *) calloc (1, sizeof (graph_edge));
  g->start = (int32_t *) calloc (vertex_num, sizeof (int32_t));
  g->pointer = 0;
  g->vertex_num = vertex_num;
  g->edge_max_size = 1;
  for (int32_t i = 0; i < vertex_num; ++i) {
    g->start[i] = -1;
  }
  return g;
}

void free_graph (graph *g) {
  free (g->edge);
  free (g->start);
  free (g);
  return;
}

void clear_graph (graph *g) {
  g->pointer = 0;
  for (int32_t i = 0; i < g->vertex_num; ++i) {
    g->start[i] = -1;
  }
}

void add_edge (graph *g, int32_t from, int32_t to, edge_weight cost) {
  if (g->pointer == g->edge_max_size) {
    g->edge_max_size *= 2;
    g->edge = (graph_edge *) realloc (g->edge, sizeof (graph_edge) * g->edge_max_size);
  }
  g->edge[g->pointer] = (graph_edge) {to, g->start[from], cost};
  g->start[from] = g->pointer++;
}

i32* BFS_graph (graph *g, int32_t src) {
  int32_t *q = (int32_t *) calloc (g->vertex_num, sizeof (int32_t));
  uint8_t *used = (uint8_t *) calloc (g->vertex_num, sizeof (uint8_t));
  int32_t front = 0;
  int32_t last = 0;
  used[src] = 1;
  q[last++] = src;
  while (front < last) {
    const int32_t v = q[front++];
    for (int32_t p = g->start[v]; p != -1; p = g->edge[p].next) {
      const int32_t u = g->edge[p].vertex;
      if (!used[u]) {
	used[u] = 1;
	q[last++] = u;
      }
    }
  }
  free(used);
  return q;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  graph *g = new_graph (n);
  for (i32 i = 1; i < n; ++i) {
    i32 a, b, c;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &a, &b, &c);
    a--;
    b--;
    c %= 2;
    add_edge (g, a, b, c);
    add_edge (g, b, a, c);
  }
  i32 *q = BFS_graph (g, 0);
  i32 *c = (i32 *) calloc (n, sizeof (i32));
  uint8_t *used = (uint8_t *) calloc (n, sizeof (uint8_t));
  used[0] = 1;
  for (i32 i = 1; i < n; ++i) {
    i32 v = q[i];
    used[v] = 1;
    for (i32 p = g->start[v]; p != -1; p = g->edge[p].next) {
      i32 u = g->edge[p].vertex;
      if (used[u]) {
	c[v] = c[u] ^ g->edge[p].cost;
      }
    }
  }
  for (i32 i = 0; i < n; ++i) {
    printf ("%" PRIi32 "\n", c[i]);
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 3968
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

long long v[3100][3100], dp[3100][3100][5];
int main() {
    int R, C, K;
    cin >> R >> C >> K;
    memset(v, 0, sizeof(v));
    for (int i = 0; i < K; ++i) {
        long long r, c, t;
        cin >> r >> c >> t;
        v[r][c] = t;
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= R; ++i) {
        for (int j = 0; j <= C; ++j) {
            for (int k = 0; k <= 3; ++k) {
                // 上へ行く
                if (i - 1 >= 0) {
                    chmax(dp[i][j][0], dp[i - 1][j][k]);
                    chmax(dp[i][j][1], dp[i - 1][j][k] + v[i][j]);
                }

                // 右へ行く
                if (j - 1 >= 0) {
                    chmax(dp[i][j][k], dp[i][j - 1][k]);
                    if (k - 1 >= 0)
                        chmax(dp[i][j][k], dp[i][j - 1][k - 1] + v[i][j]);
                }
            }
        }
    }
    long long res = 0;
    for (int k = 0; k <= 3; ++k)
        chmax(res, dp[R][C][k]);
    cout << res << endl;
}

Measured memory_bytes: 454088
N = int(input())
a = {}
for i in range(N):
    j = int(input())
    if j in a:
        a[j] += 1
    else:
        a[j] = 1
count = 0
for v in a.values():
    if v % 2 == 1:
        count += 1
print(count)

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

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

  int ans = 0;
  for (int i = 0; i <= n-3; i++) {
    string substring = s.substr(i, 3);
    if (substring == "ABC") {
      ans++;
    }
  }

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

Measured memory_bytes: 3512
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <queue>
using namespace std;

int lenght(char* str){
  int i=0;
 while(str[i]){
     i++;
 }
 return i;
}

int main(){
  int N, ans = 0 ;
  char S[1005] ;
  string Sans ;
  cin >> S ;
  ans = lenght(S) ;
  if(S[(ans-1)] == 's'){
    S[ans+2] = S[ans] ;
    S[ans] = 'e' ;
    S[ans+1] = 's' ;
  }
  else{
    S[ans+1] = S[ans] ;
    S[ans] = 's' ;
  }
  cout << S << endl ;
  return 0 ;
}

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

src = [input() for i in range(h)]

ans = []
for row in src:
    ans.append(list(row))
    
for i in range(h):
    for j in range(w):
        if src[i][j] == '#': 
            continue
        c = 0
        if i > 0:
            if j > 0 and src[i-1][j-1] == '#': c += 1
            if src[i-1][j] == '#': c += 1
            if j < w-1 and src[i-1][j+1] == '#': c +=1
        if j > 0 and src[i][j-1] =='#' : c +=1
        if j < w-1 and src[i][j+1] == '#': c +=1
        if i < h-1:
            if j > 0 and src[i+1][j-1] == "#": c +=1
            if src[i+1][j] == '#': c += 1
            if j<w-1 and src[i+1][j+1] == '#' : c += 1
        ans[i][j] = c
        
for row in ans:
    print (''.join(list(map(str,row))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  //0をK回つぶすか、1をK-1回つぶして逆転さすか。
  //1101110110000111
  //2131243に変換する
  //3つの和を調べる
  //最初が0だったら、1の両端、3の両端、5の両端を足す
  //最初が1だったら、2の両端、4の両端、、、を足すか。
  //2134243
  //21943
  //
  //10^5^2/2は多分間に合わないからどこか効率化
  //最初に1個決めてしまえば、あと両端をとってくのみ？
  //1234343434321
  //は、10が大量にある。どれからとるのが効率的か不明
  //常に左右比較で大きいものからとれば最適にはかわりないか
  //12343111111112234322222211
  //候補が複数ある場合の判定難しいな
  //126111111111111111112122222223222222222221111
  //とかがきたら逆転するな
  //結局全探索じゃないか･･･。
  //全探索になる？
  //3個の和、5個の和、7個の和･･･
  //ああああ1回きりの計算でいいっぽくね
  ll N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  ll s=S.size(), tmp=1;
  vector<ll> Z(1,0);
  for(int i=0; i<s-1; i++){//0101 0011100 111001
    if(S[i]==S[i+1])
      tmp++;
    else{
      Z.push_back(tmp);
      tmp=1;
    }
  }
  Z.push_back(tmp);
  Z.push_back(0);//011110, 02320, 03210みたいに
    ll Zs=Z.size(),ans=0;
  if(S[0]=='0' && (Zs-1)/2<=K){//Zs=4 1,=5 2, =6,2   
    cout<<s<<endl;
    return 0;
  }  
  if(S[0]=='1'&& (Zs-2)/2<=K){//Zs=4 1,=5 1, =6,2   
    cout<<s<<endl;
    return 0;
  }  
  vector<ll> sum(Zs,0);
  tmp=0;
  for(int i=0; i<Zs; i++){
    tmp+=Z[i];
    sum[i]=tmp;
  }
  //累積和とる？
  //0123456780
  //最初が0,K=1だったら
  //012,234,456,678
  //K=2なら
  //01234,23456,45678
  //0123456780
  //最初が1,K=1
  //123,345,567,780
  //K=2
  //12345,34567,56780
  ll up=K*2;
  for(int i=(S[0]=='0')? i=0: i=1; i+up<Zs; i+=2)
    ans=max(ans, sum[i+up]-sum[max(i-1,0)]);
  cout<<ans<<endl;
}

Measured memory_bytes: 2164
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string s, t;
    int i;
    int ans = 0;

    cin >> s >> t;

    for (i = 0; i < 3; i++)
    {
        if (s[i] == t[i])
        {
            ans++;
        }
    }

    cout << ans << endl;
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

signed main() {
  uint64_t a, b;
  cin >> a >> b;
  
  if(a<b) cout << "a < b" << endl;
  else if (a>b) cout << "a > b" << endl;
  else cout << "a == b" << endl;
  return 0;
}


Measured memory_bytes: 3100
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

fac = [0] * 8
fac[1] = 1
for i in range(2, N):
    fac[i] = i * fac[i - 1]

a = 0
l = list(range(1, N + 1))
for i in range(N):
    a += l.index(P[i]) * fac[len(l) - 1]
    l.remove(P[i])

b = 0
l = list(range(1, N + 1))
for i in range(N):
    b += l.index(Q[i]) * fac[len(l) - 1]
    l.remove(Q[i])

print(abs(a - b))

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>l(n);
    rep(i,n)cin>>l[i];
    ll ans=0;
    if(n<3){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]==l[j]||l[i]==l[k]||l[j]==l[k])continue;
                if(l[i]+l[j]>l[k]&&l[i]<l[j]+l[k]&&l[i]+l[k]>l[j])ans++;
            }
        }
    }
    cout<<ans<<endl;
}









































Measured memory_bytes: 3572
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N
for i in range(N):
  w, v = map(int, input().split()) 
  ws[i] = w
  vs[i] = v
 
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(1, N+1):
  for sum_w in range(W+1):
    if sum_w - ws[i-1] >= 0:
    	dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w-ws[i-1]]+vs[i-1])
    dp[i][sum_w] = max(dp[i][sum_w], dp[i-1][sum_w])
 
print(max(dp[-1]))

Measured memory_bytes: 120812
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;

const ll INF = 10000000000;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };



int main(void) {
	int X, Y, Z, K;
	ll A[1010], B[1010], C[1010];
	vector<ll> AB, ABC;
	cin >> X >> Y >> Z >> K;
	for (int i = 0; i < X; i++) cin >> A[i];
	for (int i = 0; i < Y; i++) cin >> B[i];
	for (int i = 0; i < X; i++) cin >> C[i];

	for (int i = 0; i < X; i++)
		for (int j = 0; j < Y; j++) AB.push_back(A[i] + B[j]);

	sort(AB.begin(), AB.end(), greater<ll>());
	
	int sz = AB.size();
	for (int i = 0; i < min(K, sz); i++)
		for (int j = 0; j < Z; j++) ABC.push_back(AB[i] + C[j]);

	sort(ABC.begin(), ABC.end(), greater<ll>());

	for (int i = 0; i < min(K, X*Y*Z); i++) cout << ABC[i] << endl;
	

}


Measured memory_bytes: 43276
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){
    
    ll K, X;
    cin >> K >> X;
    if(K * 500 >= X)cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int n;
	while (cin >> n && n){
		vector<VL> dp(n+1, VL(1<<16));
		REP(i,n){
			int m, x = 0;
			ll l;
			cin >> m >> l;
			while (m--){
				int s, e;
				cin >> s >> e;
				s -= 6;
				e -= 6;
				FOR(j,s,e-1) x += 1 << j;
			}
			REP(j,1<<16){
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
				if ((j & x) > 0) continue;
				dp[i+1][j|x] = max(dp[i+1][j|x], dp[i][j] + l);
			}
		}
		ll ans = 0;
		REP(j,1<<16) ans = max(ans, dp[n][j]);
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 55028
#include "bits/stdc++.h"
using namespace std;

int32_t main() {
	ios_base::sync_with_stdio(NULL);
	cin.tie(nullptr), cout.tie(nullptr);

	string s, t;
	cin >> s >> t;
	int replaces = 0;
	for (int i = 0; i < s.size(); i++) 
		replaces += s[i] != t[i];
	cout << replaces << endl;
}

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > pq;

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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;
    }
}

long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main(){
    int N, M; cin >> N >> M;
    vector<int> c(M), cost(50500, MM);
    for (int i = 0; i < M; i++){
        cin >> c[i];
    }
    cost[0] = 0;
    for (int i = 0; i < M; i++){
        for (int j = c[i]; j <= N; j++){
            if (cost[j-c[i]] == MM) continue;
            cost[j] = min(cost[j], cost[j-c[i]] + 1);
        }
    }
    cout << cost[N] << endl;
}


Measured memory_bytes: 3112
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: i64 = s.trim().parse().unwrap();
    let ans: i64 = (1..=n).filter(|&e| !(e % 5 == 0 || e % 3 == 0)).sum();

    println!("{}", ans);
}


Measured memory_bytes: 2108
//#include <bits/stdc++.h>
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
using namespace std;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n&&j>=n;--i)
#define pb push_back
#define m_p make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define mem(p,v) memset(p,v,sizeof(p))
#define present(c,x)    ((c).find(x) != (c).end())
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
const long long inf = 9e18;
double pie = 2*acos(0.0);
void show(vector<lli> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(vector<int> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(int a[], int arraysize){for (int i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(lli a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(bool a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(set<int> s){for (auto it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout<<endl;}
void show(map<lli,lli> mp){for (auto it = mp.begin(); it != mp.end(); it++){cout << it->first << " "<<it->second<<endl;}cout<<endl;}

lli modpow(lli x,lli n){lli res=1;while(n>0){if(n&1) res=((res%MOD)*(x%MOD))%MOD;x=((x%MOD)*(x%MOD))%MOD;n>>=1;}return res;}
lli power(lli x, lli n){lli res=1;while(n>0){if(n&1) res=res*x;x=x*x;n>>=1;}return res;}

/////// ------ Main code starts here ------ /////
bool visited[1000001];
vector<int> gp[1000001];
int dp[1000001];
void dfs(int s)
{
    if(visited[s])
        return;
    visited[s]=true;
    dp[s]=0;
    for(auto i:gp[s])
    {
        dfs(i);
        dp[s]=max(dp[s],dp[i]+1);
    }
}
void solve()
{
    lli n,m,x;
    cin>>n>>m;
    lli a,b;
    for(int i=0;i<n+1;++i)
        visited[i]=false;
    fr(i,0,m)
    {
        cin>>a>>b;
        gp[a].pb(b);
    }
    fr(i,1,n+1)
    if(!visited[i])
    dfs(i);
    lli ans=INT_MIN;
    fr(i,1,n+1)
    {
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}
int main()
{
    run;cout<<fixed<<setprecision(12);
    int t;
    t=1;
    while(t){solve();t--;}
    return 0;
}


Measured memory_bytes: 32608
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main()
{
    fast();
    ll x;
    cin>>x;
    if(x>=30)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


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

int main() {
  int n,k,h,ans=0;
  cin >> n >> k;
  
  for (int i = 0; i < n; i++) {
    cin >> h;
    if (h >= k) ans++;
  }
  
  cout << ans << endl;
}

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

const int maxn = 101, maxv = 1001;
long long  w[maxn], v[maxn], dp[maxn][maxn* maxv];
const long long INF = 1e12;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int N, W;
    cin>>N>>W;
    for(int i= 0; i < N; i++)cin>>w[i]>>v[i];
    fill(dp[0], dp[0]+ maxn*maxv, INF);
    dp[0][0] = 0;
    
    for(int i = 0; i < N; i++)
        for(int j = 0; j < maxv* maxn; j++){
            if(j<v[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]] + w[i]);
            }
        }
    
    long long res = 0;
    for(int i = 0; i<maxv* maxn;i++ )if(dp[N][i]<=W)res = i;
    cout<<res<<endl;
    return 0;
}





Measured memory_bytes: 80000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Miscelleneous {
	class Program {
		static int[] parins() {
			return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		}
		static int parin() {
			return int.Parse(Console.ReadLine());
		}
		static string read() { return Console.ReadLine(); }
		static void Main(string[] args) {
			var I = parins();
			int N = I[0], A = I[1]-1, B = I[2]-1, C = I[3]-1, D = I[4]-1;
			var S = read().Select(c => c == '#').ToArray();
			bool Res = !(HasWall(S, A, C) || HasWall(S, B, D));
			if (Res && C > D) Res = HasStation(S, B, D);
			Console.WriteLine(Res ? "Yes" : "No");
			read();
		}

		static bool HasWall(bool[] S,int start,int goal) {
			var phase = 0;
			for (var i = start; i <= goal; i++) {
				if (S[i]) {
					phase++;
					if (phase >= 2) return true;
				}
				else phase = 0;
			}
			return false;
		}
		static bool HasStation(bool[] S,int fStart,int fGoal) {	
			//Rem: fStart>=1,fGoal<=N-2
			var empty = 0;
			for (int i = fStart-1; i <= fGoal+1; i++) {
				if (!S[i]) {
					empty++;
					if (empty >= 3) return true;
				}
				else empty = 0;
			}
			return false;
		}

	}

}

Measured memory_bytes: 14560
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int red = 0;
    FORE(e, S) if (e == 'R') red++;
    if (red * 2 > S.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll x,y;
  cin >> x >> y;
  ll a = y / x;
  int result = 0;
  while(a != 0){
    a /= 2;
    result++;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
string s;
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>s;
    int cnt=0;
    int x=0;
    for(int i=0;i<N;i++)
    {
        cnt=(s[i]=='I'?max(cnt,++x):max(cnt,--x));
    }
    cout << cnt <<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int64_t> A(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());
    vector<int64_t> S(n + 1);
    const int64_t INF = 1e17;
    int64_t ans = INF;

    for (int i = 0; i < n; i++)
        S[i + 1] = S[i] + A[i];

    int i = 1, k = 3;
    for (int j = 2; j < n - 1; j++){
        k = max(k, j + 1);
        while(i < j - 1 and S[i] < S[j] - S[i])
            i++;
        while(k < n - 1 and S[k] - S[j] < S[n] - S[k])
            k++;
        for (int a = 0; a <= 1; a++){
            for (int b = 0; b <= 1; b++){
                vector<int64_t> D(4);
                D[0] = S[max(1, i - a)];
                D[1] = S[j] - D[0];
                D[2] = S[max(j + 1, k - b)] - S[j];
                D[3] = S[n] - S[max(j + 1, k - b)];
                int64_t ma = *max_element(D.begin(), D.end());
                int64_t mi = *min_element(D.begin(), D.end());
                ans = min(ans, ma - mi);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3328