akhauriyash/Code-Regression huggingface dataset:
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}
bool cmp2(string x1 , string x2) {
    return sz(x1) < sz(x2);
}

const int MAXN = 2 * 100 + 10;
#define int long long
int32_t main(){
    int n,k;
    cin >> n >> k;
    map<int,int>pk;
    int a[n+1];

    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        pk[a[i]];
    }
    int m;
    int cnt = 0;
    int start = 0;
    for (m = 1;; m = a[m]) {
        pk[m]++;
        if(pk[m] > 2){
            start = m;
            break;
        }
    }
    for(auto & i : pk) {
        if(i.ss == 2 || i.ss == 3) {
            cnt++;
        }
    }
    int tc=0;
    if(k < n) {
        int ans =1;
        for (int i = 1; i <= k; ++i) {
            ans = a[ans];
        }
        cout << ans << endl;
        return 0;
    }
    for (int j = 1; j != m ; j = a[j]) {
        tc++;
    }
    k = k - tc;
    int rem = k%cnt;
    int x = start;

    for (int i1 = 0; i1 < rem; ++i1) {
        x = a[x];
    }
    cout << x << endl;

//    int ans = 1;
//
//    if( k < n) {
//        for (int j = 0; j < k; ++j) {
//            ans = a[ans];
//        }
//        cout << ans << endl;
//        return 0;
//
//    }
//    for (int j = 0; j < n; ++j) {
//        ans = a[ans];
//    }
//
//    for (int l = 0; l < rem; ++l) {
//        ans = a[ans];
//    }
//    cout << ans << endl;


}

Measured memory_bytes: 17532
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-01-30 16:52:17
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=410,mod=998244353;
i64 power(i64 a,i64 b,i64 p)
{
	i64 r=1;
	for(;b;b>>=1,a=a*a%p) if(b&1) r=r*a%p;
	return r;
}
i64 inv(i64 a){ return power(a,mod-2,mod); }
i64 n,f[N][N],F[N][N],a[N],b[N],p[N][N],m,s,ans;
namespace C
{
	i64 f[N],F[N];
	void init(int n)
	{
		f[0]=1;
		fr(i,1,n) f[i]=f[i-1]*i%mod;
		F[n]=inv(f[n]);
		fd(i,n,1) F[i-1]=F[i]*i%mod;
	}
	i64 C(i64 a,i64 b){ return f[a]*F[b]%mod*F[a-b]%mod; }
}
i64 &Add(i64 &a,i64 b){ return a=(a+b)%mod; }
int main()
{
	n=read(); m=400; C::init(m);
	fr(i,1,n){ s+=(a[i]=read()); b[i]=read(); }
	fr(i,0,m) fr(j,0,m) p[i][j]=power(i,j,mod);
	fr(i,1,n)
	{
		fr(j,0,m) fr(k,0,m) F[j][k]=f[j][k];
		fr(j,0,b[i]-1) Add(f[a[i]][j],p[a[i]][j]);
		fr(j,0,m-a[i]) fr(k,0,m-b[i]) fr(l,0,b[i]-1) Add(f[j+a[i]][k+l],(mod-F[j][k])%mod*p[a[i]][l]%mod*C::C(k+l,l));
	}
//	fr(i,0,m) fr(j,0,m) printf("%d%c",int(f[i][j]),j==m?'\n':' ');
	fr(i,0,m) fr(j,0,m) Add(ans,f[i][j]*inv(p[i][j])%mod*s%mod*inv(i));
	printf("%d\n",int(ans));
	return 0;
}

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

int main() {
    int min = 1001;
    int n, t; cin >> n >> t;
    while (n--) {
        int ci, ti; cin >> ci >> ti;
        if (ti > t) continue;
        if (ci < min) min = ci;
    }
    cout << (min != 1001 ? to_string(min) : "TLE") << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  bool cnt[128] {};
  string s; cin >> s;
  for (int c : s) cnt[c] = true;

  bool ok = true;
  if (cnt['N']) ok &= (cnt['S']);
  if (cnt['W']) ok &= (cnt['E']);
  if (cnt['S']) ok &= (cnt['N']);
  if (cnt['E']) ok &= (cnt['W']);

  puts(ok ? "Yes" : "No");

  return 0;
}



Measured memory_bytes: 256
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    H, N = read_ints()
    A, B = [], []
    for _ in range(N):
        a, b = read_ints()
        A.append(a)
        B.append(b)
    OPT = [math.inf for _ in range(H+max(A)+1)]
    OPT[0] = 0
    for h in range(H):
        for i in range(N):
            OPT[h+A[i]] = min(OPT[h+A[i]], OPT[h]+B[i])
    return min(OPT[H:])


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 74596
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////

ll dp[100010][3];
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    
    rep(i,3)rep(j,100010)dp[i][j] = -LONG_MAX / 100;

    int n;cin >> n;
    vector<ll> a(n);
    vector<char> s(n);
    for(int i = 0;i < n;i++){
        if(i == 0){
            cin >> a[i];
            s[i] = '+';
        }else{
            cin >> s[i] >> a[i];
        }
    }

    dp[0][0] = a[0];
    for(int i = 1;i < n;i++){
        if(s[i] == '+'){
            chmax(dp[i][0],dp[i-1][0] + a[i]);
            chmax(dp[i][0],dp[i-1][1] - a[i]);

            chmax(dp[i][1],dp[i-1][1] - a[i]);
            chmax(dp[i][1],dp[i-1][2] + a[i]);

            chmax(dp[i][2],dp[i-1][2] + a[i]);
        }else{
            chmax(dp[i][1],dp[i-1][0] - a[i]);
            chmax(dp[i][0],dp[i-1][0] - a[i]);

            chmax(dp[i][2],dp[i-1][1] + a[i]);
            chmax(dp[i][1],dp[i-1][1] + a[i]);

            chmax(dp[i][2],dp[i-1][2] + a[i]);
        }
    }
    cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << '\n';
    //rep(i,3){
    //    rep(j,n){
    //        cout << setw(4) << (dp[j][i] < -1000 ? "-INF" : to_string(dp[j][i]));
    //    }
    //    cout << '\n';
    //}
    return 0;
}
/*
 *!!CHECK!! 
 * 制約をよく読め：まず最も愚直な解法を考えろ
 * intの掛け算をしてる場合：overflowは大丈夫？
 * 制約の下限・上限は大丈夫？
 * 木構造は一直線にした時TLEしない？
 * */


Measured memory_bytes: 3456
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
xi = list(map(int, input().split()))

ans_list = []
for i in range(N-K+1):
    l = xi[i]
    r = xi[i+K-1]
    if l*r < 0:
        a = abs(l)*2 + abs(r)
        b = abs(r)*2 + abs(l)
        if a > b :
            ans_list.append(b)
        else:
            ans_list.append(a)
    elif l < 0:
        ans_list.append(abs(l))
    else: #if li[-1] > 0:
        ans_list.append(abs(r))

print(min(ans_list))


Measured memory_bytes: 14252
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        #print(l, r)
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:# sum == K
            r = test
        if int(r) == r and r-l < 1:
            print(int(r))
            return

    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

Measured memory_bytes: 29044
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 100000;

int N, K;
int rest[MAX_N - 1];

int main(){
	scanf("%d %d", &N, &K);
	int begin, end;
	int s, t;
	for(int i = 0; i < N; i++){
		scanf("%d", &t);
		if(i != 0) rest[i - 1] = t - s;
		s = t + 1;
		if(i == 0) begin = t;
		if(i == N - 1) end = t + 1;
	}
	sort(rest, rest + N - 1);
	reverse(rest, rest + N - 1);
	int sum = 0;
	for(int i = 0; i < K - 1; i++) sum += rest[i];
	printf("%d\n", end - begin - sum);
	return 0;
}



Measured memory_bytes: 3140
#include <iostream>

using namespace std;

int main(){

  int size;

  cin >> size;

  int *array = new int[size];

  for(int i = 0; i < size; i++){
    cin >> array[i];
  }

  for(int i = 0; i < size - 1; i++){
    cout << array[i] << " ";
  }
  cout << array[size - 1] << endl;

  int i, j, v, k;

  for(i = 1; i < size; i++){
    j = i - 1;
    v = array[i];
    while(j >= 0 && array[j] > v){
      array[j + 1] = array[j];
      j--;
    }
    array[j + 1] = v;

    for(k = 0; k < size - 1; k++){
      cout << array[k] << " ";
    }
    cout << array[k] << endl;
  }

  delete[] array;
  return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){
	
	int n;
	string s, t;
	cin >> n >> s >> t;
	for(int i=n; 0<=i; i--){
		if(s.substr(n-i, i)==t.substr(0, i)){
			cout << 2*n-i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long int gcd(long long int a,long long int b){
  if(a < b){
    ll temp = a+b;
    a = temp - a;
    b = temp - b;
  }
  ll c = 1;
  if(b == 0)return a;
  while(c != 0){
    c = a%b;
    if(c == 0)return b;
    a = b;
    b = c;
  }
}

int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  a--;
  ll e = gcd(c,d);
  ll anum = a/c + a/d - a/(c*d/e);
  ll bnum = b/c + b/d - b/(c*d/e);
  cout << (b - a) - (bnum - anum) << endl;
}

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

int main()
{
  int x, a, b;
  cin >> x;
  int nsx = abs(x);

  for (int i = 0; true; i++) {
    for (int j = 0; j <= i; j++) {
      if (pow(i, 5) + pow(j, 5) == nsx) {
        if (x >= 0) {
          a = i; b = j * (-1);
        } else {
          a = i * (-1); b = j;
        }
        cout << a << " " << b << endl;
        return 0;
      } else if (pow(i, 5) - pow(j, 5) == nsx) {
        if (x >= 0) {
          a = i; b = j;
        } else {
          a = i * (-1); b = j * (-1);
        }
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  set<int> R, G, B;
  for (int i = 0; i < N; i++)
  {
    if (S[i] == 'R') R.insert(i);
    else if (S[i] == 'G') G.insert(i);
    else B.insert(i);
  }
  long ans = 0;
  for (auto x : R)
  {
    for (auto y : G)
    {
      int tmp = y - x;
      if (tmp < 0)
      {
        ans += B.size() - B.count(y + tmp) - B.count(x - tmp);
        if (tmp % 2 == 0) ans -= B.count(y - tmp/2);
      }
      else
      {
        ans += B.size() - B.count(y + tmp) - B.count(x - tmp);
        if (tmp % 2 == 0) ans -= B.count(y - tmp/2);
      }
    }
  }
  cout << ans << endl;
}


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

const int N = 200005;

int n, a[N];
std::map<int, int> str;

bool check(int m) {
	for (int i = 1; i <= n; ++i) {
		if (a[i] > a[i - 1]) str[a[i - 1] + 1] = 1;
		else {
			std::map<int, int>::iterator it = str.upper_bound(a[i]);
			while (it != str.end()) str.erase(it++);
			for (it = --str.end(); ; --it) {
				if (it->second < m) {
					int c = it->second + 1;
					auto nxt = it; ++nxt;
					int b = nxt == str.end() ? a[i] : nxt->first - 1;
					str[b] = c; break;
				} else {
					it->second = 1;
				}
				if (it == str.begin()) return 0;
			}
		}
	}
	return 1;
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> a[i];
	int l = 1, r = n, ans = -1;
	while (l <= r) {
		int mid = l + r >> 1;
		if (check(mid)) r = mid - 1, ans = mid;
		else l = mid + 1;
	}
	std::cout << ans << '\n';
	return 0;
}


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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n),b(n);
	rep(i,n) scanf("%lld",&a[i]);
	rep(i,n) scanf("%lld",&b[i]);

	if(accumulate(a.begin(),a.end(),0LL)<accumulate(b.begin(),b.end(),0LL)){
		puts("-1");
		return 0;
	}

	int ans=0;
	lint sum=0;
	vector<lint> c;
	rep(i,n){
		if(a[i]<b[i]){
			sum+=b[i]-a[i];
			ans++;
		}
		else{
			c.emplace_back(a[i]-b[i]);
		}
	}

	sort(c.rbegin(),c.rend());

	rep(i,c.size()) if(sum>0) sum-=c[i], ans++;

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FILEIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define LL long long 
#define m 1000000007LL
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define p push
#define I insert
#define bg begin()
#define ed end()
#define sz size()
#define all(v) v.begin(),v.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef map<LL ,LL > mii;
//typedef priority_queue<int> pq;
typedef queue<int>que;
typedef stack<int>stk;
#define Inf 100000005LL

int main()
{
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(d2==1){
        cout<<1<<endl;
    }
    else cout<<0<<endl;
    
}

Measured memory_bytes: 256
from sys import stdin


def main():
    n = int(stdin.readline())
    x = list(map(int, stdin.readline().split()))

    p = sum(x) / n

    p1 = int(p)
    p2 = int(p + 1)

    s1 = 0
    s2 = 0

    for xi in x:
        s1 += (xi - p1) ** 2
        s2 += (xi - p2) ** 2

    print(min(s1, s2))


if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
<?php

$str = trim(fgets(STDIN));
for ($i = 0, $len = strlen($str); $i < $len; $i++) {
    $c = $str[$i];
    if (preg_match('/[a-z]/', $c)) {
        echo strtoupper($c);
    } elseif (preg_match('/[A-Z]/', $c)) {
        echo strtolower($c);
    } else {
        echo $c;
    }
}

echo PHP_EOL;

Measured memory_bytes: 6640
#include<stdio.h>
int main()
{
    int a,b,t,to;
    scanf("%d",&a);
    scanf("%d",&b);
    t = a+b;

    if (t<24){
        printf("%d",t);
    }
    else if (t>23){
        to = t-24;
        printf("%d",to);
    }
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> X, std::vector<long long> L){
  vector<pair<ll, ll>> v;
  for(ll i=0; i<N; i++)
    v.push_back(make_pair(X[i]+L[i], X[i]-L[i]));
  sort(v.begin(), v.end());
  ll right = v[0].first;
  ll cnt = 1;
  for(ll i=1; i<N; i++) {
    if(v[i].second<right) continue;
    cnt++;
    right = v[i].first;
  }
  std::cout << cnt << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> X(N);
  std::vector<long long> L(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&X[i]);
    scanf("%lld",&L[i]);
  }
  solve(N, std::move(X), std::move(L));
  return 0;
}



Measured memory_bytes: 3956
#include <bits/stdc++.h> 
  
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long
#define M 1000000007
 
using namespace std;
 
signed main() {
    int n;
    cin >> n;
    cout << 1-n;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int r, g, b;
	cin >> r >> g >> b;

	int ans = r * 100 + g * 10 + b;

	if (ans % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

ans = 0

for _ in range(N):
  A = list(map(int, input().split()))
  buf = C
  for i in range(M):
    buf += A[i]*B[i]
  if buf > 0:
    ans += 1
print(ans)


Measured memory_bytes: 9160
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF         1e9
#define EPS         1e-9
#define REP(i,n)    for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(lint i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b)   (((a)+(b)-1)/(b))
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP        cout << fixed << setprecision(8)
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }

signed main() {
	bitset<64>bs;
	int q = in();
	REP(i, q) {
		int p = in();
		if (p == 0 || p == 1 || p == 2 || p == 3) {
			int r = in();
			if (p == 0) {
				cout << (bs.test(r) ? '1' : '0') << endl;
			} else if (p == 1) {
				bs.set(r);
			} else if (p == 2) {
				bs.reset(r);
			} else {
				bs.flip(r);
			}
		} else {
			if (p == 4) {
				cout << (bs.all() ? '1' : '0') << endl;
			} else if (p == 5) {
				cout << (bs.any() ? '1' : '0') << endl;
			} else if (p == 6) {
				cout << (bs.none() ? '1' : '0') << endl;
			} else if (p == 7) {
				cout << bs.count() << endl;
			} else {
				cout << bs.to_ulong() << endl;
			}
		}
	}
}


Measured memory_bytes: 3092
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
    int n , m , d ; 
    cin >> n >> m >> d ; 
    pair<int,int> pos[n*m+1] ; 
    int grid[n][m] ; 
    int mem[n*m+1] ; 
    memset(mem,-1,sizeof mem) ; 
    for(int i=0;i<n;i++){
    	for(int j=0;j<m;j++){
    		cin >> grid[i][j] ; 
    		pos[grid[i][j]] = { i , j } ; 
    	}
    }
    for(int i=n*m;i>=1;i--){
    	if ( mem[i] == -1 ){
    		debug() << imie(i) ; 
    		mem[i] = 0 ; 
    		int previous = i ; 
    		int start = i-d; 
    		while(start >= 1){
    			debug() << imie(previous) imie(start) ; 
    			auto pre = pos[previous] ; 
    			auto next = pos[start] ; 
    			debug() << imie(pre) imie(next) ; 
    			mem[start] = mem[previous] + abs(pre.first - next.first) + abs(pre.second - next.second) ;
    			debug() << imie(mem[start]) ; 
    			previous = start ; 
    			start -= d ; 
    		}
    	}
    }
    int t ; 
    cin >> t ; 
    while(t--){
    	int l , r ; 
    	cin >> l >> r ; 
    	debug() << imie(l) imie(r) ; 
    	cout << mem[l] - mem[r] << endl;
    }
    return 0 ;
}


Measured memory_bytes: 2560
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

s=get_nsp

L=s.size
s1=s.slice(0,(L-1)/2)
L1=s1.size

flag=true
(L/2).times do|i|
  if s[i]!=s[L-1-i]
    flag=false
    break
  end
end
(L1/2).times do|i|
  if s1[i]!=s1[L1-1-i]
    flag=false
    break
  end
end
s2=s.slice((L+3)/2-1,L-(L+3)/2+1)
L2=s2.size
(L2/2).times do|i|
  if s2[i]!=s2[L2-1-i]
    flag=false
    break
  end
end
puts yn_judge(flag)

Measured memory_bytes: 1788
N, K = map(int, input().split(' '))

MOD = 10 ** 9 + 7

min_ = sum(range(K))
max_ = sum(range(N, N-K, -1))

count_ = 0

# K個以上選ぶのでKからはじめてN+1まで増やす
for i in range(K, N + 2):
    # 作れる個数
    add = max_ - min_ + 1

    min_ += i
    max_ += (N - i)

    count_ = (count_ + add ) % MOD

print(count_)


Measured memory_bytes: 8888
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
    char b[100],a[1000];
	int i,j,k;
	while(gets(b)!=NULL) {
    i=0; j=0; 
	while(i<strlen(b)) {
		if (b[i]=='@') {
			for (k=j;k<j+(b[i+1]-'0');k++) a[k]=b[i+2];
			j=k; i+=3;
		} else a[j++]=b[i++];
	}
	a[j]='\0';
	cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1120
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
#define fi first
#define se second
#define mk make_pair
main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(((m*i+n*j)-i*j*2)==k){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	int a[m];
	int A=0,B=0;
	for(int i=0;i<m;i++){
		cin>>a[i];
		if(a[i]<x) A++;
		else B++;
	}
	cout<<min(A,B);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int x;
  cin >> x;
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  sort(all(a));

  pii ans = pii(inf, x);
  rep3(i, 0, 102) { // debuged
    int it = lb(a, i);
    if (it != sz(a) && a[it] == i) {

    } else {
      chmin(ans, pii(abs(x - i), i));
    }
  }
  cout << ans.S << endl;
}


Measured memory_bytes: 3612
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, K;
    cin >> N >> K;
    ld ans = 0.;
    rep(i, N) {
        ll cnt = 0;
        ll tmp = i+1;
        while(tmp < K) {
            tmp *= 2;
            cnt++;
        }
        ans += 1/(ld)N * pow(0.5, cnt);
    }
    print(std::setprecision(20) << ans);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}



signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n,x,y;
    cin>>n>>x>>y;
    Vi a(n);
    REP(i,0,n) cin>>a[i];

    if(n==1){
        cout<<abs(y-a[0])<<endl;
    }else{
        cout<<max(abs(a[n-2]-a[n-1]),abs(a[n-1]-y))<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
    long long n,p,count=0,a=1,hozon;
    cin >> n >> p;
    hozon = p;
    if(n>=2){
    for(int i=2;i<=sqrt(p);i++){
        while(p%i==0) {count++;p=p/i;}
        if(count>=n) {a=i;}
        count = 0;
        p = hozon;
    }
        cout << a;
    }
    if(n==1) cout << p;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

signed main() {
  int a, b, c; cin >> a >> b >> c;
  ll sum = 0;
  bool ans = false;

  for(int i = a; i <= a*b; i += a) {
    if(i%b == c) ans = true;
  }
  cout << (ans ? "YES" : "NO") << endl;
}


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

int main() {
  long double a=0.0,b=0,c=0,d=0,m=0,n=0,p=0.0,q=0;
  cin >> a >> b >> m >> n;
  c = m*30+n/2-n*6;
  if(c<0)
  { c = -c;}
  if(c>180)
  {c=360-c;}
  c=(c*3.141592653589793238)/180;
  p=sqrtl(a*a+b*b-2*a*b*cosl(c));
  cout << fixed << setprecision(15) <<p;
  
  
}


Measured memory_bytes: 4152
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<cstring>
#include<string>
using namespace std;
int a[5][105];
int dfs(int i,int j){
	if(i<=0||j<=0)return 0;
	if(i==1&&j==1)return a[i][j];
	return max(dfs(i-1,j),dfs(i,j-1))+a[i][j];
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=2;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	int ans=dfs(2,n);
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

using ll = long long;

array<ll, 51> num, pate;

ll Level(ll n, ll x) {
    if (n == 0) return 1;
    else if (x == num[n]) return pate[n];
    else if (x == 1) return 0;
    else if (x < 1 + num[n - 1]) return Level(n - 1, x - 1);
    else if (x == 1 + num[n - 1]) return pate[n - 1];
    else if (x == 2 + num[n - 1]) return pate[n - 1] + 1;
    else return pate[n - 1] + 1 + Level(n - 1, x - num[n - 1] - 2);
}

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

    ll n, x;
    cin >> n >> x;

    num[0] = pate[0] = 1;
    for (int i = 1; i <= n; ++i) {
        num[i] = 3 + 2 * num[i - 1];
        pate[i] = 1 + 2 * pate[i - 1];
    }

    cout << Level(n, x) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
 public static void main(String args[] ){
   
   Scanner in = new Scanner (System.in);
   int letter = in.nextInt();
   String a = in.next();
   int red =0,blue=0;
   for(int i =0;i<a.length();i++)
   {
   		if(a.charAt(i)=='R')red++;
     else if(a.charAt(i)=='B') blue++;
   }
   if(red>blue) System.out.println("Yes");
   else System.out.println("No");
}
}

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

int main() {
    int N;
    cin >> N;
    
    vector<int> a(N);

    rep2(i, 0, N) cin >> a.at(i);

    int temp;
    rep2(i, 0, N){
        rep2(j, 0, N-1-i){
            if(a.at(j) < a.at(j+1)){
                temp = a.at(j);
                a.at(j) = a.at(j+1);
                a.at(j+1) = temp;
            }
        }
    }

    int score_dif = 0;
    rep2(i, 0, N){
        if(i % 2 == 0) score_dif += a.at(i);
        if(i % 2 == 1) score_dif -= a.at(i);
    }

    cout << score_dif << endl;
}


Measured memory_bytes: 3644
/*
[m-solutions2019] B - Sumo
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

string S;

bool solve() {
    int cnt = 0;
    for (char c : S) {
        if (c == 'o') {
            cnt++;
        }
    }
    return 15 - S.length() + cnt >= 8;
}

int main() {
    cin >> S;

    cout << (solve() ? "YES" : "NO") << endl;

    return 0;
}


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

int main()
{
    char c;
    int current = 0;
    std::vector<int> height;
    height.push_back(current);
    while (scanf("%c", &c) != EOF) {
        switch (c) {
        case '\\' :
        {
            current--;
            height.push_back(current);
            break;
        }
        case '/':
        {
            current++;
            height.push_back(current);
            break;
        }
        case '_':
        {
            height.push_back(current);
            break;
        }
        default :
        {
            break;
        }
        }
    }

    int area = 0;
    int sum = 0;
    std::vector<int> areas;
    std::vector<int>::iterator itLeft = height.begin();
    std::vector<int>::iterator itRight = height.begin();
    while (true) {
        ++itRight;
        if (itRight == height.end()) {
            if (std::next(itLeft) == itRight) {
                break;
            } else {
                area = 0;
                itLeft++;
                itRight = itLeft;
            }
        } else {
            if (*itLeft == *itRight) {
                if (area != 0) {
                    areas.push_back(area);
                    sum += area;
                }
                area = 0;
                itLeft = itRight;
            } else if (*(itLeft) < *(itRight)) {
                itLeft = itRight;
            } else {
                area += *itLeft - *itRight;
            }
        }
    }

    std::cout << sum << std::endl << areas.size();
    for (std::size_t i = 0; i < areas.size(); ++i) {
        std::cout << " " << areas[i];
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3344
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    a,b = map(int, input().split())
    ans = max(a,b)
    first = ans
    m = min(a,b)
    while True:
        if ans%m == 0:
            print(ans)
            exit()
        ans += first

if __name__=="__main__":
    main()


Measured memory_bytes: 65908
#include <bits/stdc++.h>
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define MAX 500005
 #include<iomanip>
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define x first
 #define y second
using namespace std;
 int power(int x, unsigned int y, int p)
 {
     int res = 1;      // Initialize result
   
     x = x % p;  // Update x if it is more than or
                 // equal to p
   
     while (y > 0)
     {
         // If y is odd, multiply x with result
         if (y & 1)
             res = (res*x) % p;
   
         // y must be even now
         y = y>>1; // y = y/2
         x = (x*x) % p;
     }
     return res;
 }
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
ll arr[1000004];
void spf(ll num)
{
    fore(i,0,num+1)arr[i]=i;
    for(ll i=2;i<=num;i+=2)
    {
        arr[i]=2;
    }
    for(ll i=3;i<=num;i+=2)
    {
        if(arr[i]==i)
        for(ll j=i;j<=num;j+=i)
        {
           if(arr[j]==j) arr[j]=i;
        }
    }
}
void PrintSPF(ll num)
{
    while(num!=1)
    {
        cout<<arr[num]<<" ";
        num/=arr[num];
    }
}
int modInverse(int a, int m)
{
    int g = gcd(a, m);
    
        
    
    {
        return power(a, m-2, m);
    }
}
 int32_t main()
{
    Need_for_speed(activated);
//    satisfy
//    {}
   
   
    ll a[1000005]={0};
    ll n;cin>>n;
    fore(i,0,n)cin>>a[i];
    map<ll,ll>ans;
     vector< map< ll,ll > >m(n);
     spf(1000004);
    for(ll i=0;i<n;i++)
    {
        ll d=a[i];
        while(d!=1)
        {
            m[i][arr[d]]++;
            d/=arr[d];
        }
        for(auto it:m[i])
        {
            if(ans[it.x]<it.y)
            {
                ans[it.x]=it.y;
            }
        }
    }
 ll f=0;
//    for(ll i=0;i<n;i++)
//    {ll k=1;
//       for(auto it:ans)
//       {
//          k=(k*power(it.x,it.y-m[i][it.x],MOD))%MOD;
//        //   cout<<it.x<<" "<<b[i][it.x]<<endl;
//       }
//           f=(f+k)%MOD;
//    }
//
    ll lcm=1;
    for(auto it:ans)
    {
        lcm=(lcm*(power(it.x,it.y,MOD)))%MOD;
    }
    for(ll i=0;i<n;i++)
    {
        f+=( lcm*modInverse(a[i],MOD))%MOD;
    }
    f=f%MOD;
    cout<<f<<endl;
    return 0;
    }


Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
int n;
vector<int> v[10000];
priority_queue<int> que;
int dp[10000];

void dfs(int node)
{
    if (dp[node] != -1)
    {
        return;
    }
    dp[node] = que.top();
    que.pop();
    rep(i, v[node].size())
    {
        dfs(v[node][i]);
    }
}

int main()
{
    cin >> n;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll s = 0;
    rep(i, n)
    {
        int x;
        cin >> x;
        que.push(x);
        s += x;
    }
    s -= que.top();
    rep(i, 10000)
    {
        dp[i] = -1;
    }
    dfs(0);
    cout << s << endl;
    rep(i, n)
    {
        cout << dp[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>
#include <bitset>

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define mer(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353
//#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;

//vector<char> vc;
vector<string> vs;




int main() {
	int N;
	cin >> N;
	N %= 1000;
	if (N == 0)cout << 0 << '\n';
	else cout << 1000 - N << '\n';

	return 0;
}

Measured memory_bytes: 3616
package main

import (
    "bufio"
    "fmt"
    "os"
)

var s = bufio.NewReader(os.Stdin)

func main() {
    var W, H, x, y, r int
    fmt.Fscan(s, &W)
    fmt.Fscan(s, &H)
    fmt.Fscan(s, &x)
    fmt.Fscan(s, &y)
    fmt.Fscan(s, &r)
    if x > 0 && x < W && y > 0 && y < H && r <= x && r <= y && r <= W - x && r <= H - y {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}


Measured memory_bytes: 1168
import numpy as np
 
t = np.array(list(input()), dtype='U1')
s = np.array(list(input()), dtype='U1')
 
ls = len(s)
lt = len(t)
 
eq = s[:, None] == t[None, :]
dp = [np.zeros(lt+1, dtype=np.int16)]
 
# solve
for i in range(ls):
    prev = dp[-1].copy()
    np.maximum(prev[1:], prev[:-1] + eq[i], out = prev[1:])
    np.maximum.accumulate(prev, out = prev)
    dp.append(prev)
 
# print([list(line) for line in dp])
 
# restore
l = dp[-1][-1]
res = ''
i, j = ls, lt
while i > 0 and j > 0:
    if eq[i-1][j-1]:
        res += s[i-1]
        i, j = i-1, j-1
        continue
    
    if dp[i-1][j] > dp[i][j-1]:
        i -= 1
    else:
        j -= 1
 
print(res[::-1])

Measured memory_bytes: 39244
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)

AB = []
ABC = []
for b in B:
    for a in A:
        AB.append(a+b)
AB.sort(reverse=True)
# AB = AB[:K]
AB = AB[:min(3001, X*Y*Z+1)]

for c in C:
    for ab in AB:
        ABC.append(ab+c)
ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef long long ll;
typedef long long ll;
//typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX / 100;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
const double PI = 3.14159265358979323846;

typedef pair<ll, ll> P;

void print_line(vector<vector<int>> &ans) {
    for (int i = 0; i < ans.size(); i++) {
        for (int y = 0; y < ans[i].size(); y++) {
            cout << ans[i][y];
        }
        cout << endl;
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> as(n), bs(n);
    rep(i, n) cin >> as[i] >> bs[i];

    ll sum = 0;

    for (int i = n - 1; i >= 0; i--) {
        ll asi = as[i] + sum;
        ll next = (asi + bs[i] - 1) / bs[i] * bs[i] - asi;
        sum += next;
    }
    cout << sum << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int a[305][305];
int rec1[90005];
int rec2[90005];
int dist[90005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w, d;
	cin >> h >> w >> d;
	rep(i, h)rep(j, w) {
		cin >> a[i][j];
		rec1[a[i][j]] = i, rec2[a[i][j]] = j;
	}
	for (int i = d + 1; i <= h * w; ++i)
		dist[i] = dist[i - d] + abs(rec1[i] - rec1[i - d]) + abs(rec2[i] - rec2[i - d]);
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		printf("%d\n", dist[r] - dist[l]);
	}
	return 0;
}


Measured memory_bytes: 2560
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, k = IN()
	dq = LIN()
	rdq = dq[::-1]
	#s = input()
	max_v=0
	for left_get in range(k+1):
		for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	print(max_v)
		
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 41196
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    long long t, n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += s[i];
    }
    if (ans % 10 == 0) {
        sort(s.begin(), s.end());
        for (int i = 0; i < n; i++) {
            if (s[i] % 10 != 0) {
                ans -= s[i];
                break;
            }
        }
    }
    if (ans % 10 == 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256