akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T;
  cin >> S >> T;
  vector<vector<int>> pos(26);
  for (int i = 0; i < (int)S.size(); i++) {
    pos[S[i] - 'a'].emplace_back(i);
  }
  int res = 0, p = -1;
  for (int i = 0; i < (int)T.size(); i++) {
    int c = T[i] - 'a';
    if (pos[c].empty()) {
      cout << -1 << '\n';
      return 0;
    }
    int idx = upper_bound(pos[c].begin(), pos[c].end(), p) - pos[c].begin();
    if (idx < (int)pos[c].size()) {
      p = pos[c][idx];
    } else {
      res++;
      p = pos[c][0];
    }
  }
  cout << 1LL * res * (int)S.size() + p + 1 << '\n';
  return 0;
}


Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N, K; cin >> N >> K;

    ll ans = 1LL;
    for(int i=0; i<N; i++){
        ans = min(2*ans, ans+K);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define dup(x, y) (((x) + (y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template <class T> inline void chmax(T &a, T b) {
    if(a < b) {
        a = b;
    }
}
template <class T> inline void chmin(T &a, T b) {
    if(a > b) {
        a = b;
    }
}
template <class T> inline T gcd(T x, T y) {
    if(y == 0) {
        return x;
    } else if(x == 0) {
        return y;
    }
    return gcd(y, x % y);
}
template <class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template <class T> inline void print_vector(vector<T> vec) {
    for(int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    cout << endl;
}
const LL MOD = 1e9 + 7;
const LL LLINF = 1LL << 60;
const int INF = 1 << 30;

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

    vector<vector<char>> grid(H + 2, vector<char>(W + 2));
    for(int y = 1; y <= H; y++) {
        string tmp;
        cin >> tmp;
        for(int x = 1; x <= W; x++) {
            grid[y][x] = tmp[x-1];
        }
    }

    for(int y = 1; y <= H; y++) {
        for(int x = 1; x <= W; x++) {
            if(grid[y][x] == '#'){
                if(grid[y-1][x] == '#' or grid[y][x-1] == '#' or grid[y+1][x] == '#' or grid[y][x+1] == '#'){
                    continue;
                }else{
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, j, k) for(int i = j; i <= k; ++i)
#define dep(i, j, k) for(int i = j; i >= k; --i)
#define inv(x) (ksm(x, P - 2))

using namespace std;

const int maxn = 3e3 + 5;
const int P = 1e9 + 7;

int n, m, f[maxn][maxn][2], ans;

inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar(); }
	while(isdigit(ch))  { u = u * 10 + ch - 48; ch = getchar(); } return u * f;
}

inline int pls(int x, int y) { x += y; return x >= P ? x - P : x; }
inline int dec(int x, int y) { x -= y; return x < 0 ? x + P : x; }
inline int ksm(int x, int k, int rnt = 1) {
	for(int i = k; i; i >>= 1, x = 1ll * x * x % P) if(i & 1) rnt = 1ll * rnt * x % P;
	return rnt;
}

const int inv2 = inv(2);

int main() {
	n = read(); m = read();
	rep(i, 0, n) f[0][i][i == 0] = 1;
	rep(i, 0, m - 1) rep(j, 0, n) rep(k, 0, 1) {
		if(j) f[i + 1][j - 1][k | (j == 1)] = pls(f[i + 1][j - 1][k | (j == 1)], f[i][j][k]);
		if(j) f[i + 1][j][k | (j == 1)] = pls(f[i + 1][j][k | (j == 1)], f[i][j][k]);
		if(n - j) f[i + 1][j + 1][k] = pls(f[i + 1][j + 1][k], f[i][j][k]);
		if(n - j) f[i + 1][j][k] = pls(f[i + 1][j][k], f[i][j][k]);
	}
	rep(i, 0, n) ans = pls(ans, f[m][i][1]);
	cout << ans << endl;
	return 0;
}
/*
*/

Measured memory_bytes: 70656
#include <cstdio>
#include <algorithm>

const int N = 15;
const int INF = 1 << 25;
int dist[N][N];
void chmin(int &a, int b) {
    a = std::min(a, b);
}

int main() {
    while(1) {
        int M; scanf("%d", &M);
        if(M == 0) break;

        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if(i != j) dist[i][j] = INF;
            }
        }

        int T = 0;
        for(int i=0; i<M; i++) {
            int a, b, c; scanf("%d%d%d", &a, &b, &c);
            chmin(dist[a][b], c);
            chmin(dist[b][a], c);
            T = std::max({T, a+1, b+1});
        }

        for(int k=0; k<T; k++) {
            for(int i=0; i<T; i++) {
                for(int j=0; j<T; j++) {
                    chmin(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }

        int ans = INF, idx = 0;
        for(int i=0; i<T; i++) {
            int sum = 0;
            for(int k=0; k<T; k++) {
                sum += dist[i][k];
            }
            if(ans > sum) {
                ans = sum;
                idx = i;
            }
        }
        printf("%d %d\n", idx, ans);
    }
    return 0;
}


Measured memory_bytes: 2760
m,p,r,h,i,a,s;main(n){for(;scanf("%d%d",&n,&m)*n;i=h=!printf("%d\n",h?n:r))for(p=1e7;i++<n;s<=p?h=s==p,p=s,r=i:0)scanf("%d",&a),s=m/a*a*1e3+a;}

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

int n;
double x[1111],y[1111],dp[1111][1111];

double calc(int a,int b){
  return sqrt(pow((x[a]-x[b]),2)+pow((y[a]-y[b]),2));
}

double dfs(int l,int r,int i){
  if(i==n)return max(calc(l,n-1),calc(r,n-1));
  if(dp[l][r])return dp[l][r];
  return dp[l][r]=min(dfs(i,r,i+1)+calc(l,i) , dfs(l,i,i+1)+calc(r,i));
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>x[i]>>y[i];
  printf("%.9f\n",dfs(0,0,1));
}


Measured memory_bytes: 11948
N=gets.to_i
ab=Hash.new(0)
N.times do
  a,b = gets.split.map(&:to_i)
  ab[b] += a
end
deadlines = ab.keys.sort.reverse

t=10**9+1
deadlines.each do |d|
  if t<d
    t = t - ab[d]
  else
    t = d - ab[d]
  end
end

if t<0
  puts "No"
else
  puts "Yes"
end

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

int main()
{
    ios::sync_with_stdio(false);
    int a,b;
    int t[4];
    memset(t, 0, sizeof(t));

    for ( ; cin >> a >> b; )
    {
        ++ t[a - 1];
        ++ t[b - 1];
    }

    if ( ( t[0] == 1 && t[1] == 1 && t[2] == 2 && t[3] == 2 ) || ( t[0] == 1 && t[1] == 2 && t[2] == 1 && t[3] == 2 ) ||
         ( t[0] == 1 && t[1] == 2 && t[2] == 2 && t[3] == 1 ) || ( t[0] == 2 && t[1] == 1 && t[2] == 1 && t[3] == 2 ) || 
         ( t[0] == 2 && t[1] == 1 && t[2] == 2 && t[3] == 1 ) || ( t[0] == 2 && t[1] == 2 && t[2] == 1 && t[3] == 1 ))
        cout << "YES\n";
    else
        cout << "NO\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;

int a, b, c, d, e, f;
float max_n = -1, tmp_n;
int max_w = 0, max_s = 0;

int main(void) {
  scanf("%d %d %d %d %d %d",&a, &b, &c, &d, &e, &f);
  for(int i=0;;i++){
    if(i*a*100>f) break;
    for(int j=0;;j++){
      if(i==0 && j==0)continue;
      if((i*a + j*b)*100>f) break;
      for(int k=0;;k++){
        if((i*a + j*b)*100+k*c>f) break;
        for(int l=0;;l++){
          if((i*a + j*b)*100+k*c+l*d>f) break;
          tmp_n = (k*c + l*d)/1.0/(i*a + j*b);
          if(tmp_n > e) break;
          if(tmp_n > max_n){
            max_n = tmp_n;
            max_s = k*c + l*d;
            max_w = (i*a + j*b)*100 + max_s;
          }
	}
      }
    }
  }
  printf("%d %d\n",max_w, max_s);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;

int main(void){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		bool f1 = 0;
		bool f2 = 0;
		bool ok = 0;
		int ans = 0;
		for(int i=0; i<n; i++){
			string t;
			cin >> t;

			if(t[0] == 'l') f1 = f1 - 1;
			if(t[0] == 'r') f2 = f2 - 1;
			if(f1 == 1 && f2 == 1 && ok == 0){ ans++; ok = 1;}
			if(f1 == 0 && f2 == 0 && ok == 1){ ans++; ok = 0;}
		}

		cout << ans << endl;

	}


	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
using namespace std;
int abs(int a) {
  if (a < 0)
    return -a;
  return a;
}
int max(int a, int b) {
  if (a > b)
    return a;
  return b;
}
int main() {
  int N;
  cin >> N;
  int x[N], y[N], h[N];
  int i;
  int not_zero_i;
  for (i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] != 0)
      not_zero_i = i;
  }
  for (int C_x = 0; C_x <= 100; C_x++) {
    for (int C_y = 0; C_y <= 100; C_y++) {
      int C_h =
          h[not_zero_i] + abs(C_x - x[not_zero_i]) + abs(C_y - y[not_zero_i]);
      for (i = 0; i < N; i++) {
        if (h[i] != max(0, C_h - abs(C_x - x[i]) - abs(C_y - y[i])))
          break;
      }
      if (i == N) {
        cout << C_x << " " << C_y << " " << C_h << endl;
      }
    }
  }
}

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

int main() {
    long long n,x;
    cin >>n>>x;

    vector<long long>a(n);
    rep(i,0,n){
        cin>>a[i];
    }
    
    long long cnt=0;
    
    for(int i=1;i<n;i++){
        int sum=a[i]+a[i-1];
        if(sum>x){
            cnt+=(sum-x);
            a[i]-=(sum-x);
            if(a[i]<0){
                a[i-1]+=a[i];
                a[i]=0;
            }
        }
    }

    cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#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

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



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

    x-=a;
    P(x%b);
	
	return  0;
}

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

int main()
{
    int x;
    cin >> x;
    if (x == 0)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

  ll a, b; cin >> a >> b;
  ll ans = -1;
  if(a%b != 0) ans = a;

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,D;
	int x[23][23];
	scan(N>>D);
	rep(i,N){
		rep(j,D){
			scan(x[i][j]);
		}
	}
	int ans=0;
	rep(i,N){
		for(int j=i+1;j<N;j++){
			double wa=0;
			rep(k,D){
				wa+=pow(x[i][k]-x[j][k],2);
			}
			if(fabs(sqrt(wa)-(int)(sqrt(wa)+eps))<5*eps) ans++;
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ALDS1_3_B_Queue
//
//  Created by ptyuan on 2018/10/19.
//  Copyright © 2018 YY. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;

template <typename T>
struct Queue {
    T array[200001];
    
    int tail = 0;
    int head = 0;
    
    void enqueue(T t) {
        array[tail++] = t;
    }
    
    T dequeue() {
        return array[head++];
    }
    
    bool isEmpty() {
        return tail == head;
    }
};

struct Task {
    char name[10];
    int time = 0;
};

int main(int argc, const char * argv[]) {
    int n = 0;
    int q = 0;
    cin >> n >> q;
    
    Queue <Task> queue;
    int useTime = 0;
    
    while (n--) {
        Task task;
        cin >> task.name >> task.time;
        queue.enqueue(task);
    }
    
    while (!queue.isEmpty()) {
        Task task = queue.dequeue();
        int min = q > task.time ? task.time : q;
        useTime += min;
        task.time -= min;
        if (task.time > 0) {
            queue.enqueue(task);
        } else {
            cout << task.name << " " << useTime << "\n";
        }
    }
    
    return 0;
}



Measured memory_bytes: 6260
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//
        vector<string> S(3);
        for (int i = 0; i < 3; i++)
        {
                cin >> S[i];
        }

        cout << S[0][0] << S[1][1] << S[2][2] << endl;

        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int ans = 0;
		for (int i = 1; i <= n; i++) {
			String s = String.valueOf(i);
			if (s.length() % 2 == 1) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


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

long ship[100][100];

int main(){
  int k,r,i,a,b,n,j,ii;
  long p;
  while(1){
    scanf("%d %d",&n,&k);
    if(n==0) break;
    memset(ship,8,sizeof(ship));
    for(i=0;i<n;i++){
    	ship[i][i]=0;
    }
    for(i=0;i<k;i++){
      scanf("%d",&r);
      if(r==0){
        scanf("%d %d",&a,&b);
        printf("%ld\n",(ship[a-1][b-1]>100000001)?-1:ship[a-1][b-1]);
      }else{
        scanf("%d %d %ld",&a,&b,&p);
        for(j=0;j<n;j++){
        	for(ii=0;ii<n;ii++){
        		if(ship[j][b-1]+p+ship[a-1][ii]<ship[j][ii]){
        			ship[j][ii]=ship[j][b-1]+p+ship[a-1][ii];
        			ship[ii][j]=ship[j][b-1]+p+ship[a-1][ii];
        		}
        		if(ship[j][a-1]+p+ship[b-1][ii]<ship[j][ii]){
        			ship[j][ii]=ship[j][a-1]+p+ship[b-1][ii];
        			ship[ii][j]=ship[j][a-1]+p+ship[b-1][ii];
        		}
        	}
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 684
/*给一棵树，x和y博弈，首先x在u点，y在v点，游戏结束条件是x和y重合，
x先动，x希望游戏更晚结束dist(p,u)要大，y希望游戏更早结束，求y在游戏结束前走的步数

设游戏在p点结束，那么dist(p,u)≤dist(p,v)显然成立，当

由于x先动要求答案尽量大，所以取满足条件的max(dist(p,v))即可。
*/
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
vector<int>g[100000];
int n, u, v, a, b, ans;
int du[100000], dv[100000];

//Graph ? std::vector<int> v[100]; 100 verices
void dfs(int x, int y, int z) {
	dv[x] = z;
	for (int i = 0; i < g[x].size(); i++) {
		if (g[x][i] != y)dfs(g[x][i], x, z + 1);
	}
}

int main() {
  scanf("%d%d%d", &n, &u, &v);
	u--; v--;
	for (int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a, &b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

dfs(u, -1, 0);
for (int i = 0; i < n; i++)du[i] = dv[i];
dfs(v, -1, 0);
for (int i = 0; i < n; i++) {
  if (dv[i] >= du[i]) {//早走1步 
    if (dv[i] > ans)ans = dv[i];
  }
}
printf("%d\n", ans - 1);

  return 0;
}

Measured memory_bytes: 11648
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

K,N=input_int_list()
A_list=sorted(input_int_list())
A_list=A_list+[A_list[0]+K]
max_dis=0
for i in range(N):
    max_dis=max(max_dis,A_list[i+1]-A_list[i])
print(K-max_dis)

Measured memory_bytes: 24948
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

struct N {
  int now, mode;
};
bool operator<(const N &l, const N &r) { return l.now < r.now; }

int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<int>> p(n);
  vector<set<int>> s(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  set<int> o, e;
  multiset<N> q;
  vector<int> c(n);
  q.insert(N{0, 1});
  while (q.size() > 0) {
    N now = *q.begin();
    q.erase(q.begin());
    if (c[now.now]) {
      if (c[now.now] != now.mode) {
        cout << n * (n - 1) / 2 - m << endl;
        return 0;
      }
      continue;
    }
    c[now.now] = now.mode;
    if (now.mode == 1)
      o.insert(now.now);
    else
      e.insert(now.now);
    for (int i = 0; i < p[now.now].size(); i++) {
      q.insert(N{p[now.now][i], 2 - (now.mode - 1)});
    }
  }
  long long os = o.size(), es = e.size();
  cout << os * es - m << endl;
  return 0;
}


Measured memory_bytes: 15488
#include <iostream>
using namespace std;
int main(){
    int w,h,x,y,r;
    bool flag=true;
    cin>>w>>h>>x>>y>>r;
    if(x+r>w||x-r<0||y+r>h||y-r<0){
        flag=false;
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3092
import collections

N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

cnt = collections.Counter()
for d in s:
    cnt[d] += 1
for d in t:
    cnt[d] += -1

print(max(max(cnt.values()), 0))


Measured memory_bytes: 3316
S = input()
cnt = 0

if S[0] == 'R':
    cnt = 1
    if S[1] == 'R':
        cnt = 2    
        if S[2] == 'R':
            cnt = 3
else:
    if S[1] == 'R':
        cnt = 1
        if S[2] == 'R':
            cnt = 2
    elif S[2] == 'R':
        cnt = 1

print(cnt)

Measured memory_bytes: 9052
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var (
	SENTINEL = 2000000000
	cnt      = 0
)

func main() {
	fmt.Println(answer(os.Stdin))
}

func answer(r io.Reader) string {
	n := 0

	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())
	A := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
	}

	mergeSort(A, n, 0, n)

	result := strings.TrimRight(fmt.Sprintf("%+v", A)[1:], "]") + "\n"
	return result + strconv.Itoa(cnt)
}

func merge(A []int, n, left, mid, right int) {
	n1 := mid - left
	n2 := right - mid
	L, R := make([]int, n1+1), make([]int, n2+1)
	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}
	L[n1], R[n2] = SENTINEL, SENTINEL

	i, j := 0, 0
	for k := left; k < right; k++ {
		cnt++
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
			continue
		}
		A[k] = R[j]
		j++
	}
}

func mergeSort(A []int, n, left, right int) {
	if left+1 < right {
		mid := (left + right) / 2
		mergeSort(A, n, left, mid)
		mergeSort(A, n, mid, right)
		merge(A, n, left, mid, right)
	}
}



Measured memory_bytes: 45008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
double dist(double x,double y,double a,double b){
    return sqrt((x-a)*(x-a)+(y-b)*(y-b));
}
void Main(){
    double x1,x2,x3,y1,y2,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    vector<double> a(3);
    a[0]=dist(x1,y1,x2,y2);
    a[1]=dist(x2,y2,x3,y3);
    a[2]=dist(x3,y3,x1,y1);
    sort(ALL(a));
    double s,S,h,r;
    s=(a[0]+a[1]+a[2])/2;
    S=sqrt(s*(s-a[0])*(s-a[1])*(s-a[2]));
    h=S*2/a[2];
    r=S/(s+h);
    cout<<fixed<<setprecision(12)<<r<<endl;
}
int main(){
    Main();
    return 0;
}

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

int main() {
    int n,m; cin >> n >> m;
    vector<int> l(n);
    for(int i = 0; i < m; i ++) {
        int a,b; cin >> a >> b;
        l.at(a-1) ++; l.at(b-1) ++;
    }
    for(int i = 0; i < n; i ++) cout << l.at(i) << endl;
}

Measured memory_bytes: 256
lines = STDIN.readlines.map(&:chomp)
n = lines.shift.to_i

t = {}
c = 0
lines.each do |s|
  if t[s.each_char.sort.join].nil?
    t[s.each_char.sort.join] = 1
  else
    c += t[s.each_char.sort.join]
    t[s.each_char.sort.join] += 1
  end
end

puts c

Measured memory_bytes: 25580
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
   llong k,a,b,ans=0,trade,amari;
   cin >> k >> a >> b;
   if(b-a>2){
       trade = (k-a+1)/2;
       if((k-a+1)%2) amari=1;
       else amari=0;
       ans = trade*(b-a)+a+amari;
   }else{
       ans = k+1;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

int main()
{
	int N;
	int C[510]={};
	int S[510]={};
	int F[510]={};
	int ans=0;
	
	cin >> N;
	for(int i=0;i<N-1;i++)
		cin >> C[i] >> S[i] >> F[i];
	
	for(int k=0;k<N;k++)
	{
		ans=S[k];
		for(int i=k;i<N-1;i++)
		{
			if(ans-S[i]<0)
			{
				ans+=(S[i]-ans);
				ans+=C[i];
				continue;
			}
			if(ans==S[i])
			{
				ans+=C[i];
				continue;
			}
			while(1)
			{
				if((ans-S[i])%F[i]==0)
				{
					ans+=C[i];
					break;
				}
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i <= 25; i++)
  {
    for (int j = 0; j <= 14; j++)
    {
      if (n == (4 * i) + (7 * j))
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3640
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.*;
class Main
{
    public static void main(String[] args)throws IOException
    {
        FastReader in=new FastReader(System.in);
        StringBuffer st=new StringBuffer();
       int n=in.nextInt();
       if(n==1)
       st.append("Hello World");
       else{
         int a=in.nextInt();
         int b=in.nextInt();
         st.append(a+b);
       }
          
        System.out.print(st);
    }
    static class FastReader{
 
        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;
 
        FastReader(InputStream is) {
            in = is;
        }
 
        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }
 
        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan());
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }
 
        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan());
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
 
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan());
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}      

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

using namespace std;

struct ve {
	int vert;
	int edge;
};

vector < ve > with[100005];

int color[100005];
int coloredge[100005];

void dfs(int curr, int parent, int col, int all) {
	int currcolor = 1;
	for (int i = 0; i < with[curr].size(); i++) {
		if (with[curr][i].vert == parent) continue;
		if (currcolor == col) currcolor++;
		if (currcolor > all) currcolor = 1;
		coloredge[with[curr][i].edge] = currcolor;
		dfs(with[curr][i].vert, curr, currcolor, all);
		currcolor++;
		if (currcolor > all) currcolor = 1;
	}
}

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int res = 0;
	for (int i = 1; i < n; i++) {
		int l, r;
		cin>>l>>r;
		with[l].push_back({r, i});
		with[r].push_back({l, i});
		res = max(res, (int)max(with[l].size(), with[r].size()));
	}
	cout<<res<<endl;
	dfs(1, -1, 0, res);
	for (int i = 1; i < n; i++)
		cout<<coloredge[i]<<"\n";
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll x, y, tek, kol = 0;
    cin >> x >> y;
    tek = x, kol = 1;
    while (tek * 2 <= y)
    {
        tek *= 2;
        kol++;
    }
    cout << kol;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
double pi=3.14159265358979;

int main(){
    double r;
    cin >> r;
    printf("%.8f %.8f\n",pi*r*r,2*pi*r);
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

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

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

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

ll dp[110][100100]; // num,weight

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

	int N=in(),W=in();
	vector<ll> w(N),v(N);
	REP(i,N){
		w[i]=in();
		v[i]=in();
	}
	
	for(int num=0;num<N;num++){
		for(int weight=0;weight<=W;weight++){
			if(weight-w[num]>=0) chmax(dp[num+1][weight],dp[num][weight-w[num]]+v[num]);
			chmax(dp[num+1][weight],dp[num][weight]);
		}
	}
	
	cout << *max_element(dp[N],dp[N]+W+1) << endl;
	return 0;
}


Measured memory_bytes: 79360
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,k,a[5555]={};
	cin>>n>>k;
	FOR(i,0,n){
		cin>>a[i+1];
	}
	sort(a+1,a+n+1);
	int l=0,r=n+1,m=(l+r)/2;
	while(l!=m){
		int dp[2][10555]={},idx=0;
		dp[idx][0]=1;
		FOR(i,0,n){
			FOR(j,0,k*2+2){
				int nw=j+a[i+1];
				if(nw>k*2)nw=k*2+1;
				if(i+1!=m)dp[idx^1][j]|=dp[idx][j];
				dp[idx^1][nw]|=dp[idx][j];
				dp[idx][j]=0;
			}
			idx^=1;
		}
		FOR(i,1,k*2+2){
			dp[idx][i]+=dp[idx][i-1];
			//cerr<<i<<" "<<dp[idx][i]<<endl;
		}
		int nw=k+a[m]-1;
		if(nw>k*2)nw=k*2+1;
		if(dp[idx][nw]-dp[idx][k-1]==0){
			l=m;
		}else{
			r=m;
		}
		m=(l+r)/2;
	}
	cout<<m;
    return 0;
}


Measured memory_bytes: 1016
n, m = map(int, input().split())
a = list(map(int, input().split()))

s = [0]#len = (n + 1)
for i in range(n):
    s.append((s[i] + a[i]) % m)

ans = 0
d = dict()
for i in range(n + 1):
    t = d.get(s[i], 0)
    ans += t
    d[s[i]] = t + 1
print(ans)

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

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

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

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

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

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

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

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

ll N;
Vi solve(ll n){
  if(n == 0) return {};
  if(n == 1) return {1};
  else{
    ll s = 0, temp = 0;
    while(s + temp < n){
      s += temp;
      temp++;
    }
    Vi v = solve(n - temp);
    v.pb(temp);
    return v;
  }
}

int main(){
  cin >> N;
  Vi v = solve(N);
  for(auto &e : v){
    cout << e << endl;
  }
  
}


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

int main()
{
    int n;
    cin >> n;
    int x[n + 5];
    rep(i,n){
        cin >> x[i];
    }

    sort(x, x + n);

    ll sum = 0;
    ll m = inf;

    for (int i = x[0]; i <= x[n - 1];i++){
        sum = 0;
        for (int j = 0; j < n; j++){
            sum += (x[j] - i) * (x[j] - i);
        }
        if(sum<m){
            m = sum;
        }
    }

    cout << m << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int mod = 1e9+7;//998244353
const int N = 1e5+5;



void solve(){
	int n,m;
	cin>>n>>m;
	char c[n+1][m+1];
	forn(i,n)
		forn(j,m)cin>>c[i][j];
	pii d[8]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
	auto check = [&](int x,int y){
			return x>=1 && y>=1 && x<=n && y<=m;
	};
	forn(i,n){
		forn(j,m){
			if(c[i][j]=='#')continue;
			int cnt=0;
			for(int k=0;k<8;k++){
				if(check(i+d[k].F,j+d[k].S) && c[i+d[k].F][j+d[k].S]=='#')cnt++;
			}
			c[i][j]=char('0'+cnt);
		}
	}
	forn(i,n){
		forn(j,m)cout<<c[i][j];
		cout<<'\n';
	}

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

int main(){
    int r, c, n;
    cin >> r >> c >> n;
    map<int, int> mp;
    size_t cnt = 0;
    for(int i=1;i<=n;++i){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if((x1==0 || x1==r || y1==0 || y1==c) && (x2==0 || x2==r || y2==0 || y2==c)){
            ++cnt;
            if(y1 == 0) mp[x1] = i;
            else if(x1 == r) mp[r+y1] = i;
            else if(y1 == c) mp[2*r+c-x1] = i;
            else mp[2*r+2*c-y1] = i;
            if(y2 == 0) mp[x2] = i;
            else if(x2 == r) mp[r+y2] = i;
            else if(y2 == c) mp[2*r+c-x2] = i;
            else mp[2*r+2*c-y2] = i;
        }
    }
    if(cnt <= 1){
        cout << "YES" << endl;
        return 0;
    }

    deque<int> dq;
    for(auto p: mp){
        if(!dq.empty() && dq.back() == p.second){
            dq.pop_back();
        }else dq.push_back(p.second);
    }
    if(dq.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 9984
#include <iostream>

using namespace std;

int A, B, C, D;

int main() {
    cin >> A >> B >> C >> D;
    if ((B - C) * (D - A) <= 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << min(min(abs(B - C), abs(D - A)), min((B - A), (D - C))) << endl;
    return 0;
}

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



//conbinatin (2002,2) = 

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

  n -= k;
  int ans = 1+ n/(k-1) + int (n%(k-1) != 0);
  cout << ans << endl;
}


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

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


int main() {

int a,b,t;
cin >> a >> b;

if(a+b > 9)cout << "error" << endl;
else cout << a+b << endl;

  return 0;

}

Measured memory_bytes: 256
n, k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i>=k:
        ans += 1/n
    else:
        p2 = 0
        while i*2**p2<k:
            p2 +=1
        ans += 1/n * ((1/2)**p2)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char str[101];
    int i,j,len,cnt=0,p;
    scanf("%s",str);
    len=strlen(str);

    p=len/2-1;

    for(i=0; i<=p; i++)
    {
        if(str[i]!=str[--len])
        {
            cnt++;
        }

    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


s = S()
if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')


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

const int N = 300005;

int n, a[N];
long long l[N], r[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= 3 * n; ++i) cin >> a[i];

	// first half
	priority_queue <int> pq;
	long long sum = 0;
	for (int i = 1; i <= 3 * n; ++i) {
		pq.push(-a[i]);
		sum += a[i];
		if (i > n) {
			int top = pq.top(); pq.pop();
			sum += top;
		}
		l[i] = sum;
	}

	// second half
	sum = 0;
	pq = priority_queue<int>();
	for (int i = 3 * n; i >= 1; --i) {
		pq.push(a[i]);
		sum += a[i];
		if (i <= 2 * n) {
			int top = pq.top(); pq.pop();
			sum -= top;
		}
		r[i] = sum;
	}

	// solve
	long long ans = -1e18;
	for (int i = 1; i <= 3 * n; ++i) {
		if (i >= n && 3 * n - i >= n) {
			ans = max(ans, l[i] - r[i + 1]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7032
#include <iostream>

int main(int argc, char const* argv[])
{
	int top1 = 0, top2 = 0, top3 = 0;
	int input;

	for (size_t i = 0; i < 10; i++)
	{
		std::cin >> input;
		if(input > top1)
		{
			top3 = top2;
			top2 = top1;
			top1 = input;
		}
		else if (input > top2)
		{
			top3 = top2;
			top2 = input;
		}
		else if(input > top3)
			top3 = input;
	}

	std::cout << top1 << std::endl;
	std::cout << top2 << std::endl;
	std::cout << top3 << std::endl;
	return 0;
}

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

int main(void)
{
	char list[501][501];
    char friend[501];
    char second[501];
    int n, m;
    int i, j;
    int from, to;
    int ans;
    
    while (1){
	    scanf("%d", &n);
   		scanf("%d", &m);
    	
		if (m + n == 0){
			break;
		}
		
    	memset(list, 0, sizeof(list));
    	
    	for (i = 0; i < m; i++){
        	scanf("%d%d", &from, &to);
        	list[from][to] = list[to][from] = 1;
    	}
    	
   		memset(friend, 0, sizeof(friend));
    	friend[1] = 1;
    	
    	for (i = 2; i <= n; i++){
        	if (list[1][i] == 1){
            	friend[i] = 1;
        	}
    	}
    	
    	memset(second, 0, sizeof(second));
    	for (i = 2; i <= n; i++){
        	for (j = 2; j <= n; j++){
            	if (list[i][j] == 1 && friend[i] == 1 && friend[j] != 1 && second[i] != 1){
                	friend[j] = 1;
               		second[j] = 1;
            	}
        	}
    	}
    	
    	ans = 0;
    	for (i = 2; i <= n; i++){
        	if (friend[i] == 1){
            	ans++;
        	}
    	}
    	
    	printf("%d\n", ans);
    }
	
    return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll from, to, target = 0;
    cin >> from >> to;
    rep(i, n - 2) {
        ll a;
        cin >> a;
        target ^= a;
    }
    ll s = from + to;

    ll d = s - target;
    if (d < 0 || (d & 1) == 1) {
        puts("-1");
        return 0;
    }

    d >>= 1;

    ll toDeduct = 0;
    vl free(0);
    rep(i, 50) {
        if (target & (1ll << i)) {
            free.pb(i);
            if (d & (1ll << i)) {
                puts("-1");
                return 0;
            }
        } else {
            toDeduct += d & (1ll << i);
        }
    }
    if (toDeduct > from) {
        puts("-1");
        return 0;
    }

    for (int i = (int)free.size() - 1; i >= 0; i--) {
        if (toDeduct + (1ll << free[i]) <= from) {
            toDeduct += (1ll << free[i]);
        }
    }
    if (toDeduct == 0) {
        puts("-1");
        return 0;
    }
    cout << from - toDeduct << endl;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int t_at = c / b + !!(c % b), a_at = a / d + !!(a % d);
    cout << ((t_at <= a_at) ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 3596
/*-- ILSH  --*/

// Multipoll evaluation + Divide and Conquer
// Time ( Iterative ) < Time ( Recursive )

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double ld;

#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll > 
#define len length 
#define fi first
#define se second
#define dt cout<<"HEre\n";
#define sz(x) (ll)x.size()
const ll inf=1e18+1e17;
const ll mod = 1e9+7;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
const int N=(1<<17)+10;
int dp[43][N];
inline int add ( int a, int b){
	if ( a+b>=mod)
		return a+b-mod;
	return a+b;
}
void solve(){
	memset( dp,0,sizeof( dp));
	int n, x, y, z;
	cin>>n>> x>>  y >> z ;
	int ans= ( ( 1<<( z-1))|( 1<<( y+z-1)))|(1<<(x+y+z-1));
	int m= ( 1<<( x+y+z));
	dp[0][0]=1;
	for ( int i=0;i<n;i++)
		for ( int msk=0;msk<=m;msk++){
			if ( dp[i][msk]==0)
				continue;
			for ( int p=1;p<=10;p++){
				if ( msk==m){
					dp[i+1][msk]=add( dp[i][msk],dp[i+1][msk]);
					continue;
				}	
				ll xx=((msk<<p)|(1<<(p-1)))&(m-1);
				if ( (ans&xx)==ans) 
					xx=m;
				dp[i+1][xx]=add( dp[i+1][xx],dp[i][msk]);
			}
		}
	cout<<dp[n][m]<<'\n';
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen ("INPUT.txt" , "r" , stdin);
		freopen ("OUTPUT.txt", "w" , stdout);
	#endif
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
    //	cout << clock() / double(CLOCKS_PER_SEC) << endl;
}


Measured memory_bytes: 25668
#include <bits/stdc++.h>
using namespace std;
int n,x,y;vector<int>e[100005];
int dfs(int x,int fa)
{
	int tot=0;
	for(int i=0;i<e[x].size();i++) if(e[x][i]!=fa) tot+=dfs(e[x][i],x);
	if(tot>=2) return tot;else return tot^1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++) scanf("%d%d",&x,&y),e[x].push_back(y),e[y].push_back(x);
	puts(dfs(1,0)?"First":"Second");
}

Measured memory_bytes: 5888
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];

int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v=0;v<n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++) color[u] =WHITE;
  tt=0;

  for(u=0;u<n;u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j] = 0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();

  return 0;
}



Measured memory_bytes: 2748
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    n = int(input())
    A = list(map(int, input().split()))

    grid = [[0 for _ in range(W)] for _ in range(H)]
    h, w = 0, 0
    for i in range(n):
        cnt = A[i]
        while cnt:
            grid[h][w] = i + 1
            cnt -= 1
            if w + 1 < W:
                w += 1
            else:
                h += 1
                w = 0

    for h in range(H):
        print(*grid[h]) if h % 2 == 0 else print(*grid[h][::-1])


if __name__ == '__main__':
    resolve()


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

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

#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 ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	YES(b-a == c-b);
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by khrom on 2017/06/15.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Integer> resList = new ArrayList<>();
        while (true) {
            int left = scanner.nextInt();
            String enzan = scanner.next();
            int right = scanner.nextInt();
            if (enzan.equals("?")) break;
            switch (enzan) {
                case "+":
                    resList.add(left + right);
                    break;
                case "-":
                    resList.add(left - right);
                    break;
                case "/":
                    resList.add(left / right);
                    break;
                case "*":
                    resList.add(left * right);
                    break;
            }
        }
        resList.forEach(System.out::println);
    }
}

Measured memory_bytes: 31972