akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.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; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int H, W; cin >> H >> W;
    vector<string> a(H);
    rep(i, 0, H) cin >> a[i];

    rep(i, 0, W + 2) cout << "#";
    cout << endl;
    rep(i, 0, H){
        cout << "#";
        cout << a[i];
        cout << "#\n";
    }
    rep(i, 0, W + 2) cout << "#";
    cout << endl;

    return 0;
}

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();

		if (e - a > k) {
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}

	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'
const int dx[] = {1,-1,0,0,1,-1,1,-1};
const int dy[] = {0,0,1,-1,1,-1,-1,1};
const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}

ull t, x, y, a = -1, b;

ull play()
{
	ull s = 0, e = 1e18, mid;

	while(s != e)
	{
		mid = (s + (e - s) / 2);

		if (mid * x >= a && mid * y >= b)
		
			e = mid;
		
		else 
			s = mid + 1;
	}
	return s;
}

int main(int argc, char const *argv[])
{

	cin>>t;

	for(int i = 0; i < t; ++i)
	{
		cin>>x>>y;
		
		if(!i)a = x, b = y;

		//ull n = play();
		
		ull n = max((a + x - 1) / x, (b + y - 1) / y);
		
		a = n * x, b = n * y;

	}
	cout<<a+b;
}	

Measured memory_bytes: 256
#include <stdio.h>

int cnt=1;
int pre[500010];
int nxt[500010];
int val[500010];
int pos;

int main(){
	pre[0]=nxt[0]=-1;
	int q;
	scanf("%d",&q);
	while(q--){
		int t;
		scanf("%d",&t);
		if(t==0){
			int x;
			scanf("%d",&x);
			val[cnt]=x;
			nxt[cnt]=pos;
			pre[cnt]=pre[pos];
			pre[pos]=cnt;
			if(pre[cnt]!=-1)nxt[pre[cnt]]=cnt;
			pos=cnt;
			cnt++;
		}else if(t==1){
			int x;
			scanf("%d",&x);
			if(x<0)while(x++)pos=pre[pos];
			else while(x--)pos=nxt[pos];
		}else{
			pre[nxt[pos]]=pre[pos];
			if(pre[pos]!=-1)nxt[pre[pos]]=nxt[pos];
			pos=nxt[pos];
		}
		
	}
	while(pre[pos]!=-1)pos=pre[pos];
	while(nxt[pos]!=-1){
		printf("%d\n",val[pos]);
		pos=nxt[pos];
	}
}


Measured memory_bytes: 7608
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll Q, H, S, L2; cin >> Q >> H >> S >> L2;
    ll L1 = min(min(Q * 4, H * 2), min(S, Q * 2 + H));
    ll N; cin >> N;
    if(N % 2 == 0) {
        cout << min(L1 * N, L2 * N / 2) << endl;
    }else {
        cout << min(L1 * N, (L2 * int(N / 2)) + L1) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=0){
		long long sum=0;
		for(int i=0;i<n;i++){
			int a;
			cin>>a;
			sum+=a;
		}
		sum/=n;
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll V,E;
struct edge{
	ll to,cost,id;
};
const ll maxn = 100005;
const ll INF = 102120027425345LL;
vector<edge> G[maxn],rG[maxn],sG[maxn];
ll d[maxn], d2[maxn];
bool isBridge[maxn];
void dijkstra(ll s, vector<edge> G[maxn], ll d[maxn]) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+V, INF);
	d[s] = 0;
	que.push(P(0,s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (auto e:G[v]){
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}			
		}
	}
}
	map<P,ll> M;
ll dfs_clock,pre[maxn],low[maxn];
ll dfs(ll u, ll fa) {
	ll lowu = pre[u] = ++dfs_clock;
	for (auto e: sG[u]) {
		ll v = e.to;
		if (!pre[v]) {
			ll lowv = dfs(v,u);
			lowu = min(lowu, lowv);
			if (lowv > pre[u]){
				if (M[P(u,v)]==1) isBridge[e.id] = true;
			}
		}
		else if (pre[v] <pre[u]&&fa!=v) lowu = min(lowu, pre[v]);
	}
	return low[u] = lowu;
}

ll ans[maxn];


int main() {
	scanf("%d%d", &V, &E);

	for (ll i = 0; i < E; i++) {
		ll x,y,cost;
		scanf("%lld%lld%lld",&x,&y,&cost);
		--x,--y;
		
		G[x].push_back(edge{y,cost,i});
		rG[y].push_back(edge{x,cost,i});	
	}
	dijkstra(0,G,d);
	dijkstra(1,rG,d2);
	for(ll i = 0; i < V; i++)
	for (auto e:G[i]) {
		//cerr << i << " "  <<e.to <<" " << d[i] << " " << e.cost << " " << d[e.to] << endl;
		if (d[i] + e.cost == d[e.to]&&d[e.to]+d2[e.to]==d[1]) 
		{
			sG[i].push_back(e),sG[e.to].push_back(edge{i,e.cost,e.id});//cerr << i << " "  <<e.to<<endl; 
			M[P(i,e.to)]++;
		}
	}
	//cerr << "------" << endl;
	dfs(0,-1);
	//for (ll i = 0; i < E; i++) cerr<< isBridge[i] << " " ;
	//cerr<<endl;
	for(ll i = 0; i < V; i++)
	for (auto e:G[i]) {
		if (isBridge[e.id]) ans[e.id] = -1;
		else {
			if (d[e.to] + e.cost + d2[i] < d[1]) ans[e.id] = 1;
			else ans[e.id] = 0;
		}
	}
	for (ll i = 0; i < E; i++) {
		if (ans[i] == -1) puts("SAD");
		else if (ans[i] == 0) puts("SOSO");
		else puts("HAPPY");
	}
	
	

}



Measured memory_bytes: 45724
N = int(input())
A = [0]
B = list(map(int, input().split()))
for i in range(len(B)):
    A.append(B[i])
A.append(0)
S = []
cost = 0
pos = 0
for i in range(1, N + 1):
    cost += abs(A[i] - pos)
    pos = A[i]
    S.append(cost)
S.append(cost + abs(pos))

for i in range(N):
    print(S[-1] + abs(A[i] - A[i + 2]) - (abs(A[i] - A[i + 1]) + abs(A[i + 1] - A[i + 2])))

Measured memory_bytes: 14168
# n = int(input())
# def digitsum(x):
#     array = list(map(int, list(str(x))))
#     return sum(array)

# dsum = [digitsum(a)+digitsum(n-a) for a in range(1,int(n/2)+1)]
# print(min(dsum))
NL = list(map(int, list(input())))
 
if NL[0] == 1 and sum(NL) == 1:
    print(10)
else:
    print(sum(NL))

Measured memory_bytes: 2940
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		//String text = scan.next();
		int h[][] = new int[3][2];
		int m[][] = new int[3][2];
		int s[][] = new int[3][2];
		for(int i = 0 ; i < 3 ; i++){
			for(int j = 0 ; j < 2 ; j++){
				h[i][j] = scan.nextInt();
				m[i][j] = scan.nextInt();
				s[i][j] = scan.nextInt();
			}
		}
		for(int i = 0 ; i < 3 ; i++){
			int byou = h[i][1]*3600+m[i][1]*60+s[i][1]-(h[i][0]*3600+m[i][0]*60+s[i][0]);
			h[i][0] = byou/3600;
			m[i][0] = (byou % 3600)/60;
			s[i][0] = (byou % 3600)%60;
		}
		for(int i = 0 ; i < 3 ; i++){
			System.out.println(h[i][0] + " "+ m[i][0] +" "+ s[i][0]);
		}
	}
}

Measured memory_bytes: 26228
#N宿泊数
#K:料金X円の日数
#X:料金
#Y:割り増し料金
N=int(input()) #全宿泊日数
K=int(input()) #予定宿泊日数
X=int(input()) #基本料金
Y=int(input()) #割り増し料金
if N>K:
    S=K*X+(N-K)*Y
else: #早く帰るとき
    S=N*X
print(S)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.MSS", "r", stdin );
	int n;
	while (scanf ("%d", &n ), n ){
		vector<int> a (n+1, 0 );
		vector<int> sum (n+1, 0 );
		for (int i = 1; i <= n; i++ ){
			scanf ("%d", &a[i] );
		} // end rep
		for (int i = 1; i <= n; i++ ){
			sum[i] = sum[i-1] + a[i];
		} // end for
		int res = INT_MIN;
		for (int i = 1; i <= n; i++ ){
			int curr = 0;
			for (int j = i; j <= n; j++ ){
				curr = sum[j] - sum[i-1];
				res = max (res, curr );
			} // end for
		} // end for
		printf ("%d\n", res );
	} // end loop
	
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,y;
    cin >> n >> y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i*10000+j*5000+(n-i-j)*1000==y){
                if(n-i-j>=0){
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
                }
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
flag = [0]*(N+1)
for i, pi in enumerate(p):
    if pi==i+1:
        flag[i] = 1
ans = 0
cnt = 0
for i in range(N+1):
    if flag[i] == 1:
        cnt +=1
    else:
        ans+=(cnt+1)//2
        cnt = 0
print(ans)
        
        

Measured memory_bytes: 14008
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
using namespace std;
#define lol long long





int main()
{
	lol N;
	cin >> N;
	vector<lol> A(N);
	vector<lol> B(N);
	int C = 0;
	lol sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = abs(A[i]);
		if (A[i] < 0) {
			C++;
		}
		sum += B[i];
	}
	sort(B.begin(), B.end());
	if (C % 2 == 1) {
		cout << sum - (B[0] * 2) << endl;
	}
	else {
		cout << sum << endl;
	}
	
	
}

Measured memory_bytes: 1792
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    double x,s,h;
    while(cin>>x>>h){
        if(x==0&&h==0)break;
        s=x*x+x*sqrt(x*x+4*h*h);
       printf("%.6f",s);
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3212
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int a =0;
		int counter = 0;

		for (int n=1; n<=N;n=n+2){
			a = 0;
			for ( int j=1;j<=n;++j){
				if (n%j == 0) ++a;
			}
			if (a == 8) ++ counter;
		}

		System.out.println(counter);

	}

}

Measured memory_bytes: 22612
#include<stdio.h>
int main()
{
    long int a, sqr[100050];

    scanf("%ld", &a);

    long int m=a;

    long int max=0, v1=0, v2, cnt1=0;

    for(long int i=0; i<a; i++)
    {

        scanf("%ld", & sqr[i]);

        v2=sqr[i];

        if(v1>=v2)
        {
           cnt1++;
        }

        if(cnt1>max)
        {
            max=cnt1;
        }

        if(v1<v2)
        {
            cnt1=0;
        }

        v1=v2;
    }

    printf("%ld\n", max);


    return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)
#define pd(x) printf("%lf\n", x)
#define ps(x) printf("%s\n", x)
 
#define INF 1000000000000000000
#define MOD 1000000007

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

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

int next(long r, long D, long x) {
  return r * x - D;
}

int main() {
	long N, M;
  long i, j;
  long L, R;
  long l_check[100001] = {0};
  long r_check[100001] = {0};
  long check[100001] = {0};
  long cnt = 0;
	long ans = 0;
	
  sl(N); sl(M);
	
  for(i=1;i<=M;i++) {
    sl(L); sl(R);
    l_check[L]++;
    r_check[R]++;
  }
  
  for(i=1;i<=N;i++) {
    cnt += l_check[i];
    check[i] = cnt;
    cnt -= r_check[i];
    if(check[i] == M) ans++;
  }
  
  pl(ans);
  
	return 0;
}

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

b = [-1]*(n+1)
i = 0  # 回数
num = 1  # 場所
for j in range(k):
    if b[num] != -1:
        shu = i-b[num]
        ans = b[num]+(k-b[num]) % shu
        print(b.index(ans))
        exit()
    b[num] = i
    num = a[num-1]
    i += 1
print(num)

Measured memory_bytes: 32380
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    string ans;

    char next = sa[0];
    sa.erase(0,1);

    while(1){
        if (next == 'a')
        {
            if(sa.size()==0)
            {
                ans = 'A';
                break;
            }
            else
            {
                next = sa[0];
                sa.erase(0,1);
            }
        }
        else if(next == 'b')
        {
            if(sb.size()==0)
            {
                ans = 'B';
                break;
            }
            else
            {
                next = sb[0];
                sb.erase(0,1);
            }
        }
        else if(next == 'c')
        {
            if(sc.size()==0)
            {
                ans = 'C';
                break;
            }
            else
            {
                next = sc[0];
                sc.erase(0,1);
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define rloop(i, n, a) for(int i = (n); i >= (a); i--)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = int64_t;

constexpr ll mod = 1e9+7;

struct Comb {
    const ll mod;
    vector<ll> fact, ifact;
    ll mod_pow(ll x, ll n, const ll mod){
    ll ans = 1;
    while(n){
            if(n & 1) ans = ans*x%mod;
            x = x*x%mod;
            n >>= 1;
        }
        return ans;
    }
    Comb(int n, ll mod) : fact(n+1), ifact(n+1), mod(mod) {
        fact[0] = 1;
        loop(i, 1, n+1) fact[i] = fact[i-1] * i % mod;
        ifact[n] = mod_pow(fact[n], mod-2, mod);
        rloop(i, n, 1) ifact[i-1] = ifact[i] * i % mod;
    }
    ll operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
    }
};

int main(){
    int n, k; cin >> n >> k;
    vector<ll> a;
    rep(i, n) {
        ll x; cin >> x;
        a.push_back(x);
    }
    sort(all(a));

    Comb comb = Comb(n, mod);

    ll ans = 0;
    rep(ri, 2){
        rep(i, n){
            if(ri) ans -= a[i]*comb(i, k-1)%mod;
            else ans += a[i]*comb(i, k-1)%mod;
        }
        reverse(all(a));
    }
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2676
import itertools
n,m = map(int,input().split())

s = [[] for _ in range(m)]

for i in range(m):
	k,*t = map(int,input().split())
	for j in t:
		s[i].append(j-1)

targ = list(map(int,input().split()))
ans = 0
#print(s)

for i in itertools.product(range(2), repeat=n):
	tmpl = [0]*m
	
	for j in range(m):
		for k in s[j]:
			tmpl[j] += i[k]
	
	mode = 1
	
	for j in range(m):
		if tmpl[j]%2 != targ[j]:
			mode = 0
			break
	
	if mode:
		ans += 1

print(ans)

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

using lint = long long;

int main() {
    int N;
    cin >> N;
    vector<lint> a(3*N);
    for (int i = 0; i < 3*N; i++) {
        cin >> a[i];
    }

    priority_queue<lint, vector<lint>, greater<lint>> lq;
    vector<lint> lsum(N + 1);
    lsum[0] = 0;
    for (int i = 0; i < N; i++) {
        lq.push(a[i]);
        lsum[0] += a[i];
    }

    for (int i = 0; i < N; i++) {
        if (a[N + i] > lq.top()) {
            lsum[i + 1] = lsum[i] - lq.top() + a[N + i];
            lq.pop();
            lq.push(a[N + i]);
        } else {
            lsum[i + 1] = lsum[i];
        }
    }

    priority_queue<lint> rq;
    vector<lint> rsum(N + 1);
    rsum[0] = 0;
    for (int i = 2*N; i < 3*N; i++) {
        rq.push(a[i]);
        rsum[0] += a[i];
    }

    for (int i = 0; i < N; i++) {
        if (a[2*N - i - 1] < rq.top()) {
            rsum[i + 1] = rsum[i] - rq.top() + a[2*N - i - 1];
            rq.pop();
            rq.push(a[2*N - i - 1]);
        } else {
            rsum[i + 1] = rsum[i];
        }
    }

    lint ans = lsum[0] - rsum[N];
    for (int i = 1; i <= N; i++) {
        if (ans < lsum[i] - rsum[N - i]) {
            ans = lsum[i] - rsum[N - i];
        }
    }

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

Measured memory_bytes: 6516
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
#include <memory>
#include <climits>
#include <bitset>

constexpr long long MOD = 1000000007;

int main()
{
  int N;
  std::cin >> N;
  std::vector<std::string> strs(N);
  for (auto& str: strs)
    std::cin >> str;
  int beginBs = 0;
  int endAs = 0;
  int beginBEndAs = 0;
  int ans = 0;
  for (int j = 0; j < N; ++j)
  {
    auto& s = strs[j];
    for (int i = 0; i < (int)s.size() - 1; ++i)
    {
      if (s[i] == 'A' && s[i + 1] == 'B')
        ++ans;
    }
    auto c0 = s.front();
    auto c1 = s.back();
    if (c0 == 'B' && c1 =='A')
      beginBEndAs++;
    else if (c0 == 'B' && c1 != 'A')
      beginBs++;
    else if (c0 != 'B' && c1 == 'A')
      endAs++;
  }
  if (beginBEndAs)
  {
    ans += beginBEndAs - 1;
    if (endAs)
    {
      ++ans;
      --endAs;
    }
    if (beginBs)
    {
      ++ans;
      --beginBs;
    }
  }
  ans += std::min(beginBs, endAs);
  std::cout << ans << std::endl;
  return 0;
}



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

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

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    i64 n, w, s, e;
    n = w = s = e = 0;
    for(auto c : S){
        if(c == 'N') ++n;
        if(c == 'W') ++w;
        if(c == 'S') ++s;
        if(c == 'E') ++e;
    }
    if(((n == 0 && s == 0) || (n >= 1 && s >= 1)) && ((w == 0 && e == 0) || (w >= 1 && e >= 1))) cout << YES << endl;
    else cout << NO << endl;
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    double a, b;
    cin >> a >> b;
    cout << ceil((a + b) / 2) << endl;
    return 0;
}

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

int main()
{
  int q,i,j,beg,end;
  string str,com,p;
  char tmp;

  cin>>str;
  cin>>q;
  for(i=0;i<q;i++){
    cin>>com>>beg>>end;
    if(com=="replace"){
      cin>>p;
      str.replace(str.begin()+beg,str.begin()+end+1,p);
    } else if(com=="reverse"){
      reverse(str.begin()+beg,str.begin()+end+1);
    } else if(com=="print"){
      cout<<str.substr(beg,end-beg+1)<<endl;
    }
  }
}


Measured memory_bytes: 1220
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n,k,l;
map<pair<int,int>,int> m;

struct UF{
  int par[200001];
  int Rank[200001];
  void init(int n){
    for(int i=0;i<n;i++){
      par[i]=i;
      Rank[i]=0;
    }
  }
  int Find(int a){
    if(par[a]==a)return a;
    return par[a]=Find(par[a]);
  }
  bool same(int a,int b){
    return Find(a)==Find(b);
  }
  void Unite(int a,int b){
    if(Find(a)==Find(b))return;
    if(Rank[a]>Rank[b]){
      par[b]=a;
    }else{
      par[a]=b;
      if(Rank[a]==Rank[b]){
        Rank[a]++;
      }
    }
  }
  void Union(int a,int b){
    Unite(Find(a),Find(b));
  }
};
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n>>k>>l;
  UF load,train;
  load.init(n);
  train.init(n);
  for(int i=0;i<k;i++){
    int a,b;cin>>a>>b;
    a--;b--;
    load.Union(a,b);
  }
  for(int i=0;i<l;i++){
    int a,b;cin>>a>>b;
    a--;b--;
    train.Union(a,b);
  }
  for(int i=0;i<n;i++){
    int a=load.Find(i);
    int b=train.Find(i);
    m[pair<int,int>(a,b)]++;
  }
  for(int i=0;i<n;i++){
    int a=load.Find(i);
    int b=train.Find(i);
    cout<<m[pair<int,int>(a,b)];
    if(i!=n-1)cout<<" ";
  }
  cout<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 15232
#include<iostream>
#include<map>
#include<stdio.h>

using namespace std;

int main(){

  int in;
  while(1){
    cin >> in;
    if(in == 0) break;
    
    map<char, char> M;
    char a, b;  

    for(int i = 0; i < in; i++){
      cin >> a >> b;
      M[a] = b;
    }
    cin >> in;
    
    for(int i = 0; i < in; i++){
      cin >> a;
      if(M[a] != '\0') cout << M[a];
      else cout << a;
    }
    cout << endl;
  }
    
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    ll h;
    cin >> h;
    int bit = 0;
    ll ans=0;
    while (h > 0) {
        h /= 2;
        ans += pow(2, bit);
        bit++;
    }
    cout << ans << endl;


	return 0;
}



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

int main(){
    string s;
    cin >> s;
    if ((s.size()%2==0 && s[0] != s[s.size()-1]) || (s.size()%2!=0 && s[0] == s[s.size()-1])) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    int Q;
    string s;
    using P = pair<char, char>;
    vector<P> td;

    void input() {
        cin >> N >> Q;
        cin >> s;
        rep(i, 0, Q) {
            char t, d;
            cin >> t >> d;
            td.emplace_back(t, d);
        }
    }

    bool left_die(int k) {
        int pt = k;
        for (auto e : td) {
            if (s[pt] == e.first) {
                if (e.second == 'R') pt++;
                else pt--;
            }
            if (pt >= N) return false;
            if (pt < 0) return true;
        }
        return false;
    }

    bool right_die(int k) {
        int pt = k;
        for (auto e : td) {
            if (s[pt] == e.first) {
                if (e.second == 'R') pt++;
                else pt--;
            }
            if (pt >= N) return true;
            if (pt < 0) return false;
        }
        return false;
    }


    void solve() {
        input();
        int lok = -1, lng = N; //lokは死ぬ場所 , lngは死なない場所
        while (lng - lok > 1) {
            int mid = (lok + lng) / 2;
            if (left_die(mid)) {
                lok = mid;
            } else {
                lng = mid;
            }
        }

        int rok = N, rng = -1;
        while (rok - rng > 1) {
            int mid = (rok + rng) / 2;
            if (right_die(mid)) {
                rok = mid;
            } else {
                rng = mid;
            }
        }

        int ans = max(0, rng - lng + 1);
        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    string s;
    cin>>a>>s;
    string F=s.substr(0,a/2);
    string v=s.substr(a/2);
    if(a%2==1)
    {
        cout<<"No";
    }
    else
    {
        if(F==v)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }




	return 0;
}


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

int main() {
    int N = -1;
    int X = -1;
    vector<int> Ns;
    vector<int> Xs;
    while(N!=0 || X!=0) {
        cin >> N >> X;
        Ns.push_back(N);
        Xs.push_back(X);
    }

    Ns.pop_back(); 
    Xs.pop_back();
    rep(n, Ns.size()) {
        int cnt = 0;
        xrep(i, 1, Ns[n]+1) {
            xrep(j, i+1, Ns[n]+1) {
                xrep(k, j+1, Ns[n]+1) {
                    if(i+j+k==Xs[n]) ++cnt;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>

using namespace std;

typedef unsigned long long ull;

map<int,int> w;

int main(int argc,char** argv) {
	int a[3];
	for(int i = 0;i < 3;i++) {
		cin >> a[i];
		w[a[i]]++;
	}
	for(auto e:w) {
		if(e.second == 1) cout << e.first << endl;
	}
}


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vector<ll> a(n); cin >> a;
    vector<ll> sum(2, 0);
    sort(all(a), greater<ll>());
    rep(i, n) {
        sum[i%2] += a[i];
    }
    cout << sum[0] - sum[1] << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	cnt := 0
	for _, c := range s {
		if c == 'o' {
			cnt++
		}
	}
	if v := 15 - len(s) + cnt; v >= 8 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define y2 azdfsdgwre

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 1e7 + 123, MOD = 998244353;
int n, fact[N], rev[N];

int binpow(int x, int y) {
    int res = 1;
    while (y > 0) {
        if (y & 1) {
            res = (ll)res * x % MOD;
        }
        x = (ll)x * x % MOD;
        y /= 2;
    }
    return res;
}

int c(int x, int y) {
    if (y > x) {
        return 0;
    }
    return ((ll)fact[x] * rev[y] % MOD) * rev[x - y] % MOD;
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    fact[0] = rev[0] = 1;
    for (int i = 1; i < N; i++) {
        fact[i] = (ll)fact[i - 1] * i % MOD;
        rev[i] = (ll)rev[i - 1] * binpow(i, MOD - 2) % MOD;
    }
    cin >> n;
    int res = binpow(3, n);
    for (int i = n / 2 + 1; i <= n; i++) {
        res -= (ll)2 * binpow(2, n - i) * c(n, i) % MOD;
        if (res < 0) {
            res += MOD;
        }
    }
    cout << res;
}


Measured memory_bytes: 78336
A = []
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))
N = int(input())
dic = {0:False,1:False,2:False,3:False,4:False,5:False,6:False,7:False,8:False}
for i in range(N):
    called = int(input())
    for j in range(9):
        if called == A[j//3][j%3]:
            dic[j] = True
            continue
if dic[0] == dic[1] == dic[2] == True or dic[3] == dic[4] == dic[5] == True or dic[6] == dic[7] == dic[8] == True or dic[0] == dic[3] == dic[6] == True or dic[1] == dic[4] == dic[7] == True or dic[2] == dic[5] == dic[8] == True or dic[0] == dic[4] == dic[8] == True or dic[2] == dic[4] == dic[6] == True:
    print("Yes")
else:
    print("No")

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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




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

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

buysold = [0]*n
for i in range(n-1):
    if a[i+1] < a[i]:
        buysold[i] = 1
#print(buysold)
res = 1000
flag = False
kabu = 0
for i in range(n):
    if buysold[i] == 0 and not flag:
        kabu = res // a[i]
        res -= kabu*a[i]
        flag = True
    if buysold[i] == 1 and flag:
        res += kabu*a[i]
        kabu = 0
        flag = False

if buysold[n-1] == 0:
    res += kabu*a[n-1]
print(res)





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

/*
 * @title BinaryIndexedTree
 */
template<class Operator> class BinaryIndexedTree {
	using TypeNode = typename Operator::TypeNode;
	size_t depth;         
	size_t length;
	size_t num;
	vector<TypeNode> node;
public:
	
	//[0,N) constructed, inplace [0,1) + [1,N+1)
	//you can ignore inplace offset
	BinaryIndexedTree(const size_t num) : num(num) {
		for (depth = 1,length = 1; length < num; depth++,length *= 2);
		node.resize(length+1, Operator::unit_node);
	}
 
	//[idx,idx+1) update 
	void update(size_t idx, TypeNode var) {
		assert(0 <= idx && idx < length);
		for (++idx; idx <= length; idx += idx & -idx) node[idx] = Operator::func_node(node[idx],var);
	}

	//[0,idx) get
	TypeNode get(size_t idx) {
		TypeNode ret = Operator::unit_node;
		for (idx = min(length,idx); idx > 0; idx -= idx & -idx) ret = Operator::func_node(ret,node[idx]);
		return ret;
	}

	//return [0,length]
	int binary_search(TypeNode var) {
		if(!Operator::func_check(node.back(),var)) return num;
		TypeNode ret = Operator::unit_node;
		size_t off = 0;
		for(size_t idx = length; idx; idx >>= 1){
			if(off + idx <= length && !Operator::func_check(Operator::func_node(ret,node[off+idx]),var)) {
				off += idx;
				ret = Operator::func_node(ret,node[off]);
			}
		}
		return min(off,num);
	}

	void print() {
		cout << "{ " << get(1);
		for(int i = 1; i < length; ++i) cout << ", " << get(i+1);
		cout << " }" << endl;
	}
};

template<class T> struct NodePrefixSumPointAdd {
	using TypeNode = T;
	inline static constexpr TypeNode unit_node = 0;
	inline static constexpr TypeNode func_node(const TypeNode& l,const TypeNode& r){return l+r;}
	// Binary Search for first index where func_check is true
	inline static constexpr bool func_check(const TypeNode nodeVal,const TypeNode& val){return val <= nodeVal;}
};

template<class TypeNode> struct NodeUpdatePrefixGcd {
	TypeNode unit_node = 0;
	TypeNode func_node(const TypeNode& l,const TypeNode& r){return ((r == 0) ? l : func_node(r, l % r));}
	// Binary Search for first index at where func_check is true
	bool func_check(const TypeNode nodeVal,const TypeNode& var){return var == nodeVal;}
};

//verify https://atcoder.jp/contests/chokudai_S001/tasks/chokudai_S001_j
//verify https://atcoder.jp/contests/abc130/tasks/abc130_d

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
	BinaryIndexedTree<NodePrefixSumPointAdd<long long>> bit(N);
	for(int i=0;i<N;++i) {
		int a; cin >> a; bit.update(i,a);
	}
    while(Q--){
        int t,l,r; cin >> t >> l >> r;
        if(t) cout << bit.get(r)-bit.get(l) << "\n";
        else bit.update(l,r);
    }
    return 0;
}


Measured memory_bytes: 8436
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {

	public void solve(ArrayList<String> inLines) {
		long x = Long.parseLong(inLines.get(0));
		long ans = (x / 11) * 2;
		if (x % 11 != 0) {
			if (x % 11 <= 6)
				ans += 1;
			else
				ans += 2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 9556
n,m = map(int, input().split( ))

G =[[] for _ in range(n)]
E=[]
for i in range(m):
    ai,bi = map(int, input().split( ))
    ai-=1;bi-=1
    G[ai].append(bi)
    G[bi].append(ai)
    E.append((ai,bi))

#橋検出のライブラリを探してもいいが
#n~50と点数的に愚直にやってみる
ans = 0
from collections import deque
for i in range(m):
    V = [0]*n
    Q = deque()
    Q.append(0)
    V[0] = 1
    while Q:
        v = Q.popleft()
        for u in G[v]:
            if (E[i] != (v,u) and E[i]!= (u,v)) and not V[u]:
                V[u]=1
                Q.append(u)
    if 0 in V:
        ans += 1
print(ans)

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, int>>> v(n, vector<pair<int, int>>());
	for (int i = 0; i < m; i++) {
		int l, r, d;
		cin >> l >> r >> d;
		l--;
		r--;
		v[l].push_back(make_pair(r, d));
		v[r].push_back(make_pair(l, -d));
	}
	bool f = true;
	vector<int> x(n, INT_MAX);
	for (int i = 0; i < n && f; i++) {
		if (x[i] == INT_MAX) {
			x[i] = 0;
			queue<int> q;
			q.push(i);
			while (!q.empty() && f) {
				int j = q.front();
				q.pop();
				for (auto p : v[j]) {
					if (x[p.first] == INT_MAX) {
						x[p.first] = x[j] + p.second;
						q.push(p.first);
					} else {
						if (x[p.first] != x[j] + p.second) {
							f = false;
							break;
						}
					}
				}
			}
		}
	}
	cout << (f ? "Yes" : "No") << endl;
	return 0;
}


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

using namespace std;

int main() {
    int a, b, c, d;

    scanf("%d %d %d %d", &a, &b, &c, &d);

    printf("%d %d %d %d\n", c - d + b, d + c - a, a - d + b, b + c - a);

    return 0;
}

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

int main() {
    int month, day;
    string weekday[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    while (cin >> month >> day) {   
        if (month + day == 0) { break; }  
        time_t rawtime;
        struct tm * timeinfo;

        time(&rawtime);
        timeinfo = localtime(&rawtime);

        timeinfo->tm_year = 2004-1900;
        timeinfo->tm_mon = month - 1;
        timeinfo->tm_mday = day;
        
        mktime(timeinfo);

        cout << weekday[timeinfo->tm_wday] << endl;
    }
    return 0;
}

Measured memory_bytes: 1288
/* ex3_3
   masaaki52	*/
#include <stdio.h>
int main(void){
  int number,kisuu,ruijou,keta;
  scanf("%d %d",&number,&kisuu);//number,kisuuに値を入力
  ruijou = kisuu;//kisuuをruijouに代入
  keta = 1;//1をketaに代入
  while(number >= ruijou){//numberがruijou以上の間は
    ruijou = ruijou * kisuu;//ruijou*kisuuをruijouに代入
    keta += 1;//ketaに1を加える
  }
  printf("%d\n",keta);//ketaを出力
  return 0;
}


Measured memory_bytes: 128
#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;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0);cout<<fixed<<setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

#define pii pair<int,int>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i);
#define int long long int

signed main()
{
    string s,s1;
    cin>>s>>s1;
    string t="";
    for(int i=0;i<s1.size()-1;i++) t+= s1[i];
    if(s == t) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  int64_t N,A,B;
  cin>>N>>A>>B;
  if(A%2==B%2){cout<<(B-A)/2<<endl;}
  else{
    int64_t MIN=min(A-1,N-B);
    cout<<MIN+(B-A-1)/2+1<<endl;
  }
  
  return 0;  
}

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

int main()
{
    string s,t;
    cin>>s;
    t=s;
    reverse(t.begin(),t.end());
    int length=s.size(),num=0;
    for(int i=0;i<length;i++)
    {
        if(s[i]!=t[i])
        {
            num++;
        }
    }
    cout<<num/2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fr(n) for(int i=0;i<n;i++)
#define mod 1000000007


int32_t main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	string s;
	cin>>s;
	int n = s.length();
	int a[2020];
	fr(2019) a[i] = 0;
	a[0] = 1;
	int rem = 0;
	int mul=1;
	int c = 0;
	fr(s.length()){
		int d = s[n-i-1] - '0';
		d = (d*mul)%2019;
		mul = (mul*10)%2019;
		c = (c+d)%2019;
		//if(c==19) {cout<<c;}
		a[c]++;
	}
	int ans=0;
	//fr(2019) cout<<a[i]<<endl;
//	cout<<endl;
	fr(2019){
		ans =ans+(a[i]*(a[i]-1))/2;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll MOD = 998244353;

ll power(ll x, ll n){
    x %= MOD;
    ll res = 1;
    while(n > 0){
        if(n&1){
            res = res*x%MOD;
            res %= MOD;
        }
        x = x*x % MOD;
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return power(x, MOD-2);
}

// ラグランジュ補完
ll p(vector<ll> y, ll t){
    ll n = ll(y.size())-1, q = 1, res = 0;
    if(t <= n) return y[t];
    for(ll i=0;i<=n;i++){
        q *= t-i;
        q = (q%MOD+MOD)%MOD;
    }
    vector<ll> fac(n+1), inv(n+1);
    fac[0] = 1; inv[0] = 1;
    for(ll i=0;i<n;i++){
        fac[i+1] = fac[i]*(i+1)%MOD;
        inv[i+1] = mod_inv(fac[i+1]);
    }
    for(int i=0;i<=n;i++){
        ll tmp = y[i] * q % MOD * inv[i] % MOD * inv[n-i] % MOD * mod_inv(t-i);
        if((n-i)&1) res -= tmp;
        else res += tmp;
        res = (res%MOD+MOD)%MOD;
    }
    return res;
}

int main(){
    ll N, S, ans = 0;
    cin >> N >> S;
    ans = (S+1)*S/2 %MOD * power(S+1,N-2) % MOD;
    vector<ll> a(N+2), b(N+2);
    for(ll i=1;i<=N+1;i++){
        a[i] = (a[i-1] + power(i*2-1, N-1)) %MOD;
        b[i] = (b[i-1] + power(i*2, N-1)) %MOD;
    }
    ll od, ev;
    od = p(a, (S+1)/2);
    ev = p(b, S/2);
    if(S&1LL){
        ans += od - ev;
    }
    else{
        ans += ev - od;
    }
    ans = (ans%MOD + MOD) % MOD;
    cout << ans << endl;
    return 0;
}


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

def check():
    if D[0] != 0:
        return False
    t = sorted(list(set(D)))
    if t == list(range(len(t))):
        return True
    return False


def main():
    if check() == False:
        print(0)
        return

    C = {}
    m = 0
    for d in D:
        C[d] = C.get(d,0) + 1
        m = max(m, d)

    if C[0] > 1:
        print(0)
        return

    ans = 1
    for i in range(1,m+1):        
        ans *= (C[i-1] ** C[i])

    print(ans % 998244353)

main()

Measured memory_bytes: 21140
#include <stdio.h>
#include <string.h>

int main()
{
	char inputS[101];
	scanf("%s", inputS);

	// Get length of an inputed string
	long len = strlen(inputS);

	// Change every letter in string into 'x'
	for (int i = 0; i < len; i++)
	{
		inputS[i] = 'x';
	}

	printf("%s \n", inputS);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>

using namespace std;

int x1, x2, x3, x4, y1, y2, y3, y4;

int main()
{
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int a = x1-x2, b = y1-y2;
    x3 = x2+b; y3 = y2-a;
    x4 = x1+b; y4 = y1-a;
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}


Measured memory_bytes: 256