akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_V 100

//辺を表す構造体（行き先、容量、コスト、逆辺）
struct edge{int to, cap, cost, rev; };

int V;//頂点数
vector<edge> G[MAX_V];//グラフの隣接リスト表現
int dist[MAX_V];//最短距離
int prevv[MAX_V], preve[MAX_V];//直前の頂点と辺

//fromからtoへ向かう容量cap、コストcostの辺をグラフに追加する
void add_edge(int from, int to, int cap, int cost){
    G[from].push_back((edge){to, cap, cost, G[to].size()});
    G[to].push_back((edge){from, 0, -cost, G[from].size() - 1});
}

//sからtへの流量fの最小費用流を求める
//流せない場合は-1を返す
int min_cost_flow(int s, int t, int f){
    int res = 0;
    while(f > 0){
        //ベルマンフォード法により、s-t間最短路を求める
        fill(dist, dist + V, INF);
        dist[s] = 0;
        bool update = true;
        while(update){
            update = false;
            for(int v = 0; v < V; v++){
                if(dist[v] == INF) continue;
                for(int i = 0; i < G[v].size(); i++){
                    edge &e = G[v][i];
                    if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
                        dist[e.to] = dist[v] + e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }
        
        if(dist[t] == INF){
            //これ以上流せない
            return -1;
        }

        //s-t間最短路に沿って目一杯流す
        int d = f;
        for(int v = t; v != s; v = prevv[v]){
            d = min(d, G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d * dist[t];
        for(int v = t; v != s; v = prevv[v]){
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

signed main(){
    int E,F;
    cin >> V >> E >> F;
    int u,v,c,d;
    REP(i,E){
        cin >> u >> v >> c >> d;
        add_edge(u,v,c,d);
    }
    cout << min_cost_flow(0, V - 1, F) << endl;
}


Measured memory_bytes: 3232
def main():
    n = int(input())
    h = list(map(int, input().split()))
    ans = 0
    i = 0
    while i < n:
        if h[i] == 0:
            i += 1
            continue
        x = i+1
        m = h[i]
        while x < n and h[x] != 0:
            if h[x] < m:
                m = h[x]
            x += 1
        for j in range(i, x):
            h[j] -= m
        ans += m
        if h[i] == 0:
            i += 1
    print(ans)

if __name__ == "__main__":
    main()

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		int q = Integer.parseInt(br.readLine());

//		ArrayList<Integer> list = new ArrayList<Integer>();
//		ArrayDeque<Integer> deque = new ArrayDeque<Integer>();


		MyDeque deque = new MyDeque(400000);
		boolean changed = false;
		Integer a[] = null;
		for(int i = 0; i < q; i++){
			String[] tmpArray = br.readLine().split(" ");

			if(tmpArray[0].equals("0")){
				if(tmpArray[1].equals("0")){
					deque.push(Integer.parseInt(tmpArray[2]));

				}
				else{
					deque.add(Integer.parseInt(tmpArray[2]));
				}
//				changed = true;
			}
			else if(tmpArray[0].equals("1")){
//				if(changed){
//					a = deque.toArray(new Integer[0]);
//				}
//				System.out.println(a[Integer.parseInt(tmpArray[1])]);
				System.out.println(deque.get(Integer.parseInt(tmpArray[1])));
//				changed = false;
			}
			else {
//				list.removeLast();
				if(tmpArray[1].equals("0")){
					deque.removeFirst();
				}
				else {
					deque.removeLast();
				}
				changed = true;
			}

//			for(int j = 0; j < list.size(); j++){
//				System.out.print(list.get(j)+" ");
//			}
//			System.out.println();
		}
    }
}

class MyDeque {
	private int limit;
	private int first, last;
	private int[] data;
	MyDeque(int limit){
		data = new int [limit * 2 + 1];
		first = limit;
		last = limit;
	}

	void push(int x){
		data[--first] = x;
	}

	void add(int x){
		data[last++] = x;
	}

	int get(int index){
		return data[first + index];
	}

	int removeFirst(){
		int result = data[first++];
		return result;
	}

	int removeLast(){
		last--;

		return data[last];
	}
}



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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) {return b < a ? a = b, 1 : 0;}
template<typename T> inline bool chkmax(T &a, T b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
#endif
}

const int N = 3010, Mod = 1e9 + 7;

int n, m, R[N], dp[N][N], sum[N];

char str[N];

inline void Add(int &a, int b) {
	if ((a += b) >= Mod) a -= Mod;
}

int main() {

	File();

	n = read(); m = read();

	scanf ("%s", str + 1);
	For (i, 1, n + 1)
		sum[i] = sum[i - 1] + (i <= n ? str[i] ^ 48 : 0);
	For (i, 1, m) {
		int l = read(), r = read(); chkmax(R[l], r);
	}
	For (i, 1, n + 1)
		chkmax(R[i], max(i, R[i - 1]));
	dp[1][sum[R[1]]] = 1;

	For (i, 1, n) For (j, 0, n) if (dp[i][j]) {
		int l = R[i] + 1, r = R[i + 1], one = j, zero = (R[i] - i + 1) - j;
		if (zero) Add(dp[i + 1][j + (sum[r] - sum[l - 1])], dp[i][j]);
		if (one) Add(dp[i + 1][j + (sum[r] - sum[l - 1]) - 1], dp[i][j]);
	}
	printf ("%d\n", dp[n + 1][0]);

    return 0;

}


Measured memory_bytes: 33920
#include<bits/stdc++.h>
using namespace std;
int main(){
  int  n,y;
  cin>>n>>y;
  y/=1000;
  int a,b;
  for(a=0;a<n+1;a++){
    for(b=0;b<n+1;b++){
      int c=y-10*a-5*b;
      if(c==n-a-b && c>=0){
        cout<<a<<" "<<b<<" "<<" "<<c<<endl;
        exit(0);
      }
    }
  }
  cout<<"-1 "<<"-1 "<<"-1"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int a,b,c,d,sum=0;
  cin >> a >> b >> c >> d; 
  
  if(a > b) sum += b;
  else sum += a;
  if(c > d) sum += d;
  else sum += c;

  cout << sum << endl;
}
    


Measured memory_bytes: 256
#include<cstdio>

#define NIL -1
#define MAX 10000

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
	if (u == NIL)return;
	D[u] = d;
	setDepth(T[u].left, d + 1);
	setDepth(T[u].right, d + 1);
}

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

int getSiblings(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) {
	printf("node %d: ", u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSiblings(u));
	int deg = 0;
	if (T[u].left != NIL)deg++;
	if (T[u].right != NIL)deg++;
	printf("degree = %d, ", deg);
	printf("depth = %d, ", D[u]);
	printf("height = %d, ", 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 v, l, r, root = 0;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) T[i].parent = NIL;

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

	for (int i = 0; i < n; i++)if (T[i].parent == NIL)root = i;

	setDepth(root, 0);
	setHeight(root);

	for (int i = 0; i < n; i++)print(i);

	return 0;
}


Measured memory_bytes: 2716
#include <bits/stdc++.h>
#define LL long long
using namespace std;

int main()
{

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    LL N;
    cin>>N;
    vector<LL>arr(N);
    for(auto &it:arr)
    {
        cin>>it;
    }
    LL Min=INT_MAX;
    LL money=1000;
    LL stocks=0;
    for(auto it:arr)
    {
        if(it>Min)
        {
            // AB BECHOO BHENCHO
            LL kamayi=stocks*it;
            stocks=0;
            money+=kamayi;
            Min=it;
            LL temp = money % it;
            stocks=money/it;
            money=temp;
        }
        else if(it<=Min) 
        {
            LL change =( Min * stocks  + money ) % it;
            stocks= (Min*stocks + money) / it;
            money=change;
            Min=it;
        }
    }
    cout<<money+ stocks*Min ;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int n, a[110], res;
 
int main(){
  cin >> n;
  for (int i=1; i<=n; ++i) cin >> a[i];
  res = 100*100*100;
  for (int i=1; i<=100; ++i){
  	int tmp = 0;
    for (int j=1; j<=n; ++j) tmp+= (a[j]-i)*(a[j]-i);
    res = min(res, tmp);
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(i = 0; i < n; i++)
#define repi(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
	int e;
	while(cin>>e, e){
		int x, y, z;
		int ans = 1000000;
		for(z = 100; z >= 0; z--){
			if(z*z*z > e)continue;
			for(y = 1000; y >= 0; y--){
				if(z*z*z + y*y > e)continue;
				if(ans > (e - z*z*z - y*y )+y+z)ans = (e - z*z*z - y*y )+y+z;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,k;cin>>n>>k;
    int ans=0;
    rep(i,n){
        int h;cin>>h;
        if(h>=k){
            ans++;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

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

    now = 1
    l = []
    pre = [-1] * N
    turn = 0
    while True:
        if pre[now-1] != -1:
            break
        pre[now-1] = turn
        l.append(now)
        now = A[now-1]
        turn += 1

    if K < len(l):
        print(l[K])
    else:
        d = turn - pre[A[l[-1]-1]-1]
        f = len(l) - d
        t = (K - f) % d
        print(l[f+t])

if __name__ == "__main__":
    main()

Measured memory_bytes: 31404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll s, w;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] temp = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
        var spots = new List<int>(){0};
        spots.AddRange(temp);
        spots.Add(0);
        
        int d = 0;
        for(int i = 1;i < spots.Count;i++){
            d += Math.Abs(spots[i] - spots[i - 1]); 
        }
        
        for(int i = 1;i < spots.Count - 1;i++){
            int total = d - Math.Abs(spots[i - 1] - spots[i])
            - Math.Abs(spots[i] - spots[i + 1])
            + Math.Abs(spots[i - 1] - spots[i + 1]);
            Console.WriteLine(total);
        }
    }
}


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

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

const ll INF=1LL << 60;

int main(){

  int N=0;

  int K=0;
  cin>>N>>K;
 
  int h[N];
  ll dp[N];
  rep(i,N){
	dp[i]=INF;
    cin>>h[i];
  }  
 
  dp[0]=0;
  for(int i=1; i<N;i++){

    for(int j=1;j<K+1;j++){
      if(i>=j)chmin(dp[i], dp[i-j]+abs(h[i-j]-h[i]));
    }
    
  }
  
  cout<<dp[N-1]<<endl;

}




Measured memory_bytes: 1408
#include<cstdio>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(void) {
	int H, W, K;
	scanf("%d %d %d", &H, &W, &K);
	char c[6][6];
	getchar();
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			scanf("%c", &c[i][j]);
		}
		getchar();
	}
	int HLoop = pow(2, H);
	int WLoop = pow(2, W);

	int row[100][6];
	for (int i = 0; i < HLoop; i++) {
		int tmp = i;
		for (int j = H - 1; j >= 0; j--) {
			row[i][j] = tmp % 2;
			tmp /= 2;
		}
	}
	int col[100][6];
	for (int i = 0; i < WLoop; i++) {
		int tmp = i;
		for (int j = W - 1; j >= 0; j--) {
			col[i][j] = tmp % 2;
			tmp /= 2;
		}
	}

	int ans = 0;
	for (int h = 0; h < HLoop; h++) {
		for (int w = 0; w < WLoop; w++) {
			char test[6][6];
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					test[i][j] = c[i][j];
				}
			}

			// cout << "---------" << h << " " << w << "------" << endl;
			for (int i = 0; i < H; i++) {
				if (row[h][i] == 1) {
					for (int j = 0; j < W; j++) {
						test[i][j] = 'r';
					}
				}
			}
			for (int j = 0; j < W; j++) {
				if (col[w][j] == 1) {
					for (int i = 0; i < H; i++) {
						test[i][j] = 'r';
					}
				}
			}
			int cnt = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					// cout << i << " " << j << ": " << test[i][j]<< endl;;
					if (test[i][j] == '#') {
						cnt++;
					}
				}
				// cout << endl;
			}
			if (cnt == K) {
				ans++;
			}
			// cout << endl;
		}
	}

	printf("%d", ans);


	return 0;
}


Measured memory_bytes: 4200
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    int k;
    string s;
    cin >> k >> s;
    if ((int)s.size() <= k) cout << s << endl;
    else {
        rep(i, k) cout << s[i];
        cout << "...\n";
    }
}

Measured memory_bytes: 3628
import math
import collections
from collections import defaultdict
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
mod=10**9+7

L=[]
ct0=0
for i in range(n):
  if l[i][0]==0 and l[i][1]==0:
    ct0+=1
  elif l[i][0]==0:
    L.append((0,1))
  elif l[i][1]==0:
    L.append((1,0))
  elif l[i][0]<0:
    L.append((-l[i][0]//math.gcd(l[i][0],l[i][1]),-l[i][1]//math.gcd(l[i][0],l[i][1])))
  else:
    L.append((l[i][0]//math.gcd(l[i][0],l[i][1]),l[i][1]//math.gcd(l[i][0],l[i][1])))

ans=1
d=set()
c=collections.Counter(L)
for i in c.keys():
  if i[0]==0:
    x=(1,0)
  elif i[1]==0:
    x=(0,1)
  elif i[1]<0:
    x=(-i[1],i[0])
  else:
    x=(i[1],-i[0])
  if i not in d:
    ans*=pow(2,c[i],mod)+pow(2,c[x],mod)-1
    ans%=mod
    d.add(x)
print((ans-1+ct0)%mod)

Measured memory_bytes: 161128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    string s, t;
    cin >> s >> t;
    int sn = s.size(), tn = t.size();
    int cnt = 0;
    rep(i, sn - tn + 1) {
        int tmp = 0;
        rep(j, tn) {
            if (s[i+j] == t[j]) tmp++;
        }
        cnt = max(cnt, tmp);
    }
    cout << tn - cnt << endl;
}


Measured memory_bytes: 3576
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REPI(i, S, N) for(int i=int(S); i<int(N); i++)
#define REP(i, N) REPI(i, 0, N)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<string> S;


  if (S == "RRR")
  return 3;
  if (S == "SSS")
  return 0;

  if (S == "RRS" || S == "SRR")
  return 2;
else return 1;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cmath>
#include <algorithm>
using namespace std;
int main(){
	long long a,b,c,d;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	long long n[4]={0};
	n[0]=b*c;
	n[1]=b*d;
	n[2]=a*c;
	n[3]=a*d;
	sort(n,n+4);
	printf("%lld\n",n[3]);
	return 0;
} 

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define PII pair<int,int>
#define s second
#define f first
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
ll MOD = 998244353;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x)%MOD;
        }
        p = p >> 1;
        x = (x*x)%MOD;
    }
    return res;
}
int dp[100005];
vector<vector<int>> graph;
int dfs(int node){
    if(dp[node] != -1){
        return dp[node];
    }
    int mx = 0;
    for(int i = 0; i < graph[node].size(); i++){
        mx = max(mx, dfs(graph[node][i]));
    }
    return dp[node] = 1+ mx;
}
int main() {
    IO;
    int n, m;
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    graph.resize(n);
    int x, y;
    for(int i = 0; i < m; i ++){
        cin >>x  >> y;
        graph[x-1].push_back(y-1);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, dfs(i));
    }
    cout << ans-1;
    return 0;
}


Measured memory_bytes: 8192
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vec<ll> a(5);
    rep(i,5) cin>>a[i];
    ll mini=a[0];
    rrep(i,4) {
        mini=min(mini,a[i]);
    }
    if(mini>=n){
        cout<<5<<endl;
        return 0;
    }
    
    ll ans=0;
    if(n%mini==0) ans=n/mini;
    else ans=n/mini + 1;
    cout<<ans+4<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
//-------------
int main() {
    int a,b;
    cin >>a>>b;

    if((a*b)%2==1){
        cout << "Odd" << endl;
    }else{
        cout << "Even" << endl;
    }
}

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

public class Main {

    public void solve() {
        char[] c = in.nextToken().toCharArray();
        int k = in.nextInt();

        for (int i = 0; i < c.length; i++) {
            int code = c[i] - 'a';
            if (c[i] == 'a') {
                continue;
            }
            if (26 - code <= k) {
                k -= 26 - code;
                c[i] = 'a';
            }
        }
        int last  = (c[c.length - 1] - 'a' + k) % 26;
        c[c.length - 1] = (char) ('a' + last);
        out.println(new String(c));
    }

    public void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    FastScanner in;
    PrintWriter out;

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (FileNotFoundException e) {
            }
        }

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

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

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

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

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

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 11472
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define debug(x) cout<<x<<endl;
#define int ll
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int dp[100001];
vector<vector<int> > v;

int dfs(int u)
{
	if(dp[u]!=-1)
		return dp[u];

	int c = 0;
	for(int i=0;i<v[u].size();i++)
		c = max(c, dfs(v[u][i]));

	return dp[u] = c+1;
}
 
int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("a.in","r",stdin);
	#endif
	ios::sync_with_stdio(false);

	for(int i=0;i<100001;i++)
		dp[i] = -1;
 
 	int n,m;
 	cin>>n>>m;
 	v.resize(n);
 	for(int i=0;i<m;i++)
 	{
 		int a,b;
 		cin>>a>>b;
 		a--; b--;
 		v[a].push_back(b);
 	}


 	int ans = 0;
 	for(int i=0;i<n;i++)
 		ans = max(ans, dfs(i));

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

Measured memory_bytes: 11596
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    ll n;
    cin >> n;
    map<string,int> mp;
    rep(i,n){
        string a;
        cin >> a;
        sort(a.begin(),a.end());
        mp[a]++;
    }
    ll ans=0;
    for(auto p: mp){
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
import math
from collections import deque

n = int(input())
als = list(map(int, input().split()))

ans = "not coprime"

a, b = als[1], als[0]
if a < b:
    a,b = b,a
while a % b != 0:
    a, b = b, a % b
    if n == 2 and b == 1:
        ans = "pairwise coprime"
        failed = True

for i in range(2, n):
    a = als[i]
    if a < b:
        a,b = b,a 
    while a % b != 0:
        a, b = b, a % b
if b == 1:
    ans = "setwise coprime"
    # break

existeven = False

failed = False

for i in range(n):
    if als[i] >= 2 and als[i]%2 == 0:
        if existeven:
            failed = True
            break
        else:
            existeven = True

maxa = max(als)

afterchecklist = deque([])


if not failed:
    for i in range(3, int(math.sqrt(maxa))+2, 2):
        existfactrial = False
        failed = False
        for j in range(n):
            if als[j] >= i and als[j]%i == 0:
                afterchecklist.append(als[j]/i)
                if existfactrial:
                    failed = True
                    break
                else:
                    existfactrial = True
        if failed:
            break
    if not failed:
        for i in list(afterchecklist):
            existfactrial = False
            failed = False
            for j in range(n):
                if i != 1 and als[j] >= i and als[j]%i == 0:
                    if existfactrial:
                        failed = True
                        break
                    else:
                        existfactrial = True
            if failed:
                break
        if not failed:
            ans = "pairwise coprime"

print(ans)
        

    

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

int main(){
    ll n;
    cin >> n;
    vector <ll> a(n-1),b(n-1),c(n-1);
    vector <vector <ll>> m(n+1),m2(n+1);
    rep(i,n-1){
        cin >> a[i] >> b[i] >> c[i];
        m[a[i]].push_back(b[i]);
        m[b[i]].push_back(a[i]);
        m2[a[i]].push_back(c[i]);
        m2[b[i]].push_back(c[i]);   
    }

    ll qqq,k;
    cin >> qqq >> k;
    vector <ll> x(qqq),y(qqq);
    rep(i,qqq){
        cin >> x[i] >> y[i];
    }
    vector <ll> kyo(n+1);
    vector <int> ans(n+1,0);
    queue <ll> q;
    q.push(k);
    ll qq,l;
    kyo[k]=0;
    while(q.size()!=0){
        
        qq=q.front();
        //cout << qq << endl;
        q.pop();
        l=m[qq].size();
        //cout << l << endl;
        ans[qq]=1;
        rep(i,l){
            if(ans[m[qq][i]]==0){
                //cout << m[qq][i] << endl;
                ans[m[qq][i]]=1;
                //cout <<  kyo[qq] << endl;
                //cout << m2[qq][i] << endl;
                kyo[m[qq][i]]=kyo[qq]+m2[qq][i];
               // cout << "t" << endl;
                q.push(m[qq][i]);
                //cout << "t" << endl;
            }
        }
    }

    rep(i,qqq){
        cout << kyo[x[i]]+kyo[y[i]] << endl;
    }

    

    return 0;
}

Measured memory_bytes: 19688
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e4+5;
int num[maxn];
int M[105][105],color[105*105];

void init(int n,int m){
	int index=1,i=1,j=1;
    while(index <= n*m){
        while(M[i][j] == 0 && j <= m)
            M[i][j ++] = index ++;
        j --; 
        i ++; 

        while(M[i][j] == 0 && i <= n)
            M[i++][j] = index ++;
        i --;
        j --;

        while(M[i][j] == 0 && j >= 1)
            M[i][j --] = index ++;
        j ++;
        i --;

        while(M[i][j] == 0 && i >= 1)
            M[i --][j] = index ++;
        i ++;
        j ++;
    }
}

int main(int argc, char const *argv[])
{
	int len,n,m;
	while(~scanf("%d %d",&n,&m)){
		scanf("%d",&len);
		memset(M,0,sizeof(M));
		for(int i=1;i<=len;i++){
			scanf("%d",&num[i]);
		}
		init(n,m);
		int temp=1;
		for(int i=1;i<=len;i++){
			for(int j=0;j<num[i];j++){
				color[temp+j]=i;
			}
			temp+=num[i];
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				printf("%d%c",color[M[i][j]],j==m?'\n':' ');
			}
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main(){
	string s;
	int k;
	set<string> sub;
	cin >> s >> k;
	for(int i=0; i < s.size(); i++){
		for(int j=1; j <= k; j++) {
			sub.insert(s.substr(i, j));
		}
	}
	auto itr = sub.begin();
	for(int i=0; i < k-1; i++){
		itr++;
	}
	cout << *itr;
}



Measured memory_bytes: 1664
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int p,q,r;
	cin>>p>>q>>r;
	cout<<p+q+r-max({p,q,r});
	return 0;
}


Measured memory_bytes: 256
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,a,b = IL()
print( N//(a+b)*a + min(N%(a+b),a))

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

int main() {
  int N;
  cin >> N;
  int A[10][110];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }

  int ans = -1, sum1 = 0;
  for (int i = 0; i < N; i++) {
    sum1 += A[0][i];
    int sum2 = 0;
    for (int j = i; j < N; j++) {
      sum2 += A[1][j];
    }
    ans = max(ans, sum1 + sum2);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, H: "List[int]"):
    count = 0
    maxcount = 0
    for i in range(0, N-1):
        if H[i] >= H[i+1]:
            count += 1
        else:
            maxcount = max(maxcount, count)
            count = 0
    maxcount = max(maxcount, count)
    print(maxcount)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15384
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    A, B = map(int, input().split())

    if A == B:
        ans = 'Draw'
    else:
        if A == 1:
            ans = 'Alice'
        elif B == 1:
            ans = 'Bob'
        elif A > B:
            ans = 'Alice'
        else:
            ans = 'Bob'

    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef multiset<ll> S;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
int main(){
    int n;cin>>n;
    cout<<n*n<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define LOO for(int i=0;i<n;i++){
#define LOOEND }

int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}

int main(void){
int n,s[105];
int sum=0;
scanf("%d",&n);

LOO
scanf("%d",&s[i]);
LOOEND

qsort(s,n,sizeof(int),cmp);

LOO
sum=sum+s[i];
LOOEND

if(sum%10!=0){printf("%d\n",sum);return 0;}
else{
    LOO
        if(s[i]%10!=0){printf("%d\n",sum-s[i]); return 0;}
    LOOEND
    printf("0\n");
    }
}




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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

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

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif


void solve()
{
	string s, t;
	cin >> s >> t;

	int mn = 100000;

	for (int i = 0; i < s.size() - t.size() + 1; i++) {

		int cnt = 0;

		for (int j = 0; j < t.size(); j++) {
			if (s[i + j] != t[j]) {
				cnt++;
			}
		}

		mn = min(mn, cnt);
	}

	cout << mn << nl;
}

int main()
{


	FIO;

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}

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

//#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
//const int INF = 1107110711071107;

int dp[1000001];
int dp_odd[1000001];
int four[300];
int x;

signed main() {
  Rep(i, 210) four[i] = i * (i+1) * (i+2) / 6;
  
  Rep(i, 1000001) dp[i] = i;
  Rrep(i, 2, 300) {
    Rep(j, 1000001) {
      if ( j+four[i] <= 1000000 ) {
	dp[j+four[i]] = min(dp[j+four[i]], dp[j]+1);
      }
    }
  }

  Rep(i, 1000001) dp_odd[i] = i;
  Rrep(i, 2, 50) {
    Rep(j, 1000001) {
      dp_odd[j] = min(dp_odd[j], dp_odd[j]);
      if ( j+four[(i-1)*4+1] <= 1000000 ) {
	dp_odd[j+four[(i-1)*4+1]] = min(dp_odd[j+four[(i-1)*4+1]], dp_odd[j]+1);
      }
    }
  }
 
  while ( cin >> x, x ) {
    cout << dp[x] << " " << dp_odd[x] << endl;
  }
  return 0;
}

Measured memory_bytes: 10900
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func main() {
	line := inputs(2)

	line1 := strings.Split(line[0], " ")

	n, _ := strconv.Atoi(line1[0])
	m, _ := strconv.Atoi(line1[1])

	line2 := strings.Split(line[1], " ")
	a := make([]int, n+1)

	allVotes := 0
	for i := 1; i < (n + 1); i++ {
		a[i], _ = strconv.Atoi(line2[i-1])
		allVotes += a[i]
	}

	limit := float64(allVotes) / float64(4*m)

	count := 0

	for i := 1; i < (n + 1); i++ {
		if float64(a[i]) >= limit {
			count++
		}
	}

	if count >= m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s, t;
    cin >> s >> t;
    ll a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) a--;
    else b--;
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  if(a+b<=c*2){
    cout<<a*x+b*y<<endl;
  }
  else{
    int d=min(x,y);
    int ans=c*d*2;
    x-=d;
    y-=d;
    if(a<=c*2){
      ans+=a*x;
    }
    else{
      ans+=c*x*2;
    }
    if(b<=c*2){
      ans+=b*y;
    }
    else{
      ans+=c*y*2;
    }
    cout<<ans<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long N,A,B,C,D,ans;
void AC(long long Q,long long W,long long E,long long R,long long T)
{
	long long X=min(min(4*Q,2*W),E);
	long long Y=min(X*T,(T/2*R+T%2*X));
	cout<<Y<<"\n";
} 
int main()
{
    scanf("%d%d%d%d%d",&A,&B,&C,&D,&N);
	AC(A,B,C,D,N);
    return 0;
}

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

class Node
{
    internal int d, f;
    internal List<int> Adj;
    public Node() {
        this.Adj = new List<int>();
    }
}

class B
{
    static int time=0;
    static int n;
    public static void Main() {
        n = int.Parse(Console.ReadLine());
        Node[] nodes = new Node[n + 1];
        for(int i = 0; i < n; i++) {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            nodes[input[0]] = new Node();
            for(int j = 0; j < input[1]; j++) {
                nodes[input[0]].Adj.Add(input[j + 2]);
            }
        }
        DFSvisit(nodes);
    }

    public static void DFS(Node[] nodes, Node v) {
        v.d = ++time;
        for (int i=0;i<v.Adj.Count;i++) {
            if (nodes[v.Adj[i]].d == 0) {
                DFS(nodes, nodes[v.Adj[i]]);
            }
        }
        v.f = ++time;
    }

    public static void DFSvisit(Node[] nodes) {
        for (int i = 1; i < n; i++) {
            if (nodes[i].d == 0) {
                DFS(nodes, nodes[i]);
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            output.AppendLine(i + " " + nodes[i].d + " " + nodes[i].f);
        }
        Console.Write(output);
    }
}


Measured memory_bytes: 15996
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

const int MAXN = 200001;
int n,m,d[MAXN],col[MAXN],ans[MAXN],good[MAXN];
vector<pair<int,int>> adj[MAXN];

void dfs(int s, int c){
    col[s]=c;
    for(auto t:adj[s]){
        if(col[t.first]==-1){
            ans[t.second]=d[t.first];
            dfs(t.first,c^1);
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&d[i]);
        col[i]=-1;
    }
    for(int i=0;i<m;i++){
        int x,y;
        ans[i]=1e9;
        scanf("%d%d",&x,&y);x--;y--;
        if(d[x]==d[y]){
            good[x]=1;
            adj[x].push_back({y,i});
            adj[y].push_back({x,i});
        }
        else if(d[x]>d[y]){
            adj[y].push_back({x,i});
        }
        else {
            adj[x].push_back({y,i});
        }
    }
    for(int i=0;i<n;i++){
        if(good[i]&&col[i]==-1){
            dfs(i,0);
        }
    }
    for(int i=0;i<n;i++){
        if(col[i]==-1){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        cout<<"BW"[col[i]];
    }
    cout<<endl;
    for(int i=0;i<m;i++){
        printf("%d\n",ans[i]);
    }

}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1LL<<61);

int main() {
  int n; cin >> n;
  string s, t; cin >> s >> t;
  rep(i,n) {
    cout << s[i] << t[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	REP(i, N) cin >> v.at(i);

	int count = 0;
	REP(i, N) {
		int mini = i;
		FOR(j, i, N) {
			if(v.at(j) < v.at(mini)) mini = j;
		}
		swap(v.at(i), v.at(mini));
		if(v.at(i) != v.at(mini)) count++;
	}

	print_array(v);
	cout << count << endl;
}


Measured memory_bytes: 3100
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        long sum = 0;
        for(int i = 1; i <= N; i++) {
            if(i % 3 == 0 && i % 5 == 0) {
                continue;
            }else if(i % 3 == 0) {
                continue;
            }else if(i % 5 == 0) {
                continue;
            }else {
                sum += i;
            }
        }
        System.out.println(sum);
        
    }
}

Measured memory_bytes: 35740
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

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

    string copy(s);
    reverse(copy.begin(),copy.end());

    int count = 0;

    for (int i = 0; i < s.length(); ++i) {
        if (s[i] != copy[i]) count++;
        else continue;
    }

    cout << count / 2 << endl;

    return 0;
    
}

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

int ans[3001];

int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	int temp;
	
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			temp=min(j-i,abs(i-x)+abs(j-y)+1);
			ans[temp]++;
		}
	
	for(int i=1;i<n;i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
class union:
  def __init__(self, box):
    self.r = []
    for i in range(box):
      self.r.append(-1)
    
  def root(self, x):
    if self.r[x] < 0:
      return x
    self.r[x] = self.root(self.r[x])
    return self.r[x]

  def add(self, a):
    a[0] -= 1
    a[1] -= 1
    a[0] = self.root(a[0])
    a[1] = self.root(a[1])
    if a[0] == a[1]:
      return False
    if self.r[a[0]] > self.r[a[1]]:
      a[0], a[1] = a[1], a[0]
    self.r[a[0]] += self.r[a[1]]
    self.r[a[1]] = a[0]
    return True
  
  def size(self, x):
    return -self.r[x]

n, m = map(int, input().split())
uf = union(n)
ans = 0
for i in range(m):
  uf.add(list(map(int, input().split())))

for i in range(n):
  ans = max(ans, uf.size(i))
print(ans)


Measured memory_bytes: 14908
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  bool flag = false;
  int a,b; cin >> a >> b;
  for(int i=1;i<=1000;i++){
    if(i * 8 / 100 == a && i / 10 == b){
      flag = true;
      cout << i << endl;
      return 0;
    }
  }

  cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 256