akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long MOD = 1e9+7;

// a^n modを計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int N;
vector<long long> bitcnt(66, 0);

int main() {
    cin >> N;
    for(int i = 0; i < N; ++i) {
        long long ina; cin >> ina;
        long long bit = 0;
        long long now = 0;
        while(((long long)1<<bit) <= ina) {
            now = ((long long)1<<bit);
            // cout << now << endl;
            if(ina & now) bitcnt.at(bit)++;
            bit++;
        }
    }

    long long ans = 0;
    for(int i = 0; i <= 65; ++i) {
        long long sum = modpow(2, (long long)i, MOD)%MOD;
        sum *= bitcnt.at(i);
        sum %= MOD;
        sum *= (N-bitcnt.at(i));
        sum %= MOD;
        ans += sum;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int D = S.size();
  vector<int>A(D);
  for (int i = 0; i < D; i++) {
    A.at(i) = S.at(i) - '0';
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < D-1; i++) {
    if (A.at(0) != 49){
      cout << 'a' << endl;
      return 0;
    }
    if (A.at(i+1) - A.at(i) > 1){
      int C = A.at(i)-48;
      cout << (char)('a'+C) << endl;
      return 0;
    }
    if (i == D-2 && A.at(i+1) != 74){
      int C = A.at(i+1)-48;
      cout << (char)('a'+C) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}



Measured memory_bytes: 3816
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    unsigned ll n,i,sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3==0&&i%5==0)
            continue;
        if(i%3==0)
        {
            continue;
        }
        if(i%5==0)
            continue;
        sum+=i;
    }
    cout<<sum<<endl;
}






Measured memory_bytes: 3664
x = int(input())
if x >= 400 and x <= 599:
  print(8)
elif x >= 600 and x <= 799:
  print(7)
elif x >= 800 and x <= 999:
  print(6)
elif x >= 1000 and x <= 1199:
  print(5)
elif x >= 1200 and x <= 1399:
  print(4)
elif x >= 1400 and x <= 1599:
  print(3)
elif x >= 1600 and x <= 1799:
  print(2)
elif x >= 1800 and x <= 1999:
  print(1)

Measured memory_bytes: 9196
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"container/list"
)

const MaxNode int = 100

var d []int
var A [][]int
var N int
var l *list.List

func bfs(u int) {
	d[u] = 0
	l.PushBack(u)
	for ;l.Len() != 0; {
		u = l.Front().Value.(int)
		l.Remove(l.Front())
		for v:=0; v<N; v++ {
			if A[u][v] == 0 {
				continue
			}
			if d[v] != -1 {
				continue
			}
			d[v] = d[u] + 1
			l.PushBack(v)
		}
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func print() {
	for i:=0; i<N; i++ {
		fmt.Printf("%d %d\n", i+1, d[i])
	}
}

func initVariable() {
	d = make([]int, MaxNode)
	A = make([][]int, MaxNode)
	l = list.New()
	for i:=0; i<MaxNode; i++ {
		A[i] = make([]int, MaxNode)
		d[i] = -1
	}
}


func main() {
	initVariable()
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	for i:=0; i<N; i++ {
		idx := nextInt(scanner)
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			node := nextInt(scanner)
			A[idx-1][node-1] = 1 
		}
	}
	bfs(0)
	print()
}


Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;

long long binpow(long long a, long long b)
{
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
long long  gcd(long long a,long long b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}


int main()
{
    int n;
    n = 5;
    int a[n];
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    for(int i=1; i<=n; i++)
    {
        if(a[i]==0)
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class P implements Comparable<P> {
		int s;
		int v;

		P(int s, int v) {
			this.s = s;
			this.v = v;
		}

		public int compareTo(P t) {
			return v - t.v;
		}
	}

	int decode(String buffer) {
		int ret = 0;
		for (int i = 0; i < buffer.length(); i++) {
			ret = ret << 2;
			char ch = buffer.charAt(i);
			if (ch == 'r') {
				ret += 3;
			} else if (ch == 'g') {
				ret += 2;
			} else {
				ret += 1;
			}
		}
		return ret;
	}

	void run() {

		for (;;) {
			String buffer = sc.next();
			if (buffer.equals("0")) {
				break;
			}

			int s = decode(buffer);
			int n = buffer.length();

			PriorityQueue<P> q = new PriorityQueue<P>();
			q.add(new P(s, 0));
			boolean used[] = new boolean[1 << (n * 2)];
			int ans = -1;
			int z = 0;
			int type[] = new int[n];
			int d[] = new int[n];

			for (;;) {
				if (q.isEmpty()) {
					break;
				}

				P v = q.poll();
				if (used[v.s]) {
					continue;
				}
				used[v.s] = true;

				int max = 0;
				int s2 = v.s;
				for (int i = 0; i < n; i++) {
					type[i] = s2 & 3;
					s2 = s2 >> 2;
					if (i != 0) {
						d[i - 1] = type[i] ^ type[i - 1];
						max = (d[i - 1] | max);
					}
				}
				if (max == 0) {
					ans = v.v;
					break;
				}

				for (int i = 0; i < n - 1; i++) {
					if (d[i] != 0) {
						int v2 = v.s;
						v2 = v2 & (~(3 << (2 * (i))));
						v2 = v2 & (~(3 << (2 * (i + 1))));

						v2 = v2 | (d[i] << (2 * (i)));
						v2 = v2 | (d[i] << (2 * (i + 1)));
						if (!used[v2]) {
							q.add(new P(v2, v.v + 1));
						}
					}
				}
			}
			if (ans == -1) {
				System.out.println("NA");
			} else {
				System.out.println(ans);
			}
		}

	}

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

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int a[n];
	int sum = 0;
  	
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	//sum = (int) sum / (4*m);
	int ct = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i]*(4*m) >= sum)
			ct++;
	}
	if (ct >= m)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int a,b,c;cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;
import java.util.SplittableRandom;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[][] idx = new int[30][500];
	static SplittableRandom rnd = new SplittableRandom(42);

	public static void main(String[] args) {
		String person = sc.next();
		int[] pos = new int[1000];
		for (int i = 0; i < 1000; i++) {
			pos[i] = i;
		}
		for (int i = 0; i < idx.length; i++) {
			for (int j = 0; j < idx[0].length; j++) {
				int p = rnd.nextInt(1000 - j) + j;
				int tmp = pos[j];
				pos[j] = pos[p];
				pos[p] = tmp;
				idx[i][j] = pos[j];
			}
		}
		if (person.equals("Charlie")) {
			char[] X = sc.next().toCharArray();
			char[] Y = sc.next().toCharArray();
			int[][] parityX = new int[100][30];
			int[][] parityY = new int[100][30];
			for (int i = 0; i < 100; i++) {
				for (int j = 0; j < 30; j++) {
					parityX[i][j] = X[i * 30 + j] - '0';
					parityY[i][j] = Y[i * 30 + j] - '0';
				}
			}
			for (int i = 0; i < 100; i++) {
				char[] s = sc.next().toCharArray();
				int[] d = new int[1000];
				for (int j = 0; j < 1000; j++) {
					d[j] = s[j] - '0';
				}
				int[] parity = new int[30];
				for (int j = 0; j < 30; j++) {
					int sum = 0;
					for (int k = 0; k < 500; k++) {
						sum += d[idx[j][k]];
					}
					parity[j] = sum % 2;
				}
				OUT:
				for (int j = 0; j < 100; j++) {
					for (int k = 0; k < 100; k++) {
						boolean ok = true;
						for (int l = 0; l < 30; l++) {
							if ((parityX[j][l] ^ parityY[k][l]) != parity[l]) {
								ok = false;
								break;
							}
						}
						if (ok) {
							System.out.println((j + 1) + " " + (k + 1));
							break OUT;
						}
					}
				}
			}
		} else {
			char[] ret = new char[3000];
			for (int i = 0; i < 100; i++) {
				char[] s = sc.next().toCharArray();
				int[] d = new int[1000];
				for (int j = 0; j < 1000; j++) {
					d[j] = s[j] - '0';
				}
				for (int j = 0; j < 30; j++) {
					int sum = 0;
					for (int k = 0; k < 500; k++) {
						sum += d[idx[j][k]];
					}
					ret[i * 30 + j] = (char) (sum % 2 + '0');
				}
			}
			System.out.println(String.valueOf(ret));
		}
	}

}


Measured memory_bytes: 35240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

			int x = a;
			while (x <= (a * b)) {
				if (x % b == c) {
					System.out.println("YES");
					return;
				}
				x += a;
			}
			System.out.println("NO");

		} finally {
			sc.close();
		}
	}
}

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

using namespace std;

int main() {
    int A, B, M;
    cin >> A >> B >> M;

    vector<int> vta(A), vtb(B);
    for (int i = 0; i < A; ++i) {
        cin >> vta[i];
    }
    for (int i = 0; i < B; ++i) {
        cin >> vtb[i];
    }

    int ans = *min_element(vta.begin(), vta.end()) + *min_element(vtb.begin(), vtb.end());
    for (int i = 0; i < M; ++i) {
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, vta[x - 1] + vtb[y - 1] - c);
    }

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


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main()
{
	int a,b;
	char op;

	while(1)
	{

		cin >> a >> op >> b;
		if(op == '?')break;



		switch(op)
		{
		case '+':
			cout << a + b << endl;break;
		case '-':
			cout << a - b << endl;break;
		case '*':
			cout << a * b << endl;break;
		case '/':
			cout << a / b << endl;break;
		}
	}
}

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

int main(void){

    string str;
    cin >> str;
    smatch smatch;
    if (std::regex_search(str, smatch, std::regex("[A-Z]")))
    {
        cout << "A";
    }else{
        cout << "a";
    }
    return 0;
}

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

#define INF ((1LL <<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

#define LIMIT_SEC 2

class Timer {
    chrono::high_resolution_clock::time_point start;
public:
    double limit;
    Timer() {
        start = chrono::high_resolution_clock::now();
        limit = LIMIT_SEC;
    }
    Timer(double limit) :limit(limit) {
        start = chrono::high_resolution_clock::now();
    }
    double get_time() {
        return chrono::duration<double>(chrono::high_resolution_clock::now() - start).count();
    }
    bool time_over() {
        if (get_time() > limit) {
            return true;
        }
        return false;
    }
    void set_start() {
        start = chrono::high_resolution_clock::now();
    }
    double get_limit() {
        return limit;
    }
};

Timer timer;

// 乱数器
class XorShift {
public:
    unsigned long x, y, z, w;
    XorShift() {
        x = 123456789; y = 362436069; z = 521288629; w = 88675123;
    }
    XorShift(unsigned long seed) {
        XorShift();
        w = seed;
        for (int i = 0; i < 100; ++i) (*this)();
    }
    unsigned long operator()() {
        unsigned long t = x ^ (x << 11);
        x = y; y = z; z = w;
        return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    }
};

XorShift rnd;

ll c[27];
ll s[366][27];

const int C = 26;

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

    int D;
    cin >> D;
    rep(i, C) cin >> c[i];
    rep(i, D) rep(j, C) cin >> s[i][j];

    rep(i, D) {
        cout << (rnd() % C) + 1 << endl;
    }
}


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

int main() {
  int N,D,i,j,k,c=0;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));

  for(i=0; i<N; i++)
    for(j=0; j<D; j++)
      cin >> X.at(i).at(j);

  for(i=0; i<N; i++) {
    for(j=i+1; j<N; j++) {
      int ds=0;
      for(k=0; k<D; k++) {
        ds += pow((X.at(i).at(k)-X.at(j).at(k)),2);
      }
      float dsf = sqrt(ds);
      if(dsf == (float)(int)dsf)
        c++;
    }
  }

  cout << c << endl;
  
}


Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = Hash.new(0)
b[0] += 1
b[a[0]%m] += 1
for i in 1..n-1
    a[i] += a[i-1]
    a[i] %= m
    b[a[i]] += 1
end
ans = 0
b.values.each do |i|
    ans += i*(i-1)/2
end
puts ans

Measured memory_bytes: 12676
#include<stdio.h>
int main()
{
  int h,n,s=0,i,t;
  scanf("%d%d",&h,&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&t);
    s += t;
    if(s >= h)
    {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}
    

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

int main()
{
    int i,a,b;
    cin>>s;
    a=(s[0]-'0')*10+s[1]-'0';
    b=(s[2]-'0')*10+s[3]-'0';
    if(a>0 && a<13 && b>0 && b<13)printf("AMBIGUOUS\n");
    else if(a>0 && a<13)printf("MMYY\n");
    else if(b>0 && b<13)printf("YYMM\n");
    else printf("NA\n");
    return 0;
}


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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  long N;
  cin >> N;
  vector<long> A(N), B(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  for (long i = 0; i < N; i++) cin >> B.at(i);

  long AS = accumulate(A.begin(), A.end(), 0L);
  long BS = accumulate(B.begin(), B.end(), 0L);

  if (AS > BS) return cout << "No" << "\n", 0;

  long X = 0, Y = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) < B.at(i)) X += (B.at(i) - A.at(i)) / 2;
    else Y += A.at(i) - B.at(i);
  }

  if (Y > X) return cout << "No" << "\n", 0;
  cout << "Yes" << "\n";
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

ll sumn(ll n) {
  return (n * (n + 1)) / 2;
}

struct SegmentTree {
  vector<ll> tree, lazy;

  void push(int node, int x, int y, ll val) {
    tree[node] += val * (y - x);
    lazy[node] += val;
  }
  void split(int node, int x, int y) {
    int z = (x + y) / 2;

    push(2 * node, x, z, lazy[node]);
    push(2 * node + 1, z, y, lazy[node]);

    lazy[node] = 0;
  }
  void merge(int node) {
    tree[node] = tree[2 * node] + tree[2 * node + 1];
  }

  int sz;
  SegmentTree(int n) {
    for (sz = 1; sz < n; sz <<= 1);
    tree.resize(2 * sz, 0);
    lazy.resize(2 * sz, 0);
  }

  void update(int l, int r, ll val, int node = 1, int x = 0, int y = -1) {
    if (y == -1) y = sz;
    if (l >= y || r <= x) return;
    if (l <= x && y <= r) {
      push(node, x, y, val);
      return;
    }
    split(node, x, y);
    update(l, r, val, 2 * node, x, (x + y) / 2);
    update(l, r, val, 2 * node + 1, (x + y) / 2, y);
    merge(node);
  }

  ll query(int l, int r, int node = 1, int x = 0, int y = -1) {
    if (y == -1) y = sz;
    if (l >= y || r <= x) return 0;
    if (l <= x && y <= r) {
      return tree[node];
    }
    split(node, x, y);
    ll res = query(l, r, 2 * node, x, (x + y) / 2)
      + query(l, r, 2 * node + 1, (x + y) / 2, y);
    merge(node);
    return res;
  }
};

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  vector<VI> adj(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int u, v; cin >> u >> v;
    if (u > v) swap(u, v);
    adj[u].push_back(v);
  }

  ll ans = 0;
  SegmentTree tree(n + 1);
  for (int u = n; u >= 1; u--) {
    for (int v: adj[u]) {
      tree.update(v, n + 1, 1);
    }
    ll cur = sumn(n - u + 1) - tree.query(u, n + 1);
    ans += cur;
  }
  cout << ans << endl;


  return 0;
}


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

int main()
{
    int n;
    bool judge = false;
    cin >>n;
    if(n%10 == 7)
    {
        judge = true;
    }
    else{
        if((n%100) >= 70 && (n%100) < 80){
            judge = true;
        }
        else{
            if(n >= 700 && n < 800){
                judge = true;
            }
        }
    }
    if(judge){
        cout <<"Yes" <<endl;
        return 0;
    }
    else{
        cout <<"No" <<endl;
        return 0;
    }
}

Measured memory_bytes: 3596
#include<stdio.h>

int main(){
  int a, b;
  int result, output;

  scanf("%d %d", &a, &b);

  result = a+b;
  output = result;
  result = a-b;
  if(output < result)output = result;
  result = a*b;
  if(output < result)output = result;

  printf("%d", output);

  return 0;
}

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


int main() {

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
    }

    map<int, int> K;
    for(int i = 0; i < N; i++){
        K[A[i]]++;
    }

    int ans = 0;
    for(auto m:K){
        if(m.second % 2 != 0){
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
}

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 4000010;
bitset<N> bs;

int main() {
	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}

	bs.flip(0);
	for (int i = 0; i < n; ++i) {
		bs |= (bs << a[i]);
	}

	int S = accumulate(all(a), 0);
	S = (S + 1) / 2;
	while (!bs[S]) {
		++S;
	}
	cout << S << "\n";

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;

int N, res;
string S;

int main() {
	cin >> N >> S;
	res = N;
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == S[i + 1]) {
			res--;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> p(n), q(n), P(n);
   rep(i, 0, n) cin >> p[i];
   rep(i, 0, n) cin >> q[i];
   rep(i, 0, n) P[i] = i + 1;
   int a, b, cnt;
   cnt = 1;
   do {
      bool isok = true;
      rep(i, 0, n) if (p[i] != P[i]) isok = false;
      if (isok) a = cnt;
      isok = true;
      rep(i, 0, n) if (q[i] != P[i]) isok = false;
      if (isok) b = cnt;
      cnt++;
   } while (next_permutation(P.begin(), P.end()));
   int ans = abs(a - b);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A,B;
  cin>>A>>B;
  ll mx=-1;
  for(ll i=60;i>=0;i--){
    if((A>>i&1)!=(B>>i&1)){mx=i; break;}
    if(A>>i&1){A^=1LL<<i; B^=1LL<<i;}
  }
  if(mx==-1){cout<<1<<endl; return 0;}
  ll mx2=-1;
  for(ll i=mx-1;i>=0;i--){
    if(B>>i&1){mx2=i; break;}
  }
  if(mx2!=-1){B|=(1LL<<mx2)-1;}
  ll ans=B-A+1;
  ans+=(1LL<<mx)-A;
  B^=1LL<<mx;
  if(A<=B){ans-=B-A+1;}
  cout<<ans<<endl;
  
  return 0;
}


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


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll b[n];
    rep(i,n) b[i]=0;
    for(int i=1;i<n;++i)
    {
        ll a;
        cin >> a;
        b[a-1]++;
    }
    rep(i,n)
    {
        cout << b[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 5172
#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

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

int main()
{
    int n,k,*p,i,sum=0;

    cin>>n>>k;

    p = new int [n];

    for(i=0;i<n;i++){
        cin >> p[i];
    }

    qsort(p,n,sizeof(int),compare_fnc);

    for(i=0;i<k;i++){
        sum = sum + p[i];
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<queue>
#include<string>

using namespace std;

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++){
    if((i+1) % 2){
      if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
      cout << "No" << endl;
      return 0;
    }
    else{
      if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') continue;
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String in = sc.next();
        
        int sum = 0;
        for(int i = 0; i<in.length(); i++) {
          char thisChar = in.charAt(i);
          sum += Character.getNumericValue(thisChar);
        }

        if(sum%9==0) {
          System.out.println("Yes");  
        }
        else {
          System.out.println("No");
        }
    }
}

Measured memory_bytes: 40492
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int a, b, t;
    cin >> a >> b >> t;
    cout << b * (t/a) << endl;
    return 0;
}

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


int main()
{
	int A, B;
	string str;
	
	cin >> A >> B;
	cin >> str;
	bool flag = false;
	
	for (int i = 0; i < A + B + 1; i++) {
		if (i == A) {
			if (str[i] != '-') {
				flag = true;
				break;
			}
		}
		else {
			if (str[i] - '0' < 0 || str[i] - '0' > 9) {
				flag = true;
				break;
			}
		}
	}
	if (flag == false) cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 256
w = gets.chomp

chars = w.split(//)
ntimes = Hash.new{ |h,k| h[k] = 0 }
chars.each do |char|
  ntimes[char] += 1
end

if ntimes.values.all? { |v| v.even? }
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 3836
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
        long sum = 0;
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            int val = map.getOrDefault(num, 0);
            map.put(num, ++val);
            sum = sum + num;
        }
        
        int q = sc.nextInt();
        while (q-- > 0) {
            int prev = sc.nextInt();
            int next = sc.nextInt();
            
            long dif = next - prev;
            
            int prevcount = map.getOrDefault(prev, 0);
            sum = sum + dif * prevcount;
            
            map.remove(prev);
            int val = map.getOrDefault(next, 0);
            map.put(next, val + prevcount);
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 65720
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int n; cin >> n;) {
		vector<int> D(n); rep(i, 0, n) {
			cin >> D[i];
		}
		D.push_back(0);
		int N = n + 1;
		sort(all(D));

		auto f = [&](const vector<int> &d) {
			int score = 24 - d.back();
			rep(i, 0, N - 1) {
				chmin(score, d[i + 1] - d[i]);
			}
			return score;
		};

		if (N > 24) {
			cout << 0 << endl;
		}
		else {
			vector<int> cnt(24);
			rep(i, 0, N) {
				cnt[D[i]]++;
				cnt[(24 - D[i]) % 24]++;
			}
			if (*max_element(all(cnt)) > 2) {
				cout << 0 << endl;
			}
			else if (cnt[1]) {
				cout << 1 << endl;
			}
			else {
				int score = 0;
				rep(mask, 0, (1 << (N - 1))) {
					vector<int> d = D;
					rep(i, 0, N - 1) {
						if ((mask >> (i + 1)) & 1) {
							d[i + 1] = 24 - d[i + 1];
						}
					}
					sort(all(d));

					int tmp = 24 - d.back();
					rep(i, 0, N - 1) {
						chmin(tmp, d[i + 1] - d[i]);
					}

					chmax(score, tmp);
				}
				cout << score << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long int a, b;
    cin>>a>>b;
    long long int ans = INT_MAX;
    long long int a1 = -1 * a;
    long long int b1 = -1 * b;
    if(a1 <= b){
        ans = min(ans, 1 +(b-a1));
    } 
    if( a <= b1){
        ans = min(ans, 1 + (b1 - a));
    } 
    if(a <= b){
        ans = min(ans, b - a);
    } 
    if(a1 <= b1){
        ans = min(ans, 2 + (b1 - a1));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

ll dp[3000100][2];

int main(){
    ios::sync_with_stdio(0);
    ll n;
    cin>>n;

    for(int i=n-1 ; i<=2*n+10 ;i ++){
        dp[i][0] = n;
        dp[i][1] = n;
    }
    ll r = n*(n-1);
    r %= mod;
    for(int i = n-2; i>=0 ; i--){
        dp[i][0] = dp[i+1][0];
        dp[i][1] = dp[i+1][0];
        dp[i][1] += ((n-1))%mod;
        dp[i][1] %= mod;
        dp[i][0] += r;
        dp[i][0] %= mod;
        r -= dp[i+n][1];
        r %= mod;
        r += mod;
        r %= mod;
        r += dp[i+1][1];
    }
    cout<<dp[0][0]<<endl;
    return 0;
}


Measured memory_bytes: 33024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N + 1];
		long[] B = new long[N];
		for(int i = 0; i < N + 1; i++) {
			A[i] = sc.nextLong();
		}
		for(int i = 0; i < N; i++) {
			B[i] = sc.nextLong();
		}
		sc.close();
		long hit = 0L;
		for(int i = 0; i < N; i++) {
			long a = A[i];
			long b = B[i];
			// 勇者iが倒せる数はB[i]
			// A[i]のモンスターを倒したときの残倒せる数とモンスターの残数を設定
			if(a > b) {
				hit += b;
				b = 0L;
			} else {
				hit += a;
				b -= a;
			}
			// A[i + 1]のモンスターを倒した後のモンスターの残数を設定
			long a_1 = A[i + 1];
			if(a_1 > b) {
				hit += b;
				a_1 -= b;
			} else {
				hit += a_1;
				a_1 = 0L;
			}
			A[i + 1] = a_1;
		}
		System.out.println(hit);
	}
}


Measured memory_bytes: 84500
#include <stdio.h>
int main(void)
{
    int m,n,i,a[101],st,cou;
    double je;
    
    scanf("%d%d",&n,&m);
    
    st = 0;
    cou = 0;
    for(i=1;i<=n;i++){        
        scanf("%d",&a[i]);
        st += a[i];
    }
    
    je = (double)st * (1 / (4*(double)m));
    for(i=1;i<=n;i++){
        if(a[i] >= je)
          cou++;
    }
    
    if(cou >= m)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

bool prime[1000001];

int sieve(int n){
  for(int i=2;i<1000001;i++){
    prime[i]=true;
  }
  prime[0]=false;
  prime[1]=false;
  for(long long i=2;i<1000001;i++){
    if(prime[i]==true){
        for(long long j=i*i;j<1000001;j+=i){
            prime[j]=false;
        }
    }
    if(i==n && prime[n]==true){
        return n;
    }else if(prime[i]==true && i>n){
        return i;
    }
  }
}

int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",sieve(n));
    return 0;
}



Measured memory_bytes: 4740
#include<stdio.h>
long int sq(long int n) {
    long int l=0,r=n,m;
    while (r-l>1L){m=(r+l)/2L;if(0<n/m/m)l=m;else r=m;}
    return l-(l*l==n);
}
int main(){
  long int i,q,a,b,x;
  scanf("%ld",&q);
  for(i=0;i<q;i++){
    scanf("%ld%ld",&a,&b);if(a>b){x=a;a=b;b=x;}
    if(a==b||a+1==b)x=a*2-2;
    else {x=sq(a*b);x=2*x-2+(x*(x+1)<a*b);}
    printf("%ld\n",x);
  }
}


Measured memory_bytes: 1696
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
string s[300];
int ans[300][300];
int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	for(int i=0;i<h;i++)
		cin>>s[i];
	fill(ans[0],ans[300],-1);
	int cnt=1;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(s[i][j]=='#')
			{
				ans[i][j]=cnt;
				cnt++;
			}
		}
	}
	//右に拡大
	for(int i=0;i<h;i++)
	{
		for(int j=1;j<w;j++)
		{
			if(ans[i][j]==-1 && ans[i][j-1]!=-1)
				ans[i][j]=ans[i][j-1];
		}
	}
	//左に拡大
	for(int i=0;i<h;i++)
	{
		for(int j=w-2;j>-1;j--)
		{
			if(ans[i][j]==-1 && ans[i][j+1]!=-1)
				ans[i][j]=ans[i][j+1];
		}
	}
	bool f=true;
	while(f)
	{
		f=false;
		for(int i=0;i<h;i++)
		{
			if(ans[i][0]==-1)
			{
				f=true;
				for(int j=0;j<w;j++)
				{
					if(i<h-1 && ans[i+1][j]!=-1)
						ans[i][j]=ans[i+1][j];
					else if(i>0 && ans[i-1][j]!=-1)
						ans[i][j]=ans[i-1][j];
				}
			}
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cout<<ans[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		40010

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//


int DP[5002][5002];

//
int main(){
	int N;cin>>N;
	string S;cin>>S;

	for(int i=N-1;i>=0;--i){
		for(int j=N-1;j>=0;--j){
			if(S[i]==S[j])DP[i][j]=DP[i+1][j+1]+1;
		}
	}

	int ans = 0;
	REP(i,N)REP(j,N){
		if(i>=j)continue;
		ans = max(ans,min(DP[i][j],j-i));
	}
	cout << ans << endl;

	return 0;
}




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

int main()
{
  uint64_t N;
  std::cin >> N;
  
  bool flag = true;
  char end = ' ';
  
  std::set<std::string> set;
  std::string w;
  
  std::cin >> w;
  
  set.insert(w);
  end = w[w.size() - 1];
  
  for (uint64_t n = 1; n < N; ++n) {
    std::cin >> w;
    
    if (set.find(w) != set.end()) {
      flag = false;
    }
    
    if (w[0] != end) {
      flag = false;
    }
    
    set.insert(w);
    end = w[w.size() - 1];
  }
  
  std::cout << (flag ? "Yes" : "No") << std::endl;
  
  return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  string an[n];rep(i,n)cin>>an[i];
  string bn[m];rep(i,m)cin>>bn[i];
  
  rep(x0, n-m+1)rep(y0, n-m+1) {
    bool flg=true;
    rep(i,m)rep(j,m) {
      if (an[x0+i][y0+j] != bn[i][j]) flg=false;
    }
    if (flg) {
      cout << "Yes";
      return 0;
    }
  }
  
  cout << "No";
}


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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        var s = Console.ReadLine();
        var ans = 0;

        var i = 0;
        var k = s.Length - 1;
        while (i < k)
        {
            if (s[i] != s[k])
            {
                if (s[i] != 'x' && s[k] != 'x')
                {
                    ans = -1;
                    break;
                }
                else if (s[i] == 'x')
                {
                    i++;
                    ans++;
                }
                else
                {
                    k--;
                    ans++;
                }
            }
            else
            {
                i++;
                k--;
            }
        }


        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27544
#include <iostream>

using namespace std;

int main() {
    string ans;
    cin >> ans;
    int Q;
    cin >> Q;
    bool flag=true;
    string left="", right="";
    for(int q=0; q<Q; q++) {
        int ot;
        cin >> ot;
        if(ot==1) {
            flag=flag ? false : true;
        } else {
            int f;
            cin >> f;
            string c;
            cin >> c;
            if(f==1) {
                if(flag) {
                    left = c+left;
                } else {
                    right += c;
                }
            } else {
                if(flag) {
                    right += c;
                } else {
                    left = c+left;
                }
            }
        }
    }
    if(flag) {
        cout << left << ans << right << endl;
    } else {
        ans = left+ans+right;
        for(int i=0; i<ans.size(); i++) {
            cout << ans[ans.size()-1-i];
        }
        cout << endl;
    }


    return 0;
    
}

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

int main()
{
int A;
int B;
int C;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;
	cin >> C;

	if( A == B )
		cout << C << endl;
	else if( A == C )
		cout << B << endl;
	else
		cout << A << endl;

	return 0;
}






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

typedef struct {
  int parent, left, right;
}node;
node T[N];

int depth(int);

main() {
  int i, n, j, id, k, child, save;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  
  for(i = 0; i < n; i++) {
    scanf("%d %d", &id, &k);
    for(j = 0; j < k; j++) {
      scanf("%d", &child);
      if(j == 0) {
	T[id].left = child;
	T[child].parent = id;
	save = child;
      }
      else {
	T[save].right = child;
	T[child].parent = id;
	save = child;
      }
    }
  }
  
  for(i = 0; i < n; i++) {
    printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, depth(i));
    if(T[i].parent == NIL) {
      printf("root, [");
    }
    else if(T[i].left == NIL) {
      printf("leaf, [");
    }
    else {
      printf("internal node, [");
    }
    if(T[i].left != NIL) {
      printf("%d", T[i].left);
      save = T[i].left;
      while(T[save].right != NIL) {
	printf(", %d", T[save].right);
	save = T[save].right;
      }
    }
    printf("]\n");
  }
  return 0;
}

int depth(int i) {
  int count = 0;
  while(1) {
    if(T[i].parent == NIL) {
      return count;
    }
    else {
      i = T[i].parent;
      count++;
    }
  }
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
long long n,i,x;
struct mon{
	long long t,s;
	mon(long long t,long long s):t(t),s(s){}
	bool operator<(const mon& b)const{
		if(s!=b.s)
			return s>b.s;
	}
};
priority_queue<mon>pq;
int main(){
	cin.tie(NULL);
	for(cin>>n;i<n;i++){
		cin>>x;
		pq.push(mon(1,x));
	}
	mon a=mon(0,0),b=mon(0,0);
	while(pq.size()>1){
		a=pq.top(); pq.pop();
		b=pq.top(); pq.pop();
//		cout<<a.s<<' '<<b.s<<endl;
		if(a.s*2<b.s){
			n-=a.t;
			pq.push(mon(b.t,a.s+b.s));
		}else
			pq.push(mon(a.t+b.t,a.s+b.s));
	}
	cout<<n<<endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w,q;
  cin >> h >> w >> q;
  vector<vector<ll>> j,o,I(h+2,vector<ll>(w+2,0));
  j = o = I;
  char c;
  REP(i,1,h+1){
    REP(k,1,w+1){
      cin >> c;
      if(c == 'J'){
        j[i][k] = 1;
      }
      else if(c == 'O'){
        o[i][k] = 1;
      }
      else{
        I[i][k] = 1;
      }
    }
  }
  REP(i,1,h+1){
    REP(k,1,w+1){
      j[i][k+1] += j[i][k];
      o[i][k+1] += o[i][k];
      I[i][k+1] += I[i][k];
    }
  }
  REP(k,1,w+1){
    REP(i,1,h+1){
      j[i+1][k] += j[i][k];
      o[i+1][k] += o[i][k];
      I[i+1][k] += I[i][k];
    }
  }
  ll a,b,e,d;
  rep(i,q){
    cin >> a >> b >> e >> d;
    cout << j[e][d]+j[a-1][b-1]-j[a-1][d]-j[e][b-1]<< ' '<<o[e][d] + o[a-1][b-1] -o[a-1][d]-o[e][b-1]<< ' '<<I[e][d] +I[a-1][b-1]-I[a-1][d]-I[e][b-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 26272
#include <stdio.h>
#include <stdlib.h>
#define N 10000
#define MIN(a, b) (a < b ? a : b)

int partition(int *A, int  p, int r){
	int i, j, x, temp;
	x = A[r];
	//printf("x:%d\n", x);
	i = p-1;
	for(j=p; j<r; j++){
		if(A[j]<=x){
			i=i+1;
			//A[i] と A[j] を交換
			temp=A[i];
			A[i]=A[j];
			A[j]=temp;
		}
	}
	//A[i+1] と A[r] を交換
	temp=A[i+1];
	A[i+1]=A[r];
	A[r]=temp;
	
	return i+1;
}

void quicksort(int *A, int  p, int r){
	int q;
	if(p<r){
		q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q+1, r);
	}
}

int solve(int *A, int *B, int min, int n){
	int i, sum, c, m, ans=0;
	int X[N+1], C[N];
	for(i=0; i<n; i++) C[i]=0;
	quicksort(B, 0, n-1);
	
	for(i=0; i<n; i++) X[B[i]]=i;
	for(i=0; i<n; i++){
		if(C[i]) continue;
		int x=i;
		sum=0;
		m=N;
		c=0;
		while(1){
			C[x]=1;
			c++;
			int a=A[x];
			m=MIN(m, a);
			sum+=a;
			x=X[a];
			if(C[x]) break;
		}
		ans+=MIN(sum+(c-2)*m, m+sum+(c+1)*min);
	}
	return ans;
}

int main(void){
	int n, i, j, A[N], B[N], min=N;	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &A[i]);
		if(min>A[i]) min=A[i];
		B[i]=A[i];
	}
	printf("%d\n", solve(A, B, min, n));
	return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define sff(a,b) scanf("%d%d",&a,&b);
#define sfffl(a,b) scanf("%lld%lld",&a,&b);
#define nwln() printf("\n");
#define prd(a) printf("%d",a);
#define prld(a) printf("%lld",a);
#define space printf(" ");
#define ft cout<<"for test"<<endl;
#define read(v) for(auto &it:v)cin>>it;
#define PI 2*acos(0.0)
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    FIO;
    int n,i,j,m,a,b;
    cin>>n>>m;
    vi H(n+1);
    for(i=1; i<=n; i++)
        cin>>H[i];
    vi grap(n+1);
    for(i=0; i<m; i++)
    {
        cin>>a>>b;
        if(H[a]>H[b])
            grap[b]=1;
        else if(H[a]<H[b])grap[a]=1;
        else grap[a]=1,grap[b]=1;
    }
    int gd=0;
    for(i=1; i<=n; i++)
    {
        ///cout<<grap[i]<<' ';
        if(!grap[i])
            gd++;

    }
    cout<<gd<<endl;
}


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

int main() {
  vector<int> vec(3);
  
  for(int i=0; i<3; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
    
  cout << vec.at(0) * vec.at(1) / 2 << endl;
  
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n,k;
	string s;
	t = 1;
	while(t--) {
	 cin >> n >> k >> s;
	 s[k - 1] = s[k - 1] + 32;
	 cout << s << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 100005;

int main() {
    int n, m;
    cin >> n >> m;
    int ans = m * (m - 1) / 2 + n * (n - 1) / 2;
    cout << ans << endl;
    return 0;
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var abk = Console.ReadLine().Split(' ').Select(num => long.Parse(num)).ToArray();
            var a = abk[0];
            var b = abk[1];
            var k = abk[2];

            var min = Math.Min(a, k);
            a -= min;
            k -= min;
            if (k > 0 && b > 0)
            {
                b -= Math.Min(k, b);
            }

            Console.WriteLine($"{a} {b}");
        }
    }
}

Measured memory_bytes: 28172