akhauriyash/Code-Regression huggingface dataset:
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <array>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep1(i,n) for (int i=1;i<=(n);i++)
#define rep2(i,n) for (int i=0;i<=(n);i++)
const int MOD = 1000000007;
int main(void){
  int n,u,v;
  cin>>n>>u>>v;
  int a[n+1];
  int b[n+1];
  int f[n+1]={};
  bool q[n+1]={};
  bool hata[n+1]={};
  vector<int> vec[n+1];
  rep1(i,n-1){
    cin>>a[i]>>b[i];
    vec[a[i]].push_back(b[i]);
    vec[b[i]].push_back(a[i]);
  }
  queue<int> vs;
  vs.push(v);
  q[v]=1;
  int tmp;
  int cost=0;
  int wami=0;
  while(vs.size()!=0){
    tmp=vs.size();
    for(int i=0;i<tmp;++i){
      wami=vs.front();
      vs.pop();
      q[wami]=0;
      f[wami]=cost;
      hata[wami]=1;
      for(int j=0;j<vec[wami].size();++j){
        if(hata[vec[wami][j]]==0&&q[vec[wami][j]]==0){
          vs.push(vec[wami][j]);
          q[vec[wami][j]]=1;
          hata[vec[wami][j]]=1;
        }
      }
    }
    cost++;
  }

  cost=0;
  int f2[n+1]={};
  bool q2[n+1]={};
  bool hata2[n+1]={};
  bool cango[n+1]={};
  vs.push(u);
  q[u]=1;
  while(vs.size()!=0){
    tmp=vs.size();
    for(int i=0;i<tmp;++i){
      wami=vs.front();
      vs.pop();
      q2[wami]=0;
      f2[wami]=cost;
      if(f2[wami]<f[wami]){
        cango[wami]=1;
        for(int j=0;j<vec[wami].size();++j){
          if(hata2[vec[wami][j]]==0&&q2[vec[wami][j]]==0){
            vs.push(vec[wami][j]);
            q2[vec[wami][j]]=1;
            hata2[vec[wami][j]]=1;
          }
        }
      }
    }
    cost++;
  }
  int ans=0;
  rep1(i,n){
    if(ans<f[i]&&cango[i]==1){ans=f[i];}
    //cout<<i<<":"<<f[i]<<" "<<cango[i]<<endl;
  }
  cout<<ans-1<<endl;
  return 0;
}
/*#include <iostream>
#include <string>
using namespace std;

int main(int argc, char *argv[]) {
// このコードは標準入力と標準出力を用いたサンプルコードです。
// このコードは好きなように編集・削除してもらって構いません。
// ---
// This is a sample code to use stdin and stdout.
// Edit and remove this code as you like.

string line;
int index = 1;
while (!cin.eof()) {
getline(cin, line);
cout << "line[" << index++ << "]:" << line << "\n";

}
return 0;
}*/


Measured memory_bytes: 7936
#include<stdio.h>
int main() {
	int i, n, x[100], max = 0;
	char s[100];
	scanf("%d ", &n);
	x[0] = 0;
	for (i = 0;i < n;i++) {
		scanf("%c", &s[i]);
		if (s[i] == 'I') {
			x[i + 1] = x[i] + 1;
		}
		else if (s[i] == 'D') {
			x[i + 1] = x[i] - 1;
		}
		if (x[i + 1] >= max) {
			max = x[i + 1];
		}
	}
		printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
long long solve(long long x){
	long long res=0;
	long long mod=1;
	for(int i=0;i<60;i++){
		mod*=2;
		long long xx=x%mod;
		long long tx=x-xx;
		long long er=mod/2;
		xx-=er-1;
		xx=max(xx,0ll);
		long long times=tx/2+xx;
		if(times%2) res+=mod/2;
//		cout<<x%mod<<" "<<er<<" "<<x%mod-er<<" "<<xx<<" "<<tx<<" "<<times<<" "<<i<<" "<<res<<endl;
	}
	return res;
}
int main(){
	long long a,b;
	cin>>a>>b;
	long long x1=solve(a-1),x2=solve(b);
	cout<<(x1^x2);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

    int NX[N];
    for (int i = 0; i < N; i++) {
        int input;
        cin >> input;
        NX[i] = abs(input - X);
    }

    if (N == 1) {
        cout << NX[0];
        return 0;
    }

    int t = NX[0];
    for (int i = 1; i < N; i++) {
        t = euclidean_gcd(t, NX[i]);
    }

    cout << t;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        // カードの枚数
        Scanner scanner = new Scanner(System.in);
        String input_size = scanner.nextLine();
        int size = Integer.parseInt(input_size);
        // カードの数値
        String input_data = scanner.nextLine();
        String[] data = input_data.split(" ");
        // Scannerクラスのインスタンスをクローズ
        scanner.close();       
        // 入れ替え前のデータ出力
        for (int j = 0 ; j < size ; j++){
            if (j == size - 1) {
                System.out.printf(data[j]);
            } else {
                System.out.printf(data[j] + " ");
            }
        }
        System.out.println("");
        // カードした枚数分繰り返し処理
        for(int i = 1 ; i < size ; i++){
            // 比較するカードの数値の代入
            int number = Integer.parseInt(data[i]); // 
            // 比較対象ポイント
            int j = i - 1;
            data[j+1] = String.valueOf(number);  
            
            while( j >= 0 && Integer.parseInt(data[j]) > number ){
                data[j+1] = data[j];
                j--;   
            }
            data[j+1] = String.valueOf(number);
            // 入れ替え処理が終わった度に出力する。
            for (j = 0 ; j < size ; j++){
                if (j == size - 1) {
                    System.out.printf(data[j]);
                } else {
                    System.out.printf(data[j] + " ");
                }
            }
            System.out.println("");
        }
    }
}



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

int main()
{
   int n,w;cin>>n>>w;
   vector<pair<int,int>> v(n+1);
   ll value=0;
   for(int i=1;i<=n;i++)
   {
       int p,q;cin>>p>>q;
       v[i]={p,q};
       value+=q;
   }
   ll dp[value+1][n+1];
   dp[0][0]=0;
   for(int i=1;i<=n;i++)
       dp[0][i]=0;
   for(int i=1;i<=value;i++)
       dp[i][0]=1e18;
   ll ans=0;
   for(int i=1;i<=value;i++)
   {
       for(int k=1;k<=n;k++)
       {
           if(i-v[k].second>=0)
               dp[i][k]=min(dp[i-v[k].second][k-1]+v[k].first,dp[i][k-1]);
           else
               dp[i][k]=dp[i][k-1];
           if(dp[i][k]<=w)
               ans=i;
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 79104
import java.util.*;
public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];

        for(int i = 0; i < n; i++) {
            int val = sc.nextInt();
            arr[val - 1] = i + 1;
        }
        for(int i = 0; i < n; i++)
            System.out.println(arr[i]);
    }

}

Measured memory_bytes: 60716
#include<bits/stdc++.h>
const double PI=3.14159265358979323846;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
int main(void){
    int n;cin>>n;
    int a[200000]={0};
    rep(i, n-1){int tmp;cin>>tmp;a[tmp-1]++;}
    rep(i, n){co(a[i]);}
}



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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  vector<ll> num(N+1);
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    A.at(i) = a;
    num.at(a)++;
  }
  ll comb = 0;
  for (ll j = 1; j <= N; j++) {
    comb += num.at(j) * (num.at(j) - 1) / 2;
  }
  for (ll i = 0; i < N; i++) {
    ll a = A.at(i);
    ll x = num.at(a);
    cout << comb - x * (x-1) / 2 + (x-1) * (x-2) / 2 << "\n";
  }
  
  

  return 0;
}



Measured memory_bytes: 6360
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e6;
    
     int mod= 1e9+7;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
   
  
      
     void solve(){
       
       int n,d;
       cin>>n>>d;
       int cov=d*2+1;
       cout<<(n/cov+(n%cov>0?1:0));     
              
     }
   
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))


#if 1
//No.1
int main()
{
	INT N;
	cin >> N;

	int tmp = N % 10;
	if (tmp == 3) { cout << "bon"; }
	else if (tmp == 0 || tmp == 1 || tmp == 6 || tmp == 8) { cout << "pon"; }
	else { cout << "hon"; }

	return 0;
}
#endif


Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll a, b, c;
    cin >> a >> b >> c;

    if (c <= b + a) {
        cout << b + c;
    } else {
        cout << 2LL * b + a + 1LL;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;

int main() {
	int N;
	cin >> N;
	LL a[50];
	for (int i = 0; i < N; i++) cin >> a[i];
	LL ans = 0;
	while (1) {
		LL sum = 0;
		for (int i = 0; i < N; i++) sum += a[i] / N;
		if (sum == 0) break;
		for (int i = 0; i < N; i++) {
			LL d = a[i] / N;
			a[i] -= d*N;
			a[i] += sum - d;
		}
		ans += sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int max = a;
        int cnt;
        
        if( max < b )max = b;
        if( max < c )max = c;
        
        cnt = a+b+c+(max*10)-max;
            
        System.out.println(cnt);
        
	  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ll long long
#define INF 999999999

const ll mod = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
	cin >> n;
	if (n >= 1000){cout << "ABD" << endl;}
	else {cout << "ABC" << endl;}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	string st; cin >> st;
	for (auto&c : st) {
		int n = c - 'A';
		n = (n + 23) % 26;
		c = 'A' + n;
	}
	cout << st << endl;
	return 0;
}

Measured memory_bytes: 3152
flag = True
n = int(input())

a = input().split()

a.sort()
start = 0
for i in a:
    for j in a[start-1:start+1:2]:
        if i == j:
            flag = False
            break
    start += 1
    
if flag:
    print('YES')
else:
    print('NO')
        

Measured memory_bytes: 19160
import numpy as np
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
 
a = np.array(A)
b = np.array(B)
 
# cはaとbの要素をすべて足したもの
c = a + b
# 降順にソート
csorted = np.sort(c)[::-1]
# bの総和
bsum = np.sum(b)
# csortedの奇数番目を足していって最後にbsumの値を引けば求まる。
csum = 0
for i in range(N):
    if i % 2 == 0:
        csum += int(csorted[i])
 
ans = csum - bsum
 
print(ans)


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

int main(void){
   int n;
   cin>>n;
   cout<<n<<":";
   
   int i=2,m=n;
   while(m!=1){
       if(m%i==0){
           m/=i;
           cout << " " << i;
       }else{
           if(i>=3){i+=2;}
           else{i++;}
       }
       if(i*i>n) {
           cout << " " << m;
           break;
       }
           
   }
   cout<<endl;
}



Measured memory_bytes: 3116
def main():
    import collections
    N = int(input())
    A = list(map(int, input().split()))

    table = collections.defaultdict(int)

    for x in A:
        table[x] += 1

    ret = 0
    for x in table:
        ret += (table[x]*(table[x]-1)) // 2
    for x in A:
        tmp = ret
        tmp -= (table[x]*(table[x]-1)) // 2
        tmp += ((table[x]-1)*(table[x]-2)) // 2
        print(tmp)


main()


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

int main()
{
	double memo[100][100];
	double data[100][100];
	int n, m;

	while (true)
	{
		cin >> n >> m;
		if (n + m == 0) return 0;

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

		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				memo[i][j] = -1;
				if (i == 0) memo[i][j] = 1.0;
			}
		}

		for (int i = 1; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k < n; k++)
				{
					memo[i][j] = max(memo[i][j], memo[i - 1][k] * data[k][j]);
				}
			}
		}

		double Max = -1;
		for (int i = 0; i < n; i++)
		{
			Max = max(Max, memo[m - 1][i]);
		}
		printf("%.2f\n", Max);
	}

	return 0;
}

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

#define ll long long


int main(){
	ll N; cin >> N;
	ll mn = 2e18, mx = -2e18;
	vector < pair < ll, ll > > V(N);
	for (int i = 0; i < N; i ++){	
		ll X, Y; cin >> X >> Y; V[i].first = X; V[i].second = Y;
	}



	int res = 0, smallest, cur;
    for (int p : {1, -1}) {
        for (int q : {1, -1}) {
            smallest = p * V[0].first + q * V[0].second;
            for (int i = 1; i < N; ++i) {
                cur = p * V[i].first + q * V[i].second;
                res = max(res, cur - smallest);
                smallest = min(smallest, cur);
            }
        }
    }
    cout << res << "\n";

}

Measured memory_bytes: 6404
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int main(){

	string s[1000],tmp;
	int sumresult[1000];
	int length,i,j;
	char ctmp;

	i = 0;
	for(;;){

		getline(cin,s[i]);
		if(s[i] == "0")break;

		sumresult[i] = 0;
		tmp = s[i];
		for(j=0;j<tmp.length();j++){
			ctmp = tmp[j];
			sumresult[i] += atoi(&ctmp);
		}

		i++;
	}
	for(j=0;j<i;j++){
		cout << sumresult[j] << endl;
	}

	return 0;
}


Measured memory_bytes: 3244
list_1 = list(map(int,input().split()))
list_2 = list(map(int,input().split()))
list_3 = list(map(int,input().split()))

#n,m = map(int,raw_input().split())
#list_a = []
#for i in range(M) 
list_a=list_1


for x in list_2:
    list_a.append(x)


for x in list_3:
    list_a.append(x)


N = int(input())
#list_b = [int(x) for x in input().split()]
#list_b = list(map(int,input().split()))


list_b=[]
for k in range(N):
    b=int(input())
    list_b.append(b)


list_c = [0,0,0,0,0,0,0,0,0]
for i in range(N):
    for j in range(9):
        if list_a[j] == list_b[i]:
            list_c[j] = 1

flag=0
if list_c[0]==1 and list_c[1]==1 and list_c[2]==1:
    flag=1
if list_c[3]==1 and list_c[4]==1 and list_c[5]==1:
    flag=1
if list_c[6]==1 and list_c[7]==1 and list_c[8]==1:
    flag=1
if list_c[0]==1 and list_c[3]==1 and list_c[6]==1:
    flag=1
if list_c[1]==1 and list_c[4]==1 and list_c[7]==1:
    flag=1
if list_c[2]==1 and list_c[5]==1 and list_c[8]==1:
    flag=1
if list_c[0]==1 and list_c[4]==1 and list_c[8]==1:
    flag=1
if list_c[2]==1 and list_c[4]==1 and list_c[6]==1:
    flag=1
    
if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
import java.util.*;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int G = sc.nextInt();
        int B = sc.nextInt();
        int n = sc.nextInt();

        int count = 0;
        int rMax = n / R;
        for (int r = 0; r <= rMax; r++) {
            int gMax = (n - R * r) / G;
            for (int g = 0; g <= gMax; g++) {
                int b = (n - R * r - G * g) / B;
                if (r * R + g * G + b * B == n) count++;
            }
        }
        // write your code
        System.out.println(count);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 23124
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
 
n = int(readline())
a = Counter(map(int, readline().split()))
q = int(readline())
L = []
for i in range(q):
  L.append(list(map(int, readline().split())))
 
s = sum(x * y for x, y in a.items())
for b, c in L:
  # print(a)
  if b in a:
    s += (c - b) * a[b]
    a[c] += a[b]
    del a[b]
  print(s)


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

using lli = long long int;
int inf = 1000000007;
using namespace std;

int N, A, B, C, D;
string S;

int main()
{
	cin >> N >> A >> B >> C >> D;
	cin >> S;
	for (int i = A - 1; i < C; i++)
		if (S[i] == '#' && S[i] == S[i + 1]) { cout << "No" << endl; return 0; }
	for (int i = B - 1; i < D; i++)
		if (S[i] == '#' && S[i] == S[i + 1]) { cout << "No" << endl; return 0; }
	//交差するか
	if (C < D) {
		//しない
		cout << "Yes" << endl;
		return 0;
	}
	//A- B-D - C　みたいなとき
	//A-Dの間で[...]があれば入れ替え可能
	for (int i = B - 2; i <= D - 2; i++)
		if (S[i] == '.' && S[i] == S[i + 1] && S[i] == S[i + 2]) { cout << "Yes" << endl; return 0; }
	//cout << la << " " << ra << endl;
	cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream> 
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long
#define pb push_back

int main(int argc, char** argv) {
	int N,M;
	cin>>N>>M;

	cout<<max(M*(M-1),0)/2+max(0,N*(N-1)/2);

	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
  ll n, m, d;
  while(cin>>n>>m>>d){
    ld ans;
    if(d==0)
      ans=(((n-d)*(m-1))/((ld)(n*n)));
    else
      ans=(((n-d)*2*(m-1))/((ld)(n*n)));
    cout<<fixed<<setprecision(9)<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 384
N = int(input())
lis = list(map(int,input().split()))

A, B= 0,0
for i in range(N):
    if i % 2 == 0:
        A += max(lis)
        lis.remove(max(lis))
    else:
        B += max(lis)
        lis.remove(max(lis))

print(A-B)

Measured memory_bytes: 3064
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;
const int MAX = 10000;

/** Problem0565 : Lunch **/
int main()
{
	int minP=INF, minJ=INF;
	rep(i, 3) {
		int n;
		cin >> n;
		if (minP > n)
			minP = n;
	}
	rep(i, 2) {
		int n;
		cin >> n;
		if (minJ > n)
			minJ = n;
	}
	cout << minP + minJ - 50 << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define low(x) ((x)&(-x))
#define lc(x) (2*x)
#define rc(x) (2*x+1)
#define mid (l+r>>1)

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e5+5;
int g[maxn],f[maxn][2];
int n;

template<typename Ty>
bool read1n(Ty &x)
{
    char ch; bool neg=false;
    for(ch=getchar();ch<'0'||'9'<ch;ch=getchar())
        if(ch=='-')
            neg=true;
        else if(ch==-1)return false;
    for(x=0;'0'<=ch&&ch<='9';ch=getchar())
        x=(x<<1)+(x<<3)+ch-'0';
    if(neg) x=-x;
    return true;
}

int main(){
    #ifdef YHY_TEST
   // freopen("D:\\in.txt","r",stdin);
    #endif // YHY_TEST
    scanf("%d",&n);
    int i,j,a,b,x,y;
    for(i=1;i<=n;i++){
        scanf("%d",&g[i]);
        f[g[i]][i%2]++;
    }
    a=0;b=0;
    for(i=1;i<maxn;i++){
        if(a<f[i][0]){
            a = f[i][0];x = i;
        }
        if(b<f[i][1]){
            b = f[i][1];y = i;
        }
    }
    if(x==y){
        int a2=0,b2=0;
        for(i=1;i<maxn;i++){
            if(i==x)continue;
            a2 = max(a2,f[i][0]);
            b2 = max(b2,f[i][1]);
        }
        printf("%d\n",min(n-a-b2,n-b-a2));
        return 0;
    }
    printf("%d",n-a-b);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
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;

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

// 木グラフ．連結で閉路を持たない無向グラフ
int N, M; cin >> N >> M;
VI cnt(N+ 1, 0);
rep(i, 0, M) {
    int a, b;
    cin >> a >> b;
    ++cnt[a]; 
    ++cnt[b];
}

rep(i, 1, N+1){
    if (cnt[i] % 2 != 0){
        cout << "NO\n";
        return 0;
    }
}

cout << "YES\n";


}

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



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef pair< int, int > Pi;
typedef pair< int, Pi > Pii;
const int INF = 1 << 29;
const int dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0};
  
struct Field
{
  int W, H, X, Y;
  int L[500][500];
};
  
void InputField(Field& e)
{
  cin >> e.W >> e.H >> e.X >> e.Y;
  --e.X, --e.Y;
  for(int i = 0; i < e.H; i++) {
    for(int j = 0; j < e.W; j++) {
      cin >> e.L[i][j];
    }
  }
}
int BFSField(const Field& e, vector< int >& cost)
{
  priority_queue< Pii, vector< Pii >, greater< Pii > > que;
  que.push({1, make_pair(e.X, e.Y)});
  int min_cost[500][500];
  fill_n(*min_cost, 500 * 500, INF);
  min_cost[e.X][e.Y] = 1;
  map< int, int > cur;
  while(!que.empty()) {
    Pi point = que.top().second;
    int c = que.top().first;
    que.pop();
    if(c > min_cost[point.first][point.second]) continue;
    cur[c]++;
    for(int i = 0; i < 4; i++) {
      int ny = point.second + dy[i], nx = point.first + dx[i];
      if(ny < 0 || nx < 0 || ny >= e.H || nx >= e.W) continue;
      if(min_cost[nx][ny] > max(c, e.L[ny][nx])) {
        min_cost[nx][ny] = max(c, e.L[ny][nx]);
        que.push({min_cost[nx][ny], Pi(nx, ny)});
      }
    }
  }
  cost.assign(e.W * e.H + 1, INF);
  int sum = 0;
  cost[0] = 0;
  for(auto e : cur) {
    sum += e.second;
    cost[sum] = e.first;
  }
  for(int i = cost.size() - 2; i >= 0; i--) {
    cost[i] = min(cost[i + 1], cost[i]);
  }
}
  
int main()
{
  int R;
  Field A, B;
  
  while(cin >> R, R) {
    InputField(A);
    InputField(B);
    vector< int > a, b;
    BFSField(A, a);
    BFSField(B, b);
    
    int ret = INF;
    for(int i = 0; i < a.size(); i++) {
      if(R - i >= 0 && R - i < b.size()) {
        ret = min(ret, a[i] + b[R - i]);
      }
    }
    
    cout << ret << endl;
  }
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ans(n);
    rep(i,2) {
        int cnt = 0;
        rep(j,n) {
            if (s[j] == 'R') cnt++;
            else {
                ans[j] += cnt/2;
                ans[j-1] += (cnt+1)/2;
                cnt = 0;
            }
        }
        reverse(ans.begin(), ans.end());
        reverse(s.begin(), s.end());
        rep(j,n) {
            if (s[j] == 'L') s[j] = 'R';
            else s[j] = 'L';
        }
    }
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(a<b){
    int r=b;
    b=a;
    a=r;
  }
 if(a%b==0) return b;
   else return gcd(b,a%b);
}
int gcd2(int a,int b,int c){
  return gcd(a,gcd(b,c));
}
int main() {
  long int k,ans=0;
  cin >> k;
  for(int a=1;a<k+1;a++){
    for(int b=1;b<k+1;b++){
      for(int c=1;c<k+1;c++){
       ans+=gcd2(a,b,c);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void) {
	int a[30], l;
	char c[30];
	string s;
	for (int i = 0; i < 26; i++) {
		c[i] = 'a' + i;
		a[i] = 0;
	}
	while (cin >> s) {
		l = s.size();
		for (int i = 0; i < l; i++) {
			if ('A' <= s[i] && s[i] <= 'Z') {
				s[i] = s[i] - 'A' + 'a';
			}
			for (int j = 0; j < 26; j++) {
				if (s[i] == c[j]) {
					a[j]++;
				}
			}
		}
	}
	for (int i = 0; i < 26; i++) {
		cout << c[i] << " : " << a[i] << endl;
	}
	return 0;
}

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

string str;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> str;
    for(int x = 0; x < 4; x++){
        int licz = 0;
        for(int y = 0; y < 4; y++){
            if(str[x] == str[y])
                licz++;
        }
        if(licz != 2){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int a,b;
  cin>>a>>b;
  VI A(3);
  A[0]=a+b;
  A[1]=a-b;
  A[2]=a*b;
  sort(A.begin(),A.end());
  cout<<A[2]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  ll t1 = h1*60 + m1;
  ll t2 = h2*60 + m2;
  ll t = t2 - t1;
  if (t < 0) t += 24*60;
  cout << t - k << endl;

  return 0;
}


Measured memory_bytes: 3636
#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,m,x,y;
	int a[111]={},b[111]={};
	cin>>n>>m>>x>>y;
	FOR(i,0,n)cin>>a[i];
	FOR(i,0,m)cin>>b[i];
	FOR(t,x+1,y+1){
		int f=1;
		FOR(i,0,n){
			if(a[i]>=t){
				f=0;
			}
		}
		FOR(i,0,m){
			if(b[i]<t){
				f=0;
			}
		}
		if(f){
			cout<<"No War"<<endl;
			return 0;
		}
	}
	cout<<"War"<<endl;
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(1,0); }
	V<V<pin>> qab(2);
  int sz=ab.size();
  qab[0].reserve(sz);
  qab[1].reserve(sz);
	for (pin &x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2,x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2,(x.second + 1) / 2)); }
	}
  int c=0;
  		for (pin &x : qab[0]) {
			int qc = (2 * x.first + x.second)%3;
          c^=(qc+1);
		}
		if (!c) {
			pin ans = solve(qab[1], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += 1;
			return ans;
		}
    c=0;
		for (pin &x : qab[1]) {
			int qc = (2 * x.first + x.second)%3;
          c^=(qc+1);
		}
		if (!c) {
			pin ans = solve(qab[0], ex - 1);
			ans.first *= 2; ans.second *= 2;
			return ans;
		}
	for(pin &v:ab) { v.first++; }
	pin ans = solve(ab, ex); ans.first--;
	return ans;
}
signed main() {
	long long inf = 2e17;
	int n; scanf("%lld", &n);
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; scanf("%lld", &a); scanf("%lld", &b);
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 70);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Measured memory_bytes: 11136
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	int a[n + 1];
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i - cnt != a[i]) cnt++;
	}
	if (cnt == n) cout << -1 << "\n";
	else cout << cnt << "\n";
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}

/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*最大公約数*/
unsigned long long GCD(long long L,long long R){
    if(L>R){
        long long temp=R;
        R = L;
        L = temp;
    }
    unsigned long long pp=0,ppt=0;
    unsigned long long ans=0;
    if(R%L==0){
        ans = L;
    }else{
        while(true){
            ppt = pp;
            pp=R%L;
            if(pp == 0){
                ans = ppt;
                break;
            }
            R = L;
            L = pp;
        }
    }    
    return ans;    
}

/*最小公倍数*/
unsigned long long LCM(long long L,long long R){
    unsigned long long ans;
    unsigned long long gcd = GCD(L,R);
    ans = (L/gcd)*R;
    return ans;
}

/*Combination set*/
#define mod 1000000007
#define maxcomb 3000/*大きいものを求めるときはここを変える*/
vector<long long> fc(maxcomb+1);
vector<long long> ifc(maxcomb+1);
long long modpow(long long x,long long n){
    long long ans = 1;
    while(n > 0){
        if(n & 1) {
            ans = ans*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}
void Conb(){
    fc[0]= 1;
    ifc[0]=1;
    for(long long i=0;i<maxcomb;i++){
        fc[i+1] = fc[i]*(i+1)%mod;//n!(mod)
        ifc[i+1] = ifc[i]*modpow(i+1,mod-2)%mod;//k!^{M-2} (mod)
    }
}
unsigned long long Combination(long long L,long long R){
    unsigned long long up=1,ans;
    Conb();
    if(L==0&&R==0){
        return 1;
    }else if(L<R||L<0){
        return 0;
    }else{
        long long t = ifc[L-R]*ifc[R]%mod;
        ans = t*fc[L]%mod;
    }
    return ans;
}
/*Combination set ここまで*/

/*ここから*/
int main() {
    string s;
    cin >> s;
    if(s[s.length()-1]=='s'){
        s.insert(s.length(),"es");
    }else{
        s.insert(s.length(),"s");
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3644
n , m = map(int,input().split())
h = list(map(int,input().split()))
ma = [0] * (n)
for i in range(m):
	a , b = map(int,input().split())
	a , b = a - 1 , b - 1
	ma[a] = max(ma[a] , h[b])
	ma[b] = max(ma[b] , h[a])

ans = 0
for i in range(n):
	ans += h[i] > ma[i]

print(ans)

Measured memory_bytes: 20120
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef vector<int> vi;
const int N=2010;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int a[N],n;
bool v[N];
struct cmp{ bool operator () (const vi &a,const vi &b) { return a.back()<b.back(); } };
vi merge(vector<vi> p) {
	priority_queue<vi,vector<vi>,cmp>q;
	for (auto k:p) reverse(k.begin(),k.end()),q.push(k);
	vi ans,t;
	while (!q.empty()) {
		t=q.top();q.pop();
		ans.push_back(t.back());t.pop_back();
		if (!t.empty()) q.push(t);
	}
	return ans;	
}
inline vi dfs(int k) {
	v[k]=true;
	vector<vi>ans;
	for (int i=1;i<=n;i++)
		if (!v[i]&&__gcd(a[k],a[i])!=1)
			ans.push_back(dfs(i));
	vi v=merge(ans);
	v.insert(v.begin(),a[k]);
	return v;
}
int main()
{
	n=gi();
	for (int i=1;i<=n;i++) a[i]=gi();
	sort(a+1,a+1+n);
	vector<vi>ans;
	for (int i=1;i<=n;i++)
		if (!v[i])
			ans.push_back(dfs(i));
	vi v=merge(ans);
	for (auto k:v)
		printf("%d ",k);
	putchar(10);
	return 0;
}


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

int c[3][3];

void _main() {
    REP (i, 3) REP (j, 3) cin >> c[i][j];
    REP (a1, 101) {
        int b1 = c[0][0] - a1;
        int b2 = c[0][1] - a1;
        int b3 = c[0][2] - a1;
        int a2 = c[1][0] - b1;
        int a3 = c[2][0] - b1;
        if (a2 + b2 != c[1][1]) continue;
        if (a2 + b3 != c[1][2]) continue;
        if (a3 + b2 != c[2][1]) continue;
        if (a3 + b3 != c[2][2]) continue;
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 100000000
#define mod 1000000007
#define ld long double
#define point complex<double>
#define pi  acos(-1)
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;



	int main(){
		int arr[5];
		for(int i=0;i<5;i++)
		{
			cin>>arr[i];
			if(arr[i]==0)cout<<i+1<<" ";
		}
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int d_set=sc.nextInt();
		int[] ary=new int[d_set];
		for(int i=0; i<d_set; i++) {
			ary[i]=sc.nextInt();
		}
		int min=114514810;
		int max=-114514810;
		int tmp1=0;
		int tmp2=0;
		for(int i=0; i<d_set; i++) {
			for(int j=i; j<d_set; j++) {
				if(ary[i]>ary[j]) {
					tmp1=ary[i];
					tmp2=ary[j];
					ary[i]=tmp2;
					ary[j]=tmp1;
				}
			}
		}
		System.out.println(Math.abs(ary[d_set-1]-ary[0]));
	}
}

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

const int N = 200005;
int n, x, y;

int a[N], b[N], c[N], d[N];
struct tree {
	int head[N], tot;
	struct edge { int to, nxt; } e[N << 1];
	void link(int x, int y) {
		e[++tot] = (edge) {y, head[x]}, head[x] = tot;
		e[++tot] = (edge) {x, head[y]}, head[y] = tot;
	}
} R, B;
bool mark[N];

int depB[N], fB[N];
void dfs0(int x) {
	static auto head = B.head;
	static auto e = B.e;
	for (int i = head[x]; i; i = e[i].nxt)
		if (e[i].to != fB[x])
			fB[e[i].to] = x, depB[e[i].to] = depB[x] + 1, dfs0(e[i].to);
}
int ans = 0;
void dfs1(int x, int f = 0, int dep = 0) {
	if (dep >= depB[x]) return;
	if (mark[x]) std::cout << -1 << '\n', std::exit(0);
	ans = std::max(ans, depB[x]);
	static auto head = R.head;
	static auto e = R.e;
	for (int i = head[x]; i; i = e[i].nxt)
		if (depB[e[i].to] > dep && e[i].to != f) dfs1(e[i].to, x, dep + 1);
}

bool qaq(int x, int y) {
	if (depB[x] > depB[y]) std::swap(x, y);
	auto f = fB;
	return f[y] == f[x] || f[y] == x || f[f[y]] == x;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> x >> y;
	for (int i = 1; i < n; ++i)
		std::cin >> a[i] >> b[i], R.link(a[i], b[i]);
	for (int i = 1; i < n; ++i)
		std::cin >> c[i] >> d[i], B.link(c[i], d[i]);
	dfs0(y);
	for (int i = 1; i < n; ++i)
		if (!qaq(a[i], b[i])) mark[a[i]] = mark[b[i]] = 1;
	dfs1(x), std::cout << ans * 2 << '\n';
	return 0;
}

Measured memory_bytes: 20864
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N, K = read_values()
    H = read_list()
    H.sort(reverse=True)
    print(sum(H[min(N, K):]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 25748
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c) \
    for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;
const lint MOD = 1e9 + 7;

using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> a(n);
    rep(i, n) cin >> a[i];
    lint sum = 0;
    rep(i, n) {
        sum += a[i];
        sum %= MOD;
    }
    lint ans = 0;
    rep(i, n) {
        lint tmp = (sum - a[i]) % MOD;
        if (tmp < 0) tmp += MOD;
        ans += tmp * a[i];
        ans %= MOD;
    }
    cout << (ans * modinv(2, MOD)) % MOD << endl;
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int a=0;
  for(int i=0;i<N-1;i++)a+=v[i];
  if(a>v[N-1])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

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

        int result = 0;
        for (int i = 1; i <= n; i++) {
            int total = 0;
            int num = i;
            while (num > 0) {
                total += num % 10;
                num /= 10;
            }
            if (a <= total && total <= b) {
                result += i;
            }
        }
        System.out.println(result);
    }
}


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

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

  for (int i = 0; i <= 25; i++) {
    for (int j = 0; j < 15; j++) {
      if (n == i * 4 + j * 7) {
        std::cout << "Yes" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "No" << std::endl;
  return 0;
}


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

int bi(ll x){
  int n=0;
  while(x%2==0){
    n++;
    x /= 2;
  }
  return n;
}

int main(){
  int N;
  cin >> N;
  ll A=0;
  cin >> A;
  int ans = bi(A);
  for(int i=0;i<N-1;i++){
    cin >> A;
    ans = min(ans,bi(A));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++){
        if(i==a){
            if(s[i]=='-'){
                sum++;
            }
        }
        else{
            if(s[i]=='-'){
                sum+=114514;
            }
        }
    }
    if(sum==1){
        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 && b == c) || (a != b && b!= c && c != a)) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 1000002
int main(){
    int mod_table[MAX]={0};
    int K,ans=1;
    int num=7;
    scanf("%d",&K);
    while(1){
        if(num%K==0)
            break;
        if(mod_table[num%K]){
            ans = -1;
            break;
        }
        mod_table[num%K] = 1;
        num %= K;
        num *= 10;
        num += 7;
        num %= K;
        ans++;
    }
    printf("%d",ans);
}


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

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

  vector<double> v(N);

  for (int i = 0; i < N; i++){
    cin >> v.at(i);
  }

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

  double ans = v.at(0);

  for (int i = 1; i < N; i++){
    ans = (ans + v.at(i)) / 2;
  }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B), x(M), y(M), c(M);
    for (int i = 0; i < A; i++) cin >> a[i];
    for (int i = 0; i < B; i++) cin >> b[i];
    for (int i = 0; i < M; i++) cin >> x[i] >> y[i] >> c[i];

    int mina = 100002, minb = 100002;
    for (int i = 0; i < A; i++) if (a[i] < mina) mina = a[i];
    for (int i = 0; i < B; i++) if (b[i] < minb) minb = b[i];
    int ans = mina+minb;
    for (int i = 0; i < M; i++) {
        if (a[x[i]-1]+b[y[i]-1]-c[i] < ans) {
            ans = a[x[i]-1]+b[y[i]-1]-c[i];
        }
    }

    cout << ans << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


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

int main2() {
  int a[3];
  REP(i, 3) a[i] = nextInt();
  sort(a, a+3);
  cout << a[2] - a[0] << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<bits/stdc++.h> 
#include <vector>
 
int main() {
	// your code goes here
  int n;
  cin>>n;
  vector<double> p (n, 0);
  for(int i=0;i<n;i++){
  	cin>>p[i];
  }
  
  vector<vector<double>> dp (n , vector<double> (n +1 , 0));
  double temp=1;
  for(int i=0;i<n;i++){
  	dp[i][0]=(1-p[i])*temp;
  	temp=temp*(1-p[i]);
  }
  dp[0][1]=p[0];
  for(int i=1;i<n;i++){
  	for(int j=1;j<=n;j++){
  		dp[i][j]=(1-p[i])*dp[i-1][j] + p[i]*dp[i-1][j-1];
  	}
  }
  double ans=0;
  for(int i=n/2 + 1;i<=n;i++){
  	ans+=dp[n-1][i];
  }
  cout<<setprecision(9)<<ans<<endl;
  
}

Measured memory_bytes: 73780
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;


int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);	
	string str;
	cin >> str;
	int ans = 0;
	for (int i = 0, j = str.length() - 1; i < j;) {
		if (str[i] == 'x') {
			if (str[j] == 'x') {
				i++;
				j--;
				continue;
			} else {
				i++;
				ans++;
				continue;
			}		
		}
		if (str[j] == 'x') {
			j--;
			ans++;
			continue;
		}
		if (str[i] != str[j]) {
			cout << "-1" << endl;
			return 0;
		}
		i++;
		j--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512