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

typedef pair<int, int> P;

const double INF = 1e12;
const P NIL(-1, -1);

struct State {
	double sum;
	int done;
	int weight;
	int now;
	State(){}
	State(double sum, int done, int weight, int now): sum(sum), done(done), weight(weight), now(now){}
	bool operator < (const State &t) const {
		return sum >= t.sum;
	}
};

int n;
int id[15];
int pos[15];
int w[15];

double d[1 << 15][15];
P pre[1 << 15][15];

double calc(int f, int t, int weight)
{
	double m = 2000.0 / (70 + weight);
	return abs(pos[f] - pos[t]) / m;
}

vector<int> rec(int v)
{
	vector<int> res;
	for (P e = P((1 << n) - 1, v); e != NIL; e = pre[e.first][e.second]){
		res.push_back(id[e.second]);
		//printf("%d\n", e);
	}
	reverse(res.begin(), res.end());
	return res;
}

void solve()
{
	fill((double*)d, (double*)d + (1 << 15) * 15, INF);
	fill((P*)pre, (P*)pre + (1 << 15) * 15, NIL);
	
	priority_queue<State> que;
	for (int i = 0; i < n; i++){
		que.push(State(0.0, 1 << i, 0, i));
	}
	
	while (que.size()){
		State st = que.top(); que.pop();
		if (d[st.done][st.now] < st.sum) continue;
		//d[st.done][st.now] = st.sum;
		st.weight += w[st.now];
		
		/*
		printf("%d\n", st.weight);
		printf("%d %f\n", st.done, st.sum);
		*/
		
		if (st.done == (1 << n) - 1) break;
		
		for (int to = 0; to < n; to++){
			int x = 1 << to;
			if (st.done & x) continue;
			double ts = st.sum + calc(st.now, to, st.weight);
			if (d[st.done | x][to] > ts){
				d[st.done | x][to] = ts;
				que.push(State(ts, st.done | x, st.weight, to));
				pre[st.done | x][to] = P(st.done, st.now);
			}
		}
	}
	
	int v = 0;
	for (int i = 0; i < n; i++){
		if (d[(1 << n) - 1][v] > d[(1 << n) - 1][i]){
			v = i;
		}
	}
	//cout << d[(1 << n) - 1][v] << endl; 
	
	vector<int> res = rec(v);
	for (int i = 0; i < res.size(); i++){
		if (i) printf(" ");
		printf("%d", res[i]);
	}
	puts("");
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d %d %d", &id[i], &pos[i], &w[i]);
		w[i] *= 20;
	}
	solve();
	return 0;
}

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

int main(void)
{
  char temp[20];
  char cpy[20];
  int i;
  int length;

  scanf("%s", cpy);

  length = strlen(cpy);
 
  for(i=0; i<length; i++){
    temp[length-i-1] = cpy[i];
  }

  for(i=0; i<length; i++){
    putchar(temp[i]);
  }
  putchar('\n');

  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int

int main(){
   vector<ll> a(5);
   for(ll i=0;i<5;i++){
      cin>>a[i];
   }

   ll m=INT_MAX,pos,c;
   for(ll i=0;i<5;i++){
      ll k = a[i]%10;
      if(k==0)
        continue;
      else{
        if(k<m){
            m = k;
            pos = a[i];
            c = i;
        }
      }

   }
   if(m==INT_MAX){
     pos = a[0];
     c = 0;
   }
   ll sum = pos;
   a.erase(a.begin()+c);
   for(ll i=0;i<4;i++){
     if(a[i]%10==0){
        sum = sum + a[i];
     }
     else{
        sum = sum + (((a[i]/10)+1)*10);
     }
   }
   cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) {
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) {
	return mod_pow(a , mod-2);
}

void solve() {
	
	int a;
	
	cin >> a;
	
	cout << a + a*a + a*a*a;
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const int inf = int(1e10);
//const ll inf = ll(1e19);
const int mod = int(1e9) + 7;

ll a, b, c, d;
int main(){
    cin >> a >> b >> c >> d;
    ll temp1 = a * c, temp2 = a * d, temp3 = b * c, temp4 = b * d;
    ll res = temp1;
    res = max(res, temp2);res = max(res, temp3); res = max(res, temp4);
    cout << res << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll t;cin>>t;
  rep(_t,t){
    int n;cin>>n;
    vector<ll> A(n);
    rep(i,n){
      cin>>A[i];
    }
    string s;cin>>s;
    vector<ll> base;
    REP(i,n){
      ll a = A[i];
      if(s[i] == '1'){
        rep(j,base.size()){
          if((a ^ base[j]) < a){
            a ^= base[j];
          }
        }
        if(a > 0){
          cout<<1<<endl;
          break;
        }
      }else{
        rep(j,base.size()){
          if((a ^ base[j]) < a){
            a ^= base[j];
          }
        }
        if(a > 0){
          base.push_back(a);
        }

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

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

char s[200055];

int main() {
    scanf("%s", s);

    int n = strlen(s);

    for (int i = 0; i < n; i++) if (s[i] == '?') {
        s[i] = 'D';
    }

    puts(s);

    return 0;
}


Measured memory_bytes: 3824
def solve(N, W, vals, weights):
    dp = [[0 for _ in range(W + 1)] for _ in range(N + 1)]
    for i in range(N):
        for w in range(W + 1):
            if weights[i] <= w:
                dp[i + 1][w] = max(dp[i + 1][w - weights[i]] + vals[i], dp[i][w])
            else:
                dp[i + 1][w] = dp[i][w]
    print(dp[N][W])

if __name__ == "__main__":
    N, W = map(int, input().split())
    vals = []
    weights = []
    for _ in range(N):
        v, w = map(int, input().split())
        vals.append(v)
        weights.append(w)
    solve(N, W, vals, weights)


Measured memory_bytes: 42264
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
e = []
s = []

for i in A:
    for j in B:
        e.append(i+j)
e = sorted(e, reverse=True)

if K<len(e):
    e = e[0:K]

for i in e:
    for j in C:
        s.append(i+j)

s = sorted(s, reverse=True)

for i in range(K):
    print(s[i])

Measured memory_bytes: 212212
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;



int main() {
	
	string t;
	cin >> t;
	int n = t.size();

	if (n == 2) {
		if (t[0] == t[1])cout << 1 << " " << 2 << endl;
		else cout << -1 << " " << -1 << endl;
		return 0;
	}

	int ans1 = -2, ans2 = -2;
	for (int i = 1; i < n-1; i++) {
		if ((t[i] == t[i - 1]&&t[i]!=t[i+1])||(t[i] != t[i - 1] && t[i] == t[i + 1])||(t[i-1]==t[i+1]&&t[i]!=t[i-1])) {
			ans2 = i + 1;
			ans1 = i - 1;
			break;
		}
	}

	cout << (ans1)+1 << " " << (ans2)+1 << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

bool is_prime[60000];

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

    int n;
    cin >> n;
    for(int i = 2; i <= 55555; ++i) is_prime[i] = true;
    for(int i = 2; i <= 55555; ++i){
        if(!is_prime[i])    continue;
        for(int j = 2 * i; j <= 55555; j += i)  is_prime[j] = false;
    }
    vector<int> ans(n);
    int now = 0;
    for(int i = 6; i <= 55555; i += 5){
        if(!is_prime[i])    continue;
        ans[now++] = i;
        if(now == n)    break;
    }
    for(int i = 0; i < n; ++i){
        cout << ans[i];
        cout << ((i == n - 1) ? "\n" : " ");
    }
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0

for a in range(A+1):
    if X < 500*a:
        break
    for b in range(B+1):
        for c in range(C+1):
            if X == 500*a+100*b+50*c:
                ans+=1
print(ans)

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

static const int N = 36 + 1;

class Card {
  public:
    int value;
    char suit;
};

void bubbleSort(Card* c, int n);
void selectionSort(Card* c, int n);
void isStable(Card* c1, Card* c2, int n);
void trace(Card* c, int n);

int main() {
  Card c1[N], c2[N];
  int n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> c1[i].suit >> c1[i].value;
    c2[i] = c1[i];
  }

  bubbleSort(c1, n);
  selectionSort(c2, n);

  trace(c1, n);
  printf("Stable\n");
  trace(c2, n);
  isStable(c1, c2, n);

  return 0;
}

void trace(Card* c, int n) {
  for (int i = 0; i < n; ++i) {
    if (i) { printf(" "); }
    printf("%c%d", c[i].suit, c[i].value);
  }
  printf("\n");
}

void bubbleSort(Card* c, int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = n - 1; j > i; --j) {
      if (c[j].value < c[j - 1].value) {
        Card t = c[j];
        c[j] = c[j - 1];
        c[j - 1] = t;
      }
    }
  }
}

void selectionSort(Card* c, int n) {
  for (int i = 0; i < n; ++i) {
    int mini = i;
    for (int j = i + 1; j < n; ++j) {
      if (c[j].value < c[mini].value) { mini = j; }
    }
    Card t = c[i];
    c[i] = c[mini];
    c[mini] = t;
  }
}

void isStable(Card* c1, Card* c2, int n) {
  for (int i = 0; i < n; ++i) {
    if (c1[i].suit != c2[i].suit) { printf("Not stable\n"); return; }
  }
  printf("Stable\n");
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;


int main() {
    ll N;
    cin>>N;
    
    if(N==100000){cout<<9+999-99+99999-9999<<endl;}
    if(10000<=N&&N<100000){cout<<9+999-99+N-9999<<endl;}
    if(1000<=N&&N<10000){cout<<9+999-99<<endl;}
    if(100<=N&&N<1000){cout<<9+N-99<<endl;}
    if(10<=N&&N<100){cout<<9<<endl;}
    if(1<=N&&N<10){cout<<N<<endl;}
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  int N;
  cin >> N;
  double X[N],Y[N];
  double ans=0;
  int div=1;
  rep(i,N) div*=i+1;
  rep(i,N) cin >> X[i] >> Y[i];
  vector<int> V;
  rep(i,N) V.push_back(i+1);
  sort(V.begin(),V.end());
  do{
    double dis=0;
    rep(i,N-1){
      dis+=sqrt(pow(X[V[i+1]-1]-X[V[i]-1],2)+pow(Y[V[i+1]-1]-Y[V[i]-1],2));
    }
    ans+=dis;
  }while(next_permutation(V.begin(),V.end()));
  cout << ans/div << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
L = [int(i) for i in input().split()]

L.sort()

ans = 0

for i in range(N):
  for j in range(i+1,N):
    max_len = L[i] + L[j]
    ans += bisect_left(L,max_len) - j - 1

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, q;
    cin >> n >> q;
    vec g[200010];
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vec p(q), x(q);
    rep(i, q) {
        int a, b;
        cin >> a >> b;
        a--;
        p[i] = a, x[i] = b;
    }

    vec res(n, 0);

    rep(i, q) {
        res[p[i]] += x[i];
    }

    vector<bool> is_r(n, false);
    is_r[0] = true;

    queue<int> que;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (auto&& c : g[v]) {
            if (!is_r[c]) {
                is_r[c] = true;
                res[c] += res[v];
                que.push(c);
            }
        }
    }

    rep(i, n) {
        if (i != 0) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 17140
#include<stdio.h>

int Isprime(int a);

int main()
{
  int area[1000000];
  int n,count,i,j;

  area[2]=2;
  for (i=3;i<=1000000;i+=2)
	{
	  if(Isprime(i) == 1)
	  area[i]=i;
	}


  while(scanf("%d",&n) != EOF)
    {
      if(n<2)
	count=0;
      else if(n>=2)
	{
	  count=1;
      for(j=3;j<=n;j+=2)
	{
	  if(area[j] == j)
	    count++;
	    }
	}

      printf("%d\n",count);
    }
     return 0;
}

int Isprime(int n){
    int i;
  
    if(n < 2)
        return 0;
    else if(n == 2)
        return 1;
  
    if(n % 2 == 0)
        return 0;
  
    for(i = 3; i * i <= n; i += 2)
         if(n % i == 0)
            return 0;
    return 1;
}

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

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

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

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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<complex<double>> pile;
	rep(i,n){
		double a,b; cin>>a>>b;
		pile.emplace_back(a,b);
	}

	using edge=tuple<double,ll,ll>;
	vector<vector<edge>> fence(n);
	
	double ans=0;

	rep(i,m){
		int a,b; cin>>a>>b;
		a--, b--;
		fence[a].emplace_back(abs(pile[a]-pile[b]),a,b);
		fence[b].emplace_back(abs(pile[a]-pile[b]),a,b);
		ans+=abs(pile[a]-pile[b]);
	}

	vb isVisited(n,false);
	rep(i,n){
		if(isVisited[i])continue;

		priority_queue<edge> q;
		set<int> s;
		s.insert(i);
		for(auto&f:fence[i]){
			q.push(f);
		}

		while(!q.empty()){
			double cost; ll a,b;
			tie(cost, a, b) = q.top();
			q.pop();
			isVisited[a]=isVisited[b]=true;

			if(s.find(a)!=s.end())swap(a,b);
			if(s.find(a)!=s.end())continue;
			ans-=cost;
			s.insert(a);
			for(auto&f:fence[a]){
				q.push(f);
			}
		}
	}

	fcout(10)<<ans<<endl;
	return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

/////////////////////////////////////////////////////////
class UnionFind {
public:
  static const int MAX_N_LIB = (int)(2e5 + 100);

  int uf_par[MAX_N_LIB];
  int uf_rank[MAX_N_LIB];
  int uf_size[MAX_N_LIB];

  UnionFind(int n) {
    init(n);
  }

  void init(int n) {
    for (int i = 0; i < n; ++i) {
      uf_par[i] = i;
      uf_rank[i] = 0;
      uf_size[i] = 1;
    }
  }

  int find(int x) {
    if (uf_par[x] == x) return x;
    else {
      return uf_par[x] = find(uf_par[x]);
    }
  }

  void unite(int leaf_x, int leaf_y) {
    int x = find(leaf_x);
    int y = find(leaf_y);

    if (x == y) return;

    if (uf_rank[x] < uf_rank[y]) {
      uf_par[x] = y;
      uf_size[y] += uf_size[x];
    }
    else if (uf_rank[x] > uf_rank[y]) {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
    }
    else {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
      uf_rank[x] += 1;
    }
  }

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

  int size(int x) {
    return uf_size[find(x)];
  }
};
/////////////////////////////////////////////////////////

int n, m;

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  UnionFind union_find(n + 3);

  for (int i = 1; i <= m; ++i) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);

    union_find.unite(x, y);
  }

  set<int> island;

  for (int i = 1; i <= n; ++i) {
    island.insert(union_find.find(i));
  }

  ans = island.size();

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 6400
from math import floor

S = input()
K = int(input())

# Sが1文字しかない
if len(set(S)) == 1:
    print(floor(len(S) * K / 2))
    exit()

ans = 0
if S[0] != S[-1]:
    # Sの中での答え × K回数
    c = "0"
    count = 0
    for i in range(len(S)):
        if c == S[i]:
            count += 1
        else:
            # floor(連続した文字の回数 / 2)だけ書き換える
            ans += count // 2
            c = S[i] # 情報更新
            count = 1
    ans += count // 2 # 最後の分
    ans = ans * K
else:
    # 先頭と末端もある
    c1 = 1
    for i in range(1, len(S)):
        if S[i] == S[0]:
            c1 += 1
        else:
            break
    c2 = 1
    for j in reversed(range(len(S) - 1)):
        if S[j] == S[-1]:
            c2 += 1
        else:
            break
    ans = (c1 // 2) + (c2 // 2) + ((c1 + c2) // 2 * (K - 1))
    c3 = 0
    c = "0"
    for k in range(i, j + 1):
        if S[k] == c:
            c3 += 1
        else:
            ans += c3 // 2 * K
            c = S[k]
            c3 = 1
    ans += c3 // 2 * K
print(ans)

Measured memory_bytes: 38256
s1, s2 = gets.chomp.split(" ")
s1c, s2c = gets.chomp.split(" ").map(&:to_i)
drop = gets.chomp

if drop == s1
  puts "#{s1c - 1} #{s2c}"
elsif drop == s2
  puts "#{s1c} #{s2c - 1}"
end


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

class Program
{
	public static int Main(string[] args)
	{
        
        string[] str = Console.ReadLine().Split(' ');
        int H = int.Parse(str[0]);
        int W = int.Parse(str[1]);
        string[,] grid = new string[H, W];
        for (int i = 0; i < H;i++){
            string tmps = Console.ReadLine();
            for (int j = 0; j < W;j++){
                grid[i, j] = tmps.Substring(j, 1);
                //Console.Write(grid[i, j]);
            }
            //Console.Write("\n");
        }
        bool[] hBlanks = new bool[W];
        int hBlankNum = 0;
        bool[] wBlanks = new bool[H];
        int wBlankNum = 0;

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W;j++){
                if (grid[i, j] == "#") break;
                else if(j==W-1){
                    wBlanks[i] = true;
                    wBlankNum++;
                }
            }
        }

        for (int i = 0; i < W; i++)
        {
            for (int j = 0; j < H; j++)
            {
                if (grid[j, i] == "#") break;
                else if (j == H - 1)
                {
                    hBlanks[i] = true;
                    hBlankNum++;
                }
            }
        }


        int n = 0;
        for (int i = 0; i < hBlankNum;i++){
            while (hBlanks[n] == false){
                n++;
            }
            for (int j = 0; j < H;j++){
                grid[j, n] = " ";
            }
            n++;
        }

        n = 0;
        for (int i = 0; i < wBlankNum; i++)
        {
            while (wBlanks[n] == false)
            {
                n++;
            }
            for (int j = 0; j < W; j++)
            {
                grid[n, j] = " ";
            }
            n++;
        }

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if(grid[i,j]!=" "){
                    Console.Write(grid[i, j]);
                }
            }
            if (wBlanks[i]==false)   {
                Console.Write("\n");
            }                         
        }

        return 0;
	}
}


Measured memory_bytes: 11132
#include <stdio.h>

Search(int[],int,int);

int main(){
    int n,m,i,key,res = 0,num[10001];
    
    scanf("%d",&n);
    for(i = 0;i<n;i++){
        scanf("%d",&num[i]);
    }
    
    scanf("%d",&m);
    for(i = 0;i<m;i++){
        scanf("%d",&key);
        if(Search(num,n,key)){
            res++;
        }
    }
    printf("%d\n",res);
    
    return 0;
}
Search(int A[],int n,int key){
    int i = 0;
    A[n]=key;
    while(A[i] != key){
        i++;
    }
    return i != n;
}



Measured memory_bytes: 2108
# 全国統一プログラミング王決定戦予選/NIKKEI Programming Contest 2019: B – Touitsu
N = int(input())
A, B, C = [input() for _ in range(3)]

operations = 0

for i in range(N):
    if A[i] == B[i] == C[i]:
        pass
    elif A[i] == B[i] or B[i] == C[i] or C[i] == A[i]:
        operations += 1
    else:
        operations += 2

print(operations)

Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    vector<bool> is_ok(3, false);
    is_ok[A - 1] = is_ok[B - 1] = true;
    rep(i, 0, 3) {
        if (!is_ok[i]) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int a[111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)printf("%d%c", a[i],i==n-1?'\n':' ');
	repl(i,1,n){
		int v=a[i];
		int j=i-1;
		while(j>=0&&a[j]>v)a[j+1]=a[j],j--;
		a[j+1]=v;
		rep(i,n)printf("%d%c", a[i],i==n-1?'\n':' ');
	}
	return 0;
}

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

int N, M;
vector<vector<int>> roads;
vector<bool> came;

int move(int now, int moved){
	if(moved == N - 1){
		return 1;
	}else{
		int ans = 0;
		came[now] = true;
		for(int i = 0; i < roads[now].size(); i++){
			if(!came[roads[now][i]]){
				ans += move(roads[now][i], moved + 1);
			}
		}
		came[now] = false;
		return ans;
	}
}
 
int main(){
	cin >> N >> M;
	for(int i = 0; i < N; i++){
		roads.push_back({});
		came.push_back(false);
	}
	for(int i = 0; i < M; i++){
		int start, goal;
		cin >> start >> goal;
		roads[start - 1].push_back(goal - 1);
		roads[goal - 1].push_back(start - 1);
	}
	cout << move(0, 0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int dp[100000];
int n,a[100000];

int topdown()
{
	dp[n-1]=0;
	dp[n-2]=abs(a[n-1]-a[n-2]);

	for(int i=n-3;i>=0;i--)
	{
		dp[i]=min(abs(a[i]-a[i+1])+dp[i+1] , abs(a[i]-a[i+2])+dp[i+2]);
	}
	return dp[0];
}

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

	cout<<topdown();

	return 0;
}

Measured memory_bytes: 4316
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int count = 0;
		
		for(int i = 1; i <= n; i++){
			int sum = 0;
			for(int j = 0; j < String.valueOf(i).length(); j++){
				sum += String.valueOf(i).charAt(j)-'0';
			}
			if(a <= sum && sum <= b)count += i;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 26196
a, b = gets.split.map(&:to_i)
s = gets.chomp

# puts s.match?(/\d{#{a}}-\d{#{b}}/) ? "Yes" : "No"

def zipcode?(string, a, b)
  string.each_char.with_index do |char, index|
    case index
    when a
      return false unless char == '-'
    else
      return false unless ('0'..'9').include?(char)
    end
  end
  return true
end

puts zipcode?(s, a, b) ? "Yes" : "No"

Measured memory_bytes: 14308
#include <bits/stdc++.h>
typedef long long ll;
 
using namespace std;
 
ll V, E;
struct edge {ll from, to, cost;};
edge edges[2020];
const ll INF = 1LL << 50;
 
template <typename T>
bool FindNegativeLoop(T& d){
	for (int i = 0; i < V; i++) d[i] = 0;
 
	for (int i = 0; i < V; i++){
		for (int j = 0; j < E; j++){
			edge e = edges[j];
			if (d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
 
				if ((i == V - 1) && (e.to == V - 1)) return true;
			}
		}
	}
	return false;
}
 
template <typename T>
void BellmanFord(T& d, ll s){
	for (int i = 0; i < V; i++) d[i] = INF;
	d[s] = 0;
 
	for (int  loop = 0; loop < V - 1; loop++){
		for (int i = 0; i < E; i++){
			edge e = edges[i];
			if ((d[e.from] != INF) && (d[e.to] > d[e.from] + e.cost)){
				d[e.to] = d[e.from] + e.cost;
			}
		}
	}
}
 
int main(){
	cin >> V >> E;
	for (int i = 0; i < E; i++){
		ll a, b, c;
		cin >> a >> b >> c;
		edges[i].from = a - 1;
		edges[i].to = b - 1;
		edges[i].cost = -c;
	}
 
	vector<ll> d(V);
	if (FindNegativeLoop(d)){
		cout << "inf" << endl;
	} else { 
		BellmanFord(d, 0);
		cout << -d[V - 1] << endl;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
int main(){
    int n;
    cin >> n;
    int W[n];
    for (int i=0;i<n;i++) cin >> W[i];
    int ans = 100000000;
    for (int i=0;i<n;i++){
        int l = 0;
        int r = 0;
        for (int j=0; j<i; j++) l += W[j];
        for (int k=i; k<n; k++) r += W[k];
        ans = min(ans,abs(l-r));
    }
    cout << ans << endl;
}

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

int main(){  
  ll h, w;
  cin >> h >> w;

  ll ans = 1;
  if(w == 1 || h == 1){
  	cout << ans << endl;
  	return 0;
  }
  ans = (w/2 + (w + 1)/2)*(h/2);
  if(h%2 == 1) ans += (w + 1)/2;
  cout << ans << endl;
  return 0;
}


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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	int uf[112345];
	RC(i, n) uf[i] = i;
	RC(i, m){
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		--x;
		--y;
		while(uf[x] != uf[uf[x]]) uf[x] = uf[uf[x]];
		while(uf[y] != uf[uf[y]]) uf[y] = uf[uf[y]];
		uf[uf[x]] = uf[y];
	}
	// RC(i, n) printf("%d%c", uf[i], " \n"[i == n - 1]);
	int ans = 0;
	RC(i, n) ans += uf[i] == i;
	printf("%d\n", ans);
}


Measured memory_bytes: 640
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 (Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)

#include "bits/stdc++.h"
using i64 = long long;
using namespace std;

int main() {
    i64 a, b, c, d;

    cin >> a >> b >> c >> d;

    i64 ans = max({a*c, a*d, b*c, b*d});

    cout << ans << endl;

    return 0;
};


Measured memory_bytes: 3612
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String k = s.next();
		String t = s.next();
		
		int ctr=0;
		for(int i=0;i<k.length();i++) {
			if(k.charAt(i)==t.charAt(i))
				ctr++;
		}
		System.out.println(ctr);
		
	}
}


Measured memory_bytes: 21716
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  ll ans=0;
  rep(i,0,n){
    ans+=(n-i)*(i+1);
  }
  

  rep(i,0,n-1){
    ll a,b;cin>>a>>b;
    if(a>b)swap(a,b);
    ans-=(a)*(n-b+1);
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3624
#include <iostream>
#include <string>
const int SURFACE_NUM = 6;
enum Direction{TOP, SOUTH, EAST, WEST, NORTH, BOTTOM};

class Dice{
public:
    void roll(char op);
    int top(){
        return label_value[label_dir[TOP]];
    }
    Dice(int label_value[SURFACE_NUM]);
    int getright(int top, int front);
    void resetDirection();
private:
    Direction label_dir[SURFACE_NUM];//lavel_dir[dir] は 方角dirの面p
    int label_value[SURFACE_NUM];//label_value[p] は 面pの数値
};

Dice::Dice(int lv[SURFACE_NUM]){
    for(int i = 0; i < SURFACE_NUM; i++) Dice::label_value[i] = lv[i];
    resetDirection();
}

void Dice::roll(char op){
    Direction tmp;
    switch(op){
    case 'E':
        tmp = label_dir[BOTTOM];
        label_dir[BOTTOM] = label_dir[EAST];
        label_dir[EAST] = label_dir[TOP];
        label_dir[TOP] = label_dir[WEST];
        label_dir[WEST] = tmp;
        break;
    case 'N':
        tmp = label_dir[NORTH];
        label_dir[NORTH] = label_dir[TOP];
        label_dir[TOP] = label_dir[SOUTH];
        label_dir[SOUTH] = label_dir[BOTTOM];
        label_dir[BOTTOM] = tmp;
        break;
    case 'S':
        tmp = label_dir[BOTTOM];
        label_dir[BOTTOM] = label_dir[SOUTH];
        label_dir[SOUTH] = label_dir[TOP];
        label_dir[TOP] = label_dir[NORTH];
        label_dir[NORTH] = tmp;
        break;
    case 'W':
        tmp = label_dir[EAST];
        label_dir[EAST] = label_dir[BOTTOM];
        label_dir[BOTTOM] = label_dir[WEST];
        label_dir[WEST] = label_dir[TOP];
        label_dir[TOP] = tmp;
        break;
    }
}

int Dice::getright(int top, int front){
    //前面を確定
    if(front != label_value[label_dir[SOUTH]]){
        if(front == label_value[label_dir[WEST]]){
            roll('E');
            roll('S');
        }else if(front == label_value[label_dir[EAST]]){
            roll('W');
            roll('S');
        }else{
            do{
                roll('S');
            }while(front != label_value[label_dir[SOUTH]]);
        }
    }
    
    //上面を確定
    while(top != label_value[label_dir[TOP]]) roll('E');
    
    return label_value[label_dir[EAST]];
}

void Dice::resetDirection(){
    for(int i = 0; i < SURFACE_NUM; i++) Dice::label_dir[i] = static_cast<Direction>(i);
    /*
    label_dir[0] = label_dir[TOP] = 0;//面0
    label_dir[1] = label_dir[SOUTH] = 1;//面1
    ...
    label_dir[5] = label_dir[BOTTOM] = 5;//面5
    */
}

int main(){
    using namespace std;
    int dice_value[SURFACE_NUM];
    for(int i = 0; i < SURFACE_NUM; i++) cin >> dice_value[i];
    Dice d(dice_value);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int front, top;
        cin >> top >> front;
        d.resetDirection();
        cout << d.getright(top, front) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3072
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll nCr(int n, int r){
    if(n==r)return 1;
    if(n<r)return 0;
    if(r==0)return 1;
    if(r==1)return n;
    return nCr(n-1, r-1)+nCr(n-1, r);
}
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> cn;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        cn[A[i]]++;
    }
    
    ll total = 0;
    for (auto p : cn)
    {
        auto k = p.first;
        auto v = p.second;
        total += nCr(v, 2);
    }

    for (int i = 0; i < N; i++)
    {
      	int tmp = (cn[A[i]]>0)? cn[A[i]]-1 : 0;
        ll ans = total - tmp;
        cout << ans << endl;
    }
    

}

Measured memory_bytes: 8320
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


using namespace std;

int MAP[10][5];
int h;
void fall(){
  rep(i,h){
    for(int i=h-1;i>0;i--) rep(j,5){
      if(MAP[i][j]==-1){
        MAP[i][j]=MAP[i-1][j];
        MAP[i-1][j]=-1;
      }
    }
  }
}

int search(int x,int y,int num,int count){
  
  if(x<0||y<0||x>=5) return count;
  if(MAP[y][x]==-1||MAP[y][x]!=num) return count;
  

  int ans = 0;
  count++;
  count = search(x+1,y,num,count);

  if(count>=3) MAP[y][x]=-1;

  return count;
}

int main(){

  while(1){
    cin >> h;

    if(h==0) break;

    int ans=0;
    int p_score=-1;
      memset(MAP,-1,sizeof(MAP));
      rep(i,h) rep(j,5) cin >> MAP[i][j];


      while(1){
        rep(i,h) rep(j,5){
          int point = MAP[i][j];  
          int combo = search(j,i,MAP[i][j],0);
          if(combo>=3){
            //cout << combo << " " << point << endl;
            ans+=combo*point;
          }
        }

        fall();

        if(p_score==ans) break;
        p_score=ans;
      }
    cout << ans << endl;
  }

}

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

int main() {
    int N, L;
    cin >> N >> L;
    int min = INT_MAX;
    int sum = 0;
    int i;
    rep(i, N) {
        if (abs(L+i) < abs(min)) min = L+i;
        sum += L+i;
    }

    cout << sum - min << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define BIG 10e9
#define N 100
using namespace std;

void show(int *Array,int ArrayLength) {
	for (int i = 0; i < ArrayLength; i++) {
		if (i != ArrayLength - 1) {
			printf("%d ", Array[i]);
		}
		else {
			printf("%d\n", Array[i]);
		}
	}
}

void insertionSort(int* Array, int ArrayLength) {
	int tmp;
	int j = 0;
	for (int i = 1; i <= ArrayLength - 1; i++) {
		tmp = Array[i];
		for (j = i - 1; (j >= 0) && (Array[j] > tmp); j--) {
			Array[j + 1] = Array[j];
		}
		Array[j+1] = tmp;
		show(Array, ArrayLength);
	}
}


int main() {
	int inputN;
	int A[N];

	scanf("%d", &inputN);
	for (int i = 0; i < inputN; i++) {
		scanf("%d", &A[i]);
	}
	show(A, inputN);
	insertionSort(A, inputN);
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    ll n, m; cin >> n >> m;
    if(n > m) swap(n, m);
    ll ans = 0;
    if(n==1&&m==1) ans = 1;
    else if(n==1&&m>=2) ans = m - 2;
    else ans = (n-2) * (m-2);
    cout << ans;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>

using namespace std;

bool color[8];
int ans = 0;
int extra = 0;

int N;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a < 400)color[0] = true;
		else if (a < 800)color[1] = true;
		else if (a < 1200)color[2] = true;
		else if (a < 1600)color[3] = true;
		else if (a < 2000)color[4] = true;
		else if (a < 2400)color[5] = true;
		else if (a < 2800)color[6] = true;
		else if (a < 3200)color[7] = true;
		else extra++;
	}
	for (int i = 0; i < 8; i++)
		if (color[i])ans++;
	cout << max(ans, 1) << " " << ans + extra << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/*a b c b 
  a d d a 
  a d d a
  a b c b 
  	*/
/*
	a b e b a
	c d f d c
	a b e b a
*/
/*
	a b a
	x y x
	x y x
	a b a
*/

int main(){
	int h,w;
	char c;
	int alp[26];
	FOR(i,26) alp[i]=0;
	cin >> h >> w;
	FOR(i,h)
		FOR(j,w){
			cin >> c;

			alp[c-'a']++;
		}
	int c1=0,c2=0,c4=0;
	if(h%2==0 && w%2==0) {
		c4=h*w/4;
	}
	else if(h%2==1 && w%2==1){
		c1=1;
		c2=h/2+w/2;
		c4=(h*w-c1-c2*2)/4;
	}
	else if(w%2==1){
			c2=h/2;
			c4=(h*w-h)/4;	
		}
	else{
		c2=w/2;
		c4=(h*w-w)/4;
	}
	
	//error(c1,c2,c4);
	FOR(i,26) 
		{	
			int x=c4;
			c4-=min(alp[i]/4,c4);
			alp[i]-=min((alp[i]/4)*4,x*4);
			//error(alp[i],c4);
		}
	if(c4 > 0) cout << "No";
	else{
		FOR(i,26){
			int x=c2;
			c2-=min(alp[i]/2,c2);
			alp[i]-=min((alp[i]/2)*2,x*2);
		}
		if(c2>0) cout << "No";
		else{
			FOR(i,26){
				int x=c1;
				c1-=min(alp[i],c1);
				alp[i]-=min(alp[i],x);
			}
			if(c1 > 0) cout << "No";
			else cout << "Yes";
		}
	} 

	

	return 0;
}
/* a b b a
   a d d a
   a b b a*/

Measured memory_bytes: 3568
d = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(d)]
ld = [0]*26
score = 0
def dec(day):
    ans = 0
    for i in range(26):
        ans += c[i]*(day-ld2[i])
    return ans

rss = [[0,0] for i in range(d+1)]

for i in range(1,d+1):
    ma = rss[i-1][0]
    for t in range(26):
        ld2=ld.copy()
        ld2[t]=i
        score=s[i-1][t]-dec(i)
        ma = max(score,ma)
        if score==ma:
            t2=t+1
    rss[i][1]=t2
    print(t2)


Measured memory_bytes: 9296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int    N = in.nextInt();
			String S = in.next();
			int[] X = new int[26];
			int[] Y = new int[26];
			int ans   = 0;
			
			for(int i = 1; i < N - 1; i++) {
				int count = 0;
				for(int j = 0; j < i; j++) {
					X[S.charAt(j)-97]++;
				}
				for(int j = i; j < N; j++) {
					Y[S.charAt(j)-97]++;
				}
				for(int j = 0; j < 26; j++) {
					if(0 < X[j] && 0 < Y[j]) {
						count++;
					}
					X[j] = 0;
					Y[j] = 0;
				}
				ans = Math.max(ans, count);
			}
			out.println(ans);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> a={1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  cin >>x>>y;
  if(a[x-1]-a[y-1]==0)
     cout <<"Yes";
  else{
    cout<<"No";
  }
  return 0;
}


Measured memory_bytes: 256