akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define EACH(i,c) for (auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */



signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << H*W - (H*w+W*h-h*w) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b; cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
const int INF = 1e8;
ll D, G;
ll dp[12][1201];//i番目の問題まで見て、合計j個の問題をすでに解いている際における総合スコアの最大値
int main() {
	cin >> D >> G;
	vector<ll>P(D + 1), C(D + 1);
	for (int i = 1; i <= D; ++i) {
		cin >> P[i] >> C[i];
	}
	for (int i = 1; i <= D; ++i) {
		for (int j = 0; j <= 1010; ++j) {
			for (int k = 0; k <= P[i]; ++k) {
				if (k == P[i]) {
					dp[i][j + k] = max(dp[i][j + k], dp[i-1][j] + 100 * i*k + C[i]);
				}
				else {
					dp[i][j + k] = max(dp[i][j + k], dp[i-1][j] + 100 * i*k);
				}
			}
		}
	}
	for(int j = 0; j < 1010; ++j) {
		if (dp[D][j] >= G) {
			cout << j << endl;
			break;
		}
	}
	return 0;
}

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

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n;
    int m=0;
    int cost[50][50];
    while(cin>>n){
        if(n==0)break;
        m=0;
        rep(i,50)rep(j,50)cost[i][j]=99999999;
        rep(i,50)cost[i][i]=0;
        rep(i,n){
            int a,b,c;
            cin>>a>>b>>c;
            m=max(m,max(a,b));
            cost[a][b]=cost[b][a]=c;
        }
        m++;
        rep(k,m){
            rep(i,m){
                rep(j,m){
                    cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
                }
            }
        }
        int sum=99999999;
        int t=-1;
        rep(i,m){
            int tmp=0;
            rep(j,m){
                tmp+=cost[i][j];
            }
            if(tmp<sum){
                t=i;
                sum=tmp;
            }
        }
        cout<<t<<" "<<sum<<endl;
    }
}

Measured memory_bytes: 1172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String result = "NO";
		
		int[] input = new int[3];
		for (int i=0; i<3; i++) {
			input[i] = sc.nextInt();
		}
		
		int count5 = 0;
		int count7 = 0;
		
		for (int j=0; j<3; j++) {
			if (input[j] == 5) {
				count5++;
			} else if (input[j] == 7) {
				count7++;
			} else {
				break;
			}
		}
		
		if (count5 == 2 && count7 == 1) {
			result = "YES";
		}
		
		System.out.println(result);
	}

}


Measured memory_bytes: 21716
N = int(input())
dic = {}
for i in range(N):
    S,P = map(str,input().split())
    if S not in dic:
        dic[S] = [(-1*int(P), i+1)]
    else:
        dic[S].append((-1*int(P), i+1))
ls = list(dic.items())
ls.sort()
for city in ls:
    points = sorted(city[1])
    for point in points:
        print(point[1])

Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

long long N;

long long pow(long long n, long long k) {
  long long res = 1;
  while (k--) { res *= n; }
  return res;
}

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

  int len = 0;
  long long k = 0;
  while (k < N) {
    len++;
    k += pow(26, len);
  }

  // printf("len = %d\n", len);

  k -= pow(26, len);
  string ans = "";
  while (len > 0) {
    long long base = 0;
    for (int i = 1; i < len; i++) { base += pow(26, i-1); }

    for (char c = 'a'; c <= ('z'+1); c++) {
      if (base + ((c - 'a') + 1) * pow(26, len-1) > N) {
        // printf("%c\n", c);
        c--;
        ans += c;
        N -= ((c - 'a') + 1) * pow(26, len-1);
        len--;
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3680
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
/*union-find*/
const int MAX_V =100010;
int parent[MAX_V];//parent[x]=xの時xが根である
int rank[MAX_V];
struct edge
{
	int u,v,cost;
	edge(int _u,int _v,int _cost){
		u =_u;
		v =_v;
		cost =_cost;
	}
};
void init(int V){
	for(int i= 0;i < V;i++){
		parent[i] = i;
		rank[i] =0;
	}
}

int find(int x){
	if(parent[x] == x)
		return x;
	else{
		return find(parent[x]);
	}
}

void unit(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y)
		return;
	if(rank[x] < rank[y]){
		parent[x] = y;
	}
	else{
		parent[y] = x;
		if(rank[x] == rank[y])
			rank[x]++;
	}
}

bool same(int x,int y){
	return find(x) == find(y);
}
//コストが低い順にsortする
bool cmp(const edge left,const edge right){
	return left.cost <right.cost;
}
vector<edge> es;

int V,E;
int kruskal(){
	init(V);
	sort(es.begin(),es.end(),cmp);
	int res = 0;
	for(int i =0;i <E;i++){
		edge e =es[i];
		if(!same(e.u,e.v)){
			unit(e.u,e.v);
			res +=e.cost;
		}
	}
	return res;
}


int main(){
	cin>>V>>E;
	for(int i =0;i < E;i++){
		int u,v,cost;
		cin>>u>>v>>cost;
		es.push_back(edge(u,v,cost));
	}
	
	cout <<kruskal()<<endl;
	return 0;
}

Measured memory_bytes: 2708
import sys
from collections import deque


def bfs(x1, y1, d):
    q = deque([])
    q.append((d, x1, y1))
    M[x1][y1] = d

    while q:
        d, x1, y1 = q.popleft()
        M[x1][y1] = d

        if [x1, y1] == [xg, yg]:
            print(d)
            return

        for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
            for k in range(1, K + 1):
                x2 = x1 + dx * k
                y2 = y1 + dy * k
                if x2 < 0 or x2 >= H:  # 枠外
                    break
                if y2 < 0 or y2 >= W:  # 枠外
                    break
                if m[x2][y2] == '@':  # 蓮の葉
                    break
                if M[x2][y2] < d + 1:  # より良い経路を探索済み。
                    break
                if M[x2][y2] == d + 1:  # 同等の良さの経路を探索済み。　飛び越えて次のマスを探索する。
                    continue

                q.append((d + 1, x2, y2))
                M[x2][y2] = d + 1

    print(-1)


H, W, K = map(int, sys.stdin.readline().strip().split())
xs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())
xg -= 1
yg -= 1

m = []
for _ in range(H):
    m.append(list(map(str, sys.stdin.readline().strip())))

M = [[float('inf')] * W for _ in range(H)]

bfs(xs - 1, ys - 1, 0)


Measured memory_bytes: 45216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
	string s, t;
	cin >> s >> t;
	int dp[3010][3010];
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < s.size(); ++i) {
		for (int j = 0; j < t.size(); ++j) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}
    //復元
	string res = "";
	int i = s.size(), j = t.size();
	while (i > 0 && j > 0) {
		//(i-1,j)->(i,j)と更新されていた場合
		if (dp[i][j] == dp[i - 1][j]) {
			--i;//DPの遷移を遡る
		}
		else if (dp[i][j] == dp[i][j - 1]) {
			--j;
		}
		//(i-1,j-1)->(i,j)と更新されていた場合
		else {
			res = s[i - 1] + res;//このときs[i-1]==t[j-1]なので、res+t[j-1]でもok
			--i, --j;
		}
	}
	cout << res << endl;
	return 0;
}

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

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	ret_ng='NO'
	ret_ok='YES'
	
	n=int(io())
	l= list(map(int, io().split()))
	
	v_one_act =n*(n+1)/2
	
	if sum(l)%v_one_act != 0:
		return ret_ng
		
	act_num=sum(l)//v_one_act	
	st_num=0
	
	for a,b in zip(l, l[1:]+l):
		diff = b - a
		if (act_num-diff)%(n)!=0:
			return ret_ng
		if (act_num-diff)<0:
			return ret_ng
		st= (act_num-diff)//(n)
		st_num+=st
	
	if act_num!=st_num:
		return ret_ng
		
	
		
	return ret_ok

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))


Measured memory_bytes: 14476
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

int main(void) {
    int n;
    cin >> n;
    int a[n];
    set<int> st;
    map<int, int> mp;
    rep (i, n) {
        cin >> a[i];
        st.insert(a[i]);
        mp[a[i]]++;
    }


    int cnt = 0;
    for (auto x : mp) {
        if (x.second >= 2) cnt += x.second - 1;
    }

    if (cnt % 2 == 1) cout << st.size() - 1 << endl;
    else cout << st.size() << endl;
    return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define MIN(x) *min_element(all(x))
#define MAX(x) *max_element(all(x))
#define in(x) cin >> x
#define co(x) cout << x
#define el  cout << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#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; }


int main() {
  int n, count=0, num;
  in(n);
  REP(i, n) {
  	in(num);
  	if (num!=i+1)
  	{
  		count++;
  	}
  }
  if (count == 2 || count == 0)
  {
  	co("YES");
  }else{
  	co("NO");
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main(void) {
  int n, y;
  scanf("%d%d", &n, &y);
  REP(i, n+1) REP(j, n-i+1) {
    int k = n - i - j;
    if(i*10000 + j*5000 + k*1000 == y) {
      printf("%d %d %d\n", i, j, k);
      return 0;
    }
  }
  puts("-1 -1 -1");
  return 0;
}


Measured memory_bytes: 128
def examA():
    S = SI()
    if S[2]==S[3] and S[4]==S[5]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    X = I()
    ans = 0
    ans += (X//500) * 1000
    X %= 500
    ans += (X//5) * 5
    print(ans)
    return

def examC():
    K, N = LI()
    A = LI()
    L = [0]*N
    L[0] = K-A[-1] + A[0]
    for i in range(1,N):
        L[i] = A[i]-A[i-1]
    ans = sum(L) - max(L)
    #print(L)
    print(ans)
    return

def examD():
    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = nowW + 1
                    que.append(ne)
        return W
    N, X, Y = LI()
    V = [[]for _ in range(N)]
    for i in range(N-1):
        V[i].append(i+1)
        V[i+1].append(i)
    V[X-1].append(Y-1)
    V[Y-1].append(X-1)
    #print(V)
    ans = [0]*(N-1)
    for i in range(N):
        L = bfs(N,i,V)
        for l in L:
            if l==0:
                continue
            ans[l-1] += 1
    for v in ans:
        print(v//2)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examD()

"""

"""

Measured memory_bytes: 49628
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,j,ans;
  string s[10005];
  
  cin >> n;
  for (i=0;i<n;i++) cin >> s[i];
  
  ans=0;
  for (i=0;i<n;i++) for (j=0;j<s[i].size()-1;j++){
    if (s[i][j]=='A' && s[i][j+1]=='B') ans++;
  }
  
  int r,z,u;
  r=z=u=0;
  for (i=0;i<n;i++){
    if (s[i][0]=='B' && s[i][s[i].size()-1]=='A'){
      r++;
    }else if (s[i][0]=='B'){
      z++;
    }else if (s[i][s[i].size()-1]=='A'){
      u++;
    }
  }
  
  if (r>0){
    ans+=r-1;
    
    if (z>0){
      ans++;
      z--;
    }
    if (u>0){
      ans++;
      u--;
    }
  }
  
  ans+=min(z,u);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 768
#include<iostream>

int W = 0 , H = 0 , x = 0 , y = 0 , r = 0 ;

int main()
{
	std::cin >> W >> H >> x >> y >> r ;
	if(( x - r >= 0 ) && ( x + r <= W ) && ( y - r >= 0 ) && ( y + r <= H ))
	{
		std::cout<< "Yes" << std::endl ;
	}
	else
	{
		std::cout << "No" << std::endl ;
        }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll X, Y;
    cin >> X >> Y;
    if (abs(X - Y) >= 2) cout << "Alice"; else cout << "Brown";
    return 0;
}

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

ll answer=0;

ll dfs(ll pa,ll u,vector<ll> V[],ll x,ll A[]){
	ll ans=0;
	answer = max(answer,x);
	if(A[u]==0)
		A[u]=x;
	ll i,j;

	for(ll i=0;i<V[u].size();++i){
		if(V[u][i]!=pa){
			if(A[V[u][i]]==0){
				ans = min(dfs(u,V[u][i],V,x+1,A),ans);
			}else{
				if((A[V[u][i]]-A[u])%2==0){
					ans=-1;
				}
			}
		}
	}
	return ans;
}


ll bfs(ll x,vector<ll> V[]){
	queue<ll> Q;
	ll A[1010]={0};
	A[x]=1;
	Q.push(x);
	ll ans=0;
	while(Q.size()){
		vector<ll> temp;
		while(Q.size()){
			ll u= Q.front();
			//cout<<" "<<u;
			Q.pop();
			for(ll i=0;i<V[u].size();++i){
				if(A[V[u][i]]==0){
					A[V[u][i]]=1;
					temp.push_back(V[u][i]);
					
				}
			}
		}
		//cout<<"\n";
		for(auto it:temp)Q.push(it);
		ans++;
	}
	return ans;
}

int main(){

	ll i,j,k,l,n,m,t,a,b,c;

	cin>>n;
	vector<ll> V[n+1];
	for(i=0;i<n;++i){
		string s;
		cin>>s;
		for(j=0;j<s.size();++j){
			if(s[j]=='1'){
				V[i].push_back(j);
			}
		}
	}

	
	ll dis[n+1]={0};
	if(dfs(-1,0,V,1,dis)==-1){
		cout<<-1;
	}else{
		ll an=0;
		for(i=0;i<n;++i)an = max(an,bfs(i,V));
		cout<<an;
	}

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int A[110];
    for (int i = 0;i < N;i++){
        cin >> A[i];
    }
    bool yes = true;
    for (int i = 0;i < N;i++){
        if (A[i] % 2 == 0){
            if(A[i] % 3 == 0 || A[i] % 5 == 0){
                continue;
            }
            else
            yes = false;
        }
    }
    if(yes)
    cout << "APPROVED" << endl;
    else
    cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const int MAXN=1000005,MAXM=30000000;
int P;
#define L 1048576
#define real long double
#define eps 1e-9
char _buf[L],*S,*T,_buf1[L],*S1=_buf1;
inline char gc()
{
	if(S==T)
	{
		T=(S=_buf)+fread(_buf,1,L,stdin);
		if(S==T)return 0;
	}
	return *S++;
}
template<class T> void get(T &x)
{
	char c;
	for(c=gc();(c<'0'||c>'9')&&c!='-';c=gc());
	bool b=0;
	if(c=='-')
	{
		b=1;
		c=gc();
	}
	for(x=c^'0',c=gc();c>='0'&&c<='9';c=gc())x=(x<<3)+(x<<1)+(c^'0');
	if(b)x=-x;
}
inline void pc(char c)
{
	if(S1==_buf1+L)
	{
		fwrite(_buf1,1,L,stdout);
		S1=_buf1;
	}
	*S1++=c;
}
void out(ll x)
{
	if(x>9)out(x/10);
	pc(x%10^'0');
}
int Pow(int x,int y)
{
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%P)if(y&1)s=(ll)s*x%P;
	return s;
}
int A(int x)
{
	return x<0?-x:x;
}
int l,r,d,ans;
int main()
{
	cin>>l>>r>>d;
	for(;l<=r;l++)if(l%d==0)ans++;
	cout<<ans<<endl;
	fwrite(_buf1,1,S1-_buf1,stdout);
	return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
int main(){
	int high[10];
	int i,j;
	int max = 0;
	
	for(i = 0;i < 10;i++){
		scanf("%d",&high[i]);
	}
	
	for(i = 0;i < 3;i++){
		for(j = 0;j < 10;j++){
			if(high[max] < high[j]){
				max = j;
			}
		}
		printf("%d\n",high[max]);
		high[max] = 0;
		max = 0;
	}
	return 0;
}
	

Measured memory_bytes: 1028
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

static const int MOD = 1e9 + 7;

int main() {

    long long N;
    cin >> N;
    long long ans = N - 1;

    for (long long i = 2; i*i <= N; i++) {
        if (N%i == 0)ans = min(ans, N / i + i - 2);
    }

    cout << ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();
		int ans = P + Q;
		if(P + R < ans) {
			ans = P + R;
		}
		if(R + Q < ans) {
			ans = R + Q;
		}
		System.out.println(ans);
		sc.close();
	}

}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N; cin>>N;
  vector<int> A(N);
  for(auto& a: A) {
    cin>>a;
  }

  int cnt = 0;
  for(int i=0; i<N; i++) {
    while(A[i] > 0) {
      int r = i;
      for(; r < N; r++) {
        if(A[r] <= 0) break;
      }

      for(int start = i; start < r; start++) {
        A[start]--;
      }
      cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define NIL -1

struct node{
    int parent;
    int left;
    int right;
};

struct node t[100000];
int n,d[100000],h[100000];

int sethei(int u)
{
int h1=0,h2=0;
if(t[u].right!=NIL){
    h1=sethei(t[u].right)+1;
}
if(t[u].left!=NIL){
    h2=sethei(t[u].left)+1;
}
return h[u]=(h1>h2 ? h1:h2);
}

void setdep(int u,int p)
{
    if(u==NIL) return;
    d[u]=p;
    setdep(t[u].right,p+1);
    setdep(t[u].left,p+1);
}

int setsib(int u)
{
if(t[u].parent==NIL){
    return NIL;
}    
if(t[t[u].parent].left !=u && t[t[u].parent].left !=NIL){
    return t[t[u].parent].left;
}
if(t[t[u].parent].right !=u && t[t[u].parent].right !=NIL){
    return t[t[u].parent].right;
}
return NIL;
}

void print(int u)
{
int i,c,deg=0;

printf("node %d: parent = %d, sibling = %d, ",u,t[u].parent,setsib(u));
if(t[u].left!=NIL) deg++;
if(t[u].right!=NIL) deg++;
printf("degree = %d, depth = %d, height = %d, ",deg,d[u],h[u]);

if(t[u].parent ==NIL) printf("root\n");
else if(t[u].left == NIL && t[u].right == NIL) printf("leaf\n");
else printf("internal node\n");

}

int main(){
int n,id,l,r,i,root=0;

scanf("%d",&n);
for(i=0;i<n;i++){
    t[i].parent=NIL;
}
for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d %d",&l,&r);
    t[id].left=l;
    t[id].right=r;
    if(l!=NIL) t[l].parent=id;
    if(r!=NIL) t[r].parent=id;
}
for(i=0;i<n;i++){
if(t[i].parent==NIL) root=i;
}

setdep(root,0);
sethei(root);

for(i=0;i<n;i++){
    print(i);
}
return 0;
 }


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

int main(){
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;  
  string t;
  cin >> t;
  vector<int> result(n);
  int ans = 0;
  rep(i,k){
    result[i] = 1;
    if(t[i] == 'r') ans += p;
    else if(t[i] == 's') ans += r;
    else ans += s;
  }
  for(int i = k; i < n; i++){
    if(t[i-k] != t[i] || !result[i-k]){
      if(t[i] == 'r') ans += p;
      else if(t[i] == 's') ans += r;
      else ans += s;
      result[i] = 1;
    }
  }
  cout << ans << endl;
}
  

  

Measured memory_bytes: 896
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let ab: Vec<f64> = read_vec();
  let xs = vec![ab[0] + ab[1], ab[0] - ab[1], ab[0] * ab[1]];
  let ans = xs.iter().cloned().fold(0.0/0.0, f64::max);

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


Measured memory_bytes: 4352
n = gets.to_i
h = gets.split.map(&:to_i)
max = 0
cnt = 0
n.pred.times do |i|
  if h[i + 1] > h[i]
    max = cnt if max < cnt
    cnt = 0
  else
    cnt += 1
  end
end
max = cnt if max < cnt
puts max

Measured memory_bytes: 8580
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    string s;
    cin>>s;
    int f = 0;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3] )
        f=1;
    cout<<( f ? "Bad\n": "Good\n");
    return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	llint i,n,ans=0,gen=1;cin>>n;
	vector<llint>a(n+1);
	vector<llint>b(n+1);
	for(i=0;i<=n;i++){cin>>a[i];}
	//下から累積和
	for(i=n-1;i>=0;i--){b[i]=b[i+1]+a[i+1];}
	for(i=0;i<=n;i++){
		ans+=gen;//最大数
		gen-=a[i];
		gen*=2;
		chmin(gen,b[i]);
		if(gen<0){cout<<-1<<endl;return 0;}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4468
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;
void solve(){
    string s; cin>>s;
    int cnt=0;
    for(int i = 0; i < s.size(); i++) if(s[i]=='1') cnt++;
    cout<<min(cnt,(int)s.size()-cnt)*2;
}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL inf=1LL<<60;
LL n,a[100010],f[100010][3];
char op[100010][2];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++) scanf("%d %s",&a[i],op[i]);
    scanf("%d",&a[n]);
    f[1][0]=a[1];f[1][1]=f[1][2]=-inf;
    for(int i=2;i<=n;i++)
        if(op[i-1][0]=='+')
        {
            f[i][0]=max(f[i-1][0],f[i-1][1])+a[i];
            f[i][1]=f[i-1][1]-a[i];
            f[i][2]=f[i-1][2]+a[i];
        }
        else
        {
            f[i][0]=-inf;
            f[i][1]=max(f[i-1][0],f[i-1][1])-a[i];
            f[i][2]=max(f[i-1][1],f[i-1][2])+a[i];
        }
    printf("%lld",max(f[n][0],max(f[n][1],f[n][2])));
    return 0;
}

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


int main(){
	string s,t;
	cin >> s >> t;
	int f=0;
	for(int i=0;i<s.size();i++){
		if(s.at(i)!=t.at(i)){
			f=1;
		}
	}
	if(f==0){
	cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

// -------------------
// ここから先は変更しない
// -------------------
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  int sum = 0;
  for(int i =  0; i < N; i++){
    if(X.at(i)<K-X.at(i)){
      sum+=X.at(i);
    }else{
      sum+=K-X.at(i);
    }
  }
  cout << sum*2 << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FS r = new FS();
		int N = r.nextInt();
		int x = r.nextInt();
		int[] a = new int[N];
		long eat = 0;
		for(int i=0; i<N; i++) {
			a[i] = r.nextInt();
			if(i==0) {
				if(x < a[i]) {
					eat += a[i] - x;
					a[i] = x;
				}
				continue;
			}
			if(x < a[i-1]+a[i]) {
				eat += a[i] + a[i-1] - x;
				a[i] = x - a[i-1];
			}
		}
		System.out.println(eat);
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


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

struct UnionFind {
	vector<int>par;
	UnionFind(int n) :par(n) {
		for (int i = 0; i < n; i++)par[i] = i;
	}
	int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); }
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n, m; cin >> n >> m;
	vector<int>p(n); for (auto&& x : p)cin >> x;
	int x, y;
	UnionFind uf(n);
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		uf.unite(x - 1, y - 1);
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (uf.same(i, p[i] - 1))sum++;
	}
	cout << sum << endl;
	return 0;
}

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

#define N 1010

void LCSLength();

char X[N], Y[N];
int Xlen, Ylen;

int main(){
  int num, i, j;
  char c;
  
  scanf("%d%*[^\n]", &num);
  getchar();
  
  for(i = 0; i < num; i++){
    strcpy(X, "");
    strcpy(Y, "");

    j = 0;
    while((c = getchar()) != '\n'){
      X[j] = c;
      j++;
    }
    X[j] = '\0';
    Xlen = j;
    fflush(stdin);
    
    j = 0;
    while((c = getchar()) != '\n'){
      Y[j] = c;
      j++;
    }
    Y[j] = '\0';
    fflush(stdin);
    
    Ylen = j;

    LCSLength();
  }
  /*
  for(i = 0; i < num; i++){
    printf("%d\n", C[i]);
  }
  */
  
  return 0;
}

void LCSLength(){
 long long int c[N][N];
  int i, j;

  // printf("X = %s, Xlen = %d\n", X, Xlen);
  //printf("Y = %s, Ylen = %d\n", Y, Ylen);
  
  for(i = 1; i <= Xlen; i++){
    c[i][0] = 0;
  }
  for(j = 1; j <= Ylen; j++){
    c[0][j] = 0;
  }

  for(i = 1; i <= Xlen; i++){
    for(j = 1; j <= Ylen; j++){
      
      if(X[i-1] == Y[j-1]){
	c[i][j] = c[i-1][j-1] + 1;
      }
      else {
	if(c[i-1][j] >= c[i][j-1]){
	  c[i][j] = c[i-1][j];
	}
	else{
	  c[i][j] = c[i][j-1];
	}
      }
    }
  }
  /*
  for(i = 0; i <= Xlen; i++){
    for(j = 0; j <= Ylen; j++){
      printf(" %2d", c[i][j]);
    }
    printf("\n");
  }
  */
  printf("%d\n", c[i-1][j-1]);
 
}



Measured memory_bytes: 9696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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 INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    int now = 0;
    int ans = 0;
    int cnt = 0;
    rep(i, n) {
        int h;
        cin >> h;
        if (now >= h) cnt++;
        else cnt = 0;
        now = h;
        chmax(ans, cnt);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3604
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  ll x,k,d;
  cin>>x>>k>>d;
  
  if(k<=abs(x)/d) cout<<abs(abs(x)-k*d)<<endl;
  else if((abs(x)/d)%2==0){
    if(k%2==0) cout<<abs(x)-abs(x)/d*d<<endl;
    else cout<<(abs(x)/d+1)*d-abs(x)<<endl;
  }
  else{
    if(k%2==1) cout<<abs(x)-abs(x)/d*d<<endl;
    else cout<<(abs(x)/d+1)*d-abs(x)<<endl;
  }
  
  return 0;
}

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

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();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

int main(void){
    ll X,Y,A,B,C; cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    REP(i,A) cin >> p[i]; REP(i,B) cin >> q[i]; REP(i,C) cin >> r[i];
    SORT(p); SORT(q); SORT(r);
    priority_queue<ll,vector<ll>,greater<ll>> q1,q2;
    ll s1=0, s2=0, s3=0;
    REP(i,X){
        s1 += p[A-i-1];
        q1.push(p[A-i-1]);
    }
    REP(i,Y){
        s2 += q[B-i-1];
        q2.push(q[B-i-1]);
    }

    REP(i,C){
        if(q1.top() < q2.top()){
            if(q1.top() < r.back()){
                s1 -= q1.top(); q1.pop();
                s1 += r.back();
                q1.push(r.back()); r.pop_back();
            }
            else break;
        }
        else{
            if(q2.top() < r.back()){
                s2 -= q2.top(); q2.pop();
                s2 += r.back();
                q2.push(r.back()); r.pop_back();
            }
            else break;
        }
    }
    ll ans = s1+s2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4852
def SCC_Tarjan(g):
    def dfs(v):
        nonlocal idx
        used[v] = 1
        pre[v] = low[v] = idx
        idx += 1
        S.append(v)
        onS[v] = 1
        for c in g[v]:
            if not used[c]:
                dfs(c)
                low[v] = min(low[v], low[c])
            elif onS[c]:
                low[v] = min(low[v], pre[c])
        used[v] = 2

        if low[v] == pre[v]:
            cc = []
            while True:
                w = S.pop()
                onS[w] = 0
                cc.append(w)
                if w==v: break
            scc.append(cc)


    n = len(g)
    used = [0]*n # 0 -> 1 -> 2
    pre = [0]*n
    low = [0]*n
    onS = [0]*n
    idx = 0
    S = []
    scc = []
    for i in range(n):
        if not used[i]:
            dfs(i)
    #print(g)    
    #print("idx",pre)
    #print("low",low)
    #print(scc)
        
    return scc

###########################################################################                        
###########################################################################                        

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10**6)
#n,*w = [int(i) for i in read().split()]

n,m = [int(i) for i in readline().split()]

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

gp = SCC_Tarjan(g)
print(len(gp))
for lst in gp[::-1]:
    print(*([len(lst)]+lst))



Measured memory_bytes: 237316
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
//using namespace __gnu_pbds;
//using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int n,m,K;
ll A[200010],B[200010];
void MAIN() {
	cin>>n>>m>>K;
	rng(i,1,n)cin>>A[i],A[i]+=A[i-1];
	rng(i,1,m)cin>>B[i],B[i]+=B[i-1];
	int ans=0;
	rng(i,0,n) {
		if(A[i]>K)break;
		int j=lower_bound(B,B+m+1,K-A[i]+1)-B-1;
		ans=max(ans,i+j);
	}
	cout<<ans;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 6788
#include <iostream>
using namespace std;
int main(void) {
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b&&b<c||a<b&&b==c||a==b&&b==c){
		cout<<a<<" "<<b<<" "<<c<<endl;
	}else if(c<b&&b<a||c<b&&b==a||c==b&&b<a){
		cout<<c<<" "<<b<<" "<<a<<endl;
	}else if(b<a&&a<c||b<a&&a==c||b==a&&a<c){
		cout<<b<<" "<<a<<" "<<c<<endl;
	}else if(a<c&&c<b||a<c&&c==b||a==c&&c<b){
		cout<<a<<" "<<c<<" "<<b<<endl;
	}else if(b<c&&c<a||b<c&&c==a||b==c&&c<a){
		cout<<b<<" "<<c<<" "<<a<<endl;
	}else if(c<a&&a<b||c<a&&a==b||c==a&&a<b){
		cout<<c<<" "<<a<<" "<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include<stdio.h>

int main()
{
  int max, min, n, i, j, a[200000];

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

  i = a[0];
  max = a[1]-i;
    
  for(j=1; j<n; j++)
    {
      min = i;
      if(a[j] <= min) i=a[j];
      
      if(a[j]-min >= max) max = a[j]-min;
    }

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

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/
vec<vll> dp;

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n,weight; cin >> n >> weight;
    vi w(n), v(n); rep(i,n) cin >> w[i] >> v[i];

    dp.resize(n+1, vll(100001, infll));
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= 100000; ++j) {
            if(j-v[i] >= 0) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    for(int i = 1000*n; i > 0; --i) if(dp[n][i] <= weight) {
        cout << i << '\n';
        return 0;
    }
}

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

int h, w, st[200005 << 2], lazy[200005 << 2], inf = 0x3F3F3F3F;

void push(int x, int l, int mid){
    if (!lazy[x]) return;
    st[x<<1] = lazy[x];
    lazy[x<<1] = lazy[x];
    st[x<<1|1] = lazy[x]+(mid-l+1);
    lazy[x<<1|1] = lazy[x]+(mid-l+1);
    lazy[x] = 0;
}
void update(int x, int l, int r, int ul, int ur, int u){
    if (ul <= l && r <= ur){
        st[x] = u;
        lazy[x] = u;
        return;
    }
    int mid = (l+r) >> 1;
    push(x, l, mid);
    int del = 0;
    if (ul <= mid){
        update(x<<1, l, mid, ul, ur, u);
        del = mid-max(ul, l)+1;
    }
    if (mid < ur) update(x<<1|1, mid+1, r, ul, ur, u + del);
    st[x] = min(st[x<<1], st[x<<1|1]);
}
int query(int x, int l, int r, int q){
    if (q == 0) return inf;
    if (l == r) return st[x];
    int mid = (l+r) >> 1;
    push(x, l, mid);
    if (q <= mid) return query(x<<1, l, mid, q);
    else return query(x<<1|1, mid+1, r, q);
}

int main() {
    cin >> h >> w;
    for (int i = 1, a, b; i <= h; i++){
        cin >> a >> b;
        update(1, 1, w, a, b, query(1, 1, w, a-1)+1);
        if (st[1] > w) cout << -1 << "\n";
        else cout << st[1]+i << "\n";
    }
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const int MAX = 5010000;
long long fac[MAX], finv[MAX], inv[MAX];


void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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




ll combination(ll a, ll b){
  if(a == 0 || b == 0 || a<b)
    return 1;
  
  ll numerator = 1;
  for(ll i = 1; i <= a; i++)
    numerator *= i;
  
  ll denominator = 1;
  for(ll i = 1; i <= b; i++)
    denominator *= i;
  for(ll i = 1; i <= a-b; i++)
    denominator *= i;
  
  return numerator/denominator;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n, m;
  cin >> n >> m;
  
  COMinit();
  ll factor;
  ll M = m;
  ll ans = 1;
  for(ll i = 2; i*i <= m; i++){
    factor = 0;
    while(M%i == 0){
      factor++;
      M /= i;
    }
    
    ans *= COM(factor+n-1, factor);
    ans %= MOD;
  }
  factor = 1;
  if(M != 1)
    ans *= COM(factor+n-1, factor);
  
  ans %= MOD;
  cout << ans << endl;
  
  
}

Measured memory_bytes: 117632
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
	int h, w, count = -1;
	cin >> h >> w;
	w = w+1;
	char c[h][w];
	getchar();
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			scanf("%c", &c[i][j]);
		}
	}
	
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w-1; j++){
			if (c[i][j] == 'c'){
				count = 0;
				printf("%d", count++);
			}else {
				if (count == -1) printf("%d", count);
				else printf("%d", count++);	
			}
			if (j != w-2) printf(" ");
		}
		printf("\n"); count = -1;
	}
	return 0;
}

Measured memory_bytes: 3208