akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;


class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    int ans;
    int N, K;
    List<int>[] es;

    void calc()
    {
        cin = new Scanner();
        N = cin.nextInt();
        K = cin.nextInt();
        es = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<int>();
        }
        for (int i = 0; i < N - 1; i++)
        {
            int a = cin.nextInt() - 1;
            int b = cin.nextInt() - 1;
            es[a].Add(b);
            es[b].Add(a);
        }

        ans = 99999;

        for (int i = 0; i < N; i++)
        {
            if (K % 2 == 0) calc(i, i);
            else
            {
                foreach (int j in es[i])
                {
                    if(i < j) calc(i, j);
                }
            }
        }
        
        Console.WriteLine(ans);
    }

    void calc(int a, int b)
    {
        int[] dist;
        Queue<int> q;

        int MAX = 99999;

        dist = new int[N];
        for (int i = 0; i < N; i++)
        {
            dist[i] = MAX;
        }
        dist[a] = 0;
        dist[b] = 0;
        q = new Queue<int>();
        q.Enqueue(a);
        if(a != b) q.Enqueue(b);
        int cnt = 0;

        while (q.Count != 0)
        {
            int now = q.Dequeue();
            if (dist[now] > K / 2) break;
            cnt++;
            foreach (var next in es[now])
            {
                if (dist[next] != MAX) continue;
                dist[next] = dist[now] + 1;
                q.Enqueue(next);
            }
        }
        
        ans = Math.Min(ans, N - cnt);
    }


}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 39752
use std::{io::{self, prelude::*}, *};

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let mut scan = Scanner::new(stdin.lock());
    let mut w = io::BufWriter::new(stdout.lock());
    

    let n:usize = scan.next();

    let mut now = 0;

    for _ in 0..n {
        let a:i32 = scan.next();
        let b:i32 = scan.next();
        if a == b {
            now += 1;
            if now == 3 {
                writeln!(w, "Yes");
                return;
            }
        }
        else {
            now = 0;
        }
    }
    
    writeln!(w, "No");
}
 
 
pub struct Scanner<B> {
    reader: B,
    buf_str: Vec<u8>,
    buf_iter: std::str::SplitWhitespace<'static>,
}
impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_whitespace()
        }
    }
    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = std::str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace()) }
        }
    }
}

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

int main(void)
{
  char s[15];
  int counto=0;
  int countx=0;
  for(int i=0;i<15;i++){
    cin>>s[i];
    if(s[i]=='o')
      counto++;
    else if(s[i]=='x')
      countx++;
  }  
  if(countx<=7)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int p;
    string S;
    int N, M;
    cin >> N >> M;

    vector<int> pen(N);
    vector<bool> ac(N);

    int ansAc = 0;
    int ansPen = 0;

    rep(i, M) {
        cin >> p >> S;
        --p;
        if (S == "AC") {
            if (!ac[p]) {
                ++ansAc;
                ansPen += pen[p];
                ac[p] = true;
            }
        } else {
            ++pen[p];
        }
    }

    cout << ansAc << ' ' << ansPen << endl;

    return 0;
}


Measured memory_bytes: 640
def c_skill_up():
    N, M, X = [int(i) for i in input().split()]
    Algo = [[int(i) for i in input().split()] for j in range(N)]
    ans = float('inf')
    for bits in range(1, 1 << N):
        select = []
        for d in range(N):
            if (bits >> d) & 1 == 1:
                select.append(d)

        understanding = [0] * M
        tmp = 0
        for i in select:
            c, *a = Algo[i]
            tmp += c
            for k, p in enumerate(a):
                understanding[k] += p
        if len([1 for u in understanding if u >= X]) == M:
            ans = min(ans, tmp)
    return ans if ans != float('inf') else -1

print(c_skill_up())

Measured memory_bytes: 9236
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;

string s = "0123456789AB";
string goal = "0123456789AB0";

vector<vector<int>> adj = {
    {2},
    {2,5},
    {0,1,3,6},
    {2,7},
    {5},
    {1,4,6,9},
    {2,5,7,10},
    {3,6,8,11},
    {7},
    {5,10},
    {6,9,11,12},
    {7,10},
    {10}
};

int solve(string stat) {
    map<string, int> dist;
    dist[stat] = 0;
    queue<string> q;
    q.push(stat);
    while ( ! q.empty()) {
        string s = q.front();
        q.pop();
        int diff = 0;
        for (int k=0; k<13; ++k) {
            if (s[k] != '0') {
                diff += s[k] != goal[k];
            }
        }
        if ( ! diff) {
            return dist[s];
        }
        if (20 < dist[s] + diff) {
            continue;
        }
        for (int i=0; i<13; ++i) {
            if (s[i] != '0') continue;
            for (int j : adj[i]) {
                string next = s;
                next[i] = s[j];
                next[j] = s[i];
                if (dist.find(next) == dist.end()) {
                    dist[next] = dist[s] + 1;
                    q.push(next);
                }
            }
        }
    }
    return 21;
}

int main() {
    ios::sync_with_stdio(false);
    while (1) {
        string stat = "";
        int k;
        for (int i=0; i<13; ++i) {
            if (cin >> k && !~k) return 0;
            stat += s[k];
        }
        int ans = solve(stat);
        if (ans <= 20) {
            cout << ans << endl;
            continue;
        }
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 12320
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            String n = sc.next();
            if(n.equals("0000")) break;

            boolean boo = true;
            for(int i=0; i<n.length(); i++){
                if(n.charAt(i)!=n.charAt(0)) boo = false;
            }
            if(boo){
                System.out.println("NA");
                continue;
            }

            int cnt = 0;
            while(!n.equals("6174")){
                char[] nn = n.toCharArray();
                Arrays.sort(nn);
                int min = 0, max = 0;
                int ten = 1;
                for(int i=0; i<nn.length; i++){
                    min += (nn[nn.length-1-i]-'0') * ten;
                    max += (nn[i]-'0') * ten;
                    ten *= 10;
                }
                n = String.valueOf(max - min);
                while(n.length()!=4) n = "0" + n;
                cnt++;
            }
            System.out.println(cnt);
        }
    }

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

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  
  vector<ll> a(n + 1);
  for(int i = 1; i <= n; i++){
    cin >> a.at(i);
    a.at(i) += a.at(i - 1);
  }
  for(int i = 1; i <= n; i++){
    a.at(i) -= i;
    a.at(i) %= k;
  }
  
  map<ll, ll> mp;
  ll ans = 0;
  for(int i = 0; i <= n; i++){
    if(i < k){
      ans += mp[a.at(i)];
      mp[a.at(i)]++;
    }
    else{
      mp[a.at(i - k)]--;
      ans += mp[a.at(i)];
      mp[a.at(i)]++;
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int dp[100001][3];
int main() {
   int n;
   cin >> n;
   vector<int> a(n + 1), b(n + 1), c(n + 1);
   rep(i, n) cin >> a[i + 1] >> b[i + 1] >> c[i + 1];
   rep(i, n) {
      dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i + 1];
      dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b[i + 1];
      dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i + 1];
   }
   int ans = max({dp[n][0], dp[n][1], dp[n][2]});
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int 

//-4%3=-1
int n;
double arr[3000],dp[3000][3000];

double fun(int i,int h)
{
    if(i==n)
    {
        if(h>n/2)
        return 1.0;
        else
        return 0.0;
    }
    if(dp[i][h]!=-1.0)
    return dp[i][h];
    
    return dp[i][h]=arr[i]*fun(i+1,h+1)+(1.0-arr[i])*fun(i+1,h);
    
}
int main() {
	// your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        cin>>arr[i];
        for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
        dp[i][j]=-1.0;
        cout<<setprecision(12)<<fun(0,0)<<"\n";
        /*for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            cout<<dp[i][j]<<" ";
            cout<<"\n";
        }*/
    }
}



Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

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

  bitset<200000> bs;
  bs[0] = true;
  rep(i,6){
    int x = 100+i;
    rep(j,200000){
      if(bs[j]) bs[j+x] = true;
    }
  }

  if(bs[X]) cout << 1 << endl;
  else cout << 0 << endl;
  
  return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

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++) {
			arr[i] = sc.nextInt();
		}
		boolean primes[] = new boolean[1000001];
		sieveOfEratosthenes(primes, 1000000);
		List<Integer> list = new ArrayList<Integer>();
		Set<Integer> set = new HashSet<Integer>();
		for (int i = 0; i < 1000001; i++) {
			if (primes[i]) {
				list.add(i);
				set.add(i);
			}
		}
		boolean poss = true;
		for (int i = 0; i < n; i++) {
			int temp = arr[i];
			for (int j = 0; j < n && list.get(j) < temp; j++) {
				int div = list.get(j);
				if (primes[temp] == true) {
					div = temp;
				}
				if (temp % div == 0) {
					if (set.contains(div)) {
						set.remove(div);
					}
					else {
						poss = false;
						i = n; break;
					}
					while (temp % div == 0) temp = temp / div;
				}
			}
		}
		int gcd = arr[0];
		for (int i = 1; i < n; i++) {
			gcd = gcd(arr[i], gcd);
		}
		if (poss) {
			System.out.println("pairwise coprime");
		}
		else if (gcd == 1) {
			System.out.println("setwise coprime");
		}
		else {
			System.out.println("not coprime");
		}

	}
	
	 static void sieveOfEratosthenes(boolean prime[], int n) { 
	        for(int i=2;i<n;i++) 
	            prime[i] = true; 
	          
	        for(int p = 2; p*p <=n; p++) 
	        { 
	            // If prime[p] is not changed, then it is a prime 
	            if(prime[p] == true) 
	            { 
	                // Update all multiples of p 
	                for(int i = p*p; i <= n; i += p) 
	                    prime[i] = false; 
	            } 
	        }
	    } 
	
	public static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		
		return gcd(b, a % b);
	}

}


Measured memory_bytes: 67900
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
 
using namespace std;
using ll = long long int;
 
int main()
{
  int n;
  cin >> n;
  vector<pair<ll, ll>> dish(n);
  for(int i = 0; i < n; i++)
  {
    ll a, b;
    cin >> a >> b;
    dish[i] = {a, b};
  }
  vector<pair<ll, int>> dish_sum(n);
  for(int i = 0; i < n; i++)
  {
    dish_sum[i] = {dish[i].first + dish[i].second, i};
  }
  sort(dish_sum.begin(), dish_sum.end());
  reverse(dish_sum.begin(), dish_sum.end());
  ll takashi = 0;
  ll aoki = 0;
  for(int i = 0; i < n; i++)
  {
    if(i % 2 == 0)
    {
      takashi += dish[dish_sum[i].second].first;
    }else{
      aoki += dish[dish_sum[i].second].second;
    }
  }
  cout << takashi - aoki << endl;
}

Measured memory_bytes: 3328
<?php
# 入力
list($n, $d) = array_map('intval', explode(' ', trim(fgets(STDIN))));
for ($i = 0; $i < $n; $i++) {
    $x[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}

$cnt = 0;
for ($i = 0; $i < $n; $i++) {
    for ($j = $i + 1; $j < $n; $j++) {
        if (is_decimal(distance($x[$i], $x[$j]))) {
            $cnt++;
        }
    }
}
echo $cnt.PHP_EOL;

function distance($yi, $zi) {
    $sum = 0;
    foreach ($yi as $j => $v) {
        $sum += ($yi[$j] - $zi[$j]) ** 2;
    }
    return sqrt($sum);
}

function is_decimal($v){
    return (string)(int)$v === (string)$v;
}
?>

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll x, a, b;
  cin >> x >> a >> b;
  a = abs(x - a);
  b = abs(x - b);
  char result;
  if(a > b) result = 'B';
  else result = 'A';

  cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q, b, m, e;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    cin >> q;
    rep(i, q) {
        cin >> b >> m >> e;
        rotate(v.begin() + b, v.begin() + m, v.begin() + e);
    }
    vecout(v);
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() 
{  
    
    int arr[10];
    for(int i=0; i<3; i++)
    {
        cin>>arr[i];
    }
    ll x,y;
    cin>>x>>y;
    ll total=min(x,y);
    ll total1=max(x,y);
    ll mn3=(total1*2)*arr[2];
    ll xx=x;
    ll yy=y;
    xx-=total;
    yy-=total;
    ll mn1=(total*2)*arr[2];
    mn1+=(xx*arr[0])+(yy*arr[1]);
    ll mn2=(x*arr[0]+y*arr[1]);
    cout<<min({mn3,mn1,mn2})<<endl;
    

	return 0;
}

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

//bit全探索改
vector<string> bit_all_search(int n){
  vector<string> use(0);
  queue<string> Q;
  Q.push("");
  while(Q.size()){
    string S = Q.front();
    Q.pop();
    string T = S;
    T += '0';
    if(T.size() == n){
      use.push_back(T);
    }
    else{
      Q.push(T);
    }
    T = S;
    T += '1';
    if(T.size() == n){
      use.push_back(T);
    }
    else{
      Q.push(T);
    }
  }
  return use;
}

int main() {    
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> money(N);
    vector<vector<int>> rikai(N,vector<int>(M));
    for(int i=0; i<N; i++){
        for(int j=0; j<M+1; j++){
            if(j==0){
                cin >> money[i];
            }
            else{
                cin >> rikai[i][j-1];
            }
        }
    }
  
    
    int INF = 1e9;
    int ans = INF;
    
    vector<string> A = bit_all_search(N);
    
    
    for(int i=0; i<A.size(); i++){
        string S = A[i];
        vector<int> cnt(M,0);
        int use = 0;
        for(int j=0; j<N; j++){
            if(S[j] == '0'){
                continue;
            }
            use += money[j];
            for(int k=0; k<M; k++){
                cnt[k] += rikai[j][k];
            }
        }
        bool flag = true;
        for(int j=0; j<M; j++){
            if(cnt[j] < X){
                flag = false;
            }
        }
        if(flag){
            ans = min(ans,use);
        }
    }
    
    if(ans == INF){
        ans = -1;
    }
  
    cout << ans << endl;
}



Measured memory_bytes: 3832
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100;
int N, s[MAX_N];

void solve() {
    sort(s, s + N, greater<>());
    int sum = 0;
    REP(i, N) sum += s[i];
    if (sum % 10 == 0) {
        REPR(i, N) {
            if (s[i] % 10 != 0) {
                sum -= s[i];
                cout << sum << endl;
                return;
            }
        }
        cout << 0 << endl;
    } else {
        cout << sum << endl;
    }
}

int main() {
    cin >> N;
    REP(i, N) cin >> s[i];
    solve();
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> replicateM 4 (getl $ wrds toInt) >>= mapM_ print

solve :: [[Int]] -> [Int]
solve = map f
  where
    f [t,n] = g t * n
    g 1 = 6000
    g 2 = 4000
    g 3 = 3000
    g 4 = 2000

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 3696
#include<bits/stdtr1c++.h>
#include<list>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
    int X,t;
    cin >> X >> t;
    if (X >= t){
        cout << X-t << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=4000;
const int mod=1e9+7;
int n,k;
int fac[maxn+8],fact[maxn+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int power(int a,int k)
{
    if (k<0) return 1;
    int sum=1;
    for (;k;k>>=1,a=1ll*a*a%mod)
	if (k&1)
	    sum=1ll*sum*a%mod;
    return sum;
}

int C(int n,int m){return (n<m)?0:1ll*fac[n]*fact[m]%mod*fact[n-m]%mod;}

int main()
{
    n=read(),k=read();
    fac[0]=1;
    for (int i=1;i<=2*n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    fact[n*2]=power(fac[n*2],mod-2);
    for (int i=n*2;i;i--) fact[i-1]=1ll*fact[i]*i%mod;
    int ans=(C(n+k-2,n-1)-C(n+k-2,n)+mod)%mod;
    ans=1ll*ans*power(2,n-k-1)%mod;
    printf("%d\n",ans);
    return 0;
}
    


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

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

using namespace :: std;

bool ask(ll a){
	cout<<a<<endl;
	string s;
	cin>>s;
	if(s=="Vacant"){
		exit(0);
	}
	if(s=="Male")return 0;
	return 1;
}
void solve(ll l,ll r,bool a,bool b){
	ll mid=(l+r+1)/2;
	bool c=ask(mid);
	if((l%2 == mid%2)==(c==a)){
		solve(mid,r,c,b);
	}
	solve(l,mid,a,c);
}
int main(){
	ll n;
	cin>>n;
	solve(0,n-1,ask(0),ask(n-1));
}




















Measured memory_bytes: 852
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N = input()
div = [1] * 1100

for i in range(N):
    num = i + 1
    for den in range(2, 1000):
        while num % den == 0:
            num /= den
            div[den] += 1

ans = 1
MOD = 10 ** 9 + 7
for num in div:
    ans *= num
    ans %= MOD
print ans

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for(ll i=a;i <= b;i++)
#define rep(i,n) for(ll i=0;i < n;i++)
#define sz(x) x.size()
#define accuracy ll precision = numeric_limits<double>::digits10
#define fast_io ios_base::sync_with_stdio(false)
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define fir first
#define sec second
#define N 100005

ll n,m,ans = 0,cnt[N];
bool pos[N];

int main() {
	fast_io;
	accuracy;
	cin >> n >> m;
	fr(i,1,n) cnt[i] = 1;
	pos[1] = true;
	fr(i,1,m) {
		ll u,v; cin >> u >> v;
		assert(cnt[u] > 0);
		cnt[u]--; cnt[v]++;
		if(pos[u]) pos[v] = true;
		if(pos[u] && cnt[u] == 0) pos[u] = false;
	}	
	fr(i,1,n) {
		if(pos[i]) ans++;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int m, n; cin >> m >> n;
	if (m > n) swap(m, n);
	string a = "";
	FOR(i, 0, n) a += (m + '0');
	cout << a;
	return 0;
}



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

class Solution {
  int n, m;
  vector<vector<int>> g;
  vector<pair<int, int>> Es;
  vector<bool> used, passed;
  int greedy(int a) {
    if (passed[a]) return 0;
    passed[a] = 1;
    for (int id : g[a]) {
      if (not used[id]) {
        used[id] = 1;
        int u, v; tie(u, v) = Es[id];
        if (u == a) swap(u, v);
        return greedy(u) + 1;
      }
    }
    return 0;
  }
public:
  void run() {
    cin >> n >> m;
    g.resize(n);
    used.resize(m);
    passed.resize(n);
    Es.resize(m);
    for (int i = 0; i < m; ++i) {
      int a, b; cin >> a >> b;
      --a, --b;
      Es[i] = {a, b};
      g[b].emplace_back(i), g[a].emplace_back(i);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (g[i].size() % 2) {
        cout << "No\n";
        exit(0);
      }
      ans += g[i].size() / 2 - 1;
    }
    if (ans > 2) cout << "Yes\n", exit(0);
    for (int t = 0; t < 20; ++t) {
      passed.assign(n, 0);
      used.assign(m, 0);
      for (int i = 0; i < n; ++i) random_shuffle(g[i].begin(), g[i].end());
      int left = greedy(0);
      passed.assign(n, 0);
      for (int i = 0; i < n; ++i) {
        int add = greedy(i);
        if (add and left + add != m) {
          cout << "Yes\n";
          exit(0);
        }
      }
    }
    cout << "No\n";
  }
};


int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  Solution().run();
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int X;
    cin >> X;
   
    int ans;
    for (int i = X; i <= 10000000; i++) {
        int tmp = sqrt(i) + 1;
        bool ok = true;
        for (int j = 2; j < tmp; j++) {
            if (i % j == 0) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ans = i;
            break;
        }
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007



int main() {
  int c[3][3];
  rep(i, 3) {
    rep(j, 3) {
      cin >> c[i][j];
    }
  }

  int a1 = 0;
  int b1 = c[0][0], b2 = c[0][1], b3 = c[0][2];
  int a2 = c[1][0] - b1, a3 = c[2][0] - b1;

  if (a2 + b2 == c[1][1] && a2 + b3 == c[1][2]
   && a3 + b2 == c[2][1] && a3 + b3 == c[2][2]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }


}


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

int32_t main() {
    ios_base::sync_with_stdio(0);
    string s;
    int k;
    cin >> s >> k;

    int l = s.length();

    bool thesame = true;
    for (int i = 1; i < l; ++i) {
        if (s[i] != s[0]) {
            thesame = false;
            break;
        }
    }

    if (thesame) {
        cout << l * k / 2 << "\n";
        return 0;
    }

    if (s[0] != s[l-1]) {
        int res = 0;

        int c = 1;

        for (int i = 1; i < l; ++i) {
            if (s[i] == s[i-1]) {
                c++;
            } else {
                res += c / 2;
                c = 1;
            }
        }
        res += c/2;

        res = res * k;
        cout << res << "\n";
        return 0;
    }

    int p = 0;
    for (int i = 1; i < l; ++i) {
        if (s[i] != s[i-1]) {
            p = i;
            break;
        }
    }

    int q = l - 1;
    for (int i = l - 2; i >= 0; i--) {
        if (s[i] != s[i+1]) {
            q = i; 
            break;
        }
    }

    int res = 0;
    int c = 1;
    for (int i = p + 1; i <= q; ++i) {
        if (s[i] == s[i-1]) {
            c++;
        } else {
            res += c / 2;
            c = 1;
        }
    }
    res += c/2;
    //cerr << p << " " << q << " " << res << "\n";

    res = p/2 + (l - q - 1) / 2 + res * k +  (p + l - q - 1) / 2 * (k-1);

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
w,h,n = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(n)]
plx = 0
ply = 0
prx = w
pry = h
for x,y,a in lists:
    if a == 1:
        if plx < x:
            plx = x
    elif a == 2:
        if prx > x:
            prx = x
    elif a == 3:
        if ply < y:
            ply = y
    elif a == 4:
        if pry > y:
            pry = y
px = (prx - plx)
if px < 0:
    px = 0
py = (pry - ply)
if py < 0:
    py = 0
ans = px * py
if ans < 0:
    ans = 0
print(ans)


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

#define F(i, a, b) for(int i=a; i<b; i++)
#define rev(str) reverse(str.begin(), str.end())
#define UPPER(str) transform(str.begin(), str.end(), str.begin(), ::toupper)
#define LOWER(str) transform(str.begin(), str.end(), str.begin(), ::tolower)
#define MOD 1000000007
#define INF 1000000001
#define epsilon 1e-15
typedef long long int ll;
typedef unsigned long long int ull;

#define MAX 100000 
#define init(arr, val) memset(arr, val, sizeof(arr))

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);                                       
    freopen("output.txt", "w", stdout);
    #endif

    int x;
    cin >> x;
    if(x >= 30) cout << "Yes\n";
    else cout << "No\n";



    return 0;
}

Measured memory_bytes: 3632
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   ll all = 1, odd = 1;
   TESTS {
      wez(x);
      if (x % 2 == 0) odd *= 2;
      all *= 3;
   }
   cout << (all - odd);
}

Measured memory_bytes: 256
//107
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999LL
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int H, W, h, w, A, B, C;
string s;

int main() {
	cin >> A >> B;
	int ans = max(A, max(B, C)) * 10 + A + B + C - max(A, max(B, C));
	cout << A + 1 - B << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define ll long long
#define MAXN 1000000
#define MODD 1000000007
#define ll long long
using namespace std;

int A[111111];

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N;i++)
        cin>>A[i];
    int ct=0;
    for(int i=1;i<=N;) {
        
        int j=i;
        
        bool is_inc=false;
        bool is_dec=false;
        
        while(j+1<=N) {
            if (A[j+1]>A[j]&&is_dec)
                break;
            if (A[j+1]<A[j]&&is_inc)
                break;
            if (A[j+1]>A[j])
                is_inc=true;
            if (A[j+1]<A[j])
                is_dec=true;
            j++;
        }
        
        i=j+1;
        ct++;
        
        
    }
    cout << ct << endl;
}

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

int main()
{
    string s,t;
    cin >> s >> t;
    int l1,l2;
    l1 = s.length();
    l2 = t.length();
    int dp[l1+1][l2+1] = {0};
    
    for(int i=0;i<=l1;i++){
        for(int j = 0;j<=l2;j++){
            if(i==0||j==0){
                dp[i][j] = 0;
                continue;
            }
            if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = (dp[i-1][j]>dp[i][j-1])? dp[i-1][j]:dp[i][j-1];
            }
        }
    }
    
    string lcs ="";
    int i=l1,j=l2;
    while(i>=0 && j>=0){
        if(dp[i-1][j] == dp[i][j]){
            i--;
        }
        else if(dp[i][j-1] == dp[i][j]){
            j--;
        }
        else{
            lcs+=s[i-1];
            i--;
            j--;
        }
    }
    reverse(lcs.begin(),lcs.end());
    cout << lcs << endl;
    return 0;
}


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

// INT VS LL

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

    int n, l;
    cin >> n >> l;
    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
    	cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (auto s: a) {
    	cout << s;
    }

    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=a;i>b;i--)
#define mkp(a,b) make_pair(a,b)
#define all(v) v.begin(),v.end()
using namespace std;
bool compare(pair<int,int>& p1,pair<int,int>& p2)
{
    return p1.second<p2.second;
}
int main()
{
    fastio
    int n,k;
    cin>>n>>k;
    vector<int> price(n);
    REP(i,0,n)
        cin>>price[i];
    sort(all(price));
    int sum=0;
    REP(i,0,k)
        sum+=price[i];
    cout<<sum<<"\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#define PRIME_MAX 50000
using namespace std;

vector<int> prime;
bool isprime[PRIME_MAX+1];

void sieve() {
  fill(isprime, (bool*)isprime+PRIME_MAX+1, true);
  isprime[0] = isprime[1] = false;
  for(int i = 2; i <= PRIME_MAX; i++) {
    if(!isprime[i]) continue;
    prime.push_back(i);
    for(int j = i*2; j <= PRIME_MAX; j += i) {
      isprime[j] = false;
    }
  }
}

main() {
  sieve();
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    int cnt = 0;
    for(int i = 0; i < prime.size(); i++) {
      if(prime[i] > n/2) break;
      if(isprime[n-prime[i]]) cnt++;
    }
    cout << cnt << endl;
  }
}

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

int main(){
    int a,b,x;
    scanf("%d %d %d",&a,&b,&x);
    if((a+b) < x)
        printf("NO");
    else if(a>x)
        printf("NO");
    else
        printf("YES");
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var d, t, s int
	fmt.Fscan(r, &d, &t, &s)
	if d <= t*s {
		fmt.Fprintln(w, "Yes")
	} else {
		fmt.Fprintln(w, "No")
	}
}


Measured memory_bytes: 1844
n, w = map(int, input().split())
W, V =[0]*n, [0]*n
for i in range(n):
  W[i],V[i] = map(int, input().split())

dp =[[0 for i in range(w+1)] for j in range(n+1)]

for i in range(1,n+1):
  for j in range(w+1):
    if W[i-1] < j+1:
      dp[i][j] = max(dp[i-1][j-W[i-1]]+V[i-1],dp[i-1][j])
    else:
      dp[i][j] = dp[i-1][j]
      
print(dp[n][w])


Measured memory_bytes: 171912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(a * b, c * d) << endl;
}

Measured memory_bytes: 256
# 2019-11-12 01:01:32(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


def main():
    s = int(sys.stdin.readline().rstrip())

    a = []
    n = s
    m = 1
    while True:
        a.append(n)
        n = f(n)
        m +=1 
        if n in a:
            print(m)
            break
        

if __name__ == "__main__":
    main()


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

int main() {
  int x;
  cin >> x;
  if(x == 3 || x == 5 || x == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
//

     signed main(){
       int k,n;
       cin>>k>>n;
       int a[n];
       for(int i=0;i<n;i++)cin>>a[i];
       int ans=k-(k-a[n-1])-a[0];
       for(int i=1;i<n;i++)ans=min(ans,k-(a[i]-a[i-1]));
       cout<<ans;
   }
         


        


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

void replace( char*, int );
int main( void ){
    int times = 0;
    int digit = 0;
    int i;
    char word[201] = {'\0'};
    
    while( 1 ){
        scanf( "%s", &word );
        if( word[0] == '-' ){
            break;
        }
        
        scanf( "%d", &times );
        
        for( i = 0; i < times; i++ ){
            scanf( "%d", &digit );
            replace( word, digit );
        }
        
        for( i = 0; word[i] != '\0'; i++ ){
            printf( "%c", word[i] );
        }
        
        printf( "\n" );
    }
    
    return 0;
}

void replace( char* word, int digit ){
    int length = 0;
    int i;
    char* work;
    
    work = ( char* )malloc( sizeof( char ) * 401 );
    
    for( i = 0; word[i] != '\0'; i++ ){
        work[i] = word[i];
        length++;
    } 
    for( i = 0; word[i] != '\0'; i++ ){
        work[i + length] = word[i];
    } 
    
    for( i = 0; i < length; i++ ){
        word[i] = work[i + digit];
    }

	return;
}


Measured memory_bytes: 2032
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main { 

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int inputScore = Integer.parseInt(sc.nextLine());
    	String[] inputNumber = sc.nextLine().split(" ");
    	double[] allNumber = new double[inputScore];
    	double all = 0;
    	for(int i = 0;i<inputScore;i++) {
    		double tmp = Double.parseDouble(inputNumber[i]);
    		all += 1/tmp;
    	}

    	
    	System.out.println(1/all);
    }
}

Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>

using namespace std;

#define ll long long
#define ull unsigned long long
const ll MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<ll> size;

    UnionFind(ll N) : par(N), size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
        for(ll i = 0; i < N; i++) size[i] = 1LL;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    ll getSize(ll x) {
        return size[root(x)];
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        // if (size[rx] > size[ry]) swap(rx, ry);
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        size[ry] += size[rx];
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main() {
	ll N, M;
	cin >> N >> M;

	vector < pair<ll, ll> > edge;
	for (ll ii = 0; ii < M; ++ii){
		ll A, B;
		cin >> A >> B;
		A--; B--;
		edge.push_back(make_pair(A, B));
	}

	UnionFind tree(N);

	vector <ll> ans(M);
	ans[M-1] = N*(N-1)/2;

	for (int ii = M-1; ii > 0; --ii){
		ll A, B;
		A = edge[ii].first;
		B = edge[ii].second;

		if (tree.same(A, B)){
			ans[ii-1] = ans[ii];
		} else {
			ll sa = tree.getSize(A);
			ll sb = tree.getSize(B);
			ans[ii-1] = ans[ii] - sa*sb;
			tree.unite(A, B);
		}
	}

	for (int ii = 0; ii < M; ++ii){
		cout << ans[ii] << "\n";
	}

	return 0;
}


Measured memory_bytes: 7104
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	As := ReadInts(N)

	dp := make([][2]int, N)

	dp[0][0] = As[0]
	dp[0][1] = -As[0]
	for i := 1; i < N; i++ {
		dp[i][0] = Max(
			dp[i-1][0]+As[i],
			dp[i-1][1]-As[i],
		)
		dp[i][1] = Max(
			dp[i-1][0]-As[i],
			dp[i-1][1]+As[i],
		)
	}
	fmt.Println(dp[N-1][0])
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 5980
// while( !(succeed == try()) );

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

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX

void INP();

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

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


void alpha()
{	
	int r;
	cin>>r;

	double ans = 2*(1.0*22/7)*r;
	cout<<fixed<<setprecision(10)<<ans<<endl;
}

int32_t main(){

	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//INP();
    int t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}






















inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}
 
 

Measured memory_bytes: 3788
s = set()
pv = ""

fail = False
N = input()
for _ in xrange(N):
    w = raw_input()
    if w in s or (pv and w[0] != pv[len(pv)-1]):
        fail=True
        break
    s.add(w)
    pv = w
if fail:
    print "No"
else:
    print "Yes"


Measured memory_bytes: 2568
void main() {
    int[] tmp = readln.split.to!(int[]);
    int a = tmp[0], b = tmp[1], c = tmp[2];
    writeln(a + b >= c ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256