akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    vi G[N];
    vc<pi> edge;
    map<pi,int> m;
    rep(i,N-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].eb(b);
        G[b].eb(a);
        edge.eb(a,b);
    }
    queue<int> que;
    que.push(0);
    vi color(N,0);
    color[0]=-1;
    while(!que.empty()){
        int t=que.front(); que.pop();
        int c=1;
        for(auto a:G[t]){
            if(color[a]) continue;
            if(color[t]==c) c++;
            color[a]=c;
            m[pi(t,a)]=c;
            m[pi(a,t)]=c;
            c++;
            que.emplace(a);
        }
    }
    int K=1;
    rep(i,N-1){
        chmax(K,m[edge[i]]);
    }
    cout << K << endl;
    rep(i,N-1){
        cout << m[edge[i]] << endl;
    }
}

Measured memory_bytes: 21360
#include<stdio.h>

int V,E,R,S[500000],T[500000],D[500000];
int C[100000];
const int INF=10000*100000+100;
int i,t,j;

int main()
{

	for(i=0;i<100000;i++)
	{
		C[i]=INF;
	}

	scanf("%d",&V);
	scanf("%d",&E);
	scanf("%d",&R);

	C[R]=0;

	for(i=0;i<E;i++)
	{
		scanf("%d",&S[i]);
		scanf("%d",&T[i]);
		scanf("%d",&D[i]);
	}

	for(t=0;t<V;t++)
	{
		int update=-1;
		for(i=0;i<E;i++)
		{
			int s=S[i],t=T[i],d=D[i];
			if(C[s]<INF && C[t]>C[s]+d)
			{
				C[t]=C[s]+d;
				update=1;
			}
		}
		if(update==-1) break;
	}
	for(j=0;j<V;j++)
	{
		if(C[j]<INF)
			printf("%d\n",C[j]);
		else
			printf("INF\n");
	}
	return 0;
}

Measured memory_bytes: 7256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

Measured memory_bytes: 888
import java.io.*;
import java.util.*;


/**
 * AIZU ONLINE JUDGE
 * 0652
 *  2020/5/5
 */
public class Main {


    boolean main() throws IOException {

        Scanner sc = new Scanner(systemin);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        int w = A * 7 + B;
        int ret = C / w * 7 + Math.min(7, (C % w + A - 1) / A);
        result.printf("%d\n", ret);

        sc.close();
        return false;
    }



    PrintStream log;
    PrintStream result = System.out;
    BufferedReader systemin;

    static Main instance = new Main();

    Main() {
        systemin = new BufferedReader(new InputStreamReader(System.in));
        log = new PrintStream(new OutputStream() { public void write(int b) {} } );
    }

    public static void main(String[] args) throws IOException {

        instance.main();
        instance.systemin.close();
    }


}




Measured memory_bytes: 26560
#include<bits/stdc++.h>
#define mp make_pair
#define pr pair<ll,ll>
#define MAX 1000000
using namespace std;
typedef long long int ll;
#define mod 998244353
void sync(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main(){
	sync();
	ll t;
	t=1;
	ll k,n;
	for(ll testcase=1;testcase<=t;testcase++){
	cin>>k>>n;
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	ll mx=-1;
	for(ll i=0;i<n-1;i++){
		ll ck=abs(a[i]-a[i+1]);
		mx=max(mx,ck);
	}
	mx=max(mx,a[0]+(k-a[n-1]));
	cout<<k-mx<<endl;
	}
}

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

int main() {
  int s;
  cin >> s;
  bool flag_1 = false;
  bool flag_2 = false;
  int div_100 = s / 100;
  int rem_100 = s % 100;
  if(1 <= div_100 && div_100 <= 12) flag_1 = true;
  if(1 <= rem_100 && rem_100 <= 12) flag_2 = true;
  
  if(flag_1) {
    if(flag_2) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else {
    if(flag_2) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 3644
<?php
$n = intval(trim(fgets(STDIN)));
$sqrtN = sqrt($n);

$a = (int)ceil($sqrtN);
$d = (int)ceil($sqrtN);
$left = $a*$d - $n;
if($left == 0){
  // 二乗でぴったり
  $b = 0;
  $c = 0;
}else{
  // 二乗で余った分を、Y軸で調整する
  $b = 1;
  $c = $left;
}

echo "0 0 $a $b $c $d";

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P  = pair<int, int>;
int main() {
    string s, t;
    cin >> s >> t;
    int n = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] != t[i]) ++n;
    }
    cout << n << endl;
}

Measured memory_bytes: 3916
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] pn = new int[n+1];

        for (int i = n; i > 0; i--){
            int tmp = i;
            for(int j=2; tmp != 1;){
                if(tmp % j == 0){
                    pn[j]++;
                    tmp /= j;
                } else {
                    j++;
                }
            }
        }
        long result = 1;
        for(int count : pn){
            result = result * (count + 1)% 1000000007;
        }
        System.out.println(result );
    }
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,M;
  cin>>N>>M;
  vector<int>S(N),T(M);
  for(int i=0;i<N;i++)cin>>S[i];
  for(int i=0;i<M;i++)cin>>T[i];
  vector<vector<int>>dp(N+1,vector<int>(M+1,0));
  dp[0][0]=0;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=M;j++){
      dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;
      dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD;
      dp[i][j]=(dp[i][j]-dp[i-1][j-1])%MOD;
      if(dp[i][j]<0)dp[i][j]+=MOD;
      if(S[i-1]==T[j-1])dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%MOD;
    }
  }
  cout<<(dp[N][M]+1)%MOD<<endl;
  return 0;
}


Measured memory_bytes: 16000
#include "bits/stdc++.h"

using namespace std;

int main() {
	long long n, w;
	cin>>n>>w;
	
	vector<long long> dp(w+1);
	for(int i = 0;i<n;i++) {
		int x, y;
		cin>>x>>y;
		for(int current_weight = w-x; current_weight >= 0; current_weight--) {
			dp[current_weight+x] = max(dp[current_weight+x], dp[current_weight] + y);
		}
	}
	
	long long ans = 0;
	for(int i = 0;i<=w;i++) { 
		ans = max(ans, dp[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	char s[20];
	chin(s);
	s[3]='8';
	puts(s);
	return 0;
}

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

struct Point {
	int x; int y; int id;
	bool operator < (const Point &other) const {
		return x < other.x || (x == other.x && y < other.y);
	}
};

const int N = 110;
const double pi = acos(-1);

int n, k;
Point a[N];
Point c[N]; // convex hull
double res[N];

long long ccw(Point O, Point A, Point B) {
	A.x -= O.x; A.y -= O.y;
	B.x -= O.x; B.y -= O.y;
	return 1LL * A.x * B.y - 1LL * A.y * B.x;
}

double angle(Point O, Point A, Point B) {
	A.x -= O.x; A.y -= O.y; 
	B.x -= O.x; B.y -= O.y;
	double angleA = atan2(A.y, A.x);
	double angleB = atan2(B.y, B.x);
	double ret = angleA - angleB;
	while(ret < 0) ret += pi;
	while(ret >= pi) ret -= pi;
	return ret;	
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i].x >> a[i].y;
		a[i].id = i;
	}
	sort(a + 1, a + n + 1);

	for (int i = 1; i <= n; ++i) {
		while(k >= 2 && ccw(c[k - 2], c[k - 1], a[i]) >= 0) --k;
		c[k++] = a[i];
	}
	for (int i = n, t = k + 1; i >= 1; --i) {
		while(k >= t && ccw(c[k - 2], c[k - 1], a[i]) >= 0) --k;
		c[k++] = a[i];
	}
	--k;

	if (k == 2) {
		for (int i = 0; i < k; ++i) {
			res[c[i].id] = 0.5;
		}
	}
	else {
		for (int i = 0; i < k; ++i) {
			double cur = angle(c[i], c[(i - 1 + k) % k], c[(i + 1) % k]);
			res[c[i].id] = cur / (2 * pi);
		}
	}

	for (int i = 1; i <= n; ++i) {
		cout << setprecision(10) << fixed << res[i] << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n) {
		par = vector<int>(n, -1);
	}
	int root(int x) {
		if (par[x] < 0) return x;
		else return root(par[x]);
	}
	int size(int x) {
		return -par[root(x)];
	}
	bool unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return false;
		if (size(rx) < size(ry)) swap(rx, ry);
		par[rx] += par[ry];
		par[ry] = rx;
		return true;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int count() {
		int res = 0;
		rep(i, par.size()) {
			if (par[i] < 0) res++;
		}
		return res;
	}
};
int main() { // 問題文はしっかり読め!!!
	int n, m, k;
	cin >> n >> m >> k;
	V ans(n, 0);
	UnionFind G(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G.unite(a, b);
		ans[a]--, ans[b]--;
	}
	rep(i, n) {
		ans[i]+=G.size(i) - 1;
	}
	rep(i, k) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		if (G.same(a, b)) ans[a]--, ans[b]--;
	}
	rep(i, n) {
		cout << ans[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
//#define int long long
using LL = long long;
using namespace std;
using Graph = vector<vector<int>>;
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 INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

signed main(){
    fastcin();
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ans;
    vector<int> d(n, 0);
    if(n % 2 == 1){
        rep(i, m) ans.emplace_back(i, 2*m-1-i);
    }else{
        int rem = n-2*m-1;
        int l=m-1, r=m;
        rep(i, m){
            ans.emplace_back(l, r);
            if(i+1 == (m+1)/2){
                r+=rem;
            }
            l--; r++;
        }
    }
    repe(i, ans){
        cout << i.first+1 << " " << i.second+1 << endl;
    }
}

Measured memory_bytes: 4984
n = gets.chomp.to_i

n.times do
  line = gets.chomp.split
  3.times do |i| ## iに繰り返している回数を代入(1<=i<=3)
    line[i] = line[i].to_i
  end
  line.sort!
  if line[0]**2 + line[1]**2 == line[2]**2 ## **nでn乗を計算
    puts "YES"
  else
    puts "NO"
  end
end



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

class dice{
    public:
    int d[7];

    dice(){ //??????????????????????????????
    	
    }

    void east(){
    	d[0]=d[1],d[1]=d[4],d[4]=d[6],d[6]=d[3],d[3]=d[0];
    }

    void north(){
    	d[0]=d[5],d[5]=d[1],d[1]=d[2],d[2]=d[6],d[6]=d[0];
    }

    void turn(){
        d[0]=d[2],d[2]=d[4],d[4]=d[5],d[5]=d[3],d[3]=d[0];    
    }

};

int main(){
    dice D1,D2;
    int c=0;
    for(int i=1; i<7; i++)cin >> D1.d[i];
    for(int i=1; i<7; i++)cin >> D2.d[i];

    for(int i=1; i<7; i++){ 
        if(D1.d[1]==D2.d[1]){
            for(int j=0; j<4; j++){
                if(D1.d[2]==D2.d[2]){
                    if( D1.d[3]==D2.d[3] && D1.d[4]==D2.d[4] && D1.d[5]==D2.d[5] && D1.d[6]==D2.d[6] ){
                        cout << "Yes" << endl;
                        return 0;
                    }
                }        
                D2.turn();
            }
        }
        if(i%2==1)D2.east();
        else D2.north();
    }

    cout << "No" <<endl;   

    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*power((a*a)%mod,n/2))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int md = 998244353;
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
int n,k,ans = 1;
vector<int>adj[maxn],fact(maxn);

int ncr(int n,int r){

    if(n < r)return 0;
    int res = fact[n-r]%mod;
    res = inverse(res);
    res *= fact[n];
    res %= mod;
    return res;
}

void dfs(int x,int p){

    if(x == 1)ans *= ncr(k,sz(adj[1])+1);
    else ans *= ncr(k-2,sz(adj[x])-1);
    ans %= mod;
    for(auto &y:adj[x]){
        if(y != p){
            dfs(y,x);
        }
    }
}

signed main()
{
    showoff;
    fact[0] = 1;
    FOR(i,1,maxn)fact[i] = (fact[i-1]*i)%mod;
    cin >> n >> k;
    FOR(i,1,n){
        int u,v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1,1);
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...  

Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  for(int i=0;i<=n;++i){
    float curr = 1.0* i * 1.08;
    if(floor(curr)==n){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]

branch = [[] for _ in range(N)]
for i in range(N-1):
    branch[ab[i][0]-1].append(ab[i][1]-1)
    branch[ab[i][1]-1].append(ab[i][0]-1)

counters = [0 for _ in range(N)]
for i in range(Q):
    counters[px[i][0]-1] += px[i][1]
results = [0 for _ in range(N)]

seen = [False for _ in range(N)]
from collections import deque
seen[0] = True
todo = deque([0])
results[0] = counters[0]

while len(todo)>0:
    checking = todo.pop()
    candidates = branch[checking]
    for candidate in candidates:
        if seen[candidate] == False:
            todo.append(candidate)
            seen[candidate] = True
            results[candidate] = results[checking]+counters[candidate]


print((" ").join([str(i) for i in results]))


Measured memory_bytes: 144604
/**
	Language: C++
	Author  : 21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
	FastIO();
	int n;
	cin >> n;
	vi a(n), b(n, 0);
	for (int i = 1; i < n; ++i) {
		cin >> a[i];
		--a[i];
		b[a[i]]++;
	}
	for (int i = 0; i < n; ++i) {
		cout << b[i] << '\n';
	}
}


Measured memory_bytes: 4780
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

int main()
{
	ll k,a,b,ans=0;
	string s = "NG";

	cin >> k;
	cin >> a >> b;

	forll(i, a, b+1)
	{
		if (i % k == 0)
			s = "OK";
	}


	cout << s;

}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    if (x>y&&x>z)cout<<y+z;
    else if (y>z&&y>x)cout<<x+z;
    else cout<<x+y;
    return 0;
}

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

int main(){
    int a,b;
    char num[11];
    char tmp[3];
    while(scanf("%s",num) != EOF){
        for(int i=0;i<9;i++){
            for(int j=0;j<9-i;j++){
                a = num[j]-'0';
                b = num[j+1]-'0';
                a += b;
                sprintf(tmp,"%d",a);
                num[j] = tmp[strlen(tmp)-1];
            }
        }
        cout << num[0] << endl;
    }
}

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

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

    long long x, k, d;
    cin >> x >> k >> d;

    if (x > 0) {
        long long cur = min(k, x / d);
        x -= d * cur;
        k -= cur;
    } else {
        long long cur = min(k, -x / d);
        x += d * cur;
        k -= cur;
    }

    if (k % 2)
        if (x > 0)
            x -= d;
        else
            x += d;

    cout << abs(x) << '\n';
}

Measured memory_bytes: 3612
from itertools import combinations_with_replacement
from collections import Counter

N = int(input())

c = Counter()

def s(x, y, z):
    return x*x + y*y + z*z + x*y + y*z + z*x

for x, y, z in combinations_with_replacement(range(1, 100), 3):
    v = s(x, y, z)
    if x == y == z:
        c[v] += 1
    elif x == y or y == z or z == x:
        c[v] += 3
    else:
        c[v] += 6
for i in range(1, N+1):
    print(c[i])

Measured memory_bytes: 11676
N,X = map(int, input().split())
L_list = [int(e) for e in input().split()]

#1 回目は 座標 D1=0, 
#i 回目は 座標 Di=Di−1+Li−1(2≤i≤N+1) で跳ねます。
ans = 1
Before_Di = 0

for i in range(N):
  Di = Before_Di + L_list[i]
  #print(Di)
  if Di<=X:
    ans+=1
    Before_Di = Di
  else:
    break
    
print(ans)

Measured memory_bytes: 3060
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N, M = list(map(int, input().split(" ")))
    if N == 1 and M == 1:
        print("1")
    elif N == 1:
        print(M-2)
    elif M == 1:
        print(N-2)
    else:
        print((M-2)*(N-2))

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ll i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define int long long 
signed main() 
{
    fastio();

    int n,m;
    cin>>n>>m;
    vector<int>v(n);
    loop(i,0,n)cin>>v[i];
    int mx = *max_element(all(v));
    int el = mx*0.5;
    int i = 0;
    int found = 0;
    int lol = 0;
    while(el<=m && lol<=20000000)
    {
        i++;
        int f = 0;
        for(int j = 0;j<n;j++)
        {
            lol++;
            int p = (el-0.5*v[j])/v[j];
            if((p+0.5)*v[j] != el)
            {
                f = 1;
                break;
            }
        }
        if(f==0)
        {
            found = 1;
            // cout<<el;
            break;
        }
        el = mx*(i+0.5);
    }
    if(found==1)
    {
        int num = m/el;
        cout<<(num+1)/2;
    }
    else
        cout<<0<<endl;


    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>p(N);
    int ans = 0;
    rep(i, N) {
        cin >> p[i];
        ans += p[i];
    }
    sort(p.begin(), p.end());
    cout << ans - p[N - 1] / 2 << endl;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
vector<pair<pint,pint>>lis;
string fld[55];

bool vis[55][55][55][55];
int dp[3000][55][55];
int memo[3000];//26*10*10
int dfs(int v){
    int &ret=memo[v];
    if(ret!=-1)return ret;

    ret=0;
    fill_n(*dp[v],55*55,-1001001001);
    dp[v][lis[v].fi.fi][lis[v].fi.se]=0;
    int k=0;
    reps(i,lis[v].fi.fi,lis[v].se.fi+1){
        reps(j,lis[v].fi.se,lis[v].se.se+1){
            if(fld[i][j]=='#')continue;
            if(i+1<=lis[v].se.fi&&fld[i+1][j]!='#')chmax(dp[v][i+1][j],dp[v][i][j]);
            if(j+1<=lis[v].se.se&&fld[i][j+1]!='#')chmax(dp[v][i][j+1],dp[v][i][j]);

            while(k<lis.size()){
                bool ok=true;
                if(lis[k].fi<pint(i,j))ok=false;
                if(lis[k].fi==pint(i,j)&&(lis[k].se.fi>lis[v].se.fi||lis[k].se.se>lis[v].se.se))ok=false;
                if(lis[k].fi==lis[v].fi||lis[k].se==lis[v].se)ok=false;
                if(!ok){
                    k++;
                    continue;
                }
                if(lis[k].fi==pint(i,j)){
                    int tmp=dp[v][i][j]+dfs(k)+1;
                    if(lis[k].se.fi+1<=lis[v].se.fi)chmax(dp[v][lis[k].se.fi+1][lis[k].se.se],tmp);
                    if(lis[k].se.se+1<=lis[v].se.se)chmax(dp[v][lis[k].se.fi][lis[k].se.se+1],tmp);
                    k++;
                }
                else break;
            }
        }
    }

    return ret=dp[v][lis[v].se.fi][lis[v].se.se];
}

signed main(){
    while(cin>>H>>W,H||W){
        rep(i,H)cin>>fld[i+1];
        fld[0]=fld[H+1]=string(W,'#');
        fld[0][0]=fld[H+1][W-1]='.';
        H+=2;

        memset(vis,0,sizeof(vis));
        rep(a,H)rep(b,W){
            if(fld[a][b]=='#')continue;
            vis[a][b][a][b]=true;
            rep(c,H)rep(d,W){
                if(!vis[a][b][c][d])continue;
                if(c+1<H&&fld[c+1][d]!='#')vis[a][b][c+1][d]=true;
                if(d+1<W&&fld[c][d+1]!='#')vis[a][b][c][d+1]=true;
            }
        }

        if(!vis[0][0][H-1][W-1]){
            cout<<-1<<endl;
            continue;
        }

        lis.clear();
        lis.pb(make_pair(pint(0,0),pint(H-1,W-1)));
        rep(a,H)rep(b,W)rep(c,H)rep(d,W){
            if(a>c||b>d)continue;
            if(!islower(fld[a][b])||!isupper(fld[c][d]))continue;
            if(toupper(fld[a][b])!=fld[c][d])continue;
            if(vis[a][b][c][d]){
                lis.pb(make_pair(pint(a,b),pint(c,d)));
            }
        }

        sort(all(lis));
        memset(memo,-1,sizeof(memo));
        cout<<dfs(0)<<endl;
    }
    return 0;
}

Measured memory_bytes: 26396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  string c1, c2;
  cin >> c1 >> c2;

  if (c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

#define size_t int

using namespace std;
typedef long l;
typedef long long ll;

size_t mod(size_t a, size_t b) {
    return ((b + (a % b)) % b);
}

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

  string str;
  cin >> str;

  std::cout << "ABC" << str << '\n';

  return 0;
}


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

using namespace std;

int main()
{
  int n, m;
  while(cin >> n >> m, n || m){
    long long ans = 0;
    string N[100], B[1000];
    int M[100], cnt[100] = {0};
    for(int i = 0; i < n; i++){
      cin >> N[i] >> M[i];
      for(int j = 0; j < 8; j++){
	if(N[i][j] == '*') cnt[i]++;
      }
    }
    for(int i = 0; i < m; i++) cin >> B[i];
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
	if(N[i].substr(cnt[i], N[i].size() - cnt[i]) == B[j].substr(cnt[i], N[i].size() - cnt[i])) ans += M[i]; 
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1268
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    mod = 1000000007

    N = int(input())
    d = input().rstrip()
    input()
    domino = []
    i = 0
    #横０縦1
    if len(d)==1:
        print(3)
        exit()
    if len(d)==2:
        print(6)
        exit()
    while 1:
        if d[i]==d[i+1]:
            domino.append(0)
            i += 2
        else:
            domino.append(1)
            i += 1
        if i==len(d)-1:
            domino.append(1)
            break
        if i==len(d):
            break
    if domino[0]:
        res = 3
    else:
        res = 6
    for i in range(1, len(domino)):
        if domino[i-1]:
            res *= 2
        else:
            if not domino[i]:
                res *= 3
    print(res%mod)
            

if __name__ == '__main__':
    main()

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

#define MAX_N 10000000

using namespace std;

typedef long long lint;

const int MOD = 998244353;

int n;

lint putere(int a, int b)
{
    lint rez = 1;
    lint ca = a;
    for(int i = 0; (1 << i) <= b; i ++)
    {
        if(((1 << i) & b) != 0)
        {
            rez *= ca;
            rez %= MOD;
        }

        ca *= ca;
        ca %= MOD;
    }

    return rez;
}

lint p2[MAX_N + 1];
lint fact[MAX_N + 1];
lint inv[MAX_N + 1];

void euclid(lint a, lint b, lint &x, lint &y, lint &d)
{
    if(b == 0)
    {
        x = 1;
        y = 0;

        d = a;
        return;
    }

    lint xx, yy, q = a / b;
    euclid(b, a % b, xx, yy, d);
    x = yy;
    y = xx - yy * q;
}

lint comb(int n, int k)
{
    return (fact[n] * inv[k] % MOD * inv[n - k] % MOD);
}

int main()
{
    cin >> n;

    p2[0] = 1;
    fact[0] = 1;
    for(int i = 1; i <= n; i ++)
    {
        p2[i] = (p2[i - 1] << 1) % MOD;
        fact[i] = fact[i - 1] * i % MOD;
    }

    lint x, y, d;
    euclid(fact[n], MOD, x, y, d);
    if(x < 0)
        x = MOD + x % MOD;

    //cout << fact[n] << " " << x << "\n";
    //cout << fact[n] * x % MOD << "\n";

    inv[0] = 1;
    inv[n] = x;
    for(int i = n - 1; i >= 1; i --)
        inv[i] = inv[i + 1] * (i + 1) % MOD;

       // cout << inv[1] << "\n";

    lint rez = putere(3, n);
    lint sum = 0;
    for(int i = (n >> 1) + 1; i <= n; i ++)
    {
      //  cout << n << " " << i << " " << comb(n, i) << " " << p2[n - i] << "\n";
        sum += comb(n, i) * p2[n - i] % MOD;
        if(sum >= MOD)
            sum -= MOD;
    }

    rez = rez - (sum << 1);
    while(rez < 0)
        rez += MOD;

    cout << rez << "\n";

    return 0;
}


Measured memory_bytes: 234624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;

int main() {
    int n;
    string s;
    cin >> n >> s;
    ll sum = 0;
    ll wrong = 0;
    ll num_r = 0;
    ll num_g = 0;
    ll num_b = 0;
    rep(i,n) {
        if (s[i] == 'R') num_r++;
        if (s[i] == 'G') num_g++;
        if (s[i] == 'B') num_b++;
    }
    sum += num_r*num_g*num_b;
    if (sum == 0) {cout << 0 << endl; return 0;}
    rep(i,n) {
        REP(j,n) {
            if (i+j >= n || i+2*j >= n) continue;
            if (s[i] != s[i+j] && s[i+j] != s[i+2*j] && s[i+2*j] != s[i]) wrong++;
        }
    }
    cout << sum-wrong << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MAXN = 1e5+ 9;
#define INF 0x3f3f3f3f
vi g[MAXN];
int n, cnt, grau[MAXN];
pii edge[MAXN];
map<pii, int> mp;

void dfs(int u, int color, int p){
    bool first = p == u;
    int c = 1;
    trav(a, g[u]){
        if (a != p){
            if (c == color && color != INF){
                c = color + 1;
                mp[make_pair(a, u)] = mp[make_pair(u, a)] = c;
                dfs(a, c, u);
                c++;
            }
            else{
                dfs(a, c, u);
                mp[make_pair(a, u)] = mp[make_pair(u, a)] = c;
                c++;
            }
        }
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    
    cin >> n;
    rep(i, 0, n - 1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[i].first = a; edge[i].second = b;
        g[a].push_back(b);
        g[b].push_back(a);
        grau[a]++, grau[b]++;
    }
    rep(i, 0, n)
        cnt = max(cnt, grau[i]);
    dfs(0, INF, 0);
    cout << cnt << '\n';
    rep(i, 0, n-1){
        cout << mp[edge[i]] << '\n';
    }
    return 0;
}

Measured memory_bytes: 21632
#include <stdio.h>
int main(){
  int a,b,c,n;
  scanf("%d",&n);
  c=n%10;
    n=n-c;
  b=n%100;
  n=n-b;
  if(c==1) c=9;
    else c=1;
      if (b==10) b=90;
        else b=10;
  if (n==100) n=900;
  else n=100;
  printf("%d",c+b+n);
  return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	FOR(i, 1, 10) FOR(j, 1, 10) if (i * j == n)
	{
		cout << "Yes";
		return 0;
	}
	cout << "No";
	
	return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    ll n, x;
    cin >> n >> x;
    ll l[n];
    for (ll i = 0; i < n; i++) {
        cin >> l[i];
        if (l[i] >= x) l[i] = l[i] - x;
        else l[i] = x - l[i];
    }
    sort(l, l + n);
    ll ans = l[0];
    for (ll i = 1; i < n; i++) ans = gcd(ans, l[i]);

    cout << ans << endl;
}


Measured memory_bytes: 1024
/*input
4 5 10
1 2 1
1 4 1
3 4 1
2 2 100
3 3 100
*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=5005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
struct edge{
    int s,e,w;
};
vector<edge> v;
vector<pii> v2[maxn];
vector<pii> v3[maxn];
int dist[maxn];
bool vis[maxn];
int ok[maxn];
void dfs(int u){
vis[u]=true;
    for(pii x:v2[u]){
        assert(x.f>=0);
        if(!vis[x.f]){
          
            dfs(x.f);
            
        }
      ok[x.s]++;
    }
}
void dfs2(int u){
  vis[u]=true;
    for(pii x:v3[u]){
      assert(x.f>=0);
        if(!vis[x.f]){
          
            dfs2(x.f);
         
            
        }
      ok[x.s]++;
    }
}
bool neg(int n,int m){
    REP(i,n) dist[i]=INF;
    dist[0]=0;
    REP(i,n-1){
        REP(j,m){
            int a=v[j].s,b=v[j].e;
            if(ok[j]!=2) continue;
            if(dist[a]!=INF and dist[a]+v[j].w<dist[b]){
                dist[b]=dist[a]+v[j].w;
            }
        }
    }
        REP(j,m){
            int a=v[j].s,b=v[j].e;
            if(ok[j]!=2) continue;
            if(dist[a]!=INF and dist[a]+v[j].w<dist[b]){
                return true;
            }
        }

        return false;

}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,p;
    cin>>n>>m>>p;
    REP(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        --a;
        --b;
        v.push_back({a,b,p-c});
        v2[a].pb({b,i});
        v3[b].pb({a,i});
		//cout<<a<<' '<<b<<' '<<i<<'\n';
    }
    FILL(vis);
  FILL(ok);
    dfs(0);
    FILL(vis);
    dfs2(n-1);
    if(neg(n,m)){
        cout<<-1;
        return 0;
    }
    cout<<max(0,-dist[n-1]);
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		double x1= scanner.nextDouble();
		double y1 = scanner.nextDouble();
		
		double x2 = scanner.nextDouble();
		double y2 = scanner.nextDouble();
		
		double d = Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
		System.out.printf("%1$.8f", d);
	}
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define int long long 

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

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

  vi a(3*n);
  rep(i, 3*n) cin >> a[i];

  priority_queue<int, vector<int>, greater<int>> que1;
  int sum1 = 0;
  rep(i, n){
    sum1 += a[i]; 
    que1.push(a[i]);
  }

  vi b(n+1); 
  b[0] = sum1;
  rep(i, n){
    que1.push(a[i+n]);
    int t = que1.top();
    que1.pop();
    b[i+1] = b[i] + a[i+n] - t;
  }

  priority_queue<int> que2;
  int sum2 = 0;
  rep(i, n){
    sum2 += a[2*n+i];
    que2.push(a[2*n+i]);
  }

  vi c(n+1);
  c[n] = sum2;
  rep(i, n){
    que2.push(a[2*n-1-i]);
    int t = que2.top();
    que2.pop();
    c[n-1-i] = c[n-i] + a[2*n-1-i] - t;
  }

  int ans = -linf;
  rep(i, n+1){
    ans = max(ans, b[i]-c[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5876
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] ar = new long[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextLong();
        }
        Arrays.sort(ar);
        if(ar[n - 1] <= 0){
            StringBuilder result = new StringBuilder();
            long curr = ar[n - 1];
            for(int i = n - 2; i >= 0; i--){
                result.append(curr);
                result.append(' ');
                result.append(ar[i]);
                result.append('\n');
                curr = curr - ar[i];
            }
            System.out.println(curr);
            System.out.println(result.toString());
        }else if(ar[0] >= 0){
            StringBuilder result = new StringBuilder();
            long curr = ar[0];
            for(int i = 1; i < n - 1; i++){
                result.append(curr);
                result.append(' ');
                result.append(ar[i]);
                result.append('\n');
                curr = curr - ar[i];
            }
            System.out.println(ar[n - 1] - curr);
            result.append(ar[n - 1]);
            result.append(' ');
            result.append(curr);
            System.out.println(result.toString());
        }else{
            int index = 1;
            long curr = ar[n - 1];
            StringBuilder result = new StringBuilder();
            while(index < n && ar[index] <= 0){
                result.append(curr);
                result.append(' ');
                result.append(ar[index]);
                result.append('\n');
                curr = curr - ar[index];
                index += 1;
            }
            long currAlt = ar[0];
            for(int i = index; i < n - 1; i++){
                result.append(currAlt);
                result.append(' ');
                result.append(ar[i]);
                result.append('\n');
                currAlt -= ar[i];
            }
            System.out.println(curr - currAlt);
            result.append(curr);
            result.append(' ');
            result.append(currAlt);
            System.out.println(result.toString());
        }
    }
}


Measured memory_bytes: 62980
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>

using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using intpv=vector<intpair>;
using llpair=pair<ll,ll>;
using llpv=vector<llpair>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;
using pairmat=vector<llpv>;

template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353

#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define iter(name) decltype(name)::iterator
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())
#define init(v,size) v.resize(size); for(auto &a__: v) cin>>a__
#define matin(mat,H,W) for(int i__=0; i__<H; i__++)for(int j__=0; j__<W; j__++) cin>>mat[i__][j__]
#define out(n) cout<<n<<endl

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

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

template<class T> inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

ll GCD(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

ll Fact(ll x, ll p) { //階乗
	ll f=1;
	for(ll i=2; i<=x; i++) {
		f*=i;
		f%=p;
	}
	return f;
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll div=1LL;
	while(n/div) {
		digit++;
		div*=10;
	}
	return digit;
}


llvec fact,inv,factinv;
void prenCrP(ll n, ll p) {
	fact.resize(n+1);
	inv.resize(n+1);
	factinv.resize(n+1);
	fact[0]=fact[1]=inv[1]=factinv[0]=factinv[1]=1LL;
	for(ll i=2LL; i<=n; i++) {
		fact[i]=fact[i-1]*i%p;
		inv[i]=p-inv[p%i]*(p/i)%p;
		factinv[i]=factinv[i-1]*inv[i]%p;
	}
}
ll nCrP(ll n, ll r, ll p) { // mod pにおけるnCr
	if (r > n) return 0;
	return fact[n]*factinv[r]%p*factinv[n-r]%p;
}


int N,K,R;

void input() {
	cin>>N>>K;
	R=N-K;
}

void solve() {
	prenCrP(2500,MPRIME);
	for(int i=1; i<=K; i++) {
		int b=K-i, r=R-i+1;
		ll res=nCrP(b+i-1,i-1,MPRIME)*nCrP(r+i,i,MPRIME)%MPRIME;
		cout<<res<<endl;
	}
}

int main() {
	while(1) {
		input();
		solve();
		break;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

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

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


int main(void){
    int cnt = 0;
    unsigned long long x, y;
    scanf("%lld %lld", &x, &y);
    while (x<=y){
        x = x*2;
        cnt++;
    }

    

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


    return 0;
}


Measured memory_bytes: 128
n = int(input())
h = list(map(int,input().split()))

dp_table = [float("inf")] * (n+1)

#print(dp_table)

dp_table[0] = 0

for i in range(1,n):
    if i >= 2:
        dp_table[i] = min(dp_table[i],dp_table[i-1]+abs(h[i]-h[i-1]),dp_table[i-2]+abs(h[i]-h[i-2]))
    else:
        dp_table[i] = min(dp_table[i],dp_table[i-1]+abs(h[i]-h[i-1]))

print(dp_table[n-1])


Measured memory_bytes: 54904
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	register int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(register int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	string s,c="CODEFESTIVAL2016";
	cin>>s;
	int len=s.length(),ans=0;
	for(int i=0;i<len;i++)
		if(s[i]!=c[i])
			ans++;
	write(ans);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

int main()
{
    int a,b,x;
    cin >> a >> b >> x ;

    YES(a <= x && x <= a+b)
}

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

using namespace std;

  string S;
  
  void pre(){
      cin >> S;

  if (S == "ABC") {
    cout << "ARC" << '\n';
  } else {
    cout << "ABC" << '\n';
  }

      
      
  }

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

  return 0;
}

Measured memory_bytes: 3608