akhauriyash/Code-Regression huggingface dataset:
import javax.management.monitor.CounterMonitor;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S[] = new String[N];
        int P[] = new int[N];
        for (int i = 0; i < N; i++) {
            S[i] = sc.next();
            P[i] = sc.nextInt();
        }
        ArrayList<City> c1=new ArrayList<City>();
        for(int i=0;i<N;i++)
        {
            c1.add(new City(S[i],P[i],i));
        }
        c1.sort(Comparator.comparing(City::getName).reversed().thenComparing(City::getPoint).reversed());
        for(int i=0;i<N;i++)
        {
            System.out.println(c1.get(i).number);//c1.get(i).name+" "+c1.get(i).point+" "+
        }
        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        ///System.out.println(answer);
    }
}

class City
{
    String name;
    int point;
    int number;
    public City(String x,int y,int z)
    {
        name=x;
        point=y;
        number=z+1;
    }

    String getName()
    {
        return this.name;
    }

    int getPoint()
    {
        return this.point;
    }

    void outNum()
    {
        System.out.println(number);
    }
}

Measured memory_bytes: 28372
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	typedef double d;
	#define for(i,a,b) for(int i=a;i<b;i++)
	#define f(i,a,b) for(int i=a;i<=b;i++)
    int main()
    {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int x;
    cin>>x;
    if(x<30) cout<<"No"<<"\n";
    else cout<<"Yes"<<"\n";
	}

Measured memory_bytes: 3608
package main

import "fmt"

func main() {
	var l, r int
	fmt.Scan(&l, &r)
	if 2020 <= r-l {
		fmt.Println(0)
		return
	}
	ans := 3000
	for i := l; i <= r-1; i++ {
		for j := l + 1; j <= r; j++ {
			m := i * j % 2019
			if m < ans {
				ans = m
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
use proconio::input;
use std::cmp::min;
fn main() {
    input!{
        n:usize,
        m:usize,
        x:usize,
        text:[[usize;m+1];n]
    }
    let mut ans = 1000000000;
    for bit in 0..(1<<n){
        let mut cost = 0;
        let mut skill = vec![0; m];
        for i in 0..n{
            if (bit>>i) & 1 == 0 {
                continue;
            }
            cost += text[i][0];
            for j in 0..m{
                skill[j] += text[i][j+1];
            }
        }
        let mut flag = true;
        for i in 0..m{
            if skill[i] < x{
                flag = false;
                break;
            }
        }
        if flag {
            ans = min(ans, cost);
        }
    }
    if ans == 1000000000{
        println!("{}", -1);
    }else{
        println!("{}", ans);
    }

}


Measured memory_bytes: 2192
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int diff;
    int remainder=n%1000;
    if(remainder!=0)
    {
        diff=1000-remainder;
        cout<< diff<< endl;
    }
    else
    {
       cout<< "0"<< endl;
    }
    return 0;

}


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

int main() {
    long long  n, k;
    cin >> n >> k;
    long long ans = 0;
    for (long long b = k + 1; b <= n; b++) {
        ans += (n / b) * (b - k);
        if (n % b >= k) ans += n % b - k + 1;
    }
    if (k == 0) ans = n * n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
    public static void main(String [] args) {
        FastReader fr = new FastReader();
        int N = fr.nextInt(), W = fr.nextInt();
        int [][] input = new int [N][2];
        for (int i = 0; i < N; i++) {
            input[i][0] = fr.nextInt();
            input[i][1] = fr.nextInt();
        }
        long [] dp = new long [W + 1];
        long [] prev = new long [W + 1];
        for (int i = 0; i < N; i++) {
            int w = input[i][0], v = input[i][1];
            for (int j = 1; j <= W; j++) {
                if (w <= j) {
                    dp[j] = Math.max(dp[j], prev[j - w] + v);
                }
                dp[j] = Math.max(dp[j], dp[j - 1]);
            }
            prev = dp.clone();
        }

        System.out.println(dp[W]);
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 51724
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		500005									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static char sc1Str[D_ARRAY_MAX];								// 文字列
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 改行カット
// 戻り値：文字数
int
fCutCrLf(
	char *pcpStr				// <I> 文字列
)
{
	int i;

	for (i = 0; pcpStr[i] != '\0'; i++) {
		if (pcpStr[i] == '\n') {
			pcpStr[i] = '\0';
			break;
		}
	}

	return i;
}

// 実行メイン
long long
fMain(
)
{
	int i;

	// 文字列 - 取得
	fgets(&sc1Str[1], sizeof(sc1Str) - 1, szpFpI);
	siACnt = fCutCrLf(&sc1Str[1]) + 1;
	sc1Str[0] = '>';
	sc1Str[siACnt] = '<';

	// 配列 - セット - <<
	for (i = 1; i <= siACnt; i++) {
		if (sc1Str[i - 1] == '<' && sc1Str[i] == '<') {
			si1Array[i] = si1Array[i - 1] + 1;
		}
	}

	// 配列 - セット - >>
	for (i = siACnt; i >= 1; i--) {
		if (sc1Str[i - 1] == '>' && sc1Str[i] == '>') {
			si1Array[i] = si1Array[i + 1] + 1;
		}
	}

	// 配列 - セット - <>
	for (i = 1; i <= siACnt; i++) {
		if (sc1Str[i - 1] == '<' && sc1Str[i] == '>') {
			if (si1Array[i - 1] > si1Array[i + 1]) {
				si1Array[i] = si1Array[i - 1] + 1;
			}
			else {
				si1Array[i] = si1Array[i + 1] + 1;
			}
		}
	}

	// 和 - 取得
	long long llSum = 0;
	for (i = 1; i <= siACnt; i++) {
		llSum += si1Array[i];
	}

	return llSum;
}

// １回実行
int
fOne(
)
{
	long long llRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1Array, 0, sizeof(si1Array));						// 配列

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	llRet = fMain();

	// 出力
	sprintf(lc1Buf, "%lld\n", llRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

template<typename T>
class UnionFind{
	private:
		vector<int> par, depth;
		vector<T> sum; // 集合の重みの総和
	public:
		vector<int> cnt; // その集合の頂点数
		UnionFind() {}
		UnionFind(int n, vector<T>& c){
			init(n, c);
		}
		void init(int n, vector<T>& c){
			par = vector<int>(n);
			depth = vector<int>(n, 0);
			cnt = vector<int>(n, 1);
			sum = c;
			rep(i,n){
				par[i] = i;
			}
		}
		int find(int x){
			if(par[x] == x){
				return x;
			}else {
				return par[x] = find(par[x]);
			}
		}
		void unite(int x, int y){
			x = find(x);
			y = find(y);
			if(x == y) return;

			if(depth[x] < depth[y]){
				par[x] = y;
				cnt[y] += cnt[x];
				sum[y] += sum[x];
			}else{
				par[y] = x;
				cnt[x] += cnt[y];
				sum[x] += sum[y];
				if(depth[x] == depth[y]) depth[x]++;
			}
		}
		bool same(int x, int y){
			return find(x) == find(y);
		}
		T weight(int x){
			return sum[find(x)];
		}
};

int cul(int a){
	return a * (a - 1) / 2;
}

signed main(){
	int n, m;
	cin >> n >> m;

	vector<int> a(m), b(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	vector<int> t(n, 1);
	UnionFind<int> uni(n, t);
	vector<int> ans = {cul(n)};
	for(int i = m - 1; i > 0; i--){
		if(uni.same(a[i], b[i])){
			ans.emplace_back(ans.back());
		}else{
			int tmp = cul(uni.weight(a[i])) + cul(uni.weight(b[i]));
			//cout << cul(uni.weight(a[i])) << ' ' << cul(uni.weight(b[i])) << endl;
			//rep(j,n){ cout << uni.weight(j) << ' '; } cout << endl;
			uni.unite(a[i], b[i]);
			//show(cul(uni.weight(a[i])))
			//show(ans.back())
			ans.emplace_back(ans.back() + tmp - cul(uni.weight(a[i])));
		}
	}

	reverse(all(ans));
	for(auto i : ans){
		cout << i << endl;
	}
}


Measured memory_bytes: 7668
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc085/b.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int N;
    cin >> N;
    set<int> s;
    rep(i, N){
        int d;
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << "\n";
    return 0;
}

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

typedef long long int ll;

int main() {
    int n;
    string s[100000];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];

    ll ans = 0;
    unordered_map<string, ll> um;
    for (int i = 0; i < n; i++) {
        sort(s[i].begin(), s[i].end());
        ans += um[s[i]];
        um[s[i]]++;
    }

    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    int ok = 1e7;
    int ng = 0;
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if ((long long)mid * (mid + 1) / 2 >= n) ok = mid;
        else ng = mid;
    }
    int acc = 0;
    for (int i = ok; i > 0; i--){
        if (n - acc >= i){
            cout << i << endl;
            acc += i;
        }
    }
}

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

int main() {
  char c;
  cin >> c;
  
  if ((c == 'a') || (c == 'i') || (c == 'u') || (c == 'e') || (c == 'o')) {
    cout << "vowel" << endl;
  }
  
  else {
    cout << "consonant" << endl;
  }
  
}

Measured memory_bytes: 256
//We are still young.
// A.cpp
// Created on 2019-02-16 19:54
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;

#define MAXN 100100
#define MAXE 400400

typedef pair<int, int> pii;
#define X first
#define Y second
const int INF = 0x7FFFFFFF;
#define Debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> inline void read(T &x) {
    int ch = getchar();
    bool fg = false;
    for (x = 0; !isdigit(ch); ch = getchar()) {
        if (ch == '-') {
            fg = true;
        }
    }
    for (; isdigit(ch); ch = getchar()) {
        x = x * 10 + ch - '0';
    }
    if (fg) {
        x = -x;
    }
}

int a, b, c , n;

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
#endif
	read(a), read(b);
	if(b % a == 0) cout << a + b;
	else cout << b - a;
#ifdef LOCAL
	Debug("My Time: %.3lfms", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


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

int n, L, Sol[100005], a[100005];
int main()
{
    scanf("%d%d", &n, &L);
    for(int i = 1; i <= n ; ++i)
        scanf("%d", &a[i]);
    for(int i = 1; i < n ; ++i){
        if(a[i] + a[i + 1] >= L){
            printf("Possible\n");
            for(int j = 1; j < i ; ++j)
                printf("%d\n", j);
            for(int j = n - 1; j > i ; --j)
                printf("%d\n", j);
            printf("%d", i);
            return 0;
        }
    }
    printf("Impossible");
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXN 1001024
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
//素数列挙
ll prime[MAXN] ;//segment_sieve [a,b)
bool is_prime[MAXN];
int sieve(int n){
	int res = 0;
	fill(is_prime,is_prime+MAXN,true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2;i<=n;i++){
		if(!is_prime[i])continue;
		prime[res++] = i;
		for(int j = 2*i;j<=n;j+=i)is_prime[j] = false;
	}
	return res;	
}
bool is_prime_ab[MAXN];
ll segment_sieve(ll a,ll b){
	fill(is_prime,is_prime+MAXN,true);
	fill(is_prime_ab,is_prime_ab+MAXN,true);
	for(int i=2;i*i <= b-1 ;i++){
		if(!is_prime[i]) continue;
		for(ll j = 2*i;j*j<=b-1;j+=i)is_prime[j] = false;
		for(ll j = a-a%i;j<b;j += i){
			if(j< a) continue;
			if(is_prime_ab[j-a]) is_prime_ab[j-a] = false;
		}
	}
	ll res = 0;
	for(ll i = a;i< b ;i++ )if(is_prime_ab[i-a] ) prime[res++] = i;
	return res;
}

bool is_primef(ll n){
	if(n==1) return false;
	for(ll i=2;i*i<=n;i++)
		if(n%i==0)return false;
	return true;
}

vector<ll> divisors(ll n){
	vector<ll> res;
	for(ll i=1;i*i<=n;i++){
		if(n%i != 0) continue;
		res.push_back(i);
		if(n/i== i)continue;
		res.push_back(n/i);
	}
	return res;
}
map<ll,ll> prime_factors(ll n){
	map<ll,ll> res;
	if(n<=1){
		res[n] = 1;
		return res;
	}
	
	//for(int i=2,_n = n;i*i<=_n;i++){
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			res[i]++;
			n /= i;
		}
	}
	if(n!=1)res[n] = 1;
	return res;
}

//1からnまででnと互いにそなものの数
ll euler_phi(ll n){
	ll cnt = n;
	map<ll,ll> res = prime_factors(n);
	for(auto it = res.begin(),end = res.end();it!=end;it++){
		cnt = cnt/it->first*(it->first-1);
	}
	return cnt;
}


int main(){
	ll n;
	cin>>n;
	map<ll,ll> res = prime_factors(n);
	cout<<n<<":";
	for(auto it = res.begin(),end = res.end();it!=end;it++){
		
		for(ll i = 0;i<it->second;i++){
			cout<<' '<<it->first;
		}
	}
	cout<<endl;
	return 0;
}



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

using namespace std;

typedef long long ll;

int main () {
    string s; cin>>s;

    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else if (s == "Rainy") cout << "Sunny" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N;
	while(scanf("%d", &N) == 1){
		printf("%d\n",RecurFun(N,4));
	}
	
	return 0;
}

int RecurFun(int N, int Available){
	if(Available == 1)
		return (0 <= N && N < 10)? 1 : 0 ;
	if(N < 0)
		return 0;
	
	int i;
	int Sum = 0;
	for(i = 0; i < 10; i++){
		Sum += RecurFun(N-i,Available-1);
	}
	
	return Sum;
}

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

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

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

#define INF 1e16
#define mod 1000000007

#define MAX_LOG_V 20
#define MAX_V 100010

struct edge{
  ll v,c,d;
};
struct query{
  ll idx,c,y;
  bool islca;
};

vector<edge> G[MAX_V];
vector<query> qs[MAX_V];
int root;

int V;

int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<(int)G[v].size();i++){
    if(G[v][i].v!=p)dfs(G[v][i].v,v,d+1);
  }
}

void init(){
  dfs(root,-1,0);
  for(int k=0;k+1<MAX_LOG_V;k++){
    for(int v=0;v<V;v++){
      if(parent[k][v]<0)parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
    }
  }
}

int lca(int u,int v){
  if(depth[u]>depth[v])swap(u,v);
  for(int k=0;k<MAX_LOG_V;k++){
    if((depth[v]-depth[u])>>k&1){
      v=parent[k][v];
    }
  }
  if(u==v)return u;
  for(int k=MAX_LOG_V-1;k>=0;k--){
    if(parent[k][u]!=parent[k][v]){
      u=parent[k][u];
      v=parent[k][v];
    }
  }
  return parent[0][u];
}

ll colcnt[100010],colsum[100010];
ll res[100010];

void dfs2(ll v,ll pre,ll dep){
  for(edge e : G[v]){
    if(e.v==pre)continue;
    colcnt[e.c]++;
    colsum[e.c]+=e.d;
    dfs2(e.v,v,dep+e.d);
    colcnt[e.c]--;
    colsum[e.c]-=e.d;
  }

  for(query q : qs[v]){
    if(q.islca){
      res[q.idx]-=dep*2;
      res[q.idx]+=colsum[q.c]*2;
      res[q.idx]-=colcnt[q.c]*q.y*2;
    }else{
      res[q.idx]+=dep;
      res[q.idx]-=colsum[q.c];
      res[q.idx]+=colcnt[q.c]*q.y;
    }
  }
}

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

  int Q;
  cin>>V>>Q;
  rep(i,V-1){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;b--; c--;
    G[a].push_back((edge){b,c,d});
    G[b].push_back((edge){a,c,d});
  }

  init();

  rep(i,Q){
    ll x,y,u,v;
    cin>>x>>y>>u>>v;
    x--;u--;v--;
    ll lc=lca(u,v);
    qs[u].push_back((query){i,x,y,false});
    qs[v].push_back((query){i,x,y,false});
    qs[lc].push_back((query){i,x,y,true});
  }

  dfs2(0,-1,0);

  rep(i,Q)cout<<res[i]<<endl;

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int a[2][n],sum[2][n];
  for(int i=0; i<n; ++i){cin >> a[0][i];}
  for(int i=0; i<n; ++i){cin >> a[1][i];}
  sum[0][0] = a[0][0];
  sum[1][0] = a[0][0] + a[1][0];
  for(int i=1; i<n; ++i){sum[0][i] = sum[0][i-1] + a[0][i];}
  for(int i=1; i<n; ++i){sum[1][i] = max(sum[0][i],sum[1][i-1]) + a[1][i];}
  cout << sum[1][n-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    ll x;
    cin >> x;
    ll res = (x/500) * 1000;
    x = x%500;
    res = res + (x/5) * 5;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n;
    int i;
    int a[100];
    int max = 0,mim = 1000;
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%d ",&a[i]);
        if (max < a[i]) {
            max = a[i];
        }
        if (mim > a[i]) {
            mim = a[i];
        }
    }
    printf("%d\n",max - mim );
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 200000

int d[MAX+1][20];

bool check(int l, int r){
	bool flg=true;
	for(int i=0; i<20; i++){
		if(d[r][i]-d[l-1][i]>1) flg=false;
	}
	return flg;
}

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		for(int j=0; j<20; j++){
			d[i+1][j]=d[i][j];
			if(a%2==1) d[i+1][j]++;
			a/=2;
		}
	}

	int r=1;
	ll ans=0;
	for(int l=1; l<=n; l++){
		while(r<=n && check(l, r)) r++;
		ans+=r-l;
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int S = int(1e5)+10;
const ll MOD = ll(1e9)+7;

int a[S], b[S], c[S], dp[S][3], n;


int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n;
	rep(i, 0, n) 
		cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	rep(i, 1, n) {
		dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
	}
	cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
int main(){
    int a,b; cin>>a>>b;
    if(a==b)return puts("Draw") *0;
    else if(a==1 ||b==1)cout<<(a==1 ? "Alice":"Bob")<<endl;
    else if(a>b)puts("Alice");
    else cout<<"Bob"<<endl;
}

Measured memory_bytes: 256
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE BangPatterns #-}

module Main where

import Debug.Trace
import Data.List
--import qualified Data.Set.Strict as Set
--import qualified Data.Map.Strict as Map

main :: IO ()
main = do
  [_, _, k] <- map read . words <$> getLine
  a <- map read . words <$> getLine
  b <- map read . words <$> getLine
  --a `traceShow`
  print $ solve k a b

solve :: Int -> [Int] -> [Int] -> Int
--solve k a b = s `traceShow` (maximum $ s)
solve k a b = maximum s
  where
    a' = zip (takeWhile (<= k) $ scanl (+) 0 a) [0..]
    b' = zip (takeWhile (<= k) $ scanl (+) 0 b) [0..]
    (a'', b'') = if null a' then (b', a') else (a', b')
    s = build k a'' (reverse b'')

build :: Int -> [(Int, Int)] -> [(Int, Int)] -> [Int]
build k [] _  = []
build k al [] = map snd al
--build k al@((a, ai):as) bl@((b, bi):bs) = (al, bl) `traceShow` if a + b <= k then (ai + bi) : build k as bl else build k al bs
build k al@((a, ai):as) bl@((b, bi):bs) = if a + b <= k then (ai + bi) : build k as bl else build k al bs


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

int dp[10001];

int main(void){
  int n;
  dp[0] = 1;
  for(int i = 1; i <= 10000; i++){
    dp[i] = dp[i-1] + i;
  }
  while(cin >> n){
    cout << dp[n] << endl;
  }
  return 0;
}

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

int main() {
  string A,B;
  cin>>A>>B;
  bool AA=true;
  for(int i=0; i<A.size();i++){
    if(A.at(i)!=B.at(i)) AA=false;
  }
  if(AA) cout<<"Yes";
  else cout<<"No";
}


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

int main () {
    int taro, hana = 0;
    int n;
    cin >> n;

    for (int i=0; i<n; i++) {
        string a, b;
        cin >> a >> b;
        if ( a == b ) {
            taro++;
            hana++;
        } else if ( a > b) {
            taro += 3;
        } else {
            hana += 3;
        }
    }
    cout << taro << " " << hana << endl;
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

int32_t main(){
  boost;
  int tc = 1; //cin >> tc;
  while(tc--)
  {
  	int n, k; cin >> n >> k;
  	int arr[n];
  	for(int i=0; i<n; i++)
  		cin >> arr[i];
  	sort(arr, arr+n);
  	int ans = 0;
  	for(int i=0; i<k; i++)
  		ans += arr[i];
  	cout << ans <<"\n";
  }
}



Measured memory_bytes: 3660
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		b, _ := strconv.Atoi(sc.Text())
		fmt.Println(a*b, 2*(a+b))
	}
}



Measured memory_bytes: 1088
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll H,W;
ll A[101][101];
ll AA[101][101];
ll ans=0;
P C[101][101];
int kansus(int a,int b,int c,int d){
    if(A[a][b] == 1 && A[c][d] == 0)
    {
        return 1;
    }else{
        return 0;
    }
}
int main(){
    cin >> H >> W;
    for(int i = 0;i<H;i++){
        for(int j = 0;j<W;j++){
            char a;
            cin >> a;
            if(a == '#'){
                A[i][j] = 1;
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(i==0 && j == 0){
                continue;
            }else if(i==0){
                AA[i][j] = AA[i][j-1] + kansus(i,j,i,j-1);
            }else if(j==0){
                AA[i][j] = AA[i-1][j] + kansus(i,j,i-1,j);
            }else{
                AA[i][j] = min(AA[i-1][j]+kansus(i,j,i-1,j),AA[i][j-1]+kansus(i,j,i,j-1));
            }
        }
    }
    cout << AA[H-1][W-1] + A[0][0]<< endl;
    
}




Measured memory_bytes: 384
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int coint = 1;
        int x = scan.nextInt();
        while (x != 0) {
            System.out.println("Case " + coint + ": " + x);
            x = scan.nextInt();
            coint = coint + 1;
        }
    }
}



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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0; i <= (int)S.size() - i - 1;i++) {
		if (S[i]!=S[S.size() - i - 1]) {
			ans++;
		}

	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 256
#include <cstdint>
#include <vector>

using namespace std;

static size_t total;
static vector<size_t> stotal;
static vector<pair<size_t, size_t>> spuddles;
static size_t index;

void areas_on_cross_section_diagram_init()
{
  total = 0;
  index = 0;
  stotal.clear();
  spuddles.clear();
}

void areas_on_cross_section_diagram_add(char c)
{
  if (c == '/') {
    if (!stotal.empty()) {
      size_t old_index = stotal.back();
      stotal.pop_back();
      total += index - old_index;
      size_t puddle_size = index - old_index;
      while (!spuddles.empty() && (old_index < spuddles.back().first)) {
        puddle_size += spuddles.back().second;
        spuddles.pop_back();
      }
      spuddles.push_back(make_pair(old_index, puddle_size));
    }
  } else if (c == '\\') {
    stotal.push_back(index);
  } else {
  }
  index++;
}

size_t areas_on_cross_section_diagram_total()
{
  return total;
}

void areas_on_cross_section_diagram_areas(void (*callback)(size_t))
{
  for (int32_t i = 0; i < spuddles.size(); i++) {
    callback(spuddles[i].second);
  }
}

#if !defined(TEST)
#include <iostream>
static vector<size_t> areas;

static void callback(size_t size)
{
  areas.push_back(size);
}

int32_t main()
{
  areas_on_cross_section_diagram_init();

  char c;
  while (cin >> c) {
    if (cin.eof()) break;
    areas_on_cross_section_diagram_add(c);
  }

  size_t total = areas_on_cross_section_diagram_total();

  cout << total << endl;

  areas_on_cross_section_diagram_areas(callback);

  cout << areas.size();

  if (areas.size() != 0) {
    for (uint32_t i = 0; i < areas.size(); i++) {
      cout << ' ' << areas[i];
    }
  }

  cout << endl;
  return 0;
}

#endif

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

int main()
{
  int a;
  cin >> a;
  a = a%10;
  if (a== 3)
  {
    cout << "bon" <<endl;
      
    
 
}
  else
  {
    if (a== 0 || a== 1 || a== 6  || a== 8 )
    {
      cout << "pon" << endl;
    }
    else
    {
      cout << "hon" << endl;
    }
  }
}

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

int main(){
    string s;
    string t;
    cin>>s>>t;
    if(s.size()<t.size()){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    int n=s.size();
    bool hon=false;
    int index=0;
    for(int i=0;i<=n-t.size();i++){
        bool ok=true;
        int cnt=0;
        if(s[i]=='?' || s[i]==t[0]){
            cnt+=1;
            for(int j=i;j<i+t.size();j++){
                if(s[j]!='?' && s[j]!=t[j-i]){
                    ok=false;
                    break;
                }
            }
        }
        if(cnt==0)ok=false;
        if(ok){
            hon=true;
            index=i;
        }
    }
    if(hon){
       string before=s.substr(0,index);
       int x=index+t.size();
       n-=x;
       string after=s.substr(index+t.size(),n);
       rep(h,before.size()){if(before[h]=='?')before[h]='a';}
       rep(k,after.size()){if(after[k]=='?')after[k]='a';}
       string ans=before;
       ans+=t;
       ans+=after;
       cout<<ans<<endl;
    }else cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int a,b;
		int d,r;
		double f;

		Scanner stdIn = new Scanner(System.in);

		a = stdIn.nextInt();
		b = stdIn.nextInt();

		d = a/b;
		r = a%b;
		f = (double)a/b;

		System.out.format("%d %d %5f", d, r, f);
	}

}

Measured memory_bytes: 26592
// https://atcoder.jp/contests/abc106/tasks/abc106_d
#include <bits/stdc++.h>
using namespace std;
using P = pair<double, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

template <class T> struct CumulativeSum2D {
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<T>(H + 1, 0)) {}

    void add(int x, int y, T z) {
        ++x, ++y;
        if (x >= data.size() || y >= data[0].size())
            return;
        data[x][y] += z;
    }

    void build() {
        for (int i = 1; i < data.size(); i++) {
            for (int j = 1; j < data[i].size(); j++) {
                data[i][j] +=
                    data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy) {
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

int main(void) {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    CumulativeSum2D<int> sum(N + 1, N + 1);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        sum.add(l, r, 1);
    }
    sum.build();
    vector<int> ans;
    REP(i, Q) {
        int p, q;
        cin >> p >> q;
        int t = sum.query(p, p, q + 1, q + 1);
        ans.push_back(t);
    }
    for (auto &x : ans) {
        cout << x << "\n";
    }

    return 0;
}


Measured memory_bytes: 2424
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cstdlib>
#include<cstring>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
const int maxn = 2e5 + 10;
char label[maxn];

struct edge{
	int v,next;
	edge(int v = 0,int next = 0) : v(v), next(next) {}
} e[maxn * 2];
int hd[maxn] , ek = 1;
inline void adde(int u,int v){
	e[ek] = edge(v,hd[u]);
	hd[u] = ek++;
}
int clock;
bool vis[maxn];
int dep[maxn];
bool dfs(int len,char pas,int u){
	vis[u] = 1;
	++clock;
	if(clock >= 3e7) return 0;
	for(int i = hd[u];i;i = e[i].next){
		int v = e[i].v;
		if(label[v] == pas) continue;
		if(len >= 3e5) return 1;
		if(dfs(len + 1,label[u],v)) return 1;
	}
	return 0;
}
int main(){
	memset(dep,0x3f,sizeof dep);
	dep[1] = 1;
	int n,m;
	scanf("%d%d%s",&n,&m,label + 1);
	for(int i = 1;i <= m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		adde(u,v);
		adde(v,u);
	}
	for(int i = 1;i <= n;i++)if(dfs(1,'$',i)) return !printf("Yes"); 
	return !printf("No");
} 

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

bool isBatch(string s) {
  REP(i, s.length() / 2) {
    if (s[i] != s[s.length() - i - 1]) return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  if (isBatch(s)
  && isBatch(s.substr(0, (s.length() - 1) / 2))
  && isBatch(s.substr((s.length() + 3) / 2 - 1, s.length() - (s.length() + 3) / 2 + 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

#include <unordered_map>

int n;
vector<int> primes;
void generatePrimes(int n);
unordered_map<int, int> um;

void init()
{
	cin >> n;
	generatePrimes(n);
}


int main()
{
	init();

	for (int p : primes)
	{
		int tmp = p;
		auto it = um.insert(MP(p, 0)).first;
		
		while (tmp <= n)
		{
			it->second += n / tmp;
			tmp *= p;
		}
	}

	ll ans = 1;
	for (auto it = um.begin(); it != um.end(); it++)
	{
		ans = (ans * (ll)(it->second + 1)) % MOD;
	}

	cout << ans << endl;
}


void generatePrimes(int n)
{

	const int originPrimes[10]{ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };

	for (int i{ 0 }; i < 10; i++)
	{
		if (originPrimes[i] > n)
			return;

		primes.push_back(originPrimes[i]);
	}

	bool flag{ true };

	for (int k{ 31 }; k <= n; k += 2)
	{
		if (!(k % 3))
			continue;

		flag = true;
		int limit = (int)ceil(sqrt(k)) + 1;
		int sz{ (int)primes.size() };
		for (int i{ 0 }; i < sz && primes[i] < limit; i++)
		{
			if (!(k % primes[i]))
			{
				flag = false;
				break;
			}
		}

		if (flag)
			primes.push_back(k);
	}

	flag = true;
	for (int d : primes)
	{
		if (!(n % d))
		{
			flag = false;
			break;
		}
	}

	if (flag)
		primes.push_back(n);

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
vi adj[N];
int a[N];

void input()
{
	cin >> n;
	set <int> s;
	FOR (i, 1, n) cin >> a[i], s.insert(a[i]);
	int cur = 0;
	map <int, int> mp;
	for (int i: s) mp[i] = ++cur;
	FOR (i, 1, n) a[i] = mp[a[i]];
	
	FOR (i, 1, n - 1)
	{
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
}

int tree[4*N + 19];
int meowsea (int v, int start, int end, int l, int r)
{
	if (l > end || r < start) return 0;
	
	if (l <= start && r >= end) return tree[v];
	int mid = (start + end)/2;
	return max(meowsea(2*v, start, mid, l, r), meowsea(2*v + 1, mid + 1, end, l, r));
}
 
void update (int v, int start, int end, int index, int x)
{
	if (start == end) tree[v] = x;
	else
	{
		int mid = (start + end)/2;
		if (index <= mid) update(2*v, start, mid, index, x);
		else update(2*v + 1, mid + 1, end, index, x);
		tree[v] = max(tree[2*v], tree[2*v + 1]);
	}
}

int ans[N];
void dfs (int cur = 1, int prev = 0)
{
    int x = meowsea(1, 1, n, 1, a[cur] - 1);
    ans[cur] = max(ans[prev], x + 1);
    
    int old = meowsea(1, 1, n, a[cur], a[cur]);
    update(1, 1, n, a[cur], x + 1);
    
	for (int i: adj[cur])
		if (i != prev)
			dfs(i, cur);
	
	update(1, 1, n, a[cur], old);
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	input();
	dfs();
	FOR (i, 1, n) cout << ans[i] << endl;
}
















Measured memory_bytes: 51472
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	int q;
	cin >> q;
	deque<string> dq;
	dq.push_back(s);
	bool rev = false;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1) {
			rev = !rev;
		} else {
			int f;
			char c;
			cin >> f >> c;

			if ((f == 1 && !rev) || (f == 2 && rev)) {
				dq.push_front(string(1, c));
			}
			else {
				dq.push_back(string(1, c));
			}
		}
	}

	string res;
	while (dq.size() > 0) {
		res += dq.front();
		dq.pop_front();
	}
	if (rev) {
		reverse(res.begin(), res.end());
	}
	cout << res << endl;

}









Measured memory_bytes: 12132
a, b = input().split()
is_a_true = a == 'H'
if is_a_true and b == 'H':
    print('H')
elif is_a_true and b == 'D':
    print('D')
elif not is_a_true and b == 'H':
    print('D')
elif not is_a_true and b == 'D':
    print('H')

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll x,y,z;

int main(){
	cin >> x >> y >> z;
	cout << x/(y+z)-(x%(y+z) < z) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e2+5, M = 5e5+5, OO = 0x3f3f3f3f;
typedef long long ll;
#define PI 3.14159265358979323846
#define MOD 1000000007
int main()
{
    string s,t; cin>>s>>t;
    cout<<t<<s;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int x,n; cin >> x >> n;
	set<int> s;
	while(n--){
		int a; cin >> a;
		s.insert(a);
	}
	for(int i=0;;i++){
		if(s.find(x-i)==s.end()){
			cout << x-i << endl;
			break;
		}
		if(s.find(x+i)==s.end()){
			cout << x+i << endl;
			break;
		}
	}
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;
int main() {

	int n, m;
	cin >> n >> m;

	cout << ((n - 1) * (m - 1)) << endl;
	

	return 0;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = N;
  int num = 0;
  rep(i, 1, N){
    if(S[i] == 'E') num++;
  }
  ans = min(ans, num);

  rep(i, 1, N){
    if(S[i - 1] == 'W') num++;
    if(S[i] == 'E') num--;
    ans = min(ans, num);
  }

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


Measured memory_bytes: 900
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <stack>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
const int N=1e5;
lld dp[N+5];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout << dp[n-1];
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	double n,k;
	std::cin >> n >> k;
	// 2^mother2 >= k
    int mother2 = 0, tmp = 1;
    while (tmp < k) { mother2++; tmp *= 2; }

	double children = 0.0;
	for (int i = 1; i <= n; i++) {
        int child = 0, tmp = i;
        while (tmp < k) { child++; tmp *= 2; }

		// std::cout << "i,child:" << i << "," << child << '\n';
		children += pow(2, mother2-child);
	}

	double ans = children / pow(2,mother2) / n;

	std::cout << fixed << std::setprecision(12) << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(i==0||i==h-1||j==0||j==w-1)
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}



Measured memory_bytes: 3112