akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
vector<int> v[100100];
int dis[100100];
int intermit1,intermit2;
int fe=0;
int su=0;
bool alr[100100];
int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	REP(i,100100){
		dis[i]=-1;
		alr[i]=false;
	}
	dis[1]=0;
	queue<int> q1;
	q1.push(1);
	while(q1.size()){
		int t=q1.front();q1.pop();
		for(int i=0;i<v[t].size();i++){
			if(dis[v[t][i]]!=-1)continue;
			dis[v[t][i]]=dis[t]+1;
			q1.push(v[t][i]);
		}
	}
	int li=(dis[n]+1)/2-1;
	int next=n;
	int t_next;
	for(int i=0;i<(dis[n]+1)/2;i++){
		for(int j=0;j<v[next].size();j++){
			if(dis[v[next][j]]+1==dis[next])t_next=v[next][j];
		}
		if(i==(dis[n]+1)/2-1){
			intermit1=next;
			intermit2=t_next;
			break;
		}
		next=t_next;
	}
	q1.push(1);
	fe++;
	
	alr[1]=1;
	while(q1.size()){
		int t=q1.front();q1.pop();
		for(int i=0;i<v[t].size();i++){
			if(alr[v[t][i]])continue;
			if((t==intermit1&&v[t][i]==intermit2)||
				(t==intermit2&&v[t][i]==intermit1))continue;
			alr[v[t][i]]=true;
			fe++;
			q1.push(v[t][i]);
		}
	}
	//cout<<fe<<" "<<n-fe<<endl;
	if(fe>(n-fe))cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
long long dp[100000][3]={};
vector<vector<int> > v(100000,vector<int> (3));
long long dpp(int x,int p)
{
    if(dp[x][p]!=0)
        return dp[x][p];
    if(p==0)
        return dp[x][p]= max(v[x][p] + dpp(x+1,1),v[x][p] + dpp(x+1,2));
    if(p==1)
        return dp[x][p]= max(v[x][p] + dpp(x+1,0),v[x][p] + dpp(x+1,2));
        if(p==2)
        return dp[x][p]= max(v[x][p] + dpp(x+1,1),v[x][p] + dpp(x+1,0));
}
int main() {
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
int n;
cin>>n;


for(int i=0;i<n;i++)
{
    cin>>v[i][0]>>v[i][1]>>v[i][2];
}
dp[n-1][0]= v[n-1][0];
dp[n-1][1]= v[n-1][1];
dp[n-1][2]= v[n-1][2];
dpp(0,0);dpp(0,1);dpp(0,2);
cout<<max(dp[0][0],max(dp[0][1],dp[0][2]));
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll h,w,d;
    cin >> h >> w >> d;
    vector<vector<ll>> a(h,vector<ll>(w));
    unordered_map<ll,pair<ll,ll>> mapa; 
    for(i = 0;i < h;++i){
        rep(j,w){
            cin >> a.at(i).at(j);
            mapa[a.at(i).at(j)] = make_pair(i,j); 
        }
    }
    vector<ll> ruiseki(h*w+1,0);
    for(i = 1;i <= d;++i){
        for(j = i+d;j <= h*w;j += d){
            ll tmp = abs(mapa[j].first - mapa[j-d].first) + abs(mapa[j].second - mapa[j-d].second);
            ruiseki.at(j) = ruiseki.at(j-d) + tmp; 
        }
    }
    ll q;
    cin >> q;
    for(i = 0;i < q;++i){
        ll l,r;
        cin >> l >> r;
        cout << ruiseki.at(r) - ruiseki.at(l) << endl;
    }

    return 0;
}

Measured memory_bytes: 9444
K = int(input())

if K <= 9:
    print (K)
    exit()

lst = [[1] * 11 for _ in range(2)]

lst[0][10] = 0
lst[1][0] = 0
lst[1][10] = 0

now = 9
p = 0
flag = 0
while True:
    if p == 0:
        lst[flag + 1][0] = lst[flag][0] + lst[flag][1]
        p += 1
        continue
    tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1]
    lst[flag + 1][p] = tmp
    if now + tmp >= K:
        break
    now += tmp
    p += 1

    if p == 10:
        p = 0
        flag += 1
        lst.append([0] * 11)

# print ('now', now)
# print ('p', p)
# print ('flag', flag)
# print (lst[0])
# print (lst[1])

#先頭がpでかつ現在地がnow
ans = str(p)
flag += 1
while True:
    if flag == 0:
        break
    # print (p)
    if p >= 1 and K <= now + lst[flag - 1][p - 1]:
        flag -= 1
        ans += str(p - 1)
        p -= 1
    elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]:
        now += lst[flag - 1][p - 1]
        flag -= 1
        ans += str(p)
    else:
        now += lst[flag - 1][p - 1] + lst[flag - 1][p]
        flag -= 1
        ans += str(p + 1)
        p += 1

print (ans)

# for tmp in lst:
#     print (tmp)
    

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

using namespace std;

long long cost(vector<int> X, int p) {
    long long ans = 0;
    for (auto x : X) {
        ans += (x - p) * (x - p);
    }
    return ans;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int C = 0;
    int F = 0;
    auto ok1 = [&]() {
        return C < A + B;
    };
    auto ok2 = [&]() {
        return ok1() && F < B;
    };
    auto chk_inc = [&](char c) {
        if (c == 'a') {
            bool f = ok1();
            if (f)C++;
            return f;
        } else if( c == 'b'){
            bool f = ok2();
            if (f)C++, F++;
            return f;
        }else{
            return false;
        }
    };
    for(int i = 0 ; i < N ; i++){
        char c;
        cin >> c;
        cout << (chk_inc(c) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int main() {
  string s;
  cin >> s;
  int n = s.length();
  int ans = INF;
  for (int i = 0; i + 2 < n; ++i) {
    int num = 0;
    rep(j, 3) {
      num *= 10;
      num += s[i + j] - '0';
    }
    chmin(ans, abs(753 - num));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
# 
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a=ni()
b=ni()

if a>b:
    print('GREATER')
elif a==b:
    print('EQUAL')
elif a<b:
    print('LESS')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in); 
		//int型の値を返す
		int a = scanner.nextInt();
		//int型の値を返す
		int b = scanner.nextInt();
		//入力された2つのint型の値の大小を比較してString型で返す(3, 4 => "a < b")
		String ans = compare(a, b);
		//返されたString型を出力をする
		System.out.println(ans);
	}
	/**
	 * 入力された2つのint型の値の大小を比較してString型で返す
	 * (a より b の方が大きければ => a < b)
	 * (a より b の方が小さければ => a > b)
	 * (a と b が等しければ => a == b)
	 * @param int a
	 * @param int b
	 * @return String ans
	 */
	public static String compare(int a, int b) {
		String ans = "";
		if(a < b){
			ans = "a < b";
		}else if(a > b){
			ans = "a > b";
		}else{
			ans = "a == b";
		}
		return ans;
	}
}

/**
 * 2つのint型の値を入力する
 * 入力された2つのint型の値の大小を比較してString型で返す(3, 4 => "a < b")
 * 返されたString型を出力をする
 */

Measured memory_bytes: 17296
io = STDIN
N=io.gets.to_i
W=io.gets.split.map(&:to_i)
sum=W.inject(&:+)
ans=100
(0..(N-2)).each do |t|
  s1=W[0..t].inject(&:+)
  ans=[(s1-(sum-s1)).abs,ans].min
end
p ans


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

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define MOD 1000000007
#define INF 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y) 
#define mem(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin>>n;
	ll arr[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
	}

	sort(arr,arr+n);

	for (int i = 1; i < n; ++i)
	{
		if(arr[i]==arr[i-1]){
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES\n";

	return 0;
}

Measured memory_bytes: 1792
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, k;
  rd(n, k);
  auto a = readln.split.to!(long[]);

  long[] bits;
  foreach (i; 0 .. n) {
    long s = 0;
    foreach (j; i .. n) {
      s += a[j];
      bits ~= s;
    }
  }
  auto good = new bool[](bits.length);
  fill(good, true);
  foreach_reverse (i; 0 .. 42) {
    int m = 0;
    foreach (j, bit; bits) {
      if (good[j]) {
        if (bit & (1L << i)) {
          m++;
        }
      }
    }
    if (m >= k) {
      foreach (j, bit; bits) {
        if (good[j]) {
          if (!(bit & (1L << i))) {
            good[j] = false;
          }
        }
      }
      if (m == k) {
        long ans = (1L << 42) - 1;
        foreach (j, bit; bits) {
          if (good[j]) {
            ans &= bit;
          }
        }
        writeln(ans);
        return;
      }
    }
  }
  long ans = (1L << 42) - 1;
  foreach (j, bit; bits) {
    if (good[j]) {
      ans &= bit;
      if (--k == 0) {
        writeln(ans);
        return;
      }
    }
  }
  import std.exception : enforce;

  enforce(false);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 6780
n,T=map(int,input().split())
t=list(map(int,input().split()))

tn=T
ans=T
for i in range(n):
    if tn <= t[i]:
        ans+=T
        tn=t[i]+T
    else:
        ans+=(T-(tn-t[i]))
        tn=t[i]+T
print(ans)


Measured memory_bytes: 25200
import java.util.Scanner;

public class Main {

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

			final long n = sc.nextLong();

			long ceil = (long) (n/1000);
			if(ceil*1000<n) {
				ceil++;
			}
			System.out.println((ceil*1000)-n);
		}
	}
}

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

int main(){
    long int N,M,L,a,b;
    cin>>N>>M;

    if(N==0){
        if(1868<=M&&M<=1911){
            a=44-(1911-M);
            cout<<"M"<< a <<endl;
        }
        if(1911<M&&M<=1925){
            a=14-(1925-M);
            cout<<"T"<< a <<endl;
        }
        if(1925<M&&M<=1988){
            a=63-(1988-M);
            cout<<"S"<< a <<endl;
        }
        if(1988<M&&M<=2016){
            a=28-(2016-M);
            cout<<"H"<< a <<endl;
        }
    }
        else if(N==1){
            b=1867+M;
            cout<< b <<endl;
        }
        else if(N==2){
            b=1911+M;
            cout<< b <<endl;
        }
        else if(N==3){
            b=1925+M;
            cout<< b <<endl;
        }
        else if(N==4){
            b=1988+M;
            cout<< b <<endl;
        }
        
    
    return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
#define MAX 9

void set(int map[MAX][MAX], int i, int j, int n, int *counter){
	if(i >= n || j >= n){return;}
	map[i][j] = *counter;
	(*counter)++;
}

int main(void){
	int map[MAX][MAX];
	int i,j,l,n,counter;
	int caseNum = 1;
	while(scanf("%d",&n) != EOF){
		if(n == 0){break;}
		counter = 1;
		for(l = 0; l < 2 * n; l++){
			if(l % 2 == 0){
				i = l;
				j = 0;
				while(1){
					set(map,i,j,n,&counter);
					if(i == 0 || i == j && i == n-1){
						break;
					}
					i--;
					j++;
				}

			}else{
				i = 0;
				j = l;
				while(1){
					set(map,i,j,n,&counter);
					if(j == 0 || i == j && i == n-1){
						break;
					}
					i++;
					j--;
				}
			}
		}
		printf("Case %d:\n",caseNum);
		for(i = 0; i < n; i++){
			for(j = 0; j < n; j++){
				printf("%3d",map[i][j]);
			}
			putchar('\n');
		}
		caseNum++;
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
cn = n//2
lis = list(map(int,input().split()))
slis = sorted(lis)
if slis[cn-1] == slis[cn]:
	for i in range(len(lis)):
		print(slis[cn])
else:
	for item in lis:
		if item >= slis[cn]:
			print(slis[cn-1])
		else:
			print(slis[cn])

Measured memory_bytes: 26016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "No";
            if (sS[0] == sS[1] && sS[1] == sS[2]) { }
            else if (sS[0] != sS[1] && sS[1] != sS[2] && sS[2] != sS[0]) { }
            else { sOut = "Yes"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

#define MAX 100005
int n, dist1[MAX], dist2[MAX], u[MAX], v[MAX];
vector<int> x[MAX];

void dfs1(int pos, int depth){
	if(dist1[pos]!=-1) return;
	dist1[pos]=depth;
	for(int i=0; i<x[pos].size(); i++){ 
		dfs1(x[pos][i], depth+1);
	}
}

void dfs2(int pos,int depth){
	if(dist2[pos]!=-1) return;
	dist2[pos]=depth;
	for(int i=0; i<x[pos].size(); i++){
		dfs2(x[pos][i], depth+1);
	}
}

signed main(){
	cin>>n;
	for(int i=0; i<n-1; i++){
		int a,b;
		cin>>a>>b;
		x[a].push_back(b);
		x[b].push_back(a);
	}
	for(int i=0; i<100003; i++){
		dist1[i]=-1;
		dist2[i]=-1;
	}
	dfs1(1, 0); dfs2(n, 0);
	int cnt1=0,cnt2=0;
	for(int i=1; i<=n; i++){
		if(dist1[i]<=dist2[i]) cnt1++;
		else cnt2++;
	}
	if(cnt1>cnt2) cout<<"Fennec"<<en;
	else cout<<"Snuke"<<en;
}


Measured memory_bytes: 13568
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n , a , b ;
    cin >> n >> a >> b ;
    vector<int> v(n) ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    sort(v.begin(), v.end()) ;
    int ans = 0 ;
    for(int i = 1; i < n; i++){
        int diff = v[i] - v[i - 1] ;
        ans += min(a * diff, b) ;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int n,ans,num,a[100005];
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1,a + n + 1);
	for(int i = 1; i <= n + 1; i++)
		if(a[i] != a[i - 1]) {
			ans += num & 1;
			num = 1;
		} else
			num++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//BELOW

void solve(void)
{ 
  int N;
  cin>>N;
  vector<vector<int> > GRAPH (N);
  for (int i = 0; i < N-1; i++)
  {
    int A,B;
    cin>>A>>B;
    A--;B--;
    GRAPH[A].push_back(B);
    GRAPH[B].push_back(A);
  }
  set<pair<int,int> > SET;
  vector<int> Vdata(N,0);
  for (int i = 0; i < N; i++)
  {
    SET.insert(make_pair(GRAPH[i].size(),i));
    Vdata[i] = GRAPH[i].size();
  }
  
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  sort(ALL(vec));
  reverse(ALL(vec));
  int res = 0;
  vector<pair<int,int > > E;
  for (int i = 0; i < N; i++)
  {
    E.emplace_back(GRAPH[i].size(),i);
  }
  sort(ALL(E));
  reverse(ALL(E));
  vector<int> NUM(N,-1);
  for (int i = 1; i < N; i++)
  {
    res += vec[i];
  }
  int S = E[0].second;
  deque<int> q;
  q.push_back(S);
  int cnt = 0;
  NUM[S] = vec[cnt];
  cnt++;
  while(!q.empty())
  {
    int V = q.front();
    q.pop_front();
    for (auto &&nV : GRAPH[V])
    {
      if(NUM[nV] != -1)continue;
      NUM[nV] = vec[cnt];
      cnt++;
      q.push_back(nV);
    }
    
  }
  
  
  cout<<res<<endl;
  for (int i = 0; i < NUM.size(); i++)
  {
      if(i != 0)cout<<char(32);
      cout<<NUM[i];
  }
  cout<<endl;

  
  

  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 4976
#include <bits/stdc++.h>
#define pb push_back
#define getarray(a,n)  for(int i=0;i<n;i++) cin>>a[i]
#define ll long long
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vi vector<int>
#define w(t) int t;cin>>t;while(t--)
using namespace std;

int main()
{
    fast
    //n stones
    int n;
    cin >> n;
    int height[n]; //here we are given height of all n stones
    getarray(height, n);
    vector<int> dp(n, 0); //dp array
    dp[0] = 0; //since we are on 0 stone
    dp[1] = abs(height[1] - height[0]); //the best we can do to reach stone 2
    for (int i = 2; i < n; i++) // this is bascially a bottom up approach cause we building from the bottom to the top
    {
        dp[i] = min(dp[i - 1] + abs(height[i] - height[i - 1]), dp[i - 2] + abs(height[i] - height[i - 2]));
    }
    //bascially we are just checking the best we can do to reach at a particular stone i

    cout << dp[n - 1];



    return 0;
}


Measured memory_bytes: 3968
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

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

const int N = 1e5 + 10; 
int p[N], cnt, n, m; 

int find(int u) {
    return p[u] == u ? u : p[u] = find(p[u]);
}

int main(int argc, char const *argv[]) {
    scanf("%d %d", &n, &m); 

    for(int i = 1; i <= n; ++i) p[i] = i; 
    cnt = n; 

    while(m--) {
        int u, v, w;
        scanf("%d %d %*d", &u, &v);

        u = find(u), v = find(v); 
        if(u != v) {
            p[u] = v; 
            --cnt; 
        }
    }

    printf("%d\n", cnt);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/

struct UnionFind{
	vl par,dist;
	UnionFind(int x){par.assign(x,-1); dist.assign(x,0);}
	ll find(ll x){return par[x]<0?x:find(par[x]);}
	ll depth(ll x){return par[x]<0?0:depth(par[x])+dist[x];}
	bool same(ll x,ll y){return find(x)==find(y);}
	ll size(ll x){return -par[find(x)];}
	ll diff(ll x,ll y){return same(x,y)?depth(x)-depth(y):LINF;}
	void unite(ll x,ll y,ll k=0){
		k+=depth(y); k-=depth(x); k=-k;
		x=find(x); y=find(y);
		if(x==y)return;
		if(size(x)<size(y)){swap(x,y);k=-k;}
		par[x]+=par[y]; par[y]=x; dist[y]=k;
	}
};
ll g(ll a){
	return (a*(a-1)/2);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vl a(m),b(m);
	rrep(i,m)cin>>a[i]>>b[i];

	UnionFind uf(n);
	vl ans(m+1,0);
	rep(i,m){
		a[i]--; b[i]--;
		if(uf.same(a[i],b[i])){
			ans[i+1]=ans[i];
			continue;
		}
 		ll t=g(uf.size(a[i]))+g(uf.size(b[i]));
		uf.unite(a[i],b[i]);
		ans[i+1]=ans[i]-t+g(uf.size(a[i]));
	}
	rrep(i,m){
		puta(g(n)-ans[i]);
	}
	//puta(ans);
	return 0;
}

Measured memory_bytes: 5248
def check(list1):
    if(list1[0][0]==0 and list1[1][1]==0 and list1[2][2]==0):
        return "Yes"
    if(list1[1][1]==0 and list1[0][2]==0 and list1[2][0]==0):
        return "Yes"
    for i in range(3):
        count=0
        for j in range(3):
            if(list1[i][j]==0):
                count+=1
        if(count==3):
            return "Yes"
    for i in range(3):
        count=0
        for j in range(3):
            if(list1[j][i]==0):
                count+=1
        if(count==3):
            return "Yes"
    return "No" 
list1=[]
for i in range(3):
    list2=list(map(int,input().strip().split()))[:3]
    list1.append(list2)
n=int(input())
list3=[]
for i in range(n):
    list3.append(int(input()))
for i in list3:
    for j in range(3):
        for k in range(3):
            if(list1[j][k]==i):
                list1[j][k]=0
print(check(list1))



Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <bitset>
#include <iostream>
using namespace std;
const int MAXN = 100;
const long long mod =1e9;
int n,m,T;
long long ans=0,S,x1,x2,x3,yy1,y2,y3;
int main(){
    cin>>S;
    x1=0;yy1=0;
    x2=sqrt(S);
    if(x2*x2==S) {
        printf("0 0 0 %lld %lld 0\n",x2,x2);
        return 0;
    }
    if(x2*x2<S)   x2++;
    y2=1;
    y3=x2;
    x3=x2*y3-S;
    if(x3>mod) {
        y2=1;
        y3=x2-1;
        x3=x2*y3-S;
    }
    cout<<x1<<' '<<yy1<<' '<<x2<<' '<<y2<<' '<<x3<<' '<<y3<<endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	// test();

	int A, B;
	cin >> A >> B;
	if (0<A && A<10 && 0<B && B<10)
	{
		cout << A * B;
		return 0;
	}
	cout << "-1";
	
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner( System.in);
		String  x;
		int i=0,j=0;
		int a=stdin.nextInt();
		x =stdin.next();
		for(int k=1;k<=x.length();k++){
			String xx=x.substring(k-1,k);
			if(xx.equals("(")){i++;
			}else{i--;
			}
			if(i<0){
				j++;
				i=0;
			}
		}
		for(int f=0;f<j;f++)System.out.print("(");
		System.out.print(x);
		for(int f=0;f<i;f++)System.out.print(")");
	}
}




Measured memory_bytes: 23124
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()

	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i] = nextInt()
	}

	right := 0
	left := 0
	ans := 1 << 60
	for i := 0; i+k-1 < n; i++ {
		left = x[i]
		right = x[i+k-1]
		ans = min(ans, min(abs(left), abs(right))+right-left)
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -1 * a
	}
	return a
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}
template <typename T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}

struct Graph {
    struct Edge {int to; ll cost;};
    vector<vector<Edge>> G;
    Graph(int V): G(V) {}
    Graph(int V, int E, bool weighted = false, bool directed = false): G(V) {
        REP(i, E) {
            int u, v;
            ll c = 1;
            cin >> u >> v;
            if (weighted) cin >> c;
            // --u; --v;
            G[u].push_back(Edge{v, c});
            if (!directed) G[v].push_back(Edge{u, c});
        }
    }
    void AddEdge(int from, int to, ll cost = 1, bool directed = false) {
        G[from].push_back(Edge{to, cost});
        if (!directed) G[to].push_back(Edge{from, cost});
    }
    const vector<Edge> &operator[](int n) {
        return G[n];
    }
};

vector<ll> dijkstra(Graph &G, int s) {
    vector<ll> dist(SZ(G.G), INF);
    vector<bool> used(SZ(G.G), false);
    priority_queue<pair<ll, int>> pq;
    dist[s] = 0;
    pq.push(pair<ll, int>(0, s));
    while (!pq.empty()) {
        int v = pq.top().second;
        pq.pop();
        if (used[v]) continue;
        for (auto &e: G[v]) {
            if (chmin(dist[e.to], dist[v] + e.cost)) pq.push(pair<ll, int>(-dist[e.to], e.to));
        }
        used[v] = true;
    }
    return dist;
}

int main() {
    int v, e, r;
    cin >> v >> e >> r;
    Graph G(v, e, true, true);
    auto d = dijkstra(G, r);
    REP(i, v) {
        if (d[i] == INF) cout << "INF\n";
        else cout << d[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 19428
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

const ll INF = 100100100;

int main(){
    ll n; cin >> n;
    ll u, v; cin >> u >> v; u--; v--;
    vector<vector<ll>> G(n);
    rep(i,n-1){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    vector<ll> da(n,INF), db(n,INF);
    
    da[v] = 0;
    queue<ll> que1; que1.push(v);
    while(!que1.empty()){
        ll p = que1.front(); que1.pop();
        for(auto nv : G[p]){
            if( da[nv] <=  da[p]+1 ) continue;
            da[nv] = da[p] + 1;
            que1.push(nv);
        }
    }

    db[u] = 0;
    queue<ll> que2; que2.push(u);
    while(!que2.empty()){
        ll p = que2.front(); que2.pop();
        for(auto nv : G[p]){
            if( db[nv] <=  db[p]+1 ) continue;
            db[nv] = db[p] + 1;
            que2.push(nv);
        }
    }

    if(G[u].size() == 1 && G[u][0] == v){ cout << 0 << endl; return 0; }

    ll ans = 0;
    rep(i,n){
        if(da[i] > db[i]){
            if(da[i]-1 > ans) ans = da[i]-1;
        }
    }
    cout<< ans << endl;
}

Measured memory_bytes: 10896
import java.util.Scanner;

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

    while (in.hasNext()) {
      int N = in.nextInt();
      char[] S = in.next().toCharArray();
      char currSlimeColor = S[0];
      int countRemain = 1;
      
      for (int i = 1; i < S.length; ++i) {
        if (S[i] != currSlimeColor) {
          ++countRemain;
          currSlimeColor = S[i];
        }
      }

      System.out.println(countRemain);
    }
  }
}

Measured memory_bytes: 26272
MOD = 10**9+7
def cmb(n, r):
  if r < 0 or n < r:
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % MOD

N, K = list(map(int, input().split()))

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N+1 + 1):
  fact.append((fact[-1] * i) % MOD)
  inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
  factinv.append((factinv[-1] * inv[-1]) % MOD)


res = 0

max_sum = 0
min_sum = 0
for i in range(K):
  max_sum += N-i
  min_sum += i

for i in range(N+1+1)[K:]:
  res += (max_sum - min_sum)+1
  max_sum += N-i
  min_sum += i

print(res%MOD)

Measured memory_bytes: 110500
import collections
n = int(input())
p = list((map(int,input().split())))
x = collections.Counter(p)
y = [i[0] for i in x.items() if i[1]>=2]
z = [i[0] for i in x.items() if i[1]>=4]
y.sort(reverse=True)
y.append(0)
y.append(0)
z.sort(reverse=True)
z.append(0)
ans = y[0]*y[1]
ans1 = z[0]*z[0]
if ans1 > ans:
    ans =ans1
print(ans)


Measured memory_bytes: 18600
//abc121_d.cpp
//Wed Jun 12 22:35:27 2019

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

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

	ll ans = 0;
	for (int i=1;i<41;i++){
		ll x = pow(2,i);
		ll y = pow(2,i-1);
		if (m<y){
			break;
		}
		ll temp1 = 0;
		if ((m+1)%x-y>=0){
			temp1 = (m+1)%x-y+(((m+1)-(m+1)%x)/x)*y;
		}else{
			temp1 = (((m+1)-(m+1)%x)/x)*y;
		}
		ll temp2 = 0;
		if (n%x-y>=0){
			temp2 = n%x-y+((n-n%x)/x)*y;
		}else{
			temp2 = ((n-n%x)/x)*y;
		}
//		cout << i << " " << temp1 << " " << temp2 << endl;
		if ((temp1-temp2)%2==1){
			ans += y;
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 62;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    string S;
    llong k;
    cin >> S >> k;

    llong cnt = 1, ans = 0;
    if (S[0] == S[(int)S.size() - 1]) {
        bool flag_all_same_char = true;
        for (int i = 0; i < (int)S.size() && flag_all_same_char; ++i) {
            if (S[i] != S[0]) {
                flag_all_same_char = false;
            }
        }

        if (flag_all_same_char) {
            ans = (int)S.size() * k / 2;
        } else {
            llong tmp1 = 1, tmp2 = 1;
            for (int i = 0; i < (int)S.size() - 1; ++i) {
                if (S[i] == S[i + 1]) ++tmp1;
                else break;
            }
            for (int i = (int)S.size() - 1; i > 0; --i) {
                if (S[i] == S[i - 1]) ++tmp2;
                else break;
            }

            for (int i = tmp1; i < (int)S.size() - tmp2; ++i) {
                if (S[i] == S[i + 1]) {
                    ++cnt;
                } else {
                    ans += (cnt / (llong)2) * k;
                    cnt = (llong)1;
                }
            }
            ans += (cnt / (llong)2) * k;

            ans += tmp1 / 2 + tmp2 / 2;
            ans += ((tmp1 + tmp2) / 2) * (k - 1);
        }
    } else {
        for (int i = 0; i < (int)S.size(); ++i) {
            if (S[i] == S[i + 1]) {
                ++cnt;
            } else {
                // cout << S[i] << " " << S[i + 1] << " " << cnt << endl;
                ans += (cnt / (llong)2) * k;
                cnt = (llong)1;
            }
        }
        ans += (cnt / (llong)2) * k;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<int64_t, int> A;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        A[a]++;
    }

    int ans = 0;
    for (int64_t b = 1L << 31; b > 0; b >>= 1L){
        for (auto &a: A){
            auto k = a.first;
            auto v = a.second;
            if (A.count(b - k) == 0)
                continue;
            if (b - k == k){
                ans += A[k] / 2;
                A[k] = A[k] & 1;
                continue;
            }
            int mi = min(A[k], A[b - k]);
            ans += mi;
            A[k] -= mi;
            A[b - k] -= mi;
        }
    }

    cout << ans << endl;
}

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

int main(){
    int N,a=0;
    cin>>N;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        if(A[i]%2==0){
            if(A[i]%3==0||A[i]%5==0){
                    a=a;
                }else{
                    a+=1;
                }
        }
    }
    if(a==0){
        cout<<"APPROVED"<<endl;
    }else{
        cout<<"DENIED"<<endl;
    }
}

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


int main() {
    
    int k; cin >> k;
    string s; cin >> s;
    if(s.size() <= k){
        cout << s << endl;
        return 0;
    }
    else {
        cout << s.substr(0, k);
        cout << "..." << endl;
        return 0;
    }
}





Measured memory_bytes: 3652
#include <string>
#include <iostream>
using namespace std;
bool solve(long long x) {
	string res;
	cout << "? " << x << endl;
	cin >> res;
	return res == "Y" ? true : false;
}
void answer(long long x) {
	cout << "! " << x << endl;
}
int main() {
	if (solve(1000000000)) {
		long long mul = 10;
		while (true) {
			if (!solve(mul - 1)) mul *= 10;
			else {
				answer((mul + 1) / 10);
				break;
			}
		}
	}
	else {
		long long mul = 1;
		while (true) {
			if (solve(mul)) mul *= 10;
			else {
				mul /= 10;
				break;
			}
		}
		long long l = mul - 1, r = mul * 10 - 1;
		while (r - l > 1) {
			long long m = (l + r) >> 1;
			if (solve(m * 10)) r = m;
			else l = m;
		}
		answer(r);
	}
	return 0;
}

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

Measured memory_bytes: 1644
import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    readLine.trim.toList match {
      case '#'::Nil ⇒ return
      case l ⇒
        val suspects = ('b' to 'z').foldRight(List(l)){case (target, list) ⇒ list.flatMap(makeSuspects(_, target))}.map(_.mkString("")).sorted.toArray
        println(suspects.length)
        if (suspects.length > 10) {
          suspects.take(5).foreach(println)
          suspects.takeRight(5).foreach(println)
        }else {
          suspects.foreach(println)
        }
    }
    loop()
  }
  def makeSuspects(current: List[Char], target: Char): List[List[Char]] = {
    current match {
      case `target`::_ ⇒ Nil
      case h::t if h + 1 == target ⇒ (target::t)::makeSuspects(t, target).map(h::_)
      case h::t ⇒ makeSuspects(t, target).map(h::_)
      case Nil ⇒ List(Nil)
    }
  }
}


Measured memory_bytes: 463128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

		 int n = s.nextInt();
		 String[] str = new String[n];
		 Map map = new HashMap();

		 for(int i=0; i<n; i++) {
			 str[i] = s.next();
		 }

		 map.put("AC", new Integer(0));
		 map.put("WA", new Integer(0));
		 map.put("TLE", new Integer(0));
		 map.put("RE", new Integer(0));

		 for(int i=0; i<n; i++) {
			 Integer tmp = (Integer)map.get(str[i]);
			 Integer val = tmp + 1;
			 map.put(str[i], val);
		 }

		 System.out.println("AC x " + (Integer)map.get("AC"));
		 System.out.println("WA x " + (Integer)map.get("WA"));
		 System.out.println("TLE x " + (Integer)map.get("TLE"));
		 System.out.println("RE x " + (Integer)map.get("RE"));
	}

}

Measured memory_bytes: 54788
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,d=0,e,f,g=0;
  cin>>a;
  vector<int> b(a+1),c(a);
  fo(i,a+1)
    cin>>b[i];
  fo(i,a+1)
    g+=b[i];
  fo(i,a)
    cin>>c[i];
  for(int i=0;i<a;i++){
    e=b[i];
    f=c[i];
    b[i]=max<int>(b[i]-c[i],0);
    b[i+1]=max<int>(0,b[i+1]-max<int>(f-e,0));
  }
  fo(i,a+1)
    d+=b[i];
  cout<<g-d<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a)  a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define _for(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)

using namespace std;

int N, A, B;

int main(){
   cin >> N >> A >> B;
   string s;
   cin >> s;
   int total = 0;
   int overseas = 0;
   int b = 0;
   for(int n = 0; n < s.sz; ++n){
      if(s[n] == 'a'){
         if(total < (A + B)){
            printf("Yes\n");
            ++total;
         }
         else{
            printf("No\n");
         }
      }
      else if(s[n] == 'b'){
         ++overseas;
         if((total < (A + B)) && overseas <= B){
            printf("Yes\n");
            ++total;
         }
         else{
            printf("No\n");
         }
      }
      else{
         printf("No\n");
      }
   }
}

Measured memory_bytes: 896
import sys
A,B,C,K = map(int,(input().split()))
point = 0

if(K<=A):
  point=K
  print(point)
  sys.exit()
else:
  point+=A
  K-=A

if(K<=B):
  print(point)
  sys.exit()
else:
  K-=B
  point-=K
  print(point)

Measured memory_bytes: 9188
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
 
using namespace std;
 
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c)
    {
        cout << "Yes" << endl;
    }
    else if(b + c == a)
    {
        cout << "Yes" << endl;
    }
    else if (a + c == b)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 401000;
int fa[N],n,val[N],f[N],nxt[N],tail[N];
struct node{int k1,k2,num;}p[N];
vector<int> ans;
bool operator < (node a,node b){
	return 1ll*a.k1*b.k2<1ll*b.k1*a.k2||1ll*a.k1*b.k2==1ll*b.k1*a.k2&&a.num<b.num;
}
bool operator == (node a,node b){
	return 1ll*a.k1*b.k2==1ll*b.k1*a.k2&&a.num==b.num;
}
struct Heap{
	priority_queue<node> q,p;
	void push(node a){q.push(a);}
	void erase(node b){p.push(b);}
	bool empty(){
		while(!q.empty()&&!p.empty()&&q.top()==p.top()) q.pop(),p.pop();
		return q.empty();
	}
	node top(){
		empty();
		return q.top();
	}
	void pop(){
		empty();q.pop();
	}
}H;
int find(int x){return f[x]= f[x]==x?x:find(f[x]);}
void print(int y){
	while(y) cout<<y<<' ',y=nxt[y];
	cout<<'\n';
}
int main(){
	read(n);
	for(int i=2;i<=n;i++)
		read(fa[i]);
	for(int i=1;i<=n;i++){
		read(val[i]),f[i]=i,p[i]={!val[i],1,i};
		nxt[i]=0;tail[i]=i;
		H.push(p[i]);
	}
	while(!H.empty()){
		node u=H.top();H.pop();
		int x=u.num;
		if(!find(fa[x])){
			f[x]=0;
			while(x) ans.push_back(val[x]),x=nxt[x];
		}
		else{
			int y=find(fa[x]);
			H.erase(p[y]);
			p[y].k1+=p[x].k1;
			p[y].k2+=p[x].k2;
			H.push(p[y]);
			f[x]=y;
			nxt[tail[y]]=x;
			tail[y]=tail[x];
		//	print(y);
		}
	}
	ll sum=0,now=0;
	for(int x:ans)
		if(x==1) now++;
		else sum+=now;
	cout<<sum<<'\n';
	return 0;
}


Measured memory_bytes: 20848
# 優先度付きキュー(priority queue)のクラス。最小ヒープ木による実装
# 最小ヒープ(つまり親ノードは子ノードよりも小さい)なので、根にあるのは最小値(もし、最大ヒープであれば根は最大値になる)
# 優先度付きキューとして持っている機能は、
# 1.キューに対して要素を優先度付きで追加する。(push)
# 2.最も高い優先度を持つ要素をキューから取り除き、それを返す。(pop)
# 3.最も高い優先度を持つ要素を取り除くことなく参照する。(peek)
# また、sum(内部的にはinject)があるので、合計値の算出に使うと圧倒的に速い
# 持っていない機能は
# 1.指定した要素を取り除くことなく優先度を変更する
class Heap
  attr_reader :size
  def initialize
    @heap = []
    @size = 0
  end
  def sum
    @heap.inject(:+)
  end
  def push(n)
    i = @size
    while i > 0
      pid = (i - 1) / 2
      break if n >= @heap[pid]
      @heap[i] = @heap[pid]
      i = pid
    end
    @heap[i] = n
    @size += 1
  end
  def pop
    top = @heap[0]
    @size -= 1
    n = @heap[@size]
    i = 0
    while i * 2 + 1 < @size
      cid1 = i * 2 + 1
      cid2 = cid1 + 1
      if cid2 < @size && @heap[cid2] < @heap[cid1]
        cid1 = cid2
      end
      break if @heap[cid1] >= n
      @heap[i] = @heap[cid1]
      i = cid1
    end
    @heap[i] = n
    top
  end
  def peek
    @heap[0]
  end
end

def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, m = input_a
a = input_a

# 優先度付きキューの作成
q = Heap.new

# 優先度付きキューに値を順次追加(内部で成型するのでsortせずに突っ込む)
# 今回の場合は、最大値を取り出して操作したいので、入力する値すべてにマイナスをかけて、最小値/最大値を反転する
a.each do |num|
  q.push(-num)
end

# 最大金額の商品を順次取り出し、割引券で金額を半分にしていく
# この時、取り出した値はマイナスであるため、2で除算する前にマイナスをかけてプラスに戻しておき、pushする際はまたマイナスに戻す
# ※なぜマイナスからプラスに戻すのかは、例えば「3 / 2 = 1」だが「-3 / 2 = -2」となり、小数点の処理がプラスマイナスで違うから
m.times do
  max = q.pop
  q.push(-(-max / 2))
end

puts -q.sum

Measured memory_bytes: 9484
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Function;

public class Main {

	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		
		for(;;){
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int x = sc.nextInt();
			
			if((n|a|b|c|x) == 0){
				break;
			}
			
			Queue<Integer> y = new ConcurrentLinkedQueue<Integer>();
			for(int i =0 ; i< n ; i++){
				y.add(sc.nextInt());
			}
						
			Function<Integer,Integer> next = xx -> (a*xx+b)%c;
			
			System.out.println(solve(next,x,y));
		}
	}
	
	
	int solve(final Function<Integer,Integer> nextNum, int x, Queue<Integer>y){		
		int c_ = 0;
		final int MAX = 10000;
		for(;c_ <= MAX; c_++,x = nextNum.apply(x)){
			if(x == y.peek()){
				y.poll();
				if(y.isEmpty()) {
					break;
				}
			}
		}
		return y.isEmpty()? c_ :-1;
	}
}

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

int main () {
  
  int N, M;
  cin >> N >> M;
  
  vector<pair<int, int>> P(N);
  int A, B;
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    P[i] = make_pair(A, B);
  }
  
  sort(P.begin(), P.end());
  
  long long ans = 0;
  
  for (int i = 0; i < N; i++) {
    int buy = min(M, P[i].second);
    ans += P[i].first * (long long)buy;
    M -= buy;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1024