akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    for (;;) {
        int n;
        cin >> n;
        if (0 == n) {
            break;
        }
        int try_num = n / 4;
        int total = 0;
        int tmp;
        for (int i = 0; i < try_num; ++i) {
            cin >> tmp;
            total += tmp;
        }
        cout << total << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <stdio.h>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;
#define NUM (400000)

struct BIT {
    static const int N = NUM;
    Int x[N];
    void add(int k, Int a) {
        for (; k<N; k|=k+1) x[k] += a;
    }
    Int sum(int k) {
        Int s = 0;
        for (; k>=0; k=(k&(k+1))-1) s += x[k];
        return s;
    }
} A, B;

int n, Q;
vector<int> g[NUM], p[NUM];
int _i, x[NUM], y[NUM], h[NUM], r[NUM], sz[NUM];

/*
void rec(int at, int pre) {
    if (pre != -1) {
        p[at].push_back(pre);
        for (int ch = 1, k = 0; ch*2 <= h[at]; ch *= 2, k++) {
            p[at].push_back(p[p[at][k]][k]);
        }
    }
    x[at] = _i++;
    rep (i, g[at].size()) {
        h[g[at][i]] = h[at] + 1;
        rec(g[at][i], at);
    }
    y[at] = _i;
}
*/
void build() {
    for (int i = n-1; i >= 0; i--) {
        sz[i]++;
        sz[r[i]] += sz[i];
    }
    rep (at, n) {
        if (at) {
            p[at].push_back(r[at]);
            for (int ch = 1, k = 0; ch*2 <= h[at]; ch *= 2, k++) {
                p[at].push_back(p[p[at][k]][k]);
            }
        }
        int t = x[at] + 1;
        rep (i, g[at].size()) {
            int to = g[at][i];
            h[to] = h[at] + 1;
            x[to] = t;
            t += sz[to];
        }
        y[at] = t;
    }
}

int get(int at, int h) {
    if (h == 0) return at;
    int ch = 1, k = 0;
    while (ch*2 <= h) ch*=2, k++;
    return get(p[at][k], h-ch);
}

int common(int a, int b) {
    if (h[a] < h[b]) swap(a, b);
    if (get(a, h[a]-h[b]) == b) return b;
    int l = 0, r = h[b];
    while (r-l > 1) {
        const int mid = (l+r)/2;
        if (get(a, h[a]-mid) == get(b, h[b]-mid)) l = mid;
        else r = mid;
    }
    return get(a, h[a]-l);
}


/*
int common(int u, int v) {
    if (h[u] > h[v]) swap(u, v);
    while (x[v] < x[u] || y[u] <= x[v]) {
//        printf("%d\n", u);
        u = r[u];
    }
    return u;
}
*/

void add(int v, int a) {
    A.add(x[v], a);
    A.add(y[v], -a);
    B.add(x[v], -a * h[v]);
    B.add(y[v], a * h[v]);
}

Int f(int v) {
    return A.sum(x[v]) * h[v] + B.sum(x[v]);
}

Int solve(int u, int v) {
    int g = common(u, v);
    Int t = f(g);
//    printf("%d: %lld\n", u, f(u));
//    printf("%d: %lld\n", v, f(v));
//    printf("%d: %lld\n", g, f(g));
    return f(u) - t + f(v) - t;
}

int main() {
    scanf("%d%d", &n, &Q);
    rep (i, n-1) {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        r[b] = a;
    }
//    rec(0, -1);
    build();
//    rep (i, n) printf("%d, %d, %d, %d\n", i, x[i], y[i], d[i]);
    rep (_, Q) {
        int t, u, v;
        scanf("%d%d%d", &t, &u, &v);
//        printf("%d, %d, %d\n", t, u, v);
        if (t == 0) printf("%lld\n", solve(u, v));
        else add(u, v);
    }
    return 0;
}

Measured memory_bytes: 80880
N,Q=map(int,input().split())
L=[[]for i in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
    
S=[0 for i in range(N+1)]
for i in range(Q):
    p,x=map(int,input().split())
    S[p]+=x
    
ANS=[-1 for i in range(N+1)]
ANS[1]=S[1]
l=[]
for i in L[1]:
    l.append([i,1,S[1]])
    
for i in range(N-1):
    X=l[i][0]
    Y=l[i][1]
    Z=l[i][2]
    ANS[X]=Z+S[X]
    for j in L[X]:
        if ANS[j]<0:
            l.append([j,X,ANS[X]])
print(*ANS[1:])
        
    

Measured memory_bytes: 122656
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}


vector<vector<int>> adj(MAXN);

LL max(LL a, LL b){
	return a>b?a:b;
}

int n;
vector<LL> v;
int an[MAXN];
vector <int> lc;

void dfs(int u,int p){
	auto x = lower_bound(all(lc), v[u]) - lc.begin();
	int	ch = x;
	int val = lc[x];
	lc[x] = v[u];
	an[u] = lower_bound(all(lc), INT_MAX) - lc.begin();
	for(auto i:adj[u]){
		if(i!=p){
			dfs(i,u);
		}
	}
	lc[x] = val;
}

int main(){
  fio();
  cin>>n;
  set<LL> s;
  forn(i,n) {
  	int x; cin>>x;
  	v.pb(x);
  }
  lc.resize(n+1);
  forn(i,n+1) lc[i] = INT_MAX;
  forn(i,n-1){
  	int u, x; cin>>u>>x;
  	u--, x--;
  	adj[x].pb(u);
  	adj[u].pb(x);
  } 
  dfs(0,-1);
  forn(i,n) cout<<an[i]<<endl;

  return 0;
}


Measured memory_bytes: 28728
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
int main(){
    long double n,k,result=0;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
    	if(k>i)
    	result=result+(long double)(1/n)*(long double)pow(0.5,ceil(log2((long double)(k/i))));
    	else{
    		result=result+(long double)(1/n)*(long double)(n-i+1);
    		break;
		}
	}
	cout<<setprecision(12)<<(long double)result;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] abc = scanner.nextLine().split(" ", 3);
        int a = Integer.parseInt(abc[0]);
        int b = Integer.parseInt(abc[1]);
        int c = Integer.parseInt(abc[2]);

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


Measured memory_bytes: 21844
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> b = a;
  sort(rall(b));
  int mx = b[0];
  int mx2 = b[1];

  rep(i, n) {
    if (a[i] == mx) {
      print(mx2);
    } else {
      print(mx);
    }
  }

  return 0;
}

Measured memory_bytes: 3200
#include<stdio.h>
int i,N[7],T,F,R,t;
char S[105];
int main()
{
	for(i=1;i<=6;i++)scanf("%d",N+i);
	gets(S);
	gets(S);
	for(T=1,F=2,R=3,i=0;S[i];i++)
	{
		switch(S[i])
		{
		case 'N':t=T,T=F,F=7-t;break;
		case 'E':t=R,R=T,T=7-t;break;
		case 'S':t=F,F=T,T=7-t;break;
		case 'W':t=T,T=R,R=7-t;break;
		}
	}
	printf("%d\n",N[T]);
	return 0;
}

Measured memory_bytes: 600
from sys import stdin

class Node(object):
    def __init__(self, parent=None, left=None, right=None):
        self.parent = parent
        self.left = left
        self.right = right

def print_nodes(nodes, n):
    A = []
    B = []
    C = []
    def walk_tree(nodes, u):
        if u == -1:
            return
        r = nodes[u].right
        l = nodes[u].left
        nonlocal A
        A.append(u)
        walk_tree(nodes, l)
        B.append(u)
        walk_tree(nodes, r)
        C.append(u)

    for i in range(n):
        if nodes[i].parent == None:
            walk_tree(nodes, i)
            print("Preorder", end="\n ")
            print(*A, sep=" ")
            print("Inorder", end="\n ")
            print(*B, sep=" ")
            print("Postorder", end="\n ")
            print(*C, sep=" ")

def read_binary_tree(nodes, n):
    for _ in range(n):
        i = [int(i) for i in stdin.readline().strip().split()]
        nodes[i[0]].left = i[1]
        nodes[i[0]].right = i[2]
        if i[1] != -1:
            nodes[i[1]].parent = i[0]
        if i[2] != -1:
            nodes[i[2]].parent = i[0]

n = int(input())
nodes = [Node() for _ in range(n)]
read_binary_tree(nodes, n)
print_nodes(nodes, n)


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<bool> a(n);
	rep(i, k) {
		int d;
		cin >> d;
		rep(j, d) {
			int t;
			cin >> t;
			t--;
			a[t] = true;
		}
	}
	int ans = 0;
	rep(i, n) {
		if(a[i] == false) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#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,R;
  cin >> N >> R;
  
  if(N<10){
    cout << R + (100*(10-N)) << endl;
  }else{
    cout << R << endl;
  }
}


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

int main() {

    std::string str;

    for ( ;; ) {

        std::cin >> str;

        if ( str == "0" ) break;

        int sum = 0;

        for ( int i = 0; i < str.size(); i++ ) {

            sum += str[i] - '0';
        }

        std::cout << sum << std::endl;
    }

    return 0;
}



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

int main(void){
	int h,w,i,j;
	
	while(scanf("%d %d", &h, &w),h || w){
		for(i=0; i<h; i++){
			for(j=0; j<w; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()

def mod_nCr(n,k,mod):
    r = min(k,n-k)
    return fact[n]*factinv[k]*factinv[n-k]%mod

mod = 10**9+7
fact = [1,1]
inv = [0,1]
factinv = [1,1]
for i in range(2,n+1):
    fact.append(fact[-1]*i%mod)
    inv.append((-inv[mod%i]*(mod//i))%mod)
    factinv.append((factinv[-1]*inv[-1])%mod)
    
ans = 0
for i in range(k-1,n)[::-1]:
    ans += a[i]*mod_nCr(i,k-1,mod)
    ans %= mod
a.reverse()
for i in range(k-1,n)[::-1]:
    ans -= a[i]*mod_nCr(i,k-1,mod)
    ans %= mod
print(ans%mod)

Measured memory_bytes: 77476
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto A = iota(N).map!(_ => readln.split.map!(to!long).array).array;
    A.sort!"a[1] < b[1]";

    long t = 0;
    foreach (a; A) {
        if (t + a[0] > a[1]) {
            writeln("No");
            return;
        }
        t += a[0];
    }

    writeln("Yes");
}

Measured memory_bytes: 13308
#include<stdio.h>
#define MOD 1000000009+7

int main(){
	int N,i;
	scanf("%d",&N);
	long long a[N];
	long long ans=0;
	for(i=0;i<N;i++){
		scanf("%lld",&a[i]);
		ans+=a[i]-1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, n, x, y;
  in3(n, x, y);
  x--;
  y--;
  vector<ll> c(n - 1, 0);
  rep(i, n){
    rep2(j, i + 1, n){
      a = min(abs(j - i), abs(i - x) + 1 + abs(j - y));
      a--;
      c[a]++;
    }
  }
  rep(i, n - 1){
    out(c[i]);
    memi;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

#define min(a, b) (a < b? a : b)

int main(void){
  int N = 0;//人数
  int A = 0;//電車(1人あたり)
  int B = 0;//タクシー N人
  scanf("%d %d %d", &N, &A, &B);
  
  int ans = min(A * N, B);
  printf("%d", ans);
}

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

int N;
vector<int> a;
vector<bool> visited;

int main() {
	cin >> N;	
	a.resize(N + 1);
	visited.resize(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
		visited[i] = false;
	}

	int current = 1;
	int answer = 1;
	
	while (true) {
		visited[current] = true;
		current = a[current];
		if (current == 2) {
			cout << answer << endl;
			return 0;
		} else if (visited[current]) {
			cout << -1 << endl;
			return 0;
		} else {
			answer++;
		}
	}
}

Measured memory_bytes: 640
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  long X;
  scanln(X);


  foreach(i; 0..1000+1) {
    long l = 0;
    long r = 5*i;
    if (i*100 + l <= X && X <= i*100 + r) {
      1.writeln;
      return;
    }
  }
  0.writeln;
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (t * y < x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (t * y > x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
  static if (__VERSION__ >= 2071) {
    readf!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "readf(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<int> a(n);
	int sum = 0;
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	
	int res = 0;
	for(int i = 0; i < n; ++i) {
		if( sum <= 4 * m * a[i] ) res++;
	}
	
	if( m <= res ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)

int r,g,b,N;


int main(){
  int ans=0;
  cin >> r >> g>>b>>N;
  
  int nr,ng;
  REP(i,3001){
    nr=N-r*i;
    if (nr<0){break;}
    REP(j,3001){
      ng=nr-g*j;
      if (ng<0){break;}
      if (ng%b==0){//割り切れるなら
        ans+=1;
      }
    }
  }
  

  cout<<ans<<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) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		double L = (double) Integer.parseInt(W.split(" ")[0]);

		System.out.println(Math.pow(L/3,3));

	}

}


Measured memory_bytes: 20948
n = int(input())
a = list(map(int, input().split()))
count = 0

for i in a:
    if i % 2 ==0:
        if i % 3 != 0 and i % 5 != 0:
            count+= 1


if count >= 1:
    print("DENIED")
else:
    print("APPROVED")


Measured memory_bytes: 61920
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    int ainv[n];
    for (int i=1, a; i<=n; i++) {
        cin >> a;
        a--;
        ainv[a] = i;
    }
    for (auto ai:ainv) cout << ai << ' ';
    cout << '\n';
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>          // printf(), scanf()

#define MAX_V 15
#define min(a, b) ((a) < (b) ? (a) : (b))

static const int INF = 1000000000;

int d[MAX_V][MAX_V];
int dp[1 << MAX_V][MAX_V];
int V;

int
solve()
{
	int S, u, v;
	int e;

	e = 1 << V;
	for (S = 0; S < e; ++S)
	{
		for (v = 0; v < V; ++v)
			dp[S][v] = INF;
	}

	dp[e - 1][0] = 0;
	for (S = e - 2; S >= 0; --S)
	{
		for (v = 0; v < V; ++v)
		{
			for (u = 0; u < V; ++u)
			{
				if (!(S >> u & 1))
				{
					int t = dp[S | (1 << u)][u] + d[v][u];
					dp[S][v] = min(dp[S][v], t);
				}
			}
		}
	}

	return dp[0][0];
}

int
main(int argc, char** argv)
{
	int E;
	int s, t, c;
	int i, j;

	scanf("%d %d", &V, &E);
	for (i = 0; i < V; ++i)
	{
		for (j = 0; j < V; ++j)
		{
			if (i == j)
				d[i][j] = 0;
			else
				d[i][j] = INF;
		}
	}

	for (i = 0; i < E; ++i)
	{
		scanf("%d %d %d", &s, &t, &c);
		d[s][t] = c;
	}


	int res = solve();
	if (res == INF)
		res = -1;

	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 2520
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 br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0,v=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][v-1] = 1;
        }
      }

      StringBuilder buf = new StringBuilder(n*n*2);
      for (int[] vertex : graph) {
        for (int v : vertex) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }
}


Measured memory_bytes: 25364
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	int AB = A * B;
	int CD = C * D;
	if (AB > CD) {
		cout << AB << endl;
	}
	else {
		cout << CD << endl;
	}
}


Measured memory_bytes: 256
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()

        spl := intSprit(line)
        N := spl[0]
        K := spl[1]

        nums := []int{}
        enums := []int{}
        for i := 1; i <= N; i++ {
                if i%K == 0 {
                        nums = append(nums, i)
                }
                if K%2 == 0 {
                        if i%K == K/2 {
                                enums = append(enums, i)
                        }
                }
        }

        c := len(nums) * len(nums) * len(nums)
        c += len(enums) * len(enums) * len(enums)

        fmt.Println(c)
}



Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int> >;
using vii = vector<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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

string s, t;

bool match(int d) {
	rep(j, t.size()) {
		if (s[d + j] != t[j] && s[d + j] != '?') {
			return false;
		}
	}
	return true;
}

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

	int minD = -1;

	rep(i, s.size() - t.size() + 1) {
		if (match(i)) minD = i;
	}

	if (minD == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	string ans;

	rep(i, s.size()) {
		if (minD <= i && i < minD + t.size()) ans += t[i - minD];
		else if (s[i] == '?') ans += 'a';
		else ans += s[i];
	}
	cout << ans << endl;
}

/*
?huge????ho??geheg?
huge
*/

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define fst first
#define snd second

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

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(17);

  int x, y;
  cin >> x >> y;
  cout << x + y/2 << "\n";

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>


int main(int argc, char *argv[])
{
  int h = 0;
  int m = 0;
  int s = 0;

  fscanf(stdin, "%d", &s);

  h = s / 3600;
  m = (s - 3600*h) / 60;
  s %= 60;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}



Measured memory_bytes: 2112
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;

int n,m;
double x[1000],y[1000],z[1000];
double tx,ty,tz,ar;

double dot(double ax,double ay,double az,
           double bx,double by,double bz){
  return ax*bx+ay*by+az*bz;
}

int calc(double sx,double sy,double sz){
  double S=sqrt(sx*sx+sy*sy+sz*sz);
  double T=sqrt(tx*tx+ty*ty+tz*tz);
  double Cos = dot(tx,ty,tz,sx,sy,sz)/T/S;
  double ti=acos(Cos);

  if(ti < ar + 0.00000001 ){
    return 1;
  }else{
    return 0;
  }
}
bool flg[1000];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      flg[i]=false;
      cin>>x[i]>>y[i]>>z[i];
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>tx>>ty>>tz>>ar;
      for(int j=0;j<n;j++){
        if(calc(x[j],y[j],z[j]))flg[j]=true;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)ans+=flg[i];
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3496
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def max_heapify(index):
    left, right, largest = 2 * index, 2 * index + 1, -1

    if left <= array_length and array[left] > array[index]:
        largest = left
    else:
        largest = index

    if right <= array_length and array[right] > array[largest]:
        largest = right

    if largest != index:
        array[index], array[largest] = array[largest], array[index]
        max_heapify(largest)

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    # assert len(array) == array_length

    array.insert(0, None)
    for j in range(array_length // 2, 0, -1):
        max_heapify(j)
    print('', *array[1:])

Measured memory_bytes: 62252
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));
int N,M,R;
int G[201][201];
void warshall(){
	eFOR(i,1,N){
		eFOR(j,1,N){
			eFOR(k,1,N){
				G[j][k]=min(G[j][k],G[j][i]+G[i][k]);
			}
		}
	}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	REP(i,201){
		REP(j,201)G[i][j]=INF;
	}
	cin>>N>>M>>R;
	VI r(R);
	REP(i,R)cin>>r[i];
	REP(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		G[a][b]=c;
		G[b][a]=c;
	}
	int ans=INF;
	warshall();
	SORT(r);
	do {
    	int cnt=0;
		REP(i,R-1)
			cnt+=G[r[i]][r[i+1]];
		ans=min(ans,cnt);
	 }while (std::next_permutation(r.begin(), r.end()));
	
	cout<<ans<<endl;
	
	return 0;
}




















Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD =1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[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;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit(); 
  int n,k,ans=0;
  cin>>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++){
 	 cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
      ans=(ans+a[i]*(COM(i,k-1)-COM(n-i-1,k-1)))%MOD;
      
  }
  cout<<ans;
}  

Measured memory_bytes: 12544
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long A, D, N;
	while (cin >> A >> D >> N) {
		if (A == 0 && D == 0 && N == 0) return 0;
		int COUNT = 0;
		for (; ;) {
			bool check = true;
			if (A <= 1) check = false;
			for (long long i = 2; i * i <= A; i++) {
				if (A % i == 0) {
					check = false;
					break;
				}
			}
			if (check) COUNT++;
			if (COUNT == N) {
				cout << A << endl;
				break;
			}
			A += D;
		}
	}
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
int beki(int wa,int rr,int warukazu) {
	if(rr==0) return 1;
	if(rr==1) return wa%warukazu;
	wa%=warukazu;
	if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
	ll zx=beki(wa,rr/2,warukazu);
	return (zx*zx)%warukazu;
}
int n;
int dp[310][91001]= {};
int dp2[310][90010]= {};
signed main() {
	int mod=998244353;
	int n;
	cin>>n;
	int s=0;
	dp[0][0]=1;
	dp2[0][0]=1;
	for(int i=0; i<n; i++) {
		int y;
		cin>>y;
		s+=y;
		for(int j=0; j<=90000; j++)if(dp[i][j]) {
				dp[i+1][j+y]+=dp[i][j];
				dp[i+1][j+y]%=mod;
				dp[i+1][j]+=2*dp[i][j]%mod;
				dp[i+1][j]%=mod;
			}
		for(int j=0; j<=90000; j++)if(dp2[i][j]) {
				dp2[i+1][j+y]+=dp2[i][j];
				dp2[i+1][j+y]%=mod;
				dp2[i+1][j]+=dp2[i][j];
				dp2[i+1][j]%=mod;
			}
	}
	int g=(s+1)/2;
	int t1=0;
	for(int i=g; i<=s; i++) {
		t1+=dp[n][i];
		t1%=mod;
	}
	int t2=0;
	if(s%2==0) {
		t2=dp2[n][s/2];
	}
	int dame=(mod+t1-t2)*3%mod;
	int zen=beki(3,n,mod);
	cout<<(zen-dame+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 426240
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[200011];

void MAIN() {
    scanf("%d", &N);
    REP (i, 2*N-1) scanf("%d", A+i);
    int center = N-1;
    int lo = 1, hi = 2*N-1;
    while (hi - lo > 1) {
	int mid = (hi + lo) / 2;

	bool res = (mid <= A[center]);
	if (N % 2 == 0) res = !res;
	REP (k, N-1) {
	    bool b0 = mid <= A[center-k-1];
	    bool b1 = mid <= A[center-k];
	    bool c0 = mid <= A[center+k];
	    bool c1 = mid <= A[center+k+1];
	    if (b0 == b1) {
		res = b0;
		break;
	    } else if (c0 == c1) {
		res = c0;
		break;
	    }
	}

	(res? lo: hi) = mid;
    }

    printf("%d\n", lo);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
U=10**5
is_prime=[True]*(U+1)
is_prime[0]=False
is_prime[1]=False
for p in range(2,U+1):
    if p*p>U:
        break
    if is_prime[p]:
        for j in range(p*p,U+1,p):
            is_prime[j]=False

is_2017like=[0]*(U+1)
for p in range(1,U+1):
    if (p+1)//2>U:
        break
    tmp=(is_prime[p] and is_prime[(p+1)//2])
    is_2017like[p]=is_2017like[p-1]+tmp
    
for i in range(int(input())):
    l,r=map(int,input().split())
    ans=is_2017like[r]-is_2017like[l-1]
    print(ans)


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

using namespace std;

int main() {
	string abc = "abcdefghijklmnopqrstuvwxyz";
	string s;
	cin >> s;
	if (s.size() == 26) {
		reverse(s.begin(), s.end());
		int nabc[26] = { 0 };
		string ans = "-1";
		for (int i = 0; i < s.size(); i++) {
			for (int j = s[i]-'a'; j < 26; j++) {
				if (nabc[j] == 1) {
					ans = abc[j] + s.substr(i + 1);
					reverse(ans.begin(), ans.end());
					break;
				}
			}
			if (ans != "-1") {
				break;
			}
			else {
				nabc[s[i] - 'a'] = 1;
			}
		}
		cout << ans << endl;
	}
	else {
		int nabc[26] = { 0 };
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < abc.size(); j++) {
				if (s[i] == abc[j]) {
					nabc[j] = 1;
				}
			}
		}
		for (int i = 0; i < abc.size(); i++) {
			if (nabc[i] == 0) {
				s += abc[i];
				break;
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

seq = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())

print(seq[K-1])


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

using namespace std;


int main() {
#ifdef LOCAL
    freopen("atcoder/3/input.txt", "r", stdin);
#endif

    int n, l;
    cin >> n >> l;

    vector<string> vec(n);
    for (int i = 0; i < n; ++i) {
        cin >> vec[i];
    }

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

    string res;
    res.reserve(n * l);

    for (const auto& s : vec) {
        res += s;
    }

    cout << res << "\n";

    return 0;
}











Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
typedef pair<int, int> P;

int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n>k) out(k*x+(n-k)*y);
    else out(n*x);
}


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

using namespace std;
const int maxn = 1e5 + 5;
char S[maxn], T[maxn];
int sum_s[maxn], sum_t[maxn];
int main() {
#ifdef LDT
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    cin >> (S + 1) >> (T + 1) >> q;
    int n = strlen(S + 1), m = strlen(T + 1);
    for (int i = 1; i <= n; ++i)
        sum_s[i] = sum_s[i - 1] + (S[i] == 'A' ? +1 : -1);
    for (int i = 1; i <= m; ++i)
        sum_t[i] = sum_t[i - 1] + (T[i] == 'A' ? +1 : -1);
    
    for (int i = 1; i <= q; ++i) {
        int u, v, l, r;
        cin >> u >> v >> l >> r;
        int s1 = sum_s[v] - sum_s[u - 1];
        int s2 = sum_t[r] - sum_t[l - 1];
        s1 %= 3;
        s2 %= 3;
        s1 += 3;
        s2 += 3;
        if (s1 % 3 == s2 % 3)
            cout << "YES\n";
        else 
            cout << "NO\n";
    }
    return 0;
}

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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
ll a;
  cin >> a;
  return a;
}

vi sub(vector<bool> fin,ll n) {
  vi ret;
  REP(i,n) {
    if(fin.at(i))continue;
    vector<bool> cp = fin;
    cp.at(i) = true;
    vi result = sub(cp,n);
    ret.insert(ret.end(),result.begin(),result.end());
  }
  return ret;
}

int main() {
  ll n,m=INF,ans=0;
  cin >> n;
  REP(i,n){
    ll p;
    cin >> p;
    if(p<=m)ans++;
    m = min(p,m);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
typedef pair<int, int> pii;

//unionFind
class unionFind {
private:
	int* p;   //親配列のポインタ
	int* rank;
	int N;   //要素数
public:
	unionFind(int);   //コンストラクタ
	int parent(int);   //親要素を返す
	void unit(int, int);   //2要素をつなぐ
	int operator[](int);   //parentの省略形
	~unionFind();
	int size();   //要素数を返す
};

unionFind::unionFind(int n) {
	N = n;
	p = new int[N];
	rank = new int[N];
	for (int i = 0; i < N; i++) {
		p[i] = i;
		rank[i] = 0;
	}
	return;
}

int unionFind::parent(int n) {
	if (n < 0 || n >= N)return -1;
	if (p[n] == n)return n;   //自分が一番上の親
	return p[n] = parent(p[n]);   //つなぎ直しと上にたどる操作
}

int unionFind::operator[](int n) {
	return parent(n);
}

void unionFind::unit(int x, int y) {
	x = parent(x), y = parent(y);
	if (x == y)return;   //根が同じだから何もせずに帰る
	if (rank[x] < rank[y])p[x] = y;
	else {
		p[y] = x;
		if (rank[x] == rank[y])rank[x]++;
	}
	return;
}

unionFind::~unionFind() {
	delete(p);
	delete(rank);
	return;
}

int unionFind::size() {
	return N;
}

int N;
vector<pii> points;
vector<bool> checked;
set<int> samey[100001];
vector<set<int>> xcount;
vector<int> parentcount;

void solve() {
	cin >> N;
	points.resize(N);
	checked.resize(N, false);
	xcount.resize(100001);
	//memset(xcount, 0, 100001);
	parentcount.resize(100001, 0);
	for (int n = 0; n < N; n++) {
		cin >> points[n].first >> points[n].second;
		samey[points[n].second].insert(n);

	}
	unionFind uf(100001);
	for (int n = 0; n < N; n++) {
		if (checked[n])continue;
		checked[n] = true;
		for (auto itr = samey[points[n].second].begin(); itr != samey[points[n].second].end(); itr++) {
			uf.unit(points[*itr].first,points[n].first);
			checked[*itr] = true;
		}
	}
	for (int n = 0; n < N; n++) {
		xcount[uf.parent(points[n].first)].insert(points[n].second);
	}
	for (int x = 1; x <= 100000; x++) {
		parentcount[uf[x]]++;
	}
	long long sum = 0;
	for (int x = 1; x <= 100000; x++) {
		if (xcount[x].size() != 0)sum += xcount[x].size() * parentcount[x];
	}
	cout << sum - N << endl;
	return;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
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 (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,M;cin >> N >> M;
    vector<int> a(M);
    rep(i,M)cin >> a[i];

    int dp[100010] = {0};
    dp[0] = 1;
    rep(i,M){
        dp[a[i]] = -1;
    }

    rep(i,100001){
        if(dp[i+1] != -1 && dp[i] != -1){
            dp[i+1] += dp[i];
            dp[i+1] %= MOD;
        }
        if(dp[i+2] != -1 && dp[i] != -1){
            dp[i+2] += dp[i];
            dp[i+2] %= MOD;
        }
    }

    cout << dp[N] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define ll long long
#define MAX 100000

using namespace std;

int n,m;
int a[100010];
int ha[100010];
char s[100010];

int main()
{
  //  freopen("in.txt","r",stdin);
    cin>>n;
    int re=0;
    int x=0;
    int f=0;
    lp(i,n)
    {
        cin>>x;
        if(i==x) a[i]=1;
    }
    int ji=0;
    lp(i,n)
    {
        if(a[i]==1)
        {
            ji++;
        }
        else
        {
            re+=(ji+1)/2;
            ji=0;
        }
    }
    re+=(ji+1)/2;
    cout<<re<<endl;
    return 0;
}


Measured memory_bytes: 640
N, K = [int(x) for x in input().split()]
A_lst = [int(x) for x in input().split()]
dict = {}
for i in A_lst:
    if not i in dict:
        dict[i] = 1
    else:
        dict[i] += 1

lst = []
for i in dict.keys():
    lst.append(dict[i])
lst.sort()
k = len(lst)
cnt = 0

for i in lst:
    if k <= K:
        break
    else:
        k -= 1
        cnt += i

print(cnt)


Measured memory_bytes: 32520
#include <iostream>
#define int64 long long int
using namespace std;
const int mod = 1e9+7;
int arr[100];
int main(){
    int n , ret = 0 , p;
    scanf("%d",&n);
    int64 x ;
    for(int i=1;i<=n;i++){
        scanf("%lld",&x);
        p=1;
        for(int j=0;j<62;j++){
            arr[j] += x&1;
            ret += (1LL * p * (x&1 ? i-arr[j] : arr[j]) )%mod ;
            ret %= mod ;
            p = (1LL * 2 * p)%mod ;
            x>>=1;
        }
    }
    printf("%d\n",ret);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int X;
	cin>>X;
	if (X>=400 && X<=599){
		cout<<8<<endl;
	}else if (X>=600 && X<=799){
		cout<<7<<endl;
	}else if (X>=800 && X<=999){
		cout<<6<<endl;
	}else if (X>=1000 && X<=1199){
		cout<<5<<endl;
	}else if (X>=1200 && X<=1399){
		cout<<4<<endl;
	}else if (X>=1400 && X<=1599){
		cout<<3<<endl;
	}else if (X>=1600 && X<=1799){
		cout<<2<<endl;
	}else if (X>=1800 && X<=1999){
		cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3180
package main

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

func main() {
	N := nextInt()

	A := make(conf, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt64()
	}
	sort.Sort(A)

	ans := int64(0)

	for i := 0; i < N-1; i++ {
		ans += A[(i+1)/2]
	}

	fmt.Println(ans)
}

type conf []int64

func (a conf) Len() int           { return len(a) }
func (a conf) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a conf) Less(i, j int) bool { return a[i] > a[j] }

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 6432
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];
bool prime[55560];

vi vec;
void hurui(){
  clr(prime,false);
  for(int i = 2;i <= 55555;i++){
    if(vec.sz > 60)break;
    if(prime[i] == false){
      if(i % 5 == 1)vec.pb(i);
      for(int j = 1;j * i <= 55555;j++)prime[i*j] = true;
    }
  }
}

int main(){
  cin >> n;
  hurui();
  rep(i,0,n){
    cout << vec[i];
    if(i == n-1)break;
    cout << " ";
  }
  puts("");
  return 0;
}

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

namespace ABC079
{
    public class QuestionC
    {
        public static void Main(string[] args)
        {
            var abcd = Console.ReadLine().Select(i => (int)i - 48).ToArray();
            var (a, b, c, d) = (abcd[0], abcd[1], abcd[2], abcd[3]);

            var ops = new (bool op1, bool op2, bool op3)[8]
            {
                (false, false, true),
                (false, false, false),
                (false, true, true),
                (false, true, false),
                (true, false, true),
                (true, false, false),
                (true, true, true),
                (true, true, false)
            };

            foreach (var op in ops)
            {
                var result = Calculate(Calculate(Calculate(a, op.op1, b), op.op2, c), op.op3, d);
                if (result == 7)
                {
                    var op1 = op.op1 ? '+' : '-';
                    var op2 = op.op2 ? '+' : '-';
                    var op3 = op.op3 ? '+' : '-';
                    Console.WriteLine($"{a}{op1}{b}{op2}{c}{op3}{d}=7");
                    return;
                }
            }
        }

        private static int Calculate(int left, bool op, int right)
        {
            if (op)
            {
                return left + right;
            }
            else{
                return left - right;
            }
        }
    }
}


Measured memory_bytes: 26748
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int n;
    cin>>n;
    int p = n%10;
    if(p==2 || p==4 || p==5 || p==7 || p==9)
        cout<<"hon\n";
    else if(p==0 || p==1 || p==6 || p==8)
         cout<<"pon\n";
    else if(p==3)
         cout<<"bon\n";
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
int main()
{
    int H,W,i,j;
    scanf("%d %d",&H,&W);
    char P[H][W+1];
    for(i=0;i<H;i++) scanf("%s",P[i]);
    for(i=0;i<H+2;i++){
        for(j=0;j<W+2;j++){
            if(i==0||i==H+1||j==0||j==W+1) printf("#");
            else if(j==1) printf("%s",P[i-1]);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long long>L(N+1);
  L.at(0)=2;
  L.at(1)=1;
  for(int i=2;i<N+1;i++){
    L.at(i)=L.at(i-2)+L.at(i-1);
  }
  cout<<L.at(N)<<endl;
}

Measured memory_bytes: 256