akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var a = io.Is(n);

        Array.Sort(a);
        var gs = a.GroupBy(x => x).ToArray();
        var ans = 0;

        for (var i = 0; i < gs.Length; i++)
        {
            var t0 = gs[i].First();
            var t1 = i + 1 < gs.Length ? gs[i + 1].First() : -114514;
            var t2 = i + 2 < gs.Length ? gs[i + 2].First() : -114514;
            var t = gs[i].Count();

            if (t0 + 2 == t1) t += gs[i + 1].Count();
            else if (t0 + 1 == t1)
                if (t1 + 1 == t2) t += gs[i + 1].Count() + gs[i + 2].Count();
                else t += gs[i + 1].Count();

            ans = Max(ans, t);
        }

        io.Write(ans);
    }
}

Measured memory_bytes: 34220
#include <bits/stdc++.h>
#include <cstring>
#include <ctype.h>
#include<stdlib.h>

#define flin            freopen("input.txt", "r", stdin); 
#define flout           freopen("output.txt", "w", stdout);
#define ll              long long
#define ull             unsigned long long
#define fastio          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl              '\n'
#define nll             '\0'
#define pb              push_back
#define bdyptb          return 0;
#define sorted(x)       sort(x.begin(), x.end())
#define reversed(x)     reverse(x.begin(), x.end())
#define all(x)          x.begin(), x.end()
#define mset(a, b)      memset(a, b, sizeof(a));
#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)

#define pi acos(-1.00)   
#define mx 1000007

using namespace std;

int main()
{
	fastio;
	int n,d;
	cin>>n>>d;

	int c=0,x,y;

	for(int i=0; i<n; i++)
	{
		cin>>x>>y;
		double s=sqrt((1.0*x*x) + (1.0*y*y));
		if(s<=d*1.0)
			c++;
	}
	
	cout<<c; 

    
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string a,b;
    cin>>a>>b;
    a+=b;
    int A=stoi(a);
    for(int i=0;i<=sqrt(A);i++){
        if(i*i==A){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()

using ll = long long;
constexpr ll INF = 10000000000;

using namespace std;

//fixed << setprecision(10)

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

int main() {
	ll q, h, s, d;
	ll n;
	cin >> q >> h >> s >> d >> n;

	ll a = min(q * 4, s);
	ll b = min(h * 2, s);

	ll x = min(a, b);

	//1L_x円,2L_d円




	if (2 * x <= d) {
		cout << n * x << endl;
	}
	else {
		ll ans = (n / 2) * d;
		ll amr = n % 2;

		if (amr == 0) cout << ans << endl;
		else cout << ans + x << endl;
	}

}

Measured memory_bytes: 256
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x=int(input())
if x==0:
    print(1)
elif x==1:
    print(0)

Measured memory_bytes: 62036
s=input()

output=[]

for i in range(len(s)):
    if s[i]=='0':
        output.append('0')
    elif s[i]=='1':
        output.append('1')
    elif s[i]=='B':
        if len(output)!=0:
            del output[len(output)-1]

for i in range(len(output)):
    print(output[i],end="")

Measured memory_bytes: 3064
require 'matrix'

def cross(p1, p2)
  return p1[0]*p2[1] - p1[1]*p2[0]
end

s = []
u = []
l = []

gets.to_i.times do
  x, y = gets.split.map &:to_i
  s << Vector[x,y]
end

s.sort! { |a, b| a[0] == b[0] ? a[1] <=> b[1] : a[0] <=> b[0] }

u.push s[0]
u.push s[1]
l.push s[-1]
l.push s[-2]

(2..s.size-1).each do |i|
  n = u.size
  while n >= 2 && cross(s[i]-u[n-2], u[n-1]-u[n-2])  > 0
    u.pop
    n -= 1
  end
  u.push s[i]
end

(s.size - 3).downto(0) do |i|
  n = l.size
  while n >= 2 && cross(s[i]-l[n-2], l[n-1]-l[n-2]) > 0
    l.pop
    n -= 1
  end
  l.push s[i]
end

l.reverse!
(u.size-2).downto(1) do |i|
  l.push u[i]
end
l.reverse!


puts l.size
ofs = 0
(0..l.size-1).each do |i|
  if l[ofs][1] > l[i][1]
    ofs = i
  elsif l[ofs][1] == l[i][1]
    if l[ofs][0] > l[i][0]
      ofs = i
    end
  end
end
(0..l.size-1).each do |i|
  j = ( i + ofs ) % l.size
  puts "#{l[j][0]} #{l[j][1]}"
end

Measured memory_bytes: 22840
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename F, typename... R>void input(F& f, R&... r) { cin >> f; input(r...); }
template<typename F, typename... R>void input(vector<F>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

int main() {
    int N, M; input(N,M);
    VI a(M); input(a);
    vector<ll> dp(N + 3, 0);
    REP(i, M) {
        a[i]--;
    }
    int k = 0;
    dp[0] = 1;
    dp[1] = 1;
    REP(i, N) {
        if (k < M && a[k] == i) {
            k++;
            dp[i] = 0;
        }
        else {
            if (i - 2 >= 0) dp[i] += dp[i - 2];
            if (i - 1 >= 0) dp[i] += dp[i - 1];
            dp[i] %= MOD;
        }
    }
    cout << dp[N - 1] << endl;
    getchar(); getchar();
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int a, b;
  cin >> a >> b;
  cout << ((a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) ? "Possible" : "Impossible") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int W, H, N, L, R, T, B, A;

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d%d", &W, &H, &N);
	L = 0, R = W, T = H, B = 0;
	for(int i = 0; i < N; i++){
		int x, y, a;
		scanf("%d%d%d", &x, &y, &a);
		if(a == 1 && x > L) L = x;
		else if(a == 2 && x < R) R = x;
		else if(a == 3 && y > B) B = y;
		else if(a == 4 && y < T) T = y;
	}
	if(L > R || T < B) printf("0\n");
	else printf("%d\n", abs(L - R) * abs(T - B));
}

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

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

int main() {
  int N;
  cin >> N;
  map<int, int> as;
  int a;
  for(int i = 0; i < N; ++i) {
    cin >> a;
    as[a - 1]++;
    as[a]++;
    as[a + 1]++;
  }
  int ans = 0;
  for(auto a : as) {
    chmax(ans, a.second);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define F first
#define S second
#define STP(x) setprecision(x)
#define watch(x) cout << (#x) << " is " << (x) << "   =="
#define Yala_Besor3a ios_base::sync_with_stdio(0),ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;

const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 2e5 + 5, M = 1e3 + 5, mod = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    Yala_Besor3a;
    string a,b;
    cin>>a>>b;
    int ans=0;
    for (int i = 0; i < a.length(); ++i) {
        ans+=(a[i]!=b[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3804
from collections import Counter


def main():
    N = int(input())
    s = ["".join(sorted(input())) for _ in range(N)]
    S = Counter(s)
    ans = 0
    for a in S.values():
        ans += sigma(a)
    print(ans)


def sigma(x):
    sum = 0
    for i in range(1, x):
        sum += i
    return sum


if __name__ == "__main__":
    main()


Measured memory_bytes: 19752
#coding:utf-8
from collections import defaultdict
from itertools import  product
def main():
    N=input()

    dp = [defaultdict(int) for i in range(101)]
    def ok(s):
        if s[:-1] in ("agc", "acg", "gac"):
            return False        
        if s[1:] in ("agc", "acg", "gac"):
            return False
        if s[0:2] == "ag" and s[3] == "c":
            return False
        if s[0] == "a" and s[2:4] == "gc": 
            return False
        return True

    if N==3:
        print(61)
        return

    for s in product("atgc", repeat=4):
        s="".join(s)
        if ok(s):
            dp[4][s]=1
        else:
            dp[4][s]=0
    
    i=5
    while i<=N:
        for k,v in dp[i-1].iteritems():
            for c in "atgc":
                n=k[1:]+c
                if ok(n):
                    dp[i][n] += dp[i-1][k]
        i+=1
    print(sum(dp[N].values()) % (10**9+7))
main()


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

void solve(int N, vector<int> A)
{
    if (N == 0)
    {
        cout << (A.at(0) == 1 ? 1 : -1) << endl;
        return;
    }

    vector<int64_t> rest(N + 1);
    int64_t acc = 0;
    for (int i = N; i >= 0; i--)
    {
        acc += A.at(i);
        rest.at(i) = acc;
    }

    int64_t res = 1;
    int64_t curr = 1;
    for (int i = 0; i < N; i++)
    {
        if (curr - A.at(i) <= 0)
        {
            cout << -1 << endl;
            return;
        }
        int64_t next = min(2 * (curr - A.at(i)), rest.at(i + 1));
        res += next;
        curr = next;
    }
    cout << (curr == A.at(N) ? res : -1) << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1);
    for (int i = 0; i < N + 1; i++)
    {
        cin >> A.at(i);
    }
    solve(N, move(A));
    return 0;
}


Measured memory_bytes: 4584
#include <iostream>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 3e5 + 5;
long long int arr[maxn],ans=0;
int main() {
    long long int n,i,j,k;

    cin>>n;


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

    for(i=0;i<64;i++)
    {
        k=0; 
        for(j=0;j<n;j++)
            if((arr[j] & (1ll<<i)))
                k++;
        ans+= ((1ll<<i) % mod) * k % mod *(n-k) % mod;    
    }
    cout<< (ans + mod) % mod <<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;
	int ans = 0;
	int cnt = 0;
	REP(i, S.size()-1) {
		
		bool F = false;

		if (S[i] == 'A')cnt++;

		if (S[i] == 'B' && S[i + 1] == 'C')ans += cnt;

		if (S[i] == 'A' && S[i + 1] == 'C')F = true;
		if (S[i] == 'B' && S[i + 1] == 'B')F = true;
		if (S[i] == 'B' && S[i + 1] == 'A')F = true;
		if (S[i] == 'C' && S[i + 1] == 'C')F = true;

		if (F)cnt = 0;


	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 720
#include<bits/stdc++.h>
int mire(int y, int m, int d){
  int ans=0;
  int sumy=0;
  for(int i=y+1;i<1000;i++){
    if(i%3!=0) sumy++;
  }
  ans+=(999-y)*10*20;
  ans-=(sumy*5);
  if(y%3==0){
    for(int i=m+1;i<11;i++){
      ans+=20;
    }
  }
  else{
    for(int i=m+1;i<11;i++){
      if(i%2==1)ans+=20;
      else ans+=19;
    }
  }
  if(y%3==0 || m%2==1){
    for(int i=d;i<21;i++){
      ans++;
    }
  }
  else{
    for(int i=d;i<20;i++){
      ans++;
    }
  }
  return ans;
}
using namespace std;
int main(){
  int n,y[105],m[105],d[105];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>y[i]>>m[i]>>d[i];
  }
  for(int i=0;i<n;i++){
    cout<<mire(y[i],m[i],d[i])<<endl;
  }
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
long long N, A[1 << 18], B[1 << 18], C[1 << 18], sum, cnt;
vector<long long> X;
int main() 
{
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
	for (int i = 0; i < N; i++)
	{
		cin >> B[i];
		if (A[i] >= B[i])
			X.push_back(A[i] - B[i]);
		else
		{
			sum += (B[i] - A[i]); cnt++;
		}
	}
	sort(X.begin(), X.end());
	reverse(X.begin(), X.end());
	for (int i = 0; i < X.size(); i++)
	{
		if (sum > 0)
		{
			sum -= X[i]; cnt++;
		}
	}
	if (sum > 0)
		cnt = -1;
	cout << cnt <<"\n";
	return 0;
}

Measured memory_bytes: 5496
#include "bits/stdc++.h"
using namespace std;
using ll = long long;


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r++;
		}
	}
	for (int i = r; i < n; i++) {
		if (s[i] == 'R') {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
ll num[85];
int main () {
  int n;
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%lld", &num[i]);
  }
  ll x = 1000, y = 0;
  FOR(i, 1, n) {
    x += y * num[i]; y = 0;
    if (i < n && num[i] < num[i + 1]) {
      y = x / num[i]; x %= num[i];
    }
  }
  printf("%lld\n", x);
  return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main()
{
    string s;
    cin >> s;
    cout << s[0] << s.size() -2 << s[s.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

void visit(int);
int map[101][101];
int f[101],d[101],color[101],time,n;
int main()
{
  int i,j,v,vv,m;

  scanf("%d",&n);
  if(n < 1 || n > 100)exit(1);

  for(i = 0 ; i < n ; i++){
    color[i] = 0;
    for(j = 0 ; j < n ; j++){
      map[i][j] = 0;
    }
  }
  time = 0;
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&v,&m);
    for(j = 0 ; j < m ; j++){
      scanf("%d",&vv);
      map[v-1][vv-1] = 1;
    }
  }
  for(i = 0 ; i < n ; i++){
    if(color[i] == 0)visit(i);
  }
  for(i = 0 ; i <n ; i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

void visit(int u)
{
  int i;
  color[u]=1;
  d[u]=++time;
  for(i = 0 ; i < n ; i++){
    if(map[u][i] == 1){
      if(color[i] == 0)visit(i);

    }
  }
  color[u] = 2;
  f[u] = ++time;
}



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

int main(){
    ll N, K, ans = 0 ;
    cin >> N >> K;
    vector<ll> d(N , 1);
    for(int i = 0; i < K; i++){
        ll tmp;
        cin >> tmp;
        for(int j = 0; j < tmp; j++){
            ll tmp2 = 0;
            cin >> tmp2;
            tmp2--;
            d[tmp2] = 0;
        }
    }
    for(int i = 0; i < N; i++) ans += d[i];
    cout << ans << endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int N, M;

struct Graph{
    vector<vector<int>> es;
    vector<vector<ll>> l, r;
    vector<ll> dw, up;
    const int n;

    Graph(int n) : n(n){
        es.resize(n);
        l.resize(n), r.resize(n);
        dw.resize(n), up.resize(n);
    }

    void add_edge(int from, int to, bool directed = false){
        es[from].pb(to);
        if(!directed) es[to].pb(from);
    }

    ll dfs1(int now, int pre){
        l[now].resize(sz(es[now])+1), r[now].resize(sz(es[now])+1);
        l[now][0] = 1;
        rep(i, sz(es[now])){
            int e = es[now][i];
            if(e == pre) l[now][i+1] = l[now][i];
            else l[now][i+1] = l[now][i]*(dfs1(e, now)+1)%M;
        }
        r[now][sz(es[now])] = 1;
        rep3(i, sz(es[now])-1, 0){
            int e = es[now][i];
            if(e == pre) r[now][i] = r[now][i+1];
            else r[now][i] = r[now][i+1]*(dw[e]+1)%M;
        }
        return dw[now] = r[now][0];
    }

    void dfs2(int now, int pre){
        rep(i, sz(es[now])){
            int e = es[now][i];
            if(e == pre) continue;
            up[e] = l[now][i]*r[now][i+1]%M;
            up[e] *= up[now]+1, up[e] %= M;
            dfs2(e, now);
        }
    }

    void solve(int root = 0){
        up[root] = 0;
        dfs1(root, -1), dfs2(root, -1);
        rep(i, n){
            cout << dw[i]*(up[i]+1)%M << endl;
        }
    }
};

int main(){
    cin >> N >> M;
    Graph G(N);
    rep(i, N-1){
        int u, v; cin >> u >> v; u--, v--;
        G.add_edge(u, v);
    }
    G.solve();
}

Measured memory_bytes: 26752
<?php
fscanf(STDIN, "%d %d", $X, $Y);

if (-(2*$X - $Y) % 2 === 0 && (4*$X-$Y)%2 === 0 && 4*$X >= $Y && 2*$X <= $Y) {
  $ans = 'Yes'; 
} else {
  $ans = 'No'; 
}

print_r ($ans);
?>

Measured memory_bytes: 16164
let base = int_of_char 'a'
let () =
  Scanf.scanf "%d " @@ fun n  -> 
  let s =  Array.init n (fun _ ->
               Scanf.scanf "%c" (fun x -> x)) in
  let result = ref 0 in
  for i = 0 to (n-1) do
    let left = Array.sub s 0 i in
    let right = Array.sub s i (n-i)  in
    let left' = Array.to_list left in
    let right' = Array.to_list right in
    let num = ref 0 in
    for i = 0 to 26 do
      if List.mem (char_of_int (i+base)) left' = true
         && List.mem (char_of_int (i+base)) right' = true then
        num := 1 + !num
      else
        ()
    done;
    if !num > !result then result := !num
    else ()
  done;
  Printf.printf "%d\n" (!result)


Measured memory_bytes: 768
/*
 * 素数判定プログラム
 * n個の整数が与えられる(a,b,c)。それらのうち素数のものをカウントし、
 * カウントした結果mを一行で出力する。
 *
 * input
 * n
 * a
 * b
 * c
 *
 * output
 * m
 */
#include <stdbool.h>
#include <math.h>
#include <stdio.h>

/*int mysqrt(int x)
{
	int i = 0;

	while (true) {
		i++;
		if ((double)pow(i, 2) >= pow(sqrt(x), 2))
			break;
	}

	return i;
}
*/

bool isprime(int x) 
{
	int i;

	if (x == 2)
		return true;

	if ((x < 2) || (x % 2 == 0))
		return false;

	for (i = 3; i <= (int)sqrt(x); i=i+2)
		if ( (x%i) == 0)
			return false;

	return true;
}

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

	while (n) {
		scanf("%d", &x);

		if (isprime(x))
			m++;
		n--;
	}

	printf("%d\n", m);
	return 0;
}


Measured memory_bytes: 2052
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int n;
    int a[4][13] = { 0 };
    char marks[] = "SHCD";

    scanf("%d\n", &n);
    for (int i = 0; i < n; i++) {
        char mark;
        int rank;

        scanf("%c %d\n", &mark, &rank);
        a[strchr(marks, mark) - marks][rank - 1] = 1;
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            if (!a[i][j]) {
                printf("%c %d\n", marks[i], j + 1);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2088
#include <iostream>

using namespace std;

int main() {
    int k, s;
    cin >> k >> s;

    int res = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            if (0 <= s - i - j && s - i - j <= k) {
                res++;
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        //input
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        boolean[] b_ar = new boolean[N];

        for(int i=0;i<N;i++){
        	b_ar[i] = IsRightTriangle(sc.nextDouble(),sc.nextDouble(),sc.nextDouble());
        }

        //output
        for(boolean b:b_ar){
        	if   (b) { System.out.println("YES");}
        	else     { System.out.println("NO"); }
        }
    }

    private static boolean IsRightTriangle(double a,double b,double c){
    	if( Math.pow(a,2) + Math.pow(b,2) == Math.pow(c,2) ||
            Math.pow(b,2) + Math.pow(c,2) == Math.pow(a,2) ||
            Math.pow(c,2) + Math.pow(a,2) == Math.pow(b,2)    ){
    		return true;
    	}else {
    		return false;
    	}
    }
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

bool isprime(ll n) {
  if (n == 1)return false;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}

int cnt[1000000] = {0};
void prime_factor(int n){
  for (int i(2);i*i<=n;i++){
    bool flag(true);
    while(n%i==0){
      if(flag) {
        ++cnt[i];
        flag = false;
      }
      n /= i;
    }
  }
  if (n!=1) cnt[n]++;
  return;
}

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i(0);i<N;i++) cin>>A[i];
  for(int i(0);i<N;i++){
    prime_factor(A[i]);
  }
  int maxi(0);
  // for(int i(0);i<10;i++){
  //   cout << cnt[i] << " ";
  // }
  // cout << endl;
  for(int i(0);i<1000000;i++){
    maxi = max(maxi, cnt[i]);
  }
  // cout << maxi << endl;
  if(maxi <= 1) cout << "pairwise coprime" << endl;
  else if(maxi < N) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  return 0;
}



Measured memory_bytes: 11068
s = []
while True:
    hoge = input()
    if hoge == '-':
        break
    num = int(input())
    for i in range(num):
        h = int(input())
        hoge = hoge.replace(hoge,hoge[h:] + hoge[:h])
    s += [hoge]
for i in s: print(i)

Measured memory_bytes: 6724
#include<iostream>
#include<cmath>
using namespace std;

typedef long long ll;

int main() {
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		long long a, b; cin >> a >> b;

		long long r = (long long)sqrt(a * b), ans = r * 2;
		if (a != b)ans--;
		if (a * b <= r * r)ans--;
		if (a * b <= r * (r + 1))ans--;
		cout << ans << endl;
	}


	return 0;
}

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

int top, S[1000];

void push(int x){
    top++;
    S[top] = x;
}

int pop(){
    top--;
    return S[top+1];
}


int main(){
  int x;
  int a, b;
  top = 0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
        a = pop();
        b = pop();
        push(a + b);
    } else if ( s[0] == '-' ){
        b = pop();
        a = pop();
        push(a - b);
    } else if ( s[0] == '*' ){
        a = pop();
        b = pop();
        push(a*b);
    } else {
        push(atoi(s));

    }
  }
  
  printf("%d\n", pop());

  return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
struct edge{
	int k,next;
}e[2005];
int f[1005],a[1005],n,home[1005],cnt=-1;
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
int g[5005],ok=1;
void dfs(int k,int F){
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		dfs(e[i].k,k);
	}
	memset(g,0x3f,sizeof(g));
	g[0]=0;
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		for(int p=a[k];~p;p--){
			int x=1e9;
			if(p>=a[e[i].k]) x=min(x,g[p-a[e[i].k]]+f[e[i].k]);
			if(p>=f[e[i].k]) x=min(x,g[p-f[e[i].k]]+a[e[i].k]);
			g[p]=x;
		}
	}
	f[k]=1e9;
	for(int i=0;i<=a[k];i++) f[k]=min(f[k],g[i]);
	if(f[k]>1e8) ok=0;
}
int main(){
	memset(home,-1,sizeof(home));
	scanf("%d",&n);
	for(int i=2,x;i<=n;i++){
		scanf("%d",&x);
		add(i,x);add(x,i);
	}
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	dfs(1,0);
	if(ok) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int x = 0;
  int hap = 0;
  
  scanf("%d",&x);
  
  hap += (x / 500) * 1000;
  hap += (x % 500) / 5 * 5;
  
  printf("%d",hap);
    return 0;
}

Measured memory_bytes: 128
using System;

class DayOfTakahashi{
    static void Main(string[] args){
        var ab = Console.ReadLine().Split(' ');
        var a = int.Parse(ab[0]);
        var b = int.Parse(ab[1]);

        var count = 0;
        for(int i=0; i<a-1; i++){
            for(int j=0; j<31; j++){
                if(i==j){
                    count = count + 1;
                }
            }
        }

        for(int i=0; i<b+1; i++){
            if(a==i){
                count = count + 1;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
int W,N,P[105],i,j,k,w,n;
char c;

int ch(int s)
{
	int i,r=0;
	for(i=s;i<W&&P[i]==-1;i++)r++;
	return r;
}

int main()
{
	for(;scanf("%d%d\n",&W,&N),W;)
	{
		memset(P,-1,sizeof(P));
		for(i=0;i<N;i++)
		{
			scanf("%c",&c);
			if(c=='s')
			{
				scanf("%d%d\n",&n,&w);
				for(j=0;j<W;j++)
				{
					if(P[j]==-1&&ch(j)>=w)
					{
						for(k=0;k<w;k++)P[j+k]=n;
						printf("%d\n",j);
						break;
					}
				}
				if(j==W)puts("impossible");
			}
			else
			{
				scanf("%d\n",&n);
				for(j=0;j<W;j++)
					if(P[j]==n)P[j]=-1;
			}
		}
		puts("END");
	}
	return 0;
}

Measured memory_bytes: 616
// Aizu Vol-2 0231: Dangerous Bridge
// 2017.8.20 bal4u@uu
// ?????????????????????

#include <stdio.h>
#include <stdlib.h>

#define MAX 200

typedef struct { int t, m; } T;
T tbl[MAX*5]; int N;

int cmp(T *a, T *b) { return a->t - b->t; }

int main()
{
	int n, m, a, b;
	int i, t, s, sum;

	while (scanf("%d", &n) && n) {
		N = 0;
		while (n-- > 0) {
			scanf("%d%d%d", &m, &a, &b);
			tbl[N].t = a, tbl[N++].m = m;
			tbl[N].t = b, tbl[N++].m = -m;
		}
		qsort(tbl, N, sizeof(T), cmp);
		for (t = -1, sum = s = i = 0; i < N; i++) {
			if (t != tbl[i].t) {
				if ((sum += s) > 150) goto NG;
				t = tbl[i].t, s = tbl[i].m;
			} else s += tbl[i].m;
		}
		if ((sum += s) <= 150) puts("OK");
		else {
NG:			puts("NG");
		}
	}
	return 0;
}

Measured memory_bytes: 632
object Main extends App {
  import scala.io.StdIn.{readInt, readLine}

  val elevationRate = 0.006
  def averageTemperature(T: Double)(elevation: Int) : Double = T - elevation * elevationRate

  val _ = readInt()
  val Array(t, a) = readLine().split(' ').map(_.toInt)
  val elevationWithIndex = readLine().split(' ').map(_.toInt).zipWithIndex

  val firstElevationDistance = (averageTemperature(t)(elevationWithIndex.head._1) - a).abs

  val (_, bestElevationIndex) = elevationWithIndex.tail.foldLeft((firstElevationDistance, 0))((minWithIndex, elevationWitchIndex) => {
    val distanceFromA = (averageTemperature(t)(elevationWitchIndex._1) - a).abs
    if (minWithIndex._1 > distanceFromA) (distanceFromA, elevationWitchIndex._2) else minWithIndex
  })

  println(bestElevationIndex + 1)
}

Measured memory_bytes: 54940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////

//M=40000
//Ai=M(i+1),Bi=M(n-i-1)などとするとAi+Bi=M(n)となる。つまり添え字iの値によらず一定である
//Ai+Biもまた単調に増加する数列とする必要があるのでApiの添え字にiを足してやる
int main() {
	int N; cin >> N;
	vector<int>p(N);
	REP(i, N)cin >> p[i];
	vector<int>a(N), b(N);
	int maxi = 40000;
	REP(i, N) {
		a[i] = maxi * (i + 1);
		b[i] = maxi * (N - i - 1) + 1;
	}
	REP(i, N) {
		a[p[i] - 1] += i;
	}
	REP(i, N)cout << a[i] << " ";
	cout << endl;
	REP(i, N)cout << b[i] << " ";
	return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int x;
	cin >> x;
	int d = x/100;
	int a = x%100;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 50; j++) {
			for (int k = 0; k <= 34; k++) {
				for (int l = 0; l <= 25; l++) {
					for (int m = 0; m <= 20; m++) {
						if (i+j+k+l+m > d) {
							break;
						}
						if (i+2*j+3*k+4*l+5*m == a) {
							cout << 1 << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << 0 << endl;
	
	return 0;
}


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

int main() {
  int X, N;
  cin >> X >> N;
  set<int> p;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    p.insert(x);
  }

  for (int i = 0; i <= 100; i++) {
    if (p.count(X - i) == 0) {
      cout << X - i << endl;
      return 0;
    }
    if (p.count(X + i) == 0) {
      cout << X + i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

vector<P>p;
vector<int> G[10010];
vector<int>c;
bool visited[10010];
bool leaf[10010];
void dfs(int n) {
	int cnt = 0;
	visited[n] = true;
	for (auto x : G[n]) {
		cnt++;
	}
	p.push_back(make_pair(cnt, n));
	for (auto x : G[n]) {
		if (!visited[x]) {
			dfs(x);
		}
	}
}
int ans[10010];
int res = 0;
void dfs2(int n) {
	visited[n] = true;
	for (auto x : G[n]) {
		if (!visited[x]) {
			res += min(ans[n], ans[x]);
			dfs2(x);
		}
	}
}
set<int>rem;
vector<int>v;
void dfs3(int n) {
	visited[n] = true;
	bool found = 0;
	for (auto x : G[n]) {
		if (!visited[x]) {
			if (!leaf[x]) {
				found = true;
				dfs3(x);
			}
		}
	}
	if (!found) {
		v.pb(n);
		leaf[n] = true;
		auto itr = rem.erase(n);
	}
}
int main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);*/
	int N;
	cin >> N;
	REP(i, N - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--, b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	REP(i, N) {
		rem.insert(i);
		int C; //cin >> C;
		scanf("%d", &C);
		c.pb(C);
	}
	VSORT(c);
	m0(visited);
	bool ok = false;
	while (rem.size() != 0) {
		m0(visited);
		auto itr = rem.begin();
		dfs3(*itr);
	}
	REP(i, N) {
		ans[v[i]] = c[i];
	}

	//VSORT(c);// VREVERSE(c);
	//m0(visited);
	//dfs(0);
	//VSORT(p);
	//REP(i, N) {
	//	ans[p[i].second] = c[i];
	//}
	m0(visited);
	dfs2(0);
	print(res);
	REP(i, N) {
		pe(ans[i]);
	}cout << endl;
}


Measured memory_bytes: 2048
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

b = [k - q] * (n + 1)

for i in a:
  b[i] += 1

for i in range(1, len(b)):
  if b[i] > 0:
    print('Yes')
  else:
    print('No')




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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n,x; cin >> n >> x;
    vl m(n);
    rep(i,n) cin >> m[i];
    sort(all(m));
    ll res = n;
    x-=accumulate(all(m),0LL);
    res += x/m[0];
    cout << res << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int teams=sc.nextInt();
		int[][] kachiten=new int[teams][2];
		Arrays.fill(kachiten[0], 0);
		Arrays.fill(kachiten[1], 0);
		for(int i=0; i<teams; i++) {
			kachiten[i][1]=i;
		}
		for(int i=0; i<teams*(teams-1)/2; i++) {
			int[] tmp=new int[4];
			for(int j=0; j<4; j++) {
				tmp[j]=sc.nextInt()-1;
			}
			if(tmp[2]==tmp[3]) {
				kachiten[tmp[0]][0]++;
				kachiten[tmp[1]][0]++;
			}
			if(tmp[2]>tmp[3]) {
				kachiten[tmp[0]][0]+=3;
			}
			if(tmp[2]<tmp[3]) {
				kachiten[tmp[1]][0]+=3;
			}
		}
		quick_sort(kachiten,0,teams-1);
		int[] rank=new int[teams];
		int now=kachiten[teams-1][0];
		int jyuni=1;
		for(int i=0; i<teams; i++) {
			if(now==kachiten[teams-1-i][0]){
				rank[kachiten[teams-1-i][1]]=jyuni;
				now=kachiten[teams-1-i][0];
			}
			else if(now!=kachiten[teams-1-i][0]) {
				jyuni=teams-(teams-1-i);
				rank[kachiten[teams-1-i][1]]=jyuni;
				now=kachiten[teams-1-i][0];
			}
		}
		for(int i=0; i<teams; i++) {
			pl(rank[i]);
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static void quick_sort(int[][] d, int left, int right) {
		if (left>=right) {
			return;
		}
		int p = d[(left+right)/2][0];
		int l = left, r = right;
		int tmp,tmp1,tmp2;
		while(l<=r) {
			while(d[l][0] < p) { l++; }
			while(d[r][0] > p) { r--; }
			if (l<=r) {
				tmp = d[l][0]; d[l][0] = d[r][0]; d[r][0] = tmp;
				tmp1=d[l][1]; tmp2=d[r][1]; d[l][1]=tmp2; d[r][1]=tmp1;
				l++; r--;
			}
		}
		quick_sort(d, left, r);
		quick_sort(d, l, right);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 31312
#include<stdio.h>
#define N 100

void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  
  int length,n[N],i,j,tmp,count=0;
  
  scanf("%d",&length);
  
  for(i = 0;i < length;i++){
    
    scanf("%d",&n[i]);
  }
  
  for(i = 0;i < length;i++){
    for(j = length - 1;j > i;j--){
      
      if(n[j] < n[j - 1]){
	tmp = n[j];
	n[j] = n[j-1];
	n[j-1] = tmp;
	count++;
      }
    } 
  } 

  trace(n,length);

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 604
// Problem : D - Caracal vs Monster
// Contest : AtCoder - AtCoder Beginner Contest 153
// URL : https://atcoder.jp/contests/abc153/tasks/abc153_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    cin>>n;
    int ans = 0, cur = 1;
    while(n){
        n /= 2;
        ans += cur;
        cur *= 2;
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<queue>
#include<vector>
#include<utility>
#define mp make_pair
using namespace std;
typedef pair<int, int>  pii;
typedef pair<int, pii>  piii;//distinct, x, y
typedef pair<int ,piii> robot;//cost, piii

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

int main(int argc, char *argv[]){
  int w, h;
  const int INF = 1e8;
  while(cin >> w >> h, w){
    int grid[h][w];
    int dp[4][h][w];
    int cost[4];//straight, right, back, left
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < h; j++) {
        for (int k = 0; k < w; k++) {
          dp[i][j][k] = INF;
        }
      }      
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> grid[i][j];
      }
    }
    for (int i = 0; i < 4; i++) {
      cin >> cost[i];
    }
      
    priority_queue<robot, vector<robot>, greater<robot> > que;
    dp[0][0][0] = 0;
    que.push(mp(dp[0][0][0], mp(0, mp(0,0))));

    while(!que.empty()){
      robot r = que.top();que.pop();
      int x, y, dist, c;
      x    = r.second.second.first;
      y    = r.second.second.second;
      dist = r.second.first;
      c    = r.first;
      // std::cout << "dist:" << dist << std::endl;
      // std::cout << "   x:" << x    << std::endl;
      // std::cout << "   y:" << y    << std::endl;
      // std::cout << "cost:" << c    << std::endl;
      
      for (int i = 0; i < 4; i++) {
        int nd = (dist + i)%4, nc = c + cost[i];
        int nx = x + dx[nd], ny = y + dy[nd];
        if(grid[y][x] == i)nc -= cost[i];
        if(0 <= nx && nx < w &&
           0 <= ny && ny < h &&
           nc < dp[nd][ny][nx]){
          dp[nd][ny][nx] = nc;
          que.push(mp(nc, mp(nd, mp(nx, ny))));
        }
      }
    }
    int ans = INF;
    for (int i = 0; i < 4; i++) {
      ans = min(ans, dp[i][h - 1][w - 1]);
    }
    // for (int i = 0; i < 4; i++) {
    //   std::cout << "i:" << i << std::endl;
    //   for (int j = 0; j < h; j++) {
    //     for (int k = 0; k < w; k++) {
    //       if(dp[i][j][k] == INF)
    //         std::cout << "INF" << " ";
    //       else printf("%3d ", dp[i][j][k]);
    //     }
    //     std::cout << std::endl;
    //   }
    // }
    
    std::cout << ans << std::endl;
  }
  
  return 0;
}

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

int main() {
  int a,b;
  1 <= a,b <= 10000;
  cin >> a >> b;
  if ((a*b)%2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int a;multiset<int> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.insert(a);
    }
    int Ans=0;
    while(A.size()>=2){
        decltype(A)::iterator it = A.end();
        it--;
        int p=*it;
        A.erase(it);
        int K=(int)pow(2,(int)log2(p));
        K*=2;
        decltype(A)::iterator it2= A.find(K-p);
        if(it2 != A.end()){
            Ans++;
            A.erase(it2);
        }
        /*
        decltype(A)::iterator it3 = A.begin();
        while(it3!=A.end()){
            cout << *it3 << " ";
            it3++;
        }cout << endl;*/
    }
    cout << Ans << endl;
    return 0;
}



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

int main()
{
    int K, A, B, i;
    cin >> K;
    cin >> A;
    cin >> B;

    for (i = A; i < B + 1; i++)
    {
        if ((i % K) == 0)
        {
            cout << "OK";
            break;
        }
        else if (i == B)
        {
            cout << "NG";
            break;
        }
    }
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.At_Coder_Beginner_Contest_169
{
    class C
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long A = long.Parse(input[0]);
            decimal B = decimal.Parse(input[1]);

            Console.WriteLine(Math.Truncate(A * B));

        }
    }
}


Measured memory_bytes: 27616