akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const int N = 1 << 17;
int n;
int a[N] , v[N];
int ch1[N];
int ch2[N];
vector < pair < long long , long long > > dfs(int node , long long val){
    if(!ch1[node]){
        return vector < pair < long long , long long > > (1 , make_pair(0LL , 0LL));
    }
    int l = ch1[node];
    int r = ch2[node];
    vector < pair < long long , long long > > res1;
    vector < pair < long long , long long > > res2;
    auto lft = dfs(l , val);
    auto rgt = dfs(r , val);
    int i = 0;
    int j = 0;
    for(auto ll : lft){
        while(i + 1 < rgt.size() && ll.second + v[l] + v[r] + rgt[i + 1].first <= val){
            ++i;
        }
        if(i < rgt.size() && ll.second + v[l] + v[r] + rgt[i].first <= val){
            res1.emplace_back(make_pair(ll.first + v[l] , rgt[i].second + v[r]));
        }
        while(j < rgt.size() && rgt[j].second + v[r] + v[l] + ll.first > val){
            ++j;
        }
        if(j < rgt.size() && rgt[j].second + v[r] + v[l] + ll.first <= val){
            res2.emplace_back(make_pair(rgt[j].first + v[r] , ll.second + v[l]));
        }
    }
    vector < pair < long long , long long > > ans;
    long long mn = 1LL << 50;
    i = 0;
    j = 0;
    while(i < res1.size() || j < res2.size()){
        pair < long long  , long long > cur;
        if(i == res1.size()){
            cur = res2[j++];
        }
        else if(j == res2.size()){
            cur = res1[i++];
        }
        else{
            if(res1[i] < res2[j]){
                cur = res1[i++];
            }
            else{
                cur = res2[j++];
            }
        }
        if(cur.second < mn){
            ans.emplace_back(cur);
            mn = cur.second;
        }
    }
    return ans;
}
bool check(long long val){
    return !dfs(1 , val).empty();
}
int main(){
    scanf("%d" , &n);
    for(int i = 2 ; i <= n ; ++i){
        scanf("%d %d" , a + i , v + i);
        if(ch1[a[i]]){
            ch2[a[i]] = i;
        }
        else{
            ch1[a[i]] = i;
        }
    }
    long long l = 0;
    long long r = 1LL << 34;
    while(l < r){
        long long mid = l + r >> 1;
        if(check(mid)){
            r = mid;
        }
        else{
            l = mid + 1;
        }
    }
    printf("%lld\n" , l);
}

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

using namespace std;

int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  while (h && w) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        printf("#");
      } 
      printf("\n");
    }
    printf("\n");
    scanf("%d %d", &h, &w);
  }
  return 0;
}



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

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int combinationCount = 0;
            while (true)
            {
                var oneLine = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

                if (oneLine.All(x => x == 0))
                {
                    goto Finish;
                }

                var n = oneLine[0];
                var sum = oneLine[1];

                for (int i = 1; i <= n; i++)
                {
                    //if (3 * (i + 1) == sum)
                    //{
                    //    combinationCount++;
                    //}
                    for (int j = i + 1; j <= n; j++)
                    {
                        for (int k = j + 1; k <= n; k++)
                        {
                            if (i + j + k == sum)
                            {
                                combinationCount++;
                            }
                        }
                    }
                }
                Console.WriteLine(combinationCount);
                combinationCount = 0;
            }

            Finish:
            return;
        }
    }
}



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

int main() {

	string s;
	cin >> s;
	int x, y;
	cin >> x >> y;

	// x方向の移動とy方向の移動に分ける
	vector<int> dx, dy;
	bool direct_x = true;
	int count = 0;
	for (auto i = s.begin(); i != s.end(); i++) {
		if (*i == 'F') count++;
		else if (*i == 'T') {
			if (direct_x) dx.push_back(count);
			else dy.push_back(count);
			count = 0;
			direct_x = !direct_x;
		}
	}
	if (direct_x) dx.push_back(count);
	else dy.push_back(count);

	// 可能性のある座標を列挙していく X
	vector<vector<int>> dpx = { { *dx.begin() } };
	for (int i = 1; i < dx.size(); i++) {
		vector<int> tmp;
		vector<int> ref_vec = dpx[i - 1];
		for (auto itr = ref_vec.begin(); itr != ref_vec.end(); itr++) {
			tmp.push_back((*itr) + dx[i]);
			tmp.push_back((*itr) - dx[i]);
		}
		sort(tmp.begin(), tmp.end());
		tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
		dpx.push_back(tmp);
	}
	vector<vector<int>> dpy = { { 0 } };
	for (int i = 0; i < dy.size(); i++) {
		vector<int> tmp;
		vector<int> ref_vec = dpy[i];
		for (auto itr = ref_vec.begin(); itr != ref_vec.end(); itr++) {
			tmp.push_back((*itr) + dy[i]);
			tmp.push_back((*itr) - dy[i]);
		}
		sort(tmp.begin(), tmp.end());
		tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
		dpy.push_back(tmp);
	}
	vector<int> tmp2 = *(dpx.end() - 1);
	bool jx = binary_search(tmp2.begin(), tmp2.end(), x);
	tmp2 = *(dpy.end() - 1);
	bool jy = binary_search(tmp2.begin(), tmp2.end(), y);
	if (jx && jy) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 20608
using System;
class excel{
    public static void Main(){
        String[] str = Console.ReadLine().Split(' ');
        int m=int.Parse(str[0]);
        int n=int.Parse(str[1]);
        int[,] num = new int[m,n];
        for(int i=0; i<m; i++){
            String[] temp = Console.ReadLine().Split(' ');
            for(int j=0; j<n; j++){
                num[i,j] = int.Parse(temp[j]);
            }
        }
        int[] ans = new int[n];
        for(int i=0; i<n; i++){
            ans[i] = 0;
        }
        int sum;
        for(int i=0; i<m; i++){
            sum = 0;
            for(int j=0; j<n; j++){
                Console.Write("{0} ",num[i,j]);
                sum+=num[i,j];
                ans[j]+=num[i,j];
            }
            Console.WriteLine("{0}",sum);
        }
        sum = 0;
        for(int i=0; i<n; i++){
            Console.Write("{0} ",ans[i]);
            sum+=ans[i];
        }
        Console.WriteLine("{0}",sum);
    }
}


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

int main() {
	string A, B;
  	cin >> A >> B;
  
  	int count = 0;
  	for (int i = 0; i < (int)A.length(); ++i) {
    	if (A[i] != B[i]) ++count;
    }
  
  	printf("%d\n", count);
}

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

string a;
int main()
{
	int i;
	cin >> a;
	for (i = a.size(); i > 0;) {
		if (i >= 5 && a.substr(i - 5, 5) == "dream") i -= 5;
		else if (i >= 5 && a.substr(i - 5, 5) == "erase") i -= 5;
		else if (i >= 7 && a.substr(i - 7, 7) == "dreamer") i -= 7;
		else if (i >= 6 && a.substr(i - 6, 6) == "eraser") i -= 6;
		else {puts("NO"); return 0;}
	}
    cout << "YES";
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int n;
    cin >> n;
    vl a(MAX_N + 5);
    repeat(i, 1, n + 1) cin >> a[i];

    vl l(MAX_N + 5);
    vl r(MAX_N + 5);
    l[0] = r[n + 1] = 0;
    repeat(i, 1, n + 1) {
        l[i] = gcd(l[i - 1], a[i]);
        r[n - i + 1] = gcd(r[n - i + 2], a[n - i + 1]);
    }
    ll ans = 0;
    repeat(i, 1, n + 1) {
        ans = max(ans, gcd(l[i - 1], r[i + 1]));
    }
    out(ans);
    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin >> a;
  int bi=0,wi=0;
  int count = 0;
  for(int i=1;i<a.size();i++){
    if(a[i]=='B'){
      if(a[i-1]!='B') count++;
    }
    else{
      if(a[i-1]!='W') count++;
    }

}
cout << count  << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int i, x, n;

	scanf("%d", &n);
	i = 1;

	while(i <= n){
		x = i;
		if(x % 3 == 0){
			printf(" %d", i);
		}
		else{
			while(x != 0){
				if(x % 10 == 3){
					printf(" %d", i);
					break;
				}
				x /= 10;
			}
		}

		i++;
	}

	printf("\n");

	return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
string s1, s2,p1,p2;
int dp[3102][3102];
int LCS(int i, int j)
{
    if(i==s1.size()|| j == s2.size())
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
        long long ans1 = 0, ans2 = 0;
    if(s1[i]==s2[j])
        return dp[i][j]=1+ LCS(i+1,j+1);
 ans1 = LCS(i+1,j);
   ans2 = LCS(i,j+1);
    return dp[i][j]= max(ans1,ans2);
}
vector<int> v;
long long ind1, ind2;
void print(int i, int j)
{
    if(s1.size()==i || s2.size()==j)
    {
        cout<<p1<<endl;
           return;
    }

    if(s1[i]==s2[j])
    {

        p1.push_back(s1[i]);
         print(i+1,j+1);

    }
    else
        if(dp[i+1][j]>dp[i][j+1])
                print(i+1,j);
        else
            print(i,j+1);
}
int main()
{

        cin>>s1>>s2;
        memset(dp,-1,sizeof(dp));
        LCS(0,0);
        ind1 = 0; ind2 = 0;
        print(0,0);
        p1.clear();

    return 0;
}


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

int main() {
    ll N,M;
    cin >> N >>M;
    vector<vector<int>> A(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            int a;
            cin >> a;
            A[i].push_back(a);
        }
    }
    int l=0;
    int r =N;
    while(l+1<r){
        int mid =(l+r)/2;
        // cerr <<"mid=" << mid <<endl;
        set<int> banned;
        bool ok = true;
        while(banned.size()<M){
            ok = true;
            map<int,int> mp;
            for(int i=0;i<N;i++){
                int t=0;
                while(t < M-1 &&banned.find(A[i][t])!= banned.end()){
                    t++;
                }
                mp[A[i][t]]++;
            }
            // cerr << banned.size() << endl;
            for(auto itr = mp.begin();itr != mp.end();itr++){
                // cerr <<"num="<< itr->first<< "val="<<itr->second << endl;
                if(itr->second > mid){
                    banned.insert(itr->first);
                    ok = false;
                }
            }
            if(ok){
                break;
            }
        }
        if(ok){
            r = mid;
        }else{
            l = mid;
        }
        
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int a,b,x,ina,inb;
    std::cin >> x >> a >> b;
    ina = abs(x - a);
    inb = abs(x - b);
    if(ina < inb){
        std::cout << "A"<<std::endl;
    }else{
        std::cout <<"B"<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

// 二重連鎖木
// 左子右兄弟表現
struct Node {
  int p, l, r, d;
};

void print(vector<Node> &T, int u) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << T[u].d << ", ";

  if (T[u].p == -1)
    cout << "root, ";
  else if (T[u].l == -1)
    cout << "leaf, ";
  else
    cout << "internal node, ";

  cout << "[";
  for (int i = 0, c = T[u].l; c != -1; ++i, c = T[c].r) {
    if (i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(vector<Node> &T, int u, int p) {
  T[u].d = p;
  if (T[u].r != -1) rec(T, T[u].r, p);
  if (T[u].l != -1) rec(T, T[u].l, p + 1);
}

int main() {
  int n, l;
  cin >> n;
  vector<Node> T(n);
  REP(i, n) T[i].p = T[i].l = T[i].r = T[i].d = -1;
  REP(i, n) {
    int id, k;
    cin >> id >> k;
    REP(j, k) {
      int c;
      cin >> c;
      if (j == 0)
        T[id].l = c;
      else
        T[l].r = c;
      l = c;
      T[c].p = id;
    }
  }
  int r;
  REP(i, n) {
    if (T[i].p == -1) r = i;
  }
  rec(T, r, 0);
  REP(i, n) print(T, i);
}


Measured memory_bytes: 7476
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  double memo = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    memo += (1.0 / A.at(i));
  }
  double ans = 1.0 / memo;
  cout << fixed << setprecision(16);
  cout << ans << endl;
}
  

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b;cin>>a>>b;
  a*b%2==0 ? cout<<"Even"<<endl : cout<<"Odd"<<endl;
}


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

long long A, B, K;

int main() {
    cin >> A >> B >> K;
    
    if (K % 2 == 0) {
        for (int i = 0; i < K / 2; i++) {
            if (A % 2 == 1) A -= 1;
            B += A / 2;
            A /= 2;
            if (B % 2 == 1) B -= 1;
            A += B / 2;
            B /= 2;
        }
    } else {
        for (int i = 0; i < K / 2; i++) {
            if (A % 2 == 1) A -= 1;
            B += A / 2;
            A /= 2;
            if (B % 2 == 1) B -= 1;
            A += B / 2;
            B /= 2;
        }
        if (A % 2 == 1) A -= 1;
        B += A / 2;
        A /= 2;
    }
    
    cout << A << ' ' << B << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N; cin >> N;
  vector<vector<LL> > C(N, vector<LL>(N, 0));
  REP(i,N) REP(j,N){
	cin >> C[i][j];
  }

  LL ans = 0;
  FOR(i,0,N) FOR(j,i+1,N)
	ans += min(C[i][j], C[j][i]);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1308
#include<bits/stdc++.h>
using namespace std;
//ビット演算
int main(){
  string s,t;
  int i,j,a;
  cin>>s;
  for(i=0;i<(1<<3);i++){
    bitset<3> b(i);
    a=s.at(0)-'0';
    t=s.at(0);
    for(j=0;j<3;j++){
      if(b.test(j)){
        a+=s.at(j+1)-'0';
        t+='+';
      }
      else{
        a-=s.at(j+1)-'0';
        t+='-';
      }
      t+=s.at(j+1);
    }
    if(a==7){
      cout<<t<<"=7"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string S;
  cin>>S;
  int n = S.size();
  int sum = 0;
  for(int i=0;i<n;i++) sum += S[i] == 'o';
  sum += (15 - n);

  if(sum >= 8) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  

  return 0;
}


Measured memory_bytes: 256
/******************************************
*    AUTHOR:         julianferres         *
******************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
const int INF = 2000000000;
#define MOD 1000000007
#define MAXN 200005

vi g[MAXN];int n;
vi tsort(){  // lexicographically smallest topological sort
	vi r;priority_queue<ll> q;
	vi d(2*n,0);
	forn(i,n)forn(j,g[i].size())d[g[i][j]]++;
	forn(i,n)if(!d[i])q.push(-i);
	while(!q.empty()){
		ll x=-q.top();q.pop();r.pb(x);
		forn(i,g[x].size()){
			d[g[x][i]]--;
			if(!d[g[x][i]])q.push(-g[x][i]);
		}
	}
	return r;  // if not DAG it will have less than n elements
}


int main(){ 
    FIN;
    int m; cin >> n >> m;
    forn(i,m){
        int a,b; cin >> a >> b; a--,b--;
        g[a].pb(b);	
    }
    vi topo = tsort();
    vi dp(n, 1);
    for(auto v: topo){
        for(auto u: g[v])
            dp[u] = max(dp[u], dp[v] + 1);
    }
    ll ans = 1;
    forn(i, n) ans = max(ans, dp[i]);
    cout << ans-1 << endl;
    return 0;
}


Measured memory_bytes: 10744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        Dice d=new Dice(lines);
        String order = br.readLine();
        for(char c:order.toCharArray()){
            d.roll(c);
        }
        System.out.println(d.getNumber());
    }
}

class Dice {
    String[] s=new String[6];
    int[] d={0,1,2};
    Dice(String[] s) {
        this.s=s;
    }
    String getNumber(){
        return s[d[0]];
    }
    void roll(char n) {
        int a=0;
        int b=0;
        switch (n) {
        case 'N':
            a=0;
            b=1;
            break;
        case 'E':
            a=2;
            b=0;
            break;
        case 'S':
            a=1;
            b=0;
            break;
        case 'W':
            a=0;
            b=2;
            break;
        }
        int temp=d[a];
        d[a]=d[b];
        d[b]=5-temp;
    }
}

Measured memory_bytes: 24464
import bisect

N, M, K = map(int, input().split())

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

a = [0]
b = [0]
for i in range(N):
    a += [a[i] + A[i]]
for i in range(M):
    b += [b[i] + B[i]]

ans = 0
for i in range(N+1):
    if a[i] <= K:
        ans = max(ans, i + bisect.bisect_right(b, K - a[i])-1)

print(ans)

Measured memory_bytes: 47548
#include<stdio.h>
#define N 200000
double count=0;
void margesort(int,int);
void marge(int,int,int);
 
int S[N],Left[N/2+1],Right[N/2+1];

int main(){
  int n,i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) 
    scanf("%d",&S[i]);
  
  margesort(0,n);
  printf("%0.f\n",count); 
  
  return 0;
}

void margesort(int left,int right){
  int mid;
  if(left+1 < right){ 
    mid = (left + right)/2;
    margesort(left,mid);
    margesort(mid,right);
    marge(left,mid,right);
  }
}

void marge(int left,int mid,int right){
  int n1,n2,i,j=0,k;
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i=0;i<n1;i++) Left[i] = S[left+i];
  Left[n1]=-1;
  for(i=0;i<n2;i++) Right[i] = S[mid+i];
  Right[n2]=-1;
  
  i=0;
  for(k=left;k<right;k++){
    if(Left[i] > Right[j]){  
      S[k] = Left[i];
      i++;
    count += n2 - j;
    }
    else{
      S[k] = Right[j];
      j++;
    }
  }
}

Measured memory_bytes: 2192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll n;
    int z = 100;
    cin >> n;
    for (int i = 1; 1ll * i * i <= n; i++) if (n % i == 0) {
        z = min(z, (int)max(to_string(i).length(), to_string(n / i).length()));
    }
    cout << z;
}


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

const int INF = 1001001001;

int main(){
  int h,w;
  cin >> h >> w;
  int a,b,c;
  int ans = INF;
    {//case1 hを一辺とするチョコレートを考える場合
      int aw;
      aw = ((double)(((double)w/3)-((int)w/3))*2);
      aw += w/3;
      a = h * aw;
      {//case1-1 平行に割る
        b = h * ((w-aw)/2);
        c = h*w - a - b;
        if(b!=0 && c!=0) ans = max(a,max(b,c)) - min(a,min(b,c));
      }
      {//case1-2 垂直に割る
        b = (h/2) * (w-aw);
        c = h*w - a - b;
        if(b!=0 && c!=0) ans = min(ans,max(a,max(b,c)) - min(a,min(b,c)));
      }
    }
    {//case2 wを一辺とするチョコレートを考える場合
      int ah;
      ah = ((double)(((double)h/3)-((int)h/3))*2) + (h/3);
      a = w * ah;
      {//case2-1 平行に割る
        b = w * ((h-ah)/2);
        c = h*w - a - b;
        if(b!=0 && c!=0) ans = min(ans,max(a,max(b,c)) - min(a,min(b,c)));
      }
      {//case2-2 垂直に割る
        b = (w/2) * (h-ah);
        c = h*w - a - b;
        if(b!=0 && c!=0)ans = min(ans,max(a,max(b,c)) - min(a,min(b,c)));
      }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> A(N+1), B(N);
  REP(i, N+1) cin >> A[i];
  REP(i, N) cin >> B[i];

  ll ans = 0;
  REP(i, N+1) {
    ll m = min(A[i], B[i]);

    ans += m;
    A[i] -= m;
    B[i] -= m;

    if (B[i] == 0) continue;

    ll mm = min(A[i+1], B[i]);

    ans += mm;
    A[i+1] -= mm;
    B[i] -= mm;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N;
    cin >> N;
    cout << (N + 1) / 2 << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main() {
    ll T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    ll step = T1*A1+T2*A2 - (T1*B1+T2*B2);
    ll hop = T1 * (A1 - B1); // != 0
    if(step == 0) {
        cout << "infinity" << "\n";
        return 0;
    }
    if((step > 0) == (hop > 0)){
        cout << 0 << "\n";
        return 0;
    }
    if(step < 0) step *= -1;
    if(hop < 0) hop *= -1;
    ll ans = hop / step;
    ans = ans * 2 + 1;
    if(hop % step == 0) ans--;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
    public static void main(String args[] ) throws Exception {
        try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int x = Integer.parseInt(line);
        System.out.println(x*x*x);
        }catch(NumberFormatException e) {
            System.out.println(e);
        }
    }
}

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

const ld eps = 1e-9;
bool ze(ld a) { return fabsl(a) < eps; }
bool eq(ld a, ld b) { return ze(a - b); }
bool lt(ld a, ld b) { return b - a > eps; }
bool le(ld a, ld b) { return b - a >= -eps; }
bool gt(ld a, ld b) { return a - b > eps; }
bool ge(ld a, ld b) { return a - b >= -eps; }
ld sqr(ld x) { return x * x; }
ld Sqrt(ld x) { return sqrtl(max<ld>(0, x)); }

struct pt {
  ld x, y;
  int id;

  pt operator+(const pt& p) const { return pt{x + p.x, y + p.y, id}; }
  pt operator-(const pt& p) const { return pt{x - p.x, y - p.y, id}; }
  ld operator*(const pt& p) const { return x * p.x + y * p.y; }
  ld operator%(const pt& p) const { return x * p.y - y * p.x; }
  pt operator*(const ld& a) const { return pt{x * a, y * a, id}; }
  bool operator==(const pt& p) const { return eq(x, p.x) && eq(y, p.y); }

  bool up() const { return ze(y) ? x > 0 : y > 0; }

  pt norm() const { return *this * (1. / abs()); }
  pt rot() const { return pt{-y, x, id}; }
  pt rot_cw(pt e) const { return pt{e * *this, e % *this, id}; }
  ld abs() const { return hypotl(x, y); }
  ld abs2() const { return x * x + y * y; }
};

istream &operator>>(istream &in, pt &p) { return in >> p.x >> p.y; }
ostream &operator<<(ostream &out, const pt &p) { return out << p.x << ' ' << p.y; }

bool cmp_yx(const pt& a, const pt& b) {
  if (!eq(a.y, b.y))
    return a.y < b.y;
  if (!eq(a.x, b.x))
    return a.x < b.x;
  return false;
}
bool cmp_angle(const pt& a, const pt& b) {
  bool au = a.up(), bu = b.up();
  if (au != bu)
    return au;
  return a % b > eps;
}

struct Hull {
  vector<pt> h;
  int n;

  void build() {
    sort(h.begin(), h.end(), cmp_yx);
    h.erase(unique(h.begin(), h.end()), h.end());
    vector<pt> L, R;
    for (auto p: h) {
      while (R.size() > 1 && (p - R.back()) % (p - *next(R.rbegin())) >= -eps) {
        R.pop_back();
      }
      R.push_back(p);
      while (L.size() > 1 && (p - L.back()) % (p - *next(L.rbegin())) <= eps) {
        L.pop_back();
      }
      L.push_back(p);
    }
    if (!L.empty()) {
      L.pop_back();
    }
    reverse(L.begin(), L.end());
    if (!L.empty()) {
      L.pop_back();
    }
    h = R;
    h.insert(h.end(), L.begin(), L.end());
    n = h.size();
  }
};

signed main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif
  Hull h;
  int n;
  cin >> n;
  vector<ld> ans(n);
  for (int i = 0; i < n; ++i) {
    pt p;
    cin >> p;
    p.id = i;
    h.h.push_back(p);
  }
  h.build();
  for (int i = 0; i < h.n; ++i) {
    int id = h.h[i].id;
    pt A = h.h[i] - h.h[(i+h.n-1)%h.n];
    pt B = h.h[(i+1)%h.n] - h.h[i];
    ld ang = atan2l(A % B, A * B);
    if (ang < 0) {
      ang += 2 * acosl(-1);
    }
    ans[id] = ang / (2 * acosl(-1));
  }
  cout << fixed;
  cout.precision(10);
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << '\n';
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	priority_queue<pair<ll, ll>> q;

	ll tmpa, tmpb;
	rep(i, N) {
		cin >> tmpa >> tmpb;
		q.push(make_pair(-tmpb, -tmpa));
	}

	ll time = 0;
	rep(i, N) {
		pair<ll, ll> job = q.top();
		time = time - job.second;
		//cout << job.first << ' ' << job.second << endl;
		if(time > (-job.first)){
			cout << "No" << endl;
			return 0;
		}

		q.pop();
	}

	cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 6512
n, a, b, c = gets.chomp.split.map(&:to_i)
s = []
n.times do
  s.push(gets.chomp)
end

ans = []

n.times do |i|
  if a < 0 || b < 0 || c < 0
    puts 'No'
    exit
  end

  ss = s[i]
  if ss == 'AB'
    if a > b
      a -= 1
      b += 1
      ans.push 'B'
    elsif a < b
      a += 1
      b -= 1
      ans.push 'A'
    else
      if i == n-1
        a += 1
        b -= 1
        ans.push 'A'
      else
        sss = s[i+1]
        if sss == 'BC'
          a -= 1
          b += 1
          ans.push 'B'
        else
          a += 1
          b -= 1
          ans.push 'A'
        end
      end
    end
  elsif ss == 'BC'
    if b > c
      b -= 1
      c += 1
      ans.push 'C'
    elsif b < c
      b += 1
      c -= 1
      ans.push 'B'
    else
      if i == n-1
        b -= 1
        c += 1
        ans.push 'B'
      else
        sss = s[i+1]
        if sss == 'AC'
          b -= 1
          c += 1
          ans.push 'C'
        else
          b += 1
          c -= 1
          ans.push 'B'
        end
      end
    end
  else
    if c > a
      c -= 1
      a += 1
      ans.push 'A'
    elsif c < a
      c += 1
      a -= 1
      ans.push 'C'
    else
      if i == n-1
        c -= 1
        a += 1
        ans.push 'C'
      else
        sss = s[i+1]
        if sss == 'AB'
          c -= 1
          a += 1
          ans.push 'A'
        else
          c += 1
          a -= 1
          ans.push 'C'
        end
      end
    end
  end
end

if a < 0 || b < 0 || c < 0
  puts 'No'
  exit
end

puts 'Yes'
ans.each do |an|
  puts an
end



Measured memory_bytes: 29088
N=gets.to_i
as=gets.split.map(&:to_i)
hs=Array.new(N,0)
for i in 0..N-2
    hs[i]=1 if as[i]>=as[i+1]
end
ans=0
cnt=0
hs.each do |i|
    if i==0
        ans=ans < cnt ? cnt : ans
        cnt=0
    else
        cnt+=1
    end
end
puts ans


Measured memory_bytes: 9348
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int main(){
    int h, w;

    while(true){
        cin >> h >> w;
        if(h == 0 && w == 0) {
            break;
        }

        for(int y=1;y<=h;y++){
            if(y % 2 == 0){
                for(int x=1;x<=w;x++){
                    if(x%2 == 0) cout << "#";
                    else cout << ".";
                }
            }
            else {
                for(int x=1;x<=w;x++){
                    if(x%2 == 0) cout << ".";
                    else cout << "#";
                }
            }
            
            cout << endl;
        }
        cout << endl;
    }
}


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

using namespace std;

int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> x(m), y(m - 1);
    for(int i = 0; i < m; i++){
        cin >> x[i];
    }
    sort(begin(x), end(x));
    for(int i = 1; i < m; i++){
        y[i - 1] = x[i] - x[i - 1];
    }
    sort(rbegin(y), rend(y));
    for(int i = n - 1; i < m - 1; i++){
        ans += y[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = (sc.next());
        String mul = s.substring(s.length() - 1).equals("s") ? "es" : "s";

        System.out.println(s + mul);
    }
}

Measured memory_bytes: 39120
N,M=[int(i)for i in input().split()]
H = [int(i) for i in input().split()]
flag=[True]*N
for _ in range(M):
  A,B=[int(i)for i in input().split()] 
  if H[A-1] <= H[B-1]:
    flag[A-1]=False
  if H[A-1] >= H[B-1]:
    flag[B-1]=False
    
print(flag.count(True))

Measured memory_bytes: 20112
use std::cmp::max;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    loop {
        let h: usize = read();
        let w: usize = read();
        if h == 0 && w == 0 {
            break;
        }
        for i in 0..h {
            for j in 0..w {
                print!("{}", if (i+j) % 2 == 0 {"#"} else {"."});
            }
            println!("");
        }
        println!("");
    }
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int C;
    int S;
    int F;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N-2]に格納する
    data* A;
    NEW(A,N-1);
    for(int i=0;i<N-1;i++){
        scanf("%d%d%d",&A[i].C,&A[i].S,&A[i].F);
    }

    int ans[N];
    for(int i=0;i<N;i++){
        ans[i]=0;
        for(int j=i;j<N-1;j++){
            if(ans[i]<=A[j].S) ans[i]=A[j].S+A[j].C; //始発が出てないなら始発で移動
            else{
                if(ans[i]%A[j].F==0) ans[i]+=A[j].C;
                else ans[i]+=A[j].C+(A[j].F-ans[i]%A[j].F);
            }
        }
    }
    

    for(int i=0;i<N;i++){
        printf("%d\n",ans[i]);
    }

    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;
 


int main()
{
    SYNC
    //clock_t tStart = clock();
    
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string s; in(s);
    ll count=0;
    ll ans=0;
    l(i,0,3)
    {
        if(s[i]=='R')
            count++;
        else
            count=0;
        ans=max(ans,count);
    }
    o(ans)<<endl;







    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>

int const MAXN=2999;
int N;
double tmp[2][MAXN+1];

int main() {
  std::cin >> N;
  tmp[0][0] = 1.0;
  for(int n = 0; n < N; ++n) {
    double p;
    std::cin >> p;
    for(int i = 0; i < n+1; ++i) {
      tmp[(n+1)%2][i] = (1.0-p)*tmp[n%2][i];
    }
    tmp[(n+1)%2][n+1] = 0.0;
    for(int i = 0; i < n+1; ++i) {
      tmp[(n+1)%2][i+1] += p*tmp[n%2][i];
    }
  }
  double p = 0.0;
  for(int i = (N/2)+1; i <= N; ++i) p += tmp[N%2][i];
  printf("%.10f\n", p);
  return 0;
}


Measured memory_bytes: 256
s = input()
n = int(s)

m = str(int(s[0]) - 1) + (len(s) - 1) * "9" 
ans1 = 0
for i in range(len(m)):
    ans1 += int(m[i])

if s[-1] != "9" and n >= 10:
    n1 = n - (int(s[-1]) + 1)
    s = str(n1)

ans2 = 0
for i in range(len(s)):
    ans2 += int(s[i])

print(max(ans1, ans2))


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<queue>
#include<ctime>
#include<vector>
using namespace std;
inline int rd(){
  register char ch=getchar();
  register bool flag=false;
  register int res=0;
  while(ch<'0'||ch>'9'){flag=(ch=='-');ch=getchar();}
  while(ch>='0'&&ch<='9'){
    res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
  if(flag)res=-res;
  return res;
}
#define int long long
#define N 200010
#define INF 1000000000000000LL
int n,q;
int a,b;
/*
两人移动
*/
int x[N];int px[N];
//f[i][j]:处理到i，另一个人在j
/*
转移f[i][x[i-1]]=min(f[i][x[i-1]],f[i-1][j]+abs(x[i]-j))
f[i][j]=min(f[i][j],f[i-1][j]+abs(x[i]-x[i-1]))
*/
int tsum;
int mnl[N<<2],mnr[N<<2];
inline void build(int o,int l,int r){
  if(l==r){mnl[o]=mnr[o]=INF;return;}
  int mid=(l+r)>>1;
  build(o<<1,l,mid);
  build(o<<1|1,mid+1,r);
  mnl[o]=mnr[o]=INF;
}
inline void modify(int o,int l,int r,int x,int v){
  if(l==r){
    mnl[o]=v-x;
    mnr[o]=v+x;
    return;
  }
  int mid=(l+r)>>1;
  if(x<=mid)modify(o<<1,l,mid,x,v);
  else modify(o<<1|1,mid+1,r,x,v);
  mnl[o]=min(mnl[o<<1],mnl[o<<1|1]);
  mnr[o]=min(mnr[o<<1],mnr[o<<1|1]);
}
inline int GetAll(int o,int l,int r){
  if(l==r)return mnl[o]+l;
  int mid=(l+r)>>1;
  return min(GetAll(o<<1,l,mid),GetAll(o<<1|1,mid+1,r));
}
inline int askl(int o,int l,int r,int x){
  if(r==x)return mnl[o];
  int mid=(l+r)>>1;
  if(x<=mid)return askl(o<<1,l,mid,x);
  return min(mnl[o<<1],askl(o<<1|1,mid+1,r,x));
}
inline int askr(int o,int l,int r,int x){
  if(l==x)return mnr[o];
  int mid=(l+r)>>1;
  if(x>mid)return askr(o<<1|1,mid+1,r,x);
  return min(mnr[o<<1|1],askr(o<<1,l,mid,x));
}
void work(){
  n=rd();q=rd();a=rd();b=rd();
  x[1]=a;x[2]=b;
  int i,j;
  for(i=3;i<=q+2;i++)
    {x[i]=rd();if(x[i]==x[i-1]){i--;q--;}}
  //q=q+2;
  for(i=1;i<=q+2;i++)
    px[i]=px[i-1]+x[i];
  build(1,1,n);
  modify(1,1,n,x[1],0); //   fprintf(stderr,"begin\n");
  for(i=3;i<=q+2;i++){//fprintf(stderr,"ask %lld %lld\n",i,x[i]);
    //int qq=askl(1,1,n,x[i-1])+x[i-1];
    int myy=min(x[i]+askl(1,1,n,x[i]),askr(1,1,n,x[i])-x[i])+tsum;
    //注意不能动当前那个点！！！（x[i-1]至少要保证有一个人）
    //fprintf(stderr,"%lld ,%lld\n",tsum+x[i]+askl(1,1,n,x[i]),askr(1,1,n,x[i])-x[i]+tsum);
     tsum+=abs(x[i]-x[i-1]);
     //fprintf(stderr,"f[%lld][%lld]=%lld\n",x[i],x[i-1],myy);
    modify(1,1,n,x[i-1],myy-tsum);
  }
  printf("%lld\n",GetAll(1,1,n)+tsum);
}
#undef int 
int main(){
  work();
  return 0;
}


Measured memory_bytes: 15872
#include<stdio.h>
int solve(int, int, int);
int A[2001];
int n;
  
int main(){
  int j, q, i;
  int M[2001];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&M[i]);
  }
    
  for(i=0; i<q; i++){
    if(solve(0, 0, M[i])) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}
  
  
  
int solve(int p, int t, int k){
  if(t == k) return 1;
  if(p >= n) return 0;
  if(solve(p+1, t, k)) return 1;
  if(solve(p+1, t+A[p], k)) return 1;
  return 0;
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int N,k;
int mem[100005];
int h[100005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N>>k;
    int i;
    for(i=1;i<=N;i++) cin>>h[i];
    for(i=2;i<=N;i++){
        mem[i]=INT_MAX;
        for(int j=i-1;j>=max(i-k,1);j--){
            mem[i]=min(mem[i],mem[j]+abs(h[i]-h[j]));
        }
    }
    cout<<mem[N]<<endl;
    return 0;
}


Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int k;
  string n;
  char a[10];
  bool b=true;
  int num;
  cin>>n>>k;
  rep(i,k){
    cin>>a[i];
  }
  while(b){
    b=false;
    rep(i,n.size() ){
      rep(j,k){
	if(n[i]==a[j]){b=true;break;}
	}
      if(b) break;
    }
    if(b){
      num=atoi(n.c_str());
      num++;
      n=to_string(num);
    }
  }
  cout<<atoi(n.c_str() )<<endl; 
  return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)


class UnionFind(object):

    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        else:
            return False

N, M = map(int, input().split())
p = list(map(int, input().split()))
u = UnionFind(N+1)
for _ in range(M):
    x, y = map(int, input().split())
    u.union(x, y)

ans = 0
for i in range(N):
    if u.find(p[i]) == u.find(i+1):
        ans += 1
print(ans)


Measured memory_bytes: 13812
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    ll ans = 0;

    if(n % 2 == 1){
        cout << ans << endl;
        return 0;
    }

    ll five = 5;

    while(five <= n){
        ll tmp = n / five;
        tmp /= 2;
        ans += tmp;
        five *= 5;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>
#include <unistd.h>

using namespace std;

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

long long int INF = 1e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define line cout << "----------" << endl;


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[300005],y[300005],z[100005];
char s[500005];
bool ok;

void check(){
    bool dame = false;
    for(ll i=0;i<n-1;i++){
        if(x[i] > x[i+1])dame = true;
    }
    if(!dame){
        ok = true;
    }
    return;
}


int main(){
	cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i];
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            swap(x[i],x[j]);
            check();
            swap(x[i],x[j]);

        }
    }
    YES(ok);
	return 0;
}



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

int main() {
    char c1[3], c2[3];
    int i;

    for (i = 0; i < 3; ++i) {
        cin >> c1[i];
    }

    for (i = 0; i < 3; ++i) {
        cin >> c2[i];
    }

    for (i = 0; i < 3; ++i) {
        if (c1[i] != c2[2-i]) break;
    }

    if (i == 3) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int T = sc.nextInt();

    int now = 0;
    int bis = 0;
    while (true) {
    	if (now > T+0.5) {
    		bis -= B;
        	now -= A;
    		break;
    	}
    	bis += B;
    	now += A;
    }
    System.out.println(bis);
  }
}

Measured memory_bytes: 21204
def Con(X) :
	# concentration 濃度
	if(r + X * R - C * w  >= 0) :
		return 0
	else :
		return 1

	
while True :
	r, w, C, R = map(int, input().split())
	if(C == 0) :
		break
	else :
		for i in range(10000) :
			if(Con(i) == 0) :
				print(i)
				break
			else :
				pass


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

int main(){
    string s;
    cin >> s;
    long long n=s.size();
    for(long long i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for(long long i=0;i<n-2;i++){
        if(s[i]==s[i+2]&&s[i]!=s[i+1]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 3752