akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

int main()
{
    int n, m, c;
    std::cin >> n >> m >> c;

    std::vector<int> b(m);
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
        std::vector<int> a(m);
        for (int j = 0; j < m; j++) {
            std::cin >> a[j];
        }

        int ans = 0;
        for (int j = 0; j < m; j++) {
            ans += a[j] * b[j];
        }
        ans += c;
        if (ans > 0) {
            sum++;
        }
    }

    std::cout << sum << std::endl;
}


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

int ne[2][202020][26];
int used[26];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  string S,T; cin>>S>>T;
  int n=S.length();
  rep(i,26) ne[0][n][i]=ne[1][n][i]=200100;
  for(int i=n-1;i>=0;i--){
    rep(j,26){
      if(j==(S[i]-'a')) ne[0][i][j]=i+1;
      else ne[0][i][j]=ne[0][i+1][j];
      if(j==(T[i]-'a')) ne[1][i][j]=i+1;
      else ne[1][i][j]=ne[1][i+1][j];
    }
  }

  rep(i,n) if(!used[S[i]-'a']){
    int s=S[i]-'a', t=T[i]-'a';
    used[s]=1;
    int ind=i+1;
    if(ne[0][ind][s]!=ne[1][ind][t]){
      cout<<"No\n";
      return 0;
    }
    while(ind<=n){
      if(ne[0][ind][s]!=ne[1][ind][t]){
        cout<<"No\n";
        return 0;
      }else{
        ind=ne[0][ind][s];
      }
    }
  }
  cout<<"Yes\n";
  return 0;
}


Measured memory_bytes: 41876
import numpy as np


def main():
    h, w = list(map(int, input().split()))
    grid = []
    for _ in range(h):
        grid.append(list(input()))

    grid = np.array(grid) == '.'
    # print(grid)

    L = np.zeros((h, w), dtype=int)
    R = np.zeros((h, w), dtype=int)
    D = np.zeros((h, w), dtype=int)
    U = np.zeros((h, w), dtype=int)

    for i in range(1, h):
        U[i] = (U[i - 1] + 1) * grid[i - 1]
        # print(U[i])
    # print(U)

    for i in reversed(range(h - 1)):
        D[i] = (D[i + 1] + 1) * grid[i + 1]

    for j in range(1, w):
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j - 1]
        # print(L[:, j])
    # print(L)

    for j in reversed(range(w - 1)):
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j + 1]

    score = ((U + D + L + R) * grid).max() + 1
    print(score)


main()

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));
    int ans = 0;
    rep(i,k){
        ans+=p[i];
    }
    cout << ans << endl;
    return 0;
}

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

const int MAX_N = 3025;
char str[MAX_N],str_[MAX_N];
int dp[MAX_N][MAX_N];
int main()
{
    scanf("%s",str+1);
    scanf("%s",str_+1);
    int len = strlen(str+1),len_ = strlen(str_+1);
    for(int i = len;i>=1;--i)
    {
        for(int j = len_;j>=1;--j)
        {
            if(str[i]==str_[j])  dp[i][j] = dp[i+1][j+1]+1;
            else dp[i][j] = max(dp[i+1][j],dp[i][j+1]);
        }
    }
    int l = 1,r = 1;
    while(l<=len&&r<=len_)
    {
        if(str[l]==str_[r])
        {
            printf("%c",str[l]);
            l++,r++;
        }
        else if(dp[l][r]==dp[l+1][r]) l++;
        else r++;
    }
    printf("\n");
    return 0;
}


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

int d[2][3]={{4,5,1},{2,5,3}};//d,u,l,r

void dice(int a[6], int n){
	int tmp = a[0];
	a[0] = a[d[n][0]];
	a[d[n][0]] = a[d[n][1]];
	a[d[n][1]] = a[d[n][2]];
	a[d[n][2]] = tmp;
}

int check(int a[6], int b[6]){
	for(int i = 0;i < 6;i++)if(a[i] != b[i])return 0;
	return 1;
}

int func(int a[6], int b[6]){
	for(int i = 0;i < 6;i++){
		for(int j = 0;j < 4;j++){
			dice(b, 0);
			if(check(a, b))return 1;
		}
		if(i%2 == 0)dice(b, 1);
		else{
			swap(b[4],b[2]);swap(b[2],b[1]);swap(b[1],b[3]);
		}
	}
	return 0;
}

int main(){
	int a[6], b[6];
	for(int i = 0;i < 6;i++)cin >> a[i];
	for(int i = 0;i < 6;i++)cin >> b[i];
	
	/*for(int i = 0;i < 6;i++)cout << a[i] << " ";
	cout << endl;
	for(int i = 0;i < 6;i++)cout << b[i] << " ";
	cout << endl;*/
	
	if(func(a, b))cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,s[1000000],ans=0,f=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s[i];
    ans+=s[i];
  }
  if(ans%10==0){
    sort(s,s+n);
    for(int i=0;i<n;i++){
      if((ans-s[i])%10!=0){
        ans-=s[i];
        f=1;
        break;
      }
    }
    if(f==0) ans=0;
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)*/

//ここから書き始める
int main(){
	ll n, k ; cin >>n>>k ;
	string s; cin >> s;

	if(n==1){
		cout << 0 << endl;
		return 0;
	}

	//LとRの塊がいくつあるかを見る
	ll l=0 , L=0 , r=0 , R=0 ;//lとrはそれぞれ端っこがそうだったときに＋する。
	ll begin = 0;
	for(int i = 1 ; i < n ;i++){
		if(s[i] ==s[i-1]) {
			begin ++;
		}
	}

	rep(i,n){
		char now = s[i];
		if(i==0||i==n-1){
			if(now =='L') l ++;
			else r ++;

			if(i == n - 1 && now == s[i-1]){
				if(now=='L'){
				L --;
				}
				else R--;
			}
			if(i == 0 && s[0] == s[1]){
				if(s[0]=='L'){
					L --;
				}
				else R --;
			}
		}
		else{
			if(now == 'L' && now !=s[i-1]) L++;
			else if(now == 'R' && now != s[i-1]) R++;

		}
	}
	ll Lsum = 0;
	ll Rsum = 0;
	if(L >= k){
		Lsum += 2 * k;
	}
	else {
		Lsum += L * 2;
		ll forL = k;
		forL -= L;
		Lsum += min(l,forL) * 1;
	}

	if(R >= k){
		Rsum += 2 * k;
	}
	else {
		Rsum += R * 2;
		ll forR = k;
		forR -= R;
		Rsum += min(r,forR) * 1;
	}

	ll ans = max(Lsum,Rsum);
	cout << ans+begin << endl;

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int t=26;
    int d;
    cin>>d;
    int c[t],s[d][t],last[t]={};
    for(int i=0;i<t;i++){
        cin>>c[i];
    }
    for(int i=0;i<d;i++)for(int j=0;j<t;j++)cin>>s[i][j];
    int happy=0;
    for(int i=0;i<d;i++){
        int m=0,x;
        for(int j=0;j<t;j++){
            int up=0;
            for(int k=0;k<t;k++){
                if(k==j)up+=s[i][k];
                else up-=c[k]*(i-last[k]);
            }
            if(up>m){
                x=j;
                m=up;
            }
            last[x]=i;
        }
        cout<<x+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3672
using System;

using System.Linq;

using System.Collections.Generic;



namespace hello_cs

{

    class Program

    {

        static void Main(string[] args)

        {

            var blank = " ";

            var ipt = System.Console.ReadLine().Split(blank.ToCharArray()).Select(x => int.Parse(x));

            var a = System.Console.ReadLine().Split(blank.ToCharArray()).Select(x => int.Parse(x)).ToArray();

            var k = ipt.First();

            var n = ipt.Last();



            var max = 0;



            for(var i = 0; i < n; i++){

                var next = i != n - 1 ? a[i + 1] : a[0] + k;

                var dis = Math.Abs(a[i] - next);

                if(max < dis){

                    max = dis;

                }

            }

            System.Console.WriteLine(k - max);



        }

    }

}



Measured memory_bytes: 32732
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, h[100100], d[100100];

int solve(){
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> h[i];
    d[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
        d[i] = min(abs(h[i] - h[i - 1]) + d[i - 1], abs(h[i] - h[i - 2]) + d[i - 2]);
    }
    return d[n - 1];
}

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

    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<set>
#include<queue>
#include<vector>
#include<cstdio>
#include<map>
using namespace std;
int main()
{
  long long n,ans=0,sum=0,a;
  map<long long,int> mp;
  cin>>n;
  mp[0]++;
  for(int i=1;i<=n;i++){
    cin>>a;
    sum+=a;
    ans+=mp[sum];
    mp[sum]++;
  }
  cout<<ans;
  return 0;
}


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

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s == u) a--;
  else b--;
  cout << a << " " << b << endl;
}

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

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::min;

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<int> x(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }

    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += 2 * min(x[i], k - x[i]);
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 384
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

#define div divide

const int P = 998244353;

int add(int & a, int b) {
  if ((a += b) >= P) {
    a -= P;
  }
  return a;
}

int prod(int a, int b) {
  return (int)(ll(a) * b % P);
}

int power(int a, int n) {
  int b = 1;
  while (n) {
    if (n & 1) {
      b = prod(a, b);
    }
    a = prod(a, a);
    n /= 2;
  }
  return b;
}

int inv(int a) {
  return power(a, P - 2);
}

int div(int a, int b) {
  return prod(a, inv(b));
}

int C(const vector<int> &fact, int n, int k) {
  return div(fact[n], prod(fact[k], fact[n - k]));
}

bool solve() {
  int n, a, b;
  ll k;
  if (scanf("%d%d%d%lld", &n, &a, &b, &k) != 4) { return false; }

  vector<int> fact(n + 1);
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = prod(fact[i - 1], i);
  }

  int res = 0;
  for (ll x = 0; x <= n; ++x) {
    if ((k - x * a) % b != 0) {continue; }
    ll y = (k - x * a) / b;
    if (y > n || y < 0) { continue; }
    add(res, prod(C(fact, n, x), C(fact, n, (int)y)));
  }
  printf("%d\n", res);
  return true;
}

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

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

int zeta(int a,int b){
  if(a>=b) return a-b;
  else return b-a;
}

int main(){
  int h1,h2,m1,m2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  int len=(h2-h1)*60+(m2-m1);
  int ans=0;
  ans=len-k;
  cout<<ans<<endl;
  
  return 0;
}








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

int main(){
  int N;
  cin >> N;
  set<string> s={};
  string a;
  for (int i=0;i<N;i++){
    cin >> a;
    s.insert(a);
  }
  if (s.size()==3){
    cout << "Three" << endl;
  }
  if (s.size()==4){
    cout << "Four" << endl;
  }
 }


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int numo;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'o') {
            numo++;
        }
    }

    cout << 700 + numo * 100 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b;
	char op;
	while (1){
		cin >> a >> op >> b ;
		if (op == '+'){
			cout << a + b << endl;
		}
		else if (op == '-'){
			cout << a - b << endl;
		}
		else if (op == '*'){
			cout << a*b << endl;
		}
		else if (op == '/'){
			cout << a / b << endl;
		}
		else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3004
def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    h = [int(input()) for _ in range(N)]

    h.sort()

    ans = min(ma - mi for mi, ma in zip(h, h[K - 1:]))
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 7880
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

string s, t;
int p;

int calc(int p)
{
	int x[4];
	for(int i = 3; i >= 0; i--){
		x[i] = p % 10;
		p /= 10;
	}
	
	stack<int> stk;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '[' || s[i] == ']') continue;
		if(s[i] == 'a'){
			stk.push(x[0]);
			continue;
		}
		if(s[i] == 'b'){
			stk.push(x[1]);
			continue;
		}
		if(s[i] == 'c'){
			stk.push(x[2]);
			continue;
		}
		if(s[i] == 'd'){
			stk.push(x[3]);
			continue;
		}
		
		int op1 = stk.top(); stk.pop();
		int op2 = stk.top(); stk.pop();
		if(s[i] == '+') stk.push(op1|op2);
		if(s[i] == '*') stk.push(op1&op2);
		if(s[i] == '^') stk.push(op1^op2);
	}
	return stk.top();
}

int main(void)
{
	while(1){
		cin >> s;
		if(s == ".") break;
		cin >> p;
		
		reverse(s.begin(), s.end());
		int val = calc(p);
		
		int ans = 0;
		for(int i = 0; i < 10000; i++){
			if(val == calc(i)) ans++;
		}
		cout << val << " " << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=10000;

int main(){
    
    vector<vector<int>> nd(maxn);
    bool used[maxn]={0};
    int n;
    int num[maxn];
    int cost[maxn];
    ll sum=0,ma=0;
    
    cin >>n;
    rep(i,n-1){
        int a,b;
        scanf("%d""%d",&a,&b);
        a--;b--;
        nd[a].push_back(b);
        nd[b].push_back(a);
    }
    
    rep(i,n){
        scanf("%d",&cost[i]);
        sum+=cost[i];
        ma=max(ma,(ll)cost[i]);
        cost[i]*=-1;
    }
    
    sort(cost,cost+n);
    
    queue<int> que;
    que.push(0);
    num[0]=-cost[0];
    //cout << num[0]<<endl;
    int ite=1;
    used[0]=true;
    
    while(!que.empty()){
        int arg=que.front();que.pop();
        rep(i,nd[arg].size()){
            if(!used[nd[arg][i]]){
                used[nd[arg][i]]=true;
                que.push(nd[arg][i]);
                num[nd[arg][i]]=-cost[ite++];
            }
        }
    }
    
    printf("%d\n",sum-ma);
    rep(i,n){
        printf("%d ",num[i]);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int x,k,d;
	cin>>x>>k>>d;
	x=abs(x); 
	if(k<=x/d){
		cout<<x-k*d<<endl;
		return 0;
	}
	int zh=x%d,fu=labs(x%d-d);
	if(zh==fu){
		cout<<zh<<endl;
		return 0;
	}
	int lst=k-x/d;
	if(lst%2==0){
		cout<<zh<<endl;
		return 0;
	}
	if(lst%2==1){
		cout<<fu<<endl;
		return 0;
	}
    return 0;
}

Measured memory_bytes: 3628
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#define int long long
using namespace std;

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

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int 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,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main
//------------------------------------------
signed main(){
    // 入力
    int n;
    cin >> n;
    vector<int> a(n);
    for(int k=0;k<n;k++){
        cin>>a[k];
    }
    bool flag = false;
    for (int j = 0; j < n;j++){
        if ((a[j] % 2 == 0) && (a[j] % 3 != 0 && a[j] % 5 != 0))
        {
            flag = true;
            break;
        }
    }
    if(!flag){
        cout << "APPROVED";
    }
    else{
        cout << "DENIED";
    }
        return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApplication36
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 5; )
            {
                string s = Console.ReadLine();
                string[] ss = s.Split(' ');
                int a = int.Parse(ss[0]);
                String op = ss[1];
                int b = int.Parse(ss[2]);
                int c = 0;
                if (op == "+")
                {
                    c = a + b;
                }
                else if (op == "-")
                {
                    c = a - b;
                }
                else if (op == "*")
                {
                    c = a * b;
                }
                else if (op == "/")
                {
                    c = a / b;
                }
                else if (op == "?")
                {
                    break;
                }
                Console.WriteLine(c);
            }
        }
    }
}

Measured memory_bytes: 9080
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

int i,j,k;

int main()
{
  cin>>i;
  
  cout<<i+i*i+i*i*i;
  
}

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

def segfunc(x,y):
    return x | y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res


n = int(input())
s = input()
q = int(input())

li = []
for i in range(n):
    li.append(1 << ord(s[i]) - ord('a'))

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(li)

for _ in range(q):
    q1 = list(input().split())
    if q1[0] == '1':
        update(int(q1[1]) - 1, 1 << ord(q1[2]) - ord('a'))
    else:
        l,r = int(q1[1]), int(q1[2])
        print(bin(query(l-1,r)).count('1'))


Measured memory_bytes: 48380
#include <stdio.h>
int main(void) {
        int n,x;
        if(scanf("%d",&n)==1);
        if(scanf("%d",&x)==1);
        int m[10000]={},i=0,min=0;
        while(1){
                if(scanf("%d",&m[i])==1);
                if(i==0)min=m[0];
                else{
                        if(min>m[i])min=m[i];
                }
                x-=m[i];
                i++;
                if(i>=n)break;
        }

        printf("%d\n",n+(x/min));
        return 0;
}


Measured memory_bytes: 256
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range( n)]

x.sort()
cnt = 0
for i in range(1,n):
  for j in range(i,n):
    ans = 0
    for k in range(0,d):
      ans += (x[i-1][k] - x[j][k]) ** 2
    ans = math.sqrt(ans)
    if ans == int(ans):
      cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f,g,h,i,j;
    cin >>a>>b>>c>>d>>e>>f>>g>>h>>i>>j;

    cout << a+b+c+d+e+f+g+h+i+j <<endl;
}



Measured memory_bytes: 3104
#include<stdio.h>
int main(){
	int a,b,c,N=0;
  	scanf("%d %d %d",&a,&b,&c);
	N=a;
  	a=b;
  	b=N;
  	N=c;
  	c=a;
  	a=N;
  	printf("%d %d %d",a,b,c);
  
  
	return 0;
}

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

typedef pair<int, int> P;

int N, T;
vector<P> route;

bool pairCompare(const P& a, const P& b) {
  return a.first < b.first;
}

int main() {
  int ans = -1;

  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    int c, t;
    cin >> c >> t;
    route.push_back(make_pair(c, t));
  }
  sort(route.begin(), route.end(), pairCompare);

  for (int i = 0; i < N; i++) {
    if (route[i].second <= T) {
      ans = i;
      break;
    }
  }

  if (ans == -1) puts("TLE");
  else printf("%d\n", route[ans].first);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,s="CODEFESTIVAL2016a";
int sum;
int main(){
	getline(cin,a);
	for(int i=0;i<16;i++)if(a[i]!=s[i])sum++;
	cout<<sum<<endl;
	return 0;
}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K = 0;
ll t;
ll ret = 0;
string s;
ll total = 0;
ll table[200001];
vl A;

void input() {
  IN(N);
  REP(i, 200001) {
    table[i] = 0;
  }
  REP(i, N) {
    IN(t);
    A.pb(t);
    table[t] += 1;
  }
}

void solve() {
  REP(i, 200001) {
    if (table[i] > 0) {
      total += table[i] * (table[i] - 1) / 2;
    }
  }
  REP(i, N) {
    ll a = A[i];
    ret = total;
    ret -= table[a] * (table[a] - 1) / 2;
    ret += (table[a] - 1) * (table[a] - 2) / 2;
    PRINT(ret);
  }
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 5872
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, n; cin >> h >> n;
	vector<int> a(n);
	for(auto &i:a) cin >> i;
	if(accumulate(a.begin(), a.end(), 0) >= h) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int num[11] = {};
    for (int i=0; i<3; i++)
    {
        int A;
        cin>>A;
        num[A]++;
    }
    cout<<(num[5]==2 && num[7]==1 ? "YES" : "NO")<<endl;
}


Measured memory_bytes: 256
MOD=10**9+7
class Fp(int):
    def __new__(self,x=0):return super().__new__(self,x%MOD)
    def inv(self):return self.__class__(super().__pow__(MOD-2,MOD))
    def __add__(self,value):return self.__class__(super().__add__(value))
    def __sub__(self,value):return self.__class__(super().__sub__(value))
    def __mul__(self,value):return self.__class__(super().__mul__(value))
    def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv())
    def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD))
    __radd__=__add__
    __rmul__=__mul__
    def __rsub__(self,value):return self.__class__(-super().__sub__(value))
    def __rfloordiv__(self,value):return self.__class__(self.inv()*value)
    def __iadd__(self,value):self=self+value;return self
    def __isub__(self,value):self=self-value;return self
    def __imul__(self,value):self=self*value;return self
    def __ifloordiv__(self,value):self=self//value;return self
    def __ipow__(self,value):self=self**value;return self
    def __neg__(self):return self.__class__(super().__neg__())


N = int(input())
ans = Fp(1)
for i in range(1, N+1):
    ans *= i
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}

int main(){
        int n;cin>>n;
        ll ans = 0;
        map<ll,int>mp;
        rep(i,n){
            int a;cin>>a;
            mp[a]++;
        }
        ll res = 0;
        for(auto p:mp){
            if(p.second>=2){
                if(p.first>res){
                    res = p.first;
                }
            }
        }
        mp[res] -= 2;
        ll res2 = 0;
        for(auto p:mp){
            if(p.second>=2)res2 = max(res2,p.first);
        }
        ans = res*res2;
        cout<<ans<<endl;
}



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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    string s;
    cin >> a >> b >> s;
    for (int i = 0; i < a; i++) {
        if (s[i] < '0' || '9' < s[i]) {
            cout << "No\n";
            return 0;
        }
    }
    if (s[a] != '-') {
        cout << "No\n";
        return 0;
    }
    for (int i = a + 1; i < s.size(); i++) {
        if (s[i] < '0' || '9' < s[i]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


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

bool is_prime[2000000];
int prime[2000000];
int main() {
	memset(is_prime, 1, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i < 2000000; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = i * 2; j < 2000000; j += i)is_prime[j] = false;
		}
	}
	int n;
	while (scanf("%d", &n), n) {
		if (is_prime[n]) {
			puts("0");
			continue;
		}
		int*a = lower_bound(prime, prime + p, n);
		if (a == prime)puts("0");
		else printf("%d\n", *a - *(a - 1));
	}
}

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


def solve(c: "List[str]"):
    for i,s in enumerate(c):
        print(s[i],end="")
    print("")


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    c = [ next(tokens) for _ in range(3) ]  # type: "List[str]"
    solve(c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import math

def koch(a1, a2, b1, b2, n):
    if n <= 0:
        return 0

    s1 = 2.0/3.0*a1 + 1.0/3.0*b1
    s2 = 2.0/3.0*a2 + 1.0/3.0*b2
    t1 = 1.0/3.0*a1 + 2.0/3.0*b1
    t2 = 1.0/3.0*a2 + 2.0/3.0*b2
    u1 = 1.0/6.0*(3.0*a1 + 3.0*b1 + math.sqrt(3.0)*a2 - math.sqrt(3.0)*b2)
    u2 = 1.0/6.0*(-1.0*math.sqrt(3.0)*a1 + math.sqrt(3.0)*b1 + 3.0*a2 + 3.0*b2)
    
    koch(a1, a2, s1, s2, n-1)
    print s1, s2
    koch(s1, s2, u1, u2, n-1)
    print u1, u2
    koch(u1, u2, t1, t2, n-1)
    print t1, t2
    koch(t1, t2, b1, b2, n-1)
    
if __name__ == '__main__':
    n = int(raw_input())
    a1, a2, b1, b2 = 0.0, 0.0, 100.0, 0.0
    print a1, a2
    koch(a1, a2, b1, b2, n)
    print b1, b2

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

#define ll long long
#define pu push
#define pb push_back
#define ull unsigned long long
#define set_pre setprecision
#define cl clear
#define fi first
#define se second
#define For(i,a,b) for(int i = a; i <= b; i++)
#define Fors(i,a,b) for(int i = a; i < b; i++)

typedef pair<char, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int maxn = 1e6 + 7;
const int oo = 1e9 + 7;
const int mod = 1e9 + 7;
const int max_dsk = 3e5 + 7;
const int maxc_IT = 4 * maxn;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin >> n >> k;
    int d = 0;
    For(i,1,n)
    {
        int x;
        cin >> x;
        if(x >= k) d++;
    }
    cout << d;
}


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

typedef long long int ll;
ll mod = 1000000000 + 7;

const int nmax = 1000;
const int mmax = 10;

// All possible arrays where
// 1. Length = i
// 2. last element is j
ll arr[mmax][nmax] = {0};

int gcd(int a, int b){
    if(a > b) return gcd(b, a);
    else if(a == 0) return b;
    else return gcd(b%a, a);
}

int gcd(int a, int b, int c){
    return gcd(a, gcd(b, c));
}


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

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

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

  string s; cin>>s;
  set<char> st(s.begin(),s.end());
  if(st.find('S')!=st.end()&&st.find('N')==st.end()) cout << "No" << endl;
  else if(st.find('N')!=st.end()&&st.find('S')==st.end()) cout << "No" << endl;
  else if(st.find('E')!=st.end()&&st.find('W')==st.end()) cout << "No" << endl;
  else if(st.find('W')!=st.end()&&st.find('E')==st.end()) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, K, S;
int A[100011];

void MAIN() {
    scanf("%d%d%d", &N, &K, &S);

    int X = 1;
    while (X == S || S % X == 0) X++;
    REP (i, N) {
	if (i < K) A[i] = S;
	else A[i] = X;
    }

    rprintf("%d", A, A+N);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,count1=0,count2=0,count3=0,count4=0;
    cin>>t;
    while(t--)
    {
        string s;
     cin>>s;

     if(s=="AC") count1++;
     else if(s=="TLE") count2++;
     else if(s=="WA") count3++;
     else if(s=="RE") count4++;
    }

    cout<<"AC x "<<count1<<endl
    <<"WA x "<<count3<<endl
    <<"TLE x "<<count2<<endl
    <<"RE x "<<count4<<endl;
}

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

#define ll long long
#define scl(n) scanf("%lld",&n)
#define scd(n) scanf("%d",&n)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

ll op(ll x)
{
    if(x==1)
        return 1ll;
    ll z=op(x/2);
    z*=2;
    z++;
    return z;
}


int main()
{
    ll n,m;
    cin>>n;
    m=op(n);
    cout<<m<<endl;


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
//解説
int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    rep(i, m) {
        int k; cin >> k;
        rep(j, k) {
            int s; cin >> s; s--;
            a[s] |= 1 << i;
        }
    }
    int p = 0;
    rep(i, m) {
        int x; cin >> x;
        p |= x << i;
    }
    int ans = 0;
    rep(s, (1 << n)) {
        int t = 0; //目的のbit列pを作る
        rep(i, n) {
            if (s >> i & 1) {
                t ^= a[i];
            }
        }
        if (t == p) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int N = sc.nextInt();
        int[] p = new int[N];
        int[] ans = new int[202];
        int min = 1000;
        int result = X;
        int j=0;
        for(int i=-100;i<=101;i++){
            ans[j] = Math.abs(X-i);
            j++;
        }
        for(int i=0;i<N;i++){
            int num = sc.nextInt();
            ans[num+100] = 1000;
        }
        for(int i=0;i<ans.length;i++){
            if(min>ans[i])
            {
                min = ans[i];
            }
        }
        result -= min;
        if(ans[result+100]==1000){
            result = X + min;
        }
        if(N==0){
            result = X;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 35984
from collections import deque
n, q = map(int, input().split())

ki = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  ki[a].append(b)
  ki[b].append(a)

cnt = [0 for i in range(n)]
for i in range(q):
  p, x = map(int, input().split())
  p -= 1
  cnt[p] += x

visited = [False for i in range(n)]
visited[0] = True

queue = deque()
queue.append(0)
r = [0 for i in range(n)]
r[0] = cnt[0]
while queue:
  x = queue.popleft()
  for i in ki[x]:
    if visited[i] == True:
      continue
    # cnt[i] += cnt[x]
    r[i] = cnt[i] + r[x]
    queue.append(i)
    visited[i] = True
print (*r)

Measured memory_bytes: 108960
if __name__ == '__main__':
	N = int(input())
	S = input()
	K = int(input())
	token = S[K-1]
	ans = ''
	for i in range(N):
		if(S[i] != token):
			ans+='*'
		else:
			ans+=S[i]

	print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;


struct status {
    int x, y;
    int step_over;

    status() {}
    ~status() {} status(int a, int b, int c):
        x(a), y(b), step_over(c) {}

    bool operator < (const status& o) const {
        return step_over > o.step_over;
    }
};

const int INF = 1 << 29;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W, N;
int x1, y1, x2, y2;
int visited[505][505];
int cross[505][505][4];


int solve() {
    cin >> W >> H >> N;
    cin >> y1 >> x1 >> y2 >> x2;

    for (int j = 0; j <= H; ++j) {
        fill(visited[j], visited[j] + W + 1, INF);
        for (int k = 0; k <= W; ++k) {
            fill(cross[j][k], cross[j][k] + 4, 0);
        }
    }

    for (int j = 0; j < N; ++j) {
        int px, py, T;
        string steps;
        cin >> py >> px >> T >> steps;
        for (int _ = 0; _ < T; ++_) {
            for (int k = 0; k < steps.size(); ++k) {
                int sn;

                if (steps[k] == 'D') {
                    sn = 0;
                } else if (steps[k] == 'R') {
                    sn = 1;
                } else if (steps[k] == 'U') {
                    sn = 2;
                } else if (steps[k] == 'L') {
                    sn = 3;
                }

                int nx = px + dx[sn], ny = py + dy[sn];

                if (0 <= nx && nx < H && 0 <= ny && ny < W) {
                    if (sn == 0) {
                        cross[px+1][py][1] += 1;
                        cross[px+1][py+1][3] += 1;
                    } else if (sn == 1) {
                        cross[px][py+1][0] += 1;
                        cross[px+1][py+1][2] += 1;
                    } else if (sn == 2) {
                        cross[px][py][1] += 1;
                        cross[px][py+1][3] += 1;
                    } else if (sn == 3) {
                        cross[px][py][0] += 1;
                        cross[px+1][py][2] += 1;
                    }
                    px = nx; py = ny;
                }
            }
        }
    }

    priority_queue<status> que;
    que.push(status(x1, y1, 0));

    while (!que.empty()) {
        status st = que.top(); que.pop();

        if (visited[st.x][st.y] < st.step_over) {
            continue;
        }

        if (st.x == x2 && st.y == y2) {
            return st.step_over;
        }

        for (int i = 0; i < 4; ++i) {
            int nx = st.x + dx[i], ny = st.y + dy[i];
            if (0 <= nx && nx <= H && 0 <= ny && ny <= W) {
                int inc = cross[st.x][st.y][i];
                if (visited[nx][ny] <= st.step_over + inc) {
                    continue;
                }
                visited[nx][ny] = st.step_over + inc;
                que.push(status(nx, ny, st.step_over + inc));
            }
        }
    }

    return visited[x2][y2];
}


int main() {
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 9148
def main():
    def dfs_rec(start,prev):
        ans[start] = cnt[start]
        if start!=0:
            ans[start] +=ans[prev]
        for node in tree[start]:
            if node != prev:
                dfs_rec(node,start)
        return
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline

    n,q = map(int,input().split())
    tree = [[] for i in range(n)]
    cnt = [0] *n
    ans = [0] *n

    for i in range(n-1):
        a,b = map(int,input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    for i in range(q):
        p,x = map(int,input().split())
        cnt[p-1]+=x
    dfs_rec(0,0)
    print(*ans)
if __name__=="__main__":
    main()


Measured memory_bytes: 274428
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    if(k==1){
      System.out.println(0);
    }else{
      System.out.println(n-k);
    }
  }
}

Measured memory_bytes: 23764
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
#include <list>

#include <random>
using namespace std;

struct SandClock {
	int time;
	int min_point_a;
	int min_point_sand;
	int max_point_a;
	int max_point_sand;
	void setSandClock(int t, int min_a, int min_s, int max_a, int max_s) {
		time = t;
		min_point_a = min_a;
		min_point_sand = min_s;
		max_point_a = max_a;
		max_point_sand = max_s;
	}
	void setSandClock(int t, SandClock s_clock, bool increase, int X) {
		time = t;
		int delta_t = t - s_clock.time;
		if (increase) {
			min_point_a = s_clock.min_point_a;
			min_point_sand = s_clock.min_point_sand + delta_t;
			if (min_point_sand > X) {
				min_point_sand = X;
			}
			
			max_point_sand = s_clock.max_point_sand + delta_t;
			if (max_point_sand > X) {
				int delta = max_point_sand - X;
				max_point_sand = X;
				max_point_a = s_clock.max_point_a - delta;
				if (max_point_a < min_point_a) {
					max_point_a = min_point_a;
				}
			}
			else {
				max_point_a = s_clock.max_point_a;
			}
		}
		else {
			max_point_a = s_clock.max_point_a;
			max_point_sand = s_clock.max_point_sand - delta_t;
			if (max_point_sand < 0) {
				max_point_sand = 0;
			}

			min_point_sand = s_clock.min_point_sand - delta_t;
			if (min_point_sand < 0) {
				int delta = 0 - min_point_sand;
				min_point_sand = 0;
				min_point_a = s_clock.min_point_a + delta;
				if (min_point_a > max_point_a) {
					min_point_a = max_point_a;
				}
			}
			else {
				min_point_a = s_clock.min_point_a;
			}
		}
	}
	int getSand(int t, int a, bool increase, int X) {
		int sand = 0;
		if (a < min_point_a) {
			sand = min_point_sand;
		}
		else if (a < max_point_a) {
			sand = min_point_sand + a - min_point_a;
		}
		else {
			sand = max_point_sand;
		}

		if (increase) {
			sand += t - time;
		}
		else {
			sand -= t - time;
		}

		if (sand > X) {
			return X;
		}
		else if (sand < 0) {
			return 0;
		}
		else {
			return sand;
		}
	}
};

int main(void) {
	int K, Q, buf;
	int X;
	scanf("%d", &X);
	scanf("%d", &K);
	vector<SandClock> res = vector<SandClock>(K + 1);

	bool is_increase = false;
	res[0].setSandClock(0, 0, 0, X, X);
	for (int i = 1; i <= K; i++) {
		scanf("%d", &buf);
		res[i].setSandClock(buf, res[i - 1], is_increase, X);
		is_increase = !is_increase;
	}
	scanf("%d", &Q);

	int a, t, ans;
	int current_ind = 0;
	for (int q = 0; q < Q; q++) {
		scanf("%d %d", &t, &a);
		while (true) {
			if (current_ind + 1 > K) {
				break;
			}
			if (t > res[current_ind + 1].time) {
				current_ind++;
			}
			else {
				break;
			}
		}

		bool increase = current_ind % 2 == 1;
		printf("%d\n", res[current_ind].getSand(t, a, increase, X));
	}

	return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define SZ(x) (int)(x.size())
#define F0(i,n) for(int i=0;i<n;i++)
#define F1(i,n) for(int i=1;i<=n;i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define P(x) cerr << #x << "=" << x << endl

const int inf = 1000002013;
const double pi = atan(1.0)*4.0;
const double eps = 1e-8;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
int bc(int n) { return n ? bc((n-1)&n)+1 : 0; }

int i, j, k, m, n, l;
int ch[101];
vector<int> adj[101];
ll ans1, ans2;

void go(int depth, int i, int parent) {
    int cnt = 0;
    for (int j : adj[i]) if (j != parent) {
        cnt++;
        go(depth + 1, j, i);
    }
    ch[depth] = max(ch[depth], cnt);
}

void eval(ll s = 1) {
    int depth = 0;

    while (ch[depth] > 0) {
     //   cout << ch[depth] << " ";
        s *= ch[depth];
        depth++;
    }
   // cout << endl;
    if (depth < ans1 || (depth == ans1 && s < ans2)) {
        ans1 = depth;
        ans2 = s;
    }
}

int main() {
    //freopen("x.in", "r", stdin);

    while (cin >> n) {
        F1(i, n) adj[i].clear();
        F0(k, n - 1) {
            cin >> i >> j;
            adj[i].push_back(j);
            adj[j].push_back(i);
        }

        ans1 = ans2 = inf;
        F1(i, n) {
            CL(0, ch);
            go(0, i, -1);
            eval();
        }
        F1(i, n) for (int j : adj[i]) {
            CL(0, ch);
            go(0, i, j);
            go(0, j, i);
            //cerr << i << " and " << j << endl;
            eval(2);
        }
        cout << ans1 + 1 << " " << ans2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int SIZEN = 200010;
const int mod = 998244353;
struct Robot{
	int x,d;
}r[SIZEN];
int R[SIZEN];
int N;
int tmp[SIZEN];
int cnt = 0;
int mx[SIZEN << 2] = {0};
void change(int rt,int l,int r,int x,int y){
	if(l == r){
		mx[rt] = y;
		return;
	}
	int mid = (l+r)>>1;
	if(x <= mid)change(rt<<1,l,mid,x,y);
	else change(rt<<1|1,mid+1,r,x,y);
	mx[rt] = max(mx[rt<<1],mx[rt<<1|1]);
}
int query(int rt,int l,int r,int x,int y){
	if(x <= l && y >= r){
		return mx[rt];
	}
	int mid = (l+r)>>1;
	if(y <= mid)return query(rt<<1,l,mid,x,y);
	if(x >  mid)return query(rt<<1|1,mid+1,r,x,y);
	return max(query(rt<<1,l,mid,x,y),query(rt<<1|1,mid+1,r,x,y));

}
bool cmp(const Robot &A,const Robot &B){
	return A.x < B.x;
}
int f[SIZEN];
int main(){
	scanf("%d",&N);
	for(int i = 1;i <=N;i++)scanf("%d%d",&r[i].x,&r[i].d),tmp[++cnt] = r[i].x;
	sort(tmp + 1,tmp + 1 + cnt);
	sort(r+1,r+1+N,cmp);
	cnt = unique(tmp + 1,tmp + 1 + cnt) - tmp - 1;
	change(1,1,N,lower_bound(tmp + 1,tmp + 1 + cnt,r[N].x) - tmp,N);
	R[N] = N;
	for(int i = N-1;i >= 1;i--){
		int tr = lower_bound(tmp + 1,tmp + 1 + cnt,r[i].x + r[i].d) - tmp - 1;
		int tl = lower_bound(tmp + 1,tmp + 1 + cnt,r[i].x) - tmp;
		if(tl > tr){
			R[i] = tr;
		}
		else{
			R[i] = max(tr,query(1,1,N,tl,tr));
		}
		change(1,1,N,tl,R[i]);
	}
	// for(int i = 1;i <= N;i++)printf("%d ",R[i]);printf("\n");
	f[N+1] = 1;
	for(int i = N;i >= 1;i--){
		f[i] = (f[i+1] + f[R[i] + 1]) % mod;
	}
	printf("%d\n",f[1]);
	return 0;
}

Measured memory_bytes: 7668