akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
while True:
    N = int(input())
    if N == 0: break
    src = input().split()
    ctr = Counter()
    for i in range(N):
        ctr.update(src[i])
        if len(ctr) == 1:
            if list(ctr.values())[0] > N//2:
                print('{0} {1}'.format(list(ctr.keys())[0], i+1))
                break
        else:
            rem = N-1-i
            li = sorted(ctr.items(), key=lambda x:x[1], reverse=True)[:2]
            if li[0][1] > li[1][1] + rem:
                print('{0} {1}'.format(li[0][0], i+1))
                break
    else:
        print('TIE')

Measured memory_bytes: 5996
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll K = 0;
	ll M = 0;
	ll X = 0;
	//double a[100000] = {};
	//double b[100000] = {};
	//ll v[100] = {};
	ll *a, *b, *d;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;

	
	//char p;
	//cin >>N >> M;
	
	//vector<pair<float, float>> is(M);
	//sort(is.begin(), is.end());
	//a = (ll *)malloc(N * sizeof(ll));
	//b = (ll *)malloc(N * sizeof(ll));

	cin >> N;
	
	if (N >= 90 || N % 10 == 9)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	


		

	return 0;

}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

int main(){
    int n, m, b, j, ans=0;
    cin>>n;
    int a[n+1];
    for(int i=0; i<n; i++) cin>>a[i];
    cin>>m;
    for(int i=0; i<m; i++){
        cin>>b;
        a[n]=b;
        for( j=0; a[j]!=b; j++);
        if(j!=n)ans++;
            
    }
    cout<<ans<<endl;
    
}



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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int X, t;
    cin >> X >> t;
    cout << max(0, X-t) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = []
A = []
for i in range(n):
    a = int(input())
    A += [a]
    l_1 = []
    for j in range(a):
        l_1 += [list(map(int, input().split()))]
    l += [l_1]

ans = 0

for i in range(1 << n):
    honest = []
    liar = []
    for j in range(n):
        if ((i >> j) & 1):
            if j + 1 in liar:
                break
            elif j + 1 not in honest:
                honest += [j + 1]
            sugg = l[j]

            for k in sugg:
                if k[1] == 1:
                    if k[0] in liar:
                        break
                    elif k[0] not in honest:
                        honest += [k[0]]
                else:
                    if k[0] in honest:
                        break
                    elif k[0] not in liar:
                        liar += [k[0]]
            else:
                continue
            break

        else:
            if j + 1 in honest:
                break
            elif j + 1 not in liar:
                liar += [j + 1]
    else:
        if ans < len(honest):
            ans = len(honest)

print(ans)


Measured memory_bytes: 3064
N,M=map(int,input().split())
students=[list(map(int,input().split())) for i in range(N)]
checkpoints=[list(map(int,input().split())) for i in range(M)]

for i in range(N):
    A=[abs(students[i][0]-checkpoints[j][0])+abs(students[i][1]-checkpoints[j][1]) for j in range(M)]
    print(A.index(min(A))+1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fs first
#define sc second
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<D,D> pdd;
const D EPS = 1e-8;
const D PI = acos(-1);

int n,k;
pdd p[2000];
vector<pdd> v;
int max_r[2000], max_l[2000];

inline D modify(D seta){
  if(seta>PI)seta-=2*PI;
  if(seta<-PI)seta+=2*PI;
  return seta;
}

inline bool in_upper(D seta){
  seta = modify(seta);
  return (EPS<seta && seta<PI-EPS);
}

int main(){
  cin >> n >> k;
  rep(i,n){
    D x,y,r;
    cin >> x >> y >> r;
    P c = P(x,y);
    D d = abs(c), s = arg(c), a = sqrt(d*d-r*r);
    D ds = acos( (d*d + a*a - r*r)/(2*d*a) );
    
    D start = modify(s-ds), end = modify(s+ds);
    pdd tmp = pdd(in_upper(start)?start:0, in_upper(end)?end:PI);
    if(tmp.fs<EPS && PI-EPS<tmp.sc)continue;
    v.push_back(tmp);
  }

  sort(v.begin(),v.end());

  rep(i,v.size())rep(j,v.size()){
    if(i==j)continue;
    if(v[j].fs-EPS<v[i].fs && v[i].sc<v[j].sc+EPS){
      v.erase(v.begin()+i);
      i--;
      break;
    }
  }

  rep(i,v.size()){
    int id = -1;
    max_l[i] = v.size();
    for(int j=i+1;j<(int)v.size();j++){
      if(v[j].fs+EPS<v[i].sc){
	if(id<0 || v[id].sc+EPS < v[j].sc)id = j;
      }else{
	max_l[i] = j;
	break;
      }
    }
    max_r[i] = id;
  }
  
  vector< vector<D> > dp1(v.size()+1,vector<D>(k+1,0));
  vector< vector<D> > dp2(v.size()+1,vector<D>(k+1,0));

  rep(i,v.size()){
    rep(j,k+1){
      dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j]);
      if(j+1<=k){
	D use = max(dp1[i][j], dp2[i][j]);
	dp1[max_l[i]][j+1] = max(dp1[max_l[i]][j+1], use + v[i].sc-v[i].fs);
	if(max_r[i]>=0){
	  dp2[max_r[i]][j+1] = max(dp2[max_r[i]][j+1], use + v[max_r[i]].fs-v[i].fs);
	}
      }
    }
  }

  D ans = 0;
  rep(i,k+1){
    ans = max(ans, max(dp1[v.size()][i], dp2[v.size()][i]) );
  }
  cout << fixed << setprecision(10) << ans/PI << endl;
}

Measured memory_bytes: 36644
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
ll n , m;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  if(n==1&&m==1) {
    cout<<1<<endl;
    return;
  }
  if(n==1||m==1) {
    cout<<n*m-2<<endl;
  } else if(n==2 && m <4 || n <4 && m == 2) cout<<0<<endl;
  else cout<<(n-2)*(m-2)<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int n;cin>>n;
	int x[n],y[n];
	rep(i,n)cin>>x[i]>>y[i];
	map<P,int>mp;
	rep(i,n){
		rep(j,n){
			if(i==j)continue;
			mp[{x[i]-x[j],y[i]-y[j]}]++;
		}
	}
	int ans =n;
	for(auto x:mp){
		ans=min(ans,n-x.second);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int32_t main(){_
    //freopen("input","r",stdin);
    string s;
    set<char>st;
    cin >> s;
    for(auto it : s) st.insert(it);
    if(sz(st) == 4) rc("Yes");
    if(sz(st) == 2)
    {
        auto it1 = st.begin();
        auto it2 = st.begin();
        it2++;
        char a = *it1;
        char b = *it2;
        if(a == 'N' && b == 'S') rc("Yes");
        if(a == 'E' && b == 'W') rc("Yes");
        swap(a,b);
            if(a == 'N' && b == 'S') rc("Yes");
        if(a == 'E' && b == 'W') rc("Yes");

    }
    rc("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define double long double
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;
const double EPS = 1e-12;
 
int m, n;
double p[17][17];
double memo[1LL << 16][17];
 
// double rec(int mask, int now, int id){
//     if(id == n){
//         // cout << mask << ' ' << now << ' ' << id << ' ' << 1.0 << endl;
//         return 1.0;
//     }
//     if(mask == 0 || (mask & (1LL << now)) == 0){
//         // cout << mask << ' ' << now << ' ' << id << ' ' << 0.0 << endl;
//         return 0.0;
//     }
//     if(memo[mask][now][id] > -EPS) return memo[mask][now][id];
//     double res = 0.0;
//     rep(i, 0, m){
//         if(!(mask & (1LL << i))) continue;
//         if(i == now) continue;
//         double tmp = rec(mask - (1LL << now), i, id);
//         res = max(res, tmp);
//     }
//     res = p[now][id] * rec(mask, now, id + 1) + (1 - p[now][id]) * res;
//     // cout << mask << ' ' << now << ' ' << id << ' ' << res << endl;
//     return memo[mask][now][id] = res;
// }
 
double rec(int mask, int id){
    if(id == n){
        // cout << mask << ' ' << id << ' ' << 1.0 << endl;
        return 1.0;
    }
    if(mask == 0){
        // cout << mask << ' ' << id << ' ' << 0.0 << endl;
        return 0.0;
    }
    if(memo[mask][id] > -EPS) return memo[mask][id];
    double res = 0.0;
    rep(i, 0, m){
        if(!(mask & (1LL << i))) continue;
        double tmp = 0.0, now = 1.0;
        rep(j, id, n){
            // j番目に負けた場合
            tmp += now * (1 - p[i][j]) * rec(mask - (1LL << i), j);
            now *= p[i][j];
        }
        tmp += now;
        // tmp = p[i][id] *  rec(mask - (1LL << now), i, id);
        res = max(res, tmp);
    }
    // res = p[now][id] * rec(mask, now, id + 1) + (1 - p[now][id]) * res;
    // cout << mask << ' ' << id << ' ' << res << endl;
    return memo[mask][id] = res;
}
 
int main(){
    cin >> m >> n;
    rep(i, 0, m){
        rep(j, 0, n){
            cin >> p[i][j];
        }
    }
    rep(i, 0, 1 << m) rep(k, 0, n + 1) memo[i][k] = -1.0;
    double ans = 0.0;
    ans = rec((1LL << m) - 1, 0);
    printf("%.20Lf\n", ans);
}


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

namespace kozaiyApp
{
    public class C
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = new string[N];

            for (int i = 0; i < N; i++)
            {
                str[i] = Console.ReadLine();
            }

            var ans = str.Distinct();

            Console.WriteLine(ans.Count());
        }
    }
}


Measured memory_bytes: 48148
n,k = map(int,input().split())
p = list(map(int,input().split()))
for i in range(n):
    p[i] -= 1
c = list(map(int,input().split()))

reach = [False]*n
x = []
for i in range(n):
    if reach[i]:continue
    buf = []
    cur = i
    while not reach[cur]:
        buf.append(c[cur])
        reach[cur] = True
        cur = p[cur]
    x.append(buf)

ans = max(c)
import itertools
for i in x:
    n = k//len(i)
    ind = k%len(i)
    if n>0:
        n -= 1
        ind += len(i)
    else:
        ind = min(k,len(i)*2)
    ii = i+i+i
    r = list(itertools.accumulate(ii))
    a = max(0,r[len(i)-1]*n)
    for j in range(len(i)):
        for z in range(1,ind+1):
            s = r[j+z]-r[j]
            if z<ind+1:ans = max(ans,a+s)
            else:ans = max(ans,s)
print(ans)


Measured memory_bytes: 74776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int a[22][22];
const int mx = (1<<22);
int dp[22][mx];
int go[22][mx];
int sz[22];
int mod = 1e9+7;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; 
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<(1<<n);i++){
		int cnt = 0;
		for(int j=0;j<n;j++){
			if(i&(1<<j))cnt++;
		}
		go[cnt][sz[cnt]++] = i;
	}
	dp[0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<sz[i-1];j++){
			int msk = go[i-1][j];
			for(int k=0;k<n;k++){
				if(msk&(1<<k))continue;
				if(a[i-1][k]==0)continue;
				dp[i][msk|(1<<k)]+=dp[i-1][msk];
				if(dp[i][msk|(1<<k)]>=mod)dp[i][msk|(1<<k)]-=mod;
//				cout<<i<<" "<<k<<" "<<(msk&(1<<k))<<" "<<dp[i][msk&(1<<k)]<<endl;
			}
		}
	}
	cout<<dp[n][(1<<n)-1]<<endl;
	return 0;
}


Measured memory_bytes: 223488
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a <= c && c <= b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
#define INF bit(60)
#define pb push_back
#define mod 1000000007
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
using namespace std;
using uif=uint_fast64_t;
using ll=long long int;
 
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
 
#define FACSIZE 2002
 
ll invfac[FACSIZE];
ll fac[FACSIZE];
 
ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );
 
 
 
int main(void){
 
  ll mon[4]{0,300000,200000,100000};
  ll x,y;
  cin>>x>>y;
  ll ans=0;
  if(x>3)x=0;
  if(y>3)y=0;
  if(x==1 && y==1) ans+=400000;
  ans+=mon[x]+mon[y];
  
  cout << ans << endl;
 
  return 0;
 
}
 
ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}
 
ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}
 
ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}
 
void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}
 
void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }
 
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	char a1[4],a2[4];
  scanf("%s%s",a1,a2);
  int t=0;
  for(int i=0;i<3;i++){
  	if(a1[i]==a2[i]) t++;
  }
  printf("%d\n",t);
	return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define INF 100000000

int calc_digit(ll n) {
  int res = 0;

  while (n > 0) {
    res++;

    n /= 10;
  }

  return res;
}

int main() {
  ll n;
  cin >> n;

  ll ans = INF;

  for (ll a = 1; a * a <= n; a++) {
    if (n % a != 0) continue;

    ll b = n / a;
    ll tmp = max(calc_digit(a), calc_digit(b));
    ans = min(ans, tmp);
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
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() {
    ll n,ans=0;
	cin >> n;
	vector<vector<ll> > a(3, vector<ll>(n+1,0));
	vector<vector<ll> > dp(3, vector<ll>(n + 1, 0));
	for (ll i = 1; i <= 2; i++) {
		for (ll j = 1; j <= n; j++) {
			cin >> a[i][j];
		}
	}
	dp[1][1] = a[1][1];
	for (ll i = 1; i <=2; i++) {
		for (ll j = 1; j <= n; j++) {
			dp[i][j] = max(dp[i - 1][j] + a[i][j], dp[i][j - 1] + a[i][j]);
		}
	}
	cout<< dp[2][n] << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i, n)  FOR(i,0,(n))


class BChristmasEveEve {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n;
      in >> n;
      vector<int> p(n);
      REP(i, n) in >> p[i];
      int max_ele = *max_element(p.begin(), p.end());
      int t = max_ele / 2;
      int ans = 0;
      REP(i, n) {
        ans += p[i];
      }
      out << ans - t << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BChristmasEveEve solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
A = input()
B = input()

flag = True
if len(A) != len(B):
  flag = False 

pair_dict = dict()
reverse_dict = dict()
for i in range(len(A)):
  if A[i] not in pair_dict:
    pair_dict[A[i]] = B[i]
  elif pair_dict[A[i]] != B[i]:
    flag = False
    break
  if B[i] not in reverse_dict:
    reverse_dict[B[i]] = A[i]
  elif reverse_dict[B[i]] != A[i]:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3632
use std::io;

#[allow(unused_must_use)]
fn main() {
    let (n, mut x) = {
        let s = {
            let mut s = String::new();
            io::stdin().read_line(&mut s).unwrap();
            s.trim_right().to_owned()
        };
        let mut ws = s.split_whitespace();
        let n: i64 = ws.next().unwrap().parse().unwrap();
        let x: i64 = ws.next().unwrap().parse().unwrap();
        (n, x)
    };
    let mut a: Vec<i64> = {
        let s = {
            let mut s = String::new();
            io::stdin().read_line(&mut s).unwrap();
            s.trim_right().to_owned()
        };
        let ws = s.split_whitespace();
        let mut a = vec![];
        for i in ws {
            a.push(i.parse().unwrap());
        }
        a
    };
    if x == a.iter().sum() {
        print!("{}", n);
        return
    }
    a.sort();
    let mut cnt = 0;
    for ai in a {
        x -= ai;
        if x < 0 {
            print!("{}", cnt);
            return
        }
        cnt += 1;
    }
    print!("{}", cnt - 1);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
bool is_h_number(int n) {
	int temp = n;
	int num[9];
	for (int i = 0; i < 9; i++) {
		num[i] = n % 10;
		n /= 10;
	}
	int sum = 0;
	for (int i = 0; i < 9; i++) {
		sum += num[i];
	}
	if (temp%sum == 0) {
		return 1;
	}
	return 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	if (is_h_number(n)) {
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  reps(x, 100000) {
    int y = x + (x * 8 / 100);
    if (n == y) {
      cout << x << endl;
      return;
    }
  }
  cout << ":(" << endl;
}


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

int main(){
    int h,w,k;
    cin >>h>>w>>k;
    vector<string> C(h);
    rep(i, h){
            cin >> C[i];
    }
    int ans=0;
    rep(r, (1<<h)){
        rep(c, (1<<w)){
            int black = 0;
            rep(i, h){
                if((r & (1<<i)) != 0){
                        continue;
                    }
                rep(j, w){
                    if((c & (1<<j)) != 0){
                        continue;
                    }
                    if(C[i][j] == '#'){
                        black++;
                    }
                }
            }
            if(black==k) ans += 1;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int n;
    cin >> n;
    for(int i = 9;i > 0;i--) {
        if(n % i == 0 && n / i < 10) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

INF = float("inf")
# bitで表される状態を満たすための最小コスト
# ex. N=2
# [00]=1つも開かない, [01]=1だけ開く, [10]=2だけ開く, [11]=1,2の両方開く
dp = [INF] * (2**N)
# 1つも開かない状態はコスト0で実現される
dp[0] = 0

for i in range(1, M + 1):
    a, b = map(int, input().split())

    # ex.
    # c = [1] -> tmp = 01(2) = 1
    # c = [2] -> tmp = 10(2) = 2
    # c = [1,2] -> tmp = 11(2) = 3
    tmp = 0
    for c in list(map(int, input().split())):
        tmp += 1 << (c - 1)

    # target = ある状態(j)に対して、鍵(tmp)を使った後の状態
    # ex.
    # 状態00に鍵01を使う -> 結果は01(1が新しく開く)
    # 状態01に鍵01を使う -> 結果は01（変わらない）
    # 状態10に鍵01を使う -> 結果は11（１が新しく開く）
    # 状態11に鍵01を使う -> 結果は11（１が新しく開く）
    for j in range(2**N):
        # | = 論理和(OR)
        target = j | tmp
        # 状態jから鍵のコストaを支払ってtargetに遷移 or そのまま
        dp[target] = min(dp[j] + a, dp[target])

# 更新されていない場合、全て開けることは実現できない
if dp[2**N - 1] == INF:
    print(-1)
# 更新されている場合、全て開けることが可能
else:
    print(dp[2**N - 1])


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

using namespace std;

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

    int H, W, K;
    cin >> H >> W >> K;
    vector<string> s(H);
    for (int i = 0; i < H; ++i) {
        cin >> s[i];
    }
    vector<vector<int>> a(H, vector<int>(W));
    int first_non_empty = H + 1, cur_ind = 1;
    for (int i = 0; i < H; ++i) {
        vector<int> sb{-1};
        for (int j = 0; j < W; ++j) {
            if (s[i][j] == '#') 
                sb.push_back(j);
        }
        if (sb.size() == 1U) {
            if (i > 0) 
                a[i] = a[i - 1];
        } else {
            first_non_empty = min(first_non_empty, i);
            for (int j = 1; j < (int)sb.size(); ++j) {
                for (int m = sb[j - 1] + 1; m <= sb[j]; ++m)
                    a[i][m] = cur_ind;
                ++cur_ind;
            }
            for (int m = sb.back() + 1; m < W; ++m) 
                a[i][m] = cur_ind - 1;
        }
    }
    // first row might be empty
    for (int i = first_non_empty - 1; i >= 0; --i) {
        a[i] = a[i + 1];
    }
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cout << a[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 1280
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n,a,b;
void solve(){
	priority_queue<double,vector<double>,greater<double> > q;
	cin>>n;
	double t;
	rep(i,0,n){
		cin>>t;
		q.push(t);
	}
	while(q.size()>1){
		double x = q.top();q.pop();
		double y = q.top();q.pop();
		q.push((x+y)/2); 
	}
	cout<<q.top();
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
const ll MOD = 1000000007;

int main() {
    ll n,ans = 0;
    cin >> n;
    ll l[n];
    rep(i,n) {
        cin >> l[i];
    }
    Sort(l,n)
    for(ll i = 0;i < n;i++) {
        for(ll j = i + 1;j < n;j++) {
            for(ll k = j + 1;k < n;k++) {
                if(l[i] + l[j] > l[k]) {
                    ans++;
                }
            }
        }
    }
    cout <<ans;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<set>
#include<utility>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<cinttypes>
#include<stack>
using namespace std;

typedef long long ll;


#define ceil(a,b)  ( !(a%b) ? a/b : a/b+1 )
#define all(a)  (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define endl '\n' 
#define debug(a) cin>>#a>>a;
//vector<ll> primes{ }

int gcd( int a, int b ) { return !a ? b : gcd( b%a, a); }
int lcm( int a, int b ) { return (a*b)/gcd(a,b); } 

int main(){
    int n;
   cin>>n;
   if( n%1000 )
        cout<<(1000-(n%1000))<<endl; 
   else
    cout<<n%1000<<endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

bool f[SIZE];

int main(){
  int N;
  char s[SIZE];

  scanf("%d%s", &N, s);

  int sum = 0;

  for(int i=0; i<2*N; i++) {
    if((s[i] == 'B') ^ (sum % 2 == 1)) {
      f[i] = true;
      sum++;
    } else {
      f[i] = false;
      sum--;
    }
  }

  ll ans = 1;
  int t = 0;

  for(int i=2*N-1; i>=0; i--){
    debug(f[i]);
    if (!f[i]) {
      t++;
    } else {
      debug(t);
      ans = (ans * t) % mod;
      t--;
    }
  }

  for(int i=1; i<=N; i++) {
    ans *= i;
    ans %= mod;
  }

  if (t != 0) {
    cout << 0 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 640
# coding: utf-8
N, K = map(int, input().split())
r, s, p = map(int, input().split())
T = input()
F = [True] * len(T)
point = {"r":p, "s":r, "p":s}
ans = 0
for i in range(len(T)):
    if i < K:
        ans += point[T[i]]
        F[i] = False
    else:
        if T[i] == T[i-K]:
            if F[i - K]:
                ans += point[T[i]]
                F[i] = False
        else:
            ans += point[T[i]]
            F[i] = False
print(ans)

Measured memory_bytes: 40688
s=input()
if ((s.count("S")>=1 and s.count("N")==0) or (s.count("N")>=1 and s.count("S")==0)
   or (s.count("W")>=1 and s.count("E")==0) or (s.count("E")>=1 and s.count("W")==0)):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include<cstdio>
#include<cctype>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;

#define REP(i, N) for(int i=0;i<(int)(N);++i)

int unit[20];
int need[20];

int nextInt() {int r = 0, ch; while( isspace(ch = getchar())); do {r = r * 10 + ch - '0';}while( isdigit( ch = getchar() ) ); return r;}

int best;
int N, U;
int tno;
int gain[20];
char visited[1 << 20];
void dfs(int mask, int one, int have) {
  if( best <= one ) return;
  if( have >= U ) {
    best = one;
    return;
  }
  if( have + gain[best - one - 1] < U ) return;

  for(int i = 0; i < N; i++)
    if ( visited[mask | (1 << i)] != tno && (mask | need[i]) == mask )
      {
        visited[mask | (1 << i)] = tno;
        dfs( mask | (1 << i), one + 1, have + unit[i] );
      }
}

int main() {
  for(tno = 1;; tno++) {
    N = nextInt();
    U = nextInt();
    if( N == 0 && U == 0 ) break;
    REP(i, N) need[i] = 0;

    int all = 0;
    REP(i, N) {
      unit[i] = nextInt();
      all += unit[i];
      gain[i] = unit[i];
      int K = nextInt();
      REP(k, K) {
        int x = nextInt();
        need[i] |= (1 << x);
      }
    }

    sort( gain, gain + N );
    reverse( gain, gain + N );
    for(int i = 1; i < N; i++)
      gain[i] += gain[i - 1];

    if( all == U ) {
      printf("%d\n", N);
      continue;
    }

    best = N;
    dfs(0, 0, 0);
    printf("%d\n", best);
  }
}

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


int main(){
	long long n,k;
	cin >> n >> k;
	long long min = n;
	if(n>k){
		n = n%k;
	}
	if(n%k==0){
		cout << 0;
		return 0;
	}
	while (1){
		n = abs(n-k);
		if(n < min && n!=0){
			min = n;
		}else{
			cout << min;
			return 0;
		}
	}
	if(n!=0){
	cout << min;	
	}else{
		cout << 0;
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

vector<pair<double,int>> v[1010];
double dist[1010];
const double INF=1e10;

void dijkstra(){
  priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> PQ;
  for(int i=0;i<=1005;i++){
    dist[i]=INF;
  }

  PQ.push(make_pair(0,0));
  dist[0]=0;
  while(!PQ.empty()){
    pair<double,int> f=PQ.top();
    PQ.pop();
    int u=f.second;

    if(dist[u]<f.first) continue;

    for(int j=0;j<v[u].size();j++){
      int w=v[u][j].second;
      if(dist[w]>dist[u]+v[u][j].first){
        dist[w]=dist[u]+v[u][j].first;
        PQ.push(make_pair(dist[w],w));
      }
    }
  }
}

int main(){
  int xs,ys,xt,yt;
  cin>>xs>>ys>>xt>>yt;
  int n;
  cin>>n;
  double x[n+2]={},y[n+2]={},r[n+2]={};
  x[0]=xs;y[0]=ys;
  x[n+1]=xt;y[n+1]=yt;

  for(int i=1;i<=n;i++){
    cin>>x[i]>>y[i]>>r[i];
  }

  for(int i=0;i<=n+1;i++){
    for(int j=i+1;j<=n+1;j++){
      double z=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))-(r[i]+r[j]);
      z=max((double)0,z);
      v[i].push_back(make_pair(z,j));
      v[j].push_back(make_pair(z,i));
    }
  }

  dijkstra();
  cout<<fixed<<setprecision(15)<<dist[n+1]<<endl;

  return 0;
}


Measured memory_bytes: 22676
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		br.close();

		int n = s.length();
		int ans = n;
		for (int i = 1; i < n; i++) {
			if (s.charAt(i - 1) != s.charAt(i)) {
				int m = Math.max(i, n - i);
				ans = Math.min(ans, m);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

int main() {
    string S;
    string T;
    cin >> S >> T;
    int N = S.size();
    for(int i = 0; i < 26; i++){
        char c = char(i + 'a');
        vector<int> idxs = {};
        for(int j = 0; j < N; j++){
            if(c == S[j]){
                idxs.push_back(j);
            }
        }
        if(idxs.size() == 0) continue;
        char becon = T[idxs[0]];
        for(int k = 1; k < idxs.size(); k++){
            if(T[idxs[k]] != becon){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    for(int i = 0; i < 26; i++){
        char c = char(i + 'a');
        vector<int> idxs = {};
        for(int j = 0; j < N; j++){
            if(c == T[j]){
                idxs.push_back(j);
            }
        }
        if(idxs.size() == 0) continue;
        char becon = S[idxs[0]];
        for(int k = 1; k < idxs.size(); k++){
            if(S[idxs[k]] != becon){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" <<endl;
    return 0;
}

Measured memory_bytes: 1528
fun main(args: Array<String>) {
    val (N, K) = listOfInt()
    val A = listOfInt()
    var ans1 = ModInt(0)
    for (n in 0 until N-1) {
        for (m in n+1 until N) {
            if (A[n] > A[m]) {
                ans1 += 1
            }
        }
    }
    ans1 = ans1 * K
    var ans2 = ModInt(0)
    for (n in 0 until N) {
        for (m in 0 until N) {
            if (A[n] > A[m]) {
                ans2 += 1
            }
        }
    }
    ans2 *= K
    ans2 *= (K - 1)
    ans2 /= 2
    println(ans1 + ans2)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
data class ModInt(private var v: Long) {
    companion object {
        private const val MOD = 1000000007L
    }
    init {
        if (v >= MOD) v %= MOD
    }
    operator fun plus(other: ModInt): ModInt {
        val x = v + other.v
        if (x >= MOD) {
            return ModInt(x - MOD)
        }
        return ModInt(x)
    }
    operator fun plus(other: Int): ModInt {
        val x = v + other.toLong()
        if (x >= MOD) {
            return ModInt(x - MOD)
        }
        return ModInt(x)
    }
    operator fun minus(other: ModInt): ModInt {
        val x = v + MOD - other.v
        if (x >= MOD) {
            return ModInt(x - MOD)
        }
        return ModInt(x)
    }
    operator fun times(other: ModInt): ModInt {
        return ModInt(v * other.v % MOD)
    }
    operator fun times(other: Int): ModInt {
        return ModInt(v * other.toLong() % MOD)
    }
    operator fun div(other: ModInt): ModInt {
        return ModInt(v * calc(other.v, MOD - 2) % MOD)
    }
    operator fun div(other: Int): ModInt {
        return ModInt(v * calc(other.toLong(), MOD - 2) % MOD)
    }
    private fun calc(a: Long, b: Long): Long {
        if (b == 0L) return 1L
        if (b % 2L == 0L) {
            val d = calc(a, b / 2)
            return d * d % MOD
        }
        return a * calc(a, b - 1) % MOD
    }
    override fun toString(): String {
        return v.toString()
    }
}

Measured memory_bytes: 58468
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, k; scanf("%d%d", &n, &k);
	std::vector<int> A, B;
	int count = 0;
	for(int i = 0; i < n; i++) {
		int a; scanf("%d", &a);
		
		if(a == 0) count++;
		else if(a < 0) A.push_back(-a);
		else B.push_back(a);
	}
	sort(begin(A), end(A)); sort(begin(B), end(B));
	
	if(k <= count) {
		printf("0\n");
		return 0;
	}
	k -= count;
	
	int ans = 1 << 30;
	if(k <= A.size()) ans = std::min(ans, A[k - 1]);
	if(k <= B.size()) ans = std::min(ans, B[k - 1]);
	for(int i = 0; i < A.size(); i++) {
		if(k - i - 1 > B.size()) continue;
		if(k - i - 1 == 0) break;
		ans = std::min({ans, 2 * A[i] + B[k - i - 2], A[i] + 2 * B[k - i - 2]});
	}
	printf("%d\n", ans);
	return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M,Q;
string S,T;
int accS [100001],accT [100001];

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

	cin >> S >> T;
	N = S.size();
	M = T.size();
	FOR(i,0,N){
		accS [i + 1] = accS [i] + (S [i] == 'A' ? 1 : 2);
	}
	FOR(i,0,M){
		accT [i + 1] = accT [i] + (T [i] == 'A' ? 1 : 2);
	}

	cin >> Q;
	FOR(i,0,Q){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		if((accS [b] - accS [a - 1]) % 3 == (accT [d] - accT [c - 1]) % 3){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}

	return 0;
}


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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



//for dfs, I prepare container(tree) at global
vector<int> to[200005];
vector<int> ans(200005);
void dfs(int v, int p = -1){
	for(int u: to[v]){
		if(u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

//#define int int64_t
signed main()
{
	int n, q; cin >> n >> q;
	for(int i = 0, i_len = (int)n-1; i < i_len; ++i){
		int a, b;
		cin >> a >> b;
		--a;--b;
		to[a].emplace_back(b);
		to[b].emplace_back(a);		
	}
	//ans.resize(n);
	for(int i = 0, i_len = (int)q; i < i_len; ++i){
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);

	for(int i = 0, i_len = (int)n; i < i_len; ++i){
		cout << ans[i] << '\n';
	}

}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

const int M = 300 * 300 + 1;

int n, a[300], MOD = 998244353;
LL dp[2][M + 300];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	int s = 0;
	inc(i, n) { s += a[i]; }
	
	dp[0][0] = 1;
	inc(i, n) {
	dec(j, M) {
		(dp[0][j + a[i]] += 2 * dp[0][j]) %= MOD;
	}
	}
	
	dp[1][0] = 1;
	inc(i, n) {
	dec(j, M) {
		(dp[1][j + a[i]] += dp[1][j]) %= MOD;
	}
	}
	
	LL ans = 1;
	inc(i, n) { (ans *= 3) %= MOD; }
	
	incII(j, 0, M) {
		if(2 * j <= s) { (ans -= 3 * dp[0][j]) %= MOD; }
	}
	
	if(s % 2 == 0) { ans += (3 * dp[1][s / 2]); }
	ans = mo(ans, MOD);
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1664
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;
   
   
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)
   
typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;
   
const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;


//begin global variable
//end   global variable

int main(){
  ios::sync_with_stdio(false);
  //begin main()
  int N;
  int a[100001];
  int ans =0;
  cin >> N;
  REP(i,N) cin >> a[i];
  REP(i,N) if(a[a[i]] == i) ++ans;
  
  cout << ans/2 << endl;
  //end   main()
  return 0;
}


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

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

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

#define INF INT_MAX/3

ll n;
map<ll,ll> cnt;

int main(){
  cin>>n;
  rep(i,n){
    ll a;
    cin>>a;
    cnt[a]++;
  }
  ll res=0;
  for(P p : cnt){
    if(p.se>n){
      res+=p.fi;
      continue;
    }
    if(p.fi>p.se)res+=p.se;
    else res+=p.se-p.fi;
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h)cin >> s[i];
    int ans = 0;
    for(int i=0;i< 1<<(h+w);i++){
        vector<string> t = s;
        for(int j=0;j<h;j++){
            if( (i>>j) & 1){
                //  j行を赤く塗る
                rep(x,w)t[j][x] = '.';
            }
        }
        for(int j=h;j<h+w;j++){
            if( (i>>j) & 1){
                // (j-h)列目を赤く塗る
                rep(x,h)t[x][j-h] = '.';
            }
        }
        int cnt = 0;
        rep(x,h)rep(y,w)if(t[x][y] == '#')cnt++;
        if(cnt == k)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644