akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] a = new long[n];

        long cnt = 0;

        for (int i = 0; i < n; i++) {
            long num = sc.nextLong();
            a[i] = num;
            if (num < 0) {
                cnt++;
            }
        }

        sc.close();

        long ans = 0;

        if (cnt % 2 == 0) {
            for (int i = 0; i < n; i++) {
                ans += Math.abs(a[i]);
            }
        } else {
            long min = Long.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                ans += Math.abs(a[i]);
                min = Math.min(Math.abs(a[i]), min);
            }
            ans -= 2 * min;
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 50480
N,X = map(int, raw_input().split())
A = [0]*N
B = [0]*N
A[0] = 1
B[0] = 1
for i in range(1,N):
  A[i] = 2*A[i-1]+3
  B[i] = 2*B[i-1]+1

def f(N,X):
  if N==0:
    return 1
  if X<=1:
    return 0
  if X<=1+A[N-1]:
    return f(N-1, X-1)
  if X<=1+A[N-1]+1:
    return B[N-1]+1
  if X<=1+A[N-1]+1+A[N-1]:
    return B[N-1]+1+f(N-1, X-2-A[N-1])
  if X<=1+A[N-1]+1+A[N-1]+1:
    return 2*B[N-1]+1
  print N,X

print f(N,X)


Measured memory_bytes: 2696
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    string s;
    cin>>s;
    a--,b--,c--,d--;
    REP(i,a,max(c,d)-1){
        if(s[i]=='#'&&s[i+1]=='#'){
            cout<<"No"<<endl;
            return;
        }
    }
    if(d<c){
        bool f=false;
        REP(i,b,d){
            if((s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.')){
                f=true;
                break;
            }
        }
        if(!f){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 592
[N,K]=map(int, raw_input().split())
C=[[] for i in range(11)]
D=[[0 for j in range(N+1)] for i in range(11)]
M=[0 for i in range(11)]

for i in range(N):
    c,g=map(int, raw_input().split())
    C[g].append(c)
    M[g]+=1
for i in range(1,11):
    y=sorted(C[i], reverse=True)
    for j in range(len(y)):
        n = j+1
        D[i][n] =y[j] + D[i][n-1] + 2*(n-1)

DP=[[0 for i in range(K+1)] for j in range(11)]

for g in range(1,11):
    for k in range(K+1):
        DP[g][k] = max( [ DP[g-1][k-x] + D[g][x] for x in range(min( k+1, M[g]+1 ) ) ] + [0] )
print DP[10][K]



Measured memory_bytes: 5612
import sys
import numpy as np
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(input().strip()) for _ in range(H)]
a = [ai for ai in a if "#" in ai]
H = len(a)
a_T = np.array(a).T
a_T = [ai for ai in a_T if "#" in ai]
a = np.array(a_T).T
W = len(a[0])
for i in range(H):
    for j in range(W):
        print(a[i][j],end="")
    print("")

Measured memory_bytes: 13928
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();

		// CとDの最大公約数
		long gcd = gcd(C, D);
		// CとDの最小公倍数
		long lcm = (C * D) / gcd;
		// System.out.println("gcd=" + gcd + " lcm=" + lcm);

		// B以下のCまたはDで割り切れる個数からCとDで割り切れる重複個数を引く
		// B以下の割り切れる個数を求める
		long bCnt = (B / C) + (B / D) - (B / lcm);
		
		// A未満のCまたはDで割り切れる個数からCとDで割り切れる重複個数を引く
		// A未満の割り切れる個数が求められる
		long a = A - 1;
		long aCnt = (a / C) + (a / D) - (a / lcm);
		// System.out.println("bCnt=" + bCnt + " aCnt=" + aCnt);

		// BからB以下の割り切る個数を引く = B以下の割れない個数
		// A未満の割り切れる個数を引く = A未満の割れない個数
		// B以下の割れない個数からA未満の割れない個数を引く
		System.out.println((B - bCnt) - (a - aCnt));
	}

	// 最大公約数
    public static long gcd(long x, long y) {
        // System.out.println("x = " + x + " y = " + y);
		return y == 0 ? x : gcd(y, x % y);
	}
}


Measured memory_bytes: 23636
import numpy as np

def solve(H, W, M, h, w):
    f = [0] * (H+1)
    g = [0] * (W+1)
    for r, c in zip(h, w):
        f[r] += 1
        g[c] += 1
    p = np.max(f)
    q = np.max(g)
    num = len(list(filter(p.__eq__, f))) * len(list(filter(q.__eq__, g)))
    for r, c in zip(h, w):
        if (f[r] == p) and (g[c] == q):
            num -= 1
    return p + q - (num <= 0)

H, W, M = map(int, input().split())
h, w = zip(*[map(int, input().split()) for i in range(M)])
print(solve(H, W, M, h, w))

Measured memory_bytes: 183620
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int answer = -1;
    for(int i = 0;i < 10000;i++){
      int x1 = (int)(i * 0.08);
      int x2 = (int)(i * 0.1);
      if(x1 == A){
        if(x2 == B){
          answer = i;
          break;
        }
      }
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 22740
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h, w, k, i, j, ans = 0, k1, l;
    cin >> h >> w >> k1;
    string s[h];
    for(i = 0; i < h; i++) {
    	cin >> s[i];
    }
    for(i = 0; i < ((ll)1 << h); i++) {
    	for(j = 0; j < ((ll) 1 << w); j++) {
    		ll cur = 0;
    		string temp[h];
    		for(k = 0; k < h; k++) {
    			temp[k] = s[k];
    		}
    		for(k = 0; k < h; k++) {
    			for(l = 0; l < w; l++) {
    				if((i & (1 << k)) || (j & (1 << l))) {
    					temp[k][l] = '@';
    				}
    				if(temp[k][l] == '#') {
    					cur++;
    				}
    			}
    		}
    		if(cur == k1) {
    			ans++;
    		}
    	}
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    ll sl = len(s);
    if (s[0] == s[sl - 1]) {
        if (sl % 2 == 1) printf("Second\n");
        else printf("First\n");
    }
    else {
        if (sl % 2 == 0) printf("Second\n");
        else printf("First\n");
    }
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>

int main()
{
	long long a, b, r=1, temp;
	long long A, B;

	std::cin >> a >> b;

	A = a; B = b;

	if (a < b)
	{
		temp = a;
		a = b;
		b = temp;
	}


	while (r != 0)
	{
		r = a % b;
		a = a / b;
		a = b;
		b = r;
	}


	std::cout << A*B/a << std::endl;
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a = new int[5];
        int ans = 0;
        
        for(int i=0; i<5; i++){
            a[i] = sc.nextInt();
            if(a[i] == 0){
                ans = i+1;
            }
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 35604
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    int cnt = 1;
    rep(i, n){
        int x;
        cin >> x;
        if(x % 2 == 0){
            cnt *= 2;
        }
    }

    int ans = 1;
    rep(i, n) ans *= 3;
    cout << ans - cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int X[n];
    for (int i = 0;i<n;i++){
        cin>>X[i];
    }
    int Y[m];
    for (int i = 0;i<m;i++){
        cin>>Y[i];
    }
    sort(X,X+n);
    sort(Y,Y+m);
    int z = min(Y[0],y);
    if (X[n-1]<z && x<z){
        cout<<"No War";
    }
    else{
        cout<<"War";
    }

    
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define Maxn 100007
using namespace std;
int n,x[Maxn],y[Maxn],cnt=0;
pair<int,int>p1[Maxn],p2[Maxn];
int last[Maxn],pre[Maxn*10],other[Maxn*10],dis[Maxn*10];
bool vis[Maxn];
int que[Maxn];
set<pair<int,int> >st;
set<pair<int,int> >::iterator it;
void insert(int u,int v,int len)
{
	other[++cnt]=v,pre[cnt]=last[u],last[u]=cnt;
	dis[cnt]=len;
	other[++cnt]=u,pre[cnt]=last[v],last[v]=cnt;
	dis[cnt]=len;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	for (int i=1;i<=n;i++)
	{
		p1[i]=make_pair(x[i],i);
		p2[i]=make_pair(y[i],i);
	}
	memset(last,0,sizeof(last));
	sort(p1+1,p1+n+1);
	sort(p2+1,p2+n+1);
	for (int i=1;i<n;i++)
		insert(p1[i].second,p1[i+1].second,abs(p1[i].first-p1[i+1].first));
	for (int i=1;i<n;i++)
		insert(p2[i].second,p2[i+1].second,abs(p2[i].first-p2[i+1].first));
	memset(vis,false,sizeof(vis));
	long long ans=0;
	vis[1]=true;
	memset(que,0,sizeof(que));
	int lx=0,rx=1;
	que[1]=1;
	int t=1;
	st.clear();
	for (int i=1;i<n;i++)
	{
		for (int q=last[t];q;q=pre[q])
		{
			int v=other[q];
			if (!vis[v])
			{
				st.insert(make_pair(dis[q],v));
			}
		}
		it=st.begin();
		while (vis[(*it).second])
		{
			st.erase(it);
			it=st.begin();
		}
		t=(*it).second;
		vis[t]=true;
		que[++rx]=t;
		ans+=(*it).first;
		st.erase(it);
		++lx;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 17792
#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;
const long long INF = 1LL << 60;
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;
  cin >> N;
  if(N>=400&&N<600)
  {
    cout << 8 << endl;
  }
  else if(N>=600&&N<800)
  {
    cout << 7 << endl;
  }
  else if(N>=800&&N<1000)
  {
    cout << 6 << endl;
  }
  else if(N>=1000&&N<1200)
  {
    cout << 5 << endl;
  }
  else if(N>=1200&&N<1400)
  {
    cout << 4 << endl;
  }
  else if(N>=1400&&N<1600)
  {
    cout << 3 << endl;
  }
  else if(N>=1600&&N<1800)
  {
    cout << 2 << endl;
  }
  else if(N>=1800&&N<2000)
  {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
typedef struct{
    int x;
    int y;
}set;
int main()
{   int h,w;
    scanf("%d%d",&h,&w);
    char a[h][w+1];
    for(int i=0;i<h;i++){
        scanf("%s",a[i]);
    }
    set pos;
    pos.x=0;
    pos.y=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i==0&&j==0)continue;
            if(a[i][j]=='#'){
                if((pos.x==j-1&&pos.y==i)||(pos.x==j&&pos.y==i-1)){
                    pos.y=i;
                    pos.x=j;
                    //printf("(%d,%d)\n",pos.x,pos.y);
                    continue;
                }else{
                    printf("Impossible");
                    return 0;
                }
            }
        }
    }
    printf("Possible");

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ull unsigned long long
#define lli long long int
#define pb push_back
#define all(x) x.begin(),x.end()
ll mob=1000000007;
using namespace std;
int main()
{ 
ll a,b,n;
cin>>a>>b>>n;
if(n<b)
{
    ll r =floor((a*n)/b)-a*floor(n/b);cout<<r;
}
else if(n>=b)
{
    ll r=floor((a*(b-1))/b)-a*floor((b-1)/b);cout<<r;
}
 
 



return 0;
}











Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 2e5;

int n;
char s[maxn + 1];

int top;
char stk[maxn + 1];

int main(void) {
  scanf("%s", s);
  n = strlen(s);
  top = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'T') {
      if (top && stk[top - 1] == 'S') {
        --top;
      } else {
        stk[top++] = 'T';
      }
    } else {
      stk[top++] = 'S';
    }
  }
  printf("%d\n", top);
}


Measured memory_bytes: 512
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a, b, c[173333], sum[173333];
int main() {
	cin >> n;
	long long s = 0;
	for (int i = 0; i < n; i++) {
		cin >> a >> b; s += a;
		c[s % 86400]++;
		c[s % 86400 + 86400]++;
		s += b;
	}
	for (int i = 0; i < 172800; i++) sum[i + 1] = sum[i] + c[i];
	int ret = 0;
	for (int i = 0; i < 86400; i++) ret = max(ret, sum[i + 10801] - sum[i]);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
string d;
int len;
ll dp[15][150];
ll tenval[15];
int sum=0;
ll prod=1;
map<PP,ll> mp;

ll dfs(int v,int nsum,ll nowp,int flag){
	if(nsum>sum || nsum+(len-v)*9<sum)return 0;
	if(v==len){
		if(nowp<prod)return 1;
		if(nowp==prod && flag==2)return 1;
		return 0;
	}
	if(flag==2 && nowp*tenval[v]<=prod){
		return dp[len-v][sum-nsum];
	}
	if(flag<=1 && nowp*tenval[v]<prod){
		return dp[len-v][sum-nsum];
	}
	if(mp.find(PP(P(v,nsum),P(nowp,flag)))!=mp.end()){
		return mp[PP(P(v,nsum),P(nowp,flag))];
	}
	ll tp=0;
	for(int i=0;i<=9;i++){
		if((ll)nowp*i>prod)break;
		int nv=flag;
		if(flag==0){
			if(i>(d[v]-'0'))nv=1;
			if(i<(d[v]-'0'))nv=2;
		}
		tp+=dfs(v+1,nsum+i,(ll)nowp*(i+1),nv);
	}
	return mp[PP(P(v,nsum),P(nowp,flag))]=tp;
}

int main(void){
	cin >> d;
	ll ans=0;
	len=d.size();
	for(int i=0;i<len;i++){
		sum+=(d[i]-'0');
		prod=(ll)prod*((d[i]-'0')+1);
	}
	dp[0][0]=1;
	for(int i=0;i<len;i++){
		for(int j=0;j<=i*10;j++){
			for(int k=0;k<=9;k++){
				dp[i+1][j+k]+=dp[i][j];
			}
		}
	}
	for(int i=0;i<sum;i++){
		ans+=dp[len][i];
	}
	tenval[len]=1;
	for(int i=len-1;i>=0;i--){
		tenval[i]=tenval[i+1]*10LL;
	}
	ans+=dfs(0,0,1,0);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 25372
use std::cmp;
use std::collections::BTreeMap;

const MOD: usize = 1e9 as usize + 7;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner(s.lock());

    let x: usize = sc.read();
    let y: usize = sc.read();

    let combination = Combination::new(2e6 as usize, MOD);
    let mut ans = 0;
    for x1_count in 0..(x + 1) {
        let remain_x = x - x1_count;
        if remain_x % 2 != 0 {
            continue;
        }
        let x2_count = remain_x / 2;
        if x1_count * 2 + x2_count == y {
            ans += combination.get(x1_count + x2_count, x1_count);
            ans %= MOD;
        }
    }
    println!("{}", ans);
}
pub struct Combination {
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
    modulo: usize,
}

impl Combination {
    pub fn new(max: usize, modulo: usize) -> Combination {
        let mut inv = vec![0; max + 1];
        let mut fact = vec![0; max + 1];
        let mut inv_fact = vec![0; max + 1];
        inv[1] = 1;
        for i in 2..(max + 1) {
            inv[i] = inv[modulo % i] * (modulo - modulo / i) % modulo;
        }
        fact[0] = 1;
        inv_fact[0] = 1;
        for i in 0..max {
            fact[i + 1] = fact[i] * (i + 1) % modulo;
        }
        for i in 0..max {
            inv_fact[i + 1] = inv_fact[i] * inv[i + 1] % modulo;
        }
        Combination {
            fact: fact,
            inv_fact: inv_fact,
            modulo: modulo,
        }
    }

    pub fn get(&self, x: usize, y: usize) -> usize {
        assert!(x >= y);
        self.fact[x] * self.inv_fact[y] % self.modulo * self.inv_fact[x - y] % self.modulo
    }

    pub fn h(&self, n: usize, r: usize) -> usize {
        self.get(n + r - 1, r)
    }
}

pub struct Scanner<R>(R);

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 53500
x,y = map(int, input().split())
  

if 1 <= x <= 100 and 1 <= y <= 100:
  for a in range(0, 100, 1):
    if ( 2 * (x-a) + 4 * a == y and  a <= x ):
      print('Yes')
      exit()

  print('No')
else:
  print('No')

Measured memory_bytes: 9184
#include<stdio.h>
#include<stack>

#define MAX 100

enum SATE {
    NOT_VISIT,
    DISCOVER,
    FOUND
};

int G[MAX+1][MAX+1], d[MAX+1], f[MAX+1], STATE[MAX+1];
int n, tt;
std::stack<int> S;

void dfs(int i) {
    S.push(i);
    STATE[i] = DISCOVER;
    d[i] = ++tt;

    for (int j = 1; j <= n; ++j) {
        if (G[i][j] != 1 || STATE[j] != NOT_VISIT) continue;
        dfs(j);
    }
    STATE[i] = FOUND;
    f[i] = ++tt;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        d[i] = f[i] = 0;
        STATE[i] = NOT_VISIT;
        for (int j = 1; j <= n; ++j) {
            G[i][j] = 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            int t;
            scanf("%d", &t);
            G[u][t] = 1;
        }
    }

    tt = 0;
    for (int i = 1; i <= n; ++i) {
        if (STATE[i] == NOT_VISIT) dfs(i);
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }

}

Measured memory_bytes: 2756
import sys
import copy

sys.setrecursionlimit(10**6)

m = [0,2,5,5,4,5,6,3,7,6]

def a_le_b(a, b):
    la, lb = len(a), len(b)
    if la == lb:
        for i in range(la):
            if a[i] < b[i]:
                return True
            elif a[i] > b[i]:
                return False
        return True
    return la < lb

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(len(A)-1, 0, -1):
    for j in range(i-1, -1, -1):
        if m[A[i]] == m[A[j]]:
            del A[i]
            break
# print(A)
dp = [[] for _ in range(N+1)]

for i in range(N):
    if len(dp[i])==0 and i != 0: continue
    x = copy.copy(dp[i]) + [0]
    # print(x)
    for j in range(len(A)):
        ind = i + m[A[j]]
        if ind <= N:
            x[-1] = A[j]
            if a_le_b(dp[ind], x):
                dp[ind] = copy.copy(x)
# print(dp)
print(''.join(map(str, dp[-1])))


Measured memory_bytes: 245128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
using plli = pair<long long, int>;
plli tr[maxn<<2];
plli operator + (plli a, plli b){
  if(a.first < b.first) return a;
  return b;
}
void Create(){
  for(int i = 0; i < maxn<<2; i++) tr[i] = make_pair(1ll<<62, -1);
}
void update(int id, int l, int r, int p, long long x, int wx){
  if(l == r){
    if(tr[id].first > x) tr[id] = make_pair(x, wx);
  } else {
    int mid = (l+r)/2;
    if(p <= mid) update(id<<1, l, mid, p, x, wx);
    else update(id<<1|1, mid+1, r, p, x, wx);
    tr[id] = tr[id<<1] + tr[id<<1|1];
  }
}
plli get(int id, int l, int r, int x, int y){
  if(l > y || r < x) return make_pair(1ll<<62, -1);
  if(x <= l && r <= y) return tr[id];
  int mid = (l + r)/2;
  return get(id<<1, l, mid, x, y) + get(id<<1|1, mid + 1, r, x, y);
}
int u[maxn], who[maxn];
long long best[maxn];
void init(){
  for(int i = 0; i < maxn; i++) u[i] = i;
}
void Setup(){
  for(int i = 0; i < maxn; i++) best[i] = 1ll<<62, who[i] = -1;
}
int find(int x){
  if(x == u[x]) return x;
  return u[x] = find(u[x]);
}
int main(){
  int n; long long d; cin >> n >> d;
  vector<int> a(n); for(int & i : a) cin >> i;
  init();
  int comp = n;
  long long ans = 0;
  while(comp != 1){
    Setup();
    Create();
    for(int i = 0; i < n; i++){
      int id = find(i);
      plli myR = make_pair(1ll<<62, -1);
      if(id) myR = myR + get(1, 0, n, 0, id - 1);
      myR = myR + get(1, 0, n, id + 1, n);
      long long realCost = d * i + a[i] + myR.first;
      if(best[id] > realCost){
        best[id] = realCost;
        who[id] = myR.second;
      }
      update(1, 0, n, id, -d * i + a[i], i);
    }
    Create();
    for(int i = n-1; i >= 0; i--){
      int id = find(i);
      plli myR = make_pair(1ll<<62, -1);
      if(id) myR = myR + get(1, 0, n, 0, id - 1);
      myR = myR + get(1, 0, n, id + 1, n);
      long long realCost = -d * i + a[i] + myR.first;
      if(best[id] > realCost){
        best[id] = realCost;
        who[id] = myR.second;
      }
      update(1, 0, n, id, d * i + a[i], i);
    }
    for(int i = 0; i < n; i++) if(who[i] != -1){
      int id = find(i), idWho = find(who[i]);
      if(id != idWho){
        ans += best[id];
        comp--;
        u[id] = idWho;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
  

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

struct UnionFind{
    int ElementCount[100000],Adress[100001];
    void unite(int a ,int b){
        if (!is_Linked(a) && !is_Linked(b)) {
            ElementCount[a] = 2;
            Adress[a] = Adress[b] = a;
        } else if (!is_Linked(a)) {
            int b_root = find(b);
            ElementCount[b_root]++;
            Adress[a] = b_root;
        } else if (!is_Linked(b)) {
            int a_root = find(a);
            ElementCount[a_root]++;
            Adress[b] = a_root;
        } else {
            int a_root = find(a),b_root = find(b);
            if (a_root != b_root) {
                ElementCount[a_root] += ElementCount[b_root];
                Adress[b_root] = a_root;
            }
        }
    }
    int find(int a) {
        if (a == Adress[a]) return a;
        else {
            Adress[a] = find(Adress[a]);
            return Adress[a];
        }
    }
    int size(int a) {
        int root = find(a);
        return ElementCount[root];
    }
    bool is_Linked(int a) {
        int root = find(a);
        if (ElementCount[root]) return true;
        else return false;
    }
};


int n,m,a[100000],b[100000],now;
stack<int> ans;
UnionFind UF;

main() {
    cin >> n >> m;
    repm(i,m) cin >> a[i] >> b[i];
    now = n*(n-1)/2;
    ans.push(now);
    rep(i,m-1) {
        if (!UF.is_Linked(a[i]) && !UF.is_Linked(b[i])) now--;
        else if (!UF.is_Linked(a[i])) now -= UF.size(b[i]);
        else if (!UF.is_Linked(b[i])) now -= UF.size(a[i]);
        else if (UF.find(a[i]) != UF.find(b[i])) now -= UF.size(a[i])*UF.size(b[i]);
        UF.unite(a[i],b[i]);
        ans.push(now);
    }
    rep(i,m) cout << ans.top() << endl,ans.pop();
}


Measured memory_bytes: 5020
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() int {
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	return num
}

func main() {
	var f = false
	N := nextLine()

	for i := 1; i < 10; i++ {
		for j := i; j < 10; j++ {
			if N == i*j {
				f = true
				goto OUT
			}
		}
	}
OUT:

	if f {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        String out = "AGC";
        if (a < 1200) {
            out = "ABC";
        } else if (a < 2800) {
            out = "ARC";
        }
        // 文字列の入力
        // String s = sc.next();
        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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 int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string n;
    cin >> n;
    int l = stoi(n);
    int m = sz(n);
    vector<int> a(m);
    int ans = 0;
    REP(i, (int)pow(4, m)) {
		if (i != 0) {
          	a[m - 1]++;
            for (int j = m - 1; j > 0; j--) {
                if (a[j] < 4) break;
                a[j] = 0;
                a[j - 1]++;
            }
        }
        int x = 0;
        string y;
        REP(j, m) {
            if (a[j] == 0) {
                if (sz(y) != 0) {
                    x = 0;
                    break;
                }
            } else if (a[j] == 1) {
                x |= 1;
                y += '3';
            } else if (a[j] == 2) {
                x |= 2;
                y += '5';
            } else if (a[j] == 3) {
                x |= 4;
                y += '7';
            }
        }
        if (x == 7 && l >= stoi(y)) {
            ans++;
        }
    }
    cout << ans << endl;
}



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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int num[3] = {0};
	rep (i, 3) cin >> num[i];

	map<int,int> cnt; cnt.clear();
	rep (i, 3) cnt[num[i]]++;

	int res = -999;
	map<int,int>::iterator it = cnt.begin();
	for (; it != cnt.end(); ++it){
		int n = (*it).first;
		int c = (*it).second;
		if (c == 1){
			res = n;
		} // end if
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
Ts = Array.new(N)
As = Array.new(N)
N.times do |i|
  Ts[i], As[i] = gets.split.map(&:to_i)
end

tz = az = 1
N.times do |i|
  tk = (tz + Ts[i] - 1) / Ts[i]
  ak = (az + As[i] - 1) / As[i]
  k = [tk, ak].max
  tz = Ts[i] * k
  az = As[i] * k
end

puts tz + az


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>

#define endl '\n'
#define pb push_back
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

void solve()
{
    int m, n, i, j, k, l;

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    ll r1, r2, r3, r4;

    r1 = (ll)a*c;
    r2 = (ll)a*d;
    r3 = (ll)b*c;
    r4 = (ll)b*d;

    r1 = max(r1, r2);
    r3 = max(r3, r4);

    cout << max(r1, r3);




}

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

//    int t; cin >> t; while(t--){
        solve();
//    }
    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct UnionFind {
    vector<int> par;
    
    //要素nで初期化
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    //xが属する集合の根を返す
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    //xとyが同じ集合に属しているかを判定
    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    //xが属する集合とyが属する集合をマージ
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // 計算量が減るよ
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    //xが属する集合のサイズ
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
	int n,m;cin>>n>>m;
	vector<pair<int,int>> a(m);
	int ans = 0;
	for(int i = 0; i < m; i++) {
		int x,y;cin>>x>>y;
		a[i] = mp(x - 1,y - 1);
	}
	for(int i = 0; i < m; i++) {
		UnionFind uf(n);
		for(int j = 0; j < m; j++) {
			if (i != j){
				uf.merge(a[j].fs,a[j].sc);
			}
		}
		if (uf.size(0) != n){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

const int MAX_N=114514;

ll fact[MAX_N], fact_inv[MAX_N];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1){
			res=res*a%MOD;
		}
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll comb(int n, int r){
	if(n<r){
		return 0;
	}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

void init_comb(int n){
	fact[0]=1;
	REP(i, n){
		fact[i+1]=fact[i]*(i+1)%MOD;
	}
	fact_inv[n]=power(fact[n], MOD-2);
	FORR(i, 0, n){
		fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	}
	return;
}

// iの逆元も求める場合
// ll inv[MAX_N];
// void init_comb(int n){
//     fact[0]=fact[1]=1;
//     fact_inv[0]=fact_inv[1]=1;
//     inv[1]=1;
//     FOR(i, 2, n+1){
//         fact[i]=fact[i-1]*i%MOD;
//         inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
//         fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
//     }
// }

int num[114514];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a[114514];
	cin>>n;
	REP(i, n+1){
		cin>>a[i];
		--a[i];
		++num[a[i]];
	}
	int dup;
	REP(i, n){
		if(num[i]==2){
			dup=i;
			break;
		}
	}
	int b[2], sz=0;
	REP(i, n+1){
		if(a[i]==dup){
			b[sz++]=i;
		}
	}
	init_comb(n+1);
	ll c=b[0]+n-b[1];
	FOR(i, 1, n+2){
		cout<<(comb(n+1, i)-comb(c, i-1)+MOD)%MOD<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM + 7
#define MAX 10100000
#define INF 1e15
#define MAP 110
#define initial_value -1
#define LINF 1LL << 60
#define Pair pair<int, int>
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
ll N,C,K;
ll t[100100];
int main(){
    cin >> N >> C >> K;
    for(ll i = 0; i < N; i++){
        cin >> t[i];
    }
    sort(t,t+N);
    ll bus_num = 0;
    queue<ll> que;
    for(ll i = 0; i < N; i++){
        if(que.size() == 0){
            bus_num++;
            que.push(t[i]);
        } else if(que.size() == C){
            while(que.size()) que.pop();
            bus_num++;
            que.push(t[i]);
        } else if(que.front() + K < t[i]){
            while(que.size()) que.pop();
            bus_num++;
            que.push(t[i]);
        } else {
            que.push(t[i]);
        }
    }
    cout << bus_num << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int main (){
    char s[10];
    int i,c;
    int sum = 0;
    scanf("%s", s);
    for (i = 0; s[i] != '\0'; i++){
        c = s[i];
        sum += (s[i] - '0');
    }
    int n = atoi(s);
    if (n%sum == 0) {
        printf("Yes\n");
    } else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
dp = [0]
cost = [0,2,5,5,4,5,6,3,7,6]
for i in range(1, N+1):
    dp.append(-(2<<10))
    for a in A:
        if i >= cost[a]: 
            dp[i] = max(dp[i - cost[a]] + 1, dp[i])
ans = ""
while N > 0:
    for e in A:
        if N >= cost[e] and dp[N] - 1 == dp[N - cost[e]]:
            if dp[N] == 1:
                if N != cost[e]: continue
            N -= cost[e]
            ans += str(e)
            break
print(ans)

Measured memory_bytes: 42092
#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a, p;
  cin >> a >> p;
  int d=(3 * a + p) / 2;
  cout<<d<<endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll H, W;
    cin >> H >> W;

    char out[1000][1000];

    for(ll i = 0; i < H; i++){
        for(ll j = 0; j < W; j++){
            cin >> out[i][j];
        }        
    }

    for(ll i = 0; i < H; i++){
        for(ll j = 0; j < W; j++){
            cout << out[i][j];
        } 
        cout << endl;   
        for(ll j = 0; j < W; j++){
            cout << out[i][j];
        }       
        cout << endl;   
    }

}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    for(int i=0; i<5; i++){
        int x;
        cin >> x;
        if(x == 0) cout << i+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
let a,n,x=Array.make(4*3*10)0,read_int(),10;;for _=1to n do Scanf.scanf"%d %d %d %d
"(fun b f r v->let y=3*x*(b-1)+x*f-x+r-1 in a.(y)<-a.(y)+v)done;for b=1to 4do for f=1to 3do for r=1to 10do Printf.printf" %d"a.(3*x*(b-1)+x*f-x+r-1)done;print_newline()done;if b<4then print_endline(String.make 20 '#')done

Measured memory_bytes: 2564
#include <stdio.h>

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

	for (int i = 1; i < N; ++i)
	{
		scanf("%d",&a[i]);
		b[a[i]-1]++;
	}

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


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

void solve(long double arr[])
{
	for(int i=2;i<19;i++)
		arr[i]=(long double)(0.5)*arr[i-1];	
}

int32_t main()
{
	IOS
	long double arr[19]={0};
	arr[1]=0.5;
	solve(arr);
	int n,k;
	cin>>n>>k;
	long double ans=0;
	for(int i=1;i<=n;i++)
	{		
		if(i>=k){break;}
		long double x=ceil(log2((long double)k/i));
		ans+=(long double)1/n*(long double)arr[(int)x];
	}
	if(n>=k)
	ans+=(long double)(n-k+1)/(long double)n;
	/*std::cout << std::fixed;*/
   	std::cout << std::setprecision(20) <<ans<< '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<cstring>
#include<string>
using namespace std;

const int dat[5]={19890108,19261225,19120730,18680908,0};
const char *nengo[5]={"heisei","showa","taisho","meiji","pre-meiji"};

int main(){
	int Y,M,D;
	while(cin>>Y>>M>>D){
		int indat = Y*10000+M*100+D;
		for(int i=0;i<5;i++){
			if(indat>=dat[i]){
				printf("%s",nengo[i]);
				if(i<4){
					printf(" %d %d %d",Y-dat[i]/10000+1,M,D);
				}puts("");
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1148
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct UnionFind {
  int parent[600];
  UnionFind() { memset(parent, -1, sizeof(parent)); }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) { return false; }
    if (parent[y] < parent[x]) { swap(x, y); }
    parent[x] += parent[y];
    parent[y] = x;
    return true;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
};

typedef int Weight;
struct Edge {
  int src;
  int dest;
  Weight weight;
  Edge() {;}
  Edge(int src, int dest, Weight weight) : src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    if (weight != rhs.weight) { return weight < rhs.weight; }
    if (src != rhs.src) { return src < rhs.src; }
    return dest < rhs.dest;
  }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int n, m;
UnionFind ufind;
Edge edges[100000];

int main() {
  while (scanf("%d %d", &n, &m) > 0) {
    REP(i, m) {
      int s, t, c;
      scanf("%d %d %d", &s, &t, &c);
      s--; t--;
      edges[i] = Edge(s, t, c);
    }
    vector<int> candidate;
    sort(edges, edges + m);
    ufind = UnionFind();
    int sum = 0;
    REP(i, m) {
      if (ufind.unionSet(edges[i].src, edges[i].dest)) {
        candidate.push_back(i);
        sum += edges[i].weight;
      }
    }
    int ans_cnt = 0;
    int ans_cost = 0;
    if (-ufind.parent[ufind.root(0)] == n) {
      REP(iter, n - 1) {
        int c = candidate[iter];
        int cnt = 1;
        int lsum = 0;
        ufind = UnionFind();
        REP(i, m) {
          if (i == c) { continue; }
          if (ufind.unionSet(edges[i].src, edges[i].dest)) {
            lsum += edges[i].weight;
            cnt++;
          }
        }
        if (sum != lsum || cnt != n) { 
          ans_cnt++;
          ans_cost += edges[c].weight;
        }
      }
    }
    printf("%d %d\n", ans_cnt, ans_cost);
  }
}

Measured memory_bytes: 1808
#include <iostream>
#include <vector>

using namespace std;

string join(const vector<int>& v, const char delim = 0) {
    string s;
    if (!v.empty()) {
        s += to_string(v[0]);
        for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
            if (delim) s += delim;
            s += to_string(v[i]);
        }
    }
    return s;
}

int main() {
    int K, X;
    cin >> K >> X;

    int MIN = -1000000;
    int MAX = 1000000;

    vector<int> results {};

    results.push_back(X);
    for (int i { 1 }; i < K; ++i) {
        if (X - i >= MIN) {
            results.push_back(X - i);
        }
        if (X + i <= MAX) {
            results.push_back(X + i);
        }
    }

    sort(results.begin(), results.end());

    cout << join(results, ' ') << endl;

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstdint>

using namespace std;

typedef uint64_t u64;
typedef uint32_t u32;
typedef int64_t s64;
typedef int32_t s32;

#define rep(i, N) for(int i; i < N; ++i)
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

#define N 100000

int n;
u64 H;
u64 prevH;
u64 now;
u64 ret;

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

    rep(i, n)
    {
        scanf("%lu", &H);
        if (H <= prevH)
        {
            ++now;
        }
        else
        {
            now = 0;
        }
        prevH = H;
        ret = MAX(ret, now);
    }

    printf("%lu\n", ret);
    return 0;
}



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

int main(int argc, char** argv){
	int n,m;
	cin >> n >> m;
	vector<vector<int> > r(m);
	for(int i = 0; i < n; i++){
		int a,b;
		cin >> a >> b;
		if(a > m) continue;
		r[m-a].push_back(b);
	}
	priority_queue<int> q;
	long long ans = 0;
	for(int i = m-1; i >= 0; i--){
		for(int b : r[i]){
			q.push(b);
		}
		if(!q.empty()){
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5504
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:fiveam))
                 (shadow :run)
                 (use-package :fiveam)))

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  `(progn
     ,@(mapcar (lambda (form)
                 `(format *error-output* "~A => ~A~%" ',form ,form))
               forms))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

(defmacro dorange ((var begin end &optional step) &body body)
  (let ((step (or step 1))
        (end_ (gensym)))
    (check-type step (and integer (not (eql 0))))
    (check-type var symbol)
    `(let ((,end_ ,end))
       (declare (type integer ,end_))
       (do ((,var ,begin (+ ,var ,step)))
           ((,(if (> step 0) '>= '<=) ,var ,end_))
         (declare (type integer ,var))
         ,@body))))

;; Hauptteil

;; A: 0, C: 1, G: 2, T: 3
;; XAG-C
;; XGA-C
;; XAC-G
;; AXG-C
;; AGX-C

(defconstant +a+ 0)
(defconstant +c+ 1)
(defconstant +g+ 2)
(defconstant +t+ 3)
(defun main ()
  (let* ((n (read))
         (dp (make-array (list (1+ n) 4 4 4) :element-type 'uint32 :initial-element 0)))
    (declare (uint32 n))
    (dotimes (c0 4)
      (dotimes (c1 4)
        (dotimes (c2 4)
          (setf (aref dp 3 c0 c1 c2) 1))))
    (setf (aref dp 3 +a+ +g+ +c+) 0)
    (setf (aref dp 3 +a+ +c+ +g+) 0)
    (setf (aref dp 3 +g+ +a+ +c+) 0)
    (dorange (i 3 n)
      (declare (uint32 i))
      (dotimes (c0 4)
        (dotimes (c1 4)
          (dotimes (c2 4)
            (labels ((update (x)
                       (setf (aref dp (1+ i) c1 c2 x)
                             (mod (+ (aref dp (1+ i) c1 c2 x)
                                     (aref dp i c0 c1 c2))
                                  +mod+))))
              (declare (inline update))
              (cond
                ((and (= c1 +a+) (= c2 +c+))
                 (update +c+))
                ((or (and (= c1 +a+) (= c2 +g+))
                     (and (= c1 +g+) (= c2 +a+))
                     (and (= c0 +a+) (= c2 +g+))
                     (and (= c0 +a+) (= c1 +g+)))
                 (update +g+))
                (t (update +c+)
                   (update +g+)))
              (update +a+)
              (update +t+))))))
    (println (let ((sum 0))
               (declare (uint32 sum))
               (dotimes (c0 4)
                 (dotimes (c1 4)
                   (dotimes (c2 4)
                     (setf sum (mod (+ sum (aref dp n c0 c1 c2)) +mod+)))))
               sum))))

#-swank(main)


Measured memory_bytes: 18792
#include <iostream>
#include <stack>
#include <string>
#include <sstream>

inline int Seisu(std::string s) {
    int v;
    std::istringstream sin(s);
    sin >> v;
    return v;
}
 
int main () {
  std::string s;
  std::stack<int> st;
  while (std::cin >> s) {
        if (s[0]>='0' and s[0]<='9') {
            st.push(Seisu(s));
        }
        else {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            switch(s[0]) {
            case '+':
                st.push(a + b);
                break;
            case '-':
                st.push(b - a);
                break;
            case '*':
                st.push(a * b);
                break;
            }
        }
    }
  std::cout<<st.top()<<'\n';
    return 0;
}


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

using namespace std;

const int N = 1e5 + 1;
typedef long long ll;

int main() {
	int tmp, neg = 0, m = int(1e9) + 7, n;
	ll res = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &tmp);
		if (tmp < 0) {
			tmp = -tmp;
			neg++;
		}
		m = min(m, tmp);
		res = res + 1LL * tmp;
	}
	if (neg % 2 == 0) cout << res;
	else cout << res - m * 2;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

#define INF 0x3f3f3f3f

using namespace std;

int res[50000][10],n;
int temp[10],t1,t2;
int a[10],b[10],k=1,pos=0;
bool vis[10];

bool same(int*x,int*y){
    for(int i=0;i<n;++i)
        if(x[i]!=y[i])return false;
    return true;
}

void dfs(int dep){
    if(dep==n){
//        for(int i=0;i<n;++i)
//            res[pos][i]=temp[i];
        ++pos;
        if(same(a,temp))
            t1=pos;
        if(same(b,temp))
            t2=pos;
        return;
    }
    for(int i=1;i<=n;++i){
        if(!vis[i]){
            temp[dep]=i;
            vis[i]=true;
            dfs(dep+1);
            vis[i]=false;
        }
    }
}

int main() {
    scanf("%d",&n);
    for(int i=0;i<n;++i)
        scanf("%d",&a[i]);
    for(int i=0;i<n;++i)
        scanf("%d",&b[i]);
    for(int i=2;i<=n;++i)
        k*=i;
    dfs(0);
//    int t1,t2;
//    for(int i=0;i<k;++i){
//        if(same(a,res[i]))
//            t1=i;
//        if(same(b,res[i]))
//            t2=i;
//    }
    printf("%d\n",t1-t2<0?t2-t1:t1-t2);
    return 0;
}

Measured memory_bytes: 128