akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	int N; cin >> N;

	int c = 0, ans = 0;

	for (int i = 0; i < N; i++) {
		int a, b; cin >> a >> b;
		if (a == b) { c++; }
		else { c = 0; }
		chmax(ans, c);
	}

	if (ans >= 3) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

Measured memory_bytes: 3636
c = []
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
b = [c[0][0], c[0][1], c[0][2]]
if (c[1][0] - b[0] == c[1][1] - b[1]) and (c[1][1] - b[1] == c[1][2] - b[2]) and \
   (c[2][0] - b[0] == c[2][1] - b[1]) and (c[2][1] - b[1] == c[2][2] - b[2]) :
   print('Yes')
else :
    print('No') 

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

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

    static int dist[2000][2000];
    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    for(int i=0;i<n;++i){
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int t = q.front();
            q.pop();
            if(t > 0 && t-1 != i && dist[i][t-1] == 0){
                dist[i][t-1] = dist[i][t] + 1;
                q.push(t-1);
            }
            if(t+1 < n && t+1 != i && dist[i][t+1] == 0){
                dist[i][t+1] = dist[i][t] + 1;
                q.push(t+1);
            }
            if(t == x && y != i && dist[i][y] == 0){
                dist[i][y] = dist[i][t] + 1;
                q.push(y);
            }
            if(t == y && x != i && dist[i][x] == 0){
                dist[i][x] = dist[i][t] + 1;
                q.push(x);
            }
        }
    }
    static int cnt[2001];
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            ++cnt[dist[i][j]];
        }
    }
    for(int k=1;k<n;++k) cout << cnt[k] << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e9
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
inline ll fac(ll n){
    ll res=0;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
           if(n/i!=i)res+=2;
           else res+=1;
        }
    }
    return res;
}
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         ll n,ans=0;cin>>n;
         for(ll i=1;i<n;i++){
            ans+=(n-1)/i;
         }
         cout<<ans<<"\n";
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<"debug... "<<n1<<"\n"
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    if (n%2==0)
    {
        n/=2;
        ll x1=5;
        ll ans=0;
        while (x1<=n)
        {
            ans+=(n/x1);
            x1*=5;
        }
        cout<<ans<<"\n";
    }
    else
    {
        cout<<"0\n";
    }
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdint>
#include <tuple>
#include <vector>
 
template <typename Abelian> class PotentializedUnionFind {
 
public:
  using value_type = Abelian;
  using reference = value_type &;
  using const_reference = const value_type &;
  using size_type = std::uint_fast32_t;
 
private:
  std::vector<std::tuple<bool, size_type, value_type>> tree;
  value_type potential(const size_type x) {
    find(x);
    return std::get<2>(tree[x]);
  }
 
public:
  PotentializedUnionFind(const size_type size)
      : tree(size, std::forward_as_tuple(1, 1, value_type())) {}
  size_type find(const size_type x) {
    assert(x < tree.size());
    if (std::get<0>(tree[x]))
      return x;
    const size_type t = std::get<1>(tree[x]);
    std::get<1>(tree[x]) = find(t);
    std::get<2>(tree[x]) = std::get<2>(tree[t]) + std::get<2>(tree[x]);
    return std::get<1>(tree[x]);
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return potential(y)+ (-potential(x));
  }
  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + diff(y, x);
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (std::get<1>(tree[x]) < std::get<1>(tree[y]))
      std::swap(x, y), d = -d;
    std::get<1>(tree[x]) += std::get<1>(tree[y]);
    tree[y] = std::forward_as_tuple(0, x, d);
    return true;
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return std::get<1>(tree[find(x)]);
  }
  size_type size() const noexcept { return tree.size(); }
  bool empty() const noexcept { return tree.empty(); }
};
 
#include<iostream>
int main(void) {
	int n, m;
	std::cin >> n >> m;
	PotentializedUnionFind<int> T(n);
	while (m--) {
		int l, r, d;
		std::cin >> l >> r >> d;
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				std::cout << "No" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "Yes" << std::endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
int N, K;
LL L;
int a[200010];
 
bool judge(int x){
    LL cnt = 0;//x以下となる区間を数える
    vector<int> sum = { 0 };//sum[i]には区間[1, i]までのｘ以下の数の個数を保存
    for(int i = 1; i <= N; i++){
        sum.push_back(sum[i - 1]);
        if(a[i] <= x) sum[i]++;
        if(sum[i] - K < 0) continue;
 
        LL r = upper_bound(sum.begin(), sum.end(), sum[i] - K) - sum.begin();
        r = min(r, 1LL * (i - K + 1));
        cnt += r;
    }
    return cnt >= L;
}
 
int solve(){
    int lb = 0, ub = N;
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        if(judge(mid)){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    return ub;
}
 
void input(){
    cin >> N >> K >> L;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
    }
}
 
int main(){
    input();
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 5472
import numpy as np

input()
A = np.sort(np.array(list(map(int, input().split()))))

while A.size > 1:
    A[1:] = A[1:] % A[0]
    A = np.unique(A)
    if A[0] == 0:
        A = A[1:]

print(A[0])

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    vector<int> dp(100100);
    dp[1] = 0;
    for (int i = 2; i <= N; i++) {
        dp[i] = dp[i - 1] + abs(H[i - 1] - H[i - 2]);
        for (int j = 1; j <= K && i - j > 0; j++) {
            dp[i] = min(dp[i], dp[i - j] + abs(H[i - 1] - H[i - 1 - j]));
        }
    }
    cout << dp[N] << endl;
}

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

int z_find(string s){
  reverse(s.begin(),s.end());
  int count=0;
  for(int i=0;i<s.size();i++){
    count++;
    if(s[i]=='Z') break;
  }
  int ans =s.size()-count;
  return ans;
}

int main(){
  string s,S;
  cin >> s;
  int a=z_find(s);
  bool f = false;
  for(int i=0;i<a+1;i++){
    if(s[i]=='A') f=true;
    if(f){
      S=S+s[i];
    }
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 1428
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n;
int A[mn];
// main solution goes here:
void execute(int test_number)
{
    cin>>n;
    for (int i=1; i<=n; i++) cin>>A[i];
    sort(A+1, A+n+1);
    int ans = 0;
    for (int i=1; i<=n; i++) {
        for (int j=i+1; j<=n; j++) {
            for (int h=j+1; h<=n; h++) if (A[h] < A[i] + A[j] && A[h] != A[i] && A[i] != A[j] && A[j] != A[h]) {
                ans++;
            }
        }
    }
    cout<<ans;
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{ 
        public static void main(String[] args){
            int temp = 0;
                Scanner num = new Scanner(System.in);
                     int a = num.nextInt();
                     int b = num.nextInt();
                     int c = num.nextInt();
                    if(a>b){
                        temp = a;
                        a = b;
                        b = temp;
                    }
                    if(b>c){
                        temp = b;
                        b = c;
                        c = temp;
                    }
                    if(a>b){
                        temp = a;
                        a = b;
                        b = temp;
                    }
                System.out.printf("%d %d %d\n",a,b,c);
        }
    }


Measured memory_bytes: 26280
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long a = scanner.nextLong();
        long b = scanner.nextLong();

        long h[] = new long[n];
        for(int i = 0; i < n; i++)
        {
            h[i] = scanner.nextLong();
        }

        long l = 0;
        long r = (long)(1e9 + 1);
        while(l < r - 1)
        {
            long m = (l + r) / 2;
            long temp[] = new long[n];
            for(int i = 0; i < n; i++)
            {
                temp[i] = h[i];
            }
            for(int i = 0; i < n; i++){
                temp[i] -= b * m;
            }
            long x = 0;
            for(int i = 0; i < n; i++){
                if(temp[i] > 0){
                    if(temp[i] % (a - b) == 0)
                    {
                        x += temp[i] / (a - b);
                    }else{
                        x += (temp[i] / (a - b)) + 1;
                    }
                }
            }
            if (x > m) {
                l = m;
            }else{
                r = m;
            }
        }
        System.out.println(r);
    }
}


Measured memory_bytes: 62024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int nap[3][3];
	rep(i,3)rep(j,3)cin>>nap[i][j];
	int a2 = nap[0][1]-nap[0][0];
	int a3 = nap[0][2]-nap[0][0];
	int b2 = nap[1][0]-nap[0][0];
	int b3 = nap[2][0]-nap[0][0];
	bool ans = true;
	if(a2+b2 != nap[1][1]-nap[0][0])ans = false;
	if(a3+b2 != nap[1][2]-nap[0][0])ans = false;
	if(a2+b3 != nap[2][1]-nap[0][0])ans = false;
	if(a3+b3 != nap[2][2]-nap[0][0])ans = false;
	cout<<((ans)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
N, Y = map(int,input().split())
 
for x in range(N+1):
    y = float((-9*x)/4 + (Y-1000*N)/4000)
    if not y.is_integer():
        continue
    if 0 <= y <= N-x:
        z =  N-y-x
        print(int(x),int(y),int(z))
        exit()
 
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000
#define LL long long

int main(){
	
	int N,M;
	LL K;
	cin>>N>>M>>K;
	
	vector<LL> A(N),B(M);
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(i!=0)A[i] += A[i-1];
	}
	
	for(int i=0;i<M;i++){
		cin>>B[i];
		if(i!=0)B[i] += B[i-1];
	}
	A.insert(A.begin(),0LL);
	B.insert(B.begin(),0LL);
	
	int ans = 0;
	
	for(int i=0;i<=N;i++){
		LL t = K-A[i];
		if(t<0)continue;
		int d = distance(B.begin(),upper_bound(B.begin(),B.end(),t));
		ans = max(ans,i+d-1);
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 7972
#include <bits/stdc++.h>
using namespace std;
int i,j,k,count1=0,count2=0;
int gcd(int,int);
void ABC158();
void ABC161();
void ABC162();
void ABC163();
void ABC164();

int main(){
    ABC158();
}

void ABC158(){
    int a,b,ans=-1,x,y;
    cin>>a>>b;
    for(i=1;i<=10000;i++){
        x=i*8/100;
        y=i*10/100;
        if(a==x&&b==y){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 100000000000000
long long dp[2000][2000] = {};
long long inv[2000] = {};
long long done_before[2000] = {};
long long combi[2000][2000] = {};
long long combination(long long a,long long b) {
	if (combi[a][b] != 0) return combi[a][b];
	long long ans = 1;
	for (int i = 0;i < b;++i) {
		ans *= (a - i);
		ans %= MAX_MOD;
	}
	for (int i = 1;i <= b;++i) {
		ans *= inv[i];
		ans %= MAX_MOD;
	}
	return combi[a][b] = ans;
}
int main() {
	long long n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	dp[a-1][n] = 1;
	inv[1] = 1;
	//逆元
	for (int i = 2;i <= n;++i) {
		inv[i] = inv[MAX_MOD%i] * (MAX_MOD - MAX_MOD / i) % MAX_MOD;
	}
	for (long long i = a;i <= b;++i) {
		for (int j = n;j >= 0;--j) {
			if (dp[i - 1][j] != 0) {
				dp[i][j] += dp[i - 1][j];
				dp[i][j] %= MAX_MOD;
				long long multi = 1;
				long long hogee = j;
				for (int q = 0;q < d;++q) {
					if (hogee - i < 0) break;
					multi *= combination(hogee, i);
					multi %= MAX_MOD;
					multi *= inv[q + 1];
					multi %= MAX_MOD;
					hogee -= i;
					if (q >= c - 1) {
						dp[i][hogee] += multi * dp[i - 1][j];
						dp[i][hogee] %= MAX_MOD;
					}
				}
			}
		}
	}
	cout << dp[b][0]%MAX_MOD << endl;
	return 0;
}

Measured memory_bytes: 20096
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
using namespace std;
const long long MOD = 1000000007;

typedef long long ll;

vector<pair<int, int> > g[100010];
int n, u, v; int w, d[100010], visited[100010];

void
dfs(int i, int D)
{
  for (int j = 0; j < g[i].size(); j++) {
    int x = g[i][j].first;
    if (visited[x] == 0) {
      visited[x] = 1;
      d[x] = (D + g[i][j].second) % 2;
      dfs(x, d[x]);
    }
  }
  return;
}

  
int
main(int argc, char *argv[])
{
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &u, &v, &w);
    u--; v--;
    w %= 2;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }

  visited[0] = 1;
  dfs(0, 0);

  for (int i = 0; i < n; i++) printf("%d\n", d[i]);

  return 0;
}

  


Measured memory_bytes: 8704
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n>82)cout<<"No"<<endl;
    else{
        int flag=0;
        for(int i=1;i<=9;i++){
            if(n%i==0&&n/i<10)flag=1;
        }
        if(flag==1)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3548
#include<cmath>
#include<vector>
#include<climits>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<unordered_map>
using namespace std;

#define ld long double
#define ll long long int
#define pb push_back
#define mp make_pair
#define M 1000000007
#define f(i,a,b) for(int i=a;i<b;i++)

const int N=200;

struct hash_pair{
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const{
		auto hash1 = hash<T1>{}(p.first);
		auto hash2 = hash<T2>{}(p.second);
		return hash1 ^ hash2;
	}
};

void sieve(){
	bool prime[N+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=N;p++){
		if(prime[p] == true){
			for(int i=p*p;i<=N;i+=p)
				prime[i] = false;
		}
	}
}

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

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

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

	double n;
	cin>>n;
	cout<<(int)ceil(n/2)<<"\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;
 
int main()
{
  int N;
  int H[101];
  int res=1;
  cin >> N;
 
  rep(i,N) cin >> H[i];
 
  for(int i=1; i<N; i++) {
    bool oceanview=true;
    for(int j=0; j<i; j++){
      if(H[i]<H[j]) oceanview=false;
    }
    if(oceanview) res++;
  }
 
  cout << res << endl;
}

Measured memory_bytes: 256
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
namespace mmp = boost::multiprecision;
using llll = mmp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mmp::number<mmp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

struct s_t{
  ll u,v,w;
};

set<ll>a,b;
ll n;
map<ll,ll> mp;
vector<ll>vec;
vector<vector<ll> >v;

void dfs(ll x){              //v に関して深さ優先探索(vは頂点の番号)
  vec[x]=true;              //v に訪問済みの印を付ける

  for(ll i : v[x]){    //v に接続している各頂点i に対し
    if(vec[i]==false){
      ll u2,v2,w2;
      u2=x;
      v2=i;
      w2=mp[u2*1000000+v2];
      if(a.count(u2)){
        if(!(w2&1))a.insert(v2);
        else b.insert(v2);
      }
      else{
        if(!(w2&1))b.insert(v2);
        else a.insert(v2);
      }
      dfs(v2);           //i に関して深さ優先探索
    }
  }
}

int main(){
  cin>>n;
  if(n==1){
    cout<<1<<endl;
    return 0;
  }
  vec.assign(n,0);
  v.assign(n,vector<ll>());
  for(ll i=0;i<n-1;i++){
    s_t z;
    cin>>z.u>>z.v>>z.w;
    z.u--;
    z.v--;
    mp[z.u*1000000+z.v]=z.w&1;
    mp[z.v*1000000+z.u]=z.w&1;
    v[z.u].push_back(z.v);
    v[z.v].push_back(z.u);
  }
  a.insert(0);
  dfs(0);

  vector<ll>vvvv(n,0);
  for(auto x : a) {
    vvvv[x]=1;
  }
  for(ll i=0;i<n;i++){
    cout<<vvvv[i]<<endl;
  }
}


Measured memory_bytes: 26880
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll res = 1;
    while(res*2 <= N){
        res *= 2;
    }
    cout << res << endl;
    return 0;
}


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

int main()
{
    string S;
    cin >> S;
    string ans = "Good";
    for (int i = 0; i < S.size() - 1; i++)
    {
        if (S[i] == S[i + 1])
        {
            ans = "Bad";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,s;
  cin >> k >> s;
  int res = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (0 <= z && z <= k) res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from queue import Queue


def input_split(line):
    group, members = line.rstrip('.').split(':')
    members = members.split(',')
    return group, members


while True:
    n = int(input())
    if n == 0:
        exit()

    data = [input() for _ in range(n)]
    to = {}
    rev = {}
    sz = 0
    for line in data:
        group, members = input_split(line)
        if group not in to:
            to[group] = sz
            rev[sz] = group
            sz += 1
        for m in members:
            if m not in to:
                to[m] = sz
                rev[sz] = m
                sz += 1

    g = [[] for _ in range(sz)]
    indeg = [0] * sz
    for line in data:
        group, members = input_split(line)
        for m in members:
            g[to[m]].append(to[group]) 
            indeg[to[group]] += 1

    dp = [set() for i in range(sz)]
    q = Queue()
    for i in range(sz):
        if indeg[i] == 0:
            dp[i] |= {i}
            q.put(i)
    while not q.empty():
        cur = q.get()
        for nxt in g[cur]:
            dp[nxt] |= dp[cur]
            indeg[nxt] -= 1
            if indeg[nxt] == 0:
                q.put(nxt)
    
    print(len(dp[0]))



Measured memory_bytes: 7648
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int H;
  cin >> H;

  int n = 1;
  int ans = 0;

  while (H >= 1) {
    ans += n;
    n *= 2;
    H /= 2;
  }

  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main()
{
	int m,d,ct = 0,s,g;
	int i,j;
	cin >> m >> d;
	for(i = 2;i <= m;i++){
		for(j = 22;j <= d;j++){
			s = j / 10;
			g = j % 10;
			if(i == s * g && g > 1)
				ct++;
		}
	}
	cout << ct << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int A, B;

int calc1() {
  int a = min(B*10, A*25/2);
  int b = max(B*10, A*25/2);
  while (a<=b+1) {
    int c = a*2/25;
    int d = a*0.1;
    if (c == A && d==B) {
      return a;
    }
    a++;
  }
  return -1;
}

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

  cin >> A >> B;
  cout << calc1() << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  for(int i=0;i<tx-sx;i++)cout<<"R";
  for(int i=0;i<ty-sy;i++)cout<<"U";
  for(int i=0;i<tx-sx;i++)cout<<"L";
  for(int i=0;i<ty-sy+1;i++)cout<<"D";
  for(int i=0;i<tx-sx+1;i++)cout<<"R";
  for(int i=0;i<ty-sy+1;i++)cout<<"U";
  cout<<"LU";
  for(int i=0;i<tx-sx+1;i++)cout<<"L";
  for(int i=0;i<ty-sy+1;i++)cout<<"D";
  cout<<"R"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int M;
  cin >> M;
  int day = 0;
  for(int i = 0; i < M; i++){
    int Ai;
    cin >> Ai;
    day += Ai;
  }
  if(N < day){
    cout << -1 << endl;
  }else{
    cout << N-day << endl;
  }
}

Measured memory_bytes: 3632
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
using namespace std;
static int imin = std::numeric_limits<int>::min();
static int imax = std::numeric_limits<int>::max();
#define ll long long
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define debug(x) cout << #x << ":" << x << "\n";
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T>
std::istream& operator >> (std::istream& is, std::vector<T>& vec){
  T tmp;
  is >> tmp;
  vec.push_back(tmp);
  return is;
}
template <class T>
auto mkVec(unsigned int x){
  return std::vector<int>(x);
}

template <class T>
auto mkVec2(unsigned int x, unsigned int y){
  return std::vector<std::vector<T>>(x, std::vector<T>(y));
}

template <class T>
auto mkVec3(unsigned int x, unsigned int y, unsigned int z){
  return std::vector<std::vector<std::vector<T>>>(x, std::vector<std::vector<T>>(y, std::vector<T>(z)));
}

// 113C
// #ifndef BOOST_TEST_MAIN
// int main(int const argc, char const** argv){
//   int N, M;
//   cin >> N >> M;
//   vector<ll> P;
//   vector<ll> Y;
//   auto X = mkVec2<ll>(N + 1, 0);
//   rep(i, M){
//     ll p, y;
//     cin >> p >> y;
//     P.push_back(p);
//     Y.push_back(y);
//     X[p].push_back(y);
//   }
//   rep(i, N + 1){
//     sort(X[i].begin(), X[i].end());
//   }
//   rep(i, M) {
//     ll y;
//     rep(j, N + 1){
//       auto x = find(X[j].begin(), X[j].end(), Y[i]);
//       if(x != X[j].end()){
//         y = x - X[j].begin();
//         break;
//       }
//     }
//     printf("%06lld%06lld\n", P[i], y + 1);
//   }
// }
// #endif
#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  
  string S, T;
  cin >> S >> T;

  auto R = std::vector<std::vector<ll>>(2, std::vector<ll>(26, -1));

  rep(i, S.size()){
    auto s = S[i] - 'a';
    auto t = T[i] - 'a';
    if(R[0][s] == -1){
      R[0][s] = t;
    }
    if(R[1][t] == -1){
      R[1][t] = s;
    }
    if(R[0][s] != -1 && R[0][s] != t){
      cout << "No";
      return 0;
    }
    if(R[1][t] != -1 && R[1][t] != s){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  
}
#endif


Measured memory_bytes: 776
#include<iostream>

using namespace std;

int main() {

	char x, y;
	cin >> x >> y;

	if (x < y) {
		cout << "<" << endl;
	}
	else if(x > y){
		cout << ">" << endl;
	}
	else {
		cout << "=" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
h , w = map(int,input().split())
n = int(input())
a = tuple(map(int,input().split()))
line = []
for i in range (n) :
    line += [i+1] * a[i]
    
    
for j in range (h):
    p = j*w
    ans = line[p:p+w]
    
    if j % 2 == 1:
        ans = list(reversed(ans))
    for k in range(w-1) :
        print(ans[k],end=" ")
    print(ans[-1])

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define maxn 1000005
#define maxm 205
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
 
int n, m, k,sum;
char s[200005];
int main(){
	int i, j, x;
	scanf("%s",s+1);
	n=strlen(s + 1);
	for(i = 1;i <= n;i++) sum += s[i] - '0';
	if(sum%9==0) puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;

int main(){
  string S,T;
  cin >> S;
  S = S + S;
  cin >> T;
  
  bool chk = false;
  for(int i = 0; i < S.size()/2; i++){
    if(S.substr(i, S.size()/2) == T){
      chk = true;
    }
  }
  if(chk){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>=1 && a<=100){
         if(b>=1 && b<=100){
             if(c>=1 && c<=100){
                if(b-a==c-b){
                    cout<<"YES";
                }
                else{
                    cout<<"NO";
                }
             }
         }
    }
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int s[N], sum=0, min=101;

    for(int i=0; i<N; ++i) {
        cin >> s[i];
        sum += s[i];
        if(s[i]%10 != 0 && min > s[i])
            min = s[i];
    }

    if(min==101) cout << 0 << endl;
    else if(sum%10 != 0) cout << sum << endl;
    else cout << sum-min << endl;

    return 0;
}


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();
      int m = sc.nextInt();
      long[][] arr = new long[n][3];
      for(int i = 0; i < n; i++) {
        arr[i][0] = sc.nextLong();
        arr[i][1] = sc.nextLong();
        arr[i][2] = sc.nextLong();
      }

      long[] sum = new long[n];
      long max = 0;
      for(int a = -1; a <= 1; a += 2) {
        for(int b = -1; b <= 1; b += 2) {
          for(int c = -1; c <= 1; c += 2) {
            for(int i = 0; i < n; i++) {
              sum[i] = a * arr[i][0] + b * arr[i][1] + c * arr[i][2];
            }
            Arrays.sort(sum);
            long curSum = 0;
            for(int i = 0; i < m; i++) {
              curSum += sum[n - 1 - i];
            }
            max = Math.max(max, curSum);
          }
        }
      }

      System.out.println(max);
  }
}


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

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

int main(){
    i64 n;
    string s;
    cin >> n >> s;
    unordered_map<i64, i64> mp;
    vector<vector<bool>> dp1(n, vector<bool>(10, false)), dp2(n, vector<bool>(10, false));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 10; ++j){
            if(s[i] - '0' == j) dp1[i][j] = true;
            else if(i != 0) dp1[i][j] = dp1[i - 1][j];
        }
    }
    for(int i = n - 1; i >= 0; --i){
        for(int j = 0; j < 10; ++j){
            if(s[i] - '0' == j) dp2[i][j] = true;
            else if(i != n - 1) dp2[i][j] = dp2[i + 1][j];
        }
    }
    for(int i = 1; i < n - 1; ++i){
        for(int j = 0; j < 10; ++j){
            for(int k = 0; k < 10; ++k){
                i64 num = j * 100 + (s[i] - '0') * 10 + k;
                if(dp1[i - 1][j] && dp2[i + 1][k]) mp[num]++;
            }
        }
    }
    i64 ans = 0;
    for(int i = 0; i < 1000; ++i) if(mp[i] >= 1) ++ans;
    cout << ans << endl;
}


Measured memory_bytes: 4480
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Ord
import Data.Maybe
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B
import Data.Array.IO

main = do
  (n,m) <- getIntPair
  xys <- replicateM m getIntPair
  print =<< solve n xys

solve :: Z -> [(Z,Z)] -> IO Z
solve n xys = do
  cnt :: IOArray Z Z  <- newArray (1,n) 1
  ans :: IOArray Z Bool  <- newArray (1,n) False
  writeArray ans 1 True
  forM xys $ \ (x,y) -> do
    a <- readArray ans x
    c <- readArray cnt x
    when a $ writeArray ans y True
    when (c <= 1) $ writeArray ans x False
    writeArray cnt x (c-1)
    c2 <- readArray cnt y 
    writeArray cnt y (c2+1)
  as <- getElems ans
  return $ length (filter id as)


 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    int L;
    cin >> L;
    double a, b, c;
    a = (long double) L / 3;
    b = (long double) L / 3;
    c = (long double) L / 3;
    cout << std::setprecision(10) <<(double) a * b * c << endl;
}


Measured memory_bytes: 256
N = int(input())
a_list= []
for i in range(N):
    a_list.append(int(input()))
flag = False
target = 1
push_count = 0
while flag == False and push_count <= N:
    target = a_list[target - 1]
    push_count += 1
    if target == 2:
        print(push_count)
        flag = True
if flag == False:
    print(-1)

Measured memory_bytes: 7084
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
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 ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll MAX_N = 100100;

ll dp[MAX_N];//dp[i]がiについての答え


int main(){
    ll N; cin>>N;
	
    rep(i,MAX_N) dp[i]=N;
    dp[0]=0;
	
	for(int n=1; n<=N; n++){
		for(int j=1; j<=n; j*=6){
			dp[n]=min(dp[n], dp[n-j]+1);
		}
		for(int j=1; j<=n; j*=9){
			dp[n]=min(dp[n], dp[n-j]+1);
		}
    }
	
	cout<<dp[N]<<endl;
}

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

int main(){
    int K;
    string S;
    cin >> K;
    cin >> S;
    if(S.size() <= K){
        cout << S << endl;
    }else{
        for(int i=0; i < K; i++){
            cout << S[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <ccomplex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	set<int> s;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		s.insert(a);
	}
	if (s.size() == n) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <map>
#include <set>
#include <unordered_set>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    int n;
    vector<int> v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        v.push_back(t);
    }


    map<int, int> a,b;
    for (int i = 0; i < n; ++i) {
        if(i % 2 == 0){
            if(a.count(v[i]) == 0){
                a[v[i]] = 1;
            } else{
                a[v[i]]++;
            }
        } else{
            if(b.count(v[i]) == 0){
                b[v[i]] = 1;
            } else{
                b[v[i]]++;
            }

        }
    }

    int amax =0;
    int amax_size =0;
    for (auto itr = a.begin(); itr != a.end(); ++itr) {
        int size = itr->second;
        if(amax_size < size){
            amax = itr->first;
            amax_size = size;
        }
    }
    int amax2 =0;
    int amax2_size =0;
    for (auto itr = a.begin(); itr != a.end(); ++itr) {
        if(itr->first == amax){
            continue;
        }
        int size = itr->second;
        if(amax2_size < size){
            amax2 = itr->first;
            amax2_size = size;
        }
    }
    int bmax =0;
    int bmax_size =0;
    for (auto itr = b.begin(); itr != b.end(); ++itr) {
        int size = itr->second;
        if(bmax_size < size){
            bmax = itr->first;
            bmax_size = size;
        }
    }
    int bmax2 =0;
    int bmax2_size =0;
    for (auto itr = b.begin(); itr != b.end(); ++itr) {
        if (itr->first == bmax) {
            continue;
        }
        int size = itr->second;
        if (bmax2_size < size) {
            bmax2 = itr->first;
            bmax2_size = size;
        }
    }

    if(amax != bmax){
        int r = n - amax_size - bmax_size;
        cout << r << endl;
    }else{
        int r1 = n - amax_size - bmax2_size;
        int r2 = n - amax2_size - bmax_size;
        int r = (r1 < r2)? r1 : r2;
        cout << r << endl;
    }



    return 0;
}

Measured memory_bytes: 5368
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}
//BEGIN CUT HERE
// return sum of top K element (default: maximum)
template<typename T, T identity, typename V=vector<T>,
         typename C1=less<T>, typename C2=greater<T> >
struct PrioritySum{
  size_t num;
  T sum;  
  priority_queue<T, V, C1> pq1;
  priority_queue<T, V, C2> pq2;
  PrioritySum():num(0),sum(identity){}
  PrioritySum(size_t num):num(num),sum(identity){}

  void resolve(){
    assert(pq1.size()+pq2.size()>=num);
    while(pq2.size()<num){
      sum+=pq1.top();
      pq2.emplace(pq1.top());
      pq1.pop();
    }
    while(pq2.size()>num){
      sum-=pq2.top();
      pq1.emplace(pq2.top());
      pq2.pop();
    }
    if(pq1.empty()||pq2.empty()) return;
    while(C2()(pq1.top(),pq2.top())){
      T t1=pq1.top();pq1.pop();
      T t2=pq2.top();pq2.pop();
      sum+=t1;
      sum-=t2;
      pq1.emplace(t2);
      pq2.emplace(t1);
    }
  }

  T query(){resolve();return sum;}
  
  void push(const T &x){pq1.emplace(x);}
  void expand(){num++;}
  void shrink(){assert(num);num--;}
};
//END CUT HERE

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed ARC074_D(){
  using ll = long long;
  using PS1 = PrioritySum<ll, ll(0), vector<ll>, less<ll>, greater<ll> >;
  using PS2 = PrioritySum<ll, ll(0), vector<ll>, greater<ll>, less<ll> >;
  
  int n;
  cin>>n;
  vector<ll> a(3*n);
  for(int i=0;i<3*n;i++) cin>>a[i];

  PS1 ps1(n);
  vector<ll> dp1(3*n);
  for(int i=0;i<3*n;i++){
    if(i>=n) dp1[i]=ps1.query();
    ps1.push(a[i]);
  }
  
  PS2 ps2(n);
  vector<ll> dp2(3*n);
  for(int i=3*n-1;i>=0;i--){
    ps2.push(a[i]);
    if(i<=2*n) dp2[i]=ps2.query();
  }

  ll ans=dp1[n]-dp2[n];  
  for(int i=n;i<=2*n;i++) chmax(ans,dp1[i]-dp2[i]);
  
  cout<<ans<<endl;
  return 0;
}
/*
  verified on 2019/04/09
  https://atcoder.jp/contests/arc074/tasks/arc074_b 
*/

signed main(){
  ARC074_D(); 
  return 0;
}


Measured memory_bytes: 14064
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const double pi = acos(-1.0);
const long long inf = 100000000000LL;

int main() {
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	VL a(x), b(y), c(z);
	rep(i, x)cin >> a[i];
	rep(i, y)cin >> b[i];
	rep(i, z)cin >> c[i];

	priority_queue<LL> q;
	rep(i, x)rep(j, y) {
		q.push(a[i] + b[j]);
	}

	priority_queue<LL> q2;
	int cnt = 0;
	while (cnt != k && !q.empty()) {
		LL t = q.top(); q.pop();
		cnt++;
		rep(i, z)q2.push(t + c[i]);
	}

	cnt = 0;
	while (cnt != k) {
		cout << q2.top() << endl; q2.pop();
		cnt++;
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<int> P,Q,v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        P.push_back(x);
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        Q.push_back(x);
    }
    for (int i = 0; i < n; i++) {
        v.push_back(i+1);
    }
    int a, b, cnt = 1;
    do {
        bool f1 = 1, f2 = 1;
        for (int i = 0; i < n; i++) {
            if (P[i] != v[i]) f1 = 0;
            if (Q[i] != v[i]) f2 = 0;
        }
        if (f1) a = cnt;
        if (f2) b = cnt;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
N,K=[int(x) for x in input().split()]
if K%2:
  mod0=N//K
  print(mod0**3)
else:
  mod0,MODN=divmod(N,K)
  if MODN>=K//2:
    print(mod0**3+(mod0+1)**3)
  else:
    print((mod0**3)*2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        rep(i,n){
            map<string, int> word;
            string str;
            cin >> str;
            range(i,1,str.size()){
                string frontN, backN,frontR,backR;
                rep(j,i){
                    frontN+= str[j];
                }
                range(j,i, str.size()){
                    backN+= str[j];
                }
                //cout << frontN << endl << backN << endl << endl;
                for(int j = frontN.size() - 1; j >= 0; j--){
                    frontR += frontN[j];
                }
                for(int j = backN.size() - 1; j >= 0; j--){
                    backR += backN[j];
                }
                //cout <<frontR << endl << backR << endl << endl;
                word[frontN + backN] = 1;
                word[frontN + backR] = 1;
                word[frontR + backN] = 1;
                word[frontR + backR] = 1;
                word[backN + frontN] = 1;
                word[backN + frontR] = 1;
                word[backR + frontN] = 1;
                word[backR + frontR] = 1;
            }
            cout << word.size() << endl;
        }
    }
}

Measured memory_bytes: 1308
S = input()

Ucheck=S[2:4]
#print(Ucheck)
Ucheck=int(Ucheck)
Tcheck=S[0:2]
#print(Tcheck)
Tcheck=int(Tcheck)
YYMM="NO"
MMYY="NO"
#print(Ucheck)
#print(Tcheck)

if Ucheck!=0 and Ucheck<13:
    YYMM="OK"
if Tcheck!=0 and Tcheck<13:
    MMYY="OK"

if YYMM=="OK" and MMYY=="NO":
    print("YYMM")
elif YYMM=="NO" and MMYY=="OK":
    print("MMYY")
elif YYMM=="OK" and MMYY=="OK":
    print("AMBIGUOUS")
else:
    print("NA")



Measured memory_bytes: 3064