akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n, k, q;
    cin >> n >> k >> q;
    vi p(n, k);

    fo(i, q) {
        int a;
        cin >> a;
        p[a - 1]++;
    }

    fo(i, n) {
        if ( p[i] - q > 0 ) cout << "Yes\n";
        else cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 1024
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

string text;
int cursor;

void forward_char()
{
	if (cursor < text.length()) ++cursor;
}

void backward_char()
{
	if (0 < cursor) --cursor;
}

void forward_word()
{
	while (cursor < text.length() && text[cursor] == ' ') ++cursor;
	while (cursor < text.length() && text[cursor] != ' ') ++cursor;
}

void backward_word()
{
	while (0 < cursor && text[cursor - 1] == ' ') --cursor;
	while (0 < cursor && text[cursor - 1] != ' ') --cursor;
}

void insert_text(const string &str)
{
	text.insert(cursor, str);
	cursor += str.length();
}

void delete_char()
{
	if (cursor < text.length()) text.erase(cursor, 1);
}

void delete_word()
{
	int off = cursor;
	while (off < text.length() && text[off] == ' ') ++off;
	if (off == text.length()) return;
	while (off < text.length() && text[off] != ' ') ++off;
	text.erase(cursor, off - cursor);
}

string get_insert_string(const string &str)
{
	int i = str.find('"'), j = str.rfind('"');
	return str.substr(i + 1, j - i - 1);
}

int main()
{
	string line;

	int N;
	getline(cin, line);
	N = atoi(line.c_str());
	while(N--)
	{
		getline(cin, text);

		cursor = 0;

		getline(cin, line);
		int M = atoi(line.c_str());
		for (int i = 0; i < M; i++)
		{
			getline(cin, line);
			     if (line == "forward char")  forward_char();
			else if (line == "forward word")  forward_word();
			else if (line == "backward char") backward_char();
			else if (line == "backward word") backward_word();
			else if (line == "delete char")   delete_char();
			else if (line == "delete word")   delete_word();
			else if (line.compare(0, 6, "insert") == 0)
				insert_text(get_insert_string(line));
		}
		cout << text.substr(0, cursor) << "^" << text.substr(cursor) << endl;
	}
	return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

// 最大公約数
template<typename T>
T gcd(T a, T b) {
    T r, temp;

    while(1) {
        if(a < b) {
            temp = a;
            a = b;
            b = temp;
        }
        if(b < 1) continue;

        while((r = a % b) != 0) {
            a = b;
            b = r;
        }
        return b;
    }
}

// 最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a*b/gcd(a, b);
}

int main() {
    LL A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}



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

n = int(input())
n_len = len(str(n))
if n_len == 1:
    cnt = n
elif n_len == 2:
    cnt = 9
elif n_len == 3:
    cnt = 9 + n-99
elif n_len == 4:
    cnt = 909
elif n_len == 5:
    cnt = 909 + n-9999
else:
    cnt = 90909
print(cnt)

Measured memory_bytes: 3060
fn main() {
    let nl = read_vec::<i32>();
    let n = nl[0];
    let l = nl[1];

    let sum: i32 = (0..n).map(|i| l+i).sum();
    let mi_abs = (0..n).map(|i| l+i).min_by_key(|x| x.abs()).unwrap();

    println!("{}", sum - mi_abs);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
  ll X, Y;
  cin >> X >> Y;
  
  FOR(i,0,1001){
    FOR(j,0,1001){
      if((i+j==X) && (2*i+4*j==Y)){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
  
}

Measured memory_bytes: 3628
# include <bits/stdc++.h>
# define rep(i, n) for (ll i = 0; i < (n); i++)
# define reps(i, n) for (ll i = 1; i <= (n); i++)
# define foreps(i, m, n) for (ll i = (m); i < (n); i++)
# define len(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

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

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

int main() {
    ll N; cin >> N;
    ll ans = 1;
    rep(i, N) {
        ll a;
        cin >> a;
        ans = lcm(ans, a);
    }

    cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    map<char,int> m;
    string str = "abcdefghikjlmnopqrstuvwxyz";

    for(char c : s){
        m[c]++;
    }
    for(char c : str){
        if(m[c] == 0){
            cout << c << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
inf=10**9

def dfs(cur,a,b,c):
    if cur==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf
    ret0=dfs(cur+1,a,b,c)
    ret1=dfs(cur+1,a+l[cur],b,c)+10
    ret2=dfs(cur+1,a,b+l[cur],c)+10
    ret3=dfs(cur+1,a,b,c+l[cur])+10
    return min(ret0,ret1,ret2,ret3)

print(dfs(0,0,0,0))


Measured memory_bytes: 3064
N = int(input())

s = []

for _ in range(N):
    s.append(int(input()))
    
ans = sum(s)

if ans % 10 == 0:
    pref = sorted(s)
    ans_flag = False
    for i in range(N):
        if pref[i] % 10 != 0:
            ans_flag = True
            ans -= pref[i]
            break
    if ans_flag == True:
        print(ans)
    else:
        print(0)
else:
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

template<class type> struct WeightedUnionFind{
    vector<int> par;
    vector<int> treerank;
    vector<type> wdiff;

    WeightedUnionFind(int n){
        init(n);
    }

    void init(int n){
        par.resize(n); treerank.resize(n); wdiff.resize(n);
        rep(i, n) par[i] = i, treerank[i] = 0, wdiff[i] = 0;
    }

    int find(int x){
        if(par[x] == x) return x;
        int r = find(par[x]);
        wdiff[x] += wdiff[par[x]];
        return par[x] = r;
    }

    type weight(int x){
        find(x);
        return wdiff[x];
    }

    void unite(int x, int y, type w){
        w += weight(x); w -= weight(y);
        x = find(x); y = find(y);
        if(x == y) return;
        if(treerank[x] < treerank[y]) swap(x, y), w = -w;
        if(treerank[x] == treerank[y]) treerank[x]++;
        par[y] = x;
        wdiff[y] = w;
        return;
    }

    type diff(int x, int y){
        return weight(y) - weight(x);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    WeightedUnionFind<lint> wuf(n);
    rep(i, m){
        int l, r; lint d;
        scanf("%d%d%lld", &l, &r, &d);
        --l; --r;
        if(wuf.same(l, r)){
            if(wuf.diff(l, r) != d){
                puts("No");
                return 0;
            }
        }
        wuf.unite(l, r, d);
    }
    puts("Yes");
}

Measured memory_bytes: 1792
H, W = gets.chomp.split.map(&:to_i)
T = []
H.times do
  T << gets.chomp.split("")
end

dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, -1, -1, -1, 0, 1, 1, 1]

H.times do |i|
  W.times do |j|
    if T[i][j] == "#"
      print T[i][j]
    else
      count = 0
      8.times do |k|
        x = i + dx[k]
        y = j + dy[k]
        if x >= 0 && x < H && y >= 0 && y < W && T[x][y] == "#"
          count += 1
        end
      end
      print count
    end
  end
  puts ""
end


Measured memory_bytes: 2172
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
const ld INF = 1e9+123;
#define VEC(type,A,N) vector<type> A(N+10)
#define VECi(type,A,N,i) vector<type> A(N+10,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N+10,vector<type>(M+10))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N+10,vector<type>(M+10,i))
#define ALL(v) v.begin()+1, v.end()-9
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    int N;
    cin>>N;
    
    int size=0;
    REP(i,N){
        if(i<10)size++;
        else if(i/100>=1&&i/100<10)size++;
        else if(i/10000>=1&&i/10000<10)size++;
    }
    //cout<<ac<<" "<<wa;
    cout<<fixed<<setprecision(32)<<size;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


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

int dp[110][110];
struct S {
	int a, e, r;
	bool operator <(const S& x) const {
		return r < x.r;
	}
} t[100];

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

	int D, N;
	while(cin >> D >> N, D) {
		for(int i = 0; i < N; i++) {
			cin >> t[i].a >> t[i].e >> t[i].r;
		}

		const int INF = 1 << 25;
		fill((int*)begin(dp), (int*)end(dp), INF);
		dp[0][D] = 0;

		typedef pair<int, int> P;
		queue<P> q;
		q.push({ 0, D });
		while(q.size()) {
			int ex = q.front().first, d = q.front().second;
			q.pop();
			for(int i = 0; i < N; i++) {
				if(ex < t[i].r) continue;
				int nex = min(100, ex + t[i].e), nd = max(0, d - t[i].a);
				if(dp[nex][nd] > dp[ex][d] + 1) {
					dp[nex][nd] = dp[ex][d] + 1;
					q.push({ nex, nd });
				}
			}
		}

		int ans = INF;
		for(int j = 0; j <= 100; j++) {
			ans = min(ans, dp[j][0]);
		}
		if(ans == INF) cout << "NA" << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[101],t,w;
	int l;
	gets(a);
	l=strlen(a);
	t=a[0];
	w=a[l-1];
	l=l-2;
	cout<<t<<l<<w<<endl;
	return 0;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  static const int MAX = 21;
  int N, dp[1<<MAX];
  bool as[MAX][MAX];

  void init() {
    cin >> N;
    rep(i, N) rep(j, N) {
      cin >> as[i][j];
    }
  }

  void solve() {
    int U = (1 << N) - 1;
    dp[U] = 1;
    REPCM(i, N-1, 0) {
      int S = (1 << i) - 1;
      while(S <= U) {
        rep(j, N) if(as[i][j]) if(!((S>>j)&1)) {
          dp[S] += dp[S | (1 << j)];
          dp[S] %= MOD_1_000_000_007;
        }
        if(S!=0) {
          int x = S & -S;
          int y = S + x;
          S = ((S & ~y) / x >> 1) | y;
        } else S = U+1;
      }
    }
    cout << dp[0] << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 8448
n = int(input())
t, a = map(int, input().split())
lists = list(map(int, input().split()))

tmp_lists = [(t - i*0.006) for i in lists]
diff_lists = []
for i in tmp_lists:
  diff_lists.append(a-i if (a-i) >=0 else (a-i)* -1)
copy = diff_lists.copy()
copy.sort()
index = diff_lists.index(copy[0])
print(index+1)

Measured memory_bytes: 9100
{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Coerce

gen :: Int -> [Int] -> Int -> Int -> (Int,Bool)
gen 0 [] till acc
  | acc <= till = (1,True)
  | otherwise   = (0,False)
gen n xs till acc = foldr count out cands 0
  where
    count !k cont !left = if hasMore then
                            cont (left + now)
                          else
                            (left + now, False)
      where
        (!now,hasMore) = gen (n-1) (xs \\ [k]) till (10*acc + k)
    out !left = (left, True)
    cands = if n == length xs then xs else [3,5,7]
  
cNum :: Int -> Int
cNum till = foldr count out [3,4..9] 0
  where
    count !n cont !left = if hasMore then
                            cont (left + now)
                          else
                            left + now
      where
        (!now, hasMore) = gen n [3,5,7] till 0
    out = id

main :: IO ()
main = getLine >>= print . cNum . read 


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS



    string s;
    cin >> s;

    int ans = 0;
    int ans1 = 0;

    for(int i = 0; i < s.size(); i++)
    {
      if(s[i] == 'R')ans1++;
      else
      {
        ans = max(ans,ans1);
        ans1 = 0;
      }
    }


    ans = max(ans,ans1);
    cout << ans ;


    return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 310, P = 998244353;

int n, m;
bitset<N> bas[N];
bool vis[N];

int mpow(int x, int k, int p = P) {
  int ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * (ll)x % p;
    x = x * (ll)x % p;
    k >>= 1;
  }
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &n, &m);
  int dim = 0;
  for (int i = 1; i <= n; ++i) {
    bitset<N> cur;
    for (int j = 1; j <= m; ++j) {
      int x;
      scanf("%d", &x);
      cur[j] = x;
    }
    for (int j = 1; j <= m; ++j)
      if (cur[j])
        if (!vis[j]) {
          bas[j] = cur;
          vis[j] = true;
          ++dim;
          break;
        } else
          cur ^= bas[j];
  }
  int ans = mpow(2, n + m - 1) - mpow(2, n - dim + m - 1);
  if (ans < 0)
    ans += P;
  printf("%d\n", ans);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
N = int(input())
c = [0 if s=='R' else 1 for s in input()]

l = 0
r = N - 1

ans = 0
while l < r:
    while l < N and c[l] == 0:
        l += 1
    while r > 0 and c[r] == 1:
        r -= 1
    if l < r:
        ans += 1
    l += 1
    r -= 1
print(ans)

Measured memory_bytes: 81716
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int K;
  cin >> K;

  std::queue<ll> p;
  ll answer {};
  srep(i,1,10) {
    answer = i;
    p.push(answer);
    --K;
    if (K==0) break;
  }
  if (K==0) {
    cout << answer << '\n';
    return 0;
  }
  for (;true;) {
    answer = p.front(); p.pop();
    if (answer % 10 != 0) {
      p.push(answer*10+((answer%10)-1));
      --K;
      if (K == 0) {
        answer = answer*10 +(answer%10)- 1;
        break;
      }
    }
    p.push(answer*10+(answer%10));
    --K;
    if (K==0) {
      answer = answer*10+(answer%10);
      break;
    }
    if (answer % 10 != 9) {
      p.push(answer*10+(answer%10)+1);
      --K;
      if (K == 0) {
        answer = answer*10+(answer%10)+1;
        break;
      }
    }
  }
  //for (;!p.empty();p.pop()) {
  //  cout << p.front() << ' ';
  //}
  cout << answer << '\n';
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>

using namespace std;

int main() {

    int n;
    cin>>n;
    vector<long long int> v(n);

    for (int i = 0; i < n; i++)
        cin >> v[i];

    vector<vector<pair<long long int,long long int>>> dp(n, vector<pair<long long int,long long int>>(n));

    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j += n) {
            dp[i][j] = {v[i], 0};
        }
    }

    for (int c = 1; c < n; c++) {
        for (int i = 0; i < n; i++) {
            for (int j = i + c; j < n; j += n) {

                //cout<< i<<" "<<j<<endl;
                pair<long long int,long long int> p1 = {v[i] + dp[i + 1][j].second, dp[i + 1][j].first};
                pair<long long int,long long int> p2 = {v[j] + dp[i][j - 1].second, dp[i][j - 1].first};

                if (p1.first > p2.first) { dp[i][j] = p1; }
                else dp[i][j] = p2;
            }
        }
    }

//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            cout<<'{'<<dp[i][j].first<<':'<<dp[i][j].second<<'}';
//        }
//        cout<<endl;
//    }
//
//    cout<<"ans ";

    cout<<dp[0][n-1].first-dp[0][n-1].second;


    return 0;
}


Measured memory_bytes: 141056
var
s:string;
begin
read(s);
if (s[1]=s[2])and(s[2]=s[3])and(s[3]=s[1]) then writeln('Yes')
  else if (s[4]=s[2])and(s[2]=s[3])and(s[3]=s[4]) then writeln('Yes')
                                                  else writeln('No');
end.

Measured memory_bytes: 128
#include <iostream>
#include <vector>

int main() {
	int n;
	std::cin >> n;

	if (n % 2 == 1) {
		std::cout << "No" << std::endl;
		return 0;
	}
	
	std::vector<char> vec(n / 2);
	for (auto&& c : vec)
		std::cin >> c;

	for (auto&& e : vec) {
		char c;
		std::cin >> c;

		if (c != e) {
			std::cout << "No" << std::endl;
			return 0;
		}
	}


	std::cout << "Yes" << std::endl;
}

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

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

int main() {
    string s; cin >> s;
    int ans = 0, cnt, j;
    rep(i, s.size()){
        cnt = 0;
        j = i;
        while(j < s.size()){
            if(s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') cnt++;
            else break;
            j++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
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 FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int all = 0;
    rep(i,n) all ^= a[i];
    rep(i,n) printf("%d%c", all ^ a[i], i == n-1? '\n' : ' ');
}


Measured memory_bytes: 4044
N , K =map(int,input().split())
H = []
for i in range(N):
    H.append(int(input()))
H =sorted(H)

ans = 1000000000
for j in range(N-K+1):
    ans=min(int(H[j+K-1])-int(H[j]),ans)
    

print(ans)

Measured memory_bytes: 8280
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
#define Abra_Ka_Dabra ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const long long mod = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;

string longDiv(string n, int div, int &m) {
	string res;
	int x = n[0] - '0', y = 0;
	while (x < div) {
		if (n.size() == y + 1) {
			m = x % div;
			return "0";
		} else x = x * 10 + (n[++y] - '0');
	}
	while (y < n.size()) {
		res += (x / div) + '0';
		if (y == n.size() - 1) {
			m = x % div;
			y++;
		} else x = (x % div) * 10 + n[++y] - '0';
	}
	if (res.empty()) return "0";
	return res;
}

ll mpow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 1) return (a * mpow(a, b - 1));
	else {
		ll h = mpow(a, b / 2);
		return (h * h);
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	Abra_Ka_Dabra

	int n;
	cin>>n;
	string x = "ACL";
	while(n--) cout<<x;
	cout<<"\n";

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





//————————BFS迷路の最短経路————————————————

// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};



int main() {
    int r,c;
    cin >> r >> c;

    // 盤面入力受取 
    vector<string> p(r);
    rep(i,r) {
      cin >> p[i];
    }

    // BFS のためのデータ構造
    vector<vector<int>> dist(r,vector<int>(c,-1)); // 全マスを「未訪問」に初期化
    deque<pair<int,int>> que;

    // 初期条件 ((sx,sy) を初期ノードとする)
    int sx,sy,gx,gy;
    rep(i,r){
      rep(j,c){
        if(p[i][j]=='#') {
        sx=i;
        sy=j;  
        dist[sx][sy] = 0;
        pair<int,int> q=mp(sx,sy);
        que.pb(q); // (sx,sy) を入れる
        }
      }  
    }
  
    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        pair<int,int> v = que.front(); // キューから先頭頂点を取り出す
        que.pop_front();

        //vの上下左右をすべて調べる
        rep(i,4) {
          int nh = v.fi + dx[i];
          int nw = v.se + dy[i];

          // 場外アウトしたり、移動先が壁の場合はスルー
          if (nh < 0 || nh >= r || nw < 0 || nw >= c) continue;          
          if (dist[nh][nw] != -1) continue; // すでに発見済みのマスは探索しない

          // 新たなマスについて距離情報を更新してキューに追加する
          dist[nh][nw] = dist[v.fi][v.se] + 1;
          pair<int,int> r=mp(nh,nw);
          que.pb(r);
        }
    }

    // 結果出力 (goalのstartからの距離を見る)
    int ans=0;
    rep(i,r){
      rep(j,c){
        ans=max(ans,dist[i][j]);
      }
    }
    cout << ans << endl;
}


Measured memory_bytes: 13456
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	ll N, M;
	cin >> N >> M;
	ll ans = 0;
	if (abs(N - M) > 1) {cout << 0 << endl;}
	else {
		if (M < N)swap(N, M); //N<=Mにしたい
		VI list(100005, 0);

		auto f = [](ll x) {
			ll ret = 1;
			FOR(i, 1, x) {
				ret *= i;
				ret %= MOD;
			}
			return ret ;
		};

		if (N == M) {
			ans =2*(f(M)%MOD)*(f(M)%MOD);

		}
		else ans =(f(N)%MOD)*(f(M)%MOD);

		cout<<ans%MOD<<endl;
	}
	






	return 0;
}


Measured memory_bytes: 3708
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
'''
from collections import deque
N, Q = mi()
D = li2(N-1)
px = li2(Q)
que = deque()

adj = [[] for i in range(N+1)]

for i in range(N-1):
    adj[D[i][0]].append(D[i][1])

ans = [0]*(N+1)
for j in range(Q):
    ind, a = px[j][0], px[j][1]
    que.append(ind)
    while(que!=deque()):
        v = que.popleft()
        ans[v] += a
        for e in adj[v]:
            que.append(e)


for i in range(1, N+1):
    print(ans[i], ' ', end='')
'''

from collections import deque
sys.setrecursionlimit(10**9)

#入力受け取り
N, Q = mi()
x = li2(N-1)
#p = li2(Q)

cnt = [0]*N
for i in range(Q):
    p0, p1 = mi()
    cnt[p0-1] += p1

#隣接リスト作成
adj = [[] for i in range(N)]
for i in range(N-1):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])
    adj[x[i][1]].append(x[i][0])

que = deque()
ans = [0]*N

#for a in range(N):
que.append((0, 0))
num = 0
while que!=deque():
    v = que.popleft()
    ans[v[1]] = ans[v[0]] + cnt[v[1]]
    for next in adj[v[1]]:
        if next != v[0]:
            que.append((v[1], next))

for k in ans:
    print(k, '', end='')

Measured memory_bytes: 88892
n, x = map(int, input().split())

memol = {0: 1}
memop = {0: 1}


for i in range(1, n+1):
    memol[i] = memol[i-1] * 2 + 3
    memop[i] = memop[i-1] * 2 + 1

ret = 0
ln = 0
for i in range(n, -1, -1):
    if ln >= x:
        break
    ln += 1
    if ln >= x:
        break
    if ln + memol[i-1] > x:
        continue
    ln += memol[i-1]
    ret += memop[i-1]
    if ln == x:
        break
    ln += 1
    ret += 1
    if ln + memol[i-1] > x:
        continue
    ln += memol[i-1]
    ret += memop[i-1]
    if ln == x:
        break
    ln += 1

print(ret)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<long long> l(n);
    for(long long i = 0; i < n; i++) cin >> l[i];

    sort(l.begin(), l.end(), greater<long long>());

    long long ans = 0;
    for(long long i = 0; i < k; i++) ans += l[i];

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
n=int(input())
a=list(map(int,input().split()))
flag=[[0 for j in range(n)] for i in range(n)]
dp=[[0 for j in range(n)] for i in range(n)]
ru=[0]
for i in range(n):
    ru.append(ru[-1]+a[i])
def f(l,r):
    if flag[l][r]==1:
        return dp[l][r]
    flag[l][r]=1
    if l==r:
        return 0
    fans=10**20
    for m in range(l,r):
        fans=min(fans,f(l,m)+f(m+1,r))
    dp[l][r]=fans+ru[r+1]-ru[l]
    return dp[l][r]

ans=f(0,n-1)
print(ans)

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

using namespace std;

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

typedef long long ll;

int main(){
	ll N,X;
	cin>>N>>X;
	ll ans=N;
	ll a=max(X,N-X),b=min(X,N-X);
	while(1){
		if (a%b==0){
			ans+=(a/b*2-1)*b;
			break;
		}
		ans+=(a/b*2)*b;
		ll c=b;
		b=a%b;
		a=c;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int r, g;
    cin >> r >> g;
    cout << g * 2 - r << endl;
}




Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double PI = acos(-1);

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

int main(){
    while(1){
        int p,q,r;
        cin >> p >> q >> r;
        if(p == 0) break;

        int rotnum = (r==0)? 1: q/gcd(p-q, q);
        int splitnum = 1e4;
        int n = rotnum*splitnum;
        double dt = 2*PI/splitnum;
        vector<double> arr(n);
        for(int i=0; i<n; i++){
            double t = dt *i;
            double xpt = -(p-q)*sin(t) -r*sin(t*(p-q)/q)*(p-q)/q;
            double ypt =  (p-q)*cos(t) -r*cos(t*(p-q)/q)*(p-q)/q;
            arr[i] = sqrt(xpt*xpt +ypt*ypt);
        }

        double ans = 0;
        for(int i=0; i<n; i++){
            ans += arr[i];
        }
        ans *= dt;
        cout << fixed << setprecision(3);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 84540
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        String s = scanner.next();
        String[] t = new String[q];
        String[] d = new String[q];
        for (int i = 0; i < q; ++i) {
            t[i] = scanner.next();
            d[i] = scanner.next();
        }
        // find leftDroppedMaxIndex
        int leftMaxIndex = -1;
        int index = 0;
        char current = s.charAt(0);
        for (int i = q - 1; i >= 0; --i) {
            if (d[i].equals("L") && t[i].charAt(0) == current) {
                leftMaxIndex = index;
                if (leftMaxIndex == s.length() - 1) {
                    break;
                }
                index++;
                current = s.charAt(index);
            } else if (d[i].equals("R") && index - 1 >= 0 &&
                    t[i].charAt(0) == s.charAt(index - 1)) {
                leftMaxIndex--;
                --index;
                current = s.charAt(index);
            }
        }

        // find rightDroppedMinIndex
        int rightMinIndex = s.length();
        index = s.length() - 1;
        current = s.charAt(index);
        for (int i = q - 1; i >= 0; --i) {
            if (d[i].equals("R") && t[i].charAt(0) == current) {
                rightMinIndex = index;
                if (rightMinIndex == 0) {
                    break;
                }
                --index;
                current = s.charAt(index);
            } else if (d[i].equals("L") && index + 1 < s.length() &&
                    t[i].charAt(0) == s.charAt(index + 1)) {
                rightMinIndex++;
                ++index;
                current = s.charAt(index);
            }
        }
        int leftDropped = leftMaxIndex + 1;
        int rightDropped = s.length() - rightMinIndex;
        System.out.println((n - leftDropped - rightDropped));

    }

}


Measured memory_bytes: 83152
n = int(input())
c = input()

r, w = 0, 0
for i in range(n):
    if c[i] == 'R':
        r += 1
    else:
        w += 1

ans = 0
for i in range(r):
    if c[i] == 'W':
        ans += 1

print(ans)

Measured memory_bytes: 67744
#include <stdio.h>

int main(void)
{
	int i;
	
	for (i = 0; i < 9; i++){
		char name[16];
		int an, bn;
		
		scanf("%s %d %d", name, &bn, &an);
		printf("%s %d %d\n", name, bn + an, bn * 200 + an * 300);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;


struct query{
  ll type;//0=empty, 1=add-sum ,2=set-max
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// max-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=max(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return -INF; // max
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return max(lv,rv); // max
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmax(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

int main() {
  ll n;
  cin >> n;
  vec h(n),a(n);
  for(ll i=0;i<n;i++) cin >> h[i];
  for(ll i=0;i<n;i++) cin >> a[i];
  segtree T(n+1);
  T.Set(0,n+1,0);
  for(ll i=0;i<n;i++) {
    T.Set(h[i],h[i]+1,T.Getmax(0,h[i])+a[i]);
  }
  cout << T.Getmax(0,n+1) << endl;
}

Measured memory_bytes: 19712
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();

		// int[] : { num, to }
		List<List<int[]>> tree = new ArrayList<>();
		for (int i = 0; i <= N; i++) {
			tree.add(new ArrayList<>());
		}

		for (int i = 0; i < N - 1; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			tree.get(a).add(new int[] { i, b });
			tree.get(b).add(new int[] { i, a });

		}
		sc.close();

		int root = -1;
		for (int i = 0; i <= N; i++) {
			if (tree.get(i).size() == 1) {
				root = i;
				break;
			}
		}

		int[] color = new int[N - 1];

		color[tree.get(root).get(0)[0]] = 1;

		// int[] : { node, from, usedColor }
		Queue<int[]> que = new ArrayDeque<int[]>();

		que.add(new int[] { tree.get(root).get(0)[1], root, 1 });

		while (!que.isEmpty()) {
			int[] a = que.poll();
			int node = a[0];
			int from = a[1];
			int usedColor = a[2];

			int c = 1;
			for (int[] edge : tree.get(node)) {
				if (edge[1] == from) {
					continue;
				}
				if (c == usedColor) {
					c++;
				}
				color[edge[0]] = c;

				que.add(new int[] { edge[1], node, c });

				c++;
			}

		}

		int K = max(color);
		out.println(K);
		for (int c : color) {
			out.println(c);
		}

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int max(int[] arr) {
		if (arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for (int i = 1; i < arr.length; i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}
}


Measured memory_bytes: 103820
/////////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<cstdio>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bitset>
#include<utility>
#include<map>
#include<set>
#include<array>
#include<vector>
#include<stack>
#include<queue>
#include<iomanip>
#include<random>
#include<chrono>
#include<string>
#include<bits/stdc++.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////
#define int long long
#define forinc(a,b,c) for(int a=b;a<=c;++a)
#define fordec(a,b,c) for(int a=b;a>=c;--a)
#define forv(a,b) for(auto &a:b)
#define fors(a,b) for(__typeof(b.begin()) u=b.begin();u!=b.end();u++)

#define ii pair<int,int>
#define fi first
#define se second

#define vt vector<int>
#define vpi vector<pair<int,int>>
#define pb push_back
#define reset(f,x) memset(f,x,sizeof(f))
#define all(a) a.begin(),a.end()

#define bit(x,i) (x>>(i-1)&1ll)
#define onbit(x,i) (x|(1ll<<(i-1)))
#define offbit(x,i) (x&~(1ll<<(i-1)))

using ll=long long;
using ull=unsigned long long;
using namespace std;
///////////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e6+5,mo=1e9+7;
int n,gt[N],igt[N],x,y;
int pw(int x,int i){
    int b=1;
    for(;i;i>>=1,x=x*x%mo) if(i&1) b=b*x%mo;
    return b;
}
int ckn(int n,int k){
    return gt[n]*igt[k]%mo*igt[n-k]%mo;
}
main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>x>>y;
    if((x+y)%3) return cout<<0,0;
    gt[0]=1;
    forinc(i,1,1e6) gt[i]=gt[i-1]*i%mo;
    igt[(ll)(1e6)]=pw(gt[(ll)1e6],mo-2);
    fordec(i,1e6,1) igt[i-1]=igt[i]*i%mo;
    int n=0,m=0;
    n=(2*y-x)/3;
    m=(2*x-y)/3;
    if(n<0||m<0) return cout<<0,0;
    cout<<ckn(n+m,n);
}


Measured memory_bytes: 15872
n, a, b  = map(int, input().split())

def sum_digit(x):
    y = sum(int(digit) for digit in str(x))
    return y

result = []
for i in range(n+1):   
    z = sum_digit(i)
    if(int(z)<=b and int(z)>=a):
        result.append(i)
        
print(sum(result))                

Measured memory_bytes: 3296
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int short
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b&&a >= c) {
		cout << a * 10 + b + c << endl;
	}
	else if (b >= a&&b >= c) {
		cout << b * 10 + a + c << endl;
	}
	else if (c >= a&&c >= b) {
		cout << c * 10 + b + a << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[109];
bool rsn(int h){
	bool f=0;
	for(int i=0;i<n;i++){
		if(a[i]==h){
			f=1;
		}
	}
	return f;
}
int main() {
	int x;
	cin>>x>>n;
	for(int i=0;i<n+n;i++){
		cin>>a[i];
	}
	int k=x;
	while(1){
		if(!rsn(k))break;
		k--;
	}
	int l=x;
	while(1){
		if(!rsn(l))break;
		l++;
	}
	if((x-k)<=(l-x))
	cout<<k;
	if((x-k)>(l-x))
	cout<<l;
	return 0;
}

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

ll n, m, k, mod=998244353, ans, fac[200010];

ll p(ll a, ll b) {
	if (b==0) return 1;
	ll hsl=p(a, b/2)%mod;
	hsl=(hsl*hsl)%mod;
	if (b%2==1) hsl=(hsl*a)%mod;
	return hsl;
}

ll comb(ll a, ll b) {
	ll kali=(fac[a-b]*fac[b])%mod;
	kali=p(kali, mod-2);
	return (fac[a]*kali)%mod;
}

int main() {
	cin>>n>>m>>k;
	fac[0]=1;
	fac[1]=1;
	for (int i=2; i<200010; i++) {
		fac[i]=i*fac[i-1];
		fac[i]%=mod;
	}
	for (int i=0; i<=k; i++) {
		ll add=m*comb(n-1,i);
		add%=mod;
		add*=p(m-1, n-1-i);
		add%=mod;
		ans+=add;
		ans%=mod;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 5184