akhauriyash/Code-Regression huggingface dataset:
# Union-Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n + 1)]
 
    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return 0
        elif x < y:
            self.parents[y] = x
        else:
            self.parents[x] = y
        return 1
 
from collections import Counter
n, m = map(int, input().split())
uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    uf.unite(a, b)
roots = []
for num in uf.parents:
    roots.append(uf.find(num))
count_roots = Counter(roots)
 
 
print(len(count_roots)-2)

Measured memory_bytes: 17000
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x;
	int y;
	cin>>x>>y;
	int t=(x*4-y);
//	cout<<tmp<<endl;
	int tmp=t/2;
//	cout<<t<<endl;
	bool f=true;
	if(tmp<0) f=false;	
	if(tmp*2<t) f=false;
	if(tmp>x) f=false;
	if(f==true) cout<<"Yes"<<endl;
	if(f==false) cout<<"No"<<endl;
 } 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int n = a + b;
  if(n >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

	static int V;
	static ArrayList<Integer>[] g;
	static int[] size, P, level;

	static void dfs(int u, int p, int depth) {
		size[u]++;
		level[u] = depth;
		for (int v : g[u]) {
			if (v != p) {
				P[v] = u;
				dfs(v, u, depth + 1);
				size[u] += size[v];
			}
		}
	}

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		V = sc.nextInt();
		g = new ArrayList[V];
		for (int i = 0; i < V; i++)
			g[i] = new ArrayList<>();
		for (int i = 0; i < V - 1; i++) {
			int u = sc.nextInt() - 1, v = sc.nextInt() - 1;
			g[u].add(v);
			g[v].add(u);
		}
		P = new int[V];
		size = new int[V];
		level = new int[V];
		dfs(0, -1, 0);
		// System.err.println(Arrays.toString(size));
		// System.err.println(Arrays.toString(level));
		int nodes = level[V - 1] - level[0] - 1;
		int white = (int) (nodes - Math.ceil(nodes / 2.0));
		int node = V - 1;
		// System.err.println(white);
		while (white-- > 0)
			node = P[node];
		// System.err.println(nodes + " " + node);
		int blackTurns = size[0] - size[node], whiteTurns = size[node];
		out.println(blackTurns > whiteTurns ? "Fennec" : "Snuke");
		out.flush();
		out.close();
	}

	static class MyScanner {
		StringTokenizer st;
		BufferedReader br;

		public MyScanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public MyScanner(String filename) throws IOException {
			br = new BufferedReader(new FileReader(new File(filename)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


Measured memory_bytes: 76024
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}

int main(){
  int n,x,t;
  cin>>n>>x>>t;
  if(n%x==0)cout<<n*t/x<<endl;
  else cout<<(n/x+1)*t<<endl;
    
    
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
const int MAX_N = 2000000;
const ll MOD = 1000000007LL;
ll inv[MAX_N], fac[MAX_N], fiv[MAX_N];
void COMinit() {
    inv[1] = fac[1] = fiv[1] = inv[0] = fac[0] = fiv[0] = 1;
    for (ll i = 2; i < MAX_N; i++) {
        fac[i] = fac[i - 1] * i % MOD; // n!
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
        fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
    }
}
ll com(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * fiv[k] % MOD * fiv[n-k] % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    COMinit();
    for (ll i = 1; i <= K; i++) {
        cout << com(K-1, i-1) * com(N-K+1, i) % MOD << endl;
    }
}

Measured memory_bytes: 47104
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (ll i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	ll N;
	cin >> N;
	ll sum = 0;
	ll n = N;
	while (n) {
		ll digit = n % 10;
		n /= 10;
		sum += digit;
	}
	string ans;
	if (N % sum) {
		ans = "No";
	}
	else {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin>>S;
  for(int i=0;i<3;i++){
    if(S.at(i)==S.at(i+1)){
      cout<<"Bad"<<endl;
      return 0;
    }
  }
  cout<<"Good"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <cstdio>
using namespace std;
int main()
{
	int N,sum=0;
	cin>>N;
	for (int i=1; i<=N; i++)
	{
		sum=sum+i;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
//agc034_a.cpp
//Sat Aug  3 16:42:25 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;

	vector<P> three;
	vector<P> kabe;
	for (int i=0;i<s.size()-2;i++){
		if (s[i] == '.' &&
			s[i+1] == '.' &&
			s[i+2] == '.'){
			three.push_back(make_pair(i+1,i+3));
		}else if (s[i] == '#' &&
					s[i+1] == '#'){
			kabe.push_back(make_pair(i+1,i+2));
		}
	}

	if (c<d){
		for (int i=0;i<kabe.size();i++){
			if (kabe[i].first>a &&
				kabe[i].first<d){
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}else {
		for (int i=0;i<kabe.size();i++){
			if (kabe[i].first>a &&
				kabe[i].first<c){
				cout << "No" << endl;
				return 0;
			}
		}
		int flag = 0;
		for (int i=0;i<three.size();i++){
			if (three[i].first>=b-1 &&
				three[i].first<d){
				flag = 1;
			}
		}
		if (flag){
			cout << "Yes" << endl;
		}else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <sstream>
//#include <string>
//#include <cmath>
//#include <queue>
//#include <list>
#include <string.h>
#include <deque>

//void Aoj_learning8();
//void Aoj_learning8sub(int, int, int*, int*);
//void Aoj_learning9();
//void Aoj_learning10();
void Aoj_learning11();



int main()
{
	Aoj_learning11();

	return 0;
}

void Aoj_learning11()
{
	int intInputNum = 0;

	// 入力命令数の取得
	scanf("%d", &intInputNum);

	// 命令の実行
	std::deque<int> deqList;
	int iTemp = 0;
	char c[12];
	for (int i = 0; i < intInputNum; i++)
	{
		scanf("%s", c);

		if (c[0] == 'i')
		{
			scanf("%d", &iTemp);
			deqList.push_front(iTemp);
		}
		else
		{
			if(strlen(c) < 7)
			{
				scanf("%d", &iTemp);
				auto itr = deqList.begin();
				for (unsigned int i = 0; i < deqList.size(); i++)
				{
					if (iTemp == *itr)
					{
						deqList.erase(itr);
						break;
					}
					itr++;
				}
			}
			else
			{
				if(c[6] == 'F')
				{
					deqList.pop_front();
				}
				else
				{
					deqList.pop_back();
				}
			}
		}
	}

	auto itr = deqList.begin();
	int iListSize = deqList.size();
	for (int i = 0;; i++, itr++)
	{
		if (i == iListSize - 1)
		{
			printf("%d\n", *itr);
			break;
		}
		else
		{
			printf("%d ", *itr);
		}
	}
}


Measured memory_bytes: 7044
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    int k, x;
    cin >> k >> x;
    if (500 * k >= x)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

int a,b,c,x;

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

if(a>b){

x=a;

a=b;

b=x;

}

if(a>c){

x=a;

a=c;

c=x;

}

if(b>c){

x=b;

b=c;

c=x;

}

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


return 0;


}

Measured memory_bytes: 596
n,c,k=map(int,input().split())
tl=sorted([int(input()) for _ in range(n)])
ans=1
time=tl[0]
p=1
for t in tl[1:]:
    if t>time+k or p>=c:
        time=t
        ans+=1
        p=1
    else:
        p+=1
print(ans)

Measured memory_bytes: 8280
M = 10**9 + 7
s = int(input()) - 3
 
f = [1] * ( s + 1)
for i in range(1, s + 1):
  f[i] = f[i - 1] * i % M

r = 0
for k in range(s // 3 + 1):
  r = (r + f[s] * pow(f[k], M - 2, M) * pow(f[s - k], M - 2, M)) % M
  s -= 2

print(r)


Measured memory_bytes: 9068
#define _USE_MATH_DEFIN
#include<bits/stdc++.h>
using namespace std;  
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl  
#define DIV 1000000009  
int main(){
	vi input;
	REP(i,3){
		int a;
		cin >> a;
		input.pb(a);
	}
	sort(ALL(input));
	if(input[0] == 5 && input[1] == 5 && input[2] == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
} 

Measured memory_bytes: 256
from decimal import *
import math


a, b, c = map(int, input().split())
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)

a = Decimal.sqrt(a)
b = Decimal.sqrt(b)
c = Decimal.sqrt(c)

if a + b < c:
    print("Yes")
else:
    print("No")


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

using namespace std;

int main()
{
   int a,b,x;
   scanf("%d",&a);
     scanf("%d",&b);
   if(a>b)
    {
        x=a;a=b;
        b=x;
    }
    if(b>a*2||(b+a)>16)
        printf(":(\n");
    else
      printf("Yay!\n");
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace For_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            var points = new List<NPoint>();
            for(int i = 0; i < 2 * n; i++)
            {
                string[] inf = ReadLine().Split(' ');
                points.Add(new NPoint(int.Parse(inf[0]), int.Parse(inf[1]), i / n));
            }
            int ans = 0;

            NPoint[] points2 = points.OrderByDescending(x => x.y).OrderBy(x => x.x).ToArray();
            NPoint blueone = new NPoint(0, 0, -1);
            NPoint[] bluepns = points2.Where(x => x.color == 1).ToArray();
            for(int i = 0; i < n; i++)
            {
                NPoint[] redpar = points2.Where(x => x.color == 0).Where(x => (x.x < bluepns[i].x) & (x.y < bluepns[i].y)).ToArray();
                if (redpar.Count() != 0)
                {
                    NPoint[] redpar2 = redpar.OrderByDescending(x => x.y).ToArray();
                    redpar2[0].color = -1;
                    ans++;
                }
            }

            WriteLine(ans);
        }
    }

    class NPoint
    {
        public int x;
        public int y;
        public int color;//0=red 1=blue
        public NPoint(int a,int b,int col)
        {
            x = a;
            y = b;
            color = col;
        }
    }
}

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

int main(){
    int n, i;
    cin >> n;
    if(n % 2 == 1){
        cout << 0 << endl;
        return 0;
    }
    vector<int> d;
    for(i = 0; i < n; i++){
        int t;
        cin >> t;
        d.push_back(t);
    }
    sort(d.begin(), d.end());
    int mid = d.size() / 2;
    cout << d[mid] - d[mid-1] << endl;


}

Measured memory_bytes: 892
s = input()
flag = True
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == "L":
            flag = False
            break
    else:
        if s[i] == "R":
            flag = False
            break
if flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
main()
{
  int n,d;
  cin>>n>>d;
  int f=2*d+1,r;
  if (n%f==0)
    cout<<n/f<<endl;
  else
  {
    r=n/f;
    cout<<r+1<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>

using namespace std;

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

typedef long long ll;

int x[1001];
int y[1001];

int main(){
	int n, m;
	int a;
	
	while (cin >> n >> m , n || m){
		a = 0;
		
		REP(i,n) cin >> x[i];
		
		REP(i,m) cin >> y[i];
		
		int cnt = 0;
		
		REP(i,m){
			cnt++;
			a += y[i];
			
			if (a >= n) break;
			
			a += x[a];
			
			if (a >= n) break;
		}
		
		cout << cnt << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n; cin >> n;
    ll m; cin >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    auto f = [&](int k) {
        ll cnt = 0;
        rep(i,n){
            int d = lower_bound(a.begin(),a.end(),k-a[n-i-1])-a.begin();
            cnt += n-d;
        }
        return cnt >= m;
    };
    int ok = 0, ng = 200001;
    while(ng-ok > 1){
        int mid = (ok+ng)/2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }

    vector<ll> sum(n+1);
    rep(i,n) sum[i+1] = sum[i]+a[i];
    ll cnt = 0;
    ll ans = 0;
    rep(i,n){
        int d = lower_bound(a.begin(),a.end(),ok-a[n-i-1])-a.begin();
        if(d != n){
            cnt += n-d;
            ans += sum[n]-sum[d]+(ll)a[n-i-1]*(n-d);
        }
    }
    ans -= ok*(cnt-m);
    cout << ans << endl;
}



Measured memory_bytes: 4568
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,I=0,mx=0;
   cin>>n;
   string s;
   cin>>s;
   for(int i=0;i<n;i++){
    if(s[i]=='I'){
        I++;
    }
    else I--;
   if(I>mx){
        mx=I;
   }
   }
  cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 256
let quick_sort (a : (int * char * int) array) n cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let i = ref p in
    for j = p to r - 1 do
      if cmp a.(j) a.(r) <= 0 then begin
        swap !i j;
        incr i;
      end
    done;
    swap !i r;
    !i in
  let rec doit p r =
    if p >= r then () else
    let q = partition p r in
    doit p (q - 1);
    doit (q + 1) r in
  doit 0 (n - 1)

let stable_p (a : (int * char * int) array) n =
  try
    for i = 1 to n - 1 do
      if (fun (xi, _, xd) (yi, _, yd) -> xd = yd && xi > yi) a.(i-1) a.(i) then raise Exit
    done;
    true
  with Exit -> false

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let a = Array.init n (fun i ->
    match read_line () |> split_on_char ' ' with
    | [c; d] -> (i, c.[0], int_of_string d)
    | _ -> assert false) in
  quick_sort a n (fun (_, _, x) (_, _, y) -> compare x y);
  print_endline (if stable_p a n then "Stable" else "Not stable");
  Array.iter (fun (_, c, d) -> Printf.printf "%c %d\n" c d) a

Measured memory_bytes: 9944
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double A = sc.nextDouble();
        double B = sc.nextDouble();
        double N = sc.nextDouble();

        if(B<=N){
            if(N != 1) N = B - 1;
        }
        long ans1 = (int)((A*N)/B);
        long ans2 = (long)A * (int)(N/B);
        long ans3 = ans1 - ans2;
        System.out.println(ans3);

    }
}

Measured memory_bytes: 37200
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int k; cin >> k;
  int cnt=0;
  bool fa=0,fb=0,fc=0,fd=0,fe=0,ff=0,fg=0,fh=0,fi=0,fj=0;
  for(char a='0';a<='9';a++){
    if(a!='0') fa=1;
    for(char b=max('0',char(a-1));fa?b<=min('9',char(a+1)):b<='9';b++){
      if(b!='0') fb=1;
      for(char c=max('0',char(b-1));fb?c<=min('9',char(b+1)):c<='9';c++){
        if(c!='0') fc=1;
        for(char d=max('0',char(c-1));fc?d<=min('9',char(c+1)):d<='9';d++){
          if(d!='0') fd=1;
          for(char e=max('0',char(d-1));fd?e<=min('9',char(d+1)):e<='9';e++){
            if(e!='0') fe=1;
            for(char f=max('0',char(e-1));fe?f<=min('9',char(e+1)):f<='9';f++){
              if(f!='0') ff=1;
              for(char g=max('0',char(f-1));ff?g<=min('9',char(f+1)):g<='9';g++){
                if(g!='0') fg=1;
                for(char h=max('0',char(g-1));fg?h<=min('9',char(g+1)):h<='9';h++){
                  if(h!='0') fh=1;
                  for(char i=max('0',char(h-1));fh?i<=min('9',char(h+1)):i<='9';i++){
                    if(i!='0') fi=1;
                    for(char j=max('0',char(i-1));fi?j<=min('9',char(i+1)):j<='9';j++){
                      cnt++;
                      if(cnt==k+1){
                        ll ans=0;
                        ans+=a-'0'; ans*=10;
                        ans+=b-'0'; ans*=10;
                        ans+=c-'0'; ans*=10;
                        ans+=d-'0'; ans*=10;
                        ans+=e-'0'; ans*=10;
                        ans+=f-'0'; ans*=10;
                        ans+=g-'0'; ans*=10;
                        ans+=h-'0'; ans*=10;
                        ans+=i-'0'; ans*=10;
                        ans+=j-'0';
                        cout << ans << endl;
                        return 0;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+1;
const int M=1e9+7;
const int N1=1e18+1;
typedef pair<int, int> pi;
typedef pair<pair<int, int> , int> pii;
#define F first
#define S second
#define pb push_back
#define endl "\n"


int32_t main(){

  	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  
    
    // int t;cin>>t;
    // while(t--){

    // }

  	set<int> st;
  	int k,n;cin>>k>>n;
  	for(int i=0;i<n;i++){
  		int x;cin>>x;
  		st.insert(x);
  	}
  	int i=1;
  	for(int i=0;i<=(n+1);i++){
  		if(st.find(k-i)==st.end()){
  			cout<<k-i<<endl;
  			return 0;
  		}
  		if(st.find(k+i)==st.end()){
  			cout<<k+i<<endl;
  			return 0;
  		}
  	}


  return 0;
}



Measured memory_bytes: 3664
L,R = map(int,input().split())
d = 2019

if L <= R//d * 2019: print(0)
else: 
    L = L % 2019
    R = R % 2019
    ans = 2020
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            tmp = i*j%d
            if tmp < ans: ans = tmp
    print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<utility>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;
using ll = long long;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

const long long MOD = 1e9+7;
const long long MAX = 3e5+1;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N, M;
    in(N); in(M);
    int a, b;
    unordered_map<int, vector<int>> adj;

    rep(i, M) {
        cin >> a >> b;
        a--;
        b--;
        if (adj.find(a) != adj.end()) {
            adj[a].push_back(b);
        }
        else adj[a] = vector<int>(1, b);
        if (adj.find(b) != adj.end()) {
            adj[b].push_back(a);
        }
        else adj[b] = vector<int>(1, a);
    }

    queue<int> Q;
    Q.push(0);

    vector<int> ans(N, MOD);
    vector<bool> visited(N, false);
    visited[0] = true;
    while (!Q.empty()) {
        int curr = Q.front();
        Q.pop();
        for (int next: adj[curr]) {
            if (!visited[next]) {
                ans[next] = curr;
                Q.push(next);
            }
            visited[next] = true;
        }
    }
    rept(i, 1, N) {
        if (ans[i] == MOD) {
            out("No");
            exit(0);
        }
    }
    out("Yes");
    rept(i, 1, N) {
        out(ans[i]+1);
    }


    return 0;
}


Measured memory_bytes: 13576
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, Q;
  cin >> N >> Q;

  string s;
  cin >> s;

  s = 'r' + s + 'r';

  vector<char> t(Q), d(Q);
  REP(i, Q) cin >> t[i] >> d[i];

  auto f = [&](int ng, int ok, int last){
    while(abs(ok-ng) > 1){
      int mid = (ok+ng)/2;
      int now = mid;
      REP(i, Q){
        if(s[now] == t[i]){
          now = now+(d[i] == 'L'? -1: 1);
        }
      }
      if(now == last) ng = mid;
      else ok = mid;
    }
    return ok;
  };

  N = s.size()-1;
  cout << f(N, 0, N)-f(0, N, 0)+1 << "\n";

  return 0;
}

Measured memory_bytes: 952
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S 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 FILL(a, b) memset(a, b, sizeof(a))
#define MT make_tuple

void dout() { cerr << endl; }

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

const int INF = 1e9 + 47;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<vector<PII>> g(n);
    FOR(i, 0, m)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].EB(w, v);
        g[v].EB(w, u);
    }
    FOR(i, 0, n)
    {
        sort(ALL(g[i]));
    }
    set<tuple<int, int, int>> q;
    vector<unordered_map<int, int>> d(n);
    VI md(n, INF);
    md[0] = 0;
    for (auto e : g[0])
    {
        d[e.S][e.F] = 1;
        md[e.S] = 1;
        q.emplace(1, e.S, e.F);
    }
    int last = 0;
    vector<char> used(n, false);
    while (SZ(q))
    {
        int _, u, c;
        tie(_, u, c) = *q.begin();
        q.erase(*q.begin());
        assert(_ == d[u][c]);
        assert(last <= d[u][c]);
        last = d[u][c];
        int be = 0, en = SZ(g[u]);
        if (used[u])
        {
            be = lower_bound(ALL(g[u]), MP(c, -1)) - g[u].begin();
            en = lower_bound(ALL(g[u]), MP(c + 1, -1)) - g[u].begin();
        }
        FOR(i, be, en)
        {
            auto e = g[u][i];
            int v = e.S;
            int cc = e.F;
            if (d[v].count(cc) && cc != c)
            {
                assert(d[u][c] + 1 >= d[v][cc]);
                continue;
            }
            if (cc == c)
            {
                if (d[v].count(c))
                {
                    if (d[u][c] < d[v][c])
                    {
                        assert(q.find(MT(d[v][c], v, c)) != q.end());
                        q.erase(MT(d[v][c], v, c));
                        d[v][c] = d[u][c];
                        q.emplace(d[v][c], v, c);
                    }
                }
                else
                {
                    d[v][c] = d[u][c];
                    q.emplace(d[v][c], v, c);
                }
            }
            else
            {
                d[v][cc] = md[u] + 1;
                q.emplace(d[v][cc], v, cc);
            }
            md[v] = min(md[v], d[v][cc]);
        }
        used[u] = true;
    }
    if (md[n - 1] < INF)
        cout << md[n - 1];
    else
        cout << -1;
    return 0;
}

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

using namespace std;

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

int main() {
	bool path[20][20] = {};
	int m, n;
	cin >> m >> n;
	REP(i, n) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		path[a][b] = true;
	}
	
	
	bool s[20] = {};
	REP(i, m) {
		int ans;
		
		REP(j, m) if (!s[j]) {
			bool f = true;
			REP(k, m) if (path[k][j]) f = false;
			if (f) {
				ans = j;
				REP(k, m) path[j][k] = false;
				s[ans] = true;
				break;
			}
		}
		printf("%d\n", ans + 1);
	}
	
	return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

	    char[] A = sc.next().toCharArray();
	    char[] B = sc.next().toCharArray();
	    char[] C = sc.next().toCharArray();

	    //何枚目のカード
	    int a = 0;
	    int b = 0;
	    int c = 0;
	    boolean play1 = true;
	    boolean play2 = true;
	    boolean play3 = true;
	    int ans = 0;

	    for(;;){
	    	if(ans == 1)
	    		break;
	    	while(play1){
	    		if(a>=A.length){
	    			System.out.println("A");
	    			ans++;
	    			break;
	    		}
	    		if(A[a]=='a'){
	    			a++;
	    		}else if(A[a] == 'b'){
	    			play1 = false;
	    			play2 = true;
	    			play3 = false;
	    			a++;
	    		}else if(A[a] == 'c'){
	    			play1 = false;
	    			play2 = false;
	    			play3 = true;
	    			a++;
	    		}
	    	}
	    	while(play2){
	    		if(b>=B.length){
	    			System.out.println("B");
	    			ans++;
	    			break;
	    		}
	    		if(B[b]=='b'){
	    			b++;
	    		}else if(B[b] == 'a'){
	    			play1 = true;
	    			play2 = false;
	    			play3 = false;
	    			b++;
	    		}else if(B[b] == 'c'){
	    			play1 = false;
	    			play2 = false;
	    			play3 = true;
	    			b++;
	    		}
	    	}
	    	while(play3){
	    		if(c>=C.length){
	    			System.out.println("C");
	    			ans++;
	    			break;
	    		}
	    		if(C[c]=='c'){
	    			c++;
	    		}else if(C[c] == 'a'){
	    			play1 = true;
	    			play2 = false;
	    			play3 = false;
	    			c++;
	    		}else if(C[c] == 'b'){
	    			play1 = false;
	    			play2 = true;
	    			play3 = false;
	    			c++;
	    		}
	    	}
	    }

	}
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	vector<ll> x(n);
	rep(i, n) cin >> x[i];

	ll ans = LLONG_MAX / 2;
	for(int i = -200; i <= 200; i++){
		ll t = 0;
		rep(j, n){
			t += (x[j] - i) * (x[j] - i);
		}

		ans = min(ans, t);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}

#define ll long long
#define f first
#define s second
#define pb push_back
#define INF 1000000000000000000
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	// 入力
	ll a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (max(max(a, b), max(max(c, d), e)) - min(min(a, b), min(min(c, d), e)) > k) cout << ":(" << endl;
	else cout << "Yay!" << endl;

	return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = input[0];
            var M = input[1];
            var A = new int[M];
            var B = new int[M];
            for(var i = 0; i < M; i++)
            {
                input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                A[i] = input[0];
                B[i] = input[1];
            }
            Array.Sort(B, A);

            var ans = 1;
            var tmp = B[0] - 1;
            for(var i = 1; i < M; i++)
            {
                if (A[i] > tmp)
                {
                    ans++;
                    tmp = B[i] - 1;
                }
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 18016
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,c;
  int b[20], a, sm, cnt = 0;
  cin >> n >> m >> c;
  for(int i=0;i<m;i++) cin >> b[i];
  for(int i=0;i<n;i++){
    sm = c;
    for(int j=0;j<m;j++){
      cin >> a;
      sm += a * b[j];
    }
    if(sm > 0) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

Measured memory_bytes: 256
#include<stdio.h>
 int main(void){
     int a,b,c,d;
     scanf("%d %d %d %d",&a,&b,&c,&d);
     for(int i=0;i>=0;i++){ 
      c-=b;
      if(c<=0){
          break;
      }
      a-=d;
      if(a<=0){
          break;
      }
     }
     if(a<=0){
         printf("No");
     }else{
         printf("Yes");
     }
    return 0;
 }

Measured memory_bytes: 1732
while True:
    try:
        count=0
        num = int(input())
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a+b+c+d ==num:
                            count+=1
        print(count)
    except EOFError:
        break



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)
    sum+=a[i];
    cout<<sum<<endl;
    return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 100;
ll N;
ll x[MAX_N], y[MAX_N], h[MAX_N];

ll mdis(ll x1, ll y1, ll x2, ll y2){
   return abs(x1 - x2) + abs(y1 - y2);
}
int main(){
   cin >> N;
   REP(i, N) cin >> x[i] >> y[i] >> h[i];
   ll argmax_h = -1; ll max_h = -1;
   REP(i, N){
      if(chmax(max_h, h[i])) argmax_h = i;
   }

   REP(i, 101){
      REP(j, 101){
         ll flag = true;
         ll height = max_h + mdis(x[argmax_h], y[argmax_h], i, j);
         REP(k, N){
            if(h[k] != max(0ll, height - mdis(i, j, x[k], y[k]))){
               flag = false;
               break;
            }
         }
         if (flag){
            printf("%lld %lld %lld\n", i, j, height);
            return 0;
         }
      }
   }
}


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

int n, k, s;
int main()
{
	int i, j;
	cin >> n >> k;
	s = (n - 1) * (n - 2) / 2;
	if (s < k) {
		puts("-1");
		return 0;
	}
	s -= k;
	cout << n - 1 + s << endl;
	for (i = 2; i <= n; i++) printf("1 %d\n", i);
	i = 2; j = 3;
	while (s--) {
		printf("%d %d\n", i, j);
		j++;
		if (j > n) i++, j = i + 1;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll N;cin>>N;
    for(ll h=1;h<=3500ll;h++){
        for(ll n=1;n<=3500ll;n++){
            ll dem = (4*h*n - N*n - N*h);
            ll num = (N*h*n);

            if(dem==0 || num%dem)continue;
            ll w = num/dem;
            if(w>0)return cout<<h<<" "<<n<<" "<<w , 0;
        }
    }
}


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

char a[1005],b[1005];
int main(){
	int i,j,al,bl;
	
	scanf("%s",a);
	scanf("%s",b);
	al=strlen(a);
	bl=strlen(b);
	for(i=0;i<=al-bl;i++){
		for(j=0;j<bl;j++){
			if(b[j]=='_')continue;
			if(a[i+j]!=b[j])break;
		}
		if(j==bl)break;
	}
	if(i==al-bl+1)printf("No\n");
	else printf("Yes\n");
	
	
	return 0;
}


Measured memory_bytes: 524
#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define All(v) v.begin(),v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 1e9+7;

signed main() {
    FAST;

    int l, r, d;
    cin >> l >> r >> d;
    cout << r/d - (l-1)/d << endl;

}


Measured memory_bytes: 3636
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	string str;
	
	cin >> str;
	
	if(str == "SAT"){
		cout << 1 << endl;
	}
	else if(str == "SUN"){
		cout << 7 << endl;
	}
	else if(str == "MON"){
		cout << 6 << endl;
	}
	else if(str == "TUE"){
		cout << 5 << endl;
	}
	else if(str == "WED"){
		cout << 4 << endl;
	}
	else if(str == "THU"){
		cout << 3 << endl;
	}
	else if(str == "FRI"){
		cout << 2 << endl;
	}
	
	return 0;
} 

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

int main(void){
  int N;
  cin >> N;
  
  for(int i = 1; i < 10;i++){
    if(N%i == 0 && N/i < 10){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  	
	return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n;
    cin>>n;
    cout<<((1+n-1)*(n-1))/2;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;

typedef complex<double> P;

struct L : public vector<P>{//??´???
  L(const P &a, const P &b){
    push_back(a);push_back(b);
  }
};

struct C{//???
  P c; double r;
  C(const P &c,double r): c(c),r(r){}
};

namespace std{//??????????????????
  bool operator < (const P& a,const P& b){
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b){
    return a.real()==b.real()&&a.imag()==b.imag();
  }
}

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c){
  b-=a;c-=a;
  if(cross(b,c)>0)   return +1;// counter clockwise 
  if(cross(b,c)<0)   return -1;// clockwise 
  if(dot(b,c)<0)     return +2;// c-a-b on line
  if(norm(b)<norm(c))return -2;// a-b-c on line
  return 0;                    // a-c-b on lone
}

P intersection(P a,P b,P c,P d){//2??´????????????
  return a+(b-a)*(cross(d-c,c-a)/cross(d-c,b-a));
}

int main()
{
  int i;
  int q;

  cin>>q;

  rep(i,q){
    double xp,yp;

    cin>>xp>>yp;  P p1(xp,yp);
    cin>>xp>>yp;  P p2(xp,yp);
    cin>>xp>>yp;  P p3(xp,yp);
    cin>>xp>>yp;  P p4(xp,yp);

    P s1(p2-p1);
    P s2(p4-p3);

    if(p1==p3 || p1==p4 || p2==p3 || p2==p4){
      cout<<"1"<<endl;
      continue;
    }

    if(s1.real()*s2.imag()==s1.imag()*s2.real()){//parallel
      if(ccw(p1,p3,p4)==2||ccw(p2,p3,p4)==2 || ccw(p3,p1,p2)==2||ccw(p4,p1,p2)==2)
	  cout<<"1"<<endl;
	else
	  cout<<"0"<<endl;

    }else{
      P p=intersection(p1,p2,p3,p4);//??????
      // cout<<p<<endl;
      if(abs(p1-p)>abs(p1-p2) || abs(p2-p)>abs(p1-p2) ||
	 abs(p3-p)>abs(p3-p4) || abs(p4-p)>abs(p3-p4))
	cout<<"0"<<endl;
      else
	cout<<"1"<<endl;
    }
  }

}

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	int ans = INT_MAX, pre;
	cin >> pre;
	for (int i = 0; i < n-1; i++)
	{
		int k;
		cin >> k;
		ans = min(ans, __gcd(pre, k));
		pre = k;
	}

	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#define int long long
using namespace std;

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//main
//------------------------------------------
signed main(){
    string s;
    cin >> s;
    string rs;
    rs = s;
    reverse(rs.begin(),rs.end());
    int c=0;
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i]!=rs[i]){
            c++;
            s[i] = rs[i];
            rs = s;
            reverse(rs.begin(), rs.end());
            i = 0;
        }
    }
    cout << c;
}

Measured memory_bytes: 256
#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--;}
};
template<typename T>
using MaximumSum=PrioritySum<T, T(0), vector<T>, less<T>, greater<T> >;
template<typename T>
using MinimumSum=PrioritySum<T, T(0), vector<T>, greater<T>, less<T> >;

//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;
  
  int n;
  cin>>n;
  vector<ll> a(3*n);
  for(int i=0;i<3*n;i++) cin>>a[i];

  MaximumSum<ll> 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]);
  }
  
  MinimumSum<ll> 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