akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

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

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

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

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[1000005];
char s[1000005];

int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	for(i=0;i<=100;i++){
		for(j=0;j<=100;j++){
			bool dame = false;
			c = 0;
			h = -1;
			for(k=0;k<n;k++){
				if(z[k] == 0)continue;
				if(c == 0){
					h = z[k] + abs(i-x[k]) + abs(j-y[k]);
					c = 1;
				}else{
					num = max(0ll,h-abs(i-x[k])-abs(j-y[k]));
					if(num != z[k]){
						dame = true;
						break;
					}
				}
			}
			for(k=0;k<n;k++){
				if(z[k] != 0)continue;
				num = max(0ll,h-abs(i-x[k])-abs(j-y[k]));
				if(num != z[k]){
					dame = true;
					break;
				}
			}
			if(!dame){
				pe(i);pe(j);p(h);
			}
		}
	}
	
	return 0;

}

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

#define ll long long
#define ld long double
#define ull unsigned long long

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

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

    ll n;
    cin >> n;
    ll sq = sqrt(n);
    ll res = to_string(n).size();
    for (int x = 1; x <= sq; ++x)
    {
        if (n % x != 0)
            continue;
        ll cur = max(to_string(x).size(), to_string(n / x).size());
        res = min(res, cur);
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end());
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, a, b, c, d, e, f);
    vector<int> w(961);
    For(i, 31) For(j, 31) w[i*31+j] = 100*(a*i + b*j);
    Sort(w);
    Unique(w);
    if(w[0] == 0) w.erase(w.begin());
    w.erase(upper_bound(Range(w), f), w.end());
    // Couts(w);
    
    vector<int> s;
    for(int i = 0; c*i <= e*f/100; i ++) for(int j = 0; c*i + d*j <= e*f/100; j ++) s.push_back(c*i + d*j);
    Sort(s);
    Unique(s);
    // Couts(s);
    
    int ansd = 100*a, ansn = 0;
    for(int we : w){
        int se = *(upper_bound(Range(s), min(we*e/100, f-we)) - 1);
        if(ansn*(we+se) < se*ansd) ansn = se, ansd = we+se;
    }
    Cout(ansd, " ", ansn);
}


Measured memory_bytes: 1404
let encode s =
  let n = String.length s in
  let rec doit i acc =
    if i = n - 1 then List.rev acc
    else if String.contains "aeiou" s.[i] then doit (i + 1) (s.[i+1] :: acc)
    else doit (i + 1) acc
  in
  doit 0 [s.[0]]

let rec dup_p = function
  | [] -> false
  | hd :: tl when List.mem hd tl -> true
  | _ :: tl -> dup_p tl

let solve n =
  let rec read i acc =
    if i = n then List.rev acc
    else read (i + 1) (encode (read_line ()) :: acc)
  in
  let l = List.sort compare (read 0 []) in
  if dup_p l then (-1)
  else
    let rec duduwa k = function
      | ([], _) -> k
      | (_, []) -> k
      | (x::_, y::_) when x <> y -> k
      | (_::xs, _::ys) -> duduwa (k + 1) (xs, ys)
    and doit k = function
      | [] -> k
      | [_] -> k
      | x :: (y :: _ as tl) -> doit (max k (duduwa 0 (x, y))) tl
    in
    1 + doit 0 l

let () =
  let rec doit () =
    let n = read_int () in
    if n <> 0 then (Printf.printf "%d\n" (solve n); doit ())
  in
  doit ()

Measured memory_bytes: 4424
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

// ????????????????????£?¨?
int prim(vector<vector<pair<int, int> > > adjlist, int v);

// ?????????
int main(void){
  while(true){
    // ???????????°??¨???????????°???????????????
    int n, m;
    cin >> n;
    if(n == 0){ break; }
    cin >> m;

    // ???????????±????????????????????£??\??????????????????
    vector<vector<pair<int, int> > > adjlist(n);
    for(int i = 0; i < m; i++){
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      adjlist[a].push_back(make_pair(d, b));
      adjlist[b].push_back(make_pair(d, a));
    }
  
    // ????°???¨?????¨????????????????±??????????????????????
    int length = prim(adjlist, n);
    cout << length / 100 - n + 1 << endl;
  }

  return 0;
}

// ????????????
// ?????°: ??£??\?????????(first: ???????????????, second: ????????????), ????????°
// ?????????: ??¨????????????
int prim(vector<vector<pair<int, int> > > adjlist, int v){
  priority_queue<pair<int, int> > mincost;  // ?????§???????????????????????¨?????§???????°??????????
  vector<bool> used(v, false);  // ??????i?????¨????????????????????????
  int length = 0;  // ??¨????????????

  // ???????????????
  mincost.push(make_pair(0, 0));
  while(!mincost.empty()){
    // ????£?????????????????°?????????????????????????
    int newmember = mincost.top().second;
    int newcost = -mincost.top().first;
    mincost.pop();
    if(used[newmember]){ continue; }

    // ???newmember?????¨?????????
    used[newmember] = true;
    length += newcost;

    // ???newmember????????\?¶???????????????????????????????????????? 
    for(int i = 0; i < adjlist[newmember].size(); i++){
      // ????????¨??????????????????????????????queue?????????
      if(!used[adjlist[newmember][i].second]){
        mincost.push(make_pair(-adjlist[newmember][i].first, adjlist[newmember][i].second));
      }
    }
  }
  
  return length;
}

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

using namespace std;
typedef long long ll;

ll N;
ll h[100001];
ll dp[100001];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=2;i<N;i++) dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]));
    cout << dp[N-1] << endl;
    return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n;
	cin >> n;
	vector<tuple<string, int, int>> info;
	while (n--) {
		string s;
		int score;
		cin >> s >> score;
		info.push_back(make_tuple(s, score, info.size() + 1));
	}
	sort(begin(info), end(info), [](tuple<string, int, int> x, tuple<string, int, int> y) -> bool {
		if (get<0>(x) != get<0>(y)) {
			return get<0>(x) < get<0>(y);
		}
		else {
			return get<1>(x) > get<1>(y);
		}
	});
	for (auto&& i : info) {
		cout << get<2>(i) << "\n";
	}
}


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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2017
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define maxn 100009
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;

int main()
{
    int jishu = 0,oushu = 0;
    LL num[maxn];
    for(int i=0;i<3;i++){
        cin>>num[i];
        if(num[i] & 1)
            jishu++;
        else
            oushu++;
    }
    sort(num,num+3);
    if(jishu == 3 || oushu == 3)
        cout<<(2 * num[2] - num[1] - num[0])/2<<endl;
    else if(jishu == 1)
    {
        for(int i=0;i<3;i++)
            if(!(num[i] & 1))
                num[i] += 1;
        cout<<(2 * num[2] - num[1] - num[0])/2 + 1<<endl;
    }
    else if(oushu == 1)
    {
        for(int i=0;i<3;i++)
            if(num[i] & 1)
                num[i] += 1;

        cout<<(2 * num[2] - num[1] - num[0])/2 + 1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

long long calc(long long n, long long k)
{
  long long ans = n % k;
  if (abs(ans - k) <= ans)
  {
    return abs(ans - k);
  }
  else
  {
    return ans;
  }
}

int main()
{
  long long n, k;
  cin >> n >> k;

  cout << calc(n, k);

  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;
 
int main(){
  int n;
  scanf("%d",&n);
  double base = 100000;
  for(int i=0;i<n;i++){
    base*=1.05;
    if((int)base %1000 !=0) {
      int tmp = (int)base / 1000;
      base = tmp*1000 + 1000;
    }
 
  }
  printf("%d\n",(int)base);
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <stdlib.h>

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

int main(void) {

    int a[201];
    int b[201];
    int N,count,flag;
    
    flag = 0;
    
   scanf("%d",&N);
    for(int i = 0;i < N ;i++){
        scanf("%d",&a[i]);
    }
    
    for(int i = 0;i < N ;i++){
        while(flag == 0){
            if(a[i] % 2 == 0){
                count++;
                a[i] = a[i] / 2;
            }else{
                flag = 1;
            }
       }
        b[i] = count;
        count = 0;
        flag = 0;
    }
    
    qsort(b, N, sizeof(int), asc);
        
    printf("%d",b[0]);    
	return 0;
}


Measured memory_bytes: 128
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=105;
int b[N],n,n2,n3;
LL a[N],ans,sum;
LL cal(LL sum){
    for (int i=n3+1;i<=n2;i++){
        if (b[i]) continue;
        LL cnt=a[i]+(b[i+i]?0ll:a[i+i]);
        sum-=min(cnt,0ll);
    }
    return sum;
}
void dfs(int i){
    if (i==n3+1) {ans=max(ans,cal(sum));return;}
    if (b[i]) {dfs(i+1);return;}
    for (int j=i;j<=n;j+=i) {if (!b[j]) sum-=a[j];b[j]++;}
    dfs(i+1);
    for (int j=i;j<=n;j+=i) {b[j]--;if (!b[j]) sum+=a[j];}
    dfs(i+1);
}
int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d",&n);n3=n/3,n2=n/2;
    for (int i=1;i<=n;i++) {scanf("%lld",&a[i]);b[i]=0;}
    if (n==1) {cout<<max(a[1],0ll)<<endl;return 0;}
    if (n==2) {cout<<max(max(a[1]+a[2],a[1]),0ll)<<endl;return 0;}
    for (int i=n;i>n2;i--) a[i]=max(a[i],0ll);
    for (int i=1;i<=n;i++) sum+=a[i];
    ans=0ll;dfs(1);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;
  std::vector<int> ds;
  for (int i = 0; i < n; ++i) {
    int d;
    std::cin >> d;
    ds.push_back(d);
  }
  int m;
  std::cin >> m;
  std::vector<int> ts;
  for (int i = 0; i < m; ++i) {
    int t;
    std::cin >> t;
    ts.push_back(t);
  }
  std::sort(ds.begin(), ds.end());
  std::sort(ts.begin(), ts.end());
  int pos = -1;
  for (int i = 0; i < m; ++i) {
    for (int j = pos; j < n; ++j) {
      if (ds[j] == ts[i]) {
        pos = j + 1;
        break;
      }
      if (j == n-1 && ds[j] != ts[i]) {
        std::cout << "NO" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "YES" << std::endl;
  return 0;
}
    
    


Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 100100;
long long n, use[N], m, a, b, cc, val[N];

vector <long long> st, c[3], cy;
vector <pair<long long, long long> > v[N];
map <pair<long long, long long> , long long> e;

bool dfs(long long node, long long par) {
	use[node] = par;
	c[par].push_back(node);
	st.push_back(node);
	
	for(auto i : v[node])
		if(!use[i.st]){
			if(dfs(i.st, 3 - par)) 
				return 1;
		}
		else if(use[i.st] == use[node]) {
			while(st.back() != i.st) {
				cy.push_back(st.back());
				st.pop_back();
			}
			cy.push_back(i.st);
			return 1;
		}

	st.pop_back();
	return 0;
}

void dfs2(long long node) {
	// dbg(node);
	use[node] = 1;
	for(auto i : v[node]) {
		if(!use[i.st]) {
			use[i.st] = 1;
			val[i.st] = i.nd - val[node];
			dfs2(i.st);
		} else if(val[i.st] + val[node] != i.nd) {
			cout << "0\n";
			exit(0);
		}
	}
}


int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	for(long long i = 1; i <= m; i++) {
		cin >> a >> b >> cc;
		v[a].push_back({b, cc});
		v[b].push_back({a, cc});
		e[{a, b}] = cc;
		e[{b, a}] = cc;
	}

	dfs(1, 1);
	int start = 1;
	// dbg(cy);
	if(cy.size()) {
		// dbg_ok;
		start = cy[0];
		cy.push_back(cy[0]);
		long long r = 0;
		for(int i = 0; i + 1 < cy.size(); i++)
			if(i % 2 == 0)
				r += e[{cy[i], cy[i + 1]}];
			else 
				r -= e[{cy[i], cy[i + 1]}];
		dbg(r);
		if(r % 2 == 1) return cout << "0\n", 0;
		val[start] = r / 2;
	} 
	
	memset(use, 0, sizeof use);
	use[start] = 1;
	dfs2(start);
	if(cy.size()) {
		for(int i = 1; i <= n; i++)
			if(val[i] <= 0)
				return cout << "0\n", 0;
		cout << "1\n";
		return 0;
	}
	else {
		// dbg(c[1], c[2]);
		// dbg_v(val, n + 1);
		long long mn1 = 1e17, mn2 = 1e17;
		for(auto i :c[1])
			mn1 = min(val[i], mn1);
		for(auto i :c[2])
			mn2 = min(val[i], mn2);
		cout << max(mn1 + mn2 - 1, 0LL) << '\n';
	}
}	

	

Measured memory_bytes: 31728
#include <stdio.h>
#include <stdlib.h>

void DrawRect(int h, int w)
{
	int i,j;
	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
		{
			if (i % 2 == 0)
			{
				if (j % 2 == 0)
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			else
			{
				if (j % 2 != 0)
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
		}
		printf("\n");
	}
	printf("\n");
}

int main(int argc, char *argv[])
{
	int H, W;
	while (1)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
		{
			break;
		}
		DrawRect(H, W);
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#define N 45
using namespace std;
int n,F[N];

int main(){
  cin>>n;
  F[0]=F[1]=1;
  for(int i=2;i<=n;i++)
    F[i]=F[i-1]+F[i-2];
  cout<<F[n]<<endl;
  return 0;
}

Measured memory_bytes: 1160
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

import bisect
from collections import deque
q = deque()
q.append(a[0])

for num in a[1:]:
    if num <= q[0]:
        q.appendleft(num)
    else:
        ind = bisect.bisect_left(q,num)
        ind-=1
        q[ind]=num

print(len(q))

Measured memory_bytes: 54360
import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
import numpy as np

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W = map(int, readline().split())
    L = list(list(map(int, readline().split())) for _ in range(10))
    A = list(list(map(int, readline().split())) for _ in range(H))
    dist = dijkstra(csr_matrix(L))
    ans = 0
    for a in A:
        for i in a:
            if i == -1:
                continue
            else:
                ans += dist[i][1]
    print(int(ans))




if __name__ == '__main__':
    main()


Measured memory_bytes: 38264
if __name__ == '__main__':
    import time
    START = time.time()
    LIMIT = START + 1.9

    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    from copy import deepcopy
    # import numpy as np
    from numpy import random as np_random
    # import math
    import random
    input = stdin.readline

    CONTEST_NUM = 26
    INFTY = 10**9

    D = int(input())
    cc = [0]+list(map(int, input().split()))
    ss = [[0]*(CONTEST_NUM+1) for _ in range(D)]
    for i in range(D):
        ss[i] = [0]+list(map(int, input().split()))

    last_day = [-1]*(CONTEST_NUM+1)
    content = 0

    def count_discontent(content, date):
        for contest in range(1, CONTEST_NUM+1):
            content -= cc[contest]*(date-last_day[contest])
        return content

    def greedy_decide_contest(date):
        point = -INFTY
        for contest in range(1, CONTEST_NUM+1):
            get_point = ss[date][contest]+cc[contest]*(date-last_day[contest])
            if get_point > point:
                point = get_point
                t = contest
        return t

    tt = [0]*D
    for date in range(D):
        # t = int(input())
        t = greedy_decide_contest(date)
        tt[date] = t
        content += ss[date][t]
        last_day[t] = date
        content = count_discontent(content, date)
        # print(t)

    best_content = content
    best_tt = deepcopy(tt)

    P = 0.1

    while time.time() <= LIMIT:
        content = 0
        tt = [0]*D
        for date in range(D):
            if np_random.binomial(1, P):
                t = random.randint(1, CONTEST_NUM)
            else:
                t = greedy_decide_contest(date)
            tt[date] = t
            content += ss[date][t]
            last_day[t] = date
            content = count_discontent(content, date)
        if content > best_content:
            best_content = content
            best_tt = deepcopy(tt)
    
    # print(best_content)

    for t in best_tt:
        print(int(t))    




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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

#define MAX_N 1000000
int memo[MAX_N+1];
int memo_odd[MAX_N+1];

int plc(int n) { return n * (n + 1) * (n + 2) / 6; }

void create_table() {
  fill(memo, memo+MAX_N+1, 1<<30);
  fill(memo_odd, memo_odd+MAX_N+1, 1<<30);
  for (int i = 1; plc(i) <= MAX_N+1; i++) {
    memo[plc(i)] = 1;
    if (plc(i) % 2 == 0) continue;
    memo_odd[plc(i)] = 1;
  }
  for (int i = 1; i <= MAX_N; i++) {
    for (int j = 1; plc(j) <= i; j++) {
      memo[i] = min(memo[i], memo[i-plc(j)] + 1);
      if (plc(j) % 2 == 0) continue;
      memo_odd[i] = min(memo_odd[i], memo_odd[i-plc(j)] + 1);
    }
  }
}

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n;
  create_table();
  while (cin >> n, n) {
    cout << memo[n] << " " << memo_odd[n] << endl;
  }
  return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

struct rangetree{
  int size;
  vector<vector<ll> > dat;
  rangetree(){}

  void init(vector<ll> nums){
    int n=nums.size();
    size=1;
    while(size<n)size*=2;
    dat.resize(size*2);

    for(int i=0;i<size*2;i++)dat[i].clear();

    for(int i=0;i<n;i++){
      dat[i+size-1].pb(nums[i]);
    }

    for(int i=size-2;i>=0;i--){
      int lc=i*2+1,rc=i*2+2;
      dat[i].resize(dat[lc].size()+dat[rc].size());
      merge(dat[lc].begin(),dat[lc].end(),dat[rc].begin(),dat[rc].end(),dat[i].begin());
    }
  }

  ll query(int a,int b,ll t,int k,int l,int r){
    if(b<=l||r<=a)return 0;
    if(a<=l&&r<=b){
      return upper_bound(dat[k].begin(),dat[k].end(),t)-dat[k].begin();
    }
    return query(a,b,t,k*2+1,l,(l+r)/2)+query(a,b,t,k*2+2,(l+r)/2,r);
  }

  ll query(int a,int b,ll t){
    return query(a,b,t,0,0,size);
  }
};

ll n,k;
ll a[211111];
rangetree rt;

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>k;
  vector<ll> s;
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    a[i]-=k;
    sum+=a[i];
    s.push_back(sum);
    //dbg(a[i]);
  }
  rt.init(s);
  ll base=0,res=0;
  rep(i,n){
    res+=(n-i)-rt.query(i,n,base-1);
    base+=a[i];
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 54768
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long A = scan.nextLong()*2;
        long B = scan.nextLong()*2;
        long C = scan.nextLong()*2;
        long D = scan.nextLong()*2;
        long diff = Math.abs(A-B);
        boolean found = false;
        long center = N % 2 == 0 ? (C+D)/2 : 0;
        long gap = (D-C)/2*(N-1);
        for (int i = 0; i < (N+1)/2; i++) {
            if (D * N < center - gap) {
                break;
            }
            if (center-gap <= diff && diff <= center + gap) {
                found = true;
                break;
            }
            center += C+D;
        }
        System.out.println(found?"YES":"NO");
    }
}


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	int n;
	cin >> n;
	cout << fixed << setprecision(11) << (double)(n / 2 + n % 2) / n << '\n';
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 



long long int dp[200200]={};


long long int N,A,B,C,K,S[200200],sum=0,mymax=0,mymin=INF;;
int main(){
    cout << fixed << setprecision(18);
    cin>>A>>B>>C>>K;
    if(K%2==0){
        cout<<A-B<<endl;
    }else{
        cout<<B-A<<endl;
    }
}


Measured memory_bytes: 256
from sys import stdin
n,m = map(int,stdin.readline().split())
ans = 1
x = 1
a = []
while x * x <=m:
 if m%x==0:
  a.append(x)
  a.append(m/x)
 x+=1
for i in a:
 if m/i >= n:
  ans = max(ans,i)
print ans

Measured memory_bytes: 2568
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int k, x;
    cin >> k >> x;

    if(k*500 >=x ) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <bits/stdc++.h>
#define mst(a) memset(a,0,sizeof(a))
#define rev(a) reverse(a,a+strlen(a))
using namespace std;
typedef long long ll;
int main()
{
   int k,j=0,o=0;
   cin>>k;
   for(int i=1;i<=k;i++){
    if(i%2==0) o++;
    else j++;
   }
   cout<<j*o<<endl;
   return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a, b, c, d, k;
bool ok(int mid){
    int A = a, B = b;
    int an = (mid - 1) / k + 1;
    if(mid == 0) an = 0;
    A -= mid;
    B -= an;
    if(B < 0) return 0;
    if(B <= k - 1 || 1LL * A * k >= B) return 1;
    return 0;
}
int q;
int main(){
//    freopen("in.txt", "r", stdin);
    //freopen("myout.txt", "w", stdout);
    scanf("%d", &q);
    for(int i = 1; i <= q; ++i){
        scanf("%d%d%d%d", &a, &b, &c, &d);
        k = (max(a, b) - 1) / (min(a, b) + 1) + 1;
        if(1LL * a * k < b){
            for(int i = c; i <= d; ++i)
                putchar((a + b - i + 1) % (k + 1) == 0 ? 'A' : 'B');
            puts("");
            continue;
        }
        //cout << k << endl;
        int l = 0, r = a;
        while(l <= r){
            int mid = (l + r) / 2;
            if(ok(mid)) l = mid + 1;
            else r = mid - 1;
        }
        //cout << r << endl;
int A = a, B = b;
        int an = (r - 1) / k + 1;
        if(r == 0) an = 0;
A -= r;
B -= an;
++B;
int L = r + an;
if(r % k && 1LL * A * k >= B) --L;

        int R = a + b - L;
        for(int i = c; i <= min(L, d); ++i)
            putchar(i % (k + 1) == 0 || i == L && L == r + an ? 'B' : 'A');
        if(b == an) for(int i = max(L + 1, c); i <= d; ++i) putchar('A');
        else for(int i = max(L + 1, c); i <= d; ++i)
            putchar((i == L + 1 && r < a) || (a + b - i + 1) % (k + 1) == 0 ? 'A' : 'B');
        puts("");
    }
    return 0;
}
/*
4 6 1 10
7 6 1 13
*/



//
//
//#include<cstdio>
//#include<algorithm>
//using namespace std;
//int T,k,n,a,b,c,d;
//int main(){
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//	scanf("%d",&T);
//	while(T--){
//		scanf("%d%d%d%d",&a,&b,&c,&d);n=a+b;
//		int l=0,r=n+1,mid,A,B;k=(max(a,b)-1)/(min(a,b)+1)+1;
//		while(l<r){
//			mid=(l+r)>>1;
//			A=a-mid/(k+1)*k-mid%(k+1);B=b-mid/(k+1);
//			if(B<=1ll*A*k)l=mid+1;else r=mid;
//		}
//		A=a-l/(k+1)*k-l%(k+1);B=b-l/(k+1);r=l+B-A*k+1;
//		for(int i=c;i<=min(d,l);i++)putchar(i%(k+1)?'A':'B');
//		for(int i=max(c,l+1);i<=d;i++)putchar((i-r)%(k+1)?'B':'A');
//		puts("");
//	}
//	return 0;
//}//ONION_CYC QwQ


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long cost[200007];
const long long cst=INT_MAX;
vector<pair<int,long long> > edge[200007];
void dfs(int u, int pre, int c)
{
    cost[u]=c;
    for(int i=0;i<edge[u].size();i++){
        int v=edge[u][i].first;
        if(cost[v]==cst)
            dfs(v,u,c+edge[u][i].second);
        else{
            if(c+edge[u][i].second!=cost[v]){
                cout<<"No"<<endl;
                exit(0);
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;

    while(m--){
        long long li,ri,di;
        cin>>li>>ri>>di;
        edge[li].push_back(make_pair(ri,di));
        edge[ri].push_back(make_pair(li,-di));
    }
    fill(cost,cost+n+5,cst);
    for(int i=1;i<=n;i++){
        if(cost[i]==cst){
            dfs(i,-1,0);
        }
    }
    cout<<"Yes"<<endl;

    return 0;
}


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

using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);

  for(int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(),A.end());

  for(int i = 0; i < N - 1; i++){
    if(A[i] == A[i + 1]){ cout << "NO"; return 0; }

  }

  cout << "YES";
 return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1);
const ll mod=1e9+7;
char s[200500];
ll s1[2019];
ll a[2019];
int main()
{
	
	cin>>s;
	int n=strlen(s);
	ll sum=0;
	int tem;
	for(int i=0;i<n;i++)
	{
		tem=s[i]-'0';
		a[tem]=1;
		for(int j=0;j<2019;j++)
		{
			if(s1[j]!=0)
			{
			    a[(j*10+tem)%2019]+=s1[j];	
			}
		}
		memcpy(s1,a,sizeof(a));
		memset(a,0,sizeof(a)); 
		sum+=s1[0];
	}
	cout<<sum<<endl;
	
	return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int a,b,c;
	cin >> a >> b >> c;

	if(a == b)
		cout << c << endl;
	else if(a==c)
		cout << b << endl;
	else
		cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] h = new int[N+1];
    for(int i = 1; i <= N; i++) h[i] = sc.nextInt();
    int[] dp = new int[N+1];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = Math.abs(h[2] - h[1]);
    for(int i = 3; i <= N; i++) {
      dp[i] = Math.min(dp[i-1] + Math.abs(h[i] - h[i-1]), dp[i-2] + Math.abs(h[i] - h[i-2]));
    }
    System.out.println(dp[N]);
  }
}


Measured memory_bytes: 48944
a=int(input())
l=[]
if a==0:
  print(a)
else:
  while a!=1:
    if a<0:
      l.append(abs(a)%2)
      if abs(a)%2==1:
        a=abs(a-1)//2
      else:
        a=abs(a)//2
    elif a>0:
      l.append(a%2)
      a=-(a//2)
  l.append(a)
  s=""
  for i in range(1,1+len(l)):
    s+=str(l[-i])
  print(s)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * b / 2 << endl;
}

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

namespace AtTest.ABC_140
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            WriteLine(n * n * n);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
    ll K;
    cin >> K;
    ll res = 0;
    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= K; j++) {
            ll g = gcd(i, j);
            for(int k = 1; k <= K; k++) {
                res += gcd(g, k);
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define MAX_N 100000
int n, a[MAX_N][3];
int dp[MAX_N][3];

int rec(int i, int j) {
    if (dp[i][j]) return dp[i][j];
    if (i == 0) return a[0][j];
    int res = 0;
    rep(k, 3) {
        if (k != j) {
            res = max(res, rec(i - 1, k));
        }
    }
    return dp[i][j] = res + a[i][j];
}

int main() {
    cin >> n;
    rep(i, n) { cin >> a[i][0] >> a[i][1] >> a[i][2]; }
    cout << max({rec(n - 1, 0), rec(n - 1, 1), rec(n - 1, 2)}) << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <stdio.h>

int A[200000];

void Do(int N){
  int i, M1, M2, t;
  M1 = 0;
  M2 = 0;
  for(i = 0;i < N;i++){
    scanf("%d", &A[i]);
    if(A[i] > M2){
      M2 = A[i];
      if(M2 > M1){
	t = M1;
	M1 = M2;
	M2 = t;
      }
    }
  }
  for(i = 0;i < N;i++){
    if(M1 == A[i]) printf("%d\n", M2);
    else printf("%d\n", M1);
  }
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


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

signed main(){
	int A, B;
	cin >> A >> B;
	if(A==1){
		if(B==1) cout << "Draw\n";
		else cout << "Alice\n";
	}else if(B==1){
		if(A==1) cout << "Draw\n";
		else cout << "Bob\n";
	}else{
		if(A>B) cout << "Alice\n";
		else if(A<B) cout << "Bob\n";
		else if(A==B) cout << "Draw";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
	long long int m,n,ans=0,sum=0,a[200009];
	string s;
	float big;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	big=float(sum)/float(4*m);
	// cout<<big<<" ";
	sort(a,a+n);
	for(int i=n-1;i>=n-m;i--)
	{
		if(a[i]<big)
			ans=1;
	}
	if(ans==1)
		cout<<"No";
	else
		cout<<"Yes";
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BRACK 2

void visit(int);

int array[MAX][MAX], road_color[MAX] ,arr1[MAX], arr2[MAX];
int n, vst=0;

int main(){
  int num1, num2, num3, i, j;

  scanf("%d", &n);

  for( i=0; i<n; i++){
    for( j=0; j<n; j++){
      array[i][j] = 0;
    }
  }

  for( i=0; i<n; i++){
    scanf("%d %d", &num1, &num2);
    num1--;

    for( j=0; j<num2; j++){
      scanf("%d", &num3);
      num3--;

      array[num1][num3] = 1;
    }
  }

  for( i=0; i<n; i++){
    road_color[i] = WHITE;
  }

  for( i=0; i<n; i++){
    if( road_color[i] == WHITE )visit(i);
  }

  for( i=0; i<n; i++){
    printf("%d %d %d\n", i+1, arr1[i], arr2[i]);
  }

  return 0;
}

void visit(int u ){
  int i;

  road_color[u] = GRAY;

  arr1[u] = ++vst;

  for( i=0; i<n; i++){
    if( array[u][i] == 0 )continue;

    if( road_color[i] == WHITE )visit(i);
  
  }
    road_color[i] = BRACK;

    arr2[u] = ++vst;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

struct Combination {
    vector<lint> fac, finv, inv;
    Combination(lint maxN) : fac(maxN + 100), finv(maxN + 100), inv(maxN + 100) {
        maxN += 100; // for safety
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1]            = 1;
        for (lint i = 2; i <= maxN; ++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;
        }
    }
    lint operator()(lint n, lint k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    Combination nCk(400000);
    if (n - 1 <= k) {
        cout << nCk(n - 1 + n, n) << "\n";
        return 0;
    }
    lint ret = 1;
    for (int i = 1; i <= k; ++i) {
        ret = (ret + nCk(n, i) * nCk(n - 1, i) % mod) % mod;
    }
    cout << ret << "\n";
    return 0;
}

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }

ll solve(ll hp,ll c){
  if (hp == 1) return c + 1;
  return 2 * solve(hp / 2, c) + 1;
}

int main() {
  ll H;
  scanf("%lld", &H);
  ll ans = solve(H, 0);

  printf("%lld", ans);
  return 0;
}

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

int main() {
  int k, n;
  cin >> k >> n;

  vector<int> a(n);
  for(int i = 0; i < n; i++) {
      cin >> a.at(i) ;
  }

	sort(a.begin(), a.end());
	a.push_back(a.at(0) + k);
	int max_length = 0;
	for(int i = 1; i <= n; i++) {
		int x, y;
		x = a.at(i);
		y = a.at(i -1);
		//if ((x - y) < 0) x += k;
  	if ((x - y) > max_length) 
			max_length = a.at(i) - a.at(i - 1);
  }

	cout << (k - max_length) << endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    long long N,i,a,b,c,ans,mod;
    mod=1e9+7;
    cin>>N;
    long long A[N];
    for(i=0;i<N;i++){
        cin>>A[i];
    }
    a=0;b=0;c=0;ans=1;
    for(i=0;i<N;i++){
        if(a==b&&b==c){
            if(A[i]==a){
                ans=(ans*3)%mod;
                a++;
            }else{
                ans=0;
            }
        }else if(a!=b&&b!=c&&c!=a){
            if(A[i]==a){
                a++;
            }else if(A[i]==b){
                b++;
            }else if(A[i]==c){
                c++;
            }else{
                ans=0;
            }
        }else{
            if(a==b){
                if(A[i]==a){
                    ans=(ans*2)%mod;
                    a++;
                }else if(A[i]==c){
                    c++;
                }else{
                    ans=0;
                }
            }else if(b==c){
                if(A[i]==b){
                    ans=(ans*2)%mod;
                    b++;
                }else if(A[i]==a){
                    a++;
                }else{
                    ans=0;
                }
            }else if(c==a){
                if(A[i]==c){
                    ans=(ans*2)%mod;
                    c++;
                }else if(A[i]==b){
                    b++;
                }else{
                    ans=0;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,A,B;
  cin >> N >> A >> B;
  int sum = 0;
  if(A==1&&N==10000)
  {
    sum += 10000;
  }
  for(int i=0;i<10;i++)
  {
    for(int j=0;j<10;j++)
    {
      for(int k=0;k<10;k++)
      {
        for(int l=0;l<10;l++)
        {
          if(i+j+k+l<=B&&i+k+j+l>=A&&1000*i+100*j+10*k+l<=N)
          {
            sum += 1000*i+100*j+10*k+l;
          }
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256