akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

int main(){
    ll x,ans;
    cin >> x;
    ll eleven = x/11;
    // cout << "eleven = " << eleven << endl;
    ll rest = x - 11 * eleven;
    if (rest == 0){
        ans = 2 * eleven;
    }else{
        if (rest <= 6) ans = eleven * 2 + 1;
        else ans = eleven * 2 + 2;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
	char s[4],t[4];
	cin>>s;
	cin>>t;
	int num=0;
	for(int i=0;i<3;i++){
		if(s[i]==t[i]){
			num++;
		}
	}
	cout<<num<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if ((a + b) != c && (a + c) != b && (b + c) != a) {
		printf("%s", "No");
	} else {
		printf("%s", "Yes");
	}
	return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
    int init; cin >> init;
    vector<int> v; v.push_back(init);
    set<int> s; s.insert(init);

    int cnt = 1;
    while (1) {
        int prev = v[v.size()-1];
        int val;
        if (prev%2) {
            val = 3*prev+1;
        } else {
            val = prev/2;
        }
        v.push_back(val);
        if (s.find(val) == s.end()) {
            s.insert(val);
        } else {
            break;
        }
    }

    cout << v.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
using namespace std;
typedef long long LL;

string s; map<string,LL> w;
LL n;

int main(){
	cin >> n;
	while(n --){
		cin >> s;
		w[s] ++;
	}
	cout << "AC x " << w["AC"] << '\n';
	cout << "WA x " << w["WA"] << '\n';
	cout << "TLE x " << w["TLE"] << '\n';
	cout << "RE x " << w["RE"] << '\n';
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
  long long int a,b;
  cin>>a>>b;




  int arr[2019];

  for (int i=0;i<2019;i++)
  {
      arr[i] = 0;
  }

  for (long long int i=a;i<b;i++)
  {
      for (long long int j = i+1; j<=b;j++)
      {
          arr[(i*j)%2019]++;

          if (arr[0]>0)
            break;
      }

      if (arr[0]>0)
            break;

  }



  for (int i=0;i<10000;i++)
  {
      if (arr[i]>0)
      {
          cout<<i<<endl;
          break;
      }
  }

}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x = c - a;
  int y = d - b;
  cout << c - y << " " << d + x << " " << a - y << " " << b + x <<endl;
}


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

char win(char h){
    return (h=='r'?'p':h=='s'?'r':'s');
}
int main(){
    int n,k,r,s,p,score=0;
    string t,win_h;
    cin>>n>>k>>r>>s>>p>>t;
    for(int i=0;i<n;i++){
        win_h.push_back(win(t[i]));
        
    }

    for(int i=k;i<n;i++){
        if(win_h[i-k]==win_h[i])win_h[i]+=char('A'-'a');
    }

    for(int i=0;i<n;i++){
        if(win_h[i]=='r')score+=r;
        if(win_h[i]=='s')score+=s;
        if(win_h[i]=='p')score+=p;
    }

    for(int i=k;i<n;i++){
        if(win_h[i]=='R'||win_h[i]=='S'||win_h[i]=='P'){
            if(win_h[i-k]=='R'||win_h[i-k]=='S'||win_h[i-k]=='P'){
                if(win_h[i]=='R'){score+=r;win_h[i]='r';}
                if(win_h[i]=='S'){score+=s;win_h[i]='s';}
                if(win_h[i]=='P'){score+=p;win_h[i]='p';}
            }
        }
    }
    cout<<score<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;
int main()
{
    int a;
    string b;
    int c;
    cin>>a>>b>>c;
    for (int i=0; i<a; i++)
    {
        if (b[i]!=b[c-1])
        {
            b[i]='*';
        }
    }
    cout<<b;
    
    return 0;
}

Measured memory_bytes: 256
import numpy as np
U = 55556
T = np.zeros(U)
T[2] = 1
T[3::2] = 1
for i in range(3,U,2):
  if i*i>U:
    break
  if T[i]:
    T[i*i::2*i] = 0
pls = np.where(T)[0]
N = int(input())
ans = []
for p in pls:
  if p%5==1:
    ans += [str(p)]
  if len(ans)==N:
    break
print(' '.join(ans))

Measured memory_bytes: 13108
#include <stdio.h>
int main(void){
    int n;
    scanf("%d ",&n);
    char s;
    char old;
    long long int rslt = 1;

    scanf("%c",&old);
    for(int i=1;i<n;i++){
        scanf("%c",&s);
        if(old!=s)rslt += 1;
        old=s;
    }

    printf("%lld\n",rslt);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val, class Cmp>
class DynamicRMQ {
    int n;
    Val init;
    vector<Val> dat;
    Cmp cmp;
    inline Val query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return init;
        if (a <= l&&r <= b) return dat[k];
        else {
            Val vl, vr;
            vl = query(a, b, k << 1, l, (l + r) >> 1);
            vr = query(a, b, (k << 1) | 1, (l + r) >> 1, r);
            return cmp(vl, vr) ? vl : vr;
        }
    }
public:
    DynamicRMQ() {}
    DynamicRMQ(int n_, Val init_) :n(1), init(init_) {
        for (; n<n_; n <<= 1);
        dat = vector<Val>(n << 1, init);
    }
    void update(int k, Val a) {
        k += n;
        dat[k] = a;
        while (k > 1) {
            k >>= 1;
            dat[k] = cmp(dat[k << 1], dat[(k << 1) | 1]) ? dat[k << 1] : dat[(k << 1) | 1];
        }
    }
    Val query(int a, int b) {
        return query(a, b, 1, 0, n);
    }
};

typedef DynamicRMQ<long long, less<long long> > RMinQ64;
typedef DynamicRMQ<long long, greater<long long> > RMaxQ64;
typedef DynamicRMQ<int, less<int> > RMinQ32;
typedef DynamicRMQ<int, greater<int> > RMaxQ32;

int H, W, N;
int X1[100001], Y1[100001], X2[100001], Y2[100001];

int jdg(int x, int y) {
    if (!(x == 0 || x == H || y == 0 || y == W))return -1;
    if (y == 0)return x;
    if (x == H)return H + y;
    if (y == W)return H + W + H - x;
    return H + H + W + W - y;
}

int g() {
    vector<pii> S;
    rep(i, N) {
        int a = jdg(X1[i], Y1[i]);
        int b = jdg(X2[i], Y2[i]);
        if (a != -1 && b != -1) {
            S.push_back(mp(a, i));
            S.push_back(mp(b, i));
        }
    }
    sort(all(S));

    RMaxQ32 rmq(sz(S), -1);
    vi a(N, -1);

    int i = 0;
    each(p, S) {
        int pos, idx;
        tie(pos, idx) = p;
        if (a[idx] == -1) {
            a[idx] = i;
        } else {
            int ma = rmq.query(0, a[idx]);
            if (ma > a[idx])return 0;
            rmq.update(a[idx], i);
        }
        i++;
    }
    return 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W >> N;
    rep(i, N)cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];

    cout << (g() ? "YES" : "NO") << endl;
}


Measured memory_bytes: 5872
import java.util.*;


public class Main {

	public static void main(String[] args) {
		
		// 3????????°???????????????????????§????????????
		Scanner scanner = new Scanner(System.in);
		String line = scanner.nextLine();
		scanner.close();
		
		String array[] = line.split(" ");
		int a = Integer.parseInt(array[0]);
		int b = Integer.parseInt(array[1]);
		int c = Integer.parseInt(array[2]);
		
		
		// 0??\???100??\????????°????????\??????????????´???????????????????????????
		if ( (a>=0)&&(a<=100) && (b>=0)&&(b<=100) && (c>=0)&&(c<=100) ) {
			// a < b < c ??????????????????Yes???????????????????????????????????°No???????????????
			if ( (a<b)&&(b<c) ) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		
		
		
	
		
	}

}

Measured memory_bytes: 26056
#include <bits/stdc++.h>
using namespace std;
#define inf 1e9

int main(){
 
 int n;
 cin >> n;
    int *a = new int[n+1];
    for(int i=1;i<=n;i++) cin >> a[i];

  int *dp = new int[n+1];
  dp[0] = dp[1] = 0;  // dp[1] = 0 bcoz same to same cost = 0
    
    for(int i=2;i<=n;i++){

        int op1 = abs(a[i] - a[i-1]) + dp[i-1];
        int op2 = (i==2) ? inf : abs(a[i] - a[i-2]) + dp[i-2];
        dp[i] = min(op1,op2);
    }
 cout << dp[n] << endl;

  return 0;  
}

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

int main(void){
	int i,j,m,n,d,walk;
	int di[]={-1,0,1,0};
	int dj[]={0,1,0,-1};
	char rst[104][104];

	cin>>m;
	while(m--){
		cin>>n;

		for(i=0;i<n+4;i++){
			for(j=0;j<n+4;j++){
				if(i==0 || i==n+3 || j==0 || j==n+3) rst[i][j] = '#';
				else rst[i][j] = ' ';
			}
		}

		i = n + 1;
		j = 2;
		d = 0;

		while(1){
			for(walk=0;rst[i+2*di[d]][j+2*dj[d]] != '#';walk++){
				rst[i][j] = '#';
				i += di[d];
				j += dj[d];
			}

			rst[i][j] = '#';
			d = (d+1) % 4;
			if(walk <= 1) break;
		}

		if(n==2) rst[2][3]='#';
		for(i=2;i<n+2;i++){
			for(j=2;j<n+2;j++) cout<<rst[i][j];
			cout<<endl;
		}
		if(m) cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    int n;
    cin >> n;
    deque<int> a;
    int x;
    cin >> x;
    a.push_back(x);
    for (int i = 1; i < n; i++)
    {
        int x;
        cin >> x;
        if (x <= a[0])
        {
            a.push_front(x);
        }
        else
        {
            int p = lower_bound(a.begin(), a.end(), x) - a.begin();
            a[p - 1] = x;
        }
    }
    cout << a.size() << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int x;
	cin >> x;
	if (x < 1200) cout << "ABC" << endl;
	else cout << "ARC" << endl;
	return 0;
}

Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    cin>>s;
    int ans=0;
    int n=s.size();
    int cnt=0;
    rep(i,n){
        if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
            cnt ++;
        }
        else{
            ans =max(ans,cnt);
            cnt =0;
        }
    }
    ans =max(ans,cnt);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> vx,vy;
    ll p[a],q[b],r[c];
    for(int i=0;i<a;i++){
    	cin>>p[i];
    }
    for(int i=0;i<b;i++){
    	cin>>q[i];
    }
    for(int i=0;i<c;i++){
    	cin>>r[i];
    }
    sort(p,p+a);
    sort(q,q+b);
    sort(r,r+c);
    reverse(p,p+a);
    reverse(q,q+b);
    reverse(r,r+c);

    for(int i=0;i<x;i++){
    	vx.pb(p[i]);
    }
    for(int i=0;i<y;i++){
    	vy.pb(q[i]);
    }
    ll idc=0,idx=x-1,idy=y-1;
    //for(int i=0;i<c;i++)cout << r[i] <<endl;
    while(1){
    	bool maki=true;
    	if(idc==c)break;
    	if(idx==-1){
    		if(idy==-1)break;
    		else{
    			if(vy[idy]<r[idc]){
    				maki=false;
    				vy[idy]=r[idc];
    				idy--;
    				idc++;
    			}
    		}
    	}else{
    		if(idy==-1){
    			if(vx[idx]<r[idc]){
    				maki=false;
    				vx[idx]=r[idc];
    				idx--;
    				idc++;
    			}
    		}else{
    			if(vx[idx]<vy[idy]){
    				if(vx[idx]<r[idc]){
    				    maki=false;
    				    vx[idx]=r[idc];
    				    idx--;
    				    idc++;
    			    }
    			}else{
    				if(vy[idy]<r[idc]){
    				    maki=false;
    				    vy[idy]=r[idc];
    				    idy--;
    				    idc++;
    			    }
    			}
    		}
    	}
        if(maki)break;
    }
    ll ans=0;
    for(auto& i:vx){
    	//cout << i<<" ";
    	ans+=i;
    }
    //cout << endl;
    for(auto& i:vy){
    	//cout << i<<" ";
    	ans+=i;
    }
    //cout << endl;
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    vec L(N); cin >> L;
    Sort(L);
    int ans = 0;
    REP(i, N) FOR(j, i + 1, N){
        ans += Lower_bound(L, L[i] + L[j]) - j - 1;
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
import itertools
L = [list(map(int, input().split())) for i in range(3)]
L = list(itertools.chain.from_iterable(L))
bool_L = [[False, False, False] for i in range(3)]
N = int(input())
b_L = [int(input()) for i in range(N)]

for b in b_L:
    if b in L:
        index = L.index(b)
        show = index // 3
        amari = index % 3
        bool_L[show][ amari] = True
        
flag = "No"
for i in bool_L:
    if i == [True, True, True]:
        flag = "Yes"
        break
        
for j in range(3):
    temp_l = []
    for i in range(3):
        temp_l.append(bool_L[i][j])
    if temp_l == [True, True, True]:
        flag = "Yes"
        break

if [bool_L[0][0],bool_L[1][1],bool_L[2][2]] == [True, True, True]:
    flag = "Yes"
elif [bool_L[2][0],bool_L[1][1],bool_L[0][2]] == [True, True, True]:
     flag = "Yes"
print(flag)

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

set <int> s;
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				int num = 100*i + 10*j + k;
				s.insert(num);
			}
		}
	}

	cout << s.size() << '\n';
	
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, X; cin >> n >> X;
    vi x(n); for(auto& e : x) cin >> e;

    vi xp, xn;
    for(auto& e : x){
        (e - X > 0 ? xp:xn).emplace_back(abs(e - X));
    }
    sort(_all(xp));
    sort(_all(xn));
    if(xp.size() == 0) xp = xn;
    if(xn.size() == 0) xn = xp;

    int res = __gcd(xp[0], xn[0]);
    for(auto& y : {xp, xn}){
        rep(i, 1, y.size()){
            res = __gcd(res, y[i] - y[i-1]);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1616
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*(n+1)
for i in range(n):
    coun[a[i]]+=1
for i in range(n+1):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)

Measured memory_bytes: 84172
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
ll longinf=1ll<<60;
int inf=1<<29;

int D;
int p[11];
int c[11];
int G;
int dp[11][1001];
int tb[11][101];
 
int main(){
    cin>>D>>G;
    rep1(i,D){
        cin>>p[i]>>c[i];
    }
    rep1(i,D){
        rep1(j,p[i]){
            tb[i][j]=tb[i][j-1]+100*i;
            if(j==p[i]) tb[i][j]+=c[i];
        }
    }
    /*rep0(i,D+1){
        rep0(j,p[i]+1){
            cout<<tb[i][j]<<" ";
        }
        cout<<endl;
    }*/
    int sum=0;
    rep1(i,D){
        sum+=p[i];
        rep1(j,sum){
            int M=0;
            if(i==1) dp[i][j]=tb[i][j];
            else{
                rep0(k,j+1){
                    M=max(M,tb[i][j-k]+dp[i-1][k]);
                }
                dp[i][j]=M;
            }
        }
    }
    /*rep0(i,D+1){
        rep0(j,sum+1){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    rep1(j,sum){
        if(dp[D][j]>=G){
            cout<<j<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*
oruegg19 - Arundhati Bhattacharya
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<unsigned ll>
#define mp make_pair
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const unsigned ll l=1000000007;
const int MAX_=2000;
int T;


void solve(int t)
{
  string s;
  cin >> s;
  int cnt=0;
  char c = s.front();

  for(auto x: s)
  {
    if(c != x)
    {
      cnt++;
      c = x;
    }
  }
  cout << cnt << endl;
}

// 1735 , 50

int main()
{
  IOS
  int t,testCases;
  testCases=1;
  #ifdef DEBUG
    freopen("input.txt","r",stdin);
    cin >> testCases;
    cout << "Running " << testCases << " testcases" << endl;
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif

  while(testCases--)
  {
    t=1;
    // cin >> t; //comment this in case of singular test case
    T = t;
    while(t--)
    {
      // cout << "HERE" << endl;
      solve(t);
    }
  }
  return 0;

}




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

int main() {
  int H, W;

  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0)
      break;
    
    for (int h=0;h<H;h++) {
      for (int w=0;w<W;w++)
        cout << "#";
      cout << endl;
    }

    cout << endl;
  }
}



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

n = int(input())
guzai_valu = list(map(int, input().split()))
heikin=0
i=1
while i <= n-1:
   guzai_valu_sort = sorted(guzai_valu)
   #print(guzai_valu_sort)
   heikin=(guzai_valu_sort.pop(0)+guzai_valu_sort.pop(0))/2
   guzai_valu_sort.append(heikin)
   guzai_valu = guzai_valu_sort
   i=i+1
print(heikin)


'''自動で成分がずれるのでリスの成分の内最初のものを2回選ぶことが最小のもの
   を2つ選ぶことと等価になるんや
   #print(heikin)'''


Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
	int k, g;
	int p, c;
	int tmp;
	int pattern[100];
	int i, j;
	
	scanf("%d %d", &k, &g);
	c = k;
	
	for(i=0; i<k; i++){
		scanf("%d", &p);
		pattern[i] = p;
		g -= p;
	}
	
	for(i=0;i<k;i++){
		for(j=i+1;j<k;j++){
			if(pattern[i]>pattern[j]){
				tmp = pattern[i];
				pattern[i] = pattern[j];
				pattern[j] = tmp;
			}
		}
	}
	for(i=0;i<k && g!=0;i++){
		while(pattern[i] <= g){
			g -= pattern[i];
			c += 1;
		}
	}
	
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10000)

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

#N = [int(x) for x in input().split()]

S = input()

if S.count("1") == 1 and S.count("9") and S.count("7") and S.count("4"):
    print("YES")
else:
    print("NO")




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

int main() {
	// your code goes here
	int n, i, j, k;
	cin >> n;
	double p[n];
	for (i = 0; i < n; i++)
	{
		cin >> p[i];
	}
	double ans[n][n+1];
	for (i = 0; i < n; i++)
	{
		for(j = 0; j < n+1; j++)
		{
			ans[i][j] = 0;
		}
	}
	ans[0][0] = 1 - p[0];
	ans[0][1] = p[0];
	for (i = 0; i < n - 1; i++)
	{
		for (j = 0; j <= i+1; j++)
		{
			ans[i+1][j] += (1 - p[i+1])*ans[i][j];
			ans[i+1][j+1] += p[i+1]*ans[i][j];
		}
	}
	double res;
	res = 0;
	for (i = n/2 + 1; i < n+1; i++)
	{
		res+=ans[n-1][i];
	}
	cout.precision(9);
	cout << res;
	return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if (A + B >= 10) cout << "error" << endl;
    else cout << A + B << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
 
        if (a * b > c * d) {
            _out.println(a * b);
        } else {
            _out.println(c * d);
        }
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

ll func(ll d, ll c, ll &last) {
	if (c == 1) {
		last = d;
		return 0;
	}
	ll ret = c/2;
	ll a = d + d;
	if (a >= 10) {
		a = a % 10 + a / 10;
		ret *= 2;
	}
	ret += func(a, c / 2, last);
	if (c & 1) {
		a = d + last;
		ret++;
		if (a >= 10) {
			a = a % 10 + a / 10;
			ret++;
		}
		last = a;
	}
	return ret;
}


int main() {
	int m; cin >> m;
	vector<ll> d(m), c(m);
	for (int i = 0; i < m; i++) cin >> d[i] >> c[i];
	vector<ll> last(m);
	ll ans = 0;
	for (int i = 0; i < m; i++) {
		ans += func(d[i], c[i], last[i]);
	}
	for (int i = 0; i < m - 1; i++) {
		ll a = last[i] + last[i + 1];
		ans++;
		if (a >= 10) {
			a = a % 10 + a / 10;
			ans++;
		}
		last[i + 1] = a;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


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

int main() {
  int T; cin >> T;

  rep(t, T) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if (a < b || b > d) {
      cout << "No" << endl;
      continue;
    }

    ll p = gcd(b, d);
    ll k1 = (a-b)/p + 1;
    ll k2 = (a-c+p-1)/p - 1;
    if (k1 > k2) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
struct edge{int to,cost;};
vector<int> G[100005];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
std::vector<P> tree[100010];
ll i,j;

ll n,k;
long long int ans=0;
ll a=0,b=0,c;
//a=guusuu b=kisuu

int main(){
	cin>>n>>k>>a;
	c=a;
	for(i=2;i<=n;i++){
		cin>>b;
		c=max(c,b);
		if(b>a)swap(a,b);
		ll r;
		r=a%b;
		while(r!=0){
			a=b;
			b=r;
			r=a%b;
		}
		a=b;
	}
	if(a==1 && c>=k){
		cout<<"POSSIBLE"<<endl;
	}else if(k%a==0 && c>=k){
		cout<<"POSSIBLE"<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}

	return 0;
}

Measured memory_bytes: 4992
/*
AUTHOR : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
*/

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 100050

#define ll long long
#define ld long double
#define lli long long int

#define pb emplace_back
#define INF 1000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define loop(i,n) for (lli i = 0; i < n; i++)
#define loopitr(xt,vec) for (auto xt : vec)
#define FOR(i,a,b) for (lli i = a; i < b; i+=1)
#define loop_rev(i,n) for (lli i = n-1; i >= 0; i--)
#define FOR_REV(i,a,b) for (lli i = a; i >= b; i--)
#define itr :: iterator it
#define WL(t) while(t --)

#define all(v) v.begin(),v.end()
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>
#define vi vector<lli>
#define seti set<lli>
#define pii pair<lli,lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvector(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvector(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";
#define printset(st) for(auto xt : st) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define endl '\n'

#define deb(x) cout<<#x<<" "<<x<<endl;

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}


int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    lli n,m,k;
    cin>>n>>m>>k;
    lli a[n] , b[m];
    scanarr(a,n);
    scanarr(b,m);
    FOR(i,1,n)
        {
            a[i]+=a[i-1];
        }
        
    FOR(i,1,m)
        {
            b[i]+=b[i-1];
        }
    
    
    lli ans = upper_bound(b,b+m,k)-b;
    
    lli maxi = ans;
    
    loop(i,n){
        if(a[i]<=k){
            lli count = upper_bound(b,b+m,k-a[i])-b;
            maxi = max(maxi , (i+1+count));
        }
    }
    print(maxi);


  }
return 0;
}


Measured memory_bytes: 6720
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;


int map[50][50];

signed main()
{
	int W, H;
	cin >> H >> W;
	REP(y, H)
	{
		char str[100];
		cin >> str;
		REP(x, W)
		{
			if (str[x] == '#')
				map[x][y] = -1;
		}
	}


	REP(y, H)
	{
		REP(x, W)
		{
			if (map[x][y] == -1)
			{
				cout << '#';
			}
			else
			{
				int cnt = 0;
				for (int i = -1; i <= 1; i++)
				{
					for (int j = -1; j <= 1; j++)
					{
						if (i == 0 && j == 0) continue;
						int dx = x + i;
						int dy = y + j;
						if (0 <= dx && dx < W && 0 <= dy && dy < H)
						{
							if (map[dx][dy] == -1)
							{
								cnt++;
							}
						}
					}
				}
				cout << cnt;
			}
		}
		cout << endl;
	}
}



Measured memory_bytes: 256
(lambda nums: (lambda index, itertools=__import__("itertools"): print(sum([eval("".join((lambda t: [[t.insert(j, "+") for j in reversed(i)], t][1])(list(nums)))) for i in itertools.chain(*[itertools.combinations(index, x) for x in range(len(index) + 1)])])))(range(1, len(nums))))(input())

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a;cin >> a;
    bool f = 0;
    for (int i = 0;i < (int) a.size();++i){
        if (a[i] == '7'){
            f = 1;
            cout << "Yes\n";
            break;
        }
    }
    if (!f){
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3616
import sys
for c1, c2, c3 in (map(int, l.split()) for l in sys.stdin.readlines()):
    available = set(range(1, 11)) - {c1, c2, c3}
    if len([1 for n in available if 20-c1-c2 >= n]) >= 4:
        print("YES")
    else:
        print("NO")


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

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

	vector<int> al(26);

	for (int i = 0; i < w.size(); ++i)
	{
		al.at(w.at(i)-97) += 1;
	}

	for (int i = 0; i < al.size(); ++i)
	{
		if (al.at(i)%2==1)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;

int main()
{
    const int INF=12345678;
    int n,m,s,g1,g2;
    while(scanf(" %d %d %d %d %d",&n,&m,&s,&g1,&g2),n)
    {
        //Graph
        vector<vi> G(n,vi(n,INF));
        rep(i,n) G[i][i]=0;

        rep(i,m)
        {
            int a,b,c;
            scanf(" %d %d %d",&a,&b,&c);
            --a;
            --b;
            G[a][b]=c;
        }

        //Warshall-Floyd
        rep(k,n)rep(i,n)rep(j,n) G[i][j]=min(G[i][j],G[i][k]+G[k][j]);

        int ans=INF;
        rep(i,n) ans=min(ans,G[s-1][i]+G[i][g1-1]+G[i][g2-1]);
        printf("%d\n", ans);
    }
    return 0;
}

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

int main() {
    int a = 0;
    int b = 0;
    string op = "";
    int result = 0;

    for(int i = 0; i == 0;){
        cin >> a >> op >> b;
        
        if(op == "?"){
            break;
        }

        if(op == "+"){
            result = a + b;
            cout << result << "\n";
        }else if(op == "-"){
            result = a - b;
            cout << result << "\n";
        }else if(op == "*"){
            result = a * b;
            cout << result << "\n";
        }else if(op == "/"){
            result = a / b;
            cout << result << "\n";
        }
    }
}


Measured memory_bytes: 3160
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


class Seg():
    def __init__(self, na, default, func):
        if isinstance(na, list):
            n = len(na)
        else:
            n = na
        i = 1
        while 2**i <= n:
            i += 1
        self.D = default
        self.H = i
        self.N = 2**i
        if isinstance(na, list):
            self.A = [default] * (self.N) + na + [default] * (self.N-n)
            for i in range(self.N-1,0,-1):
                self.A[i] = func(self.A[i*2], self.A[i*2+1])
        else:
            self.A = [default] * (self.N*2)
        self.F = func

    def find(self, i):
        return self.A[i + self.N]

    def update(self, i, x):
        i += self.N
        self.A[i] = x
        while i > 1:
            i = i // 2
            self.A[i] = self.merge(self.A[i*2], self.A[i*2+1])

    def merge(self, a, b):
        return self.F(a, b)

    def total(self):
        return self.A[1]

    def query(self, a, b):
        A = self.A
        l = a + self.N
        r = b + self.N
        res = self.D
        while l < r:
            if l % 2 == 1:
                res = self.merge(res, A[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = self.merge(res, A[r])
            l >>= 1
            r >>= 1

        return res

def main():
    n = I()
    a = LI()
    uv = [LI_() for _ in range(n-1)]

    e = collections.defaultdict(set)
    for u,v in uv:
        e[u].add(v)
        e[v].add(u)

    seg = Seg(n, 0, max)

    d = {}
    for i, c in enumerate(sorted(set(a))):
        d[c] = i
    z = [d[c] for c in a]

    rr = [0] * n
    def f(i, p, cr):
        ai = z[i]
        b = seg.find(ai)
        t = seg.query(0, ai)
        if cr < t + 1:
            cr = t + 1
        rr[i] = cr
        if b < t + 1:
            seg.update(ai, t + 1)
        for c in e[i]:
            if c == p:
                continue
            f(c, i, cr)
        if b < t + 1:
            seg.update(ai, b)

    f(0, -1, 0)

    return JA(rr, "\n")

print(main())





Measured memory_bytes: 670772
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string s; cin >> s;
    if(s == "SUN") cout << 7 << endl;
    else if(s == "MON") cout << 6 << endl;
    else if(s == "TUE") cout << 5 << endl;
    else if(s == "WED") cout << 4 << endl;
    else if(s == "THU") cout << 3 << endl;
    else if(s == "FRI") cout << 2 << endl;
    else if(s == "SAT") cout << 1 << endl; return 0;
}


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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = ["; __print(x);


int main()
{
    int n;
    scanf("%d", &n);
    int a[n+2];
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a+n);
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            cnt += lower_bound(a, a+n, a[i] + a[j]) - a - j - 1;
            // dbg(cnt);
        }
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3772
#include <stdio.h>

int N; long long X,A[2020],U[2020];

int main()
{
	scanf ("%d %lld",&N,&X);
	for (int i=0;i<N;i++) scanf ("%lld",&A[i]);
	long long ans = 0;
	for (int i=0;i<N;i++) ans += A[i], U[i] = A[i];
	for (int i=1;i<N;i++){
		long long now = i * X;
		for (int j=0;j<N;j++){
			int k = (j + N - i) % N;
			if (U[j] > A[k])
				U[j] = A[k];
			now += U[j];
		}
		if (ans > now)
			ans = now;
	}
	printf ("%lld\n",ans);

	return 0;
}

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


    int main(){
        char s[10];
        for (int i=0; i < 10; i++) {
            cin >> s[i];
        }
        cout << "2018/01/" << s[8] << s[9] << endl;
        return 0;
    }
   
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    char last = ' ';
    rep(i,N){
        if(last == S[i])continue;
        last = S[i];
        ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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(){
    string s,t;
    cin>>s;
    int n=s.size();
    t="keyence";
    bool ok=0;
    if(s==t)ok=1;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            string u;
            for(int k=0;k<i;k++)u+=s[k];
            for(int k=j+1;k<n;k++)u+=s[k];
            if(u==t){
                ok=1;
                break;
            }
            if(ok)break;
        }
        if(ok)break;
    }
    cout<<(ok?"YES":"NO");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005

int main(){
  ll x,y;
  while(1){
    cin >> x >> y;
    if(x==0&&y==0){break;}
    cout << min(x,y) << " " << max(x,y) << endl;
  }
  return 0;
}


Measured memory_bytes: 3028