akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Possible":"Impossible")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,l;
	Vi ans;
	pair<int,ll>up=mp(-1,-1);
	cin >>n>>l;
	V a(n);
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n-1){
		if(chmax(up.S,a[i]+a[i+1])){
			up.F=i;
		}
	}
	cout<<solve(up.S >=l)<<endl;

	if(up.S <l){return 0;}
	ans.push_back(up.F);
	for(int i=up.F+1;i<n-1;i++){
		ans.push_back(i);
	}
	for(int i=up.F-1;i>=0;i--){
		ans.push_back(i);
	}
	reverse(all(ans));
	repi(itr,ans){
		cout<<(*itr)+1<<endl;	}
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  long long sum=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      sum+=a[i];
  }
  unordered_map<int,int> mp;
   for(int i=0;i<n;i++)
      {
        mp[a[i]]++;
      }
    int q;
    cin>>q;
    for(int i=0;i<q;i++)
    {
      int x,y;
      cin>>x>>y;
      if(mp.find(x)==mp.end())
      {
        cout<<sum<<endl;
        continue;
      }
      int diff=(y-x)*mp[x];
      sum=sum+diff;
      cout<<sum<<endl;
      mp[y]+=mp[x];
      mp.erase(x);
      
    } 
  return 0;
}

Measured memory_bytes: 7008
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N, M, Q; cin >> N >> M >> Q;
	vector<bool>oks(N);
	vector<pair<int, int>>moves(N);
	for (int i = 0; i < N; ++i) {
		moves[i] = make_pair( (i + N - 1) % N, (i + 1) % N);
	}
	int now = 0;
	for (int i = 0; i < M; ++i) {
		int a; cin >> a;

		if (!(a % 2)) {
			for (int i = 0; i < a; ++i) {
				now = moves[now].second;
			}
			oks[now] = true;
		}
		else {
			for (int i = 0; i < a; ++i) {
				now = moves[now].first;
			}
			oks[now] = true;
		}
		moves[moves[now].first].second = moves[now].second;
		moves[moves[now].second].first = moves[now].first;
		now = moves[now].second;
	}
	for (int i = 0; i < Q; ++i) {
		int q; cin >> q;
		if (oks[q]) {
			cout << 0<< endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4408
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#include <cstdint>
#include<iomanip>
#define ll long long int
#define rep(i,rept) for (int (i) = 0; (i) < rept; (i)++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define lolo 92233720368547757
#define susu 1000000007
typedef std::pair<int, int> pp;
typedef std::pair<ll, ll> llpp;
using namespace std;

int main() {
	double n,m,ans;
	cin >> n >> m;
	ans = n / m;
	cout << fixed;
	cout << setprecision(10) << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> jobs(m);
    rep(i,n){
        int a, b; cin >> a >> b;
        if(a > m) continue;
        jobs[m-a].pb(b);//m-a日目までに終わらさなければならない仕事
    }
    priority_queue<int> q;
    ll ans = 0;
    for(int i = m-1; i >= 0; --i){
        for(int b : jobs[i]){
            q.push(b);
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5504
#include <stdio.h>
#define N 100005
#define NIL -1

typedef struct node {
  int p;
  int l;
  int r;
} Node;

Node no[N];
int n;
int d[N];

void output(int node){
  int i, left;
  printf("node %d: parent = %d, depth = %d, ", node, no[node].p, d[node]);

  if(no[node].p == NIL){
    printf("root, ");
  }else if(no[node].l == NIL){
    printf("leaf, ");
  }else{
    printf("internal node, ");
  }

  printf("[");
  
  for(i = 0, left = no[node].l; left != NIL; i++, left = no[left].r){
    if(i){
      printf(", ");
    }
    printf("%d", left);
  }
  printf("]\n");
}

int depth(int node, int parent){
  d[node] = parent;
  if(no[node].r != NIL){
    depth(no[node].r, parent);
  }
  if(no[node].l != NIL){
    depth(no[node].l, parent+1);
  }
}

int main(){
  int i, j, m, k;
  int node, num, x;

  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    no[i].p = NIL;
    no[i].l = NIL;
    no[i].r = NIL;
  }
  
  for(i = 0; i < n; i++){
    scanf("%d%d", &node, &num);
    for(j = 0; j < num; j++){
      scanf("%d", &x);
      if(j == 0){
	no[node].l = x;
      }else{
	no[m].r = x;
      }
      m = x;
      no[x].p = node;
    }
  }
  
  for(i = 0; i < n; i++){
    if(no[i].p == NIL){
      k = i;
    }
  }

  depth(k, 0);
  
  for(i = 0; i < n; i++){
    output(i);
  }
  
  return 0;
}



Measured memory_bytes: 6368
n = int(input())
a_lst = [int(elem) for elem in input().split()]

dic = {}
for i in range(n):
    if not i - a_lst[i] in dic:
        dic[i - a_lst[i]] = 1
    else:
        dic[i - a_lst[i]] += 1
        
cnt = 0
for j in range(n):
    if j + a_lst[j] in dic:
        cnt += dic[j + a_lst[j]]

print(cnt)

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

int main()
{
    int n;
    cin >> n;
    // cout << 2 * n << endl;
    map<int, int> a_map;
    rep(i, 0, n)
    {
        int a;
        cin >> a;
        
        a_map[a] += 1;
        // cout << a << "->" << a_map[a] << endl;

    }

    int ans = 0;
    for (auto a_cnt: a_map)
    {
        // cout << a_cnt.first << "->" << a_cnt.second << endl;
        int mono = a_cnt.first;
        int cnt = a_cnt.second;
        if (mono > cnt)
        {
            // zenbukesu
            ans+=cnt;
        }
        else if (mono < cnt)
        {
            ans+= cnt-mono;
        }
        else if (mono == cnt)
        {
ans+=0;
        }
    }
cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4736
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define ll long long

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    int n, x;
    cin >> n >> x;
    while (n != 0 || x != 0) {
        int cnt = 0;
        for (int i = 1; i <= n - 2; i++) {
            for (int j = i + 1; j <= n - 1; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) cnt++;
                }
            }
        }
        cout << cnt << "\n";
        cin >> n >> x;
    }

    return 0;
}



Measured memory_bytes: 3080
#! /usr/bin/env python3

n = int(input())
a = [int(i) for i in input().split()]

maxabs = 0

for i in range(n - 1):
    for j in range(i, n):
        v = abs(a[i] - a[j])
        if v > maxabs:
            maxabs = v

print(maxabs)


Measured memory_bytes: 2940
let input = readLine()!.split(separator: " ").map { Int($0)! }
let A = input[0]
let B = input[1]
let C = input[2]
let K = input[3]

var score = 0
var count = K

score = min(A, count)
count = max(count - A, 0)
count = max(count - B, 0)
score -= count

print(score)


Measured memory_bytes: 8292
#include<stdio.h>
 
int main(void)
{
  char d[3];
  scanf("%s",d);
  int n;
  
  if(d[0]=='S'&&d[1]=='A'&&d[2]=='T'){
    n=1;
  }else if(d[0]=='F'&&d[1]=='R'&&d[2]=='I'){
    n=2;
  }else if(d[0]=='T'&&d[1]=='H'&&d[2]=='U'){
    n=3;
  }else if(d[0]=='W'&&d[1]=='E'&&d[2]=='D'){
    n=4;
  }else if(d[0]=='T'&&d[1]=='U'&&d[2]=='E'){
    n=5;
  }else if(d[0]=='M'&&d[1]=='O'&&d[2]=='N'){
    n=6;
  }else{
    n=7;
  }
  
  printf("%d",n);
  
  return 0;
}

Measured memory_bytes: 128
def solve(aaa):
    bbb = list(map(abs, aaa))
    if 0 in aaa:
        return sum(bbb)
    if sum(1 for a in aaa if a < 0) % 2 == 0:
        return sum(bbb)
    return sum(bbb) - 2 * min(bbb)


n = int(input())
aaa = list(map(int, input().split()))
print(solve(aaa))


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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
pii a[Sz];

int dp[Sz];
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  int n;
  cin >> n;
  int t;
  cin >> t;


  for (int i = 1; i<= n; i++) {
  	int x, y;
  	cin >> x >> y;
  	a[i] = mp(x,y);
  }
  sort(a+1,a+n+1);

  dp[0] = 0;
  for (int i = 1; i <= 6000; i++)
  	dp[i] = -MX;
  for (int i = 1; i<= n; i++) {
  	for (int sum = t-1; sum >= 0; sum--) {
  		if (dp[sum + a[i].first] < dp[sum] + a[i].second)
  			dp[sum+a[i].first] = dp[sum] + a[i].second;
  	}
  }
  cout << *max_element(dp, dp + 6001);

  return 0;
}






// Coded by Z..

Measured memory_bytes: 2304
N=int(raw_input())
S=raw_input()

s=list(S)

i=0
j=0
while i<N and j<N:
    #print i,s
    if s[i]=='(':
        j=i
        while j<N:
            #print i,j
            if s[j]==')':
                s[i]='x'
                s[j]='x'
                #print (i,j),s
                i+=1
                break
            else:
                j+=1
    else:
        i+=1

op=s.count(')')
cl=s.count('(')

print '('*op+S+')'*cl

Measured memory_bytes: 2568
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int N, Y, x = -1, y = -1, z = -1;
	cin >> N >> Y;
	
	
	REP(i, N + 1) {
		REP(j, N - i + 1) {
			if (Y == 10000 * i + 5000 * j + 1000 * (N - i - j)) {
				x = i;
				y = j;
				z = N - i - j;
			}
		}
	}

	cout << x << " " << y << " " << z << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    W = [int(a) for a in input().split()]
    dmin = 10**9
    for T in range(1, N):
        if abs(sum(W[:T])-sum(W[T:])) < dmin:
            dmin =  abs(sum(W[:T])-sum(W[T:]))
    print(dmin)
main()

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

#define index(x, y) ((x) + (y) * (w + 1))
#define out(x, y) ((x) < 0 || (y) < 0 || (x) >= w || (y) >= h)

typedef vector<map<int, int>> graph;

int dijkstra(int s, int g, const graph &G) {
	typedef pair<int, int> P;
	const int n = G.size();

	priority_queue<P, vector<P>, greater<P>> que;
	vector<int> dist(n, INT_MAX);

	que.push(P(0, s));
	dist[s] = 0;

	while(!que.empty()) {
		const int v = que.top().second;
		const int d = que.top().first;
		que.pop();

		if(dist[v] < d) continue;
		if(v == g) return d;

		for(const auto &e : G[v]) {
			const int next_dist = d + e.second;
			if(dist[e.first] > next_dist) {
				dist[e.first] = next_dist;
				que.push(P(next_dist, e.first));
			}
		}

	}

	assert(false);
}


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

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

	dir['R'] = 0;
	dir['D'] = 1;
	dir['L'] = 2;
	dir['U'] = 3;

	int w, h, n;
	cin >> w >> h >> n;

	const int V = (w + 1) * (h + 1);
	graph G(V, map<int, int>());

	for(int x = 0; x <= w; ++x) {
		for(int y = 0; y <= h; ++y) {
			if(x < w) G[index(x, y)][index(x + 1, y)] = G[index(x + 1, y)][index(x, y)] = 0;
			if(y < h) G[index(x, y)][index(x, y + 1)] = G[index(x, y + 1)][index(x, y)] = 0;
		}
	}

	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;

	for(int i = 0; i < n; ++i) {
		int x, y, t;
		string pattern;
		cin >> x >> y >> t >> pattern;

		for(int j = 0; j < t; ++j) {
			for(const auto &c : pattern) {
				const int d = dir[c];
				const int nx = x + dx[d];
				const int ny = y + dy[d];

				if(out(nx, ny)) continue;

				const int mx = max(x, nx);
				const int my = max(y, ny);

				const int v = (x == nx ? index(mx + 1, my) : index(mx, my + 1));
				const int u = index(mx, my);
				++G[v][u];
				++G[u][v];

				x = nx;
				y = ny;
			}
		}
	}

	cout << dijkstra(index(sx, sy), index(gx, gy), G) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 62856
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;

int main(){
    int n, w, h, x, y, s, t;
    while(cin >> n, n){
        cin >> w >> h;
        int mat[h+1][w+1];
        memset(mat, 0, sizeof(mat));
        for(int i = 0; i < n; i++){
            cin >> x >> y;
            mat[y][x]++;
        }
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                mat[i][j] += mat[i-1][j]+mat[i][j-1]-mat[i-1][j-1];
            }
        }
        cin >> s >> t;
        int ans = 0;
        for(int i = t; i <= h; i++){
            for(int j = s; j <= w; j++){
                ans = max(ans, mat[i][j]-mat[i][j-s]-mat[i-t][j]+mat[i-t][j-s]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n;
	cin>>n;
	n=n%1000;
	if(n)
        n=1000-n;
	cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 3652
import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

a,b,c=map(int,input().split())
n=math.gcd(a,b)
ans=make_divisors(n)
print(ans[-c])

Measured memory_bytes: 9432
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
int main(){
    int N;
    int a[104];
    cin >> N;
    REP(i,N){cin >>a[i];}
    sort(a,a+N);
    cout << a[N-1]-a[0] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int t,d,l;
    while(cin >> t >> d >> l){
        if(t + d + l == 0)break;
        vector<int>v(t);
        for(auto && e : v ) cin >> e;
        int ans = 0;
        int lim = 0;
        rep(i,t){
            if(v[i] >= l){
                ans += (i < lim);
                lim = i + d + 1;
            } else if(i < lim){
                ans++;
            }
        }
        cout << ans << endl;
    }
}





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

int map[123][123];
int ans[123][123];

int main(){
	int h, w;
	char buf;
	memset(ans, 255, sizeof(ans));
	scanf("%d%d", &h, &w);
	for (int a = 0; a < h; a++){
		scanf("%d", &buf);
		for (int b = 0; b < w; b++){
			scanf("%c", &buf);
			switch (buf){
			case '.':
					map[a][b] = 0;
					break;
			case 'c':
				map[a][b] = 1;
				break;
			}
		}
	}
	for (int a = 0; a < h; a++){
		for (int b = 0; b < w; b++){
			if (map[a][b] == 1){
				for (int c = 0; c < w - b; c++){
					ans[a][b + c] = c;
				}
			}
		}
	}
	for (int a = 0; a < h; a++){
		printf("%d", ans[a][0]);
		for (int b = 1; b < w - 1; b++){
			printf(" %d", ans[a][b]);
		}
		printf(" %d\n", ans[a][w - 1]);
	}
	return 0;
}

Measured memory_bytes: 2840
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn=100005;

int n,q,cnt;
vector<int>G[maxn];
int fa[maxn],dep[maxn],size[maxn],son[maxn];
int top[maxn],id[maxn],rk[maxn];
ll seg[4*maxn],lazy[4*maxn];

void dfs1(int u,int p) {
    fa[u]=p;
    dep[u]=dep[p]+1;
    size[u]=1;
    for (int v:G[u]) {
        if (v==p) continue; 
        dfs1(v,u);
        size[u]+=size[v];
        if (size[son[u]]<size[v])
            son[u]=v;
    }
}

void dfs2(int u,int t) {
    top[u]=t;
    id[u]=++cnt;
    rk[cnt]=u;
    if (son[u]) dfs2(son[u],t);
    for (int v:G[u])
        if (v!=son[u] && v!=fa[u])
            dfs2(v,v);
}

void add(int id,int l,int r,int ql,int qr,int v) {
    if (lazy[id]) {
        seg[id]+=lazy[id]*(r-l+1);
        if (l!=r) {
            lazy[id<<1]+=lazy[id];
            lazy[id<<1|1]+=lazy[id];
        }
        lazy[id]=0;
    }
    if (ql==l && qr==r) {
        lazy[id]+=v;
        return;
    }
    int m=l+r>>1;
    if (qr<=m) add(id<<1,l,m,ql,qr,v);
    else if (ql>m) add(id<<1|1,m+1,r,ql,qr,v);
    else {
        add(id<<1,l,m,ql,m,v);
        add(id<<1|1,m+1,r,m+1,qr,v);
    }
    seg[id]=seg[id<<1]+seg[id<<1|1]+lazy[id<<1]*(m-l+1)+lazy[id<<1|1]*(r-m);
}

ll query(int id,int l,int r,int ql,int qr) {
    if (lazy[id]) {
        seg[id]+=lazy[id]*(r-l+1);
        if (l!=r) {
            lazy[id<<1]+=lazy[id];
            lazy[id<<1|1]+=lazy[id];
        }
        lazy[id]=0;
    }
    if (ql==l && qr==r) return seg[id];
    int m=l+r>>1;
    if (qr<=m) return query(id<<1,l,m,ql,qr);
    else if (ql>m) return query(id<<1|1,m+1,r,ql,qr);
    else return query(id<<1,l,m,ql,m)+query(id<<1|1,m+1,r,m+1,qr);
}

void update(int v,int w) {
    while (top[1]!=top[v]) {
        add(1,1,n,id[top[v]],id[v],w);
        v=fa[top[v]];
    }
    add(1,1,n,id[1],id[v],w);
}

ll getsum(int u) {
    ll res=0;
    while (top[1]!=top[u]) {
        res+=query(1,1,n,id[top[u]],id[u]);
        u=fa[top[u]];
    }
    res+=query(1,1,n,id[1],id[u]);
    return res;
}

int main() {
    cin>>n;
    for (int i=1;i<=n;i++) {
        int m; cin>>m;
        for (int j=0;j<m;j++) {
            int v; cin>>v; ++v;
            G[i].pb(v);
        }
    }
    dfs1(1,0);
    dfs2(1,1);
    cin>>q;
    for (int i=0;i<q;i++) {
        bool op; cin>>op;
        if (op) {
            int u; cin>>u; ++u;
            cout<<getsum(u)-getsum(1)<<'\n';
        }
        else {
            int v,w; cin>>v>>w; ++v;
            update(v,w);
        }
    }
}



Measured memory_bytes: 21620
w = int(input())
s = [i for i in range(1,w+1)]
n = int(input())
for i in range(n):
    a = list(map(int, input().split(',')))
    s[a[0]-1],s[a[1]-1] = s[a[1]-1],s[a[0]-1]

for i in s:
    print(i)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    string s; cin >> s;
    string str = s;
    str.pop_back();
    while(str.size() > 1){
        if(str.size() % 2 == 0){
            int n = str.size();
            string A = str.substr(0,n/2);
            string B = str.substr(n/2);
            if(A == B) break;
            str.pop_back();
        }else{
            str.pop_back();
            continue;
        }
    }
    cout << str.size() << endl;
}

Measured memory_bytes: 384
S = input()
S = S[::-1]
pattern = ["dream", "dreamer", "erase", "eraser"]
check = True
while check:
    check = False
    for i in range(len(pattern)):
        if S.startswith(pattern[i][::-1]):
            S = S[len(pattern[i]):]
            check = True
if len(S) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
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 d = sc.nextInt();
		int l = Math.max(a, c);
		int u = Math.min(b, d);
		System.out.println(Math.max(u - l, 0));
	}
}

Measured memory_bytes: 21712
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long int n,k=1,a[100001];
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]==0){
            k=0;
            break;
        }
        if(k>1000000000000000000/a[i]||k==-1){
            k=-1;
        }else{
          k*=a[i];
        }
    }
    cout << k;
  return 0;
}

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

int main(void)
{
    char ch;
    int a[26];
    int tmp;

    for(int i=0;i<26;i++){
        a[i] = 0;
    }

    while(cin >> ch){
        int num = ch - 'A';
        if(num>=0 && num<=25){
            a[num]++;
        }
        else if(num>=32 && num<=57){
            a[num-32]++;
        }
    }

    for(int i=0;i<26;i++){
        printf("%c : %d\n", i+'a', a[i]);
    }
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1000000000000000000;
struct Edge {
    long long from;
    long long to;
    long long cost;
};
void Warshall_Floyd(long long V, vector<vector<long long>>& D) {
    for (long long k = 0; k < V; k++) {
        for (long long i = 0; i < V; i++) {
            for (long long j = 0; j < V; j++) {
                D.at(i).at(j) = min(D.at(i).at(j), D.at(i).at(k) + D.at(k).at(j));
            }
        }
    }
}
int main() {
    long long V, E; cin >> V >> E;
    vector<Edge>G(E);
    vector<vector<long long>>D(V, vector<long long>(V, INF));
    for (long long i = 0; i < V; i++) {
        D.at(i).at(i) = 0;
    }
    for (long long i = 0; i < E; i++) {
        cin >> G.at(i).from >> G.at(i).to >> G.at(i).cost;
        D.at(G.at(i).from).at(G.at(i).to) = G.at(i).cost;
    }
    Warshall_Floyd(V, D);
    for (long long i = 0; i < V; i++) {
        if (D.at(i).at(i) != 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    for (long long i = 0; i < V; i++) {
        for (long long j = 0; j < V; j++) {
            if (D.at(i).at(j) >= 999999802000000000) cout << "INF";
            else cout << D.at(i).at(j);
            if (j != V - 1) cout << ' ';
        }
        cout << endl;
    }
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        #define endl "\n"
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int N, M;
const int MAX_N = 4001;
int dp[MAX_N][MAX_N];
int fact[MAX_N];
int fact_inv[MAX_N];
int bin_pow_mod(int a, int b, int m = M) {
    int ret = 1;
    while (b > 0) {
        if (b & 1) ret = (ret * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return ret;
}
int combination(int n, int r) {
    return fact[n] * fact_inv[n - r] % M * fact_inv[r] % M;
}
void init_fact() {
    fact[0] = 1, fact_inv[0] = 1;
    for (int i = 1; i < MAX_N; ++i) {
        fact[i] = fact[i - 1] * i % M;
        fact_inv[i] = bin_pow_mod(fact[i], M - 2);
    }
}
void calc_dp() {
    dp[0][0] = 1;
    REPF(i, 1, N + 1) {
        dp[i][0] = 1;
        REPF(j, 1, N + 1) {
            dp[i][j] = (dp[i-1][j] + dp[i-1][j-1] + dp[i-1][j] * j) % M;
        }
    }
}
int f(int k) {
    int s = 0;
    REP(i, k + 1) {
        int tmp = dp[k][i] * bin_pow_mod(2, (N - k) * i) % M;
        s = (s + tmp) % M;
    }
    int t = bin_pow_mod(2, N - k, M - 1);
    return s * bin_pow_mod(2, t) % M;
}
signed main() {
    cin >> N >> M;
    init_fact();
    calc_dp();

    int ans = 0;
    REP(i, N + 1) {
        int tmp = combination(N, i) % M * f(i) % M;
        if (i % 2) {
            ans += M - tmp;
        } else {
            ans += tmp;
        }
        ans %= M;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 94208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;

ll MOD=1000000007;



int main(){
	string S;
	cin >> S;
	ll N=S.size();
	ll without=0;
	deque<ll> qcheck;
	for(ll i=0;i<N;i++){
		if(S[i]=='?'){qcheck.emplace_front(i);}
		else {
			ll k=(N-i)%6;if(k==0)k=6;
			ll s=S[i]-'0';
			ll r=pow(10,k-1);
			without+=(s*r)%13;
			without%=13;
		}
	;}
	ll make=(18-without)%13;
	vector<vector<ll>> vec(qcheck.size(), vector<ll>(13, 0));
	for(ll i=0;i<qcheck.size();i++){
		ll k=(N-qcheck[i])%6;if(k==0)k=6;
		if(i==0){
		for(ll j=0;j<10;j++){
			ll r=pow(10,k-1);
		vec[i][(j*r)%13]++;
		}}
		else{
			for(ll t=0;t<13;t++){
			 for(ll j=0;j<10;j++){
				 ll r=pow(10,k-1);
				 vec[i][(j*r+t)%13]+=vec[i-1][t];
				 vec[i][(j*r+t)%13]%=MOD;
			 ;}
			;}
		}
	;}
	if(qcheck.size())
	cout<<vec[qcheck.size()-1][make]%MOD<<endl;
	else {
		if(without==5)cout<<1<<endl;
		else cout<<0<<endl;
	}

return 0;
}  



Measured memory_bytes: 14464
#include<iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
using namespace std;

int main()
{
	vector<string> v(3);
	for(int i=0; i<3; i++) cin >> v[i];

	for(int i=0; i<3; i++) cout << v[i][i];
	std::cout << '\n';

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var str = Console.ReadLine();
            Console.WriteLine((str == "AAA" || str == "BBB") ? "No" : "Yes");
        }
    }
}


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

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

  sort(s.begin(), s.end());
  if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int d,n;

	scanf("%d%d",&d,&n);

	if(d==0){
		if(n==100){
			printf("101\n");
			return 0;
		}
		printf("%d",n);
		return 0;
	}
	if(d==1){
		if(n==100){
			printf("10100\n");
			return 0;
		}
		printf("%d",n*100);
		return 0;
	}
	if(d==2){
		if(n==100){
			printf("1010000\n");
			return 0;
		}
		printf("%ld",n*10000);
		return 0;
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    cin >> n >> x;
  
    int MIN = 10000;
    for(int i=0;i<n;i++){
      int a;
      cin >> a;
      x-=a;
      MIN = min(MIN,a);
    }
  
    cout << n+x/MIN << endl;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);
$input = trim(fgets(STDIN));
$arr = explode(' ', $input);

$sum = array_sum($arr);
$x = $sum * $sum;

$y = 0;
foreach ($arr as $d) {
    $y += $d * $d;
}

echo ($x - $y) / 2;


Measured memory_bytes: 5368
import sys
input = sys.stdin.buffer.readline

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
deg = [0 for _ in range(N)]
dp = [0 for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)
    deg[y - 1] += 1

stack = []

for i in range(N):
    if not deg[i]:
        stack.append(i)

while stack:
    node = stack.pop()
    for adj in graph[node]:
        deg[adj] -= 1
        dp[adj] = max(dp[adj], dp[node] + 1)
        if not deg[adj]:
            stack.append(adj)

print(max(dp))

Measured memory_bytes: 94624
// 2020-09-13 11:51:24
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if (t1 * a1 + t2 * a2 < t1 * b1 + t2 * b2) {
    swap(a1, b1);
    swap(a2, b2);
  }
  ll d1 = t1 * (a1 - b1);
  ll d2 = t2 * (a2 - b2);
  if (d1 + d2 == 0) {
    cout << "infinity" << '\n';
    return;
  } else if (d1 > 0) {
    cout << 0 << '\n';
    return;
  }
  ll ans = (-d1) / (d1 + d2) * 2 + 1;
  if ((-d1) % (d1 + d2) == 0) ans--;
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int N;
    char a;
    cin>>N;
    int s[N],max=0,min=0,now=0;
    for(int i=0;i<N;i++){
        cin>>a;
        if(a=='('){
            s[i]=-1;
        }
        else{
            s[i]=1;
        }
    }
    for(int i=0;i<N;i++){
        now+=s[i];
        if(now>max){
            max=now;
        }
    }
    now=0;
    for(int i=0;i<N;i++){
        now+=s[N-1-i];
        if(now<min){
            min=now;
        }
    }
    for(int i=0;i<max;i++){
        cout<<"(";
    }
    for(int i=0;i<N;i++){
        if(s[i]>0){
            cout<<")";
        }
        else{
            cout<<"(";
        }
    }
    for(int i=0;i<-min;i++){
        cout<<")";
    }
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=sum(a)
sb=sum(b)
if sb<sa:
    print("No")
else:
    cnt=sb-sa
    resa=0
    resb=0
    for i in range(n):
        if b[i]<a[i]:
            resa+=a[i]-b[i]
        else:
            resb+=math.ceil((b[i]-a[i])/2)
    if resa>cnt or resb>cnt:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 74768
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;

int main() {
  int a,b,x;
  cin>>a>>b>>x;
  if(x/a/b*2<=a){
    double h=(double)x/b/a*2;
    printf("%.20lf\n",90.0-atan(h/b)*180.0/PI);
  }else{
    x=a*a*b-x;
    double h=(double)x/a/a*2.0;
    printf("%.20lf\n",atan(h/a)*180.0/PI);
  }
  
}



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

int main() {
  int a,b,c=0;
  cin>>a>>b;
  if(b%2==1)c=1;
  else if(a*4<b)c=1;
  else if(a*2>b)c=1;
  if(c==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3568
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void a_honest_or_dishonest(void) {
	string a, b;
	cin >> a >> b;

	if (a == "H") {
		cout << (b == "H" ? "H" : "D") << endl;
	}
	else {
		cout << (b == "H" ? "D" : "H") << endl;
	}
}

int main()
{
    a_honest_or_dishonest();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define sz size

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

        int n;
        cin>>n;
        vector <int> v(n);
        for(int i=0;i<n;i++)
        {
                cin>>v[i];
        }
        sort(v.begin(),v.end());

        if(n%2==1)
        {
                cout<<"0\n";
        }

        cout<<v[n/2]-v[n/2-1]<<"\n";

        return 0;
}


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

int main(){
  int N;
  string S;
  cin>>N>>S;
  int counter=0;
  int insert_count=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='('){
      counter++;
    }else{
      counter--;
    }
    if(counter<0){
      insert_count++;
      counter++;
    }
  }

  for(int i=0;i<insert_count;i++){
    cout<<'(';
  }
  cout<<S;
  for(int i=0;i<counter;i++){
    cout<<')';
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

using VL = vector<long long>;
using VVL = vector<VL>;

const int mod = 1e9 + 7;
int h, w;

void show(VVL &vv) {
	cout << "------" << endl;
	for (auto v: vv) {
		for (auto x: v) {
			printf("%3lld ", x);
		}
		printf("\n");
	}
}


bool is_inside(int r, int c) {
	return 0 <= r && r < h && 0 <= c && c < w;
}

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

	vector<string> grid(h);
	for (int i = 0; i < h; i++) {
		cin >> grid[i];
	}

	VVL ways(h, VL(w, 0));
	ways[0][0] = 1;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (grid[i][j] != '.') {
				continue;
			}

			for (int k = 0; k < 2; k++) {
				int ni = i + (k == 0 ? 1 : 0);
				int nj = j + (k == 0 ? 0 : 1);

				if (is_inside(ni, nj) && grid[ni][nj] == '.') {
					ways[ni][nj] += ways[i][j];
					ways[ni][nj] %= mod;
				}
			}
		}
	}

	// show(ways);
	cout << ways[h-1][w-1] << endl;
	return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=140010;
int val[N];
int son[N][2];
ll dis[N];
void calcdis(int u,ll Dis)
{
	dis[u]=Dis;
	int s1=son[u][0],s2=son[u][1];
	if(!s1) return;
	calcdis(s1,Dis+ll(val[s1]));calcdis(s2,Dis+ll(val[s2]));
}
struct data
{
	int s,t;
	data(){}
	data(int s,int t):s(s),t(t){}
};
vector<data>q[N];
int work(int u,int mx,int s1,int s2,data que[])
{
	int sz1=(int)q[s1].size(),sz2=(int)q[s2].size();
	int l=0,cnt=0;
	for(int i=0;i<sz1;i++)
	{
		bool flag=false;
		while(l<sz2&&dis[q[s1][i].t]+dis[q[s2][l].s]-(dis[u]<<1)<=ll(mx))
		{
			l++;
			flag=true;
		}
		if(!flag) continue;
		que[cnt++]=data(q[s1][i].s,q[s2][l-1].t);
	}
	return cnt;
}
data que1[N],que2[N];
bool solve(int u,int mx)
{
	q[u].clear();
	int s1=son[u][0],s2=son[u][1];
	if(!s1)
	{
		q[u].push_back(data(u,u));
		return true;
	}
	if(!solve(s1,mx)||!solve(s2,mx)) return false;
	int cnt1=work(u,mx,s1,s2,que1),cnt2=work(u,mx,s2,s1,que2);
	if(!cnt1&&!cnt2) return false;
	int p1=0,p2=0;
	while(p1<cnt1||p2<cnt2)
	{
		if(p1==cnt1) q[u].push_back(que2[p2++]);
		else if(p2==cnt2) q[u].push_back(que1[p1++]);
		else{
			if(dis[que1[p1].s]<dis[que2[p2].s])
			{
				q[u].push_back(que1[p1]);
				while(p2<cnt2&&dis[que2[p2].t]>=dis[que1[p1].t]) p2++;
				p1++;
			}
			else{
				q[u].push_back(que2[p2]);
				while(p1<cnt1&&dis[que1[p1].t]>=dis[que2[p2].t]) p1++;
				p2++;
			}
		}
	}
	return true;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int Fa;scanf("%d%d",&Fa,&val[i]);
		if(!son[Fa][0]) son[Fa][0]=i;
		else son[Fa][1]=i;
	}
	calcdis(1,0ll);
	int l=0,r=1,now=2;
	while(now*2<n)
	{
		now*=2;
		r++;
	}
	r*=2000000;
	int ans;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(solve(1,mid)==true)
		{
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

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

int main() {
    int N, M;
    cin >> N >> M;

    int X[M];
    REP(0, i, M) {
        cin >> X[i];
    }

    sort(X, X + M);

    // REP(0, i, M) {
    //     if (i == 0) {
    //         printf("%d", X[i]);
    //     } else {
    //         printf(", %d", X[i]);
    //     }
    // }
    // printf("\n");

    int D[M - 1];
    REP(0, i, M - 1) {
        D[i] = X[i + 1] - X[i];
    }

    // REP(0, i, M - 1) {
    //     printf("%d\n", D[i]);
    // }

    sort(D, D + M - 1);

    int ans = 0;
    REP(0, i, M - N) {
        ans += D[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
A, B, C, X, Y = map(int, input().split())

if A+B <= 2*C:
    answer = A * X + B * Y
else:
    answer = C * min(X, Y) * 2
    if X < Y:
        answer += min(B, C * 2) * (Y - X)
    else:
        answer += min(A, C * 2) * (X -Y)

print(answer)

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

ll solve(ll val[], ll w[], ll capacity, ll n, vector<vector<ll>>& dp){
	if(capacity==0 || n==0)
		return 0;
	
	if(dp[n][capacity]!=-1)
		return dp[n][capacity];
		
	ll ans=0;
	if(capacity >= w[n-1]) {
		ans = max ( solve(val, w, capacity, n-1, dp), val[n-1] + solve(val, w, capacity-w[n-1], n-1, dp) );
	} else {
		ans = solve(val, w, capacity, n-1, dp);
	}
	return dp[n][capacity] = ans;
}

void solve(){
	ll n, capacity;
	cin >> n >> capacity;
	ll val[n];
	ll w[n];
	
	vector<vector<ll>> dp(n+1, vector<ll>(capacity+1, -1));
	
	for(ll i=0; i<n; i++) {
		cin >> w[i];
		cin >> val[i];
	}
	
	cout << solve(val, w, capacity, n, dp) << "\n";
}

int main(){
	solve();
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5 + 5;
int a[maxn], S[maxn], L[maxn], R[maxn], top;

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
	}
	a[0] = a[n + 1] = -1;
	for(int i = 1; i <= n + 1; i++){
		while(top && a[i] < a[S[top]]){
			R[S[top]] = i - 1;
			top--;
		}
		S[++top] = i;
	}
	for(int i = n; i >= 0; i--){
		while(top && a[i] < a[S[top]]){
			L[S[top]] = i + 1;
			top--;
		}
		S[++top] = i;
	}
	LL ans = 0;
	for(int i = 1; i <= n; i++){
		ans += (LL)(i - L[i] + 1) * (R[i] - i + 1) * a[i];
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    string preS;
    preS += S[0];

    ll ans = 1;
    string tmp;
    for (ll i = 1; i < S.size(); i++) {
        tmp += S[i];
        if (preS != tmp) {
            ans++;
            preS = tmp;
            tmp = "";
        }
    }

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

Measured memory_bytes: 720
#include <iostream>
using namespace std;
int main() {

	int s;
	int m;
	int h;

	cin >> s;

	h = s / 3600;
	s = s - h * 3600;

	m = s / 60;
	s = s - m * 60;

	cout << h << ":" << m << ":" << s << endl;

	return 0;
}


Measured memory_bytes: 3080
// you should probably see at the bottom ..
#include<bits/stdc++.h>

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(3e5 + 10)
#define ff first
#define ss second

using namespace std;

int n, m, k;
map<pair<int, int>, int> val;
vector<pair<int, int>> row(N), col(N);

int give(int i, int j) {
	if (i == n or j == m) return 0;
	return row[i].ff + col[j].ff - val[ {row[i].ss, col[j].ss}];
}

void solve() {
	cin >> n >> m >> k;
	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;
		row[a].ff++;
		col[b].ff++;
		val[ {a, b}]++;
	}

	for (int i = 1; i <= n; i++) row[i].ss = i;
	for (int i = 1; i <= m; i++) col[i].ss = i;

	sort(rrange(row)), sort(rrange(col));
	int ans = 0;
	int i = 0, j = 0;
	while (i < n and j < m) {
		int cur = give(i, j);
		ans = max(ans, cur);
		if (give(i + 1, j) > give(i, j + 1)) i++;
		else j++;
	}
	cout << ans << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

/*
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
*/


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

int main() {

  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a <= k) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }

}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

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


    ll i = 0;
    for(; i < n; i++){
        if(x <= 0) break;
        x -= a[i];
    }

    if(0 != x) i--;
    cout << i << endl;


    return 0;
}



Measured memory_bytes: 256
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    sotmp=sorted(tmp)
    stmp=''.join(sotmp)
    s.append(stmp)

ss=sorted(s)

for word in ss:
    if((word in cnt.keys())==False):
        cnt[word]=0
    else:
        cnt[word]+=1


total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)


Measured memory_bytes: 20200
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
const ll mod=1e9+7;

// int32_t main()
// {
//     int N,W,w[101],v[101];
//     cin>>N>>W;
//     for (int i = 0; i < N; ++i)
//     {
//         cin>>w[i]>>v[i];
//     }

// }

int32_t main()
{
    int n;
    cin>>n;
    int a[n+1],b[n+1],c[n+1];
    for (int i = 1; i <= n; ++i)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[n+1][3];
    memset(dp,0,sizeof(dp));
    dp[1][0]=a[1];
    dp[1][1]=b[1];
    dp[1][2]=c[1];
    
    for (int i = 2; i <= n; ++i)
    {
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
       //cout<<dp[i][0]<<dp[i][1]<<dp[i][2]<<endl;
    }
    cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<endl;
}

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

using namespace std;

long long int n,i,a,b;
long long int dp[100003][2];
vector <int> wektor[100003];
bool visited[100003];

void dfs(int x)
{
    visited[x] = true;
    for(auto q : wektor[x])
    {
        if(!visited[q])
        {
            dfs(q);
            dp[x][1] = (dp[q][0]*dp[x][1])%1000000007;
            dp[x][0] = ((dp[q][0]+dp[q][1])*dp[x][0])%1000000007;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(i=0;i<n-1;i++)
    {
        cin >> a >> b;
        wektor[a].push_back(b);
        wektor[b].push_back(a);
    }
    for(i=0;i<=n;i++)
    {
        dp[i][0]=1;
        dp[i][1]=1;
    }
    dfs(1);
    cout << ((dp[1][1]+dp[1][0])%1000000007);
    return 0;
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        200005
#define mod         1000000007
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if((s[0]==s[1] && s[2]==s[3] && s[1]!=s[2])||(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1])||(s[0]==s[3] && s[1]==s[2] && s[0]!=s[1])){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 256