akhauriyash/Code-Regression huggingface dataset:
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

std::string s;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> s;

	bool ok = false;
	for (size_t i = 2; i < s.size()-1; i++)
	{
		if (s[i] == 'C') {
			s[i] = 'c';
			ok = true;
			break;
		}
	}
	ok &= s[0] == 'A';

	for (size_t i = 1; i < s.size(); i++)
	{
		if ('a' <= s[i] && s[i] <= 'z') {
		}
		else {
			ok &= false;
		}
	}

	if (ok) {
		out << "AC" << endl;
	}
	else{
		out << "WA" << endl;
	}


	return 0;
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    cin>>n;
    cout<<(n*(n+1))/2;
}

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

int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

int cmp( const void *p, const void *q ) {
    return -*(int*)p + *(int*)q;
}//大きい順
//qsort(a,n,sizeof(int),cmp);
//char s[n][11]

int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);


int main (void)
{
	int a,b,sum;

	scanf("%d%d",&a,&b);
	for(int i=0;i<=a;i++){
sum=i*2+(a-i)*4;
if(sum==b){
	printf("Yes\n");
	return 0;
}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int r;
    cin>>r;
    cout<<3*r*r<<endl;

    return 0;
}

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

int k, n, d, mx, a[200005];
int main() {
	int i;
	cin >> k >> n;
	for(i=0; i<n; i++) scanf("%d", &a[i]);
	for(i=0; i<n; i++) {
		d = max((a[(i+1)%n] - a[i] + k) % k, (a[i] - a[(i-1+n)%n] + k) % k);
		mx = max(mx, d);
	}
	cout << k- mx;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int main() {
  int n,k,h[110000];
  cin >> n >> k;
  for(int i = 0; i < n; i++)
    cin >> h[i];

  vector<long> dp(n, INF);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2; i < n; i++) {
    for(int j = 1; j < k+1; j++) {
      if(i >= j)
        dp[i] = min(dp[i-j] + abs(h[i]-h[i-j]), dp[i]);
    }
  }
  cout << dp[n-1] << endl;
}

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

const int N = 200000;

int a[N+5];

bool check(int n, int k, int d){
    long long cost = 0;
    for (int i = 1; i <= n; ++i){
        cost += (a[i] - 1) / d;
    }
    return cost <= k;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int _max = 0;
    for (int i = 1; i <= n; ++i){
        scanf("%d", a + i);
        _max = max(_max, a[i]);
    }
    int L = 1, R = _max;
    while (L < R){
        int M = (L + R) / 2;
        if (check(n, k, M)) R = M;
        else L = M + 1;
    }
    printf("%d\n", L);
    return 0;
}

Measured memory_bytes: 4408
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

ll const MAX = 200005;
ll parent[MAX];
ll rk[MAX];
ll get_money[MAX];
ll min_money[MAX];


void init(ll n) {
	for (ll i = 1; i <= n; i++) {
		parent[i] = i;
		rk[i] = 1;
	}
}

ll find(ll x) {
	if (parent[x] == x) {
		return x;
	}
	parent[x] = find(parent[x]);
	return parent[x];
}

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

void unite(ll x, ll y) {
	if (!same(x, y)) {
		x = parent[x];
		y = parent[y];
		if (rk[x] < rk[y]) {
			parent[x] = y;
		}
		else {
			parent[y] = x;
			if (rk[x] == rk[y]) {
				rk[x]++;
			}
		}
	}
}


struct edge
{
	long long val; long long from; long long to;
	bool operator<(const edge& rhs) const {
	return val > rhs.val;
	}
};
priority_queue<edge> pq;

ll a[MAX], b[MAX];

void uni(ll f, ll t) {
	if (a[f] > a[t]) {
		swap(f, t);
	}
	ll bf = find(f); ll bt = find(t);
	ll money = get_money[bf] + get_money[bt];
	ll min_val1 = max(min_money[bf], a[t] - get_money[bf]);
	ll min_val = min(min_val1, min_money[bt]);
	unite(f, t);
	ll r = find(f);
	min_money[r] = min_val;
	get_money[r] = money;
}

ll make_mst(ll n) {
	REP(i, 1, n) {
		min_money[i] = a[i];
		get_money[i] = b[i];
	}
	ll cnt = n - 1;
	while (cnt > 0) {
		edge cur = pq.top();
		pq.pop();
		ll f = cur.from; ll t = cur.to;
		if (!same(f, t)) {
			uni(f, t);
			cnt--;
		}
	}
	return min_money[find(1)];
}

int main() {
	ll n, m;
	cin >> n >> m;
	ll ttl = 0;
	REP(i, 1, n) {
		cin >> a[i] >> b[i];
		ttl += b[i];
		a[i] -= b[i];
	}
	REP(i, 1, m) {
		ll u, v;
		cin >> u >> v;
		pq.push({ max(a[v], a[u]), u, v });
	}
	init(n);
	ll ans = 0;
	ans = make_mst(n);
	cout << max(ans,ll(0)) + ttl << endl;
}

Measured memory_bytes: 10992
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
const int MAXN = 1e3 + 1;
const int MOD = 1e9 + 7;
int H, W;
string m[MAXN];
vector<vector<int> > dp;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		cin >> m[i];
	}
	dp.resize(H, vector<int>(W, 0));
	dp[0][0] = (int)(m[0][0] == '.');
	for (int i = 1; i < H; ++i) dp[i][0] = (int)(dp[i - 1][0] && m[i][0] == '.');
	for (int i = 1; i < W; ++i) dp[0][i] = (int)(dp[0][i-1] && m[0][i] == '.');
	for (int i = 1; i < H; ++i) {
		for (int j = 1; j < W; ++j) {
			if (m[i][j] == '#') continue;
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
		}
	}
	cout << dp[H - 1][W - 1] << '\n';
	return 0;
}

Measured memory_bytes: 8224
from collections import Counter

n = int(input())
v = [int(c) for c in input().split()]
vo = v[::2]
ve = v[1::2]
co = Counter(vo).most_common()
ce = Counter(ve).most_common()
co.append((-1, 0))
ce.append((-2, 0))
if co[0][0] != ce[0][0]:
	print(n - co[0][1] - ce[0][1])
else:
	res1 = n - co[0][1] - ce[1][1]
	res2 = n - co[1][1] - ce[0][1]
	print(min(res1, res2))

Measured memory_bytes: 65388
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

string s;cin>>s;
if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes";
else cout<<"No";

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const LL INF = 1e17;
const int LIM = 10000001;

LL N;
LL A;
LL dp[LIM+1];
LL imos[LIM+1];

LL Solve(LL N) {
  LL ret = N;
  if (N < LIM) MN(ret, imos[N]);
  
  reps(i, 2, LL(LIM)) {
    reps(k, 1, 100) {
      LL m = 1;
      rep(j, k) m *= i;

      LL t = N/m + (N%m != 0);
      if (t < LIM) {
        MN(ret, imos[t] + A*k + imos[i]*k);
      } else {
        MN(ret, imos[i]*k + A*k + t);
      }

      if (m >= N) {
        MN(ret, imos[i]*k + A*(k-1));
        break;
      }
    }
    
  }

  return ret;
}

int main() {
  scanf("%lld%lld", &N, &A);

  fill(dp, dp+LIM, INF);

  reps(i, 1, LIM) {
    MN(dp[i], LL(i));
    int cnt = 2;
    for (LL j=i+i; j<LIM; j+=i) {
      MN(dp[j], dp[i] + A + dp[cnt]);
      cnt++;
    }
  }

  imos[LIM] = INF;
  rrep(i, LIM) {
    imos[i] = min(imos[i+1], dp[i]);
  }

  LL ans = Solve(N);
  printf("%lld\n", ans);
}


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

using lint = long long;
pair<lint, lint> XH[200002];


int main(){
    lint N, D, A;
    lint Xtemp, Htemp;
    cin >> N >> D >> A;
    for(lint i=0;i<N;i++){
        cin >> Xtemp >> Htemp;
        XH[i] = pair<lint, lint>(Xtemp, Htemp);
    }

    sort(XH, XH+N);

    lint count = 0;
    lint current_count = 0;
    queue<pair<lint, lint>> que;
    for(lint i=0;i<N;i++){
        while(!que.empty()){
            lint x = que.front().first;
            lint c = que.front().second;
            if(x >= XH[i].first) break;
            que.pop();
            current_count -= (lint)c;
        }
        lint h = max((lint)0, XH[i].second - current_count * A);
        lint tempcount = lint(h / A) + (h % A != 0);
        if(h > 0) que.push(pair<lint, lint>(XH[i].first + 2*D, tempcount));
        current_count += tempcount;
        count += tempcount;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
    int a=0,b=0,ab=0,o=0,d;
    char c[3];
    while(scanf("%d,%s",&d,c)!=EOF){
        if(c[0]=='A'&&c[1]!='B'){
            a++;
        }
        else if(c[0]=='B'){
            b++;
        }
        else if(c[0]=='O'){
            o++;
        }
        else{
            ab++;
        }
    }
    printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
    return 0;
}

Measured memory_bytes: 596
def gcd(a,b):
	x,y = min(a,b), max(a,b)
	while x*y>0:
		x,y = min(x,y), max(x,y)
		x,y = y-x,x
	return y

N,M=map(int,input().split())
S=input()
T=input()
g=gcd(N,M)
p,q=M//g,N//g
print((N//g)*M) if S[0::q]==T[0::p] else print('-1')


Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int h[1 << 17];
int main() {
	int n; cin >> n; int k; cin >> k;
	rep(i, n) {
		cin >> h[i];
	}
	sort(h, h + n);
	int out = mod;
	rep(i, n - k + 1) {
		out = min(out, h[i + k-1] - h[i]);
	}
	cout << out << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int n; cin >> n;
    if (n == 0) return;
    vi64 a(n); cin >> a;
    vi64 sums(n + 1);
    rep(i, n) sums[i + 1] += sums[i] + a[i];
    i64 ma = -1e18;
    for (int l = 0; l < n; l++)
    for (int r = l + 1; r <= n; r++) {
      amax(ma, sums[r] - sums[l]);
    }
    cout << ma << '\n';
  }
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int N, K;
  cin >> N >> K;

  vector<bool> nn(N, false);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int b;
      cin >> b;
      nn[b - 1] = true;
    }
  }

  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (nn[i] == false) {
      sum++;
    }
  }

  cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
int main()
{
    unordered_map<string, ll> mp;
    ll n, i;
    cin>>n;
    string s;
    for(i=0; i<n; i++){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


Measured memory_bytes: 3636
import numpy as np

#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

q=int(input())
lr=[[int(x) for x in input().split()] for _ in range(q)]

primelist=[0,]*(100000+1)
for n in primes(100000):
  primelist[n]=1

list2017=[primelist[n] and primelist[(n+1)//2] for n in range(1,100000,2)]
cumsum=np.cumsum(list2017)
for query in lr:
  print(cumsum[(query[1]-1)/2]-cumsum[max(0,(query[0]-1)/2-1)])

Measured memory_bytes: 32804
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
  int R[MAX], n;

  cin >> n;

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

  int maxv = -2000000000;
  int minv = R[0];
  
  for(int i = 1 ; i < n ; i++){
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  
  cout << maxv << endl;

  return 0;
}
	  


Measured memory_bytes: 3876
import scala.io.StdIn.readLine
object Main {
    def main(args: Array[String]): Unit = {
        readLine.split(" ").map(_.toInt) match {
            case Array(a, b, c) =>  {
                if (a <= b) {
                    if (a <= c) {
                        if (b <= c) {
                            println(s"${a} ${b} ${c}")
                        } else {
                            println(s"${a} ${c} ${b}")
                        }
                    } else {
                        println(s"${c} ${a} ${b}")
                    }
                } else {
                    if (a <= c) {
                        println(s"${b} ${a} ${c}")
                    } else {
                        if (b <= c) {
                            println(s"${b} ${c} ${a}")
                        } else {
                            println(s"${c} ${b} ${a}")
                        }
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 43860
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

  int n, c;
  cin >> n >> c;
  VI x(n), v(n);
  REP(i, n) cin >> x[i] >> v[i];

  VI dp1(n);
  dp1[0] = v[0] - x[0];
  FOR(i, 1, n) dp1[i] = dp1[i-1] + v[i] - (x[i] - x[i-1]);
  FOR(i, 1, n) chmax(dp1[i], dp1[i-1]);

  VI dp2(n);
  dp2[n-1] = v[n-1] - (c - x[n-1]);
  for(int i=n-2; i>=0; --i) {
    dp2[i] = dp2[i+1] + v[i] - (x[i+1] - x[i]);
  }
  for(int i=n-2; i>=0; --i) {
    dp2[i] = max(dp2[i], dp2[i+1]);
  }

  // cout << dp1 << endl << dp2 << endl;

  int ans = max(0LL, dp2[0]);
  REP(i, n) {
    // i番目まで時計回りで取る
    int tmp = dp1[i];
    // [i+1, n-1] の最大
    if(i+1<n && dp2[i+1] - x[i] > 0) tmp += dp2[i+1] - x[i];
    chmax(ans, tmp);
  }
  for(int i=n-1; i>=0; --i) {
    int tmp = dp2[i];
    if(i >= 1 && dp1[i-1] - (c - x[i]) > 0 ) tmp += dp1[i-1] - (c - x[i]);
    chmax(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define LL long long
using namespace std;
inline LL in()
{
	LL x=0,w=0; char ch=0;
	while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
struct AA
{
	LL num;
	LL ybh;
}a[1000001];
bool compare(AA x,AA y)
{
	return x.ybh<y.ybh;
}
LL ans;
int main()
{
	int n,m;
	n=in(),m=in();
	for(LL i=1;i<=n;i++)
	a[i].ybh=in(),a[i].num=in();
	sort(a+1,a+n+1,compare);
	for(LL i=1;i<=n;i++)
	{
		if(a[i].num<m)ans+=a[i].num*a[i].ybh;
		else 
		{
			ans+=m*a[i].ybh;
			break;
		}
		m-=a[i].num;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,G; cin>>N>>G;
    vint p(N),c(N);
    REP(i,N) cin>>p[i]>>c[i];

    int ans=1e9;
    REP(S,1<<N){
        int score=0,cnt=0;
        REP(i,N){
            if(S>>i&1){
                score+=100*(i+1)*p[i]+c[i];
                cnt+=p[i];
            }
        }
        for(int i=N-1;i>=0;i--){
            if(S>>i&1) continue;
            REP(j,p[i]){
                if(score<G){
                    score+=100*(i+1);
                    cnt++;
                }
            }
        }
        if(score>=G) ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

int N,cnt[3];

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

    int i,x;
    for (i=1; i<=N; i++){
        cin >> x;
        if (x%4==0) cnt[0]++;
        else if (x%2==0) cnt[1]++;
        else cnt[2]++;
    }

    if (cnt[0]<(cnt[2]+(cnt[1]>0? 1 : 0)-1)) cout << "No\n";
    else cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
-- Atcoder https://atcoder.jp/contests/abc177/tasks/abc177_a

local input= io.read()
local d, t, s = string.match(input, "(%d+) (%d+) (%d+)")
d, t, s = tonumber(d), tonumber(t), tonumber(s)

if t * s >= d then
    print("Yes")
else
    print("No")
end

Measured memory_bytes: 2680
/*input
5 3
-10 10 -10 10 -10
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
ll a[maxn];
int main()
{
	IOS;
	int n,k;
	cin>>n>>k;
	REP(i,n) cin>>a[i];
	ll ans=0;

	ll sum=0;
	REP(i,k) sum+=a[i];
	ll pos=0;
	for(int i=k;i<n;i++) pos+=max(0LL,a[i]);

	REP(i,n-k+1){
		ans=max(ans,max(0LL,sum)+pos);
		if(i==n-k+1) continue;

		sum-=a[i];
		sum+=a[i+k];
		pos+=max(a[i],0LL);
		pos-=max(a[i+k],0LL);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<pii> v(N+1);
    vector<int> t(N+1);
    v[0] = pii(0, 0);
    t[0] = 0;
    for (int i = 1; i <= N; i++) {
        int x, y;
        cin >> t[i] >> x >> y;
        v[i] = pii(x, y);
    }
    bool can = true;
    for (int i = 0; i < N; i++) {
        int dt = t[i+1] - t[i];
        int d = abs(v[i].first - v[i+1].first) + abs(v[i].second - v[i+1].second);
        if (d > dt || (d % 2 != dt % 2)) can = false;
    }
    cout << (can ? "Yes" : "No") << '\n';
}


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


#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 961748941;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 5e3 + 5;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

struct Hash
{
  const ll mod1 = 1e9 + 7;
  const ll mod2 = 100001347; 
  const ll P1 = 547;
  const ll P2 = 769;
  string s;
  ll pre1[maxn];
  ll pre2[maxn];
  ll poww1[maxn];
  ll poww2[maxn];
  Hash(string s) : s(s){}
  Hash(){}
  void init()
  {
    poww1[0] = 1;
    poww2[0] = 1;
    for(int i = 1 ; i < maxn ; i++)
    {
      poww1[i] = (poww1[i - 1] * P1) % mod1;
      poww2[i] = (poww2[i - 1] * P2) % mod2;
    }

    for(int i = 0; i < s.size(); i++)
    {
      pre1[i + 1] = ((pre1[i] * P1) + s[i] - 'a' + 1) % mod1;
      pre2[i + 1] = ((pre2[i] * P2) + s[i] - 'a' + 1) % mod2;
    }
  }

  pair<ll,ll> substr(int l, int r)
  {
    ll x = (pre1[r] - (pre1[l - 1] * poww1[r - l + 1]) % mod1 + mod1) % mod1;
    ll y = (pre2[r] - (pre2[l - 1] * poww2[r - l + 1]) % mod2 + mod2) % mod2;
    return {x,y};
  }

} h;

map<pair<ll, ll>, int>mapa;
int n;
bool check(int mid)
{
  mapa.clear();
  for(int i = 0 ; i < n ; i++)
  {
    int j = i + mid - 1;
    if(j >= n)
      break;
    auto H = h.substr(i+1,j+1);
    if(mapa.count(H) == 0)
      mapa[H] = j;
    else if(mapa[H] < i)
      return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(0);
  
  cin >> n;
  string s;
  cin >> s;
  h.s = s;
  h.init();

  int lo = 0; 
  int hi = n;

  int ans = 0;
  while(lo <= hi)
  {
    int mid = (lo + hi) >> 1;
    if(check(mid))
    {
      ans = mid;
      lo = mid + 1;
    }
    else
    {
      hi = mid - 1; 
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4140
#include<bits/stdc++.h>
using namespace std;
int main(){ 
int m,n,s=0;
cin>>n>>m;
int a;
for (int i = 0; i < m; i++) {
cin>>a;
  s+=a;
}
if(n>=s)
cout<<n-s<<endl;
else
cout<<-1<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll x;
        cin >> x;
        cout << 10 - x / 200;
    }
    return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n, k;cin >> n >> k;
    vector<LL> a(n), s(n+1), ps(n+1);
    for(int i=0;i<n;i++) cin >> a[i];
    s[0] = ps[0] = 0;
    for(int i=0;i<n;i++){
        s[i+1] = s[i] + a[i];
        ps[i+1] = ps[i];
        if(a[i] > 0) ps[i+1] = ps[i] + a[i];
    }
    LL ans = 0;
    for(int i=0;i<n-k+1;i++){
        ans = max(ans, (ps[i])+(ps[n]-ps[i+k]));
        ans = max(ans, (ps[i])+(s[i+k]-s[i])+(ps[n]-ps[i+k]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;


int main() {
    int n; cin>>n;
    vector<int> ans(n+1);
    for (int i = 1; i <= n; ++i) {
        int a; cin>> a;
        ans[a] = i;
    }
    for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 1152
import math


def submit():
    a, b = map(int, input().split())
    b_price_min, b_price_max = b * 10, (b + 1) * 10 - 1

    for b_price in range(b_price_min, b_price_max + 1):
        if math.floor(b_price * 0.08) == a:
            print(b_price)
            return

    print(-1)


if __name__ == "__main__":
    submit()

Measured memory_bytes: 3060
N, A, B = map(int, input().split())
ans = 0

for i in range(N + 1):
  sum = 0

  q = i // 10000
  sum += q
  x = i - 10000 * q

  q = x // 1000
  sum += q
  x = x - 1000 * q

  q = x // 100
  sum += q
  x = x - 100 * q

  q = x // 10
  sum += q
  x = x - 10 * q

  q = x // 1
  sum += q

  if A <= sum and sum <= B:
    ans += i

print(ans)


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

void trace(int A[], int N) {
    cout << A[0];
    for (int i=1; i < N; i++) {
        cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[], int N) {
    int v;
    int j;
    for (int i=1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 & A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
    return;
}


int main(){
    int n;
    int A[110];

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


Measured memory_bytes: 3048
import java.util.Scanner;

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

		String S = sc.nextLine();
		String T = sc.nextLine();

		int cnt = 0;
		for (int i = 0; i < 3; i++) {
			String si = S.substring(i, i + 1);
			String ti = T.substring(i, i + 1);
			cnt += si.equals(ti) ? 1 : 0;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
#define STS system("pause")
#define C(x,y) memset(x,y,sizeof(x))
template<class U>I read(U &res){
	res=0;register U g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
const int INF=1e9+7;
vector<int>v[101000];
struct E{int to,nt,w;}e[808000];
#define T e[k].to
int n,m,p,head[202000],dis[202000],X,tot=-1,S,D,cur[202000];
int a[202000],b[202000],vis[202000][2];
queue<int>q;
IN B_1(){
	C(dis,-1);dis[S]=0;q.push(S);
	memcpy(cur,head,sizeof(head));
	while(!q.empty()){
		p=q.front();q.pop();
		for(re k=head[p];k!=-1;k=e[k].nt){
			if(dis[T]==-1&&e[k].w>0){dis[T]=dis[p]+1;q.push(T);}
		}
	}
	return dis[D]!=-1;
} 
IN D_1(int x,int lim){
	if(x==D||!lim)return lim;
	re flow=0,ext;
	for(re &k=cur[x];k!=-1;k=e[k].nt){
		if(dis[x]+1==dis[T]&&e[k].w>0){
			ext=D_1(T,min(lim,e[k].w));
			if(!ext)continue;
			flow+=ext;lim-=ext;
			e[k].w-=ext;e[k^1].w+=ext;
			if(!lim)break;
		}
	}
	if(lim)dis[x]=-1;
	return flow;
}
I add(int x,int y,int w){
	e[++tot].to=y;
	e[tot].nt=head[x];
	head[x]=tot;
	e[tot].w=w;
	e[++tot].to=x;
	e[tot].nt=head[y];
	head[y]=tot;
	e[tot].w=0;
}
IN dinic(){re res=0;while(B_1())res+=D_1(S,INF);return res;}
int main(){
	read(n);tot=-1;C(head,-1);S=0;D=(n<<1);
	F(i,1,n-1){
		read(m);add(S,n+i,1);add(i,D,1);
		F(j,1,m){read(X);add(n+i,X,1);v[X].emplace_back(i);}
	}
	add(n,D,1);
	if(dinic()<n-1){cout<<"-1";return 0;}
	F(i,1,n-1){
		for(re k=head[n+i];k!=-1;k=e[k].nt){
			if(T&&(!e[k].w))a[i]=T,vis[T][0]=1;
		}
	}
	F(i,1,n)if(!vis[i][0])q.push(i);
	m=0;
	while(!q.empty()){
		p=q.front();q.pop();m++;
		for(auto k:v[p]){
			if(!vis[k][1]){vis[k][1]=1;b[k]=p;q.push(a[k]);}
		}
	}
	if(m<n){cout<<"-1";return 0;}
	F(i,1,n-1)cout<<a[i]<<" "<<b[i]<<endl;
	return 0;
}



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

int main() {

  int N;
  cin >> N;

  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }

  sort(X.begin(), X.end());

  int answer = 100000000;
  
  for (int i = 1; i <= 100; i++) {
    int p = 0;
    for (int j = 0; j < N; j++) {
      p += (X[j] - i) * (X[j] - i);
    }
    answer = min(answer, p);
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline

N, Q = [int(x) for x in input().strip().split()]
res = [0 for _ in range(N)]
tree = [[] for _ in range(N)]
for n in range(N-1):
    a, b = [int(x) for x in input().strip().split()]
    tree[a-1].append(b)

for q in range(Q):
    p, x = [int(x) for x in input().strip().split()]
    res[p-1] += x

q = deque([1])
cq = deque([0])
while q:
    n = q.popleft()
    c = cq.popleft()
    res[n-1] += c
    if len(tree[n-1])!=0:
        for num in tree[n-1]:
            q.append(num)
            cq.append(res[n-1])

print(*res)

Measured memory_bytes: 85652
#include<bits/stdc++.h>
using namespace std;
vector <int> dr[1000100],db[1000100];
int fa[1000100],dep[1000100],ans;
void prework(int s)
{
	for (int k=0;k<db[s].size();k++) if (db[s][k]!=fa[s])
	{
		fa[db[s][k]]=s;
		dep[db[s][k]]=dep[s]+1;
		prework(db[s][k]);
	}
}
bool check(int u,int v)
{
	if (dep[u]<dep[v]) swap(u,v);
	if (fa[fa[u]]==v) return true;
	if (fa[u]==fa[v]) return true;
	if (fa[u]==v) return true;
	if (u==v) return true;
	return false;
}
void dfs(int s,int pre,int d)
{
	ans=max(ans,dep[s]);
	if (dep[s]<=d) return;
	for (int k=0;k<dr[s].size();k++) if (dr[s][k]!=pre)
	{
		if (!check(dr[s][k],s)) {printf("-1\n");exit(0);}
		dfs(dr[s][k],s,d+1);
	}
}
		
int main()
{
	int n,b,r;scanf("%d%d%d",&n,&b,&r);
	for (int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		dr[u].push_back(v);dr[v].push_back(u);
	}
	for (int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		db[u].push_back(v);db[v].push_back(u);
	}
	prework(r);
	dfs(b,0,0);
	printf("%d\n",ans<<1);
}

Measured memory_bytes: 76032
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
#define PI acos(-1)
typedef long long ll;
using namespace std;
int n;
ll **dp, w;
pair<ll, int> *x;
ll nap(int i, int rem)
{
    if(i == n && rem)
        return (ll)1e9 + 1;
    else if(!rem)
        return 0;
    if(~dp[i][rem])
        return dp[i][rem];
    ll first = nap(i + 1, rem), second = (ll)1e9 + 1;
    if(rem >= x[i].second)
        second = x[i].first + nap(i + 1, rem - x[i].second);
    return dp[i][rem] = min(first, second);
}
int main()
{
    //cin.tie(NULL); cout.tie(NULL);  ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif
    scanf("%d %lld", &n, &w);
    x = new pair<ll, int>[n];
    int mx = 0;
    for(int i = 0; i < n; i++)
    {
        scanf("%lld %d", &x[i].first, &x[i].second);
        mx += x[i].second;
    }
    dp = new ll*[n];
    for(int i = 0; i < n; i++)
    {
        dp[i] = new ll[mx + 1];
        memset(dp[i], -1, (mx + 1) * 8);
    }
    for(int i = mx; i >= 0; i--)
        if(nap(0, i) <= w)
        {
            printf("%d", i);
            break;
        }
}


Measured memory_bytes: 78592
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a<=0 && b>=0)
	{
		cout<<"Zero"<<endl;
		return 0;
	}
	if(a>0)
	{
		cout<<"Positive"<<endl;
		return 0;
	}
	if(b<0 && (b-a+(-1))%2==0)
	{
		cout<<"Positive"<<endl;
		return 0;
	}
	cout<<"Negative"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::unordered_set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int N; cin >> N;
  
  std::multiset<int> S{};
  S.emplace(0);
  S.emplace(0);
  S.emplace(N + 1);
  S.emplace(N + 1);
  vector<int> P(N+1);
  for(int i = 0; i < N; ++i)
  {
    int p; cin >> p;
    P[p] = i + 1; 
  }

  ull ans{};
  for(int i = N; i > 0; --i)
  {
    auto index = P[i];
    auto it = S.lower_bound(index);
    auto x = std::prev(it);
    auto w = std::prev(x);
    auto y = it;
    auto z = std::next(y);
    auto r = (*x - *w) * (ull)(*y - index) + (index - *x) * (ull)(*z - *y);
    ans += ((ull)r * i);
    S.emplace_hint(it, index);
  }

  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 5376
from heapq import heappop, heappush
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
table = [list(map(int, input().split())) for i in range(N)]
table.sort(key=lambda x:x[0])
Q = []
ans = 0
j = 0
for i in range(1,M+1):
  while j <= N-1:
    A, B = table[j]
    if A <= i:
      heappush(Q,-B)
      j += 1
    else:
      break
  if Q:
    ans += -1*heappop(Q)
print(ans)

Measured memory_bytes: 31972
#include <stdio.h>
int main(void){
  int n,ans,i;
  char a[3],b[3];
  while(1){
    scanf("%d",&n);
    if(!n)
      break;
    ans=0;
    for(i=0;i<n/2;i++){
      scanf("%s %s",a,b);
      if(a[1]==b[1])
	ans++;
    }
    if(n%2)
      scanf("%s",a);
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
string s,t;
int f[5005][5005];

void truyvet(int i,int j)
{
    if (i<=0 || j<=0) return;
    if (s[i-1]==t[j-1] && f[i][j]==f[i-1][j-1]+1)
    {
        truyvet(i-1,j-1);
        cout<<s[i-1];
        return;
    }
    if (f[i][j]==f[i-1][j]) truyvet(i-1,j);
    else truyvet(i,j-1);
}

int main()
{
 
    ios_base::sync_with_stdio(false);
    cin>>s>>t;
    for(int i=1;i<=s.length();i++)
        for(int j=1;j<=t.length();j++)
    {
        char h1=s[i-1],h2=t[j-1];
        if (h1==h2) f[i][j]=f[i-1][j-1]+1;
        f[i][j]=max(f[i][j],max(f[i-1][j],f[i][j-1]));
    }
    truyvet(s.length(),t.length());
    //cout<<f[s.length()][t.length()];
}


Measured memory_bytes: 59648
#include <bits/stdc++.h>
 
using namespace std;
 
const long double pi = acos(-1.0);
 
const long double fo = 20.0 - pi * 5.0;
 
struct pt {
    int x, y;
    pt(int x = 0, int y = 0) : x(x), y(y) {}
    bool operator<(const pt& p) const {
        if (x == p.x)
            return y < p.y;
        return x < p.x;
    }
};
 
const int MAXC = 1e8 - 1;
unordered_map<int, int> t;
 
void upd(int v, int tl, int tr, int pos, int val) {
    if (tl == tr)
        t[v] = val;
    else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            upd(v * 2, tl, tm, pos, val);
        else
            upd(v * 2 + 1, tm + 1, tr, pos, val);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }
}
 
int get(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return max(get(v * 2, tl, tm, l, min(r, tm)),
               get(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}
 
int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if (x1 > x2) {
        swap(x1, x2);
        swap(y1, y2);
    }
    bool flip = false;
    if (y1 > y2) {
        flip = true;
        y1 = MAXC - y1;
        y2 = MAXC - y2;
    }
    int left = x1, right = x2, bot = y1, top = y2;
    int n;
    scanf("%d", &n);
    vector<pt> a;
    for (int i = 0; i < n; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (flip) 
            y = MAXC - y;
        if (left <= x && x <= right &&
            bot <= y && y <= top)
            a.push_back(pt(x, y));
    }
    n = a.size();
    sort(a.begin(), a.end());
    unordered_map<int, int> dp;
    for (int i = 0; i < n; ++i) {
        int cnt = get(1, 0, MAXC, 0, max(0, a[i].y - 1));
        dp[a[i].y] = max(dp[a[i].y], cnt + 1);
        upd(1, 0, MAXC, a[i].y, dp[a[i].y]);
    }
    long double ans = (x2 - x1) + abs(y2 - y1);
    int cc = get(1, 0, MAXC, 0, MAXC);
    if (x1 == x2 || y1 == y2)
        ans = ans * 100.0 + (pi * 10.0 - 20.0) * cc;
    else {
        ans = ans * 100.0 - fo * cc;
        if (cc == min((x2 - x1), (y2 - y1)) + 1)
            ans += fo + (pi * 10.0 - 20.0);
    }
    printf("%.11Lf", ans);
    return 0;
}

Measured memory_bytes: 159204
#include <bits/stdc++.h>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt; // 最初の訪問
    for (v = 0; v < n; v++) {
        if (M[u][v] == 0) continue;
        if (color[v] == WHITE) dfs_visit(v);
    }
    color[u] = BLACK;
    f[u] = ++tt; // 訪問の完了
}

void dfs() {
    int u;
    for (u = 0; u < n; u++) {
        color[u] = WHITE;
    }
    tt = 0;

    for (u = 0; u < n; u++) {
        // 未訪問のuを始点として深さ優先探索
        if (color[u] == WHITE) dfs_visit(u);
    }
    for (u = 0; u < n; u++) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main() {
    int u, v, k, i, j;
    cin >> n;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for (i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}


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

int main() {
    string S;
    cin >> S;
    rep(i, S.size()) {
        if (i % 2 == 1) {
            if (S[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (S[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256