akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    vector<long long> A(3 * N);
    for(long long i  = 0; i < 3 * N; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    long long ans = 0;
    for(long long i = 0; i < N; i++){
        ans += A.at(N + 2 * i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5572
package main

import "fmt"

func main() {
	var L int
	fmt.Scan(&L)

	a, b := calc(L)
	remain := L - 1 - a
	cnt := 0
	for remain > 0 {
		if remain&1 == 1 {
			cnt++
		}
		remain >>= 1
	}
	fmt.Printf("%d %d\n", b, 2*(b-1)+cnt)

	tmp := 1
	for i := 1; i < b; i++ {
		fmt.Printf("%d %d %d\n", i, i+1, 0)
		fmt.Printf("%d %d %d\n", i, i+1, tmp)
		tmp *= 2
	}

	remain = L - 1 - a
	t := 1
	t2 := 1
	t3 := 1
	for remain > 0 {
		if remain&1 == 1 {
			fmt.Printf("%d %d %d\n", t, b, a+t3)
			t3 += t2
		}
		remain >>= 1
		t++
		t2 <<= 1
	}
}

func calc(L int) (int, int) {
	ret1 := 1
	ret2 := 0
	for L > 0 {
		ret1 <<= 1
		ret2++
		L >>= 1
	}
	return ret1/2 - 1, ret2
}


Measured memory_bytes: 512
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;

vector<int> uft;

int search(int p){
    if(uft[p]==p){return p;}
    int k=search(uft[p]);
    uft[p]=k;
    return k;
}


int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a;
    vector<int> w(n);
    uft.resize(n);
    for(int i=0;i<n;i++){
        uft[i]=i;
    }
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        b--;
        w[b]=i;
        a.push_back(b);
    }
    for(int i=0;i<m;i++){
        int k,l;
        cin>>k>>l;
        k--; l--;
        uft[search(k)]=search(l);
    }
    int count=0;
    for(int i=0;i<n;i++){
        if(search(i)==search(w[i])){count++;}
    }
    cout<<count<<endl;
    
    return 0;
}


Measured memory_bytes: 1660
import itertools

N = int(input())

record = [0] * (10 ** 4 + 1)
for p in itertools.product(range(1, 99), range(1, 99), range(1, 99)):
    x, y, z = p
    n = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
    if n > N:
        continue
    record[n] += 1

for i in range(1, N + 1):
    print(record[i])

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
const int MAX_N = 100;

int main() {
    int n; cin >> n;
    int p[MAX_N+1]; rep(i, 1, n+1) cin >> p[i-1] >> p[i];
    
    int dp[MAX_N+1][MAX_N+1];
    rep(i, 1, n+1) dp[i][i] = 0;
    rep(l, 2, n+1){
        rep(i, 1, n-l+2){
            int j = l + i - 1;
            dp[i][j] = (1<<21); // dp[i][j]に巨大な数を入れる
            rep(k, i, j){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }

    cout << dp[1][n] << endl;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b; cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n;
int ans=0;
int a=0,b=0;
int ba=0;

main(){
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    
    rep(j,s.size()-1){
      if(s[j]=='A'&&s[j+1]=='B') ans++;
    }
    if(s[0]=='B') b++;
    if(s[s.size()-1]=='A') a++;
    if(s[0]=='B'&&s[s.size()-1]=='A') ba++;
  }
//  cout<<ans<<' '<<a<<' '<<b<<endl;

  if(a>0&&b>0){
    ans+=min(a,b);
  }

  if(ans>0&&a>0&&a==b&&a==ba)
    cout<<ans-1<<endl;
  else
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long[] b = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      b[i] = sc.nextLong();
    }
    long ans = 0;
    long p = 0;
    for(int i = n - 1; i >= 0; i--) {
      a[i] += p;
      if((a[i] % b[i]) != 0) {
        long t = b[i] - (a[i] % b[i]);
        ans += t;
        p += t;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 89080
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

#define mod 1000000007

int main(){
	long long n;
	long long d;
	cin >> n >> d;
	vector<long long> vd(n);
	for(long long i = 0;i < n;i++){
		cin >> vd[i];
	}
	vector<long long> sd;
	sd.push_back(d);
	for(long long i = 0;i < n;i++){
		if(sd[i]*2 < vd[i]){
			sd.push_back(sd[i]);
		}
		else if(sd[i] < vd[i]){
			sd.push_back(vd[i]-sd[i]);
		}
		else{
			sd.push_back(sd[i]-vd[i]);
		}
	}
	vector<long long> dp(n);
	dp[n-1] = 0;
	for(long long i = n-1;i > 0;i--){
		if(vd[i]/2 <= dp[i]){
			dp[i-1] = dp[i] + vd[i];
		}
		else{
			dp[i-1] = dp[i];
		}
	}
	long long q;
	cin >> q;
	for(long long i = 0;i < q;i++){
		cin >> d;
		d--;
		if(dp[d] >= sd[d]){
			cout << "NO" << endl;
		}
		else{
			cout << "YES" << endl;
		}
	}
}


Measured memory_bytes: 13804
//#include "stdafx.h"
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int a, b,x;
	cin >> x>> a >> b;
	if (abs(x - a) < abs(x - b))
		cout << "A";
	else
		cout << "B";
	
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i ++)

const double EPS = 1e-8;

int n;
double x[303], y[303];

int main() {
        while (cin >> n && n) {
                rep(i, n) cin >> x[i] >> y[i];
                int ans = 1;
                rep(i, n) rep(j, n) {
                        if (i == j) continue;
                        double dx = x[i] - x[j], dy = y[i] - y[j];
                        double d = sqrt(dx * dx + dy * dy);
                        if (d > 2.0 + EPS) continue;
                        double r = sqrt(1.0 - (d / 2.0) * (d / 2.0));
                        double vx = -dy / d * r;
                        double vy = dx / d * r;
                        double xx = (x[i] + x[j]) / 2.0 + vx;
                        double yy = (y[i] + y[j]) / 2.0 + vy;
                        int cnt = 0;
                        rep(k, n) if ((x[k] - xx) * (x[k] - xx) + (y[k] - yy) * (y[k] - yy) < 1.0 + EPS) cnt ++;
                        ans = max(ans, cnt);
                }
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int a,b;
    cin >> a >>b;
    if(a>8 || b>8){
        cout<<":("<<endl;
    }else{
        cout<<"Yay!"<<endl;
    }
}
   

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

#define eb emplace_back
#define ld long double
#define ll long long

using namespace std;

const int nm = 1002;
const int inf = 1e9;
const int x[] = {-1, 0, 0, 1};
const int y[] = {0, -1, 1, 0};

int m, n;
int u, v, s, t;
char a[nm][nm];
int d[nm][nm];
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> q;

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> m >> n >> u >> v >> s >> t;
	u--;
	v--;
	s--;
	t--;
	for (int i = 0; i < m; ++i) {
		cin >> a[i];
	}
	memset(d, 0x3f, sizeof(d));
	d[u][v] = 0;
	q.emplace(0, u, v);
	while (!q.empty()) {
		int di, u, v;
		tie(di, u, v) = q.top();
		q.pop();
		if (di != d[u][v]) {
			continue;
		}
		for (int i = 0; i < 4; ++i) {
			int u2 = u + x[i], v2 = v + y[i];
			if (u2 >= 0 && u2 < m && v2 >= 0 && v2 < n && a[u2][v2] == '.' && d[u2][v2] > d[u][v]) {
				d[u2][v2] = d[u][v];
				q.emplace(d[u2][v2], u2, v2);
			}
		}
		for (int u2 = max(u - 2, 0); u2 <= u + 2 && u2 < m; ++u2) {
			for (int v2 = max(v - 2, 0); v2 <= v + 2 && v2 < n; ++v2) {
				if (a[u2][v2] == '.' && d[u2][v2] > d[u][v] + 1) {
					d[u2][v2] = d[u][v] + 1;
					q.emplace(d[u2][v2], u2, v2);
				}
			}
		}
	}
	cout << (d[s][t] < inf ? d[s][t] : -1) << "\n";
}


Measured memory_bytes: 8620
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e2+5;
int a[maxn];

int main(){
    int n,num=0;cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(i%2&&a[i]%2)
      num++;
  }
  cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    string s;
    cin >> s;
    if (s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    int count =0;
    rep(i,2,s.size()-1) {
        if(s[i] == 'C') count++;
    }
    if (count != 1) {
        cout << "WA" << endl;
        return 0;
    }
    rep(i,1,s.size()) {
        if(!((s[i] >= 'a' && s[i] <= 'z') || s[i] == 'A' || s[i] == 'C')) {
        cout << "WA" << endl;
        return 0;
        }
    }
    cout << "AC" << endl;
    return 0;

}

Measured memory_bytes: 3040
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
struct edge{long long to,cost;};
struct st{int rate,way,num;};
typedef pair<int,int>P;
#define inf 1000000007
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int num[3][3];
    rep(i,0,3)rep(j,0,3)cin>>num[i][j];
    bool ans=true;
    rep(i,0,2){
        if(num[i+1][0]-num[i][0]!=num[i+1][1]-num[i][1]||num[i+1][0]-num[i][0]!=num[i+1][2]-num[i][2])ans=false;
    }
    rep(i,0,2){
        if(num[0][i+1]-num[0][i]!=num[1][i+1]-num[1][i]||num[0][i+1]-num[0][i]!=num[2][i+1]-num[2][i])ans=false;
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main(){
	int i,j;
	for (i=1;i<=9;i++)
	{
		for (j=1;j<=9;j++)
		{
			cout<<i<<'x'<<j<<'='<<i*j<<endl;
		}		
	}
    return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(ll i = 0; i < (ll)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 998244353ll;
const dou pi=3.141592653589793*2;
int main(){
    string s;
    std::cin >> s;
    std::vector<std::vector<int> > a(26);
    int n=s.size();
    rep(i,26){
        a[i].pb(-1);
    }
    rep(i,n){
        a[s[i]-'a'].pb(i);
    }
    itn cnt=0;
    rep(i,26){
        if(a[i].size()-1)cnt++;
        a[i].pb(n);
    }
    if(cnt==1){
        std::cout << 0 << std::endl;
        exit(0);
    }
    
    std::vector<std::vector<int> > aa(26);
    rep(i,26){
        rep(j,a[i].size()-1){
            aa[i].pb(a[i][j+1]-a[i][j]);
        }
    }
    int ans=INF;
    rep(i,26){
        int d=0;
        //std::cout << aa[i].size() << std::endl;
        if(a[i].size()==2)continue;
        rep(j,aa[i].size()){
            chmax(d,aa[i][j]-1);
        }
        chmin(ans,d);
    }
    std::cout << ans << std::endl;

 
   
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    long long W, weight[110], v[110];
    cin >> W;
    for (int i = 0; i < N; ++i) {
        cin >> weight[i] >> v[i];
    }

    long long dp[110][100100] = {0};

    for (int i = 0; i < N; ++i) {
        for (long long j = 0; j <= W; ++j) {
            if (j < weight[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + v[i]);
            }
        }
    }
    printf("%lld\n", dp[N][W]);
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t>A(N);
    vector<int64_t>B(N);
    vector<int64_t>C(N);
    for (int i=0; i<N; i++) {
        cin >> A.at(i);
    }

    for (int i=0; i<N; i++) {
        cin >> B.at(i);
    }

    for (int i=0; i<N; i++) {
        cin >> C.at(i);
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    map<int64_t, int64_t>d;
    int64_t sum_ = 0;
    for (int64_t i=N-1; i>=0; i--) {
        auto itr = upper_bound(C.begin(), C.end(), B[i]);
        int64_t count = C.end() - itr;
        sum_ += count;
        d[B[i]] = sum_;
    }

    int64_t count = 0;
    for (int i=0; i<N; i++) {
        auto itr = upper_bound(B.begin(), B.end(), A[i]);
        int64_t index = itr - B.begin();
        if (itr != B.end()) {
            count += d[B[index]];
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 11972
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int n,k; cin >> n >> k;
    if (k == 1) cout << 0 << endl;
    else cout << n-k << endl;
    return 0;
}

Measured memory_bytes: 256
const MAXN: usize = 200010;
const MOD: usize = 1000000007;

struct Comb {
    fact: [usize; MAXN],
    finv: [usize; MAXN],
}
// 階乗・順列・組み合わせ・重複組合せ
// modとmaxnは引数に持たせないことにした(配列の初期化ができない)
impl Comb {
    // これをメンバーに持たせるのは悩みどころさん
    fn p_mod(base: usize, exp: usize) -> usize {
        if exp != 0 {
            if (exp & 1) == 1 {
                Comb::p_mod(base * base % MOD, exp / 2) * (base) % MOD
            } else {
                Comb::p_mod(base * base % MOD, exp / 2)
            }
        } else {
            1
        }
    }

    fn fact_new() -> Self {
        let mut fact: [usize; MAXN] = [0; MAXN];
        fact[0] = 1;
        for i in 1..MAXN {
            fact[i] = (fact[i - 1] * i) % MOD;
        }
        let mut finv: [usize; MAXN] = [0; MAXN];
        finv[MAXN - 1] = Comb::p_mod(fact[MAXN - 1], MOD - 2);
        for i in (0..(MAXN - 1)).rev() {
            finv[i] = (finv[i + 1] * (i + 1)) % MOD;
        }
        Comb {
            fact: fact,
            finv: finv,
        }
    }
    fn nPr(&self, n: usize, r: usize) -> usize {
        if n < r || r == 0 {
            0
        } else {
            self.fact[n] * self.finv[n - r] % MOD
        }
    }
    fn nCr(&self, n: usize, r: usize) -> usize {
        if n < r {
            0
        } else if r == 0 {
            1
        } else {
            self.fact[n] * self.finv[r] % MOD * self.finv[n - r] % MOD
        }
    }
    fn nHr(&self, n: usize, r: usize) -> usize {
        if n == 0 && r == 0 {
            1
        } else {
            self.nCr(n + r - 1, r)
        }
    }
}

fn solve() {
    let (n, k): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut ans = 0;
    let c = Comb::fact_new();
    for i in k..n + 2 {
        ans += n * i - i * (i - 1) + 1;
        ans %= MOD;
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2264
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,cnt,ans;
char L;
string s;
vector<ll>v;
int main(void){
    cin>>s>>n;
    L=s[0];
    cnt++;
    for(int i=1;i<s.size();i++){
        if(L==s[i])cnt++;
        else{
            L=s[i];
            v.push_back(cnt);
            cnt=1;
        }
    }
    v.push_back(cnt);
    //for(auto x:v)cout<<x<<endl;
    if(v.size()==1){
        cout<<v[0]*n/2<<endl;
        return 0;
    }
    for(int i=1;i<v.size()-1;i++){
        ans+=v[i]/2*n;
    }
    ans+=v[0]/2;
    ans+=v[v.size()-1]/2;
    //cout<<ans<<endl;
    if(s[0]==s[s.size()-1]){
        ans+=(v[v.size()-1]+v[0])/2*(n-1);
    }
    else{
        ans+=v[v.size()-1]/2*(n-1)+v[0]/2*(n-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <vector>

#define REP(a, b) for (int a = 0; a < b; a++)
#define FORU(a, b, c) for (int a = b; a <= c; a++)
#define FORD(a, b, c) for (int a = b; a >= c; a--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

int main() {
	int N, M, pieces[100005], delta[100005];

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

	REP(i, M) {
		scanf("%d", &pieces[i]);
	}

	sort(pieces, pieces + M);

	REP(i, M - 1) {
		delta[i] = pieces[i + 1] - pieces[i];
	}

	sort(delta, delta + M - 1);

	int ans = 0;

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

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

	return 0;	
}


Measured memory_bytes: 896
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()

	edges := make([][2]int, 0)
	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			if n%2 == 1 && i+j != n {
				edges = append(edges, [2]int{i, j})
			} else if n%2 == 0 && i+j != n+1 {
				edges = append(edges, [2]int{i, j})
			}
		}
	}

	puts(len(edges))
	for _, edge := range edges {
		puts(edge[0], edge[1])
	}
}


Measured memory_bytes: 2248
#include<iostream>
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int a,b;
    cin >> a >> b;
    
    if((a+b)%2==0) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;

}

Measured memory_bytes: 888
#include <stdio.h>
#include <assert.h>
int n,i,j,x,a[10][10],list[200][3],size;
void push(int x,int y,int s){list[size][0]=i;list[size][1]=j;list[size][2]=s;size++;}

int check(int x,int y,int s){
	int d;
	if(s<3 && (x<1 || x>9 || y<1 || y>9)) return 0;
	if(s==3 && (x<2 || x>8 || y<2 || y>8)) return 0;
	d=a[x][y];
	if(a[x-1][y]<d)d=a[x-1][y];
	if(a[x+1][y]<d)d=a[x+1][y];
	if(a[x][y-1]<d)d=a[x][y-1];
	if(a[x][y+1]<d)d=a[x][y+1];
	if(s==1 || d==0)return d;
	if(a[x-1][y-1]<d)d=a[x-1][y-1];
	if(a[x+1][y+1]<d)d=a[x+1][y+1];
	if(a[x+1][y-1]<d)d=a[x+1][y-1];
	if(a[x-1][y+1]<d)d=a[x-1][y+1];
	if(s==2 || d==0)return d;
	if(a[x-2][y]<d)d=a[x-2][y];
	if(a[x+2][y]<d)d=a[x+2][y];
	if(a[x][y-2]<d)d=a[x][y-2];
	if(a[x][y+2]<d)d=a[x][y+2];
	return d;
}

void draw(int x,int y,int s,int d){
	if(size==3 && (x<2 || x>8 || y<2 || y>8)) return;
	a[x][y]+=d;
	a[x-1][y]+=d;
	a[x+1][y]+=d;
	a[x][y-1]+=d;
	a[x][y+1]+=d;
	if(s==1)return;
	a[x-1][y-1]+=d;
	a[x+1][y+1]+=d;
	a[x+1][y-1]+=d;
	a[x-1][y+1]+=d;
	if(s==2)return;
	a[x-2][y]+=d;
	a[x+2][y]+=d;
	a[x][y-2]+=d;
	a[x][y+2]+=d;
}

int search(int nn,int from){
	int i,x,y,s,t;
	for(i=from;i>=0;i--){
		x=list[i][0];y=list[i][1];s=list[i][2];
		if(a[x][y]==0 && a[x+1][y]>0)return 0;
		if(x<8){
		if(s<3 && a[x+2][y]>0)return 0;
		if(y==1 && a[x+2][y-1]>0)return 0;
		}
		if(y==1 && s<2 && a[x+1][y-1]>0)return 0;
        if(y==8 && s<2 && a[x+1][y+1])return 0;
		t=check(x,y,s);
		if(t>0){
			draw(x,y,s,-t);
			for(;t>0;t--){
				if(nn-t>0){
					if(search(nn-t,i-1)>0){goto answer;}
				}else{
					int p,q;
					for(p=0;p<10;p++)for(q=0;q<10;q++){{if(a[p][q]!=0)goto miss;}}
					goto answer;
					miss:;
				}
				draw(x,y,s,+1);
			}
		}
	}
	return 0;

	answer:
	for(;t>0;t--)printf("%d %d %d\n",y,x,s);
	return 1;
}

int main(void){
	scanf("%d",&n);size=0;
	for(i=0;i<10;i++){for(j=0;j<10;j++){scanf("%d",&a[i][j]);}}
	for(i=1;i<9;i++){
		for(j=1;j<9;j++){
			x=check(i,j,1); if(x==0)continue; push(i,j,1);
			x=check(i,j,2); if(x==0)continue; push(i,j,2);
			x=check(i,j,3); if(x==0)continue; push(i,j,3);
		}
	}
	/*
	 if(a[i][j]>5){
	 fprintf(stderr,"%3d\n",n);
	 for(i=0;i<10;i++){for(j=0;j<10;j++){fprintf(stderr,"%3d",a[i][j]);}fprintf(stderr,"\n");}fprintf(stderr,"\n");
	 assert(0);
	 }*/
	//for(i=0;i<size;i++)printf("%d %d %d\n",list[i][0],list[i][1],list[i][2]);
	search(n,size-1);
	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;


int main(){
    int n, ans = 0; cin >> n;
    map<int, int> mp;
    REP(i, n){
        int a; cin >> a;
        auto itr = mp.find(a-1);
        if(itr != mp.end()) ++itr->second;
        else mp[a-1] = 1;
        itr = mp.find(a);
        if(itr != mp.end()) ++itr->second;
        else mp[a] = 1;
        itr = mp.find(a+1);
        if(itr != mp.end()) ++itr->second;
        else mp[a+1] = 1;
    }
    for(auto it = mp.begin(); it != mp.end(); ++it){
        ans = max(ans, it->second);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4736
N = int(input())
h = [int(x) for x in input().split()]

ans = 0
sum_height = sum(h)
while sum_height > 0:
    for i in range(N):
        if h[i] == 0:
            pos = False
            continue
        elif (i == 0 and h[i] > 0) or (i > 0 and not pos):
            ans += 1
        h[i] -= 1
        sum_height -= 1
        pos = True

print(ans)


Measured memory_bytes: 3060
from collections import deque
S = deque(list(input()))
q = int(input())
r = False
for _ in range(q):
    t = input().split()
    if len(t) == 1:
        r = not r
    else:
        t[1] = int(t[1]) - 1
        if (not t[1] and not r) or (t[1] and r):
            S.appendleft(t[2])
        else:
            S.append(t[2])
if r:
    S = list(S)
    print(''.join(S[::-1]))
else:
    print(''.join(S))

Measured memory_bytes: 10084
#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define MOD 1000000007

using namespace std;

void solver()
{
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}

int main(int argc, char const *argv[])
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);   
    freopen("output.txt","w",stdout);
    #endif 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    
    int t=1;
    // cin>>t;
    while(t--)
    {
        solver();
    }
    return 0;
}


Measured memory_bytes: 3596
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1, l, M
#define rson rt<<1|1, M+1, r
#ifdef local
#define dbg(a) cout << #a": " << a << endl;
#else
#define dbg(a)
#endif // loacl


using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-6;
const int mod=1e9+7;
const int maxn=200+10;
const int N=1e6+10;
const int M=N*20;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll MOD)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%MOD;
        b>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}


int main()
{
	IOS;
	int a[3];cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);cout<<a[0]+a[1];
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    int n,j,k=0,l,i;
    cin>>n;
    while(n>0)
    {
        j=n%10;
        n=n/10;
    if(j==7)
        {

            k++;
        }

    }
    if(k>0)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
    #include<cstdio>
    #include<math.h>
    #include<string>
    #include<algorithm>
    #include<functional>
    #include<vector>
    #include<set>
    #include<map>
    #define INF 999999
    #define EPS 1.0e-6
     
    using namespace std;
     
    typedef long long ll;
    typedef pair<int, int> P;
     
    int n;
     
    int main()
    {
    	cin >> n;
    	if (n / 10 == 9 || n % 10 == 9)cout << "Yes" << endl;
    	else cout << "No" << endl;
     
    	return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a;
  int count1=0,count2=0;
  for(int i=0;i<3;i++){
    scanf("%d ",&a);
    if(a==5) count1++;
    if(a==7) count2++;
  }
  if(count1==2 && count2==1) printf("YES\n");
  else printf("NO\n");
 return 0;
 }

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

int main()
{
    int n, k;
    cin >> n >> k;
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        
        if (x < (k - x))
            ans += x * 2;
        else
            ans += (k - x) * 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(void){
  string s;cin >> s;
  int a = (s.at(0) - '0')*10 + (s.at(1) - '0');
  int b = (s.at(2) - '0')*10 + (s.at(3) - '0');
  if((a >=13 or a==0)  and b<13 and b>0){
    cout << "YYMM"<<endl;
  }else if(a>0 and a < 13 and (b>12 or b==0)){
    cout << "MMYY" <<endl;
  }else if( a<13  and b<13 and (a>0 or b>0)){
    cout << "AMBIGUOUS" << endl;
  }else{
    cout <<"NA" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 305

ll N,K;
ll H[SIZE];
ll dp[SIZE][SIZE]; //dp[右端の列][削除個数] = 最小コスト

int main(){

	scanf("%lld %lld",&N,&K);

	H[0] = 0;

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

		scanf("%lld",&H[i]);
	}
	H[N+1] = 0;

	ll ans = 0;

	if(K == 0){

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

			ans += max(0LL,H[i+1]-H[i]);
		}

		printf("%lld\n",ans);

		return 0;
	}

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

			dp[i][k] = HUGE_NUM;
		}
	}

	dp[0][0] = 0;

	for(ll i = 1; i <= N+1; i++){ //今回の列
		for(ll a = max(0LL,i-K-1); a <= i-1; a++){ //1つ前の列
			ll add = (i-1)-(a+1)+1;
			for(ll b = 0; b <= K; b++){ //削除個数
				if(b+add > K)break;

				dp[i][b+add] = min(dp[i][b+add],dp[a][b]+max(0LL,H[i]-H[a]));
			}
		}
	}

	ans = HUGE_NUM;

	for(ll i = 0; i <= K; i++){

		ans = min(ans,dp[N+1][i]);
	}

	printf("%lld\n",ans);

	return 0;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  i64 q, h, s, d;
  i64 n;
  cin >> q >> h >> s >> d >> n;
  h = min(h, 2 * q);
  s = min(s, 2 * h);

  i64 ans;
  if(2 * s <= d) ans = s * n;
  else ans = (n / 2) * d + (n % 2) * s;
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            const string S = "Sunny";
            const string C = "Cloudy";
            const string R = "Rainy";
            var a = Console.ReadLine();

            if(a == S) { Console.WriteLine(C); }
            if(a == C) { Console.WriteLine(R); }
            if(a == R) { Console.WriteLine(S); }
        }
    }
}


Measured memory_bytes: 9044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    VI a(N+10);
    REP(i,M){
        int tmp; cin >> tmp;
        a[tmp] = 1;
    }
    LL dp[112345] = {};
    dp[0] = 1;

    REP(i,N+1){
        if(a[i+1] != 1){
            if(i != 0){
                dp[i+1] = (dp[i] + dp[i-1])%MOD;
            }
            else{
                dp[i+1] = dp[i];
            }
        }
        else{
            dp[i+1] = 0;
        }
    }
    REP(i,N+1){
        dump(dp[i])
    }
    cout << dp[N] << endl;


}

Measured memory_bytes: 1536
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort()

dp = [[0 for _ in range(t)] for _ in range(n+1)]

ans = 0
i = 0
for a, b in ab:
    ans = max(ans, max(dp[i]) + b)
    if a < t:
        dp[i+1][a] = max(dp[i][a], b)
    for j in range(1, t):
        if dp[i][j] > 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
            if a + j < t:
                dp[i+1][a+j] = max(dp[i][a+j], dp[i][j] + b)
    i += 1

ans = max(ans, max(dp[n]))

print(ans)

Measured memory_bytes: 123736
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    long long N, D;
    cin >> N >> D;
    vector<long long> X(N), Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }

    long long d = D*D;

    int res = 0;
    for (int i = 0; i < N; i++) {
        long long _d = X[i] * X[i] + Y[i] * Y[i];
        if (_d <= d) {
            res += 1;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 6052
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):
    if A == 0:
        print(0)
        return
    All = A+B

    answer = (N//All)*A
    amari = N%All
    
    if amari > A:
        answer += A
    else:
        answer += amari
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005



int N,start,goal;
int PARENT[SIZE];
ll T,num_visited[SIZE];

struct Edge{
	Edge(int arg_to,ll arg_weight){
		to = arg_to;
		weight = arg_weight;
		value = -1;
	}
	bool operator<(const struct Edge &arg) const{

		return value < arg.value;
	}

	int to;
	ll weight,value;
};

vector<Edge> G[SIZE];


void dfs(int node_id,int parent){

	PARENT[node_id] = parent;

	bool FLG = false;
	int edge_index;

	vector<Edge> V;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == parent || child == goal)continue;

		num_visited[child]++;
		dfs(child,node_id);
		G[node_id][i].value = G[node_id][i].weight-num_visited[child]*T;
	}
	sort(G[node_id].begin(),G[node_id].end());

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == parent)continue;

		if(child == goal){

			FLG = true;
			edge_index = i;
			continue;
		}

		G[node_id][i].weight -= (num_visited[node_id]+num_visited[child])*T;
		num_visited[node_id]++;
	}

	if(FLG){ //ゴールは最後に訪れる

		num_visited[goal]++;
		dfs(goal,node_id);
		G[node_id][edge_index].weight -= T*(num_visited[node_id]+num_visited[goal]);
	}
}

int main(){

	scanf("%d %lld %d %d",&N,&T,&start,&goal);
	start--;
	goal--;

	int from,to;
	ll weight;

	for(int loop = 0; loop < N-1; loop++){

		scanf("%d %d %lld",&from,&to,&weight);

		from--;
		to--;

		G[from].push_back(Edge(to,weight));
		G[to].push_back(Edge(from,weight));
	}

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

		num_visited[i] = 0;
	}

	dfs(start,-1);

	//戻りのコストの過剰計上分を直す(戻りはgoalで止まるので、片道分のコストがあれば良い)
	int tmp_node = goal;

	while(true){

		int parent = PARENT[tmp_node];

		if(parent == -1)break;

		for(int i = 0; i < G[parent].size();i++){

			if(G[parent][i].to == tmp_node){

				G[parent][i].weight += num_visited[tmp_node]*T;
				break;
			}
		}

		if(parent == start)break;
		tmp_node = parent;
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < G[i].size(); k++){
			if(G[i][k].weight <= 0){

				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");

	return 0;
}



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

int main() {
	string S; cin >> S;
	int res = 0;
	for (int i = 0; i + 1 < S.size(); i++)
		if (S[i] !=S[i + 1]) res++;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int L, N;
	int x, w;
	int i;
	int AsumiKana = 0;
	if (scanf("%d", &L) != 1) return 1;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d%d", &x, &w) != 2) return 1;
		AsumiKana += x * w;
	}
	if (AsumiKana > 0) {
		printf("1\n-1 %d\n", AsumiKana);
	} else if (AsumiKana < 0) {
		printf("1\n1 %d\n", -AsumiKana);
	} else {
		puts("0");
	}
	return 0;
}

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

#define boost ios_base::sync_with_stdio(false);     cin.tie(NULL);

int main()
{
    boost;
    int n;
    cin >> n;
    int arr[n][3];
    for(int i=0;i<n;i++)
    {
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }
    int dp[n+1][3];
    dp[0][0]=dp[0][1]=dp[0][2]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=max(arr[i-1][1] + dp[i-1][1],arr[i-1][2] + dp[i-1][2]);
        dp[i][1]=max(arr[i-1][0] + dp[i-1][0],arr[i-1][2] + dp[i-1][2]);
        dp[i][2]=max(arr[i-1][1] + dp[i-1][1],arr[i-1][0] + dp[i-1][0]);
    }
    cout << max(max(dp[n][0],dp[n][1]),dp[n][2]) << "\n";
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int a[100000+10],n;
int cnt;
#define GG return printf("No"),0
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if (a[n]-a[1]>1) GG;
	if (a[1]==a[n]) return printf("%s",n==a[1]+1||n>=a[1]*2?"Yes":"No"),0;
	for(int i=1;i<=n;++i) if (a[i]==a[1]) ++cnt;
	if (cnt>a[1]) GG;
	return printf("%s",(n-cnt)>=(a[n]-cnt)*2?"Yes":"No"),0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define int long long
#define BUF 1e5
#define INF 1<<30
#define EPS 1e-5
#define all(a) (a).begin(),(a).end()
#define INTCEIL(a, b) ((a + (b - 1)) / b)
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

void dfs(string num, int digit, vector<int>& x) {
	if (digit == 0) {
		x.push_back(stoll(num));
	}
	else {
		int now = num.back() - '0';
		if (now - 1 >= 0) {
			dfs(num + to_string(now - 1), digit - 1, x);
		}
		if (now + 1 < 10) {
			dfs(num + to_string(now + 1), digit - 1, x);
		}
		dfs(num + to_string(now), digit - 1, x);
	}
}


signed main() {
	vector<vector<int>> dp(10, vector<int>(10, 0));
	for (int i = 0; i < 10; i++) {
		dp[0][i] = 1;
	}
	for (int i = 1; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			dp[i][j] = (j - 1 < 0 ? 0 : dp[i - 1][j - 1]) + dp[i - 1][j] + (j + 1 > 9 ? 0 : dp[i - 1][j + 1]);
		}
	}
	cin >> N;
	pair<int, int> p;
	int pos = 0;
	for (int i = 0; i < 10; i++) {
		bool flag = 0;
		for (int j = 1; j < 10; j++) {
			ans += dp[i][j];
			if (ans >= N) {
				flag = 1;
				p = { i,j };
				pos = N - (ans - dp[i][j]);
				break;
			}
		}
		if (flag) {
			break;
		}
	}
	vector<int> res;
	dfs(to_string(p.second), p.first, res);
	sort(res.begin(), res.end());
	cout << res[pos - 1] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
struct stuck{
  int s[100];/*量に応じて変更*/
  int top;
  void initialize(){
    top=0;
  }
  bool isEmpty(){
    return top==0;
  }
  void push(int x){
    s[top]=x;
    top++;
  }
  int pop(){
    if (isEmpty()){
      std::cout << "Empty" << '\n';
      return -1;
    }else{
      top--;
      return s[top];
    }
  }
};

int main(){
  int a,b;
  struct stuck d;
  d.initialize();
  std::string s;
  while (std::cin >> s){
    if (s=="+"){
      a=d.pop();b=d.pop();
      d.push(b+a);
    }else if (s=="-"){
      a=d.pop();b=d.pop();
      d.push(b-a);
    }else if (s=="*"){
      a=d.pop();b=d.pop();
      d.push(b*a);
    }else {
      a=atoi(s.c_str());
      d.push(a);
    }
  }
  if (d.isEmpty()){
    std::cout << "Error" << '\n';
  }else{
    std::cout << d.pop() << '\n';
  }
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[105][100005];
ll w[105];
ll v[105];
ll n,mx;
ll f(int ind,ll rem){
	if(ind==n+1) return 0;
	if(dp[ind][rem]) return dp[ind][rem];
	ll a = 0;
	a = max(a,f(ind+1,rem));
	if(rem>=w[ind]){
		a = max(a,f(ind+1,rem-w[ind])+v[ind]);
	}
	return dp[ind][rem] = a;
}

int main(){
	cin>>n>>mx;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	cout<<f(1,mx);
}


Measured memory_bytes: 78080
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
    ll n,m;cin>>n>>m;
    vl h(n);
    rep(i,n)cin>>h[i];
    vvl child(n);
    rep(i,m){
        ll a,b;cin>>a>>b;
        a--;b--;
        child[a].push_back(b);
        child[b].push_back(a);
    }
    ll count=0;
    rep(i,n){
        bool ans=true;
        for(auto x:child[i]){
          if(h[i]<=h[x])ans=false;
        }
        if(ans)count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 9808
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  ll lhs,rhs,d;
  while(~scanf("%ld %ld %ld",&lhs,&rhs,&d)){
    if(lhs==rhs && rhs==d && lhs==0) break;
    //abs(lhs*x-rhs*y) = d or abs(lhs*x+rhs*y) = d
    //lhs^2*x^2 -2*lhs*rhs*x*y +rhs^2*y^2 = d^2
    //lhs^2*x^2 +2*lhs*rhs*x*y +rhs^2*y^2 = d^2
    //(rhs^2)*y^2 + (-2*lhs*rhs*x)*y + (lhs^2*x^2 - d^2) = 0;
    //(rhs^2)*y^2 + (+2*lhs*rhs*x)*y + (lhs^2*x^2 - d^2) = 0;

    ll res_x=INF,res_y=INF;
    for(ll x=0;x<=50000;x++){
      ll a = rhs*rhs;
      ll b1 = (-2*lhs*rhs*x);
      ll b2 = (2*lhs*rhs*x);
      ll c = lhs*lhs*x*x - d*d;

      ll numerator[4];
      ll D = b1*b1 - 4*a*c;
      
      numerator[0] = -b1 + sqrt(D);
      numerator[1] = -b1 - sqrt(D);
      numerator[2] = -b2 + sqrt(D);
      numerator[3] = -b2 - sqrt(D);

      if(D < 0) continue;
      for(int i=0;i<4;i++){
	if(numerator[i] >= 0 && (numerator[i] % (2*a) == 0)){
	  ll y = numerator[i] / (2*a);
	  if(x + y <= res_x + res_y
	     && x*lhs + y*rhs <= res_x*lhs + res_y*rhs){
	    res_x = x;
	    res_y = y;
	  }
	}
      }
    }
    printf("%ld %ld\n",res_x,res_y);
  }
}

Measured memory_bytes: 1188
#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end() 
#define X first;
#define Y second;
#define mp make_pair;
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll; 
const int MOD = 1000000007;


int main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    

// 	int t{},T{};
// 	cin>>t;T=t;
// 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        ll n{},m{},k{},a{1},b{},c{},f{},q=0;
        cin>>n;
        string s;
        cin>>s;
        int i=0,j=n-1;
        while(i<j){
            if(s[i]=='W'&&s[j]=='R'){
                swap(s[i],s[j]);
                ++i;--j;
                ++c;
            }else if(s[i]=='R'){
                ++i;
            }else if(s[j]=='W'){
                --j;
            }else{
                if (s[i]=='W'){
                    s[i]='R';
                    c+=1;
                    i+=1;
                    
                }
                if (s[j]=='R'){
                    s[j]='W';
                    c+=1;
                    j-=1;
                }
            }
        }
        cout<<c<<endl;
 //   }
    
    
	return 0;
}

Measured memory_bytes: 3736