akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    int n,a,b;
    cin >> n ;
    if(n == 1 ){cout << "Hello World" << endl;}
    else {cin >> a >> b; cout << a + b << endl;}
    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 rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
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; }

const int MAX_N = 100010;
int q, l[MAX_N], r[MAX_N];
int nlike[MAX_N];
bool like[MAX_N];
bool is_prime[MAX_N];

void eratos() {
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i < MAX_N; i++) is_prime[i] = true;
    for (int i = 2; 2*i < MAX_N; i++) {
        is_prime[2*i] = false;
    }
    for (int i = 3; i < sqrt(MAX_N); i++) {
        if (is_prime[i]) {
            for (int j = 2*i; j < MAX_N; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

void acc() {
    eratos();
    for (int i = 1; i < MAX_N; i++) {
        if (i%2==1 && is_prime[i] && is_prime[(i+1)/2]) like[i] = true;
    }
    for (int i = 1; i < MAX_N; i++) {
        nlike[i] = nlike[i-1] + like[i];
    }
}

int main() {
    cin >> q;
    rep(i, q) cin >> l[i] >> r[i];
    acc();
    rep(i, q) {
        int a = l[i], b = r[i];
        cout << nlike[b] - nlike[a-1] << endl;
    }
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	unsigned long long s = 0;
	for (int i = 0; i < n - k; i++) {
		s += v[i];
	}
	cout << s << endl;
	return 0;
}

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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int k, x;
  int n;
  cin >> n;
  vector<string> vs;
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    vs.push_back(s);
  }
  sort(vs.begin(), vs.end());
  ll ans = 0;
  ll i = 0, j = 0;
  while(i<n&&j<n){
    while(vs[i]==vs[j]){
      j++;
      if(j==n) break;
    }
    ans += (j-i)*(j-i-1)/2;
    i = j;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7452
N = int(input())
n, p, score = N, 2, 0
while p ** 2 <= N and n > 1:
  e = 1
  while n % (p ** e) == 0:
    n //= (p ** e)
    score += 1
    e += 1
  else:
    while n % p == 0:
      n //= p
    p += 2 - (p == 2)
else:
  score += n > 1
print(score)

Measured memory_bytes: 9200
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, m, t; cin >> n >> m >> t;
    int check[10100];
    rep(i, 10100) check[i] = 0;
    rep(i, n) {
        int a; cin >> a;
        check[a - m] = 1, check[min(t, a + m)] = -1;
    }
    rep(i, 10000) {
        check[i + 1] += check[i];
    }
    int ans = 0;
    rep(i, t) {
        if(check[i] == 0) ++ ans;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n;
	ll count[5] = { 0, 0, 0, 0, 0 };

	cin >> n;

	REP(i, n) {
		string s;
		cin >> s;
		if (s[0] == 'M') {
			count[0]++;
		}
		else if (s[0] == 'A') {
			count[1]++;
		}
		else if (s[0] == 'R') {
			count[2]++;
		}
		else if (s[0] == 'C') {
			count[3]++;
		}
		else if (s[0] == 'H') {
			count[4]++;
		}
	}

	ll ans = 0;

	REP(i, 3) {
		FOR(j, i + 1, 4) {
			FOR(k, j + 1, 5) {
				ans += count[i] * count[j] * count[k];
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    // 言語をc++にするの忘れない

    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
}

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

using namespace std;
const int INF=1e9+5;
int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];}
	vector<int> dp(n);
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	if(n==2){
		cout<<dp[1]<<endl;}
	else{
	dp[2]=abs(v[2]-v[0]);
	for(int i=3;i<n;i++){
		dp[i]=min(dp[i-1]+abs(v[i-1]-v[i]),dp[i-2]+abs(v[i-2]-v[i]));
	}
	cout<<dp[n-1];}
	
	
	
}


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

int main(void) {
  int n;
  scanf("%d", &n);
  int d = (int)(log2(n) / log2(3));
  if((int)(log2(n) / log2(3)) != log2(n) / log2(3)) ++d;
  printf("%d\n", d);
  return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"¥n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n);

	if (n == 0) {
		OUT(0);
		return 0;
	}
	vector< int > ans;
	while (n != 0) {
		if (abs(n) % 2 == 1) {
			ans.push_back(1);
			n--;
		} else {
			ans.push_back(0);
		}
		n /= -2;
		//debug(n);
	}

	RREP(i, ans.size()) {
		OUT(ans[i]);
	}
	
  
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
MOD=10**9+7
N=int(input())

def factorize(M):
  fact=defaultdict(int)
  for i in range(2,int(M**0.5)+1):
    if M==1:
      break
    while(M%i==0):
      M//=i
      fact[i]+=1
  
  if M!=1:
    fact[M]=1
  return fact

pdic=defaultdict(int)
for i in range(2,N+1):
  fact=factorize(i)
  for k,v in fact.items():
    pdic[k]+=v
#print(pdic)

answer=1
for v in pdic.values():
  answer*=(v+1)
  answer%=MOD
  
print(answer)

Measured memory_bytes: 3444
#include<stdio.h>
int main(){
    int a,b;

    scanf ("%d %d",&a,&b);

    if (a < b){
      printf ("a < b\n");
    }
    else if (a > b){
      printf ("a > b\n");
    }
    else {
      printf ("a == b\n");
    }
    return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main(){
  int N, sum = 0 , sumleft = 0 ;
  int ans = 100000 ;
  cin >> N ;
  int A[N];
  rep(i,N) cin >> A[i];
  rep(i,N) sum +=A[i] ;
  for(int i =0 ; i < N-1 ; i++){
  sumleft += A[i];
  int sumright = sum - sumleft ;
  int B = max( sumleft - sumright , sumright - sumleft );
  //cout << B << endl;
  ans = min(ans,B);
  }
  cout << ans << endl;
}
    
    

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int[]nW=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n=nW[0];
        long W=nW[1];
        long[]w=new long[n];
        int[]v=new int[n];
        for(int i=0;i<n;i++){
            int[]wv=Console.ReadLine().Split().Select(int.Parse).ToArray();
            w[i]=(long)wv[0];
            v[i]=wv[1];
        }
        int V=v.Sum();
        long[]dp=new long[V+1];
        for(int i=1;i<=V;i++){
            dp[i]=long.MaxValue;
        }
        for(int i=0;i<n;i++) {
            for(int j=V-v[i];j>=0;j--){
                if(dp[j]==long.MaxValue)continue;
                Chmin(ref dp[j+v[i]], dp[j]+w[i]);
            }
        }
        long ans=0;
        for(int i=0;i<=V;i++){
            if(dp[i]<=W)ans=i;
        }
        Console.WriteLine(ans);
    }
    public static void Chmin(ref long x, long y) {
        x = Math.Min(x, y);
    }
}



Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s[200000];
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> s[i];
	}
	sort(s, s + n);
	int ans = 1;
	for(int i = 1;i < n;i++){
		if(s[i] != s[i - 1]){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9760
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;


void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//ワーシャルフロイト法のテンプレ.graphに最短経路が格納される.inf + const = inf に気を付ければ大丈夫
//graphは隣接行列
void WF(vector<vector<ll>> &graph){
	int n = graph.size();
	for (int k = 0; k < n; k++){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
			}
		}
	}
}

int main() {
	ll n, m, l;
	cin >> n >> m >> l;
	vector<vector<ll>> graph(n, vector<ll>(n, Inf));
	rep(i, m)
	{
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		graph[a][a] = 0;
		graph[b][b] = 0;
		graph[a][b] = c;
		graph[b][a] = c;
	}

	WF(graph);
	vector<vector<ll>> graph2(n, vector<ll>(n, Inf));
	rep(i,n){
		rep(j,n){
			if(graph[i][j] <= l)
				graph2[i][j] = 1;
		}
	}
	
	WF(graph2);
	int q;
	cin >> q;
	rep(i, q){
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		if (graph2[s][t] == Inf)
			cout << -1 << endl;
		else 
			cout << graph2[s][t] - 1 << endl;
	}

		return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

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

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX_N = 1011;
ll dp[MAX_N][MAX_N];

void init() {
	for (ll i = 0; i < MAX_N; i++) {
		for (ll j = 0; j < MAX_N; j++) {
			dp[i][j] = 0;
		}
	}
}

int main() {
	ll H, W;
	cin >> H >> W;
	vector<string> A;
	ll i, j;
	for (i = 0; i < H; i++) {
		string s;
		cin >> s;
		A.push_back(s);
	}

	dp[0][0] = 1;

	for (j = 1; j < W; j++) {
		if (A[0][j] != '#') {
			dp[0][j] = dp[0][j - 1];
		}
	}
	for (i = 1; i < H; i++) {
		if (A[i][0] != '#') {
			dp[i][0] = dp[i - 1][0];
		}
	}

	for (i = 1; i < H; i++) {
		for (j = 1; j < W; j++) {
			if (A[i][j] != '#') {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			}
		}
	}
	cout << dp[H - 1][W - 1] << endl;

	return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
//int main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
int main(){
 string S;
 cin >> S;
 int N = S.size();
 string ans = "yes";
 for(int i = 0; i < N; ++i){
 for(int j = i + 1; j < N; ++j){
 if(S[i] == S[j]){
     ans = "no";
 }
 }
 }
cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 200000 + 5;
const double PI = acos(-1);
#define ll long long

class TaskC {
private:
	Debugger debugger;
	int get(vector<ll> &a, vector<ll> &b, int limit){
		int ans = 0;
		int n = a.size();
		int m = b.size();
		for(int i = 0; i < n; i++){
			if(a[i] <= limit){
				auto it = upper_bound(b.begin(), b.end(), limit - a[i]);
				int pos = 0;
				if(it != b.begin()){
					pos = it - b.begin();
				}
				ans = max(ans,pos + i + 1);
			}
		}
		return ans;
	}

public:
	void solveOne(int it){
		int n, m;
		int limit;
		cin >> n >> m;
		cin >> limit;
		vector<ll> a(n);
		vector<ll> b(m);
		for(int i = 0; i < n; i++){
			cin >> a[i];
			if(i){
				a[i] += a[i-1];
			}
		}
		for(int i = 0; i < m; i++){
			cin >> b[i];
			if(i){
				b[i] += b[i-1];
			}
		}
		int ans = get(a, b, limit);
		ans = max(ans, get(b, a, limit));
		cout << ans << endl;

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


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

int main()
{
    int n, x, y;
    vector<int> res(2001, 0);
    cin >> n >> x >> y;
    x--; y--;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (j <= x || i >= y) {
                res[j-i]++;
                continue;
            }
            int ii = max(i, x);
            int jj = min(j, y);
            int dist = max(x-i, 0) + max(j-y, 0) + min(jj-ii, y-jj + ii-x + 1);
            res[dist]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 256
from bisect import bisect_left

N, Q = map(int, input().split())
A = [int(i) for i in input().split()]
X = [int(input()) for _ in range(Q)]

i = (N & 1) ^ 1
j = N // 2

st = sum(A[j:])

ret_k = []
ret_v = []

while i < j :
    ret_k.append((A[i] + A[j]) // 2)
    ret_v.append(st)
    st = st - A[j] + A[i]
    i += 2
    j += 1
ret_k.append(1e+12)
ret_v.append(st)

for x in X :
    print(ret_v[bisect_left(ret_k, x)])

Measured memory_bytes: 77676
<?php

//$_input = explode(
//    "\n",
//    '000'
//);

function getNext() {
    return trim(
        isset($GLOBALS['_input'])
            ? array_shift($GLOBALS['_input'])
            : fgets(STDIN)
    );
}

$s = getNext();
$count = count(array_filter(str_split($s), function ($x) {
    return $x === '1';
}));

printf("%d\n", $count);



Measured memory_bytes: 4604
N=int(input())
P=[int(x)-1 for x in input().split()]
Q=[int(x)-1 for x in input().split()]
ap=[[-1 for i in range(N)]for j in range(N)]
b=[0]*N
for i in range(N+1):
    for j in range(N):
        if ap[j][P[j]]>=0:
            if b[j]==0:b[j]=i-ap[j][P[j]]
        else:
            ap[j][P[j]]=i
        P[j]=Q[P[j]]
a=[ap[i][i] for i in range(N)]
flag=True
if sum(A<0 for A in a)>0:
    flag=False
A=0
B=1
def extgcd(a,b):
    if b==0:
        return (a,1,0)
    q=a//b
    g,x,y=extgcd(b,a-q*b)
    z=x-q*y
    return (g,y,z)
def f(A,B,a,b):
    g,x,y=extgcd(B,b)
    if (a-A)%g!=0:
        return (0,0)
    x*=(a-A)//g
    A+=B*x
    B=B//g*b
    A%=B
    if A<0:A+=B
    return (A,B)
for i in range(N):
    if flag:
        A,B=f(A,B,a[i],b[i])
        if B==0:flag=False
print(A if flag else -1)



Measured memory_bytes: 5936
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n, k;
	cin >> n >> k;
	k--; n--;
  int ans;
  ans=n/k;
  if(n%k!=0) ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
Ax = A * 25
if Ax & 1:
    Ax += 1
Ay = (A + 1) * 25
if Ay & 1:
    Ay += 1
Ax //= 2
Ay //= 2
Bx = B * 10
By = (B + 1) * 10

if Ay <= Bx or By <= Ax:
    print(-1)
else:
    ans = max(Bx, Ax)
    print(ans)

Measured memory_bytes: 38256
//=template==================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long LL;

// conversion
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//===========================================================================//

//=function prototype========================================================//

//===========================================================================//

//=variables=================================================================//
long X, Y, Z;
//===========================================================================//
int main(void)
{
  // Scan begin.
  scanf("%ld %ld %ld", &X, &Y, &Z);
  // Scan done.

  // Code begin.
  printf("%ld\n", (X-Z)/(Y+Z));
  // Code done.

  // return begin.
  return 0;
  // return done.
}

//=functions=================================================================//

//===========================================================================//

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long ll[200001];
int main()
{
	
	int n;
	int j;
	int ans=1;
	int m=1;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> j;
		ll[j] = i + 1;
	}
	for (int i = 1; i <= n; i=i+m)
	{
		m = 1;
		for (int k = i; k <= n; k++)
		{
			
			if (ll[k] < ll[k + 1])
				m++;
			else
			{
				if (m > ans)
					ans = m;
				break;
			}

		}

	}
	cout << n - ans;

}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        Integer num[] = new Integer[n];
        for (int i = 0; i < n; i++) {
            num[i] = scan.nextInt();
        }
        Arrays.sort(num, Collections.reverseOrder());
        int Alice = 0;
        int Bob = 0;
        for(int i=0; i< num.length; i++) {
            if(i % 2 ==0 ) {
                Alice = Alice + num[i];
            } else {
                Bob = Bob + num[i];
            }
        }
        System.out.print(Alice - Bob);
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

vector<int> makePrimes(int n) { 
    vector<int> res, pr(n + 1, 1);
    pr[0] = pr[1] = 0;
    for(int p=2;p<sqrt(n)+2;p++) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0;
    for(int p=2;p<n + 1;p++) if (pr[p]) res.push_back(p);
    return res;
}

int main(){
	int a;
	while(scanf("%d",&a)!=EOF){
		cout << makePrimes(a).size() << endl;
	}
}


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

int main()
{
	int a,b,c;
	bool flag=false;
	cin>>a>>b>>c;
	for(int i=0;i<10000000;i++)
	{
		if((a*i)%b==c%b)
		{
			flag=true;
			break;
		}
	}
	if(flag==true)cout<<"YES\n";
	else cout<<"NO\n";
//	if(a%b==c%b || c%b==0)
//	{
//		cout<<"YES\n";
//	}
//	else
//	{
//		bool flag=false;
//		int hit=0,sum=a;
//		while(1)
//		{
//			hit++;
////			a+=a;
//			sum+=a;
//			if(sum%b==c%b){
//				flag=true;
//				break;
//			}
//			if(sum>b && hit>=10)break;
//		}
//		if(flag==true)cout<<"YES\n";
//		else cout<<"NO\n";
//	}
//
//	
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc110/tasks/abc110_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf(" %c%c", 'a' + a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
#define DUMPB(a, n) REP(_i, n) printf(" %c%c", a[_i] ? 'o' : 'x', _i + 1 == n ? '\n' : ' ')

const int S_MAX = 2*1e5;

char S[S_MAX + 1];
char T[S_MAX + 1];

int N;
int cnv[26];
bool used[26];

void solve() {
  N = strlen(S);
  REP(i, 26) cnv[i] = -1;

  REP(i, N) {
    int s = S[i] - 'a';
    int t = T[i] - 'a';
    if (cnv[s] >= 0) {
      if (cnv[s] != t ) {
        puts("No");
        return;
      }
    } else {
      if (used[t]) {
        puts("No");
        return;
      }
      cnv[s] = t;
      used[t] = true;
    }
  }

  puts("Yes");
}

void input() {
  scanf("%s", S);
  scanf("%s", T);
}

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


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

int main()
{
	int X,Y,cnt;
	while(cin >> X >> Y, (X||Y))
	{
		cnt = 0;

		if(X<Y) swap(X,Y);
		while(Y!=0)
		{
			cnt++;
			X%=Y;
			swap(X,Y);
		}

		cout << X << " " << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, m, atari, d;
string s[35];
int a[35][11];
signed main() {
	while (cin >> n, n) {
		cin >> m >> atari >> d;
		for0(i, d)cin >> s[i];
		for1(i, n)a[0][i] = i;
		for1(j, d) {
			for1(i, n)a[j][i] = a[j - 1][i];
			for0(i, n - 1)if (s[j - 1][i] == '1')swap(a[j][i + 1], a[j][i + 2]);
		}
		atari = a[d][atari];
		if (atari == m) {
			printf("0\n");
			continue;
		}
		for1(j, d) {
			for0(i, n - 1) {
				if (s[j - 1][i] == '1')continue;
				if (i > 0)if (s[j - 1][i - 1] == '1')continue;
				if (i < n - 1)if (s[j - 1][i + 1] == '1')continue;
				if (a[j][i + 2] == m && a[j][i + 1] == atari) {
					cout << j << ' ' << i + 1 << endl;
					goto heaven;
				}
				if (a[j][i + 2] == atari && a[j][i + 1] == m) {
					cout << j << ' ' << i + 1 << endl;
					goto heaven;
				}
			}
		}
		printf("1\n");
	heaven:;
	}
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

typedef long long ll;
typedef pair<int, int> p;


int main(){
  ll n, x;
  cin >> n >> x;
  // ll res = 3 * x * ((n-x) / x);
  n -= x;
  ll res = 0;
  while(x != 0){
    ll tmp = x;
    ll num = n / x;
    res += 3 * x * num;
    if(x == 0) break;
    x = n % x;
    n = tmp;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <float.h>
int main(void){
    double x;
    double min=DBL_MAX,max=DBL_MIN;
    while(1){
        x=-1;
        scanf("%lf",&x);
        if(x==-1)break;
        if(x<min)min=x;
        if(x>max)max=x;
    }
    
    printf("%lf\n",max-min);
    
    return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

long long modinv(long long a, long long valid = 1000000007)
{
	long long b = valid, u = 1, v = 0;
	while (a)
	{
		if (a < b)
		{
			swap(a, b);
			swap(u, v);
		}
		long long t = a / b;
		a -= t * b;
		u -= t * v;
	}
	v %= valid;
	if (v < 0)
		v += valid;
	return v;
}

void execute()
{
	lint X, Y;
	lint n, r;
	lint ans = 1, div = 1;
	cin >> X >> Y;
	r = (X + Y) / 3;
	n = min(X - r, Y - r);
	if (n < 0 || (X + Y) % 3 != 0)
	{
		cout << 0 << endl;
		return;
	}

	for (int i = 0; i < n; i++)
	{
		ans *= r - i;
		div = i + 1;

		ans = ans % INV * modinv(div) % INV;
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), m = in(), r = in();
    vll v(r);
    rep(i, r)
    {
        cin >> v[i];
        --v[i];
    }
    sort(ALL(v));
    vvll d(n, vll(n, INF));
    rep(i, n) d[i][i] = 0;
    rep(i, m)
    {
        ll a = in(), b = in(), c = in();
        --a;
        --b;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k, n) rep(i, n) rep(j, n)
    {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    ll ans = LINF;
    do
    {
        ll sum = 0;
        rep(i, r - 1)
        {
            sum += d[v[i]][v[i + 1]];
        }
        ans = min(ans, sum);

    } while (next_permutation(ALL(v)));
    cout << ans << endl;
}

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


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--) {
        int g[9], j[9];
        int win = 0;
        for(int i=0; i<9; i++) cin>>g[i];
        for(int i=0; i<9; i++) cin>>j[i];
        sort(j, j+9);
        do {
            int point = 0;
            for(int i=0; i<9; i++) if(g[i]>j[i]) point += g[i]+j[i];
            if(point>85) win++;
        } while(next_permutation(j, j+9));
        double p = (double) win/362880;
        printf("%.5f %.5f\n", p, 1.0-p);
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define rep(i, a, b)    for(int i = (a); i <= (int)(b); ++i)
#define per(i, a, b)    for(int i = (a); i >= (int)(b); --i)
#define debug(x)    cerr << #x << ' ' << x << endl;
using namespace std;
 
typedef long long ll;
const int MAXN = 2e5 + 7;
 
struct node{
    int val, cost;
    bool use;
    friend bool operator < (const node &a, const node &b){
        return a.cost < b.cost;
    }
}s[MAXN];
int main() {
    int n, m;
    cin >> n >> m;
    rep(i, 1, n){
        cin >> s[i].cost >> s[i].val;
    }
    sort(s+1, s+1+n);
    priority_queue<int> que;
    int cur = 1;
    ll res = 0;
    rep(i, 1, m){
        while(s[cur].cost <= i && cur <= n){
            que.push(s[cur].val);
            cur++;
        }
        if(que.size()){
            res += que.top();
            que.pop();
        }
    }
    cout << res << endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> x(n), y(n), h(n);
	REP(i, n)cin >> x[i] >> y[i] >> h[i];
	REP(i, 101) {
		REP(j, 101) {
			int m = INF;
			bool ok = true;
			REP(k, n) {
				if (h[k] == 0)continue;
				m = abs(i - x[k]) + abs(j - y[k]) + h[k];
				break;
			}
			REP(k, n) {
				if (h[k] != max(0ll,m - abs(i - x[k]) - abs(j - y[k])))ok = false;
			}
			if (ok) {
				cout << i << " " << j << " " << m << endl;
				return 0;
			}
		}
	}
}

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

struct Edge{
	int to, cost;
	/*
	bool operator < (const Edge& edge) const {
		return cost < edge.cost;
	}
	*/
};


vector<Edge> list[20];
bool check[20] = {false};

int dfs1(int a){
	check[a] = true;
	int res = 0;
	for(size_t i = 0; i < list[a].size(); ++i){
	   Edge	e = list[a][i];
	   if(list[e.to].size() != 1 && !check[e.to]){
		  	res += dfs1(e.to) + e.cost * 2;
		}
	}
	return res;
}

int dfs2(int a){
	check[a] = true;
	int res = 0;
	for(size_t i = 0; i < list[a].size(); ++i){
	   Edge	e = list[a][i];
	   if(list[e.to].size() != 1 && !check[e.to]){
		   res = max(res, dfs2(e.to) + e.cost);
	   }
	}
	check[a] = false;
	return res;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	while(cin >> n && n != 0){
	
		for(int i = 0; i < n - 1; ++i){
			int a, b, t;
			cin >> a >> b >> t;
			--a, --b;
			list[a].push_back(Edge{b, t});
			list[b].push_back(Edge{a, t});
		}
		/*
		for(int i = 0; i < n; ++i){
			sort(list[i].begin(), list[i].end());
		}
		*/
		
		int cost1 = dfs1(0);
		
		for(int i = 0; i < 20; ++i){
			check[i] = false;
		}
		
		int cost2 = dfs2(0);
		
		cout << cost1 - cost2 << endl;
		
		for(int i = 0; i < 20; ++i){
			while(!list[i].empty()){
				list[i].pop_back();
			}
		}
		
		for(int i = 0; i < 20; ++i){
			check[i] = false;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1216
# 写経AC
N = int(input())
A = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

# N!
fact = 1
for n in range(2, N + 1):
    fact = (fact * n) % MOD


factInvSum = [pow(n, MOD-2, MOD) for n in range(N+1)]
for i in range(N):
    factInvSum[i+1] = (factInvSum[i+1] + factInvSum[i]) % MOD

ans = 0
for i in range(N):
    coef = (factInvSum[N-i] + factInvSum[i+1] - factInvSum[1]) % MOD
    ans = (ans + coef * A[i]) % MOD

ans = (ans * fact) % MOD

print(ans)

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, k;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++) {
        if(i % k == 0) {
            print("OK");
            return 0;
        }
    }
    print("NG");
}

Measured memory_bytes: 3648
program main
   implicit none
   character(100000)c,d,e
   integer::i,le,dl=0,el=0
   read(*,*)c
   le=len_trim(c)
   do i=1,le,2
     if(c(i:i)=='0')then
        dl=dl+1
     else
        el=el+1
     endif
   enddo
   do i=2,le,2
     if(c(i:i)=='1')then
        dl=dl+1
     else
        el=el+1
     endif     
   enddo
   write(*,'(i0)')min(dl,el)
end program main


Measured memory_bytes: 768
/*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pai pair<int,int>
#define pal pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,b) for(int i=a;i<=b;i++)
#define ff first 
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll,ll>
#define mpi map<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int INF = INT_MAX;

vi adj[100005];
int ind[100005];
int longest[100005];

int dfs(int start){
    if(longest[start]!=-1) return longest[start];
    int child=0;
    for(auto x:adj[start]){
        child=max(child,dfs(x));
    }
    return longest[start]=child+1;
}

void solve(){
    int n,m;
    cin>>n>>m;
    while(m--){
        int u,v;
        cin>>u>>v;
        u--,v--;
        adj[u].pb(v);
        //adj[v].pb(u);
        ind[v]++;
    }
    int ans=0;
    memset(longest,-1,sizeof(longest));
    for(int i=0;i<n;i++){
        if(ind[i]==0){
            ans=max(ans,dfs(i));
           // cout<<i<<endl;
        }
    }
   // cout<<endl;
    cout<<ans-1<<endl;
}

int main(){
    solve();
}


Measured memory_bytes: 14536
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >>b;
    
    if(a == 1 && b != 1)cout << "Alice" << endl;
    else if(b == 1 && a != 1)cout << "Bob" << endl;
    else if(a > b)cout << "Alice" << endl;
    else if(a < b)cout << "Bob" << endl;
    else cout << "Draw" << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a, b, *L = map(int, input().split())
x = 0
for l in L:
  x ^= l
s = a+b
if s-x < 0 or (s-x)%2:
  print(-1)
  exit()
d = (s-x)//2
if d&x:
  print(-1)
  exit()
if d > a:
  print(-1)
  exit()
for i in range(50, -1, -1):
  if (x>>i)&1 and d|(1<<i) <= a:
    d |= 1<<i
if d == 0:
  print(-1)
  exit()
ans = a - d
print(ans)

Measured memory_bytes: 9156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define MAX_V 100


// ????????¨???
struct edge{int to,cap,rev;};

vector<edge> G[MAX_V];  //??°???????????????
int level[MAX_V];       //?§??????????????????¢
int iter[MAX_V];        //???????????§????????????

// from??????to?????????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap){
	G[from].push_back(  (edge){ to  ,cap,(int)G[to  ].size()   }  );
	G[to  ].push_back(  (edge){ from,0  ,(int)G[from].size()-1 }  );
}

// s????????????????????¢???BFS??§?¨??????????
void bfs(int s){
	rep(i,MAX_V)level[i]=-1;
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		
		rep(i,G[v].size()){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0&&level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

// s??????t???????????§???????±???????
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}


int main(){
	int v,e;
	cin>>v>>e;
	rep(i,e){
		int a,b,c;
		cin>>a>>b>>c;
		add_edge(a,b,c);
	}
	cout<<max_flow(0,v-1)<<endl;
}

Measured memory_bytes: 3180
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), K=sc.nextInt(), sum=0;
    int A[] = new int[N];
    for(int i=0; i<N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    for(int j=0; j<K; j++) {
      sum += A[j];
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 38680
program atcoder
    implicit none
    integer :: n,maxp,sum,i,k
    maxp = 0
    sum = 0
    read *,n
    do i = 1,n
        read *,k
        sum = sum + k
        maxp = max(maxp,k)
    enddo
    write(*,'(I0)')sum-maxp/2
!----------------------functions--------------------------
contains

end program atcoder

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    char a;
    cin >> a;
    vector<char> v {'a', 'e', 'i', 'o', 'u'};
    if(find(v.begin(), v.end(), a) != v.end()){
        cout << "vowel";
    }
    else
    {
        cout << "consonant";
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int x[] = new int[n+1];


		for (int i=0;i<=n;++i){
			x[i]=sc.nextInt();
		}

		Arrays.sort(x);

		int common=x[1]-x[0];
		int a;
		int b;
		int c;

		for (int i=1;i<n;++i){
			a=Math.max(x[i]-x[i-1], x[i+1]-x[i]);
			b=Math.min(x[i]-x[i-1], x[i+1]-x[i]);
			while (b!=0&&(c=a%b)!=0){
				a=b;
				b=c;
			}
			common = Math.min(common, b);
		}

		System.out.println(common);

	}
}

Measured memory_bytes: 49740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define F first
#define S second
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;}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  IN(ll,N);
  IN(ll,M);
  vector<P> ab(M);
  REP(i, M){
    cin >> ab.at(i).second >> ab.at(i).first;
  }
  SORT(ab);
  ll count = 0;
  ll num = 0;
  REP(i,M){
    if(ab.at(i).second >= num){
      count++;
      num = ab.at(i).first;
    }
  }
  OUT(count);
}

Measured memory_bytes: 1792
N, M = map(int, input().split())
graph = [[] for i in range(N)]
alst, blst = [], []
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    alst.append(a)
    blst.append(b)
    graph[a].append(b)
    graph[b].append(a)

all_use = (1 << N) - 1


def rec(v, use):
    use |= 1 << v
    for u in range(N):
        if (u not in graph[v]) or (use >> u) & 1:
            continue
        use |= rec(u, use)
    return use


ans = 0
for a, b in zip(alst, blst):
    graph[a].remove(b)
    graph[b].remove(a)
    if rec(0, 0) != all_use:
        ans += 1
    graph[a].append(b)
    graph[b].append(a)
print(ans)


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

int main()
{
  int n;
  cin >> n;
  int a;
  int ans = 1000000001;
  for (int i = 0; i < n; ++i)
  {
    cin >> a;
    int t = 0;
    while(a % 2 == 0)
    {
      a /= 2;
      t++;
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll mod=1e9+7;
const ll inf=1ll<<60;

/* */

int main(){

    // 入力スタンダード（複数指定）
    int N, W; // 1<= N <= 100
    cin >> N >> W; // 1<= W <= 10^5
    
    // **************************************
    int w[N]; 
    ll v[N];  
    for(int i=0; i<N; i++){
        cin >> w[i] >> v[i] ;
    } 
    // **************************************

    // おそらくコンパイラのバグ
    //以下の通り指定すると上手く動かない
    //long long dp[N+1][W+1] = {0};
    //ll dp[110][100100] = {0};
    //*********************************
    
    ll dp[N+1][W+1];
    for(int i=0; i<N+1; i++){
        for(int j=0; j<W+1; j++){
            dp[i][j] = 0;
        }
    }
    
    for(int i=0; i<N; i++){
        for(int sum_w =0; sum_w <= W; sum_w++){
            // i番目を選ぶ場合
            if(sum_w - w[i] >= 0){
                chmax(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }

            // i番目を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    /*
    for(int i=0; i<=N; i++){
        cout << i << " :" ;
        for(int j=0; j<=W; j++){
            cout << " " << dp[i][j];
        }
        cout << endl;
    }
    */

    cout << dp[N][W] << endl;


    return 0;
}

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

int main() {
  int x,a,b,A,B;
  cin >> x >> a >> b;
  A=a-x;
  B=b-x;
  if (A<0){
    A=A*(-1);
  }
  if (B<0){
    B=B*(-1);
  }
  if(A>B){
    cout << "B" << endl;
  }
  else{
    cout << "A" << endl;
  }
}


Measured memory_bytes: 764
n=int(input())
s=[]
for i in range(n):
    s.append("".join(sorted(input())))

S=set(s)

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

from collections import Counter

ans=0
l=Counter(s)
for x in S:
    a=l[x]
    if a<2:
        continue
    else:
        ans+=cmb(a,2)
print(ans)



Measured memory_bytes: 27080