akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
   
using namespace std;
   
string str[2];
int s, n, t, m, lt, rt, t_w, t_t;
long double p;
   
int conv(string s){
  string data[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};  
  for(int i=0;i<7;i++) if(s == data[i]) return i;
  if(s == "All") return -1;
}
   
bool check(int s_w, int s_t, int f_w, int f_t){
  if(!(t_w == -1 || (t_w == s_w && t_w == f_w))) return false;
  if(t_t == 0){
    if(0 <= s_t && s_t < 24 * 60 && 0 <= f_t && f_t < 24 * 60) return true;
  }
  if(t_t == 1){
    if(6 * 60 <= s_t && s_t < 18 * 60 && 6 * 60 <= f_t && f_t < 18 * 60) return true;
  }
  if(t_t == 2){
    if(((18 * 60 <= s_t && s_t < 24 * 60) || (0 <= s_t && s_t < 6 * 60))
       && ((18 * 60 <= f_t && f_t < 24 * 60) || (0 <= f_t && f_t < 6 * 60))) return true;
  }
  return false;
}
   
main(){
  while(cin >> s >> n >> t >> str[0] >> str[1] >> p >> m && (s|n|t|m) && str[0] != "None" && str[1] != "None"){
    t_w = conv(str[0]);
    if(str[1] == "All") t_t = 0;
    if(str[1] == "Day") t_t = 1;
    if(str[1] == "Night") t_t = 2;
    long double ans = 0.0;
    for(int i=0;i<7;i++){
      for(int j=0;j<24*60;j++){
        int s_w = i;
        int s_t = j;
        long double cnt = 0.0;
        for(int k=0;k<m;k++){
          int f_w = s_w;
          int f_t = s_t + s;
          if(f_t >= 24 * 60){
            f_t -= 24 * 60;
            f_w = (f_w + 1) % 7;
          }
          if(check(s_w, s_t, f_w, f_t)) cnt++;
          s_t += t;
          if(s_t >= 24 * 60){
            s_t -= 24 * 60;
            s_w = (s_w + 1) % 7;
          }
        }
        ans = max(ans, 1.0 - pow((p - 1.0) / p, n * cnt));
      }
    }
    cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;
  }
}

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

int main(){
	int n; cin>>n;
	vector<int> A(n);
	for(int i=0; i<n; i++) cin>>A[i];
	int cnt{};
   bool flag = 1; // 逆の隣接要素が存在する
   while (flag){
   	
     flag = 0;
     for (int j = n-1; j>=1; j--){
       if (A[j] < A[j-1]){
         swap(A[j] , A[j-1]);
         cnt ++;
         flag = 1;
        }
    }
	}
	for(int i=0; i<n; i++) cout << A.at(i) <<(i<n-1?' ':'\n');
	cout << cnt << endl;
}



Measured memory_bytes: 3104
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        P: [u32; n],
    }
    let mut min = u32::max_value();
    let mut ans = 0;
    for (i, &p) in P.iter().enumerate() {
        if p < min {
            min = p;
        }
        if min == p {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
 
int main()
{
	string s;
	cin>>s;
	
	int month=0;
	month = 10*(s[5]-'0') + (s[6]-'0');
	if(month > 4)
		cout<<"TBD\n";
	else
		cout<<"Heisei\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<cstdlib>
#include<unordered_map>
#include<algorithm>
 
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
		
#define ii pair	<long long ,long long >
#define i64ii pair< long long, pair<int,int> >
#define i64i pair<long long , int >
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >	
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>
 
#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;
 
 
typedef long long ll;	
typedef vector< int> vi;
typedef long double ld;
 
const int MAX = 800;
const int maxn = 2e5+100;


int p[maxn];

void f(int n ,int e){
	p[1] = 1;
	p[0] = 1;
	for(ll i = 2;i <= n;i++){
		for(ll j = i*i; j<=n;j+=i)
			p[j] = 1;
		if (!p[i])
			if ( i >= e ){
				cout << i << '\n';
				return;
			}
	}
	return ;
}

int main (){
	//~ in
	int n ;
	cin >> n;
	
	f(1e5+10, n);
	
 
	return 0;
}




Measured memory_bytes: 640
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	s := nextString()
	x := strings.Repeat("x", len(s))
	fmt.Println(x)
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int a,b,c,count;
  while(1){
    if(scanf("%d%d",&a,&b)==EOF)break;
    count=0;
    c=a+b;
    while(c!=0){
      c=c/10;
  
	count++;
    } 
    printf("%d\n",count);
  }  
  return 0;
}

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

int main(){
  int n;
  int table[200]={0};
  int table_odd[200]={0};
  int dp1[1000000]={0};
  int dp2[1000000]={0};
  for(int i=0,c=0;i<200;i++){
    table[i]=(i+1)*(i+2)*(i+3)/6;
    if(table[i]%2==1){
      table_odd[c++]=table[i];
    }
  }
  for(int i=0;i<1000000;i++){
    int min1=1<<30;
    int min2=1<<30;
    for(int j=0;j<200;j++){
      if(table[j]!=0 && i>=table[j]){
	min1=min(min1,dp1[i-table[j]]+1);
      }
      if(table_odd[j]!=0 && i>=table_odd[j]){
	min2=min(min2,dp2[i-table_odd[j]]+1);
      }
    }
    if(min1 == 1<<30) min1 = 0;
    if(min2 == 1<<30) min2 = 0;

    dp1[i]=min1;
    dp2[i]=min2;
  }
  while(cin>>n,n){
    cout<<dp1[n]<<' '<<dp2[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 8980
#include <iostream>
#include <set>

int main() {
  int AB;
  int BC;
  int CA;

  std::cin >> AB >> BC >> CA;
  std::multiset<int> mst{AB, BC, CA};

  int tmp = 1;
  int count = 0;

  for (auto i : mst) {
    if (count < 2) {
      tmp *= i;
      count += 1;
    }
  }
  std::cout << tmp / 2 << std::endl;
  return 0;
}

Measured memory_bytes: 256
/// Template by Zayed ///

/// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>

#include <string>
#include <cstring>
#include <sstream>

//#include <tuple>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
//#include<unordered_map>
#include <set>
//#include<unordered_set>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>

using namespace std;
int caseno = 1;

#define NL '\n'
#define SF scanf
#define PF printf
#define PC() printf("Case %d: ", caseno++)//NOTES:printf
//#define PC cout << "Case "//NOTES:cout
//#define CN cout << caseno++ << ": "//NOTES:cout
#define CLR(ar) memset(ar, 0, sizeof(ar))
#define SET(ar) memset(ar, -1, sizeof(ar))
#define READ() freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST std::ios_base::sync_with_stdio(0);

typedef long long LL;//NOTES:"%lld"
typedef unsigned long long ULL;//NOTES:"%llu"

#define INF (1 << 31) - 1
#define MOD 1000000007
#define PRIME 999998727899999 			// (largest prime below 10^16)
#define PB push_back
#define pii pair<int, int>
#define pic pair<int, char>
#define pci pair<char, int>
#define pLL pair<LL, LL>
#define pis pair<int, string>
#define psi pair<string, int>
#define pss pair<string, string>
//#define tiii tuple<int, int, int>
#define PI 2 * acos(0.0)
#define EPS 1e-11


// Numeric Functions
template < class T > inline void SWAP(T &a, T &b) { T t = a; a = b; b = t; }
inline LL POW(LL base, LL power){
	LL res = base; if (power == 0) return 1;
	for (int I = 0; I < power - 1; I++) res *= base; return res;
}


// Translator Functions
int ToInt(string s) { int r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToInt(
double ToDouble(string s) { double r = 0; istringstream sin(s); sin >> r; return r; }//NOTES:ToDouble(
string ToString(int n) { string s; stringstream convert; convert << n; s = convert.str(); return s; }//NOTES:ToString(


/*
*******4 Direction Array*******
int dx[] = {0, 0, - 1, 1}, dy[] = {-1, 1, 0, 0};
*******8 Direction Array*******
int dx[] = {0, 0, -1, +1, -1, -1, +1, +1}, dy[] = {-1, +1, 0, 0, -1, +1, -1, +1};
********Knight Moves********
int dx[] = {-2, -2, -1, -1, +1, +1, +2, +2}, dy[] = {-1, +1, -2, +2, -2, +2, -1, +1};
*/


const int SIZE = 2000 + 10;




int main()
{
	BOOST
	///READ();
	///WRITE();
	LL T, I, J, K, N, n, m, k, cnt = 0, len, Y, a, b, c;

	cin >> N >> Y;

	c = 0;
	for(a = 0; a <= N; a++)
	{
		for(b = 0; b <= N; b++)
		{
			c = 0;
			m = Y - (a * 10000 + b * 5000);

			if(m >= 1000 && (m % 1000 == 0))
			{
				c = m / 1000;
				m -= (c * 1000);
			}


			if(m == 0 && a + b + c == N)
			{
				cout << a << ' ' << b << ' ' << c << NL;
				return 0;
			}

		}

	}

	cout << -1 << ' ' << -1 << ' ' << -1 << NL;


	return 0;
}






Measured memory_bytes: 256
#include <vector>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <iostream>
//using namespace std;
 
template <typename T> class Segment_Tree {
private:
    int n; // n = ????´???° ???2*n-1 = ????????°
    std::vector<T> SegTree;
 
public:
    Segment_Tree(int n_) {
	n = 1;
	while( n < n_ )  n *= 2;
	SegTree = std::vector<T>(2*n-1, INT_MAX);
    }
     
    void update(int k, T a) {
	k += n - 1; // ??????index
	SegTree[k] = a; // k?????????????´???? a ?????´??°
	while( k > 0 ) { // ????????§?????????????????´??°
	    k = (k-1) / 2;
	    SegTree[k] = std::min(SegTree[2*k+1],SegTree[2*k+2]); // ??????:2*k+1?????????:2k+2
	}
    }
 
    T range_query(int a, int b) { // [a,b)????§£
	return query(a,b,0,0,n);
    }
 
    // [a,b)??????????±???????
    // k:?????????index???l,r:??????k????????????????????????[l,r)
    // ?????£?????????????????????????????¨?????? query(a,b,0,0,n) ??¨??????
    T query(int a, int b, int k, int l, int r) {
	if( r <= a or  b <= l ) return INT_MAX;    // ?????????????????§??????
	if( a <= l and r <= b ) return SegTree[k]; // [a,b)???[l,r)????????¨???????????????????????´???
 
	T vl = query(a,b,k*2+1,l,(l+r)/2);
	T vr = query(a,b,k*2+2,(l+r)/2,r);
	return std::min(vl,vr);
    }
 
    void dump() { // ??¨?????¨???
	std::cout << "-------------------------Tree------------------------" << std::endl;
	for(int i=1; i<2*n; i*=2) {
	    for(int j=0; j<i; j++ ) {
		std::cout << std::setw(2) << SegTree[i+j-1];
		for(int w=0; w<(2*(n-1)/i); w++) std::cout << "  ";
	    }
	    std::cout << std::endl;
	}
	std::cout << "-----------------------------------------------------" << std::endl;
    }
};
 
 
 
int main() {

    int n,q;
    std::cin >> n >> q;
    Segment_Tree<long long > seg(n);

    for(int i=0; i<q; i++) {
	int c,x,y;
	std::cin >> c >> x >> y;
	if(c==0)
	    seg.update(x,y);
	else
	    std::cout << seg.range_query(x,y+1) << std::endl;

    }
    

    /*
    Segment_Tree<long long > seg(10);
    for(int i=0; i<10; i++)
	seg.update(i,i+1);
    seg.dump();
    for(int i=0; i<10; i++)
	std::cout << seg.range_query(0,i+1) << std::endl;
    */
}

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

using namespace std;
bool c(string s,char t){
	int n = (int)s.length();
	for(int i=0;i<n;++i){
		if(s[i]!=t){
			return false;
		}
	}
	return true;
}
int d(string s,char t){
	int cnt = 0;
	int n = (int)s.length();
	while(!c(s,t)){
		cnt++;
		if(n-cnt == 0){
			continue;
		}
		string s_(n-cnt,'a');
		for(int i=0;i<n-cnt;++i){
			
			if(s[i]==t || s[i+1]==t){
				s_[i]=t;
			}else{
				s_[i] = s[i];
			}
		}
		s = s_;
		if(cnt>100)break;
	}
	
	return cnt;
}
int main()
{
	string s;
	cin >> s;
	int n = (int)s.length();
	int chrs[30] = {};
	for(int i=0;i<n;++i){
		chrs[s[i]-97]+=1;
	}
	int cnt = n /2;
	int max_chr = 0;
	for(int i=0;i<28;++i){
		max_chr = max(max_chr,chrs[i]);
	}
	if(max_chr == n){
		cout << 0;
		return 0;
	}else if(max_chr == 1){
		cout <<  cnt;
		return 0;
	}
	for(int i=0;i<28;++i){
		if(chrs[i]>0){
			cnt =min(d(s,i+97),cnt);
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
from statistics import median


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    min_median = median(A)
    max_median = median(B)
    if N % 2 == 1:
        print(max_median - min_median + 1)
    else:
        print(round((max_median-min_median)*2)+1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 28900
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define tc int t;cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff(i,a,b) for(i=a;i<b;i++)
#define fb(i,b,a) for(i=b;i>a;i--)
#define ffi(i,a,b,c) for(i=a;i<b;i+=c)
#define fbi(i,b,a,c) for(i=b;i>a;i-=c)
#define clin(s) getline(cin,s)
#define MOD 1e9+7
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ub upper_bound
#define lb lower_bound
int visited[200001];
int arr[200001];
bool found=false;
int linearexp(int i,ull k){

}
int explore(int i,int steps, ull k){
	if(k==0){
		return i+1;
	}
	if(visited[i]){
		if(!found){
			found=true;
			int clen=steps-visited[i];
			k=k%clen;
			if(k==0)return i+1;
		}
		return explore(arr[i]-1, 0, k-1);//steps do not matter
	}
	//cout<<i+1<<"-->";
	visited[i]=steps;
	return explore(arr[i]-1,steps+1,k-1);
}
int main() {
	fio;
	int n,i;
	ull k;
	cin>>n>>k;
	ff(i,0,n){cin>>arr[i];}
	cout<<explore(0,1,k);
	return 0;
}


Measured memory_bytes: 5252
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


ll dp1[100][4];
ll dp2[100][4];

int ctoi(char c){
	return c - '0';
}

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

	dp1[0][1] = 1;
	dp2[0][0] = 1;
	dp2[0][1] = ctoi(s[0])-1;

	for (int i = 1; i < s.length(); i++){
		for (int j = 0; j <= 3; j++){
			if (ctoi(s[i]) == 0){
				dp1[i][j] += dp1[i-1][j];
				dp2[i][j] += dp2[i-1][j];
				if (j != 0){
					dp2[i][j] += dp2[i-1][j-1]*9;
				}
			}else{
				if (j != 0){
					dp1[i][j] += dp1[i-1][j-1];
					dp2[i][j] += dp1[i-1][j-1]*(ctoi(s[i])-1);
					dp2[i][j] += dp2[i-1][j-1]*9;
				}
				dp2[i][j] += dp2[i-1][j];
				dp2[i][j] += dp1[i-1][j];
			}
		}
	}
	cout << dp1[s.length()-1][k] + dp2[s.length()-1][k] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define GO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
const int N = 3e4 + 5;
const int M = 1e6 + 5;
const int Mod = 1e9 + 7;


int main()
{
	//GO;
	string s;
	cin >> s;
	for (auto i : s)
		if (i == '7')
			return cout << "Yes\n", 0;
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
int n;
int a[114];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	reverse(a, a + n);
	rep(i, n) {
		if (i == n - 1)cout << a[i] << endl;
		else cout << a[i] << " ";
	}
	ggr
}



Measured memory_bytes: 3088
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<int> s;
	while(n--)
	{
		int x;
		cin >> x;
		auto i = lower_bound(s.begin(), s.end(), -x+1);
		if (i == s.end()) s.push_back(-x);
		else *i = -x;
	}
	cout << s.size() << '\n';
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n, greater<int>());
  int c = 0, d = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) c += a[i];
    else d += a[i];
  }
  cout << c - d << endl;
  return 0;
}


Measured memory_bytes: 256
import math


def solve(N, ABs):
    count = 0
    for (a, b) in reversed(ABs):
        k = (a + count)
        n = b * math.ceil(k / b)
        count += n - k
    return count

if __name__ == "__main__":
    N = int(input())
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, ABs))


Measured memory_bytes: 16628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;

int main(){

    int f;
    cin >> f;
    cout << (f - 30) / 2 << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------


bool dp[11][11][11];
//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    string S; cin>>S;

    dp[0][0][0]=true;
    rep(i,N){
        int c=S[i]-'0';
        if(c==0) c=10;

        repr(j,10,0){
            repr(k,10,0){
                repr(l,10,0){
                    if(dp[j][k][l]==0) continue; 
                    if(j==0 and k==0 and l==0){
                        dp[c][k][l]=true;
                    }
                    else if(j!=0 and k==0 and l==0){
                        dp[j][c][l]=true;
                    }
                    else if(j!=0 and k!=0 and l==0){
                        dp[j][k][c]=true;
                    }
                }
            }
        }
    }

    int ct=0;

    reps(i,1,11){
        reps(j,1,11){
            reps(k,1,11){
                ct+=dp[i][j][k];
                //if(dp[i][j][k]) cout<< i <<" "<< j <<" "<< k<<"\n";
            }
        }
    }
    cout<< ct<<"\n";


}   
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 384
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#include <climits> //max & min

#define int long long
#define pb(n) push_back(n)
#define For(n,i) for(int i=0;i<n;i++)
#define ForI(n) for(int i=0;i<n;i++)
#define ForJ(n) for(int j=0;j<n;j++)
#define ForK(n) for(int k=0;k<n;k++)
#define Pr(n) cout<<n<<endl;
#define INS(v,n) for(int i=0;i<n;i++){cin >>v.at(i);}//vector 代入
#define ELM 100001 //問題によっては1000000001に変更
using namespace std;

//int Move(vector<int> v,int n){
//    int m[ELM] ={0};
//    for(int i=0; i<n; i++){
//        m[v[i]]++;
//    }
//    vector<int> s;
//    for (int i=0; i<n; i++) {
//        if (m[v[i]]!=0) {
//            cout<<m[v[i]]<<endl;
//            s.pb(m[v[i]]);
//        }
//    }
//    int move = *max_element(s.begin(), s.end());
//    return move;
//}
signed  main(){
////    ABC124-a
////    int A,B;
////    cin >> A>>B;
////    int ans = 0;
////    sample(2){
////        if(A>B){
////            ans+=A;
////            A--;
////        }else{
////            ans+=B;
////            B--;
////        }
////    }
////    cout<<ans<<endl;
//
////    ABC124-b
//    int ans = 0;
//    int N;
//    cin >> N;
//    vector<int> h(N);
//    INS(h, N);
//    ForI(N){
//        int flag=0;
//        ForJ(N){
//            if (h[i]<h[j]) {
//                flag=1;
//            }
//            if(j>=i){
//                break;
//            }
//        }
//        if(flag==0){
//            ans++;
//        }
//    }
//    Pr(ans);
    
//    ABC124-c
//    string s;
//    cin >> s;
//    int ans[2]={0}; // ans[0] =10101… ans[1]=01010…
//    ForI(s.size()){
//        if (i%2==0) {//ans[0]==1 ans[1]==0
//            if (s[i]=='0'){
//                ans[0]++;
//            }else{
//                ans[1]++;
//            }
//        }else{
//            if (s[i]=='1'){
//                ans[0]++;
//            }else{
//                ans[1]++;
//            }
//        }
//    }
//    Pr(min(ans[0], ans[1]))
    
//    abc076-a
    int r,g;
    cin >>r>>g;
    Pr(2*g-r)
    
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	string s;
	cin>>n>>s;
	if(n&1){
		cout<<"No"<<endl;
	}else{
		for(int i = 0; i < n/2; i++){
			if(s[i] != s[n/2 + i]){
				cout<<"No"<<endl;
				exit(0);
			}
		}
		cout<<"Yes"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n * 2);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i + n] = a[i];
    }
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        ans += a[i];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6356
#include <iostream>

using namespace std;

#define N 1000000007

long int n, m, k;

long int divide(long int a, long int b) {
    long int z1, z2, x_tmp, y_tmp, z_tmp, r;
    long int x1 = 1;
    long int y1 = 0;
    long int x2 = 0;
    long int y2 = 1;
    while (true) {
        z1 = N*x1+b*y1;
        z2 = N*x2+b*y2;
        if (z2 == 1) {
            long int retval = a*y2;
            if (retval < 0) {
                retval += N*(-retval/N+1);
            }
            return retval%N;
        }
        r = z1/z2;
        x_tmp = x1-r*x2;
        y_tmp = y1-r*y2;
        z_tmp = z1-r*z2;
        x1 = x2;
        y1 = y2;
        z1 = z2;
        x2 = x_tmp;
        y2 = y_tmp;
        z2 = z_tmp;
    }
}

long int a0() {
    long int x_last[] = {n+k, k, m};
    long int a = (m+1)*(n+1)%N;
    for (int x=1; x<=m+n+2*k; x++) {
        a = a*x%N;
    }
    for (int i=0; i<3; i++) {
        for (int x=1; x<=x_last[i]; x++) {
            a = divide(a, x);
        }
    }
    a = divide(a, (m+1)*(n+k+1));
    return a;
}

void next_a(long int &ai, int i) {
    ai = ai*(k-i)*(n+k-i+1)%N;
    ai = divide(ai, (i+1)*(m+i+2));
}

int main() {
    long int a;
    long int count = 0;

    cin >> n >> m >> k;
    a = a0();
    for (int i=0; i<k; i++) {
        count += a;
        next_a(a, i);
    }
    count += a;
    cout << count%N << endl;

    return 0;
}

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

int main() {
  int n,k;
  string s;
  cin>>n>>k>>s;
  int in=0,happy=0;
  rep(i,n) {
    if (s[i]=='R') {
      if (i==n-1) continue;
      if (s[i+1]=='R') happy++;
      else in++;
    }
    else {
      if (i==0) continue;
      if (s[i-1]=='L') happy++;
      else in++;
    }
  }
  cout<<min(happy+2*k,n-1)<<endl;
  
  return 0;
}

Measured memory_bytes: 512
// G.cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
const int MX_N = 1e5 + 200;
int n, m, head[MX_N], m_current, tmpx, tmpy, deg[MX_N], ans, dp[MX_N];
struct edge
{
    int to, nxt;
} edges[MX_N];
void addpath(int src, int dst)
{
    edges[m_current].to = dst, edges[m_current].nxt = head[src];
    head[src] = m_current++;
}
void dfs(int u)
{
    dp[u] = 0;
    for (int i = head[u]; i != -1; i = edges[i].nxt)
    {
        if (dp[edges[i].to] == -1)
            dfs(edges[i].to);
        dp[u] = max(dp[u], dp[edges[i].to] + 1);
    }
    ans = max(dp[u], ans);
}
int main()
{
    memset(head, -1, sizeof(head)), memset(dp, -1, sizeof(dp));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++)
        scanf("%d%d", &tmpx, &tmpy), addpath(tmpx, tmpy), deg[tmpy]++;
    for (int i = 1; i <= n; i++)
        if (deg[i] == 0)
            dfs(i);
    printf("%d", ans);
    return 0;
}

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

ll N;

ll getdigit(ll num) {
    ll ans = 0;
    while(num) {
        num/=10;
        ans++;
    }
    return ans;
}

int main() {
    cin >> N;
    ll ans = getdigit(N);
    for (ll i = 1; i*i <= N; i++) {
        if (N%i != 0) continue;
        ll temp = N/i;
        ll cur = max(temp, i);
        ans = min(ans, getdigit(cur));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>

using namespace std;

int main(void){

    int N,M,C;
    cin>>N;
    cin>>M;
    cin>>C;

    vector<vector<int>> A;
    vector<int> B;
    A.resize(N);
    for(int i=0;i<N;i++){
        A[i].resize(M);
    }
    B.resize(M);

    for(int i=0;i<M;i++){
        cin>>B[i];
    }
    for(int i=0;i<N;i++){
        for(int k=0;k<M;k++){
            cin>>A[i][k];
        }
    }

    int ans=0;
    for(int i=0;i<N;i++){
        int sum=C;
        for(int k=0;k<M;k++){
            sum+=A[i][k]*B[k];
        }

        if(sum>0){ans++;}
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    vector<int> a(N);
    map<int,int> mp;
    rep(i,N){
        cin >> a[i];
        mp[a[i]]++;
    }
    int res = 0;
    rep(i,N){
        if(mp[a[i]]>=a[i]){
            res+=mp[a[i]]-a[i];
            mp[a[i]]=a[i];
        }else{
            res+=mp[a[i]];
            mp[a[i]]=0;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5120
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()

for i in range(1, 120):
	for j in range(-120, 119):
		if i**5 - j**5 == X:
			print(i, j)
			exit()

Measured memory_bytes: 9984
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,k;

int main(){
	cin>>n>>k;
	int res=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		res+=min(x,k-x);
	}
	cout<<2*res<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
struct edge {int to,cost;};
#define VMAX 51
//typedef std::pair<int,int> P;

    ll N,K;
    ll A[200000+10];
    ll F[200000+10];
    ll C;
    ll ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>K;
    REP(i,N){
        cin>>A[i];
        if(F[A[i]-1]==0)C++;
        F[A[i]-1]++;
    }
    sort(F,F+N);
    DEB(C)
    ll Q=C-K;
    if(Q<=0){
        cout<<0;
        return 0;
    }
    REP(i,N){
        if(F[i]!=0){
            ans+=F[i];
            Q--;
        }

        if(Q==0)break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
//#include<bits/extc++.h> inavilable in dev-cpp
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
#define me(i,k) memset(i,k,sizeof(i))
#define fr1(a,n) for(int a=1;a<=(n);a++)
#define frab(i,a,b) for(int i=(a);i<(b);i++)
#define fr0(i,n) for(int i=0;i<(n);i++)
#define trav(a,n) for(auto& a : n)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
const ll modn=1000000007;

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[1]<<c[2]<<'\n';
	return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
#define ull_cin(X) scanf("%llu", &X)
#define lf_cin(X) scanf("%lf", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)

#define  ll_cout(X) printf("%lld\n",X)
#define  ull_cout(X) printf("%llu\n",X)



typedef long long  ll;
typedef unsigned long long  ull;

#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion



int main(void)
{
	ll      a,b,n;

	ll_cin(a);	ll_cin(b); ll_cin(n);

	n = (n >= b) ? b - 1 : n;
	ll_cout((ll)floor(a * n / b) - a * (ll)floor(n / b));
		
	return 0;
}

//#define _N 1000000000

//int main(void)
//{
//
//	int  n,i;
//	ull   tmp=1;
//
//	i_cin(n);
//
//	for (i = 1; i <= n; i++) {
//		if (!(tmp % ((ull)_N + 7)))
//			tmp = 1;
//		tmp *= (ull)i;
//	}
//	tmp %= ((ull)_N + 7);
//		
//	ull_cout(tmp);
//	return 0;
//}



Measured memory_bytes: 1712
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


# def fib_bad(n):
#     if not n or n == 1:
#         return 1
#     return fib_bad(n - 2) + fib_bad(n - 1)


def fib_dp(n):
    fib_list[:1] = [1, 1]
    for i in range(2, n + 1):
        fib_list[i] = fib_list[i - 2] + fib_list[i - 1]
    return fib_list[n]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    index = int(_input[0])
    fib_list = [None] * index
    print(fib_dp(index))

Measured memory_bytes: 7688
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
N, Q = [int(i) for i in input().split()]
tree = {i:[] for i in range(1,N+1)}
cost_ls = {i:0 for i in range(1,N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

def plus(node, _from):
    #cost_ls[node] += num
    for child in tree[node]:
        if child == _from:
            continue
        cost_ls[child] += cost_ls[node]
        plus(child, node)

for _ in range(Q):
    p, x = map(int, input().split())
    cost_ls[p] += x

plus(1, 0)

print(' '.join(str(cost_ls[i]) for i in range(1,N+1)))

Measured memory_bytes: 267752
#include <iostream>
#include <vector>
#include <deque>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    std::vector<int> done(n);
    int ret = 0;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int c = 0;
        std::deque<int> q { i };
        done[i] = 1;
        while (!q.empty()) {
            const int v = q.front();
            q.pop_front();
            c++;
            for (const int to : g[v]) {
                if (!done[to]) {
                    done[to] = 1;
                    q.push_back(to);
                }
            }
        }
        if (c > ret) ret = c;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 15704
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		for (int i = 0; i < 2; i++) {
			if (a >= b && a > 0) {
				sum += a--;
			} else {
				sum += b--;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 23632
#include<stdio.h>

int main(void)
{
	int a, b,x,y;
	int i;
	char s[4], t[20];
	scanf("%d %d", &x, &y);

	for(int i=0;i<=x;i++)
		if (i * 4 + (x - i) * 2 == y) {
			printf("Yes");
			return 0;
		}


	printf("No");

	return 0;
}

Measured memory_bytes: 1732
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int stk = 0;
		int cnt = 0;
		int left = 0;
		int right = 0;
		for(int i=0;i<N;i++){
			if(S[i] == '('){
				left++;
				stk++;
			}
			if(S[i] == ')'){
				stk--;
				right++;
				if(stk < 0) { cnt++; stk = 0;}
			}
		
		}
		
		List<char> L = new List<char>();
		for(int i=0;i<cnt;i++) L.Add('(');
		for(int i=0;i<N;i++) L.Add(S[i]);
		for(int i=0;i<left+cnt-right;i++) L.Add(')');
		Console.WriteLine(new String(L.ToArray()));
		
		
	}
	int N;
	String S;
	public Sol(){
		N = ri();
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

using namespace std;

typedef long long ll;

string s, t;

int main() {
	cin >> s >> t;
	
	ll i = 0, j = 0;
	ll cnt = 0, mmax = -1;
	
	for (; i < s.size();) {
		if (s[i] == t[j]) {
			cnt++;
		}
		
		i++, j++;
		
		if (j >= t.size()) {
			j = 0;
			i = i - t.size() + 1;
			
			mmax = max(mmax, cnt);
			
			cnt = 0;
		}
	}
	
	cout << t.size() - mmax << endl;
	
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i< (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
bool p[201]={};
int ans=0;
int k=(30<<1);
int main(){
	int x,n;
	cin>>x>>n;
	rep(i,n){
		int a; cin>>a;
		p[a]=true;
	}
	rep(i,102){
		if(!p[i]){
			//cout<<i<<endl;
			if(k>abs(x-i)){
				ans=i;
				k=abs(x-i);
			}
		}
	}
	cout<<ans<<endl;
}
	
	

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int A[10000];

int min(int n) {
  if (n == 1) return A[0];
  int t = min(n-1);
  return A[n-1] > t ? t : A[n-1];
}

int max(int n) {
  if(n == 1) return A[0];
  int t = max(n-1);
  return A[n-1] > t ? A[n-1] : t;
}

long long sum(int n) {
  if(n == 1)
    return A[0];
  
    return A[n-1] + sum(n-1);
}

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

  cout << min(n) <<" "<< max(n) << " " << sum(n) << endl;
}

Measured memory_bytes: 3284
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
using namespace std;
const int N=1e6+50,mod=1e9+7;
int h,lim,p[N],cnt,dat[N],inv[N],idat[N],sum[N],ans;
vector<pii>v[N];
int read(){
    int x=0,c;
    while(!isdigit(c=getchar()));
    while(isdigit(c))x=x*10+c-48,c=getchar();
    return x;
}
int main(){
    scanf("%d",&h);lim=1<<h;cnt=lim>>1;
    inv[1]=1;
    for(int i=2;i<lim;i++)
        inv[i]=mod-1ll*mod/i*inv[mod%i]%mod;
    for(int i=cnt,x;i<lim;i++)v[i].pb(mp(i,read()+cnt-1));
    dat[1]=idat[1]=1;
    for(int i=2;i<lim;i++)
        dat[i]=1ll*dat[i>>1]*i%mod,
        idat[i]=1ll*idat[i>>1]*inv[i]%mod;
    for(int i=1;i<lim;i++)idat[i]=1ll*i*idat[i]%mod*idat[i]%mod;
    for(int i=cnt-1;i;i--){
        v[i]=v[i<<1];
        for(int j=0;j<v[i<<1|1].size();j++)
            v[i].pb(v[i<<1|1][j]);
    }
    for(int i=1;i<cnt;i++){
        for(int j=0;j<v[i<<1].size();j++){
            int x=v[i<<1][j].first,y=v[i<<1][j].second,yy=y;
            while(y)sum[y]=(sum[y]+1ll*dat[x]*idat[i]%mod*dat[yy])%mod,y>>=1;
        }
        for(int j=0;j<v[i<<1|1].size();j++){
            int x=v[i<<1|1][j].first,y=v[i<<1|1][j].second,yy=y;
            int tmp=0;
            while(y)tmp=(tmp+1ll*sum[y]*(idat[y]-idat[y>>1]))%mod,y>>=1;
            ans=(ans+1ll*tmp*dat[yy]%mod*dat[x])%mod;
        }
        for(int j=0;j<v[i<<1].size();j++){
            int y=v[i<<1][j].second;while(y)sum[y]=0,y>>=1;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 54852
/**********************************************************************/
/********                                                      ********/
/********                     Writer:孙~~                      ********/
/********                       Lang:C++                       ********/
/********                     Status:Unknow                    ********/
/********                                                      ********/
/**********************************************************************/
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;

int main(){
	int n,k,p;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		int tmp;
		scanf("%d",&tmp);
		if(tmp==1) p=i;
	}
	int right=k-1-p%(k-1);
	int ans=p/(k-1)+ceil((double)max(0,n-p-1-right)/(k-1))+1;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {

   def loop(i:Int, x:Int, y:Int):Int = if(i == 0) y else loop(i-1, y, x+y)

  def main(args:Array[String]) = {
    val n = readInt
    println(loop(n,0,1))
  }
}


Measured memory_bytes: 43668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c; cin>>c;
    char ans;
    if(c=='A') ans = 'T';
    if(c=='T') ans = 'A';
    if(c=='C') ans = 'G';
    if(c=='G') ans = 'C';
    cout << ans <<endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

ll s, c;
int main() {
    cin >> s >> c;
    ll l = 0, r = s + c;
    while (l < r) {
        ll m = (r - l + 1) / 2 + l;
        bool ok = true;
        // scc
        if (m * 2 > c) {
            ok = false;
        } else {
            if (m > s) {
                ll d = (c - m * 2) / 2;
                if (s + d < m)
                    ok = false;
            }
        }
        if (ok)
            l = m;
        else
            r = m - 1;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
using namespace std;
int main()
{
	int d, k, s, x;
	while (cin >> d){
		s = x = 0;
		k = 600 / d;
		for (int i = 0; i < k; ++i, x += d)
			s += x * x * d;
		cout << s << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160