akhauriyash/Code-Regression huggingface dataset:
<?php
  $n = trim(fgets(STDIN));
  $cnt = [];
  $a = $n;
  for($i=2; $i*$i<=$n; $i++){
      while($a%$i == 0){
          $cnt[$i]++;
          $a /= $i;
      }
  }
  if($a > 1){
      $cnt[$a] = 1;
  }
//   print_r($cnt);
  $ans = 0;
  foreach ($cnt as $count){
      $i=1;
      while($count >= $i){
          $count -= $i;
          $ans++;
          $i++;
      }
  }
  echo $ans;

Measured memory_bytes: 16212
#include <iostream>
#include <algorithm>


const int MAXN = 3000;

long long change[MAXN];
long long bestScore[2][MAXN + 1][MAXN + 1];
bool seen[2][MAXN + 1][MAXN + 1];


long long findscore(int player, int start, int end)
{
	if (start == end)
			return 0;
	if (!seen[player][start][end])
	{
		seen[player][start][end] = true;
		bestScore[player][start][end] = std::max(change[start] - findscore(1 - player, start + 1, end), change[end - 1] - findscore(1 - player, start, end - 1));
	}

	return bestScore[player][start][end];
}

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

	int dequeSize; std::cin >> dequeSize;
	for (int iElem = 0; iElem < dequeSize; iElem++)
			std::cin >> change[iElem];
	std::cout << findscore(0, 0, dequeSize) << '\n';

	return 0;
}


Measured memory_bytes: 158336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, x, t;
  cin >> n; // 目標
  cin >> x; // 個/回
  cin >> t; // 分/回

  int count = n%x == 0 ? n/x : n/x + 1;
  
  cout << count*t << endl;
  return 0; 
}

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

long long int N, X, x, a;

int main(){
    scanf("%lld%lld%lld", &N, &X, &x);
    a = abs(X - x);
    for(int i = 1; i < N; ++i){
        scanf("%lld", &x);
        a = __gcd(a, abs(X - x));
    }
    cout << a << endl;
    return 0;
}


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

int main(void)
{
    
    int W,H;
    int N;
    int x[100];
    int y[100];
    int n[100];
    int f[100][100];
    
    int cnt=0;
    
    scanf("%d %d %d",&W,&H,&N);
    
    
    for (int i=0; i<N; i++) {
        
        scanf("%d %d %d",&x[i],&y[i],&n[i]);
        
    }
    for (int i=0; i<100; i++) {
        for (int j=0; j<100; j++) {
            
            f[i][j]=0;
        }
        
    }
    
    
    
    for (int i=0; i<N; i++) {
        if (n[i]==1) {
            for (int Y=0; Y<H; Y++) {
                
            for (int X=0; X<x[i]; X++) {
                
                f[X][Y]=1;
                
            }
            }
            
            
        }
        if (n[i]==2) {
            for (int Y=0; Y<H; Y++) {
                
                for (int X=x[i]; X<W; X++) {
                    
                    f[X][Y]=1;
                    
                }
            }

            
            
        }
        if (n[i]==3) {
            for (int Y=0; Y<y[i]; Y++) {
                
                for (int X=0; X<W; X++) {
                    
                    f[X][Y]=1;
                    
                }
            }
            
            
        }
        if (n[i]==4) {
            for (int Y=y[i]; Y<H; Y++) {
                
                for (int X=0; X<W; X++) {
                    
                    f[X][Y]=1;
                    
                }
            }
            
            
        }
        
    
    }
    
    
    for (int i=0; i<W; i++) {
        for (int j=0; j<H; j++) {
            if(f[i][j]==0){
                
                cnt++;
                
            }
        }
        
    }
    
    printf("%d\n",cnt);
    
    
   
    
    
    
  
    
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
#print(n,k)
goto = [-1] + list(map(int, input().split()))
#print(goto)

l = [[_, 0] for _ in range(2*n)] # [順番, 町番号]
#print(l)
cnt = [0 for _ in range(n+1)] # カウンター

tmp = 1
for i in range(1, 2*n):
    l[i][1] = tmp
    cnt[l[i][1]] += 1
    tmp = goto[tmp]
    if cnt[l[i][1]] == 2:
        x = l[i]
        break
#print(l)
#print(x)

for j in range(n):
    if l[j][1] == x[1]:
        y = l[j]
        break
#print(y)

if y[0] > k:
    print(l[k+1][1])
else:
    z = (k-y[0]+1) % (x[0]-y[0]) + y[0]
    print(l[z][1])

Measured memory_bytes: 66148
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef struct{
  int parent,child,brother;
}node;
node tree[100001];
int depth(int x,int sum);
int children(int x);
int main(){
  int n;
  memset(tree,-1,sizeof(tree));
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int id,k;
    scanf("%d%d",&id,&k);
    if(k>0){
      scanf("%d",&tree[id].child);
      int p=tree[id].child;
      tree[p].parent=id;
      for(int j=0;j<k-1;j++){
	scanf("%d",&tree[p].brother);
	p=tree[p].brother;
	tree[p].parent=id;
      }
    }
  }
  for(int i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,tree[i].parent);
    printf("depth = %d, ",depth(tree[i].parent,0));
    if(tree[i].parent==-1) printf("root, ");
    else if(tree[i].child==-1) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    if(tree[i].child==-1) printf("]\n");
    else{
      printf("%d",tree[i].child);
      int p=tree[i].child;
      children(tree[p].brother);
      printf("]\n");
    }
  }
    return 0;
}
int depth(int x,int sum){
  if(x==-1) return sum;
  return depth(tree[x].parent,sum+1);
}
int children(int x){
  if(x==-1) return 0;
  else{
    printf(", %d",x);
    return children(tree[x].brother);
  }
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  vector<int> p(n), q(n);
  REP(i,n){
    cin>>p[i];
    p[i]--;
  }
  REP(i,n){
    cin>>q[i];
    q[i]--;
  }
  bool flag = true;
  REP(i,n){
    if(p[i] == q[i])continue;
    if(p[i] < q[i])break;
    if(p[i] > q[i]){
      flag = false;
      break;
    }
  }
  if(!flag){
    REP(i,n){
      swap(p[i], q[i]);
    }
  }
  int ans = 0;
  do{
    bool cflag = false;
    REP(i,n){
      if(p[i] == q[i])continue;
      cflag = true;
    }
    if(!cflag){
      break;
    }
    ans++;
  }while(next_permutation(ALL(p)));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import static java.lang.Math.*;
import java.util.Scanner;

//Tetrahedra
public class Main{

	double EPS = 1e-10;
	double det(double[][] A){
		int n = A.length;
		double res = 1;
		for(int i=0;i<n;i++){
			int pivot = i;
			for(int j=i+1;j<n;j++)if(abs(A[j][i])>abs(A[pivot][i]))pivot = j;
			swap(A, pivot, i);
			res *= A[i][i] * (i!=pivot?-1:1);
			if(abs(A[i][i])<EPS)break;
			for(int j=i+1;j<n;j++)for(int k=n-1;k>=i;k--)A[j][k]-=A[i][k]*A[j][i]/A[i][i];
		}
		return res;
	}
	void swap(double[][] A, int a, int b){
		int n = A[a].length;
		for(int i=0;i<n;i++){
			double t = A[a][i];
			A[a][i] = A[b][i];
			A[b][i] = t;
		}
	}
	
	int[] l;
	boolean tri(int a, int b, int c){
		int m = max(l[a], max(l[b], l[c]));
		return m < l[a]+l[b]+l[c]-m;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			l = new int[n];
			for(int i=0;i<n;i++)l[i]=sc.nextInt();
			double max = 0;
			for(int a=0;a<n;a++){
				for(int b=0;b<n;b++){
					if(a==b)continue;
					for(int c=0;c<n;c++){
						if(a==c||b==c)continue;
						for(int p=0;p<n;p++){
							if(a==p||b==p||c==p||!tri(a, b, p))continue;
							for(int q=0;q<n;q++){
								if(a==q||b==q||c==q||p==q||!tri(a, c, q))continue;
								for(int r=0;r<n;r++){
									if(a==r||b==r||c==r||p==r||q==r||!tri(b, c, r)||!tri(p, q, r))continue;
									double[][] A = {{0, l[p]*l[p], l[q]*l[q], l[a]*l[a], 1},
											{l[p]*l[p], 0, l[r]*l[r], l[b]*l[b], 1},
											{l[q]*l[q], l[r]*l[r], 0, l[c]*l[c], 1},
											{l[a]*l[a], l[b]*l[b], l[c]*l[c], 0, 1},
											{1, 1, 1, 1, 0}
									};
									max = Math.max(max, det(A)/288);
								}
							}
						}
					}
				}
			}
			System.out.printf("%.8f\n", Math.sqrt(max));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

template <class T>
class PriorityQueue {
private:
  int maxSize, sz;
  T *data;

public:
  PriorityQueue(int maxSize) {
    this->maxSize = maxSize;
    sz = 0;
    data = new T[maxSize];
    for(int i = 0; i < maxSize; ++i) data[i] = NULL;
  }

  ~PriorityQueue() {
    delete [] data;
  }

  int size() {
    return sz;
  }

  bool empty() {
    return sz == 0;
  }

  void push(T x) {
    int i = sz++;

    while(i > 0) {
      int p = (i-1)/2;
      if(!(x < data[p])) break;
      data[i] = data[p];
      i = p;
    }

    data[i] = x;
  }

  T top() {
    return data[0];
  }

  void pop() {
    T x = data[--sz];
    int i = 0;
    while(i*2+1 < sz) {
      int a = i*2+1, b = i*2+2;
      if(b < sz && data[b] < data[a]) a = b;
      if(!(data[a] < x)) break;
      data[i] = data[a];
      i = a;
    }
    data[i] = x;
  }
};

#include <string>

struct State {
  int i;
  State() {}
  State(int i) : i(i) {}
  bool operator <(const State &s) const {
    return i > s.i;
  }
};


int main() {
  string s;
  PriorityQueue<State> que(2000000);
  while(cin >> s) {
    if(s == "insert") {
      int a;
      cin >> a;
      que.push(a);
    } else if(s == "extract") {
      cout << que.top().i << endl;
      que.pop();
    } else {
      break;
    }
  }
  return 0;
}

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

long long attack(long long hp){
  if(hp>1){
    return 2*attack(hp/2)+1;
  }else if(hp==1){
    return 1;
  }else{
    return 0;
  }
}
int main(){
  long long  h;
  long long ans=0;
  cin >> h;

  ans = 2 * attack(h/2)+1;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--n >= 0){
        string s;
        cin >> s;
        int n = s.size();
        if(n < 6 || n % 2 == 1){
            cout << "NA" << endl;
            continue;
        }

        string sa(n, '=');
        sa[0] = '>';
        sa[1] = '\'';
        sa[n/2] = '#';
        sa[n-1] = '~';
        if(s == sa){
            cout << 'A' << endl;
            continue;
        }

        string sb(n, '=');
        sb[0] = '>';
        sb[1] = '^';
        for(int i=2; i<n-2; i+=2)
            sb[i] = 'Q';
        sb[n-2] = '~';
        sb[n-1] = '~';
        if(s == sb)
            cout << 'B' << endl;
        else
            cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main() {

    int inf=1e8;
    int maxi=10010;
    int dp[maxi];
    for(int i=0; i<maxi; i++){
        dp[i] = inf;
    }
    dp[0]=0;

    int h,n; 
    cin >> h >> n;

    vector<pair<int, int>> v;
    int a,b;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        v.push_back(pair<int ,int>(a,b));
    }

    sort(v.begin(), v.end());

    for(int i=0; i<n; i++){
        a = v[i].first;
        b = v[i].second;

        for(int i=a; i<maxi; i++){
            dp[i]=min(dp[i], dp[i-a]+b);
        }
    }

    int ans = dp[h];
    for(int i=h; i<maxi; i++){
        ans=min(dp[i], ans);
    }
    
    cout << ans;



/*    
    vector<pair<int, int>> vc;
    int x;
    cin >> x;
    int s=x;
    while(x--){
        int a,b;
        cin >> a >> b;
        vc.push_back(pair<int, int>(a,b));
    }
    pair<int,int> p = vc[s-1];
    cout << p.first << ' ' << p.second << endl;
*/
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18 ;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	ll f=0,n,i,j,a,b;
	cin>>n;
	ll c=inf;
	for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            a=n/i;
            b=abs(a-1)+abs(i-1);
            c=min(c,b);
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
int main(){
    int n,x,count=0,ans=0,a,b,c,k,y,d[26]={0};
    string s,aa;
    vector<int> v;
        cin>>s;
        char ch[100];
        for(int i=0;i<s.size();i++)ch[i]=s[i];
        for(int i=0;i<s.size();i++){
        if(ch[i]=='a')d[0]++;
        if(ch[i]=='b')d[1]++;
        if(ch[i]=='c')d[2]++;
        if(ch[i]=='d')d[3]++;
        if(ch[i]=='e')d[4]++;
        if(ch[i]=='f')d[5]++;
        if(ch[i]=='g')d[6]++;
        if(ch[i]=='h')d[7]++;
        if(ch[i]=='i')d[8]++;
        if(ch[i]=='j')d[9]++;
        if(ch[i]=='k')d[10]++;
        if(ch[i]=='l')d[11]++;
        if(ch[i]=='m')d[12]++;
        if(ch[i]=='n')d[13]++;
        if(ch[i]=='o')d[14]++;
        if(ch[i]=='p')d[15]++;
        if(ch[i]=='q')d[16]++;
        if(ch[i]=='r')d[17]++;
        if(ch[i]=='s')d[18]++;
        if(ch[i]=='t')d[19]++;
        if(ch[i]=='u')d[20]++;
        if(ch[i]=='v')d[21]++;
        if(ch[i]=='w')d[22]++;
        if(ch[i]=='x')d[23]++;
        if(ch[i]=='y')d[24]++;
        if(ch[i]=='z')d[25]++;
        }
        if(d[0]%2==0&&d[1]%2==0 &&d[2]%2==0 &&d[3]%2==0 &&d[4]%2==0 &&d[5]%2==0 &&d[6]%2==0 &&d[7]%2==0&&d[8]%2==0&&d[9]%2==0&&d[10]%2==0&&d[11]%2==0 &&d[12]%2==0 &&d[13]%2==0 &&d[14]%2==0 &&d[15]%2==0 &&d[16]%2==0 &&d[17]%2==0&&d[18]%2==0&&d[19]%2==0&&d[20]%2==0&&d[21]%2==0 &&d[22]%2==0 &&d[23]%2==0 &&d[24]%2==0 &&d[25]%2==0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        
        
        
        
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void func(long long W, long long H, long long x, long long y) {
    cout << fixed << setprecision(6);
    // cout << (double)W * (double)H / 2 << " ";
    cout << W * H / 2.0 << " ";
    cout << (W == x * 2 && H == y * 2) << endl;
}

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

    long long W;
    scanf("%lld", &W);
    long long H;
    scanf("%lld", &H);
    long long x;
    scanf("%lld", &x);
    long long y;
    scanf("%lld", &y);
    func(W, H, x, y);
    return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

mt19937 rng( (int)chrono::steady_clock::now().time_since_epoch().count() );

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

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafClover

  int l; cin >> l;
  int n = 20;
  vector<tuple<int, int, int> > edge;

  if ( (l >> 19) & 1) {
    vector<int> id(n);
    for (int i = 0, cur; i < 18; ++i, ++cur) {
      if (cur ^ i) {
        edge.emplace_back(i, i + 1, 0);
        edge.emplace_back(i, i + 1, 1 << cur);
        id[cur + 1] = i + 1;
      }
      else {
        if (i && !( (l >> i) & 1) ) {
          edge.emplace_back(i - 1, i, 1 << cur);
          edge.emplace_back(i - 1, i, (1 << cur) + (1 << (cur - 1) ) );
          id[cur + 1] = i;
          ++cur;
        }
        edge.emplace_back(i, i + 1, 0);
        edge.emplace_back(i, i + 1, 1 << cur);
        id[cur + 1] = i + 1;
      }
    }

    for (int i = 19; ~i; --i) if ( (l >> i) & 1) {
      l ^= 1 << i;
      edge.emplace_back(id[i], n - 1, l);
    }
  }
  else {
    for (int i = 0; i < 18; ++i) {
      edge.emplace_back(i, i + 1, 0);
      edge.emplace_back(i, i + 1, 1 << i);
    }

    for (int i = 18; ~i; --i) if ( (l >> i) & 1) {
      l ^= 1 << i;
      edge.emplace_back(i, n - 1, l);
    }
  }

  cout << n << ' ' << sz(edge) << '\n';
  for (const auto &i : edge) cout << get<0>(i) + 1 << ' ' << get<1>(i) + 1 << ' ' << get<2>(i) << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

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

    if (a == 1)
    {
        a = 14;
    }
    if (b == 1)
    {
        b = 14;
    }

    if (a == b)
    {
        cout << "Draw" << endl;
    }
    else
    {
        cout << (a > b ? "Alice" : "Bob") << endl;
    }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H+2);

  for(int i=0; i<H+2; i++){
    if(i==0||i==H+1){
      string frame(W+2, '#');
      a[i] = frame;
    }
    else{
      string frame;
      cin >> frame;
      a[i] = '#'+frame+'#';
    }
  }

  for(int i=0; i<H+2; i++){
    cout << a[i] << endl;
  }
}


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

constexpr int INF = 1e9+1;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i) {
        cin >> a[i];
    }
    vector<int> dp(n, INF);
    for(int i=0; i<n; ++i) {
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }
    cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 2000005;
const int mod = 1000000007;

void gcd(ll a,ll b, ll& d,ll& x,ll& y){
  if(!b) {d=a;x=1;y=0;}
  else   {	gcd(b,a%b,d,y,x);	y-=a/b*x;}
}

ll inv(ll a,ll n)  {
  ll d,x,y;	gcd(a,n,d,x,y);
  return d==1?(x%n+n)%(n/d):-1;
}

ll p[maxn];

ll solve(int r, int c){
  ll ret = 0;
  for(int i=0;i<=c;i++){
    ret += p[r+i+1]*inv(p[i+1]*p[r]%mod, mod)%mod;
    ret%=mod;
  }
  return ret;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  p[0] = 1;
  for(int i=1;i<maxn;i++)p[i]=p[i-1] * i % mod;
  int r1,c1,r2,c2;
  cin>>r1>>c1>>r2>>c2;
  ll ret = (solve(r2,c2)+solve(r1-1,c1-1)-solve(r1-1,c2)-solve(r2,c1-1));
  ret = (ret%mod+mod)%mod;
  cout<<ret<<endl;
  return 0;
}

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

using namespace std;

int m,n,i,j,ans;

int main()
{
	scanf("%d%d",&m,&n);
	for(j=1;j<=m;j++)
		for(i=1;i<=n;i++)
			if(i%10>=2&&i/10>=2&&j==(i%10)*(i/10))
				ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1
#define sosuu 1000000007

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N)
    cin >> d[i];
  sort(ALL(d));
  cout << d[N/2] -d[N/2-1] << endl;
}

Measured memory_bytes: 640
N = gets.chomp
def dfs(num, array)
  # 入力値よりも桁数が大きくならない範囲で処理
  if num.length <= N.length
    array << num unless num.empty? # 初期値避け
    dfs(num + "3", array)
    dfs(num + "5", array)
    dfs(num + "7", array)
  end
  if num.empty?
    array
  end
end
array = dfs("", [])
# 入力値よりも小さく、3, 5, 7を含むものだけ残して個数を出す
puts array.map { |num| num.to_i <= N.to_i && num.include?("3") && \
  num.include?("5") && num.include?("7") ? num : nil }.compact.count


Measured memory_bytes: 4348
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (long(i) = 0; (i) < (n); (i)++)
#define sort(s) sort(s.begin(), s.end(), greater<int>())
using namespace std;
int main() {
  int n, count = 0;
  cin >> n;
  vector<int> a(2 * n);
  REP(i, 2 * n) cin >> a[i];
  sort(a);
  REP(i, 2 * n) {
    if (i % 2 == 1)
      count += a[i];
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<functional>
#include<string>

using namespace std;

int main(void){

    int n;
    cin >> n;
    string s, t, ans = "";
    cin >> s >> t;

    for(int i = 0;s[i] != '\0';i++){
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
   int n, a, b, c, d, sum, key;
   while(scanf("%d", &n) != EOF){
      key = 0;
      for(a = 0; a <= 9; a++){
         for(b = 0; b <= 9; b++){
            for(c = 0; c <= 9; c++){
               for(d = 0; d <= 9; d++){
                  if(n == a + b + c + d){
                     key++;
                  }
               }
            }
         }
      }
      printf("%d\n", key);
   }
   return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(all(t));
	vector<int> cnt1(26), cnt2(26);
	int n = s.size();
	rep(i, n) {
		cnt1[s[i] - 'a']++;
		cnt2[t[i] - 'a']++;
	}
	sort(all(cnt1));
	sort(all(cnt2));
	if (cnt1 == cnt2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3804
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 21145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
struct edge { int to, cost; };
P x[200005];
int ans[200005];
signed main() {
	int n; cin >> n;
	rep(i, n) {
		int a; cin >> a; x[i] = P(a, i);
	}
	sort(x, x + n);

	rep(i, n) {
		int F = x[i].first, S = x[i].second;
		int mi;
		if (i < n / 2)mi = n / 2;
		else mi = n / 2 - 1;
		ans[S] = x[mi].first;
	}

	rep(i, n)cout << ans[i] << endl;
}

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

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

vector<string> S(51);
int M = 0,H,W;
int dist[51][51];
queue<pair<int, int>> que;

int BFS(int sy,int sx)
{
    rep(i,51){
        rep(j,51)dist[i][j]=-1;
    }
    que.push(make_pair(sy, sx));
    dist[sy][sx] = 0;
    while (!que.empty())
    {
        int y = que.front().first;
        int x = que.front().second;
        que.pop();

        rep(i, 4)
        {
            int ny = y + dy[i];
            int nx = x + dx[i];

            if (nx < 0 || nx >= W || ny < 0 || ny >= H)continue;
            if (S[ny][nx] == '#')continue;
            if (dist[ny][nx] != -1)continue;
            dist[ny][nx] = dist[y][x] + 1;
            M = max(M, dist[ny][nx]);

            que.push(make_pair(ny, nx));
        }
    }
    return 0;
}

int main(){
    cin>>H>>W;

    rep(i,H){
        cin>>S[i];
    }


    rep(sy,H){
        rep(sx,W){
            if(S[sy][sx]=='.')BFS(sy,sx);
        }
    }

    cout<<M<<endl;

    return 0;
}

//a=97,z=122

/*

4 5
#####
....#
.####
.....

*/

Measured memory_bytes: 256
#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() {
    char c;
    cin >> c;
    if (isupper(c)) cout << "A" << endl;
    else cout << "a" << endl;
    return 0;
}

Measured memory_bytes: 3524
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	string s;
	int x[] = {0, 0, 1, 2, 0, 0, 2, 0, 1, 2};
	while (cin >> s && s != "#"){
		int n = s.length();
		if (n <= 2){
			cout << 0 << endl;
			continue;
		}
		VI a(n);
		REP(i,n) a[i] = s[i] - '0';
		int l = -1, r = 3;
		int f, lstart = 0, rstart = 0;
		f = 0;
		REP(i,n){
			if (f == 0){
				if (x[a[i]] <= r){
					l = x[a[i]];
					f ^= 1;
				}else{
					r = x[a[i]];
					lstart++;
				}
			}else{
				if (x[a[i]] >= l){
					r = x[a[i]];
					f ^= 1;
				}else{
					l = x[a[i]];
					lstart++;
				}
			}
		}
		l = -1, r = 3;
		if (l > r) swap(l,r);
		f = 1;
		REP(i,n){
			if (f == 0){
				if (x[a[i]] <= r){
					l = x[a[i]];
					f ^= 1;
				}else{
					r = x[a[i]];
					rstart++;
				}
			}else{
				if (x[a[i]] >= l){
					r = x[a[i]];
					f ^= 1;
				}else{
					l = x[a[i]];
					rstart++;
				}
			}
		}
		cout << min(lstart, rstart) << endl;
	}
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    
    int a = scanner.nextInt();
    String op = scanner.next();
    int b = scanner.nextInt();
    
    //　A と B をopに従って計算する
    if(op.equals("+")) {
      System.out.println(a + b);
    } else if(op.equals("-")) {
      System.out.println(a - b);
    } else {
      System.out.println("+か-の演算子を使用してください。");
    }
  }
}

Measured memory_bytes: 35816
<?php
    fscanf(STDIN,"%d %d ",$a,$b);

    $keisan = array(($a+$b),($a-$b),($a*$b));
    $max = -1000000000;
    foreach($keisan as $value){
        if($max<$value){
            $max=$value;
        }

    }
echo $max."\n";


Measured memory_bytes: 4728
class UnionFind():
    "Either 0-indexed or 1-indexed"

    __slots__ = ["parent"]

    def __init__(self, size):
        self.parent = [-1] * (size + 1)
    
    def find(self, a):
        path = []
        while self.parent[a] > 0:
            path.append(a)
            a = self.parent[a]
        for child in path:
            self.parent[child] = a
        return a

    def union(self, a, b):
        a = self.find(a)
        b = self.find(b)

        if a == b:
            return
        else:
            if self.parent[a] == self.parent[b]:
                self.parent[a] = b
                self.parent[b] -= 1
            elif self.parent[a] < self.parent[b]: #aのほうが大きい
                self.parent[b] = a
            else:
                self.parent[a] = b #bのほうが大きい
        
    def same(self, a, b):
        return self.find(a) == self.find(b)

    # def group(indexed = -1):
    #     """
    #     indexed = i if the UnionFind is i-indexed (i = 0, 1).
    #     -1 if not specified.
    #     Return a list, i-th element of which has what group the element belongs to
    #     ex:
    #         0 - 1 - 4 and 2 - 3
    #         [0, 0, 1, 1, 0]
    #     Time complexity: O(Nα(N))
    #     """
    #     group = dict()
    #     ret = [-1] * len(self.parent)
    #     for i in range(len(self.parent)):


    

N = int(input())
xys = [tuple(map(int, input().split())) for _ in range(N)]

# 座圧
xs_decode, ys_decode = map(sorted, map(set, zip(*xys)))
xs_encode = {x: i for i, x in enumerate(xs_decode)}
ys_encode = {y: i for i, y in enumerate(ys_decode, start=len(xs_decode))}

uf = UnionFind(len(xs_decode) + len(ys_decode))
for x, y in xys:
    i = xs_encode[x]
    j = ys_encode[y]
    uf.union(i, j)

ancestor2group = dict()
for i in range(len(xs_decode) + len(ys_decode)):
    a = uf.find(i)
    if a in ancestor2group:
        ancestor2group[a].append(i)
    else:
        ancestor2group[a] = [i]

ans = 0
for group in ancestor2group.values():
    xs_count = 0
    ys_count = 0
    for elem in group:
        if elem < len(xs_decode):
            xs_count += 1
        else:
            ys_count += 1
    ans += xs_count * ys_count

ans -= len(xys)

print(ans)

Measured memory_bytes: 105144
n = int(input())
a = input().split()
list = []
list_of_topcoder = []

for i in range(n):
    if 1<=int(a[i])<=399:
        if "gray" not in list:
            list.append("gray")
        else:
            pass
    elif 400<=int(a[i])<=799:
        if "brown" not in list:
            list.append("brown")
        else:
            pass
    elif 800<=int(a[i])<=1199:
        if "green" not in list:
            list.append("green")
        else:
            pass
    elif 1200<=int(a[i])<=1599:
        if "water" not in list:
                list.append("water")
        else:
            pass
    elif 1600<=int(a[i])<=1999:
        if "blue" not in list:
            list.append("blue")
        else:
            pass
    elif 2000<=int(a[i])<=2399:
        if "yellow" not in list:
            list.append("yellow")
        else:
            pass
    elif 2400<=int(a[i])<=2799:
        if "orange" not in list:
            list.append("orange")
        else:
            pass
    elif 2800<=int(a[i])<=3199:
        if "red" not in list:
            list.append("red")
        else:
            pass
    elif 3200<=int(a[i])<=4800:
        list_of_topcoder.append(i)

if len(list) != 0:
    print(len(list), len(list)+len(list_of_topcoder))
else:
    print(1, len(list_of_topcoder))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;


int main(){
    cin>>S;
    N = S.size();
    set<ll> est;
    est.insert(0);
    map<ll,ll> num;
    num[0] = 0;
    ll now = 0;
    rep(i,N){
        ll alph = S[i] - 'a', res = INF;
        now = now ^ (1LL<<alph);
        //cout<<now<<endl;
        rep(j,26){
            if(est.find(now ^ (1LL<<j)) != est.end()) {
                res = min(res, num[now ^ (1LL << j)] + 1);
            }
        }
        if(est.find(now) != est.end()){
            res = min(res, num[now]);
        }
        est.insert(now);
        num[now] = res;
    }
    cout<<(num[now] == 0 ? 1 : num[now])<<endl;
    //rep(i,27) cout<<num[(1LL<<i) - 1]<<endl;
}

Measured memory_bytes: 22276
from bisect import bisect_left
def main():
    h, w, m = map(int, input().split())
    bombs = set()
    cnt_row, cnt_col = [0]*(h+1), [0]*(w+1)
    for _ in range(m):
        y, x = map(int, input().split())
        cnt_row[y] += 1
        cnt_col[x] += 1
        bombs.add((y, x))
    max_cnt_row = max(cnt_row)
    max_cnt_col = max(cnt_col)
    idx_row = []
    idx_col = []
    for i in range(h+1):
        if cnt_row[i] == max_cnt_row:
            idx_row.append(i)
    for j in range(w+1):
        if cnt_col[j] == max_cnt_col:
            idx_col.append(j)
    ans = max_cnt_row + max_cnt_col - 1
    for i in idx_row:
        for j in idx_col:
            if not (i, j) in bombs:
                ans = max_cnt_row + max_cnt_col
                break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 83388
A,B =map(int,input().split())
 
# 元の価格ｘ,8%  y、１０％
import math
x = math.ceil(A/0.08)
x_1 = math.ceil((A+1)/0.08 )
y = math.ceil(B/0.1)
y_1 = math.ceil( (B+1)/0.1 )

x_2 = {i for i in range(int(x),int(x_1) ) }
y_2 = {i for i in range(int(y),int(y_1) ) }
moto_nedan = x_2 & y_2
if len(moto_nedan) == 0:
    print("-1")
else:
    print(min(moto_nedan))

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        string inpt = Reader.ReadLine();
        string ans = "yes";
        if(inpt.Any(a=>inpt.Count(b=>b==a)>1)) {
            ans = "no";
        }
        Console.WriteLine(ans);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"

uncopyrightable


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 13268
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  dchar[] s; readV(s);
  dchar[] t; readV(t);

  s.sort!"a<b";
  t.sort!"a>b";

  writeln(s < t ? "Yes" : "No");
}


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

int main(){
	int n;
	int data[4][13];
	int i, j;
	char c;
	int num;


	scanf("%d", &n);


	for(j=0;j<4;j++){
		for(i=0;i<13;i++){
			data[j][i]=0;
		}
	}


	for(i=0; i<n; i++){

		scanf("%*c%c %d", &c, &num);

		switch(c){
			case 'S':
				data[0][num-1]=1;
				break;

			case 'H':
				data[1][num-1]=1;
				break;

			case 'C':
				data[2][num-1]=1;
				break;

			case 'D':
				data[3][num-1]=1;
				break;
		}

	
	}

	for(j=0; j<4; j++){
		for(i=0; i<13; i++){
			if(data[j][i] == 0){
				switch(j){
					case 0:
					printf("S %d\n", i+1);
					break;

					case 1:
					printf("H %d\n", i+1);
					break;

					case 2:
					printf("C %d\n", i+1);
					break;

					case 3:
					printf("D %d\n", i+1);
					break;


				}
			}
		}
	}

	
	return 0;

}


Measured memory_bytes: 2048
package main
  
import (
    "fmt"
)

var mp map[int]map[int]bool
var chk map[int]bool

func main() {
    var n, m int
    fmt.Scan(&n, &m)

    mp = make(map[int]map[int]bool)
    chk = make(map[int]bool)

    for i := 0; i < m; i++ {
        var x, y, z int
        fmt.Scan(&x, &y, &z)
        x--
        y--
        if _, ok := mp[x]; !ok {
            mp[x] = make(map[int]bool)
        }
        mp[x][y] = true
        if _, ok := mp[y]; !ok {
            mp[y] = make(map[int]bool)
        }
        mp[y][x] = true
    }

    var sum int
    for i := 0; i < n; i++ {
        sum += search(i)
    }
    fmt.Println(sum)
}

func search(pos int) int {
    if b, ok := chk[pos]; ok && b {
        return 0
    }
    chk[pos] = true
    for k, _ := range mp[pos] {
        search(k)
    }
    return 1
}


Measured memory_bytes: 57344
N,M,K = map(int,input().split())
ans=[0 for i in range(N)]
  
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
uf = UnionFind(N)
for i in range(M):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
  ans[a-1]-=1;ans[b-1]-=1
    
for i in range(K):
  c,d=map(int,input().split())
  if uf.same(c-1,d-1):
    ans[c-1]-=1;ans[d-1]-=1
    
for i in range(N):
  ans[i]+=uf.size(i)-1
  print(ans[i],end=" ")


Measured memory_bytes: 96032
#include <bits/stdc++.h>
using namespace std;
  
  int main() {
    int n;
	cin >> n;
    float m, m2;
  for (int i = 1; i <=9; i++) {
  	m = (double)n / i;
    if (floor(m) == m && 1 <= m && m <= 9) {
      cout << "Yes";
      return 0;
    }else if(i == 9) {
      cout << "No";
      return 0;
    }
  }
}

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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
//}}}


int solve(){
  int n;cin>>n;

  int a[3*n];
  rep(i, 3*n){ cin>>a[i]; }

  priority_queue<int, vector<int>, greater<int>> L;
  priority_queue<int, vector<int>> R;

  // LSUM{{{
  int LSUM[3*n]={};
  int sum = 0;
  rep(i, n){
    L.push(a[i]);
    sum += a[i];
  }
  LSUM[n-1] = sum;
  rep(i, n, 3*n){
    LSUM[i] = LSUM[i-1];
    LSUM[i] += a[i];
    L.push(a[i]);
    LSUM[i] -= L.top(); L.pop();
  }/*}}}*/
  // RSUM{{{
  int RSUM[3*n]={};
  sum = 0;
  rrep(i, 2*n, 3*n){
    R.push(a[i]);
    sum += a[i];
  }
  RSUM[2*n] = sum;
  rrep(i, 0, 2*n){
    RSUM[i] = RSUM[i+1];
    RSUM[i] += a[i];
    R.push(a[i]);
    RSUM[i] -= R.top(); R.pop();
  }/*}}}*/

  dump_1d(LSUM, 3*n);
  dump_1d(RSUM, 3*n);

  int res = -INF;
  rep(r, n, 2*n+1){  // r:start
    chmax(res, LSUM[r-1] - RSUM[r]);
  }
  cout << res << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 9588
//専用ライブラリ
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int cmp(P a,P b){
        if(a.fi!=b.fi)
        return a.fi>b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
struct unionfind{
    vector<int> rank,parent,size;
    int independent_tree;
    int N;
    
    unionfind(int n){
        N=n;
        for(int i=0;i<n;i++){
            rank.push_back(1);
            parent.push_back(i);
            size.push_back(1);
            independent_tree=N;
        }
    }
    int getroot(int x){
        if(parent[x]==x)
            return x;
        return parent[x]=getroot(parent[x]);
    }
    bool issame(int a,int b){
        return getroot(a)==getroot(b);
    }
    void unite(int a,int b){
        a=getroot(a);
        b=getroot(b);
        if(a==b)
            return;
        else if(rank[a]>rank[b]){
            parent[b]=a;
            size[a]+=size[b];
        }
        else if(rank[a]==rank[b]){
            parent[b]=a;
            rank[a]++;
            size[a]+=size[b];
        }
        else{
            parent[a]=b;
            size[b]+=size[a];
        }
    }
};

int n,m;
vector<vector<int> >M;
//---------------------------------------------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    
    cin>>n>>m;
    M.resize(m);
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        for(int j=0;j<k;j++)
        {
            int a;
            cin>>a;
            a--;
            M[a].push_back(i);
        }
    }
    unionfind uf(n);
    for(int i=0;i<m;i++)
    {
        if(M[i].size()>1)
        {
            for(int j=1;j<M[i].size();j++){
                if(!uf.issame(M[i][0],M[i][j]))
                    uf.unite(M[i][0],M[i][j]);
            }
        }
    }
    int ans=-1;
    for(int i=0;i<n;i++)
        ans=std::max(ans,uf.size[uf.getroot(i)]);
    if(ans==n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 4736