akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    int ans = 0;
        int th = 0;
        int temp = 0;
        th = (x / 500) * 1000;
        ans += th;
        x %= 500;
        if(x != 0){
            temp = x / 5;
            ans += temp * 5;
        }
        cout << ans;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = a + b;
		if (c % 2 == 0) {
			System.out.println(c / 2);
		} else {
			System.out.println(c / 2 + 1);
		}
	}
}


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

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

int main(){
	int n;
	cin>>n;
	vector<ll>a(n),b(n);
	vector<ll>num(n+1);
	for(int i=0;i<n;i++){
		cin>>a[i];
		num[a[i]]++;	
	}	
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=num[i]*(num[i]-1)/2;
	}
	for(int i=0;i<n;i++){
		int tmp=(num[a[i]]-1);
		cout<<ans-tmp<<endl;
	}
	return 0;
}


Measured memory_bytes: 7296
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int64 solve(const vector<int>& a) {
  int n = a.size();
  vector<int> b(n);
  int ll, rr, d;
  ll = rr = (n - 1) / 2; d = 1;
  // trace(ll, rr, d);
  for (int i = 0; ; ++i) {
    if (d > 0) {
      if (ll < 0) break;
      b[ll] = a[i];
      rr += 2;
    } else {
      if (rr >= n) break;
      b[rr] = a[i];
      ll -= 2;
    }
    d = -d;
  }
  // trace(ll, rr, d);
  ll = rr = (n + 1) / 2; d = -1;
  for (int i = n - 1; ; --i) {
    if (d > 0) {
      if (ll < 0) break;
      b[ll] = a[i];
      rr += 2;
    } else {
      if (rr >= n) break;
      b[rr] = a[i];
      ll -= 2;
    }
    d = -d;
  }
  // for (int i = 0; i < n; ++i) {
  //   cout << b[i] << " ";
  // }
  // cout << endl;
  int64 ret = 0;
  for (int i = 1; i < n; ++i) {
    ret += abs(b[i] - b[i - 1]);
  }
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  int64 ret = solve(a);
  reverse(a.begin(), a.end());
  ret = max(ret, solve(a));
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 1024
const val MOD: Long = (1e9+7).toLong()

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    /* val b = ArrayList(readLine()!!.split(' ').map{it.toInt()-1}) */
    val b = arrayListOf(*readLine()!!.split(' ').map{it.toInt()-1}.toTypedArray())

    val l = arrayListOf(0)
    l.removeAt(0)
    /* val l: ArrayList<Int> = arrayListOf() */
    while (b.size > 1) {
        var f = false
        for ((i, x) in b.withIndex().reversed()) {
            if (i == 0) continue
            if (i == x) {
                l.add(x+1)
                b.removeAt(i)
                f = true
                break
            }
        }

        if (!f) {
            if (b[0] == 0) {
                l.add(1)
                b.removeAt(0)
                continue
            }

            println(-1)
            return
        }
    }
    if (b[0] != 0) {
        println(-1)
        return
    } else {
        println(1)
        for (x in l.reversed()) {
            println(x)
        }
    }
}


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

// DATA TYPES
typedef long long ll;
#define double long double
//

// CONTAINERS
#define vec vector
#define pb push_back
#define ALL(x) begin(x), end(x)
#define SZ(x) (int)x.size()
#define mp make_pair
#define ii pair<int, int>
#define F first
#define S second
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U> &L, const std::pair<T,U> &R) {
  return {L.first + R.first, L.second + R.second};
}
//

// LOOP
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
//

// BIT
#define bitcount(n) __builtin_popcountll(n)
//

// DEBUG
#define format(x) << #x << ": " << (x)
#define com << ", "
#define ndl << "\n"
#define debug1(x) cerr format(x) ndl;
#define debug2(x, y) cerr format(x) com format(y) ndl;
#define debug3(x, y, z) cerr format(x) com format(y) com format(z) ndl;
void debug_out() { cerr << "\n"; }
template <typename H, typename... T> 
void debug_out(H h, T... t) { cerr << " " << (h); debug_out(t...); }
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
// 

// CONSTANTS
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
//

// NUMERICAL OPERATIONS
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

int norm(int a) {
  return ((a % MOD) + MOD) % MOD;
}

int mul(int a, int b) {
  return int(a * 1LL * b % MOD);
}

int binPow(int a, int k) {
  int ans = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
  }
  return ans;
}

// If I need to find (x / a) % MOD, I need to use this function:
//    (x / a) % MOD = (x * inv(a)) % MOD
int inv(int a) {
  int b = binPow(a, MOD - 2);
  assert(mul(a, b) == 1);
  return b;
}
//

// Init variables here
const int N = 1e6 + 7;

void init() {
  //freopen("??.in", "r", stdin);
  //freopen("??.out", "w", stdout);

}

void solve() {
  string s;
  cin >> s;
  int n = s.length();
  FOR(i, 0, n) {
    if ((i % 2 == 0 and s[i] == 'L') 
      or (i % 2 and s[i] == 'R')) {
      cout << "No\n";
      return;
    }
  }
  cout << "Yes\n";
  // read the question correctly (is y a vowel?)
  // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
}

int main() {
  //ios_base::sync_with_stdio(false); cin.tie();
  //auto beginProgram = chrono::steady_clock::now();
  //int t; scanf("%d", &t); while (t--) 
  {
    init();
    solve();
  }
  //auto endProgram = chrono::steady_clock::now();

  return 0;
}



Measured memory_bytes: 256
k,x=map(int,input().split())
ans=[]
for i in range(k):
    if -1000000<=x-i:
        ans.append(x-i)
    ans.append(x)
    if x+i<=1000000:
        ans.append(x+i)
ans=set(ans)
ans=list(ans)
ans=sorted(ans)
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 3064
#include <iostream>
#include <valarray>
//#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    int q;
    std::cin >> q;

    for (int i = 0; i < q; i ++) {
        std::valarray<int> p0(2), p1(2), p2(2), p3(2);
        std::cin >> p0[0] >> p0[1] >> p1[0] >> p1[1] >> p2[0] >> p2[1] >> p3[0] >> p3[1];

        std::valarray<int> v1 = p1 - p0;
        std::valarray<int> v2 = p3 - p2;

        if (v1[0] * v2[1] - v1[1] * v2[0] == 0) {
            std::cout << 2 << std::endl;
        } else if ((v1 * v2).sum() == 0) {
            std::cout << 1 << std::endl;
        } else {
            std::cout << 0 << std::endl;
        }
    }
}



Measured memory_bytes: 3100
#include <iostream>
 
using namespace std;
 
void answer(string S, int K) {
    for (int i=0; i<K; i++) {
        if(S[i] != '1') {
            cout << S[i] << endl;
            return;
        }
    }

    cout << '1' << endl;
    return;
}

int main()
{
    string S;
    int K;
    cin >> S >> K;

    answer(S, K); 
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0] * N
xy = [0] * N
for i in range(N):
  A[i] = int(input())
  xy[i] = [0] * A[i]
  for j in range(A[i]):
    xy[i][j] = [int(k) for k in input().split()]

ans = 0
for bit in range(2**N):
  # 正直者の証言の整合性確認
  are_correct = True
  n_honest = 0
  for i in range(N):
    a = (bit >> i) & 1
    if a == 0:
      continue
    else:
      n_honest += 1
    for j in xy[i]:
      b = (bit >> (j[0]-1)) & 1
      if b != j[1]:
        are_correct = False
  # 整合性の確認が取れた場合，正直者の最大人数を更新
  if are_correct:
    if ans < n_honest:
      ans = n_honest

print(ans)


Measured memory_bytes: 3188
package main

import (
	"fmt"
)

func main() {
	var a, b string
	fmt.Scan(&a, &b)

	if (a == "H" && b == "H") || (a == "D" && b == "D") {
		fmt.Println("H")
	} else {
		fmt.Println("D")
	}
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>

using namespace std;

using namespace std;

int n, k, i, j;
int sum;

int main()
{
	while(cin >> n >> k)
	{
		sum = k;
		for(i = 1; i < n; i++)
			sum *= (k - 1);
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

Measured memory_bytes: 61752
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt[27];
    REP(i, 27){
        cnt[i] = 0;
    }
    REP(i, s.length()){
        cnt[s[i] - 'a']++;
    }
    REP(i, 27){
        if(cnt[i] == 0){
            if(i == 26){
                cout << "None" << endl;
                return 0;
            }
            string ans = string(1, 'a' + i);
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 512
from collections import deque

def solve(K):
    stack = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    for _ in range(K):
        num = stack.popleft()
        one_digit = num % 10
        if one_digit % 10 == 0:
            nexts = [num * 10, num * 10 + 1]
        elif one_digit % 10 == 9:
            nexts = [num * 10 + 8, num * 10 + 9]
        else:
            nexts = [num * 10 + one_digit - 1, num * 10 + one_digit, num * 10 + one_digit + 1]

        for n in nexts:
            stack.append(n)
    return num

if __name__ == '__main__':
    K = int(input())
    print(solve(K))


Measured memory_bytes: 11980
#include <cstdio>

int arr[20];

int main(){
	int i, a;
	for(i = 0; i < 3; i++) scanf("%d", &a), arr[a]++;
	if(arr[5] == 2 && arr[7] == 1) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            long a = in.nextLong();
            long b = in.nextLong();
            long x = in.nextLong();

            System.out.println(count(b, x) - (a == 0 ? 0 : count(a - 1, x)));
        }
    }

    private static long count(long l, long x) {
        return 1 + l / x;
    }
}


Measured memory_bytes: 26876
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <limits>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll solve()
{
    ll N;

    std::cin >> N;

    return ((N - 1)*N) / 2;
}

int main()
{
    std::cout << solve() << std::endl;

    return 0;
}


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

public class Main{

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int h = Integer.parseInt(lines[0]);
      int w = Integer.parseInt(lines[1]);
      boolean[][] mat = new boolean[h][w];

      String line;
      for(int y=0; y<h; y++) {
        line = in.readLine();
        for(int x=0; x<w; x++) {
          mat[y][x] = line.charAt(x) == '#' ? true : false;
        }
      }

      int[] rx = {0,0,-1,1};
      int[] ry = {-1,1,0,0};
      boolean result = true;
      boolean isPossible = false;
      for(int y=0; result && y<h; y++) {
        for(int x=0; result && x<w; x++) {
          if(mat[y][x]) {
            for(int i=0; !isPossible && i<4; i++) {
              if(y+ry[i] > -1 && y+ry[i] < h && x+rx[i] > -1 && x+rx[i] < w)
                if(mat[y+ry[i]][x+rx[i]]) isPossible = true;
            }
            if(isPossible) isPossible = false;
            else {
              result = false;
              // System.out.println( y + " " + x);
            }
          }
        }
      }

      String ans = result ? "Yes" : "No";
      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

const int MAX = 100050; // change here as problems
const int MOD = 1000000007;

int64_t fac[MAX], inv[MAX], finv[MAX]; // arrays for factorial, inverse (mod p), and inverse of factorial, respectively

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

int64_t comb(int n, int k) {
    return fac[n] * finv[k] % MOD * finv[n - k] % MOD;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m; cin >> n >> m;
    if (m == 1) {
        cout << 1 << endl;
        return 0;
    }
    map<int, int> mp;
    bool update = true;
    while (update) {
        update = false;
        for (int i = 2; i <= sqrt(m) + 0.5; i++) {
            if (m % i == 0) {
                update = true;
                mp[i]++;
                m /= i;
                break;
            }
        }
        if (!update) mp[m]++;
    }
    
    int64_t ans = 1;
    table();
    for (auto &iter : mp) {
        int p = iter.second;
        ans = ans * comb(n - 1 + p, p) % MOD;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 31);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int main() {
	int n, a, b; cin >> n >> a >> b;
    ll ans = mod_pow(2, n, MOD) - 1;
    ll sum = 1,y=1; int j = 1;
    for (int i = n; i >= n-a+1; i--) {
        sum *= i; sum %= MOD;
        y *= j; j++; y %= MOD;
    }
    y = mod_pow(y, MOD - 2, MOD);
    ans =(ans - (sum * y) % MOD)%MOD;
    ans += MOD;
    sum = 1, y = 1; j = 1;
    for (int i = n; i >= n - b + 1; i--) {
        sum *= i; sum %= MOD;
        y *= j; j++; y %= MOD;
    }ans += MOD;
    y = mod_pow(y, MOD - 2, MOD);
    ans = (ans - (sum * y) % MOD) % MOD;
    cout << ans % MOD << endl;
}

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

using namespace std;

struct Node
{
	int parent = -1;
	int left;
	int right;
} node[25];

int get_sibling(int id) {
	if (node[id].parent == -1) {
		return -1;
	}
	else {
		if (node[node[id].parent].left != id) {
			return node[node[id].parent].left;
		}
		else {
			return node[node[id].parent].right;
		}
	}
}

int get_degree(int id) {
	int degree = 0;

	if (node[id].left != -1) {
		degree++;
	}
	if (node[id].right != -1) {
		degree++;
	}

	return degree;
}

int get_depth(int id) {
	if (node[id].parent != -1) {
		return get_depth(node[id].parent) + 1;
	}
	else {
		return 0;
	}
}

int get_height(int id) {
	int h1 = 0, h2 = 0;

	if (node[id].left != -1) {
		h1 = get_height(node[id].left) + 1;
	}
	if (node[id].right != -1) {
		h2 = get_height(node[id].right) + 1;
	}

	return max(h1, h2);
}

string get_type(int id) {
	if (node[id].parent == -1) {
		return "root";
	}
	else if (node[id].left == -1 && node[id].right == -1) {
		return "leaf";
	}
	else {
		return "internal node";
	}
}

int main()
{
	int n, id, left, right;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> id >> left >> right;
		node[id].left = left;
		node[id].right = right;
		node[left].parent = id;
		node[right].parent = id;
	}

	for (int i = 0; i < n; i++) {
		cout << "node " << i << ": ";
		cout << "parent = " << node[i].parent << ", ";
		cout << "sibling = " << get_sibling(i) << ", ";
		cout << "degree = " << get_degree(i) << ", ";
		cout << "depth = " << get_depth(i) << ", ";
		cout << "height = " << get_height(i) << ", ";
		cout << get_type(i) << endl;
	}

	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,m;cin>>n>>m;
    out(n*(n-1)/2+m*(m-1)/2);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main{

    public static void main(String[] args) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(reader.readLine());

        ArrayList<Integer> a = new ArrayList<>();

        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                int prod = i*j;
                a.add(prod);
            }
        }

        if(a.contains(n))
        {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 22996
void main() {
	auto S = rs;
	auto T = rs;
	ulong res;
	foreach(i; 0..S.length) {
		if(S[i] != T[i]) res++;
	}	
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

long rl() {
	return readAs!long;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 3144
#include<stdio.h>
int main()
{
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	m=(S-h*3600)/60;
	s=S-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
} 


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

int main(){
    int A,B;
    cin>>A>>B;
    if(A==1&&B==1){cout<<"Draw"<<"\n";  return 0;}
    if(A==1&&B!=1){cout<<"Alice"<<"\n"; return 0;}
    if(A!=1&&B==1){cout<<"Bob"<<"\n";   return 0;}

    if(A>B){
        cout<<"Alice"<<"\n";
    }else if(A==B){
        cout<<"Draw"<<"\n";
    }else{
        cout<<"Bob"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>

using namespace std;

#define x first
#define y second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

typedef pair<pii,pii> C;

C norm(C c) {
    return min(min(C{{c.x.y, c.y.x}, {c.y.y, c.x.x}}, C{{c.y.y,c.x.x},{c.x.y,c.y.x}}), min(c, {c.y,c.x}));
}

int get(const C&c, int i) {
    switch(i&3) {
        case 0: return c.x.x;
        case 1: return c.x.y;
        case 2: return c.y.x;
        case 3: return c.y.y;
    }
}

int rot(const C&c) {
    if (c.x == c.y) {
        if (c.x.x == c.x.y) return 4;
        else return 2;
    } else return 1;
}

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    int N; cin >> N;

    map<C, int> P;
    map<C, int> R;
    vector<C> Q;
    for (int i = 0; i < N; i++) {
        int a,b,c,d; cin >> a >> b >> c >> d;
        C x{{a,b},{c,d}};
        x = norm(x);
        P[x] += 1;
        R[x] = rot(x);
        Q.push_back(x);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        C &p = Q[i];
        P[p]--;
        for (int j = i+1; j < N; j++) {
            C &q = Q[j];
            P[q]--;
            for (int k = 0; k < 4; k++) {
                ll cur = 1;
                C u[4];
                for (int l = 0; l < 4; l++) {
                    u[l] = norm({{get(p,l+1),get(p,l)},{get(q,k-l+1),get(q,k-l)}});
                    int opts = P[u[l]];
                    if (opts <= 0) {
                        cur = 0;
                    } else {
                        cur *= opts*R[u[l]];
                    }
                    P[u[l]]--;
                }
                for (int l = 0; l < 4; l++) {
                    P[u[l]]++;
                }
                ans += cur;
            }
            P[q]++;
        }
        P[p]++;
    }

    cout << ans/3 << endl;
}


Measured memory_bytes: 80128
// {{{ input macro (thanks tanakh-san)
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}
macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}
// }}}

fn index_perm(xs: &[usize]) -> usize {
  let n = xs.len();
  let mut r = 0;
  let mut a = vec![0; n+1];

  for i in 0..n {
    let mut s = xs[i];
    let mut k = xs[i];
    while k > 0 { 
      s -= a[k];
      k = k & (k - 1);
    }
    r = (n - i) * r + s;
    let mut k = xs[i]+1;
    while k < n {
      a[k] += 1;
      k += k & (!k + 1);
    }
  }
  return r;
}

fn main() {
  input! {
    n: usize,
    p: [usize; n],
    q: [usize; n],
  };
  let p: Vec<usize> = p.iter().map(|a| a-1).collect();
  let q: Vec<usize> = q.iter().map(|a| a-1).collect();
  // println!("{:?}", p);
  // println!("{:?}", q);

  let a = index_perm(p.as_slice());
  let b = index_perm(q.as_slice());
  
  println!("{}", (a as isize - b as isize).abs());
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    double BTC = 380000.0;

    cin >> n;

    double sum = 0;
    for (int i = 0; i < n; i++) {
        double x;
        string y;
        cin >> x >> y;
        if (y == "JPY") {
            sum += x;
        } else {
            sum += (x * BTC);
        }
    }

    cout << sum;

    return 0;
}

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

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

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

int main(){
  
  int dp[5][60];
  memset(dp,0, sizeof(dp));
  dp[0][0]=1;
  
  rep(i,4){
    rep(j,60){
      rep(k,10){
        if(j-k>=0) dp[i+1][j]+=dp[i][j-k];
      }
    }
  }
  
  int n;
  while(cin>>n){
    cout<<dp[4][n]<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 2964
#include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>

using namespace std;

int main()
{
    int N;
    int data[1001][1001]={};
    cin>>N;
    string str1,str2;
    for(int i=0;i<N;i++){
        cin>>str1>>str2;
        for(int i=0;i<str1.length();i++){
            for(int j=0;j<str2.length();j++){
                if(str1[i]==str2[j]){
                    data[i+1][j+1]=data[i][j]+1;
                }else{
                    data[i+1][j+1]=data[i+1][j]>data[i][j+1]?data[i+1][j]:data[i][j+1];
                }
            }
        }
        cout<<data[str1.length()][str2.length()]<<endl;
    }
}

Measured memory_bytes: 5128
import java.time.Instant;
import java.util.*;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args){

		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] v = new int[N];
		int[] c = new int[N];

		for(int i=0; i<N; i++){
			v[i] = sc.nextInt();
		}

		for(int i=0; i<N; i++){
			c[i] = sc.nextInt();
		}

		for(int i=0; i<N; i++){
			if(v[i] > c[i]) {
				ans += v[i] - c[i];
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
 
    int main() {
        int64_t N;
        string S;
        cin >> N >> S;
        if (S.size()<=N) {
            cout << S << endl;
        }
        else if (S.size() == N+1) {
            S.at(N) = '.';
            string G = "..";
            cout << S+G << endl;
        }
        else if (S.size() == N + 2) {
            S.at(N) = '.';
            S.at(N + 1) = '.';
            char E = '.';
            cout << S+E << endl;
        }
        else if (S.size() == N + 3) {
            S.at(N) = '.';
            S.at(N + 1) = '.';
            S.at(N + 2) = '.';
            cout << S << endl;
        }

        else {
            S.at(N) = '.';
            S.at(N + 1) = '.';
            S.at(N + 2) = '.';
            string D;
            D = S.erase(N + 3);
            cout << D << endl;
        }
    }

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
    
    int R, G;
    cin >> R >> G;
    cout << G * 2 - R << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
inline int read()
{
    int x=0,k=1;char c=getchar();
    while(c<'0' || c>'9'){if(c=='-') k=0;c=getchar();}
    while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return k?x:-x;
}
map<string,int>mp;
int n,m,p,wa[100010];
bool ac[100010];
string str;
int main()
{
    n=read(),m=read();
    for(int i=0;i<m;i++)
    {
        p=read();
        cin>>str;
        if(!ac[p])
        {
            if(str=="AC") ac[p]=1;
            else wa[p]++;
            mp[str]++;
        }
    }
    for(int i=0;i<=n;i++) if(!ac[i]) mp["WA"]-=wa[i];
    printf("%d %d\n",mp["AC"],mp["WA"]);
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
 
void swap(int A[], int i, int j) 
{
    int tmp = A[j];
    A[j] = A[i];
    A[i] = tmp;
}
 
int selectionSort(int n, int A[]) //n:??????A?????????
{
    int count = 0;
    int i, j;						//i:?????´?????¨?????????,j:????°?????????¢????????°
    for (i = 0; i < n; i++) {
        int m = i;					//m:?????´?????¨???????°????,??????????????????
        for (j = i+1; j < n; j++) {		//????°?????????¢???
            if (A[m] > A[j]) {
                m = j;
            }
        }
        if (m != i) {				//????°???????????????§???????????°??????
            swap(A, i, m);
            count++;				//?????????????????????????????????
        }
    }
    return count;
}
 
int main()
{
    int i;
    int N;
    int A[100];
    scanf("%d", &N);
    for (i = 0; i < N ;i++) {
        scanf("%d", &A[i]);
    }
     
    int count = selectionSort(N, A);
    for (i = 0; i < N ;i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", count);
         
    return 0;
}

Measured memory_bytes: 1768
/*
 _     _    ___  ___  __ __ 
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,ans=0;
		cin>>n;
		ll a[n+1],b[n+1],c[n];
		rep(i,1,n+1)cin>>a[i];
		rep(i,1,n+1){cin>>b[i];ans+=b[i];}
		rep(i,1,n)cin>>c[i];
		rep(i,2,n+1)
		{
			if(a[i]==a[i-1]+1)ans+=c[a[i-1]];
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int r;
  cin>>r;

  if(r<1200){
    cout<<"ABC"<<endl;
  }else if(r<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }

  

}

Measured memory_bytes: 256
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    s = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    p = list(map(int, input().rstrip('\n').split()))
    ls = [True, False]
    a_cnt = 0
    for it in itertools.product(ls, repeat=n):
        b = True
        for i, v in enumerate(s):
            cnt = 0
            for j, vv in enumerate(v):
                if j != 0:
                    if it[vv-1]:
                        cnt += 1
            if p[i] != cnt % 2:
                b = False
                break
        if b:
            a_cnt += 1
    print(a_cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 42352
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

const int MAXD = 35;

inline bool checkCross(long long dblk1, long long dblk2) {
    if (dblk2 - dblk1 >= 3) {
        return true;
    } else {
        for (long long y = dblk1+1; y < dblk2; ++y) {
            if (y % 3 == 1) {
                return true;
            }
        }
    }
    return false;
}

inline long long getDist(long long div, long long a, long long b, long long da, long long db) {
    long long blk1 = a / div;
    long long blk2 = b / div;

    long long dblk1 = da / div;
    long long dblk2 = db / div;

    if (blk1 == blk2 && blk1%3 == 1 && checkCross(min(dblk1, dblk2), max(dblk1, dblk2))) {
        long long from = blk1 * div - 1;
        long long to = (blk1+1) * div;
        return min(abs(a-from)+abs(b-from), abs(a-to)+abs(b-to));
    }

    return abs(a-b);
}

inline long long solve(long long a, long long b, long long c, long long d) {
    long long bx = abs(a-c);
    long long by = abs(b-d);
    long long dx = bx;
    long long dy = by;
    long long div = 1;

    for (int i = 0; i < MAXD; ++i) {
        dx = max(dx, getDist(div, a, c, b, d));
        dy = max(dy, getDist(div, b, d, a, c));

        div *= 3;
    }

    return max(dx + by, bx + dy);
}

int main() {
    int Q;
    cin >> Q;

    while (Q--) {
        long long a;
        long long b;
        long long c;
        long long d;

        cin >> a >> b >> c >> d;
        cout << solve(a-1, b-1, c-1, d-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 3648
package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func NextString()string{
    sc.Scan()
    return sc.Text()
}

func NextInt ()int{
	i,e:=strconv.Atoi(NextString())
	if e != nil {
		panic(e)
	}
	return int(i)
}
func main(){
	// Your code here!
	sc.Split(bufio.ScanWords)
	r:=NextInt()
	fmt.Println(3*r*r)
    
}

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n, -1) {} // -1で初期化(負の場合をrootとし、この値で木の深さも表す)
  int root(int x) {
    if (d[x] < 0) return x; // 負の場合はroot
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y]; // -1からさらに—1していくことで、-2,-3… となり木の深さを表現
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; /* 木の深さを正の値で返す */ }
};

int main() {
  int n,m,ans=0;
  cin >> n >> m;
  vector<int> p(n);
  REP(i,n) cin >> p[i];

  UnionFind uf(n);

  REP(i,m) {
    int a,b; cin >> a >> b;
    uf.unite(a-1,b-1);
  }
  REP(i,n) {
    if (uf.same(i, p[i]-1)) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

typedef struct{
  int p,l,r;
}node;



int main(){

  int i,j,k,n,id,d,c,a;

  node T[100000];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    T[i].p = T[i].r = T[i].l = -1;

  for(i=0;i<n;i++){
    scanf("%d %d",&id,&k);

    for(j=0;j<k;j++){
      scanf("%d",&c);
      T[c].p = id;
      if(j == 0)T[id].l = c;
      else T[a].r = c;
      a = c;
    }

  }

  for(i=0;i<n;i++){
 
    a = T[i].p;
    d = 0;
    while(a != -1){
      d++;
      a = T[a].p;
    }

    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,d);
    if(T[i].p == -1)printf("root, [");
    else if(T[i].l == -1)printf("leaf, [");
    else printf("internal node, [");

    a = T[i].l;
    if(a != -1){
      printf("%d",T[i].l);
      while(T[a].r != -1){
	printf(", %d",T[a].r);
	a = T[a].r;
      }
    }

    printf("]\n");

  }

    return 0;
}

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

double a,b,x,d;
int main(){
    ios_base::sync_with_stdio(0);
    const long double PI = (acos(-1));
    cin.tie(0);
    cin>>a>>b>>x;

    if(x<=a*a*b/2){
        d=2*x/(b*a);
        d=atan(d/b)*180/PI;
        cout<<fixed<<setprecision(10)<<90.0-d;
    }

    else{
        d=(2*x)/(a*a)-b;
        d=b-d;
        cout<<fixed<<setprecision(10)<<atan(d/a)*180/PI;
    }



}

Measured memory_bytes: 512
import Control.Applicative
import Control.Monad

main = do
    n <- readLn
    if n == 0
       then return ()
       else do
           cards <- map (map read.words)<$>replicateM n getLine :: IO [[Int]]
           putStrLn $ unwords.map show.foldl countPoint [0,0] $ cards
           main

countPoint :: [Int] -> [Int] -> [Int]
countPoint [a,b] [a1,b1]
  | a1 > b1 = [a + a1+b1, b]
  | a1 < b1 = [a, b + a1+b1]
  | a1 == b1 = [a+a1, b+b1]

Measured memory_bytes: 8112
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <limits>

using namespace std;

#ifndef debug_on
#define debug_on 0
#endif

#define dbg \
    if(debug_on) cerr << "DEBUG:"
#define ast(cond)           \
    do {                    \
        if((cond) == false) \
        {                   \
            if(debug_on)    \
            cerr << "ASSERT" << #cond " failed at line:" << __LINE__ << endl;   \
            exit(1);        \
        }                   \
    }while(0)


const int MAX_N = 2 * 100000 + 3;
int64_t N;
int A[MAX_N];

int main(int, char *[])
{
    cin >> N;
    for(int i = 1; i <= N; ++i)
        cin >> A[i];

#if 0
    const int64_t sum = accumulate(A + 1, A + N + 1, 0LL);
    const double p = 1.0 * sum / N -  (N+1.0) / 2.0;

    const int b_min = floor(p);
    const int b_max = ceil(p);

    dbg << "sum:" << sum << " p:" << p << " min:" << b_min << " b_max:" << b_max << endl;

    int64_t min_sum = numeric_limits<int64_t>::max();
    for(int b = b_min-100; b <= b_max+100; ++b)
    {
        int64_t sum = 0;
        for(int i = 1; i <= N; ++i)
        {
            sum += abs(A[i] - (b + i));
        }
        min_sum = min(min_sum, sum);
        dbg << "B:" << b << " " << sum << endl;
    }
    cout << min_sum << endl;
#else
    vector<int> B(N+1);
    for(int i = 1; i <= N; ++i)
        B[i] = A[i] - i;

    sort(B.begin()+1, B.end());
    int64_t min_sum = numeric_limits<int64_t>::max();
    for(int b_idx = 0 + N / 2; b_idx <= 1 + (N+1)/2; ++b_idx)
    {
        const int b = B[b_idx];
        int64_t sum = 0;
        for(int i = 1; i <= N; ++i)
        {
            sum += abs(A[i] - (b + i));
        }
        min_sum = min(min_sum, sum);
        dbg << "B:" << b << " " << sum << endl;
    }
    cout << min_sum << endl;
#endif

    return 0;
}


Measured memory_bytes: 1792
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int a,b,c,d,f=0;
    cin>>a>>b>>c>>d;
    for(int i=0;i<N;i++)
    {
        if(i%2==0)
        {
            c-=b;
            if(c<=0)
            {
                f=1;
                break;
            }
        }
        else
        {
            a-=d;
            if(a<=0)
            break;
        }
    }
    if(f==1)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3596
n, l = map(int, input().split())
total = 0
for i in range(1, n + 1):
    total += l + i - 1

ret = float('inf')
index = None
for i in range(1, n + 1):
    if ret > abs(total - (total - (l + i - 1))):
        ret = abs(total - (total - (l + i - 1)))
        index = i
print(total - (l + index - 1))


Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
from heapq import heappop,heappush
hq=[]
n,k=map(int,input().split())
for i in range(n):
	t,d=map(int,input().split())
	heappush(hq,(-d,t))
D=0
dic={}
got=[]
for i in range(k):
	r=heappop(hq)
	got.append(r)
	if r[1] in dic:
		dic[r[1]]+=1
	else:
		dic[r[1]]=1
	D+=-r[0]
ans=D+len(dic)**2

while hq:
	while got:
		p=got.pop()
		if dic[p[1]]>1:
			dic[p[1]]-=1
			D-=-p[0]
			break
	if len(got)==0:
		print(ans)
		exit()

	r=heappop(hq)
	got.append(r)
	if r[1] in dic:
		dic[r[1]]+=1
	else:
		dic[r[1]]=1
	D+=-r[0]	
	ans=max(D+len(dic)**2,ans)
print(ans)


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

int main() {
    int N, x;
    cin >> N >> x;

    int a[10000];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(a, a+N);
    int count = 0;

    for(int i = 0; i < N; i++) {
        if(x > 0) {
            x -= a[i];
            count++;
        }      
    }
    
    if(x == 0) {
        cout << count << endl;
    } else {
        cout << count - 1 << endl;
    }
    
}

Measured memory_bytes: 3624