akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> par_size;

    UnionFind(int N) : par(N){ //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
            par[i] = i;
        }
        par_size.resize(N);
        for(int i = 0; i < N; i++){
            par_size[i] = 1;
        }

    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x){
            return x;
        }
        else{
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        par_size[ry] += par_size[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int get_size(int x){
        int rx = root(x);
        return par_size[rx];
    }
};

int main(){


    ll N, M;
    cin >> N >> M;

    vector< vector<ll> > lang(M);
    UnionFind uni(N);

    for(int i = 0; i < N; i++){
        ll K;
        cin >> K;
        for(int k = 0; k < K; k++){
            ll l;
            cin >> l;
            l --;
            lang[l].push_back(i);
        }
    }

    for(int m = 0; m < M; m++){
        if(lang[m].size() == 0 ) continue;
        for(int i = 0; i < lang[m].size(); i++){
            uni.unite(lang[m][0], lang[m][i]);
        }
    }

    if(uni.get_size(0) == N) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 4736
#include <iostream>

int main(){
    int a,b;
    std::cin >> a >> b ;
    int sum = 0;
    for(int i=0;i<2;++i){
        if(a > b){
            sum += a--;
        }else{
            sum += b--;
        }
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

#define MAX_E 5001
#define MAX_V 2501
// 頂点fromから頂点toへのコストcostの辺 
struct edge { ll from, to, cost; };
edge es[MAX_E]; // 辺
ll d[MAX_V]; // 最短距離
ll N, V, E; // Vは頂点数、Eは辺数
// s番目の頂点から各頂点への最短距離を求める
bool shortest_path(int s) {
	for (int i = 0; i < V; i++) d[i] = INF; 
	d[s] = 0;
	for (int i = 0; i < V; i++) {
		bool update = false;
		for (int j = 0; j < E; j++) {
			edge e = es[j];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true; 
				if (i == V - 1) return true;
			}
		}
		if (!update) break; 
	}
	return false;
}

void dijkstra(int s, vector<edge> G[]) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

bool ng[MAX_V];

int main(){	
	long long M;
	long long P;
	scanf("%lld",&N);
	scanf("%lld",&M);
	scanf("%lld",&P);
	V = N;
	E = M;
	edge es1[MAX_E];
	vector<edge> G1[MAX_V],G2[MAX_V];
	for(int i = 0 ; i <= M-1 ; i++){
	    ll A, B, C;
		scanf("%lld",&A);
		scanf("%lld",&B);
		scanf("%lld",&C);
		A--;
		B--;
		edge e;
		e.from = A;
		e.to = B;
		e.cost = P-C;
		es1[i] = e;
		edge e1 = {A,B,1};
        G1[A].push_back(e1);
		edge e2 = {B,A,1};
        G2[B].push_back(e2);
	}
	
	dijkstra(0,G1);
	// cout << d[0] << endl;
	// cout << d[1] << endl;
	rep(i,N) {
		if (d[i] == INF) ng[i] = true;
	}
	dijkstra(N-1,G2);
	rep(i,N) {
		if (d[i] == INF) ng[i] = true;
	}
	E = 0;
	// rep(i,V) {
	// 	cout << ng[i] << endl;
	// }
	rep(i,M) {
		if (!ng[es1[i].from] && !ng[es1[i].to]) {
			es[E] = es1[i];
			E++;
			// cout << es1[i].from << " " << es1[i].to << " " << es1[i].cost << endl;
		} 
	}
	bool b = shortest_path(0);
	if (b) {
		cout << "-1\n";
	} else {
		cout << max(-d[N-1],0LL) << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

class FloppyCube
{
public:
	int state[30];
	int c;

	bool complete()
	{
		if (count(&state[0] , &state[9] , state[0])  != 9) return false;
		if (count(&state[9] , &state[12], state[9])  != 3) return false;
		if (count(&state[12], &state[15], state[12]) != 3) return false;
		if (count(&state[15], &state[18], state[15]) != 3) return false;
		if (count(&state[18], &state[21], state[18]) != 3) return false;
		if (count(&state[21], &state[30], state[21]) != 9) return false;
		return true;
	}
	FloppyCube get(int order)
	{
		FloppyCube cube = *this;
		cube.c++;

		if (order == 0)
		{
			swap(cube.state[0], cube.state[27]);
			swap(cube.state[1], cube.state[28]);
			swap(cube.state[2], cube.state[29]);
			swap(cube.state[14], cube.state[15]);
			swap(cube.state[18], cube.state[20]);
		}
		else if (order == 1)
		{
			swap(cube.state[6], cube.state[21]);
			swap(cube.state[7], cube.state[22]);
			swap(cube.state[8], cube.state[23]);
			swap(cube.state[12], cube.state[17]);
			swap(cube.state[9], cube.state[11]);
		}
		else if (order == 2)
		{
			swap(cube.state[0], cube.state[23]);
			swap(cube.state[3], cube.state[26]);
			swap(cube.state[6], cube.state[29]);
			swap(cube.state[9], cube.state[20]);
			swap(cube.state[15], cube.state[17]);
		}
		else if (order == 3)
		{
			swap(cube.state[2], cube.state[21]);
			swap(cube.state[5], cube.state[24]);
			swap(cube.state[8], cube.state[27]);
			swap(cube.state[11], cube.state[18]);
			swap(cube.state[12], cube.state[14]);
		}
		return cube;
	}
};

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

	for (int i = 0; i < n; i++)
	{
		FloppyCube cube;
		queue<FloppyCube> que;
		for (int j = 0; j < 30; j++)
		{
			cin >> cube.state[j];
		}
		cube.c = 0;
		que.push(cube);
		while (true)
		{
			cube = que.front();
			que.pop();

			if (cube.complete())
			{
				cout << cube.c << endl;
				break;
			}
			for (int k = 0; k < 4; k++) que.push(cube.get(k));
		}
	}

	return 0;
}

Measured memory_bytes: 11900
#include<stdio.h>
 
char H[1000000][14]; 
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){
  key = key%1000000;
  return key;
}
int h2(int key){
  key = 1+key%(1000000-1);
  return key;
}
 
int find(char str[]){
  long long sum,key2,i;
  sum = getKey(str);
  for(i=0;i<20;i++){
    key2=(h1(sum)+i*h2(sum))%1000000;
    if(strcmp(H[key2],str)==0)return 1;
    else if(strlen(H[key2])==0)return 0;
  }
  return 0;
}
 
int insert(char str[]){
  long long sum,key2,i;
  sum = getKey(str);
  for(i=0;i<20;i++){
    key2=(h1(sum)+i*h2(sum))%1000000;
    if(strcmp(H[key2],str)==0)return 1;
    if(strlen(H[key2])==0){
      strcpy(H[key2],str);
      return 0;
    }
  }
}
 
int main(){
  int i, n, h;
  char str[14], com[9];
  for ( i = 0; i < 1000000; i++ ) H[i][0] = '\0';
   
  scanf("%d", &n);
   
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
     
    if ( com[0] == 'i' )
      insert(str);
     else {
      if (find(str))
    printf("yes\n");
       else 
    printf("no\n");
      
    }
  }
  return 0;
}

Measured memory_bytes: 14280
N,M=map(int,input().split())
H=list(map(int,input().split()))
t=[1]*N
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        t[b-1]=0
    elif H[a-1]<H[b-1]:
        t[a-1]=0
    else:
        t[a-1],t[b-1]=0,0
print(sum(t))

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

typedef    long long          ll;
typedef    vector<long long>    vi; 
typedef    vector<vi>         vvi; 
typedef    pair<long,long>      ii; 
#define    sz(a)              long((a).size()) 
#define    pb                 push_back 
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end() 
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define    present(c,x)       ((c).find(x) != (c).end()) 
#define    cpresent(c,x)      (find(all(c),x) != (c).end())  
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "


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

  ll m,k,i;
  cin>>m>>k;
  if(m==0)
  {
    if(k==0)cout<<"0 0";
    else cout<<"-1";
    return 0;
  }
  if(m==1){
    if(k==0)cout<<"0 0 1 1";
    else cout<<-1;
    return 0;
  }
  ll n=pow(2,m);
  if(k>=n){
    cout<<-1;
    return 0;
  }
  for(i=0;i<n;i++)
    if(i==k)continue;
    else cout<<i<<" ";
    cout<<k<<" ";
    for(i=n-1;i>=0;i--)
      if(i==k)continue;
    else cout<<i<<" ";
     cout<<k;


  return 0;
 }

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

int main () {
  int A, B, ans = 1;
  cin >> A >> B;
  string S;
  cin >> S;
  for (int i = 0; i < A; i++) {
    if (!('0' <= S[i] && S[i] <= '9')) ans = 0;
  }
  if (S[A] != '-') ans = 0;
  for (int i = A+1; i < A+B+1; i++) {
    if (!('0' <= S[i] && S[i] <= '9')) ans = 0;
  }
  if (ans) printf("Yes");
  else printf("No");
  return 0;
}
 


Measured memory_bytes: 3680
import java.awt.*;
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		Point[]a=new Point[n];
		Arrays.setAll(a,o->new Point(s.nextInt(),s.nextInt()));

		double r=0;
		for(int i=0;i<n;++i)
			for(int j=i+1;j<n;++j)
				r+=a[i].distance(a[j]);
		System.out.println(r*2/n);
	}
}


Measured memory_bytes: 36072
Q = gets.chomp.to_i
p_length = 100001


# 1~10^5までの素数をbooleanで持つ
# 累積和でそれぞれ何個か調べる
# あとは順番に処理


prime = Array.new(p_length, false)

def fetch_prime_list(max)
  table = Array.new(max + 1,true)
  prime_list = []

  (2..max).each do |num|
    if table[num] == true
      prime_list << num
      k = num * num
      while k <= max
        table[k] = false
        k += num
      end
    end
  end
  return prime_list
end

#配列を返すメソッド
p_arr =  fetch_prime_list(p_length)

p_arr.each do |num|
  prime[num] = true
end

ruiseki = [0]

1.upto(p_length) do |i|
  if i.odd? && prime[i] && prime[(i + 1)/2]
    tmp = 1
  else
    tmp = 0
  end

  ruiseki[i] = ruiseki[i-1] + tmp
end


ans = []

Q.times do |i|
  l, r = gets.chomp.split.map(&:to_i)
  ans << ruiseki[r] - ruiseki[l-1]
end

ans.each do |r|
  puts r
end


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

string s;
void solve() {
    cin >> s;
    rep(i, s.size()) cout << "x";
    cout << endn;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


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

#define int long long

string s, t;
int dp[3333][3333]; // dp[si][tj]: s[i], t[j]まで見たときのLCSの大きさの最大値
int pre[3333][3333]; // どこからきたかを記録。左から: 3, 上から: 2, 左上から: 4

// DPでLCSの大きさを求める
void lcs() {
  int n = s.size(), m = t.size();
  s = "+" + s;
  t = "*" + t;

  fill(dp[0], dp[1111], 0LL);
  fill(pre[0], pre[1111], 0LL);

  for (int si = 1; si <= n; si++) {
    for (int ti = 1; ti <= m; ti++) {
      if (s[si] == t[ti]) {
        dp[si][ti] = dp[si-1][ti-1] + 1;
        pre[si][ti] = 1;
      } else if (dp[si-1][ti] > dp[si][ti-1]) {
        dp[si][ti] = dp[si-1][ti];
        pre[si][ti] = 2;
      } else {
        dp[si][ti] = dp[si][ti-1];
        pre[si][ti] = 3;
      }
    }
  }
}

string solve() {
  string ans = "";

  int si = s.size() - 1;
  int ti = t.size() - 1;
  while (si >= 1 && ti >= 1) {
    if (pre[si][ti] == 1) { // 左上に遷移
      ans += s[si];
      si--, ti--;
    } else if (pre[si][ti] == 2) { // 上に遷移
      si--;
    } else { // 右に遷移
      ti--;
    }
  }

  reverse(ans.begin(), ans.end());
  return ans;
}

signed main() {
  cin >> s >> t;
  lcs(); // dpテーブルを埋める
  cout << solve() << endl;

  return 0;
}

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

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

typedef long long ll;
template <class T = ll> T in() { T x; cin >> x; return (x); }

signed main () {
	int n;
	cin >> n;
	int a[n];
	REP (i,n) cin >> a[i];
	sort(a,a+n);
	int ans;
	if (n % 2 == 0) {
		int mi = 0;
		int ma = 0;
		for (int i = 0;i < n/2;i++) {
			if (i != n/2-1) mi += 2 * a[i];
			else mi += a[i];
		}
		for (int i = n/2;i < n;i++) {
			if (i != n/2) ma += 2 * a[i];
			else ma += a[i];
		}
		cout << ma - mi << endl;
	} else {
		int mi = 0;
		int ma = 0;
		int p1 = 0;
		REP (i,n/2) mi += 2 * a[i];
		FOR (i,n/2,n) {
			if (i > n/2 + 1) ma += 2 * a[i];
			else ma += a[i];
		}
		p1 = ma - mi;
		ma = mi = 0;
		REP (i,n/2+1) {
			if (i < n/2 - 1) mi += 2 * a[i];
			else mi += a[i];
		}
		FOR (i,n/2+1,n) ma += 2 * a[i];
		cout << max(p1,ma-mi) << endl;
	}
}

Measured memory_bytes: 1024
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    print(int(input())**2)


if __name__ == '__main__':
    main()

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

int main() {
  string N;
  cin >> N;
  if (N[0] == N[1] && N[1] == N[2]){
    cout << "Yes" << endl;  
  }
  else if (N[1] == N[2] && N[2] == N[3]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner (System.in);
		
		String n = sc.next();
		String chkNumStr = "";
		int chkNum=0;
		
		
		
		while(n.length() != 0) {
			chkNumStr = n.substring(0, 1);
			chkNum = chkNum + Integer.parseInt(chkNumStr);
			n = n.substring(1, n.length());
		}
		if(chkNum%9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 56416
//#line 2 "SubstringQueries.cpp"

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int e = abs(a + b - c - d);
	int f = abs(a - b + c - d);
	int g = abs(a - b - c + d);
	cout << min(min(e, f), g) << endl;
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()

using namespace std;

int main() {
  string str;
  cin >> str;

  set<char> _s;
  for (auto e : str) {
    _s.insert(e);
  }
  puts(_s.count('a') && _s.count('b') && _s.count('c') ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
S = input()
K = int(input())

t = bytearray(S * 3, 'us-ascii')
for i in range(1, len(t)):
    if t[i - 1] == t[i]:
        t[i] = 0
b0 = t[:len(S)].count(0)
b1 = t[len(S):len(S)*2].count(0)
b2 = t[len(S)*2:len(S)*3].count(0)
print(b0 + b1 * (K // 2) + b2 * ((K - 1) // 2))


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

int main() {

    int a, b, k;
    cin >> a >> b >> k;
    int p = __gcd(a, b);
    int count = 0;
    for (int i=p; i>0; i--) {
        if (p % i == 0) {
            count++;
            if (count == k) {
                cout << i;
            }
        }
    }

}


Measured memory_bytes: 256
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1][1]>=l[1]:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
input()
f=lambda x,y:(x,int(y))
A=[f(*e.split())for e in sys.stdin]
B=A[:]
k(A,0,len(A)-1)
print(['Not s','S'][A==d(B)]+'table')
for e in A:print(*e)


Measured memory_bytes: 20168
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int [] a = new int [n];
        int [] b = new int [n];
        int [] c = new int [m];
        int [] d = new int[m];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        for (int i = 0 ; i < m ; i++) {
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        for (int i = 0 ; i < n ; i++ ) {
            int distance = 500000000;
            int checkPoint = 0;
            for (int j = 0 ; j < m ; j++ ) {
                if (distance > Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j])) {
                    distance = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
                    checkPoint = j;
                }
            }
            System.out.println(checkPoint + 1);
        }
    }

}

Measured memory_bytes: 23508
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int max = Math.max(a, Math.max(b, c));
        int ans = a + b + c - max;
        for (int i = 0; i < k; i++) {
            max *= 2;
        }
        System.out.println(ans +max);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

	long long ans = x / 11 * 2;
	x %= 11;
	if(x and x <= 6) ans += 1;
	else if(x) ans += 2;

	cout << ans << endl;

    return 0;
}


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

int main(){
    string s ;
    cin >> s ;
    vector<int> v ;
    for(char c : s){
        if ( c == '1' ){
            v.push_back(1);
        }
        else if ( c == '0' ){
            v.push_back(0);
        }
        else{
            if ( v.size() )
                v.pop_back();
        }
    }
    for(int x : v){
        cout << x ;
    }
    cout << endl;
    return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll b=0,c=0,a,d=0,e,l,m,n,k,x,o=0,p,q,x1,y1,z,max1=0,s=0,ans,r,i1=-1;
    string t,u;

    cin>>x>>a;
    if(x<a)cout<<0<<endl;
    else cout<<10<<endl;
}




Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a=0;
	string s;
	cin>>s;
	for(int i=1;i<=s.size();i++)
	{
		if(s[i]!=s[i-1])
		{
			a++;
		} 
	}
	cout<<a-1;
}

Measured memory_bytes: 512
import itertools
n=(int)(input())
moji = list('0123456789')
s=input()
count = 0

for i in itertools.product(moji, repeat=3):
  sousa = list(s)
  try:
    
    n1 = sousa.index(i[0])
    n2 = sousa[n1+1:].index(i[1])+n1+1
    n3 = sousa[n2+1:].index(i[2])+n2+1
    #print(sousa, sousa[n1+1:], sousa[n1+2:])
    count += 1
  except ValueError:
    continue
  #print(i)
  #moji.append(s[i[0]] + s[i[1]] + s[i[2]])
  #print(moji)
  
print(count)

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

int main(){
  int N;
  cin >> N;
  if(N<=9){
    cout << N << endl;
  }
  else if(N<=99){
    cout << 9 << endl;
  }
  else if(N<=999){
    cout << N-90 << endl;
  }
  else if(N<=9999){
    cout << 909 << endl;
  }
  else if(N<=99999){
    cout << N-9090 << endl;
  }
  else{
    cout << 90909 << endl;
  }
}

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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

void sputs(){}
template <class Head, class... Tail>
void sputs(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(Tail) == 0) { cout << endl; }
  else { cout << " "; }
  sputs(std::move(tail)...);
}

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  if (n==1){
    cout << "First" << endl;
    return 0;
  }
  vvi g(n);
  rep(i, n-1){
    int a,b;cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  int x = -1;
  int max_d = 0;
  auto dfs = [&](const auto& dfs, auto& d, int u, int cost) -> void {
    each(v, g[u]){
      if (d[v]<INF) continue;
      d[v] = cost+1;
      if (d[v]>max_d){
        chmax(max_d, d[v]);
        x = v;
      }
      dfs(dfs, d, v, cost+1);
    }
  };

  vi d0(n, INF); d0[0] = 0;
  dfs(dfs, d0, 0, 0);

  vi dx(n, INF); dx[x] = 0;
  max_d = 0;
  dfs(dfs, dx, x, 0);
  dump(max_d);

  vi dp(n+1);

  dp[0] = 0;
  dp[1] = 1;
  dp[2] = 0;
  rep(i, 3, n+1){
    if (dp[i-1]==0 || dp[i-2]==0) dp[i] = 1;
  }
  dump(dp);
  cout << (dp[max_d+1]?"First":"Second") << endl;

  return 0;
}


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    char a, b, c;
	gc(a), gc(b), gc(c);
	if(a == '7' || b == '7' || c == '7') pstr("Yes");
	else pstr("No");
}


Measured memory_bytes: 3660
n,k = map(int,input().split())
s = input()

l = [0]

for i in range(n-1):
  if s[i] != s[i+1]:
    l.append(i+1)

l.append(n)

ans = 0
for i in range(len(l)-1):
  index = min(i+2*k + int(s[l[i]]=="1"), len(l)-1)
  ans = max(ans, l[index] - l[i])

print(ans)

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

#define ll long long int
ll mod=1e9+7;

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j;
        cin >> n;
        string s;
        cin >> s;
        string cpy = s;
        // n = s.size();
        
        ll start = 0;
        ll end = n-1;
        ll swapops = 0;

        while(start < end)
        {
            while(start < n && start < end && s[start] != 'W')
            {
                start++;
            }

            while(end >= 0 && start < end && s[end] != 'R')
            {
                end--;
            }

            if(start < end)
            {
                swap(s[start],s[end]);
                start++;
                end--;
                swapops++;
            }        
        }

        // cout << s << '\n';
        cout << swapops << '\n';

    }
    
    return 0;
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL)
#define PI acos(-1.0)
#define TEST(n) cout<<"dhukse"<<n<<'\n'
#define endl '\n'
#define FILEREAD freopen("input.txt","r",stdin)
#define FIXED(n) cout << fixed << setprecision(n);
#define CASE(n) cout<<"Case " << n << ": ";
long long Set(long long N,long long pos){ return N=N | (1<<pos);}
long long reset(long long N,long long pos){return N= N & ~(1<<pos);}
bool check(long long N,long long pos){return (bool)(N & (1<<pos));}
long long min(long long a, long long b){if(a<b)return a;else return b;}
long long max(long long a, long long b){if(a>b)return a;else return b;}

/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////In the name of almighty ALLAH/////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Coded By: pranonrahman////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    FAST;
    long long t=1;
   // cin >> t;
    long long T = t;
    while(t--)
    {
        long long n,k;
        cin >> n >> k;
        long long sum=0;
        long long arr[n+3];
        for(long long i=0;i<n;i++)
        {
            cin >> arr[i];
            sum+=arr[i];
        }
       // cout << sum << endl;
        sort(arr,arr+n);
        long long s1=0;
        for(long long i=0;i<min(n,k);i++)
        {
            s1+=arr[n-1-i];
           // cout << "fbhaikfbh" << s1 << endl;
        }

        cout << sum-s1 << endl;
    }
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

//    vector<int> a(m);
    vector<bool> broken(n);

    int tmp_a = 0;
    for ( int i = 0; i < m; i++ ) {
//        cin >> a[i];
        cin >> tmp_a;
        broken[tmp_a] = true;
    }

    vector<int> dp(n+1, 0);

    dp[0] = 1;

    int j = 0;
    for ( int i = 1; i <= n; i++ ) {
//        if ( i == a[min(j, m-1)] && j < m ) {
//            dp[i] = 0;
//            j++;
//        }
        if ( broken[i] ) {
            dp[i] = 0;
            continue;
        }
        else if ( i == 1 ) {
            dp[i] = dp[0];
        }
        else {
            dp[i] = dp[i-1] % 1000000007 + dp[i-2] % 1000000007;
        }
    }

    cout << dp[n] % 1000000007 << endl;

    return 0;
}

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

int main(){
	
	ll k; cin>>k;
	ll ans = 0;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			for(int m = 1; m<= k; m++){
				ans += (__gcd(__gcd(i,j),m));
			}
		}
	}
	cout<<ans<<"\n";
	
	
	
	
}


















Measured memory_bytes: 3632
#include <iostream>
#include <cstdlib>

using namespace std;

void printarray(int n, int a[]){
  for (int i=0; i<n; i++){
    cout << a[i] << " ";
  }
  cout << endl;
}

void CountingSort(int n, int a[], int b[]){
  int m = -1;
  for (int i=0; i<n; i++){
    m = max(a[i], m);
  }
  int c[m+1];
  for (int i=0; i<=m; i++){
    c[i] = 0;
  }
  for (int i=0; i<n; i++){
    c[a[i]]++;
  }

  int i = 0;
  int j = 0;
  while (j<n){
    for (int k=j; k<j+c[i]; k++){
      b[k] = i;
    }
    j += c[i];
    i++;
  }
}

int main(){
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int tmp;
  for (int i=0; i<n; i++){
    cin >> tmp;
    a[i] = tmp;
  }

  CountingSort(n,a,b);

  for (int i=0; i<n; i++){
    if (i==0){
      cout << b[i];
    }
    else{
      cout << " " << b[i];
    }
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 18672
#include <iostream>
#include <set>

using namespace std;

int main()
{
    multiset<int> x;
    for( int i = 0; i < 3; ++i ){
        int tmp;
        cin >> tmp;
        x.insert(tmp);
    }

    auto itr = x.begin();
    int ans = *itr;
    ++itr;
    ans += *itr;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split(' ');
            var H = int.Parse(HW[0]);
            var W = int.Parse(HW[1]);

            string[,] array = new string[H, W];
            for (int i = 0; i < H; i++)
            {
                var line = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    array[i, j] = line.Substring(j, 1);
                }
            }

            List<string> answer = new List<string>();
            for (int i = 0; i < H; i++)
            {
                string answerLine = "";
                for (int j = 0; j < W; j++)
                {
                    int count = 0;
                    var s = array[i, j];
                    if (s == "#")
                    {
                        answerLine = answerLine + s;
                        continue;
                    }

                    //上
                    if (i - 1 >= 0)
                    {
                        count = (j - 1 < 0) ? count : (array[i-1, j - 1] == "#") ? count+1 : count;
                        count = (array[i-1, j] == "#") ? count+1 : count;
                        count = (j + 1 >= W) ? count : (array[i-1, j + 1] == "#") ? count+1 : count;
                    }
                    //中
                    {
                        count = (j - 1 < 0) ? count : (array[i, j - 1] == "#") ? count+1 : count;
                        count = (j + 1 >= W) ? count : (array[i, j + 1] == "#") ? count+1 : count;
                    }
                    //下
                    if (i + 1 < H)
                    {
                        count = (j - 1 < 0) ? count : (array[i+1, j - 1] == "#") ? count+1 : count;
                        count = (array[i+1, j] == "#") ? count+1 : count;
                        count = (j + 1 >= W) ? count : (array[i+1, j + 1] == "#") ? count+1 : count;
                    }
                    answerLine = answerLine + count.ToString();
                }
                answer.Add(answerLine);
            }

            for (int i = 0; i < answer.Count; i++)
            {
                Console.WriteLine(answer[i].ToString());
            }

        }
    }
}

Measured memory_bytes: 13140
s = input()

dp_prev = [1, 0, 0, 0]

MODE_BASE = 1000000007

for c in s:
    dp_new = [dp_prev[i] for i in range(0, 4)]
    for i in range(0, 4):
        if c == "A":
            dp_new[1] = (dp_prev[0] + dp_prev[1]) % MODE_BASE

        elif c == "B":
            dp_new[2] = (dp_prev[1] + dp_prev[2]) % MODE_BASE

        elif c == "C":
            dp_new[3] = (dp_prev[2] + dp_prev[3]) % MODE_BASE

        else:
            dp_new[0] = (dp_prev[0] * 3) % MODE_BASE
            dp_new[1] = (dp_prev[0] + dp_prev[1] * 3) % MODE_BASE
            dp_new[2] = (dp_prev[1] + dp_prev[2] * 3) % MODE_BASE
            dp_new[3] = (dp_prev[2] + dp_prev[3] * 3) % MODE_BASE

    dp_prev = dp_new

ans = dp_prev[3]
print(ans)


Measured memory_bytes: 3188
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
string s;

int main() {
	cin >> n >> s;
	int ans = 0;
	REP(i,n) {
		set<char>st;
		string S = s.substr(0, i + 1);
		string T = s.substr(i + 1, n - i - 1);
		REP(j, S.size())REP(k, T.size())if (S[j] == T[k])st.insert(S[j]);
		ans = max(ans, (int)st.size());
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) ((int)(x).size())
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1e9;
const ll INF = 1e15;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  int N;
  cin >> N;

  vector<ll> a(3 * N + 1);

  priority_queue<ll, vector<ll>, greater<ll>> red;
  ll redsum = 0;
  NREP(i, N) {
    cin >> a[i];
    red.push(a[i]);
    redsum += a[i];
  }

  FOR(i, N + 1, 2 * N + 1) {
    cin >> a[i];
  }

  priority_queue<ll> blue;
  ll bluesum = 0;
  FOR(i, 2 * N + 1, 3 * N + 1) {
    cin >> a[i];
    blue.push(a[i]);
    bluesum += a[i];
  }

  vector<ll> redmax(N + 1), bluemin(N + 1);
  redmax[0] = redsum;
  bluemin[0] = bluesum;

  NREP(k, N) {
    red.push(a[k + N]);
    redsum += a[k + N] - red.top();
    red.pop();
    redmax[k] = redsum;

    blue.push(a[2 * N - k + 1]);
    bluesum += a[2 * N - k + 1] - blue.top();
    blue.pop();
    bluemin[k] = bluesum;
  }

  ll maxdiff = -INF;
  REP(k, N + 1) {
    maxdiff = max(maxdiff, redmax[k] - bluemin[N - k]);
  }

  cout << maxdiff << endl;
  return 0;
}

Measured memory_bytes: 6004
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def removeDup(C: Array[Int]): Array[Int] = {
    val newC = new mutable.MutableList[Int]
    var prev = -1
    for (i <- C.indices) {
      if (C(i) != prev) {
        newC += C(i)
      }
      prev = C(i)
    }
    newC.toArray
  }

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val C = removeDup(Array.fill(N)(sc.nextInt))
    //println(C.mkString(","))

    val R = ArrayBuffer.fill(200001)(-1)
    val A = ArrayBuffer.fill(C.length + 1)(1L)
    for (i <- (C.length - 1) to (C.length - 2) by -1 if i >= 0) {
      R(C(i)) = i
    }
    for (i <- (C.length - 3) to 0 by -1) {
      A(i) = A(i + 1)
      val j = R(C(i))
      if (j >= 0) {
        A(i) += A(j)
        A(i) %= 1000000007
      }
      R(C(i)) = i
    }

    A(0).toString
  }
}


Measured memory_bytes: 74672
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	string s;
	LL w;
	cin >> s >> w;
	FOR(i, 0, s.length()) {
		if (i%w == 0) {
			cout << s[i];
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
s = []
for i in range(m):
    tmp = list(map(int, input().split()))[1:]
    s.append(sum(2 ** (i - 1) for i in tmp))
p = list(map(int, input().split()))

c = 0
for i in range(2 ** n):
    for j in range(m):
        if bin(i & s[j]).count("1") % 2 != p[j]:
            break
    else:
        c += 1
print(c)

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

int main(){
  int n, a; cin >> n >> a;
  int x[n+1], sum=0;
  for(int i=0; i<n; i++){
    cin >> x[i];
    sum += x[i];
  }

  ll dp[n+1][n+1][sum+1];
  memset(dp, 0, sizeof(dp));

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

  ll ans = 0;
  for(int j=1; j<=n; j++){
    for(int k=0; k<=sum; k++){
      if(k == a*j) ans += dp[n][j][k];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 51072
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int H, W;
std::vector<std::string> S;
int res[100][100], dx[] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 }, dy[] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };

int main()
{
	in>>H>>W;
	S.resize(H);
	rep(i,H)
	{	in>>S[i];}

	rep(i,H)
	{
		rep(j,W)
		{
			if(S[i][j]=='#')
			{
				rep(k,9)
				{
					res[i+1+dx[k]][j+1+dy[k]]++;
				}
			}
		}
	}

	rep(i,H)
	{
		rep(j,W)
		{
			if(S[i][j]!='#')
			{	out<<res[i+1][j+1];}
			else
			{	out<<S[i][j];}
		}
		out<<std::endl;
	}

	return 0;
}


Measured memory_bytes: 256