akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct Combination {
  vector<mint> fact, ifact;
  Combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  Combination c(h+w);
  mint ans = 0;
  rep(i,h-a) ans += c(b-1+i,i)*c(h-1-i+w-1-b,h-1-i);
  cout << ans << endl;
}

Measured memory_bytes: 6328
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut it = buf.split_whitespace().map(|x| x.parse::<i64>().unwrap());
    let a = it.next().unwrap() as f64;
    print!("{}", a * 6.28318530717958623200);
}


Measured memory_bytes: 2172
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    string w; cin >> w;
    int n = 'z' - 'a' + 1;
    int cnt[n]; rep(i,n) cnt[i] = 0;
    rep(i,w.size()) ++cnt[w[i] - 'a'];

    bool flag = true;
    rep(i,n) {
        if (cnt[i] % 2 == 1) flag = false;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}






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

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

  // int型の2次元配列(3×4要素の)の宣言
  vector<int> data(N),dataB(N);
  
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  
  int count = 0;
  int s = 0;
  
  for (int i = 0; i < N; i++) {
    if (data.at(i)%2 == 0) {
      dataB.at(s) = data.at(i);
      s++;
    }
  }
  
  for (int i = 0; i < N; i++) {
    if (dataB.at(i)%3 != 0 && dataB.at(i)%5 != 0) {
      count++;
    }
  }
  
  if (count >= 1) {
    cout <<"DENIED"<<endl;
  }
  else {
    cout << "APPROVED" <<endl;
  }
  
  

}


Measured memory_bytes: 256
import numpy as np
n, m, c = map(int, input().split())
b = np.array([int(x) for x in input().split()])
a = np.array([[int(x) for x in input().split()] for y in range(n)])
ans = (np.dot(a, b) + c) > 0
print(np.count_nonzero(ans))


Measured memory_bytes: 12452
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int fp(int a, int b){
  if(!b) return 1;
  int ret = fp(a, b / 2);
  if(b & 1) return mul(mul(ret, ret), a);
  return mul(ret, ret);
}

int inv(int x){
  return fp(x, mod - 2);
}

int fac[100500];

int nCk(int n, int k){
  if(k < 0 || k > n) return 0;
  return mul(fac[n], mul(inv(fac[k]), inv(fac[n - k])));
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n, k;
  cin >> n >> k;
  vi a(n);
  for(int& x : a){
    cin >> x;
  }
  sort(all(a));
  fac[0] = 1;
  for(int i = 1; i <= n; i++){
    fac[i] = mul(fac[i - 1], i);
  }
  int res = 0;
  int cnt = 0;
  for(int i = n - 1; i >= 0; i--){
    res = add(res, mul(a[i], nCk(i, k - 1)));
    res = sub(res, mul(a[i], nCk(cnt, k - 1)));
    if(res < 0) res += mod;
    if(res >= mod) res -= mod;
    cnt++;
  }
  cout << res;
}

Measured memory_bytes: 1024
import sys

N, X, Y = map(int, sys.stdin.readline().rstrip().split())

nodes = list(range(1, N + 1))
ans = [0] * N
for i in range(1, N):
    for j in range(i + 2, N + 1):
        distance = min(abs(X - i) + abs(Y - j) + 1, j - i)
        ans[distance] += 1

for k in range(1, N):
    if k == 1:
        print(N)
    else:
        print(ans[k])


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

ll one = 1;

int main() {
    ll N; cin >> N;
    vector<ll> A(N+1);
    for (ll i = 0; i <= N; i++) cin >> A[i];
    vector<ll> max_node(N+1);
    max_node[N] = A[N];
    for (ll i = N-1; i >= 0; i--) {
        if (i >= 63) {
            max_node[i] = max_node[i+1] + A[i];
        }
        else {
            max_node[i] = min((one << i), max_node[i+1] + A[i]);
        }
    }
    ll ans = 0;
    vector<ll> real_node(N+1);
    real_node[0] = 1;
    for (ll i = 0; i < N; i++) {
        if (real_node[i] - A[i] > 0) {
            ans += real_node[i];
            real_node[i+1] = min((real_node[i] - A[i])*2, max_node[i+1]);
        }
        else {
            //cout << i << endl;
            //rep(j, N+1) cout << real_node[i] << " ";
            cout << -1 << endl;
            return 0;
        }
    }
    if (real_node[N] < A[N]) {
        cout << -1 << endl;
        return 0;
    }
    ans += A[N];
    cout << ans << endl;
}


Measured memory_bytes: 5632
import sys
def input():
    return sys.stdin.readline().rstrip('\n')


def calc(N, A):
    result = 1
    A.sort()
    if A[0] == 0:
        return 0
    for i in range(N):
        result *= A[i]
        if result > 10 ** 18:
            return -1
    return result
    

N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<str> vs;

#define all(a) a.begin(), a.end()

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

//２列配列入力
template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

//３列配列入力
template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

//２重配列入力
template <typename T>
void VV(T &n, ll size)
{
  for (ll i = 0; i < n.size(); i++)
  {
    for (ll j = 0; j < size; j++)
    {
      cin >> n[i][j];
    }
  }
}

void Main()
{
  ll n, m; cin >> n >> m;
  vll a(n), b(n), c(m), d(m); V2(a, b), V2(c, d);
  for(ll i = 0;i < n;i++)
  {
    ll flag = -1;
    ld ans;
    for(ll j = 0;j < m;j++)
    {
      if(flag == -1)
      {
        ans = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        flag++;
      }
      else
      {
        if(ans > abs(a[i] - c[j]) + abs(b[i] - d[j]))
        {
          flag = j;
          ans = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        }
      }
    }
    cout << flag + 1 << endl;
  }
  return;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()


l=[]
p="1"
q=0
for i in s:
    if i==p:
        q+=1
    else:
        l.append(q)
        q=1
        if p=="1":
            p="0"
        else:
            p="1"
l.append(q)

r=[0]
def ruiseki(a):
    for i in range(len(a)):
        r.append(r[i]+a[i])
ruiseki(l)
ans=0

if len(r)-(2*k+2)+1<=0:
    print(r[-1])
    import sys
    sys.exit()
    
for i in range(len(r)-(2*k+2)+1):
    if (i+2*k+1)%2==1:
        ans=max(ans,r[i+2*k+1]-r[i])
ans=max(ans,r[-1]-r[len(r)-(2*k+2)+1])
print(ans)

Measured memory_bytes: 7932
#include <iostream>

using namespace std;

int main() {
    int K, ways = 0;

    cin >> K;

    for(int i = 1; i <= K; i++) {

        if(i % 2 == 0) {
            for(int j = 1; j <= K; j++){

                if(j % 2 != 0) {
                    ways++;
                }
            }
        }

    }

    cout << ways << endl;

    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
s = input()
cnt = 0
d = s[0]
ss = []
for i in range(N):
  if s[i] == d:
    cnt += 1
  else:
    ss.append(cnt)
    cnt = 1
    d = s[i]
ss.append(cnt)
ss.append(0)
ss.append(0)
ss.append(0)

cs = [0]
if s[0]=="0":
  cs.append(0)
for x in ss:
  cs.append(cs[-1]+x)

ans = 0
for i in range(1,len(cs)-2*K,2):
  ans = max(ans,cs[2*K+i]-cs[i-1])
if 2*K+1>=len(cs):
  ans = cs[-1]
print(ans)


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

int main() {
    string s, t;  cin >> s >> t;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] != t[i]) ++ans;
    }
    cout << ans << endl;
}


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

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

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

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

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

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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll L, R, d;
  cin >> L >> R >> d;
  ll c = 0;
  FOR(i, L, R + 1) if (i % d == 0) c++;
  cout << c << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <stack>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

int main()
{
    stack<int> Num;
    string s;
    while (cin >> s)
    {
        if (s == "*")
        {
            int tmp1, tmp2;
            tmp1 = Num.top();
            Num.pop();
            tmp2 = Num.top();
            Num.pop();
            Num.push(tmp2 * tmp1);
        }
        else if (s == "+")
        {
            int tmp1, tmp2;
            tmp1 = Num.top();
            Num.pop();
            tmp2 = Num.top();
            Num.pop();
            Num.push(tmp2 + tmp1);
        }
        else if (s == "-")
        {
            int tmp1, tmp2;
            tmp1 = Num.top();
            Num.pop();
            tmp2 = Num.top();
            Num.pop();
            Num.push(tmp2 - tmp1);
        }
        else
        {
            Num.push(stoi(s));
        }
    }
    cout << Num.top() << endl;
    return 0;
}


Measured memory_bytes: 3236
#include <iostream>                                                                                                                                                                                         
#include <algorithm>
#include <unordered_set>
using namespace std;

const int MAX_N = 103;

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

    unordered_set<int> s(a, a+N);
    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 256
// यथा चतुर्भिः कनकं परीक्ष्यते निघर्षणच्छेदनतापताडनैः।
// तथा चतुर्भिः पुरुषः परीक्ष्यते त्यागेन शीलेन गुणेन कर्मणा॥
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv std::vector<int>
#define mapii std::map<int,int>
#define mpaci std::map<char,int>
#define umapii std::unordered_map<int,int>
#define umapci std::unordered_map<char,int>
#define seti std::set<int>
#define useti std::unordered_set<int>
#define qi std::queue<int>
#define qc std::queue<char>
#define sti std::stack<int>
#define stc std::stack<char>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end() 
#define printv(v) for(auto x: v){ cout<< x << " ";}
#define pi 3.14159265358979323846
#define setprc(x) setprecision(x)
void file(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
bool sortdesk(const pair<int,int> &a, const pair<int,int> &b){return a.ff>b.ff;}
bool sortdesv(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;}
bool sortascv(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasck(const pair<int,int> &a, const pair<int,int> &b){return a.ff<b.ff;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
int gcd(int a, int b){if (b == 0){return a;} return gcd(b, a % b);}
int cntdiv(int n){int cnt=0;for(int i=1;i<=sqrt(n);++i){if(n%i==0){if(n/i==i)++cnt;else{cnt = cnt + 2;}}}return cnt;}
lld posnegmod(lld a,lld b){//return (x%mod+mod)%mod;
long long int r = a % b;
    return r < 0 ? r + b : r;
}
// cout<<fixed<<setprecision(20)
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
// const int maxi = 1e6+10;
// vector<lld> v[maxi];
// vector<lld> h(maxi);
// vector<long long> a(maxi,0);
// lld res=0;
// void dfs(int x){
//     if(a[x]){
//         return;
//     }
//     a[x]=1;
//     int flag=1;
//     for(int i:v[x]){
//         if(h[x]<=h[i]){
//             flag=0;
//             break;
//         }
//     }
//     if(flag){
//         ++res;
//     }
// }

void test_case(){
    string s;
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;++i){
        if(s[i]=='?'){
            s[i]='D';
        }
    }
    cout<<s;
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
        test_case();
    }
}
// PD?D??P

Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i,N) cin>>A.at(i);
    B = A;
    sort(begin(A), end(A), greater<int>());
    rep(i,N) {
        if (B[i] == A[0]) {
            cout << A[1] << endl;
        } else {
            cout << A[0] << endl;
        }
    }
}


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

// #define multitest 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	int a, b;
	cin >> a >> b;
	if ((a + b) & 1)
		cout << "IMPOSSIBLE\n";
	else
		cout << (a + b) / 2;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef TIME
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int H; int W;

    do{
      H = scan.nextInt();
      W = scan.nextInt();
      if(H==0 && W==0){break;}

        //????????????????????????
      StringBuilder sb1 = new StringBuilder();//??¶??°??? ??????02468
      StringBuilder sb2 = new StringBuilder();//?\???°??? ??????13579
      for(int i=0; i<W; i++){
        if(i%2==0){sb1.append("#"); sb2.append(".");}
        else{sb1.append("."); sb2.append("#");}
      }

      for(int j=0; j<H; j++){
        if(j%2==0){System.out.println(sb1);}
        else {System.out.println(sb2);}
      }
      System.out.println("");
    } while(H!=0 || W!=0);
     
  }
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)


typedef long long ll;
typedef unsigned long long int llt;

const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

string ans ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ans += to_string(x);
     return;
}

llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}



int main()
{
  llt n, k;
  cin>>n>>k;
  llt ans = k;
  rep(i, 1, n)
  {
    ans *= (k-1);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    int sum = 0;
    rep(i, 0, n){
        a[i] = b[i] - a[i];
        sum += a[i];
    }
    bool f = true;
    if(sum < 0) f = false;
    else{
        int cnt1 = sum;
        int cnt2 = sum;
        rep(i, 0, n){
            if(a[i] > 0){
                int tmp = (a[i] + 1) / 2;
                cnt1 -= tmp;
                if(a[i] % 2) cnt2--;
            }
            if(a[i] < 0){
                cnt2 += a[i];
            }
        }
        if(cnt1 < 0 || cnt2 < 0) f = false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

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

	printf("%d\n", m * (m - 1) / 2 + n * (n - 1) / 2);
	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
using namespace std;

bool a[100001];

int main()
{
	int n, k;
	while (cin >> n >> k)
	{
		if (n == 0 && k == 0)
		{
			break;
		}

		memset(a, false, sizeof(a));
		for (int i = 0; i < k; i++)
		{
			int input;
			cin >> input;
			a[input] = true;
		}

		//i番目から始めたらいくつまで行けるかを考える
		int max = 0;
		for (int i = 1; i <= n; i++)
		{
			if (a[i] == true) //i番目のカードが無ければアウト
			{
				int j = i;
				int cnt = 0;

				int flag = false; //白紙のカードを使ったかどうか

				while (true)
				{
					if (a[j] == true) //基本的には、i = jから始めてjを1個ずつ増やしていき、j番目のカードがあるかなーって考える
					{
						cnt++;
						j++;
						if (flag == false) //後述
						{
							i++;
						}
					}
					else
					{
						if (a[0] == true && flag == false) //もしも、j番目のカードが無かったら、白紙が残っているかチェック。あればそれを消費して続行。
						{
							cnt++;
							j++;
							flag = true; //白紙を使ったかどうかはflagで管理。
						}
						else //白紙をすでに使ってしまった、もしくはそもそも引いていなかったなどして、白紙が無かった場合は終了。
						{
							break;
						}
					}
				}

				if (cnt > max)
				{
					max = cnt;
				}
				//ここまででi番目に関する処理は終わり。次に何番目からやるかだが、i番目の処理において、もしも白紙を挟んでいなかった場合、計測終了地点の次にiをセット
				//もしも白紙を挟んでいた場合は、白紙を使用した地点にiをセット
				//そしたらforのiインクリメントでいい感じになる
			}
		}
		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 1264
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int x,y;
		while(true){
			x=sc.nextInt();
			y=sc.nextInt();
			if(x==0&&y==0){
				break;
			}
			if(x>y){
				System.out.println(y+" "+x);
			}else{
				System.out.println(x+" "+y);
			}
		}
		sc.close();
	}

}



Measured memory_bytes: 36412
#include<stdio.h>
#include<math.h>
main(){
  int n,data[100000],i,j,count;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
    for(j=2;j<=sqrt(data[i]);j++)
      if(data[i]%j==0){
    data[i]=-1;
      }
  }
  for(i=0;i<n;i++)
    if(data[i]!=-1)
      count++;
  printf("%d\n",count);
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  map<char, string> mp;
  cin >> mp['a'];
  cin >> mp['b'];
  cin >> mp['c'];
  eprintf("%s,%s,%s\n", mp['a'].c_str(), mp['b'].c_str(), mp['c'].c_str());
  //reverse(ALL(mp['a']));
  //reverse(ALL(mp['b']));
  //reverse(ALL(mp['c']));
  char turn = 'a';
  while(1) {
    if(mp[turn].size() == 0) {
      printf("%c\n", toupper(turn));
      return 0;
    }
    char next_turn = mp[turn].front();
    mp[turn].erase(mp[turn].begin());
    turn = next_turn;
  }

  return 0;
}


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

int main(){
    //get N
    int N;cin>>N;
    //define queue
    queue<long>num;
    for(int i=1;i<=9;i++)
    {num.push(i);}

    int ctr=0;
    while(ctr<N-1)
    {   long frt=num.front();
        int fst=num.front()%10;
        if(fst>0){num.push(frt*10+fst-1);}
        num.push(frt*10+fst);
        if(fst<9){num.push(frt*10+fst+1);}
        num.pop();
        ctr++;
        
        
        
    }
    
    cout<<num.front()<<endl;
    
    
    
    
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int W, Q; cin >> W >> Q;
		if (!W)break;
		vector<int>vs(W);
		for (int i = 0; i < Q; ++i) {
			char c; cin >> c;
			if (c == 's') {
				int a, b; cin >> a >> b;
				a++;
				int num = 0;
				int l = 0;
				bool flag = false;
				for (int j = 0; j < W; ++j) {
					if (!vs[j]) {
						num++;
						if (num == b) {
							for (int k = l; k < l + b; ++k) {
								vs[k] = a;
							}
							cout << l << endl;
							flag = true;
							break;
						}
					}
					else {
						num = 0;
						l = j + 1;
					}
				}
				if (!flag) {
					cout << "impossible" << endl;
				}
			}
			else {
				int a; cin >> a;
				a++;
				int l = find(vs.begin(), vs.end(), a)-vs.begin();
				while (l != W&&vs[l] == a) {
					vs[l] = 0;
					l++;
				}
			}
		}
		cout << "END" << endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include<stdio.h>
void trace(int a[],int n){
int i; 
for ( i = 0;i < n; i++ ) { 
if ( i > 0 ) 
printf(" ");
printf("%d",a[i]);
}
printf("\n");		
}
void incsertionsort(int a[],int n){
	int i,j,v;
	for(i=1;i<n;i++){
	   v=a[i];
	   j=i-1;
    while(j>=0&&a[j]>v){
    	a[j+1]=a[j];
    	j--;
	}
	a[j+1]=v;
	trace(a,n);
  }
}
int main(){
	int n,i,j;
	int a[100];
	scanf("%d",&n);
    for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	trace(a,n);
	incsertionsort(a,n);
	return 0;
} 


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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  string s;
  CIN(s);
  if (s == "Sunny") {

    COUT("Cloudy");
  } else if (s == "Cloudy") {

    COUT("Rainy");
  } else
    COUT("Sunny");

  return 0;
}


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

ans = 0
for i in range(1, n):
    num_eat_candy = max(0, (a[i - 1] + a[i]) - x)
    ans += num_eat_candy
    a[i] = max(0, a[i] - num_eat_candy)
    # a[i] -= num_eat_candy
print(ans)

Measured memory_bytes: 14052
#include<iostream>
using namespace std;
int main (){

  int a=0,b=0;
  string n,c;

  cin >>n;

  c=n.substr(0,1);
    
    if( c == "o"){
    a++;
  }else{
    b++;
  }
  
    for(int i=1; i < n.size(); i++){
      
      c=n.substr(i,1);
      
      if( c != n.substr(i-1,1)){
	if( c == "o" ){
	  a++;
	}else{
	  b++;
	}
      }
    }
    
    if( a >= b ){
      cout <<"o"<<endl;
    }else{
      cout <<"x"<<endl;
    }
    
    return 0; 
}

Measured memory_bytes: 1188
n,k = map(int,input().split())
S = input()
nums = []
now = 1
cnt = 0
for i in range(n):
    if S[i] == str(now):
        cnt += 1
    else:
        nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    nums.append(cnt)

if len(nums) % 2 == 0:
    nums.append(0)

add = 2*k + 1
ans = 0
l = 0
r = 0
tmp = 0

for i in range(0,len(nums),2):
    nl = i
    nr = min(i+add,len(nums))
    
    while nl > l:
        tmp -= nums[l]
        l += 1
    while nr > r:
        tmp += nums[r]
        r += 1
    ans = max(tmp,ans)

print(ans)

Measured memory_bytes: 4092
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	string S;
	cin >> S;
	
	vector<string> str(N);
	for (int i = 0; i < N; i++)
	{
		// 文字1個ずつ格納
		str[i] = S.substr(i, 1);
	}
	
	
	int answer = 1;
	for (int i = 0; i < N - 1; i++)
	{
		if (str[i] != str[i + 1])
		{
			answer++;
		}
	}
	
	// 出力
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main()
{
    int h,n,p,temp,sum=0;
    scanf("%d%d",&h,&n);
    
    while(n--){
        scanf("%d",&p);
        
        temp=p;
        sum=sum+p;
    }
    
    if(h<=sum)printf("Yes");
    else printf("No");
    
    return 0;
}

Measured memory_bytes: 1712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(unsigned int key){
  /* your code */
  NodePointer n;

  for(n = nil->next ; n != nil ;n = n->next){
    if(n->key == key) return n; }
    return nil;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer t;
  t = nil->prev;
  nil->prev->prev->next = nil;
  nil->prev =nil->prev->prev;
  free(t);
}

void delete(int key){
  /* your code */
  NodePointer t;
  t = listSearch(key);
  if(t != nil) deleteNode(t);
  }


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* 

   your code 


  */
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 32952
void main() {
	auto ip = readAs!(int[]), D = ip[0], G = ip[1];
	int[] ps, cs;
	long res = long.max;

	foreach(i; 0..D) {
		auto ip2 = readAs!(int[]), p = ip2[0], c = ip2[1];
		ps ~= p;
		cs ~= c;
	}
	foreach(i; bitset(D)) {
		long tmp, cnt, max_index;
		foreach(j, v; i) {
			if(v) {
				tmp += (j + 1) * 100 * ps[j] + cs[j];
				cnt += ps[j];
			} else {
				max_index = j;
			}
		}
		if(tmp < G) {
			long s = 100 * (max_index + 1);
			long need = ceil((G - tmp) / s.to!double).to!long;
			if(need >= ps[max_index]) continue;
			cnt += need;
		}
		res = min(res, cnt);
	}
	res.writeln;
}

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

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

bool[][] bitset(T)(T n) if (isIntegral!T) {
	bool[][] res;
	foreach(i; 0..2^^n) {
		res ~= format(format("%%.%db", n), i).map!(i => i == '0' ? false : true).array;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 380
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<list<int>> a(n);

	for (int i = 0; i < m; i++)
	{
		int q, t, x;
		cin >> q >> t;

		bool sp = false;

		switch (q)
		{
			case 0:
				cin >> x;
				a[t].push_back(x);
				break;

			case 1:
				for (int j : a[t])
				{
					print((sp ? " " : "") << j);
					sp = true;
				}
				println("");
				break;

			case 2:
				cin >> x;
				a[x].splice(a[x].end(), move(a[t]));
				break;
		}
	}
}


Measured memory_bytes: 18720
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 1000000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    int n;cin>>n;
    V<int>a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }

    if(prev_permutation(b.begin(),b.end())){
        for(int i=0;i<n;i++){
            cout<<b[i];
            if(i<n-1)cout<<" ";
        }cout<<endl;
        //next_permutation(a.begin(),a.end());
    }

    for(int i=0;i<n;i++)
    {
        cout<<a[i];
        if(i<n-1)cout<<" ";
    }cout<<endl;
    

    if(next_permutation(a.begin(),a.end())){
        for(int i=0;i<n;i++){
            cout<<a[i];
            if(i<n-1)cout<<" ";
        }cout<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------















































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

const int N = 150000;
vector<int> g[N];
double dp[N];
double dp1[N];
double dp2[N];
double ans[N];

// †全方位木DP†はO(N)頂点からやると落とされちゃうめう

void dfs(int i, int p = -1) {
  int sz = (g[i].size() - (p != -1));
  for(int j : g[i]) if(j != p) {
    dfs(j, i);
    dp[i] += (1 + dp1[j]);
    dp1[i] += (1 + dp1[j]) / sz;
  }
}

void dfs2(int i, int p = -1) {
  ans[i] = dp[i] + (p != -1 ? dp2[i] : 0);
  for(int j : g[i]) if(j != p) {
    dp2[j] = 1 + (ans[i] - (1 + dp1[j])) / (g[i].size() - 1); /// コーナーに気をつけよう
    dfs2(j, i); ////
  }
  ans[i] /= g[i].size();
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  if(n == 1) { //
    cout << 0.0 << endl;
    return 0;
  }
  if(n == 2) { //
    cout << 1.0 << endl;
    cout << 1.0 << endl;
    return 0;
  }
  for(int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b; a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  int t = 0;
  for(int i = 0; i < n; i++) if(g[i].size() >= 2) t = i; /// はい
  dfs(t);
  dfs2(t);
  cout << fixed << setprecision(7);
  for(int i = 0; i < n; i++) cout << ans[i] << endl;
}



Measured memory_bytes: 20480
N, M = map(int, input().split())

class UnionFind():
    '''
    UnionFindでグラフの状態を管理する
    '''
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        '''
        ルートのノードを見つける
        '''
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        '''
        ノード同士を連結する
        '''
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def is_same_group(self, x, y):
        '''
        同一のルーツを持つかどうか調査する
        '''
        return self.find_root(x) == self.find_root(y)

    def count(self, x):
        return -self.root[self.find_root(x)]

uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.unite(a-1, b-1)

ans = 0
for i in range(N):
    ans = max(ans, uf.count(i))

print(ans)


Measured memory_bytes: 14624
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define arep(X, Y) for (auto(X) : Y)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl
#define printDouble(x) cout << fixed << setprecision(13) << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

using decendingQueue = priority_queue<pll, vector<pll>>; //降順

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INT_INF = 1e9;
const ll LL_INF = 1e18;
const int mod = 1000000007;

void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
  decendingQueue pq;
  rep(i, 0, N) {
    if (A[i] != B[i]) {
      pq.push(mp(B[i], i));
    }
  }

  ll cnt = 0;
  while (!pq.empty()) {
    auto i = pq.top().sc;
    pq.pop();

    ll s = B[i - 1 < 0 ? N - 1 : i - 1] + B[(i + 1) % N];
    ll t = (B[i] - A[i]) / s;
    B[i] -= s * t;

    cnt += t;

    if (t == 0) {
      print("-1");
      return;
    }

    if (B[i] > A[i]) {
      pq.push(mp(B[i], i));
    }
  }
  print(cnt);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &B[i]);
  }
  solve(N, std::move(A), std::move(B));
  return 0;
}


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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

using R = long double;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto n = load<int>();
    auto p = loadMany<R>(n);
    auto dyn = vector<vector<R>>(n+1, vector<R>(n+1, 0.0l));
    dyn[0][0] = 1.0l;
    for (auto i=0; i<n; ++i) {
        for (auto h=0; h<=i; ++h) {
            dyn[i+1][h+1] += dyn[i][h] * p[i];
            dyn[i+1][h] += dyn[i][h] * (1 - p[i]);
        }
    }
    auto answer = 0.0l;
    for (auto h=n/2+1; h<=n; ++h)
        answer += dyn[n][h];
    cout << fixed << setprecision(12) << answer << '\n';
}


Measured memory_bytes: 141312
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005


ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


/////////////////////////////////////////////////////////////////



int main(){
    int n,x;cin>>n>>x;
    if(x==1||x==2*n-1){cout<<"No"<<endl;return 0;}
    else{
        cout<<"Yes"<<endl;
        if(x==2){
            int t=3;
            rep(i,1,n-2){
                cout<<t<<endl;t++;
            }
            cout<<2<<endl<<1<<endl;
            rep(i,1,n-1){
                cout<<t<<endl;t++;
            }
        }else{
            queue<int>q;
            rep(i,3,2*n-1){
                if(i!=x&&i!=x+1)q.push(i);
            }
            rep(i,1,n-3){
                cout<<q.front()<<endl;q.pop();
            }
            cout<<1<<endl<<x<<endl<<x+1<<endl<<2<<endl;
            rep(i,1,n-2){
                cout<<q.front()<<endl;q.pop();
            }
        }
    }
    
    
    
    return 0;
}

Measured memory_bytes: 2304
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;

int mp[3][105];
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        memset(mp,0,sizeof(mp));
        for(int i=1;i<=2;i++){
            for(int j=1;j<=n;j++){
                scanf("%d",&mp[i][j]);
            }
        }
        for(int i=1;i<=2;i++){
            for(int j=1;j<=n;j++){
                mp[i][j]=max(mp[i][j]+mp[i][j-1],mp[i][j]+mp[i-1][j]);
            }
        }
        printf("%d\n",mp[2][n]);
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 500000;

int N; ll P, Q;
ll C[MAX_N];

int main(){
	scanf("%d %lld %lld", &N, &P, &Q);
	ll sum = 0LL;
	for(int i = 0; i < N; i++){
		scanf("%lld", &C[i]);
		C[i] += (ll)i * P;
		sum += C[i];
	}
	sort(C, C + N);
	ll res = sum;
	for(int i = 1; i <= N; i++){
		sum -= C[i - 1];
		sum += (Q + 2LL * (ll)(i - 1)) * P;
		res = max(res, sum);
	}
	res -= P * (ll)N * (ll)(N - 1) / 2LL;
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 6680