akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int sx, sy, tx, ty;

string solve() {
    string res = "";
    for (int i = 0; i < tx-sx; i++) res += 'R';
    for (int i = 0; i < ty-sy; i++) res += 'U';
    for (int i = 0; i < tx-sx; i++) res += 'L';
    for (int i = 0; i < ty-sy; i++) res += 'D';
    res += 'D';
    for (int i = 0; i <= tx-sx; i++) res += 'R';
    for (int i = 0; i <= ty-sy; i++) res += 'U';
    res += 'L';
    res += 'U';
    for (int i = 0; i <= tx-sx; i++) res += 'L';
    for (int i = 0; i <= ty-sy; i++) res += 'D';
    res += 'R';

    return res;
}

void input() {
    cin >> sx >> sy >> tx >> ty;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))
P.sort()
Q.sort()
R.sort()
P = P[::-1]
Q = Q[::-1]
R = R[::-1]


ans = 0

np = nq = nr = 0
x = y = 0
k = 0

while k < X + Y:
    p = -1 if np == X else P[np]
    q = -1 if nq == Y else Q[nq]
    r = -1 if nr == C else R[nr]
    # print(p, q, r)

    if p == max(p, q, r):
        ans += p
        np += 1
    elif q == max(p, q, r):
        ans += q
        nq += 1
    else:
        ans += r
        nr += 1
    k += 1

print(ans)


Measured memory_bytes: 106980
#include<bits/stdc++.h>
using namespace std;
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T GCD_L(T a,T b){
  T r;
  while(a){
    r=b;
    b=a;
    a=r%a;
  }
  return b;
}
template<class T> inline T LCM_L(T a,T b){
  return a/GCD_L(a,b)*b;
}
long long A;
long long B;
long long C;
long long D;
int main(){
  long long m, res;
  rd(A);A += (-1);
  rd(B);
  rd(C);
  rd(D);
  m =LCM_L(C, D);
  res = B - A;
  res -= B / C + B / D - B / m;
  res += A / C + A / D - A / m;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// ll A, B, C, D;
// {
//   ll m, res;
//   rd(A--,B,C,D);
//   m = lcm(C,D);
//   res = B - A;
//   res -= B / C + B / D - B / m;
//   res += A / C + A / D - A / m;
//   wt(res);
// }


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

const int MAX = 59049; // 3 ^ 10
const int MOD = 100000007;

int h,w,v[10][10],memo[10][MAX];

int getbit(int bit, int a){
  for(int i=0;i<a;i++) bit /= 3;
  return bit %= 3;
}

int setbit(int bit, int a, int b){
  return bit + a * (int)pow(3.0,b);
}

void dfs(int y, int x, int bit, int next, int yoko, int prev){
  //cout << "y = " << y << ", x = " << x << ", next = " << next << ", yoko = " << yoko << endl; 

  int gbit = getbit(bit,x);
  int cnt = yoko + gbit;

  if(x >= w - 1){
    if(v[y][x] - cnt >= 0 && v[y][x] - cnt <= 2){
      int nexta = setbit(next,v[y][x]-cnt,x);
      memo[y][nexta] = (memo[y][nexta] + prev) % MOD;
    }else if(v[y][x] == 0 && gbit && yoko == 0){
      int nexta = setbit(next,gbit,x);
      memo[y][nexta] = (memo[y][nexta] + prev) % MOD;
    }
    return;
  }

  if(v[y][x] == 0){
    if(yoko == 0 || gbit == 0) dfs(y,x+1,bit,setbit(next,gbit,x),yoko,prev);
    return;
  }
 
  for(int i=0;i<=2;i++){
    for(int j=0;j<=2;j++){
      if(cnt + i + j == v[y][x]){
        dfs(y, x+1, bit, setbit(next,i,x), j, prev);
      }
    }
  }
}

int main(){
  while(cin >> h >> w){
    int pos = -1;
    fill(memo[0],memo[10],0);
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        char c;
        cin >> c;
        if(c == '.') v[i][j] = 0;
        else v[i][j] = c - '0';
      }
    }
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(v[i][j] > 0){
          dfs(i, j, 0, 0, 0, 1);
          pos = i;
          break;
        }
      }
      if(pos >= 0) break;
    }
    
    for(int i=pos+1;i<h;i++)
      for(int j=0;j<MAX;j++)
        if(memo[i-1][j] > 0)
          dfs(i, 0, j, 0, 0, memo[i-1][j]);
    
    cout << memo[h-1][0] << endl;
  }
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,i;
    string s;
    cin>>x;
    cin>>s;
    if(s.size()<=x)
    {
        cout<<s;
    }
    else
    {
        for(i=0;i<x;i++)
        {
             cout<<s[i];
        }

        cout<<"...";
    }
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1; } return 0; }

struct Edge{
public:
ll from,to,cost;
Edge() {}
Edge(ll _from,ll _to,ll _cost) {
from = _from;
to = _to;
cost = _cost;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<ll, ll> P;

vll dijkstra(int s, Graph G) {//s=>始点
	priority_queue<P, vector<P>, greater<P> > que;
	vll D(SZ(G), LINF);
	D[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first)continue;
		for (Edge e : G[v]) {
			if (D[e.to] > D[v] + e.cost) {
				D[e.to] = D[v] + e.cost;
				que.push(P(D[e.to], e.to));
			}
		}
	}
	return D;
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	Graph G(N);
	REP(i, N - 1) {
		ll u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		G[u].push_back(Edge(u, v, w));
		G[v].push_back(Edge(v, u, w));
	}
	vll d = dijkstra(0, G);
	REP(i, N) {
		cout << d[i] % 2 << endl;
	}
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  ll mod = pow(10, 9) + 7;
  int l = S.length();
  ll dp[l + 1][13]{};
  dp[0][0] = 1;
  for (int i = 0; i < l; i++) {
    if (S[i] != '?') {
      int t = S[i] - '0';
      for (int j = 0; j < 13; j++) {
        dp[i + 1][(10 * j + t) % 13] += dp[i][j];
        dp[i + 1][(10 * j + t) % 13] %= mod;
      }
    } else {
      for (int j = 0; j < 13; j++) {
        for (int k = 0; k < 10; k++) {
          dp[i + 1][(10 * j + k) % 13] += dp[i][j];
          dp[i + 1][(10 * j + k) % 13] %= mod;
        }
      }
    }
  }
  cout << dp[l][5] << "\n";
  return 0;
}

Measured memory_bytes: 10624
S = input()
N = len(S)
total = 0

for bit in range(1 << (N-1)):
  f = S[0]
  for i in range(N-1):
    if bit & (1 << i):
      f += '+'
    f += S[i+1]
  total += sum(map(int, f.split('+')))

print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
//char chess(int i,int j);
int main(void){
    int H,W;
    while (true){
        cin >> H >> W;
        if (H==0&&W==0){
            break;;
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout << '#';
        }
        cout << endl ;
        }
     cout << endl;
    }
}



Measured memory_bytes: 3096
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Div Game
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_P = 1001000;
const int K = 10;

/* typedef */

typedef long long ll;

/* global variables */

bool primes[MAX_P + 1];
int pnums[MAX_P], ss[K];;

/* subroutines */

int gen_primes(int maxp, int pnums[]) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  int p, pn = 0;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums[pn++] = p;
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums[pn++] = p;
  return pn;
}

/* main */

int main() {
  int pn = gen_primes(MAX_P, pnums);
  //printf("pn=%d\n", pn);

  ss[0] = 0;
  for (int k = 1; k < K; k++) ss[k] = ss[k - 1] + k;

  ll n;
  scanf("%lld", &n);

  int cnt = 0;
  for (int i = 0; (ll)pnums[i] * pnums[i] <= n; i++)
    if (n % pnums[i] == 0) {
      int f = 0;
      while (n % pnums[i] == 0) n /= pnums[i], f++;

      int k = upper_bound(ss, ss + K, f) - ss - 1;
      cnt += k;
    }

  if (n > 1) cnt++;

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


Measured memory_bytes: 4524
#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>;
using v  = vector<int>;
using vv = vector<v>;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    cout << 3*n*n << endl;
    
    return 0;
}

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

bool is_capital(char c) {
    return 'A' <= c && c <= 'Z';
}

int atom(string const& s, int& p, map<string, int>& m) {
    string atm;
    atm += s[p++];
    while('a' <= s[p] && s[p] <= 'z') {
        atm += s[p++];
    }
    if(m.count(atm) == 0) {
        throw std::runtime_error("bad");
    }
    return m[atm];
}

int number(string const& s, int& p) {
    int res = 0;
    while(isdigit(s[p])) {
        res *= 10;
        res += s[p++]-'0';
    }
    return res;
}

int molecule(string const& s, int& p, map<string, int>& m) {
    int res = 0;
    while(p < s.size()) {
        int t = 0;
        if(is_capital(s[p])) {
            t += atom(s, p, m);
            if(isdigit(s[p])) {
                t *= number(s, p);
            }
        } else if(s[p] == '(') {
            t += molecule(s, ++p, m);
            t *= number(s, ++p);
        } else if(s[p] == ')') {
            break;
        }
        res += t;
    }
    return res;
}

int main() {
    string s;
    map<string, int> m;
    while(cin >> s, s != "END_OF_FIRST_PART") {
        int n; cin >> n;
        m[s] = n;
    }
    while(cin >> s, s != "0") {
        try {
            int p=0;
            int res = molecule(s, p, m);
            cout << res << endl;
        } catch(...) {
            cout << "UNKNOWN" << endl;
        }
    }
}


Measured memory_bytes: 3160
n,m=map(int,input().split())
a=[ -int(i) for i in input().split()]
import heapq
heapq.heapify(a)
for i in range(m):
  x=heapq.heappop(a)
  heapq.heappush(a,-(-x//2))
  
print(-sum(a))

Measured memory_bytes: 15196
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const string space=" ";
int main(){
	while(1){
		int n,l,r;
		cin>>n>>l>>r;
		if(!n)break;
		int a[n];
		rep(i,n)cin>>a[i];
		int ans=0;
		REP(i,l,r){
			int j;
			for(j=0;j<n;j++){
				if(i%a[j]==0){
					if(j%2==0)ans++;
					break;
				}
			}
			if(j==n&&n%2==0)ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3160
#include<stdio.h>

int main(void)
{
	int n, b, f, r, v, i, j, k = 0;
	int ar[4][3][10] = {{{0}}};
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++) 
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);
		
		ar[b - 1][f - 1][r - 1] = ar[b - 1][f - 1][r - 1] + v;
	}
	
	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 3; j++)
		{
			for(k = 0; k < 10; k++)
			{
				printf(" %d", ar[i][j][k]);
			}
			printf("\n");
		}
		if(i != 3) printf("####################\n");
	}
	
	return 0;
}


		


Measured memory_bytes: 2044
n = int(input())
a = [int(x) for x in input().split()]
count = 0

for i in range(n):
    for j in range(0, n-i-1):
        if a[j] > a[j+1]:
            a[j], a[j+1] = a[j+1], a[j]
            count += 1

print(' '.join([str(x) for x in a]))
print(count)


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

typedef long long ll;

ll comp(ll n,ll r){
    if(r>n||r<0) return 0;
    ll i;
    ll c=1;
    for(ll i=1;i<=r;i++){
        c=c*(n+1-i)/i;
    }
    return c;
}

int main(){
    ll N,A,B; cin >> N >> A >> B;
    ll v[N+1];
    map<ll,ll> ma;
    for(ll i=1;i<=N;i++){
        cin >> v[i];
        ma[v[i]]++;
    }
    sort(v+1,v+N+1,greater<ll>());
    double ave=0;
    for(int i=1;i<=A;i++){
        ave+=v[i];
        //cout << v[i] << endl;
    }
    ave/=A;
    cout << setprecision(20) << ave << endl;
    ll ans=0;
    if(v[1]!=v[A]){
        ll cnt=0;
        for(ll i=1;i<=A;i++){
            if(v[i]==v[A]) cnt++;
        }
        ans=comp(ma[v[A]],cnt);
    }else{
        for(ll i=A;i<=B;i++){
            if(v[i]==v[A]){
                ans+=comp(ma[v[A]],i);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e10;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
typedef tuple<int, int, int> Q;


int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    int a1_a2 = abs(a2 - a1);
    int a2_a3 = abs(a3 - a2);
    int a3_a1 = abs(a3 - a1);


    int ans_1 = a1_a2 + a2_a3;
    int ans_2 = a2_a3 + a3_a1;
    int ans_3 = a3_a1 + a1_a2;

    int ans = INF;

    ans = min(ans, ans_1);
    ans = min(ans, ans_2);
    ans = min(ans, ans_3);

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string s, t;
        cin >> s >> t;
        sort(all(s));
        sort(t.rbegin(), t.rend());
        if (s < t) {
                cout << "Yes" << endl;
        }  else {
                cout << "No" << endl;
        }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,t;
	cin >> n >> x>> t;
	int d = x;
	int p = t;
	while(x<n){
		x+=d;
		p+=t;
	}
	cout << p << endl;
	return 0;
}



Measured memory_bytes: 3616
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <iostream>
#include <set>
#include <assert.h>

using namespace std;

struct Tree {
  Tree *left;
  Tree *right;
  set<string> unions;
  string code;
  double v;
  Tree() : left(NULL), right(NULL), v(-1) {;}
  bool operator<(const Tree &rhs) const { 
    if (v != rhs.v) { return v > rhs.v; }
    if (left == NULL && rhs.left == NULL) { return false; }
    if (max(*left, *right) != max(*rhs.left, *rhs.right)) {
      return max(*left, *right) < max(*rhs.left, *rhs.right);
    }
    return min(*left, *right) < min(*rhs.left, *rhs.right);
  }
  bool operator!=(const Tree &rhs) const {
    return *this < rhs || rhs < *this;
  }
};

char str[10000];

Tree *parse(int &index) {
  if (isspace(str[index])) { index++; }
  if (str[index] == 'x') {
    index++;
    return new Tree();
  }
  Tree *ret = new Tree();
  assert(str[index] == '(');
  index++;
  ret->left = parse(index);
  ret->right = parse(index);
  assert(str[index] == ')');
  index++;
  return ret;
}

string encode(Tree *tree) {
  if (tree->left == NULL) {
    return "x";
  }
  string ret = "(" + encode(tree->left) + " " + encode(tree->right) + ")";
  return ret;
}

void calcv(Tree *tree) {
  if (tree->left == NULL) {
    tree->v = 0.0;
  } else {
    calcv(tree->left);
    calcv(tree->right);
    set<string> l = tree->left->unions;
    set<string> r = tree->right->unions;
    tree->unions = l;
    tree->unions.insert(r.begin(), r.end());
    int all = tree->unions.size();
    int sub = l.size() + r.size() - all;
    tree->v = (double)sub / (double)all;
    if (tree->left->code < tree->right->code) {
      swap(tree->left, tree->right);
    }
  }
  tree->code = encode(tree);
  tree->unions.insert(tree->code);
}

void dfs(Tree *tree, bool left) {
  if (tree->left == NULL) { return; }
  if (left) {
    if (*tree->left < *tree->right) {
      swap(tree->left, tree->right);
    }
  } else {
    if (*tree->right < *tree->left) {
      swap(tree->left, tree->right);
    }
  }
  dfs(tree->left, true);
  dfs(tree->right, false);
}

int main() {
  while (fgets(str, 9999, stdin), str[0] != '0') {
    int index = 0;
    Tree *root = parse(index);
    calcv(root);
    dfs(root, true);
    cout << encode(root) << endl;
  }
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ans = 0;
    rep(i, 4) {
        if (S[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func newInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := newInt()
	d := newInt()

	count := 0

	for i := 0; i < n; i++ {
		x := newInt()
		y := newInt()

		if x*x+y*y <= d*d {
			count++
		}
	}
	fmt.Println(count)
}


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

int main() {
    int h, w;
    cin >> h >> w;
    char c[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int k = 0; k < 2; k++){
            for (int j = 0; j < w; j++) {
                cout << c[i][j];
            }
            cout << endl;
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n, m;
    cin >> n >> m;
    vector<int> ans(n);
    if(m == 0){
        if(n == 1) ans[0] = 0;
        if(n == 2) {
            ans[0] = 1;
            ans[1] = 0;
        }
        if(n == 3){
            ans[0] = 1; ans[1] = 0; ans[2] = 0;
        }
        for (auto& p : ans) {
            cout << p;
        }
        cout << endl;
        return 0;
    }
    vector<P> v(m);
    rep(i, m){
        cin >> v[i].first >> v[i].second;
    }

    sort(all(v));
    rep(i, m-1){
        if(v[i].first == v[i+1].first){
            if(v[i].second != v[i+1].second){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    
    if(n != 1)ans[0] = 1;
    rep(i, m){
        ans[v[i].first-1] = v[i].second;
    }
    if(ans[0] == 0 && n != 1){
        cout << -1 << endl;
        return 0;
    }
    for (auto& p : ans) {
        cout << p;
    }
    cout << endl;

    return 0;
}


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

int main(){
    int s[3];
    cin>>s[0]>>s[1]>>s[2];
    int seven=0; int five=0;
    for(int i=0;i<3;i++){
        switch (s[i])
        {
            case 5:
                five++;
                break;
            case 7:
                seven++;
                break;
            default:
                break;
        }
    }

    if(five==2&&seven==1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l,r = map(int, input().split())
    print(t[r-1] - t[l-1]) 



Measured memory_bytes: 13036
def slv():
 sq1 = raw_input()
 sq2 = raw_input()
 a, b = len(sq1), len(sq2)
 x1 = [0 for i in range(b+1)]
 for i in range(a):
  e1 = sq1[i]
  x2 = x1+[]
  for j in range(b):
   if e1 == sq2[j]:
    x1[j+1] = x2[j] + 1
   elif x1[j+1]<x1[j]:
    x1[j+1] = x1[j]
 return x1[-1]
n = input()
for i2 in range(n):
 print slv()

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 2e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, B; cin >> A >> B;
    if(A + B >= 10) cout << "error" << endl;
    else cout << A + B << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
import sys
K, X = map(int, raw_input().split())

assert(1<= K <= 100)
assert(0<=X<=100)

left = X - (K - 1)
left = max(left, -1000000)

right = X + (K - 1)
right = min(right, 1000000)

for i in range(left, right + 1):
    print i,

Measured memory_bytes: 2568
#include<iostream>
#include<cstring>
using namespace std;
int main( ){
  while(1){
    int s=0,d=0;
    char a[1000];
    cin>>a;
    if(a[0]==48)break;
    for(int i=0;i<strlen(a);i++){
      s+=a[i];
      d++;
    }
    cout<<s-d*48<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,a,b,temp,x,y;
string str;
set<ll> s;
const int m=1e9+7;
ll factorial [100000+1];
 
ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
ll inverse(ll a) 
{ 
    { 
        return  power(a, m-2, m); 
    } 
}
long long binomial_coefficient(int n, int k) {
    return factorial[n] * inverse(factorial[k]) % m * inverse(factorial[n - k]) % m;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	ll k;
	cin>>k;
	vll v(n);
	read(v);
	factorial[0] = 1;
    for (int i = 1; i <= 100000; i++) 
    {
    factorial[i] = factorial[i - 1] * i % m;
     }
	sort(v.begin(),v.end(),greater<>());
	ll ans=0;
	for(int i=0;i<n-k+1;i++)
	{
	    ans+=(v[i]*binomial_coefficient(n-i-1,k-1))%m;
	    ans%=m;
	}
	sor(v);
    for(int i=0;i<n-k+1;i++)
    {
        ans=(ans-(v[i]*binomial_coefficient(n-i-1,k-1))%m);
        if(ans<0)
        ans+=m;
        ans%=m;
    }
	cout<<ans%m;
}

Measured memory_bytes: 1792
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, sys.stdin.buffer.readline().split())
rest = np.array(sys.stdin.buffer.read().split(), np.int)
in_, out, weight = rest[0:3*M:3], rest[1:3*M:3], rest[2:3*M:3]

graph = csr_matrix((weight, (in_, out)), shape=(N+1, N+1))
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0

S, T = rest[3*M+1::2], rest[3*M+2::2]
print(*(graph[S, T].astype(int) - 1), sep='\n')


Measured memory_bytes: 32532
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string c1, c2;
  cin >> c1 >> c2;
  
  if(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3628
//Author : Nishit Patel
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef double db;
typedef long long ll;
#define pb push_back
#define FAST cin.sync_with_stdio(0); cin.tie(0);
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define arep(i, a, n)  for(int i = a; i <= (n); ++i)
#define drep(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x)     for(auto& a : x)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef unordered_map<ll, ll> hash;
#define deb_1(A)                     {cerr << "[" << #A << "] : " << A << endl;}
#define deb_2(A,B)                   {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl;}
#define deb_3(A,B,C)                 {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl\
									   << "[" << #C << "] : " << C << endl;}
#define deb_4(A,B,C,D)               {cerr << "[" << #A << "] : " << A << endl<< "[" << #B << "] : " << B << endl\
									   << "[" << #C << "] : " << C << endl<< "[" << #D << "] : " << D << endl;}
#define deb_X(x,A,B,C,D,FUNC, ...)  FUNC  
#define deb(...)                    deb_X(,##__VA_ARGS__,\
                                          deb_4(__VA_ARGS__),\
                                          deb_3(__VA_ARGS__),\
                                          deb_2(__VA_ARGS__),\
                                          deb_1(__VA_ARGS__),\
                                         )
                                         
                                         
ll max(ll a, ll b)
{
	if(a>b) return a;
	return b;
}
int itr = 0;
ll n;
ll knapsack(ll v[],ll w[],ll W ,ll n,ll curr,vector<vector<ll> > &dp)
{
	itr++;
	if(curr<0 || W == 0)return 0;
	if(dp[curr][W] != -1) return dp[curr][W];
	if(w[curr] <= W)
	{
		ll temp = max(knapsack(v,w,W-w[curr],n,curr-1,dp)+v[curr],knapsack(v,w,W,n,curr-1,dp));
		dp[curr][W] = temp;
		//deb(dp[curr][W]);
		return temp;
	}
	else{
		return knapsack(v,w,W,n,curr-1,dp);
	}
}

int main() {
	FAST
	ll W;
	cin>>n>>W;
	ll v[n],w[n];
	//ll dp[n][W+1];
	vector<vector<ll> > dp(n+1,vector<ll> (W+1,-1));
	//memset(dp,-1,sizeof(dp));
	
	rep(i,n)
	{
		cin>>w[i]>>v[i];
	}
	//deb(v[0]);
	ll ans = knapsack(v,w,W,n,n-1,dp);
	//deb(itr);
	cout<<ans<<endl;
		
	
}


Measured memory_bytes: 83100
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  double odd=0;
  for(int i=1;i<=N;i++) {
    if(i%2==1) {
      odd++;
    }
  }
    cout<<odd/N<<endl;
    return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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 T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
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; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
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; }



int N;
string S;
long long m, c, tmp;

void add(int i) {
    if (S[i] == 'M') {
        ++m;
    }
    else if (S[i] == 'C') {
        ++c;
        tmp += m;
    }
}

void erase(int i) {
    if (S[i] == 'M') {
        --m;
        tmp -= c;
    }
    else if (S[i] == 'C') {
        --c;
    }
}

long long solve(int K) {
    long long res = 0;
    m = 0; tmp = 0;
    int i = 0, j = 0;
    while (j < K) {
        add(j++);
        //cout << i << ", " << j << ": " << S.substr(i, j-i) << ": " << m << ", " << c << ", " << tmp << endl;
    }
    while (j < N) {
        if (S[i] == 'D') res += tmp;
        erase(i++);
        add(j++);
        //cout << i << ", " << j << ": " << S.substr(i, j-i) << ": " << m << ", " << c << ", " << tmp << endl;
    }
    while (i < N) {
        if (S[i] == 'D') res += tmp;
        erase(i++);
        //cout << i << ", " << j << ": " << S.substr(i, j-i) << ": " << m << ", " << c << ", " << tmp << endl;
    }
    return res;
}

int main() {
    while (cin >> N >> S) {
        int Q; cin >> Q;
        for (int i = 0; i < Q; ++i) {
            int k; cin >> k;
            cout << solve(k) << endl;
        }
    }
}


Measured memory_bytes: 1412
// A - AtCoder Beginner Contest 999
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string N; cin>>N;
	rp(i, 0, 3) N[i] = N[i]=='1'?'9':'1';
	cout<< N <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define llint long long
#define mod 1000000007

using namespace std;

llint fact[1005], fact_inv[1005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 1005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 1005; i++){
		fact_inv[i] = modpow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint n;
llint a[205];
llint keta[205];
llint beki[1005];
llint num[205];
llint cnt[6];
llint dp[6][205][1005];

llint calc2(int x)
{
	cnt[x]--; n--;
	
	for(int i = 0; i <= 5; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k < 1005; k++){
				dp[i][j][k] = 0;
			}
		}
	}
	dp[0][0][0] = 1;
	
	for(int i = 0; i < 5; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k < 1005; k++){
				for(int l = 0; l <= cnt[i+1]; l++){
					if(j+l <= n && k+l*(i+1) < 1005){
						dp[i+1][j+l][k+l*(i+1)] += dp[i][j][k] * comb(cnt[i+1], l) % mod;
						dp[i+1][j+l][k+l*(i+1)] %= mod;
					}
				}
			}
		}
	}
	
	llint ret = 0;
	for(int j = 0; j <= n; j++){
		for(int k = 0; k < 1005; k++){
			llint tmp = dp[5][j][k] * fact[j] % mod;
			tmp *= num[n-j], tmp %= mod;
			tmp *= beki[k], tmp %= mod;
			ret += tmp, ret %= mod;
		}
	}
	cnt[x]++; n++;
	
	return ret;
}

llint calc()
{
	for(int i = 1; i <= 5; i++) cnt[i] = 0;
	for(int i = 1; i <= n; i++) cnt[keta[i]]++;
	
	llint ret = 0;
	for(int i = 1; i <= 5; i++){
		llint tmp = calc2(i);
		for(int j = 1; j <= n; j++){
			if(keta[j] == i){
				ret += tmp * a[j] % mod;
				ret %= mod;
			}
		}
	}
	return ret;
}

llint getketa(llint x)
{
	if(x == 0) return 1;
	llint ret = 0;
	for(;x;x/=10) ret++;
	return ret;
}

int main(void)
{
	make_fact();
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	reverse(a+1, a+n+1);
	
	if(n == 1){
		cout << a[1] << endl;
		return 0;
	}
	
	beki[0] = 1;
	for(int i = 1; i < 1005; i++) beki[i] = beki[i-1]*10%mod;
	for(int i = 1; i <= n; i++) keta[i] = getketa(a[i]);
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= i; j++){
			num[i] += comb(i, j) * fact[j] % mod;
			num[i] %= mod;
		}
	}
	
	llint ans = calc(), zcnt = 0;
	for(int i = 1; i <= n; i++) if(a[i] == 0) zcnt++;
	n--;
	ans += mod - zcnt*calc()%mod;
	ans %= mod;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 12576
const gInput = require('fs').readFileSync('/dev/stdin', 'utf8')
const input = gInput.split(' ').map( s => parseInt(s))

const a = input[0]
const b = input[1]

if(a < b){
    console.log('a < b')
} else if( a > b){
    console.log('a > b')
} else {
    console.log('a == b')
}


Measured memory_bytes: 15124
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{
  int n,a=0,b;
  cin>>b>>a;
  
  
  cout<<round((a+b)/2.0)<<endl;

}
return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int w = sc.nextInt();
    for (int i = 0; i < s.length(); i++) {
      if (i % w == 0) {
        System.out.print(s.charAt(i));
      }
    }
  }
}

Measured memory_bytes: 23764
n, x = map(int, input().split())
a = [abs(y-x) for y in map(int, input().split())]


def gcd(a, b):
    # 最大公約数
    while b > 0:
        a, b = b, a % b
    return a

ret = a[0]

for i in range(1, n):
    ret = gcd(ret, a[i])
print(ret)

Measured memory_bytes: 14252
# code-festival-2016-qualaC - 次のアルファベット / Next Letter
from string import ascii_lowercase as abc


def main():
    S = input().rstrip()
    K = int(input())
    N, MOD = len(S), 26
    # dist[c] := distance to "a" through "z"
    dist = {c: 26 - i for i, c in enumerate(abc)}
    dist["a"] = 0
    A = [dist[i] for i in S]
    for i in range(N):
        if A[i] and A[i] <= K:  # A[i] -> "a" if possible
            A[i], K = 0, K - A[i]
    A[-1] = (A[-1] - K) % MOD  # use the remaining K on A[-1]
    rest = {v: k for k, v in dist.items()}
    ans = [rest[i] for i in A]  # restore dist to chr
    print(*ans, sep="")


if __name__ == "__main__":
    main()

Measured memory_bytes: 8476
#include <stdio.h>
int main(){
	for(;;){
		int max=0,set[100000],n,m,a,b,c;
		scanf("%d%d",&n,&m);
		if(n==0&&m==0){
			break;
		}
		for(a=0;a<n;a++){
			scanf("%d",&set[a]);
		}
		for(a=0;a<n-m;a++){
			c=0;
			for(b=0;b<m;b++){
				c+=set[a+b];
			}
			if(max<c)max=c;
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 2960
-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU
 
-- 解説読後
-- http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf

import qualified Data.ByteString.Char8 as C
import Data.Array (listArray, accumArray, (!))
 
main = print . solve .map red . C.words =<< C.getContents
    where
        red x = case C.readInteger x of Just v -> fst v

solve (n:x:a) = ans where
    sm = sum a
    ans = f n sm a x
    f 1 r _ _ = r
    f c r ar xx = f (c - 1) r2 ar2 (xx + x) where
        ar2 =zipWith min a $ [last ar] ++ ar
        r2 = minimum [r, xx + sum ar2]


Measured memory_bytes: 3452
#include<iostream>
#define abs(k) ((k > 0) ? (k) : (-1)*(k))
using namespace std;
int main(){
	int n;
	cin >> n;
	int k;
	cin >> k;
	int h[n];
	int dp[n];
	for(int a = 0;a < n;a++){
		cin >> h[a];
		dp[a] = 0;
	}
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int a = 2;a < n;a++){
		dp[a] = 2000000000;
		for(int b = 1;b <= k;b++){
			if (a - b < 0) break;
			dp[a] = min(dp[a],dp[a-b] + abs(h[a-b]-h[a]));
		}
	}
	cout << dp[n-1];
}

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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=300010;
struct Point
{
    int x,y;
    Point(int _x=0,int _y=0):x(_x),y(_y){}
    bool operator < (Point a) const{return x<a.x||x==a.x&&y<a.y;}
} a[N];
int mx[N<<2],tag[N<<2];
stack<Point> s1,s2;
int w,h,n,ans=0;

void add(int o,int l,int r,int nl,int nr,int x)
{
    if(l>=nl&&r<=nr)
    {
        mx[o]+=x;
        tag[o]+=x;
        return;
    }
    int mid=(l+r)/2;
    if(nl<=mid) add(o<<1,l,mid,nl,nr,x);
    if(nr>mid) add(o<<1|1,mid+1,r,nl,nr,x);
    mx[o]=max(mx[o<<1],mx[o<<1|1])+tag[o];
}

void gao()
{
    memset(mx,0,sizeof(mx));
    memset(tag,0,sizeof(tag));
    sort(a+1,a+1+n);
    while(!s1.empty()) s1.pop();
    while(!s2.empty()) s2.pop();
    for(int i=1;i<=n;i++)
    {
        if(a[i].y<=h/2)
        {
            int nxt=i-1;
            while(!s1.empty()&&s1.top().y<a[i].y)
            {
                Point p=s1.top();s1.pop();
                add(1,1,n,p.x,nxt,p.y-a[i].y);
                nxt=p.x-1;
            }
            if(nxt!=i-1) s1.push(Point(nxt+1,a[i].y));
        }
        else
        {
            int nxt=i-1;
            while(!s2.empty()&&s2.top().y>a[i].y)
            {
                Point p=s2.top();s2.pop();
                add(1,1,n,p.x,nxt,a[i].y-p.y);
                nxt=p.x-1;
            }
            if(nxt!=i-1) s2.push(Point(nxt+1,a[i].y));
        }
        s1.push(Point(i,0));
        s2.push(Point(i,h));
        add(1,1,n,i,i,h-a[i].x);
        ans=max(ans,mx[1]+a[i+1].x);
    }
}

int main()
{
    w=read();h=read();n=read();
    for(int i=1;i<=n;i++)
        a[i].x=read(),a[i].y=read();
    a[++n]=Point(0,0);a[++n]=Point(w,h);gao();
    for(int i=1;i<=n;i++) swap(a[i].x,a[i].y);
    swap(w,h);gao();
    printf("%d\n",ans<<1);
    return 0;
}

Measured memory_bytes: 14284
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<string> vec(N);
  for(int i=0;i<N;i++) {
    cin>>vec.at(i);
  }
  string ans="Yes";
  
  for(int i=0;i<N-1;i++) {
    if(vec.at(i)[vec.at(i).size()-1]!=vec.at(i+1)[0]) {
      ans="No";
      break;
    }
  }
  
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<N-1;i++) {
    if(vec.at(i)==vec.at(i+1)){
      ans="No";
      break;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int n;
     cin>>n;
     vi v(n);
     in(v,n);
     sort(all(v));
     int res=0;
     for (int i = 0; i < n - 2; ++i)  
    {  
        int k=0;
        for (int j = i + 1; j < n; ++j)  
        {  
           while (k < n && v[i] + v[j] > v[k])  
            ++k;  
            if(k > j)  
            res += k - j - 1;  
        }  
    }  
     cout<<res<<endl;
     time();
     return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int c, r,a[101][101],i, j;
  scanf("%d %d", &r, &c);
  for(i=0;i<101;i++){
    for(j=0;j<101;j++){
      a[i][j] = 0;
    }
  }
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf("%d", &a[i][j]);
      a[i][100] += a[i][j];
      a[100][j] += a[i][j];
    }
  }
  for(i=0;i<r+1;i++){
    for(j=0;j<c+1;j++){
      if(i<r){
      if(j<c)
      printf("%d ", a[i][j]);
      else{
        printf("%d\n",a[i][100]);
      }
    }
      else{
        if(j<c){
        printf("%d ", a[100][j]);
        a[100][100] += a[100][j];
      }
        else{
          printf("%d\n", a[100][100]);
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2112
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <iostream>

using namespace std;

long long puf[200004],suf[200004],k,n,m;
bool func(long long x)
{
    long long sum=0LL;
    if(x==0LL){return true;}
   for(long long i=1;i<=x;i++)
   {
       if(x>=i+1&&i<=n&&x-i<=m){sum=suf[i]+puf[x-i];
       if(sum<=k){return true;}
                 }
     //cout<<"bbb";
   }
   if((x<=n&&suf[x]<=k)||(x<=m&&puf[x]<=k)){return true;}
   return false;
    
}
int main()
{
    long long i,lo,hi,mid;
    cin>>n>>m>>k;
    long long arr[n+1],brr[m+1];
    for(i=1;i<=n;i++){cin>>arr[i];}
    for(i=1;i<=m;i++){cin>>brr[i];}
    //if(arr[0]>k&&brr[0]>k){cout<<0;return 0;}
    for(i=1;i<=n;i++){if(i==1){suf[i]=arr[i];}else{suf[i]=suf[i-1]+arr[i];}}
    for(i=1;i<=m;i++){if(i==1){puf[i]=brr[i];}else{puf[i]=puf[i-1]+brr[i];}}
    //for(i=1;i<=n;i++){cout<<suf[i]<<" "<<puf[i]<<" "<<i<<"\n";}
    lo=0LL;hi=n+m;
    while(lo<hi)
    {
        //cout<<func(1)<<"aa ";
        mid=lo+(hi-lo+1)/2;
        if(func(mid)){lo=mid;}
        else{hi=mid-1;}
    }
  cout<<lo;
    return 0;
}


Measured memory_bytes: 9836