akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

class Node 
{
public:
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

Node* treeMinimum(Node *x) 
{
    while (x->left != NIL){
        x = x->left;
    }
    return x;
}

Node* treeSuccessor(Node *x)
{
    if (x->right != NIL){
        return treeMinimum(x->right);
    }
    Node *y = x->parent;
    while (y != NIL && x == y->right){
        x = y;
        y = y->parent;
        
    }
    return y;
}

void treeDelete(Node *z) 
{
    Node *y;
    Node *x;
    if (z->left == NIL || z->right == NIL){
        y = z;
    } else {
        y = treeSuccessor(z);
    }
    if (y->left != NIL){
        x = y->left;
    } else {
        x = y->right;
    }

    if (x != NIL){
        x->parent = y->parent;
    }

    if (y->parent == NIL){
        root = x;
    } else {
        if (y == y->parent->left){
            y->parent->left = x;
        } else {
            y->parent->right = x;
        }
    }
    
    if (y != z){
        z->key = y->key;
    }
    free(y);
}


void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z = new Node();
    
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while( x != NIL ){
        y = x;
        if (z->key < x->key){
            x = x->left;
        } else {
            x = x->right;
        }
    }
    z->parent = y;
    if ( y == NIL ){
        root = z;
    } else {
        if ( z->key < y->key){
            y->left = z;
        } else {
            y->right = z;
        }
    }
    
}

void inorder(Node *u)
{
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u)
{
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}
Node* find(Node *u, int k)
{
    while(u != NIL && k != u->key){
        if (k < u->key){
            u = u->left;
        } else {
            u = u->right;
        }
    }
    return u;
}


int main()
{
    int n, x;
    string com;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        cin >> com;
        if (com == "insert"){
            scanf("%d", &x);
            insert(x);
        } else if ( com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else if ( com[0] == 'f') {
            scanf("%d", &x);
            Node *t = find(root, x);
            if (t != NIL) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        } else if ( com == "delete"){
            scanf("%d", &x);
            treeDelete(find(root, x));
        }
        
        
    }
    return 0;
    
}

Measured memory_bytes: 20008
#include <stdio.h>

int solve(int, int);

int n, A[20];

int main(){

  int i, q, M[200];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &M[i]);

    if(solve(0, M[i]) == 1) printf("yes\n");
    else printf("no\n"); //solve()==0のとき

  }

  return 0;
}

int solve(int i, int m){

  if(m==0) return 1;
  if(i>=n) return 0;

  int res;
  res=solve(i+1, m)||solve(i+1, m-A[i]);

  return res;
}



Measured memory_bytes: 2052
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;

	vector<pair<int32_t, int32_t>> red(N);
	for (int32_t i = 0; i < N; i++) {
		int32_t x, y;
		cin >> x >> y;
		red[i] = make_pair(x, y);
	}

	vector<pair<int32_t, int32_t>> blue(N);
	for (int32_t i = 0; i < N; i++) {
		int32_t x, y;
		cin >> x >> y;
		blue[i] = make_pair(x, y);
	}

	sort(blue.begin(), blue.end(), [](pair<int32_t, int32_t> left, pair<int32_t, int32_t> right) -> bool { return left.first < right.first; });
	int32_t res = 0;
	for (int32_t b_index = 0; b_index < N; b_index++) {
		//cout << "blue:(" << blue[b_index].first << "," << blue[b_index].second << ")" << endl;
		vector<int32_t> candidates;
		for (size_t r_index = 0; r_index < red.size(); r_index++) {
			if (blue[b_index].first > red[r_index].first && blue[b_index].second > red[r_index].second) {
				//cout << "red:(" << red[r_index].first << "," << red[r_index].second << ")" << endl;
				candidates.push_back(r_index);
			}
		}

		int32_t max_y = -1;
		int32_t max_index = -1;
		for (int32_t _index: candidates) {
			if (max_y < red[_index].second) {
				max_y = red[_index].second;
				max_index = _index;
			}
		}
		if (max_index == -1)
			continue;

		//cout << "result:(" << red[max_index].first << "," << red[max_index].second << ")" << endl;
		res++;
		red.erase(red.begin() + max_index);
	}

	cout << res << endl;

	return 0;
}


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

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

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

    double k = (double)sum / n;
    int ans = 0;
    double dis = 1000.0;
    for(int i = 0; i < n; i++){
        if(dis > abs(k - a[i])){
            dis = abs(k - a[i]);
            ans = i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int k;
    cin>>k;
    vec A={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};
    cout<<A[k-1];
}


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

int main() {
    int H, W;
    cin >> H >> W;

    int hh, ww;
    cin >> hh >> ww;

    int area[H][W];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            area[i][j] = 0;
            if (i < hh || j < ww) area[i][j] = 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (area[i][j] == 0) ++ans;
        }
    }

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

Measured memory_bytes: 256
def gcd(a,b):
    if a<b:
        tmp = a
        a = b
        b = tmp
    r = a % b
    while r!=0:
      a = b
      b = r
      r = a % b
    return b
  
def main():
    K = int(input())
    list_ = []
    sum_ = 0
    for i in range(1,K+1):
        for j in range(1,K+1):
            a = gcd(i,j)
            list_.append(a)
    for i in list_:
        for j in range(1,K+1):
            a = gcd(i,j)
            sum_ += a
    print(sum_)

main()
  

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

int main() {
  string N;
  cin >> N;
  
  if (N.at(0) == N.at(1) && (N.at(1) == N.at(2) && N.at(2) == N.at(3)) ){
    cout << "Yes" <<endl;
  }
  else if (N.at(0) == N.at(1) && N.at(1) == N.at(2) ){
    cout << "Yes" <<endl;
  }
  else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	sc.Scan()
	strs := strings.Split(sc.Text(), " ")
	fs := make([]float64, 4)
	for i, s := range strs {
		fs[i], _ = strconv.ParseFloat(s, 64)
	}
	d := math.Sqrt(math.Pow(fs[2]-fs[0], 2) + math.Pow(fs[3]-fs[1], 2))
	fmt.Println(d)
}



Measured memory_bytes: 1128
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main()
{
	long double a, b, c;
	long double eps = 1.0e-14;
	cin >> a >> b >> c;
	if (sqrt(a)+sqrt(b)+eps<sqrt(c))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

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

    if (a + b == c || b + c == a || c + a == b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        PrintWriter pw = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String read1 = null;
        String read2 = null;
        try {
            read1 = br.readLine();
            read2 = br.readLine();
            br.close();
        } catch (IOException e){
            e.printStackTrace();
        }
        String str[] = read1.split(" ", 0);
        String str2[] = read2.split(" ", 0);
        int n = Integer.parseInt(str[0]);
        int k = Integer.parseInt(str[1]);
        int at = n - k;
        if (at > 0) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(str2[i]);
            }
            Arrays.sort(a);
            long atc = 0;
            for (int i = 0; i < at; i++) {
                atc = atc + a[i];
            }
            pw.println(atc);
        }else {
            pw.println(0);
        }
        pw.flush();
    }
}

Measured memory_bytes: 58836
#include <iostream>
#include <cmath>

int main() {
    int n;
    double m = 100000.;
    long long int part;
    std::cin >> n;

    for (;n--;) {
        m *= 1.05;
        m = std::floor(m);
        part = (long long int )m % 1000;
        if (part > 0) {
            m += 1000. - (double)part;
        }
    }

    std::cout << (long long int) m << std::endl;

    return 0;
}

Measured memory_bytes: 1156
#coding: utf-8
import numpy as np
H, W = map(int, input().split())
h, w = map(int, input().split())
goban = np.array([[1 for i in range(W)] for j in range(H)])
goban[:h :] = 0
goban[:, :w] = 0
print(np.sum(goban))

Measured memory_bytes: 22020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    string n;
    string n2 = "";
    string n3 = "";
    ll k;
    cin >> n >> k;

    ll ans = 0;
    ll len = n.size();

    if(k == 1){
        ans = (len - 1) * 9 + ll(char(n[0])) - ll(char('0'));
    }else if(k == 2){
        ans = (len - 1) * (len - 2) / 2 * 9 * 9;
        ans += (ll(char(n[0])) - ll(char('0')) - 1) * 9 * (len - 1);

        bool flag = false;
        rep(i, 1, len){
            if(n[i] != '0'){
                flag = true;
            }
            if(flag){
                n2 += n[i];
            }
        }

        ll len2 = n2.size();
        if(len2 <= 0){
            cout << ans << endl;
            return 0;
        }
        ans += (len2 - 1) * 9 + ll(char(n2[0])) - ll(char('0'));
    }else if(k == 3){
        ans = (len - 1) * (len - 2) * (len - 3) / 6 * 9 * 9 * 9;
        ans += (ll(char(n[0])) - ll(char('0')) - 1) * (len - 1) * (len - 2) / 2 * 9 * 9;

        bool flag = false;
        rep(i, 1, len){
            if(n[i] != '0'){
                flag = true;
            }
            if(flag){
                n2 += n[i];
            }
        }

        ll len2 = n2.size();
        if(len2 <= 1){
            cout << ans << endl;
            return 0;
        }
        ans += (len2 - 1) * (len2 - 2) / 2 * 9 * 9;
        ans += (ll(char(n2[0])) - ll(char('0')) - 1) * 9 * (len2 - 1);

        flag = false;
        rep(i, 1, len2){
            if(n2[i] != '0'){
                flag = true;
            }
            if(flag){
                n3 += n2[i];
            }
        }

        ll len3 = n3.size();
        if(len3 <= 0){
            cout << ans << endl;
            return 0;
        }
        ans += (len3 - 1) * 9 + ll(char(n3[0])) - ll(char('0'));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
using namespace std;
ll mod = 1000000007;
ll INF = 1000000000000000000;
ll n, k;
ll a[100001];

void solve(int t)
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	ll b[n];
	b[0] = 0;


	for (int i = 1; i < n; i++)
	{
		b[i] = INF;
		for (int j = i - 1; j >= 0 and abs(i - j) <= k; j--)
			b[i] = min(b[i], abs(a[j] - a[i]) + b[j]);
	}
	cout << b[n - 1] << endl;


}

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


	int t = 1;
	//cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}
}


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

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

	long long L, R;

	cin >> L >> R;

	long long a, b;

	int m[3000] = {};

	a = 999999999999;

	for (long long i = L; i < R; i++) {
		b = i % 2019;
		if (m[b] == 0) {
			m[b]++;
			for (long long j = i+1; j <= R; j++) {
				b = (i * j) % 2019;
				if (b == 0) {
					cout << 0 << endl;
					return 0;
				} else if (a > b) {
					a = b;
				}
			}
		}
	}

	cout << a << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;
int n;
vector<vector<int>> adj;
vector<bool> vis;
vector<int> increase;
void dfs(int node,int sum)
 {
  vis[node] = 1;
  increase[node] += sum;
  sum = increase[node];
  for(auto x : adj[node])
     if(!vis[x])
       dfs(x,sum);
 }
void solve()
  {
   int q;
   cin>>n>>q;
   adj = vector<vector<int>> (n+1);
   vis = vector<bool> (n+1,false);
   increase = vector<int> (n+1,0ll);
   loop(i,0,n-1)
    {
      int u,v;
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
   loop(i,0,q)
    {
      int p,x;
      cin>>p>>x;
      increase[p] += x;
    }
   dfs(1ll,0ll);
   loop(i,1,n+1)
    cout<<increase[i]<<" ";

  } 
signed main()
 {
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

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

int main() {
    string s;
    vector<int> vec(10);
    cin >>s;
    int count = 0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T'){
            count++;
          	vec.at(i)=count;
        }
        else{
            vec.at(i)=count;
            count=0;
        }
    }
    int max = *std::max_element(vec.begin(), vec.end());
    cout<<max<<endl;
    
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DEquals solver = new DEquals();
        solver.solve(1, in, out);
        out.close();
    }

    static class DEquals {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints(), m = in.ints();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[in.ints() - 1] = i;
            }
            UnionFind uf = new UnionFind(n);
            for (int i = 0; i < m; i++) {
                uf.union(in.ints() - 1, in.ints() - 1);
            }

            int ans = 0;
            for (int i = n - 1; i >= 0; i--) {
                if (uf.find(i) == uf.find(p[i])) {
                    ans++;
                }
            }
            out.println(ans);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }

    static final class UnionFind {
        private final int[] groups;

        public UnionFind(int size) {
            groups = IntStream.range(0, size).toArray();
        }

        public int find(int i) {
            int ans = groups[i];
            while (ans != groups[ans]) {
                ans = groups[ans];
            }
            return groups[i] = ans;
        }

        public int union(int a, int b) {
            return groups[find(b)] = find(a);
        }

    }
}



Measured memory_bytes: 47920
// In the name of Allah
// #Isart

#include<bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double

using namespace std;

const int MAXN = 1e5 + 10;
int root[MAXN], sz[MAXN];
pair<ll, ll> x[MAXN], y[MAXN]; 
vector<pair<ll, pair<ll, ll> > > e;

int get_root(int v){
	return (root[v] == v) ? v : root[v] = get_root(root[v]);
}

bool merge(int x, int y){
	x = get_root(x), y = get_root(y);
	if(x == y) return false;
	if(sz[x] < sz[y]) swap(x, y);
	sz[x] += sz[y]; root[y] = x;
	return true;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n; i ++) sz[i] = 1, root[i] = i;
	ll sum = 0;
	for(int i = 0; i < n; i ++) cin >> x[i].F >> y[i].F, x[i].S = y[i].S = i;
	sort(x, x + n);
	sort(y, y + n);
	for(int i = 0; i < n - 1; i ++){
		e.pb({x[i + 1].F - x[i].F, {x[i].S, x[i + 1].S}});
		e.pb({y[i + 1].F - y[i].F, {y[i].S, y[i + 1].S}});
	}
	sort(e.begin(), e.end());
	for(auto u : e){
		if(merge(u.S.F, u.S.S)) sum += u.F;
	}
	cout << sum << endl;
	return 0;	
}

Measured memory_bytes: 12272
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) <<endl; return 0;
}


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

namespace ConsoleApplication19
{
    class Program
    {
        static void Main(string[] args)
　　　　{
　　　　　　int a =int.Parse(Console.ReadLine());
　　　　　　int[] b = new int[2];
　　　　　　for(int c=0;c<a;c++)
　　　　　　{
　　　　　　	int[] d = new int[2];
　　　　　　	d= Console.ReadLine().Split().Select(int.Parse).ToArray();
　　　　　　	if(d[0]>b[0])
　　　　　　	{
　　　　　　	   b[0]=d[0];
　　　　　　	   b[1]=d[1];
　　　　　　	}
　　　　　　}
　　　　　　Console.WriteLine(b[0]+b[1]);
　　　　　　
　　　}
   }
}



Measured memory_bytes: 17448
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INS(s) scanf("%s",s)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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;
  }
}
ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(void){
  int n;
  INI(n);
  int x[n];
  FOR(n)INI(x[i]);
  ll sum,mi=INF;
  FOR(101){
    sum=0;
    FORJ(n)sum+=(i-x[j])*(i-x[j]);
    mi=min(mi,sum);
  }
  PRL(mi);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << (x) << endl
#define TGET(a, b) get<b>(a)

int is_prime(ll n)
{
    double n_sqrt;
    if (n == 2 || n == 3)
    {
        return 1;
    }
    if (n <= 1 || n % 6 != 1 && n % 6 != 5)
    {
        return 0;
    }
    n_sqrt = double(sqrt((double)n));
    for (int i = 5; i <= n_sqrt; i += 6)
    {
        if (n % i == 0 | n % (i + 2) == 0)
        {
            return 0;
        }
    }
    return 1;
}

int main()
{
    string a;
    cin >> a;
    if(a[2]==a[3]&&a[4]==a[5])
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  int r;
  cin >> r;
  cout << r * r << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>

#define MOD 1000000007
#define REP(i,n) for ((i)=0;i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define LL long long
#define ULL unsigned long long

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

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

int main(void) {

	int L,T,i;
	int a[100];

	scanf("%d %d", &L, &T);

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

	qsort(a,T,sizeof(int),compare_int);

	if(a[0]-1>L-a[0]){
		printf("%d", a[0]-(L-a[0])-1);
	}else{
		printf("0");
	}

	return 0;
}

/* 最後の改行忘れるな！！ */


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

using namespace std;

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

int c[11];

int main(){
	int a[3];
	REP(i,3){
		cin>>a[i];
	}
	REP(i,3){
		c[a[i]]++;
	}
	if (c[5]==2 && c[7]==1){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

#define INF (1 << 30)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    double waru = 0;
    rep(i, N){
        cin >> a[i];
        waru += 1.0/a[i];
    }
    printf("%.7f\n", 1.0/waru);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    string s;
    cin>>s;
    unordered_set<int> a;
    for (int i=0;i<s.length();i++)
    {
        a.insert(s[i]-'a');
    }
    for (int i=0;i<=25;i++)
    {
        if (a.find(i)==a.end())
        {
            char c='a'+i;
            cout<<c;
            return 0;
        }
    }
    cout<<"None";
    return 0;
}

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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}
const int MAXN = 120000;

int dd[2][MAXN];
vector<int> eds[MAXN];
int n;

void dfs1(int v, int d, int c, int p = -1) {
    dd[c][v] = d;
    for (int u: eds[v]) { 
        if (u == p)
            continue;
        dfs1(u, d + 1, c, v);
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a, --b;
        eds[a].push_back(b);
        eds[b].push_back(a);
    }
    dfs1(0, 0, 0);
    dfs1(n - 1, 0, 1);
    int c1 = 0;
    int c2 = 0;
    for (int i = 0; i < n; ++i)
        if (dd[0][i] <= dd[1][i])
            ++c1;
        else
            ++c2;
    if (c1 > c2)
        cout << "Fennec\n";
    else
        cout << "Snuke\n";
    return 0;
}




Measured memory_bytes: 13184
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n;
	cin>>n;
	int nt=0,nx=0,ny=0;
	FOR(i,0,n){
		int t,x,y;
		cin>>t>>x>>y;
		int d1=nx-x,d2=ny-y;
		if(d1<0)d1*=-1;
		if(d2<0)d2*=-1;
		if(d1+d2<=t-nt&&((t-nt-d1-d2)%2==0)){

		}else{
			cout<<"No";
			return 0;
		}
		nt=t,nx=x,ny=y;
	}
	cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <time.h>
#include <chrono>
#include <random>
//#include <math.h>
#include <cmath>
#include <fstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <stdlib.h>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <bitset>

#pragma comment(linker, "/STACK:36777216")
using namespace std;

#define flu fflush(stdout)
#define gg return 0
#define mp make_pair

typedef long double ptype;

long long mod = /*27449*//*998244353*/ 1e9 + 7 /*1e9 + 9*/;
int inf = 1e9;
double eps = 1e-7;
long double pi = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ifstream in("input.txt");
ofstream out("output.txt");

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		int t1, t2;
		cin >> t1 >> t2;
		a[i] = t1 == t2;
	}
	for (int i = 2; i < n; i++)
	{
		if (a[i] + a[i - 1] + a[i - 2] == 3)
		{
			cout << "Yes";
			return;
		}
	}
	cout << "No";
}

int main()
{
	cout << setprecision(20) << fixed;
	cin.tie();
	cout.tie();
	clock_t t1 = clock();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
		//test();
	}
	//cout << (clock() - t1) * 1.0 / CLOCKS_PER_SEC;
	gg;
}

Measured memory_bytes: 3676
#include<iostream>
using namespace std;
string input;
int len;
struct bit{
	int val[100000] = {};
	int lowbit(const int &a){
		return a & -a;
	}
	int query(int l, int r){
		int res = 0;
		--l;
		while(l){
			res -= val[l];
			l -= lowbit(l);
		}
		while(r){
			res += val[r];
			r -= lowbit(r);
		}
		return res;
	}
	void plus(int i){
		while(i <= 100000){
			++val[i];
			i += lowbit(i);
		}
	}
}tree;
int main(){
	int ans = 0, Q;
	cin >> len >> Q >> input;
	for(int i = 1;i < input.size();++i){
		if(input[i] == 'C' and input[i - 1] == 'A')tree.plus(i);
	}
	while(Q--){
		int l, r;
		cin >> l >> r;
		cout << tree.query(l, r - 1) << '\n';
	}
}


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

int main() {
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(u == s) cout << a-1 << ' ' << b << endl;
  else cout << a << ' ' << b-1 << endl;
}

Measured memory_bytes: 256
n, y = map(int, input().split())
for i in range(n + 1):
	for j in range(n+1 - i):
		k = n - i - j
		if i *10000 + j * 5000 + k *1000 == y:
			print(i,j,k)
			exit()
			
print('-1 -1 -1')

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

using namespace std;

typedef long long ll;
const int MAXN = 3e5 + 5;

int d[MAXN];

bool dfs()

int main ()
{
    int t;
    scanf("%d", &t);
    while(t --)
    {
        int n, k, l;
        bool flag = false;
        scanf("%d%d%d", &n, &k, &l);
        for(int i = 1; i <= n; i ++)
        {
            scanf("%d", &d[i]);
            if(d[i] > l)
                flag = true;
        }
        if(flag)
        {
            cout<<"No"<<endl;
            continue;
        }
        if(dfs());
    }
    return 0 ;
}
*/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x;
    cin>>x;
    switch(x)
    {
    case 400 ... 599:
        cout<<8<<endl;
        break;
    case 600 ... 799:
        cout<<7<<endl;
        break;
    case 800 ... 999:
        cout<<6<<endl;
        break;
    case 1000 ... 1199:
        cout<<5<<endl;
        break;
    case 1200 ... 1399:
        cout<<4<<endl;
        break;
    case 1400 ... 1599:
        cout<<3<<endl;
        break;
    case 1600 ... 1799:
        cout<<2<<endl;
        break;
    case 1800 ... 1999:
        cout<<1<<endl;
        break;

    }
    return 0;
}


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

int main () {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  rep(i, n - 1) cin >> b[i];
  vector<int> a(n);
  a[0] = b[0];
  a[n - 1] = b[n - 2];
  for(int i = 1; i < n - 1; i++) {
    a[i] = min(b[i], b[i - 1]);
  }
  int ans = 0;
  rep(i, n) ans += a[i]; 
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    double ans = 0;
    for(ll i=0;i<n;i++){
        ll num = (i + 1);
        ll cnt = 1;
        while(num < k){
            num *= 2;
            cnt *= 2;
        }
        ans += (1.0 / ((double)n * (double)cnt));
    }
    cout << setprecision(15) << ans << endl;
}

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

static const long long INFTY=(1LL<<32);
long long A[100][100];
int E,V;
void count(){
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            if(A[i][k]==INFTY) continue;
            for(int j=0;j<V;j++){
                if(A[k][j]==INFTY) continue;
                A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
            }
        }
    }
}

int main(){
    int s,t,d;
    cin>>V>>E;
    for(int i=0;i<V;i++){
        for(int j=0;j<V;j++){
            if(i==j) A[i][j]=0;
            else A[i][j]=INFTY;
        }
    }
    for(int i=0;i<E;i++){
        cin>>s>>t>>d;
        A[s][t]=d;
    }
    count();
    bool ngt=false;
    for(int i=0;i<V;i++){
        if(A[i][i]<0){
            ngt=true;
            break;
        }
    }

    if(ngt) cout<<"NEGATIVE CYCLE"<<endl;
    else{
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                if(j) cout<<" ";
                if(A[i][j]==INFTY) cout<<"INF";
                else cout<<A[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}


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

int n,m;
int arr[200005];
int pre[200005];

int size;
struct ufds{
    int p[200005];
    int r[200005];

    ufds(){
        for (int x=0;x<200005;x++){
            p[x]=x;
            r[x]=0;
        }
    }
    int parent(int i){return (p[i]==i)?i:p[i]=parent(p[i]);}
    void unions(int i,int j){
		//printf("%d %d\n",i,j);
        i=parent(i),j=parent(j);
        if (i==j) return;
		size--;
        if (r[i]<r[j]){
            p[i]=j;
        }
        else{
            p[j]=i;
            if (r[i]==r[j]) r[i]++;
        }
    }
}dsu=ufds();


int main(){
	cin>>n>>m;
	
	for (int x=0;x<n;x++) cin>>arr[x];
	pre[0]=1;
	for (int x=1;x<n;x++){
		pre[x]=(arr[x-1]<arr[x])?pre[x-1]+1:1;
	}
	
	size=n-m+1;	
	
	int sorted=-1;
	for (int x=m-1;x<n;x++) if (pre[x]>=m) sorted=x;
	for (int x=m-1;x<n;x++) if (pre[x]>=m) dsu.unions(sorted,x);
	
	set<int> s;
	
	int l=0,r=m;

	
	for (int x=1;x<r;x++) s.insert(arr[x]);
	
	while (r<n){
		//cout<<*s.begin()<<" "<<*(--s.end())<<endl;
		if (arr[l]<*s.begin() && *(--s.end())<arr[r]) dsu.unions(r-1,r);
		
		l++;
		s.erase(arr[l]);
		s.insert(arr[r]);
		r++;
	}
	
	printf("%d\n",size);
}

Measured memory_bytes: 12800
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
	string s;
  cin >> s;
  
  int hash[27] = { 0 };
  
  for (int i = 0; i < s.length(); i++)
  {
	hash[s[i] - 'a']++;
  }
  bool valid = true;
  for (int i = 0; i < 27; i++)
  {
	if (hash[i] % 2 != 0) { cout << "No" << endl; return 0; }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[200001],ok[200001];
vector <int> v;
long long k;
int main()
{ cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin>>n>>k;
  for(int i=1;i<=n;i++)
    cin>>a[i];
  int s=1;
  while(!ok[s])
  { ok[s]=1;
    s=a[s];
    k--;
    if(k==0)
    { cout<<s<<'\n';
      return 0;
    }
  }
  while(ok[s]!=2)
    v.push_back(s),ok[s]=2,s=a[s];
  k%=v.size();
  cout<<v[k]<<'\n';
  return 0;
}


Measured memory_bytes: 5360
L=input()
mod=10**9+7
l=len(L)
dp=[[0]*(l+1) for i in range(2)]
dp[1][0]=1
for i in range(l):
    s=int(L[i])

    dp[0][i+1]+=dp[0][i]*3
    dp[0][i+1]%=mod

    if s==1:
        dp[0][i+1]+=dp[1][i]
        dp[1][i+1]+=2*dp[1][i]
    else:
        dp[1][i+1]+=dp[1][i]
    dp[0][i+1]%=mod
    dp[1][i+1]%=mod

#print(dp)    
print((dp[1][l]+dp[0][l])%mod)

Measured memory_bytes: 43244
#include <stdio.h>

int main(int argc, const char* argv[])
{
	long inputN, FizzBuzzSum = 0, aElement = 0;
	scanf("%ld", &inputN);

	// Looks inside iterator (i) for a number that has division remainder (remainder > 0). Then adds that remainder to FizzBuzzSum
	for (int i = 0; i <= inputN; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)
		{
			FizzBuzzSum += i;
		}
	}

	printf("%ld \n", FizzBuzzSum);
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> p;
vector<ll>v;
int main()
{
    ll n,k,a,ans=0;
    cin >>n>>k;
    for(ll i=0;i<n;i++)
    {
    	cin >> a;
    	v.push_back(a);
    }
    sort(v.begin(),v.end());
    for(ll i=0;i<k;i++)
    {
    	ans+=v[i];
    }
    cout << ans<<endl; 
    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
 
int main() {
  int n ; cin>>n;
  map<string,int>mp;
  rep(i,n){
    string s; cin>>s;
    sort(s.begin(),s.end());
    mp[s]++;    
  } 
  ll ans=0;
  for(auto p:mp){
    ll x=p.second;
    ans+=x*(x-1)/2;
  }    
  cout<<ans<<endl; 
}


Measured memory_bytes: 11136
#include <iostream>
#include <cstring>
#include <set>
using namespace std;
int main() {
    for (int h = 1; ; ++h) {
        int n;
        cin >> n;
        if (!n) break;

        if (h > 1)
            cout << endl;

        bool a[7][7][7]{}, b[7][7][7]{};
        for (int z = 1; z <= 5; ++z) {
            for (int y = 1; y <= 5; ++y) {
                char s[6];
                cin >> s;
                for (int x = 1; x <= 5; ++x)
                    a[z][y][x] = s[x - 1] == '1';
            }
        }
        int m1, m2;
        set<int> s1, s2;
        cin >> m1;
        while (m1--) {
            int p;
            cin >> p;
            s1.insert(p);
        }
        cin >> m2;
        while (m2--) {
            int p;
            cin >> p;
            s2.insert(p);
        }
        while (n--) {
            for (int z = 1; z <= 5; ++z) {
                for (int y = 1; y <= 5; ++y) {
                    for (int x = 1; x <= 5; ++x) {
                        int ct = 0;
                        for (int i = x - 1; i <= x + 1; ++i)
                            for (int j = y - 1; j <= y + 1; ++j)
                                for (int k = z - 1; k <= z + 1; ++k)
                                    if (!(i == x && j == y && k == z))
                                        ct += a[k][j][i];
                        b[z][y][x] = (a[z][y][x] ? s2 : s1).count(ct);
                    }
                }
            }
            memcpy(a, b, sizeof a);
        }
        cout << "Case " << h << ':' << endl;
        for (int z = 1; z <= 5; ++z) {
            for (int y = 1; y <= 5; ++y) {
                for (int x = 1; x <= 5; ++x)
                    cout << int(a[z][y][x]);
                cout << endl;
            }
            if (z < 5)
                cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n, m;
    cin >> n >> m;
    cout << (1900*m + 100*(n-m))*(int)pow(2, m) << endl;
}


Measured memory_bytes: 3128
#include <stdio.h>
#define INF -1//辿りつけなかったらー１
#define TRUE 1000
#define FALSE -1000
#define WHITE -2
#define GRAY -3
#define BLACK -4
#define N 100

void bfs(int);
int dequeue(void);
void enqueue(int);
int empty(void);

int Q[N], color[N], d[N];//d -> distance
int G[N+1][N+1];//隣接行列 0-origin
int head = 0, tail = 0;
int n = 0;

int main(){

  int i = 0, j = 0, l = 0, u = 0;
  int id = 0, k = 0;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      G[i][j] = 0;
    }
  }
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d%d",&id,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&u);
      G[id-1][u-1] = 1;
    }
  }

  bfs(0);

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

void bfs(int s){//s->source vertex

  int u = 0, v = 0, i = 0;
  
  for(u = 0; u < n; u++){//全て白に
    
    color[u] = WHITE;
    d[u] = INF;
    
  }
  
  color[s] = GRAY;
  d[s] = 0;
  enqueue(s);

  while(empty() == FALSE){
    
    u = dequeue();
    
    for(v = 0; v < n; v++){

      if(G[u][v] == 0)continue;//隣接していない
      if(d[v] != INF)continue;//一度通ったらとばす
      if(color[v] == WHITE){
	color[v] = GRAY;
	d[v] = d[u] + 1;
	enqueue(v);
      }
      
    }
    
    color[u] = BLACK;
    
  }
}

int dequeue(void){
  
  int q = 0;

  q = Q[head];
  head++;

  return q;
  
}

void enqueue(int q){
  
  Q[tail] = q;
  tail++;
  
}

int empty(void){
  
  if(head == tail){
    return TRUE;
  }
  else return FALSE;
  
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
    int N,K,L;cin>>N>>K>>L;
    UnionFind road(N),train(N);
    for(int i = 0; i < K ; i++){
        int p,q;cin>>p>>q;
        p--,q--;
        road.unite(p,q);
    }
     for(int i = 0; i < L ; i++){
        int r,s;cin>>r>>s;
        r--;s--;
        train.unite(r,s);
    }

    map<pair<int,int>,int> mp;
    for(int i = 0; i < N ;i++){
      mp[{road.find(i),train.find(i)}]++;
    }
    for(int i = 0 ; i < N ; i++){
      cout << mp[{road.find(i),train.find(i)}] << " ";
    }
    cout << endl;

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    double ans;
    for(int i = 0; i < N; i++) {
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") {
            ans+=x;
        }
        else {
            ans+=x*380000;
        }
    }
    cout << fixed << setprecision(4) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  if (N%1000==0) cout << 0 << endl;
  else cout << 1000-N%1000 << endl;
  return 0;
}

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

struct mint {
    const int mod = 1e9 + 7;
    long long x;
    
    mint (long long x = 0) : x((x % mod + mod) % mod) {
        
    }
    
    mint& operator=(const long long a) {
        x = a % mod;
        return *this;
    }
    
    mint& operator=(const mint a) {
        x = a.x % mod;
        return *this;
    }
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    
    mint& operator-=(const mint a) {
        if ((x += (mod - a.x)) >= mod) x -= mod;
        return *this;
    }
    
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    mint inv() const {
        return pow(mod - 2);
    }
    
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]++;
    }
    vector<int> color(3, 0);
    mint ans = 1;
    rep(i, n) {
        int cnt = 0;
        rep(ii, 3) {
            if (color[ii] == (a[i] - 1)) cnt++;
        }
        ans *= cnt;
        rep(ii, 3) {
            if (color[ii] == (a[i] - 1)) {
                color[ii] = a[i];
                break;
            }
        }
        // printf("i=%d, cnt=%d\n", i, cnt);
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n;
ll d,a;
ll x[222222];
ll h[222222];
ll rui[222222];
vector<ll>t;

/*
ll calc_life(in){
    auto it_mi=lower_bound(t.begin(),t.end(),x[in]-d):
    auto it_ma=upper_bound(t.begin(),t.end(),x[in]+d):
    ll num=it_ma-it_mi;
    return h[in]-num*a;
}
*/
vector<pair<ll,ll> > hoge;

int main(){
    cin>>n>>d>>a;
    rep(i,n)cin>>x[i]>>h[i];
    rep(i,n)hoge.pb(mp(x[i],h[i]));
    sort(hoge.begin(),hoge.end());

    rep(i,n)x[i]=hoge[i].first,h[i]=hoge[i].second;


    //int in=0;
    int now=0;
    ll ans=0;
    for(;;){
        if(now>=n)break;
        if(now>0)rui[now]+=rui[now-1];
        if(h[now]-rui[now]<=0){
            now++;
            continue;
        }

        int in=upper_bound(x,x+n,x[now]+d+d)-x;
        ll attack=(h[now]-rui[now])/a;
        if((h[now]-rui[now])%a)attack++;
        ans+=attack;
        rui[now]+=attack*a;
        rui[in]-=attack*a;
        //rui[in]+=rui[now];
        now++;
       // cout<<now<<" "<<in<<"A"<<endl;
    }

    //rep(i,n)cout<<h[i]<<" "<<rui[i]<<endl;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9712