akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e17;
using P = pair<ll,ll>;

template<typename T, typename E, typename F, typename G, typename H>
class LazySegmentTree {
  int n, height;
  F f; G g; H h; const T ti; const E ei;
  vector<T> dat; vector<E> laz; vector<int> highest;

  void propagate(int k) {
    if(laz[k] != ei) {
      laz[2*k] = h(laz[2*k],laz[k]); laz[2*k+1] = h(laz[2*k+1],laz[k]);
      dat[k] = g(dat[k],laz[k],n/highest[k]);
      laz[k] = ei;
    }
  }
  inline void recalc(int k) {
    while(k >>= 1) dat[k] = f(g(dat[2*k],laz[2*k],n/highest[2*k]),g(dat[2*k+1],laz[2*k+1],n/highest[2*k+1]));
  }
  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }
public:
  LazySegmentTree(int _n, F f, G g, H h, T ti, E ei): f(f), g(g), h(h), ti(ti), ei(ei) {
    n = 1; height = 0;
    while(n < _n) n <<= 1, height++;
    dat.assign(2*n,ti); laz.assign(2*n,ei); highest.assign(2*n,0);
    int c = 1;
    for(int i = 1; i < 2*n; i++) {
      if(c*2 <= i) c <<= 1;
      highest[i] = c;
    }
  }
  void set(int k, T x) {
    dat[k+n] = x;
  }
  void build() {
    for(int i = n-1; i >= 0; i--) {
      dat[i] = f(dat[2*i],dat[2*i+1]);
    }
  }
  void update(int a, int b, const E x) {
    thrust(a += n); thrust(b += n-1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l],x), ++l;
      if(r & 1) --r, laz[r] = h(laz[r],x);
    }
    recalc(a); recalc(b);
  }
  T query(int a, int b) {
    thrust(a += n); thrust(b += n-1);
    T l = ti, r = ti; b++;
    while(a < b) {
      if(a & 1) l = f(l,g(dat[a],laz[a],n/highest[a])), a++;
      if(b & 1) b--, r = f(g(dat[b],laz[b],n/highest[b]),r);
      a >>= 1; b >>= 1;
    }
    return f(l,r);
  }
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<P>> add(n+1), del(n+1); 
  rep(i,m) {
    int l, r; ll a;
    cin >> l >> r >> a;
    add[l].push_back(P(l,a));
    del[r].push_back(P(l,-a));
  } 
  auto f = [](ll a, ll b){return max(a,b);};
  auto g = [](ll a, ll b, int l){return a+b;};
  auto h = [](ll a, ll b){return a+b;};
  LazySegmentTree<ll,ll,decltype(f),decltype(g),decltype(h)> lst(n+1,f,g,h,-INF,0);
  rep(i,n+1) lst.set(i,0);
  lst.build();
  for(int i = 1; i <= n; i++) {
    for(auto k : add[i]) lst.update(0,k.first,k.second);
    lst.update(i,i+1,lst.query(0,i));
    for(auto k : del[i]) lst.update(0,k.first,k.second);
  }
  cout << lst.query(0,n+1) << endl; 
  return 0;
}

Measured memory_bytes: 32384
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  string s;cin>>s;
  cout<<((s=="AAA"||s=="BBB")?"No":"Yes")<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

using namespace std;

int Q, C, A, N;


int solve() {
	int cnt;

	cnt = min(C, min(A, N));
	C -= cnt;
	A -= cnt;
	N -= cnt;
	while (C >= 2 && A >= 1) {
		++cnt;
		C -= 2;
		A -= 1;
	}
	while (C >= 3) {
		++cnt;
		C -= 3;
	}

	return cnt;
}

int main() {

	cin >> Q;
	for (int i = 0; i < Q; ++i) {
		cin >> C >> A >> N;
		cout << solve() << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3104
#include <iostream>
using namespace std;
int main ()
{
	int h, n; 
	cin >> h >> n;
	int zbir = 0; 
	int niz[n];
	for (int i = 0; i < n; i++)
	{	
		cin >> niz[i]; 
		zbir = zbir + niz[i]; 
	}
	if (zbir >= h) cout << "Yes" << endl; 
	else cout << "No" << endl; 
	return 0;
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

ll h, w;
vector<string> field(405);

vector<vector<bool>> was(405,vector<bool>(405,false));

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

bool check(int i,int j,int k){
	int ni = i + dy[k];
	int nj = j + dx[k];
	if(ni < 0 || ni >= h) return false;
	if(nj < 0 || nj >= w) return false;
	if(was[ni][nj]) return false;
	if(field[i][j] == field[ni][nj]) return false;
	return true;
}
int main()
{
	cin >> h >> w;
	rep(i,h) cin >> field[i];

	ll ans = 0;
	queue<P> que;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ll black = 0, white = 0;
			if(was[i][j]) continue;
			que.push({i,j});was[i][j] = true;
			
			if(field[i][j] == '#') black ++;
			else white++;

			while(!que.empty()){
				int si = que.front().first, sj = que.front().second;
				que.pop();

				for(int k = 0; k < 4; k++){
					if(!check(si, sj, k)) continue;
					// push
					int ni = si + dy[k], nj = sj + dx[k];
					que.push({ni,nj});
					was[ni][nj] = true;
					if(field[ni][nj] == '#') black ++;
					else white++;
				}
			}
			ans += black * white;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

int main()
{
    int N, M, C;
    int i, j;
    int cnt = 0;
    vector<int> B;
    
    cin >> N >> M >> C;
    int tmp;
    
    for (i=0; i<M; i++) {
        cin >> tmp;
        B.push_back(tmp);
    }
    int isplus;
    for (i=0; i<N; i++) {
        isplus = 0;
        for (j=0; j<M; j++) {
            cin >> tmp;
            isplus = isplus + tmp * B[j];
        }
        if (isplus + C > 0) {
            cnt++;
        }
    }
    cout << cnt << endl;
    
    //getline(cin, str);
    //vector < vector < int > > A(N, vector<int>(M, 0));
    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
// #define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b, n;
  while (cin >> a >> b >> n) {
    a %= b;
    int s = 0;
    rep(i, n) {
      a *= 10;
      s += a / b % 10;
      a %= b;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 3056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        static void Main()
        {
            int n = NextInt;
            var a = LongList;

            long now0 = a.Sum() - Enumerable.Range(0, n / 2).Sum(i => a[2 * i + 1] * 2);
            long now1 = a.Sum() - Enumerable.Range(0, n / 2).Sum(i => a[2 * i + 2] * 2);
            var list = new List<long> {now0, now1};

            for (int i = 2; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    now0 = now0 + (a[i - 1] - a[i - 2]) * 2;
                    list.Add(now0);
                }
                else
                {
                    now1 = now1 + (a[i - 1] - a[i - 2]) * 2;
                    list.Add(now1);
                }
            }

            System.Console.WriteLine(string.Join("\n", list));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}

Measured memory_bytes: 31324
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll dp[301][301];

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


	int N, M;
	scanf("%d %d", &N, &M);

	int xm[301][4], xM[301][4];
	rep1(i, N) {
		xm[i][1] = N;
		xm[i][2] = N;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l, r, x;
		scanf("%d %d %d", &l, &r, &x);
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	int mj = 0;
	int mk = 0;
	rep1(i, N) {
		for (int j = i - 1; j >= mj; j--) {
			auto dpj = dp[j];
			for (int k = i - 1; k >= max(j, mk); k--) {
				dpj[i] += dpj[k];
				dp[k][i] += dpj[k];
			}
		}

		for (int j = i; j > xm[i][2]; j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xm[i][2]; j > max(xM[i][3], mj - 1); j--) {
			for (int k = i; k > max(max(xm[i][1], mk - 1), j - 1); k--) dp[j][k] = 0;
			if (i % 4 == 0) {
				for (int k = xm[i][1]; k > max(max(xM[i][2], mk - 1), j - 1); k--) {
					dp[j][k] %= mod;
				}
			}
			for (int k = xM[i][2]; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xM[i][3]; j >= mj; j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		if (mj <= xM[i][3]) mj = xM[i][3] + 1;
		if (mk <= xM[i][2]) mk = xM[i][2] + 1;
	}

	ll kotae = 0;
	rep(j, N + 1) rep(k, N + 1) {
		kotae += dp[j][k] % mod;
	}
	printf("%lld", kotae% mod);

	Would you please return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

#define N 3010
#define M 5010
struct edge { ll from, to, cost; };
vector<edge> es(M);

int main() {
  int a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;

}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long yen[] = new long[N];
		long honsu[] = new long[N];
		long total = 0;


		for (int i = 0; i < N; i++) {
			yen[i] = sc.nextInt();
			honsu[i] = sc.nextInt();
		}

		Data []d = new Data[N];
        for(int i= 0; i < N; i++) {
            d[i] = new Data(yen[i],honsu[i]);
        }


		Arrays.sort(d, new Comparator<Data>() {
            public int compare(Data d1, Data d2) {
                return d1.getA() - d2.getA();
            }
        });

		for (int i = 0; i < N; i++) {

			long a = d[i].getB();
			long b = d[i].getA();

			 if(M >= d[i].getB()) {
				 total += a * b;
				 M -= d[i].getB();
			 }else {
				 total += M * b;
				 break;
			 }

		}
		System.out.println(total);
	}

}

class Data{
    private long a;
    private long b;
    public Data(long a, long b) {
        this.a = a;
        this.b = b;
    }
    public int getA() {
        return (int) a;
    }
    public int getB() {
        return (int) b;
    }
}

Measured memory_bytes: 65332
#include <stdio.h>

int main(void){
	int n;
	scanf("%d", &n);
	int v[n], c[n];
	int ans=0;
	for(int i=0;i<n;i++){
		scanf("%d",& v[i]);
	}
	for(int j=0;j<n;j++){
		scanf("%d", &c[j]);
	}
	for(int i=0;i<n;i++){
		if(v[i]-c[i]>0) ans += v[i]-c[i];
	}
	printf("%d", ans);
	return 0;
}

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


int main() {
    int n,k;
    cin >> n >> k;
    double ans=(n<k) ? 0 : 1.0*(n-k+1)/n;
    for (int i=1;i<=min(n,k-1);i++) {
        double ians=1.0/n;
        int p=i;
        while (p<k) {
            p*=2;
            ians *= 0.5;
        }
        ans+=ians;
    }
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
package main

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

func solve() {
	s := bufio.NewReader(os.Stdin)
	pre := 'A'
	count := 0
	for {
		c, _ := s.ReadByte()
		if c != 'B' && c != 'W' {
			break
		}
		if pre != rune(c) {
			count++
		}
		pre = rune(c)
	}
	fmt.Println(count - 1)
	return
}

var sc = bufio.NewScanner(os.Stdin)

func scanString() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}
func Permute(nums []int) [][]int {
	n := factorial(len(nums))
	ret := make([][]int, 0, n)
	permute(nums, &ret)
	return ret
}
func permute(nums []int, ret *[][]int) {
	*ret = append(*ret, makeCopy(nums))

	n := len(nums)
	var i, j int
	for {
		for i = n - 2; i >= 0; i-- {
			if nums[i] < nums[i+1] {
				break
			}
		}
		if i < 0 {
			return
		}
		for j = n - 1; ; j-- {
			if nums[j] > nums[i] {
				break
			}
		}
		nums[i], nums[j] = nums[j], nums[i]
		for k, l := i+1, n-1; k < l; {
			nums[k], nums[l] = nums[l], nums[k]
			k++
			l--
		}
		*ret = append(*ret, makeCopy(nums))
	}
}

func factorial(n int) int {
	ret := 1
	for i := 2; i <= n; i++ {
		ret *= i
	}
	return ret
}

func pow(n, m int) int {
	ret := 1
	for i := 0; i < m; i++ {
		ret *= n
	}
	return ret
}

func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}
func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func eratosthenes(n int) []int {
	search := make([]bool, n+1)
	ans := []int{}
	for i := 2; i < n+1; i++ {
		search[i] = true
	}
	for i := 2; i*i < n+1; i++ {
		for j := 2; i*j < n+1; j++ {
			search[i*j] = false
		}
	}
	for i := 2; i < n; i++ {
		if search[i] {
			ans = append(ans, i)
		}
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	solve()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  co(min(a*b, c));

  return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var ans = (a + b) / 2;
        if ((a + b) % 2 == 0) Console.WriteLine(ans);
        else Console.WriteLine("IMPOSSIBLE");
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	LD rate = 380000.0;
	sll(n);
	LD worth = 0;
	rep(i, 0, n) {
		LD val; cin >> val;
		string curr; cin >> curr;
		if(curr == "BTC")	worth += val * rate;
		else	worth += val;
	}
	cout << setprecision(10) << worth << endl;
}


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

using namespace std;

int main(){

	int m, h[100], j = 0;
	string s[10];

	while (true){

		cin >> s[j];
		if (s[j] == "-")break;
		cin >> m;
		for (int i = 0; i < m; i++){
			cin >> h[i];
		}

		for (int i = 0; i < m;i++){

			s[j] += s[j].substr(0, h[i]);
			s[j].erase(0, h[i]);
		}
		j++;
	}

	for (int i = 0; i < j;i++){
		cout << s[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3196
n = int(input())
s = format(input())

w = 0
e = 0

w_list = [0]
e_list = [0]
for i in range(n):
  if s[i] == "W":
    w += 1
  else:
    e += 1
  w_list.append(w)
  e_list.append(e)

ans = 10**10
for i in range(1, n+1):
  ans = min(ans, w_list[i-1] + (e_list[-1] - e_list[i]))

print(ans)

Measured memory_bytes: 17644
N = int(input())
X = sum(range(1, N))
if N % 2 == 0:
    X -= 1


delete = set()
for n in range(1, N + 1):
    diff = sum(range(1, N + 1)) - X - n
    minus = N - 1
    minus += (N % 2 == 0)
    while diff:
        if (diff - minus < 0) or (minus == n):
            minus -= 1
            continue
        diff -= minus
        delete.add((min(n, minus), max(n, minus)))


ans = []
for n in range(1, N + 1):
    for to in range(n + 1, N + 1):
        if (n, to) in delete:
            continue
        else:
            ans.append([n, to])

print(len(ans))
for a, b in ans:
    print(a, b)


Measured memory_bytes: 4124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

vector<ll> zalgo(string s){
  vector<ll> ret(s.size());
  ll c=0;
  FOR(i,1,s.size()){
	if(i+ret[i-c]<c+ret[c]) ret[i]=ret[i-c];
	else{
	  ll j=max(0ll,c+ret[c]-i);
	  while(i+j<s.size() && s[j]==s[i+j]) j++;
	  ret[i]=j;
	  c=i;
	}
  }
  ret[0]=s.size();
  return ret;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	rep(i,n){
		string t=s.substr(i);
		vector<ll> ret=zalgo(t);
		rep(j,(ll)ret.size()){
			ll now=min(ret[j],j);
			chmax(ans,now);
		}
	}
	cout<<ans<<endl;
}

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


int main() {
    
    int n; cin >> n;
    vector <double> p(n); for(double& pi: p) cin >> pi;
    vector < vector < double > > dp (n+1, vector<double>(n+1));


    dp[0][0] = 1 - p[0]; dp[1][0] = p[0];

    for(int j = 1; j < n; j++)
    {
        dp[0][j] = dp[0][j-1] * (1 - p[j]); 
        for (int i = 1; i <= j+1; i++)
            dp[i][j] = dp[i-1][j-1] * p[j] + dp[i][j-1] * (1 - p[j]);
    }



    double ans = 0;
    for(int i = (n+1)/2; i <= n; i++)
        ans += dp[i][n-1];

    cout.precision(10);
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 70656
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */


#include <string>
#include <iostream>
using namespace std;

class BYYMMOrMMYY {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string s;
        cin >> s;
        bool ok1 = false,ok2 = false;

        string first  = s.substr(0,2);
        string second = s.substr(2,2);
        if ("00" < second && second <= "12"){
            ok1 = true;
        }
        if ("00" < first && first <= "12"){
            ok2 = true;
        }

        if (ok1 && ok2){
            cout << "AMBIGUOUS" << endl;
        }else if (ok1){
            cout << "YYMM" << endl;
        }else if (ok2){
            cout << "MMYY" << endl;
        }else {
            cout << "NA" << endl;
        }
	}
};


int main() {
	BYYMMOrMMYY solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;

void solve(long long H, long long W, std::vector<std::string> A){
    vector<vector<LL>> tab(H, vector<LL>(W, INF));
    int ans = 0;
    deque<pair<int, pair<int, int>>> q;
    rep(i,H){
        rep(j,W){
            if(A[i][j]=='#') {
                q.emplace_back(make_pair(0, make_pair(i, j)));
            }
        }
    }

    vector<vector<int>> dxdy = {{0,1},{0,-1},{1,0},{-1,0}};

    while(!q.empty()){
        auto p = q.front();
        auto i=p.second.first, j=p.second.second;
        auto l0=p.first;
        q.pop_front();

        if(l0 >= tab[i][j])continue;
        tab[i][j]=l0;
        ans = max(l0, ans);
        for(auto d:dxdy){
            auto i2=i+d[0], j2=j+d[1];
            if(i2<0 || j2<0 || i2>=H || j2>=W)continue;
            q.emplace_back(make_pair(l0+1, make_pair(i2, j2)));
        }
    }

    cout << ans << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::string> A(H);
    for(int i = 0 ; i < H ; i++){
        std::cin >> A[i];
    }
    solve(H, W, std::move(A));
    return 0;
}


Measured memory_bytes: 57544
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x)  cerr << #x << ": " << x << endl;
#define rep(i,a)  for(ll i=0; i< a; i++)
#define pb push_back
#define vl vector<ll>
template<typename ForwardIterator, typename T>
ForwardIterator first_less_than (ForwardIterator first, ForwardIterator last, T value) {
auto it = std::upper_bound (first, last, value);
return (it == first ? last : --it);
}
ll bb;
ll modify(ll x)
{
	return ((x%bb)+bb)%bb;
}
const ll N=1e5+5;
int main()
{
	fast;ll t;t=1;
	while(t--)
	{
		ll a,b,c;cin>>a>>b>>c;
		ll k;cin>>k;
		if(b>a && c>b){cout<<"Yes\n";continue;}
		ll z=0;
		if(a>=b)
		{
			while(a>=b)b*=2,z++;
		}
		if(b>=c)
			while(b>=c)c*=2,z++;
		if(z<=k)cout<<"Yes\n";
		else cout<<"No\n";

	}
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String[] ab = x.split(" ");
		
		int a = Integer.parseInt(ab[0]);
		int b = Integer.parseInt(ab[1]);

		if (a < b) System.out.println("a < b");
		if (a > b) System.out.println("a > b");
		if (a == b) System.out.println("a == b");
	}
}

Measured memory_bytes: 24240
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
const int MAXN = 302;
double memo[MAXN][MAXN][MAXN];
int n;

double dp(int i, int j, int k) {
  if (i < 0 || j < 0 || k < 0) return 0;
  double& ans = memo[i][j][k];
  if (ans < -0.5) {
    if (i == 0 && j == 0 && k == 0) {
      ans = 0.0;
    } else {
      ans = 1.0;
      ans += ((double(i)/double(n)) * dp(i - 1, j + 1, k));
      ans += ((double(j)/double(n)) * dp(i, j - 1, k + 1));
      ans += ((double(k)/double(n)) * dp(i, j, k - 1));
      ans = (ans * double(n))/double(i+j+k);
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int a = 0, b = 0, c = 0;
  cin >> n;
  foi (i,0,n) {
    int x; cin >> x;
    a += (x == 3);
    b += (x == 2);
    c += (x == 1);
  }
  foi (i,0,MAXN) {
    foi (j,0,MAXN) {
      foi (k,0,MAXN) {
        memo[i][j][k] = -1.0;
      }
    }
  }
  cout << fixed << setprecision(10) << dp(a,b,c) << '\n';
  return 0;
}


Measured memory_bytes: 215680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  ll ans = 0;
  rep(i, n-1) {
    if (v.at(i) == i+1) {
      swap(v.at(i), v.at(i+1));
      ans++;
    }
  }
  if (v.at(n-1) == n) ans++;
  cout << ans << endl;
}

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

int main(void) {
  int N;
  cin >> N;
  int S = N % 10;
  int t = 1;
  for(int i = 1; i <= 9; i++) {
    t *= 10;
    S += N / t - N / (t * 10) * 10;
  }
  if(N % S == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
//26

int a[300000], s[300000];
signed main(){
	int n, sum = 0, ans = INF;
	scanf("%lld", &n);
	rrep(i,n){scanf("%lld", &a[i]);sum += a[i];}
	rrep(i,n)s[i] += s[i-1]+a[i];
	rrep(i,n){
		int ss = s[i];
		P p[4];
		//p[1] = P(INF, INF);p[3] = P(INF, INF);
		int x = upper_bound(s, s+n+1, s[i]/2)-s;
		//if(i == 2)printf("*%lld*\n", x);
		p[0] = P(s[x], s[i]-s[x]);
		p[1] = P(s[x-1], s[i]-s[x-1]);
		x = upper_bound(s, s+n+1, s[i]+(sum-s[i])/2)-s;
		//if(i == 2)printf("*%lld %lld*\n", s[i]+(sum-s[i])/2, x);
		p[2] = P(s[x]-s[i], sum-s[x]);
		p[3] = P(s[x-1]-s[i], sum-s[x-1]);
		rep(j,2)rep(k,2){
			int mn = min({p[j].fi, p[j].se, p[2+k].fi, p[2+k].se});
			int mx = max({p[j].fi, p[j].se, p[2+k].fi, p[2+k].se});
			ans = min(ans, mx-mn);
			//if(i == 2)printf("%lld %lld\n", mx, mn);
		}
	}
	
	printf("%lld\n", ans);
	return 0;
}





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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst<<": "; dbg(rst...); }


int main()
{
	const double PI = acos(-1);
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VI p(n);
	rep(i, n) cin >>p[i];
	sort(all(p));
	ll ans =0;
	rep(i, k) ans += p[i];
	
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(m);
  rep(i, m){
    int k; cin >> k;
    vec[i].resize(k);
    rep(j, k){
      cin >> vec[i][j];
      --vec[i][j];
    }
  }

  vector<int> p(m);
  rep(i, m){
    cin >> p[i];
  }

  int ans = 0;
  rep(i, 1 << n){
    bool ok = true;
    rep(j, m){
      int c = 0;
      for(int id: vec[j]){
        if(i >> id & 1){
          c++;
        }
      }
      c %= 2;
      if(c != p[j]){
        ok = false;
        break;
      }
    }
    if(ok){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

ll cake[1010][3];

int main(){

    ll N, M;
    cin >> N >> M;
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < 3; j++){
            cin >> cake[i][j];
        }
    }
    ll ans = 0;
    for(ll i = 0; i < (1 << 3); i++){
        vector<P>v(N);
        for(ll j = 0; j < N; j++){
            ll tmp = 0;
            for(ll k = 0; k < 3; k++){
                if(i & (1 << k))tmp += cake[j][k];
                else tmp -= cake[j][k];
            }
            v[j] = P(tmp, j);
        }
        sort(v.begin(), v.end(), greater<P>());
        ll sum[3] = {};
        for(ll j = 0; j < M; j++){
            ll idx = v[j].second;
            for(ll k = 0; k < 3; k++){
                sum[k] += cake[idx][k];
            }
        }
        ans = max(ans, abs(sum[0])+abs(sum[1])+abs(sum[2]));
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    int count = 0;
    int mode = 2;
    for(int i = 0; i < n; i++){
        if(n == 1){
            mode = 2;
        } else if(a.at(i) < a.at(i+1)){
            mode = 0;
            break;
        } else if(a.at(i) > a.at(i+1)){
            mode = 1;
            break;
        }
    }
    int flag = 1;
    for(int i = 0; i < n-1; i++){
        if(flag == 0){
            if(a.at(i) < a.at(i+1)){
                mode = 0;
                flag = 1;
            } else if(a.at(i) > a.at(i+1)){
                mode = 1;
                flag = 1;
            } else {
                flag = 0;
            }
        } else if(mode == 0 && a.at(i) > a.at(i+1)){
            count++;
            flag = 0;
        } else if(mode == 1 && a.at(i) < a.at(i+1)){
            count++;
            flag = 0;
        }
    }
    if(mode == 2){
        cout << 1;
    } else {
        cout << count+1;
    }
}

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

using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    string s;
    while (n > 0) {
        n--;
        s += n % 26 + 0x61;
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


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

const int kN = 1000 + 5;
const int kX = 5000 + 5;
const int kInf = 1'000'000'000;
vector<int> g[kN];
int dp[kN][2]; 
// dp[x][0] = min sum of weights of black vertices in sub(x) when x is colored white
// dp[x][1] = min sum of weights of white vertices in sub(x) when x is colored black
int x[kN];

void Dfs(int v) {
    array<int, kX> tmp[2];
    for (int i = 0; i < 2; ++i) {
        fill(tmp[i].begin(), tmp[i].end(), kInf);
    }
    tmp[0][0] = tmp[1][0] = 0;
    for (int u : g[v]) {
        Dfs(u);
        array<int, kX> nxt[2];
        for (int i = 0; i < 2; ++i) {
            fill(nxt[i].begin(), nxt[i].end(), kInf);
        }
        for (int j = kX - 1; j >= 0; --j) {
            if (j >= x[u]) {
                nxt[0][j] = min(nxt[0][j], tmp[0][j - x[u]] + dp[u][0]);
                nxt[1][j] = min(nxt[1][j], tmp[1][j - x[u]] + dp[u][1]);
            }
            if (j >= dp[u][1]) nxt[0][j] = min(nxt[0][j], tmp[0][j - dp[u][1]] + x[u]);
            if (j >= dp[u][0]) nxt[1][j] = min(nxt[1][j], tmp[1][j - dp[u][0]] + x[u]);
        }
        for (int i = 0; i < 2; ++i) tmp[i] = nxt[i];
    }
    dp[v][0] = dp[v][1] = kInf;
    for (int i = 0; i <= x[v]; ++i) {
        dp[v][0] = min(dp[v][0], tmp[0][i]);
        dp[v][1] = min(dp[v][1], tmp[1][i]);
    }
}

int main() {
    int n; scanf("%d", &n);
    for (int i = 1; i < n; ++i) {
        int p; scanf("%d", &p);
        g[p - 1].push_back(i);
    }
    for (int i = 0; i < n; ++i) scanf("%d", &x[i]);
    Dfs(0);
    if (dp[0][0] < kInf || dp[0][1] < kInf) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 34048
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n, Q;
llint a[200005], b[200005];
multiset<llint> posS, negS;
llint psum;

llint del(multiset<llint> &S, llint x)
{
	auto it = S.lower_bound(x);
	if(it == S.end() || *it != x) return 0;
	S.erase(it);
	return x;
}

llint calc()
{
	if(posS.size() % 2 == 0) return psum;
	llint ret = psum - *posS.begin();
	ret = max(ret, psum + *negS.rbegin());
	return ret;
}

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= 2*n; i++) cin >> a[i];
	for(int i = 1; i <= 2*n; i++) cin >> b[i];
	
	llint ans = 0;
	for(int i = 1; i <= 2*n; i++){
		ans += a[i];
		if(i > 1 && i < 2*n){
			if(b[i]-a[i] >= 0) posS.insert(b[i]-a[i]), psum += b[i]-a[i];
			else negS.insert(b[i]-a[i]);
		}
	}
	
	llint p, x, y;
	for(int q = 1; q <= Q; q++){
		cin >> p >> x >> y;
		ans -= a[p];
		if(p > 1 && p < 2*n){
			psum -= del(posS, b[p]-a[p]);
			del(negS, b[p]-a[p]);
		}
		a[p] = x, b[p] = y;
		ans += a[p];
		if(p > 1 && p < 2*n){
			if(b[p]-a[p] >= 0) posS.insert(b[p]-a[p]), psum += b[p]-a[p];
			else negS.insert(b[p]-a[p]);
		}
		cout << ans + calc() << endl;
	}
	
	return 0;
}


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

int main(){
  int n,h,w,ans=0;
  cin >>n>>h>>w;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++){
    cin>>a[i]>>b[i];
    if(a[i] >= h &&b[i]>=w) ans++;
  }
  cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int l,r,ans;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

using namespace std;

int main(){
    double W,H,x,y;
    cin >> W >> H >> x >> y;
    cout << W*H/2 << " " << ((x*2==W && y*2==H)?1:0 )<< endl;
    return 0;
}


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

int main() {
	int h, w; cin >> h >> w;
	char s[50][50];
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> s[i][j];
		}
	}

	int cnt = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (s[i][j] == '#' && s[i][j - 1] != '#' && s[i - 1][j] != '#' && s[i][j + 1] != '#' && s[i + 1][j] != '#')
				cnt++;
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
char a;
int main()
{
	cin>>a;
	if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
	{
		cout<<"vowel";
	}
	else
	{
		cout<<"consonant";
	}
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a;
	scanf("%d",&a);
	int b[a];
	int i;
	for(i=0;i<a;i++){
	scanf("%d",&b[i]);
	}
	int j;
	int sum=0;
	for(i=0;i<a-1;i++){
		for(j=i+1;j<a;j++){
			sum = sum+b[i] * b[j];
		}
		
	}
	printf("%d",sum);
return(0);
}

Measured memory_bytes: 128
// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.
import java.util.*;
import java.io.*;

class Main
{
    public static void main(String[] args)
    {
		new Main().run();
    }
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[N];
		int[] A_diff=new int[2*N-1];
		int[] B=new int[N];
		int[] B_diff=new int[N];
		for(int i=0;i<N;++i)A[i]=sc.nextInt();
		for(int i=0;i<N;++i)B[i]=sc.nextInt();
		for(int i=0;i<N;++i)A_diff[i]=A[i]^A[(i+1)%N];
		for(int i=0;i<N;++i)B_diff[i]=B[i]^B[(i+1)%N];
		for(int i=0;i<N-1;++i)A_diff[i+N]=A_diff[i];
		boolean[] search=search(A_diff,B_diff);
		int ans=0;
		PrintWriter pw=new PrintWriter(System.out);
		for(int i=0;i<N;++i){
			if(search[i]){
				pw.println(i+" " +(B[0]^A[i]));
			}
		}
		pw.close();
	}
	
	boolean[] search(int[] a,int[] b){
		int[] border=border(b);
		boolean[] ret=new boolean[a.length];
		int s=0,t=0,match=0;
		for(int i=0;i<a.length;++i){
			while(match>=0&&(match>=b.length||b[match]!=a[i]))match=(match==0?-1:border[match-1]);
			++match;
			if(match==b.length){ret[i-match+1]=true;}
		}
		return ret;
	}
	
	int[] border(int[] b){
		int n=b.length;
		int[] pat=new int[n];
		int match=0;
		for(int i=1;i<n;++i){
			while(match>=0&&b[i]!=b[match])
				match=(match==0?-1:pat[match-1]);
			++match;
			pat[i]=match;
		}
		return pat;
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}

// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase


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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e5+10, maxm=5e3+10, lg=31, mod=1e9+7, inf=1e18;

ll n,ans=0,mn=inf,ff,sz[maxn];
vector<pll> g[maxn];
void dfs(ll v=1,ll p=0){
	sz[v]=1;
	for(auto u:g[v])if(u.F!=p){
		dfs(u.F,v);
		if(2*sz[u.F]==n) ff=u.S;
		ans+=min(sz[u.F],n-sz[u.F])*u.S;
		sz[v]+=sz[u.F];
	}
}
ll fcen(ll v=1,ll p=0){
	for(auto u:g[v])if(u.F!=p && 2*sz[u.F]>n) return fcen(u.F,v);
	return v;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		ll v,u,w; cin>>v>>u>>w;
		g[v].pb({u,w}), g[u].pb({v,w});
	}
	dfs();
	if(ff) return cout<<2*ans-ff,0;
	ll v=fcen();
	for(auto u:g[v]) mn=min(mn,u.S);
	cout<<2*ans-mn;
	
	return 0;
}





Measured memory_bytes: 18676
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

  ll a, b;
  cin >> a >> b;
  ll c = a ^ b, d = (a - 1) ^ b;
  if(a % 4 == 3){
    if(b % 4 == 3) cout << a << endl;
    if(b % 4 == 0) cout << c << endl;
    if(b % 4 == 1) cout << a - 1 << endl;
    if(b % 4 == 2) cout << d << endl;
    return 0;
  }
  if(a % 4 == 2){
    if(b % 4 == 2) cout << b << endl;
    if(b % 4 == 3) cout << 1 << endl;
    if(b % 4 == 0) cout << b + 1 << endl;
    if(b % 4 == 1) cout << 0 << endl;
    return 0;
  }
  if(a % 4 == 0){
    if(b % 4 == 0) cout << b << endl;
    if(b % 4 == 1) cout << 1 << endl;
    if(b % 4 == 2) cout << b + 1 << endl;
    if(b % 4 == 3) cout << 0 << endl;
    return 0;
  }
  if(a % 4 == 1){
    if(b % 4 == 1) cout << a << endl;
    if(b % 4 == 2) cout << c << endl;
    if(b % 4 == 3) cout << a - 1 << endl;
    if(b % 4 == 0) cout << d << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int N;
vector<int> A;
vector<vector<int>> G;
vector<int> B;
vector<bool> isVisited;

int maxpair(vector<int> &v){
    if(v.size() <= 1) return 0;

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

    int sm = 0;
    for(int i=0; i<v.size()-1; i++) sm+=v[i];
    int mx = v.back();
    if(sm >= mx) return (sm+mx)/2;
    else return sm;
}

int dfs(int s){
    isVisited[s] = true;

    int cnt = 0;
    int num = 0;
    vector<int> v;
    for(int t : G[s]){
        if(isVisited[t]) continue;
        num++;
        B[t] = dfs(t);
        cnt += B[t];
        v.push_back(B[t]);
    }
    if(num==0) return A[s];
    int a=2*A[s]-cnt, b=cnt-A[s];
    int maxb = maxpair(v);
    if(a < 0 || b < 0 || b > maxb) return -1;
    return a;
    /*
    a: child -> parent
    b: child -> child
    cnt: from children
    a+2*b=cnt
    A=a+b
    ->a+2*(A-a)=cnt
    ->-a+2A=cnt
    ->a=2A-cnt
    ->b=A-a=cnt-A
     */
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    A.resize(N);
    G.resize(N);
    B.resize(N, 0);
    isVisited.resize(N, false);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if(N==2){
        if(A[0] == A[1]){
            cout << "YES" << endl;
            return 0;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    int s = 0;
    for(int i=0; i<N; i++){
        if(G[i].size() >= 2){
            s = i;
            break;
        }
    }

    B[s] = dfs(s);

    if(B[s] != 0){
        cout << "NO" << endl;
        return 0;
    }
    for(int i=1; i<N; i++){
        if(B[i] == -1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 15872