akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<map>
#include<bitset>
#include<stack>
#include<queue>
#include<set>
#include<cmath>
#include<vector>

using namespace std;

#define bomb exit(1)
#define INF 1000000000
#define LINF 1000000000000000000ll
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
#define EE(x); struct edge { int nxt,to,w; }e[M << 1]; int head[N],cnt = x ^ 1;\
	void add(int u,int v,int w = 0) { e[++cnt].w = w,e[cnt].to = v,e[cnt].nxt = head[u];head[u] = cnt; }\
	void add_edge(int u,int v,int w = 0) { add(u,v,w),add(v,u,w * x); }
#define Mod(x) ((x) >= mod ? x - mod : x)
#define eps 0.00000001
#define sqr(x) ((x) * (x))
//#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
//char BB[1 << 15],*SS = BB,*TT = BB;
inline long long read()
{
	long long x = 0;int f = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') f = -1;
	for(;isdigit(ch);ch = getchar()) x = x * 10 + (ch ^ 48);
	return x * f;
}
void print(long long x)
{
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
long long gcd(long long a,long long b) { return b ? gcd(b,a % b) : a; }

const int N = 5010,M = 300;
int n,m;
long long sum[N],f[N],ans;
int a[N][M],lg[N],st[M][N][20];
void init()
{
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			st[j][i][0] = read();
	lg[0] = -1;
	for(int i = 1;i <= n;i++) lg[i] = lg[i >> 1] + 1;
	for(int p = 1;p <= m;p++)
		for(int j = 1;j < 20;j++)
			for(int i = 1;i <= n - (1 << j) + 1;i++)
				st[p][i][j] = max(st[p][i][j - 1],st[p][i + (1 << j - 1)][j - 1]);
}
int query(int i,int l,int r)
{
	int k = lg[r - l + 1];
	return max(st[i][l][k],st[i][r - (1 << k) + 1][k]);
}
void solve(int l,int r,int L,int R)
{
	if(l > r) return;
	int mid = l + r >> 1;
	long long ans = 0,pos;
	for(int i = L;i <= min(mid,R);i++)
	{
		long long now = sum[i] - sum[mid];
		for(int j = 1;j <= m;j++)
			now += query(j,i,mid);
		if(now > ans) ans = now,pos = i;
	}
	f[mid] = ans;
	solve(l,mid - 1,L,pos),solve(mid + 1,r,pos,R);
}

int main()
{
	n = read(),m = read();
	for(int i = 2;i <= n;i++) sum[i] = sum[i - 1] + read();
	init();
	solve(1,n,1,n);
	for(int i = 1;i <= n;i++) ans = max(ans,f[i]);
	fprint(ans);
	return 0;
}

Measured memory_bytes: 81920
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a+b)==(c+d))
    cout<<"Balanced"<<endl;
  else if((a+b)<(c+d))
    cout<<"Right"<<endl;
  else if((a+b)>(c+d))
    cout<<"Left"<<endl;
  }

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ll mod=1e9+7;
const ld PI = 2 * acos(0.0);
ll m(ll a){ return (a+mod)%mod;}
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
	if(b==0)
		return 1;
	ll d=power(a,b/2,m);
	d=(d*d)%m;
	if(b&1)
		d=(d*a)%m;
	return d;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int solve(){}
int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int x,y,z;cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
	return 0;
}

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

int main()
{
    int a, b, c, d;
    int area1, area2;
    cin >> a >> b >> c >> d;
    area1 = a * b;
    area2 = c * d;
    if (area1 > area2) {
        cout << area1 << endl;
    } else {
        cout << area2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;


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


Measured memory_bytes: 256
N, X, Y = input().split()
N = int(N)
X  =int(X)
Y = int(Y)

k = [0] * N
for i in range(1, N):
    for j in range(i+1, N+1):
        min = abs(j-i)
        min1 = abs(Y-j)+abs(X-i)+1
        min2 = abs(Y-i)+abs(j-X)+1
        if min > min1:
            min = min1
        if min > min2:
            min = min2
        k[min] += 1
for i in range(1, N):
    print(k[i])


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));
    vector<ll> ans(n);
    ll anss = 0;

    if(n % 2 == 0) {
        ll idx = 0, idx2 = 0;
        REP(i, n) {
            if(i % 2 == 0) {
                ans[i] = a[idx2 + n/2];
                idx2++;
            } else {
                ans[i] = a[idx];
                idx++;
            }
        }
        REP(i, n-1) {
            anss += abs(ans[i] - ans[i+1]);
        }
    } else {
        ll idx = 0, idx2 = 0;
        REP(i, n-1) {
            if(i % 2 == 0) {
                ans[i] = a[idx2 + n/2 + 1];
                idx2++;
            } else {
                ans[i] = a[idx];
                idx++;
            }
        }
        REP(i, n-2) {
            anss += abs(ans[i] - ans[i+1]);
        }
        anss = max(anss + abs(ans[0] - a[n/2]), anss + abs(ans[n-2] - a[n/2]));
    }

    cout << anss << endl;

    return 0;
}

Measured memory_bytes: 1792
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type station struct {
	c int
	s int
	f int
}

func divCeil(x, d int) int {
	if x%d == 0 {
		return x / d
	}
	return (x / d) + 1
}

func maxInt(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func solve(tNow int, iNow int, sta []station, ans []int, n int) int {
	if iNow == n-1 {
		return tNow
	}
	if tNow > 0 && tNow <= sta[iNow].s {
		return ans[iNow]
	}
	tLeave := maxInt(sta[iNow].s, sta[iNow].f*divCeil(tNow, sta[iNow].f))
	return solve(tLeave+sta[iNow].c, iNow+1, sta, ans, n)
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()

	sta := make([]station, n)
	for i := 0; i < n-1; i++ {
		sta[i].c, sta[i].s, sta[i].f = nextInt(), nextInt(), nextInt()
	}
	sta[n-1].c, sta[n-1].s, sta[n-1].f = 0, 0, 1

	ans := make([]int, n)
	for i := n - 1; i >= 0; i-- {
		ans[i] = solve(0, i, sta, ans, n)
	}

	for _, a := range ans {
		fmt.Println(a)
	}
}


Measured memory_bytes: 768
# -*- coding: utf-8 -*-

from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)
li = sorted(c.items(), key=lambda x: x[0], reverse=True)

cands = []
for num, cnt in li:
    if cnt >= 4:
        cands += [num, num]
    elif cnt >= 2:
        cands += [num]

cands += [0, 0]
ans = cands[0] * cands[1]
print(ans)


Measured memory_bytes: 22436
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var str=Arr.shift();
   if(str=="0 0")break;
   var arr=str.split(" ").map(Number);
   arr.sort(function(a,b){return b-a;});
   var x=arr[0];
   var y=arr[1];
   var cnt=0;
   while(y!==0){
      var m=x%y;
      x=y;
      y=m;
      cnt++;
   }
   console.log(x+" "+cnt);
}

Measured memory_bytes: 10576
#include <stdio.h>

int main(void) {
	int n, m, i, j, c, num;
	int a[1000][1000], b[1000];
	
	scanf("%d%d", &n, &m);
	
	//aの配列に値を入力する
	for(i = 0; i < n; i++) {
	    for(j = 0; j < m; j++) {
	        scanf("%d", &num);
	        a[i][j] = num;
	    }
	}
	
	//bの配列に値を入力する
	for(i = 0; i < m; i++) {
	    scanf("%d", &num);
	    b[i] = num;
	}
	
	for(i = 0; i < n; i++) {
	    c = 0;
		for(j = 0; j < m; j++) {
			c += a[i][j] * b[j];
		}
		printf("%d\n", c);
	}
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a, b;

  int v;
  for (int i = 0; i < A; i++) {
    cin >> v;
    a.push_back(v);
  }
  for (int i = 0; i < B; i++) {
    cin >> v;
    b.push_back(v);
  }
  
  int min = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
  int x, y, c;
  for (int i = 0; i < M; i++) {
    cin >> x >> y >> c;
    v = a[x-1] + b[y-1] - c;
    min = (min < v) ? min : v;
  }
  cout << min << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main() 
{
    cin>>a>>b;
    if ((((a+b)%3)==0)||(b%3==0)||(a%3==0)) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

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

typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
int main(){
    cin>>n;
    vector<int> d(n);
    rep(i,n)cin>>d.at(i);
    if(n%2){
        cout<<"0"<<endl;
    }
    sort(d.begin(),d.end());

    int right_smallest=n/2,left_upper=right_smallest-1;
    cout<<d.at(right_smallest)-d.at(left_upper)<<endl;
    return 0;
}




Measured memory_bytes: 640
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl             '\n'
#define all(a)           a.begin(), a.end()
#define mem(a, n)        memset(a, n, sizeof(a))
#define Unique(n)        (n).erase(unique(all(n)), (n).end())
#define NumofDigits(n)   ((long long)log10(n)+1)
#define repeat(i, a, n)  for(int i=a; i<n; i++)
#define isPowerOfTwo(n)  (n && !(n & (n - 1)))

typedef long long ll;
typedef long double ld;

int sieve(int n);
unsigned long long pow(long long base, long long power);
long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
void file(){
    #ifdef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif /*ONLINE_JUDGE*/
}

int main(){
    quicken();

    int n; cin >> n;
    vector<ll> v1, v2;
    v1.resize(n), v2.resize(n);
    repeat(i, 0, n) cin >> v1[i];
    repeat(i, 0, n) cin >> v2[i];

    vector<ll> v;
    repeat(i, 0, n) v.push_back(i+1);
    ll a, b, cnt=0;

    do{
        cnt++;
        if(v==v1) a = cnt;
        if(v==v2) b = cnt;
    }while(next_permutation(all(v)));

    cout << abs(a-b);

    return 0;
}

unsigned long long pow(long long base, long long power){ /// mod?
    if(power==0) return 1;
    if(power==1) return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1) return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

int sieve(int n){
    int c = 0;
    vector<bool> isPrime(n+1, true);
    isPrime[0] = isPrime[1] = 0;

    for(long long i=2; i*i<=n; i++)
        if(isPrime[i])
            for(long long j=i*2; j<=n; j+=i)
                isPrime[j] = 0;
    repeat(i, 0, n+1)
        if(isPrime[i]) c++;
    return c; /// primeCount [1:n]
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    multiset<string> st;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        st.insert(s);
    }
    string ans = "";
    for(auto x : st)
    {
        ans += x;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
import java.util.*;

class Main {
	public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
      	int n = Integer.parseInt(sc.next());
      	int d = Integer.parseInt(sc.next());
      	int c = 0;
      
      	int[][] A = new int[n][2];
      	int x, y;
      	for (int i = 0; i < n; i++) {
          	x = Integer.parseInt(sc.next());
          	y = Integer.parseInt(sc.next());
          	if ((Math.pow(x, 2) + Math.pow(y, 2)) <= Math.pow(d, 2)) {c++;}
        }
      	System.out.println(c);
    }
}

Measured memory_bytes: 64836
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 62;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
ll cnt = 0;

void solve()
{
     ll a,b,c;
     cin >> a >> b >> c;
     cout<<c<<" "<<a<<" "<<b;
}

int main()
{
     FAST;
     ll t = 1;
    // cin >> t;
     while(t--)
     {
         
          solve();
     }
}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    map<int, long long> A;
    int N, M;
    cin >> N >> M;

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

    IFD{
        for(auto itr = A.begin(); itr != A.end(); itr++) {
            cout << itr->first << ": " << itr->second << ", ";
        }
        cout << endl;
    }

    for(int i = 1; i <= M; i++) {
        long long B, C;
        cin >> B >> C;
        while(B > 0) {
            auto v = A.begin();
            IFD {
                for(auto itr = A.begin(); itr != A.end(); itr++) {
                    cout << itr->first << ": " << itr->second << endl;
                }
            }
            if(v->first >= C) {
                break;
            }
            int flip_num = min(v->second, B);
            IFD cout << "f: " << flip_num << endl;
            if(flip_num == v->second) {
                IFD cout << "erasing" << endl;
                A.erase(v);
            } else {
                A[v->first] -= flip_num; 
            }
            A[C] += flip_num;
            B -= flip_num;
            IFD cout << endl;
        }
    }

    long long ans = 0;
    for(auto itr = A.begin(); itr != A.end(); itr++) {
        ans += itr->first * itr->second;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
A=[chr(97+i) for i in range(26)]
T={a:float("inf") for a in A}

N=int(input())
for _ in range(N):
    S=input()
    for a in A:
        T[a]=min(T[a],S.count(a))

X=""
for a in A:
    X+=a*T[a]
print(X)


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

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

int main()
{
    int n;
    scanf("%d", &n);

    int inp[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &inp[i]);

    int ans = 0;
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if (inp[i - 1] >= inp[i])
            cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

ll mod_pow(ll x, ll n, ll mod = MOD) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

int N;
vector<int> g[212345];
int cnt[212345], par[212345];

int dfs(int u, int p) {
	int res = 1;
	for (int v : g[u]) if (v != p) {
		par[v] = u;
		res += dfs(v, u);
	}
	return cnt[u] = res;
}

int main() {
	cin >> N;
	REP(i, N - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	dfs(0, -1);
	
	ll ans = 0;
	REP(i, N) {
		vector<int> childs;
		if (N - cnt[i] > 0) childs.push_back(N - cnt[i]);
		for (int v : g[i]) if (par[i] != v) childs.push_back(cnt[v]);
		if (childs.size() <= 1) continue;
		ll pat = (mod_pow(2, N - 1) - 1 + MOD) % MOD;
		for (int c : childs) pat = (pat - (mod_pow(2, c) - 1) + MOD) % MOD;
		ans = (ans + pat) % MOD;
	}
	ans = ans * mod_pow(mod_pow(2, N), MOD - 2) % MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 21888
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
//const int N = 2e5 + 5;
   
int sum(int l, int r) {

	return (l + r)*(r - l + 1) / 2;

}

int gcd(int a, int b) {

	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a%b);
	}

}

int32_t  main() {

	IOS;

	int N, K;

	cin >> N >> K;
 
		int ans = N % K;
		int ans2 = abs(ans - K);

		
		cout << min(ans,ans2) << endl;

	 
}


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

#define si(v) v.size()
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (n); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

using ll = long long;
using ld = long double;
using namespace std;

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

  int a, b; cin >> a >> b;
  if (a == 1) a = 14;
  if (b == 1) b = 14;

  cout << (a < b ? "Bob\n" : a > b ? "Alice\n" : "Draw\n");
  
  return (0);
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N,Q;
	cin >> N >> Q;
	vector<int> tree(N,-1);
	for (int i = 0; i < N-1; i++){
		int l, r;
		cin >> l >> r; l--; r--;
		tree[r] = l;
	}
	vector<lli> num(N,0);
	for (int i = 0; i < Q; i++) {
		lli l, r;
		cin >> l >> r; l--;
		num[l] += r;;
	}
	for (int i = 0; i < N; i++) {
		//tree up;
		int pos = i;
		vector<int> allp = { i };
		while (pos >= i) {
			if (tree[pos] == -1) {
				break;
			}
			for (int pp : allp) {
				num[pp] += num[tree[pos]];
			}
			allp.push_back(tree[pos]);
			pos = tree[pos];
		}
		cout << num[i];
		if (i == N - 1) {
			cout << endl;
		}
		else {
			cout << " ";
		}
	}
	return 0;
}


Measured memory_bytes: 4736
//
//  main.cpp
//  oct_26
//
//  Created by 田中諒 on 2019/10/26.
//  Copyright © 2019 田中諒. All rights reserved.
//

#include <iostream>
using namespace std;

int main()
{
    
    int A, B;
    cin >> A >> B;
    
    if (A == 1 or B == 1){
        if(A==B){
            cout << "Draw" << endl;
        } else if (A == 1){
            cout << "Alice" << endl;
        } else{
            cout << "Bob" << endl;
        }
    }
    
    else{
        if (A > B){
            cout << "Alice" << endl;
        }else if (A < B){
            cout << "Bob" << endl;
        }else {
            cout << "Draw" << endl;
        }
    }
    
    return 0;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int >v(n);
    int totalVotes=0;
    for(int i=0;i<n;i++)
    {
         cin>>v[i];
         totalVotes+=v[i];
    }
    int threshold=totalVotes/(4*k);
    int counter=0;
    for(int i=0;i<n;i++)
    {
        if(v[i]>(threshold) or v[i]==threshold and totalVotes%(4*k)==0 )
            counter++;
    }
    if(counter>=k)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
max_h = h[0]
ans = 1
for i in range(1,n):
  if h[i]-h[i-1] >= 0 and max_h <= h[i]:
    ans += 1
  max_h = max(h[i],max_h)
print(ans)

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

int main() {
  long N;
  cin>>N;
  int a=0,w=0,t=0,r=0;
  for(int i=0;i<N;i++){
    string s;
    cin>>s;
    if(s=="AC") a++;
    if(s=="WA") w++;
    if(s=="TLE") t++;
    if(s=="RE") r++;
  }
  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<w<<endl;
  cout<<"TLE x "<<t<<endl;
  cout<<"RE x "<<r<<endl;

  }


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, d, x, d0; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1,-1,-1,-1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    int dfs(int i, int p, int d) {
        pair<int, int> d0 = { v[i].d = d, p };
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge &o = e[j];
            if (o.i == p) continue;
            d0 = max(d0, { dfs(o.i, i, d + 1), o.i });
        }
        v[i].d0 = d0.first;
        //v[i].x = d0.second;
        return d0.first;
    }
    void dfs2(int i, int p, int d, int r0) {
        if (d <= d1 && d1 - d < d) {
            int e = d - (d1 - d);
            r0 = max(r0, v[i].d0 - e + max(e - 1, 0));
        }
        if (i == v1) r1 = r0;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge &o = e[j];
            if (o.i == p) continue;
            dfs2(o.i, i, d + 1, r0);
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m, d1, v1, r1;
};

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

    int n, u, v;
    cin >> n >> v >> u;
    u--; v--;

    Graph g(n, (n - 1) * 2);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.dfs(u, -1, 0);

    int d = g.v[v].d;
    int d0 = g.v[v].d0;
    g.d1 = d;
    g.v1 = v;
    g.r1 = -1;
    g.dfs2(u, -1, 0, -1);

    cout << g.r1 << endl;

    //青木君がいる場所を根として高橋君は可能なら深そうなとこへ逃げる

    return 0;
}

Measured memory_bytes: 7936
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=202202;
char s[N];
int n,x,t;
int main(){
	scanf("%s",s);
	n=strlen(s);
	int sum=0;
	for (int i=0; i<n; i++)
		sum=sum+s[i]-'0';
	sum%9==0?printf("Yes\n"):printf("No\n");
	return 0;
}

Measured memory_bytes: 1804
class Dice():
    directions = "EEENEEENEEESEEESEEENEEEN"

    def __init__(self, lst):
        self.top = lst[0]
        self.front = lst[1]
        self.right = lst[2]
        self.left = lst[3]
        self.back = lst[4]
        self.bottom = lst[5]

    def rotate(self, direction):
        if direction == "E":
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        if direction == "N":
            self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        if direction == "S":
            self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom
        if direction == "W":
            self.top, self.left, self.bottom, self.right = self.right, self.top, self.left, self.bottom

    def fit_top_front(self, num_top, num_front):
        for direction in Dice.directions:
            if self.top == num_top and self.front == num_front:
                break
            self.rotate(direction)

    def fit_all(self, dice):
        for direction in Dice.directions:
            if self.top == dice.top and self.front == dice.front and self.right == dice.right and self.left == dice.left and self.back == dice.back and self.bottom == dice.bottom:
                return True
            self.rotate(direction)
        return False


def compare(lst, dice):
    for direction in Dice.directions:
        if lst[0] == dice.top and lst[1] == dice.front and lst[2] == dice.right and lst[3] == dice.left and lst[4] == dice.back and lst[5] == dice.bottom:
            return True
        dice.rotate(direction)
    return False


def main():
    num_dices = int(input())  # number of dices
    dices = []  # label of dices
    dices.append(list(map(int, input().split())))  # first dice
    for _ in range(num_dices - 1):
        label_dice = list(map(int, input().split()))
        dice = Dice(label_dice)
        for i in range(len(dices)):
            result = compare(dices[i], dice)
            if result == True:
                print("No")
                return 0
        dices.append(label_dice)
    print("Yes")


if __name__ == "__main__":
    main()



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,K;
  cin >> N >> K;
  vector<int> a(N);
  for(int i=0;i<N;i++)  cin >> a.at(i);

  vector<bool> dp(K+1,false);
  dp.at(0)=false;
  for(int i=0;i<=K;i++){
    for(int j=0;j<N;j++){
      if(i-a.at(j)<0) continue;
      if(!dp.at(i-a.at(j))) dp.at(i)=true;
    }
  }
  if(dp.at(K))  cout << "First" << endl;
  else  cout << "Second" << endl;

  return 0;
}

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

int main() {
  vector<int64_t>N(3);
  cin >> N.at(0) >> N.at(1) >> N.at(2);
  sort(N.begin(), N.end());
  
  if(N.at(0)%2!=0 && N.at(1)%2!=0 && N.at(2)%2!=0){
    cout << N.at(0)*N.at(1) << endl;
  }
  else cout << 0 << endl;
  
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c-a-b;
    if (d>0 && d*d - 4*a*b >0) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

typedef struct DP{
    int dist;
    pair<int, int> from;
    bool st;
} DP;

typedef pair<int, int> P;

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

int main(int argc, char const *argv[]) {
    int h, w;
    cin >> h >> w;
    char c[h][w];
    REP(i,h) {
        string s;
        cin >> s;
        REP(j,w) c[i][j] = s[j];
    }
    int sy = 0; int sx = 0; int gy = h-1; int gx = w-1;
    DP dp[h][w];
    REP(i,h) REP(j,w) {
        dp[i][j].dist = INF;
        dp[i][j].from = {INF, INF};
        dp[i][j].st = false;
    }
    dp[sy][sx].dist = 0; dp[sy][sx].from = {INF, INF}; dp[sy][sx].st = true;

    queue<P> q;
    q.push({sy, sx});

    while(!q.empty()){
        P p = q.front();
        int y = p.first; int x = p.second;
        q.pop();
        REP(i,4){
            int ny = y+dy[i]; int nx = x+dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if (c[ny][nx] == '#') continue;
            if (dp[ny][nx].dist == INF) {
                dp[ny][nx].dist = dp[y][x].dist+1;
                dp[ny][nx].from = {y, x};
                q.push({ny, nx});
            }
        }
    }
    int y = gy; int x = gx;
    if (dp[y][x].dist == INF) {
        cout << -1 << std::endl;
        return 0;
    }
    while(y != INF && x != INF){
        dp[y][x].st = true;
        P from = dp[y][x].from;
        y = from.first; x = from.second;
    }
    int ans = 0;
    REP(i,h) REP(j,w) {
        if (!dp[i][j].st && c[i][j] == '.') ans++;
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
  int a, b;
  cin >> a >> b;
  
  printf("%d", a * b);
  
}

int main()
{
  std::cout << std::fixed << std::setprecision(15);
  Main();
}



Measured memory_bytes: 3752
import sys
from io import StringIO
import unittest


# https://atcoder.jp/contests/abc083/tasks/arc088_a
# 入力例1、間違ってね?
# 入力；3 20 で、出力3。これは分かるが・・「数式3,6,18」が条件を満たします。->「3,6,12」じゃね?
# その前提でやってみよう。

def resolve():
    # ★get input
    x, y = map(int, input().split())

    count = 0
    work_x = x
    while work_x <= y:
        count += 1
        work_x = work_x*2

    print(count)



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 20"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """25 100"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """314159265 358979323846264338"""
        output = """31"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 51436
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace D_ABC162
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            string u = ReadLine();
            int n = s[0];
            // long sum = 0;

            long r = 0;
            long g = 0;
            long b = 0;
            long rg = 0;
            long gr = 0;
            long rb = 0;
            long br = 0;
            long gb = 0;
            long bg = 0;
            long rgb = 0;

            for (int i = n - 1; i >= 0; i--)
            {
                if (u[i] == 'R')
                {
                    r++;
                    rb += b;
                    rg += g;
                    rgb += (gb+ bg);
                    for (int j = i; j <= (i + n - 1) / 2; j++)
                    {
                        if ((u[j] == 'B' && u[j + (j - i)] == 'G') || (u[j] == 'G' && u[j + (j - i)] == 'B'))
                        {
                            rgb--;
                        }
                    }
                }
                else if (u[i] == 'G')
                {
                    g++;
                    gr += r;
                    gb += b;
                    rgb += (rb + br);
                    for (int j = i; j <= (i + n - 1) / 2; j++)
                    {
                        if ((u[j] == 'B' && u[j + (j - i)] == 'R') || (u[j] == 'R' && u[j + (j - i)] == 'B'))
                        {
                            rgb--;
                        }
                    }
                }
                else
                {
                    b++;
                    br += r;
                    bg += g;
                    rgb += (rg + gr);
                    for (int j = i; j <= (i + n - 1) / 2; j++)
                    {
                        if ((u[j] == 'G' && u[j + (j - i)] == 'R') || (u[j] == 'R' && u[j + (j - i)] == 'G'))
                        {
                            rgb--;
                        }
                    }
                }
            }
            WriteLine(rgb);
        }
    }
}


Measured memory_bytes: 28032
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,0,1,-1,1,-1,0,1};
int dy[]={-1,-1,-1,0,0,1,1,1};

    int w,h;
void dfs(int i,int j,vector<vector<int>>& x){
        x[i][j]=0;
        for(int r=0;r<8;r++)
            if(0<=i+dx[r] && i+dx[r]<h && 0<=j+dy[r] && j+dy[r]<w && x[i+dx[r]][j+dy[r]])
                dfs(i+dx[r],j+dy[r],x);



}
int main(){
    while(cin>>w>>h,w){
        vector<vector<int>> x(h,vector<int>(w,0));
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                cin>>x[i][j];
        int cnt=0;
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++){
                if(x[i][j]){
                    cnt++;
                    dfs(i,j,x);


                }




            }
        cout<<cnt<<endl;



    }


    return 0;
}

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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}


int N;


void dfs(string s,char mx){
    if(s.length()==N){
        cout<<s<<endl;
        //return;
    }else{
        for(char c='a';c<=mx;c++){
            dfs(s+c,
                    ((c==mx)? (char)(mx+1):mx)  );
        }
    }
}

int main()
{
    cin>>N;
    dfs("",'a');

    return 0;

}




Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
 
//defines
typedef long long ll;
typedef long double ld;

ll n,m,k,tar,a,b,d,e;
void solve()
{
    cin>>n>>k;
    cout<<(n*k);
// if(t>0)cout<<"\n";

}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
   
        solve();
    
    
        
    return 0;
}

Measured memory_bytes: 3640
import itertools

n, m = map(int, input().split())

l = []

for i in range(n):
    l.append(2)
for i in range(m):
    l.append(1)

ll = itertools.combinations(l, 2)

ans = 0
for i in ll:
    if (i[0]+i[1])%2 == 0:
        ans += 1

print(ans)

Measured memory_bytes: 40092
from collections import defaultdict
from math import gcd

N = int(input())
MOD = 1000000007
d = defaultdict(int)
num_00 = 0
pow2 = [1]
for i in range(N):
  pow2.append((pow2[-1] * 2) % MOD)

def to_idx(a, b):
  if a == 0 and b != 0:
    return ((0, -1), (0, 1))
  elif a != 0 and b == 0:
    return ((-1, 0), (1, 0))
  else:
    return tuple(sorted(((a, b), (-a, -b))))

ans = 0
for i in range(N):
  a, b = map(int, input().split())
  if a*b == 0 and a != b:
    d[to_idx(a, b)] += 1
  elif a == b == 0:
    num_00 += 1
  else:
    g = gcd(a, b)
    a //= g; b //= g
    d[to_idx(a, b)] += 1

memo = []
key_set = set(d.keys())
while key_set:
  k = key_set.pop()
  v1, v2 = k
  a, b = v1
  idx = to_idx(-b, a)
  memo.append((pow2[d[k]] + pow2[d[idx]] - 1) % MOD)
  key_set.discard(idx)

ans = 1
for m in memo:
  ans *= m
  ans %= MOD

print((ans - 1 + num_00) % MOD)

Measured memory_bytes: 172960
from itertools import accumulate as acc

N,K=map(int,input().split())
a=list(map(int,input().split()))
b=[max(a[i],0) for i in range(N)]

A=list(acc(a))
B=list(acc(b))

ans=0
for i in range(N-K+1):
    if i==0: tmp=max(A[K-1],0)+(B[N-1]-B[K-1])
    elif i==N-K: tmp=B[N-K-1]+max(A[N-1]-A[N-K-1],0)
    else: tmp=B[i-1]+max(A[i+K-1]-A[i-1],0)+(B[N-1]-B[i+K-1])
    ans=max(ans,tmp)


print(ans)

Measured memory_bytes: 17728
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;
 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

#define N 300001

char c[N];
int stk[N], top = -1;
int main()
{
	fastIO;

	int n, m = 0, ans = 0; cin >> n;

	for(int i = 0; i < n; i++) 
	{
		cin >> c[i];
		if(c[i] == 'R') m++;
		else stk[++top] = i;
	}
	for(int i = 0, k = 0; i < n && k < m; i++, k++)
	{
		if(c[i] == 'W')
		{
			int idx = stk[top--];
			c[i] = 'R'; c[idx] = 'W';
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4564
A, B = [int(i) for i in input().strip().split(" ")]

base = B * 10
while True:
  price8p = base * 8 // 100
  if price8p == A:
    print(base)
    break
  elif price8p > A:
    print(-1)
    break
  base += 1
  if base // 10 != B:
      print(-1)
      break


Measured memory_bytes: 2940
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll M =1e9+7;
const int N = 1e5+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

vector<int> adj[N];
bool vis[N]={0};

void dfs(int x)
{
    vis[x]=1;
        
    for(auto it:adj[x])   
    if(!vis[it])
    dfs(it);
        
}


int main()
{
    int a,b,c;
    scf(a),scf(b),scf(c);

    if(a<=c&&b>=c)
        cout<<"Yes\n";

    else
 cout<<"No\n";        
    
 

    
}

Measured memory_bytes: 6088
import java.util.*;
import java.lang.Math;

public class Main {

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

		int b = 0;
		
		for (int i = 0 ;i < a; i++){
			x[i] = sc.nextInt();
			b += x[i];
		}
		
		int c = (int)(b/a);
		int d = c + 1;
		
		int sum1 = 0;
		int sum2 = 0;
		
		for(int i = 0; i < a; i++){
			sum1 += Math.pow(x[i] - c, 2);
		}
		for(int i = 0; i < a; i++){
			sum2 += Math.pow(x[i] - d, 2);
		}
		
		System.out.println(Math.min(sum1, sum2));
	}
}


Measured memory_bytes: 9556
fun main(args: Array<String>) {
    val (s1, s2) = readLine()!!.split(" ")
    var (A, B) = readLine()!!.split(" ").map { it.toLong() }
    val s3 = readLine()!!
    when {
        s1 == s3 -> A--
        s2 == s3 -> B--
    }
    println("$A $B")
}

Measured memory_bytes: 35944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    map<char, int> mp;
    rep(i, N) {
        string S;
        cin >> S;
        mp[S[0]] = (mp.count(S[0]) != 0) ? mp[S[0]] + 1 : 1;
    }
    vector<int> vec(5);
    vec[0] = (mp.count('M') != 0) ? mp['M'] : 0;
    vec[1] = (mp.count('A') != 0) ? mp['A'] : 0;
    vec[2] = (mp.count('R') != 0) ? mp['R'] : 0;
    vec[3] = (mp.count('C') != 0) ? mp['C'] : 0;
    vec[4] = (mp.count('H') != 0) ? mp['H'] : 0;
    ll ans = 0;
    FOR(i, 0, 3) FOR(j, i + 1, 4) FOR(k, j + 1, 5) {
        ans += (ll)vec[i]*(ll)vec[j]*(ll)vec[k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarize_list(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

# nCr -- START --
def nCr(n,r):
  if n<r:
    return 0
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
# nCr --- END ---

def main():
  n=I()
  l=LI()

  for i in range(n-1):
    l[i+1]+=l[i]

  l=summarize_list(l)

  ans=0
  for x in l:
    if x[0]==0:
      ans+=x[1]

    if x[1]>1:
      ans+=nCr(x[1],2)

  return ans

# main()
print(main())


Measured memory_bytes: 41312
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  string s;
  cin >> s;
  cout << s[0] << s[1] << s[2] << endl;
  return 0;
}

Measured memory_bytes: 3624
import collections
n=int(input())
a=list(map(int,input().split()))
q=int(input())
s=sum(a)
d=collections.Counter(a)
for i in range(q):
  b,c=map(int,input().split())
  s=s-b*d[b]+c*d[b]
  print(s)
  if c in d:
    d[c]+=d[b]
  else:
    d[c]=d[b]
  d[b]=0

Measured memory_bytes: 87392
k, n = map(int,input().split())
a = [int(i) for i in input().split()]
distance = []
for i in range(len(a) - 1):
    distance.append(a[i + 1] - a[i])
distance.append(k - a[len(a)- 1] + a[0])
print(k - max(distance))

Measured memory_bytes: 26444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define int long long
long double poww(long double n)
{
    long double ans=1;
    for(int i=1;i<=n;i++)
    {
        ans*=2;
    }
    return ans;
}
int32_t main()
{
    long double n,k; cin>>n>>k;
    long double ans=0;
    for(int i=1;i<=n;i++)
    {
            //cout<<"work";
            int temp=i;
            //cout<<temp<<endl;
            long double x=1/n;
            while(temp<k)
            {
                temp*=2;
                x/=2;
            }
            //cout<<1/x<<endl;
            ans+=x;
    }
    printf("%0.12Lf",ans);
}


Measured memory_bytes: 256