akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const char cINF = 'z'+1;

struct Segment{
  
  int n,suji[600000];
  char moji[600000];
  
  void init(int size){
    n = 1;
    while(n < size) n <<= 1;
    fill(suji,suji+n,0);
    fill(moji,moji+n,cINF);
  }

  void update(int k,char c){
    k += n-1;
    moji[k] = c;
    while(k > 0){
      k = (k-1)/2;
      moji[k] = min(moji[k*2+1],moji[k*2+2]);
    }
  }
  
  char query(int a,int b,int k,int l,int r){
    if(r < a || b < l) return cINF;
    if(a <= l && r <= b){
      
      return moji[k];
    }
    char nl = query(a,b,2*k+1,l,(l+r)/2);
    char nr = query(a,b,2*k+2,(l+r)/2+1,r);
    return min(nl,nr);
  }
  
  char query(int a,int b){
    return query(a,b,0,0,n-1);
  }
  
  void add(int k,int a){
    k += n-1;
    suji[k] += a;
    while(k > 0){
      k = (k-1)/2;
      suji[k] = suji[k*2+1]+suji[k*2+2];
    }
  }
  
  int sum(int a,int b,int k,int l,int r){
    if(r < a || b < l) return 0;
    if(a <= l && r <= b) return suji[k];
    int nl = sum(a,b,2*k+1,l,(l+r)/2);
    int nr = sum(a,b,2*k+2,(l+r)/2+1,r);
    return nl+nr;
  }
  
  int sum(int b){
    return sum(b,n-1,0,0,n-1);
  }
  
};

int main(){
  
  string s;
  int k;
  
  Segment seg;
  vector<int> vec[30];
  int cnt[30]={};
  
  cin >> s >> k;
  seg.init(s.size());

  for(int i=0;i<s.size();i++){
    seg.update(i,s[i]);
    vec[s[i]-'a'].push_back(i);
  }
  
  char c;
  int ind,l,r,mid,hasi;
  for(int i=0;i<s.size();i++){
    
    l = 0;
    r = s.size()-1;
    hasi = 0;
    while(l <= r){
      mid = (l+r)/2;
      
      if( (mid-i)+seg.sum(mid) > k){
	r = mid-1;
      } else {
	hasi = max(hasi,mid);
	l = mid+1;
      }
      
    }
    
    c = seg.query(0,hasi);
    cout << c;
    
    ind = vec[c-'a'][ cnt[c-'a'] ];
    cnt[c-'a']++;

    k -= ind-i+seg.sum(ind);
    seg.update(ind,cINF);
    seg.add(ind,1);
    
  }
  cout << endl;

  return(0);
}



Measured memory_bytes: 6372
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
const int MOD   = 1000000007;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N, M;
    cin >> N >> M;
    ll a = 1, b = 1, ans;
    if (abs(N - M) > 1) {
        cout << 0 << endl;
        return 0;
    }
    REP(i, N) {
        a *= (i + 1);
        a %= MOD;
    }
    REP(i, M) {
        b *= (i + 1);
        b %= MOD;
    }
    ans = a * b;
    if (N == M)
        ans *= 2;
    ans %= MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use proconio::input;

// use std::f64::consts::PI;
use std::cmp::*;
// use std::collections::*;
// use proconio::marker::Chars;
// const MOD: u64 = 1000000007;
// const INF_I64: i64 = 92233720368547758;
// const INF_USIZE: usize = 18446744073709551;

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

fn main() {
    input! {
        k:i32,
        s:i32

        // s: String
        // s: Chars
        // n: i64
    }
    let mut ans = 0;
    for x in 0..k + 1 {
        for y in 0..k + 1 {
            let z = s - (x + y);
            if z >= 0 && z <=k {
                ans += 1;
            }
        }
    }
    echo!(ans);
}


Measured memory_bytes: 2128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll x1,y1,x2,y2;
	scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);
	ll dx=x2-x1,dy=y2-y1;
	ll px=x2,py=y2;
	rep(i,0,2){
		//(2,1)->(-1,2)
		ll t=dx;
		dx=-dy;
		dy=t;
		printf("%lld %lld ",px+=dx,py+=dy);
	}
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

int main() {
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
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; }
const long long INF = 1LL << 60;

int main() {
	long long L, R;
	cin >> L >> R;

	long long res = 2018;
	if (R - L > 4000) {
		cout << 0 << endl;
		exit(0);
	}

	for (long i = L; i < R; i++) {
		for (long long j = i+1; j < R + 1; j++)
		{
		   res = min(res, (i*j) % 2019);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
char a[100100];
int ans=0;
int main()
{
	gets(a);
	int n=strlen(a);
	for(int i=1;i<=n;i++)if(a[i]!=a[i-1])ans++;
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main()
{

    int x, y;
    cin >> x >> y;
    int sum = 0;

    for (int i = 0; i <= x; i++) {
        sum = 0;
        sum = sum + 4 * (x - i);
        sum = sum + 2 * (i);

        if (sum == y) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 3608
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
x=0
for i in range(N):
  if A[i]+A[i+1]<=B[i]:
    x+=A[i]+A[i+1]
    A[i+1]=0
  elif A[i]>=B[i]:
    x+=B[i]
  elif A[i]<B[i]:
    x+=B[i]
    A[i+1]=A[i]+A[i+1]-B[i]
print(x)    

Measured memory_bytes: 18396
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] adjMatrix = new int[n][n];
        for (int i = 0; i < n; i++) {
            int u = in.nextInt();
            int k = in.nextInt();
            for (int j = 0; j < k; j++) {
                int neighbor = in.nextInt();
                adjMatrix[u-1][neighbor-1] = 1;
            }
        }
        System.out.print(printMatrix(adjMatrix));
    }

    private static String printMatrix(int[][] matrix) {
        StringBuilder sb = new StringBuilder();
        for (int[] i : matrix) {
            StringBuilder line = new StringBuilder();
            for (int j : i) {
                line.append(j).append(" ");
            }
            line.deleteCharAt(line.length()-1);
            line.append("\n");
            sb.append(line);
        }
        return sb.toString();
    }
}



Measured memory_bytes: 29344
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
const int maxn = 1000000 + 10;
const int N = maxn << 1;
const int maxE = 3000000;
const int INF = 0x3f3f3f3f;

int n, h[N], ecnt, tot, S, T;
struct enode{
	int v, n, w, op;
	enode() {}
	enode(int _v, int _n, int _w, int _op):v(_v), n(_n), w(_w), op(_op) {}
}e[maxE << 1];

inline void addedge(int u, int v, int w) {
	ecnt ++; e[ecnt] = enode(v,h[u],w,ecnt + 1); h[u] = ecnt;
	ecnt ++; e[ecnt] = enode(u,h[v],0,ecnt - 1); h[v] = ecnt;
}

int level[N], q[N << 1], cur[N];
inline bool bfs() {
	memset(level,0,sizeof(level));
	int head = 1, tail = 0;
	level[S] = 1; q[++ tail] = S;
	for(int i = S;i <= tot;i ++) cur[i] = h[i];
	while(head <= tail) {
		int u = q[head]; head ++;
		for(int i = h[u];~ i;i = e[i].n) {
			int v = e[i].v;
			if(!level[v] && e[i].w > 0) {
				level[v] = level[u] + 1;
				q[++ tail] = v;
				if(v == T) return 1;
			}
		}
	}
	return 0;
}

int dfs(int u, int c) {
	if(u == T || c == 0) return c;
	int tmp = 0;
	for(int i = h[u];~ i;i = e[i].n) {
		int v = e[i].v;
		if(level[v] == level[u] + 1) {
			int x = dfs(v,min(c,e[i].w));
			if(x) {
				e[i].w -= x; e[e[i].op].w += x;
				tmp += x; c -= x;
				if(!c) break;
			}
		}
	}
	if(!tmp) level[u] = -1;
	return tmp;
}

int pre[maxn], used[maxn], lis[maxn];
vector<int> g[maxn], from[maxn];

int main() {
	scanf("%d", &n); tot = n;
	S = 0; T = ++ tot; ecnt = 0;
	memset(h,-1,sizeof(h));
	for(int i = 2;i <= n;i ++) addedge(i,T,1);
	for(int i = 1;i < n;i ++) {
		int p = ++ tot;
		addedge(S,p,1);
		int k; scanf("%d", &k);
		for(int j = 1;j <= k;j ++) {
			int x; scanf("%d", &x);
			g[i].push_back(x);
			from[x].push_back(i);
			addedge(p,x,INF);
		}
	}
	int flow = 0;
	while(bfs())
		flow += dfs(S,INF);
	if(flow < n - 1) {
		puts("-1");
		return 0;
	}
	for(int u = 2;u <= n;u ++) {
		for(int i = h[u];~ i;i = e[i].n) {
			int v = e[i].v;
			if(v != T && e[i].w) lis[v - n - 1] = u;
		}
	}
	int head = 1, tail = 0;
	q[++ tail] = 1; pre[1] = -1;
	while(head <= tail) {
		int u = q[head]; head ++;
		for(int i = 0, Sz = from[u].size();i < Sz;i ++) {
			int id = from[u][i];
			if(used[id]) continue;
			used[id] = 1;
			int v = lis[id];
			pre[v] = u;
			q[++ tail] = v;
		}
	}
	for(int i = 2;i <= n;i ++) {
		int u = lis[i - 1], v = pre[u];
		printf("%d %d\n", u, v);
	}
	return 0;
}


Measured memory_bytes: 95360
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
int find(vector<int>& grp, int x) {
    if (grp[x] != x)
        return find(grp, grp[x]);
    return x;
}
int main() {
    int N, x, y;
    cin >> N;
    unordered_map<int, vector<int>> x_axis;
    unordered_map<int, vector<int>> y_axis;
    vector<vector<int>> arr;
    for(int i = 0; i < N; i++) {
        cin >> x >> y;
        arr.push_back({x, y});
        x_axis[x].push_back(i);
        y_axis[y].push_back(i);
    }
    vector<int> grp(N, 0);
    for(int i = 0; i < N; i++)
        grp[i] = i;
    for(auto& p: x_axis) {
        auto& vec = p.second;
        if (vec.size() > 1) {
            for(int i = 1; i < vec.size(); i++) {
                int r0 = find(grp, vec[0]);
                int r = find(grp, vec[i]);
                // union
                grp[r0] = grp[r] = min(r0, r);
            }
        }
    }
    for(auto& p: y_axis) {
        auto& vec = p.second;
        if (vec.size() > 1) {
            for(int i = 1; i < vec.size(); i++) {
                int r0 = find(grp, vec[0]);
                int r = find(grp, vec[i]);
                // union
                grp[r0] = grp[r] = min(r0, r);
            }
        }
    }
    unordered_map<int, vector<int>> grp2;
    for(int i = 0; i < N; i++) {
        // cout << find(grp, grp[i]) << " ";
        grp2[find(grp, grp[i])].push_back(i);
    }
    ll ans = 0;
    for(auto& p: grp2) {
        vector<int>& vec = p.second;
        unordered_set<int> cnt_x;
        unordered_set<int> cnt_y;
        for(auto& i: vec) {
            cnt_x.insert(arr[i][0]);
            cnt_y.insert(arr[i][1]);
        }
        ans += (ll)cnt_x.size() * (ll)cnt_y.size() - (ll)vec.size();
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 19504
#include<stdio.h>
int main()
{
	int y, x, r, box;

	scanf("%d %d", &y, &x);
	if (x < y) {
		box = x;
		x = y;
		y = box;
	}

	r = x%y;
	while (r > 0) {
		x = y;
		y = r;
		r = x%y;
	}

	printf("%d\n", y);


    return 0;
}

Measured memory_bytes: 1844
#   AtCoder abc045 a
#   ストレッチ課題

#   入力
top = int(input())      # 上底の長さ
bottom = int(input())   # 下底の長さ
height = int(input())   # 高さ

#   処理
area = int((top + bottom) * height / 2)

#   出力
print(area)


Measured memory_bytes: 9020
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v.at(i);
  sort(ALL(v));
  double ans = 0;
  rep2(i, 1, n){
    ans += v.at(i)/(pow(2, (n-i)));
  }
  ans += v.front()/pow(2, n-1);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 4192
N, A, B = map(int, input().split())
S = input()

pass_user_num = 0
f_pass_user_num = 0

for index, user in enumerate(S):
    if user == 'a' and pass_user_num < (A+B):
        print('Yes')
        pass_user_num += 1
    elif user == 'b' and pass_user_num < (A+B) and f_pass_user_num < B:
        print('Yes')
        pass_user_num += 1
        f_pass_user_num += 1
    else:
        print('No')


Measured memory_bytes: 4016
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



const int NUM = 2000000;
bool IsPrime[NUM];

void Era(int n) {
	IsPrime[0] = false; 
	IsPrime[1] = false; 
	for (int i = 2; i < NUM; ++i) {
        IsPrime[i] = true;
    }
	for (int i = 2; i <= n; ++i) {
		if (IsPrime[i]) {
			for (int j = i*2; j <= n; j += i) IsPrime[j] = false;
		}
	}
}

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    Era(1200000);
    
    int a,d,n;
    while (cin >> a >> d >> n) {
        if (a == 0 && d == 0 && n == 0) break;
        int con = 0, res = a;
        for (res = a; res < 1200000; res += d) {
            if (IsPrime[res]) {
                ++con;
            }
            if (con == n) break;
        }
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 1e6 + 9;
const int INF = 1e9 + 239;
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, -1, 1};

int d[N];
vector<pair<int, int>> g[N];

int n, m;

int ok(int i, int j) {
	return i >= 0 && j >= 0 && i < n && j < m;
}

int bfs(int st, int en) {
	deque<int> q;
	fill(d, d + n * m, INF);
	d[st] = 0;
	q.push_back(st);
	while (!q.empty()) {
		int v = q.front();
		q.pop_front();
		for (auto [u, w] : g[v]) {
			if (d[u] > d[v] + w) {
				d[u] = d[v] + w;
				if (!w) {
					q.push_front(u);
				} else {
					q.push_back(u);
				}
			}
		}
	}
	return d[en];
}

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

	cin >> n >> m;
	int i1, j1, i2, j2;
	cin >> i1 >> j1 >> i2 >> j2;
	i1--;
	j1--;
	i2--;
	j2--;
	vector<vector<int>> a(n, vector<int> (m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			a[i][j] = (c == '.');
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int di = -2; di <= 2; di++) {
				for (int dj = -2; dj <= 2; dj++) {
					int ni = i + di;
					int nj = j + dj;
					if (ok(ni, nj) && a[i][j] == 1 && a[ni][nj] == 1) {
						g[i * m + j].push_back({ni * m + nj, 1});
					}
				}
			}
			for (int k = 0; k < 4; k++) {
				int ni = i + dx[k];
				int nj = j + dy[k];
				if (ok(ni, nj) && a[i][j] == 1 && a[ni][nj] == 1) {
					g[i * m + j].push_back({ni * m + nj, 0});
				}	
			}
		}
	}
	int ans = bfs(i1 * m + j1, i2 * m + j2);
	if (ans == INF) {
		cout << -1 << '\n';
	} else {
		cout << ans << '\n';
	}
}

Measured memory_bytes: 123384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll mod = 998244353;

int main()
{
  ll n, s; cin >> n >> s;
  vector<ll> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  vector<vector<ll>> dp(n+2, vector<ll>(s+1, 0));
  ll ans = 0;
  rep(i, n) {
    (dp[i][0] += 1) %= mod;
    (dp[i+1][0] += 1) %= mod;
    rep(j, s+1-a[i]) {
      (dp[i+1][j+a[i]] += dp[i][j]) %= mod;
    }
    (ans += dp[i+1][s]) %= mod;
    dp[i+2] = dp[i+1];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70784
#include <stdio.h>
#include <stdbool.h>

#define N_MAX 50
#define INF 1145141919
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

int i, j;

int n, m;
int q;

bool max[N_MAX * N_MAX];
bool d[N_MAX][N_MAX];

void solve(){
	return;
}

int main (void) {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b && a == c) {
		puts("1");
	} else if (((a == b) && (a != c)) || ((a != b) && (a == c)) || ((b == c) && (a != b))) {
		puts("2");
	} else {
		puts("3");
	}
	return 0;
}




Measured memory_bytes: 128
import java.util.*;

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

        int a_pos=0;
        for(int i=0; i<s.length; i++){
            if(s[i].equals("A")){
                a_pos = i;
                break;
            }
        }
        
        int z_pos=0;
        for(int i=s.length-1; i>=0; i--){
            if(s[i].equals("Z")){
                z_pos = i;
                break;
            }
        }

        int ans = z_pos - a_pos;
        
        System.out.println(ans+1);
        
    }
}

Measured memory_bytes: 55080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;
using Graph = vector<vector<ll>>;

Graph G;
ll N, Q;
vector<ll> P;
vector<ll> cost;
bool f[200010];

void dfs(ll v, ll c)
{
	if (f[v]) return;
	f[v] = true;
	cost[v] += c;

	for (auto &nv : G[v])
	{
		dfs(nv, c+P[nv]);
	}
}

int main(int argc, char **argv)
{
	cin >> N >> Q;

	G.resize(N);
	for (ll i = 0; i < N-1; ++i)
	{
		ll a, b; cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	P.assign(N, 0);
	for (ll i = 0; i < Q; ++i)
	{
		ll v, c; cin >> v >> c;
		--v;
		P[v] += c;
	}

	cost.assign(N, 0);
	memset(f, 0, sizeof f);
	dfs(0, P[0]);

	for (ll i = 0; i < N; ++i)
		std::cout << cost[i] << " ";
	std::cout << std::endl;
}


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

int main() {

	while (1) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		}
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				cout << "#";
				}
			cout << endl;
		}
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <vector>
#include <string>
#define FIN freopen("inputs.txt", "r", stdin)
using namespace std;
typedef pair<int, int> P;

int main(){
//FIN;
    int h, a;
    cin>>h>>a;
    int ans = h/a;
    ans = h%a == 0?ans:ans + 1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws IOException{
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int[] a = new int[x];
        for(int i=0; i<x; i++) {
        	a[i] = sc.nextInt();
        }

        int y = sc.nextInt();
        int[] b = new int[y];
        for(int i=0; i<y; i++) {
        	b[i] = sc.nextInt();
        }

        int[] c = new int[x+1];
        for(int i=0; i<x; i++) {
        	c[i] = a[i];
        }

        int sum = 0;
        for(int i=0; i<y; i++) {
        	c[x] = b[i];
        	if(serch(c, x, b[i])) {
        		sum++;
        	}
        }

        System.out.println(sum);

        sc.close();
    }

    public static boolean serch(int[] c, int x, int b) {
    	int i = 0;
    	while(c[i]!=b) {
    		i++;
    	}
    	return i!=x;
    }
}


Measured memory_bytes: 40164
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  if (s[0] >= 'A' && s[0] <= 'Z')
    cout << "A\n";
  else {
    cout << "a\n";
  }
}

Measured memory_bytes: 3644
import sys
N,Y = map(int,input().split())
for x in range(0,N+1):
    for y in range(0,N+1-x):
        if 10000*x+5000*y + (N-x-y)* 1000 == Y:
            print('%d %d %d' % (x,y,N-x-y))
            sys.exit(0)
print('-1 -1 -1')


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

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int main(){
   int a,b;scanf("%d%d",&a,&b);
   printf("%d",a+b>a-b?(a+b>a*b?a+b:a*b):(a-b>a*b?a-b:a*b));
}

Measured memory_bytes: 128
class Node:
    def __init__(self, key:int):
        self.key = key
        self.p = None
        self.left = None
        self.right = None

class Tree:
    def __init__(self):
        self.root = None

    def insert(self, z:Node):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.left
            else:
                x = x.right
        z.p = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.left = z
        else:
            y.right = z

def Preorder(target:Node):
    yield target.key
    if target.left != None:
        yield from Preorder(target.left)
    if target.right != None:
        yield from Preorder(target.right)

def Inorder(target:Node):
    if target.left != None:
        yield from Inorder(target.left)
    yield target.key
    if target.right != None:
        yield from Inorder(target.right)

def find(target:Node,findkey:int):
    if target.key == findkey:
        return True
    elif target.key > findkey:
        if target.left:
            return find(target.left, findkey)
    else:
        if target.right:
            return find(target.right, findkey)
    return False

from sys import stdin
tree = Tree()
n = int(input())
lines = stdin.readlines()
for line in lines:
    proc,*key = line.split()
    if proc == "insert":
        tree.insert(Node(int(key[0])))
    elif proc == "find":
        print("yes" if find(tree.root, int(key[0])) else "no")
    else:
        print(" ",end="")
        print(*Inorder(tree.root))
        print(" ",end="")
        print(*Preorder(tree.root))


Measured memory_bytes: 128504
#include<bits/stdc++.h>
#define int long long
#define deb(x) cout << #x << " = " << x << "\n";
using namespace std;

signed main() {
    
    int n; cin >> n;
    int prev = 0, prev2 = 0, cur = 0;
    string ans = "No";
    for(int i = 0, x, y; i < n; i++) {
        cin >> x >> y;
        cur = (x == y);
        if(cur + prev + prev2 == 3) 
            ans = "Yes";
        prev2 = prev;
        prev = cur;
    }
    cout << ans;
}

Measured memory_bytes: 3620
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF = 1e9;
#define MOD = 1e9+7;
#define INF64 = 1e18;


using namespace std;

int main() {

	set<string> SET;
	SINT32 N = 0;
	string S;
	cin >> S;
	cin >> N;

	rep(i,0,S.length()) {
		SINT32 buf = MIN(N+1,S.length()-i+1);
		rep(j,0,buf) {
			SET.insert(S.substr(i,j));
		}
	}

    set<string>::iterator it; //  イテレータを用意
 //   for(it = SET.begin(); it != SET.end(); it++) {
 //       cout << *it << endl;
 //   }


	it = SET.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;

	
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 1664
n = input()
l = list(map(int, input().split()))

maxNum = 0
maxIndex = 0
for i, score in enumerate(l):
    if maxNum < score:
        maxNum = score
        maxIndex = i
l.pop(maxIndex)
if sum(l) > maxNum:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14
 
int main(){
    string s;
    cin >> s;
    string correct_s = "CODEFESTIVAL2016";
    int ans = 0;
    rep(i,s.size())ans += s[i] != correct_s[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;

int f(int n) {
    if (n & 1)
        return 3 * n + 1;
    else
        return n / 2;
}

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

    set<int> a;
    a.insert(s);

    for (int i = 1;; i++) {
        s = f(s);
        if (a.find(s) != a.end()) {
            cout << i + 1 << endl;
            break;
        }
        a.insert(s);
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd( T m, T n ){
    if ( ( 0 == m ) || ( 0 == n ) ) return 0;

    while( m != n ){
        if ( m > n ) m %= n;
        else         n %= m;

        if(m == 0) return n;
        if(n == 0) return m;
    }
    return m;
}

int main()
{
    ll N, K;
    cin >> N >> K;
    ll Ai;
    cin >> Ai;
    ll vgcd = Ai;
    ll vmax = Ai;
    for(int i=1;i<N;i++){
        cin >> Ai;
        vgcd = gcd(vgcd, Ai);
        vmax = max(vmax, Ai);
    }
    if(K<=vmax && K%vgcd==0) cout<<"POSSIBLE"<<endl;
    else                     cout<<"IMPOSSIBLE"<<endl;

    return 0;
}

Measured memory_bytes: 256
//【ライブラリここから】
// 1. 入力の容易化（https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8）
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//【ライブラリここまで】

fn main() {
    input! {n:usize, a:[i64; n]};
    let mut result: i64 = 0;
    let mut remainsum: i64 = 0;

    for i in 0..(n) {
        remainsum += a[i];
        remainsum %= 1000000007;
    }

    for i in 0..(n - 1) {
        remainsum += 1000000007;
        remainsum -= a[i];
        remainsum %= 1000000007;
        result += remainsum * a[i];
        result %= 1000000007;
    }
    println!("{}", result);
}

// 1000000007


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

using namespace std;

using ll = long long;
constexpr int INF = numeric_limits<int>::max() / 2;

int N;
vector<ll> A(1 << 20), sum(1 << 20);
vector<vector<ll>> dp(1 << 20, vector<ll>(2, 0));

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

    cin >> N;
    for (int i = 0; i < (1 << N); i++)
    {
        cin >> A[i];
        dp[i][0] = A[i];
        dp[i][1] = -INF;
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < (1 << N); j++)
        {
            if (j & (1 << i))
            {
                if (dp[j][0] < dp[j ^ (1 << i)][0])
                {
                    dp[j][1] = max(dp[j][0], dp[j ^ (1 << i)][1]);
                    dp[j][0] = dp[j ^ (1 << i)][0];
                }
                else
                {
                    dp[j][1] = max(dp[j][1], dp[j ^ (1 << i)][0]);
                }
            }
        }
    }
    sum[0] = dp[0][0] + dp[0][1];
    for (int i = 1; i < (1 << N); i++)
    {
        sum[i] = max(sum[i - 1], dp[i][0] + dp[i][1]);
        cout << sum[i] << endl;
    }
}


Measured memory_bytes: 76800
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;cin>>s;
    int cnt[3];
    fill(cnt,cnt+3,0);
    rep(i,0,s.size()){
        if(s[i]=='m')cnt[0]++;
        else if(s[i]=='e')cnt[1]++;
        else cnt[2]++;
    }
    if(cnt[0]!=cnt[1]||cnt[1]!=cnt[2]||cnt[2]!=cnt[0]){
        cout<<"Rabbit"<<endl;
        return 0;
    }
    int n=s.size();
    bool dp[n][n+1];
    memset(dp,false ,sizeof dp);
    rep(i,0,n)dp[i][0]=true;
    rep(i,0,n-2){
        string t=s.substr(i,3);
        if(t=="mew")dp[i][3]=true;
        else dp[i][3]=false;
    }
    for(int i=6;i<=n;i+=3){
        rep(j,0,n-i+1){
            int l=j,r=j+i-1;
            int rr=0;
            if(s[l]!='m'||s[r]!='w'){
                dp[j][i]=false;
                continue;
            }
            rep(k,l+1,r){
                if(s[k]=='e'){
                    int m1=k-l-1;
                    int m2=r-1-k;
                    if(dp[l+1][m1]&&dp[k+1][m2]){
                        rr=1;
                        break;
                    }
                }
            }
            if(rr)dp[j][i]=true;
            else dp[j][i]=false;
        }
    }
    if(dp[0][n])cout<<"Cat"<<endl;
    else cout<<"Rabbit"<<endl;
    
}










Measured memory_bytes: 3472
n = int(input())
a = [int(i) for i in input().split()]

sum1 = 0
sum2 = 0

for _ in a:
  sum1 += _
  sum2 += (_*_)
sum1 = (sum1 * sum1)
print(((sum1 - sum2)//2)%1000000007)


Measured memory_bytes: 31436
use proconio::{input, marker::Usize1};

const ALPHA: usize = 26;

fn main() {
    input!(
        dmax: usize,
        c: [i64; ALPHA],
        s: [[i64; ALPHA]; dmax],
        t: [Usize1; dmax]
    );

    let score = |t: Vec<usize>| -> Vec<i64> {
        let mut miss: Vec<i64> = vec![0; ALPHA];
        t.into_iter()
            .enumerate()
            .map(|(d, i)| {
                miss.iter_mut().for_each(|x| {
                    *x += 1;
                });
                miss[i] = 0;
                s[d][i] - c.iter().zip(miss.iter()).map(|(x, y)| x * y).sum::<i64>()
            })
            .scan(0, |acc, x| {
                *acc += x;
                Some(*acc)
            })
            .collect()
    };

    println!(
        "{}",
        score(t.clone())
            .into_iter()
            .map(|x| x.to_string() + "\n")
            .fold("".to_string(), |acc, s| acc + s.as_str())
    );
}


Measured memory_bytes: 2332
import java.util.*;

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

class Solver {

    private int count2(int v, Map<Integer, Integer> m) {
        if (v % 2 == 1) return 0;
        else if (m.containsKey(v)) return m.get(v);
        else {
            int ret = (count2(v/2, m) + 1);
            m.put(v, ret);
            return ret;
        }
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();

        int dx = x2 - x1;
        int dy = y2 - y1;

        int x3 = x2 - dy;
        int y3 = y2 + dx;

        int x4 = x1 - dy;
        int y4 = y1 + dx;

        System.out.println(String.format("%d %d %d %d", x3, y3, x4, y4));

        return;
    }

}

Measured memory_bytes: 21844
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int a[25];
int n, k;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b;
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a+b)% 3 == 0){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl; 
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <map>
using namespace std;

const int MAXN = 2e5 + 10;
int a[MAXN];
map<int, int> vis1, vis2;

int main(void){
	int n, x, m;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &x);
		vis1[x]++;
	}
	scanf("%d", &m);
	for(int i = 0; i < m; i++){
		scanf("%d", &a[i]);
		vis2[a[i]]++;
	}
	bool flag = true;
	for(int i = 0; i < m; i++){
		if(vis1[a[i]] < vis2[a[i]]){
			flag = false;
			break;
		}
	}
	if(flag) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 19712
n, m = map(int,input().split())
numbers = [{} for _ in range(n)]

for i in range(m):
    p, y = map(int,input().split())
    numbers[p-1][i] = y #pで県を指定して、iで順番の情報を保つ

answers = {}

for i in range(n):
    number = numbers[i]
    if len(number) == 0:
        continue
    new_number = sorted(number.items(), key = lambda x : x[1]) #x[1]で誕生ねんでソート
    cnt = 1
    for num in new_number:
        answers[num[0]] = (6-len(str(i+1)))*'0' + str(i+1) + (6-len(str(cnt)))*'0' + str(cnt)
        cnt += 1

answer = sorted(answers.items(), key = lambda x : x[0])

for i in answer:
    print(i[1])

Measured memory_bytes: 59760
import math
n,x=map(int,input().split());l=[abs(x-i) for i in list(map(int,input().split()))]
if len(l)>1:
  r=math.gcd(l[0],l[1])
  for i in range(1,len(l)):
    r=math.gcd(r,l[i])
else:
  print(l[0])
  exit()
print(r)

Measured memory_bytes: 20364
#include <stdio.h>
int main(void){
	char w[100] = {"\0"};
	scanf("%s",w);
	int number[26] = {0};
	for(int a = 0; a < 100; a++){
		if(!w[a]){
			break;
		}
		int difference = w[a] - 'a';
		number[difference] += 1;
	}
	for(int b = 0; b < 26; b++){
		if(number[b]%2 != 0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}


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

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    rep(i, n) {
        cout << s[i] << t[i];
    }
    cout << endl;
}

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    r = I()
    g = I()

    return r+(g-r)*2


print(main())




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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
//using ll = long long;
//using P = pair<int,int>;

long long dp[50];

long long fibonacci(int n){
    if (n == 0) return dp[0];
    if (n == 1) return dp[1];
    
    if(dp[n]) return dp[n];
    
    return dp[n] = fibonacci(n-1) + fibonacci(n-2);
}

int main(){
    int n;
    cin >> n;
    
    dp[0] = 1, dp[1] = 1;
    
    cout << fibonacci(n) << endl;
}


Measured memory_bytes: 3080
#include<stdio.h>

int pai[10];

int Check() {
	int insPai[10];
	int cnt;
	for (int head = 1; head < 10; head++) {
		for (int i = 0; i < 10; i++) {
			insPai[i] = pai[i];
		}
		cnt = 0;
		if (insPai[head] < 2)continue;
		insPai[head] -= 2;
		for (int shunt = 1; shunt < 8; shunt++) {
			if (insPai[shunt] <= 0)continue;
			else if (insPai[shunt + 1] > 0 && insPai[shunt + 2] > 0) {
				insPai[shunt]--; insPai[shunt + 1]--; insPai[shunt + 2]--;
				cnt++;
				shunt--;
			}
		}
		for (int ank = 1; ank < 10; ank++) {
			if (insPai[ank] < 3)continue;
			insPai[ank] -= 3;
			cnt++;
		}
		
		if (cnt == 4) return 1;
	}
	return 0;
}

int Check2() {
	int insPai[10];
	int cnt;
	for (int head = 1; head < 10; head++) {
		for (int i = 0; i < 10; i++) {
			insPai[i] = pai[i];
		}
		cnt = 0;
		if (insPai[head] < 2)continue;
		insPai[head] -= 2;
		for (int ank = 1; ank < 10; ank++) {
			if (insPai[ank] < 3)continue;
			insPai[ank] -= 3;
			cnt++;
		}
		for (int shunt = 1; shunt < 8; shunt++) {
			if (insPai[shunt] <= 0)continue;
			else if (insPai[shunt + 1] > 0 && insPai[shunt + 2] > 0) {
				insPai[shunt]--; insPai[shunt + 1]--; insPai[shunt + 2]--;
				cnt++;
				shunt--;
			}
		}
		if (cnt == 4) return 1;
	}
	return 0;
}

int main() {
	char input[20];
	int flag, flag2;
	int checker[9], pos;
	while (scanf("%s", input)==1) {
		pos = 0;
		for (int i = 0; i < 10; i++)pai[i] = 0;
		for (int i = 0; i < 13; i++) {
			pai[input[i] - 48]++;
		}
		for (int k = 1; k < 10; k++) {
			if (pai[k] == 4)continue;
			pai[k] += 1;
			flag = Check();
			flag2 = Check2();
			pai[k] --;
			if (flag||flag2) { checker[pos] = k; pos++; }
		}
		for (int i = 0; i < pos; i++) {
			printf("%d", checker[i]);
			if (i != pos - 1)printf(" ");
		}
		if (pos == 0)printf("0");
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 1980
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    T = list(map(int, readline().rstrip().split()))
    S = sum(T)
    M = int(readline())
    for _ in range(M):
        p, x = map(int, readline().rstrip().split())
        print(S - T[p-1] + x)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
def popcount(x):
  r = 0
  while x:
    r += 1
    x &= x - 1
  return r
 
n = int(input())
r = range(n)
a = [[0, 0] for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y] |= 1 << (x - 1)
 
m = 0
l = (1 << n) - 1
for x in range(1, l + 1):
  if all(a[i][0] & x == a[i][1] & l - x == 0 for i in r if x >> i & 1):
    m = max(m, popcount(x))
print(m)


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

int main() {
  int color[4];
  rep(i,4) color[i] = 0;
  int n;
  cin >> n;
  rep(i,n) {
    string s;
    cin >> s;
    if (s == "P") color[0]++;
    if (s == "W") color[1]++;
    if (s == "G") color[2]++;
    if (s == "Y") color[3]++;
  }
  int ans = 0;
  rep(i,4) {
    if (color[i] > 0) ans++;
  }
  if (ans == 3) cout << "Three" << endl;
  if (ans == 4) cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

#define F first
#define S second
typedef long long ll;
typedef pair<char, ll> P;

int main()
{
    bool found = 0;
    ll len[3];    
    vector<P> X[3];
    for (int i = 0; i < 3; i++) {
        char c;
        ll l;
        while (cin >> c, c != '$') {
            cin >> l;
            X[i].push_back(P(c, l));
        }
        len[i] = X[i].size();
    }
    for (int i = 0; i <= len[0]-len[1]; i++) {
        bool same = 1;
        for (int j = i; j < i+len[1]; j++) {
            if (X[1][j-i].F != X[0][j].F ||
                (i < j && j < i+len[1]-1 && X[1][j-i].S != X[0][j].S)) {
                same = 0;
                break;
            }
        }
        if (X[0][i].S < X[1][0].S || X[0][i+len[1]-1].S < X[1][len[1]-1].S) {
            continue;
        }

        if (same) {
            vector<P> v, res;
            for (int j = 0; j < i; j++) {
                v.push_back(X[0][j]);
            }
            ll diff = X[0][i].S - X[1][0].S;
            if (len[1] != 1) {
                if (diff > 0) {
                    v.push_back(P(X[0][i].F, diff));      
                }
                for (int j = 0; j < len[2]; j++) {
                    v.push_back(X[2][j]);
                }
                diff = X[0][i+len[1]-1].S - X[1][len[1]-1].S;
                if (diff > 0) {
                    v.push_back(P(X[0][i+len[1]-1].F, diff));
                }
            } else {
                for (int j = 0; j < len[2]; j++) {
                    v.push_back(X[2][j]);
                }                
                if (diff > 0) {
                    v.push_back(P(X[0][i].F, diff));   
                }
            }
            for (int j = i+len[1]; j < len[0]; j++) {
                v.push_back(X[0][j]);
            }
            
            for (int j = 0; j < (int)v.size(); ) {
                ll k = j, sum = 0;
                while (k < (ll)v.size() &&
                       v[j].F == v[k].F) {
                    sum += v[k].S;
                    k++;
                }
                res.push_back(P(v[j].F, sum));
                j = k;
            }
            
            for (int j = 0; j < (int)res.size(); j++) {
                cout << res[j].F << " " << res[j].S << " ";
            }
            cout << "$" << endl;
            found = 1;
            break;
        }
    }
    if (!found) {
        for (int i = 0; i < len[0]; i++) {
            cout << X[0][i].F << " " << X[0][i].S << " ";
        }
        cout << "$" << endl;
    }
    return 0;
}

Measured memory_bytes: 1328
import java.util.Scanner;

public class Main
{
    public static void main(String arg[])
    {
        Scanner sc = new Scanner(System.in);
        String aa = sc.next();
        String bb = sc.next();
        String cc = sc.next();

        int a = Integer.parseInt(aa);
        int b = Integer.parseInt(bb);
        int c = Integer.parseInt(cc);

        if ((a < b) && (b < c))
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }

}


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

#define sz(x)          (int)x.size()
#define en             '\n'
#define sp             ' '
#define input(vec)     for(auto &a: vec)cin >> a;
#define output(vec)    for(auto &a: vec)cout << a << sp;cout << en;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int tc = 1, n, x, i;
    //cin >> tc;

    while(tc--){
        cin >> n;
        vector < int > bruh(n);
        for(i = 0;i < n;i++){
            cin >> x;
            bruh[x-1] = i + 1;
        }
        output(bruh);
    }
    return 0;
}


Measured memory_bytes: 3692
import math
from collections import Counter
n=int(input())
s = [str(sorted(list(input()))) for i in range(n)]
c = Counter(s)
#l=[]
#for si in set(s):
#    l.append(s.count(si))
ans=0
for i in c.values():
    if i>=2:
        x = (math.factorial(i) // (math.factorial(i - 2) * math.factorial(2)))
        ans+=x
print(ans)

Measured memory_bytes: 24556