akhauriyash/Code-Regression huggingface dataset:
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();
			if(n == 0) break;
			int[] w = new int[n + 1];
			for(int i = 1; i <= n; i++) {
				w[i] = sc.nextInt();
			}
			int[][] dp = new int[n + 1][n + 1];
			for(int i = 1; i < n; i++) {
				dp[i][i + 1] = Math.abs(w[i] - w[i + 1]) <= 1 ? 2 : 0;
			}
			for(int j = 2; j < n; j++) {
				for(int i = 1; i + j <= n; i++) {
					if(dp[i + 1][i + j - 1] == j - 1 && Math.abs(w[i] - w[i + j]) <= 1) {
						dp[i][i + j] = j - 1 + 2;
					}
					for(int k = 0; k < j; k++) {
						dp[i][i + j] = Math.max(dp[i][i + k] + dp[i + k + 1][i + j], dp[i][i + j]);
					}
				}
			}
			System.out.println(dp[1][n]);
		}
	}
}



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

struct SetStk {
  vector<vector<LL>> stk;
  void add(LL x) {
    stk.push_back({x});
    while (stk.size() > 1) {
      int n = stk.size();
      if (stk[n - 1].size() == stk[n - 2].size()) {
        vector<LL> ans;
        merge(stk[n - 2].begin(), stk[n - 2].end(), 
              stk[n - 1].begin(), stk[n - 1].end(), back_inserter(ans));
        stk.pop_back();
        stk.back() = ans;
      }
      else break;
    }
  }
  int rank(LL a) {
    LL ans = 0;
    for (int i = 0; i < stk.size(); ++i) {
      auto &A = stk[i];
      ans += upper_bound(A.begin(), A.end(), a) - stk[i].begin();
    }
    return ans;
  }
};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, k; cin >> n >> k;
  vector<LL> A(n + 1);
  for (int i = 0; i < n; ++i) cin >> A[i + 1], A[i + 1] -= k, A[i + 1] += A[i];
  SetStk ds;
  LL ans = 0;
  ds.add(A[0]);
  for (int i = 1; i <= n; ++i) {
    ans += ds.rank(A[i]);
    ds.add(A[i]);
  }
  cout << ans << '\n';
}  


Measured memory_bytes: 4848
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    int n;
    cin>>n;
    vec l(n);
    rep(i,n) cin>>l[i];
    int sum=0;
    sort(all(l));
    rep(i,n-1) sum+=l[i];
    if(l[n-1]<sum) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, 0, n)

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

ll a[2010];

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

        double o = 0;
        int count = 0;
        if (N>=0){
            while(N <= o){
                o += pow((double)2,(double)count);
                count+=2;
            }
        }

    	return 0;
    }
    */

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

    int T = N%K;

    if(T>0){
        cout << 1;
    }else{
        cout << 0;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////
int N, M;
vector<int>G[10];
vector<bool>visited(10, false);
int ans = 0;
int cnt = 0;
int dfs(int now,int cnt) {
	if (visited[now])return 0;
	if (cnt == N - 1)return 1;
	visited[now] = true;
	int ans = 0;
	for (int a : G[now]) {
		ans += dfs(a, cnt + 1);
	}
	visited[now] = false;
	return ans;
}
int main() {
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cout << dfs(0,0) << endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
hoge = [int(i) for i in input().split()]

for i in range(N):
  sa=T-0.006*hoge[i]-A
  if(sa<0):
    sa=-sa
  hoge[i]=sa

print(hoge.index(min(hoge))+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define pb(s) push_back(s)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
  ll A;
  ll B;
  ll C;
  cin >>A>>B>>C;
  
  
  if((A%2==0) || (B%2==0) || (C%2==0) )  {
    cout<<0<<endl;
  }
  
  else {
    if((A>=B) &&(B>=C)) {
      ll a=B*C;
    cout<<a<<endl;
    }
    else if((A>=C)&&(C>=B)) {
      ll a=B*C;
      cout<<a<<endl;
    }
 else if((B>=A)&&(A>=C)) {
      ll a=A*C;
      cout<<a<<endl;
    }
    else if((B>=C)&&(C>=A)) {
      ll a=A*C;
      cout<<a<<endl;
    }
    else if((C>=A)&&(A>=B)) {
      ll a=B*A;
      cout<<a<<endl;
    }
    else if((C>=B)&&(B>=A)) {
      ll a=B*A;
      cout<<a<<endl;
    }
    
  }
  
  
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define INF 1000000
#define watch(x) cout << setw(10) << "[" << (#x) << ":] " << (x) 
#define FORE(i,v,n) for(int i=v;i<n;i++)
#define FORI(i,v,n) for(int i=v;i<=n;i++)
#define vi vector<int>;
#define pii pair<int, int>

using namespace std;
using namespace __gnu_pbds;

//typedef tree <int, null_type, less<int> rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int const MOD = 1000000007;

int test_case(){
	unsigned long long int n,k;
	cin >> n >> k;
	unsigned long long int answer = min(k-n%k,n%k);
	cout << answer;
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int test=1;
	//cin >> test;
	for(int i=0;i<test;i++){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
  int n,i,j,ans=1;
  if(scanf("%d", &n)==1);
  if(n>1){
    for(i=2;i<sqrt(n);i++){
    for(j=i*i;j*i<=n;j*=i);
    if(j<=n && j>ans)ans=j;
  }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
main(){int A,B,C,D,i=8;scanf("%1d%1d%1d%1d",&A,&B,&C,&D);while(i--)if(A+(i&4?-B:B)+(i&2?-C:C)+(i&1?-D:D)==7){char p[]={'+','-'};printf("%d%c%d%c%d%c%d=7\n",A,p[i/4%2],B,p[i/2%2],C,p[i%2],D);break;}}

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

int main(){

  int A,B,C,D,E,F;
    int all=100,suger=0;
    cin>>A>>B>>C>>D>>E>>F;
    for(int a=0;a*A*100<=F;a++){
        for(int b=0;a*A*100+b*B*100<=F;b++){
            for(int c=0;a*A*100+b*B*100+c*C<=F;c++){
                for(int d=0;a*A*100+b*B*100+c*C+d*D<=F;d++){
                    if((c*C+d*D)*(100+E)<=E*(a*A*100+b*B*100+c*C+d*D)){
                        if((c*C+d*D)*all>=suger*(a*A*100+b*B*100+c*C+d*D)){
                            all=a*A*100+b*B*100+c*C+d*D;
                            suger=c*C+d*D;
                        }
                    }
                }
            }
        }
    }
    cout<<all<<" "<<suger<<endl;
}
    
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
 
signed main(){
	int a,b;
	cin>>a>>b;
	vector<int>c(a);
	vector<int>d(b);
	for(int e=0;e<a;e++)cin>>c[e];
	for(int e=0;e<b;e++)cin>>d[e];
	vector<vector<int>>dp(a+1,vector<int>(b+1));
	for(int f=0;f<a;f++){
		int x=INT_MAX;
		for(int g=f;g<b;g++){
			x=min(x,dp[f][g]);
			dp[f+1][g+1]=x+c[f]*d[g];
			}
		}
		int s=INT_MAX;
		for(int x:dp[a]){
			if(x!=0&&x<s)s=x;
			}
			cout<<s<<endl;
}

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;


int main(){
  ll N;
  cin>>N;
  string S;
  cin>>S;
  ll Left=0;
  ll Right=N-1;
  ll Count=0;
  while(1){
    while(S[Right]=='W'&&Right>0){
      Right--;
    }
    while(S[Left]=='R'&&Left<N-1){
      Left++;
    }
    if(Left>=Right){
      break;
    }
    Count++;
    S[Right]='W';
    S[Left]='R';
    Right--;
    Left++;
  }
  cout<<Count<<endl;

} 

Measured memory_bytes: 3716
n = int(input())
li = list(map(int,input().split()))
A = 0
B = 0
C = 0

for a in li:
  if a % 4 == 0:
    A += 1
  elif a % 2 == 0:
    B += 1
  else:
    C += 1
if B == 0:
  if C <= A + 1:
    print('Yes')
  else:
    print('No')
else:
  if C <= A:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n=0,mm,ans=1;
    cin>>n;
    vector<int> v(n+1);
    for(int i=0;i<n;i++) cin>>v[i];
    mm=v[0];
    for(int i=1;i<n;i++){
        if(v[i]<mm) {
            ans++;
            mm=v[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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

typedef unsigned long long ull;

const ull B1=1e8+7;
const ull B2=1e9+7;

bool rolling_hash(string const&S, int t_start, int m){
    int s_start = t_start + m;

    //B^mの準備
    ull pow_B_m1=1,pow_B_m2=1;
    rep(k,m){
        pow_B_m1*=B1, pow_B_m2*=B2;
    }
    //sとtの先頭m文字のハッシュ値sh, thを計算
    ull sh1=0, sh2=0, th1=0, th2=0;
    rep(k,m){
        th1=th1*B1+S[t_start + k], th2=th2*B2+S[t_start + k];
        sh1=sh1*B1+S[s_start + k], sh2=sh2*B2+S[s_start + k];
    }
    //sをずらしてハッシュ値を更新
    for(int k=0;s_start+k<S.length();k++){
        if(sh1==th1 && sh2==th2) return true;
        if(k+s_start<S.length()){
            sh1=sh1*B1+S[s_start+m+k]-S[s_start+k]*pow_B_m1;
            sh2=sh2*B2+S[s_start+m+k]-S[s_start+k]*pow_B_m2;
        }
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    string S;
    cin >> S;
    int ng=n+1, ok=0;
    while(ng-ok>1){
        int mid=(ng+ok)/2;
        bool matched=false;
        rep(i,n){
            if(i+mid*2>n) break;
            if(rolling_hash(S,i,mid)){
                matched=true;
                break;
            }
        }
        if(matched) ok=mid;
        else ng=mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long int
const int mod = pow(10,9)+7;
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;


signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin>>n;
    vector<int>arr(n);
    for(int i=0; i<n; i++){
         cin>>arr[i];
     }
    int res = 0;
    int bit[62] = {0};
    for(int i=0; i<n; i++){
        for(int j=0; j<61; j++){
            if(1LL << j & arr[i]) bit[j]++;
        }
    }

    for(int i=0; i<61; i++){
        int sum = (bit[i] * (n - bit[i]))%mod;
        int val = (1LL << i)%mod;
        res += (sum * val)%mod;
        res = res%mod;
    }
    cout<<res%mod<<endl;

    return 0;
}

Measured memory_bytes: 5508
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0) continue;
        if(i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
n=int(input())
G=[[0 for i in range(n+1)] for i in range(n+1)]
for i in range(n):
    arr=[int(x) for x in input().split()[2:]]
    for j in arr:
        
        G[i+1][j]=1
        
for k in range(1,n+1):
    G[k].pop(0)
    print(' '.join(map(str, G[k])))


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

int main() {
  int N,K,num=1;
  cin >> N >>K;
  for (int i=0;i<N;i++){
    if ((num*2)<(num+K))
      num=num*2;
    else
      num=num+K;
  }
  cout << num << endl;
}

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

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

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

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

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

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

    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int ans = 0;
    if(A >= K) {
        ans = K;
    }
    else if(A + B >= K) {
        ans = A;
    }
    else {
        ans = A - (K - (A + B));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;

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

    ll k, count = 0, a; cin>>k;
    if(k<=12) return cout<<k<<"\n", 0;
    queue <ll> q;
    for(int i = 1; i <= 9; i++) q.push(i);
    //count = 9;
    int last = 0;
    while(count<k){
        count++;
        a = q.front(), q.pop();
        last = a%10;
        if(last == 0){
            q.push(10*a);
            q.push(10*a + 1);
        }
        else if(last == 9){
            q.push(10*a + 8);
            q.push(10*a + 9);
        }
        else{
            q.push(10*a + last - 1);
            q.push(10*a + last);
            q.push(10*a + last + 1);
        }
    }
    cout<<a;
    return 0;
}

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

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

	int n, k;
	cin >> n >> k;
	int a[n], dp[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = 1e9;
		for (int j = i - 1; j >= 0 and (i - j) <= k ; j--) {
			dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
		}
	}
	// for (auto x : dp)
	// 	cout << x << " ";
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 4388
# 191027 D
import math
a,b,x = list(map(int,input().split()))
da = a * a
y = (2*x - da*b) / da
#print(y)
#print((b - y) / math.sqrt(a))
if y < 0:
    y = (2 * x) / (a * b)
    print(90 - math.degrees(math.atan(y/b)))
else:
    print(math.degrees(math.atan((b - y) / a)))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n,maxv=INT_MIN,minv=INT_MAX;
  int temp;
  cin >> n;
  while(n--){
    cin >> temp;
    maxv=max(maxv,temp);
    minv=min(temp,minv);
  }
  cout << maxv-minv << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n, m;
typedef pair<ll, ll> P;

ll rec[90001];//kachi,kazu
ll toorimemo[114514];
vector<vector<ll>> G(301);
bool vis[300] = { false };
ll maxa = 0;
//-------------------関数----------------------//


int main() {
	string a, b, c; cin >> a >> b >> c;
	ll as=a.size(), bs=b.size(), cs=c.size();
	if (a[as - 1] == b[0] && b[bs - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 256
N,Y = gets.chomp.split(" ").map(&:to_i)

(0..N).each do |a|
  (0..N-a).each do |b|
    c = N-a-b
    if 10000 * a + 5000 * b + 1000 * c == Y
      puts "#{a} #{b} #{c}"
      exit
    end
  end
end

puts "-1 -1 -1"


Measured memory_bytes: 3836
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>
#include <stack>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int solve(int N, std::string& s)
{
    int counter = 0;
    char prev = 0;

    for (int i = 0; i < N; ++i)
    {
        if (s[i] != prev)
        {
            ++counter;
            prev = s[i];
        }
    }

    return counter;
}

int main() {
    fast_io();

    int N = fetch<int>();
    std::string s = fetch<std::string>();
    
    std::cout << solve(N, s) << std::endl;

    return 0;
}


Measured memory_bytes: 512
/*
Looking from a window above
It's like a story of love
Can you hear me?
Came back only yesterday
I'm moving further away
Want you near me
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you
Sometimes when I think of her name
When it's only a game
And I need you
Listen to the words that you say
It's getting harder to stay
When I see you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you
Uh uh uh only you, only you
Only you, only you, only you
This is going to take a long time
And I wonder what's mine
Can't take no more
Wonder if you'll understand
It's just the touch of your hand
Behind a closed door
And all I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
Only you
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) ((int)(x.size()))
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 3e18;
const int N = 5e5 + 100;




int32_t main(){ 
   FAST;
   map<int,int> f;
   f[1] = 9, f[9] = 1;
   string s;   cin >> s;
   for(auto ch : s){
      cout << f[ch - '0'];
   }
}

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

int n, m, sum;
int a[110]; 
bool cmp (int a, int b) {return a > b; }

int main () {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
    	cin >> a[i];
    	sum += a[i]; 
	} 
	sort (a + 1, a + n + 1, cmp); 
    
    if (a[m] * 4 * m >= sum) cout << "Yes";
	else cout << "No"; 
	
	return 0; 
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  int count = 0;
  int i = 0;
  while (i * k <= b) {
    if (i * k < a)
      i++;
    else {
      count = 1;
      break;
    }
  }
  if (count == 1)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
const int N = 66666, MOD = 1e9 + 7; // N > 2 * sqrt(n) 就可
void add(int &x, int y) {
  x += y;
  if(x >= MOD) x -= MOD;
}
vector<int> v;
int dp[2][N], len[N]; // len[] 记录每一个一起计算的部分的长度
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, k; cin >> n >> k;
  for(int i = 1, j; i <= n; i = j + 1) {
    j = n / (n / i); // 边界值
    v.push_back(i);
  }
  v.push_back(n + 1);
  for(int i = 0; i + 1 < int(v.size()); i++) {
    len[i] = v[i + 1] - v[i];
  }
  const int m = v.size();
  for(int i = 1; i < m; i++) dp[0][i] = 1;
  for(int q = 1; q <= k; q++) {
    int cur = 1, whe = m - 1;
    for(int i = 1, j; i <= n; i = j + 1, cur++, whe--) {
      j = n / (n / i); // 边界值
      dp[q & 1][cur] = 1ll * dp[~q & 1][whe] * len[cur - 1] % MOD; // dp转移
    }
    for(int i = 1; i < m; i++) add(dp[q & 1][i], dp[q & 1][i - 1]); // 求前缀和
  }
  cout << dp[k & 1][m - 1] << "\n";
}

Measured memory_bytes: 1404
import sys
sys.setrecursionlimit(10**6)
N, M, Q = map(int, input().split())
a_list = [list(map(int, input().split())) for i in range(Q)]

temp_list = []

max_count = 0


def solve(i, j):
    global max_count
    if i == N:
        temp_count = 0

        for m in a_list:
            if j[m[1] - 1] - j[m[0] - 1] == m[2]:
                temp_count += m[3]
        if max_count < temp_count:
            max_count = temp_count

        return

    a = 0
    if len(j) > 0:
        a = j[-1]
    else:
        a = 1
    for k in range(a, M + 1):
        solve(i + 1, j + [k])


solve(0, [])
print(max_count)

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

using namespace std;

#define MAXN 100000
#define MAXV 2500

int prime[MAXV+5];
long long x[MAXN+5], y[MAXN+5];
vector<long long> primes;
map<long long,long long> sn, sk;
set<long long> v;

int main()
{
    for (long long i = 2; i <= MAXV; ++i) {
        if (prime[i] == 0) {
            primes.push_back(i);
            int t = i*i;
            while (t <= MAXV) {
                prime[t] = 1;
                t += i;
            }
        }
    }

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        long long a;
        scanf("%lld", &a);

        long long tmp = a;
        long long k = 1, n = 1;
        for (auto &p: primes) {
            int cnt = 0;
            while (tmp % p == 0) {
                tmp /= p;
                ++cnt;
            }
            if (cnt % 3 == 1) {
                k *= 1LL*p*p;
                n *= 1LL*p;
            }
            if (cnt % 3 == 2) {
                k *= 1LL*p;
                n *= 1LL*p*p;
            }

        }
        n *= tmp;

        long long s = sqrt(tmp);
        while (s*s < tmp) ++s;
        while (s*s > tmp) --s;
        if (s*s == tmp) {
            k *= s;
        }
        else {
            k *= tmp*tmp;
        }

        x[i] = k; y[i] = n;
        if (n > 1) {
            sk[k]++;
            sn[n]++;
        }
    }

    int ans = 0;
    int nocube = 1;
    for (int i = 0; i < n; ++i) {
        if (x[i] == 1) {
            if (nocube) {
                ++ans;
                nocube = 0;
            }
            continue;
        }
        if (v.find(x[i]) == v.end() && v.find(y[i]) == v.end()) {
            ans += max(sk[x[i]], sk[y[i]]);
            v.insert(x[i]);
            v.insert(y[i]);
        }
    }
    printf("%d\n", ans);

    return 0;
}


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

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





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

int main() {
    int n; scanf("%d", &n);
    int a[n]; for (int i = 0; i < n; ++i) a[i] = i + 1;
    
    printf("%d", a[0]);
    for (int i = 1; i < n; ++i) printf(" %d", a[i]);
    printf("\n");
    
    while (next_permutation(a, a + n)) {
        printf("%d", a[0]);
        for (int i = 1; i < n; ++i) printf(" %d", a[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2736
#include<bits/stdc++.h>
using namespace std;
int num[10][10];
int main()
{
 int x,y,i,j,n,sum=0;
 cin>>n;
 for(i=1;i<=n;i++)
 {
  x=i%10; //末尾 
  y=i;  //首位 
  while(y>=10)
  {
   y=y/10;
  }
  num[y][x]+=1;
 }
 for(i=0;i<10;i++)
 {
  for(j=0;j<10;j++)
  {
   int m=num[i][j]*num[j][i];
            sum+=m;
  }
 }
 cout<<sum;
 return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct StronglyConnectedComponents {
  int V;
  vector<vector<int>> G, rG;
  vector<int> vs, cmp;
  vector<bool> used, added;

  StronglyConnectedComponents(int V) : V(V) {
    used.assign(V, false), added.assign(V, false);
    G.resize(V), rG.resize(V);
    cmp.resize(V);
  }

  void add_edge(int from, int to) {
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void dfs(int s) {
    stack<int> stk;
    stk.push(s);
    while (not stk.empty()) {
      int v = stk.top();
      used[v] = true;
      bool pushed = false;
      for (int c : G[v]) if (not used[c]) stk.push(c), pushed = true;
      if (not pushed) {
        if (not added[v]) added[v] = true, vs.push_back(v);
        stk.pop();
      }
    }
  }

  void rdfs(int s, int k) {
    stack<int> stk;
    stk.push(s);
    while (not stk.empty()) {
      int v = stk.top(); stk.pop();
      used[v] = true;
      cmp[v] = k;
      for (int c : rG[v]) if (not used[c]) stk.push(c);
    }
  }

  int run() {
    fill(used.begin(), used.end(), false);
    fill(added.begin(), added.end(), false);
    vs.clear();
    for (int v = 0; v < V; v++) if (!used[v]) dfs(v);
    fill(used.begin(), used.end(), false);
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) if (not used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }
};

int main() {
  int V, E; scanf("%d %d", &V, &E);
  StronglyConnectedComponents scc(V);
  REP(_, E) {
    int f, t; scanf("%d %d", &f, &t);
    scc.add_edge(f, t);
  }
  scc.run();
  int Q; scanf("%d", &Q);
  REP(_, Q) {
    int x, y; scanf("%d %d", &x, &y);
    printf("%d\n", (scc.cmp[x] == scc.cmp[y]));
  }
  return 0;
}

Measured memory_bytes: 4348
#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cctype>
#include <numeric>
#include <cassert>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
        os << *it << (it + 1 == v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

int main(void){
    vb lastmonth(1000);
    vb thismonth(1000);
    map<int, int> t;
    int num, val;
    string str;

    while (getline(cin, str), str.size() != 0){
        istringstream iss(str);
        iss >> num;
        iss.ignore();
        iss >> val;
        lastmonth[num] = true;
        t[num]++;
    }

    while (getline(cin, str)){
        istringstream iss(str);
        iss >> num;
        iss.ignore();
        iss >> val;
        thismonth[num] = true;
        t[num]++;
    }

    for (auto const& it : t){
        if (lastmonth[it.first] && thismonth[it.first]){
            cout << it.first << " " << it.second << endl;
        }
    }
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

static const long long D = 998244353;

// 掛け算して剰余取る
long long Mul(long long a, long long b) {
	long long c = a * b;
	c %= D;
	return c;
}

long long* factMemo;
long long* modInvMemo;
long long* modInvMemoIntegrated;
long long* powMemo;

// nCk
long long Combination(int n, int k) {
	if (k == 0 || n == k)
		return 1;
	/*
	if (k == 0)
		return 1;
	long long a = 1;
	for (int i = n; i > n - k; i--) {
		a *= i;
		a %= D;
	}
	
	/*
	for (int i = 1; i <= k; i++) {
		a *= modInvMemo[i];
		a %= D;
	}
	*/
	return Mul(Mul(factMemo[n], modInvMemoIntegrated[k]), modInvMemoIntegrated[n - k]);
	// return Mul(a, modInvMemoIntegrated[k]);
}

long long CalcModInv(long long a) {
	long long u = 1, v = 0;
	long long b = D;
	while (b) {
		long long t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= D;
	if (u < 0)
		u += D;
	return u;
}

int main() {
	int N, M, K;
	{
		string s;
		getline(cin, s);
		sscanf(s.c_str(), "%d %d %d", &N, &M, &K);
	}

	factMemo = new long long[N];
	factMemo[0] = 1;
	for (int i = 1; i < N; i++) {
		factMemo[i] = Mul(factMemo[i - 1], i);
	}
	modInvMemo = new long long[N + 1];
	modInvMemoIntegrated = new long long[N + 1];
	modInvMemo[0] = 1;
	for (int i = 1; i <= N; i++) {
		modInvMemo[i] = CalcModInv(i);
	}
	// どうせ階乗でしか割らないので更にメモ
	modInvMemoIntegrated[1] = modInvMemo[1];
	modInvMemoIntegrated[0] = 1;
	for (int i = 2; i <= N; i++) {
		modInvMemoIntegrated[i] = Mul(modInvMemoIntegrated[i - 1], modInvMemo[i]);
	}

	powMemo = new long long[N + 1];
	powMemo[0] = 1;
	for (int i = 1; i <= N; i++) {
		powMemo[i] = Mul(powMemo[i - 1], M - 1);
	}

	// N 個
	// 最初の一個は無理
	// 以降の N - 1 個について、直前と同じ色になるものを k 個まで選ぶ
	//		sigma k = 0 to k = K
		// 逆に言えば 違う色になるものを K+1 個以上選ぶ ということになる
	// N - 1 - k 個について、直前と違う適当な色を塗る（M - 1 色ある）
	// 最初の 1 個はなんでもいいので M をかける

	// M * (N-1)C_k * (M-1)^(N-1-k)
	// これを sigma k = 0 to k = K
	// (N-1)C_k = (N-1)! / (k! * (N-1 - k)!)
	//

	long long ans = 0;
	for (int i = 0; i <= K; i++) {
		// long long a = 1;
		/*
		for (int j = 0; j < N - 1 - i; j++) {
			a = Mul(a, M - 1);
		}*/
		long long a = powMemo[N - 1 - i];
		a = Mul(a, Combination(N - 1, i));
		ans += a;
		ans %= D;
	}

	ans = Mul(ans, M);

	cout << ans << endl;

	delete[] factMemo;
	delete[] modInvMemo;
	delete[] modInvMemoIntegrated;

	return 0;
}

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

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

int main() {
  string szGiven, szTarget;
  cin >> szGiven >> szTarget;
  bool fMatch = false;
  rep(i, szGiven.size()) {
    rotate(szGiven.begin(), szGiven.begin() + 1, szGiven.end());
    if (szGiven == szTarget) {
      fMatch = true;
    }
  }
  puts(fMatch ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/


using namespace std;

int a,b,c;

int main()
{
    cin >> a >> b >> c;
    cout << c-(min(c,a-b)) << endl;
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  double A;
  long long B,N;
  cin >>  A >> B >> N ;
  long long K = min(B-1,N);
  //cout << K<<endl;
  double f=(double)(A/B)*K;
  //cout << K << f << endl;
  cout << floor(f) << endl;;
}

Measured memory_bytes: 3788
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n:f64,
        k:f64
    }
    let mut ans:f64 = 0.0;
    for mut i in 1..((n+1.0) as usize){
        let mut count:f64 = 0.0;
        while i < (k as usize){
            i *= 2;
            count += 1.0;
        }
        if count == 0.0{
            ans += (1.0/n) as f64;
        }else{
            ans += 1.0/(n*(2_f64.powf(count))) as f64;
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 4476
#include<stdio.h>

int search(int *,int,int);

int main()
{
  int i,n,A[10000 + 1],null,yamagami,sum = 0;

  scanf("%d",&n);
  for(i = 0;i < n;i++)
    scanf("%d",&A[i]);

  scanf("%d",&null);

  for(i = 0;i < null;i++)
  {
    scanf("%d",&yamagami);
    if(search(A,n,yamagami))
      sum++;
  }
  
  printf("%d\n",sum);
  
  return 0;
}

int search(int *A,int n,int yamagami)
{
  int i = 0;
  A[n] = yamagami;
  
  while(A[i] != yamagami)
    i++;
  
  return i != n;
}

	



Measured memory_bytes: 2048
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		int answer=0;
		//String answer="Heisei";
		//List<Integer> h=new ArrayList<Integer>();
		//int t[]=new int[(int)Math.pow(10,5)];
		int max=Integer.MIN_VALUE;
		int min=Integer.MAX_VALUE;
		//入力
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		//X=sc.nextDouble();
		//int A[]=new int[N];
		//List<Integer> l=new ArrayList<Integer>();
		//for(int i=0;i<N;i++)
		//{
		//	l.add(sc.nextInt());
		//}
		//String S=sc.next();
		
		//処理
		if(A*C<=B)
		{
			answer=C;
		}else
		{
			answer=B/A;
		}
		// 出力
		//System.out.println(Arrays.toString(X));
		//System.out.println(Arrays.deepToString(a));
		//System.out.println(Arrays.toString(A.toArray()));
		System.out.println(answer);
	}
}

Measured memory_bytes: 21972
#include<algorithm>
#include <iostream>
#include<vector>
#include<string>
#include <iomanip>
#include <queue> 
using namespace std;

int main(){
    int n,Q;
    cin>>n>>Q;

    vector<vector<int>> adj(n+1);

    for(int i=1;i<n;i++){
        int p,c;
        cin>>p>>c;
        adj[p].push_back(c);
        adj[c].push_back(p);
    }

    vector<long long> cost(n+1,0);

    for(int i=0;i<Q;i++){
        int v,c;
        cin>>v>>c;
        cost[v] += c;
    }

    queue <int> q;

    // int a = 0;
    // for(int i=0;i<adj.size();i++)
    //     if(adj[i].size()>0){
    //         a=i;
    //         break;
    //     }
    q.push(1);
    vector<bool> vis(n+1,0);
    // vis[1] = 1;
    while(!q.empty()){
        int nc = q.size();
        
        while(nc>0){
            int pa = q.front();
            q.pop();
            vis[pa]=1;
            nc--;
            long long pc = cost[pa];
            for(int i=0;i<adj[pa].size();i++){
                    if(!vis[adj[pa][i]]){                
                    q.push(adj[pa][i]);
                    cost[adj[pa][i]] += pc;
                }
            }
        }
    }

    for(int i=1;i<n+1;i++)
        cout<<cost[i]<<" ";
    cout<<endl;
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a < b){
    if(c < d){
      cout << a + c << endl;
    }
    else{
      cout << a + d << endl;
    }
  }
  else{
    if(c < d){
      cout << b + c << endl;
    }
    else{
      cout << b + d << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import sys 
MOD = 10**9 +7
INF = 10**5

def main():
    h,w,k = map(int,input().split())
    grid = [[0] * (w + 1)] + [[0] + [int(i) for i in list(input())] for _ in range(h)]
    

    for i in range(h + 1):
        for j in range(1,w + 1):
            grid[i][j] += grid[i][j - 1]
    
    for i in range(1,h + 1):
        for j in range(w + 1):
            grid[i][j] += grid[i - 1][j]
    #print(grid)
    ans = INF
    for bit in range(1<<(h - 1)):
        flag = False
        cut = [0]
        for i in range(h - 1):
            if (bit>>i)&1:
                    cut.append(i + 1)
        cut.append(h)
        #print(cut)
        l = len(cut)
        cnt = l - 2
        c = 0
        for j in range(1,w + 1):
            for i in range(1,l):
                #print(c)
                a = cut[i - 1]
                b = cut[i]
                if grid[b][j] - grid[b][c] - grid[a][j] + grid[a][c] > k:
                    if j != 1:
                        c = j - 1
                        cnt += 1
                        break
                    else:
                        flag = True
                        break
            if flag:
                break
        if flag == False:
            ans = min(ans,cnt)
    
    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 3316
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(b / a >= c) {
			System.out.println(c);
		}else {
			System.out.println(b/a);
		}
		
		sc.close();
	}

}

Measured memory_bytes: 25172
import java.util.Scanner;

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

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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 main(){
	ll n,h,w;cin>>n>>h>>w;
	ll ans= 0;
	for(int i = 0; i < n; i++) {
		ll a,b;cin>>a>>b;
		if (a >= h && b >= w)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define MAX_SIZE 10

int in, xsum[MAX_SIZE], ysum[MAX_SIZE], grand, size;

void var_reset(void)
{
	memset(xsum, 0, sizeof(xsum));
	memset(ysum, 0, sizeof(ysum));
	grand = 0;
}

void maketable(void)
{
	int x, y;
	for (y = 0; y < size; y++) {
		for (x = 0; x <size; x++) {
			scanf("%d", &in);
			xsum[y % size] += in;
			ysum[x % size] += in;
			grand += in;
			printf("%5d", in);
		}
		printf("%5d\n", xsum[y]);
	}
	for (x = 0; x < size; x++)
		printf("%5d", ysum[x]);
	printf("%5d\n", grand);
}

int main(void)
{

	int x, y;
	for (;;) {
		scanf("%d", &size);
		if (size == 0)
			return 0;
		var_reset();
		maketable();
	}
}

Measured memory_bytes: 612
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] x = new int[n];
		for(i=0;i<n;i++) {
			x[i] = parseInt(sc.next());
		}
		sc.close();
		int[] y = new int[n];
		arraycopy(x, 0, y, 0, n);
		Arrays.sort(y);
		int medlow  = y[n/2-1];
		int medhigh = y[n/2];
		PrintWriter pw = new PrintWriter(out);
		for(i=0;i<n;i++) {
			if(x[i]<=medlow) {
				pw.println(medhigh);
			} else {
				pw.println(medlow);
			}
		}
		pw.flush();
	}
}


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

using namespace std;

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

bool exist[100010];
int len[100010];
int Id[100010];

signed main()
{
    int n, k;

    while (cin >> n >> k, n) {
        memset(exist, false, sizeof(exist));
        memset(len, 0, sizeof(len));
        memset(Id, 0, sizeof(Id));
        bool f = false;

        rep(i, k) {
            int tmp;
            cin >> tmp;
            --tmp;
            if (tmp == -1) f = true;
            exist[tmp] = true;
        }

        int id = 0;

        memset(Id, -1, sizeof(Id));

        bool consecutive = false;
        for (int i = 0; i < n; ++i) {
            if (exist[i]) {
                if (!consecutive) id++, consecutive = true;
                len[id]++, Id[i] = id;
            } else consecutive = false;
        }

        int ma = 0;
        rep(i, n) if (Id[i] != -1) ma = max(ma, len[Id[i]]);

        if (f) {
            rep(i, n) {
                int l = 0, r = 0;
                if (i - 1 >= 0 && Id[i - 1] != -1) l = len[Id[i - 1]];
                if (i + 1 < n && Id[i + 1] != -1) r = len[Id[i + 1]];
                if (i - 1 >= 0 && i + 1 < n && Id[i - 1] == Id[i + 1]) ma = max(ma, l + 1);
                else ma = max(ma, l + r + 1);
            }
        }

        if (ma == n + 1) ma --;

        cout << ma << endl;
    }
}

Measured memory_bytes: 3820
N = int(input())
T, A = map(int, input().split())
kouho = list(map(int, input().split()))
dragon = 100000
for i in range(N):
    ondo = T - 0.006 * kouho[i]
    if abs(ondo - A) < abs(dragon - A):
        ans = i
        dragon = ondo
print(ans + 1)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>

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

using namespace std;

const int INF = 10000;

int main()
{
	
	int inputNumber;

	cin >> inputNumber;

	int ans = inputNumber * inputNumber * inputNumber;

	cout << ans << endl;
 
	return 0;

}



Measured memory_bytes: 3096
N=int(input())
a=list(map(int,input().split()))
ans=0
go=True
while go:
    for i in range(N):
        if a[i]%2==0:
            a[i]=a[i]/2
        else:
            go=False
            break
    if go==False:
        break
    ans+=1
print(ans)

Measured memory_bytes: 3060
from collections import deque
def bfs(y,x):
  q=deque([(y,x)])
  visited[y][x]=0
  while q:
    cy,cx=q.popleft()
    for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:
      ny,nx=cy+dy,cx+dx
      if 0<=ny<h and 0<=nx<w and visited[ny][nx]==-1:
        if s[ny][nx]=="#":continue
        visited[ny][nx]=visited[cy][cx]+1
        q.append((ny,nx))
  res=0
  for i in range(h):
    for j in range(w):
      if s[i][j]!="#":
        res=max(res,visited[i][j])
  return res

h,w=map(int,input().split())
s=[input() for _ in range(h)]
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":continue
    sh=i
    sw=j
    visited=[[-1]*w for _ in range(h)]
    ans=max(ans,bfs(sh,sw))
print(ans)



Measured memory_bytes: 9472