akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
long long func(long long x) {
    x = min(n, x / b * b + b - 1);
    return (a*x)/b - a*(x/b);
}
double ts(double start, double end){
    double l = start, r = end;
    while(l < r - 3) {
      long long l1 = (l*2+r)/3;
      long long l2 = (l+2*r)/3;
      long long f1 = func(l1);
      long long f2 = func(l2);
      if(f1 > f2)r = l2;
      else if(f2 > f1)l = l1;
      else r = l2, l = l1;
    }
    return max(func(l), func(r));
}
void solve() {
    cin >> a >> b >> n;
    cout << ts(0, n);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tc = 1;
  // cin >> tc;
  for(int i = 1; i <= tc; ++i) {
    // cout << "Case #" << i <<": ";
    solve();
  }
  return 0;
}

Measured memory_bytes: 3756
h, w = gets.split.map(&:to_i)
center_c = (h&1) * (w&1)
axis_c = (h*(w&1) + w*(h&1) - center_c) / 2
list = h.times.map{gets.chomp}.join.chars.group_by(&:itself).map{|k, v| v.size}
ct_c = list.count(&:odd?)
ct_a = list.count{|x| x%4==2}
if ct_c<=center_c and ct_a <= axis_c
  puts "Yes"
else
  puts "No"
end

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

using namespace std;

using ll = long long;

struct _IN {
    _IN() {
        ios::sync_with_stdio(0);
        cin.tie(0);
    }
    template <typename T>
    operator T() const {
        T x;
        cin >> x;
        return x;
    }
    template <typename Container>
    void operator()(Container& c) {
        for (auto& x : c)
            cin >> x;
    }
} IN;

int main() {
    ll N = IN;
    int ans = 0;
    for (ll i = 2; i * i <= N; i++) {
        int cnt = 0;
        while (N % i == 0) {
            cnt++;
            N /= i;
        }
        for (int j = 1;; j++) {
            if (cnt < j)
                break;
            ans++;
            cnt -= j;
        }
    }
    if (N > 1)
        ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A <= C && C <= B) cout << "Yes" << endl;
    else cout << "No" << endl; 
    return 0;
}


Measured memory_bytes: 256
def factorial(n, mod):
    num = 1
    for i in range(1, n + 1):
        i %= mod
        num *= i
        num %= mod
    return num


def main():
    n, m = map(int, input().split())
    md = 10 ** 9 + 7

    if abs(n - m) >= 2:
        ans = 0
    elif abs(n - m) == 1:
        ans = (factorial(n, md) * factorial(m, md))
        ans %= md
    else:
        ans = (factorial(n, md) * factorial(m, md)) * 2
        ans %= md

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 8976
// AOJ 1246: Concert Hall Scheduling
// 2017.11.8 bal4u@uu
// 2018.4.21
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define INF 0x10101010
#define MAX 400
typedef struct { int to, rev; int cap, cost; } EDGE;
EDGE *edge[MAX]; int hi[MAX], lim[MAX];
int  V;             // 頂点数
int  dist[MAX], prevv[MAX], preve[MAX];

void check_lim(int a)
{
	if (hi[a] < lim[a]) return;
	if (lim[a] == 0) {
		lim[a] = 16, hi[a] = 0;
		edge[a] = malloc(sizeof(EDGE) *lim[a]);
	} else if (hi[a] == lim[a]) {
		int k = lim[a];
		if (k > 512) k = 512;
		lim[a] += k;
		edge[a] = realloc(edge[a], sizeof(EDGE) *lim[a]);
	}
}

void add_edge(int from, int to, int cap, int cost)
{
	int f, t;
	EDGE *e;

	check_lim(from), check_lim(to);
	f = hi[from]++, t = hi[to]++;
	e = &edge[from][f], e->to = to, e->cap = cap, e->cost = cost, e->rev = t; 
	e = &edge[to][t], e->to = from, e->cap = 0, e->cost = -cost, e->rev = f;
}

int minCostFlow(int S, int T, int F)
{
	int i, v, nv, t, nt, update, ret;
	EDGE *e;

	ret = 0;
  
	while (F > 0) {
		memset(dist, INF, V << 2);
		dist[S] = 0;
		do {
			update = 0;
			for (v = 0; v < V; v++) {
				if (dist[v] == INF) continue;
				for (i = 0; i < hi[v]; i++) {
					e = &edge[v][i];
					if (e->cap <= 0) continue;
					nv = e->to;
					nt = dist[v] + e->cost;
					if (dist[nv] > nt) {
						dist[nv] = nt, prevv[nv] = v, preve[e->to] = i;
						update = 1;
					}
				}
			}
		} while (update);

		if (dist[T] == INF) return -1;

		t = F;
		for (v = T; v != S; v = prevv[v]) {
			e = &edge[prevv[v]][preve[v]];
			if (t > e->cap) t = e->cap;
		}
		F -= t;

		ret += t * dist[T];
		for (v = T; v != S; v = prevv[v]) {
			e = &edge[prevv[v]][preve[v]];
			e->cap -= t;
			edge[v][e->rev].cap += t;
		}
	}
	return ret;
}
 
// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int n, i, j, k, w;
	int source, sink;

	while (n = in()) {
		source = 0, sink = 365;
		V = sink+1;
		memset(hi, 0, V<<2), memset(lim, 0, V<<2);
		for (k = 0; k < n; k++) {
			i = in(), j = in(), w = in();
			add_edge(i-1, j, 1, -w);
		}
		for (i = 0; i < 365; i++) add_edge(i, i+1, 2, 0);
		printf("%d\n", -minCostFlow(source, sink, 2));
	}
	return 0;
}


Measured memory_bytes: 2060
#include<stdio.h>
 
int main(){
  char S[101];
  scanf("%s",S); 
  
  int len = strlen(S);
  
  for(int i = 0; i < len; i++){
   if(i % 2 == 0){
     if(S[i] == 'L'){
       puts("No");
       return 0;
     }
   }
   else{
     if(S[i] == 'R'){
       puts("No");
       return 0;
     }
   }
  }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include <iostream>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;

int main(){
	string S;
	cin >> S;
	for (int i = 0; i < S.length(); ++i){
		printf("x");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int D = sc.nextInt();

    System.out.println( A * B >= C * D ? A * B : C * D  );

  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int x,y,z;
  cin >> x >> y >> z;
  if(x == y && x != z){
      cout << "Yes";
  } else if(y == z && x != y){
      cout << "Yes";
  } else if(x == z && x != y){
      cout << "Yes";
  } else
  {
      cout << "No";
  }
  
    
 
  
}

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

int main(){
	string s;
	cin>>s;
	if(s[1]=='R'){
		if(s[0]=='R' and s[2]=='R'){
			cout<<3<<endl;
		}else if(s[0]=='R' or s[2]=='R'){
			cout<<2<<endl;
		}else{
			cout<<1<<endl;
		}
	}else{
		if(s[0]=='R' or s[2]=='R'){
			cout<<1<<endl;
		}
		else cout<<0<<endl;
	}


	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double a,b,x;
	cin >> a >> b >> x;
	double s = x/a;
	double rad = 0;
	if(s>= a*b/2){
		double h = (a*b - s)*2/a;
		rad = atan2(h,a);
	}else{
		double w = s*2/b;
		rad = atan2(b,w);
	}
	double PI = acos(-1);
	double deg = rad/(2*PI) * 360;
	cout << fixed << setprecision(10) << deg << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
char s[300005];
char t[300005];
vector<int> a[30],b[30];
int main(){
	scanf("%s",&s);
	scanf("%s",&t);
	int l=strlen(t);
	for(int i=0;i<l;i++){
		int x=t[i]-'a';
		a[x].push_back(i);
	}
	int f=0;
	for(int i=0;i<26;i++){
		if(a[i].size()<=1)
			continue;
		for(int j=1;j<a[i].size();j++){
			if(s[a[i][j]]!=s[a[i][0]]){
				f=1;
				break;
			}
		}
		if(f==1)
			break;
	}
	for(int i=0;i<l;i++){
		int x=s[i]-'a';
		b[x].push_back(i);
	}
	for(int i=0;i<26;i++){
		if(b[i].size()<=1)
			continue;
		for(int j=1;j<b[i].size();j++){
			if(t[b[i][j]]!=t[b[i][0]]){
				f=1;
				break;
			}
		}
		if(f==1)
			break;
	}
	if(f==0)
		printf("Yes\n");
	else
		printf("No\n");
}


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

using namespace std;

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> cnt_e(N + 1);
  for (int i = 0; i < N; i++) {
    cnt_e[i + 1] = cnt_e[i];
    if (S[i] == 'E') cnt_e[i + 1]++;
  }
  int ans = 1e9;
  for (int i = 0; i < N; i++) {
    int left_w = 0;
    if (i > 0) {
      left_w = i - cnt_e[i];
    }
    int right_e = 0;
    if (i < N - 1) {
      right_e = cnt_e[N] - cnt_e[i + 1];
    }
    chmin(ans, left_w + right_e);
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 1796
mod = 10**9+7
def cmb(n,k):
    return fac[n]*inv_fac[n-k]*inv_fac[k] % mod
def g(r,c):
    x = 0
    for i in range(1,r+2):
        x += cmb(c+i,i)
    x %= mod
    return x

r1,c1,r2,c2 = map(int,input().split())
N = r2+c2+1
fac = [1]
for i in range(1,N+1):
    fac.append(fac[-1]*i % mod)
inv_fac = [pow(fac[N],mod-2,mod)]
for i in range(1,N+1)[::-1]:
    inv_fac.append(inv_fac[-1]*i % mod)
inv_fac = inv_fac[::-1]
print((g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1))% mod)

Measured memory_bytes: 214864
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  int k;
  cin >> k;
  string s;
  cin >> s;
  if(k>=s.size())cout << s << endl;
  else{
    rep(i,k)cout << s.at(i);
    cout << "...";
  }
  cout << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<string> a = {"AC", "WA", "TLE", "RE"};
    vector<int> b = {0, 0, 0, 0};

    for (int i = 0; i < n; i++) {
        string x;
        cin >> x;
        for (int j = 0; j < 4; j++) {
            if (x == a.at(j)) {
                b.at(j)++;
                break;
            }
        }
    }

    for (int i = 0; i < 4; i++) {
        cout << a.at(i) << " x " << b.at(i) << endl;
    }
}

Measured memory_bytes: 3640
#include<cstdio>

int main(void){
  char a[200],b[200];

  scanf("%s %s",a,b);

  int i=0,j=0;

  while(a[i]!=0||b[j]!=0){
    if(i==j){
      putchar(a[i]);
      i++;
    }
    else{
      putchar(b[j]);
      j++;
    }
  }
  putchar('\n');

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a,b;
  bool flag=true;
  cin>>a>>b;
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(i<a){
      if(!(('0'<=s[i])&&('9'>=s[i]))){
        flag=false;
      }
    }
    if(a<i){
      if(!(('0'<=s[i])&&('9'>=s[i]))){
        flag=false;
      }
    }
    if(a==i){
      if(s[i]!='-'){
        flag=false;
      }
    }
  }
  if(flag){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    int ret = 0;
    for(int k = 1; k <= n; k++){
        if(n%k) continue;
        bool ok = true;
        for(int i = 0; i < n/k; i++){
            bool valid = true;
            for(int j = 0; j < k; j++)    valid &= a[i] == a[n/k*j+i];
            if(!valid)  ok = false;
        }
        if(ok)  ret = k;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3884
n=int(input())
s=input()
maxx=-1
def got(a,al):
    for i in a:
        if i==al :
      	    return(True)
    return(False)
for i in range(n):
    a=s[:i]
    b=s[i:]
    cnt=0
    alp="abcdefghijklmnopqrstuvwxyz"
    for al in alp:
        if got(a,al) and got(b,al):
      	    cnt+=1
    maxx=max(maxx,cnt)
print(maxx)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int time;
	int *line;
	cin>>time;
	line=new int[time];
	for(int i=0;i<time;++i){
		cin>>line[i];
	}
	int place;
	int doll;
	for(int i=0;i<time-1;++i){
		cout<<line[i]<<' ';
	}
	cout<<line[time-1]<<endl;
	for(int it=1;it<time;++it){
		doll=line[it];
		for(place=it-1;place>=0&&line[place]>doll;--place)
			line[place+1]=line[place];
		line[place+1]=doll;
		for(int i=0;i<time-1;++i){
			cout<<line[i]<<' ';
		}
	cout<<line[time-1]<<endl;
	}
	delete[] line;
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define IN(n) int n; cin>>n;
#define ARR(arr,i,n) int arr[n]; REP(i,0,n){cin>>arr[i];}
#define MOD 1000000007

using namespace std;

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

    // code comes here

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

    int ind1=n/2-1;
    int ind2=ind1+1;
    cout<<arr[ind2]-arr[ind1]<<"\n";
    return 0;
}






Measured memory_bytes: 640
//q1
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <tuple>
#define pb push_back
#define mkt make_tuple
#define pqueue priority_queue
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
const int INF =  2147483647;
const ll INFLL = 9223372036854775807;



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

  int  n, m;
  ll ans;
  cin >> n >> m;

  if (abs(n - m) > 1) {
    ans = 0;
  } else {

    ll factn = 1, factm = 1;
    ll d = 1e9+7;
    for (ll i = 1; i <= m; i++) {
      factm = ((factm % d) * (i % d)) % d;
    }
    for (ll i = 1; i <= n; i++) {
      factn = ((factn % d) * i) % d;
    }
    factm = factm % d;
    factn = factn % d;

    if (m == n) {
      ans = 2 * factm * factn;
    } else {
      ans = factm * factn;
    }

    ans = ans % d;
  }

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


Measured memory_bytes: 256
a_1, b_1 = map(int, input().split())
a_2, b_2 = map(int, input().split())
a_3, b_3 = map(int, input().split())
list_r = list([a_1,a_2,a_3,b_1,b_2,b_3])
a = list_r.count(1)
b = list_r.count(2)
c = list_r.count(3)
d = list_r.count(4)
list_count = list([a,b,c,d])
count = list_count.count(2)
if count == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if (a != 1 && b != 1) {
      System.out.println(1);
    } else if (a != 2 && b != 2) {
      System.out.println(2);
    } else if (a != 3 && b != 3) {
      System.out.println(3);
    }
  }
}

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

int main() {
	int Q;
	cin >> Q;
	
	int prime[100001];
	int temp=2;
	for(int i=0; i<100001; i++){
		prime[i]=1;
	}
	prime[0]=0;
	prime[1]=0;
	
	int flag=1;
	while(flag){
	for(int i=temp*2; i<100001; i+=temp){
		prime[i]=0;
	}
	for(int i=temp+1; i<100001; i++){
		if(prime[i]==1){temp=i; break;}
		if(i==100000){flag=0;}
	}
	}
	
	int similar[100001];
	for(int i=0; i<100001; i++){
		if(prime[i]==1 && prime[(i+1)/2]==1){
			similar[i]=1;
		}else{
			similar[i]=0;
		}
	}
	
	for(int i=0; i<100000; i++){
		similar[i+1]=similar[i+1]+similar[i];
	}

	for(int i=0; i<Q; i++){
		int l,r;
		cin >> l >> r;
		cout << similar[r]-similar[l-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

int a[200001];
int pos[200001];

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,1,n) {
        scanf("%d",&a[i]);
        pos[a[i]] = i;
    }
    set<int> st, rev;
    st.insert(n+1);
    rev.insert(0);
    ll ans = 0;
    REP (i,1,n) {
        int right = *st.lower_bound(pos[i]);
        int left = -*rev.lower_bound(-pos[i]);
        ans += (ll) i * (right-pos[i]) * (pos[i]-left);
        st.insert(pos[i]);
        rev.insert(-pos[i]);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 20608
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        int Q = sc.nextInt();
        int[] A = new int[Q];
        int[] B = new int[Q];
        for (int i = 0; i < Q; i++) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }

        for (long ans : solve(Q, A, B)) {
            System.out.println( ans );
        }
    }

    private static long[] solve(int Q, int[] A, int[] B) {
        long[] ans = new long[Q];
        for (int i = 0; i < Q; i++) {
            ans[i] = calc(A[i], B[i]);
        }
        return ans;
    }

    private static long calc(int a, int b) {
        if( a == b ) {
            return calcSquare(a);

        } else {
            return calcNormal(a, b);
        }
    }

    private static long calcNormal(int a, int b) {
        long ab = (long)a * b;
        long r = (long)Math.floor(Math.sqrt(ab));
        long q = ab / r;

        int plusQr = ab > (q * r) ? 1 : 0;
        return (r-1) + (q-1) + plusQr - 1;
    }

    private static long calcSquare(int a) {
        long r = a-1;
        return r * 2;
    }
}


Measured memory_bytes: 21716
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

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


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int H, W;
ll black=0LL, white=0LL;
map<P, bool>mp;
char S[500][500];

void search_root(int i, int j){
    if(mp[P{i,j}]){
        return;
    }

    if(S[i][j]=='#') {
        black++;
    }else{
        white++;
    }
    mp[P{i,j}]=true;

    for(int k=0; k<4; k++){
        if(0<=j+dx[k] && j+dx[k]<W && 0<=i+dy[k] && i+dy[k]<H){
            if(S[i][j]==S[i+dy[k]][j+dx[k]])
                continue;

            search_root(i+dy[k], j+dx[k]);
        }
    }
}

int main() {
    cin >> H >> W;
    rep(i,H){
        cin >> S[i];
    }
    ll ans=0LL;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            black=0, white=0;
            if(S[i][j]=='#') {
                search_root(i, j);
                ans += black * white;
            }
        }
    }

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

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

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> v;
    map<int,vector<int>> mp;
    queue<pair<int,vector<int>>> q;
    for(int i = 0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        mp[x].push_back(y);
        mp[y].push_back(x);
        v.push_back(make_pair(x,y));
    }

    vector<int> visited(n);
    vector<int> possible(n);

    //apply pair bfs to solve the problem

    if(mp[1].empty())
    {
        cout<<"No\n";
    }
    else
    {
        q.push({1,mp[1]});
        while(!q.empty())
        {
            pair<int,vector<int>> p = q.front();
            vector<int> temp = p.second;
            int index = p.first;
            q.pop();
            for(int i:temp)
            {
                if(!visited[i-1])
                {
                    visited[i-1]++;
                    possible[i-1] = index;
                    q.push({i,mp[i]});
                }
    
            }
            temp.clear();
        }

        int flag = true;
        for(int j:visited)
        {
            if(!j)
            {
                cout<<"No\n";
                flag = false;
                break;
            }
        }
        if(flag)
        {
            cout<<"Yes\n";
            for(int k = 1;k<possible.size();k++)
            {
                cout<<possible[k]<<"\n";
            }
        }
    }


    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n, a, b; cin >> n >> a >> b;
    string s; cin >> s;
    int cnt_b = 0, cnt = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'a'){
            if (cnt < a+b){
                cout << "Yes" << endl;
                cnt++;
            }
            else cout << "No" << endl;
        }
        if (s[i] == 'b'){
            if (cnt < a+b && cnt_b < b){
                cnt++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
            cnt_b++;
        }
        if (s[i] == 'c')cout << "No" << endl;
    }
    
}

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

int main(){
    char com[20];
    priority_queue<int> PQ;

    while(1){
        scanf("%s",com);
        if(com[0]=='i'){
            int key; scanf("%d",&key);
            PQ.push(key);
        }else if(com[1]=='x'){
            printf("%d\n",PQ.top());
            PQ.pop();
        }else if(com[0]=='e'){
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 6976
#include <stdio.h>
 
int main(void)
{
    int a, b, c, d;
    int count;
    int n;
      
    while(scanf("%d",&n)!=EOF){
    	count=0;
    	for(a=0;a<=9;a++){
    		for(b=0;b<=9;b++){
    			for(c=0;c<=9;c++){
    				for(d=0;d<=9;d++){
    					if(a+b+c+d==n){
    						count++;
    					}
    					
    				}
    			}
    		}
    	}
    	printf("%d\n",count);
    }
    return (0);
}

Measured memory_bytes: 596
#include<stdio.h>
int main(void){
  int n,a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  scanf("%d",&n);
  printf("%d",a[n-1]);
  return 0;
}

Measured memory_bytes: 128
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
    if b[i] > i + 1:
        print(-1)
        exit()
L = []
i = 1
while i <= n:
    for j in range(1, len(b)+1):
        if b[j-1] == j:
            m = j
    L.append(m)
    b.pop(m-1)
    i += 1
for l in reversed(L):
    print(l)


Measured memory_bytes: 3064
//Single Source Shortest Path (Negative Edges)
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    const ll INF = 1e8;
    struct edge{
        ll from;
        ll to;
        ll cost;
    };
    ll V, E, r;
    cin >> V >> E >> r;
    vector<edge>edges(E);
    rep(i,E){
        int s, t, d;
        cin >> s >> t >> d;
        edges[i] = {s, t, d};
    }
    vector<ll>shortest(V, INF);
    shortest[r] = 0;
    rep(i,V-1){
        rep(j,E){
            if(shortest[edges[j].from] != INF){
                shortest[edges[j].to] = min(shortest[edges[j].to], shortest[edges[j].from] + edges[j].cost);
            }
        }
    }
    bool ok = true;
    rep(j,E){
        ll a = shortest[edges[j].to];
        if(shortest[edges[j].from] != INF){
            shortest[edges[j].to] = min(shortest[edges[j].to], shortest[edges[j].from] + edges[j].cost);
        }
        if(a != shortest[edges[j].to] && a < 1e7){ 
            ok = false;
            break;
        }
    }
    if(!ok){
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }else{
        rep(i,V){
            if(shortest[i] == INF) cout << "INF" << endl;
            else cout << shortest[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3108
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
    int n,k;
    long long ans;
    cin >> n >> k;
    vector<long long> x(n);
    for(int i=0; i<n; i++) cin >> x[i];
    ans=abs(x[k-1]-x[0])+abs(x[0]);
    for(int i=0; i<n-k+1; i++){
      long long a;
      a=min(abs(x[k-1+i]-x[i])+abs(x[i]),abs(x[k-1+i]-x[i])+abs(x[k-1+i]));
      ans=min(ans,a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
#define mod 1000000007

bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[900005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;
    // cout << node << "\n";
    min_indx[count1] = node;
    max_indx[node] = min(max_indx[node], count1);
    count1++;

    //  count1++;
    child[node] = height++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            min_indx[count1] = node;
            max_indx[node] = min(max_indx[node], count1);
            count1++;
        }
    }
    height--;
}

int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
void process2(int A[], int N)
{
    int i, j;

    //initialize M for the intervals with length 1
    for (i = 0; i < N; i++)
        M[i][0] = i;
    //compute values from smaller to bigger intervals
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (A[M[i][j - 1]] < A[M[i + (1 << (j - 1))][j - 1]])
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
//int parent[200005];
vector<int> vec1;
//bool vis[200005];
//int hei[200005];
int lev[200005];
int dis[200005];
bool cmp(pair<int, int> &a,
         pair<int, int> &b)
{
    return a.second < b.second;
}
int32_t main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    //  int t;
    string str1, str2;
    cin >> str1 >> str2;
    str1.append(str2);
    stringstream geek(str1);
    int n = 0;
    geek >> n;
    int p = sqrt(n);
   // cout << n << " " << p;
    if (p * p == n)
        cout << "Yes"
             << "\n";
    else
    {
        cout << "No"
             << "\n";
    }

    return 0;
}


Measured memory_bytes: 50464
n = gets.chomp.to_i
s = Hash.new(0)

n.times do
    input = gets.chomp
    s[input] += 1
end

s = s.sort_by{|_, v| v}.reverse
ans = []
maxim = s[0][1]

s.each do |a|
    break if maxim != a[1]
    ans << a[0]
end

ans.sort!

ans.each do |i|
    puts i
end

Measured memory_bytes: 40384
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n = 0, m = 0;
int len[5050], tax[5050][250];
int xds[5050 << 2], laz[5050 << 2];
pair<int, int> sta[250][5050]; int top[250];
inline void flesh(int t, int l, int r) {
	xds[t] += laz[t];
	if(l < r) {
		laz[t << 1] += laz[t];
		laz[t << 1 | 1] += laz[t];
	}
	laz[t] = 0;
}
void add(int u, int v, int w, int t, int l, int r) {
	flesh(t, l, r);
	if(u <= l and r <= v) {
		laz[t] += w;
	} else {
		const int x = (l + r) >> 1;
		flesh(t << 1, l, x), flesh(t << 1 | 1, x + 1, r);
		if(u <= x) add(u, v, w, t << 1, l, x);
		if(v > x) add(u, v, w, t << 1 | 1, x + 1, r);
		xds[t] = max(xds[t << 1], xds[t << 1 | 1]);
	}
	flesh(t, l, r);
}
int sol(int u, int v, int t, int l, int r) {
	flesh(t, l, r);
	if(u <= l and r <= v) {
		return xds[t];
	} else {
		int a = -1000000000000LL;
		const int x = (l + r) >> 1;
		if(u <= x) a = max(a, sol(u, v, t << 1, l, x));
		if(v > x) a = max(a, sol(u, v, t << 1 | 1, x + 1, r));
		return a;
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n = 0, m = 0; cin >> n >> m;
	for(int i = 1; i < n; i++) {
		cin >> len[i];
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> tax[i][j];
		}
	}
	int ans = -1000000000000LL;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			int las = i;
			while(top[j] and sta[j][top[j]].first <= tax[i][j]) {
				add(sta[j][top[j] - 1].second + 1, sta[j][top[j]].second, -sta[j][top[j]].first, 1, 1, n);
				sta[j][top[j]] = make_pair(0, 0), top[j]--;
			}
			top[j]++, sta[j][top[j]] = make_pair(tax[i][j], i);
			add(sta[j][top[j] - 1].second + 1, sta[j][top[j]].second, sta[j][top[j]].first, 1, 1, n);
		}
		ans = max(ans, sol(1, i, 1, 1, n));
		add(1, i, -len[i], 1, 1, n);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main()
{
    int k;
    cin>>k;
    k--;
    cout<<a[k]<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
	    while(true){
	    int parson=Integer.parseInt(reader.readLine());
	    if(parson==0)
		break;
	    String str=reader.readLine();
	    String s[]=str.split(" ");
	    int seiseki[]=new int[parson];
	    ArrayList<Integer> list=new ArrayList<>();

	    
	    
	    for(int i=0;i<parson;i++){
		seiseki[i]=Integer.parseInt(s[i]);
	    }

	    for(int i=0;i<parson;i++){
		for(int j=0;j<parson;j++){
		    if(i!=j){
			list.add(Math.abs(seiseki[i]-seiseki[j]));
		    }
		}
	    }
	    System.out.println(Collections.min(list));
	    }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static int gcd (int a, int b){
	return b>0?gcd(b,a%b):a;
    }
    static int lcm (int a, int b) {
	return a*b/gcd(a,b);
    }
}



Measured memory_bytes: 95268
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 200005

int N,M;
bool check[SIZE];

int main(){

	scanf("%d %d",&N,&M);
	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	vector<int> G;

	int from,to;

	for(int i = 0; i < M; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;
		if(from > to)swap(from,to);

		if(from != 0 && to != N-1)continue;

		if(from == 0){

			G.push_back(to);

		}else{ //to == N-1

			check[from] = true;
		}
	}

	for(int i = 0; i < G.size(); i++){

		if(check[G[i]]){

			printf("POSSIBLE\n");
			return 0;
		}
	}


	printf("IMPOSSIBLE\n");

	return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#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 Clear(a) a = decltype(a)() //queueのclear
#define all(s) (s).begin(),(s).end()
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

  string s;
  cin >> s;
  reverse(all(s));
  while(1){
    if((int)s.size()<5){cout << "NO" << endl;return 0;}
    string t="";
    int n=(int)s.size();
    for(int i=n-1;i>=n-5;i--){
      t.push_back(s[i]);
      s.pop_back();
    }
    if(!(t=="dream"||t=="erase")){cout << "NO" << endl;return 0;}
    if((int)s.size()==0)break;
    if(t=="erase"&&s[(int)s.size()-1]=='r')s.pop_back();
    if(t=="dream"&&(int)s.size()>=2&&s[(int)s.size()-1]=='e'&&s[(int)s.size()-2]=='r'){
      if(!((int)s.size()>2&&s[(int)s.size()-3]=='a')){
        s.pop_back();s.pop_back();
      }
    }
    if((int)s.size()==0)break;
  }
  cout << "YES" << endl;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        int d = sc.NextInt();

        string answer = Math.Abs(a - c) <= d || (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) ? "Yes" : "No";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11220
from itertools import accumulate as ac

n,l=map(int,input().split())
*a,=map(int,input().split())
v=[]

for i in range(n-1):
  if a[i]+a[i+1]>=l:
    v.append(i+1)
    break
else:
  print("Impossible")

if v:
  st=v[0]
  v+=list(range(1,st)[::-1])
  v+=list(range(st+1,n))
  print("Possible")
  for i in v[::-1]:
    print(i)

Measured memory_bytes: 14528
from collections import deque
def bfs():
    d = [[float("inf")] * w for i in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
 
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
 
    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    if d[gy][gx] != float("inf"):
        return d[gy][gx]
    else:
        return -1
h, w = map(int, input().split())
sy, sx = 0, 0
gy, gx = h - 1, w - 1
s = [list(input()) for i in range(h)]
black = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            black += 1
if bfs() == -1:
    print(-1)
else:
    print(h * w - bfs() - black - 1)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

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

const int INF = 1001001001;

int main(){
    int N;
    cin >> N;
    vector<P> x(N), y(N);
    
    for(int i = 0; i < N; ++i){
        int temp;
        cin >> temp;
        x[i] = P(temp, i);
        cin >> temp;
        y[i] = P(temp, i);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    
    vector<vector<P>> graph(N);     // (cost, to)
    for(int i = 0; i < N - 1; ++i){
        P p1 = x[i];
        P p2 = x[i + 1];
        int temp = p2.first - p1.first;
        graph[p1.second].push_back(P(temp, p2.second));
        graph[p2.second].push_back(P(temp, p1.second));
        
        p1 = y[i];
        p2 = y[i + 1];
        temp = p2.first - p1.first;
        graph[p1.second].push_back(P(temp, p2.second));
        graph[p2.second].push_back(P(temp, p1.second));
    }
    
    ll res = 0;
    vector<bool> used(N, false);            // 頂点が部分最小全域木に含まれているかどうか
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, 0));          // (現在の部分最小全域木からのcost, coord)
    
    while(!que.empty()){
        P p = que.top();
        que.pop();
        
        // 部分最小全域木に含まれていれば何もしない
        if(used[p.second])      continue;
        
        // 部分最小全域木に入れる(usedのフラグを立てる)
        // priority_queueから部分木からの最小コストは取り出せている
        used[p.second] = true;
        res += p.first;
        
        for(int i = 0; i < graph[p.second].size(); ++i){
            P t = graph[p.second][i];
            // 部分最小全域木からの最小コスト候補をどんどん入れていく
            // 最小全域木に含まれなければcontinueで操作が飛ばされる
            que.push(P(t.first, t.second));
        }
    }
    
    cout << res << endl;
}

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

int main() {
  int n; string s;
  cin >> n >> s;
  
  if (n >= 3200) cout << s << endl;
  else cout << "red" << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug_x(x) cout<< #x <<"---> : "<<x<<endl;
#define debug_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
//std::mt19937 mrand(random_device{}());
//int rnd(int x) { return mrand() % x ; }
const ll mod=1e7;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

/***********************/

int main(){
    ssd;
    int n ;cin>> n ;
    VI a(n);
    for(auto & it : a) cin>>it;
    sort(all(a));
    int minv = a[0],maxv= a[n-1];
    int sum=0,ans = 0x3f3f3f3f;
    _rep(i,minv,maxv){
        sum= 0 ;
        for(auto &it : a){
            sum +=pow((i - it),2);
        }
        ans = min(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

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

// 起点の半径1(斜め込)がひっくり返る
int main() {
	//intじゃたりない！
	long width, height;
	std::cin >> width >> height;

	//w == h == 1の時、裏になる
	if (width == 1 && height == 1)
		std::cout << 1 << std::endl;
	//w or h ==1の時、端の２つだけがひっくり返る
	else if (width == 1)
		std::cout << height - 2 << std::endl;
	else if (height == 1)
		std::cout << width - 2 << std::endl;
	//外周は偶数回数 内側は奇数回数ひっくり返る
	else
	{
		long result = (width - 2) * (height - 2);
		std::cout << result << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,x,m,min=1000,ans;
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++){
        scanf("%d",&m);
        x-=m;
        if(min>m) min=m;
    }
    ans=n+x/min;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
/*
ABC151-D AC
幅優先探索 : 最短距離を求める
参考　: https://qiita.com/drken/items/6a95b57d2e374a3d3292#4-2-%E3%82%B0%E3%83%A9%E3%83%95%E4%B8%8A%E3%81%AE%E6%8E%A2%E7%B4%A2
*/

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

//4方向の移動を示す
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  int H, W;
  cin>>H>>W;
  vector<string> S(H);
  for(int i=0; i<H; i++){
    cin>>S[i];
  }

  int ans = 0;

  for(int sx=0; sx<H; sx++)for(int sy=0; sy<W; sy++){
    for(int gx=0; gx<H; gx++)for(int gy=0; gy<W; gy++){
      //スタートとゴールを探すループ
      if(S[sx][sy]=='.' && S[gx][gy]=='.'){
        //スタートとゴールにできるとき
        //ここから一般的な最短距離探索
        vector<vector<int>> dist(H, vector<int>(W, -1)); //dist=-1のマスは未発見
        queue<pair<int, int>> unvisited; //発見したけど訪問していないマスの情報
        /*
        pushは後ろから入れる
        popは先頭から出す
        */

        dist[sx][sy] = 0; //スタートを発見
        unvisited.push(make_pair(sx, sy)); //訪問はしてないのでスタートを入れる

        //探索開始
        while(!unvisited.empty()){
          //unvisitedが空になるまで
          pair<int, int> current = unvisited.front(); //先頭を読む
          unvisited.pop(); //先頭を捨てる
          int x = current.first;
          int y = current.second;

          for(int i=0; i<4; i++){
            //4方向にnextを探索
            int next_x = x + dx[i];
            int next_y = y + dy[i];
            if(next_x<0 || next_x>=H || next_y<0 || next_y>=W) continue;
            //外に出たらダメ
            if(S[next_x][next_y]=='#') continue;
            //壁はダメ

            if(dist[next_x][next_y] == -1){
              //未発見だったらこれで発見なので未訪問キューに入れる
              unvisited.push(make_pair(next_x, next_y));
              dist[next_x][next_y] = dist[x][y] + 1; //nextのdistは現在地+1
            }
          }
        }//while(!unvisited.empty())
        
        //printf("(%d,%d)->(%d,%d) : %d\n", sx, sy, gx, gy, dist[gx][gy]);

        ans = max(ans, dist[gx][gy]);

      }//if(S[sx][sy]=='.' && S[gx][gy]=='.')
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int x[n];
    vector<int> b(n);
    rep(i, n) {
        cin >> b[i];
    }

    rep(j, n) {
        for(int i = b.size()-1; i >= 0; i--) {
            if(b[i] == i+1) {
                x[j] = b[i];
                b.erase(b.begin() + i);
                break;
            }

            if(i == 0) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    reverse(x, x+n);

    rep(i, n) {
        cout << x[i] << "\n";
    }

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> s(m), c(m);
  rep(i, m) std::cin >> s[i] >> c[i];

  rep(i, 1000) {
    string str = to_string(i);
    if (str.size() != n) {
      continue;
    }
    bool ok = true;
    rep(j, m) {
      if (str[s[j] - 1] != c[j] + '0') {
        ok = false;
      }
    }
    if (ok) {
      std::cout << i << std::endl;
      return 0;
    }
  }

  std::cout << -1 << std::endl;

  return 0;
}


Measured memory_bytes: 3668