akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
ll a[221111];

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n)cin>>a[i];
  ll sum=0;
  rep(i,n)sum+=a[i];
  ll res=INF;
  ll ns=0;
  rep(i,n-1){
    ns+=a[i];
    minch(res,abs(sum-ns-ns));
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
typedef long long ll;

int main(void){
    // Your code here
    char b;
    cin >> b;
    if(b == 'A')cout << 'T' << endl;
    if(b == 'T')cout << 'A' << endl;
    if(b == 'G')cout << 'C' << endl;
    if(b == 'C')cout << 'G' << endl;
}

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

using namespace std;

typedef long long	ll;

int main (){
	ll a, b, c, x, y;
	
	cin >> a >> b >> c >> x >> y;
	
	ll ma = max(x, y) * 2LL;
	ll mn = ll(1e9);
	
	for(ll i = 0LL ; i <= ma ; i++){
		ll cur = i * c + max(0LL, (x - i / 2LL) * a) + max(0LL, (y - i / 2LL) * b); 
		
		mn = min(mn, cur);
	}
	
	cout << mn << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define loop(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define br                break
#define con               continue

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
 
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

priority_queue<pii, vector<pii>, greater<pii> >q;
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output1.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    string s,s1,str;
    cin>>s>>s1;
    int mn = sz(s1);
    int n= sz(s);
    int n1= sz(s1);

    for(int i=0;i<n-n1+1;i++){
    	str = s.substr(i,n1);
    	int coun=0;
    	if(str.size()<n1)break;
    	for(int j=0;j<n1;j++){
    		if(str[j]!=s1[j])coun++;
    	}
    	mn = min(mn,coun);
    	if(mn==0){
    		cout<<0<<endl;
    		return 0;
    	}
    	str.clear();
    }
    cout<<mn<<endl;
 
}


Measured memory_bytes: 3564
#include<iostream>
using namespace std;
int main(){
	int r,g,b,n;
	cin >> r >> g >> b >> n;
	int ans=0;
	for(int i=0;i<=3000;i++){
		for(int j=0;j<=3000;j++){
			int k=n-(i*r+j*g);
			if(k>=0 && k%b==0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;
    vec C(N, 0);
    REP(i,0,N) {
        ll c;
        cin >> c;
        --c;
        ++C[c];
    }

    ASC(C);
    ll sum = 0, cnt = N;
    REP(i,0,N-1) {
        if(C[i] == 0) --cnt;
        else {
            sum += C[i];
            --cnt;
        }
        if(cnt <= K) break;
    }
    PR(sum);

    return 0;
}

/*

0 0 1 2 2
0 0 0 3 2

*/

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

int main(){
  int kosuu[1200]={},num;
  char a;

  while(cin>>a){
    if(a<='z'&&a>='a'){
      num=a-'a';
      kosuu[num]++;
    }
    else if(a<='Z'&&a>='A'){
      num=a-'A';
      kosuu[num]++;
    }

  }
  a='a';

  for(int i=0;i<26;i++){
    cout<<(char)(a+i)<<" : "<<kosuu[i]<<endl;
  }

  return 0;
}



Measured memory_bytes: 3076
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, K = LI()
A = LI()


def main():
    ans = A.copy()
    w = [0] * (N + 1)
    for i in range(N):
        w[max(0, i - A[i])] += 1
        w[min(N, i + A[i] + 1)] -= 1
    
    for _ in range(K):
        x = 0
        l = [0] * (N + 1)
        flag = True
        for i in range(N):
            x += w[i]
            if x != N:
                flag = False
            ans[i] = x
            l[max(0, i - x)] += 1
            l[min(N, i + x + 1)] -= 1
        if flag:
            break
        w = l
    
    print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 160888
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        k: i64,
        t: usize,
        a: [i64; t]
    }

    let max = a.iter().max().unwrap();

    if max - (k - max) <= 1 {
        println!("0");
    } else {
        println!("{}", max - (k - max) - 1);
    }
}


Measured memory_bytes: 4352
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e3+5 ,mod = 1e9+7 ;

int n ,m ,a[N] ,b[N] ,mem[N][N] ;

int solve(int i,int j){
    if(i==n || j==m) return 1;
    int&ret = mem[i][j];
    if(~ret) return ret;
    ret = (solve(i+1,j) + solve(i,j+1) - solve(i+1,j+1))%mod;
    ret = (ret + mod)%mod;
    if(a[i]==b[j]) ret = (ret + solve(i+1,j+1))%mod;
    return ret;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i) scanf("%d",a+i);
    for(int i=0;i<m;++i) scanf("%d",b+i);
    memset(mem,-1,sizeof mem);
    cout << solve(0,0);
    return 0;
}


Measured memory_bytes: 16256
n, p = map(int, input().split())
s = input()
x = [1] + [0]*(p-1)
ans = 0
u = 0
if p in [2,5]:
  for i in range(n):
    if int(s[i])%p==0:
      ans += i+1
else:
  for i in range(n-1,-1,-1):
    u = (int(s[i])*pow(10,n-1-i,p)+u)%p
    ans += x[u]
    x[u] += 1
print(ans)

Measured memory_bytes: 41180
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>    
#include <map>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int k;
    cin >> k;
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,t,res;
    cin>>n>>m;
    res=0;
    for(int i = 1;i*i<=(m+1);i++){
        if(m%i==0){
            if(m/i>=n){
                res = max(res,i);
            }
            if(i>=n){
                res = max(res,m/i);
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
a,b,c,x,y=gets.split.map(&:to_i)
answer=0
min=[x,y].min
max=[x,y].max

if a+b>2*c
   answer+=c*min*2 
else
   answer+=(a+b)*min
end

if x>y
    if a<2*c
        answer+=(x-y)*a
    else
        answer+=(x-y)*c*2
    end
else
    if b<2*c
        answer+=(y-x)*b
    else
        answer+=(y-x)*c*2
    end
    
end

puts answer

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

int main() {
	ll a, b, c; cin >> a >> b >> c;
	ll left = a * b * 4;
	ll right = c - a - b;
	if (right <= 0) { cout << "No" << endl; return 0; }
	right *= right;
	if (left < right) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   string s;
   int cnt = 0;
   cin >> s;

   rep(i, s.size())
   {
      if (s[i] == 'o')
         cnt++;
   }

   cnt = cnt * 100;
   cout << cnt + 700 << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n,q;
vector<int> g[200005]; //グラフデータ 
vector<int> c; //カウンタ

void dfs(int v, int from = -1){
  for (int u : g[v]){
    if (u == from) continue;
    c[u] += c[v];
    dfs(u,v);
  }
}

int main() {
  cin >> n >> q;
  
  c.resize(n); //初期化。resizeすると0埋めされる。
  
  rep(i,n-1){
    int a, b;
    cin >> a >> b;
    a--,b--;
    
    //双方向
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  rep(i,q){
    int p,x;
    cin >> p >> x;
    p--;
    
    c[p] += x;
  }
  
  dfs(0);
  
  rep(i,n){
    cout << c[i] << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main(){
  ll n;
  cin>>n;
  ll sum=0;
  ll ans=0;
  vector<ll> a(n);
  cin>>a[0];
  sum+=a[0];
  for(int i=1;i<n;i++){
    cin>>a[i];
    ans+=sum*a[i];
    ans=ans%(INF+7);
    sum+=a[i];
    sum=sum%(INF+7);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>

int main() {
	int N; std::cin >> N;
	std::map<std::string, int> MAP ;
	int max = 0;
	for (int i = 0; i < N; ++i) {
		std::string s; std::cin >> s;
		MAP[s]++;
	}
	for (auto& r : MAP)
		max = std::max(r.second, max);
	for (auto& r : MAP)
		if (r.second == max)
			std::cout << r.first << std::endl;

	return 0;
}


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

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

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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;

  int count_5=0, count_7=0;
  if (A==5) {
    count_5++;
  } else if (A==7) {
    count_7++;
  }

  if (B==5) {
    count_5++;
  } else if (B==7) {
    count_7++;
  }

  if (C==5) {
    count_5++;
  } else if (C==7) {
    count_7++;
  }

  if (count_5==2 && count_7==1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int h[N];
    int nowh = 0;
    int ans = 0;
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }

    for(int i = 0; i < N; i++){
        if(nowh <= h[i]){
            ans++;
            nowh = h[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S=input()
if S=="SUN":
  print(7)
elif S=="MON":
  print(6)
elif S=="TUE":
  print(5)
elif S=="WED":
  print(4)
elif S=="THU":
  print(3)
elif S=="FRI":
  print(2)
elif S=="SAT":
  print(1)

Measured memory_bytes: 9060
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    s=[0]*n
    f=1
    for j in range(n):
        if (i>>j)&1:
            s[j]=1
    for j in range(m):
        c=0
        for k in range(1,1+l[j][0]):
            if s[l[j][k]-1]:
                c+=1
        if c%2!=p[j]:
            f=0
            break
    if f:
        ans+=1
print(ans)


Measured memory_bytes: 41072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const ll mod = 1e9+7;
const int N = 2e5+5;

void solve(){
    int a,b; 
    cin>>a>>b; 
    cout<<a*b<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    scanf("%d",&t);
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
	int n; cin >> n;
	vector<int>a(n);

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

	sort(a.begin(), a.end(),greater<int>());
	int ans = 0;
	
	for(int i = 0; i < n; i++){
		while(a[i] % 2 == 0){
			a[i] /= 2;
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        /*
        long n = long.Parse(Console.ReadLine());
        long[] input = new long[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=long.Parse(Console.ReadLine());
        }
        */
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        input = input.OrderBy(i => i).ToArray();

        Console.WriteLine(input[0]==5&&input[1]==5&&input[2]==7?"YES":"NO");

        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法

        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();
        
    }
}

Measured memory_bytes: 13396
#include<iostream>
using namespace std;
#include<stdio.h>

int *S;

int root(int a){ if(S[a] == a) return a; S[a] = root(S[a]); return S[a]; }

bool same(int x, int y){ return root(x) == root(y); }

void unite(int x, int y){ int a = root(x), b = root(y); S[a] = b; }

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

    S = new int [n];
    for(i = 0; i < n; i++) S[i] = i;

    int cmd, x, y;
    while(q){
        scanf("%d %d %d", &cmd, &x, &y);
        if(cmd){ if(same(x, y)){ printf("1\n"); }else{ printf("0\n"); } }
        else{ unite(x, y); }
        q--;
    };
    delete [] S;

    return 0;
}

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

int a[100100];
int dp[100100];

main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
    {
    	scanf("%d",&a[i]);
	}
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		dp[i]=2e9;
		for(int j=1;j<=k&&i-j>=0;j++)
		{
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
			//printf("%d ",dp[i]);
		}
		//printf("\n");
	}
	printf("%d\n",dp[n-1]);
}


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

int main() {
	int n[5][4][11] = { 0 };
	int x, b, f, r, v;
	
	cin >> x;

	for (int i = 0; i < x; i++) {
		cin >> b >> f >> r >> v;
		n[b][f][r] += v;
	}

	for (int i = 1; i < 5; i++) {
		for (int j = 1; j < 4; j++) {
			for (int k = 1; k < 11; k++) {
				cout << " "  << n[i][j][k] ;
			}
			cout << endl;
		}
		if(i != 4)
			cout << "####################" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define ll long long  
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
 
#define md          1000000007
#define fmd         998244353 
#define M           200011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
vector<int> g[M];
ll down[M],sz[M];
ll F[M],IV[M];
void go(int u,int p){
	sz[u]=1;
	down[u]=1;
	for(auto v:g[u]){
		if(v==p)continue;
		go(v,u);
		sz[u]+=sz[v];
		ll k=down[v];
		k=k*IV[sz[v]];k%=md;
		down[u]*=k;
		down[u]%=md;

	}
	// trace(u,down[u],F[sz[u]-1]);
	down[u]*=F[sz[u]-1];
	down[u]%=md;

}

void go2(int u,int p){
	for(auto v:g[u]){
		if(v==p)continue;
		ll k=down[u];
		k=k*exp(sz[1]-sz[v],md-2);k%=md;
		k=k*sz[v];k%=md;
		down[v]=k;
		go2(v,u);
	}
}

int solve(){
    ll n,i,j,k,m,x,y,z;
    cin>>n;
    for(i=0;i<n-1;++i){
    	cin>>x>>y;
    	g[x].pb(y);g[y].pb(x);
    }
    go(1,0);
    go2(1,0);

    for(i=1;i<=n;++i)
    	cout<<down[i]<<"\n";



    
 
 
 
 
 
    // trace(f(2,2));
 
 
 
	die();
 
}
void prec(){
	F[0]=IV[0]=1;
	for(int i=1;i<M;++i){
		F[i]=F[i-1]*i%md;F[i]%=md;
		IV[i]=IV[i-1]*exp(i,md-2)%md;IV[i]%=md;
	}
} 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
    int t;
    t=1;;
    prec();
    // cin>>t;
 
    while(t--){
 
        solve();
    }
 
 
 
 
 
 
#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
 int n; cin >> n;
  if(n == 1){
    cout << "1";
  }else if(n % 2 == 1){
  	cout << (n/2 + 1)/(double)n; 
  }else{
    cout << "0.500";
  }
}

Measured memory_bytes: 256
a, b, k = [int(i) for i in input().split()]
if k <= (b-a)//2:
  for i in range(k):
    print(a+i)
  for i in range(k-1,-1,-1):
    print(b-i)
else:
  for i in range(b-a+1):
    print(a+i)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int ka, ki, ku, ta, ti, tu, ma, mi;
	scanf("%d %d %d", &ka, &ki, &ku);
	ta = ka;
	ti = ki;
	tu = ku;
	if (ka > ki){
		ta = ki;
		ti = ka;
	}
	ma = ti;
	if (ti > ku){
		ti = ku;
		tu = ma;
	}
	mi = ta;

	if (ta > ti){
		ta = ti;
		ti = mi;
	}
	printf("%d %d %d\n", ta, ti, tu);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    int num=scan.nextInt();
    int bnum[]=new int[num-1];
    int anum[]=new int [num];
    int Ans=0;
    for(int a=0; a<num-1; a++){
      bnum[a]=scan.nextInt();
    }
    anum[0]=bnum[0];
    for(int a=0; a<num-1; a++){
      if(anum[a]>bnum[a]){
        anum[a]=bnum[a];
      }
      anum[a+1]=bnum[a];
    }
    for(int a=0; a<num; a++){
      Ans+=anum[a];
    }
    System.out.println(Ans);
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string c;
    cin>>c;
    if(c=="a"||c=="i"||c=="e"||c=="u"||c=="o"){
        cout<<"vowel"<<endl;
    }else{
        cout<<"consonant"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAXN=1e3+7;
const long long MOD=1e9+7;
int h,w,f[MAXN][MAXN];
char a[MAXN][MAXN];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0);
	cin>>h>>w;
	for(int i=1;i<=h;i++) cin>>(a[i]+1);
	f[0][1]=1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(a[i][j]!='#')
				f[i][j]=(f[i-1][j]+f[i][j-1])%MOD;
	cout<<f[h][w]<<endl;
	return 0;
}

Measured memory_bytes: 8536
// C - Candies

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[2][100];

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

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

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

	int ans = 0;

	for (int i=0; i<N; i++) {
		int candies = 0;

		for (int j=0; j<=i; j++) {
			candies += A[0][j];
		}

		for (int j=i; j<N; j++) {
			candies += A[1][j];
		}

		ans = max(ans, candies);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc053_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string s;
  cin >> s;
  int N = s.size();

  int start = 0;
  rep(i, N) {
    if (s[i] == 'A') {
      start = i;
      break;
    }
  }

  int end = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      end = i;
      break;
    }
  }

  ll ans = end - start + 1;

  cout << ans << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],b[100005],c[100005];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int x,y,z;
        cin>>x>>y>>z;
        if(i==1){
            a[i]=x,b[i]=y,c[i]=z;
        }
        else{
            a[i]=max(b[i-1],c[i-1])+x;
            b[i]=max(c[i-1],a[i-1])+y;
            c[i]=max(b[i-1],a[i-1])+z;
        }
    }
    cout<<max(a[n],max(b[n],c[n]));
    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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


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

	vd x(3), y(3);
	double px, py;
	double a1, a2, a3;
	bool s = false;

	while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> px >> py){
		s = false;

		a1 = (x[1] - x[0])*(py - y[1]) - (y[1] - y[0])*(px - x[1]);
		a2 = (x[2] - x[1])*(py - y[2]) - (y[2] - y[1])*(px - x[2]);
		a3 = (x[0] - x[2])*(py - y[0]) - (y[0] - y[2])*(px - x[0]);

		if (((a1 > 0) && (a2 > 0) && (a3 > 0)) || ((a1 < 0) && (a2 < 0) && (a3 < 0)))
			s = !s;

		if (s)
			puts("YES");
		else
			puts("NO");
	}
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

ll n;
ll ans = 0;

void dfs(ll x, int a, int b, int c) {
	if (x > n)return;
	if (a && b && c)ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}

int main() {
	int a, b;
	cin >> a >> b;
	int loop = 100 * b;
	int ans = -1;
	for (int i = 1;i <= loop;++i) {
		int res = i * 2 / 25;
		if ( res== a && i/10 == b) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------
int n;
string s;
vector<vector<int> >rgb(4040, vector<int>(3));
ll ans;
ll r, g, b;
void solve(){
    ans = 0;
    for(int i = 0; i < n - 2; i++){//まずiの色を決める
    for(int j = i + 1; j < n - 1; j++){//次にjの色を決める
    if(s.at(i) == s.at(j)) continue;//同じ色なら次へ
    if(s.at(i) != 'R' && s.at(j) != 'R'){//kの色がR
        ans += (r - rgb.at(j).at(0));
        if(j + (j - i) >= n) continue;
        if(s.at(j + (j - i)) == 'R'){
            ans --;
        }
    }
    else if(s.at(i) != 'G' && s.at(j) != 'G'){//kの色がG
        ans += (g - rgb.at(j).at(1));
        if(j + (j - i) >= n) continue;
        if(s.at(j + (j - i)) == 'G'){
            ans--;
        }
    }
    else if(s.at(i) != 'B' && s.at(j) != 'B'){//kの色がB
        ans += (b - rgb.at(j).at(2));
        if(j + (j - i) >= n) continue;
        if(s.at(j + (j - i)) == 'B'){
            ans--;
        }
    }
    }
    }
    cout << ans << endl;
}
int main(){
    cin >> n;
    cin >> s;
    for(int i = 0; i < n; i++){//i番目までにこの色は何個、を管理
        if(s.at(i) == 'R'){
            rgb.at(i).at(0)++;
        }
        else if(s.at(i) == 'G'){
            rgb.at(i).at(1)++;
        }
        else{
            rgb.at(i).at(2)++;
        }
        for(int j = 0; j < 3; j++){
            rgb.at(i + 1).at(j) = rgb.at(i).at(j);
        }
    }
    r = rgb.at(n - 1).at(0);
    g = rgb.at(n - 1).at(1);
    b = rgb.at(n - 1).at(2);
    solve();

    return 0;
}



Measured memory_bytes: 3856
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <cstring>

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

#define INF (int)1e9+7

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

typedef long long ll;

using namespace std;

int a[100005];
int c[100005];

int main(){
    int n;

    cin >> n;
    
    a[0] = 0;
    a[n+1] = 0;
    int now = a[0];
    ll sum = 0;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        c[i] = abs(a[i] - now);
        now = a[i];
        sum += c[i];
    }
    sum += abs(a[n]);
    
    for(int i = 1; i <= n; i++){
        cout << sum + abs(a[i-1]-a[i+1]) - abs(a[i-1]-a[i]) - abs(a[i] - a[i+1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int n, m, k; cin>>n>>m>>k;
    vector<int> d(m);
    vector<int> numDark(n, -1);
    for(int i=0; i<m; i++){
        cin>>d[i];
        d[i]--;
        numDark[d[i]] = i;
    }

    vector<vector<int>> v(n, vector<int>(k));
    for(int i=0; i<n; i++){
        for(int j=0; j<k; j++){
            cin>>v[i][j];
            v[i][j]--;
        }
    }

    vector<int> dist((1 << m), 1e9);
    dist[(1 << m) - 1] = 0;
    queue<int> que;
    que.emplace((1 << m) - 1);
    while(que.size()){
        int cbit = que.front();
        que.pop();

        for(int i=0; i<k; i++){
            int nbit = 0;
            for(int j=0; j<m; j++){
                if(cbit & (1 << j)){
                    int nxtRoom = v[d[j]][i];

                    if(numDark[nxtRoom] < 0) continue;

                    nbit |= (1 << numDark[nxtRoom]);
                }
            }

            if(dist[cbit] + 1 < dist[nbit]){
                dist[nbit] = dist[cbit] + 1;
                que.emplace(nbit);
            }
        }
    }

    cout << dist[0] << endl;
}


Measured memory_bytes: 3452
n = int(input())
aaa = [0] + list(map(int, input().split())) + [0]
diff = [abs(a - b) for a, b in zip(aaa, aaa[1:])]
sa = sum(diff)
omit = [abs(aaa[i] - aaa[i + 2]) - diff[i] - diff[i + 1] for i in range(n)]
print('\n'.join(map(str, (sa + o for o in omit))))


Measured memory_bytes: 22896
/** Author: Nicklaus **/
 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
 
int main(){
	int n;
	cin>>n;
	int m=n/100;
	int y=n%100;
	if(m>0 && m<=12){
		if(y<=12 && y>0){
			cout<<"AMBIGUOUS";
		}else{
			cout<<"MMYY";
		}
	}else if(y>0 && y<=12){
		cout<<"YYMM";
	}else{
		cout<<"NA";
	}
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 100010
using namespace std;
int main()
{
    char x[N];
    scanf("%s",&x);
    int m;
    m=strlen(x);
    if(x[0]==x[m-1])
    {
        if(m%2)
        {
            printf("Second\n");
        }
        else printf("First\n");
    }
    else
    {
        if(m%2)
        {
            printf("First\n");
        }
        else printf("Second\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    string input;
    cin >> input;
    int zenhan = stoi(input.substr(0, 2));
    int kouhan = stoi(input.substr(2, 2));

    if (zenhan >= 13 || zenhan == 0) {
        if (kouhan >= 13 || kouhan == 0) {
            cout << "NA";
            return 0;
        } else {
            cout << "YYMM";
            return 0;
        }
    } else {
        if (kouhan >= 13 || kouhan == 0) {
            cout << "MMYY";
            return 0;
        } else {
            cout << "AMBIGUOUS";
            return 0;
        }
    }
}

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

A = a[0]; B = a[1]; K = a[2]

for i in range(K):
    if i % 2 == 0:
        if A % 2 == 1:
            A -= 1
        cokkie = A / 2
        A -= cokkie
        B += cokkie
    else:
        if B % 2 == 1:
            B -= 1
        cokkie = B / 2
        B -= cokkie
        A += cokkie

print(str(int(A)) + " " + str(int(B)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:0;}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:0;}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=100005;

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1)
	{
		c-=b;
		if(c<=0)return 0*printf("Yes\n");
		a-=d;
		if(a<=0)return 0*printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var A = input[0];
        var B = input[1];
        var T = input[2];
        
        Console.WriteLine(B * (T / A));
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <ctype.h>

int stack[102]; int top;
char buf[2000];

int main()
{
	int  v1, v2;
	char *p;

	fgets(p=buf,500,stdin);
	top = 0;
	while (*p>=' ') {
		while (isspace(*p)) p++;
		if (isdigit(*p)) {
			v1 = 0;
	    	while(isdigit(*p)){
	    	    v1 = 10*v1 + (*p++ & 0xf);
			}
		stack[top++] = v1;
		}else{
			v1 = stack[--top];
			v2 = stack[--top];
			if(*p == '+') v2 += v1;
			else if(*p == '-') v2 -= v1;
			else if(*p == '*') v2 *= v1;
			stack[top++] = v2;
			p++;
		}
	}
	printf("%d\n",stack[--top]);
	return 0;
}


Measured memory_bytes: 2128
#include <stdio.h>
#include <algorithm>
using namespace std;

int arr[3];

int main(void)
{
	scanf("%d%d%d", arr, arr + 1, arr + 2);
	sort(arr, arr + 3);
	printf("%d\n", arr[2] * 10 + arr[1] + arr[0]);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  int mincnt = 0;
  rep(i,N) if(A[i]<0) mincnt++;

  ll ans = 0;
  if(mincnt%2==1){
    rep(i,N) A[i] = abs(A[i]);
    sort(all(A));
    A[0]*=-1;
    rep(i,N) ans += A[i];
  }
  else{
    rep(i,N) ans += abs(A[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3984
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ a, b ] <- readInts
	putStrLn $ solve a b

solve a b
	| a + b == 15 = "+"
	| a * b == 15 = "*"
	| otherwise = "x"

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long ll;

int main() {
  vector<int> v(101);
  REP(i,0,3) {
    int x;
    cin >> x;
    v[x]++;
  }
  int c = 0;
  REP(i,0,v.size()) {
    if(v[i]) c++;
  }
  cout << c << endl;
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++) cin >> H.at(i);
  int cnt=0;;
  for(int i=N-1; i>0; i--){
    if(H.at(i)>=H.at(i-1)){
      cnt++;
    }
    else if(H.at(i-1)-H.at(i)<=1){
      cnt++;
      H.at(i-1)--;
    }
  }
  if(cnt==N-1) cout << "Yes" << endl;
  else if(N==1) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 640
//B
/*==========================================================*/
/*    Template ver 2017-0401    |   Created by AVM.Martin   */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<algorithm>
#include<cmath>

#include<cstring>
#include<string>
#include<cctype>
#include<utility>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<list>

typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
typedef std::vector<int> vi;

const int OO=(int)2e9;
const ll INF=(ll)4e18;
const double EPS=(double)1e-12;

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

#define INL(i,a,b) ((a<=i)&&(i<=b))
#define EXL(i,a,b) ((a< i)&&(i< b))
#define REPP(i,a,b,c) for(int i=a;i<=b;i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a;i>=b;i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
using namespace std;

int n,k,res;
int dat[55];

int main(){
	scanf("%d %d",&n,&k);
	REP(i,1,n)scanf("%d",dat+i);
	sort(dat+1,dat+1+n);
	res=0;
	REP(i,1,k)res+=dat[n-i+1];
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

puts gc.map{|i| i == '+' ? 1:-1}.inject(:+)


Measured memory_bytes: 2300
/******************************************
* NICK : nikhilsinghh59 *
******************************************/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;

int main()
{   
    

    vector<ll>v;
    queue<ll>q;

    for(ll i=1 ; i<=9 ; i++) {
        q.push(i);
    }

    ll ct=0;

    while(ct <= 100000) {
        ll ele = q.front();
        q.pop();
        v.push_back(ele);
        ct++;

        ll digit = ele%10;

        if(digit) {
            q.push(ele*10 + digit-1);
        }
        q.push(ele*10 + digit);
        if(digit!=9) {
            q.push(ele*10 + digit + 1);
        }

    }

    ll k;
    cin >> k;

    cout << v[k-1];

    
    return 0;
}

Measured memory_bytes: 2548
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{n:i64};

    let mut mx = 0;
    for i in 1..(n as f64).sqrt() as i64 + 1 {
        if i*i <= n {
            mx = i*i;
        }
    }
    println!("{}",mx);
}

Measured memory_bytes: 4352