akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string S;
    cin >> S;
    int N = S.size();

    bool possible = true;
    if (S[0] == '0' || S[N - 1] == '1') {
        possible = false;
    }
    rep(i, 0, N - 1) {
        if (S[i] != S[N - 2 - i]) {
            possible = false;
        }
    }
    
    if (!possible) {
        write(-1);
        return 0;
    }

    vector<pair<int, int>> edge;

    // if (N < 4 || S == "1110") {
    //     rep(i, N - 1) edge.emplace_back(i + 1, i + 2);
    // }
    // else if (S == "1010") {
    //     rep(i, N - 1) edge.emplace_back(1, i + 2);
    // }
    if (false);
    else {
        int diameter = 0;
        rep(i, 0, N - 1) if (S[i] == '1') diameter++;

        rep(i, diameter) edge.emplace_back(i + 1, i + 2);

        int current = 2;
        int nv = diameter + 2;
        rep(i, 1, N - 2) {
            if (S[i] == '1') {
                current++;
            }
            else {
                edge.emplace_back(current, nv);
                nv++;
            }
        }
    }

    rep(i, edge.size()) {
        cout << edge[i].first << " " << edge[i].second << endl;
    }
}

Measured memory_bytes: 2372
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define MOD 1000000007
vector <ll> g[10];
ll visited[10];
ll dfs(ll v,ll N){
    ll i;
    bool flag=1;
    for(i=0;i<N;i++){
        if(visited[i]==0)flag=0;
    }
    if(flag)return 1;
    ll cnt=0;
    for(auto itr=g[v].begin();itr!=g[v].end();++itr){
        if(visited[*itr]==0){
            visited[*itr]=1;
            cnt+=dfs(*itr,N);
            visited[*itr]=0;
        }
    }
    return cnt;
}
int main(){
    ll N,M;
    cin >> N >> M;
    ll i,a,b;
    for(i=0;i<N;i++){
        visited[i]=0;
    }
    for(i=0;i<M;i++){
        cin >> a >> b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }
    visited[0]=1;
    cout << dfs(0,N)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;


int main(){
 int N;cin>>N;
 double X=0;
 for(int i=0;i<N;i++){
   double x;string u; cin>>x>>u;
   if(u=="JPY") X += x;
   else X += 380000.0 * x;
  
 }

printf("%lf",X);
cout<<endl;
  

  return 0;
}
  

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  int N, X, Y, len = 1, min, st, use_b, b_len;
  cin >> N >> X >> Y;
  b_len = 1;
  st = N;
  use_b = N;
  min = N;
  vector<int> count(N, 0);
  FOR(i, 1, N - 1) {
    FOR(n, i + 1, N) {
      st = n - i;
      if (i <= X) {
        if (n <= X) {
          use_b = st;
        } else {
          if (n <= Y) {
            use_b = X - i + b_len + Y - n;
          } else {
            use_b = X - i + b_len + n - Y;
          }
        }
      } else if (X < i < Y) {
        if (n <= Y) {
          use_b = i - X + b_len + Y - n;
        } else {
          use_b = i - X + b_len + n - Y;
        }
      } else {
        use_b = st;
      }
      if (st < use_b) {
        min = st;
        if (min < N) {
          count[min] += 1;
        }
      } else if (use_b < st) {
        min = use_b;
        if (min < N) {
          count[min] += 1;
        }
      } else {
        min = st;
        if (min < N) {
          count[min] += 1;
        }
      }
      // cout << "I:" << i << "  N:" << n << "  ST:" << st << "  USE_B:" << use_b
      //      << "  MIN:" << min << endl;
    }
  }
  FOR(i, 1, N - 1) { cout << count[i] << endl; }
}

signed main() {
  solve();

  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp;
    auto K = readln.chomp.to!int;

    auto DP = new long[][][](3, K+1, N.length);
    DP[2][K-1][0] += 1;
    foreach (x; 1..N[0]-'0') DP[1][K-1][0] += 1;
    DP[0][K][0] += 1;
    foreach (i; 1..N.length) {
        if (N[i] == '0') {
            foreach (k; 0..K+1) DP[2][k][i] += DP[2][k][i-1];
        } else {
            foreach (k; 1..K+1) DP[2][k-1][i] += DP[2][k][i-1];
            foreach (k; 0..K+1) DP[1][k][i] += DP[2][k][i-1];
        }
        foreach (_; 1..N[i]-'0') {
            foreach (k; 1..K+1) DP[1][k-1][i] += DP[2][k][i-1];
        }

        foreach (k; 0..K+1) DP[1][k][i] += DP[1][k][i-1];
        foreach (_; 1..10) foreach (k; 1..K+1) DP[1][k-1][i] += DP[1][k][i-1];

        foreach (k; 0..K+1) DP[0][k][i] += DP[0][k][i-1];
        foreach (_; 1..10) foreach (k; 1..K+1) DP[1][k-1][i] += DP[0][k][i-1];
    }
    long r;
    foreach (x; 0..3) r += DP[x][0][N.length-1];
    writeln(r);
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}


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

bool f(int x, vector<int> v){
    rep(i,v.size()){
        if(x == v.at(i)){ return true; }
    }
    return false;
}

int main(){
    int s = 0,e = 0;
    int n, m, x; cin >> n >> m >> x;
    vector<int> a(m); rep(i,m) cin >> a.at(i);

    for(int i = x; i > 0; i--){
        if(f(i,a)){ s++; }
    }
    for(int i = x; i < n; i++){
        if(f(i,a)){ e++; }
    }

    cout << min(s, e) << endl;
}

Measured memory_bytes: 256
N,K=$<.read.split.map(&:to_i)
m = 10**9+7

ret = 0
i = 0
j = N
is = 0
js = 0
while i <= N
  is += i
  js += j
  i += 1
  j -= 1
  if K <= i
    # p [i,j,is,js]
    ret += (js - is + 1) % m
  end
end

p (ret%m)

Measured memory_bytes: 14392
/*input
6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int n;
int c[100001];
int a[100001];
int b[100001];

bool comp(int x,int y){
    return  a[x]+b[x] > a[y]+b[y];
}

void solve(){
    cin >> n;
    REP(i,n){
      cin >> a[i] >> b[i];
      c[i] = i;
    }
    sort(c,c+n,comp);
    int ans = 0;
    REP(i,n){
      if(i%2)ans -= b[c[i]];
      else ans += a[c[i]];
    }
    cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

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

using namespace std;

int main() {
  int h,w; cin >> h >> w;
  vector<pair<int,int> > bu;
  char c;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cin >> c;
      if(c=='B') bu.push_back(make_pair(i,j));
    }
  }
  int ans=0;
  for(int i=0;i<bu.size();++i)
    for(int j=i+1;j<bu.size();++j)
      ans=max(ans,abs(bu[i].first-bu[j].first)+abs(bu[i].second-bu[j].second));
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 3112
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
using namespace std;

const int maxM = 200005;
int parent[maxM];
int sum[maxM];

int Find(int x)
{
	if (x != parent[x])
	{
		int i = parent[x];
		parent[x] = Find(parent[x]);
		sum[x] += sum[i];
	}
	return parent[x];
}


int main()
{
	int m, n;
	int ans = 0,flag = 0;
	scanf("%d%d", &m, &n);
		for (int i = 0; i <= m; i++)
		{
			parent[i] = i;
			sum[i] = 0;
		}
		while (n--)
		{
			int l, r, value;
			cin >> l >> r >> value;
			int fl = Find(l);
			int fr = Find(r);
			if (fl == fr)
			{
				if ((sum[l] - sum[r]) != value)
				{
					flag = 1;
				}
			}
			else {
				parent[fl] = fr;
				sum[fl] = -sum[l] + sum[r] + value;
			}
		}
		if(flag)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }

	return 0;
}

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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()
#define sz(x) x.size()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    string s;
    cin>>s;
    ll sum=0;
    for(auto c:s){
        sum+=c-'0';
    }
    if(sum%9==0)cout<<"Yes\n";
    else cout<<"No\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <cstdio>
using namespace std;

#define sqr(x) ((x) * (x))

struct sphere {
	double x, y, r;
	sphere(double x_, double y_, double r_) {
		x = x_; y = y_; r = r_;
	}
};

const double EPS = 1e-10;

int main() {
	int n;
	while(cin >> n, n) {
		vector<sphere> v;
		for(int i = 0; i < n; i++) {
			double x, y, r;
			cin >> x >> y >> r;
			v.push_back(sphere(x, y, r));
		}

		double top, bottom;
		top = 300; bottom = 0;
		for(int i = 0; i < 40; i++) {
			bool flag = true;
			double z = (top + bottom) / 2;
			for(int j = 0; j < v.size(); j++) {
				if(z > v[j].r)
					flag = false;
			}
			vector<pair<double,double> > points;
			for(int j = 0; j < v.size() && flag; j++) {
				points.push_back(pair<double,double>(v[j].x, v[j].y));
				for(int k = j + 1; k < v.size(); k++) {
					double r0, r1;
					r0 = sqrt(sqr(v[j].r) - sqr(z));
					r1 = sqrt(sqr(v[k].r) - sqr(z));
					double d;
					d = sqrt(sqr(v[j].x - v[k].x) + sqr(v[j].y - v[k].y));

					if(!(r0 + r1 < d || r1 + d < r0 || d + r0 < r1)) {
						double theta, phi;
						theta = atan2(v[k].y - v[j].y, v[k].x - v[j].x);
						phi = acos((sqr(r0) + sqr(d) - sqr(r1)) / (2 * r0 * d));

						if(isnan(theta) || isnan(phi))
							cout << "viss" << endl;

						double x0, y0, x1, y1;
						x0 = v[j].x + r0 * cos(theta + phi);
						y0 = v[j].y + r0 * sin(theta + phi);
						x1 = v[j].x + r0 * cos(theta - phi);
						y1 = v[j].y + r0 * sin(theta - phi);
						points.push_back(pair<double,double>(x0, y0));
						points.push_back(pair<double,double>(x1, y1));
					}
				}
			}

			if(flag) {
				for(int j = 0; j < points.size(); j++) {
					bool sub_flag = true;
					flag = false;
					for(int k = 0; k < v.size(); k++) {
						if(sqrt(sqr(points[j].first - v[k].x) + sqr(points[j].second - v[k].y)) > sqrt(sqr(v[k].r) - sqr(z)) + EPS) {
							sub_flag = false;
						}
					}
					if(sub_flag) {
						flag = true;
						break;
					}
				}
			}
			if(!flag)
				top = z;
			else
				bottom = z;
		}

		printf("%.10f\n", (top + bottom) / 2);
	}
}

Measured memory_bytes: 1392
#include<bits/stdc++.h>
using namespace std;
#define min(a,b) (a>b? b:a)
int main()
{
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  int cnt0=upper_bound(s.begin(),s.end(),'0')-lower_bound(s.begin(),s.end(),'0');
  int cnt1=upper_bound(s.begin(),s.end(),'1')-lower_bound(s.begin(),s.end(),'1');
  cout<<min(cnt0,cnt1)*2;
}

Measured memory_bytes: 512
#define CIN_ONLY 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const double PI = 3.14159265358979323846;

int aa[100000];

set<int> s;

int main()
{
	if (CIN_ONLY) {
		ios::sync_with_stdio(0);
		cin.tie(0);
	}
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &aa[i]);
		s.insert(aa[i]);
	}
	if (s.size() > 2) {
		cout << "No" << endl;
		return 0;
	}
	int a = *(s.begin());
	s.erase(s.begin());
	if (s.size() == 0) {
		cout << (n == a + 1 || n >= a * 2 ? "Yes" : "No") << endl;
		return 0;
	}
	int b = *(s.begin());
	s.erase(s.begin());
	if (b != a + 1) {
		cout << "No" << endl;
		return 0;
	}
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (aa[i] == a) {
			++cnt;
		}
	}
	if (cnt >= b || n - cnt < (b - cnt) * 2) {
		cout << "No" << endl;
		return 0;
	} else {
		cout << "Yes" << endl;
		return 0;
	}
	return 0;
}



Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




/* main */
int n;
string s;

string solve(char fir, char sec){

    string ret = ""; ret += fir; ret += sec;

    rep(i,1,n + 10){
        if(s[i % n] == 'o'){
            if(ret[i] == 'S') ret += ret[i-1];
            else ret += (ret[i-1] == 'S' ? 'W' : 'S');
        }else{
            if(ret[i] == 'S') ret += (ret[i-1] == 'S' ? 'W' : 'S');
            else ret += ret[i-1];
        }
    }

    bool isok = true;

    rep(i,0,5){
        if(ret[i] != ret[n + i]){
            isok = false;
            break;
        }
    }

    if(isok) return ret.substr(0, n);
    else return "-1";
}





signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    n = input();
    s = raw_input();

    string tmp;
    if((tmp = solve('S', 'S')) != "-1") {
        print(tmp);
        return 0;
    }
    if((tmp = solve('S', 'W')) != "-1"){
        print(tmp);
        return 0;
    }
    if((tmp = solve('W', 'S')) != "-1"){
        print(tmp);
        return 0;
    }
    if((tmp = solve('W', 'W')) != "-1"){
        print(tmp);
        return 0;
    }

    print(-1);

    



    







    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










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

int main()
{
    ll A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;

    ll AB = 0;
    ll BA = 0;
    ll AAB = 0;
    ll BAB = 0;
    ll ans;
    AB = C * max(X,Y) * 2;
    BA = A * X + B * Y;
    if(X > Y)
    {
        AAB = C * Y * 2 + A * (X - Y);
        ans = min(AB,BA);
        ans = min(ans,AAB);
    }
    else
    {
        BAB = C * X * 2 + B * (Y - X);
        ans = min(AB,BA);
        ans = min(ans,BAB);
    }
    
    
    
    

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

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

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;

int n,len;
int head[MAXN],f[MAXN],ans[MAXN],a[MAXN];

struct Edge{
	int to,next;
} e[MAXN << 1];

void add(int u,int v){
	e[++len].to = v;
	e[len].next = head[u];
	head[u] = len;
}

void dfs(int u,int fa){
	int p = lower_bound(f + 1,f + 1 + n,a[u]) - f;
	int tmp = f[p];
	f[p] = a[u];
	ans[u] = max(ans[fa],p);
	for(int i = head[u];i != -1;i = e[i].next){
		int v = e[i].to;
		if(v == fa)
			continue;
		dfs(v,u);
	}
	f[p] = tmp;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		f[i] = INF;
	}
	for(int i = 1;i < n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	for(int i = 1;i <= n;i++)
		printf("%d\n",ans[i]);
	return 0;
}



Measured memory_bytes: 24344
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int n;cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int count = 0;
  repp(i,1,n-1){
    if(p[i]>p[i-1] && p[i]<=p[i+1]) ++count;
    else if(p[i]>p[i+1] && p[i]<=p[i-1]) ++count;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        int H = stdIn.nextInt();
        int W = stdIn.nextInt();
        char[][] a = new char[H][W];
        int[] h = new int[W];
        int[] w = new int[H];
        int counth = W;
        int count= H;
        boolean[] trushW = new boolean[W];
        boolean[] trushH = new boolean[H];
        for(int i=0; i < H;i++){
            String s = stdIn.next();
            w[i]=0;
            trushH[i] = true;
            for(int j=0; j<W;j++){
                a[i][j] = s.charAt(j);
                if(a[i][j] == '#')w[i]+=1;
                else w[i] -= 1;
            }
            if(w[i] == -counth){
                trushH[i]=false;
            }
        }
        for(int i =0; i<W;i++){
            trushW[i] = true;
            h[i] = 0;
            for(int j=0; j<H;j++){
               if(a[j][i] == '#')h[i]+=1;
                else h[i] -= 1; 
            }
            if(h[i] == -count){
                trushW[i]=false;
            }
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(trushH[i]&&trushW[j])System.out.print(a[i][j]);
            }
            if(trushH[i])System.out.println();
        }
    }
}


Measured memory_bytes: 30944
#include <iostream>
#include <cstring>

#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    string s; cin>>s;
    int hash[26],hash1[26];
    memset(hash1,0,sizeof(hash1));
    memset(hash,0,sizeof(hash));
    for(int i=0;i<s.length();i++){
        hash[int(s[i])-97]++;
    }
    int maxm=0;
    for(int i=0;i<s.length();i++){
        hash[int(s[i])-97]--;
        hash1[int(s[i])-97]++;
        int count=0;
        for(int j=0;j<26;j++){ if(hash[j]>0 && hash1[j]>0) count++;}
        maxm=max(count,maxm);
    }
    cout<<maxm;
    return 0;
}

Measured memory_bytes: 256
val = input().split(" ")
A = int(val[0])
B = int(val[1])
K = int(val[2])
 
arr1 = [i for i in range(1,A + 1) if A % i == 0]
arr2 = [j for j in range(1,B + 1) if B % j == 0]
 
result = list(set(arr1) & set(arr2))
result.sort(reverse=True)
print(result[K - 1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        ll n;
        cin >> n;
        ll keta = 0;
        ll sm = 0;
        REP(i,1,n){
                ll d,c;
                cin >> d >> c;
                keta += c;
                sm += d*c;
        }
        cout << keta - 1 + (sm - 1) / 9 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  int N,M;

  cin >> N >> M;

  cout << N*(N-1)/2 + M*(M-1)/2 << endl;

  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	string alphabet = "abcdefghijklmnopqrstuvwxyz";
	map<char, int> min_alphabet;
	for (int i = 0; i < alphabet.size(); i++) min_alphabet[alphabet[i]] = INT_MAX;

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		map<char, int> check_alphabet;
		for (int j = 0; j < alphabet.size(); j++) check_alphabet[alphabet[j]] = 0;
		for (int j = 0; j < s.size(); j++) check_alphabet[s[j]]++;

		for (int j = 0; j < alphabet.size(); j++) {
			if (check_alphabet[alphabet[j]] < min_alphabet[alphabet[j]]) {
				min_alphabet[alphabet[j]] = check_alphabet[alphabet[j]];
			}
		}
	}

	for (auto& item : min_alphabet) {
		for (int i = 0; i < item.second; i++) cout << item.first;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
	int N;
	cin >> N;
	map<char, long long> m;
	for (int i = 0; i < N; ++i) {
		string S;
		cin >> S;
		++m[S[0]];
	}
	
	long long ans = 0;

	const string F = "MARCH";
	for (int i = 0; i < 5; ++i) {
		for (int j = i + 1; j < 5; ++j) {
			for (int k = j + 1; k < 5; ++k) {
				ans += m[F[i]] * m[F[j]] * m[F[k]];
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
int T,n,m;
int main() {
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<x+y+z-max(x,max(y,z))<<endl; 
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define inf 1e9
typedef pair<int,int> pii;
typedef pair <long long,long long> pll;
typedef long long ll; 
typedef long double ld; 
const ll mod = 1e9+7;
vector <vector <ll> > mul(vector <vector <ll> > const&a, vector <vector <ll> > const &b)
{	int n = a.size();
	vector <vector <ll> > prod(n, vector <ll>(n, 0)); 
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
			for(int k = 0; k < n ; ++k) {
               prod[i][j]=(prod[i][j]+a[i][k]*b[k][j])%mod;
            }
    return prod;
}
vector <vector <ll> > pow(vector <vector <ll> > &mat, ll exp)
{
	if (exp == 1)
		return mat;
	vector <vector <ll> > res = pow(mat, exp/2);
	if(exp&1)
		return mul(mul(mat,res),res);
	else
		return mul(res, res);
}
ll solve(vector< vector <ll> > &adj, ll n , ll k )
{	ll ans = 0;
	vector <vector <ll> > ak = pow(adj,k);
	for(ll i = 0; i < n; i++)
		for(ll j = 0; j < n; j++)
			ans = (ans + ak[i][j]) % mod;
	return ans;
} 
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n,k ; cin >> n >> k;
	vector < vector <ll> > adj(n, vector <ll>(n));
	for(ll i = 0; i < n; i++)
		for(ll j = 0; j < n; j++)
			cin >> adj[i][j];
	cout << solve( adj , n , k );
	return 0;
}


Measured memory_bytes: 3712
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Here your code !

process.stdin.on("data",function(chunk){
    var line = chunk.trim().split(" ");
    var arr= [];
    for(var i=parseInt(line[0]);i<=parseInt(line[1]);i++){
        if(line[2]%i===0){
             arr.push(i);
        }
    }
    console.log(arr.length);
});

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

def main():
    S = input().strip()
    ma = 0
    ACGT = ['A', 'C', 'G', 'T']
    count = 0
    for s in S:
        if s in ACGT:
            count += 1
        else:
            ma = max(ma, count)
            count = 0
    ma = max(ma, count)
    print(ma)


if __name__ == '__main__':
    main()




Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0008
{
    class Program
    {
        static void Main(string[] args)
        {
            Calc calc = new Calc();
            // nが入力された時の、a+b+c+d=nを満たす組み合わせの数を出力するプログラム
            // a,b,c,dの範囲はいずれも0～9の範囲の整数とする。

            string str ="";
            while ((str = Console.ReadLine()) != null)
            {
                int count = 0;
                int n = int.Parse(str);

                count = calc.combination(count, n);

                Console.WriteLine(count);
            }
        }
    }

    public class Calc
    {
        public int combination(int count, int n)
        {
            for (int a = 0; a < 10; a++)
            {
                for (int b = 0; b < 10; b++)
                {
                    for (int c = 0; c < 10; c++)
                    {
                        for (int d = 0; d < 10; d++)
                        {
                            count = Count(a, b, c, d, n, count);
                        }
                    }
                }
            }
            return count;
        }

        public int Count(int a, int b, int c, int d, int n, int count)
        {
            if (a + b + c + d == n)
            {
                count++;
            }
            return count;
        }
    }
}



Measured memory_bytes: 15964
#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    int N;
    int num;
    int half;
    int rtn;
    char S[100+1] = {0};
    char T[50+1] = {0};
    char TT[100+1] = {0};

    if(scanf("%d", &N) == 1);
    if(scanf("%s", S) == 1);

    num = N % 2;

    if (num == 1) {
        printf("No");
        return(0);
    } else {
        half = N / 2;
        strncpy(T, S, half);
        strcat(TT, T);
        strcat(TT, T);

        rtn = strcmp(S, TT);
        if(rtn == 0){
            printf("Yes");
        } else {
            printf("No");
        }
    }

    return(0);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 using namespace std;
int main(){
  char b;
  cin >> b;
  if (b == 'A') {
      cout << 'T' << "\n";
  }else if (b == 'T') {
      cout << 'A' << "\n";
  }else if (b == 'G') {
      cout << 'C' << "\n";
  }else if (b == 'C') {
      cout << 'G' << "\n";
  }
}


Measured memory_bytes: 256
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for i in range(1, min(N,K)+1):
    for j in range(i+1):
        W = sorted(V[:j]+V[N-i+j:])
        for k in range(min(i,K-i)+1):
            ans = max(ans, sum(W[k:]))
print(ans)

Measured memory_bytes: 3060
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll n,k,x,y,sum=0;
  cin >> n >> k >> x >> y;
  for(int i=1;i<=n;i++){
    if(i<=k) sum += x;
    else sum += y;
  }
  cout <<sum<<endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

	void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double[] a = new double[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextDouble();
		}
		final int max = 200001;
		double[][] dp = new double[2][max];
		double div = 1.0 / a[0];
		for (int i = 0; i < max; i++) {
			dp[0][i] = Math.abs(a[0] - i) * div;
		}
		for (int i = 1; i < n; i++) {
			int t = i & 1;
			Arrays.fill(dp[t], 1e9);
			div = 1.0 / a[i];
			for (int j = 1; j < max; j++) {
				for (int k = j; k < max; k += j) {
					dp[t][k] = Math.min(dp[t][k], Math.max(dp[1 - t][j], Math.abs(a[i] - k) * div));
				}
			}
		}
		double ans = 1e9;
		for (int i = 1; i < max; i++) {
			ans = Math.min(ans, dp[(n - 1) & 1][i]);
		}
		System.out.printf("%.9f\n",ans);
	}
}

Measured memory_bytes: 32236
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<a; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
 
using namespace std;
 
const int Mod=1e9+7;

ll Pow(ll a, ll b){
	ll y=1;
	ll z=a;
	while(b>0){
		if(b%2==1){
			y=(y*z);
			b--;
		}
		b=b/2;
		z=(z*z);
	}
	return y;
}
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n,x,y;
	cin >> n;
	int a[n];
	vector<pii> vec[n];
	pii p;
	loop(n){
		cin >> a[i];
		loopi(j,a[i]){
			cin >> x >> y;
			p.first=x-1;
			p.second=y;
			vec[i].push_back(p);
		}
	}
	int Max=-1;
	int subset=0;
	bool ok;
	while(subset<(1<<n)){
		ok=true;
		loop(n){
			if((subset&(1<<i))==0) continue;
			loopi(j,a[i]){
				if(vec[i][j].second==1){
					if((subset&(1<<vec[i][j].first))==0) ok=false;
				}
				else if(vec[i][j].second==0){
					if((subset&(1<<vec[i][j].first))!=0) ok=false;
				}
			}
			if(!ok) break;
		}
		if(ok){
			Max=max(Max,__builtin_popcount(subset));
			//cout << subset << "\n";
		}
		subset++;
	}
	cout << Max << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n,i,j,k,x,y,gg;
long long dis[505][505],ans;
int bz[505][505];
int p[250005];
int list[2500005][3],head,tail,B[505][505];
int fx1[5],fx2[5];

void update(int x,int y)
{
	int xx,yy,t;
	head=0; tail=1;
	list[1][1]=x; list[1][2]=y;
	B[x][y]=1;
	while (head<tail)
	{
		head++;
		x=list[head][1]; y=list[head][2];
		for (t=1;t<=4;t++)
		{
			xx=x+fx1[t];
			yy=y+fx2[t];
			if (dis[xx][yy]>dis[x][y]+(bz[xx][yy]^1))
			{
				dis[xx][yy]=dis[x][y]+(bz[xx][yy]^1);
				if (B[xx][yy]==0)
				{
					B[xx][yy]=1;
					tail++;
					list[tail][1]=xx;
					list[tail][2]=yy;
				}
			}
		}
		B[x][y]=0;
	}
}

int main()
{
//	freopen("read.in","r",stdin);
	fx1[1]=1; fx1[2]=-1; fx1[3]=0; fx1[4]=0;
	fx2[1]=0; fx2[2]=0; fx2[3]=1; fx2[4]=-1;
	scanf("%d",&n);
	for (i=1;i<=n*n;i++) scanf("%d",&p[i]);
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			dis[i][j]=min(min(i,j),min(n-i+1,n-j+1));
		}
	}
	for (i=1;i<=n*n;i++)
	{
		x=(p[i]-1)/n+1; y=(p[i]-1)%n+1;
		bz[x][y]=1;
		dis[x][y]--; 
		ans+=dis[x][y];
		update(x,y);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 9500
import scala.io.StdIn

object Main extends App {
  val counts = StdIn.readInt()
  val ls = scala.collection.mutable.ArrayBuffer.empty[Int]

  for (n <- 0 until counts) yield {
    ls += StdIn.readInt()
  }

  val ans = ls.toSet.size
  println(ans)

}


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

int main(){

    int n;
    cin >> n;
    string arr[n];
    int i;
    for(i=0;i<n;++i){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int k =1;
    for(i=0;i<n-1;++i){
        if(arr[i]!=arr[i+1]){
            k++;
        }
    }
    cout << k;


}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll H, W;
    cin >> H >> W;
    vc<string> G(H);
    rep(i, H) cin >> G[i];
    vl dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};

    ll ans = 0;
    queue<pair<ll, ll>> q;
    vvc<ll> road(H, vc<ll>(W, INF));

    rep(i, H) rep(j, W) {
        if (G[i][j] == '#') continue;
        vvc<ll> dist;
        dist = road;
        dist[i][j] = 0;

        q.emplace(i, j);
        while (!q.empty()) {
            ll x, y;
            tie(x, y) = q.front();
            q.pop();

            rep(d, 4) {
                ll nx = x + dx[d], ny = y + dy[d];
                if (nx < 0 || nx > H - 1 || ny < 0 || ny > W - 1) continue;
                if (G[nx][ny] == '#' || dist[nx][ny] <= dist[x][y] + 1) continue;

                dist[nx][ny] = dist[x][y] + 1;
                q.emplace(nx, ny);
            }
        }

        ll tmp = 0;
        for (auto R : dist)
            for (auto r : R)
                if (r != INF) tmp = max(tmp, r);
        ans = max(ans, tmp);
    }

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 1;
        for(int i=0;i<N;i++){
            if(ans*2<ans+K){
                ans = ans*2;
            }else{
                ans += K;
            }
        }
        System.out.println(ans);
        
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
    }
}

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

int main() {
    int n, cnt=0;
    string s;
    cin>>n>>s;
    int N=n/2;

    for(int i=0; i<N; i++){
        if(s.at(i)==s.at(N+i)) cnt++;
    }

    if(cnt!=N || n%2!=0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


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

L, N = map(int, input().split())
A = [int(input()) for _ in range(N)]

def solve(A):
    if len(A) == 1:
        return A[0]
    S = [None]*N
    s = 0
    for i, a in enumerate(A):
        s += a
        S[i] = s

    T = [None]*N
    t = 0
    for i in reversed(range(N)):
        t += (L-A[i])
        T[i] = t

    ans = 0
    for i in range(N-1):
        if 2*i+3 < N:
            ans = max(ans, 2*S[i]+2*(T[i+1]-T[2*i+3])-(L-A[i+1]))
        elif 2*i+2 > N:
            ans = max(ans, 2*(S[i]-S[2*i-N+1]) + 2*T[i+1] - (L-A[i+1]))
        else:
            ans = max(ans, 2*S[i]+2*T[i+1]-(L-A[i+1]))
    return ans

a1 = solve(A)
a2 = solve([L-a for a in reversed(A)])
print(max(a1, a2))

Measured memory_bytes: 37784
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 c = sc.nextInt();
		
		int sum1 = 0;
		int sum2 = 0;
		
		for(int i =1 ; i <= b ; i++){
			
			if ( (c % i == 0) && (b >= i) ){
				sum1++;
			}
			if ( (c % i == 0) && (a > i) ){
				sum2++;
			}
		}
		System.out.println(sum1 - sum2);

	}

}


Measured memory_bytes: 26412
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int main(void)
{
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d",(a-1)*(b-1));
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<cmath>
#include<queue>
#define MAX 1000050
#define ll long long int
using namespace std;


string str;
int used[10000000];
int main(){
  cin>>str;
  int cnt  =0;
  int say = 0;
  for(int i=0;i<str.size()-1;i++){
    if(str[i]!=str[i+1]) say++;
  }
  cout<<say<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
 {

	  int a,b;
	  cin>>a>>b;
	  if(a>=1 && a<10 && b>=1 && b<10){
        cout<<a*b<<endl;
	  }else{
	    cout<<"-1"<<endl;
	  }


	return 0;
}

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

using namespace std;

const int MaxN = 200005;

struct FenwickTree
{
    int n;
    vector<long long> FT;
    void init(int _n)
    {
        n = _n;
        FT.assign(n + 1, 0);
    }
    void Update(int x, long long val)
    {
        while (x <= n)
        {
            FT[x] = max(FT[x], val);
            x += (x & -x);
        }
    }
    long long Get(int x)
    {
        long long Resuft = 0;
        while (x > 0)
        {
            Resuft = max(Resuft, FT[x]);
            x -= (x & -x);
        }
        return Resuft;
    }
};

int n;
int h[MaxN], a[MaxN];
long long dp[MaxN];
FenwickTree FT;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    FT.init(n);
    for (int i = 1; i <= n; i++)
    {
        dp[i] = FT.Get(h[i]) + a[i];
        FT.Update(h[i], dp[i]);
    }
    cout << FT.Get(n);
    return 0;
}

Measured memory_bytes: 7920
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars,
        t: Chars,
    };
    let ans = s
        .iter()
        .zip(t.iter())
        .filter(|&(&s_i, &t_i)| s_i != t_i)
        .count();
    println!("{}", ans);
}


Measured memory_bytes: 3952
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _1000
{
	class Program
	{
		static void Main(string[] args)
		{
			TextReader input = Console.In;
			if (args.Length > 0)
			{
				input = File.OpenText(args[0]);
			}

			string line = null;
			while ((line = input.ReadLine()) != null)
			{
				var pair = line.Split(' ');
				int a = int.Parse(pair[0]);
				int b = int.Parse(pair[1]);
				Console.Out.WriteLine(a + b);
			}
		}
	}
}

Measured memory_bytes: 5652
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 998244353

class BIT2:
    def __init__(self, N):
        self.N = (N+1)
        self.data0 = [0] * (N+1)
        self.data1 = [0] * (N+1)
        
    def _add(self, data, k, x):
        while k < self.N: #k <= Nと同義
            data[k] += x
            k += k & -k

    def _sum(self, data, k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    def add(self, l, r, x):
        self._add(self.data0, l, -x*(l-1))
        self._add(self.data0, r, x*(r-1))
        self._add(self.data1, l, x)
        self._add(self.data1, r, -x)

    def sum(self, l, r):
        return self._sum(self.data1, r-1) * (r-1) + self._sum(self.data0, r-1) - self._sum(self.data1, l-1) * (l-1) - self._sum(self.data0, l-1)
    
N, K = map(int, readline().split())
bit = BIT2(N)
d = []
for _ in range(K):
    L,R = map(int, readline().split())
    d.append((L,R))

bit.add(1,2,1)

for i in range(2,N+1):
    for k in range(K):
        L,R = d[k]
        tmp = bit.sum(max(1,i-R),max(1,i-L+1))%MOD
        bit.add(i,i+1,tmp)
print(bit.sum(N,N+1)%MOD)

Measured memory_bytes: 79844
#AtCoDeerくん
#a = 'H'のとき正直者
#a = 'D'のとき嘘つき
#AtCoDeerくん
#b = 'H'のとき、「TopCoDeerくんは正直者だ」と発言する
#b = 'D'のとき、「TopCoDeerくんは嘘つきだ」と発言する

#TopCoDeerくんが正直者かどうか判定してください。
#a = H b = H →H
#a = H b = D →D
#a = D b = H →D
#a = D b = D →H

a,b = map(str,input().split())

if a == "H" and b == "H":
    print("H")
if a == "H" and b == "D":
    print("D")
if a == "D" and b == "H":
    print("D")
if a == "D" and b == "D":
    print("H")

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H-h)*(W-w) << endl;
	return 0;
}


Measured memory_bytes: 256
from operator import itemgetter
import sys


def read():
    return sys.stdin.readline().rstrip()


def add(arr, i):
    while i < len(arr):
        arr[i] += 1
        i += i & -i


def sub(arr, i):
    while i < len(arr):
        arr[i] -= 1
        i += i & -i


def range_sum(arr, a, b):
    s = 0
    i = b
    while i > 0:
        s += arr[i]
        i -= i & -i
    i = a - 1
    while i > 0:
        s -= arr[i]
        i -= i & -i
    return s


def main():
    n, q = map(int, read().split())
    c = [int(i) - 1 for i in read().split()]
    queries = [(0, 0, 0) for _ in range(q)]
    for i in range(q):
        l, r = map(int, read().split())
        queries[i] = (i, l, r)
    queries = iter(sorted(queries, key=itemgetter(2)))
    last = [0] * n
    bit = [0] * (n + 1)
    ans = [-1] * q
    k, l, r = next(queries)
    for i in range(n):
        ci = c[i]
        li = last[ci]
        if li > 0:
            sub(bit, li)
        last[ci] = i + 1
        add(bit, i + 1)
        while i + 1 == r:
            ans[k] = range_sum(bit, l, r)
            try:
                k, l, r = next(queries)
            except StopIteration:
                break
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 221364
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , a[N] , c[N];
char s[N];

bool check(int x) {
  rep(i,0,n) c[i] = a[i] >= x;
  set<pii> seg;
  priority_queue<pair<int,pii> > q[2];
  int cnt[2] = {0 , 0};
  for(int i=0,j=0;i<n;i=j) {
    for(j=i;j<n&&c[j]==c[i];++j);
    seg.insert(mp(i , j - 1));
    q[c[i]].push(mp(-(j - i) , mp(i , j - 1)));
  }
  rep(i,0,n-1) {
    cnt[s[i] == 'M']++;
    int p = s[i] == 'M' ? 0 : 1;
    while(sz(q[p])) {
      int x = -q[p].top().fi;
      pii s = q[p].top().se;
      if(!seg.count(s)) {
        q[p].pop();
        continue;
      }
      if(x + cnt[p] > cnt[p^1]) break;
      q[p].pop();
      seg.erase(s);
      int l = s.fi , r = s.se;
      //cout << i << " " << l << " " << r << endl;
      auto it = seg.upper_bound(s);
      if(it != seg.end()) {
        r = it->se;
        seg.erase(it);
      }
      it = seg.upper_bound(s);
      if(it != seg.begin()) {
        --it;
        l = it->fi;
        seg.erase(it);
      }
      c[l] = c[r] = p ^ 1;
      seg.insert(mp(l , r));
      q[c[l]].push(mp(-(r - l + 1) , mp(l , r)));
    }
  }
  for(auto e : seg) {
    int l = e.fi , r = e.se;
    int p = c[l];
    if(p) l -= cnt[1] , r -= cnt[0];
    else r -= cnt[1] , l -= cnt[0];
    if(l <= 0 && 0 <= r)
      return p;
  }
  return true;
}

int main(){
  scanf("%d",&n);
  rep(i,0,n) scanf("%d",a + i);
  scanf("%s",s);
  int l = 1 , r = n + 1;
  while(l + 1 < r) {
    int mid = (l + r) >> 1;
    (check(mid) ? l : r) = mid;
  }
  printf("%d\n",l);
  return 0;
}


Measured memory_bytes: 5080