akhauriyash/Code-Regression huggingface dataset:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

K = ni()
if K <=9: 
    print(K)
    exit(0)

u = []
dp = [[1] * 10,] 
sum = 0
for j in range(1,10):
    sum += dp[0][j]
# print(sum)
u.append(sum)
for i in range(1,10):
    a = dp[i-1]
    b = [a[0]+a[1],]
    for j in range(1,9):
        b.append(a[j-1]+a[j]+a[j+1])
    b. append(a[8]+a[9])
    dp.append(b)
    # print(dp)
    for j in range(1,10):
        sum += dp[i][j]
    # print(sum)
    u.append(sum)
# print(u)

def ggg(upN,keta,n):
    # print("ggg",upN,keta,n)
    s = 0
    start = max(upN-1,0)
    end = min(upN+ 1,9)
    for i in range(start, end+1):
        #print("keta",keta,start,"N",n,s,dp[keta -1][i])
        if n <= s + dp[keta -1][i]:
            #print("debug")
            if keta == 1:
                    # print("deb2")
                    return i
            else:
                return i * 10 **(keta -1) + ggg(i,keta-1,n -s)
        s += dp[keta-1][i]
        #print("xxx",i,s)
    print("Erorr ggg",upN,keta,n)
    exit(-1)

def fff (keta,n):
    #print("fff",keta,n)
    s = 0
    for i in range(1,10):
        if n <= s + dp[keta-1][i]:
            return i * 10 ** (keta-1) + ggg(i,keta-1,n-s)
        s += dp[keta-1][i]
    print("Error")
    exit(-1)


for i in range(1,10):
    if K <= u[i]:
        print(fff(i+1,K-u[i-1]))
        exit(0)



Measured memory_bytes: 3192
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(m,vector<int>());
    vector<int> b(m);
    rep(i,m){
        int k;
        cin >> k;
        rep(j,k){
            int q;
            cin >> q;
            a[i].push_back(q);
        }
    }
    rep(i,m){
        cin >> b[i];
    }
    ll ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        bool w = true;
        rep(i,m){
            int sum = 0;
            for(int v:a[i]){
                if((1<<(v-1)) & bit){
                    sum++;
                }
            }
            if(sum%2!=b[i]){
                w = false;
            }
        }
        if(w){
            ans++;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	n := nextInt64()
	a := make([]int64, n)
	total := nextInt64()
	a[0] = total
	for i := int64(1); i < n; i++ {
		a[i] = nextInt64()
		total = total ^ a[i]
	}
	for i := int64(0); i < n; i++ {
		fmt.Print(a[i] ^ total)
		fmt.Print(" ")
	}
	fmt.Println("")
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()


void solve(){
  int k, x;
  cin >> k >> x;
  FOR(i,x-k+1,x+k) cout << i << ' ';
}

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

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

#define MAXL (500010)

int n, l, sum_digit;
int num[MAXL];
char str[MAXL];

bool check(int k){
	num[0] += 9;
	sum_digit += 9;
	for(int i = 0; i < n; ++ i){
		if(num[i] < 10){
			break;
		}
		sum_digit -= num[i];
		sum_digit += num[i] / 10 + num[i] % 10;
		num[i + 1] += num[i] / 10;
		num[i] %= 10;
	}
	if(num[n]) ++ n;
	return sum_digit <= 9 * k;
}

int main(){
	scanf("%s", str);
	l = n = strlen(str);
	std::reverse(str, n + str);
	for(int i = 0; i < n; ++ i){
		num[i] = (str[i] - '0') * 9;
	}
	for(int i = 0; i < n; ++ i){
		num[i + 1] += num[i] / 10;
		num[i] %= 10;
	}
	if(num[n]) ++ n;
	for(int i = 0; i < n; ++ i){
		sum_digit += num[i];
	}
	for(int i = 1; i <= l; ++ i){
		if(check(i)){
			return printf("%d\n", i), 0;
		}
	}
	return 0;
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>=0?(a):-(a))

const int mod=998244353;

typedef long long int int64;

int modPow(int r,int64 n){
  int t=1;
  int s=r;
  while(n>0){
    if(n%2) t=(int64)t*s%mod;
    s=(int64)s*s%mod;
    n>>=1;
  }
  return t;
}

typedef struct masu{
  int a,b,c;
} node;

int cmpE(const void *a,const void *b){
  node *p=(node *)a;
  node *q=(node *)b;
  if(p->a!=q->a) return p->a-q->a;
  return p->b-q->b;
}

int calcWay(int n,node *e,int len){
  int64 cnt=(int64)(n-3)*(n-2)/2;
  int ok=1;
  int i=0;
  while(i<len){
    cnt--;
    i++;
    if(i<len && cmpE(e+i,e+i-1)==0){
      if(e[i].c!=e[i-1].c){
	ok=0;
      }
      i++;
    }
  }
  return (int64)ok*modPow(2,cnt)%mod;
}

int cmpD(const void *a,const void *b){
  node *p=(node *)a;
  node *q=(node *)b;
  int x=MAX(p->a,p->b);
  int y=MAX(q->a,q->b);
  if(x!=y) return x-y;
  return (p->a-p->b)-(q->a-q->b);
}

int popcnt(int n){
  int res=0;
  while(n){
    res+=n&1;
    n>>=1;
  }
  return res;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  node *d=(node *)calloc(m,sizeof(node));
  node *e=(node *)calloc(m,sizeof(node));
  int dlen=0;
  int elen=0;
  while(m--){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(ABS(a-b)<=2){
      d[dlen++]=(node){a,b,c};
    } else {
      if(b<a){
	int s=a;
	a=b;
	b=s;
      }
      e[elen++]=(node){a,b,c};
    }
  }
  qsort(d,dlen,sizeof(node),cmpD);
  qsort(e,elen,sizeof(node),cmpE);
  int way=calcWay(n,e,elen);
  int dp[4]={0,0,0,0};
  int i,j,k;
  for(i=0;i<(1<<4);i++){
    if(popcnt(i)&1) continue;
    int ok=1;
    for(j=0;j<dlen && cmpD(d+j,&((node){2,1,0}))<=0;j++){
      int shift=d[j].a-1+2*(d[j].b-1);
      if(d[j].c!=((i>>shift)&1)) ok=0;
    }
    dp[i>>3]+=ok;
  }
  int now=0;
  k=0;
  for(i=3;i<=n;i++){
    while(k<dlen && cmpD(d+k,&((node){i-2,i,0}))<0) k++;
    int next=now^2;
    dp[next]=dp[next+1]=0;
    for(j=0;j<(1<<5);j++){
      if(popcnt(j)%2==1) continue;
      int ok=1;
      for(int l=k;l<dlen && cmpD(d+l,&((node){i,i-2,0}))<=0;l++){
	int shift=cmpD(d+l,&((node){i-2,i,0}));
	if(d[l].c!=((j>>shift)&1)) ok=0;
      }
      if(ok){
	int index=next+((j>>2)&1);
	dp[index]=(dp[index]+dp[now+popcnt((j>>1)&7)%2])%mod;
      }
    }
    now=next;
  }
  int ans=(int64)(dp[now]+dp[now+1])*way%mod;
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 1916
/*
 * aoj/dpl_2_a_3rd/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

class Bits {
public:
  inline static bool included(ll S, ll v) {
    return ((S&(1<<v))>>v) == 1;
  }
  inline static ll add(ll S, ll v) {
    return S|(1<<v);
  }
  inline static ll remove(ll S, ll v) {
    return S&(~(1<<v));
  }
};

const ll INF = 100000000000000000;
const int MAX = 20;
int V, E;
int G[MAX][MAX] = {-1};

ll all = 1;
// dp[S][i] := S: これまでに訪れた頂点集合（iを含む）, i: 今いる頂点
ll dp[0b111111111111111111][MAX];

void input() {
  memset(G, -1, sizeof(G));
  cin >> V >> E;
  ll v, u, d;
  loop(n,0,E) {
    cin >> v >> u >> d;
    G[v][u] = d;
  }

  for (int v=0; v<V; v++) {
    all = Bits::add(all, v);
  }
}

void solve() {
  loop(S,0,all+1) loop(i,0,V+1) dp[S][i] = INF;
  dp[1][0] = 0;
  for (ll S=1; S<=all; S++) {
    for (int to=1; to<V; to++) {
      if (!Bits::included(S, to)) continue;
      for (int from=0; from<V; from++) {
        if (G[from][to] == -1) continue;
        if (!Bits::included(S, from)) continue;
        if (chmin(dp[S][to], dp[Bits::remove(S, to)][from] + G[from][to])) {
          // cout << S << " " << to << " " << from << " " << dp[S][to] << endl;
        }
      }
    }
  }
  ll min_ = INF;
  loop(i,0,V) {
    if (dp[all][i] != INF && G[i][0] >= 0) {
      chmin(min_, dp[all][i] + G[i][0]);
    }
  }
  if (min_ == INF) cout << -1 << endl;
  else cout << min_ << endl;
}

void dump() {
  for (ll S=0; S<all; S++) {
    for (int i=0; i<V; i++) {
      if (!Bits::included(S, i)) continue;
      cout << S << ": i = " << i << " dp = " << dp[S][i] << endl;
    }
  }
}

int main() {
  // cout.precision(15);
  input();
  solve();
  // dump();
  return 0;
}



Measured memory_bytes: 8260
package main

import "fmt"

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		c := a % b
		a, b = b, c
	}
	return a
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	var n, t int
	fmt.Scan(&n)
	ans := 1
	for range make([]struct{}, n) {
		fmt.Scan(&t)
		ans = lcm(ans, t)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque, defaultdict
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def main():
    N, D = mi()
    print(ceil(N / (2 * D + 1)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
n = int(input())
h = list(map(int, input().split()))

for i in range(n-1, 0, -1):
  sa = h[i-1] - h[i]
  
  if sa > 1:
    print("No")
    exit()
  elif sa > 0:
    h[i-1] -= 1
  else:
    pass

print("Yes")

Measured memory_bytes: 14252
#include<stdio.h>
int main()
{
	int n,count=0;
    int i,j;
    scanf("%d",&n);
    for(i=1;i<10;i++)
    {
		for(j=1;j<10;j++)
        {
			if(n==i*j)
            {printf("Yes");
              count=1;
            break;
            }
        }
      if(count==1)
      break;
    }
  if(count==0)
    printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
ll gcd(ll c, ll d){
  if(d==0) return c;
  else return gcd(d,c%d);
}
ll lcm(ll c, ll d){
  return c*d/gcd(c,d);
}
ll f(ll x,ll c,ll d){
  ll res=x;
  res-=x/c;
  res-=x/d;
  res+=x/lcm(c,d);
  return res;
}
int main()	{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans=f(b,c,d)-f(a-1,c,d);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> p(n);
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
    }
    int ans = 0;
    std::vector<int> v(3);
    for (int i = 0; i < n - 2; i++) {
        for (int j = 0; j < 3; j++) v[j] = p[i + j];
        std::sort(v.begin(), v.end());
        if (v[1] == p[i + 1]) ans++;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program {
    static void Main( string[] args )
    {
        string[] s = Console.ReadLine().Split();
        int a = int.Parse( s[ 0 ] );
        int b = int.Parse( s[ 1 ] );
        int c = int.Parse( s[ 2 ] );
        Console.WriteLine( a < b ? ( b < c ? "Yes" : "No" ) : "No" );
    }
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_K 100010

ll N, K;
vector<ll> A;
// 残りの石の数が i で、現在 player のターンの時に、
// 勝利するプレイヤーを返す
ll dp[MAX_K][2];

enum Player { Taro = 0, Jiro = 1 };

signed main()
{
    cin >> N >> K;
    A.assign(N, 1);
    REP(i, N) { cin >> A[i]; }
    MINUS(dp);

    dp[0][Taro] = Jiro;
    dp[0][Jiro] = Taro;
    for (ll i = 1; i <= K; ++i) {
        for (ll player = 0; player <= 1; ++player) {
            ll next_player = (player == Taro) ? Jiro : Taro;
            dp[i][player] = next_player;
            // j 個取るパターンを全て試す
            for (auto& a : A) {
                if (i - a < 0) { break; }
                if (dp[i - a][next_player] == player) {
                    dp[i][player] = player;
                    break;
                }
            }
        }
    }

    ll ans = dp[K][Taro];
    printf("%s\n", ans == Taro ? "First" : "Second");
    return 0;
}


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

int n, a[100], c[100];

int main(){
  cin >> n;
  int sum = 0;
  rep(i, n){ cin >> a[i]; a[i]--; }
  rep(i, n){ int b; cin >> b; sum += b; }
  rep(i, n - 1) cin >> c[i];
  rep(i, n - 1){
    if(a[i + 1] == a[i] + 1){
      sum += c[a[i]];
    }
  }
  cout << sum << endl; 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 50
typedef long long LL;
int n,k,ans=1;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)ans=min(ans+k,ans<<1);
	printf("%d\n",ans);	
	return 0;
}

Measured memory_bytes: 256
t,n,m,r;main(){for(scanf("%d",&t);t--;printf("%d\n",r))for(scanf("%d%d",&n,&m),r=0;m-n;m/=2,n/=2)r+=(n%2+2)%2+(m%2+2)%2,n+=(n%2+2)%2,m-=(m%2+2)%2;}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define rep1(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define PI acos(-1.0)
#define LONG_LONG_MAX 9223372036854775807
#define LONG_LONG_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int n, m;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    vector<int> a(3);
    a[0] = n+m;
    a[1] = n-m;
    a[2] = n*m;
    cout << *max_element(a.begin(), a.end()) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL  INF=1<<31;



int main(){
     LL n,w;
     cin>>n>>w;
     LL shina[100][2];
     for(int i=0;i<n;i++){
          for(int j=0;j<2;++j){
               cin>>shina[i][j];
          }
     }
     LL dp[101][100001]={0};
     
     for(int i=0;i<n;++i){
          for(int j=0;j<=w;++j){
               dp[i+1][j]=dp[i][j];
               if(shina[i][0]<=j){
                    dp[i+1][j]=max(dp[i][j],dp[i][j-shina[i][0]]+shina[i][1]);
               }
          }

     }
     cout<<dp[n][w];
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll pow(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return pow(x * x % mod, y / 2, mod) % mod;
    } else {
        return x * pow(x, y - 1, mod) % mod;
    }
}

ll calc_cost(vector<ll> vec, ll target){
    ll sum_vec = accumulate(vec.begin(), vec.end(), 0);
    ll cost = 10 * (vec.size() - 1);
    cost += abs(target - sum_vec);
    return cost;
}

void Main() {
    // 考察: 順番は変えられる，合成->(加算or減算)でいい
    // 木の本数が少ないので(どれにも使わない, A, B, C)用の木のプールを用意して全ての組み合わせを探索
    ll N, A, B, C; cin >> N >> A >> B >> C;
    vector<ll> l(N); rep(i, N){cin >> l.at(i);}
    ll best_cost = INF;

    // bit全探索の4乗ver.
    rep(i, pow(4, N, MOD)){
        ll cost = 0;
        vector<ll> vec1, vec2, vec3;
        rep(j, N){
            switch (i / pow(4, j, MOD) % 4){
                case 0: break; // do nothing
                case 1: vec1.push_back(l.at(j)); break;
                case 2: vec2.push_back(l.at(j)); break;
                case 3: vec3.push_back(l.at(j)); break;
            }
        }

        // 一本も木が入らないパターンを排除
        if (vec1.size() == 0 || vec2.size() == 0 || vec3.size() == 0){continue;}
        cost += calc_cost(vec1, A);
        cost += calc_cost(vec2, B);
        cost += calc_cost(vec3, C);
        if (cost < best_cost){best_cost = cost;}
    }
    cout << best_cost << endl;
}

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


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def main():
    S = input().strip()
    y = int(S[:4])
    m = int(S[5:7])
    if y == 2019 and m >= 5:
        print("TBD")
    else:
        print("Heisei")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> a(n),b(n*n);
    rep(i,n)cin >> a[i];
    rep(i,n)rep(j,n){
        if(i==j)b[i*n+j]=a[j];
        else if(i<j)b[i*n+j]=b[i*n+j-1]+a[j];
    }
    ll x_max=0;
    for(int i=40;i>=0;--i){
        //もしx_max+(1<<i)が立っているようなb[j]がk個以上あれば、そのk個のandはx_maxの下界
        int cnt=0;
        rep(j,n*n)if(((x_max+(1LL<<i))&b[j])==(x_max+(1LL<<i)))++cnt;
        if(cnt>=k)x_max+=(1LL<<i);
    }
    cout << x_max << endl;
    return 0;
}

Measured memory_bytes: 8064
//作成日：4/20

//日付を受け取る変数
var day = Int(readLine()!)!

//条件分岐
if (day == 25){
  print ("Christmas")
}
else if (day == 24){
  print ("Christmas Eve")
}
else if (day == 23){
  print ("Christmas Eve Eve")
}
else{
  print ("Christmas Eve Eve Eve")
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,a,b;cin >> n >> a >> b;
    vector<ll> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    ll l=0,r=1e10;
    while(r-l>1){
        ll mid=(l+r)/2;
        ll cnt=0;
        for(int i=0;i<n;i++){
            cnt+=(max(0LL,h[i]-b*mid)+a-b-1)/(a-b);
        }
        if(cnt>mid){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    cout << r << endl;
}

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

using namespace std;

int main() {
    unsigned long long sum = 0;
    int N;
    cin >> N;
    long A[N];
    for (int i = 0; i < N; i++) cin >> A[i];

    long maxHeight = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] < maxHeight) {
            sum += maxHeight - A[i];
        } else {
            maxHeight = A[i];
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 5160
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a<b){
            System.out.println("a < b");
        }else if(a>b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
        sc.close();
    }
}


Measured memory_bytes: 26220
import sys
import copy
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

def bfs():
    d = [[-1] * w for _ in range(h)]

    que = deque([])
    que.append((0, 0))
    d[0][0] = 0

    while que:
        x, y = que.popleft()
        if x == h - 1 and y == w - 1:
            break
        for dx, dy in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            nx = x + dx
            ny = y + dy
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == -1:
                que.append((nx, ny))
                d[nx][ny] = d[x][y] + 1

    return d[h - 1][w - 1]

h, w = na()
maze = [list(input()) for _ in range(h)]
ct = 0
for i in range(h):
    ct += maze[i].count("#")
res = bfs()
if bfs() == -1:
    print(-1)
else:
    print(h * w - bfs() - 1 - ct)


Measured memory_bytes: 5228
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a[3][114]={};
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }

    int ans=0;
    for(int i=1;i<=n;i++){
        int ma=0;
        int f=0;
        for(int j=1;j<=n;j++){
            if(i==j){
                f=1;
                ma+=a[1][i];
                ma+=a[2][i];
            }else if(f==0){
                ma+=a[1][j];
            }else{
                ma+=a[2][j];
            }
        }
        if(ma>ans){
            ans=ma;
        }
    }
    cout<<ans<<endl;
}   





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

int main(){
	int a,b,d,f;
	double r;
	cin >> a >> b;
 d = a / b;
 f = a % b;
 r = 1.000000* a /b ;
cout << d << " "<< f << " "<< fixed<< setprecision(10) << r << endl; 
return 0;
}



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

#define INT_MAX	1000000000
int N, A, B, C;
int take[8];

int dfs( int depth, int a, int b, int c )
{
	if( depth == N )
	{
		if( !a || !b || !c ) return INT_MAX;
		else return abs( A - a ) + abs( B - b ) + abs( C - c )-30;
	}

	int ret0 = dfs( depth + 1, a, b, c );
	int ret1 = dfs( depth + 1, a + take[depth], b, c ) + 10;
	int ret2 = dfs( depth + 1, a, b + take[depth], c ) + 10;
	int ret3 = dfs( depth + 1, a, b, c + take[depth] ) + 10;

	return min( { ret0, ret1, ret2, ret3 } );
}

int main()
{
	cin >> N;
	cin >> A >> B >> C;
	for( int i = 0; i < N; ++i )
		cin >> take[i];
	cout << dfs( 0, 0, 0, 0 ) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from operator import add


class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


def main():
    N, Q = map(int, input().split())
    C = list(map(int, input().split()))

    P = [[] for _ in range(N)]
    for i, c in enumerate(C):
        P[c - 1].append(i)

    right = [0] * N
    for p in P:
        if len(p):
            right[p.pop()] = 1
    seg = SegmentTree(right, add, 0)

    query = [[] for _ in range(N)]
    for i, s in enumerate(sys.stdin.readlines()):
        l, r = map(int, s.split())
        query[r - 1].append((l - 1, i))

    ans = [None] * Q

    cur = N - 1
    for r, q in enumerate(reversed(query)):
        r = (N - 1) - r
        while q:
            l, i = q.pop()
            while r < cur:
                c = C[cur] - 1
                p = P[c]
                if len(p):
                    seg.update(p.pop(), 1)
                cur -= 1
            tmp = seg.get(l, r + 1)
            ans[i] = tmp

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 283552
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

signed main()
{
    int Q; cin >> Q;

    rep(_, Q) {
        int c, a, n; cin >> c >> a >> n;

        int ans = 0;

        while (n) {
            if (a == 0 || c == 0) break;
            -- c, -- a, -- n;
            ans++;
        }

        while (a) {
            if (c <= 1) break;
            c -= 2, -- a;
            ans++;
        }

        while (c) {
            if (c <= 2) break;
            c -= 3;
            ans++;
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second


int par[500000];
int urank[500000];

void init(int n) {//初期化、引数は要素数
	for (int i = 0; i < n; i++) {
		par[i] = i;
		urank[i] = 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 (urank[x] < urank[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (urank[x] == urank[y]) urank[x]++;
	}
}

bool same(int x, int y) {//同じか判定
	return find(x) == find(y);
}

struct edge { ll u, v, cost; };//無向でも一つでいい
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
edge es[500000];
int V, E; // 頂点数と辺数
int kruskal() {
	sort(es, es + E, comp); // edge.costが小さい順にソートする
	init(V); // Union-Findの初期化
	int res = 0;
	for (int i = 0; i < E; i++) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

typedef pair<ll,ll> P;

ll x[100000],y[100000];

P p[100000];
int n;

int main(){
	cin >> n;
	V = n;
	REP(i,n) {
		cin >> x[i] >> y[i];
	}

	REP(i,n) {
		p[i].fi = x[i];p[i].sc = i;
	}

	sort(p,p+n);

	REP(i,n - 1) {
		es[E++] = (edge) {p[i].sc,p[i + 1].sc , abs(p[i].fi - p[i + 1].fi)};
		es[E++] = (edge) {p[i + 1].sc,p[i].sc , abs(p[i + 1].fi - p[i].fi)};
	}
	REP(i,n) {
		p[i].fi = y[i];p[i].sc = i;
	}

	sort(p,p+n);

	REP(i,n - 1) {
		es[E++] = (edge) {p[i].sc,p[i + 1].sc , abs(p[i].fi - p[i + 1].fi)};
		es[E++] = (edge) {p[i + 1].sc,p[i].sc , abs(p[i + 1].fi - p[i].fi)};
	}

	cout << kruskal() << endl;
	return 0;
}


Measured memory_bytes: 18816
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>
 
using namespace std;
long long MOD = 1000000007LL;
 
int main() {
	int X;
	cin >> X;
	int i = X / 100;
	if (i * 100 <= X && X <= i * 105) {
		cout << 1 << endl;
		return 0;
	}
 
	cout << 0 << endl;
 
	return 0;
}

Measured memory_bytes: 256
N = int(input())
def main():
    head_prob_table = [[0.0] * (N+1) for i in range(N)]
    head_prob = list(map(float, input().split()))

    head_prob_table[0][1] = head_prob[0]
    head_prob_table[0][0] = 1-head_prob[0]

    for i in range(1, N):
        for j in range(i+2):
            head_prob_table[i][j] += head_prob_table[i-1][j] * (1 - head_prob[i])
            if j > 0:
                head_prob_table[i][j] += head_prob_table[i-1][j-1] * head_prob[i]

    print(sum(head_prob_table[N-1][(N+1)//2:]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 222828
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main() {
    int H,W,N;
    cin >> H >> W >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    vector< vector <int> > ans(H, vector<int> (W));
    int cnt=0;
    int i=0;
    for(int h=0; h<H; h++){
        if(h%2==0){
            for(int w=0; w<W; w++){
                cnt++;
                ans[h][w]=i+1;
                if(cnt==a[i]){
                    cnt=0;
                    i++;
                }
            }
        }else{
            for(int w=0; w<W; w++){
                cnt++;
                ans[h][W-w-1]=i+1;
                if(cnt==a[i]){
                    cnt=0;
                    i++;
                }
            }
        }
    }

    for(int h=0; h<H; h++){
        for(int w=0; w<W-1; w++){
            cout << ans[h][w] << ' ';
        }
        cout << ans[h][W-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> e(n);
    vector<int> degree(n);
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        ++degree[--u];
        ++degree[--v];
        e[u].push_back(v);
        e[v].push_back(u);
    }
    string s;
    cin >> s;
    vector<int> color(n);
    for (int i = 0; i < n; ++i)
        color[i] = s[i] == 'B' ? 0 : 1;
    queue<int> que;
    for (int i = 0; i < n; ++i)
        if (degree[i] <= 1 && color[i] == 0)
            que.push(i);
    int rest = n;
    vector<bool> removed(n);
    while (!que.empty()) {
        int u = que.front();
        removed[u] = true;
        --rest;
        que.pop();
        for (int v : e[u])
            if (--degree[v] == 1 && color[v] == 0)
                que.push(v);
    }
    if (rest <= 2) {
        cout << rest << "\n";
        return 0;
    }
    int ans = 2 * rest - 2;
    for (int i = 0; i < n; ++i) {
        if (!removed[i]) {
            color[i] ^= degree[i] % 2;
            ans += color[i];
        }
    }
    vector<int> dis;
    auto bfs = [&](int s) {
        queue<int> que;
        dis.assign(n, -1);
        dis[s] = color[s];
        que.push(s);
        while (!que.empty()) {
            int u = que.front();
            que.pop();
            for (int v : e[u]) {
                if (removed[v] || dis[v] != -1)
                    continue;
                dis[v] = dis[u] + color[v];
                que.push(v);
            }
        }
        int t = s;
        for (int i = 0; i < n; ++i)
            if (dis[i] > dis[t])
                t = i;
        return t;
    };
    for (int i = 0; i < n; ++i) {
        if (!removed[i]) {
            int s = bfs(i);
            s = bfs(s);
            cout << ans - 2 * dis[s] << "\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 7800
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 1000000007
#pragma GCC optimize ("-O3")
#define mod 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 

template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<a[i]<<c;
	cout<<"\n";
}

lli tmod(lli x,lli m=mod){return (x%m+m)%m;}//USE AT YOUR OWN RISK
lli power(lli x, lli y,lli m=mod) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%m; 
        y = y>>1; 
        x = (x*x)%m;  
    }
    if(res<0)
       res+=m; 
    return res; 
}

// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }

int main() 
{ 
    // fact[0]=1;
    // f(i,1,2000001)fact[i]=(i*fact[i-1])%mod;
    fastio;
    int t;
    // cin>>t;	
    t=1;
	while(t--){
        string s;cin>>s;
        if(s[2]!=s[3] || s[4]!=s[5]){
            cout<<"No\n";
            return 0;
        }
        // if(s[3]==s[4]){
        //     cout<<"No\n";
        //     return 0;
        // }
        cout<<"Yes\n";
    }   
    return 0; 	
}


Measured memory_bytes: 256
// AtCoder agc002

#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define iii pair<int,ii>
#define se second
#define fi first
using namespace std;
string a[111];
int main(){
    //cout.precision(12);
    //ifstream fin("in");
    int n,l; cin>>n>>l;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++)cout<<a[i];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
// #define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
vi f, g;
vvi adj, prefix, suffix, tree;
vector<map<int, int>> pos;
int n, mod, u, v;
void dfs(int v, int p)
{
    f[v] = 1;
    for (auto it : adj[v])
    {
        if (it == p)
            continue;
        tree[v].pb(it);
        dfs(it, v);
        f[v] *= (1 + f[it]);
        f[v] %= mod;
    }
    for (int i = 0; i < tree[v].size(); i++)
    {
        if (i == 0)
            prefix[v].pb(1 + f[tree[v][i]]);
        else
            prefix[v].pb(prefix[v].back() * (1 + f[tree[v][i]]));
        prefix[v].back() %= mod;
    }
    for (int i = (int)tree[v].size() - 1; i >= 0; i--)
    {
        if (i == (tree[v].size() - 1))
            suffix[v].pb(1 + f[tree[v][i]]);
        else
            suffix[v].pb(suffix[v].back() * (1 + f[tree[v][i]]));
        suffix[v].back() %= mod;
    }
    return;
}
void dfs2(int v, int p)
{
    for (int i = 0; i < tree[v].size(); i++)
    {
        int next = tree[v][i];
        g[next] = g[v];
        if (i > 0)
            g[next] *= prefix[v][i - 1];
        g[next] %= mod;
        if (i < (tree[v].size() - 1))
            g[next] *= suffix[v][tree[v].size() - i - 2];
        g[next]++;
        g[next] %= mod;
        dfs2(next, v);
    }
    return;
}
signed main()
{
    cin >> n >> mod;
    f.resize(n + 1, 1);
    g.resize(n + 1, 1);
    adj.resize(n + 1);
    prefix.resize(n + 1);
    suffix.resize(n + 1);
    pos.resize(n + 1);
    tree.resize(n + 1);
    for (int i = 1; i < n; i++)
    {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1, 1);
    g[1] = 1;
    dfs2(1, 1);
    for (int i = 1; i <= n; i++)
        cout << ((f[i] * g[i]) % mod) << endl;
    return 0;
}

Measured memory_bytes: 37136
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define print(n) std::cout << n << std::endl
#define FOR(i,n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
    string x;
    cin >> x;
    if(x[0] == x[2])print("Yes");
    else print("No");
}

Measured memory_bytes: 256
import math

n = int(input())
a = list(map(int, input().split()))

x = math.ceil((n - 3) / 2) + 1

cnt4 = 0
cnt2 = 0
for i in a:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 4 != 0 and i % 2 == 0:
        cnt2 += 1
     
if (cnt4 + cnt2//2) >= x:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15020
N, K = map(int, input().split())

########関数部分##############
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
############################
 
 
x10 = N
x2 = Base_10_to_n(x10, K)
print( len(x2) )#"100011"が表示される．

Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main()
{
    int a[105]={0},n,x,temp,i,j;
    cin>>x>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        a[temp]=1;
    }

    for(i=x,j=x;i>0||j<101;i--,j++)
        {
            if(a[i]==0)
            {
                cout<<i<<endl;
                return 0;
            }
            else if(a[j]==0)
            {
                cout<<j<<endl;
                return 0;
            }
        }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3668
// D - RGB Triplets
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	string s;
	cin >> n >> s;
	vector<pair<int, int> > a;

	vector<int> r(n + 1), g(n + 1), b(n + 1);
	for (int i = 0; i < n; i++) {
		r[i + 1] = r[i], g[i + 1] = g[i], b[i + 1] = b[i];
		if (s[i] == 'R') r[i + 1]++;
		else if (s[i] == 'G') g[i + 1]++;
		else if (s[i] == 'B') b[i + 1]++;
	}
	long long ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) continue;
			if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
				ans += b[n] - b[j];
			else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G'))
				ans += r[n] - r[j];
			else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
				ans += g[n] - g[j];
		}
	for (int k = 1; k < n / 2 + 1; k++)
		for (int i = 0; i + k + k < n; i++)
			if (s[i] != s[i + k] && s[i] != s[i + k + k] && s[i + k] != s[i + k + k]) ans--;

	cout << ans << endl;

	return 0;
}


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

using namespace std;

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

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

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

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

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

  int n, x; cin >> n >> x;
  vi m(n);
  int su = 0;
  int mi = INF;
  for(int i=0;i<n;++i) {
    cin >> m[i];
    su += m[i];
    mi = min(mi, m[i]);
  }
  cout << n + (x - su) / mi << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

const int Maxn = 1005;
const int Maxm = 5005;

int n;
vector <int> neigh[Maxn];
int X[Maxn];
int dp[Maxn];
bool has[Maxm];

bool Solve(int v)
{
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i];
		if (!Solve(u)) return false;
	}
	fill(has, has + Maxm, false); has[0] = true;
	int tot = 0;
	for (int i = 0; i < neigh[v].size(); i++) {
		int u = neigh[v][i]; tot += X[u] + dp[u];
		for (int j = Maxm - 1; j >= 0; j--) if (has[j]) {
			has[j] = false;
			if (j + X[u] < Maxm) has[j + X[u]] = true;
			if (j + dp[u] < Maxm) has[j + dp[u]] = true;
		}
	}
	int nd = X[v];
	while (nd >= 0 && !has[nd]) nd--;
	if (nd < 0) return false;
	dp[v] = min(tot - nd, Maxm);
	return true;
}

int main()
{
	scanf("%d", &n);
	for (int i = 2; i <= n; i++) {
		int p; scanf("%d", &p);
		neigh[p].push_back(i);
	}
	for (int i = 1; i <= n; i++)
		scanf("%d", &X[i]);
	printf("%s\n", Solve(1)? "POSSIBLE": "IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 384
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for n in range(1000):
        n = str(n).zfill(3)
        idx = 0
        for s in S:
            if s == n[idx]:
                idx += 1
                if idx == 3:
                    ans += 1
                    break

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int aa = a*a;
      int aaa = a*a*a;
      int xxx = (a+aa+aaa);
      System.out.print(xxx);
    }
}

Measured memory_bytes: 35632
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1 - i):
        if 10000 * (n - i - j) + 5000 * j + 1000 * i == y:
            print(n - i - j, j, i)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#define Find order_of_key
#define at find_by_order
#define x first
#define y second
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl '\n'


int main()
{
	string s,t;
	cin>>s>>t;
	size_t a=t.find(s);
	if(a==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3620