akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
char ans[100003];
char out[100003];

char same(char c) {
	return c == 'S' ? 'S' : 'W';
}
char diff(char c) {
	return c == 'S' ? 'W' : 'S';
}

void assign(int i) {
	if (out[i] == 'S' && ans[i] == 'o') {
		out[i + 1] = same(out[i - 1]);
	}
	else if (out[i] == 'S' && ans[i] == 'x') {
		out[i + 1] = diff(out[i - 1]);
	}
	else if (out[i] == 'W' && ans[i] == 'o') {
		out[i + 1] = diff(out[i - 1]);
	}
	else {
		out[i + 1] = same(out[i - 1]);
	}
}

bool check(int i) {
	char ret;
	if (out[i] == 'S' && ans[i] == 'o') {
		ret = same(out[(i - 1 + n) % n]);
	}
	else if (out[i] == 'S' && ans[i] == 'x') {
		ret = diff(out[(i - 1 + n) % n]);
	}
	else if (out[i] == 'W' && ans[i] == 'o') {
		ret = diff(out[(i - 1 + n) % n]);
	}
	else {
		ret = same(out[(i - 1 + n) % n]);
	}
	return out[(i + 1) % n] == ret;
}

void proc() {
	scanf("%d", &n);
	scanf("%s", ans);

	for (char a : { 'S', 'W' }) {
		for (char b : { 'S', 'W' }) {
			out[0] = a;
			out[1] = b;
			for (int i = 1; i + 1 < n; ++i) {
				assign(i);
			}

			if (check(n - 1) && check(0)) {
				printf("%s", out);
				return;
			}
		}
	}
	printf("-1");
}

int main() {
	//freopen("input.txt", "r", stdin);
	proc();
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
using namespace std;
string  lcsPUREDP(string s1,string s2){
	int row = s1.length()+1;
	int col = s2.length()+1;
	vector<vector<int>> dp(row,vector<int>(col,0));
	for(int i=0;i<row;i++){
		dp[i][col-1] = 0;
	}
	for(int i=0;i<col;i++){
		dp[row-1][i] = 0;
	}
	for(int i=row-2;i>=0;i--){
		for(int j=col-2;j>=0;j--){
			if(s1[i]==s2[j]){
				dp[i][j] = dp[i+1][j+1] +1;
			}
			else{
				int a = dp[i+1][j];
				int b = dp[i][j+1];
				dp[i][j] = max(a,b);
			}
		}
	}
	string s = "";
	int i = 0;
	int j = 0;
	while(i<row-1 and j<col-1){
		if(s1[i]==s2[j]){
			s = s + s1[i];
			i++;
			j++; 
		}
		else{
			if(dp[i+1][j]>dp[i][j+1]){
				i++;
			}
			else{
				j++;
			}
		}
	}
	return s;
	

}
int main() {
	string s1,s2;
	cin>>s1>>s2;
	int n = s1.length();
	int m = s2.length();
	
	cout<<lcsPUREDP(s1,s2)<<endl;
	//cout<<"ac"<<endl;
	return 0;
}

Measured memory_bytes: 38880
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
sumA = 0
for x in range(N):
    if x == 0:
        sumA += 0
    elif x == 1:
        sumA += A[0]
    else:
        div, mod = divmod(x - 1, 2)
        sumA += A[div + mod]
print(sumA)


Measured memory_bytes: 94208
def find_sum_of_digits(n):
    total = 0
    while n > 0:
        total += n % 10
        n //= 10
    return total


[N, A, B] = map(int, input().split())
ret = 0
for n in range(1, N + 1):
    total = find_sum_of_digits(n)
    if A <= total and total <= B:
        ret += n
print(ret)


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

using namespace std;

using ll = unsigned long long;

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

    vector<ll> nums(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
        if (nums[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll sum = 1;
    for (int i = 0; i < n; i++) {
        ll a = sum, b = nums[i];
        ll cnta = 0, cntb = 0;
        while (a >= 10) {
            a /= 10;
            cnta++;
        }
        while (b >= 10) {
            b /= 10;
            cntb++;
        }

        if (cnta + cntb > 18 || cnta + cntb > 17 && (a * b) >= 10) {
            cout << -1 << endl;
            return 0;
        }
        sum *= nums[i];
        if (sum > 1000000000000000000) {
            cout << -1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 4052
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = 0;
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < array.length; i++) {
			array[i] = sc.nextInt();
		}
		for (int i = 1; i < n - 1; i++) {
			if ((array[i] > array[i + 1] && array[i] < array[i - 1]) || (array[i] < array[i + 1] && array[i] > array[i - 1])) {
				++count;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 22868
#include<iostream>
#include <string>
#include<vector>

using namespace std;

int main(){

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int I, J;
	I = a*b;
	J = c*d;
	if(I >= J){
		cout << I << endl;
	}
	else{
		cout << J << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char rbuf[2800014];
char wbuf[699997];
int rbufl, wbufl;

#define getchar_unlocked() rbuf[rbufl++]
#define putchar_unlocked(c) wbuf[wbufl++]=(c)

inline uint32_t nextpint(void){ char c=getchar_unlocked(); uint32_t x=0; while('0'<=c){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
inline void printpint(int32_t x){ if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

int edge[200000][2];

int qmem[400000];

int *e[100001];
int el[100001];

int prev[100001];

int s[100000];
int sl, sr;

int main(void){
	read(STDIN_FILENO, rbuf, sizeof(rbuf));
	int n=nextpint();
	int m=nextpint();
	for(int i=0; i<m; i++){
		int A=nextpint();
		int B=nextpint();
		edge[i][0]=A;
		edge[i][1]=B;
		el[A]++;
		el[B]++;
	}
	int ne=0;
	for(int i=1; i<=n; i++){
		e[i]=&qmem[ne];
		ne+=el[i];
		el[i]=0;
	}
	for(int i=0; i<m; i++){
		int A=edge[i][0];
		int B=edge[i][1];
		e[A][el[A]++]=B;
		e[B][el[B]++]=A;
	}
	int k=0;
	prev[1]=1;
	s[sr++]=1;
	while(sl<sr){
		k++;
		int from = s[sl++];
		for(int i=0; i<el[from]; i++){
			int to = e[from][i];
			if(prev[to]==0){
				prev[to]=from;
				s[sr++]=to;
			}
		}
	}
	if(k==n){
		putchar_unlocked('Y');
		putchar_unlocked('e');
		putchar_unlocked('s');
		putchar_unlocked('\n');
		for(int i=2; i<=n; i++){
			printpint(prev[i]);
		}
		write(STDOUT_FILENO, wbuf, wbufl);
	}else{
		puts("No");
	}
}


Measured memory_bytes: 9552
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

    //cout << fixed << setprecision(15);

    int sum = 0;
    int a1[4];
    for (int i = 0; i < 4; ++i)
        cin >> a1[i];
    sort(a1, a1 + 4);

    sum += a1[1] + a1[2] + a1[3];

    int a2[2];
    for (int i = 0; i < 2; ++i)
    {
        cin >> a2[i];
    }
    sum += max(a2[0], a2[1]);
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3164
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>


int main()
{
    int n;
    std::string s;
    std::cin >> n >> s;
    if (n == 1 || n % 2 != 0)
    {
        std::cout << "No";
        return 0;
    }
    for (int i = 0; i < n / 2; i++)
    {
        if (s[i] != s[(n / 2) + i])
        {
            std::cout << "No";
            return 0;
        }
    }
    std::cout << "Yes";
    return 0;
}

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

int main() {
  long n,q,aa,x,y,z;
  cin >> n >> q;
  fenwick_tree<long> a(n);
  for(long i=0;i<n;i++) {
    cin >> aa;
    a.add(i,aa);
  }
  for(long i=0;i<q;i++) {
    cin >> x >> y >> z;
    if(x==0) a.add(y,z);
    else cout << a.sum(y,z) << endl;
  }
}

Measured memory_bytes: 8220
#include<algorithm>
#include <iostream>
#include<vector>
// #include<queue>
// #include<string>
#include <iomanip>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

void dfs(int v, int p, long long cost, vvi &a, vector<long long> &c, vector<long long> &up){
   c[v] = cost+up[v];
   for(auto u: a[v]){
       if(u==p) continue;
       dfs(u, v, c[v], a, c, up);
   } 
   return;
}

int main(){
    int n,m;
    cin>>n>>m;
    vvi a(n+1);
    for(int i=0;i<n-1;i++){
        int x, y;
        cin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    vector<long long> up(n+1, 0);
    for(int i=0;i<m;i++){
        long long x, y;
        cin>>x>>y;
        up[x] +=y;
    }

    vector<long long> c(n+1, 0);

    dfs(1, -1, 0, a, c, up); 
    for(int i=1;i<n+1;i++){
        cout<<c[i]<<" ";
    }

}

Measured memory_bytes: 32128
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h, w, n;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

bool can(int y,int x) {
	if(0 <= y && y < h && 0 <= x && x < w) return true;
	return false;
}

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

	vector<string> s(h);
	rep(i, h) cin >> s[i];

	int sx = -1, sy = -1;
	rep(i, h) {
		rep(j, w) {
			if(s[i][j] == 'S') {
				sy = i;
				sx = j;
			}
		}
	}

	int ans = 0, y = sy, x = sx;
	int d[1005][1005];
	bool used[1005][1005];

	rep(i, n) {
		queue<P> que;
		que.push(P(y, x));

		memset(used, 0, sizeof(used));
		used[y][x] = x;

		memset(d, 0, sizeof(d));
		int cnt = 0;

		while(que.size()) {
			P p = que.front();
			que.pop();

			if(s[p.first][p.second] == char('1' + i)) {
				ans += d[p.first][p.second];
				y = p.first;
				x = p.second;
				break;
			}

			rep(j, 4) {
				int ny = p.first + dy[j];
				int nx = p.second + dx[j];

				if(can(ny, nx) && !used[ny][nx] && s[ny][nx] != 'X') {
					used[ny][nx] = true;
					d[ny][nx] += d[p.first][p.second] + 1;
					que.push(P(ny, nx));
				}
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7204
N, M ,C = map(int, input().split())
B = list(map(int, input().split()))

A = [0] * N
ans = 0
for n in range(N):
    A[n] = list(map(int, input().split()))

    calc = 0
    for m in range(M):
        calc += B[m] * A[n][m]

    if calc + C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        char c=sc.next().charAt(0);
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
            System.out.println("vowel");
        }else{
            System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 21332
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0,T a=0):n(n_),bit(n_+1,a){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
};
long n;
vector<int>a,b;
#include<map>
bool C(int K)
{
	long cnt=0;
	BIT<int>P(2*n+1);
	int ofset=n+1;
	int sum=0;
	P.add(ofset,1);
	for(int i=0;i<n;i++)
	{
		sum+=a[i]<=K?1:-1;
		cnt+=P.sum(sum+ofset-1);
		P.add(sum+ofset,1);
	}
	return cnt<n*(n+1)/2/2+1;
}
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int m;cin>>m;
		a.push_back(m);
		b.push_back(m);
	}
	sort(b.begin(),b.end());
	b.erase(unique(b.begin(),b.end()),b.end());
	int l=-1,r=b.size()-1;
	for(;r-l>1;)
	{
		int m=(l+r)/2;
		if(C(b[m]))l=m;
		else r=m;
	}
	cout<<b[r]<<endl;
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
LL f[105][5005]={};
LL A[100005]={};
int main()
{
LL a,b;
while(cin>>a>>b){
    for(int i=1;i<=a;i++){
        cin>>A[i];
    }
    f[0][0]=1;
    for(int i=1;i<=a;i++){
        for(int j=0;j<=5000;j++){
            f[i][j]=f[i-1][j];
            if(A[i]<=j){
                f[i][j]+=f[i-1][j-A[i]];
            }
        }
    }
    LL ans=0;
    for(int i=0;i<=5000;i++){
        if(i%2==b){
            ans+=f[a][i];
        }
    }
    cout<<ans<<endl;
}
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<double> x(N);
    vector<string> u(N);
    for(int i = 0; i < N; i++) cin >> x[i] >> u[i];
    double otoshi = 0;
    for(int i = 0; i < N; i++){
        if(u[i] == "BTC") otoshi += x[i] * 380000;
        else otoshi += x[i];
    }
    cout << setprecision(13) << otoshi << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll INF = 4e18;

vi ms = {2,3,5};
vector<ll> c(4);

map<ll,ll> memo;
ll go(ll n) {
    if (n == 0) return 0;
    if (memo.count(n)) return memo[n];

    ll &res = memo[n];
    res = INF;
    if (n <= INF/c[3]) res = n*c[3];
    forn(i,3) {
        int m = ms[i];
        int d = n%m;
        res = min(res, go((n-d)/m) + c[i] + d*c[3]);
        res = min(res, go((n+m-d)/m) + c[i] + (m-d)*c[3]);
    }
    return res;
}

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

    int T; cin >> T;
    while (T--) {
        memo.clear();
        ll n; cin >> n;
        for (auto &x : c) cin >> x;
        cout << go(n) << '\n';
    }
    return 0;
}


Measured memory_bytes: 4836
function Main(input) {
  input = input.split(/\s+/);
  const a = parseInt(input[0]);
  const b = parseInt(input[1]);

  const c = a * b;
  if (c % 2 == 0) {
    console.log("Even");
  } else {
    console.log("Odd");
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11340
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
def nsin(X,y):
    if(int(X/y)):
        return nsin(int(X/y),y)+str(X%y)
    return str(X%y)

cost=10000
for i in range(3**n):
    g=list(nsin(i,3).zfill(n))
    if len(set(g))!=3:
        continue
    la=[]
    lb=[]
    lc=[]
    for j in range(n):        
        if g[j]=="0":
            la.append(l[j])
        elif g[j]=="1":
            lb.append(l[j])
        elif g[j]=="2":
            lc.append(l[j])
    costa=10000
    costb=10000
    costc=10000
    for j in range(1,2**len(la)):
        ga=list(nsin(j,2).zfill(len(la)))
        A=0
        cont=-1
        for k in range(len(la)):
            if ga[k]=="1":
                A+=la[k]
                cont+=1
        tmp=cont*10+abs(A-a)
        if tmp<costa:
            costa=tmp
    for j in range(1,2**len(lb)):
        gb=list(nsin(j,2).zfill(len(lb)))
        B=0
        cont=-1
        for k in range(len(lb)):
            if gb[k]=="1":
                B+=lb[k]
                cont+=1
        tmp=cont*10+abs(B-b)
        if tmp<costb:
            costb=tmp
    for j in range(1,2**len(lc)):
        gc=list(nsin(j,2).zfill(len(lc)))
        C=0
        cont=-1
        for k in range(len(lc)):
            if gc[k]=="1":
                C+=lc[k]
                cont+=1
        tmp=cont*10+abs(C-c)
        if tmp<costc:
            costc=tmp
    if cost>(costa+costb+costc):
        cost=costa+costb+costc
print(cost)

Measured memory_bytes: 3192
using System;

namespace abc115_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int day=int.Parse(Console.ReadLine());
            if (day == 25)
            {
                Console.WriteLine("Christmas");
            }
            if (day == 24)
            {
                Console.WriteLine("Christmas Eve");
            }
            if (day == 23)
            {
                Console.WriteLine("Christmas Eve Eve");
            }
            if (day == 22)
            {
                Console.WriteLine("Christmas Eve Eve Eve");
            }

        }
    }
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long tot = A.Sum();
		long snuke = 0;
		long min = (long)1e18;
		for(int i=0;i<N-1;i++){
			snuke += A[i];
			tot -= A[i];
			min = Math.Min(min,Math.Abs(snuke-tot));
		}
		Console.WriteLine(min);
	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main() {
	int n, d, x;
	cin >> n >> d >> x;
	int a;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ans += (d - 1) / a + 1;
	}
	cout << ans+x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

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

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

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

  int count = 0;
  int mi = p[0];
  for(int i = 0; i < n; i++){
    if(p[i] <= mi) ++count;
    mi = min(mi, p[i]);
  }

  cout << count << endl;

  return 0;
}


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

struct Point
{
        double x, y, z;
        Point () {}
        Point (double x, double y, double z) : x(x), y(y), z(z) {}
        
        double dist(Point &d)
        {
                double vx = x - d.x;
                double vy = y - d.y;
                double vz = z - d.z;

                return ( sqrt(vx * vx + vy * vy + vz * vz) );
        } 
};

struct Sphere
{
        Point center;
        double r;

        Sphere () {}
        Sphere (Point center, double r) : center(center), r(r) {}

        double dist(Sphere &d)
        {
                if ( isCollied(d) ) return ( 0.0 );
                return ( center.dist(d.center) - r - d.r );
        }

        bool isCollied(Sphere &d)
        {
                return ( center.dist(d.center) < r + d.r );
        }
};

struct Edge
{
        int a, b;
        double cost;

        Edge () {}
        Edge (int a, int b, double cost) : a(a), b(b), cost(cost) {}

        bool operator < (const Edge &d) const
        {
                return ( cost < d.cost );
        }
};

struct Unionfind
{
        vector < int > par;

        Unionfind(int n)
        {
                par = vector < int >(n);
                for ( int i = 0; i < n; i++ ) {
                        par[i] = i;
                }
        }

        void unite(int x, int y)
        {
                x = root(x), y = root(y);
                if ( x == y ) return;
                par[x] = y;
        }

        bool same(int x, int y)
        {
                return ( root(x) == root(y) );
        }

        int root(int n)
        {
                return par[n] = (par[n] == n ? n : root(par[n]));
        }
};

int main()
{
        int n;
        Sphere data[105];

        while ( cin >> n, n ) {
                vector < Edge > edges;
                for ( int i = 0; i < n; i++ ) {
                        double x, y, z, r;
                        cin >> x >> y >> z >> r;
                        data[i] = Sphere(Point(x, y, z), r);
                }

                for ( int i = 0; i < n; i++ ) {
                        for ( int j = i + 1; j < n; j++ ) {
                                edges.emplace_back(i, j, data[i].dist(data[j]));
                        }
                }
                
                sort(begin(edges), end(edges));

                Unionfind tree(n);
                
                double cost = 0.0;
                for ( auto &x : edges ) {
                        if ( !tree.same(x.a, x.b) ) {
                                tree.unite(x.a, x.b);
                                cost += x.cost;
                        }
                }

                printf("%.3f\n", cost);
        }
                
        return ( 0 );
}


Measured memory_bytes: 3248
import java.util.*;

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

        while(true){
            int n = sc.nextInt();
            int[] test = new int[n];
            double[] tmp = new double[n];

            if(n == 0)  break;

            double sum = 0;
            for(int i = 0;i < n;i++){
                test[i] = sc.nextInt();
                sum += test[i];
            }
            double avg = (double)sum / n;
            
            sum = 0;
            for(int i = 0;i < n;i++){
                sum += (test[i] - avg) * (test[i] - avg);
            }

            System.out.printf("%.8f\n",Math.sqrt(sum / n));
        }
    }
}


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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	int N, K;
	cin >> N >> K;
	vector<int> vec(N);
	rep(i,0,N) cin >> vec[i];
	sort_asc(vec);
	int sum = 0;
	rep(i,0,K)
		sum+=vec[i];
	cout << sum << endl;
}

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;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
int mod=1e9+7;
const int maxn=2001;
int dp[maxn][maxn];

signed main(){
	int h,w;cin>>h>>w;
	vector<string>a(h);
	for(auto&& u:a)cin>>u;
	fill( dp[0],dp[maxn],0);
	dp[0][0]=1;
	rep(i,h)rep(j,w){
	 if(a[i][j]=='.'){
		if(i>0)(dp[i][j]+=dp[i-1][j])%=mod;
		if(j>0)(dp[i][j]+=dp[i][j-1])%=mod;
	}
	}
	cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 32640
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  ll n; cin >>n;
  vector<ll>  a(n);
  rep(i,n) cin >>a[i];
  ll ans=0;
  ll key=0;
  ll key2=a[0];
  rep2(i,1,n)key+=a[i];
  ans=abs(a[0]-key);
  rep2(i,1,n-1){
      key2+=a[i];
      key-=a[i];
      ans=min(ans,abs(key2-key));
  }
  cout <<ans<<endl;
}

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

int main(){
    int N;
    int red=0,blue=0;
    string S;
    cin>>N;
    cin>>S;
    for (int i=0; i<N;i++){
        if (S[i]=='R'){
            red+=1;
        }else{
            blue+=1;
        };
    };
    if (red>blue){cout<<"Yes";}else{cout<<"No";};
    return 0;
}


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

vector<string> fourS={"dream","dreamer","erase","eraser"};
string S;

int match(int idx){
    int res=0;
    REP(i,0,4){
        bool judge=true;
        REP(j,0,fourS[i].size()){
            if(idx+j>=S.size()){
                judge=false;
                break;
            }
            if(S[idx+j]!=fourS[i][j]) judge=false;
        }
        if(judge){
            res=fourS[i].size();
        }
    }
    return res;
}

int main(){
    cin >> S;
    reverse(ALL(S));
    REP(i,0,4){
        reverse(ALL(fourS[i]));
    }
    int idx=0, res;
    
    while(1){
        if(idx>=S.size()) break;
        res=match(idx);
        if(res){
            idx+=res;
        }else{
            break;
        }
    }
    
    cout << (idx==S.size() ? "YES" : "NO") << endl;
}

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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int c[5][5];

int eq(int a, int b, int c) {
    return a == b and b == c;
}

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

    for(int i = 1; i <= 3; i++) {
        for(int j = 1; j <= 3; j++) {
            cin>>c[i][j];
        }
    }

    bool ok = 0;
    for(int b1 = 0; b1 <= 100; b1++) {
        for(int b2 = 0; b2 <= 100; b2++) {
            for(int b3 = 0; b3 <= 100; b3++) {
                int a1 = INF, a2 = INF, a3 = INF;
                if(eq(c[1][1] - b1, c[1][2] - b2, c[1][3] - b3)) a1 = c[1][1] - b1;
                if(eq(c[2][1] - b1, c[2][2] - b2, c[2][3] - b3)) a2 = c[2][1] - b2;
                if(eq(c[3][1] - b1, c[3][2] - b2, c[3][3] - b3)) a3 = c[3][1] - b1;
                if(a1 != INF and a2 != INF and a3 != INF) {
                    ok = 1;
                }
            }
        }
    }

    cout<<(ok ? "Yes" : "No")<<"\n";
    return 0;
}

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

unsigned long xor128(){
    static unsigned long x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned long t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

class Dice
{
public:
    vector<int> pip; // 東南西北上下の目
    Dice(){
        int a[] = {5, 3, 2, 4, 1, 6};
        pip.resize(6);
        for(int i=0; i<6; ++i)
            pip[i] = a[i];
    }
    void roll(int d){ // 東南西北右左に回転
        int dir[][4] = {{4,2,5,0},{4,3,5,1},{4,0,5,2},{4,1,5,3},{0,3,2,1},{0,1,2,3}};
        int tmp = pip[dir[d][0]];
        for(int i=0; i<3; ++i)
            pip[dir[d][i]] = pip[dir[d][i+1]];
        pip[dir[d][3]] = tmp;
    }
    bool operator==(const Dice& d) const{
        return pip == d.pip;
    }
};

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

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<int> > h(2*n+1, vector<int>(2*n+1, 0));   // 高さ
        vector<vector<int> > num(2*n+1, vector<int>(2*n+1, 0)); // 一番上のサイコロの上面の目

        for(int i=0; i<n; ++i){
            int t, f;
            cin >> t >> f;
            Dice d;
            while(d.pip[4] != t || d.pip[1] != f) // 指定の向きになるまでランダムに回転
                d.roll(xor128() % 6);

            int y = n;
            int x = n;
            for(;;){
                bool ng = true;
                for(int j=6; j>=4; --j){
                    int k = find(d.pip.begin(), d.pip.begin()+4, j) - d.pip.begin();
                    if(k == 4)
                        continue;
                    int y2 = y + dy[k];
                    int x2 = x + dx[k];
                    if(h[y2][x2] < h[y][x]){
                        y = y2;
                        x = x2;
                        d.roll(k);
                        ng = false;
                        break;
                    }
                }
                if(ng)
                    break;
            }

            ++ h[y][x];
            num[y][x] = d.pip[4];
        }

        vector<int> ret(7, 0);
        for(int i=0; i<2*n+1; ++i){
            for(int j=0; j<2*n+1; ++j){
                ++ ret[num[i][j]];
            }
        }

        cout << ret[1];
        for(int i=2; i<=6; ++i)
            cout << ' ' << ret[i];
        cout << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int a, b;
    cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9)
        cout << a * b;
    else
        cout << -1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Heap
{
    int key;
    int getLeft(int v) { return v * 2; }
    int getRight(int v) { return v * 2 + 1; }
    int getParent(int v) { return v / 2; }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Heap hp[n + 1];
    for(int i = 1; i <= n; i++)
    {
        int x; cin >> x;
        hp[i].key = x;
    }
    for(int i = 1; i <= n; i++)
    {
        cout << "node " << i << ": key = " << hp[i].key << ", ";
        int p = hp[i].getParent(i);
        int l = hp[i].getLeft(i);
        int r = hp[i].getRight(i);
        if(p >= 1) cout << "parent key = " << hp[p].key << ", ";
        if(l <= n) cout << "left key = " << hp[l].key << ", ";
        if(r <= n) cout << "right key = " << hp[r].key << ", ";
        cout << "\n";
    }
    return 0;
}




Measured memory_bytes: 3160
#include <stdio.h>
#include <math.h>

/* prototype declaration */
void calc(double x0, double y0, double x1, double y1, double x2, double y2);
void init();

double xr, yr, r;

int main(int argc, const char *argv[])
{
	int cnt = getchar() - '0';
	double x0, y0, x1, y1, x2, y2;
	init();

	for(; cnt>0; cnt--){
		scanf("%lf %lf %lf %lf %lf %lf",&x0, &y0, &x1, &y1, &x2, &y2);
		calc(x0, y0, x1, y1, x2, y2);
		printf("%.3f %.3f %.3f\n", xr, yr, r);
	}

	return 0;
}

void init()
{
	xr = 0.0; yr = 0.0; r = 0.0;
}

void calc(double x0, double y0, double x1, double y1, double x2, double y2)
{
	double a, b, c, d, e, f, det;
	a = 2*(x1 - x0); b = 2*(y1 - y0);
	c = 2*(x2 - x0); d = 2*(y2 - y0);
	e = x1*x1 - x0*x0 + y1*y1 - y0*y0;
	f = x2*x2 - x0*x0 + y2*y2 - y0*y0;
	det = a*d - b*c;

	xr = (d*e - b*f)/det;
	yr = (a*f - c*e)/det;
	
	r = sqrt((x0-xr)*(x0-xr) + (y0-yr)*(y0-yr)); 	
}

Measured memory_bytes: 0
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] cnt = new int[n+1];
		int k = 0;
		Edge[] edge = new Edge[n];
		ArrayList<Edge>[] list = new ArrayList[n+1];
		for(int i = 1; i <= n; i++){
		    list[i] = new ArrayList<Edge>();
		}
		for(int i = 0; i < n-1; i++){
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    cnt[a]++;
		    cnt[b]++;
		    k = max(k, max(cnt[a], cnt[b]));
		    if(a > b){
		        int c = a;
		        a = b;
		        b = c;
		    }
		    edge[i] = new Edge(a, b, 0);
		    list[a].add(edge[i]);
		    list[b].add(edge[i]);
		}
		
		// 計算
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
		int[] color = new int[n+1];
		int[] visited = new int[n+1];
		pq.add(1);
		while(!pq.isEmpty()){
		    Integer i = pq.poll();
		    visited[i] = 1;
		    ArrayList<Edge> edges = list[i];
		    int c = color[i];
		    for(Edge e : edges){
		        int next = e.from;
		        if(i == next) next = e.to;
		        if(visited[next] == 1) continue;
		        c++;
		        if(c > k) c = 1;
		        e.c = c;
		        color[next] = c;
		        pq.add(next);
		    }
		}
		
		// 出力
		System.out.println(k);
		for(int i = 0; i < n-1; i++){
		    System.out.println(edge[i].c);
		}
	}
}

class Edge {
    int from;
    int to;
    int c;
    
    Edge(int from, int to, int c){
        this.from = from;
        this.to = to;
        this.c = c;
    }

    public String toString(){
        return "from:" + from + " to:" + to + " c:" + c;
    }   
}


Measured memory_bytes: 110664
A,B,C,D=map(int,list(input()))
if A+B+C+D==7:
  print('%d+%d+%d+%d=7'%(A,B,C,D))
  exit()
elif A+B+C-D==7:
  print('%d+%d+%d-%d=7'%(A,B,C,D))
  exit()
elif A+B-C+D==7:
  print('%d+%d-%d+%d=7'%(A,B,C,D))
  exit()
elif A-B+C+D==7:
  print('%d-%d+%d+%d=7'%(A,B,C,D))
  exit()
elif A+B-C-D==7:
  print('%d+%d-%d-%d=7'%(A,B,C,D))
  exit()
elif A-B+C-D==7:
  print('%d-%d+%d-%d=7'%(A,B,C,D))
  exit()
elif A-B-C+D==7:
  print('%d-%d-%d+%d=7'%(A,B,C,D))
  exit()

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

using namespace std;

unsigned long long x, cnt, a;

int main() {
	cin >> x;
	cnt = 0;
	a = 100;
	while(1) {
		a = a * 1.01;
		cnt += 1;
		if (a >= x) {
			cout << cnt;
			return 0;
		}
	}
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{

    public static void main(String[] args){
        int n;
        int r;
        int p;
        int c;
        Scanner scanner = new Scanner(System.in);

        int i;
        int[] pile;
        int[] pilecopy;

        n = scanner.nextInt();
        r = scanner.nextInt();
        while(n != 0 && r != 0){
            pile = new int[n];
            pilecopy = new int[n];
            for(i = 0; i < n; i++){
                pile[i] = n - i;
            }

            for(i = 0; i < r; i++){
                p = scanner.nextInt();
                c = scanner.nextInt();

                System.arraycopy(pile, p - 1, pilecopy, 0, c);
                if(p != 1) System.arraycopy(pile, 0, pilecopy, c, p - 1);
                if(n - c - p + 1 != 0)System.arraycopy(pile, p + c - 1, pilecopy, p + c - 1, n - c - p + 1);

                System.arraycopy(pilecopy, 0, pile, 0, n);
            }

            System.out.println(pile[0]);
            
            n = scanner.nextInt();
            r = scanner.nextInt();
        }

        scanner.close();
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  string s; cin >> s;
  ll ans = N;


  int black_from_left = 0;
  int white_from_right = count(ALL(s), '.');

  for (int i = 0; i <= N; i++) {
    ll val = black_from_left + white_from_right;
    chmin(ans, val);

    if (s[i] == '#') black_from_left++;
    if (s[i] == '.') white_from_right--;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3840
import heapq

Q = int(input())
b_sum = 0
a_list = []
left = []
right = []
res = 0

for i in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        b_sum += query[2]
        if len(right) == 0:
            a = query[1]
            heapq.heappush(right, -a)
        else:
            res += abs(query[1] + right[0])
            if query[1] <= -right[0]:
                heapq.heappush(right, -query[1])
            else:
                heapq.heappush(left, query[1])
        if len(right) < len(left):
            x = heapq.heappop(left)
            y = -right[0]
            res += y - x
            heapq.heappush(right, -x)
        elif len(right) > len(left) + 1:
            x = - heapq.heappop(right)
            heapq.heappush(left, x)
    else:
        print(-right[0], res + b_sum)


Measured memory_bytes: 11176
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_all_same(S):
    pre_s = S[0]
    for s in (S):
        if s != pre_s:
            return False
    return True

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    N = int(input_raw[0])

    while 1:
        if is_all_same(str(N)):
            print N
            exit()
        N += 1

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int A[SIZE];
LL N,M;
LL f(int mm){
    int it=N;
    LL nn=0;
    REP(i,N){
        while(it>0&&A[it-1]+A[i]>=mm)it--;
        nn+=N-it;
    }
    return nn;
}
LL dp[SIZE];
int main(){
    R(N,M);
    REP(i,N)R(A[i]);
    sort(A,A+N);
    dp[N-1]=A[N-1];
    for(int i=N-2;i>=0;i--){
        dp[i]=dp[i+1]+A[i];
    }
    LL ll=2,rr=2e5;
    while(ll<rr){
        LL mm=(ll+rr+1)/2;
        LL nn=f(mm);
        if(nn<M)rr=mm-1;
        else ll=mm;
    }
    LL nn=f(ll);
    LL an=-(nn-M)*ll;
    int it=N;
    REP(i,N){
        while(it>0&&A[it-1]+A[i]>=ll)it--;
        int num=N-it;
        an+=(LL)A[i]*num+dp[N-num];
    }
    W(an);
    return 0;
}


Measured memory_bytes: 5120
// https://atcoder.jp/contests/dp/tasks/dp_b

#include <bits/stdc++.h>
using namespace std;
int n, k;
int ans = INT_MAX;
vector<int> hs;
#define rep(i, k, n) for (int i = k; i < (int)(n); i++)

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

    rep(i, 0, n)
    {
        int h;
        cin >> h;
        hs.push_back(h);
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(hs[0] - hs[1]);

    rep(i, 2, n)
    {
        int temp = INT_MAX;
        rep(j, i - k, i)
        {
            if (j < 0)
                continue;
            temp = min(temp, dp[j] + abs(hs[i] - hs[j]));
        }
        dp[i] = temp;
    }
    cout << dp[n - 1] << endl;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
	int n, l;
	string tmp;
	vector<string> s;
	scanf("%d %d", &n, &l);
	rep(i, n) {
		cin >> tmp;
		s.push_back(tmp);
	}
	sort(s.begin(), s.end());
	rep(i, s.size()) cout << s[i];
	cout << endl;
	return 0;
}

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

int main() {
  int N,R,B;
  R=0;
  B=0;
  cin >> N;
  string s;
  cin >> s;
  for (int i=0; i<N ; i++){
    if(s.at(i)=='R'){
      R=R+1;
    }
    else{
      B=B+1;
    }
  }
  if (R>B){
    cout << "Yes" << endl;
  }
  else{
    cout << "No"<< endl;
  }
      
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		int result = 0;
		for(int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
			result += t[i];
		}
		int m= sc.nextInt();
		for(int i = 0; i < m; i++) {
			int index = sc.nextInt()-1;
			int effect = sc.nextInt()-t[index];
			int ans = result+effect;
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 23636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<int> que;
  que.push(0);
  vector<int> ans(n, -1);
  vector<int> seen(n, 0);
  while(!que.empty()) {
    int f = que.front();
    que.pop();
    for(auto p : g[f]) {
      if(seen[p] != 0) {
        continue;
      }
      seen[p] = 1;
      ans[p] = f;
      que.push(p);
    }
  }
  cout << "Yes\n";
  for(int i = 1; i < n; i++) {
    cout << ans[i] + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 10572
#入力値0になるまで繰り返す
while True:
    num = int(input())
    if num == 0:break

#numが偶数の時は22で割り、奇数のときは3倍し1を足す
    else:
        kei = 0
        while num != 1:
            if num % 2 == 0:num /= 2
            else:
                num *= 3
                num += 1
            kei += 1
        print(kei)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,b;cin>>n>>b;
  if(n==1 || b==1 )cout<<1;
 else if(n%2==0)cout<<(n/2)*b;
  else if(b%2==0)cout<<n*(b/2);
  else cout<<(n*(b-1)/2)+((n+1)/2);
  
}


Measured memory_bytes: 256
import Control.Monad

solver::[String]->Char->[String]->Bool
solver _ _ [] = True
solver says l (x:xs) = if (head x) == l && not (elem x says) then solver (x:says) (last x) xs else False

main::IO()
main=do
  nc<-getLine
  let n = read nc ::Int
  dat<-mapM (\_-> getLine ) [1..n]
  putStr (if solver [(head dat)] (last (head dat)) (tail dat) then "Yes\n" else "No\n")


Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	int N, W;
	cin >> N >> W;
	vector<int> w(N), v(N);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	vector<vector<int>> Memo(N, vector<int>(sum + 1));
	int ans = 0;
	for (int j = 1; j < sum + 1; j++) {
		if (v[0] >= j) Memo[0][j] = w[0];
		else Memo[0][j] = 1000000001;
		if (Memo[0][j] < W) ans = max(ans, j);
	}
	for (int i = 0; i < N; i++) {
		Memo[i][0] = 0;
		for (int j = 1; j < sum + 1; j++) {
			if (i == 0) {
				if (v[0] >= j) Memo[0][j] = w[0];
				else Memo[0][j] = 1000000001;
			}
			else Memo[i][j] = min(Memo[i - 1][max(0, j - v[i])] + w[i], Memo[i - 1][j]);
			if (Memo[i][j] <= W) ans = max(ans, j);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 42628