akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;

int main()
{
	int n, ans = 0;
	scanf("%d", &n);
	int l[2*n];
	for (int i=0; i<2*n; i++){
		scanf("%d", &l[i]);
	}
	sort(l, l+2*n, greater<int>());
	for (int i=0; i<2*n; i=i+2){
		ans = ans + l[i+1];
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
long long m,a[100005];
int n,ans;
int main()
{
    scanf("%d%lld",&n,&m);
    for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    sort(a+1,a+n+1);
    for (int i=1;i<n;i++)
        if (m>=a[i]) m-=a[i],ans++;
    if (m==a[n]) ans++;
    printf("%d\n",ans);
    return 0;
}

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


int main() {
	double r;
	cin >> r;
	double pi = 3.141592653589;
	double L = 2 * r * pi;
	double S = r * r * pi;
	cout << fixed << setprecision(12) << S << " " << L << endl;
	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  cout << S.substr(0, S.size()-8) << "\n";
  return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <map>

using namespace std;

double solve(int D, int E){
    double mincos = 100;
    for(int x = 0; x <= 100; x++){
        int y = D - x;
        // cout<<fabs(E - (sqrt(x*x + y*y))) <<endl;
        if(y >= 0)
        mincos = min(fabs(E - (sqrt(x*x + y*y))), mincos);
    }
    return mincos;
}

int main(){
    int D,E;
    vector<double> ans;
    while(1){
        cin>>D>>E;
        if(!D && !E)break;
        ans.push_back(solve(D, E));
    }
    for(double a: ans)printf("%f\n",a);
}


Measured memory_bytes: 3256
package main

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
}

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	n, _ := strconv.Atoi(ReadString())
	return n
}

func readInt64() int64 {
	n, _ := strconv.ParseInt(ReadString(), 0, 64)
	return n
}

// 10 11 12 => [10, 11, 12]
func readIntSlice(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

func main() {
	N, M := readInt(), readInt()

	res := pair(N/2, 0)
	res = append(res, pair(N-N/2-1+N%2, N/2)...)

	for i := 0; i < M; i++ {
		fmt.Printf("%d %d\n", res[i][0], res[i][1])
	}
}

func pair(n, offset int) [][]int {
	var res [][]int
	left := n / 2
	right := n/2 + 1 + n%2

	for i := 0; i < n/2; i++ {
		res = append(res, []int{offset + left, offset + right})
		left--
		right++
	}
	return res
}


Measured memory_bytes: 12048
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll po(ll a, ll b) {
    ll c = 1;
    while (b) {
        if (b % 2) c = c * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return c;
}

int main() {
    ios::sync_with_stdio(false);
    ll f[1000006] = {1}, g[1000006] = {};
    for (int i = 1; i <= 1000000; i++) f[i] = f[i - 1] * i % mod;
    g[1000000] = 397802501;
    for (int i = 999999; i >= 0; i--) g[i] = g[i + 1] * (i + 1) % mod;
    ll n, k;
    cin >> n >> k;
    if (k >= n) {
        cout << f[n + n - 1] * g[n - 1] % mod * g[n] % mod;
    } else {
        ll z = 0;
        for (int i = 0; i <= k; i++) {
            z = (z + f[n] * g[i] % mod * g[n - i] % mod * f[n - 1] % mod * g[i] % mod * g[n - 1 - i]) % mod;
        }
        cout << z;
    }
}


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

int main(){
    int aa=0,bb=0,cc=0;
cin >> aa;
cin >> bb;
for (int a=1; a<= 2;a++){
    if (aa>=bb){
        cc= aa+cc;
        aa=aa-1;
    }else {
        cc= bb+cc;
        bb= bb-1;
    }
}
cout << cc;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;

const int md = 1e9 + 7;
const int N = 3e5 + 10;
int n, c[N][61], pw2[61];
ll a[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(6);
	cout << fixed;
	
	pw2[0] = 1;
	for (int i = 1; i < 61; ++i)
		pw2[i] = (ll)pw2[i - 1] * 2 % md;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (int j = 0; j < 60; ++j)
			c[i + 1][j] = c[i][j] + ((a[i] >> j) & 1);
	}
	
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 61; ++j) {
			if ((a[i] >> j) & 1)
				ans += ll(n - i - c[n][j] + c[i][j]) * pw2[j] % md;
			else
				ans += ll(c[n][j] - c[i][j]) * pw2[j] % md;
			ans %= md;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 74112
use whiteread::parse_line;

fn main() {
    let (a, b, c, d): (i32, i32, i32, i32) = parse_line().unwrap();

    if (a - c).abs() <= d {
        println!("Yes");
    } else if (a - b).abs() <= d && (b - c).abs() <= d {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2124
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 500010, inf = 1e9 + 233;

template<typename T>
inline void read(T &k)
{
	int f = 1; k = 0; char c = getchar();
	while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
	while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
	k *= f;
}

int main()
{
	int n, K;
	read(n); read(K);
	puts((n + 1) / 2 >= K ? "YES" : "NO");
}

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

#define lli long long int

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    int flag = 1;
    if(n == 1)
    {
        flag = 1;
    }
    else
    {
        for(int i = 1; i < n; i++)
        {
            if(a[i] - a[i - 1] < -1)
            {
                flag = 0;
                break;
            }
            else if(a[i] >= a[i - 1])
                continue;
            else
            {
                a[i]++;
            }
        }
    }
    
    
    if(flag)
        cout << "Yes";
    else
        cout << "No";
    
    
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int x;
  cin >> x;
  cout << 1 - x << '\n';
  return (0);
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define mod 1000000007
#define pb emplace_back
#define MP make_pair
#define dbg(x) cout << #x << ": " << x << endl
#define check(k, i, j) ((k>=i) && (k<=j))
#define ff first
#define ss second
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;
int dx[]={1,1,0,-1,-1,-1, 0, 1}; 
int dy[]={0,1,1, 1, 0,-1,-1,-1};

template<typename T>
void printV(vector<T> v){
    for(int i=0; i<v.size(); i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

// ===================================== //

ll dp[2005];

ll solve(int s){
    if(s==0){
        return 1;
    }
    if(s==1 || s==2){
        return 0;
    }
    if(check(s, 3, 5)){
        return 1;
    }
    if(dp[s] != -1){
        return dp[s];
    }
    ll total=0;
    for(int i=3; i<=s; i++){
        if(s-i >= 0){
            total = (total%mod + solve(s-i)%mod + mod)%mod;
        } 
    }
    return dp[s] = total;
}

int main(){


    FAST_IO;
    int s;
    cin >> s;
    memset(dp, -1, sizeof(dp));
    dp[0] = 1;
    ll ans = solve(s);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;
  
void f(int n) {
  int count;
  int temp;
  int ans = 0;
  forn(i, n){
    count = 0;
    temp = i;
    while(temp / 10 > 0){
    	temp /= 10;
      	count++;
    }
    if(count % 2 == 0){
      ans++;
      //cout << i << endl;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  f(n);
  return 0;
}

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

int main(){
    int a,b,x;
    cin >> a >> b >> x;
    if(x < a*a*b/2.0) cout << setprecision(16) << atan(a*b*b/(2.0*x))*180/acos(-1) << endl;
    else cout << setprecision(16) << atan(2.0*(a*a*b-x)/(a*a*a))*180/acos(-1) << endl;
}

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

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

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
int d[60];
int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const double PI = 3.14159265358979323846264338327950288;

int main()
{
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for (int i = A; i <= B; i++) {
		bool ok = true;
		string S = to_string(i);
		for (int j = 0; j < 2; j++) {
			if (S[j] != S[S.size() - j - 1]) {
				ok = false;
				break;
			}
		}
		if (ok) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.math.*;
import java.io.*;

class Point{
    int x, y;
    public Point(int x, int y){
        this.x = x;
        this.y = y;
    }
    public int getX(){return x;}
    public int getY(){return y;}

    public boolean equals(Object a) {
        if(a instanceof Point) {
            Point A = (Point)a;
            return this.x==A.getX() && this.y==A.getY();
        }else return false;
    }
    public int hashCode(){
        return x * 30011 + y;
    }
}

public class Main {
    static int maxValue(int[] a){
        int m = a[0];
        for(int i=1; i<a.length; i++) m = Math.max(m, a[i]);
        return m;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int M = sc.nextInt();
        Set<Point> bombs = new HashSet<>();

        int[] bombH = new int[H];
        int[] bombW = new int[W];

        for(int m=0; m<M; m++){
            int hm = sc.nextInt()-1;
            int wm = sc.nextInt()-1;
            bombH[hm]++;
            bombW[wm]++;
            bombs.add(new Point(hm,wm));
        }

        int bh = maxValue(bombH);
        int bw = maxValue(bombW);

        Set<Integer> mostH = new HashSet<>(), lessH = new HashSet<>();
        Set<Integer> mostW = new HashSet<>(), lessW = new HashSet<>();

        for(int h=0; h<H; h++){
            if(bombH[h]==bh) mostH.add(h);
            else if(bombH[h]==bh-1) lessH.add(h);            
        }
        for(int w=0; w<W; w++){
            if(bombW[w]==bw) mostW.add(w);
            else if(bombW[w]==bw-1) lessW.add(w);      
        }
        
        int ans = bh+bw-1;

        for(int h:mostH) for(int w:mostW){
            if(ans >= bh+bw || !bombs.contains(new Point(h,w))){
                ans = bh+bw;
                break;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 108836
N,K,*as=$<.read.split.map(&:to_i)

min = 10**10
(N-K+1).times do |i|
    l = as[i]
    r = as[K+i-1]
    if l*r >= 0
        n = [l.abs,r.abs].max
    else
        a,b = [l.abs,r].sort
        n = a*2+b
    end
    min = n if n < min
end

puts min

Measured memory_bytes: 11772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int W_MAX = 3000;

ll dp[55][W_MAX][55];

int main() {
    int n, a;
    cin >> n >> a;
    int x[n];
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) dp[i][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int w = 0; w <= W_MAX; w++) {
                if (w >= x[i]) dp[i + 1][w][j] += dp[i][w - x[i]][j - 1];
                dp[i + 1][w][j] += dp[i][w][j];
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += dp[n][i * a][i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 66560
def main():
    lower_limit, upper_limit, ranges = map(int, input().split(" "))
    for i in range(lower_limit, min(lower_limit + ranges, upper_limit + 1)):
        print(i)
    for i in range(max(upper_limit - ranges + 1, lower_limit + ranges), upper_limit + 1):
        print(i)


if __name__ == '__main__':
    main()

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

#define all(x) (x).begin(), (x).end() // passa por todos os elementos

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

  vector<int> X(n), Y(n), C(n);

  iota(all(C),1); // vai de 1 ate n

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

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

  }

  int A, B, flag=0;

  do{
    if(C == X)
      A = flag;
    if(C == Y)
      B = flag;
    flag++;
  }while(next_permutation(all(C))); // enquanto passar pelo vector C todo, ou seja, ir do 1 ao n;

  cout<<abs(B-A)<<endl;

  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  F
//
//  Created by 曾憲揚 on 2020/8/19.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

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

typedef long long ll;
const int maxn = 2e5+5;

int c[maxn];
vector<int> G[maxn];
ll sol[maxn];
int n;
int cnt_son[maxn];
int num[maxn];

ll cal(int x){
    return 1LL*x*(x+1)/2;
}

void DFS(int p, int cur){
    cnt_son[cur] = 1;
    int col = c[cur];
    int tmp = num[col];
    for(int i:G[cur]){
        if(i!=p){
            int now = num[col];
            DFS(cur, i);
            now = num[col]-now;
            sol[col] -= cal(cnt_son[i]-now);
            cnt_son[cur] += cnt_son[i];
        }
    }
    num[col] = tmp + cnt_son[cur];
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin>>n;
    for(int i=1; i<=n; i++) cin>>c[i];
    for(int i=1; i<n; i++){
        int a, b; cin>>a>>b;
        G[a].push_back(b); G[b].push_back(a);
    }
    fill(sol+1, sol+1+n, cal(n));
    
    DFS(0, 1);
    for(int i=1; i<=n; i++){
        sol[i] -= cal(n-num[i]);
        cout<<sol[i]<<" ";
    }
    cout<<endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(s.at(i) == '1') s.at(i) = '9';
        else s.at(i) = '1';
    }

    cout << s << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a > 12) cout << b << endl;
  else if (6 <= a && a <= 12) cout << b/2 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
    map<long long, long long> m;
    long long n; cin >> n;
    long long x = n;

    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }

    bool added = false;
    for (long long i = 2; i * i <= x; i++) {
        if (n == 1) break;
        while (n % i == 0) {
            n /= i;
            m[i]++;
            added = true;
            // cout << "add: " << counter << endl;
            // cout << "n: " << n << endl;
        }
    }
    if (n != 1) {
        m[n]++;
        added = true;
    }
    if (!added) {
        m[x]++;
    }
    int res = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
        int c = 1;
        auto p = *it;
        // cout << p.first << ":" << p.second << endl;
        while (p.second >= c) {
            p.second -= c;
            c++;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3632
n = int(input())
s = str(input())
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    cursor = 0
    for j in range(n):
        if s[j] == i[cursor]:
            cursor += 1
            if cursor == 3:
                ans += 1
                break

print(ans)

Measured memory_bytes: 40940
n = int(input())
a = list(map(int,input().split()))

ans1 = 0
ans2 = 0
tmp = 0

for i,e in enumerate(a):
    tmp += e
    if i % 2 == 0:
        if tmp > 0:
            pass
        else:
            ans1 += 1 - tmp
            tmp = 1
    else:
        if tmp < 0:
            pass
        else:
            ans1 += tmp + 1
            tmp = -1

tmp = 0

for i,e in enumerate(a):
    tmp += e
    if i % 2 == 1:
        if tmp > 0:
            pass
        else:
            ans2 += 1 - tmp
            tmp = 1
    else:
        if tmp < 0:
            pass
        else:
            ans2 += tmp + 1
            tmp = -1

print(min(ans1, ans2))


Measured memory_bytes: 85008
n,m=map(int,input().split())
eage=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    eage[a-1].append(b-1)
    eage[b-1].append(a-1)
for e in eage:
    i_to_1=False
    i_to_n=False
    for ee in e:
        if ee==0:
            i_to_1=True
        if ee==n-1:
            i_to_n=True
        
        if i_to_1==True and i_to_n==True:
            print('POSSIBLE')
            exit()
print('IMPOSSIBLE')

Measured memory_bytes: 38320
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

string S;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> S;
  for(int i = 0 ; i < 3 ; i++){
    if(S[i] == '9'){
      S[i] = '1';
    }
    else if(S[i] == '1'){
      S[i] = '9';
    }
  }
  cout << S << endl;

  return 0;
}


Measured memory_bytes: 504
#include <stdio.h>

#define M_PI 3.14159265358979323846

int main()
{
  int R=0;
  
  while(R<1 || R>100)
    scanf("%d", &R);
  
  printf("%.20lf\n", (double)2*M_PI*R);
  
  
  return 0;
}

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

using namespace std;

const int N = 1e5 + 5, M = 1e2 + 2, OO = 0x3f3f3f3f;

long long n, w, rem[M], cost[M];

long long mem[M][N];

long long solve(long long i, long long remW)
{
	if(i == n)	return 0;
	if(mem[i][remW] != -1)	return mem[i][remW];
	long long opt1 = solve(i + 1, remW);
	long long opt2 = remW >= rem[i] ? solve(i + 1, remW - rem[i]) + cost[i] : 0;
	
	return mem[i][remW] = max(opt1, opt2);
}

int main()
{
	memset(mem, -1, sizeof mem);
	scanf("%lld %lld", &n, &w);
	for(int i = 0 ; i < n; ++i)	scanf("%lld %lld", rem + i, cost + i);
	printf("%lld\n", solve(0, w));
	return 0;
}

Measured memory_bytes: 80000
'use strict';

let lines = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const N = +lines[0];
if (N == 1) {
    console.log(0);
    process.exit();
}
const as = lines[1].split(' ').sort();
console.log(as.pop() - as.shift());

Measured memory_bytes: 20936
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    A = read_int()
    B = read_int()
    print(6 - A - B)


main()


Measured memory_bytes: 3572
#include <iostream>

int main() {
    using namespace std;
    long long a, b, c;
    int k;
    cin >> a >> b >> c >> k;
    long long m = max(a, max(b, c));
    long long o = a + b + c - m;
    for (int i = 0; i < k; i++) {
        m *= 2;
    }
    cout << m + o << endl;
}

Measured memory_bytes: 888
import java.math.BigInteger;
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static List<Edge>[] edges;

    static long es;
    static boolean getEdgeSet(int from, int to, int par) {
        if (from == to) {
            es = 0;
            return true;
        }
        for (Edge e: edges[from]) {
            if (e.to == par) continue;
            if (getEdgeSet(e.to, to, from)) {
                es |= 1L << e.id;
                return true;
            }
        }
        return false;
    }

    static class Edge {
        int to;
        int id;

        public Edge(int to, int id) {
            this.to = to;
            this.id = id;
        }
    }
    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        edges = new List[N];
        for (int i = 0; i < N; i++) {
            edges[i] = new ArrayList<>();
        }

        for (int i = 0; i < N - 1; i++) {
            int a = Integer.parseInt(scanner.next()) - 1;
            int b = Integer.parseInt(scanner.next()) - 1;
            edges[a].add(new Edge(b, i));
            edges[b].add(new Edge(a, i));
        }

        int M = Integer.parseInt(scanner.next());
        long[] edgeSet = new long[M];
        for (int i = 0; i < M; i++) {
            int a = Integer.parseInt(scanner.next()) - 1;
            int b = Integer.parseInt(scanner.next()) - 1;
            getEdgeSet(a, b, -1);
            edgeSet[i] = es;
        }

        long ans = 0;
        for (int i = 0; i < 1 << M; i++) {
            long activeEdges = 0;
            for (int j = 0; j < M; j++) {
                if ((i & (1L << j)) > 0) {
                    activeEdges |= edgeSet[j];
                }
            }
            long white = Long.bitCount(activeEdges);
            long cnt = 1L << (N - 1 - white);
            if (Integer.bitCount(i) % 2 == 0) {
                ans += cnt;
            } else {
                ans -= cnt;
            }
        }

        System.out.println(ans);
    }
}


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

typedef long long ll;

ll fact[100010];
void gen(ll m) {
    fact[0] = 1;
    for(int i = 1; i <= 100000; i++) {
        fact[i] = i * fact[i - 1];
        fact[i] %= m;
    }
}

ll binpow(ll a, ll b, ll m) {
    if(b == 0) return 1;

    ll res = binpow(a, b / 2, m);
    res *= res;
    res %= m;

    if(b & 1) return (res * a) % m;
    else return res;
}

ll modinv(ll a, ll m) {
    return binpow(a, m - 2, m);
}

ll ncr(ll n, ll k, ll m) {
    ll inv = (modinv(fact[n - k], m) * modinv(fact[k], m)) % m;
    return (fact[n] * inv) % m;
}

const int mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);

    gen(mod);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);

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

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

    ll mx = 0;

    for(int i = k - 1; i < n; i++) {
        mx += (a[i] * ncr(i, k - 1, mod)) % mod;
        mx %= mod;
    }

    reverse(a.begin(), a.end());

    ll mn = 0;

    for(int i = k - 1; i < n; i++) {
        mn += (a[i] * ncr(i, k - 1, mod)) % mod;
        mn %= mod;
    }

    cout << (mx - mn + mod) % mod << endl;
}



Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int n;
    cin>>n;
    int p[n];
    int sum=0;
    int maxv=0;
    for(int i=0;i<n;i++){
        cin>>p[i];
        sum+=p[i];
        maxv=max(maxv,p[i]);
    }
    cout<<sum-maxv/2<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	i64 k; scanf("%lld", &k);
	const int n = s.size();

	std::vector<std::pair<char, i64>> vec;
	for(int i = 0; i < s.size(); i++) {
		if(vec.empty() or vec.back().first != s[i]) vec.push_back({s[i], 1});
		else vec.back().second++;
	}

	/*
	for(auto v: vec) cout << "(" << v.first << ", " << v.second << "), ";
	cout << endl;
	*/
	
	if(vec.size() == 1) {
		printf("%lld\n", ((i64)s.size() * k) >> 1LL);
		return 0;
	}

	i64 base = 0;
	for(int i = 1; i < (int)vec.size() - 1; i++) base += vec[i].second >> 1LL;

	i64 ans = base * k;
	ans += vec.front().second >> 1LL;
	ans += vec.back().second >> 1LL;
	if(vec.front().first == vec.back().first) {
		ans += ((vec.front().second + vec.back().second) >> 1LL) * (k - 1);
	} else {
		ans += ((vec.front().second >> 1LL) + (vec.back().second >> 1LL)) * (k - 1);
	}
	
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;
int main(){
    int X,Y,Z,K,a,b,c;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X),B(Y),C(Z),AB,S;
    for(int i=0;i<X;i++){
        cin >> A[i];
    }
    for(int i=0;i<Y;i++){
        cin >> B[i];
    }
    for(int i=0;i<Z;i++){
        cin >> C[i];
    }
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            AB.push_back(A[i]+B[j]);
        }
    }
    sort(AB.rbegin(),AB.rend());
    for(int i=0;i<min(X*Y,K);i++){
        for(int j=0;j<Z;j++){
            S.push_back(AB[i]+C[j]);
        }
    }
    sort(S.rbegin(),S.rend());
    for(int i=0;i<K;i++){
        cout << S[i] << endl;
    }
}

Measured memory_bytes: 42856
N = int(input())
S = input()

opposite = {"S": "W",
            "W": "S"}

for ans in ["SS","SW","WS","WW"]:
  for i in range(1,N-1):
    if ans[i] == "S" and S[i] == "o":
      ans += ans[i-1]
    elif ans[i] == "S" and S[i] == "x":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and S[i] == "o":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and S[i] == "x":
      ans += ans[i-1]
  
  for i in [-1,0]:
    if ans[i] == "S":
      if (S[i] == "o" and ans[i-1] != ans[i+1]) or (S[i] == "x" and ans[i-1] == ans[i+1]):
        break
    else:
      if (S[i] == "o" and ans[i-1] == ans[i+1]) or (S[i] == "x" and ans[i-1] != ans[i+1]):
        break
  else:
    print(ans)
    break
else:
  print(-1)

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		
		int cnt = 0;
		for(int i = 0; i < s.length() ;i++) {
			if(s.charAt(i) != t.charAt(i)) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 32112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
static int MOD = 1000000007;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> x(n), y(m);
	for(int i = 0; i < n; ++i){ cin >> x[i]; }
	for(int i = 0; i < m; ++i){ cin >> y[i]; }
	ll row_sum = 0;
	for(int i = 1; i < n; ++i){
		const ll t = x[i] - x[i - 1];
		const ll l = i, r = n - i;
		row_sum = (row_sum + (t * (l * r % MOD))) % MOD;
	}
	ll col_sum = 0;
	for(int i = 1; i < m; ++i){
		const ll t = y[i] - y[i - 1];
		const ll l = i, r = m - i;
		col_sum = (col_sum + (t * (l * r % MOD))) % MOD;
	}
	const ll answer = (row_sum * col_sum) % MOD;
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 1792
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var c = long.Parse(line[2]);
        if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
//v.erase(unique(v.begin(),v.end()),v.end());
 
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
 
typedef double ld;
typedef long long ll;
const ll N = 100500;
const ll mod = 1000000007;
const ll INF = 1e+9;
using namespace std;
//using namespace __gnu_pbds;
 
//typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

vector <pair <int, int>> xd[N];    

void solve(){
	int n, k; cin >> n >> k;

	for(int i = 0; i < n ;i++){
		int a, b; cin >> a >> b;
		xd[a].push_back({-b, i + 1});
	}
	//for(int i = 0; i < N; i++) sort(xd[i].rbegin(), xd[i].rnd());
	set <pair <int, int>> s;
	ll ans = 0; 
	for(int i = 1; i <= k; i++){
		for(auto x: xd[i]) s.insert(x);
		pair <int, int> p = *(s.begin());
		ans += (-p.ff);
		s.erase(p);
	}

	cout << ans << endl;
	
}
 
int main(){
    
    int tc = 1;
    //cin >> tc;	
	
    while(tc--) solve();
    
    return 0;
}

Measured memory_bytes: 11308
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>

using namespace std;

int main() {

    int R, G, B, N, count = 0;

    cin >> R >> G >> B >> N;

    for (int i = 0; R * i <= N; i++) {
        for (int j = 0; G * j <= N; j++) {
            if ((N - R * i - G * j) % B == 0 && N - R * i - G * j >= 0) {
                count++;
            }
        }
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 3560
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MX = 100010;
int A[MX] = {};


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

  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  int ans = 0;
  for (int i = 0; i < MX; i++) {
    if (A[i] >= 1) {
      ans++;
    }
  }
  if (ans % 2 == 1) {
    cout << ans << endl;
  } else {
    cout << ans - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int h ,w;
    cin >> h  >> w;
    string a[h];
    
    for (int g = 0;g < h;g++){
        cin >> a[g];
    }
   
    for(int i = 0; i <= h+1;i++){
        cout << "#";
        for(int j = 0;j <= w; j++){
        if(i == 0 && j != w || i == h+1 && j != w){
            cout <<"#";
        }    
        else if(1 <= i && i <= h && j != w){
            cout <<a[i-1][j];
        }
        else if(j == w){
            cout << "#" << endl;        
        }
        }
    }
    
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

struct data {
  int to;
  ll d;
  data(int to_, ll d_) : to(to_), d(d_) {}
};

bool dfs(vector<ll>& G, vector<vector<data> >& A, vector<bool>& vis, int tmp, int par, ll d) {
  // cout << tmp << ' ' << par << ' ' << d << endl;
  if(par != -1) {
    if(G[tmp] == longinf)
      G[tmp] = G[par] + d;
    else if(G[tmp] - G[par] != d)
      return false;
  }
  if(!vis[tmp]) {
    vis[tmp] = true;
    for(auto ne: A[tmp])
      if(!dfs(G, A, vis, ne.to, tmp, ne.d))
        return false;
    return true;
  } else {
    return true;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<data> > A(N);
  rep(i, M) {
    int l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    A[l].push_back(data(r, d));
    A[r].push_back(data(l, -d));
  }
  vector<ll> G(N, longinf);
  vector<bool> vis(N);
  bool res = true;
  rep(i, N) {
    if(!vis[i]) {
      G[i] = 0;
      if(!res) break;
      res &= dfs(G, A, vis, i, -1, 0);
    }
  }
  if(res)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 17408
#include <iostream>

using namespace std;

int main()
{
    int ma=0;
    int ma_2=0;
    int ma_3=0;
    int*A=new int[10];
    for(int c=0;c<10;c++)
    {
        cin>>A[c];
        if(ma<A[c])
        {
            ma_3=ma_2;
            ma_2=ma;
            ma=A[c];
        }
        else
        {
            if(ma_2<A[c])
            {
                ma_3=ma_2;
                ma_2=A[c];
            }
            else
            {
                if(ma_3<A[c])
                ma_3=A[c];
            }
        }
    }
    cout<<ma<<endl;
    cout<<ma_2<<endl;
    cout<<ma_3<<endl;
    return 0;
}

Measured memory_bytes: 1188
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    n = int(input())
    T = [int(input()) for _ in range(n)]
    g = 0
    lcm = 1
    for i in range(n):
        g = gcd(lcm,T[i])
        #print(g)
        lcm = lcm // g * T[i]
    #print(g)
    print(lcm)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5148
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  int a, b, c ;
  cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  else if(a == c) cout << b << endl;
  else if(c == b) cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class Graph:
    class Edge:
        def __init__(self, to, cost):
            """
            :param to:  終点ノード
            :param cost: 辺の重み
            """
            self.to, self.cost = to, cost

    def __init__(self, n, directed=False, decrement=True, edges=[]):
        self.n = n
        self.directed = directed
        self.decrement = decrement
        self.edges2 = []
        self.parent = [-1]*self.n
        self.info = [-1]*self.n
        for x, y, cost in edges:
            self.add_edge(x, y, cost)

    def add_edge(self, x, y, cost):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges2.append((x, y, cost))
        if self.directed == False:
            self.edges2.append((y, x, cost))

    def bellman_ford(self, start, INF=10**18):
        """
        :return: 負の閉路が存在する場合は -1 を返す
        """
        dist = [INF] * self.n
        if self.decrement:
            start -= 1
        dist[start] = 0
        for cnt in range(self.n):
            for x, y, cost in self.edges2:
                if dist[x] != INF and dist[x] + cost < dist[y]:
                    if cnt == self.n - 1:
                        return -1
                    dist[y] = dist[x] + cost
        return dist

    def bellman_ford2(self, start, goal, INF=10**18):
        """
        :return: 負の閉路が存在する場合は -1 を返す
        """
        dist = [INF] * self.n
        if self.decrement:
            start -= 1
            goal -= 1
        dist[start] = 0
        for cnt in range(2*self.n):
            for x, y, cost in self.edges2:
                if dist[x] != INF and dist[x] + cost < dist[y]:
                    dist[y] = dist[x] + cost
                    if cnt >= self.n:
                        dist[y] = -INF
                if cnt == self.n - 1:
                    res = dist[goal]
        if res == dist[goal]:
            return res

    def draw(self):
        """
        :return: グラフを可視化
        """
        import matplotlib.pyplot as plt
        import networkx as nx

        if self.directed:
            G = nx.DiGraph()
        else:
            G = nx.Graph()
        for x, y, cost in self.edges2:
            G.add_edge(x + self.decrement, y + self.decrement, weight=cost)

        edge_labels = {(i, j): w['weight'] for i, j, w in G.edges(data=True)}
        pos = nx.spring_layout(G)
        nx.draw_networkx(G, pos, with_labels=True)
        nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
        plt.axis("off")
        plt.show()



##############################################################################################################

N, M, P = map(int, input().split())
graph = Graph(N, directed=True, decrement=True)
for _ in range(M):
    x, y, cost = map(int, input().split())
    graph.add_edge(x, y, P-cost)

res = graph.bellman_ford2(1,N)
if res is None:
    print(-1)
else:
    print(max(-res,0))

Measured memory_bytes: 74644
def partition(A, p, r):
    i = p-1
    x = A[r]
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return A, i+1

    

if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().rstrip().split()))
    A, index = partition(A, 0, len(A)-1)
    A_str = ''
    for i in range(len(A)):
        if i == index:
            A_str = A_str + ' [' + str(A[i]) + ']'
        else:
            A_str = A_str + ' '+ str(A[i])
    print(A_str.strip().rstrip())


Measured memory_bytes: 16388
#python3.4
import math
def inpul(): return list(map(int, input().split()))

N, M = inpul()
A = inpul()

c = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010

f[0] = 0
for i in range(1, N+1):
	for x in A:
		if i-c[x] >= 0:
			f[i] = max(f[i], f[i-c[x]]*10+x)
print(f[N])


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 5017;

int n, k, N;
vector<int> g[M];
bool used[M];

void add(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
}

void read() {
  cin >> n >> k;
  int x = n;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    add(u, x);
    add(v, x);
    ++x;
  }
  N = n;
  n = x;
}

int dfs(int v, int d) {
  int ans = 0;
  if (v < N)
    ++ans;

  used[v] = true;
  if (d > 0)
    for (int to : g[v])
      if (!used[to])
        ans += dfs(to, d - 1);
  return ans;
}


void kill() {
  int ans = 0;
  for (int v = 0; v < n; ++v) {
    fill(used, used + n, false);
    ans = max(ans, dfs(v, k));
  }

  cout << N - ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 640
#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <set>
const int maxlongint=2147483647;
const int mo=1e9+7;	
const int N=105;
using namespace std;
short f[N][N][N][N],n,m,a[N][N],ans,sx,sy,v[N][N],v1[N][N];
int main()
{
	//freopen("agc004e.in","r",stdin);
	//freopen("agc004e.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			char c=getchar();
			while(c!='.' && c!='o' && c!='E') c=getchar();
			v[i][j]=v1[i][j]=a[i][j]=(c=='o');
			v[i][j]+=v[i][j-1];
			v1[i][j]+=v1[i-1][j];
			if(c=='E') sx=i,sy=j;
		}
	for(short i=sx;i>=1;i--)
		for(short j=sy;j>=1;j--)
			for(short i1=sx;i1<=n;i1++)
				for(short j1=sy;j1<=m;j1++)
				{
					if(1<i && i1+1<sx+i)
						f[i-1][j][i1][j1]=max((int)f[i-1][j][i1][j1],(int)f[i][j][i1][j1]+v[i-1][min((int)j1,m-sy+j)]-v[i-1][max((int)j-1,j1-sy)]);
        			if(i1<n && sx+i1<n+i)
        				f[i][j][i1+1][j1]=max((int)f[i][j][i1+1][j1],(int)f[i][j][i1][j1]+v[i1+1][min((int)j1,m-sy+j)]-v[i1+1][max((int)j-1,j1-sy)]);
        			if(1<j && j1+1<sy+j)
        				f[i][j-1][i1][j1]=max((int)f[i][j-1][i1][j1],(int)f[i][j][i1][j1]+v1[min((int)i1,n-sx+i)][j-1]-v1[max((int)i-1,i1-sx)][j-1]);
        			if(j1<m && sy+j1<m+j)
        				f[i][j][i1][j1+1]=max((int)f[i][j][i1][j1+1],(int)f[i][j][i1][j1]+v1[min((int)i1,n-sx+i)][j1+1]-v1[max((int)i-1,i1-sx)][j1+1]);
				}
for(short i=sx;i>=1;i--)
		for(short j=sy;j>=1;j--)
			for(short i1=sx;i1<=n;i1++)
				for(short j1=sy;j1<=m;j1++) ans=max(f[i][j][i1][j1],ans);
	cout<<ans<<endl;
}

Measured memory_bytes: 227584
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int MOD = 1e9 + 7;

signed main(){

  string s; cin >> s;

  int n = s.size();
  static int dp[100001][2];
  dp[0][0] = 1;
  for(int i = 0; i < n; i++){
    //a ^ b = 0
    if(s[i] == '0'){
      dp[i+1][0] += dp[i][0];
      dp[i+1][1] += dp[i][1];
    }else {
      dp[i+1][1] += dp[i][0] + dp[i][1];
    }
    //a ^ b = 1
    if(s[i] == '0'){
      dp[i+1][1] += dp[i][1] * 2;
    }else {
      dp[i+1][0] += dp[i][0] * 2;
      dp[i+1][1] += dp[i][1] * 2;
    }
    dp[i+1][0] %= MOD;
    dp[i+1][1] %= MOD;
  }
  cout << (dp[n][0] + dp[n][1]) % MOD << endl;

  return 0;
}


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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define UNIQUE(o) (o).erase(unique(sort(all((o)))))

typedef long long ll;
const int N = 50;
int n, r, p, c;
int a[N][2];

int main() {
  while (1) {
    scanf("%d%d ", &n, &r);
    if (!n) break;
    REP(i,n) a[n-1-i][0] = i+1;
    int crt, nxt;
    REP(i,r) {
      crt = i&1, nxt = (i+1)&1;
      scanf("%d%d ", &p, &c);
      p--;
      REP(j,c) a[j][nxt] = a[p+j][crt];
      REP(j,p) a[j+c][nxt] = a[j][crt];
      FOR(j,p+c,n) a[j][nxt] = a[j][crt];
    }
    printf("%d\n", a[0][nxt]);
  }
  return 0;
}

Measured memory_bytes: 3188
def main():
  import sys
  input=sys.stdin.buffer.readline
  h,w=map(int,input().split())
  s=input()
  a=b=x=y=s[0]==35
  d=[(b,a)]
  for i in range(1,w):
    f=s[i]==35
    b+=a^f
    a=f
    d+=(b,a),
  for _ in range(1,h):
    s=input()
    f=s[0]==35
    y+=x^f
    b=y
    a=x=f
    p=[(b,a)]
    for i in range(1,w):
      f=s[i]==35
      b+=a^f
      c,g=d[i]
      c+=f^g
      if b>c:b=c
      a=f
      p+=(b,a),
    d=p
  print(b+1>>1)
main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long w[200000],v[200000],dp[200000][101];

long long max_value(long long wieght, long long j)
{
	if(j==1)
	{
		if(wieght>=w[1])
			return v[1];
		return 0;
	}
	if(dp[wieght][j]==-1)
	{
		if(wieght>=w[j])
			dp[wieght][j] = max(max_value(wieght-w[j],j-1)+v[j], max_value(wieght,j-1));
		else
			dp[wieght][j] = max_value(wieght,j-1);
	}
	return dp[wieght][j];
}

int main()
{
	long long n,W;
	cin>>n>>W;
	for (long long i = 0; i <= W; ++i)
	{
		for(long long j = 0; j <= n ;j++)
		{
			dp[i][j] = -1;
		}
	}
	for (long long i = 1; i <= n ; ++i)
	{
		cin>>w[i]>>v[i];
	}

	cout<<max_value(W,n)<<endl;

	
	return 0;
}

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

/*-------------------------- HRIDOY ROY -------------------------*/

#define     fRead           freopen("input.txt","r",stdin)
#define     fWrite          freopen("output.txt","w",stdout)

#define     I(X)            scanf("%d",&(X))
#define     II(X, Y)        scanf("%d%d",&(X),&(Y))
#define     III(X,Y,Z)      scanf("%d%d%d",&(X),&(Y),&(Z))
#define     IL(X)           scanf("%lld",&(X))
#define     IIL(X, Y)       scanf("%lld%lld",&(X),&(Y))
#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     PLL             pair<lld,lld>
#define     MAX             100000000000014
#define     MIN             -100000000000014

#define     pi2             2.0*acos(0.0)


int main()
{
    double R,ans;
    cin>>R;

    ans = 2*pi2*R;
    printf("%0.5f\n",ans);
}



Measured memory_bytes: 3804