akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
#define ld long double
vector<int> v;
ld dp[302][302][302],n;
ld solve(int i, int j, int k){
  if(i<0 or j<0 or k<0)return 0;
  if(j==0 and i==0 and k==0)return 0;
  //cout<<"nani\n";
  if(dp[i][j][k]>=0)return dp[i][j][k];
  ld ans=0;
  int rem=(i+j+k);
  ans=n+i*solve(i-1,j,k)+j*solve(i+1,j-1,k)+k*solve(i,j+1,k-1);
  ans/=(ld)(rem);
  dp[i][j][k]=ans;
  return ans;
}
int32_t main(){
   cin>>n;
   int oc=0,tc=0,thc=0;
   rep(i,0,n){
     int t; cin>>t;
     v.pub(t);
     oc+=(t==1);
     tc+=(t==2);
     thc+=(t==3);
   }
   rep(i,0,n+1)rep(j,0,n+1)rep(k,0,n+1)dp[i][j][k]=-1;
   ld ans=solve(oc,tc,thc);
   cout<<fixed<<setprecision(11)<<ans<<"\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


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

int main() {
   int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
   if(e-a<=k){
     cout << "Yay!" <<endl;
   }
   else{
     cout << ":(" <<endl;
   }
}


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

bool is_month(string s) { return "01" <= s && s <= "12"; }

bool is_year(string s) { return "00" <= s && s <= "99"; }

int main() {
    string S;
    cin >> S;
    string s1 = S.substr(0, 2);
    string s2 = S.substr(2, 2);
    if (is_month(s1) && is_year(s2) && is_year(s1) && is_month(s2))
        cout << "AMBIGUOUS" << endl;
    else if (is_month(s1) && is_year(s2))
        cout << "MMYY" << endl;
    else if (is_year(s1) && is_month(s2))
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a=0, b=0;
    REP(i,0,s.size())
    {
        if(s[i] == '0') a++;
        else b++;
    }
    cout << 2*min(a,b) << endl;
    return 0;
}


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

int main() {
	string str1="JOI",str2="IOI";
	while(1){
		int count1=0,count2=0;
		string t;
		cin>>t;
		if(t.size()==0)
			break;
		for(int i=0; i<t.size(); i++){
			if(t[i]==str1[0]){
				if(t[i+1]==str1[1]){
					if(t[i+2]==str1[2])
						count1++;
				}
						
			}
			if(t[i]==str2[0]){
				if(t[i+1]==str2[1]){
					if(t[i+2]==str2[2])
						count2++;
				}
						
			}
		}
		cout<<count1<<endl<<count2<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

int n,m,k,arr[N];

void solve()
{
    cin>>n>>k;
    forn(i,1,n)cin>>arr[i];
    if(n<=k)
    {
    	cout<<0;
    	die;
    }
    
    int ans = 0;
    sort(alln(arr));
    n-=k;
    forn(i,1,n)
    {
    	ans+=arr[i];
    }
    cout<<ans;
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}

//       clang++ c.cpp ; ./a.out < a.txt ;  

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
vector<int> G[100000];
int n;
int a[100006];
int depth[100006];
vector<int> P;

void saiki(int p)
{
	int t=G[p].size();
	if(t==0)
	{
		depth[p]=0;
		return;
	}
	rep(i,t)
	{
		saiki(G[p][i]);
	}
	int ts=0;
	P.clear();
	rep(i,t)P.push_back(depth[G[p][i]]);
	sort(all(P));
	int kk=1;
	for(int tt=t-1;tt>=0;tt--)
	{
		ts=max(P[tt]+kk,ts);
		kk++;
	}
	depth[p]=ts;
	return;
}
int main()
{
	cin>>n;
	rep(i,n-1)cin>>a[i];
	rep(i,n-1)
	{
		G[a[i]-1].push_back(i+1);
	}
	saiki(0);
	cout<<depth[0]<<endl;
	return 0;
}

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

int main(){
  long long int tmp=0,tma,tmb;
  int a,b,c,x,y,lm;
  cin >> a >> b >> c >> x >> y;
  lm = max(x,y);
  long long int ta = x * a + y * b;
  for(int i=2;i<=lm*2;i=i+2){
    x--;
    y--;
    tmp = c * i;
    if(x>0)
      tma = (x)*a;
    else
      tma = 0;
    if(y>0)
      tmb = (y)*b;
    else
      tmb = 0;
    if(ta>tmp+tma+tmb)
      ta = tmp+tma+tmb;
  }
  cout << ta << endl;
}

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

using namespace std;

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

	double total = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			double xx = x[i] - x[j];
			double yy = y[i] - y[j];
			total += sqrt(xx * xx + yy * yy);
		}
	}

	printf("%.10f\n", total * 2 / N);
	return 0;
}


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

int main() {
    string a;
    cin >> a;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if(a[i] == '1') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
signed main() {
    int N, M;
    cin >> N >> M;
 
    vector<int> a(M), b(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i]>> c[i];
        --a[i], --b[i];
    }
 
    const int inf = 1e18;
    vector<int> dist(N, -1e18);
    dist[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (dist[a[j]] == -inf) continue;
            if (dist[a[j]] + c[j] <= dist[b[j]]) continue;
            dist[b[j]] = dist[a[j]] + c[j];
            if (i == N - 1 && b[j] == N - 1) return cout << "inf" << endl, 0;
        }
    }
    cout << dist[N - 1] << endl;
 
    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
T, A = map(int,input().split())
lst = input().split()

delta_temp_min = 100000000000
ans = 0

for i in range(N):
    temp_i = T-int(lst[i])*0.006
    delta_temp = math.sqrt((A-temp_i)**2)
    if delta_temp_min > delta_temp:
        ans = i
        delta_temp_min = delta_temp

print(str(ans+1))


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("CSS");
            WillReturn.Add("CSR");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("SSR");
            WillReturn.Add("SSR");
            //3
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("RRR");
            WillReturn.Add("SSS");
            //0
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        string S = InputList[0];
        string T = InputList[1];

        int Answer = 0;
        for (int I = 0; I <= S.Length - 1; I++) {
            if (S[I] == T[I]) {
                Answer++;
            }
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 11220
#include<stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);
 
  int max = 0;
  for (int i = 0; i <= n; i++) {
      if (i * i > n) {
        break;
      }
      max = i * i;
  }
  printf("%d\n", max);
  
  return 0;
}


Measured memory_bytes: 128
a=input()
b=input()
if len(a)>len(b):
  print("GREATER")
elif len(a)<len(b):
  print("LESS")
else:
  i=0
  f=0
  while len(a)>i:
    if int(a[i])>int(b[i]):
      f=1
      break
    elif int(a[i])<int(b[i]):
      f=2
      break
    i+=1
  if f==0:
    print("EQUAL")
  elif f==1:
    print("GREATER")
  else:
    print("LESS")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            int id,m,s;
            std::map<int, int> map;
            for (int i=0;i<n;i++) {
                cin>>id;
                int sum=0;
                for (int j=0;j<4;j++) {
                    cin>>m>>s;
                    sum+=60*m+s;
                }
                map.insert(make_pair(sum,id));
            }
            auto itr=map.begin();
            for (int k=0;k<n;k++) {
                if (k==0||k==1||k==n-2) {
                    cout<<(itr->second)<<endl;
                    itr=next(itr,1);
                } else {
                    itr=next(itr,1);
                }
            }
        }
    }
}


Measured memory_bytes: 3336
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef int LL;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline int read(){
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
int n,m;
map<int,int>M;
int main(){
    n=read();
    for(int i=1;i<=n;i++)M[read()]++;
    m=read();
    for(int i=1;i<=m;i++){
    	int zs=read();
    	if(M[zs])M[zs]--; else{
    		puts("NO"); return 0;
		}
	}
	puts("YES");
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int n,k;cin>>n>>k;
    vector<ll>a(n);ll sum=0;
    REP(i,n){cin>>a[i];sum+=a[i];}
    sort(ALL(a));
    set<ll>key;
    for(int i=1;i*i<=sum;i++)if(sum%i==0){key.insert(i);key.insert(sum/i);}
    ll ans=0;
    for(ll itr:key)
    {
        vector<ll>r(n);ll suml=0;
        REP(i,n){r[i]=a[i]%itr;suml+=itr-r[i];}
        sort(ALL(r));
        ll sumr=0;
        ll summin=1e18;
        REP(i,n)
        {
            sumr+=r[i];
            suml-=itr-r[i];
            summin=min(summin,max(suml,sumr));
        }
        if(summin<=k)ans=max(ans,itr);
    }
    cout<<ans<<endl;
}

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

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    vector<int> prime;
    prime.push_back(2);
    for (int i = 3; i < 100010; i = i+2) {
        bool flag = true;
        for (int j = 0; j < prime.size(); ++j) {
            if(i % prime[j] == 0){
                flag = false;
                break;
            }
        }
        if(flag) prime.push_back(i);
    }

    vector<int> v;
    for (int i = 3; i < 100010; i = i+2) {
        if(binary_search(prime.begin(), prime.end(), i) && binary_search(prime.begin(), prime.end(), (i+1)/2)){
            v.push_back(i);
        }
    }

    int q;
    cin >> q;
    int l, r;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r;
        cout << upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l) << endl;
    }
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main()
{
    char a,b,c,w,r,e;
    cin >> a >> b;
    if(a<b)
    {
        cout << "<";
    }
    else if(a>b)
    {
        cout << ">";
    }
    else
        cout << "=";
        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s) a--;
    else b--;
    printf("%d %d\n",a,b);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    deque<ll> b;
    rep(i,n){
        if(i&1)b.emplace_front(a[i]);
        else b.emplace_back(a[i]);
    }
    if(a.size() & 1)reverse(all(b));
    rep(i,n){
        ll t = b.front();b.pop_front();
        cout << t << " ";
    }
    cout << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int n;
    int ans = 0;
    string s;
    cin >> n >> s;
    for (int i=0; i<n; i++) {
        string s1,s2;
        s1 = s.substr(0, i);
        s2 = s.substr(i, s.size() - i);

        map<char,bool> m1,m2;

        for (int j=0; j<s1.size(); j++) m1[s1[j]] =true;
        for (int j=0; j<s2.size(); j++) m2[s2[j]] =true;

        int cnt = 0;
        for (int j=0; j<n; j++) {
            char c = 'a' + j;
            if (m1[c] && m2[c]) cnt++;
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();
        if(d <= t*s)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}

Measured memory_bytes: 35592
l,r = map(int,input().split())

if 2018 <= r-l:
  ans = 0
elif r-l <= 2017:
  r_mod = r%2019
  l_mod = l%2019
  ans = 2019
  
  if l_mod < r_mod:
    for i in range(r_mod-l_mod):
      for j in range(1,r_mod-l_mod-i+1):
        temp = (l_mod+i)*(l_mod+i+j)%2019
        
        if temp < ans:
          ans = temp
      
      
  elif r_mod < l_mod:
    ans = 0
    
print(ans)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;

int gcd(int x,int y){
  return y?gcd(y,x%y):x;
}
int main(){
  //freopen("aa.in","r",stdin);
  int n,m;
  string s,t;
  cin>>n>>m;
  cin>>s>>t;
  int d=gcd(n,m);
  int step=m/d;
  int step2=n/d;
  for(int i=0;i<n;i++){
    long long now=1+1LL*i*step;
    // printf("now %d %lld\n",i,now);
    if((now-1)%step2==0 && t[(now-1)/step2]!=s[i]){
      // printf("comp %d %lld %d\n",i,now,(now-1)/step2);
      return puts("-1"),0;
    }
  }
  printf("%lld\n",1LL*n*m/d);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int p[100005],n,k,q,tmp;
int32_t main(){
	cin>>n>>k>>q;
	for(int i=1;i<=q;i++){
		cin>>tmp;
		p[tmp]++;
	}
	for(int i=1;i<=n;i++){
		if(q-p[i]>=k) cout<<"No\n";
		else cout<<"Yes\n";
	}
}


Measured memory_bytes: 1408
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 2e5 + 20 ;
int n , m , a[N] , b[N] ;

inline bool check (int x) {
	for (int i = 0 ; i < m ; i ++) b[i] = (a[i] >= x) ;

	int p1 = 0 , p2 = 0 ;
	while (p1 < n - 1 && b[n - p1 - 2] != b[n - p1 - 1]) p1 ++ ;
	while (p2 < n - 1 && b[n + p2] != b[n + p2 - 1]) p2 ++ ;

	if (p1 == n - 1 && p2 == n - 1) return (b[n - 1] ^ !(n & 1)) ;
	if (p1 <= p2) return b[n - p1 - 2] ;
	return b[n + p2] ;
}

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

	cin >> n ;
	m = 2 * n - 1 ;

	for (int i = 0 ; i < m ; i ++) cin >> a[i] ;

	int low = 0 , high = m ;

	while (high - low > 1) {
		int mid = (low + high) >> 1 ;

		if (check(mid)) low = mid ;
		else high = mid ;
	}

	cout << low << '\n' ;
}


Measured memory_bytes: 1920
s = list(input())

moji = []
if len(s)%2 == 0:
    for i in range(len(s)//2):
        moji.append(s[2*i])
else:
    for i in range((len(s)+1)//2):
        moji.append(s[2*i])
print("".join(moji))


Measured memory_bytes: 71728
Scanf.(Array.(scanf " %d" @@ fun n ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  let rec solve l r prev =
    let mn = ref a.(l) in
    for i=l to r do
      mn := min !mn a.(i)
    done;
    let mn = !mn in
    let res,tmpl,tmpr = ref [],ref l,ref (l-1) in
    for i=l to r do
      if a.(i) <> mn then (
        tmpr := !tmpr + 1;
      ) else (
        if !tmpr >= !tmpl then (
          res := (!tmpl,!tmpr) :: !res;
        );
        tmpl := i+1;
        tmpr := i;
      )
    done;
    if !tmpr >= !tmpl then
      res := (!tmpl,!tmpr) :: !res;
    List.fold_left (fun u (l,r) ->
      (* Printf.printf "%d,%d\n" l r; *)
      u + solve l r mn
    ) (mn - prev) !res
  in
  print_int @@ solve 0 (n-1) 0
))

Measured memory_bytes: 384
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using ll = long long;
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,w,h,i,j,k,l,m,n,q,x,y,z,t,u,v;
	ll		ans = 0;
	string	s;
	cin >> n >> q;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));
	dsu d(n);
	for(i=0;i<q;i++) {
		cin >> t >> u >> v;
		if (t==0) {
			d.merge(u,v);
		} else {
			if (d.same(u,v)) {
				cout << 1 << endl;
			} else {
				cout << 0 << endl;
			}
		}
	}
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4020
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())


def solve():
    import sys
    input = sys.stdin.readline
    n = int(input())
    if n % 2 == 0:
        print(n // 2 - 1)
    else:
        print(n // 2)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let k: usize = read();
    let mut h: Vec<u64> = (0..n).map(|_| read()).collect();

    h.sort();

    println!("{}", h.windows(k).map(|p_| p_[k - 1] - p_[0]).min().unwrap());
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

signed main(){
    ll N;
    cin >> N;
    vector<ll> h(N);
    FOR(i,0,N)cin >> h[i];
    ll DP[N];
    DP[0] = 0;
    DP[1] = abs(h[1]-h[0]);
    FOR(i,2,N)DP[i] = min(DP[i-1]+abs(h[i]-h[i-1]),DP[i-2]+abs(h[i]-h[i-2]));
    cout << DP[N-1] << endl;
}

Measured memory_bytes: 1792
alpha=list('abcdefghijklmnopqrstuvwxyz')
a=[]
ans=''
n=int(input())
for i in range(n):
    a.append(str(input()))

for s in alpha:
    count=50
    for i in a:
        if i.count(s)<count:
            count=i.count(s)
    ans += s*count

print(ans)

Measured memory_bytes: 3060
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	int a, b;
	for (int i = 0; i < 4; i++) {
		cin >> a >> b;
		if (a == 1)cout << 6000 * b << endl;
		if (a == 2)cout << 4000 * b << endl;
		if (a == 3)cout << 3000 * b << endl;
		if (a == 4)cout << 2000 * b << endl;
	}
}

Measured memory_bytes: 3092
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int h, w;
vector<string> field;
vector<vector<int>> dark;

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

int max_cnt = 0;

int main() {
  cin >> h >> w;
  field.assign(h, "");
  dark.assign(h, vector<int>(w, -1));
  for (int i = 0; i < h; ++i) {
    cin >> field[i];
  }
  queue<pair<int, int>> que;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (field[i][j] == '#') {
        dark[i][j] = 0;
        que.push(make_pair(i, j));
      }
    }
  }
  while (!que.empty()) {
    pair<int, int> crnt_pos = que.front();
    int y = crnt_pos.first;
    int x = crnt_pos.second;
    que.pop();
    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
      if (dark[ny][nx] != -1) continue;
      if (field[ny][nx] == '#') continue;
      dark[ny][nx] = dark[y][x] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      max_cnt = max(max_cnt, dark[i][j]);
    }
  }
  cout << max_cnt << endl;
}

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

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

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(const string& s)
{
    int N = s.size();

    vector<ll> hs(N, 0);

    ll r = 0, ans = 0, i = 0, base = 1;

    for (int i = N - 1; i >= 0; --i)
    {
        r = (r + (base*(s[i] - '0'))) % 2019;

        base = (base * 10) % 2019;

        ans += (r == 0 ? 1 : 0);
        ans += hs[r];

        ++hs[r];
//cout << "i = " << i << ", r = " << r << ", h = " << hs[r] << ", ";
//cout << "s = " << s.substr(0, i) << endl;
    }
 
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    string s;
    cin >> s;


    auto ans = solve(s);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 5208
program sum_and_subarray
  implicit none
  integer :: n, k, i, m, l, r
  integer(8) :: a(1000), s(500500), u, t, x, p, v
  a = 0_8
  s = 0_8
  read(*,*) n, k
  read(*,*) a(1:n)
  u = (n*(n+1))/2
  i = 1
  do l = 1, n
    v = 0_8
    do r = l, n
      v = v + a(r)
      s(i) = v
      i = i + 1
    end do
  end do
  x = 0_8
  do t = 40_8, 1_8, -1_8
    m = 0
    p = 2_8**(t-1_8)
    do i = 1, u
      if (and(x+p,s(i)).eq.x+p) m = m + 1
    end do
    if (m.ge.k) x = x + p
  end do
  write(*,'(i0)') x
  stop
end program sum_and_subarray

Measured memory_bytes: 4096
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

int n,m;

void solve(){
  vector<int>c(m);
  rep(i,m)cin>>c[i];
  vector<int>x(n);
  rep(i,n)cin>>x[i];
  vector<vector<int>>dp(n+1,vector<int>(300,1e9));
  dp[0][128]=0;
  rep(i,n){
    rep(j,256){
      rep(k,m){
        chmin(dp[i+1][min(255,max(0,j+c[k]))],dp[i][j]+(x[i]-min(255,max(0,(j+c[k]))))*(x[i]-min(255,max(0,(j+c[k])))));
      }
    }
  }
  int ans=1e9;
  rep(i,256){
    chmin(ans,dp[n][i]);
  }
  //cout<<dp[n][255]<<endl;
  cout<<ans<<"\n";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)return 0;
    solve();
  }
  //solve();
	return 0;
}



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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

const double pi = 2*acos(0.0);
//__gcd(n1, n2);
//cout << fixed;
//cout << setprecision(6); //fixes # of dp
//tgamma(i+1) is 1!

void solve(){
    int r;
    cin >> r;
    cout << fixed << setprecision(4) << 2*pi*r;
}


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
    solve();
}








Measured memory_bytes: 3792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

	static MyReader sc = new MyReader();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		int n = sc.nextInt();
		boolean ans = false;
		while(n != 0) {
			ans = ans || (n % 10 == 7);
			n /= 10;
		}
		out.println((ans ? "Yes" : "No"));
		out.close();

	}

	//GCD
	static int GCD(int n, int m) {
		if(m > n)
			return GCD(m, n);
		if(n % m == 0)
			return m;
		else {
			return GCD(m, n % m);
		}
	}

}

class MyReader {
	private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	private static String[] line = new String[0];
	private static int num = 0;

	protected MyReader() {

	}

	private void nextline() throws IOException {
		String s = in.readLine();
		line = s.split(" ");
	}

	protected String next() throws IOException {
		if(num == line.length) {
			nextline();
			num = 0;
		}
		String ret = line[num];
		num++;
		return ret;
	}

	protected int nextInt() throws IOException {
		if(num == line.length) {
			nextline();
			num = 0;
		}
		int ret = Integer.valueOf(line[num]);
		num++;
		return ret;
	}

	protected long nextLong() throws IOException {
		if(num == line.length) {
			nextline();
			num = 0;
		}
		long ret = Long.valueOf(line[num]);
		num++;
		return ret;
	}

}

// 組み合わせ計算
class Combination {
	public static int MAX = 510000;
	public static int MOD = 1000000007;

	public static long[] f = new long[MAX];
	public static long[] finv = new long[MAX];
	public static long[] inv = new long[MAX];

	protected Combination() {
		f[0] = f[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for(int i = 2; i < MAX; i++) {
			f[i] = f[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	public static long Com(int n, int k) {
		if(n < k)
			return 0;
		if(n < 0 || k < 0)
			return 0;
		return f[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}

	public static long Inverse(int n) {
		return inv[n];
	}

	public static long Factorial(int n) {
		return f[n];
	}
}

// union-find木
class UnionFind {
	private int[] parent;
	private int[] depth;
	private int[] size;

	protected UnionFind(int n) {
		super();
		parent = new int[n];
		for(int i = 0; i < n; i++) {
			parent[i] = i;
		}
		depth = new int[n];
		size = new int[n];
		for(int i = 0; i < n; i++) {
			depth[i] = 1;
			size[i] = 1;
		}
	}

	public int Parent(int n) {
		if(parent[n] == n) {
			return n;
		} else {
			return Parent(parent[n]);
		}
	}

	public void Union(int a, int b) {
		int pa = Parent(a);
		int pb = Parent(b);
		if(pa != pb) {
			if(depth[pa] > depth[pb]) {
				parent[pb] = pa;
				size[pa] += pb;
			} else if(depth[pa] == depth[pb]) {
				parent[pb] = pa;
				size[pa] += pb;
				depth[pa]++;
			} else {
				parent[pa] = pb;
				size[pb] += pa;
			}
		}
	}

	public int Size(int n) {
		return size[Parent(n)];
	}

}

Measured memory_bytes: 32656
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const int MAX = 100000;
static const int NIL = -1;
using namespace std;


int main() {

    ll n; cin >> n;
    map<ll,ll> mp;
    set<ll> st;
    ll ans = 0;

    rep(i,n){
        ll tmp; cin >> tmp;
        st.insert(tmp);
        if(mp.count(tmp) == 0) mp[tmp] = 1;
        else mp[tmp] ++;
    }

    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        ll tmp = *itr;


        if(mp[tmp] >= tmp && mp[tmp]-tmp < mp[tmp] - 0) ans += abs(mp[tmp]-tmp);
        else ans += abs(mp[tmp]-0);
        //ans += min(abs(mp[tmp]-tmp),abs(mp[tmp]-0));
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 13892
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL ec = 1,to[600005],nxt[600005],hed[300005] = {0};
LL col[600005] = {0};
LL deg[300005] = {0};
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

void dfs(LL u,LL f){
	LL cnt = 1;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if((i ^ 1) == f) continue;
		if(cnt == col[f]) cnt ++;
		col[i] = cnt; cnt ++;
		dfs(v,i);
	}
}

int main(){
	LL n,u,v,id = 0;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		deg[u] ++; deg[v] ++;
		add_edge(u,v);
		add_edge(v,u);
	}
	for(LL i = 1;i <= n;i ++) if(deg[i] > deg[id]) id = i;
	cout << deg[id] << endl;
	dfs(id,0);
	for(LL i = 1;i < n;i ++) cout << max(col[i * 2],col[i * 2 + 1]) << endl;
	return 0;
}
//

Measured memory_bytes: 14976
#include <bits/stdc++.h>
//#include "../lib/graph/graph.hpp"



using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

  int h, w; cin >> h >> w;
  vector<vector<char>> c(h, vector<char>(w));

  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      cin >> c[i][j];
    }
  }

  vector<vector<int>> g(h*w, vi(h*w, INF));
  for(int i=0;i<h*w;++i) {
    g[i][i] = 0;
  }
  vi dr = {0, 0, -1, 1};
  vi dc = {-1, 1, 0, 0};
  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      if(c[i][j] != '.') continue;
      for(int k=0;k<4;++k) {
        
        int nxti = i + dr[k], nxtj = j + dc[k];
        //cout << i << ":" << j << ":" << nxti << ":" << nxtj << endl;
        if(!(0 <= nxti && nxti < h && 0 <= nxtj && nxtj < w)) continue;
        if(c[nxti][nxtj] != '.') continue;
        g[i*w+j][nxti*w+nxtj] = 1;
      }
    }
  }

  for(int k=0;k<h*w;++k) {
    for(int i=0;i<h*w;++i) {
      for(int j=0;j<h*w;++j) {
        if(g[i][k] != INF && g[k][j] != INF) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  int ans = 0;
  for(int i=0;i<h*w;++i) {
    for(int j=i+1;j<h*w;++j) {
      if(g[i][j] != INF) ans = max(ans, g[i][j]);
    }
  }

  cout << ans << endl;


}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var n = ReadInt();
            Console.WriteLine($"{Modulo.FactorialMod(n, Modulo.Mod)}");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
    public static class Modulo
    {
        public static readonly long Mod = (long)Math.Pow(10, 9) + 7;

        public static long PowMod(long a, long n, long mod)
        {
            long result = 1;
            while (n > 0)
            {
                if ((n & 1) != 0) result = result * a % mod;
                a = a * a % mod;
                n >>= 1;
            }
            return result;
        }

        public static long FactorialMod(long n, long mod)
        {
            long ans = 1;
            while (n > 1)
            {
                ans = ans * n % mod;
                n--;
            }
            return ans;
        }
    }
}


Measured memory_bytes: 13140
import collections

n=int(input())
a=list(map(int,input().split()))
m=max(a)
cnt=collections.Counter(a)
if m==0:
  print(len(a))
else:
  ans=[0]*(m-1)
  for j in range(m-1):
    ans[j]=cnt[j]+cnt[j+1]+cnt[j+2]
  print(max(ans))

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

int main()
{
    int n,k;
    cin>>n>>k;
    int ar[n+1];
    memset(ar,0,sizeof(ar));
    for(int i=0;i<k;i++)
    {
        int x;
        cin>>x;
        for(int j=0;j<x;j++)
        {
            int y;
            cin>>y;
            ar[y]++;
        }
    }
    int c=0;
    for(int i=1;i<=n;i++)
    {
        if(ar[i]==0)
        {
            c++;
        }
    }
    cout<<c<<endl;

    return 0;
}





















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


int main()
{
  int n;
  cin>>n;
  int x[n],y[n];
  for(int i=0;i<n;i++)
  {
    cin>>x[i]>>y[i];
  }
  
  double d=0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
      d+=pow((pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2)),0.5);
    }
  }
  d=(d*2)/n;
cout << fixed << setprecision(10) << d << endl;
  }


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

const long mod = 1000000007;
int n;
vector<int> g[200000];
long sz[200000];
long dp[200000];
long f[200001];
long ans[200000];

void pre() {
  f[0] = 1;
  for (int i = 0; i < n; ++i) {
    f[i + 1] = f[i] * (i + 1) % mod;
  }
}

long fact(int k) {
  return f[k];
}

long mpow(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return mpow(b, e - 1) * b % mod;
  long t = mpow(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return mpow(n, mod - 2);
}

// (size, dp)
pair<long, long> prerec(int from, int prev) {
  long way = 1;
  long cnt = 1;
  long coeff = 1;
  for (int to : g[from]) {
    if (to == prev) continue;
    auto p = prerec(to, from);
    cnt += p.first;
    way = way * p.second % mod;
    coeff = coeff * fact(p.first) % mod;
  }
  
  long ret = way * fact(cnt - 1) % mod * inv(coeff) % mod;
  sz[from] = cnt;
  dp[from] = ret;
  return make_pair(cnt, ret);
}

void rec(int from, int prev, pair<long, long> inher) {
  int m = g[from].size();
  long cnt = 1;
  vector<long> ways;
  for (int to : g[from]) {
    if (to == prev) {
      cnt += inher.first;
      ways.push_back(inher.second * inv(fact(inher.first)) % mod);
    } else {
      cnt += sz[to];
      ways.push_back(dp[to] * inv(fact(sz[to])) % mod);
    }
  }
  
  vector<long> l(m + 1, 1);
  vector<long> r(m, 1);
  for (int i = 1; i <= m; ++i) l[i] = l[i - 1] * ways[i - 1] % mod;
  for (int i = m - 2; i >= 0; --i) r[i] = r[i + 1] * ways[i + 1] % mod;
  
  for (int i = 0; i < m; ++i) {
    int to = g[from][i];
    if (to == prev) continue;
    long ncnt = cnt - sz[to];
    long nret = l[i] * r[i] % mod * fact(ncnt - 1) % mod;
    rec(to, from, make_pair(ncnt, nret));
  }
  ans[from] = fact(n - 1) * l[m] % mod;
}

int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  pre();
  prerec(0, -1);
  rec(0, -1, make_pair(0, 1));
  
  for (int i = 0; i < n; ++i) {
    cout << ans[i] % mod << endl;
  }
}


Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
// #define INF (1LL << 31)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

struct Edge {
    long long to;
    long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;
 
/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}

int main() {
    int V; cin >> V;
    int E;
    cin >> E;
    int r; cin >> r;

    Graph G(V);
    Edge e;
    for (int i=0; i<E; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        e = {b, c};
        G[a].push_back(e);
        // e = {a, c};
        // G[b].push_back(e);
    }

    VI d;
    dijkstra(G, r, d);
    for (int i=0; i<V; ++i) {
        if(d[i] != INF) {
            cout << d[i] << endl;
        }else{
            cout << "INF" << endl;
        }
    }
}



Measured memory_bytes: 19440
import java.util.Scanner;
import java.awt.image.BandedSampleModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {


    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        if(s.equals("RRR"))
        {
            System.out.println(3);
        }
        else  if(s.equals("SRR")||s.equals("RRS"))
        {
            System.out.println(2);
        }
        else if(s.equals("SSS"))
        {
            System.out.println(0);
        }
        else
        {
            System.out.println(1);
        }

    }
}


Measured memory_bytes: 35588
N, A, B, C = map(int, input().split())

length = [0] * N

for i in range(N):
    length[i] = int(input())

inf = 10 ** 9

def dfs(pos, a, b, c):
    if pos == N:
        if min(a, b, c) > 0:
            #a = 0, b = 0, c = 0だったら題意が成立しない
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return inf
    
    ret1 = dfs(pos + 1, a, b, c)
    ret2 = dfs(pos + 1, a + length[pos], b, c) + 10
    ret3 = dfs(pos + 1, a, b + length[pos], c) + 10
    ret4 = dfs(pos + 1, a, b, c + length[pos]) + 10
    return min(ret1, ret2, ret3, ret4)
    
print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e2) + 17;

int n;
string s;

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

void solve() {
    n = sz(s);

    if (s[0] == 'A' && s[1] != 'A' && s[1] != 'C'
            && count(s.begin() + 2, s.end() - 1, 'C') == 1 && count(s.begin() + 2, s.end(), 'A') == 0) {
        int cnt = 0;

        for (auto& c : s)
            if ('A' <= c && c <= 'Z')
                ++cnt;

        if (cnt == 2)
            cout << "AC\n";
        else
            cout << "WA\n";
    } else {
        cout << "WA\n";
    }
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
//A[i]の後ろから考えることで、配列を固定できる
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] In = Console.ReadLine().Split(' ');
        int[] A = new int[n];
        for (int i = 0; i < n; i++)
        {
            A[i] = int.Parse(In[i]);
        }
        int[] B = new int[n];
        for(int i=n-1; i >= 0; i--)
        {
            int t = 1;
            int sum = 0;
            while ((i + 1) * t <= n)
            {
                sum += B[(i + 1) * t - 1];
                sum %= 2;
                t++;
            }
            if (A[i] == sum) B[i] = 0;
            else B[i] = 1;
        }
        int ans =0;
        for(int i=0; i < n; i++)
        {
            if (B[i] == 1) ans++;
        }
        Console.WriteLine(ans);
        for(int i=0; i < n; i++)
        {
            if (B[i] == 1) Console.WriteLine(i+1);
        }
    }
}

//計算A合わない
//namespace D
//{
//    class Program
//    {
//        static public int n;
//        static public bool flag;
//        static public int[] A;
//        static void Main(string[] args)
//        {
//            n = int.Parse(Console.ReadLine());
//            string[] In = Console.ReadLine().Split(' ');
//            A = new int[n];
//            for(int i=0; i < n; i++)
//            {
//                A[i] = int.Parse(In[i]);
//            }
//            //iの倍数の箱のボールの和を2で割った余りはAi、ただし一つの箱に入るボールは一つまで
//            //A[i],A[i+1],...,A[n]を全て見たさないといけない
//            int[] B = new int[n];
//            for(int i=0; i < n; i++)
//            {
//                DFS(0, B, i+1);
//                if (flag) break;
//                B = Enumerable.Repeat(0, n).ToArray();
//            }
//            int ans = 0;
//            for (int i = 0; i < n; i++){
//                if (B[i] == 1) ans++;
//            }
//            Console.WriteLine(ans);
//            for (int i = 0; i < n; i++)
//            {
//                Console.WriteLine(B[i]);
//            }
//        }
//        static public void DFS(int index, int[] B, int cnum)
//        {
//            if (index >= n)
//            {
//                flag=Check(B, cnum);
//                return;
//            }
//            DFS(index + 1, B,cnum);
//            B[index] = 1;
//            DFS(index + 1, B,cnum);
//        }
//        static public bool Check(int[] B, int cnum)
//        {
//            int t = 1;
//            int sum = 0;
//            while (cnum * t <= n)
//            {
//                sum += B[cnum * t - 1];
//                t++;
//            }
//            if (sum % 2 == A[cnum - 1]) return true;
//            else return false ;
//        }
//    }
//}


Measured memory_bytes: 43300
#include <bits/stdc++.h>
using namespace std;
int main(){
  while(true){
    int x,h;
    scanf("%d%d",&x,&h);
    if(x+h==0)return 0;
    // x/2, h, ?
    double sha = sqrt(x*x/4.0 + 1.0*h*h);
    double ans = x*x*1.0 + 4.0*x*sha/2.0;
    printf("%.9f\n",ans);
  }
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<math.h>

int main()
{
  int i, j, k, l, n;
  int p[101], m[101][101];

  scanf("%d", &n);
  for(i = 1; i <= n; i++)
    {
      scanf("%d", &p[i-1]);
      scanf("%d", &p[i]);
      m[i][i] = 0;
    }
  for(l = 2; l <= n; l++)
    {
      for(i = 1; i <= n-l+1; i++)
	{
	  j = i + l - 1;
	  m[i][j] = 1 << 21;
	  for(k = i; k <= j-1; k++)
	    {
	      m[i][j] = fmin(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
	    }
	}
    }
  printf("%d\n", m[1][n]);
  return 0;
}



Measured memory_bytes: 2108