akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int ans=min(B,D)-max(A,C);
    if(ans<0)ans=0;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    string s;
    cin>>s;
    if(s=="AAA"||s=="BBB")cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

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

int worm2id(const char *worm) {
	int id=0;
	int m=1;
	while(*worm!='\0') {
		switch(*worm) {
			case 'r': id+=m*1;break;
			case 'g': id+=m*2;break;
			case 'b': id+=m*3;break;
		}
		m*=4;
		worm++;
	}
	return id;
}

void id2worm(char *worm,int id) {
	while(id>0) {
		if(id%4>0)*(worm++)="rgb"[id%4-1];
		id/=4;
	}
	*worm='\0';
}

char get_next(char c1,char c2) {
	switch(c1) {
		case 'r':
			switch(c2) {
				case 'r': return 'r';
				case 'g': return 'b';
				case 'b': return 'g';
			}
			break;
		case 'g':
			switch(c2) {
				case 'r': return 'b';
				case 'g': return 'g';
				case 'b': return 'r';
			}
			break;
		case 'b':
			switch(c2) {
				case 'r': return 'g';
				case 'g': return 'r';
				case 'b': return 'b';
			}
			break;
	}
	return c1;
}

int is_zenbu_onazi(const char *worm) {
	int i;
	for(i=0;worm[i]!='\0';i++) {
		if(worm[0]!=worm[i])return 0;
	}
	return 1;
}

int search(const char *input) {
	static int queue_cost[1048576];
	static int queue_id[1048576];
	static char visited[1048576];
	int queue_begin,queue_end;
	memset(visited,0,sizeof(visited));
	queue_cost[0]=0;
	queue_id[0]=worm2id(input);
	visited[queue_id[0]]=1;
	queue_begin=0;
	queue_end=1;
	while(queue_begin<queue_end) {
		int cur_cost=queue_cost[queue_begin];
		int cur_id=queue_id[queue_begin];
		char cur_worm[32];
		char bak1,bak2;
		char *p;
		queue_begin++;
		id2worm(cur_worm,cur_id);
		if(is_zenbu_onazi(cur_worm))return cur_cost;
		for(p=cur_worm;*(p+1)!='\0';p++) {
			if(*p!=*(p+1)) {
				int next_id;
				bak1=*p;
				bak2=*(p+1);
				*p=*(p+1)=get_next(*p,*(p+1));
				next_id=worm2id(cur_worm);
				*p=bak1;
				*(p+1)=bak2;
				if(!visited[next_id]) {
					visited[next_id]=1;
					queue_cost[queue_end]=cur_cost+1;
					queue_id[queue_end]=next_id;
					queue_end++;
				}
			}
		}
	}
	return -1;
}

int main(void) {
	char input[32];
	while(scanf("%s",input)==1 && input[0]!='0') {
		int ret=search(input);
		if(ret<0)puts("NA"); else printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 3684
#include <stdio.h>
#include <string.h>
 
int main(void){
  char s[1001], order[8], ch[1001];
  int i, j, n, a, b;
 
  scanf("%s\n%d", s, &n);
 
  for(i=0;i<n;i++){
    scanf("%s %d %d", order, &a, &b);
     
    if(!strcmp(order, "reverse")){
      for(j=a;j<=b;j++)
        ch[b-j] = s[j];
      for(j=a;j<=b;j++)
        s[j] = ch[j-a];
    }
 
    if(!strcmp(order, "replace")){
      scanf("%s", ch);
      for(j=0;ch[j]!='\0';j++)
        s[a+j] = ch[j];
    }
 
    if(!strcmp(order, "print")){
      for(j=a;j<=b;j++)
        printf("%c", s[j]);
      printf("\n");
    }
  }
 
  return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a*c;
    chmax(ans, a*d);
    chmax(ans, b*c);
    chmax(ans, b*d);
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;

string S,T;
void input(){
    cin>>S>>T;
    int ans=0;
    rep(i,3){
        if(S[i]==T[i])ans++;
    }
    cout<<ans<<endl;
}

void solve(){

}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}


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

using namespace std;

int main(){
   long a,b,c,d;
   cin>>a>>b>>c>>d;
   int n;
   cin>>n;
   cout<<(n/2)*min(min(8*a,4*b),min(2*c,d))+(n%2)*min(min(4*a,2*b),c)<<endl;
}
   


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

typedef long long ll;

void print(int n,vector<int> a){
  cout << a[0];
  for(int i=1;i<n;i++) cout << " " << a[i];
  cout << endl;
}

int main(){
  int n,count=0;
  bool flag = true;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  while(flag){
    flag = false;
    for(int j=n-1;j>0;j--){
      if(a[j] < a[j-1]) {
	int tmp = a[j];
	a[j] = a[j-1];
	a[j-1] = tmp;
	flag = true;
	count++;
      }
    }
  }
  print(n,a);
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3164
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();

    println!("{}", if solve(&s) { "Yes" } else { "No" });
}

fn solve(s: &str) -> bool {
    let n = s.len();
    if !is_p(s) {
        return false;
    }

    let s1 = &s[..((&s.len() - 1) / 2)];
    if !is_p(s1) {
        return false;
    }

    let s2 = &s[(n + 3) / 2 - 1..];
    if !is_p(s2) {
        return false;
    }

    true
}

fn is_p(s: &str) -> bool {
    let v: Vec<char> = s.trim().chars().collect();

    for i in 0..v.len() / 2 {
        if v[i] != v[v.len() - i - 1] {
            return false;
        }
    }

    true
}


Measured memory_bytes: 4352
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp;
  writeln(s[0..4], " ", s[4..$]);
}


Measured memory_bytes: 256
#include <stdio.h>

int N,K,V,A[2001][2001];

void add(int x1, int y1, int x2, int y2)
{
	if (x1 == x2 || y1 == y2) return;
	if (x1 > x2){
		add(x1,y1,V,y2);
		add(0,y1,0,y2);
		return;
	}
	if (y1 > y2){
		add(x1,y1,x2,V);
		add(x1,0,x2,y2);
		return;
	}
	A[x1][y1]++;
	A[x1][y2]--;
	A[x2][y1]--;
	A[x2][y2]++;
}

int main()
{
	scanf ("%d %d",&N,&K); V = 2 * K;
	for (int i=0;i<N;i++){
		int x,y,v; char c;
		scanf (" %d %d %c ",&x,&y,&c);
		if (c == 'B') v = 1;
		else v = 0;

		x %= V;
		y %= V;
		for (int i=0;i<2;i++) for (int j=0;j<2;j++) if ((i + j + v) % 2){
			add((x+i*K)%V,(y+j*K)%V,(x+i*K+K)%V,(y+j*K+K)%V);
		}
	}

	int mx = 0;
	for (int i=0;i<V;i++) for (int j=0;j<V;j++){
		if (i) A[i][j] += A[i-1][j];
		if (j) A[i][j] += A[i][j-1];
		if (i && j) A[i][j] -= A[i-1][j-1];
		if (mx < A[i][j])
			mx = A[i][j];
	}
	printf ("%d\n",mx);

	return 0;
}

Measured memory_bytes: 15744
N = int(input())

# dpテーブル考える
# 最小化するのでINFで設定する
INF = float('inf')
dp = [[-1 for pattern in range(3)] for _ in range(N+1)]

# スタートは0で設定
dp[0][0] = 0
dp[0][1] = 0
dp[0][2] = 0

# 貰うdpで考える
for n in range(1, N+1) :
    # 1行取得する
    day = list(map(int, input().split()))
    
    for i in range(3): 
        for j in range(3):
            # 2日連続同じことはしない
            if (i == j): continue
            dp[n][i] = max(dp[n][i], dp[n-1][j] + day[i])
    
print(max(dp[-1]))

Measured memory_bytes: 24396
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
void check(long long a,long long b,long long c,long long d){
    long long same=a;
    a = a-b;
    while(same != a && a >= 0){
        cout << a << endl ;
        if(a <= c){
            a += d;
            if(a == same){
                cout << "Yes" << endl;
                return;
            }
        }
        a = a-b ;
    }

    if(a<0)
        cout << "No" << endl;
    return;
}


int main(int argc, const char * argv[]) {
    
    // source code
    int N;
    int T,A;
    cin >> N >> T >> A;
    int H[N];
    inputArray(H,N);
    double min = abs(A-(T-H[0]*0.006));
    int mini=0;
    rep(i,N){

        if(min > abs(A-(T-H[i]*0.006))){
            min =abs(A-(T-H[i]*0.006));
            mini = i;
        }
    }
    cout << mini +1 << endl;

}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<int>> direction(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    direction[a-1].push_back(b-1);
    direction[b-1].push_back(a-1);
  }
  int cnt = 0;
  rep(i, n) {
    bool flag = true;
    rep(j, direction[i].size()) {
      if(h[i] <=h[direction[i][j]]) flag = false;
    }
    if(flag) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 8720
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long m = sc.nextLong();
        int v = sc.nextInt();
        int p = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        Arrays.sort(a);

        boolean flag = true;

        int l = 0, r = n-p+1;

        while (l<r){
            int mid = (l+r)/2;
            if (a[mid]+m<a[n-p]){
                flag = false;
            }else {
                long sum = (p-1+mid+1)*m;
                for (int i=mid+1; i<=n-p; i++){
                    sum += a[mid]+m-a[i];
                }
                if (sum<m*v) flag = false;
                else flag = true;
            }
            if (flag) r = mid;
            else l = mid+1;
        }
        System.out.println(n-l);
    }
}


Measured memory_bytes: 50764
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,l;
  cin >> n >> l;
  vector<string>data(n);
  for(int i=0;i<n;i++){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  for(int i=0;i<n;i++){
    cout << data.at(i);
  }
  cout << endl;
}


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

i=0
max=a[0]
min=a[0]
sum=0
while i<=n-1:
    if max<a[i]:
        max=a[i]
    
    if min>a[i]:
        min=a[i]
    
    sum+=a[i]
    i+=1
    
print(min, max, sum)


Measured memory_bytes: 6596
n, k = map(int, input().split())
ans = 0
for i in range(k, n+2):
    a = 0.5*i*(i-1)
    b = 0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans += int(b-a+1)

print(ans % (10**9+7))


Measured memory_bytes: 70732
from collections import deque

n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append([b, c])
    e[b].append([a, c])

m, k = map(int,input().split())
k -= 1

d = [-1] * n
d[k] = 0
q = deque()
q.append([k, 0])
while q:
    f, cc = q.pop()
    for t, nc in e[f]:
        if d[t] == -1:
            d[t] = cc + nc
            q.append([t, d[t]])

for i in range(m):
    f, t = map(int,input().split())
    f -= 1
    t -= 1
    print(d[f] + d[t])

Measured memory_bytes: 119468
#include<cstdio>
#include<algorithm>
using namespace std;

void selectionSort(int A[],int N){
    int cnt=0;
    for(int i=0;i<N;i++){
        int minj=i;
        for(int j=i;j<N;j++){
            if(A[j]<A[minj]){
                minj=j;
            }
        }
        if(minj!=i){
            swap(A[i],A[minj]);
            cnt++;
        }
    }
    for(int i=0;i<N;i++){
        printf("%d%c",A[i],i==N-1?'\n':' ');
    }
    printf("%d\n",cnt);
}

int main(){
    int num;
    scanf("%d",&num);
    int A[num];
    for(int i=0;i<num;i++){
        scanf(" %d",&A[i]);
    }
    selectionSort(A,num);
    return 0;
}


Measured memory_bytes: 2740
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= n - i; ++j) {
			string tmp = s.substr(i, j);
			bool ok = true;
			for (auto& c : tmp) {
				if (c != 'A' && c != 'G' && c != 'C' && c != 'T') ok = false;
			}
			if (ok) {
				ans = max(ans, int(tmp.size()));
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int a, b, c; cin >> a >> b >> c;
    // rep(i, )
    string res = "NO";
    bool flag = false;
    for(int i = a; i < a * b + 1; i += a){
        if(i % b == c) { flag = true; break; }
    }
    if(flag) res = "YES";
    cout << res << endl;
    return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		String S = rs();
		int[] cnt = new int[26];
		foreach(var c in S) cnt[c - 'A']++;
		
		int cnt2 = 0;
		for(int i=0;i<26;i++) if(cnt[i] == 2) cnt2++;
		Console.WriteLine(cnt2 == 2 ? "Yes" : "No");
		
		
		
	}

	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
N,M = inputlist()
ans = 0
ab = [0]*M
for i in range(M):
    ab[i] = inputlist()
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j == i:
            continue
        uf.union(ab[j][0]-1,ab[j][1]-1)
    if len(uf.roots()) != 1:
        ans +=1
print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <bitset>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

#define ALL(obj) (obj).begin(), (obj).end() 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    int all_non_plus=1;
    rep(i,n) if(a[i]>0) all_non_plus=0;
    if(all_non_plus){
        // all of a_n are 0 or minus
        ll max=a[0],max_id=0;
        rep(i,n){
            if(max < a[i]){max = a[i]; max_id=i;}
        }
        cout << max << endl;
        cout << n-1 << endl;
        rep(i,n - max_id - 1) cout << n - i << endl;
        rep(i,max_id) cout << 1 << endl;
    }else{
        ll e_sum=0;
        ll o_sum=0;
        rep(i,n) if(((i + 1) % 2 == 0) &&(a[i] > 0)) e_sum += a[i];
        rep(i,n) if(((i + 1) % 2 == 1) &&(a[i] > 0)) o_sum += a[i];
        vector<pair<ll,ll> > v(n);
        vector<ll> ord;
        if(e_sum > o_sum){
            rep(i,n){ 
                if(((i + 1) % 2 == 0) &&(a[i] > 0)){
                    v[i] = make_pair(a[i], 1);
                }else{
                    v[i] = make_pair(a[i], 0);
                }
            }
            cout << e_sum << endl;    
        }else{
            rep(i,n){ 
                if(((i + 1) % 2 == 1) &&(a[i] > 0)){
                    v[i] = make_pair(a[i], 1); 
                }else{
                    v[i] = make_pair(a[i], 0); 
                }
            }
            cout << o_sum << endl;
        }

        while(v.size()!=1){
                rep(j,v.size()){
                    if(j==0&&v[j].second==0){
                        v.erase(v.begin()+j);               
                        ord.push_back(j+1);
                        break;
                    }else if(j>0&&j<v.size()-1&&v[j+1].second==1&&v[j-1].second==1){
                        v[j]= make_pair(v[j+1].first+v[j-1].first,1);
                        v.erase(v.begin()+j-1);
                        v.erase(v.begin()+j);                 
                        ord.push_back(j+1);
                        break;
                    }else if(j>0&&j<v.size()-1&&v[j+1].second==0&&v[j-1].second==0){
                        v[j]= make_pair(v[j+1].first+v[j-1].first,0);
                        v.erase(v.begin()+j-1);
                        v.erase(v.begin()+j);                    
                        ord.push_back(j+1);
                        break;
                    }else if(j==v.size()-1&&v[j].second==0){
                        v.erase(v.begin()+j);
                        ord.push_back(j+1);
                        break;
                    }
                }
            }
        cout << ord.size() << endl;
        rep(i,ord.size()) cout << ord[i] << endl;
     
    }
    return 0;
}

Measured memory_bytes: 256
n,x,y=map(int,input().split())
x-=1
y-=1
import collections
l=[0 for _ in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ll=min(j-i,abs(x-i)+1+abs(y-j))
        l[ll]+=1
for i in l[1:]:
    print(i)
        

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
struct pr{int nw,p;};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,q; cin>>n>>q;
	vector<vector<int>>g(n);
	for(int i=1;i<n;++i){
		int a,b; cin>>a>>b; --a,--b;
		g.at(a).emplace_back(b);
		g.at(b).emplace_back(a);
	}
	vector<int>cnt(n,0);
	for(int i=0;i<q;++i){
		int p,x; cin>>p>>x; --p;
		cnt.at(p)+=x;
	}
	queue<pr>que; que.push({0,-1});
	while(que.size()){
		pr t=que.front(); que.pop();
		for(auto&&i:g.at(t.nw)){
			if(i==t.p)continue;
			cnt.at(i)+=cnt.at(t.nw);
			que.push({i,t.nw});
		}
	}
	cout<<cnt.front();
	for(int i=1;i<n;++i)cout<<" "s<<cnt.at(i);
	cout<<"\n"s;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  double r, g;
  cin >> r >> g;
  double ans = g * 2.0 - r;
  cout << ans << endl;
  

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>S;
    N=S.size();
    rep(i,N){
        if(i%2==0){
            cout<<S[i];
        }
    }
    
    cout << endl;


    return 0;
    

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

double a,b;

int main(){
	cin>>a>>b;
	cout<<syosu(9)<<a/b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <algorithm> 
#include <vector> 
#include <string.h> 
#include <math.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <chrono> 
#include <thread> 
#include <iomanip>
#include <typeinfo>
 
//define
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int 

//typedef
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long inf = 1000000000000000000;

using namespace std;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

ll power(ll x, ll n)
{
    ll res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

void update(int n, vi &v, int x, int ch)
{
    while(x<=n)
    {
        v[x]+=ch;
        x+=(x&(-x));
    }
}

int query(vi &v, int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=v[x];
        x-=(x&(-x));
    }
    return ans;
}

void solve()
{
    ll n, x, t;
    cin>>n>>x>>t;
    ll a=(n/x)*t;
    if(n%x)
        a+=t;
    cout<<a<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3804
from sys import stdin
import numpy as np
from bisect import bisect, bisect_left, bisect_right
N,M,K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
A = [0] + A
#B = [0] + B
cumsum_A = np.cumsum(A)
cumsum_B = np.cumsum(B)

#print(cumsum_A)
#print(cumsum_B)
ans = 0
for i in range(0,N+1):
    tmp = K - cumsum_A[i]
    if tmp < 0:
        continue
    ans = max(ans,bisect_right(cumsum_B,tmp)+i)
    #print(i,ans,tmp)
    
print(ans)

Measured memory_bytes: 57548
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a[5][4][11];
	int n;
	int b;
	int f;
	int r;
	int v;
	cin>>n;
	for(int i=0;  i<5; i++){
		for(int j=0;  j<4; j++){
			for(int k=0;  k<11; k++){
				a[i][j][k]=0;
			}
		}
	}

	for(int i=0;  i<n; i++){
		cin>>b>>f>>r>>v;
		a[b][f][r]+=v;
	}
	for(int i=1;  i<4; i++){
		for(int j=1;  j<4; j++){
			for(int k=1; k<11; k++){
				cout<<" "<<a[i][j][k];
			}
			cout<<endl;
		}
		cout<<"####################"<<endl;
	}
	for(int j=1;  j<4; j++){
		for(int k=1;  k<11; k++){
			cout<<" "<<a[4][j][k];
		}
		cout<<endl;
	}
}

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  char s[n];
  int overseas=0;
  rep(i,n){
    cin >> s[i];
    if(s[i]=='b'){

    }
  }
  int max = a+b;
  int passed=0;
  rep(i,n){
    switch(s[i]){
      case 'a':
        if(max>passed){
          cout << "Yes" <<endl;
          passed++;
        }
        else cout <<"No" <<endl;
        break;
      case 'b':
        if(max>passed && b>overseas){
          cout << "Yes" <<endl;
          passed++;
          overseas++;
        }
        else cout <<"No" <<endl;
        break;
      case 'c':
        cout << "No" <<endl;
        break;
    }
  }
  return 0;
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> a(n+10);
    vector<int> oddcnt(100010, 0), evencnt(100010, 0);
    for(int i=1; i<=n; i++) {
        cin>>a[i];

        if(i % 2 == 1){
            oddcnt[a[i]]++;
        }
        else{
            evencnt[a[i]]++;
        }
    }

    int oddmany=0, evenmany=0;
    int oddnum, evennum;
    for(int i=1; i<=100000; i++){
        if(oddcnt[i] > oddmany){
            oddmany=oddcnt[i];
            oddnum=i;
        }

        if(evencnt[i] > evenmany){
            evenmany=evencnt[i];
            evennum=i;
        }
    }

    if(oddnum != evennum){
        cout << n - (oddmany + evenmany) << endl;
    }
    else{
        int oldoddnum=oddnum;
        int oldoddmany=oddmany, oldevenmany=evenmany;
        //cout << oldoddmany << " " << oldevenmany << endl;
        oddmany=0, evenmany=0;
        for(int i=1; i<=100000; i++){
            if(i == oldoddnum) continue;

            if(oddcnt[i] > oddmany){
                oddmany=oddcnt[i];
                oddnum=i;
            }

            if(evencnt[i] > evenmany){
                evenmany=evencnt[i];
                evennum=i;
            }
        }

        int MAX=max(oldoddmany+evenmany, oldevenmany+oddmany);
        cout << n - MAX << endl;
    }
}

Measured memory_bytes: 1408
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<pll> R;
  REP(i, N) {
    ll x, l;
    cin >> x >> l;
    R.push_back({x + l, x - l});
  }
  sort(ALL(R));

  ll ans = 0;
  ll now = -llINF;
  REP(i, N) {
    // cout << R[i].first << "," << R[i].second << endl;
    if (now <= R[i].second) {
      now = R[i].first;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main() {
    int r,D,x0;
    cin>>r>>D>>x0;
    int ans=x0;
    for(int i=0;i<10;i++){
        ans=r*ans-D;
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
main(){
	int c;
	priority_queue<int>  pq;

	for (int i=0;i<10;i++){
		cin >> c;
		pq.push(c);
	}
	for (int i=0;i<3;i++){
		cout << pq.top() << endl;
		pq.pop();

	}

}

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

int main(){
  long long x,k,d;
  cin>>x>>k>>d;
  if(x<0) x*=-1;
  long long step = x/d;

  if(k<=step) cout<<x-d*k;
  else{
  	k-=step;
  	if(k%2==0) cout<<x-step*d;
  	else cout<<step*d+d-x;
  }
}

Measured memory_bytes: 3648
fun main(args: Array<String>) = abc159d()

fun abc159d() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val groupBy = aList.groupBy { it }.mapValues { it.value.size.toLong() }

    val allMap = groupBy.map {
        Pair(it.key, (it.value - 1) * it.value / 2)
    }.toMap()

    val allSum = allMap.map { it.value }.sum()

    val minusMap = groupBy.map {
        Pair(it.key, (it.value - 2) * (it.value - 1) / 2)
    }.toMap()

    val answer = aList.map { allSum - allMap[it]!! + minusMap[it]!! }.joinToString(System.lineSeparator())

    println(answer)
}


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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i,n) for(ll i=0; i<(n); i++)
#define forn for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void max_self(ll &a, ll b){
	a = max(a,b);
}

void solve(){
	int n;
	cin >> n;
	set<string> st;
	forn{
		string s;
		cin >> s;
		st.insert(s);
	}
	int ans = 0;
	for(auto i:st){
		ans++;
	}
	cout << ans << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 19236
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

void chmax(ll& x, ll y) {
    if (x < y) x = y;
}

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);

        if (x == y) return false;

        // merge by size
        // force size of x to be bigger than that of y
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;

        return true;
    }

    ll size(int x) {
        return -par[root(x)];
    }
};

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n, m; cin >> n >> m;

    vector<int> a(m), b(m);
    REP(i, m) cin >> a[i] >> b[i];

    reverse(ALL(a));
    reverse(ALL(b));

    UnionFind uf(n + 1);

    vector<ll> ans(m, 0);
    ans[0] = n * (n - 1) / 2;
    REP(i, m - 1) {
        ll t = uf.size(a[i]) * uf.size(b[i]);
        if (uf.issame(a[i], b[i])) t = 0;
        uf.merge(a[i], b[i]);
        ans[i + 1] = ans[i] - t;
    }

    reverse(ALL(ans));

    for(auto &e: ans) print(e);

}

Measured memory_bytes: 5228
import sys
import heapq


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort(reverse=True)
    ls = []
    heapq.heapify(ls)
    t = 0
    for i in range(1, m + 1):
        while True:
            if len(ab) != 0:
                if ab[-1][0] <= i:
                    heapq.heappush(ls, -ab.pop()[1])
                else:
                    break
            else:
                break
        if len(ls) != 0:
            t -= heapq.heappop(ls)
    print(t)


if __name__ == '__main__':
    solve()


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

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


int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b == c + d) cout << "Balanced" << endl;
  else if(a + b < d + c) cout << "Right" << endl;
  else cout << "Left" << endl;
}

Measured memory_bytes: 256
import math

n = int(raw_input())

for _ in range(n):
    (x1, y1, x2, y2, x3, y3) = map(float, raw_input().split())

    a1 = (x2 - x1) * 2
    a2 = (x3 - x1) * 2
    b1 = (y2 - y1) * 2
    b2 = (y3 - y1) * 2
    c1 = x1**2 - x2**2 + y1**2 - y2**2
    c2 = x1**2 - x3**2 + y1**2 - y3**2

    x = (b1*c2 - b2*c1) / (a1*b2 - a2*b1)
    y = (c1*a2 - c2*a1) / (a1*b2 - a2*b1)
    r = math.sqrt((x-x1)**2 + (y-y1)**2)

    print '{0:.3f} {1:.3f} {2:.3f}'.format(x, y, r)

Measured memory_bytes: 4432
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,k; cin >> n >> k;
    vector<int> p(n); rep(i,n) cin >> p[i];
    double ans = 0, t = 0;
    for(int i=0; i<k;i++) t = t + ((double)(p[i]+1) / 2.0);
    ans = t;
    for(int i=k; i<n; i++){
        t = t + ((double)(p[i]+1) / 2.0) - ((double)(p[i-k]+1) / 2.0);
        ans = max(t, ans);
    }
    printf("%.13lf\n", ans);
    return 0;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

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

	private void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Engine[] arr = new Engine[N];
		for (int i = 0; i < N; i++) {
			arr[i] = new Engine(sc.nextLong(), sc.nextLong());
		}
		Arrays.sort(arr, (e1, e2) -> {
			if (e1.theta > e2.theta) {
				return 1;
			}
			if (e1.theta < e2.theta) {
				return -1;
			}
			return 0;
		});
		long max = 0L;
		for (int start = 0; start < N; start++) {
			for (int end = start; end < start + N; end++) {
				long sum_x = 0L;
				long sum_y = 0L;
				for (int i = start; i <= end; i++) {
					sum_x += arr[i % N].x;
					sum_y += arr[i % N].y;
				}
				long tmp = sum_x * sum_x + sum_y * sum_y;
				if (max < tmp) {
					max = tmp;
				}
			}
		}
		System.out.println(Math.sqrt(max));
	}

	class Engine {
		long x;
		long y;
		double theta;
		public Engine(long x, long y) {
			this.x = x;
			this.y = y;
			this.theta = Math.atan2(y, x);
		}
	}

	class Scanner {
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int index;
		private int length;

		public Scanner(InputStream in) {
			this.in = in;
		}

		private boolean isPrintableChar(int c) {
			return '!' <= c && c <= '~';
		}

		private boolean isDigit(int c) {
			return '0' <= c && c <= '9';
		}

		private boolean hasNextByte() {
			if (index < length) {
				return true;
			} else {
				try {
					length = in.read(buffer);
					index = 0;
				} catch (IOException e) {
					e.printStackTrace();
				}
				return length > 0;
			}
		}

		private boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[index])) {
				index++;
			}
			return hasNextByte();
		}

		private int readByte() {
			return hasNextByte() ? buffer[index++] : -1;
		}

		public String next() {
			if (!hasNext()) {
				throw new RuntimeException("no input");
			}
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext()) {
				throw new RuntimeException("no input");
			}
			long value = 0L;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			while (isPrintableChar(b)) {
				if (isDigit(b)) {
					value = value * 10 + (b - '0');
				}
				b = readByte();
			}
			return minus ? -value : value;
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 28372
package main
import (
	"fmt"
	"sort"
)
func main(){
	temp:=0
	a:=make([]int, 3)
	for i:=0;i<3;i++{
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	for i:=1;i<3;i++{
		temp+=a[i-1]-a[i]
	}
	fmt.Println(temp)
}


Measured memory_bytes: 512
#include <iostream>

std::string battle(int A, int B, int C, int D);

int main(void) {
    int A, B, C, D;
    std::cin >> A >> B >> C >> D;
    std::cout << battle(A, B, C, D) << std::endl;
    
    return 0;
}

std::string battle(int A, int B, int C, int D) {
    int numAttackT, numAttackA;
    numAttackT = (C - 1)/B + 1;
    numAttackA = (A - 1)/D + 1;
    
    if(numAttackT <= numAttackA) {
        return "Yes";
    }

    return "No";
}

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

int main() {
    string S;
    cin >> S;

    int cnt[3] = {};
    for (int i = 0; i < (int)S.size(); i++) {
        cnt[S[i] - 'a']++;
    }
    sort(cnt, cnt + 3);

    if (cnt[0] == cnt[1] && cnt[2] - cnt[0] <= 1) {
        cout << "YES" << endl;
    } else if (cnt[1] == cnt[2] && cnt[2] - cnt[0] <= 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////
ll ans;
ll k;
ll ruin=0;
vector<ll> vec[100005];

ll fin[100005];
ll al[100005];
ll kai[100005];


void bfs(ll u){
	ll cnt=0;
  for(ll i=0;i<vec[u].size();i++){
ll t=vec[u][i];
fin[t]++;
if(al[t]!=1) cnt++;
  }

if(k-fin[u]<cnt){ruin=1;}
  if(COM(k-fin[u],cnt)!=0)
ans*=COM(k-fin[u],cnt);
ans%=MOD;
ans*=kai[cnt];
ans%=MOD;
 for(ll i=0;i<vec[u].size();i++){
	 ll va=vec[u][i];
if(al[va]==0){
	al[va]=1;
bfs(va);
  }

}
}





int main() {
ll n;
cin>>n>>k;
ans=k;
COMinit();

kai[0]=1;
kai[1]=1;
for(ll i=2;i<=100001;i++){
	kai[i]=kai[i-1]*i;
	kai[i]%=MOD;
}


for(int i=1;i<=n-1;i++){
ll a,b;
cin>>a>>b;
vec[a].push_back(b);
vec[b].push_back(a);
}

rep(i, n){
	fin[i]=1;
	al[i]=0;
}


ll st=0;
for(int i=1;i<=n;i++){
	if(vec[i].size()==1){
st=i;
break;
	}
}

al[st]=1;

bfs(st);

if(ruin){cout<<0<<endl;
return 0;}

cout<<ans<<endl;
return 0;




}




Measured memory_bytes: 23168