akhauriyash/Code-Regression huggingface dataset:
/* Standard Deviation */
#include <stdio.h>
#include <math.h>

int main()
{
    int n, i;
    double s[1001], m, a;

    while(1){
        scanf("%d", &n);
        if(n == 0){ break; }
        m = 0.0;
        for(i=0; i<n; i++){
            scanf("%lf", &s[i]);
            m += s[i];
        }
        m /=  n;
        a = 0.0;
        for(i=0; i<n; i++){
            a += pow(s[i] - m,2);
        }
        printf("%.8lf\n", sqrt(a / n));
    }
    return 0;
}


Measured memory_bytes: 2044
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	ll N;
	cin >> N;
	string str;
	cin >> str;
	if(str.find("W")==string::npos or str.find("R")==string::npos){
		cout << 0 << endl;
		return 0;
	}
	ll l=0, r=N-1;
	ll c=0;
	while(true){
		while(l<r and str[l]=='R')l++;
		while(l<r and str[r]=='W')r--;
		if(l>=r)break;
		c++;
		l++;
		r--;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;

int main(){
  int N,T,A,point;
  cin >> N >> T >> A;
  double sa,ka=T+1000;
  int H[N+10];
  for(int i=0; i<N; i++){
    cin >> H[i];
  }for(int i=0; i<N; i++){
      sa=T-H[i]*0.006;
      sa=abs(sa-A);
      if(sa<ka){
        point =i;
        ka=sa;
      }
  }cout << point+1 << endl;
}

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

int min(int a, int b){
    if (a > b){
        return b;
    }else{
        return a;
    }
}

int main()
{    
    int N;
    cin >> N;
    long long h[N];
    long long dp[N];
    for (int i = 0; i < N; ++i) 
        cin >> h[i];

    for (int i = 0; i < N; ++i) 
        dp[i]=0;

    dp[1]=abs(h[0]-h[1]);

    for (int i = 2; i < N; ++i)
        dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);

    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;

namespace ConsoleApp {

    class Program {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Trim().Split().Select(s => int.Parse(s)).ToArray();
            var cnt = 0;

            while (true) {
                for(int i = 0; i < n; i++) {
                    if(array[i] % 2 == 0) {
                        array[i] /= 2;
                    }
                    else {
                        goto fin;
                    }
                }
                cnt++;
            }
            fin:
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13396
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))

a_b_pairs = [list(map(int, input().split(' '))) for _ in range(M)]
a_b_pairs.sort(key=lambda x: x[1])
right = a_b_pairs[0][1] - 1

ans = 1
for a, b in a_b_pairs[1:]:
    if a > right:
        right = b - 1
        ans += 1

print(ans)





Measured memory_bytes: 28516
import itertools
def main():
    n=int(input())
    a=sorted(map(int,input().split()))
    b=list(itertools.accumulate(a))
    cnt=0
    for i in reversed(range(1, n)):
        if b[i-1]*2 < a[i]:
            return n-i
    return n
            
if __name__ == "__main__":
    print(main())

Measured memory_bytes: 20636
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int x;
    cin >> x;
    if (x == 1) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef long long ll;
ll n, m, v, p;
string to_string(string s) {
  return '"' + s + '"';
}
string to_string(const char* s) {
  return to_string((string) s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef KEK
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
bool check(int mid, vector <ll> A) {
	A[mid] += m;
	ll tot = m * (v - 1);
	int cnt = 0;
	int ip = 0;
	for(int i = n - 1; ip < p - 1; i--) {
		if(i != mid) {
			ip++;
			if(tot > 0) {
				A[i] += m;
				tot -= m;
			}
		}
	}

	for(int i = 0; i < n; i++) {
		if(A[i] < A[mid] && tot > 0) {
			ll inc = min(A[mid] - A[i], min(tot, m));
			A[i] += inc;
			tot -= inc;
		}
		cnt += A[i] > A[mid];
	}
	return cnt < p && tot == 0;
}

int main() {fio;
	cin >> n >> m >> v >> p;
	vector <ll> A(n);
	for(int i = 0; i < n; i++) {
		cin >> A[i];
	}
	sort(all(A));
	int lo = 0, hi = n - 1;
	while(lo < hi) {
		int mid = lo + (hi - lo) / 2;
		if(check(mid, A)) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		ans += A[i] >= A[lo];
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn gcd(mut a: i32, mut b: i32) -> i32 {
    while b != 0 {
        let r = a % b;
        a = b; b = r;
    }
    a
}
fn lcm(x: i32, y: i32)->i32{
    return x /gcd(x, y) * y;
}
fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
   input!{
       r: i32,
   } 
   puts!("{}\n", 3 * r * r);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

Measured memory_bytes: 8572
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n,x;
  cin >> n >> x;
  int a[2*n-1];
  if(x > 2*n-2 || x < 2){
    cout << "No" << endl;

  }else{
    cout << "Yes" << endl;
    for(int i = 0; i < 2*n-1; i++){
      a[i] = 0;
    }
    int blk = 0;

    if(x > n){
      a[n-1] = 2*n-1;
      a[n] = x;
      blk = 1;

      for(int i = 0; i < 2*n-1; i++){
        if(a[i] == 0){
          a[i] = blk;
          blk++;
          if(blk == x)
            blk++;
        }
      }

    }else if(x < n){
      a[n-1] = 1;
      a[n] = x;
      if(x == 2){
        blk = 3;
      }else{
        blk = 2;
      }
      for(int i = 0; i < 2*n-1; i++){
        if(a[i] == 0){
          a[i] = blk;
          blk++;
          if(blk == x)
            blk++;
        }
      }

    }else if(x == n){
      for(int i = 0; i < 2*n-1; i++){
        a[i] = i+1;
      }
    }
    for(int i = 0; i < 2*n-1; i++){
      cout << a[i] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int[] A = new int[N];
		
		long[] box = new long[N];
		for(int i = 0; i < N; i ++) {
			box[i] = 0;
		}
		
		for(int i = 0; i < N; i ++) {
			A[i] = stdIn.nextInt();
			box[A[i] - 1] ++;
		}
		
		long ans = 0;
		for(int i = 0; i < N; i ++) {
			if(box[i] == 0) {
				continue;
			}
			ans += box[i] * (box[i] - 1) / 2;
		}
		
		for(int i = 0; i < N; i ++) {
			System.out.println(ans - (box[A[i] - 1] - 1));
		}
	}
}

Measured memory_bytes: 103136
def main()->None:
    # 解説見た
    # 強さを弱い順に並べて、初めからN番目までは各チームの１番弱い人
    # N番から２N番は各チームで２番目に強い人
    N = int(input()) # team数
    a = list(map(int, input().split()))
    sorted_a = sorted(a)
    
    sum_a = 0 # ２番目の人の和
    range_N = range(N)
    for i in range(N):
        sum_a += sorted_a[3*N - 2*i - 2]
    print(sum_a)


if __name__ == "__main__":
    main()

Measured memory_bytes: 37084
n = int(input())
a = [int(i) for i in input().split(" ")]
b = [int(j) for j in input().split(" ")]
c = [int(i) for i in input().split(" ")]
gain = 0 
for i in range(n):
	if(i==0):
		gain += b[a[i]-1]
	else:
		gain += b[a[i]-1]
		if(a[i]==a[i-1]+1):
			gain += c[a[i-1]-1]
print(gain)

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

using namespace std;

int cnt, ans, K, N, ap[5009], p[5009], a[5009], b[5009], M, dp[5009][5009];
const int mod = 1e9 + 7;
vector < int > v[5009];

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int fac[2000009], inv[2000009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){if (K > N || N < 0 || K < 0) return 0; int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}

int currA, currB;
void dfs (int nod)
{
    if (ap[nod])
        return ;
    ap[nod] = 1, currB ++, currA += (p[nod] == -1);
    for (auto it : v[nod])
        dfs (it);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N), Prec (2 * N + 100), cnt = 1;
for (int i=1; i<=N; i++)
{
    scanf ("%d", &p[i]);
    if (p[i] == -1)
        K ++, cnt = mul (cnt, N - 1);
    else
        v[i].push_back (p[i]),
        v[p[i]].push_back (i);
}
ans = mul (cnt, N);
for (int i=1; i<=N; i++)
    if (ap[i] == 0)
    {
        currA = currB = 0, dfs (i);
        ans = subtract (ans, cnt);
        if (currA != 0)
            b[++M] = currB;
    }
///for every new connection ++
for (int i=1; i<=M; i++)
    adto (ans, mul (power (N - 1, K - 1), N - b[i]));
///for every cycle --
/*for (int msk = 1; msk < (1 << M); msk ++)
{
    int L = 0, curr = 1;
    for (int i=0; i<M; i++)
        if (msk & (1 << i))
            curr = mul (curr, b[i + 1]), L ++;
    if (L == 1)
        continue;
    curr = mul (curr, fac[L - 1]);
    curr = mul (curr, power (N - 1, K - L));
    ans = subtract (ans, curr);
}*/
dp[0][0] = 1;
for (int i=0; i<M; i++)
    for (int j=0; j<=i; j++)
    {
        adto (dp[i + 1][j], dp[i][j]);
        adto (dp[i + 1][j + 1], mul (dp[i][j], b[i + 1]));
    }
for (int L = 2; L <= M; L ++)
{
    int curr = mul (power (N - 1, K - L), mul (dp[M][L], fac[L - 1]));
    ans = subtract (ans, curr);
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 70740
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int l = 1001;
  int r = -1;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    l = min(l, a);
    r = max(r, a);
  }
  cout << r-l << endl;
  return 0;
}


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

res = 0
for i in range(N-2):
    n = 1
    while True:
        j = i+n
        k = j+n
        if k > N-1: break
        res += (S[i] != S[j] and S[j] != S[k] and S[k] != S[i])
        n += 1
    
    
rgb = S.count("R") * S.count("G") * S.count("B")
print(rgb - res)


Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 1000010;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> v(MAX);
  iota(v.begin(), v.end(), 1);
  for (int i = 1; i <= MAX; i++) {
    if (i%3 == 0 || i%5 == 0)
      v[i-1] = 0;
  }
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n)
    ans += v[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7096
k = int(input())
n = 50

ans = list(map(lambda x: x + (k // n), range(n)))

for i in range(k % n):
    for j in range(n):
        if i == j:
            ans[j] += n
        else:
            ans[j] -= 1
print(n)
print(" ".join(list(map(str, ans))))

Measured memory_bytes: 38512
X = int(input())
if X < 600:
    ans = 8
elif X < 800:
    ans = 7
elif X < 1000:
    ans = 6
elif X < 1200:
    ans = 5
elif X < 1400:
    ans = 4
elif X < 1600:
    ans = 3
elif X < 1800:
    ans = 2
else:
    ans = 1
print(ans)

Measured memory_bytes: 9176
import java.util.*;
import java.util.concurrent.ConcurrentLinkedDeque;

public class Main {
	static class Island {
		int index;
		Island parent;
		Set<Island> members;

		Island(int index) {
			this.index = index;
			this.parent = null;
			this.members = new HashSet<>();
		}

		int getGroupIndex() {
			if (this.parent == null) {
				return index;
			} else {
				return this.parent.getGroupIndex();
			}
		}

		Set<Island> getMembers() {
			if (this.parent == null) {
				return this.members;
			} else {
				return this.parent.getMembers();
			}
		}

		Island getRoot() {
			if (this.parent == null) {
				return this;
			} else {
				return this.parent.getRoot();
			}
		}

		long merge(Island island) {
			Island anotherRoot = island.getRoot();
			Island thisRoot = this.getRoot();
			if (thisRoot.index > anotherRoot.index) {
				return anotherRoot.merge(thisRoot);
			} else if (thisRoot.index == anotherRoot.index) {
				return 0;
			}
			long anoSize = anotherRoot.members.size() + 1;
			long size = thisRoot.members.size() + 1;
			anotherRoot.parent = thisRoot;
			thisRoot.members.add(anotherRoot);
			thisRoot.members.addAll(anotherRoot.members);
			return size * anoSize;
		}
	}

	int N, M;
	int[] A, B;
	Island[] islands;
	Deque<Long> results;

	void calc() {
		this.islands = new Island[N];
		for (int i = 0; i < N; ++i) {
			this.islands[i] = new Island(i);
		}
		this.results = new ConcurrentLinkedDeque<>();
		this.results.addFirst((long) N * (long) (N - 1) / 2);
		for (int i = M - 1; i >= 0; --i) {
			int index = A[i] - 1;
			int anoIndex = B[i] - 1;
			long diff = islands[index].merge(islands[anoIndex]);
			long r = results.getFirst() - diff;
			results.addFirst(r);
		}
		results.pollFirst();
	}

	void show() {
		while (!results.isEmpty()) {
			System.out.println(results.pollFirst());
		}
	}

	Main() {
		Scanner in = new Scanner(System.in);
		N = in.nextInt();
		M = in.nextInt();
		A = new int[M];
		B = new int[M];
		for (int i = 0; i < M; ++i) {
			A[i] = in.nextInt();
			B[i] = in.nextInt();
		}
		in.close();
	}

	public static void main(String[] args) {
		Main ins = new Main();
		ins.calc();
		ins.show();

	}

}


Measured memory_bytes: 137220
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x; }

int main(){
    int n; cin >> n;
    ll ans; cin >> ans;
    rep(i, n-1){
        ll x; cin >> x;
        ans = gcd(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
using P=pair<int,int>;
int main() {
    int n;cin>>n;
    ll power=1;
    for(int i=1;i<=n;i++){
        power*=i;
        power%=1000000007;
    }
    cout<<power<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

class Solver{
private:
  priority_queue<int> l;
  priority_queue<int, vector<int>, greater<int>> r;

  ll sum_b, m;

  void insert(int a){
    if(l.size() == 0 || a < l.top()){
      l.push(a); l.push(a);
      r.push(l.top()); l.pop();
    } else if(a <= r.top()){
      l.push(a); r.push(a);
    } else {
      r.push(a); r.push(a);
      l.push(r.top()); r.pop();
    }
  }

public:
  Solver(){
    sum_b = m = 0;
  }

  void query1(int a, int b){
    sum_b += b;

    if(l.size() && (a < l.top() || r.top() < a)){
        m += min(abs(a - l.top()), abs(a - r.top()));
    } 

    insert(a);
  }

  void query2(){
    cout << l.top() << " " << m + sum_b << endl;
  }
};

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

  Solver sv;
  while(q--){
    int c; cin >> c;
    if(c == 1){
      int a, b; cin >> a >> b;
      sv.query1(a, b);
    } else {
      sv.query2();
    }
  }

  return 0;
}


Measured memory_bytes: 3828
// copied by Nurstan Duisengaliev
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;

void solve () {
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 1; i <= n; i ++) {
		int k;
		cin >> k;
		if (k >= m) sum ++;
	}	
	cout << sum;
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//  cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int x=(n+1)/1.08;
		int y=x+0.5;
		if((int)(x*1.08)==n)
			cout<<x<<endl;
		else cout<<":("<<endl;
	}
	
	return 0;
} 

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

monsters = [int(i) for i in input().split()]
savers = [int(i) for i in input().split()]

cnt = 0
for i in range(N):
    first_match = savers[i] - monsters[i]
    if first_match > 0:
        cnt += monsters[i]
        monsters[i] = 0
        
        second_match = first_match - monsters[i+1]
        
        if second_match >= 0:
            cnt += monsters[i+1]
            monsters[i+1] = 0
        else :
            cnt += first_match
            monsters[i+1] = abs(second_match)
    else :
        cnt += savers[i]
        monsters[i] = abs(first_match)

print(cnt)

Measured memory_bytes: 19648
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
using namespace std;
using P = pair<char, char>;

inline bool compareBySecond(P &a, P &b) {
    if (a.second != b.second)
        return a.second < b.second;
    else
        return a.first < b.first;
}

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

	string s, t; cin >> s >> t;
	int n = s.size();

	vector<P> c;
	REP(i, n)
		c.push_back(make_pair(s[i], t[i]));

	bool ok = true;
	sort(ALL(c));
	REP(i, (int)c.size() - 1) {
		if (c[i].first == c[i+1].first)
			if (c[i].second != c[i+1].second)
				ok = false;
	}
    sort(ALL(c), compareBySecond);
	REP(i, (int)c.size() - 1) {
		if (c[i].second == c[i+1].second)
			if (c[i].first != c[i+1].first)
				ok = false;
	}

	if (ok) cout << "Yes" << '\n';
	else cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 4284
//abc132_e.cpp
//Wed May 13 22:06:42 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

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

	vector<int> edge[3*n];

	for (int i=0;i<m;i++){
		int u,v;
		cin >> u >> v;
		u--;v--;
		edge[u].push_back(v+n);
		edge[u+n].push_back(v+2*n);
		edge[u+2*n].push_back(v);
	}

	int s,t;
	cin >> s >> t;
	s--;t--;
	int dist[3*n];
	fill(dist,dist+3*n,-1);
	dist[s] = 0;
	queue<int> q;
	q.push(s);
	while(q.size()){
		int cur = q.front(); q.pop();
		for (int i=0;i<edge[cur].size();i++){
			int tmp = edge[cur][i];
			if (dist[tmp]==-1){
				dist[tmp] = dist[cur]+1;
				q.push(tmp);
			}
		}
	}
	if (dist[t]==-1){
		cout << -1 << endl;
	}else {
		cout << dist[t]/3 << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;

int main(){
    int N = 0;
    cin >> N;
    vector<int> T(N);
    int sum = 0;

    for (int i = 0; i < N; i++)
    {
        cin >> T[i];
        sum += T[i];
    }
    int sumc = sum;
    int M;
    cin >> M;
    vector<int> P(M);
    vector<int> X(M);
    for (int i = 0; i < M;i++)
    {
        cin >> P[i] >> X[i];
        sum -= T[P[i]-1];
        sum += X[i];
        cout << sum << endl;
        sum = sumc;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
  
using namespace std;

#define pi 3.141592653589793

double solve(int n, int t, int l, int b, int lose[], int back[])
{
	double result[110][110];
	int islose[101] = {}, isback[101] = {};
	double ans = 0;

	for(int i = 0; i < t + 1; i++){
		for(int j = 0; j < n + 1; j++){
			result[i][j] = 0.0;
		}
	}
	result[0][0] = 1.0;

	for(int i = 0; i < l; i++){
		islose[lose[i]] = 1;
	}
	for(int i = 0; i < b; i++){
		isback[back[i]] = 1;
	}

	for(int i = 0; i < t + 1; i++){
		for(int j = 0; j < n; j++){
			for(int k = 1; k < 7 ;k++){
				int next = j + k;
				if(next > n) next = n - (next - n);
				if(isback[next] == 1) result[i + 1][0] += result[i][j] / 6.0;
				else if(islose[next] == 1) result[i + 2][next] += result[i][j] / 6.0;
				else result[i + 1][next] += result[i][j] / 6.0;
			}
		}
	}

	for(int i = 1; i < t + 1; i++){
		ans += result[i][n];
	}
	return ans;
}

int main()
{
	int n, t, l, b;
	while(1){
		cin >> n >> t >> l >> b;
		if(n == 0 && t == 0 && l == 0 && b == 0) break;
		int lose[100], back[100];
		for(int i = 0; i < l; i++){
			cin >> lose[i];
		}
		for(int i = 0; i < b; i++){
			cin >> back[i];
		}
		printf("%6f\n", solve(n, t, l, b, lose, back));
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
   int p = (int)log2(n);
   return (int)pow(2, p);  
}
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;  
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
 
int main()
{
    fastio;
    ll d,t,s;
    cin>>d>>t>>s;
    double val = (double)d/s;
    if(val<=double(t))
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3668
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x)
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    //start from here

    readc(n, a, b);
    readarr(p, n);

    int c1, c2, c3;
    c1 = c2 = c3 = 0;

    fori (i, 1, n)
    {
    	if(p[i] <= a) c1++;
    	else if(p[i] > a && p[i] <= b) c2++;
    	else c3++;
    }

    cout << min(c1, min(c2, c3));

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 5e5+5;
int n = 0, q = 0;

struct Query
{
    int id, l, r;
    bool operator<(Query a) const
    {
        return r < a.r;
    }
} query[maxn];

int v[maxn], sum[maxn], ans[maxn];

int lowbit(int x)
{
    return x & (-x);
}

void change(int i, int a)
{
    while (i <= n)
    {
        sum[i] += a;
        i += lowbit(i);
    }
}

int getsum(int i)
{
    int sum_t = 0;
    while (i > 0)
    {
        sum_t += sum[i];
        i -= lowbit(i);
    }
    return sum_t;
}

int main()
{

    scanf("%d %d", &n,&q);
        memset(v, 0, sizeof(v));
    memset(sum, 0, sizeof(sum));
    memset(ans, 0, sizeof(ans));

    int t = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &v[i]);
    }
    //scanf("%d", &q);
    for (int i = 1; i <= q; i++)
    {
        scanf("%d%d", &query[i].l, &query[i].r);
        query[i].id = i;
    }
    sort(query + 1, query + q + 1);

    int pre = 1;
    map<int, int> mymap;
    for (int i = 1; i <= q; i++)
    {
        for (int j = pre; j <= query[i].r; j++)
        {
            //已存在
            if (mymap[v[j]])
            {
                change(mymap[v[j]], -1);
            }
            mymap[v[j]] = j;
            change(j, 1);
        }
        pre = query[i].r + 1;
        ans[query[i].id] = getsum(query[i].r) - getsum(query[i].l - 1);
    }

    for (int i = 1; i <= q; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

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

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    string squares[10];
    rep(i,h) cin >> squares[i];
    int ans = 0;

    rep(row, pow(2,h)){
        rep(column, pow(2,w)){
            int count = 0;
            rep (i,h){
                rep (j,w){
                    if ((row >> i)&1 && (column >> j)&1 && squares[i][j]=='#') count++;
                    //cout << i << ' ' << j << ' ' << count << endl;
                }
            }
            if (count == k) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3972
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
#1_A
"""
import math

n = int(input())
m = n
ans = []
i = 2
k = math.sqrt(n)
while i <= k:
    if n%i == 0:
        n = n//i
        ans.append(i)
        i -= 1
        if n == 1:
            break
    i += 1
if len(ans) == 0 or n != 1:
    ans.append(n)
print(m,end = ": ")
for i in range(len(ans)-1):
    print(ans[i], end = " ")
print(ans[-1])
"""

#1_B
"""
m,n = map(int, input().split())
b = bin(n)[2:]
num = [m]
for i in range(len(b)-1):
    num.append(num[-1]**2%1000000007)
ans = 1
for i in range(len(b)):
    ans *= num[i] if b[len(b)-1-i] == "1" else 1
    ans %= 1000000007
print(ans)
"""

#1_C
"""
import math

l = int(input())
a = list(map(int, input().split()))
dict = {}
for n in a:
    ans = []
    i = 2
    k = math.sqrt(n)
    dic = {}
    while i <= k:
        if n%i == 0:
            n = n//i
            ans.append(i)
            i -= 1
            if n == 1:
                break
        i += 1
    if len(ans) == 0 or n != 1:
        ans.append(n)
    for i in ans:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
    for i in dic.keys():
        if i in dict:
            dict[i] = max(dict[i], dic[i])
        else:
            dict[i] = dic[i]
sum = 1
for x,y in dict.items():
    sum *= x**y
print(sum)
"""

#1_D
"""
import math

n = int(input())
m = n
ans = []
i = 2
k = math.sqrt(n)
dic = {}
while i <= k:
    if n%i == 0:
        n = n//i
        ans.append(i)
        i -= 1
        if n == 1:
            break
    i += 1
if len(ans) == 0 or n != 1:
    ans.append(n)
ans = list(set(ans))
sum = m
for i in ans:
    sum *= (1-1/i)
print(int(sum))
"""

#1_E
"""
def gcd(a,b):
    if a==0:
        return b
    return gcd(b%a,a)
a,b = LI()
g = gcd(a,b)
a//=g
b//=g
if b == 1:
    print(0,1)
    quit()
if b < 4:
    f = b-1
else:
    p = []
    x = 2
    m = b
    while x**2 <= b:
        if not m%x:
            p.append(x)
            while not m%x:
                m//=x
        x += 1
    if m != 1:p.append(m)
    f = b
    for i in p:
        f *= (1-1/i)
    f = int(f)
x_ = pow(a,f-1,b)
y_ = (1-a*x_)//b
ans = [x_,y_,abs(x_)+abs(y_)]
for i in range(-10000,10000):
    s = -b*i+x_
    t = a*i+y_
    m = abs(s)+abs(t)
    if m < ans[2]:
        ans = [s,t,m]
    elif m == ans[2] and s <= t:
        ans = [s,t,m]
print(ans[0],ans[1])
"""

#2
#2_A
"""
a,b = LI()
print(a+b)
"""

#2_B
"""
a,b = LI()
print(a-b)
"""

#2_C
"""
a,b = LI()
print(a*b)
"""

#2_D
"""
a,b = LI()
if a*b < 0:
    print(-(-a//b))
else:
    print(a//b)
"""
#2_E

a,b = LI()
print(a%b)



Measured memory_bytes: 8168
program diverta2019c
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,l
    character(10),allocatable:: s(:)
    integer(int64):: i,j, ca, cb, cab,ans

    ca=0; cb=0; cab=0; ans=0
    read*, n
    allocate(s(n))
    do i=1,n
        read*, s(i)
    end do

    do i=1,n
        do j=1,len_trim(s(i))-1
            if (s(i)(j:j+1) == 'AB') ans=ans+1
        end do
    end do
    do i=1,n    
        l = len_trim(s(i))
        if (s(i)(1:1) /= 'B' .and. s(i)(l:l) /= 'A') cycle

        if (s(i)(1:1) == 'B' .and. s(i)(l:l) == 'A') then
            cab=cab+1
        else if (s(i)(1:1) == 'B') then
            cb=cb+1
        else
            ca=ca+1
        end if
    end do
    if (ca+cb==0)then
        print'(i0)', ans+max(cab-1,0)
    else
        print'(i0)', ans+cab+min(ca,cb)
    end if


end program diverta2019c

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


using namespace std;




int main() 
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   int flag=1;
   while(a>0 && c>0)
   {
       if(flag){c=c-b;flag=0;}
       else {a=a-d;flag=1;}
   }
   if(a<=0)cout<<"No";
   else cout<<"Yes";
}


Measured memory_bytes: 3652
#include <stdio.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	if(a >= 0){
		return a % p;
	}
	else{
		return p + a % p;
	}
}

signed main(){
	int n, m, k, ans;
	scanf("%lld%lld", &n, &m);
	if(n == 1 || n - 1 > m){
		printf("%lld\n", MOD(m + 1));
		return 0;
	}
	k = MOD(m / (n - 1));
	ans = MOD(MOD(m + 1) + MOD(k * MOD(2 * (m + 1) - (k + 1) * (n - 1))));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1824
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll K; std::cin >> K;
  ll N = 50;
  std::vector<ll> a(N);
  rep(i,N) a[i] = N - 1 + K/N;
 
  rep(i,K%N) {
    a[i] += N;
    rep(j,N) a[j]--;
    a[i]++;
  }
 
  std::cout << N << std::endl;
  rep(i,50){
    std::cout << a[i] << ' ';
  }
  std::cout << std::endl;
 
  return 0;
}


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

int main() {
  char c;
  cin >> c;

  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
  return 0;
}


Measured memory_bytes: 3676
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int abs(int x){return x>0?x:-x;}
void mins(int &a,int b){if(a>b)a=b;}
void maxs(int &a,int b){if(a<b)a=b;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f;

int n;
char s[10000];
int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n-8;i++)printf("%c",s[i]);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


ll calc(ll a,ll b,ll p){//a^(b) mod p   
	if(b==0)return 1;
	ll y = calc(a,b/2,p);y=(y*y)%p;
	if(b & 1) y = (y * a) % p;
	return y;
}

vector< pair<int,int> > leaf_to_root(const vector<int> &u,const vector<int> &v,const int root){
	// return <parent,child>
	int yet = 1000000000;
	vector<int> d(u.size()+1,yet);
	vector< pair<int,int> > res;
	queue<int> Q;
	Q.push(root);
	d[root] = 0;
	vector< vector<int> > G(u.size()+1);
	for(int i=0;i<u.size();i++){
		G[u[i]].push_back(v[i]);
		G[v[i]].push_back(u[i]);
	}
	while( Q.size() ){
		int now = Q.front();
		Q.pop();
		for(auto nex:G[now]){
			if(d[nex]!=yet)continue;
			d[nex] = d[now] + 1;
			Q.push(nex);
			res.push_back( make_pair(now,nex) );
		}
	}
	reverse(res.begin(), res.end());
	return res;
}
int main(){

	ll N,M,ans = 0;
	cin >> N;
	vector<int> a(N-1),b(N-1);
	
	FOR(i,0,N-1) cin >> a[i] >> b[i];
	FOR(i,0,N-1) a[i]--,b[i]--;

	cin >> M;
	vector<int> u(M),v(M);
	FOR(i,0,M) cin >> u[i] >> v[i];
	FOR(i,0,M) v[i]--,u[i]--;
	map<pair<int,int>,int> ma;
	FOR(i,0,N-1){
		ma[{a[i],b[i]}] = i;
		ma[{b[i],a[i]}] = i;
	}
	
	auto x = leaf_to_root(a,b,0);
	vector<ll> pass(M,0);
	FOR(i,0,M){
		vector<int> cnb(N,0);
		cnb[v[i]]=1;
		cnb[u[i]]=1;
		for(auto to:x){
			int p = to.first;
			int c = to.second;
			if(cnb[c]==1){
				pass[i] += (1LL << ma[{p,c}]);
				cnb[p]+=cnb[c];
			}
			//cnb[p] += cnb[c];
			//if(i==3)cout << "ssss " << p+1 <<" " << c+1 << " " << cnb[c] << endl;
		}
	}
	FOR(s,1,1LL<<M){
		ll pass_or = 0;
		FOR(i,0,M){
			if(s&(1<<i)){
				pass_or |= pass[i];
			}
		}
		ll num = 1LL<<(N-1-bitset<64>(pass_or).count());
		if(bitset<64>(s).count() & 1){
			ans += num;
		}else{
			ans -= num;
		}
	}


	cout << (1LL<<(N-1))-ans << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

char a[1000][1000];

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

int H, W;

typedef pair<int, int>point;
typedef pair<point, int>ppl;
queue<ppl>que;

int dfs() {
	int ans = 0;
	while (!que.empty()) {
		int x = que.front().first.first;
		int y = que.front().first.second;
		int dict = que.front().second;
		ans = max(ans, dict);
		que.pop();
		rep(k, 4) {
			int nx = x + dx[k];
			int ny = y + dy[k];
			if (nx < 0 || ny < 0 || H <= nx || W <= ny)continue;
			if (a[nx][ny] == '.') {
				a[nx][ny] = '#';
				que.push(ppl(point(nx, ny), dict + 1));
			}
		}
	}
	return ans;
}


int main() {
	cin >> H >> W;
	rep(i, H)rep(j, W)cin >> a[i][j];
	rep(i, H) {
		rep(j, W) {
			if (a[i][j] == '#') {
				que.push(ppl(point(i, j), 0));
			}
		}
	}
	print(dfs());
	return 0;
}

Measured memory_bytes: 13328
n = int(input())
a = list(map(int, input().split()))
mean1 = int(sum(a)/n)
mean2 = mean1+1
ans1 = 0
ans2 = 0
for aa in a:
    ans1 += (aa-mean1)**2
    ans2 += (aa-mean2)**2
print(min(ans1, ans2))


Measured memory_bytes: 3060
moves = [(0, -1), (0, 1), (-1, 0), (1, 0)]
 
 
def search(dataset):
    min_time = 0
    mouse = 1
    gx, gy = get_start(dataset)
    for i in range(N):
        gx, gy, min_time_tmp = bfs(dataset, (gx, gy), mouse)
        mouse += 1
        min_time += min_time_tmp
    print(min_time)
 
 
def bfs(dataset, start, mouse):
    INF = 10000000
    min_time = [[INF for j in range(W)] for i in range(H)]
    min_time[start[0]][start[1]] = 0
    queue = [start]
 
    while len(queue) != 0:
        dx, dy = queue.pop(0)
        for i, j in moves:
            nx = dx + i
            ny = dy + j
            if 0 <= nx < H and 0 <= ny < W and dataset[nx][ny] != 'X' and min_time[nx][ny] == INF:
                cell = dataset[nx][ny]
            else:
                continue
            if type(cell) is int:
                if mouse == int(cell):
                    min_time[nx][ny] = min_time[dx][dy] + 1
                    return nx, ny, min_time[nx][ny]
            min_time[nx][ny] = min_time[dx][dy] + 1
            queue.append((nx, ny))
 
 
def get_start(dataset):
    for i in range(H):
        rows = dataset[i]
        for j in range(W):
            cell = rows[j]
            if cell == 'S':
                return i, j
 
 
dataset = []
while True:
    line = input().rstrip().split()
    if len(line) == 3:
        H, W, N = map(int, line)
    else:
        row = []
        for e in line[0]:
            if e.isdigit():
                row.append(int(e))
            else:
                row.append(e)
        dataset.append(row)
    if len(dataset) == H:
        search(dataset)
        break

Measured memory_bytes: 37708
#include<bits/stdc++.h>
using  namespace std;
int main(){
  string s,t;
  cin>>s;
  t=s;
  int n,c=0,d=0;
  n=s.length();
  for(int i=1;i<n;i++)
  {
     if(s[i]==s[i-1])
     {
           if(s[i-1]=='0')
           {
             s[i]='1';
           }
           else
           {
             s[i]='0';
           }
           c++;
     }
  }
  s=t;
  for(int i=n-1;i>=0;i--)
  {
    if(s[i]==s[i-1])
    {
      if(s[i]=='1')
      {
             s[i]='0';
      }
      else
      {
        s[i]='1';
      }
      d++;
    }
  }
  //cout<<c<<" "<<d<<endl;
  cout<<c<<endl;
}


Measured memory_bytes: 512
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.List (unfoldr)


main :: IO ()
main = do
  n <- readLn
  putStrLn $ if solve n then "Yes" else "No"

solve :: Int -> Bool
solve n = n `mod` s n == 0

s :: Int -> Int
s = sum . unfoldr f where
  f x
    | x == 0    = Nothing
    | otherwise = Just (x `mod` 10, x `div` 10)


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

ll N, M, K, Q, W, H, L, R, C;
string S;

double lim[41000];

void update(int s, int len, double v) {
    s *= 2;
    len *= 2;
    for (int i = s; i <= s + len; i++) {
        chmin(lim[i], v);
    }
}

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

    int T = 0;
    for (int i = 0; i < N; i++) {
        T += t[i];
    }

    for (int i = 0; i < 41000; i++) {
        lim[i] = (double)INF;
    }

    int now = 0;
    for (int i = 0; i < N; i++) {
        update(now, t[i], v[i]);
        now += t[i];
    }
    lim[0] = 0.0;
    lim[2 * T] = 0.0;

    for (int i = 0; i < 2 * T + 1; i++) {
        chmin(lim[i + 1], lim[i] + 0.5);
    }
    for (int i = 2 * T; i >= 0; i--) {
        chmin(lim[i], lim[i + 1] + 0.5);
    }

    double ans = 0.0;
    for (int i = 0; i < 2 * T; i++) {
        ans += (lim[i] + lim[i + 1]) * 0.5 / 2.0;
    }

    cout << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 512