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

using Graph = vector<vector<int>>;

int main(){
  //点i,j間の最短距離はmin(|j - i|, |X-i| + |Y-j| + 1(この1はY - X), |X - j| + |Y - i| + 1)
  int N , X , Y;
  cin >> N >> X >> Y;
  vector<int>A(N,0); //カウントしていく k番目に入ってる個数
  //まずは最短距離を調べる
  int mind = 2000; // N < 2 * 10^3より，十分大きい値
  for(int i = 1; i <= N -1; i++){
    for(int j = i + 1 ; j <= N; j++){
      mind = min(abs(j - i), min(abs(X - i)+ 1 +abs(Y - j), abs(Y - i) + 1 + abs(X - j) ) ) ;
      A[mind]++;
    }
  }
  for(int k = 1; k < N; k++){
    cout << A[k] << endl;
  }
}


Measured memory_bytes: 256
#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<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	int N;
	cin >> N;

	int cnt = 0;
	vector<int> vH(N, 0);
	int prev = 0;
	rep(i, N) cin >> vH[i];

	int maxcnt = 0;
	for (int i = 1; i != N; ++i) {
		if (vH[i] <= vH[i - 1]) {
			cnt++;
		}
		else {
			if (maxcnt < cnt) {
				maxcnt = cnt;
			}
			cnt = 0;
		}
	}

	if (maxcnt < cnt) {
		maxcnt = cnt;
	}

	cout << maxcnt << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  ll N, A, B; cin >> N >> A >> B;
  auto d = B - A;
  if (d % 2 == 0) {
    auto ans = d / 2;
    cout << ans << CRLF;
  } else {
    auto a1 = (A-1 + B-1 + 1) / 2;
    auto a2 = (N-B + N-A + 1) / 2;
    auto ans = a1 < a2 ? a1 : a2;
    cout << ans << CRLF;
  }
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
from collections import deque
def bfs():
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

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

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1

    return d[gx][gy]

h,w  = map(int,input().split())
maze = [list(input()) for i in range(h)]
sx, sy = 0,0
gx,gy = h-1,w-1
black = 0
white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            white += 1
res = bfs()
if 0 < res < float("inf"):
    print(white-res-1)
else:
    print(-1)

Measured memory_bytes: 3316
function Time(x){
   var ary=x.split("-");
   ary=ary.map(function(v){
      v=v.split(":").map(Number);
      return (v[0]*60)+v[1];
   });
   return ary;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var a=arr.shift().split(" ");
a.shift();
var A=a.map(function(v){
   return Time(v);
});
var B=[];
var n=arr.shift()-0;
while(n--){
   var b=arr.shift().split(" ");
   b.shift();
   b=b.map(function(v){
      return Time(v);
   }); 
   B.push(b);
}
var C=[];
var m=arr.shift()-0;
while(m--){
   var c=arr.shift().split(" ");
   c.shift();
   c=c.map(function(v){
      return Time(v);
   }); 
   C.push(c);
}
var ans=0;
A.forEach(function(value){
   var cntB=0;
   var cntC=0;
   B.forEach(function(v){
      var flag=v.some(function(V){
         if(V[0]<=value[0] && value[1]<=V[1])return true;
      });
      if(flag)cntB++;
   });
   C.forEach(function(v){
      var flag=v.some(function(V){
         if(V[0]<=value[0] && value[1]<=V[1])return true;
      });
      if(flag)cntC++;
   });
   ans+=Math.min(cntB,cntC);
});
console.log(ans);

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

int main()
{
    int m,m1,n,n1,k;
    cin>>m>>m1>>n>>n1>>k;

   n=(n*60)+n1;
   n=n-k;
   m=(m*60)+m1;

 cout<<n-m<<endl;
}


Measured memory_bytes: 3624
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

# A=[3,2,2,4,1]
# B=[1,2,2,2,1]
l_ans=[]
for i in range(len(A)):
    
    sum_num=sum(A[:i+1])+sum(B[i:])
    l_ans.append(sum_num)
print(max(l_ans))


Measured memory_bytes: 2940
input()
A=[0]+list(map(int,input().split()))
H=len(A)
def h(i):
 l=2*i;r,g=l+1,[i,l][l<H and A[i]<A[l]]
 if r<H and A[g]<A[r]:g=r
 if g!=i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 65084
import sys
input = sys.stdin.readline
N,K=map(int,input().split())
import numpy as np
hights=np.array(list(map(int,input().split())))
steps=np.array([10**10]*N)
steps[0]=0
for i in range(N-1):
    gaps=hights[i+1:i+K+1]-hights[i]
    gaps=np.abs(gaps)
    gaps+=steps[i]
    steps[i+1:i+K+1]=np.minimum(steps[i+1:i+K+1],gaps)
print(steps[-1])

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

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

	cin >> n;

	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
			if(i*j==n)
			{
				cout << "Yes" << '\n';
				return 0;
			}
		}
	}

	cout << "No" << '\n';
	
	return 0;
}


Measured memory_bytes: 3616
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=405;
int fac[N],ifac[N],bin[N],f[N][N][N],a[N],b[N],n,s1,s2;
inline void init(R int n=400){
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	init();
	fp(i,1,n)scanf("%d%d",&a[i],&b[i]);
	f[0][0][0]=P-1;
	fp(i,1,n){
		fp(j,0,s1)fp(k,0,s2)f[i][j][k]=f[i-1][j][k];
		bin[0]=1;fp(j,1,b[i]-1)bin[j]=mul(bin[j-1],a[i]);
		fp(j,0,b[i]-1)bin[j]=mul(bin[j],ifac[j]);
		fp(j,0,s1)fp(k,0,s2)fp(v,0,b[i]-1)
			upd(f[i][j+v][k+a[i]],P-mul(f[i-1][j][k],bin[v]));
		s1+=b[i]-1,s2+=a[i];
	}
	R int res=0;
	fp(i,0,s1)fp(j,1,s2){
		R int ret=mul(f[n][i][j],fac[i]);
		ret=mul(ret,ksm(j,P-1-i));
		upd(res,mul(ret,mul(s2,ksm(j,P-2))));
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256256
N = int(input())
A = list(map(int,input().split()))
rate = [0] * 9
for e in A:
    for i in range(8,-1,-1):
        if e >= 400*i:
            rate[i] += 1
            break
rate_ex = rate[:-1]
color_kind = 0
for e in rate_ex:
    if e > 0:
        color_kind += 1
min_kind = color_kind 
if min_kind == 0:
    min_kind = 1
max_kind = color_kind + rate[-1]
print(min_kind,max_kind)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int MAX=2e5+7,MOD=1e9 + 7;
void solve(){
    string s;cin>>s;
    if(s=="ABC")cout<<"ARC";
    else cout<<"ABC";
}
int main (){
    int t=1;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

int v[1000][1000];
int memo[1000][1000];
int now[1000];
bool used[1000];

// TLEしそう. 
int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n-1; j++){
            scanf("%d", &v[i][j]);
            v[i][j]--;
            memo[i][v[i][j]] = j;
        }
    }
    int cnt = 0, fin = 0;
    while(fin != n){
        cnt++;
        bool update = false;
        memset(used, 0, sizeof(used));
        for(int i = 0; i < n; i++){
            if(used[i] || now[i] == n-1)   continue;
            int enemy = v[i][now[i]];
            if(memo[enemy][i] == now[enemy]){
                update = true;
                used[i] = used[enemy] = true;
            }
        }
        for(int i = 0; i < n; i++){
            if(!used[i])    continue;
            now[i]++;
            if(now[i] == n-1)   fin++;
        }
        if(!update){
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        int cnt = 1;

        for (int i = 0; i < n - 1; i++) {
            if (s.charAt(i + 1) != s.charAt(i)) {
                cnt++;
            }
        }
        System.out.println(cnt);
        sc.close();
    }
}

Measured memory_bytes: 23892
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	ll a[N];

	bool flag = true;

	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		if (a[i] % 2)
		{
			flag = false;
		}
	}

	if (flag)
	{
		cout << "second" << endl;
	}
	else
	{
		cout << "first" << endl;
	}
	
	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll a;
  cin >> a;
  long double x;
  cin >> x;
  int b = (int)(x * 100 + 0.0001);
  ll ans = a * b;
  ans /= 100;
  cout << ans << endl;
}


Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    vector<int> ans(n), per(n), w(n), s(n);
    vector<string> name(n);
    int g = INT_MAX;
    REP(i,n){
      cin>>name[i]>>w[i]>>s[i];
      per[i] = i;
    }
    do{
      int gg = 0;
      int ww = 0;
      bool flag = true;
      for(int i=n-1; i>=0; i--){
	int pp = per[i];
	if(s[pp] < ww){
	  flag = false;
	  break;
	}
	ww += w[pp];
	gg += (i+1) * w[pp];
      }
      if(flag && g > gg){
	g = gg;
	ans = per;
      }
    }while(next_permutation(per.begin(), per.end()));
    
    REP(i,n) cout << name[ans[i]] << endl;
  }
  return 0;
}

Measured memory_bytes: 916
#include <stdio.h>
int main(void){
   
int d,i,s,x,y;

   while(scanf("%d", &d)!= EOF) {
       int sum=0;
       
       for(i=1;i<600/d;i++){
           
           x=i*d;
           y=x*x;
           s=d*y;
           sum+=s;
           
       }
       printf("%d\n",sum);
       if(d == 0) {
           break;
           
       }
       
   }
   return 0;
    
}


Measured memory_bytes: 2572
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef vector<bool> vec;
typedef vector<vec> mat;

ostream &operator<<(ostream &os, const vec &a) {
  FOR(it, a) os << setw(6) << *it << " ";
  return os;
}
ostream &operator<<(ostream &os, const mat &a) {
  FOR(it, a) os << *it << endl;
  return os;
}

vec mul(const mat &A, const vec &b) {
  vec c(A.size());
  REP(i,A.size())
    REP(j,A[i].size())
    c[i] = c[i] | (A[i][j]&b[j]);
  return c;
}

mat mul(const mat &A, const mat &B) {
  mat C(A.size(), vec(B[0].size()));
  REP(i,A.size())
    REP(j,B[0].size())
    REP(k,B.size())
    C[i][j] = C[i][j] | (A[i][k]&B[k][j]);
  return C;
}

mat pow(mat A, ll n) {
  mat B(A.size(), vec(A.size()));
  REP(i,A.size())
    B[i][i] = 1;
  while(n) {
    if (n&1) B = mul(B, A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}

int g[50][50];

int main() {
  int n, m, z;
  while(cin>>n>>m>>z,n||m||z) {
    memset(g,-1,sizeof(g));
    int cnt = 0;
    REP(i,m) {
      int a, b;
      cin >> a >> b;
      a--;b--;
      g[a][b] = cnt++;
      g[b][a] = cnt++;
    }
    mat A(cnt+1,vec(cnt+1));
    // start
    REP(i,n) if (i!=0&&g[0][i]!=-1) A[g[0][i]][cnt] = 1;
    // other
    REP(i,n) {
      REP(j,n) {
        if (g[i][j]!=-1) {
          REP(k,n) {
            if (g[j][k]!=-1 && k!=i) {
              A[g[j][k]][g[i][j]] = 1;
            }
          }
        }
      }
    }
    //cout << A << endl;
    vec b(cnt+1);
    b[cnt] = 1;
    vec res = mul(pow(A,z),b);
    bool ans = 0;
    REP(i,n) {
      if (g[i][n-1]!=-1) ans |= res[g[i][n-1]];
    }
    cout<<(ans?"yes":"no") << endl;
    
  }
}

Measured memory_bytes: 1264
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
long long n,m,ans=0,sum=0;
long long a[200009];
map <long long,long long> p;
int main()
{
	cin>>n;
	p[0] = 1;
	ans = 0;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum += a[i];
		ans += p[sum];
		p[sum]++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 14336
import java.util.Scanner;

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		String[] s = sc.nextLine().split("");
		sc.close();
		boolean f1 = true;
		boolean f2 = true;
		for(int i = 0; i < s.length; i++) {
			if(f1) {
				if(s[i].equals("C"))  f1 = false;
			}else if(!f1) {
				if(s[i].equals("F")) {
					f2 = false;
					break;
				}
			}
		}
		if(!f1 && !f2)  System.out.println("Yes");
		else System.out.println("No");

	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	while(1){
		lli n,pn,q0;
		cin >> n >> pn >> q0;
		pn--; q0--;
		if(n == 0) break;

		vector<lli> p(n+1);
		p[n] = pn;
		string op = "";
		for(int i=n; i>0; i--){
			lli half = 1LL<<(i-1);
			if(p[i] < half){
				op += "U";
				p[i-1] = half-1 -p[i];
			}else{
				op += "D";
				p[i-1] = p[i] -half;
			}
		}
		reverse(op.begin(), op.end());

		vector<lli> q(n+1);
		q[0] = q0;
		string ans = "";
		for(int i=0; i<n; i++){
			lli half = 1LL<<(n-i-1);
			if(q[i] < half){
				if(op[i] == 'U'){
					q[i+1] = half-1 -q[i];
					ans += "L";
				}else{
					q[i+1] = q[i];
					ans += "R";
				}
			}else{
				if(op[i] == 'U'){
					q[i+1] = 2*half-1 -q[i];
					ans += "R";
				}else{
					q[i+1] = q[i] -half;
					ans += "L";
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
  int m, nmin, nmax;
  int p[201];
  int gap;
  int ans;
  while(cin>>m>>nmin>>nmax&&m&&nmin&&nmax){
    ans = -1;
    gap = -1;

  for(int i=0; i<201; i++){
    p[i]=0;
  }

    for(int i=1; i<=m; i++){
      cin >> p[i];
    }
    for(int i=nmin; i<=nmax; i++){
      if(gap<=p[i]-p[i+1]){
        gap = p[i]-p[i+1];
        ans = i;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3020
N, X = map(int, input().split())
# a=レベルiバーガーの厚さ, p = レベルiバーガーのパティの数
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

# レベルNバーガーの下からX層にあるパティの数


def f(N, X):
    if N == 0:
        if X <= 0:
            return 0
        else:
            return 1
    if X == 1:
        return 0
    elif 1 < X <= 1 + a[N - 1]:
        return f(N - 1, X - 1)
    elif X == 2 + a[N - 1]:
        return p[N - 1] + 1
    elif 2 + a[N - 1] < X <= 2 + 2 * a[N - 1]:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
    elif X == 3 + 2 * a[N - 1]:
        return 2 * p[N - 1] + 1

print(f(N, X))


Measured memory_bytes: 9092
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if(a+b > c+d) cout << "Left" << endl;
  else if(a+b == c+d) cout << "Balanced" << endl;
  else cout << "Right" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string  N;
  cin>>N;
  if(N.at(0)=='7'||N.at(1)=='7'||N.at(2)=='7'){
  cout<<"Yes"<<endl;
  
  }
  else{
  cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3628
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define INF_INT 2147483647

long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


long nCr(long n, long r){
    if(n==r || r==0){
        return 1;
    } else {
        return mod_add(nCr(n-1,r),nCr(n-1,r-1));
    }
}


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

    int ans = 0;
    int m = 0;


    for(int i=0; i<N; i++){
        int temp; cin>>temp;
        if(m<temp){
            m=temp;
        }
        ans+= temp;
    }


    cout << ans-m/2 << endl;
    return 0;

}


Measured memory_bytes: 256
from sys import stdin
X, N = [int(x) for x in stdin.readline().rstrip().split()]
p = [int(x) for x in stdin.readline().rstrip().split()]

ans = 10000
ans_diff = 10000

list_100 = [0] * 100
for i in range(100):
  list_100[i] = i+1
  
list_100.append(0)
list_100.append(-1)
list_100.append(101)
  
live_list = list(set(list_100) - set(p))

for i in live_list:
  diff = abs(X - i)
  if diff < ans_diff:
    ans = i
    ans_diff = diff
  if diff == ans_diff:
    ans = min(ans, i)
 
print(ans)

Measured memory_bytes: 9232
#include<bits/stdc++.h>
#include<set>
#define LL long long
#define PAIR pair<int,LL>
using namespace std;
int n,q;
set<PAIR> S;
set<PAIR> :: iterator it,ot;
int main()
{
	int x,u; LL y,v,w,s,xyk;
	scanf("%d %d",&n,&q);
	S.insert(PAIR(0,(LL)(1e18)));
	S.insert(PAIR(1,0));
	S.insert(PAIR(n+1,0));
	while(q--){
		scanf("%d %lld",&x,&y);
		it=S.upper_bound(PAIR(x+1,-1));
		it--,xyk=it->second;
		while(1){
			it=S.upper_bound(PAIR(x+1,-1));
			it--,ot=it,ot--;
			w=ot->second-it->second;
			s=x-it->first+1;
			if(y/s<w){
				u=it->first,v=it->second;
				S.erase(it);
				if(y%s==0)
					S.insert(PAIR(u,v+y/s));
				else{
					S.insert(PAIR(u,v+y/s+1));
					S.insert(PAIR(u+y%s,v+y/s));
					it=S.find(PAIR(u,v+y/s+1));
					ot=it,ot--;
					if(ot->second==v+y/s+1)
						S.erase(it);
				  }
				break;
			  }
			y-=w*s;
			S.erase(it);
		  }
		if(x<n){
			it=S.upper_bound(PAIR(x+1,-1));
			ot=it,it--;
			if(it->second>xyk&&ot->first>x+1)
				S.insert(PAIR(x+1,xyk));
		  }
	  }
	it=S.begin(),it++,x=1;
	for(;it!=S.end();it++){
		for(u=x;u<it->first;u++)
			printf("%lld\n",y);
		x=it->first,y=it->second;
	  }
	return 0;
}


Measured memory_bytes: 7680
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define ran(x) (x).begin(),(x).end()
#define for(ko,koo) for(int ko=0;ko<koo;++ko)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define plli pair<lli,lli>
#define paf(L,R) pair<L,R>
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int d, t, s;
    cin >> d >> t >> s;
    cout<<(d <= t * s ? "Yes" : "No") << endl;

}

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

int64_t MOD = 998244353;
double PI = 3.141592653589793;
int64_t MAX = 500000;
vector<int64_t> fac(MAX), finv(MAX), inv(MAX);

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

int64_t COM(int64_t n, int64_t k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int64_t mypow(int64_t x, int64_t y) //x ^ y
{
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    else if (y % 2 == 1)
        return mypow(x, y - 1) * x % MOD;
    else
    {
        int64_t tmp = mypow(x, y / 2);
        return tmp * tmp % MOD;
    }
}

int main()
{
    COMinit();
    int64_t N, M, K, tmp, ans = 0;
    cin >> N >> M >> K;
    for (int64_t i = 0; i <= K; i++)
    {
        tmp = M * mypow(M - 1, N - i - 1) % MOD;
        tmp = (tmp * COM(N - 1, i)) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans;
}

Measured memory_bytes: 14896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int64_t i=0; i<(n); ++i) 
int main(){
    
    int N;
    cin >> N;
    double res = 0;
    rep(i, N){
        string x, v;
        cin >> x>> v;
        const int rate = 380000;
        if(v=="BTC"){
            double b = stod(x);
            res += b * rate;
        }
        else{
            int y = stoi(x);
            res += y;
        }
    }
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int c[505],s[505],f[505];

signed main(){
	
	int n;cin>>n;
	rep(i,n-1) cin>>c[i]>>s[i]>>f[i];
	
	rep(i,n-1)
	{
		int now = 0;
		FOR(j,i,n-2)
		{
			if(now <= s[j]) now = s[j];
			else now = ((now-s[j]-1)/f[j]+1)*f[j] + s[j];
			now += c[j];
		}
		cout << now << endl;
		
		
	}
	
	cout << 0 << endl;
	
}
 

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

int main() {
  int N,M;
  cin>>N>>M;
  // string s;
  // cin>>s;
  std::multiset<int> A;
  int a;
  for (int i = 0; i < N;i++) {
    cin>>a;
    A.insert(a);
  }

  for (int i = 0; i < M;i++) {
    std::multiset<int>::iterator itr = A.end();
    itr--;
    int val = (*itr)/2;
    A.erase(itr);
    A.insert(val);
    // cout<<A.size()<<endl;
  }

  long long sum = 0;
  for (std::multiset<int>::iterator itr = A.begin();itr != A.end();itr++) {
    sum += *itr;
  }
  cout<<sum<<endl;

  // int val = 0;
  // cout<<val<<endl;
  return 0;
}

Measured memory_bytes: 6912
A,B,C=list(map(int,input().split()))
K=int(input())

d=[]
d.append(A)
d.append(B)
d.append(C)

maxc=max(d)
max = max(d)

for i in range(K):
    max = max*2

print(max+A+B+C-maxc)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		if(i % 2 && x % 2)
			ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {
  int n,l;
  cin>>n>>l;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin>>s.at(i);
  }
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++){
    cout<<s.at(i);
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static final long INF = (long) 1e17;
    static int n, a[], maxskips;
    static Long memo[][];

    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        a = sc.nextIntArray(n);
        maxskips = 1 + (n % 2);
        memo = new Long[3][n];
        long ans = dp(0, 0);
        out.println(ans);
        out.flush();
        out.close();
    }

    static long dp(int skip, int i) {
        if (skip > maxskips) return -INF;
        if (i >= n) return (n%2!=0 && skip==0)?-INF:0;
        if (memo[skip][i] != null) return memo[skip][i];
        long max = a[i] + dp(skip, i + 2);
        if (i != n - 1) max = Math.max(max, dp(skip + 1, i + 1));
        return memo[skip][i] = max;
    }


    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        boolean ready() throws IOException {
            return br.ready();
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        int nextChar() throws IOException {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 67076
#include <bits/stdc++.h>
typedef long long ll;    
typedef long double ld;  
#define pb push_back     
using namespace std;


bool pr[100010];
int ct[100010];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    for(int i = 2; i <= 100000; i++) pr[i] = true;
    for(int i = 2; i <= 100000; i++){
        if(pr[i]){
            for(int j = 2 * i; j <= 100000; j += i){
                pr[j] = false;
            }
        }
    }
    for(int i = 3; i <= 100000; i+=2){
        if(pr[i] && pr[(i + 1) / 2]) ct[i] = 1;
    }
    for(int i = 3; i <= 100000; i++){
        ct[i] += ct[i - 1];
    }
    
    int q;
    cin >> q;

    for(int i = 1; i <= q; i++){
        int l, r;
        cin >> l >> r;
        cout << ct[r] - ct[l - 1] << endl;
    }

    return 0;

}


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

using namespace std;

#define DB( x ) cout << #x << " = " << x << endl;
#define LEFT(n) (2 * (n))
#define RIGHT(n) (2 * (n) + 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> node;
//typedef vector <vector <ll>> matrix;

const ll INF = 1e9;
const double EPS = 1e-9;
const ll MOD = (ll)(1000000007);
const ll MAXV = (ll)(2e5 + 10);
const ll MAXE = (ll)(1e6 + 10);

ll x, y;

int main(){
	cin.sync_with_stdio( 0 );cin.tie( 0 );

	cin >> x >> y;

	cout << max(max(x + y, x - y), x * y) << "\n";

	return 0;
}


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

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

    string S;
    string T;
    cin >> S;
    cin >> T;
    int size;
    vector<char> vc;
    for(int i=0;i<T.size();i++){
        vc.push_back(T[i]);
    }
    for(int i=0;i<S.size();i++){
        vc.push_back(S[i]);
    }
    for(int i=0;i<vc.size();i++){
        cout << vc.at(i);
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	bool A=false,B=false;
	string s;
	cin>>s;
	for(int i=0;i<s.size();++i) 
	{
		if(s[i]=='A') A=true;
		else B=true;
	}
	if(A==true && B==true) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
H,W = map(int, input().strip().split(' '))

maze = ['#'*(W+2)]
maze += ['#'+input().strip()+'#' for _ in range(H)]
maze.append('#'*(W+2))
maze_map = [[float('inf')]*(W+2) for _ in range(H+2)]
maze_map[1][1] = 1

# 幅優先
mem = [(1,1)]

while True:
  if len(mem) == 0: break
  x,y = mem.pop()
  for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
    if maze[y+dy][x+dx] == '.':
      if maze_map[y+dy][x+dx] > maze_map[y][x]+1:
        maze_map[y+dy][x+dx] = maze_map[y][x]+1
        mem.append((x+dx,y+dy))
        
if maze_map[H][W] == float('inf'):
  print(-1)
else:
  w = sum(m.count('.') for m in maze)
  print(w-maze_map[H][W])

Measured memory_bytes: 42348
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    
    int bits_size = S.size() - 1;
    int64_t total = 0;
    for (int tmp = 0; tmp < (1 << bits_size); tmp++) {
        bitset<10> s(tmp);
        int64_t subtotal = 0;
        
        int start = 0;
        int till = 0;
        for (int i = 0; i < bits_size; i++) {
            if(s.test(i)) {
                till = i;
                subtotal += stoll(S.substr(start, till - start + 1));
                start = till + 1;
            }
        }
        subtotal += stoll(S.substr(start)); //残り
        total += subtotal;
    }
    cout << total << endl;
    
}


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

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

  vector<string> S(N);
  vector<int> T(N);

  for (int i = 0; i < N; i++) {
    cin >> S.at(i) >> T.at(i);
  }

  string X;
  cin >> X;

  bool Sleep = false;
  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (Sleep) ans += T.at(i);

    if (X == S.at(i)) Sleep = true;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
import bisect
n,m=map(int,input().split())
PY=[list(map(int,input().split())) for _ in range(m)]
d=defaultdict(list)
for py in sorted(PY):
  d[py[0]].append(py[1])
for p, y in PY:
  print(str(p).zfill(6)+str(bisect.bisect_left(d[p],y)+1).zfill(6))


Measured memory_bytes: 82900
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    string a;
    cin >> a;
    
    for(int i=0; i<3; i++)
    {
        if(a[i] == '7')
        {cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <queue>

using namespace std;

//long long
const long long maxn = 120000;
struct node {
	long long x , i;
} tmp;
bool operator < ( node x1 , node x2 ) {
	return x1.x < x2.x;
}
long long n;
long long a[maxn] , ans[maxn];
priority_queue < node > q;
void work () {
	long long i , now , tot;
	scanf ( "%lld" , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%lld" , &a[i] );
		tmp.x = a[i]; tmp.i = i;
		q.push ( tmp );
	}
	now = q.top ().x;
	tot = 0;
	i = 99999999;
	while ( q.size () ) {
		while ( q.size () && ( q.top ().x == now) ) {
			i = min ( i , q.top ().i );
			q.pop ();
			tot++;
			//printf ( " %lld %lld\n" , now , tot );
		}
		ans[i] += tot * (now-q.top().x);
		now = q.top ().x;
	}
	//printf ( "%lld\n" , now );
	ans[1] += now * tot;
	for ( i = 1 ; i <= n ; i++ ) printf ( "%lld\n" , ans[i] );
}
int main () {
	work ();
	return 0;
}

Measured memory_bytes: 4336
/*    Mohammed Sami Khan
                       মোহাম্মদ সামী খান
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define mp(a,b) make_pair(a,b)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;

bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}

int main()
{
    fastio;
    ll t, n, m, x=0, y, p, q, r, i, j, d, f=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]!=i+1) x++;
    }
    if(x<=2) cout<<"YES";
    else cout<<"NO";
}


Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<int> G[100005];
vector<long long> memo_l[100005];
vector<long long> memo_r[100005];
long long ans[100005];
int N, M;

long long dfs(int v, int parent) {
    memo_l[v].resize(G[v].size()+2, 1);
    memo_r[v].resize(G[v].size()+2, 1);
    for (int i = 0; i < G[v].size(); i++) {
        int child = G[v][i];
        if (child == parent) continue;

        memo_l[v][i+1] = (dfs(child, v) + 1) % M;
    }
    for (int i = G[v].size(); i > 0; i--) {
        memo_r[v][i] = memo_l[v][i] * memo_r[v][i+1] % M;
    }
    for (int i = 1; i <= G[v].size(); i++) {
        memo_l[v][i] = memo_l[v][i] * memo_l[v][i-1] % M;
    }
    return memo_r[v][1];
}

void calc_ans(int v, int parent, long long parent_res) {
    ans[v] = (parent_res + 1) * memo_r[v][1] % M;
    for (int i = 0; i < G[v].size(); i++) {
        int child = G[v][i];
        if (parent == child) continue;

        calc_ans(child, v, memo_l[v][i] * memo_r[v][i+2] % M * (parent_res + 1) % M);
    }
}



int main(void) {
    cin >> N >> M;
    for (int i = 0; i < N-1; i++) {
        int x, y; cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1, 0);
    calc_ans(1, 0, 0);
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 27776
w = gets.chomp!
h = {}
w.chars.sort!.each do |c|
  if h.has_key?(c)
    h[c] += 1
  else
    h[c] = 1
  end
end

h.each do |k, v|
  if v % 2 != 0
    puts "No"
    exit
  end
end

puts "Yes"

Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int cost[100][100];
int mincost[100];
bool used[100];
const int INF = 1e6;
int main(void){
  int n,m;
  while(cin>>n>>m){
    if(n==0) break;
    REP(i,n){
      REP(j,n)cost[i][j] = INF;
      mincost[i]=INF;
      used[i] = false;
    }
    REP(i,m){
      int a,b,c;
      cin>>a>>b>>c;
      cost[a][b] = cost[b][a] = c;
    }
    mincost[0] = 0;
    int ans = 0;
    while(true){
      int v = -1;
      REP(u,n)
        if(!used[u]&&(v==-1||mincost[u]<mincost[v]))
          v = u;
      if(v==-1) break;
      ans += mincost[v];
      used[v] = true;
      REP(u,n)mincost[u] = min(mincost[u],cost[v][u]);
    }
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 0
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int A, B, m; cin >> A >> B >> m;
    vector<int> a(A), b(B);
    int mia = INF, mib = INF;
    rep(i, A) {
        cin >> a[i];
        chmin(mia, a[i]);
    }
    rep(i, B) {
        cin >> b[i];
        chmin(mib, b[i]);
    }
    int ans = mia + mib;
    rep(i, m) {
        int x, y, c; cin >> x >> y >> c;
        -- x; -- y;
        chmin(ans, a[x] + b[y] - c);
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();
        
        String first = s1.substring(0,1).toUpperCase();
        String middle = s2.substring(0,1).toUpperCase();
        String last = s3.substring(0,1).toUpperCase();
        System.out.println(first + middle + last);
    }
}


Measured memory_bytes: 21844
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

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

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >> getLine >>= print . length . group

Measured memory_bytes: 6524
using System;
using System.Linq;

namespace AtCoderTutorial
{
    public class AtCoder175
    {
        public static void Main(string[] args)
        {
            long[] inputs = Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray();

            long X = inputs[0];
            long K = inputs[1];
            long D = inputs[2];

            long min = X;

            long Y = (Math.Abs(X) / D) + 1;
            if (K >= Y)
            {
                if ((K - Y) % 2 == 0)
                {
                    if (X > 0)
                    {
                        min = X - D * Y;
                    }
                    else
                    {
                        min = X + D * Y;
                    }
                }
                else
                {
                    if (X > 0)
                    {
                        min = Math.Min(Math.Abs(X - D * (Y + 1)), Math.Abs(X - D * (Y - 1)));
                    }
                    else
                    {
                        min = Math.Min(Math.Abs(X + D * (Y + 1)), Math.Abs(X + D * (Y - 1)));
                    }
                }
            }
            else
            {
                if (X > 0)
                {
                    min = X - D * K;
                }
                else
                {
                    min = X + D * K;
                }
            }

            Console.WriteLine(Math.Abs(min));
        }
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k; cin>>n>>k;
	ll ans=0;
	rep(i, n){
		int h; cin>>h;
		if (h>=k) ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
// 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;}

const double PI = acos(-1.0);

int main(){
    cout<<fixed<<setprecision(10);
    double a, b, x; cin >> a >> b >> x;
 
    double ans;
    if(x > a*a*b / 2.0){
        ans = atan(2*(a*a*b-x) / (a*a*a));
    } else {
        ans = PI/2 - atan((2*x)/(a*b*b));
    }
    cout << (ans * 180 / PI) << endl;
}

Measured memory_bytes: 512
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A.append(A[0])
B.append(B[0])

AX=[]
BX=[]
for i in range(N):
    AX.append(A[i]^A[i+1])
    BX.append(B[i]^B[i+1])

AX+=AX[:-1]

# MP法


LEN=len(BX)
MP=[-1]*(LEN+1) #「接頭辞と接尾辞が最大何文字一致しているか」を記録する配列
NOW=-1 # 何文字一致しているか.

for i in range(LEN):
    while NOW>=0 and BX[i]!=BX[NOW]: # 一致していなかったら0から数え直すのではなく, MP[NOW]から数える.
        NOW=MP[NOW]
    NOW+=1
    MP[i+1]=NOW

LEN2=len(AX)

MP_SEARCH=[0]*(LEN2) # その文字までで何個一致しているかを調べる. LEN文字一致したらSが検出できたということ.
NOW=0
for i in range(LEN2):
    while NOW>=0 and AX[i]!=BX[NOW]:
        NOW=MP[NOW]
    NOW+=1
    MP_SEARCH[i]=NOW

    if NOW==LEN: # LEN文字一致したら, MP[LEN]から数える.
        NOW=MP[NOW]
        
for i in range(LEN2):
    if MP_SEARCH[i]==LEN:
        print(i-LEN+1,A[i-LEN+1]^B[0])

Measured memory_bytes: 54136