akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	int n; cin >> n;
	int ma = 0, mi = n;
	int a[100003];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		ma = max(ma, a[i]);
		mi = min(mi, a[i]);
	}
	if (ma - mi > 1) {
		cout << "No" << endl;
		return 0;
	}
	if (ma == mi) {
		if (n == ma + 1) {
			cout << "Yes" << endl;
			return 0;
		}
		if (n >= 2 * ma) {
			cout << "Yes" << endl;
			return 0;
		}
		cout << "No" << endl;
	}
	else {
		int cnt = 0;
		for (int i = 0; i < n; ++i) cnt += a[i] < ma;
		if (cnt + 1 <= ma && ma <= cnt + (n - cnt) / 2) {
			cout << "Yes" << endl;
			return 0;
		}
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18;

template<typename Monoid>
struct SegmentTree{
    typedef function<Monoid(Monoid,Monoid)> F;
    int n;
    F f;
    Monoid id;
    vector<Monoid> dat;
    SegmentTree(int n_,F f,Monoid id):f(f),id(id){init(n_);}
    void init(int n_){
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,id);
    }
    void build(const vector<Monoid> &v){
        for (int i=0;i<v.size();++i) dat[i+n]=v[i];
        for (int i=n-1;i;--i) dat[i]=f(dat[i<<1|0],dat[i<<1|1]);
    }
    void update(int k,Monoid x){
        dat[k+=n]=x;
        while(k>>=1) dat[k]=f(dat[k<<1|0],dat[k<<1|1]);
    }
    Monoid query(int a,int b){
        if (a>=b) return id;
        Monoid vl=id,vr=id;
        for (int l=a+n,r=b+n;l<r;l>>=1,r>>=1){
            if (l&1) vl=f(vl,dat[l++]);
            if (r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
    Monoid operator[](int i){
        return dat[i+n];
    }
    // most left position that meets condition "check"
    template<typename C>
    int find(int a,int b,const C &check,int k,int l,int r){
        if (!check(dat[k])||r<=a||b<=l) return -1;
        if (l+1==r) return k-n;
        int vl=find(a,b,check,k<<1|0,l,(l+r)>>1);
        if (~vl) return vl;
        return find(a,b,check,k<<1|1,(l+r)>>1,r);
    }
    template<typename C>
    int find(int a,int b,const C &check){
        return find(a,b,check,1,0,n);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll E,T; cin >> N >> E >> T;
    vector<ll> x(N+1); x[0]=0;
    for (int i=1;i<=N;++i) cin >> x[i];
    vector<ll> x_2(N+1);
    for (int i=0;i<=N;++i) x_2[i]=x[i]*2;
    vector<ll> dp(N+1,INF),dp0(N+1);
    SegmentTree<ll> seg(N+1,[](ll a,ll b){return min(a,b);},INF);
    dp[0]=0; dp0[0]=-x_2[1];
    seg.update(0,0);
    for (int i=1;i<=N;++i){
        int pos=upper_bound(x_2.begin(),x_2.end(),x_2[i]-T)-x_2.begin()-2;
        if (pos>=0) dp[i]=min(dp[i],dp0[pos]+3*x[i]);
        dp[i]=min(dp[i],seg.query(max(0,pos+1),i)+T+x[i]);
        if (i==N) continue;
        dp0[i]=min(dp0[i-1],dp[i]-x_2[i+1]-x[i]);
        seg.update(i,dp[i]-x[i]);
    }
    cout << dp[N]+(E-x[N]) << '\n';
}

Measured memory_bytes: 8484
Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i =
        if i = n - 1 then -1, -1 else
            if i < n - 2 && s.[i] = s.[i + 2] then i + 1, i + 3 else
                if s.[i] = s.[i + 1] then i + 1, i + 2 else
                    loop (i + 1)
    in
    let a, b = loop 0 in
    Printf.printf "%d %d\n" a b
)

Measured memory_bytes: 4204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

#define SIZE 100010

vector<pair<int,int> > way[SIZE];

pair<int,int> dfs(int now, int back = -1){
  pair<int,int> res = {0, now};
  
  for(int i=0;i<way[now].size();i++){
    if(way[now][i].first == back) continue;
    auto p = dfs(way[now][i].first, now);
    p.first += way[now][i].second;
    res = max(res, p);
  }

  return res;
}

bool solve(){
  int n, p[SIZE], d[SIZE], inedge[SIZE] = {};
  long long ans = 0;
  
  scanf("%d", &n);
  if(n == 0) return false;
  
  for(int i=0;i<n;i++) way[i] = vector<pair<int,int> > ();
  for(int i=1;i<n;i++){
    scanf("%d", p+i);
    p[i]--;
    inedge[p[i]]++;
    inedge[i]++;
  }

  int start = -1;
  
  for(int i=1;i<n;i++){
    scanf("%d",d+i);

    if(inedge[i] == 1 || inedge[p[i]] == 1){
      ans += d[i];
    }else{
      start = i;
      way[i].push_back({p[i],d[i]});
      way[p[i]].push_back({i,d[i]});
      ans += d[i]*3;
    }
  }

  //cerr << start << endl;
  
  if(start != -1){
    auto res = dfs(start);
    auto res2 = dfs(res.second);
  
    //cerr << res.second << " " << res2.first << endl;
    
    cout << ans - res2.first << endl;
  }else{
    cout << ans << endl;
  }
  return 1;
}

int main(){
  while(solve());

}



Measured memory_bytes: 5996
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split("").map(&:to_i)
end

nlist = gets_i_list
c = nlist.first
k = nlist.size

dpp nlist

if nlist.sum == c + 9 * (k -1)
  puts c + 9 * (k -1)
else
  puts c + 9 * (k - 1) - 1
end

Measured memory_bytes: 14480
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	string a;
	while(cin >> a)
	{
		int l = a.length();
		char str1[l];
		char str2[l];
		int flag1, flag2;
		flag1 = flag2 = 0;
		int k1 = 0;
		int k2 = 0;
		for(int i=0;i<l;i++)
		{
			if(i % 2 == 0)
			{
				str1[k1++] = a[i];	
			}	
			if(i % 2 != 0)
			{
				str2[k2++] = a[i];
			}
		}
		for(int i=0;i<k1;i++)
		{
			if(str1[i] == 'L')
			{
				flag1 = 1;
				break;
			}
		}
		for(int i=0;i<k2;i++)
		{
			if(str2[i] == 'R')
			{
				flag2 = 1;
				break;
			}
		}
		if(flag1 == 1 || flag2 == 1)
		{
			cout << "No" << endl;
		}
		else
		{
			cout << "Yes" << endl;
		}
	}	
	return 0;
} 

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

void read(vector<string> &g, int n, int m) {
    for(int i = 0; i < n; i++) cin >> g[i];
}

bool isIn(int x, int y, int n, int m) {
    return(x >= 0 and x < n and y >= 0 and y < m);
}

int solve(const vector<string> &g, int n, int m) {
    vector<vector<int>> ans(n,vector<int>(m,0));
    int mov[2][2] = { {1,0},{0,1} };
    ans[n-1][m-1] = 1;

    for(int i = n-1; i >= 0; i--) {
        for(int j = m-1; j >= 0; j--) {
            if(g[i][j] == '#') continue;
            for(int k = 0; k < 2; k++) {
                int ii = i + mov[k][0];
                int jj = j + mov[k][1];
                if(isIn(ii,jj,n,m) and g[ii][jj] != '#')
                    ans[i][j] = (ans[i][j] + ans[ii][jj]) % MOD;
            }
        }
    }

    return ans[0][0];
}

int main() {
    ios_base::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<string> g(n);
    read(g,n,m);
    cout << solve(g,n,m) << endl;
    return 0;
}


Measured memory_bytes: 5248
#!/usr/bin/env python3
import sys
from collections import defaultdict
INF = float("inf")


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):

    L = 10**5+1
    DP = [[INF]*(L) for _ in range(N+1)]
    for i in range(N+1):
        DP[i][0] = 0

    for i in range(N):
        for j in range(L):
            DP[i+1][j] = DP[i][j]
            if 0 <= j-v[i] < L:
                DP[i+1][j] = min(DP[i+1][j], DP[i][j-v[i]]+w[i])

    for j in range(L-1, -1, -1):
        if DP[N][j] <= W:
            print(j)
            return

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 418616
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
	int a,b;
	
	cin >> a>>b;
	




	cout <<(b-a)*(b-a+1)/2-b<< endl;
	
}

Measured memory_bytes: 256
// NK
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define all(x) x.begin(), x.end()

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

  ll x; cin>>x;
  ll r1,r2;
  r1 = x / 500;
  x%=500;
  r2 = x/5;
  ll ans = r1*1000 + r2*5;
  cout<<ans<<'\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int v, d, fib[1005];
int par[1005];

int find(int x)
{
	if (x == par[x]) return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y)
{
	x = par[x];
	y = par[y];
	par[x] = y;
}


int main()
{
	fib[0] = 1; fib[1] = 2;
	REP(i, 1002)
	{
		fib[i + 2] = (fib[i + 1] + fib[i]) % 1001;
	}
	while (cin >> v >> d)
	{
		REP(i, 1005) par[i] = i;
		FOR(i, 1, v+1)FOR(j, 1, v+1)
		{
			if (abs(fib[i] - fib[j]) < d && find(i) != find(j))
			{
				unite(i, j);
			}
		}
		bool used[1005] = {};
		int cnt = 0;
		FOR(i, 1, v+1)
		{
			if (used[find(i)] == false)
			{
				cnt++;
				used[find(i)] = true;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

int main(void){
	int N,A,B;cin>>N>>A>>B;
	cout<<(N * A >= B?B:N * A);
}


Measured memory_bytes: 256
//143 B - TAKOYAKI FESTIVAL 2019 2019/10/19
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n; cin >> n;
    vector<int> d(n);
    int ans=0;
    rep(i ,n) cin >> d[i];
    rep(i ,n){
        for(int j=i+1;j<n;++j){
            ans+=d[i]*d[j];
        }
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int length = sc.nextInt();
		String str = sc.next();
		long r=0,g=0,b=0;
		char[] rgb = str.toCharArray();
		for(int i=0;i<length;i++) {
			if(rgb[i]=='R') r++;
			if(rgb[i]=='G') g++;
			if(rgb[i]=='B') b++;
		}
		long ans = r*g*b;
		for(int i=1;i<=length;i++) {
			for(int j=0;2*i+j<length;j++) {
				if(rgb[j]!=rgb[j+i] && rgb[j]!=rgb[j+2*i] && rgb[j+i]!=rgb[j+2*i]) ans--;
			}
		}
		System.out.println(ans);
	}
}

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

int main() {
	string str,command,p;
	char cpy[1000];
	int a, b, q;

	cin >> str;
	cin >> q;

	for (int i = 0;i < q;i++) {
		cin >> command;
		
		if (command == "print") {
			cin >> a >> b;
			for (int j = a;j < b+1;j++)
				cout << str[j];
			cout << endl;
		}
		else if(command == "reverse") {
			cin >> a >> b;
			for (int j = a;j < b+1;j++)
				cpy[j] = str[j];
			for (int j = a;j < b+1;j++)
				str[a + b - j] = cpy[j];
		}
		else if(command=="replace") {
			cin >> a >> b >> p;
			for (int j = a;j < b+1;j++)
				str[j] = p[j - a];
		}
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;


int main() {

    int N;scanf("%d",&N);
    N=N%500;
    int A;scanf("%d",&A);
    if(A>=N){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(P: int, Q: int, R: int):
    print(min(P+Q,P+R,Q+R))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    P = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(P, Q, R)

if __name__ == '__main__':
    main()


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

int main() {
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0; i < 3; i++){
  if(S.at(i) == S.at(i+1) ){
  count += 1;
  }
  }
  if (count == 0){
  cout << "Good";
  }else{
  cout << "Bad";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<long long,long long>
#define vll          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (long long)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main(){
	int n;cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	reverse(a,a+n);
	int cnt=0,ans=0;
	for(int i=0;i<n-1;i++){
		if(a[i]<=a[i+1]){
			cnt++;
		}
		else{
			ans=max(cnt,ans);
			cnt=0;
		}
	}
	ans=max(ans,cnt);
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>

using namespace std;

#define PII pair<int, int>

priority_queue<PII,vector<PII >, greater<PII > > Q;

int main(void){
	int N,L;
	while(scanf("%d%d", &N, &L) != EOF){
		int a[100005]={0};
		int temp;
		int ans = 0;
		
		
		for(int i = 1; i <= N; i++){
			scanf("%d", &temp);
			Q.push(PII(temp,i));
		}
		
		while( !Q.empty() ){
			int leng = Q.top().first;
			int soej = Q.top().second;
			
			Q.pop();
			int time = a[soej] + L-leng;
			
			a[soej-1] = max(time,a[soej-1]);
			a[soej+1] = max(time,a[soej+1]);
		}
		
		for(int i = 1; i <= N; i++)
			ans = max(a[i],ans);
		
		printf("%d\n",ans);
	
	}
	return 0;
}

Measured memory_bytes: 2072
#include <iostream>

using namespace std;

int main() {
    string s, t, u;
    long int a, b;
    long int ans = 0;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if (u == s)
        a--;
    else
        b--;

    cout <<a<< " " << b <<"\n";
    
    return 0;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){

int X, A, B;
cin >> X >> A >> B;


int ans = X - A - B;
while(ans >= B) ans -= B;
print(ans);


}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*float n乗*/ll floatpow(float x,ll n){ll i;float ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n,k;
 ll times;
 double prob=1;
 sc(n);sc(k);
 rep(i,1,n+1){
  prob=1;
  rep(j,0,k){//何回サイコロを振ればよいか
   if(i*llpow(2,j)>=k){
    times=j;break;
   }
  }
  rep(j,0,times)prob*=0.500;
  ans+=prob/(double)n;
  //cout<<i<<" "<<times<<" "<<ans<<endl;
 }
 printf("%.9lf\n",ans);
return 0;}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define db double
#define pint pair<int,ll>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=1e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline ll read(){
	ll x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
unordered_map<ll,int>Map,vis;
int n,cnt,p[MAXN],v[MAXN],ans;ll a[MAXN],p3[MAXN];
inline void Init(int n=3e3){
	Rep(i,2,n){
		if(!v[i])p[++cnt]=i,p3[cnt]=1ll*i*i*i;
		for(int j=1;j<=cnt&&i*p[j]<=n;j++){
			v[i*p[j]]=1;if(i%p[j]==0)break;
		}
	}
}
namespace PR{
	ll cnt,a[50];
	inline ll Abs(ll x){return x<0?-x:x;}
	inline ll gcd(ll x,ll y){for(ll z;y;z=x,x=y,y=z%y);return x;}
	inline ll Fm(ll a,ll b,ll Mod){a%=Mod,b%=Mod;return (a*b-(ull)((ld)a/Mod*b)*Mod+Mod)%Mod;}
	inline ll Fp(ll x,ll k,ll Mod){ll ans=1;for(;k;k>>=1,x=Fm(x,x,Mod))if(k&1)ans=Fm(ans,x,Mod);return ans;}
	int kx[5]={2,3,5,7,43};
	inline bool Mr(ll a,ll n){
		if(Fp(a,n-1,n)!=1)return 0;
		for(ll y=n-1,z;!(y&1);){
			y>>=1,z=Fp(a,y,n);
			if(z!=1&&z!=n-1)return 0;
			if(z==n-1)return 1;
		}return 1;
	}
	inline bool chk(ll n){
		if(n<2)return 0;if(n==2||n==3||n==5||n==7||n==43)return 1;
		return Mr(2,n)&&Mr(3,n)&&Mr(5,n)&&Mr(7,n)&&Mr(43,n);
	}inline ll Find(ll n){
		for(ll x,y,z,c,g;;){
			y=x=rand()%n,c=rand()%n,z=1;
			for(int i=0,j=1;++i;){
				x=(Fm(x,x,n)+c)%n,z=Fm(z,Abs(y-x),n);
				if(x==y||!z)break;
				if(!(x%127)||i==j){
					g=gcd(z,n);if(g>1)return g;
					if(i==j)y=x,j<<=1;
				}
			}
		}
	}inline void Rho(ll n){
		if(n==1)return;if(chk(n)){a[++cnt]=n;return;}
		ll p=Find(n);Rho(p),Rho(n/p);
	}
	inline ll Solve(ll n){
		cnt=0,Rho(n),sort(a+1,a+cnt+1),cnt=unique(a+1,a+cnt+1)-a-1;
		ll res=1;
		Rep(i,1,cnt){
			int tmp=3;for(;n%a[i]==0;n/=a[i],tmp--);
			for(;tmp--;){res*=a[i];if(res>1e10)return -1;}
		}return res;
	}
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	srand(time(NULL)),Init(),n=read();
	Rep(i,1,n){ll x=read();Rep(j,1,cnt)while(x%p3[j]==0)x/=p3[j];a[i]=x,Map[a[i]]++;}
	Rep(i,1,n)if(!vis[a[i]]){
		if(a[i]==1){ans++,vis[a[i]]=1;continue;}
		ll rev=PR::Solve(a[i]);
		ans+=max(Map[a[i]],Map[rev]),vis[a[i]]=vis[rev]=1;
	}
	cout<<ans<<'\n';
	return 0;
}




Measured memory_bytes: 18104
n, m = gets.split.map(&:to_i)
as = gets.chomp.split

h = Hash.new("0")

table = {
  "1" => "2",
  "2" => "5",
  "3" => "5",
  "4" => "4",
  "5" => "5",
  "6" => "6",
  "7" => "3",
  "8" => "7",
  "9" => "6"
}

as.each do |a|
  h[table[a]] = [a, h[table[a]]].max
end

keys = h.keys
dp = Hash.new("0")
(1..n).each do |i|
  tmp = h[i.to_s]
  keys.each do |k|
    k = k.to_i
    if dp[i - k] != "0"
      a = dp[i - k].to_s
      b = h[k.to_s].to_s
      str = a < b ? (b + a) : (a + b)
      if tmp.length < str.length || (tmp.length == str.length && tmp < str)
        tmp = str
      end
    end
  end
  dp[i] = tmp
end

puts dp[n]

Measured memory_bytes: 57980
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int N, Q, k;
string S;

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

    REP(_, Q)
    {
        lint ans = 0;
        cin >> k;

        lint nD = 0, nM = 0, dp = 0;
        REP(i, N)
        {
            if (i >= k)
            {
                if (S[i - k] == 'D')
                {
                    nD--;
                    dp -= nM;
                }
                if (S[i - k] == 'M') nM--;
            }
            if (S[i] == 'D') nD++;
            else if (S[i] == 'M')
            {
                nM++;
                dp += nD;
            }
            else if (S[i] == 'C')
            {
                ans += dp;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

int main() {
  int A, B;
  cin >> A >> B;
  int C, D;
  cin >> C >> D;
  cout << min(A, B) + min(C, D) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct Point {
    db x,y;
    Point(db _x = 0.0,db _y = 0.0) {x = _x;y = _y;}
    friend Point operator + (const Point &a,const Point &b) {
	return Point(a.x + b.x,a.y + b.y);
    }
    friend Point operator - (const Point &a,const Point &b) {
	return Point(a.x - b.x,a.y - b.y);
    }
    db norm() {
	return sqrt(x * x + y * y);
    }
}P[MAXN],S,T;
db R[MAXN],dis[MAXN];
int N;
bool vis[MAXN];
void Solve() {
    scanf("%lf%lf%lf%lf",&S.x,&S.y,&T.x,&T.y);
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
	scanf("%lf%lf%lf",&P[i].x,&P[i].y,&R[i]);
	dis[i] = max(0.0,(S - P[i]).norm() - R[i]);
    }
    for(int i = 1 ; i <= N ; ++i) {
	int u = -1;
	for(int j = 1 ; j <= N ; ++j) {
	    if(!vis[j]) {
		if(u == -1) u = j;
		else if(dis[j] < dis[u]) u = j;
	    }
	}
	vis[u] = 1;
	for(int j = 1 ; j <= N ; ++j) {
	    if(!vis[j]) {
		dis[j] = min(dis[j],dis[u] + max(0.0,(P[u] - P[j]).norm() - R[u] - R[j]));
	    }
	}
    }
    db ans = (S - T).norm();
    for(int i = 1 ; i <= N ; ++i) {
	ans = min(ans,dis[i] + max(0.0,(P[i] - T).norm() - R[i]));
    }
    printf("%.10lf\n",ans);
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

n, m = map(int, input().split())
a = []
for i in map(int, input().split()): heappush(a, i)

ans = []
for b, c in sorted([list(map(int, input().split()))for i in range(m)], key=lambda x:-x[1]):
        for i in range(b):
                if len(a)==0: break
                ans.append(max(c,  heappop(a)))
while len(a): ans.append(heappop(a))
print(sum(ans))

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, sum = 0;
    cin >> N;
    vector<int64_t> in(N), list(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> in[i];
        if (i % 2 == 0)
            list[0] += in[i];
        if (i % 2 == 1)
            list[0] -= in[i];
    }
    for (int i = 1; i < N; i++)
        list[i] = in[i - 1] * 2 - list[i - 1];
    for (auto x : list)
        cout << x << " ";
}

Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#define ll long long
#define maxn 0x3f3f3f3f
using namespace std;
int a[100010];
int b[100010];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	double k=a[n]*1.0;
	k = k/2.0;
	for(int i=1;i<=n-1;i++)
	{
		b[i]=(a[i]-k<0?-(a[i]-k):a[i]-k);
	}
	int minn=0x3f3f3f3f,sum=0;
	for(int i=1;i<=n-1;i++)
	{
		if(minn>b[i]){
			minn = b[i];
			sum = i;
		}
		
	}
	cout<<a[n]<<" "<<a[sum]<<endl;
}


Measured memory_bytes: 1024
N = int(input())
A = [int(x) for x in input().split()]
mod = 10**9+7
c = 1-N%2
flag = True
di = {}
if(N==1):
    if(A[0]==0):
        print(1)
    else:
        print(0)
else:
    for i in A:
        if(i not in di):
            di[i]=1
        else:
            di[i]+=1
    for i in range(N//2):
        if(i+c==0):
            if(0 not in di):
                flag = False
            else:
                flag &= (di[i]==1)
        else:
            if(i*2+c not in di):
                flag = False
            else:
                flag &= (di[i*2+c]==2)
        if(not flag):
            print(0)
            break
    else:
        print((2<<(N//2-1))%mod)


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int Min_diff = n;

    rep(i, n - 1) {
        if (s[i] != s[i + 1]) {
            Min_diff = min(Min_diff, max(i + 1, n - i - 1));
        }
    }

    cout << Min_diff << endl;

    return 0;
}

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

int main(){
    ll ans=0; string s; cin>>s;
    char state = ' ';
    ll rep = 0;
    int n=s.size()+1;
    vector<int> left(n,0);
    vector<int> right(n,0);
    for (int i=0; i<=s.size(); i++){
        if(s[i]=='<'){
            left[i+1]=left[i]+1;
        }
        else{
            left[i+1]=0;
        }
        if(s[n-i-2]=='>'){
            right[n-i-2]=right[n-i-1]+1;
        }
        else{
            right[n-i-2]=0;
        }
    }
    for(int i=0; i<n; i++) ans+=max(left[i], right[i]);
    cout << ans << endl;
}

Measured memory_bytes: 7648
def f(Hn, Wn):
    ret = float('inf')
    for Wi in range(1, Wn):
        h = Hn // 2
        w = Wn - Wi
        Sn = Wi * Hn, w * h, w * (Hn - h)
        ret = min(ret, max(Sn) - min(Sn))
        w //= 2
        Sn = Wi * Hn, w * Hn, (Wn - Wi - w) * Hn
        ret = min(ret, max(Sn) - min(Sn))
    return ret


def main():
    H, W = map(int, input().split())
    ans = f(H, W)
    if not ans:
        print(ans)
        return
    ans = min(ans, f(W, H))
    if not ans:
        print(ans)
        return
    print(ans)
    return


main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(void){
    string str[1000];
    int num = 0;
    
    while(1){
        cin >> str[num];
        if(str[num].at(0) == '0'){
            break;
        }
        ++num;
    }
    for(int i = 0;i < num;++i){
        int sum = 0;
        for(int j = 0;j < str[i].length();++j){
            sum += str[i].at(j) - '0';
        }
        cout << sum << endl;
    }
}



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

int main(){
  int n, m, i, j;
  scanf("%d %d", &n, &m);
  int a[n][m], b[m],  ans[n];
  for(i = 0; i < n; i++){
    ans[i] = 0;
    for(j = 0; j< m; j++)scanf("%d", &a[i][j]);
  }
  for(i = 0; i < m; i++) scanf("%d", &b[i]);

  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      ans[i] += (a[i][j] * b[j]);
    }
    printf("%d\n", ans[i]);
  }
}


Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextDouble()) {
			double[] p = new double[8];
			for (int i = 0; i < 8; i++)
				p[i] = sc.nextDouble();
			double s = 0.0;
			s += (p[0]-p[2])*(p[4]-p[6])+(p[1]-p[3])*(p[5]-p[7]);
			System.out.println(s==0.0?"YES":"NO");
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
using namespace std;
 
int main() {
	int a[200][3];
	int n;
	int ans[200];
	cin >> n;
	for(int i = 0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		ans[i]=0;
	}
	for(int i = 0;i<3;i++){
		int b[100];
		for(int j = 0;j<100;j++){
			b[j]=0;
		}
		for(int j = 0;j<n;j++){
			b[a[j][i]-1]++;
		}
		for(int j = 0;j<n;j++){
			if(b[a[j][i]-1]==1){ans[j]=a[j][i]+ans[j];}
		}
	}
	for(int i = 0;i<n;i++){
		cout <<ans[i] <<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m; cin >> n >> m;

	priority_queue<int> que;

	LL ans = 0;
	for (int i = 0; i < n; i++) {
		int val; cin >> val;
		ans += val;
		que.push(val);
	}

	for (int i = 0; i < m; i++) {
		int tmp=que.top();
		que.pop();
		ans -= tmp;

		ans += tmp / 2;

		que.push(tmp / 2);
	}

	cout << ans<< endl;

	return 0;
}

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

int main(){
  int N; 
  string S;
  cin >> N >> S;
  
  int ans = 1;
  for(int i = 1; i < N; i++){
    if(S[i-1] != S[i]) {
      ans++;
    }
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> G[100010];
queue<int> que;
priority_queue<int> que2;
int a[100010];
void bfs(){
	while(que.size()){
		int x = que.front();
		que.pop();
		for(auto v:G[x]){
			if(a[v]==-1){
				int y = que2.top();
				a[v] = y; que2.pop();
				que.push(v);
			}
		}
	}
}
long long sum = 0;
void solve(int v, int p){
	for(auto x:G[v]){
		if(x!=p){
			sum += min(a[x],a[v]);
			solve(x,v);
		}
	}
}

int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n-1;i++){
		int s,t; cin >> s >> t;
		s--; t--;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	for(i=0;i<n;i++){
		a[i] = -1;
		int c; cin >> c; que2.push(c);
	}
	a[0] = que2.top();
	que2.pop(); que.push(0);
	bfs(); solve(0,-1);
	cout << sum << endl;
	for(i=0;i<n;i++){
		cout << a[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 3584
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto n = readln.chomp.to!int;

	foreach (i; 0..n) {
		auto as = readln.split.map!(to!int);
		int l ,r;
		bool f;
		foreach (a; as) {
			if (l < a) l = a;
			else if (r < a) r = a;
			else {
				f = true;
			}
		}
		writeln(f?"NO":"YES");
	}
}

Measured memory_bytes: 1060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

//using Graph = vector<vector<pair<int, int>>>;
using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> cost;
Graph G;

void dfs(int v){
    seen[v] = true;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        cost[next_v]+=cost[v];
        dfs(next_v);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,q;
    cin>>n>>q;
    //Graph G(n);
    //vector<int> cost(n);
    //vector<bool> seen(n,false);
    G.resize(n);
    cost.resize(n);
    seen.resize(n,false);
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    int p,x;
    rep(i,q){
        cin>>p>>x;
        p--;
        cost[p]+=x;
    }

    seen[0]=true;
    dfs(0);

    rep(i,n){
        cout<<cost[i]<<endl;
    }   
}

Measured memory_bytes: 177408
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a<b){
  if(a<c&&c<b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  }
  if(a>b){
    if(a>c&&c>b){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N,ans=100;
      cin >> N;
      for (int i=0; i<N; i++){
        int a,count=0;
        cin >> a;
        while(a%2 == 0){
          a /= 2;
          count++;
        }
        if (count < ans)ans = count;
      }
      cout << ans;
    }

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


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

	char c = s[k - 1];

	string ans = "";
	for (char s_ele : s) {
		if (s_ele == c) {
			ans += s_ele;
		} else {
			ans += '*';
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    e = list(map(int, input().split()))
    e_set = list(set(e))

    if len(e_set) == 1:
        print("ok")
    else:
        f = True
        for i in range(len(e_set)):
            cnt = 0
            for j in range(len(e)):
                if e_set[i] == e[j]:
                    cnt += 1
            if cnt != 2:
                f = False
                break
        if f == False:
            print("no")
        else:
            print("yes")

if __name__ == "__main__":
    main()

Measured memory_bytes: 7780
N = int(input())
count = 0

def has_357(A):
    return '3' in A and '5' in A and '7' in A

def dfs(A):
    global count

    if A != '' and int(A) > N:
        return

    if has_357(A):
        count += 1

    for i in '357':
        A += i
        dfs(A)
        A = A[:-1]

    return count

print(dfs(''))


Measured memory_bytes: 2940
#include<stdio.h>

int main(void)
{
	int A,B,C,D,P,a,b;
	
	scanf("%d%d%d%d%d",&A,&B,&C,&D,&P);
	a=A*P;
	if(P<=C) b=B;
	else b=B+(P-C)*D;
	if(a<b) printf("%d\n",a);
	else printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
 
 
public class Main {
     
    public static void main(String[] args){
         
        Scanner sc = new Scanner(System.in);
         
        while(true){
             
            int n = sc.nextInt();
            int m = sc.nextInt();
            int a = sc.nextInt();
             
            if(n == 0 && m == 0 && a == 0){
                break;
            }
             
            int h[] = new int[m];
            int p[] = new int[m];
            int q[] = new int[m];
            int max = 0;
             
            for(int i = 0; i < m; i++){
                h[i] = sc.nextInt();
                p[i] = sc.nextInt();
                q[i] = sc.nextInt();
                if(h[i] > max){
                    max = h[i];
                }
            }
             
            int map[][] = new int[n + 1][max + 1];
             
            for(int i = 0; i < n + 1; i++){
                for(int j = 0; j < max + 1; j++){
                    map[i][j] = 0;
                }
            }
             
            for(int i = 0; i < m; i++){
                map[p[i]][h[i]] = q[i];
                map[q[i]][h[i]] = p[i];
            }
             
            int nowLocate[][] = new int[1][2];
            nowLocate[0][1] = max;
            nowLocate[0][0] = a;
             
            while(true){
                 
                if(nowLocate[0][1] == 0){
                    break;
                }
                if(map[nowLocate[0][0]][nowLocate[0][1]] != 0){
                    nowLocate[0][0] = map[nowLocate[0][0]][nowLocate[0][1]];
                }
                nowLocate[0][1]--;
            }
             
            System.out.println(nowLocate[0][0]);
             
        }
         
    }
 
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int l, n, m;

int main(){
	cin >> l >> n >> m;
	while(1){
		if(m==n+1){
			cout << "Borys"<< endl;
			return 0;
		}
		n++;
		if(n==m-1){
			cout << "Alice"<< endl;
			return 0;
		}
		m--;
	}
	return 0;
}

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

pos = 0
steps = 0
max_step = 0
fin = False

if len(h) == 1:
  print(0)
else:
  while fin == False:
    if h[pos] >= h[pos+1]:
      steps += 1
    else:
      steps=0

    pos += 1
    if steps > max_step:
      max_step = steps

    if pos == n-1:
      fin = True

  print(max_step)

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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
    int n, r, p[64], c[64];
    while (scanf("%d%d", &n, &r), n | r)
    {
	for (int i = 0; i < r; ++i)
	    scanf("%d%d", p + i, c + i);

	int pos = 1;
	for (int i = r - 1; i >= 0; --i)
	{
	    if (pos <= c[i])
		pos += p[i] - 1;
	    else if (pos <= c[i] + p[i] - 1)
		pos -= c[i];
	}
	printf("%d\n", n - (pos - 1));
    }
}

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


int main()
{
    int n, t, a;
    cin >> n >> t >> a;
    int height_;
    cin >> height_;
    int index = 0;
    double min = abs((t - height_ * 0.006) - a);
    for (int i = 1; i < n; i++)
    {
        int height;
        cin >> height;
        double tmp = abs((t - height * 0.006) - a);
        if (tmp < min)
        {
            min = tmp;
            index = i;
        }
    }
    cout << index + 1 << endl;

}

Measured memory_bytes: 256
MOD=10**9+7
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
dp=[0]*(n+1)
dp[0]=1
dp[1]=0 if 1 in a else 1  
for i in range(2,n+1):
  if i in a:
    dp[i]=0
  else:
    dp[i]=(dp[i-1]+dp[i-2])%MOD
print(dp[-1]%MOD)

Measured memory_bytes: 18992
require 'prime'
INF = 10 ** 9 + 7

n = gets.to_i
cnt = Hash.new(0)
Prime.each(n) do |i|
  d = i
  while n / d > 0
    cnt[i] += n / d
    d *= i
  end
end

res = 1
cnt.each do |k, v|
  res = (res * (v + 1)) % INF
end
puts res

Measured memory_bytes: 14328