akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>
#include <stack>
#include <cstring>
#include <cctype>
#include <random>

using namespace std;
typedef long long  ll;
const ll INF = 1000000007;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if (n % 2 == 0) {
		int l, r;
		l = a[n / 2 - 1] + a[n / 2];
		r = b[n / 2 - 1] + b[n / 2];
		cout << (r - l) + 1 << endl;
	}
	else {
		int l, r;
		l = a[(n + 1) / 2 - 1];
		r = b[(n + 1) / 2 - 1];
		cout << (r - l) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 6384
#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
  string in;
  getline(cin, in);
  if(in.compare("SUN") == 0) { cout << 7 << endl; }
  if(in.compare("MON") == 0) { cout << 6 << endl; }
  if(in.compare("TUE") == 0) { cout << 5 << endl; }
  if(in.compare("WED") == 0) { cout << 4 << endl; }
  if(in.compare("THU") == 0) { cout << 3 << endl; }
  if(in.compare("FRI") == 0) { cout << 2 << endl; }
  if(in.compare("SAT") == 0) { cout << 1 << endl; }
  return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        Map<String,Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
        	String s = sc.next();
        	if (map.containsKey(s)) {
        		map.put(s, map.get(s)+1);
        	} else {
        		map.put(s, 1);
        	}
        }
        
        int M = sc.nextInt();
        for (int i = 0; i < M; i++) {
        	String t = sc.next();
        	if (map.containsKey(t)) {
        		map.put(t, map.get(t)-1);
        	} else {
        		map.put(t, -1);
        	}
        }
        
        int maxCount = 0;
        for (Entry<String,Integer> e: map.entrySet()) {
        	if (maxCount < e.getValue()) {
        		maxCount = e.getValue();
        	}
        }
        
        System.out.println(maxCount);
    }
}




Measured memory_bytes: 25044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = ReadLine().Split();
        WriteLine((n[0][0].ToString() + n[1][0].ToString() + n[2][0].ToString()).ToUpper());
    }
}


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

int A[20];
int n, q;

bool solve(int p, int t)
{
    if(p == n) return false;
     if(t == 0 || A[p] == t) return true;

    if(A[p] > t) return solve(p + 1, t);
    return solve(p + 1, t) || solve(p + 1, t - A[p]);
}

int main()
{
    int i, m;
    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];
    cin >> q;
    for(i = 0; i < q; i++){
        cin >> m;
        if(solve(0, m)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int h[100005],dp[100005];
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",h+i);
	}
	for(int i=1;i<n;i++){
		dp[i]=2e9;
		for(int j=max(0,i-k);j<i;j++){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  int sum = 0;
  rep(i,n){
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  vector<int> dif(m);
  rep(i,m){
    int p,x;
    cin >> p >> x;
    dif[i] = t[p-1] - x;
  }
  rep(i,m){
    cout << sum - dif[i] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define read freopen("input/test (4).txt","r",stdin)
#define write freopen("output/test (4).txt","w",stdout)
#define fr first
#define sc second
#include <sstream>
#define ii pair < int , int >
using namespace std;
int main()
{
 int a,b,c;
 cin>>a>>b>>c;
 set <  int > v;
 v.insert(a);
 v.insert(b);
 v.insert(c);
 cout<<v.size();
}


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

int arr[100005];
int main() {
  int n;
  cin >> n;

  int mn = INT_MAX;
  int mx = 0;
  int freqmn = 0;
  int freqmx = 0;

  for (int i = 1; i <= n; i++){
    cin >> arr[i];
    mn = min (mn, arr[i]);
    mx = max (mx, arr[i]);
  } 

  for (int i = 1; i <= n; i++){
    if (arr[i] == mx) freqmx++;
    else freqmn++;
  }

  if (freqmx == n){
    if ((mx == n-1) || (mx <= n/2))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  else{
    if ((freqmn <= mn) && (mx <= (freqmn + freqmx/2)))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3484
r1, c1, r2, c2 = map(int, input().split())


class Combination:
    def __init__(self, N: int, MOD: int):
        fac = [0 for _ in range(N + 1)]
        fac[0] = 1
        for i in range(1, N + 1):
            fac[i] = fac[i - 1] * i % MOD
        self.fac = fac
        self.N = N
        self.MOD = MOD

    def _modpow(self, x: int, n: int) -> int:
        ret = 1
        while n > 0:
            if n % 2 == 1:
                ret = ret * x % self.MOD
            x = x * x % self.MOD
            n >>= 1
        return ret

    def _modinv(self, x: int) -> int:
        return self._modpow(x, self.MOD - 2)

    def combination(self, n: int, k: int) -> int:
        if n < k:
            return 0
        return self.fac[n] * self._modinv(self.fac[k]) % self.MOD * self._modinv(self.fac[n - k]) % self.MOD

MOD = 1000000007
comb = Combination(2 * 1000000 + 10, MOD)

ans = (2 * MOD + comb.combination(r1 + c1, r1) - comb.combination(r1 + c2 + 1, r1) - comb.combination(r2 + c1 + 1, r2 + 1) + comb.combination(r2 + c2 + 2, r2 + 1)) % MOD
print(ans)

Measured memory_bytes: 82200
from heapq import heappop, heappush
INF = float('inf')

n, m, s, t = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(m)]

graph = [[] for _ in range(n + 1)]
for u, v, a, b in edges:
    graph[u].append((v, a, b))
    graph[v].append((u, a, b))

def dijkstra(s, pay):
    """
    s: start
    pay: 0 = yen, 1 = snuuk
    """
    d = [INF] * (n + 1)
    visited = [False] * (n + 1)
    pq = []

    heappush(pq, (0, s))
    d[s] = 0
    visited[s] = True

    while pq:
        cost, x = heappop(pq)
        visited[x] = True

        for v, *c in graph[x]:
            if visited[v]:
                continue

            if d[v] > d[x] + c[pay]:
                d[v] = d[x] + c[pay]
                heappush(pq, (d[v], v))

    return d

d1 = dijkstra(s, 0)
d2 = dijkstra(t, 1)

ans = []
tmp = float('inf')
for i in reversed(range(1, n + 1)):
    tmp = min(tmp, d1[i] + d2[i])
    ans.append(10 ** 15 - tmp)
    
print(*ans[::-1], sep='\n')


Measured memory_bytes: 124888
#include<iostream>
using namespace std;
int main(){
    int a,b,tmp;
    string res;
    cin >> a >> b;
    tmp = (a+11)%13-(b+11)%13;
    if(tmp>0) res = "Alice";
    else if(tmp==0) res = "Draw";
    else res = "Bob";
    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int R, G, x;

    scanf("%d", &R);
    scanf("%d", &G);

    x = 2 * G - R;

    if(R >= 0 && R <= 4500 && G >= 0 && G <= 4500){
        printf("%d", x);
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std ;
int main (){
string z;
getline (cin ,z);
if ( z== "Sunny"){
    cout << "Cloudy" ;
}
else if (z== "Cloudy") {
    cout << "Rainy" ;
}
else {
     cout << "Sunny" ;
}
return 0 ;
 }

Measured memory_bytes: 256
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

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

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		// 計算
		Map<String, Integer> map = new TreeMap<String, Integer>();
		for (String s : "abcdefghijklmnopqrstuvwxyz".split("")) {
			if (!s.equals("")) {
				map.put(s, 0);
			}
		}
		for (String s : S.split("")) {
			if (!s.equals("")) {
				map.put(s, map.get(s) + 1);
			}
		}
		String output = "None";
		for (Entry<String, Integer> entry : map.entrySet()) {
			if (entry.getValue() == 0) {
				output = entry.getKey();
				break;
			}
		}

		// 出力
		System.out.println(output);

		return;
	}
}


Measured memory_bytes: 32968
s = input()

if s[0]==s[1] and s[2]==s[3] and s[0]!=s[2]:
    print("Yes")
elif s[0]==s[2] and s[1]==s[3] and s[0]!=s[1]:
    print("Yes")
elif s[0]==s[3] and s[1]==s[2] and s[0]!=s[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9072
#0:上面　1:S 2:E 3:W 4:N 5:下
class Dice:
    def __init__(self):#クラス内で用いる変数の定義（クラス作成時に代入しなくてよい）
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'
    #サイコロの目の数を設定
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5
        
    #サイコロを転がせ，それぞれのいちを追跡
    def roll(self, loc):#loc:
    #初期位置
        for i in range(6):
            self.work[i] = self.number[i]
        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        else:
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    
    def query(self, top_num, front_num):
        self.save_data = [i for i in range(6)]
        #元のデータの保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]
        
        ret = -1
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
        return ret;
    

dice = Dice()
table = list(map(int, input().split()))
dice.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])#init
# loc_array=str(input())

q = int(input())
for loop in range(q):
    u, f = map(int, input().split())
    print(dice.query(u, f))

# for tmp_loc in loc_array:
    # dice.roll(tmp_loc)
# print(dice.get_Top())
        
        
        


Measured memory_bytes: 5624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

#define mp make_pair
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

long long dp[5001][5001];

int main() {
        int n;
        scanf("%d", &n);
        vector<long long> h(n), p(n);
        for (int i = 0; i < n; i ++) scanf("%lld%lld", &h[i], &p[i]);
        vector<pair<long long, int>> prop(n);
        for (int i = 0; i < n; i ++) prop[i] = mp(h[i] + p[i], i);
        sort(prop.begin(), prop.end());
        for (int i = 0; i < 5001; i ++) {
                for (int j = 0; j < 5001; j ++) {
                        dp[i][j] = INFL;
                }
        }
        dp[0][0] = 0;
        for (int i = 0; i < n; i ++) {
                for (int j = 0; j < n; j ++) {
                        if (dp[i][j] == INFL) continue;
                        if (dp[i][j] <= h[prop[i].second]) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + p[prop[i].second]);
                        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
                }
        }
        int ans = 0;
        for (int i = 0; i <= n; i ++) if (dp[n][i] != INFL) ans = i;
        printf("%d\n", ans);
        return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<string> s = {"Sunny", "Cloudy", "Rainy"};
    string t;
    cin >> t;
    cout << s[(find(s.begin(),s.end(),t)-s.begin()+1)%3];
    return 0;
}
                

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

struct Node{
int key;
Node *right, *left, *parent;
};

Node *root,*NIL;

void insert(int k){
 Node *y=NIL;
 Node *x=root;
 Node *z;
 
 z=(Node *)malloc(sizeof(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);
 }
 
 int main(){
 int n,i,x;
 string com;
 
 scanf("%d",&n);
 
 for(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");
   }
   }
   
   return 0;
   }


Measured memory_bytes: 26736
#include <iostream>
#include <vector>
#include <algorithm>
#define all(c) (c).begin(),(c).end()

#define maxv 100000

using namespace std;

int n,len;
vector<int> tree[maxv], in, out, up[100];

void dfs(int u, int p, int &k){
  in[u] = k++;
  up[0][u] = p;
  for(int i = 1; i < len; i++)
    up[i][u] = up[i - 1][up[i - 1][u]];

  for(int i = 0; i < tree[u].size(); i++){
    if(tree[u][i] != p)dfs(tree[u][i],u,k);
  }
  out[u] = k++;
}

void init(int root){
  len = 1;
  while((1 << len) <= n)len++;
  for(int i=0;i<len;i++){
    up[i].resize(n);
    fill(all(up[i]),0);
  }
  in.resize(n);
  out.resize(n);
  fill(all(in),0);
  fill(all(out),0);
  int k=0;
  dfs(root,root,k);
}

bool isParent(int parent, int child){
  return in[parent] <= in[child] && out[child] <= out[parent];
}

int lca(int a, int b){
  if(isParent(a,b))return a;
  if(isParent(b,a))return b;
  for(int i = len - 1; i >= 0; i--){
    if(!isParent(up[i][a],b))a = up[i][a];
  }
  return up[0][a];
}


int main(void){

  cin >> n;
  for(int i=0;i<n;i++){
    int k,c;
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> c;
      tree[i].push_back(c);
    }
  }

  init(0);

  int q;
  cin >> q;
  while(q--){
    int u,v;
    cin >> u >> v;
    cout << lca(u,v) << endl;
  }
  return 0;
}

Measured memory_bytes: 20280
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling, digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vpll path;
//***********//
int main() { 
	cin >> N >> M;
	vl X(N), Y(M);
	for (i = 0; i < N; i++) {
		cin >> X[i];
	}
	for (i = 0; i < M; i++) {
		cin >> Y[i];
	}
	vl Y_sum(M+1);
	Y_sum[M] = 0;
	for (i = M-1; i >=0; i--) {
		(Y_sum[i] = Y_sum[i+1] + Y[i])%=MOD;
	}
	ll pre = 0;
	for (i = 0; i < M; i++) (pre += Y_sum[i + 1] - (Y[i] * (M - i - 1)) % MOD +MOD) %= MOD;
	//cout << pre;
	vl X_sum(N + 1);
	X_sum[N] = 0;
	for (i = N - 1; i >= 0; i--) {
		(X_sum[i] = X_sum[i + 1] + X[i]) %= MOD;
	}
	ll ans = 0;
	for (i = 0; i < N; i++) (ans += (X_sum[i + 1] - (X[i] * (N - i - 1)) % MOD + MOD)%MOD*pre) %= MOD;
	cout << ans;
}

Measured memory_bytes: 3328
import java.util.Scanner;
 
public class Main {
    long count = 0;
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    private void run() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        StringBuilder builder = new StringBuilder();
        int[] A = new int[n];
        int[] B = new int[n];
        int K = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            A[i] = scanner.nextInt();
            K = Math.max(K, A[i]);
        }
        CountingSort(A, B, K);
        builder.append(B[0]);
        for (int i = 1; i < n; i++) {
            builder.append(' ').append(B[i]);
        }
        System.out.println(builder);
    }
 
    private void CountingSort(int[] a, int[] b, int k) {
        int[] C = new int[k + 1];
        for (int i = 0; i < a.length; i++)
            C[a[i]]++;
 
        for (int i = 1; i <= k; i++)
            C[i] += C[i - 1];
 
        for (int i = a.length - 1; i >= 0; i--) {
            C[a[i]]--;
            b[C[a[i]]] = a[i];
 
        }
    }
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int cnt = 0;
  for (int i = 0; i < N/2; i++){
    if(S.at(i) != S.at(N-1-i)) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h" 
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rerep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int main(){
    ll n;
    cin>>n;
    ll a[n];
    ll b[n];
    rep(i,0,n)b[i]=0;
    rep(i,1,n){
        cin>>a[i];
        b[a[i]-1]++;
    }
    rep(i,0,n)cout<<b[i]<<endl;
    return 0;
}

Measured memory_bytes: 6756
#include <stdio.h>

int main(int argc, char *argv[])
{
    int a, b;
    char op;
    char line[256];


    while (1) {

        if (!fgets(line, sizeof(line), stdin)) {
            fprintf(stderr, "error input val\n");
            return -1;
        }

        if (sscanf(line, "%d %c %d", &a, &op, &b) != 3) {
            fprintf(stderr, "error input format\n");
            return -1;
        }

        if (op == '?') {
            return 0;
        }
        switch (op) {
        case '+':
            printf("%d\n", a+b);
            break;
        case '-':
            printf("%d\n", a-b);
            break;
        case '*':
            printf("%d\n", a*b);
            break;
        case '/':
            printf("%d\n", a/b);
            break;
        };

    }
    return 0;
}

Measured memory_bytes: 612
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(N);
    bool pos[N+1]={false};
    pos[0]=true;
    FORI(i,0,N+1)
    {
        if(pos[i])
        {
            if(i+100<=N)
            {
                pos[i+100]=true;
            }
            if(i+101<=N)
            {
                pos[i+101]=true;
            }
            if(i+102<=N)
            {
                pos[i+102]=true;
            }
            if(i+103<=N)
            {
                pos[i+103]=true;
            }
            if(i+104<=N)
            {
                pos[i+104]=true;
            }
            if(i+105<=N)
            {
                pos[i+105]=true;
            }
        }
    }
    if (pos[N])
    {
        cout<<1<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_066_A_ringring
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] word = Console.ReadLine().Split(' ');
			int a = int.Parse(word[0]);
			int b = int.Parse(word[1]);
			int c = int.Parse(word[2]);


			int d = a + b;
			int e = a + c;
			int f = b + c;
			int x = d;
			if (e < x) x = e;
			if (f < x) x = f;

			Console.WriteLine(x);

			//Console.ReadKey();
		}
	}
}


Measured memory_bytes: 27464
import math

nums = list(map(int, input().split()))
a = nums[0]
b = nums[1]
h = nums[2]
m = nums[3]

a_rad = 30 * h + 0.5 * m
b_rad = 6 * m
rad = abs(a_rad - b_rad)

if rad > 180:
    rad = 360 - rad
    
cos = math.cos(math.radians(rad))

c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cos)

print(c)

Measured memory_bytes: 9452
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  cout <<(N*(N+1))/2 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll x;
    if(b-1 <= n){
        x = b-1;
        cout << a*x/b - a*(x/b) << endl;
    }
    else{
        cout << a*n/b - a*(n/b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
// https://atcoder.jp/contests/practice2/tasks/practice2_f

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

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

    vector<long long> a(n), b(m);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i)
    {
        cin >> b[i];
    }

    vector<long long> c = convolution(a, b);
    for (int i = 0; i < n + m - 1; ++i)
    {
        cout << c[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 27224
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let l: usize = sc.read();
    let mut r = 1;
    while (1 << (r + 1)) <= l {
        r += 1;
    }

    let n = r + 1;
    let mut graph = vec![vec![]; n + 1];
    for i in 0..r {
        graph[i].push((i + 1, 1 << i));
        graph[i].push((i + 1, 0));
    }

    let sum = (1 << r) - 1;
    let mut upper = l;
    for i in (0..r).rev() {
        let to_i = (1 << i) - 1;
        if upper <= to_i {
            continue;
        }
        let new_edge = upper - to_i - 1;
        // add [new_edge, ..., to_i+new_edge]
        if new_edge > sum {
            graph[i].push((n - 1, new_edge));
            upper = new_edge;
        }
    }

    let mut ans = vec![];
    for (from, v) in graph.into_iter().enumerate() {
        for (to, w) in v.into_iter() {
            ans.push((from, to, w));
        }
    }

    println!("{} {}", n, ans.len());
    for (from, to, w) in ans.into_iter() {
        println!("{} {} {}", from + 1, to + 1, w);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

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


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector< pair<int,int> > adj[MAX];

void dijkstra(){
	priority_queue< pair<int,int> > PQ;
	int color[MAX];
	int d[MAX];
	for(int i=0;i<n;i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	PQ.push(make_pair(0,0));
	color[0] = GRAY;

	while(!PQ.empty()){
		pair<int,int> f = PQ.top(); PQ.pop();
		int u = f.second;
		color[u] = BLACK;

		if(d[u] < f.first * (-1)) continue;

		for(int j=0; j<adj[u].size(); j++){
			int v = adj[u][j].first;
			if(color[v] == BLACK) continue;
			if(d[v] > d[u] + adj[u][j].second){
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v]*(-1), v));
				color[v] = GRAY;
			}
		}
	}

	for(int i=0; i<n; i++){
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main(){
	cin >> n;

	int k,c,u,v;
	for(int i=0;i<n;i++){
		cin >> u >> k;
		for(int j=0;j<k;j++){
			cin >> v >> c;
			adj[u].push_back(make_pair(v,c));
		}
	}

	dijkstra();

	return 0;
}



Measured memory_bytes: 8020
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
#include <iomanip>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, K; cin >> N >> K;
int64_t cnt = 0;

if (2 * N < K) {
    cout << 0 << "\n";
    return 0;
}

vector<int64_t> num(K, 0);
rep(i, 1, N+1) num[i%K]++;

// (a+b)%K = 0 より，b%K = -a%K = (K - a)%K
rep(a, 0, K){
    int b = (K - a) % K;
    int c = b;
    if ((b + c)%K == 0) 
        cnt += num[a] * num[b] * num[c];
}

cout << cnt <<  "\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> T MV(T v) { return v; }
template<typename T, typename ... U> auto MV(T v, int a, U ... b) { return vector<decltype(MV(v, b ...))>(a, MV(v, b ...)); }

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };

int main() {
	IN(int, h, w, k, si, sj, gi, gj);
	vector<string> s(h + 2);
	s.FR = s.BA = string(w + 2, '@');
	inc1(i, h) { IN(string, t); s[i] = "@" + t + "@"; }
	h += 2;
	w += 2;
	
	const int INF = 1e7;
	auto dist = MV(INF, 2, h, w);
	queue<tuple<int, int, int, int>> q;
	auto update = [&](int v, int i, int j, int d) {
		if(setmin(dist[v][i][j], d)) { q.emplace(v, i, j, d); }
	};
	update(0, si, sj, 0);
	update(1, si, sj, 0);
	until(q.empty()) {
		auto [v, i, j, d] = q.front(); q.pop();
		if(dist[v][i][j] != d) { continue; }
		
		vector<int> di = { +1, -1,  0,  0 };
		vector<int> dj = {  0,  0, +1, -1 };
		inc(l, 4) {
			int ii = i + di[l];
			int jj = j + dj[l];
			if_not(inID(ii, 0, h) && inID(jj, 0, w)) { continue; }
			if(s[ii][jj] == '@') { continue; }
			update(l / 2, ii, jj, (l / 2 == v ? d + 1 : ce(d, k) * k + 1));
		}
	}
	int ans = min(dist[0][gi][gj], dist[1][gi][gj]);
	OUT(ans == INF ? -1 : ce(ans, k));
}


Measured memory_bytes: 41432
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct LCA{
  const int lg = 8;
  const int sz = 1<<lg;
  const int ms = sz-1;
  int n;
  vector<int> P,D,E,A,B,T,ht;
  vector<vector<int> > G,dat;
  LCA(int n):
    n(n),P(n,-1),D(n),E(n*2,0),A(n*2,-1),B(n*2/lg+1),T(sz,0),G(n){}

  void add_edge(int u,int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  void dfs(int v,int p,int d,int &k){
    D[v]=k;
    A[k]=P[v]=p;
    E[k++]=d;
    for(int u:G[v])
      if(u!=p) dfs(u,v,d+1,k);
    A[k]=P[v];
    E[k++]=d-1;
  }

  inline int comp(int i,int j){return E[i]<E[j]?i:j;};
  inline int comp(int i,int j,int k){return comp(comp(i,j),k);};
  
  void build(int r=0){
    int k=0;
    dfs(r,-1,1,k);
    
    B[0]=1;
    for(int i=1;i<n*2;i++) B[i/lg]|=(E[i-1]<E[i])<<(i%lg);

    for(int b=0;b<sz;b++){
      int e=0,w=1,&x=T[b];
      for(int i=0;i<lg;i++){
	if((b>>i)&1) e++;
	else e--;
	if(e<w) e=w,x=i;
      }
    }

    int m=(n*2+lg-1)/lg;
    int h=1;
    while((1<<h)<m) h++;
    dat.assign(h,vector<int>(m,-1));
    ht.assign(m+1,0);
    for(int j=2;j<=m;j++) ht[j]=ht[j>>1]+1;
    
    for(int j=0;j<n*2;j++){
      if(dat[0][j/lg]<0) dat[0][j/lg]=j;
      dat[0][j/lg]=comp(dat[0][j/lg],j);
    }
    
    for(int i=1,p=1;i<h;i++,p<<=1)
      for(int j=0;j<m;j++)
        dat[i][j]=comp(dat[i-1][j],dat[i-1][min(j+p,m-1)]);
  }

  inline int cs(int a,int b){
    int l=b-a;
    return comp(dat[ht[l]][a],dat[ht[l]][b-(1<<ht[l])]);
  }

  inline int es(int i,int l,int r){
    int x=r-i*lg+1,y=l-i*lg;
    int b=(((B[i]|(ms<<x))>>y)|(ms<<(lg-y)))&ms;
    return l+T[b];
  }
  
  inline int ls(int i,int l){
    int k=l-i*lg;
    int b=((B[i]>>k)|(ms<<(lg-k)))&ms;
    return l+T[b];
  }

  inline int rs(int j,int r){
    int k=r-j*lg+1;
    int b=(B[j]|(ms<<k))&ms;
    return j*lg+T[b];
  }

  inline int rmq(int l,int r){
    int i=l/lg,j=r/lg;
    if(i==j) return es(i,l,r);
    if(i+1==j) return comp(ls(i,l),rs(j,r));
    return comp(ls(i,l),cs(i+1,j),rs(j,r));    
  }
  
  int lca(int l,int r){
    if(l==r) return l;
    if(D[l]>D[r]) swap(l,r);
    int x=D[l],y=D[r];
    int m=rmq(x,y);
    return m==x?l:A[m];
  }
};
//END CUT HERE

//INSERT ABOVE HERE
signed GRL_5_C(){
  int n;
  scanf("%d",&n);
  LCA lca(n);
  for(int i=0;i<n;i++){
    int k,c;
    scanf("%d",&k);
    for(int j=0;j<k;j++){
      scanf("%d",&c);
      lca.add_edge(i,c);
    }
  }
  
  lca.build();
  int q;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    int x,y;
    scanf("%d %d",&x,&y);
    printf("%d\n",lca.lca(x,y));
  }
  return 0;
}

/*
  verified on 2018/08/13
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C&lang=jp
*/


//INSERT ABOVE HERE
signed main(){
  GRL_5_C();
  return 0;
}



Measured memory_bytes: 15980
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    r = S.count("R")
    g = S.count("G")
    b = S.count("B")

    minus = 0
    for k in range(2000):
        if k * 2 + 3 > N:
            break
        for i in range(N-k*2-2):
            if S[i] != S[i+k+1] and S[i] != S[i+2*k+2] and S[i+k+1] != S[i+2*k+2]:
                minus += 1

    print(r*g*b - minus)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
vector<string>v;
void solve(){
	ll n; 
	cin>>n;
	string s = ""; 
	while(n>0){
		if(n)n--;
		else break;
		int x = n%26;
		n/=26;
		s+=char('a'+x);
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3592
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        b: chars
    }

    let mut hmap = std::collections::HashMap::new();
    hmap.insert('A', 'T');
    hmap.insert('T', 'A');
    hmap.insert('C', 'G');
    hmap.insert('G', 'C');
    println!("{}", hmap[&b[0]]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
 
#define INF 1000000000
int dist[10][10];
int cost[10];
char used[10];

void dijkstra(int g)
{
 int x, y, min;
 for(x = 0; x < 10; x++){
  cost[x] = INF;
  used[x] = 0;
 }
 cost[g] = 0;
 while(1){
  min = INF;
  for(x = 0; x < 10; x++){
   if(!used[x] && min > cost[x])
    min = cost[x];
  }
  if(min == INF)
   break;
  for(y = 0; y < 10; y++){
   if(cost[y] == min){
    used[y]=1;
    for(x = 0; x < 10; x++){
     if(cost[x] > dist[x][y] + cost[y])
      cost[x] = dist[x][y] + cost[y];
    }
   }
  }
 }
}

int main() { ;
  int h, w;
  int A[200][200] ;
  long long int sum=0; 
  scanf("%d %d", &h, &w) ;
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      scanf("%d", &dist[i][j]);
    }
  }
  dijkstra(1);
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      scanf("%d", &A[i][j]);
      if(A[i][j] != -1){
        sum+=cost[A[i][j]];
      }
    }
  }
  printf("%lld\n", sum);
  return 0 ;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

  vector<vector<ll>> g(n);
  for (ll i = 1; i < n; ++i) {
    g[i-1].push_back(i);
    g[i].push_back(i-1);
  }
  g[x].push_back(y);
  g[y].push_back(x);

  vector<ll> ans(n);
  for (ll i = 0; i < n; ++i) {
    vector<ll> dist(n, -1);
    dist[i] = 0;
    queue<ll> q;
    q.push(i);
    while (!q.empty()) {
      ll j = q.front();
      q.pop();
      each (k, g[j]) {
        if (dist[k] != -1) continue;
        dist[k] = dist[j]+1;
        q.push(k);
      }
    }

    for (ll j = i+1; j < n; ++j) {
      if (dist[j] > 0) ans[dist[j]]++;
    }
  }

  for (ll i = 1; i < n; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]


#n = int(input)
#h,w = [int(i) for i in readline().split()]
#n,k,s = [int(i) for i in read().split()]

#n = int(input())
#a = [int(i)-1 for i in readline().split()]
n,m = [int(i) for i in readline().split()]
d = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
a = map(int,read().split())

INF = 10**9

#edges = []
for i,(u,v) in enumerate(zip(a,a)):
    u -= 1; v -= 1
    g[u].append((v,i))
    g[v].append((u,i))
    #edges.append((u,v))

ans = [INF]*m

dd = [(c,i) for i,c in enumerate(d)]
dd.sort()

UF = UnionFind(2*n)

def ng():
    print(-1)
    exit()

for c,idx in dd:
    conn = 0
    notconn = []
    for (v,i) in g[idx]:
        if d[v] <= c:
            UF.merge(v,idx+n)
            UF.merge(v+n,idx)
            ans[i] = c
            break
    else:
        ng()
                

s = []

good = set()
bad = set()
for i in range(n):
    p = UF.root(i)
    if p in bad:
        s.append("B")
    elif p in good:
        s.append("W")
    else:
        s.append("W")
        good.add(p)
        bad.add(UF.root(i+n))


print("".join(s))
    

print(*ans,sep="\n")

    
    
    









Measured memory_bytes: 126844
#include <stdio.h>
#include <string.h>
int main(){
    char str[1001], temp[1001], p[1001], cmd[10];
    int q, a, b;
    scanf("%s", str);
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%s", cmd);
        scanf("%d %d", &a, &b);
        if (strcmp(cmd, "print") == 0)
        {
            for (int j = a; j <= b; j++)
            {
                printf("%c", str[j]);
            }
            printf("\n");
        }else if (strcmp(cmd, "replace") == 0)
        {
            scanf("%s", p);
            for (int j = 0; j < strlen(p); j++)
            {
                str[a + j] = p[j];
            }
        }else if (strcmp(cmd, "reverse") == 0)
        {
            strcpy(temp, str);
            for (int j = 0; j < b - a + 1; j++)
            {
                str[a + j] = temp[b - j];
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
  using namespace std;
  typedef long long ll;
  int main()
  {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);

      int n,k;
      cin>>n>>k;
      vector<int>a(n);
      for(int i=0;i<n;i++)
        cin>>a[i];
      sort(a.begin(),a.end());
    ll sum=0;
    for(int i=0;i<n && i<k;i++)
        sum+=a[i];
    cout<<sum<<endl;

    return 0;
  }


Measured memory_bytes: 3656
//02
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  for(int m;cin>>m,m;){
    int mr=360;
    double ms=0;
    for(int i=0;i<m-1;i++){
      int a;
      cin>>a;
      mr-=a;
      ms+=sin(acos(-1)*a/180);
    }
    ms+=sin(acos(-1)*mr/180);
    int nr=360;
    double ns=0;
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
      int a;
      cin>>a;
      nr-=a;
      ns+=sin(acos(-1)*a/180);
    }
    ns+=sin(acos(-1)*nr/180);
    int ans;
    if(ms>ns+1e-9){
      ans=1;
    }else if(ms+1e-9<ns){
      ans=2;
    }else{
      ans=0;
    }
    cout<<ans<<endl;
  }
  return 0;
}
    

Measured memory_bytes: 1196
#include<stdio.h>
int main(void){
	int x[3001];
	int y[3001];
	int i;
	int t;

	for (i = 1; i <= 3000;i++) {
		
		scanf("%d %d",&x[i],&y[i]);
		
		if ((x[i]==0)&&(y[i]==0)) {
			break;
		}
	}
	for (t = 1; t <= 3000; t++) {
		if (t == i)break;
		if (x[t] <= y[t]) {
			printf("%d %d\n", x[t], y[t]);
		}
		else {
			printf("%d %d\n", y[t], x[t]);
		}

	}
	return 0;
	}

Measured memory_bytes: 620
#include <iostream>
#include <vector>
#include <valarray>
#include <numeric>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

std::vector<std::vector<int>> create_bitarrays(int length) {
    if (length == 0) {
        return {{}};
    } else {
        std::vector<std::vector<int>> bitarrays;
        for (auto bits : create_bitarrays(length - 1)) {
            auto bits0 = bits;
            bits0.push_back(0);
            bitarrays.push_back(bits0);

            auto bits1 = bits;
            bits1.push_back(1);
            bitarrays.push_back(bits1);
        }
        return bitarrays;
    }
}

std::valarray<int> to_valarray(std::vector<int> vec) {
    std::valarray<int> array(vec.size());
    for (int i = 0; i < vec.size(); i ++) {
        array[i] = vec[i];
    }
    return array;
}

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

    std::vector<std::vector<int>> F;
    F.assign(N, std::vector<int>(10));
    for (auto& row : F) {
        for (int& f : row) {
            std::cin >> f;
        }
    }

    std::vector<std::vector<int>> P;
    P.assign(N, std::vector<int>(11));
    for (auto& row : P) {
        for (int& p : row) {
            std::cin >> p;
        }
    }

    int max_profit = -1000000000;
    for (auto bits : create_bitarrays(10)) {
        if (to_valarray(bits).sum() == 0) continue;

        int profit = 0;
        for (int i = 0; i < N; i ++) {
            int c = (to_valarray(F[i]) * to_valarray(bits)).sum();
            profit += P[i][c];
        }
        max_profit = std::max(profit, max_profit);
    }
    std::cout << max_profit << std::endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    int a, b, q;
    scanf("%d %d %d", &a, &b, &q);
    vector<ll> s(a + 2), t(b + 2);
    s[0] = -INF;
    for(int i = 1; i <= a; i++){
        scanf("%lld", &s[i]);
    }
    s[a + 1] = INF;
    t[0] = -INF;
    for(int i = 1; i <= b; i++){
        scanf("%lld", &t[i]);
    }
    t[b + 1] = INF;
    for(int i = 0; i < q; i++){
        ll x;
        scanf("%lld", &x);
        int idx1 = lower_bound(s.begin(), s.end(), x) - s.begin();
        int idx2 = lower_bound(t.begin(), t.end(), x) - t.begin();
        ll ans = INF;
        ans = min(ans, x - min(s[idx1 - 1], t[idx2 - 1]));
        if(s[idx1 - 1] < t[idx2]){
            ans = min(ans, x - s[idx1 - 1] + (t[idx2] - s[idx1 - 1]));
            ans = min(ans, t[idx2] - x + (t[idx2] - s[idx1 - 1]));
        }
        if(t[idx2 - 1] < s[idx1]){
            ans = min(ans, x - t[idx2 - 1] + (s[idx1] - t[idx2 - 1]));
            ans = min(ans, s[idx1] - x + (s[idx1] - t[idx2 - 1]));
        }
        ans = min(ans, max(s[idx1], t[idx2]) - x);
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 2944