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

const int N = 2e5 + 5;

int n;
int a[N];

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    int xor_sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        xor_sum ^= a[i];
    }
    for (int i = 0; i < n; i++) {
        cout << (xor_sum ^ a[i]) << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4444
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
#define ll long long int
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for(i=l;i<r;i++)
#define bep(i,l,r) for(i=l;i>=r;i--)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
int main()
{
    io;
    int n;
    cin>>n;
    vector<int>a(n+1);
    vector<int>b(n+1);
    int i,j;
    rep(i,1,n+1)
        cin>>a[i];
    bep(i,n,1)
    {
        int k=0;
        if(a[i])
        {
            for(j=i+i;j<=n;j+=i)
                if(b[j]==1)
                k++;
            if(k%2==0)
            b[i]=1;
        }
        else
        {
            for(j=i+i;j<=n;j+=i)
                if(b[j]==1)
                k++;
            if(k%2)
            b[i]=1;
        }
    }
    vector<int>ans;
    rep(i,1,n+1)
    if(b[i])
    {
        ans.pb(i);
    }
    cout<<ans.size()<<"\n";
    rep(i,0,ans.size())
    cout<<ans[i]<<" ";
    return 0;
}


Measured memory_bytes: 3192
#include<cstdio>
#define N 100000
using namespace std;

int n,q;
long long sum;
int a[N+5];
int main()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&q);
		a[q]++;
		sum+=q;
	}
	scanf("%d",&q);
	for(i=1;i<=q;i++)
	{
		int b,c;
		scanf("%d%d",&b,&c);
		sum+=(c-b)*a[b];
		a[c]+=a[b];
		a[b]=0;
		printf("%lld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 2076
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long
const int N=300010;
const int M=100010;
const int maxn=100000;
using namespace std;

int n;
int a[M],b[M];
LL num[N],tot;

int lowbit(int x){
	return x&(-x);
}

LL GET(int x){
	LL res=num[0];
	while(x>0){
		res+=num[x];
		x-=lowbit(x);
	}
	return res;
}

void ADD(int x){
	while(x<=200000){
		num[x]++;
		x+=lowbit(x);
	}
}

int CHK(int x){
	rep(i,0,200000)num[i]=0;
	ADD(maxn);
	int now=100000;
	LL res=0;
	rep(i,1,n){
		if(a[i]<=x)now++;
		  else now--;
		res+=GET(now-1);
		ADD(now);
	}
	if(res>=(tot/2+1))return 1;
	return 0;
}

int main(){
	scanf("%d",&n);
	tot=(LL)(n+1)*n/2;
	rep(i,1,n)scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1);
	int R=unique(b+1,b+n+1)-b-1;
	int L=1,ans=0;
	while(L<=R){
		int mid=(L+R)>>1;
		if(CHK(b[mid]))R=mid-1,ans=b[mid];
		  else L=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define FASTNIBBA   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define lbnd        lower_bound
#define ubnd        upper_bound
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
#define endl        '\n'
mii m;
void solve()
{
   int n,k; cin>>n>>k;
   vector<pii> v;
   rep(i,0,n)
   {
     int x,y;
     cin>>x>>y;
     v.pb({y,x});
   }
   sort(v.rbegin(),v.rend());
   priority_queue<int,vector<int>,greater<int>> q;
   ll ans=0,cur=0,diff=0;
   rep(i,0,k)
   {
     if(!m[v[i].S]) diff++;
     cur+=v[i].F;
     if(m[v[i].S]) q.push(v[i].F);
     else m[v[i].S]++;
   }
   ans=cur+diff*diff;
   rep(i,k,n)
   {
     if(!q.empty())
     {
       if(m[v[i].S]) continue;
       m[v[i].S]++;
       diff++;
       int temp=q.top();
       q.pop();
       cur-=temp;
       cur+=v[i].F;
       ans=max(ans,cur+diff*diff);
     }
     else break;
   }
   cout<<ans;
}
int main()
{
    FASTNIBBA;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 4212
import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		//Scanner scan = new Scanner(System.in);
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		int n = Integer.parseInt(br.readLine());
		for(int i = 0; i < n ; i++){
			String a = br.readLine();
			a = a.replaceAll("Hoshino","Hoshina");
			System.out.println(a);
		}
	}
}

Measured memory_bytes: 24552
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n; long long a[100000];
  scanf("%d", &n);
  scanf("%lld", &a[0]);
  for(int i = 1; i < n; i++){
    scanf("%lld", &a[i]);
    a[i] += a[i - 1];
  }
    

  long long ans = 0, c = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0 && a[i] + c >= 0){
      ans += a[i] + c + 1;
      c -= a[i] + c + 1;
    }
    if(i % 2 == 1 && a[i] + c <= 0){
      ans += -(a[i] + c) + 1;
      c += -(a[i] + c) + 1;
    }
  }
  long long cnt = 0; c = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 1 && a[i] + c >= 0){
      cnt += a[i] + c + 1;
      c -= a[i] + c + 1;
    }
    if(i % 2 == 0 && a[i] + c <= 0){
      cnt += -(a[i] + c) + 1;
      c += -(a[i] + c) + 1;
    }
  }
  

  printf("%lld\n", ans > cnt ? cnt : ans);

  return 0;
}
  


Measured memory_bytes: 896
N = int(input())
T = [0] * N
for i in range(N):
    T[i] = int(input())

import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm(*T))

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

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long Int;
typedef pair<Int,Int> P;

Int gcd(Int x, Int y){
	if(y == 0) return x;
	return gcd(y, x%y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x,y);
}

bool sosuu(Int x){
	bool b = 1;
	if(x == 1) b = 1;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0){b = 0; break;}
	}
	return b;
}

string s;

int main(){
	cin >> s;
	bool b = 1;
	bool erase = 0, dreamer = 0;
	string ss[4] = {"dream", "dreamer", "erase", "eraser"};
	for(int i = 0; i < s.size();){
		if(s[i] == 'd'){
			for(int j = 0; j < ss[0].size();j++){
				if(s[i+j] != ss[0][j]){
					b = 0;
					break;
				}
			}
			i += 5;
			dreamer = 1;
		}
		else if(s[i] == 'e'){
			if(s[i+1] != 'r'){b = 0; break;}
			if(!dreamer && s[i+2] != 'a'){b = 0; break;}
			dreamer = 0;
			erase = 1;
			i += 2;
		}
		else if(s[i] == 'a' && erase){
			erase = 0;
			if(s[i+1] != 's' || s[i+2] != 'e'){b = 0; break;}
			else if(s[i+3] == 'r') i++;
			i += 3;
		}
		else {b = 0; break;}
	}
	if(b) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 512
/* メモ   STLについて
 * min(a, b)
 * max(a, b)
 * swap(a, b)
 *
 * sort(vec.begin(), vec.end())
 * reverse(vec.begin(), vec.end())
 *
 * vectorについて
 * vector<型> 配列名(要素数);
 * 例 vector<int> array(N);
 *    vector<char> str(4);  とか
 *
 * 2次元配列について
 * vector<vector<int>> vec(要素数1, vector<int>(要素数2, 初期値))
 * 例 vector<vector<int>> vec(3, vector<int>(4))
 * これで3 * 4の2次元配列ができる
 * 
*/

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

int main() {
  int N, A, B;
  int ans;
  cin >> N >> A >> B;
  ans = N * A;
  if (ans >= B) {
    cout << B << endl;
  } else if (ans < B) {
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define endl "\n"
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const string YES = "";
const string NO = "";

struct edge{
    int id, to;
};

int color[100100];
int _max = -INF;
vector<vector<edge>> g(100100);

void dfs(int v, int p, int pe){
    int cnt = 0;
    for(edge e:g[v]){
        if(e.to == p)continue;
        while(pe!=-1&&cnt == color[pe])cnt++;
        color[e.id] = cnt++;
        dfs(e.to, v, e.id);
    }
    _max = max(_max,cnt);
}

int main() {
    int n;
    cin>>n;
    rep(i,n)color[i] = -1;
    rep(i,n-1){
        int a, b;
        cin >> a >> b; a--; b--;
        g[a].push_back(edge{i, b});
        g[b].push_back(edge{i, a});
    }    
    dfs(0, -1, -1);
    cout << _max << endl;
    rep(i,n-1){
        cout << color[i]+1 << endl;
    }
}


Measured memory_bytes: 8448
N=int(input())
x=[int(i) for i in input().split()]
d=[x[i+1]-x[i] for i in range(N-1)]
ans=0
tmp=0
N1fact=1
mod=10**9+7
def inv(x):
    return pow(x,mod-2,mod)
for i in range(1,N):
    N1fact=(i*N1fact)%mod
for k in range(1,N):
    tmp+=inv(k)
    tmp%=mod
    a1=tmp
    a2=(d[k-1]*N1fact)%mod
    #print(a1,a2)
    ans+=(a1*a2)%mod
    ans%=mod
print(ans)
#print(N1fact)
#print((ans*N1fact)%mod)

Measured memory_bytes: 14252
import java.lang.Math

fun main(args: Array<String>) {
    val mod = 1000000007L
    val N = readInputLine().toInt()
    val T = readInputLine().split(" ").map { it.toLong() }.toLongArray()
    val A = readInputLine().split(" ").map { it.toLong() }.toLongArray()

    val Tmin = LongArray(N) { 1L }
    val Tmax = LongArray(N) { 1L }

    Tmin[0] = T[0]
    Tmax[0] = T[0]

    for (i in 1 until N) {
        Tmax[i] = Math.max(Tmax[i - 1], T[i])
        if (T[i - 1] != T[i]) {
            Tmin[i] = T[i]
        }
    }

    val Amin = LongArray(N) { 1L }
    val Amax = LongArray(N) { 1L }

    Amin[N - 1] = A[N - 1]
    Amax[N - 1] = A[N - 1]

    for (i in N - 2 downTo 0) {
        Amax[i] = Math.max(Amax[i + 1], A[i])
        if (A[i] != A[i + 1]) {
            Amin[i] = A[i]
        }
    }

    var ans = 1L
    for (i in 0 until N) {
        val min = Math.max(Tmin[i], Amin[i])
        val max = Math.min(Tmax[i], Amax[i])

        if (max < min) {
            println(0)
            return
        }

        ans *= max - min + 1L
        ans %= mod
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main() {
    int A, B; cin >> A >> B;
    if (1 != A && 1 != B) {
        cout << 1 << endl;
    } else if (2 != A && 2 != B) {
        cout << 2 << endl;
    } else if (3 != A && 3 != B) {
        cout << 3 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
#define DIV0 1000000007
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    REPD(i,1,n+1){
        ans += (ll)i * (n/i)*(n/i+1)/2;
    }
    fin(ans);
    return 0;
}

Measured memory_bytes: 3156
w,a,b=map(int,input().split())
if a+w<b:
            print(b-(a+w))
elif a>b+w:
            print(a-(b+w))
elif a+w==b:
            print(0)
elif a<b<a+w<b+w:
            print(0)
elif a==b:
            print(0)
elif b<a<b+w<a+w:
            print(0)
else:
            print(0)


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

int N, M;
vector<int> g[8];
bool b[8];

int rsearch(int depth, int cur)
{
	if(b[cur] == true){
		return 0;
	} else if(depth == N-1){
		return 1;
	} else {
		b[cur] = true;
		int res = 0;
		for(auto it=g[cur].begin(); it!=g[cur].end(); it++){
			res += rsearch(depth+1, *it);
		}
		b[cur] = false;
		return res;
	}
}

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

	for(int ni=0; ni<N; ni++){
		b[ni] = false;
	}

	for(int mi=0; mi<M; mi++){
		int a, b;
		cin >> a >> b;
		g[a-1].push_back(b-1);
		g[b-1].push_back(a-1);
	}

	cout << rsearch(0, 0) << endl;

	return 0;
}


Measured memory_bytes: 256
d,G=map(int,input().split())
l=[list(map(int,input().split())) for i in range(d)]
ans=1000
for i in range(2**d):
    g=0
    t=0
    ncp=[1,0]
    for j in range(d):
        if i>>j&1:
            g+=l[j][0]*(j+1)*100+l[j][1]
            t+=l[j][0]
        else:
            ncp=[(j+1)*100,l[j][0]]
    t+=max(min(-(-(G-g)//ncp[0]),ncp[1]),0)
    g+=max(min(-(-(G-g)//ncp[0]),ncp[1]),0)*ncp[0]
    if g>=G:
        ans=min(ans,t)
print(ans)

Measured memory_bytes: 41328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


inline void solve(){

    int n,w[1005];
    int sum[1000]={};
    int mini=INF;
    cin >> n;
    FOR(i,n){
        cin >> w[i];
        sum[i+1] = sum[i]+w[i];
    }
    iFOR(i,1,n){
        chmin(mini,abs((sum[n]-sum[i])-(sum[i])));
    }

    cout << mini fin;
        

  

}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


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

int count_2(int n) {
    int cnt = 0;
    while ((n & 1) == 0) {
        n >>= 1;
        cnt++;
    }
    return cnt;
}

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

    int cnt = INT_MAX;
    for (int i = 0; i < N; i++) {
        int t; cin >> t;
        cnt = min(cnt, count_2(t));
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
		
			int[] ans = new int[3];
			
			ans[sc.nextInt() - 1 ]  = 1;
			ans[sc.nextInt() - 1 ] = 1;
			
			for(int i = 0 ; i < 3 ; i++ ) {
				if ( ans[i] == 0 ) {
					System.out.println(i+1);
				}
			}

		}
	}

}

Measured memory_bytes: 35632
fn rec(x: usize, v: &mut Vec<usize>) {
    if x == 1 {
        return;
    }

    let div = (2..(x as f64).sqrt() as usize + 1)
        .find(|i| x % i == 0)
        .unwrap_or(x);
    v[div] += 1;
    rec(x / div, v);
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let n: usize = buf.trim().parse().unwrap();
    let mut v = vec![0_usize; n + 1];
    for i in 2..n + 1 {
        rec(i, &mut v);
    }

    let mut ans = 1;
    for &i in v.iter() {
        ans *= i + 1;
        ans %= 1_000_000_007;
    }
    println!("{}", ans);
}


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

using namespace std;

unsigned long calc(unsigned long n)
{
  n += n * 0.01;

  return n;
}

int main()
{
  unsigned long x;
  unsigned long n = 100ul;
  unsigned long year = 0ul;
  cin >> x;

  while (true)
  {
    if (n < x)
    {
      n = calc(n);
      year += 1ul;
    }
    else
    {
      cout << year;
      break;
    }
  }

  return 0;
}

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

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("input.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL);
#define fix cout << fixed << setprecision(15);
//#define left left228
//#define right right228
//#define next next228
#define rank rank228
//#define prev prev228
#define y1 y1228
#define dout if(debug) cout
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
using vll = vector<ll> ;
using vpii = vector<pii> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const int nmax = 1e6 + 577;
const ll basell = 1e18 + 3;
const int mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int nv = 100505;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(ld a, ld b) { return fabs(a-b) < 1e-9; }
inline bool IF(int a, int b, int c) { return (a >= b && a <= c); }
inline bool IFS(int a, int b, int c) { return (a > b && a < c); }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//typedef pair<int, int> pt;
//#define x first
//#define y second
//ifstream cin("input.txt");
//ofstream cout("output.txt");
/*
sort(a, a + n, [&](pair<pt, int> a, pair<pt, int> b){if (a.x.x != b.x.x)
        return a.x.x < b.x.x; return a.x.y > b.x.y;});
for(int c : s)
for(int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
__int128;
char 0 = int 48;
char c = cin;
int h = (int)c - 48;
*/

/*char memory[(int)1e8];

char memorypos;

inline void * operator new(size_t n){
    char * ret = memory + memorypos;
    memorypos += n;
    return (void *)ret;
}

inline void operator delete(void *){}
*/

int dp[nv][3];

int inline solve() {
    //input;//,output;
    //fix;
    fast_io;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        dp[i + 1][0] = max(dp[i][1] + b, dp[i][2] + c);
        dp[i + 1][1] = max(dp[i][0] + a, dp[i][2] + c);
        dp[i + 1][2] = max(dp[i][0] + a, dp[i][1] + b);
    }
    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
    return 0;
}

int32_t main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
    return 0;
}
/*
6
2 1 6 3 4 5
2 1 3 4 5 6
6 0
1 7 8 2 4 6
 * */

Measured memory_bytes: 1408
// luogu-judger-enable-o2
const
  dx:array[1..8]of -1..1=(-1,1,0,0,-1,-1,1,1);
  dy:array[1..8]of -1..1=(0,0,-1,1,-1,1,-1,1);
var
  n,m,i,j:longint;
  a:array[0..101,0..101]of longint;
  s:string;
function dfs(h,l:longint):longint;
var
  i,count:longint;
begin
  count:=0;
  for i:=1 to 8 do
  if a[h+dx[i],l+dy[i]]=1 then inc(count);
  dfs:=count;
end;
begin
  readln(n,m);
  for i:=1 to n do
  begin
    readln(s);
    for j:=1 to m do if s[j]='#' then a[i,j]:=1
    else a[i,j]:=2;
  end;
  for i:=1 to n do
  begin
    for j:=1 to m do
    if a[i,j]=1 then write('#')
    else write(dfs(i,j));
    writeln;
  end;
end.

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

	public Main() {
		FastScanner scanner = new FastScanner();
		int N = scanner.nextInt();
		long[] L = new long[N];

		for (int i = 0; i < N; i++) {
			L[i] = scanner.nextLong();
		}

		int Ans = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				if (L[i] == L[j]) continue;
				for (int k = j+1; k < N; k++) {
					if (L[i] == L[k] || L[j] == L[k]) continue;

					if (L[i] + L[j] <= L[k]) continue;
					if (L[i] + L[k] <= L[j]) continue;
					if (L[j] + L[k] <= L[i]) continue;

					Ans++;
				}
			}
		}

		System.out.println(Ans);
	}

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

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 32968
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X, K, D = MAP()

if D*K < abs(X):
    print(abs(X)-D*K)
else:
    times, d = divmod(abs(X), D)
    if times%2 == K%2:
        print(d)
    else:
        print(abs(d-D))


Measured memory_bytes: 10020
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n;
ll a[1000005],b[1000005],sum,tot;
int main(){
	in(n);
	for(int i=1;i<=n;i++){
		in(a[i]);
		a[i]=a[i]*2;
		sum=sum+a[i];
	}
	sum=sum/2;
	if(n==3){
		printf("%lld %lld %lld\n",sum-a[2],sum-a[3],sum-a[1]);
		return 0;
	}
	tot=a[1];
	for(int i=4;i<n;i+=2)tot=tot+a[i];
	b[3]=sum-tot;
	b[2]=a[2]-b[3];
	b[1]=a[1]-b[2];
	for(int i=4;i<=n;i++){
		b[i]=a[i-1]-b[i-1];
	}
	for(int i=1;i<=n;i++)printf("%lld ",b[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 6144
def main():
    n = int(input())
    a = list(map(int,input().split()))

    ans = 0
    from collections import Counter
    cnt = Counter(a)
    lim = max(a) + 1
    tmp = [0] * (lim)
    # set_a = list(set(a))
    # set_a.sort()
    a.sort()

    for aa in a:
        if tmp[aa] == 0:
            for j in range(lim):
                if aa * j > lim-1:
                    break
                tmp[aa*j] = 1

            if cnt[aa] == 1:
                # print(aa, ans)
                ans += 1




    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 38736
import math
a, b, x = list(map(int, input().split()))

h = x / (a*a)

if h > b / 2:
    ans = math.degrees(math.atan((b-h) / (a/2)))
else:
    ans = math.degrees(math.atan(a*b*b/(2*x)))

print(ans)


Measured memory_bytes: 38384
//MISHON69
//DATE:6/22/2020
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[20],b[20],c[19];
  for(int i=0;i<n;i++){
     cin>>a[i];
  }
  for(int i=0;i<n;i++){
     cin>>b[i];
  }
  for(int i=0;i<n-1;i++){
    cin>>c[i];
  }
  int sum=0;
  for(int i=0;i<n;i++){
     int temp1=a[i]-1;
      int temp2=a[i]-2;
     if(i==0){
        sum+=b[temp1];
     }
     else if(a[i]==a[i-1]+1){
        sum+=b[temp1]+c[temp2];
     }
     else
    sum+=b[temp1];
     
  }
  cout<<sum<<endl;

}  


Measured memory_bytes: 3612
// Vicfred
// https://atcoder.jp/contests/abc177/tasks/abc177_d
// union find, data structures
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;

class UnionFind {                                // OOP style
private:
  vi p, rank, setSize;                           // vi p is the key part
  int numSets;
public:
  UnionFind(int N) {
    p.assign(N, 0); for (int i = 0; i < N; ++i) p[i] = i;
    rank.assign(N, 0);                           // optional speedup
    setSize.assign(N, 1);                        // optional feature
    numSets = N;                                 // optional feature
  }

  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }

  int numDisjointSets() { return numSets; }      // optional
  int sizeOfSet(int i) { return setSize[findSet(i)]; } // optional

  void unionSet(int i, int j) {
    if (isSameSet(i, j)) return;                 // i and j are in same set
    int x = findSet(i), y = findSet(j);          // find both rep items
    if (rank[x] > rank[y]) swap(x, y);           // keep x 'shorter' than y
    p[x] = y;                                    // set x under y
    if (rank[x] == rank[y]) ++rank[y];           // optional speedup
    setSize[y] += setSize[x];                    // combine set sizes at y
    --numSets;                                   // a union reduces numSets
  }
};

int main() {
    int n, m;
    cin >> n >> m;

    UnionFind friends(n);

    int a, b;
    for(int i = 0; i < m; ++i) {
        cin >> a >> b;
        a -= 1;
        b -= 1;

        friends.unionSet(a, b);
    }

    int ans = 0;
    for(int i = 0; i < n; i++)
        ans = max(ans, friends.sizeOfSet(i));

    cout << ans << endl;

    return 0;
}



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

#define ll long long int
#define vi vector<int>
#define ii pair< int , int >
#define vii vector<ii>
#define FOR(i, n) for(ll i = 0; i < (ll)n; i++)
int MAX(int a, int b){return (a > b) ? a:b;}
int MIN(int a, int b){return (a < b) ? a:b;}
int ABS(int x){return (x > 0) ? x:-x;}
int left(int x){return (x<<1);}
int right(int x){return (x<<1)+1;}
int lsone(int x){return (x&(-x));}

const int maxn = 1e5 + 5;
const ll MOD = 1e9 + 7;

int n;
vector<int> ne[maxn], c[maxn];
ll ans[maxn][2];
bool found[maxn][2];

int dp(int pos, bool last){
	if(found[pos][last]) return ans[pos][last];
	found[pos][last] = true;
	// Try if white
	ll tmp = 1;
	for(auto i : c[pos]){
		tmp = (tmp*dp(i, false))%MOD;
	}
	ans[pos][last] = tmp;
	// Try if black
	if(last == false){
		tmp = 1;
		for(auto i : c[pos]){
			tmp = (tmp*dp(i, true))%MOD;
		}
		ans[pos][last] = (ans[pos][last]+tmp)%MOD;
	}
	return ans[pos][last];
}

void buildTree(int pos, int prv){
	for(auto i : ne[pos]){
		if(i == prv) continue;
		c[pos].push_back(i);
		buildTree(i, pos);
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n-1; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		ne[u].push_back(v);
		ne[v].push_back(u);
	}
	buildTree(1, 0);
	printf("%lld\n", dp(1, 0));
}

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

using ll = long long;
using P = pair<ll,ll>;

int main() {
    int n; cin >> n;
    vector<P> data(n);
    for (int i = 0; i < n; i++) cin >> data[i].first >> data[i].second;

    int check;
    for (int i = 0; i < n; i++) {
        int comp = ( abs(data[i].first) + abs(data[i].second) ) % 2;
        if ( i == 0 ) check = comp;
        else if ( check != comp ) {
            cout << -1 << endl;
            return 0;
        }
        data[i] = make_pair(data[i].first + data[i].second, data[i].first - data[i].second);
    }

    vector<ll> dist;
    for (int i = 30; i >= 0; i--) dist.push_back(1ll<<i);
    if ( check == 0 ) dist.push_back(1ll);
    cout << (int)dist.size() << endl;
    for (int i = 0; i < (int)dist.size(); i++) cout << dist[i] << (i == (int)dist.size() - 1 ? "\n" : " ");

    for (int i = 0; i < n; i++) {
        bool to_x, to_y;
        ll sum_x = 0, sum_y = 0;
        ll goal_x = data[i].first, goal_y = data[i].second;
        for (int j = 0; j < (int)dist.size(); j++) {
            if ( sum_x < goal_x ) { to_x = 1; sum_x += dist[j]; }
            else { to_x = 0; sum_x -= dist[j]; }
            if ( sum_y < goal_y ) { to_y = 1; sum_y += dist[j]; }
            else { to_y = 0; sum_y -= dist[j]; }
            
            if (to_x && to_y) cout << "R";
            else if (to_x) cout << "U";
            else if (to_y) cout << "D";
            else cout << "L";
        }
        cout << endl;
    }
    return 0;
}


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

int main(){
  int w,h,x,y,r;cin >> w >> h >> x >> y >> r;
  if(x >= r && x <= w-r && y >= r && y <= h-r)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3108
eps :: Double
eps = 1e-10

main :: IO ()
main = do
  [a, b] <- fmap (map read . words) getLine
  let low = ceiling $ (-eps) + max (12.5 * a) (10 * b)
      high = floor $ (-eps) + min (12.5 * a + 12.5) (10 * b + 10)
  putStrLn $ show $ if low <= high then low else -1

Measured memory_bytes: 508
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N, a, i, ans = 0;
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &a);
		while(a % 2 == 0){
			ans++;
			a /= 2;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  
  vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(2,vector<ll>(n+1,0)));
  dp[0][0][0] = 1;
  rep(i,n){
    ll y=s[i]-'1';
    rep(f,2){
      rep(g,k+1){
	if(f==0){
	  if(y==-1){
	    dp[i+1][0][g] += dp[i][f][g];
	  }
	  else {
	    dp[i+1][0][g+1] += dp[i][f][g];
	    dp[i+1][1][g+1] += dp[i][f][g]*y;
	    dp[i+1][1][g] += dp[i][f][g];
	  }
	}
	else{
	  dp[i+1][1][g+1] += dp[i][f][g]*9;
	  dp[i+1][1][g] += dp[i][f][g];
	}
      }
    }
  }

  cout << dp[n][0][k]+dp[n][1][k] << "\n";
  
  return 0;
}


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

using namespace std;

typedef double fl;

int main()
{
  fl w,h;
  int x,y;
  cin >> w >> h >> x >> y;

  fl mmax = (w*h)/2;
  int flag = 0;
  //fl ans=0;

  if((x+x)==w&&(y+y)==h){
    flag = 1;
  }
  
  cout << mmax << " " << flag << endl;
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	string s,t; cin >> s >> t;
	bool ok=true;
	map<char,char> ma,ma2;
	for(int i=0;i<s.size();i++){
		if(ma.count(s[i])){
			if(ma[s[i]]!=t[i])ok=false;
		}
		if(ma2.count(t[i])){
			if(ma2[t[i]]!=s[i])ok=false;
		}
		ma[s[i]]=t[i],ma2[t[i]]=s[i];
	}
	if(ok){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 776
use std::io;

fn main(){
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin
        .read_line(&mut buf)
        .unwrap();
    let v: Vec<i64> = buf.split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();

    let ans = if v[2] + v[0] < v[1] {
        v[1] - (v[2] + v[0])
    } else if v[2] > v[1] + v[0] {
        v[2] - (v[1] + v[0])
    } else {
        0
    };

    println!("{:?}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
inline int newline() { putchar('\n'); return 0; }

int main() {
    ll k;
    string s;
    cin(k);
    cin(s);

    if (s.size() <= k) {
        print(s);
    } else {
        string sx = s.substr(0, k);
        sx += "...";
        print(sx);
    }

    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 100000
#define SENTINEL 200000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX /2+2],R[MAX /2+2];

void merge(struct Card A[],int n,int left, int mid,int right){
  int i,j,k;
  int n1 = mid-left;
  int n2 = right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1].value =R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
    }
  }
}
void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t= A[i+1];A[i+1]=A[r];A[r]=t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s%d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit)stable=0;
  }

  if(stable==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  return 0;
}



Measured memory_bytes: 4128
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 200005
 
int n;
long long a[N];
 
inline long long cnt(long long x) {
    long long ans = 0;
    for (int i = 0; i < n; ++i)
        if (!a[i]) ans += x >= 0 ? n - i - 1 : 0;
        else if (a[i] < 0) ans += std::min(n - i - 1, (int)(a + n - std::lower_bound(a, a + n, (long long)std::ceil((long double)x / a[i]))));
        else if (a[i] > 0) ans += std::max(0, (int)(std::upper_bound(a, a + n, (long long)std::floor((long double)x / a[i])) - a - i - 1));
    return ans;
}
 
int main() {
    long long k;
    scanf("%d%lld", &n, &k);
    for (int i = 0; i < n; ++i) scanf("%lld", a + i);
    std::sort(a, a + n);
    long long l = -1e18, r = 1e18;
    while (l < r) {
        long long mid = l + r >> 1;
        if (cnt(mid) < k) l = mid + 1;
        else r = mid;
    }
    printf("%lld\n", l);
    return 0;
}

Measured memory_bytes: 1792
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let q: usize = sc.cin();
    let mut neigh = vec![vec![]; n];
    for _ in 0..n-1 {
        let a: usize = sc.cin();
        let b: usize = sc.cin();
        neigh[a-1].push(b-1);
    }
    let mut df = vec![0; n];
    for _ in 0..q {
        let p: usize = sc.cin();
        let x: u64 = sc.cin();
        df[p-1] += x;
    }

    let mut ans = vec![0; n];
    let mut stack = vec![(0usize, 0u64)];
    while let Some((u, ac)) = stack.pop() {
        let z = ac + df[u];
        ans[u] = z;
        for &v in neigh[u].iter() {
            stack.push((v, z));
        }
    }
    put!(..ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 23940
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

int main()
{
    ll n;
    cin >> n;

    ll l, prev, pprev;

    prev = 1;
    pprev = 2;

    if (n==1)
    {
        cout << prev << endl;
        return 0;
    }

    for (ll i=2; i<=n; i++)
    {
        l = prev + pprev; 
        pprev = prev;
        prev = l;
        //cout << l << ' ' << prev << ' ' << pprev << endl;
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 384
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

if N == 1:
	print(sum(A1) + sum(A2))

else:
	B1 = [0 for i in range(N)]
	B2 = [0 for i in range(N)]

	B1[0] = A1[0]
	for i in range(1, N):
		B1[i] = B1[i - 1] + A1[i]

	B2[0] = B1[0] + A2[0]
	for i in range(1, N):
		B2[i] = max(B1[i], B2[i - 1]) + A2[i]

	print(B2[N - 1])

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	k, x := readInt(), readInt()

	if k*500 >= x {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
/* 
    Author : Jeff Ahn
    Sat 15 Aug 2020 05:32:17 AM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
int x, k, d;

signed main() {
  fastio;
  cin >> x >> k >> d;
  if (x < 0) x = -x;
  int m = x / d;
  if (m < k) {
    x -= m * d;
    k -= m;
    if (k % 2) {
      x = min(abs(x + d), abs(x - d));
    }
  } else {
    x -= d * k;
  }
  cout << x << endl;
  return 0;


}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(void){
  int K,A,B;
  cin>>K;
  cin>>A>>B;
  for(int i=1;i*K<=B;++i){
    if(A<=K*i&&K*i<=B){
      cout<<"OK\n";
    return 0;
    }
  }
  cout<<"NG\n";
  
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,a,b,max_a=0,ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a >> b;
    if(a>max_a) {
      max_a=a;
      ans=a+b;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q,a[101010],b[101010],c[101010],p[101010];
long long ans,m;
set<int>st;
int zg(int x)
{
	if(p[x]==x)
	{
		return x;
	}
	p[x]=zg(p[x]);
	return p[x];
}
void gz(int x,int y)
{
	x=zg(x);
	y=zg(y);
	if(x!=y)
	{
		p[x]=y;
	}
}
int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<n;i++)
	{
		p[i]=i;
	}
	for(int i=0;i<q;i++)
	{
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		if(c[i]==0)
		{
			gz(a[i],b[i]);
		}
	}
	for(int i=0;i<q;i++)
	{
		if(c[i]==1)
		{
			if(m==n-1)
			{
				cout<<"No"<<endl;
				return 0;
			}
			if(zg(a[i])==zg(b[i]))
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	ans=n-1;
	for(int i=0;i<n;i++)
	{
		st.insert(zg(i));
	}
	long long sz=st.size();
	ans+=sz*(sz-1)/2-sz+1;
	if(ans<m)
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 9868
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<ll>> v(3, vector<ll>(n));
    rep(i, n) cin >> v[0][i] >> v[1][i] >> v[2][i];

    ll ans = 0;
    for(int bit=0; bit<(1<<3); bit++){
        vector<ll> s(n);
        rep(i, 3){
            if(bit & (1<<i)) rep(j, n) s[j] += v[i][j];
            else rep(j, n) s[j] -= v[i][j];
        }
        sort(rall(s));
        ll sum = 0;
        rep(i, m) sum += s[i];
        ans = max(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
char buf[1800000],f[5];
sz,osz;
#define rd(x)x=0;for(;;){k=buf[sz++];if(k<'0')break;x=x*10+k-'0';}
N,M,L,Q;
D[301][301];
i,j,k;
a,b,c;
main()
{
	read(0,buf,1800000);
	rd(N);rd(M);rd(L);
	for(i=0;i<N;i++)for(j=0;j<N;j++)D[i][j]=1000000001;
	for(i=0;i<M;i++)
	{
		rd(a);rd(b);rd(c);
		--a;
		--b;
		D[a][b]=D[b][a]=c;
	}
	for(k=0;k<N;++k)for(i=0;i<N;++i)for(j=0;j<N;++j)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	for(i=0;i<N;++i)for(j=0;j<N;++j)D[i][j]=D[i][j]>L?1000000000:1;
	for(k=0;k<N;++k)for(i=0;i<N;++i)for(j=0;j<N;++j)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	rd(Q);
	for(i=0;i<Q;++i)
	{
		rd(a);rd(b);
		--a;
		--b;
		if(D[a][b]<1000000000)
		{
			c=D[a][b]-1;
			k=0;
			do{
				f[k++]=c%10+'0';
				c/=10;
			}while(c);
			for(j=k-1;j>=0;--j)buf[osz++]=f[j];
		}
		else buf[osz++]='-',buf[osz++]='1';
		buf[osz++]='\n';
	}
	write(1,buf,osz);
}

Measured memory_bytes: 2176