akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void makegraph(int x,vector<vec> &v){rep(i,x-1){int a=in(),b=in();v[a].pb(b);v[b].pb(a);}}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 255050

ll n,m,k;

vec G[N];
main(){
    n=in();
    vector<string> v(3);
    rep(i,3)cin>>v[i];
    int ans=0;
    rep(i,n){
        int temp=INF;
        rep(j,3){
            char now=v[j][i];
            int nn=0;
            rep(k,3){
                if(v[k][i]!=now)nn++;
            }
            temp=min(nn,temp);
        }
        ans+=temp;
    }
    cout<<ans;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m;
vector<tuple<ll,ll,ll>> es;
vll G[1005];
vll rG[1005];

bool reachable[1005];
bool rReachable[1005];
void dfs(ll v){
  reachable[v]=true;
  for(auto nv:G[v]){
    if(reachable[nv]) continue;
    dfs(nv);
  }
}

void rdfs(ll v){
  rReachable[v]=true;
  for(auto nv:rG[v]){
    if(rReachable[nv]) continue;
    rdfs(nv);
  }
}

ll dist[1005];

bool bellmanford(ll s){
  vector<bool> ok(n);
  rep(i,n) ok[i]=reachable[i]&&rReachable[i];
  rep(i,n) dist[i]=LINF;
  dist[s]=0;
  bool update=true;
  ll cnt=0;
  while(update){
    update=false;
    for(auto e: es){
      ll a,b,c;
      tie(a,b,c)=e;
      if(!ok[a]||!ok[b]) continue;
      if(dist[a]!=INF&&chmin(dist[b],dist[a]+c)){
        update=true;
      }
    }
    
    if(cnt>=n){
      return true;
    }
    cnt++;
  }
  return false;
}


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m;
  es.resize(m);
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--;
    es.emplace_back(a,b,-c);
    G[a].push_back(b);
    rG[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  if(bellmanford(0)){
    puts("inf");
  }else{
    cout<<-dist[n-1]<<endl;
  }
}

Measured memory_bytes: 512
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint a, b, x;
    cin >> a >> b >> x;
    lint ans = b / x;
    if(a % x == 0){
        ans -= a / x - 1;
    }
    else {
        ans -= a / x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	char a, b;
	cin >> a >> b;
	if (a == b) cout << 'H' << endl;
	else cout << 'D' << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, h, w;
    cin >> n >> h >> w;
    int ret = 0;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        if(h <= a && w <= b){
            ret++;
        }
    }
    cout << ret << endl;
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    if(S == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if(S == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

//#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
   long long n,m;
   cin>>n>>m;
   
   long long a[n];
   for(long long i=0;i<n;i++)
   cin>>a[i];
   
   bool b[n];
   for(long long i=0;i<n;i++)b[i]=true;
   
   map<pair<long long,long long>,long long>mp;
   
   while(m--)
   {
       long long a1,b1;
       cin>>a1>>b1;
       long long h;
       
       if(a1>b1)
       {
           h=a1;
           a1=b1;
           b1=h;
       }
       
       mp[{a1,b1}]++;
       
       
       {
           if(a[a1-1]==a[b1-1])
           {
              {b[a1-1]=false;b[b1-1]=false;}
           }
           else if(a[a1-1]>a[b1-1])
           b[b1-1]=false;
           else
           b[a1-1]=false;
       }
   }
   
   long long z=0;
   for(long long i=0;i<n;i++)
   {
       if(b[i])
       z++;
   }
   cout<<z;
    return 0;
}


Measured memory_bytes: 10676
#include <stdio.h>
int main()
{
    int n, i, p, max=-1000000, min=1000000;
    long long int sum=0;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &p);
        if(p<min){
            min = p;
        }
        if(p>max){
            max=p;
        }
        sum+=p;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}
 

 

Measured memory_bytes: 600
#include<iostream>

using namespace std;

//累乗
int pow(int a,int b)
{
  int i,ans;
  ans=1;
  for(i=0;i<b;i++)
  {
    ans=ans*a;
  }
  return ans;
}
  

int main() 
{
  int N,K,high,low,ans;
  cin>>N>>K;
  
  for(ans=0;ans<40;ans++)
  {
    high=pow(K,ans);//全部最大値だったとき
    low=pow(K,ans-1);
    if(N>=low&&N<high)
    {
      cout<<ans;
      goto end;
    }
  }
  end:
  ; 
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
char ch;
int ans=0; 
int main()
{
	while(scanf("%c",&ch)!=EOF&&ch!='\n'&&ch!=' ') ans=(ans+ch-'0')%9;
	if(!ans) puts("Yes");
	else puts("No"); 
	return 0;
}

Measured memory_bytes: 1568
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> c(h);
  rep(i, h) cin >> c[i];

  rep(i, h) {
    cout << c[i] << endl << c[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3624
program xor_sum_3
  implicit none
  integer :: n, i, j, k, x(100000,60) = 0
  integer(8) :: a(100000) = 0_8, ans1 = 0_8, ans2 = 0_8, tmp
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    do j = 1, 60
      if (btest(a(i),j-1)) x(i,j) = 1
    end do
  end do
  do j = 1, 60
    if (mod(sum(x(1:n,j)),2) == 1) then
      ans1 = or(ans1,lshift(1_8,j-1))
      x(1:n,j) = 0
    end if
  end do
  x(1:n,1:60) = x(1:n,60:1:-1)
  call normal_form(x(1:n,:))
  x(1:n,1:60) = x(1:n,60:1:-1)
  j = 60
  do i = 1, n
    do while (j > 0 .and. x(i,j) == 0)
      j = j-1
    end do
    if (j == 0) exit
    tmp = 0_8
    do k = 1, 60
      if (x(i,k) == 1) tmp = ibset(tmp,k-1)
    end do
    ans2 = xor(ans2,tmp)
  end do
  write(*,'(i0)') ans1+2_8*ans2
contains
  subroutine normal_form(a)
    integer, intent(inout) :: a(:,:)
    integer :: n, m, i, j, k, l
    n = size(a,1)
    m = size(a,2)
    i = 1
    do j = 1, m
      if (sum(a(i:n,j)) == 0) cycle
      if (a(i,j) == 0) then
        do k = i+1, n
          if (a(k,j) == 1) then
            do l = j, m
              a(i,l) = xor(a(i,l),a(k,l))
            end do
            exit
          end if
        end do
      end if
      do k = 1, n
        if (k == i) cycle
        if (a(k,j) == 0) cycle
        do l = j, m
          a(k,l) = xor(a(k,l),a(i,l))
        end do
      end do
      i = i+1
      if (i > n) exit
    end do
  end
end program xor_sum_3

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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i = 0;i < n;++i) {
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=1;
    for(int i = 0;i < n;++i) {
        if(__builtin_smulll_overflow(ans,a[i],&ans)){
            cout<<-1<<endl;
            return 0;
        }
    }
    if(ans>1000000000000000000)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3956
def splitting_pile_2():
	n = int(raw_input())
	nums = list(map(int, raw_input().split(" ")))
	total_sum = sum(nums)
	left_sum = nums[0]
	ans = abs(total_sum-left_sum*2)

	for i in range(1, n-1):
		left_sum = left_sum + nums[i]
		ans = min(ans, abs(total_sum-left_sum*2))
	print ans


if __name__ == "__main__":
	splitting_pile_2()

Measured memory_bytes: 18440
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    string hitachi[5] = {"hi", "hihi", "hihihi", "hihihihi", "hihihihihi"}; 
    /*int Leng = s.size();*/
    for (int i=0; i < 5; i++) {
        if (s == hitachi[i]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double x1,x2,x3,y1,y2,y3;
  double a,b,c;
  cin>>x1>>y1>>x2>>y2>>x3>>y3;
  a=hypot((x1-x2),(y1-y2));
  b=hypot((x2-x3),(y2-y3));
  c=hypot((x3-x1),(y3-y1));
  double s=(a+b+c)/2;
  double S=sqrt(s*(s-a)*(s-b)*(s-c));
  double r=2*S/(a+b+c);
  double ma=max(a,max(b,c));
  double ans=ma*r/(2*r+ma);
  printf("%.10f\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=k;i<n;i++){
        if(a[i] > a[i-k]) puts("Yes");
        else puts("No");
    }
}


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

int main(int argc, char *argv[])
{
    const string YAKI = "YAKI";
    string str;
    cin >> str;
    bool val = true;
    for(int i = 0; i < 4; ++i)
    {
        if(str[i] != YAKI[i]) val = false;
    }

    cout << (val ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n1,n2) for(int i=n1;i<n2;i++)
using namespace std;
typedef long long ll;

int div2(int n){
    int rtn=0;
    while(n%2==0){
        rtn++;
        n /= 2;
    }
    return rtn;
}

int main() {
    int n;
    int a[10010];
    cin >> n;
    int rtn = 0;
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        rtn += div2(a[i]);
    }
    
    //int res =;
    //int cnt = 0;
    cout << rtn << endl;
    /*vector<pair<int,int>> pair1(n);
     vector<pair<int,int>> pair2(n);
     REP(i,n){
     int a,b;
     cin >> a >> b;
     pair1[i] = make_pair(a,b);
     }
     REP(i,n){
     int c,d;
     cin >> c >> d;
     pair2[i] = make_pair(c,d);
     }
     
     sort(pair1.begin(),pair1.end());
     sort(pair2.begin(),pair2.end());
     REP(i, n){
     cout << pair1[i].first << pair1[i].second <<endl;
     }
     int maxn = -1;
     int cand = -1;
     REP(i,n){
     REP(j,n){
     if(pair1[i].first<pair2[j].first){
     if(pair1[i].second>maxn){
     cand = i;
     }
     }
     }
     }
     /*REP(i, n){
     cout << pairs[i].first << pairs[i].second <<endl;
     }
     /*int n;
     int res = 100000;
     cin >> n;
     //vector<int> x(n);
     REP2(i,1,n/2+1){
     res = min(res,psum(i)+psum(n-i));
     if(psum(i)+psum(n-i)==1){
     cout << "i:" << i <<endl;
     }
     }
     cout << res << endl;*/
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  ll ans=0LL;
  if(n<=k){
    cout << 0 << endl;
    return 0;
  }
  rep(i,n-k){
    ans += h[i];
  }
  cout << ans << endl;
}

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

using namespace std;

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


int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> v(m, 0);
  for (int i = 0; i < m; i++){
    cin >> v[i];
  }

  int costA = 0;
  int costB = 0;
  for (int i = 0; i <= x; i++){
    for(int j : v){
      if (i == j) {
        costA++;
        break;
      }
    }
  }

  for (int i = x; i <= n; i++){
    for(int j : v){
      if (i == j) {
        costB++;
        break;
      }
    }
  }

  cout << min(costA, costB) << endl;


  return 0;
}


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

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

    vector<int>p(n);
    vector<int>s(n);
    vector<int>a(n);

    rep(i,n)cin>>p.at(i);
    rep(i,n)cin>>s.at(i);
    rep(i,n)a.at(i)=i+1;
    
    map<vector<int>, int> mp;
    do {
    mp[a] = mp.size();
     }while (next_permutation(a.begin(),a.end()));
 
  int ans = abs(mp[p] - mp[s]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);

const int MAX = 2000010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
signed main(){
	COMinit();
	cout << fixed << setprecision(14);
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int com[51][51]{};
    com[0][0] = 1;
    for (int i = 1; i < 51; ++i) {
        for (int j = 0; j <= i; ++j) {
            com[i][j] += com[i-1][j];
            if (j > 0) com[i][j] += com[i-1][j-1];        
        }
    }

	int N, A, B;
	cin >> N >> A >> B;
	vector<int> vec(N);
	rep(i,N) cin >> vec[i];
	sort(vec.begin(), vec.end(), greater<int>());
	double ans = 0;
	rep(i,A) ans += vec[i];
	ans /= A;
	cout << ans << endl;
	if(vec[0] != vec[A-1]){
		int cnt0 = 0;
		int cnt1 = 0;
		rep(i,N){
			if(vec[i] == vec[A-1]){
				cnt0++;
				if(i <= A-1){
					cnt1++;
				}
			}
		}
		cout << com[cnt0][cnt1] << endl;
	}
	else{
		int cnt0 = 0;
		rep(i,N){
			if(vec[0] == vec[i]) cnt0++;
		}
		int ans = 0;
		for(int i=A;i<=B;i++){
			ans += com[cnt0][i];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 47104
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll k;
    cin>>k;
    vl v;
    for(int i=1;i<=9;i++)
        v.pb(i);
    while(v.size()<100023)
    {
        ll c=v.back();
        c/=10;
        auto it=upper_bound(all(v),c);
        c=(*it);
        ll d=c%10;
        if(d>=1)
            v.pb(c*10+d-1);
        v.pb(c*10+d);
        if(d<9)
            v.pb(c*10+d+1);
    }
    cout<<v[k-1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 13176
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    string s;
    cin >> s;
    set<char> st;
    for(const auto &it: s) {
        st.insert(it);
    }
    if(st.count('W') * st.count('E') == 0 && (st.count('W') + st.count('E') != 0)) {
        cout << "No" << endl;
    } else if (st.count('N') * st.count('S') == 0 && (st.count('N') + st.count('S') != 0)){
        cout << "No" << endl;
    } else cout << "Yes" << endl;

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
dice = 1 / n
ans = []
for i in range(1,n+1):
    if i >= k:
        ans.append(dice)
    else:
        k1 = i
        count = 0
        while k > k1:
            k1 = k1 * 2
            count += 1
        ans.append(dice * (0.5 ** count))
print(sum(ans))

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

using ll = long long;

void solve(long long N){
    ll ans = 0;
    for(int i = 1;i <= N;i++){
        ll cnt = (N - 1) / i;
        ans += cnt;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3760
N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 10**18
for i in range(1<<N):
    cnt = 0
    tot = 0
    now = 0
    for j in range(N):
        if A[j] > now:
            cnt += 1
            now = A[j]
        elif i&(1<<j):
            cnt += 1
            tot += now-A[j]+1
            now += 1
    if cnt >= K:
        ans = min(ans, tot)
print(ans)


Measured memory_bytes: 9144
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
static const double EPS = 1e-6;

struct P
{
  double x, y, z;
  P() {}
  P(double a, double b, double c) : x(a), y(b), z(c) {}
  P operator+(const P& that) const { return P(x + that.x, y + that.y, z + that.z); }
  P operator-(const P& that) const { return P(x - that.x, y - that.y, z - that.z); }
  P& operator*=(double a) { x *= a; y *= a; z *= a; return *this; }
  P operator*(double a) const { P p(*this); p *= a; return p; }
  P& operator/=(double a) { x /= a; y /= a; z /= a; return *this; }
  P operator/(double a) const { P p(*this); p /= a; return p; }

  double abs() const { return sqrt(x*x + y*y + z*z); }
  double dot(const P& that) const { return x*that.x + y*that.y + z*that.z; }
  P cross(const P& that) const
  {
    return P(
        y*that.z - that.y*z,
        z*that.x - that.z*x,
        x*that.y - that.x*y);
  }
};

struct line
{
  P a, b;
  line(const P& x, const P& y) : a(x), b(y) {}
};

struct sphere
{
  P o;
  double r;
  sphere(const P& p, double x) : o(p), r(x) {}

  bool intersects(const line& ln) const
  {
    const P ab = ln.b - ln.a;
    const P ao = o - ln.a;
    if (ab.dot(ao) < 0) {
      return false;
    }
    const double h = ab.cross(ao).abs() / ab.abs();
    return h < r;
  }

  P intersection(const line& ln) const
  {
    const P ab = ln.b - ln.a;
    const P ao = o - ln.a;
    const double h = ab.cross(ao).abs() / ab.abs();
    const double d = ao.abs();
    const double l = sqrt(d*d - h*h);
    double left = 0.0, right = l/ab.abs();
    for (int i = 0; i < 100; i++) {
      const double mid = (left + right)/2.0;
      const P ap = ab*mid;
      const double t = (ap - ao).abs();
      if (t < r) {
        right = mid;
      } else {
        left = mid;
      }
    }
    return ln.a + ab*((left + right)/2.0);
  }

  line reflect(const line& ln) const
  {
    const P q = intersection(ln);
    const P qa = ln.a - q;
    P qn = q - o;
    qn /= qn.abs();
    const P x = qn.cross(qa);
    if (x.abs() < EPS) {
      return line(q, ln.a);
    }
    P qm = qn.cross(x);
    qm /= qm.abs();
    const double t = qn.dot(qa)/(qn.abs()*qa.abs());
    const P qr = qm*sqrt(1-t*t) + qn*t;
    return line(q, q + qr);
  }
};

int main()
{
  int N;
  while (scanf("%d", &N) != EOF && N != 0) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    line ln(P(0, 0, 0), P(u, v, w));
    vector<sphere> ss;
    for (int i = 0; i < N; i++) {
      int x, y, z, r;
      scanf("%d %d %d %d", &x, &y, &z, &r);
      ss.push_back(sphere(P(x, y, z), r));
    }

    P ans;
    for (;;) {
      map<double,int> m;
      for (int i = 0; i < N; i++) {
        if (ss[i].intersects(ln)) {
          const P p = ss[i].intersection(ln);
          m.insert(make_pair((p - ln.a).abs(), i));
        }
      }
      if (m.empty()) {
        break;
      }
      const sphere& s = ss[m.begin()->second];
      ln = s.reflect(ln);
      ans = ln.a;
    }
    printf("%.4f %.4f %.4f\n", ans.x, ans.y, ans.z);
  }
  return 0;
}

Measured memory_bytes: 0
b = False
while True:
    n = int(input())
    if n == 0:
        break
    dataset = []
    if b:
        print()
    b = True
    for _ in range(n):
        name, w, l, d = input().split()
        dataset.append((name, 3*int(w) + int(d), n-len(dataset)))
    for name, score, _ in sorted(dataset, key=lambda x: (x[1], x[2]))[::-1]:
        print(name + "," + str(score))

Measured memory_bytes: 7688
#include<bits/stdc++.h>
using namespace std;
int main(){
  for (;;){
    int m, f, r; cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) return 0;
    int n = m + f;
    if (m == -1 || f == -1) cout << "F" << endl;
    else if (n >= 80) cout << "A" << endl;
    else if (n >= 65) cout << "B" << endl;
    else if (n >= 50) cout << "C" << endl;
    else if (n <  30) cout << "F" << endl;
    else if (r >= 50) cout << "C" << endl;
    else if (n >= 30) cout << "D" << endl;
  }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

struct obj{ int a,b,c; };

signed main(){
	int h,w;
	string f[610];
	cin >> h >> w;
	for(int i = 0;i < h;i++) cin >> f[i];
	vector<obj> vec;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if((i && f[i][j] != f[i - 1][j]) || (!i && f[i][j] == '#')){
				vec.push_back({h - i,j + 1,1});
				vec.push_back({h - i,j,-1});
			}
			if((j != w - 1 && f[i][j] != f[i][j + 1]) || (j == w - 1 && f[i][j] == '#')){
				vec.push_back({h - i - 1,j + 1,1});
				vec.push_back({h - i,j + 1,-1});
			}
		}
	}
	sort(all(vec),[](const obj &x,const obj &y){
		return (x.a * y.b != x.b * y.a) ? (x.a * y.b < x.b * y.a) : (x.c < y.c);
	});
	int sum = 0,ma = 0;
	for(const auto &v : vec){
		sum += v.c;
		chmax(ma,(sum + 3) / 2);
	}
	cout << ma << endl;
}


Measured memory_bytes: 28088
#include <stdio.h>
const int MAX_V = 999999;

int main() {
	int i, k, n;
	int prime[MAX_V + 1], cnt[MAX_V + 1];
	for( i = 2; i <= MAX_V; i++) {
		 prime[i] = 1;
	}
	for( i = 2; i * i <= MAX_V; i++) {
		if(prime[i]) {
			for( k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	cnt[0] = 0;
	for( i = 0; i <= MAX_V; i++) {
		cnt[i + 1] = cnt[i] + prime[i + 1];
	}
	while(scanf("%d", &n) != EOF) {
		printf("%d\n", cnt[n]);
	}
	return 0;
}

Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__",", __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  string s;
  cin>>s;
  vector<int> m(26,0);

  int n = s.size();
  int ans = n;

  rep(i,26){
    int j = 0;
    int t = 0;
    while(j<n){
      int c = 0;
      while(j<n && s[j]!=i+'a'){j++;c++;}
      t = max(t,c);
      j++;
    }
    ans = min(ans, t);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define ll long long
using namespace std;
char s[200005];
int main(){
    int n,i,ans=0;
    int cntw=0,cntr=0;
    scanf("%d%s",&n,s);
    for(i=0;i<n;i++){
        if(s[i]=='W') cntw++;
        else cntr++;
    }
    for(i=0;i<cntr;i++){
        if(s[i]!='R') ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1868
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int most_min(vi &a,int x, int y) {
    int answer;
    answer=min(a.at(x),a.at(y));
    for(int i=x+1; i<=y; i++) {
        answer=min(answer,a.at(i));
    }
    return answer;
}

int most_max(vi &a, int x,int y) {
    int answer;
    answer=max(a.at(x),a.at(y));
    for(int i=x+1; i<=y; i++) {
        answer=max(answer,a.at(i));
    }
    return answer;
}

int main() {
    int N,M;
    cin>>N>>M;
    vi L(M),R(M);
    rep(i,M) {
        int l,r;
        cin>>l>>r;
        L.at(i)=l;
        R.at(i)=r;
    }
    int a,b;
    a=most_max(L,0,M-1);
    b=most_min(R,0,M-1);
    int ans=b-a+1;
    if(ans>=0) cout<<ans<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9)
      {cout<<"hon";
      }
    else if(n==0 || n==1 || n==6 || n==8)
      {cout<<"pon";
      }
    else
      {cout<<"bon";
      }

    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    int n; cin >> n;
    ll ans = 0;
    ll a,b;
    a = 1,b = 1;
    for(int i = 0; i < n; i++){
        ll s,t;
        cin >> s >> t;
        ll x = max((a+(s-1))/s,(b+(t-1))/t);
        a = x * s;
        b = x * t;
    }
    cout << a+b;
}

Measured memory_bytes: 256
def main():
    alpha = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    n = int(input())
    s = input()
    output = ''
    for c in s:
        index = alpha.index(c) + n
        index = index % 26
        output += alpha[index]
    print(output)


if __name__ == "__main__":
    main()


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s, t;
	cin >> s >> t;
	if (t.substr(0, s.size()) == s) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define mod 1000000007

lli a[100005][3];
lli n;
lli dp[100005][3];

lli func(lli in,lli c){
    if(in==n) return 0;
    if(dp[in][c]!=-1) return dp[in][c];

    return dp[in][c] = a[in][c] + max(func(in+1,(c+1)%3) , func(in+1,(c+2)%3));
}

int main(){
    cin>>n;
    lli i,j,l;
    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    lli ans=0;
    ans=max(func(0,0) , max(func(0,1) , func(0,2)));
    cout<<ans<<endl;
    return 0;
}


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

int main() {
	int N; cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++){
    	cin >> vec.at(i);
    }
  	int n = 0;
  	int counter = 0;
  	while (n != 1){
    	n = vec.at(n) - 1;
    	counter += 1;
      	if (counter > N){
        	break;
        }
    }
  	if (counter > N){
    	cout << -1 << endl;
    }
  	else{
    	cout << counter << endl;
    }
}


Measured memory_bytes: 3772
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int X = scanner.nextInt();
		int Y = scanner.nextInt();
		if (X % Y == 0) {
			System.out.println(-1);
		} else {
			System.out.println(X);
		}
	}
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
using ll = long long;
using namespace std;
using P = pair<int, int>;

/*
int main(){
    string T;
    ll PD_count = 0;
    ll D_count = 0;
    cin >> T;
    rep(i, T.size()) if(T.at(i) == '?') T.at(i) = 'D';
    rep(i, T.size()) if(T.at(i) == 'D') D_count++;
    rep(i, T.size()-1) if(T.at(i) == 'P' && T.at(i) == 'D') PD_count++;
    cout << D_count + PD_count << endl;
}
*/
int main(){
    string T;
    ll PD_count = 0;
    ll D_count = 0;
    cin >> T;
    rep(i, T.size()){
        if(T.at(i) == '?') cout << 'D';
        else cout << T.at(i);
    }
  cout << endl;
}


Measured memory_bytes: 3716
import Control.Monad
import Data.List

main = do
    t <- forM [1 .. 5] $ \i -> read <$> getLine
    putStrLn $ show $ solve t

solve :: [Int] -> Int
solve t = sum t + sum (take 4 $ sort $ map f t)
  where
    f x = (130 - x) `mod` 10


Measured memory_bytes: 508
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n;
vector<int> G[max_n];
int sz[max_n];
int dp[max_n];
int fac[max_n],inv[max_n];
void link(int u,int v){
    dp[u]=Mul(dp[u],inv[sz[u]-1]);
    sz[u]+=sz[v];
    dp[u]=Mul(dp[u],fac[sz[u]-1]);
    dp[u]=Mul(dp[u],Mul(dp[v],inv[sz[v]]));
}
void cut(int u,int v){
    dp[u]=Mul(dp[u],inv[sz[u]-1]);
    sz[u]-=sz[v];
    dp[u]=Mul(dp[u],fac[sz[u]-1]);
    dp[u]=Mul(dp[u],Pow(Mul(dp[v],inv[sz[v]]),mod-2));
}
void dfs(int u,int fa){
    dp[u]=1;sz[u]=1;
    for(auto v:G[u]){
        if(v==fa)continue;
        dfs(v,u);
        link(u,v);
    }
}
int ans[max_n];
void dfs2(int u,int fa){
    ans[u]=dp[u];
    for(auto v:G[u]){
        if(v==fa)continue;
        cut(u,v);
        link(v,u);
        dfs2(v,u);
        cut(v,u);
        link(u,v);
    }
}
int main(){
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n;i++)fac[i]=Mul(fac[i-1],i);
    inv[n]=Pow(fac[n],mod-2);
    for(int i=n-1;i>=0;i--)inv[i]=Mul(inv[i+1],i+1);
    for(int i=1;i<n;i++){
        int u,v;scanf("%d%d",&u,&v);
        G[u].push_back(v),G[v].push_back(u);
    }
    dfs(1,0);
    dfs2(1,0);
    for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
    return 0;
}

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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(int n, int m) {return (n / gcd(n, m) * m);}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int a, b, x;
  cin >> a >> b >> x;

  if(a + b < x || a > x) puts("NO");
  else puts("YES");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  ll ans = 0;
  ll mx = a.front();
  rep2(i, 1, n){
    if(mx <= a.at(i)){
      mx = a.at(i);
    }else{
      ll add = mx - a.at(i);
      ans += add;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4048
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

std::vector<int> find_all(const std::string str, const std::string subStr) {
  std::vector<int> result;

  int subStrSize = subStr.size();
  int pos = str.find(subStr);

  while (pos != std::string::npos) {
    result.push_back(pos);
    pos = str.find(subStr, pos + subStrSize);
  }

  return result;
}

int main() {
  int N;
  cin >> N;
  vector<string> s_list;
  vector<int> end_a_list;
  vector<int> start_b_list;
  vector<int> both_list;
  int count = 0;
  rep(i, N) {
    string s;
    cin >> s;
    count += find_all(s, "AB").size();
    s_list.push_back(s);
    bool start_b = s[0] == 'B';
    bool end_a = s[s.size() - 1] == 'A';
    if (start_b && end_a) {
      both_list.push_back(i);
    } else if (start_b) {
      start_b_list.push_back(i);
    } else if (end_a) {
      end_a_list.push_back(i);
    }
  }

  if (both_list.size() == 0) {
    count += min(end_a_list.size(), start_b_list.size());
  } else {
    if (end_a_list.size() + start_b_list.size() == 0) {
      count += both_list.size() - 1;
    } else {
      count += both_list.size() + min(end_a_list.size(), start_b_list.size());
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1024
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	double d,t,s;
	cin>>d>>t>>s;
	double time=d/s;
	if(time<=t)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



Measured memory_bytes: 3728
#include <iostream>

using namespace std;
int a,b;
int main()
{
    cin >> a >> b;
    if(a >= 13){
        cout << b;
    }
        else if(a >= 6 && 12 >= a){
            cout << b/2
            ;
        }
        else {
            cout << "0";
        }
    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 A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int X = scan.nextInt();
		int Y = scan.nextInt();
		
		
		
		int cheapest_price = A*X + Y*B;
		
		if(A+B<=2*C){
			System.out.println(cheapest_price);
		}
		else{
			for (int i = 0 ; i<=2*X || i<=2*Y ;i=i+2){
				
				if(i>2*X){
					if (cheapest_price > (Y-i/2)*B+ C*i){
						cheapest_price = (Y-i/2)*B+ C*i;
					}
				}
				else if(i>2*Y){
					if (cheapest_price > (X-i/2)*A+ C*i){
						cheapest_price = (X-i/2)*A+ C*i;
					}
				}
				else{ 
					if (cheapest_price > (X-i/2)*A+(Y-i/2)*B+ C*i){
						cheapest_price = (X-i/2)*A+(Y-i/2)*B+ C*i;
					}
				}
				
			}
			System.out.println(cheapest_price);
		}
	}
}

Measured memory_bytes: 25300
while True:
    n=int(input())
    if n==0:break
    card_t=sorted([int(input())for i in range(n)])
    card_h=[]
    for i in range(2*n):
        if i+1 not in card_t:card_h.append(i+1)
    ba=0
    while True:
        for i in range(len(card_t)):
            if card_t[i]>ba:
                ba=card_t.pop(i)
                break
            if i==len(card_t)-1:ba=0
        if len(card_t)==0:break
        for i in range(len(card_h)):
            if card_h[i]>ba:
                ba=card_h.pop(i)
                break
            if i==len(card_h)-1:ba=0
        if len(card_h)==0:break
    print(len(card_h))
    print(len(card_t))

Measured memory_bytes: 7656
#include<bits/stdc++.h>
using namespace std;
static const int MAX = 10000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<20);
int n;
vector<pair<int,int> >adj[MAX];


void dijkstra(){
    priority_queue<pair<int,int> >PQ;
    int color[MAX],d[MAX];
    
    for (int i = 0; i < n; i++)
    {
        color[i] = WHITE;
        d[i] = INFTY;
        
    }
    d[0] = 0;color[0] = GRAY;
    PQ.push(make_pair(0,0));

    while (!PQ.empty())
    {
        pair<int,int> f = PQ.top();PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        //最小値を取り出し、それが最短でなければ無視
        if(d[u]<f.first*(-1))continue;
        
        for (int j = 0; j < adj[u].size(); j++)
        {
            int v = adj[u][j].first;
            if(color[v]==BLACK)continue;
            
            if(d[v]>d[u]+adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v] = GRAY;
            }
            
        }
    }
    for (int  i = 0; i < n; i++)
        {
            cout << i << " " << (d[i]==INFTY?-1:d[i]) << endl;
        }  
}


int main(){
    cin >> n;
    int u,k,c,v;
    
    
    
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v>> c;
           adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    return 0;
    
}


Measured memory_bytes: 8080