akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
constexpr ll INF=(1ll<<60);
constexpr ll mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n,d;cin>>n>>d;
    cout<<(n+(2*d+1)-1)/(2*d+1)<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <stack>
#include <string>

int main() {
  std::stack<int> s;
  std::string str;
  getline(std::cin, str);
  int i = 0;
  while(1) {
    if (i >= (int)str.size())
      break;
    std::string::size_type j = str.find_first_of(' ', i);
    if (j == std::string::npos)
      j = str.size();
    std::string w = std::string(str.begin() + i, str.begin() + j);
    i = j + 1;
    if (w == "+" || w == "-" || w == "*") {
      int a = s.top(); s.pop();
      int b = s.top(); s.pop();
      if (w == "+")
        s.push(b + a);
      else if (w == "-")
        s.push(b - a);
      else if (w == "*")
        s.push(b * a);
    } else {
      int n = std::stoi(w);
      s.push(n);
    }
  }
  std::cout << s.top() << std::endl;;
}

Measured memory_bytes: 3196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int a[1010],b[1010],x[1001001],y[1001001];

int main(void){
	int n,m,i,j,h=0,w=0;
	ll ans=1ll;
	fill(x,x+1001001,-1);
	fill(y,y+1001001,-1);
	cin >> n >> m;
	for(i=0; i<n; ++i){
		cin >> a[i];
		if(x[a[i]]>=0){
			ans = 0ll;
		}
		x[a[i]] = i;
	}
	for(j=0; j<m; ++j){
		cin >> b[i];
		if(y[b[i]]>=0){
			ans = 0ll;
		}
		y[b[i]] = i;
	}
	for(i=n*m; i>0; --i){
		if(!ans){
			break;
		}
		if(x[i]<0 && y[i]<0){
			mul_mod(ans,max((ll)(h*w-n*m+i),0ll));
		}else if(x[i]<0){
			mul_mod(ans,(ll)(w));
			++h;
		}else if(y[i]<0){
			mul_mod(ans,(ll)(h));
			++w;
		}else{
			++h;
			++w;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8064
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007

// ll T,N;
// vector<ll> a(N);
// const int M = 2;
// void dfs(vector<int> &A) {
//     // 終端条件 --- 10 重ループまで回したら処理して打ち切り
//     if (A.size() == n) {
//         return;
//     }

//     for (int v = 0; v < M; ++v) {
//         A.push_back(v);
//         dfs(A);
//         A.pop_back(); // これが結構ポイント
//     }
// }

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    ll n;
  cin>>n;
  // vector<ll> a(n);
  ll cnt[100010] = {0};
  rep(i,n){
    ll a;      cin>>a;
    cnt[a]++;
  }
  ll q; cin>>q;
  vector<ll> b(q), c(q);
  ll sum = 0;
  rep(i, 100010){
    sum += i*cnt[i];
  }
  
  // ll sum = std::accumulate(a.begin(), a.end(), 0LL);
  rep(i,q){
      cin>>b[i]>>c[i];

      ll diff = c[i] - b[i];
      sum += diff * cnt[b[i]];
      cnt[c[i]] += cnt[b[i]];
      cnt[b[i]] = 0;
      
      cout << sum << endl; 


   
  }

  



  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int cnto = 0;

  for(int i=0;i<3;i++){
    if(s[i] == 'o') cnto++;
  }

  cout << 700 + cnto * 100 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

#include <algorithm>

using namespace std;

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

  int max_h = H[0], num = 1;
  for (int i = 1; i < N; ++i) {
    if(H[i] >= max_h){
      max_h = max(H[i], max_h);
      num++;
//      printf("[%d] %d, %d\n", i, H[i], max_h);
//      cout << i << " - " << H[i] << endl;
    }
  }

  cout << num << endl;



  return 0;
}

Measured memory_bytes: 256
#import math
#import itertools
#import numpy as np
#from collections import deque


INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,m=INTM()
    A=LIST()
    bcs=[]
    for i in range(m):
        temp=LIST()
        bcs.append(temp)
    A=sorted(A)
    bcs=sorted(bcs, key=lambda x: x[1], reverse=True)
    itr=-1
    flg=False
    #print(A)
    for b,c in bcs:
        if itr+b>n-1:
            flg=True
        if flg:
            for i in range(itr+1,n):
                if A[i]<c:
                    A[i]=c
                else:
                    itr=10**9
                    break
        else:
            if A[itr+b]<c:
                A[itr+1:itr+b+1]=[c]*b
            else:
                for i in range(itr+1,itr+b+1):
                    if A[i]<c:
                        A[i]=c
                    else:
                        itr=10**9
                        break

        itr+=b

        if itr>n-1:
            break
    print(sum(A))
    #print(A)

    


if __name__=='__main__':
    do()

Measured memory_bytes: 33740
#include <stdio.h>
#include <math.h>
typedef long long int ll;

int main(void){
  char buf[40];
  ll x;
  fgets(buf, 40, stdin);
  sscanf(buf, "%ld", &x);
  int b = 1;
  if(x <= 3){
  	printf("%lld\n", x);
    return 0;
  }
  while(b){
    ll n = (int)sqrt(x) + 1;
    int bb = 0;
    for(ll i = 2; i <= n; i++){
      if(x % i == 0) bb = 1;
    }
    if(bb == 0) b = 0;
    x++;
  }
  printf("%lld\n", --x);
  return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  ll tn = n;
  while(tn) {
    ans += tn % 10;
    tn /= 10;
  }
  if(n % ans) printf("No");
  else printf("Yes");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll a , b , c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b;	

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int N,Q;
    cin>>N>>Q;
    tuple<ll,ll,ll> ob[210000];
    for(int i=0;i<N;i++){
        ll s,t,x;
        cin>>s>>t>>x;
        s-=x;
        t-=x;
        ob[i]=tie(x,s,t);
    }
    sort(ob,ob+N);
    set<P> S;
    for(int i=0;i<Q;i++){
        int d;
        cin>>d;
        S.insert( P(d,i+1) );
    }
    ll ans[210000];
    for(int i=0;i<210000;i++) ans[i]=-1;
    for(int i=0;i<N;i++){
        ll x,l,r;
        tie(x,l,r)=ob[i];
        auto it=S.lower_bound( P(l,-1) );
        while(it!=S.end()){
            if(it->first>=r) break;
            ans[it->second]=x;
            S.erase(it++);
        }
    }
    for(int i=1;i<=Q;i++){
        cout<<ans[i]<<endl;
    }
    
}



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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

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

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

Measured memory_bytes: 3632
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define MAX ((ll)1<<(ll)31)-1

int main(void) {
	int n; cin >> n;
	string a, b;
	cin >> a;
	cin >> b;
	rep(i, n) {
		cout << a[i] << b[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
long long a,b,c,min,temp;
long long ar[3];
for(int i=0;i<3;i++){
    scanf("%lli",&ar[i]);
}
min = ar[0];
for(int i=0;i<3;i++){
    if(ar[i]<min)
        min = ar[i];
}
for(int i=0;i<3;i++){
    if(ar[i]==min){
        temp = ar[0];
        ar[0] = ar[i];
        ar[i] = temp;
        break;
    }
}
if(ar[1]>ar[2]){
    temp = ar[1];
    ar[1] = ar[2];
    ar[2] = temp;
}
printf("%lli %lli %lli\n",ar[0],ar[1],ar[2]);

return 0;
}



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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    int N;
    cin >> N;

    vector<pair<int, int>> v;
    FOR(i, 0, N) {
        int a, b;
        cin >> a >> b;
        v.emplace_back(make_pair(a, b));
    }

    VV<int> dp(N + 1, V<int>(N + 1, INF));
    FOR(i, 0, dp.size()) {
        dp[i][i] = 0;
    }

    FOR(width, 0, N) {
        FOR(left, 0, N - width) {
            int right = left + width;
            FOR(k, left + 1, right + 1) {
                int cost = dp[left][k - 1] + dp[k][right] + v[left].first * v[k - 1].second * v[k].first * v[right].second;
                dp[left][right] = min(dp[left][right], cost);
            }
        }
    }
    print(dp[0][N - 1]);
    return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 1000000000
#define inf 1000000000000000000
#define M 998244353
using namespace std;
typedef long long ll;
const int N = 1e6+300;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double TAU = 2*PI;

int x;

void solve(){
  cin >> x;
  int k = 1;
  for(int i = 1;i<=360 ; i++){
    if((x*i)%360==0){
      k=i;
      break;
    }
  }
  cout << k << endl;

}


signed main() {
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3104
def modpow(a, n, m)
  return 1 if n == 0

  tmp = modpow(a, n / 2, m)
  n % 2 == 0 ? tmp * tmp % m : tmp * tmp * a % m
end

n = gets.chomp.to_i
M = (1e9+7).to_i
puts (modpow(10, n, M) - 2 * modpow(9, n, M) + modpow(8, n, M)) % M

Measured memory_bytes: 14376
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 300005;

struct Seg
{
	int l,r,id;
}sl[MAXN],sr[MAXN];

int n;

long long ans;

bool mark[MAXN];

bool cmp1(const Seg &a,const Seg &b)
{
	return a.l > b.l;
}

bool cmp2(const Seg &a,const Seg &b)
{
	return a.r < b.r;
}

void run()
{
	memset(mark,0,sizeof(mark));
	int p = 0;
	long long res = 0;
	for (int i = 1,j = 1,k = 1;i <= n;i++)
	{
		if (i & 1)
		{
			while (mark[sl[j].id])
				j++;
			mark[sl[j].id] = 1;
			res += max(0,sl[j].l - p);
			p = max(p,sl[j].l);
			j++;
		}
		else
		{
			while (mark[sr[k].id])
				k++;
			mark[sr[k].id] = 1;
			res += max(0,p - sr[k].r);
			p = min(p,sr[k].r);
			k++;
		}
	}
	ans = max(ans,res + abs(p));
}

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
	{
		scanf("%d%d",&sl[i].l,&sl[i].r);
		sl[i].id = i;
		sr[i] = sl[i];
	}
	sort(sl + 1,sl + n + 1,cmp1);
	sort(sr + 1,sr + n + 1,cmp2);
	run();
	for (int i = 1;i <= n;i++)
	{
		sl[i].l = -sl[i].l;
		sl[i].r = -sl[i].r;
		swap(sl[i].l,sl[i].r);
		sr[i] = sl[i];
	}
	sort(sl + 1,sl + n + 1,cmp1);
	sort(sr + 1,sr + n + 1,cmp2);
	run();
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
    int ans=0,sum=0;
    int n,a;
    int max1=0,max2=0;
    cin >> n;
    int data[n];
    int sorted[n];

    for (int i = 0; i < n; i++){
        cin >>data[i];
        sorted[i]=data[i];
    }
    
    sort(sorted,sorted+n,greater<int>());
    max1=sorted[0];
    int p=0;
    while (sorted[p] == sorted[0])p++;

    if(p>=n){
        max2=max1;
    }else if(p==1){
        max2=sorted[p];
    }else{
        max2=max1;
    }

    for (int i = 0; i < n; i++){
        if(data[i]==max1){
            std::cout << max2 << endl;
        }else{
            std::cout << max1 << endl;

        }
    }
    


    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include <algorithm>
#include <string>
#define syso(s) std::cout<<s<<endl;
#define sc(i) std::cin>>i;
using namespace std;
int main() {
	char A[100], s[200], B[100];
	sc(A)
		sc(s)
		sc(B)
		string str = "A";
	str += s[0];
	str += "C";
	syso(str)
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
//    freopen("in.in", "r", stdin);
//    freopen("out.out", "w", stdout);
}

const int N = 1e5 + 9, M = 2e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


int main(){
    init();

    ll x;   cin >> x;

    ll c = 100, ans = 0;
    while(c < x){
        c += c * 0.01;
        ans++;
    }

    cout << ans;


}







Measured memory_bytes: 3648
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string s; cin >> s;
	int ans = 0;
	while (s.size ()) {
		s.pop_back();
		if(s.size()%2 != 0) continue;
		string t;
		for (int i = 0; i < s.size () / 2; i++) {
			t.push_back(s[i]);
		}
		if (t + t == s) {
			ans = s.size();//max(ans, (int)t.size()*2);
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

void solve() {
    lli n, m;
    cin >> n >> m;
    map<lli, set<plli>> mp;
    vector<string> city(MAXN);
    for (int i = 0; i < m; ++i) {
        lli p, y;
        cin >> p >> y;
        mp[p].insert({y, i + 1});
    }
    for (auto it : mp) {
        string pid = to_string(it.first);
        lli len = 6 - pid.length();
        while (len--) {
            pid = '0' + pid;
        }
        lli cnt = 1;
        for (auto i : it.second) {
            string cid = to_string(cnt);
            lli len1 = 6 - cid.length();
            while (len1--) cid = '0' + cid;
            city[i.second] = pid + cid;
            cnt++;
        }
    }
    for (int i = 1; i <= m; ++i) {
        cout << city[i] << endl;
    }
}

int main()
{
    opt;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 22656
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef long double td;
typedef vector<td> vd;
typedef pair<ll,ll> ii;
typedef vector<ii> vii; typedef vector<bool> vb;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = ll(a); i < (ll)(b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define show(v,n) cerr << #v << " = "; forn(i,n) cerr << v[i] << " "; cerr << endl;
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
int MAXN = 500005;


ll solve(vector <int> &v, int n, int k)
{
	ll MAXN = (ll)(1e18);
	vector <ll> dp(n,MAXN);
	dp[0]=0;
	forr(i,1,n)
	{
		forr(j,1,k+1)
		{
			if(i-j < 0) break;
			dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
		}
	}
	return dp[n-1];
}
 
int main()
{ 	
	FIN;
	#ifdef input
		freopen("test1.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector <int> v(n);
	forn(i,n) cin >> v[i];
	cout << solve(v,n,2) << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int N;

	cin >> N;
	
	if(N==22)cout << "Christmas Eve Eve Eve" << endl;
	else if(N==23)cout << "Christmas Eve Eve" << endl;
	else if(N==24)cout << "Christmas Eve" << endl;
	else cout << "Christmas" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>

int gcd(int x, int y){
	if(x< y){
		int tmp= x;
		x= y;
		y= tmp;
	}

	if(x%y ==0)
		return y;
	else
		return gcd(y, x%y);
}

int main(){
	int n;
	std::vector<int> aList;
	std::vector<int> gcdFor;
	std::vector<int> gcdBack;
	std::vector<int> cand;


	std::cin>>n;
	aList.resize(n);
	gcdFor.resize(n, 0);
	gcdBack.resize(n, 0);
	cand.resize(n, 0);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	gcdFor[0]= aList[0];
	gcdBack[n-1]= aList[n-1];

	for(int i=1; i<n; i++){
		gcdFor[i]= gcd(gcdFor[i-1], aList[i]);
		gcdBack[n-i-1]= gcd(gcdBack[n-i], aList[n-i-1]); 
	}

	cand[0]= gcdBack[1];
	cand[n-1]= gcdFor[n-2];

	for(int i=1; i< n-1; i++)
		cand[i]= gcd(gcdFor[i-1], gcdBack[i+1]);

	int ans=1;

	for(int i=0; i<n; i++)
		ans= std::max(ans, cand[i]);

	std::cout<<ans<<std::endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N;
    cin >> N;
    vector<P> table;
    for(int i = 0; i < N; ++i){
        int A, B;
        cin >> A >> B;
        table.emplace_back(A, B);
    }
    sort(table.begin(), table.end(), [](const P& p1, const P& p2){
        return p1.first - p2.second > p2.first - p1.second;
    });
    ll ans = 0;
    for(int i = 0; i < N; ++i){
        if(i % 2)   ans -= table[i].second;
        else    ans += table[i].first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    a = list(int(_) for _ in input().split())
    sum_p = 0
    sum_q = sum(a)
    r = INF
    for i in range(N-1):
        sum_p += a[i]
        sum_q -= a[i]
        r = min(r,abs(sum_p-sum_q))
    print(r)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 24404
<?php
$input = array_map('intval', explode(' ', fgets(STDIN)));
$a = $input[0];
$b = $input[1];
$c = $input[2];
$d = $input[3];

if (($a*$b)>=($c*$d)) {
    print $a*$b;
} else {
    print $c*$d;
}

Measured memory_bytes: 4728
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9+7;
ll N,K;
ll ans;
int main() {
    cin>>N>>K;
    if(K==0) ans=N*N;
    else {
        REP(j, K + 1, N + 1) {
            ans += ((N - K) / j) * (j - K);
            ans += min((j - K), (N - K) % j + 1);
        }
    }
    p(ans);
    return 0;
}

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

//FILE *fin = freopen("c.in", "r", stdin);

int n, m, a[maxN];

int frq[maxN], cov[maxN];

int ans;

void precomp()
{
    for (int i = 1; i <= n; ++ i)
        if (frq[i])
        {
            cov[max(1, i - frq[i] + 1)] += 1;
            cov[i + 1] -= 1;
        }
    for (int i = 1; i <= n; ++ i)
    {
        cov[i] += cov[i - 1];
        if (!cov[i])
            ++ ans;
    }
}

void updVector(int x, int y)
{
    -- frq[a[x]];
    ++ frq[y];
    a[x] = y;
}
int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++ i)
    {
        scanf("%d", &a[i]);
        ++ frq[a[i]];
    }
    precomp();
    for (int i = 1; i <= m; ++ i)
    {
        int x, y;
        scanf("%d %d", &x, &y); ///  x-th ball y value
        /// uncover a[x] - frq[a[x]] + 1
        /// cover y - frq[y]
        if (a[x] != y)
        {
            if (a[x] - frq[a[x]] + 1 > 0)
                {
                    ans += (cov[a[x] - frq[a[x]] + 1] == 1);
                    -- cov[a[x] - frq[a[x]] + 1];
                }

            if (y - frq[y] > 0)
                {
                    ans -= (!cov[y - frq[y]]);
                    ++ cov[y - frq[y]];
                }

            updVector(x, y);
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3712
import java.util.*
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ab =Array(n-1){ readLine()!!.split(" ").map { it->it.toInt()-1 }}
    val c =readLine()!!.split(" ").map { it.toInt() }.sortedBy { -it }.toIntArray()
    val es = Array(n){ArrayList<Int>()}
    ab.forEach {
        es[it[0]].add(it[1])
        es[it[1]].add(it[0])
    }
    val visit = BooleanArray(n){false}
    println(c.sum()-c.max()!!)
    val result = IntArray(n){0}
    val queue = ArrayDeque<Int>()
    visit[0]=true
    queue.add(0)
    var cursor = 0
    while (!queue.isEmpty()){
        val node = queue.pop()
        es[node].forEach{
            if(!visit[it]){
                visit[it]=true
                queue.add(it)
            }
        }
        result[node]=c[cursor]
        cursor+=1
    }
    println(result.joinToString(" "))
}


Measured memory_bytes: 48128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define pb push_back
typedef long long ll;
typedef pair<ll,ll>P;
#define fi first
#define sc second
#define mp make_pair
int x[11][11],n,m,k,s,dep;
bool ok = 0;
void dfs(){
	int rui[11][11]={},rui2[11][11]={}; int pre = 0;
	for(int i=1;i<=n;i++){pre = 0; for(int j=1;j<=m;j++){
		rui[i][j] = rui[i][j-1]+x[i][j];
		if(rui[i][j]-pre > s){
			if(dep == k) return;
			for(int k=1;k<=j;k++){
				x[i][k]*=-1; dep++; dfs(); dep--; x[i][k]*=-1;
				
			}return;
		}
		pre = min(pre,rui[i][j]);
	}}
	for(int j=1;j<=m;j++){pre=0; for(int i=1;i<=n;i++){
		rui2[i][j] = rui2[i-1][j]+x[i][j];
		if(rui2[i][j]-pre > s){
			if(dep == k) return;
			for(int k=1;k<=i;k++){
				x[k][j]*=-1; dep++; dfs(); dep--; x[k][j]*=-1;
				
			}return;
		}
		pre = min(pre,rui2[i][j]);
	}}
	//repn(i,n){repn(j,m)cout<<x[i][j]<<" ";cout<<endl;}
	ok=1; return;
}
int main(){
	cin>>n>>m>>k>>s;
	repn(i,n)repn(j,m)cin>>x[i][j];
	dfs();
	puts(ok?"Yes":"No");
}



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

int main() {
    int n,T,minT=1001;
    int c[1001], t[1001],count=0;
    cin >> n >> T;

    vector< pair<int,int> > route(n);

    for(int i=0;i<n;i++){
        cin >> c[i] >> t[i];
        if(t[i]<=T){
            if(minT>t[i]) minT=t[i];
            route[count] = make_pair(c[i],t[i]);
            count++;
        }
    }
    if(minT > T){
        cout << "TLE" << endl;
        return 0;
    }

    sort(route.begin(),route.begin()+count);
    cout << route[0].first << endl;
  return 0;
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")"; return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

void solve() {
    int n, m;
    set<int> S;
    cin >> m >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        S.insert(a);
    }
    int min_delta = 1e9;
    int sol;
    for (int i = -10; i <= 110; i++) {
        if (S.count(i) == 0) {
            int delta = abs(i - m);
            if (min_delta > delta) {
                min_delta = delta;
                sol = i;
            }
        }
    }
    cout << sol << endl;
}

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


Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int n;
  cin >> n;
  
  unsigned int a0,b0;
  cin >> a0 >> b0;
  unsigned int max_b = b0 , max_a = a0 , min_b = b0, min_a =a0;
  
  rep(i,1,n){
    unsigned int a,b;
    cin >> a >> b;
    if(b > max_b){
      max_b = b;
      max_a = a;
    }

    if(b < min_b){
      min_b = b;
      min_a = a;
    }
  }
  
  /*
  cout << "min_b" << min_b << endl;
  cout << "min_a" << min_a << endl;
  cout << "max_b" << max_b << endl;
  cout << "max_a" << max_a << endl;
  */

  unsigned int sum = 0;

  sum += min_a - max_a;

  sum += max_a - 1;
  
  for(long i = min_b ; i >= 0 ; i--){
    sum++;
    //cout << i << endl;
  }

  
  cout << sum << endl;
  ret 0;
}

Measured memory_bytes: 256
module ABC081A
	sub Main(ByVal args() as String)
		dim s as string
		dim c,i as integer
		s=Console.ReadLine()
		c=0
		for i=0 to 2
			if s(i)="1"c then 'thenはなくても良い
				c=c+1
			end if
		next
		Console.WriteLine(c)
	end sub
end module


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

typedef struct Goods_ {
    u_int value;
    u_int weight;
} Goods;

void bubble_sort(Goods *goods, u_int n)
{
    for (u_int i = 0; i < n; i++)
        for (u_int j = i+1; i < n; i++)
            if (goods[i].value < goods[j].value)
                swap(goods[i], goods[j]);
}

int main(void)
{
    u_int n, total;
    cin >> n >> total;
    Goods goods[n];
    for (u_int i = 0; i < n; i++) {
        u_int v, w;
        cin >> v >> w;
        goods[i] = Goods{v, w};
    }

    bubble_sort(goods, n);

    u_int values[total+1];
    for (u_int i = 0; i <= total; i++)
        values[i] = 0;
    
    for (u_int i = 0; i < n; i++) {
        Goods g = goods[i];
        for (u_int w = total; w >= g.weight; w--) {
            auto temp = g.value + values[w - g.weight];
            if (!values[w] || values[w] < temp)
                values[w] = temp;
        }
    }

    cout << values[total] << endl;
    
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define Gput(a,b) G[a].push_back(b)
const ll dx[4]={1,0,-1,0};
const ll dy[4]={0,1,0,-1};

int main() {
  cout << fixed << setprecision(16);
  ll h,w;
  cin>>h>>w;
  vector<string> field(h);
  loop(i,h){
    cin>>field[i];
  }
  bool check=true;
  loop(i,h){
    loop(j,w){
      
    if(field[i][j]=='#'){
      check=false;
      loop(k,4){
        ll zi=i+dx[k];
        ll zj=j+dy[k];
        if(zi<0||zi>=h||zj<0||zj>=w)continue;
        if(field[zi][zj]=='#')check=true;
      }
    }
   if(!(check)) goto end;
  }
 }
  end:
  if(check)putout("Yes");
  else putout("No");
  
}

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

int main() {
  int n, m; cin >> n >> m;
  vector<int> k(m), p(m);
  vector<vector<int>> s(m, vector<int>(n, 0));
  rep(i, m) {
    cin >> k[i];
    rep(j, k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, m) {
    cin >> p[i];
  }
  int ans = 0;
  //全てのスイッチのon offパターンについて
  for (int bit = 0; bit < (1<<n); bit++) {
    bool flag = true;
    //全ての電球について
    rep(i, m) {
      int on = 0;
      //その電球につながっているスイッチの状態について
      //ONのスイッチの個数をカウント
      rep(j, k[i]) {
        if (bit & (1<<s[i][j])) on++;
      }
      if (on % 2 != p[i]) flag = false;
    }
    if (flag) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
unsigned long long n,m,i;
int main()
{
    scanf("%llu %llu",&n,&m);
    if(n<=m/2)
    {
        m-=n*2;
        i+=n;
    }
    else
    {
        i+=m/2;
        m=0;
    }
    i+=m/4;
    printf("%llu",i);
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){

	int i,j,tmp;
	int idx[5];

	while(scanf("%d %d %d %d %d",&idx[0],&idx[1],&idx[2],&idx[3],&idx[4])!=EOF){
		tmp=0;
		for(i=5;i!=0;i--){
			for(j=1;j<i;j++){
				if(idx[j-1]>idx[j]){
					tmp=idx[j];
					idx[j]=idx[j-1];
					idx[j-1]=tmp;
				}
			}
		}
		printf("%d %d %d %d %d\n",idx[4],idx[3],idx[2],idx[1],idx[0]);


	}
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int inf = 1e9;
 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W; cin >> H >> W;
  // ワーシャルフロイド
  int n,m;// 頂点、辺
  int dist[10][10];
  FOR(i,0,10) {
    FOR(j,0,10) {
      int cost; cin >> cost;
      dist[i][j] = cost;
    }
  }
 
  FOR(k,0,10) FOR(i,0,10) FOR(j,0,10) {
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
  }
  int ans = 0;
  FOR(h,0,H) {
    FOR(w,0,W) {
      int a; cin >> a;
      if(a == -1 || a == 1) continue;
      ans += dist[a][1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
t=list(map(int,input().split()))
m=int(input())
ans=[]
for i in range(m):
    p,x=map(int,input().split())
    tot=sum(t)
    tot=tot-t[p-1]+x
    ans.append(tot)
for i in ans:
    print(i)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	// int t;
	// cin>>t;
	// while(t--){
	// 	int a,b;
	// 	cin>>a>>b;
	// 	cout<<a*b<<endl;
	// }
	int a,b;
		cin>>a>>b;
		cout<<a*b<<endl;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main(){
  prep();
  int n;
  cin >> n;
  int arr[n*3];
  for (int i=0; i<3*n; i++){
      cin >> arr[i];
  }
  long long sum = 0;
  multiset<int> s;
  for (int i=0; i<n; i++){
      sum += arr[i];
      s.insert(arr[i]);
  }
  long long sumlst1[n+1];
  long long sumlst2[n+1];
  sumlst1[0] = sum;
  for (int i=n; i<2*n; i++){
      int cur = arr[i];
      //cout << *(s.begin()) << " " << arr[i] << endl;
      if (arr[i] > *(s.begin())){
          
          sum -= *s.begin();
          sum += arr[i];
          s.erase(s.begin());
          s.insert(arr[i]);
          
      } 
      sumlst1[i-n+1] = sum;
  }
  
  sum = 0;
  s.clear();
  for (int i=2*n; i<3*n; i++){
      sum += arr[i];
      s.insert(arr[i]);
  }

  sumlst2[n] = sum;
  for (int i=2*n-1; i>=n; i--){
      int cur = arr[i];
      if (arr[i] < *(--s.end())){
          sum -= *(--s.end());
          sum += arr[i];
          s.erase(--s.end());
          s.insert(arr[i]);
          
      }
      sumlst2[i-n] = sum;
  }
  long long maxx = -1000000000000000000LL;
  for (int i=0; i<n+1; i++){
      //cout << sumlst1[i] << " " << sumlst2[i] << endl;
      maxx = max(maxx, sumlst1[i]-sumlst2[i]);
  }
  cout << maxx;
  return 0; 
}

Measured memory_bytes: 7680
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

string st;
const int N = 15;
int n;

vector <vector<int>> arr(N + 1, vector<int>(N + 1, -1));
int ans;
void validate() {
	int c = 0;
	for (int i = 0; i < st.length(); i++) {
		if (st[i] == '1') {
			for(int j= 0 ; j < N;j++)
				if (!(arr[i + 1][j + 1] == -1 || arr[i + 1][j + 1] == st[j] - '0')) {
					return;
				}
			c++;
		}
	} 
	ans = max(ans, c);
}
void combinations() {
	if (st.length() == n)
	{
		validate();
		return;
	}

	st += '0';
	combinations();
	st.pop_back();

	st += '1';
	combinations();
	st.pop_back();


}
int main()
{
	int ntestimony = 0;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> ntestimony;
		for (int j = 0; j < ntestimony; j++) {
			int ith, testimony;
			cin >> ith;
			cin >> testimony;
			arr[i + 1][ith] = testimony;
		}
	}

	combinations();
	cout << ans;
}
 

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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().ToArray();

        var sum = input.Select(x => int.Parse(x.ToString())).Sum();

        var ans = Math.IEEERemainder(sum, 9) == 0 ? "Yes" : "No";

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 34212
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  int n,p;
  while(cin>>p>>n,n|p){
    PI xy=mp(p,1),uv=mp(0,1);
    for(int i=1;i<=n;i++){
      for(int j=max(1,int(i/sqrt(p)-1));j<=min(n,int(i/sqrt(p)+2));j++){
	if(__gcd(i,j)>1)continue;
	if(i*i<p*j*j && j*uv.F<uv.S*i)uv=mp(i,j);
	if(i*i>p*j*j && xy.F*j>i*xy.S)xy=mp(i,j);
      }
    }
    cout<<xy.F<<'/'<<xy.S<<' '<<uv.F<<'/'<<uv.S<<endl;
  }
}
	   
	   

Measured memory_bytes: 864
from collections import Counter
N = int(input())  # 長さN
A = list(map(int, input().split()))  # 整数列A

S = [0]
for i in range(len(A)):
    S.append(S[-1] + A[i])

c = Counter(S)

ans = 0
for v in c.values():
    ans += v*(v-1)//2

print(ans)


Measured memory_bytes: 41708
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

const int maxn = 1000 * 1000 + 218;
const ll mod = 998244353;

ll mu[maxn], a[maxn], b[maxn], c[maxn];

ll GetPower(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      result *= x;
      result %= mod;
      n--;
    } else {
      x *= x;
      x %= mod;
      n /= 2;
    }
  }
  return result;
}

int main()
{
  int n;
  cin >> n;
  for (int i = 0 ; i < n; ++i) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (int i = 0; i < maxn; ++i) {
    b[i] = a[i] * i % mod;
    c[i] = a[i] * ll(i) * ll(i) % mod;
  }
  mu[1] = 1;
  for (int d = 1; d < maxn; ++d) {
    if (d != 1) mu[d] *= -1;
    for (int x = 2 * d; x < maxn; x += d) {
      mu[x] += mu[d];
    }
  }

  ll result = 0;
  for (int g = 1; g < maxn; ++g) {
    ll revg = GetPower(g, mod - 2);
    for (int d = g; d < maxn; d += g) {
      if (mu[d / g] == 0) continue;
      ll sum = 0;
      ll sum2 = 0;
      for (ll x = d; x < maxn; x += d) {
        sum += b[x];
        sum2 += c[x];
      }
      sum %= mod;
      sum2 %= mod;
      ll cur = (sum * sum - sum2) % mod;
      cur *= mu[d / g];
      cur *= revg;
      cur %= mod;
      result += cur;
    }
  }
  result %= mod;
  result *= GetPower(2, mod - 2);
  result = (result % mod + mod) % mod;
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 31488
package main

import "fmt"

var n, Y int

func main() {
	fmt.Scan(&n, &Y)
	for x := 0; x <= n; x++ {
		for y := 0; y <= n-x; y++ {
			z := n - x - y
			g := 10000*x + 5000*y + 1000*z
			if g == Y {
				fmt.Printf("%d %d %d", x, y, z)
				return
			}
		}
	}
	fmt.Printf("%d %d %d",-1, -1, -1)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int X, Y; cin >> X >> Y;

	if (abs(X - Y) < 2) cout << "Brown" << endl;
	else cout << "Alice" << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	string s; cin >> s;
	int ans = 1;
	rep(i, 1, N) {
		if (s[i - 1] == 'x'&&s[i] == 'x') {
			break;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3352
import java.util.Scanner;

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

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

        if (B % A == 0) {
            System.out.println(A + B);
        } else {
            System.out.println(B - A);
        }
    }
}


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

int main(void){
    string s;
    while(s[0]!='0'){
    cin >> s;
    if(s == "0"){
        break;
    }
    int o = 0;
    for(int i = 0; i < s.size();i++){
     o += s[i] - '0' ;
    }
    cout << o << endl;
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int  main (){
string a,b;
 cin>>a>>b;
 if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
   cout<<"YES"<<"\n";
 }else{
   cout<<"NO"<<"\n";
 }
 return(0);
}


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

int N, A, B, C;
int l[8];

int dfs (int cur, int a, int b, int c) {
  
  
  if (cur == N) {
    if (min(a, min(b, c)) > 0) {
      return abs(a - A) + abs (b - B) + abs(c - C) - 30;
    } else {
      return 1e9;
    }
  }
  
  int ret0 = dfs (cur + 1, a, b, c);
  int ret1 = dfs (cur + 1, a + l[cur], b, c) + 10;
  int ret2 = dfs (cur + 1, a, b + l[cur], c) + 10;
  int ret3 = dfs (cur + 1, a, b, c + l[cur]) + 10;
  
  return min(ret0, min(ret1, min(ret2, ret3)));
}
 
int main() {

  cin >> N >> A >> B >> C;
  for (int i = 0; i < N; i++) {
    cin >> l[i];
  }
  cout << dfs (0, 0, 0, 0) << endl;
  
}


Measured memory_bytes: 256
program atcoder
  implicit none
  integer A, B
  read *, A, B    ! 変数mに、標準入力から数字を読み込み代入する

               ! このあたりに、解答を導く計算を書く

  print '(i0)',6-A-B    !  ","のあとに解答となる変数を書く
end program atcoder


Measured memory_bytes: 640
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	
	if(k % 2){
		cout << (a-b) * (-1) << endl;
	}
	else{
		cout << (a-b)  << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256