akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
int num(){
    char s[11];
    int i, n;
    for(i=0; i<sizeof(s); i++){
        s[i] = getchar();
        if(s[i] == ' ' || s[i] == '\n'){
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}
void sort(int x[], int n){
    int y, i, j;
    for(i=n; i>1; i--){
        for(j=0; j<=i-2; j++){
            if(x[j] > x[j+1]){
                y = x[j];
                x[j] = x[j+1];
                x[j+1] = y;
            }
        }
    }
}
void sort2(int x[], int n){
    int y, i, j;
    for(i=n; i>1; i--){
        for(j=0; j<=i-2; j++){
            if(x[j] < x[j+1]){
                y = x[j];
                x[j] = x[j+1];
                x[j+1] = y;
            }
        }
    }
}
int main(void){
    int n, x;
    int a[100];
    int i, y, cou=0;
    
    n = num();
    x = num();
    for(i=0; i<n; i++){
        a[i] = num();
    }
    
    sort(a, n);
    
    for(i=0; i<n; i++){
        if(x >= a[i]){
            x -= a[i];
            cou++;
        }
    }
    
    sort2(a, n);
    
    if(cou == n){
        y = 1;
    }
    else{
        y = 0;
    }
    i=0;
    while(x > 0){
//        x -= a[i];
        if(y==1){
            cou--;
        }
        x -= a[i];
        if(x < 0){
            x *= -1;
        }
        if(a[i] >= x){
            break;
        }
        
    }
//    if(x < 0){
//        cou++;
//    }
    
    printf("%d\n", cou);
    
    return 0;
    
}

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;



int main() {

	int n;
	cin >> n;
	vector<double> x(n), y(n);
	rep(i, n)cin >> x[i] >> y[i];

	double steer = 1;
	vi t = {}, tt = {};
	rep(i, n) { t.push_back(i);tt.push_back(i); steer *=(double) i + 1; }

	double ans = 0;
	int ha = 0;
	do {

		double hoge = 0;
		rep(i, n - 1) {
			hoge += sqrt(	pow(	(x[t[i + 1]] - x[t[i]]),2	)	+	pow(	(y[t[i + 1]] - y[t[i]]),2	)	);
		}
		ans += hoge/steer;
	} while (next_permutation(all(t)));

	cout << fixed << setprecision(8);
	cout << ans<< endl;
}

Measured memory_bytes: 256
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "tmp.cpp"

int main() {
  ll n;
  cin >> n;
  ll ans = 1e14;
  for (ll i = 1; i < min(1000001LL, n + 1); i++) {
    if (n % i == 0) {
      ans = min(ans, n / i - 1 + i - 1);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int comand(string s){
		if(s == "print"){
				return 1;
		}else if(s == "reverse"){
				return 2;
		}else if(s == "replace"){
				return 3;
		}
}

int main(){
		int a,b,q,num;
		string str,com;
		string temp,rep,r_str;

		cin >> str >> q;

		for(int i = 0;i < q;i++){
				cin >> com;
				num = comand(com);

				switch(num){
						case 1: //print a b　a文字目からb文字目まで表示
								cin >> a >> b;
								cout << str.substr(a,b-a+1) << endl;
								break;
						case 2: //reverse a b a文字目からb文字目まで逆順
								cin >> a >> b;
								temp = str.substr(a,b-a+1);
								r_str = temp;
								for(int i = 0;i < temp.size();i++){
										r_str[i] = temp[b-a-i];
								}
								str = str.replace(a,b-a+1,r_str);
								break;
						case 3: //replace a b rep a文字目からb文字目まで任意の文字で置換
								cin >> a >> b >> rep;
								str = str.replace(a,b-a+1,rep);
								break;
						default:
								break;
				}
		}
		return 0;
}

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

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

    double ans;
    for(int i=0; i<k; i++){
        ans += ((p[i] + 1.0)/2.0);
    }

    double pre_ans = ans;
    for(int i=0; i<n-k+1; i++){
        pre_ans -= ((p[i] + 1.0)/2.0);
        pre_ans += ((p[i+k] + 1.0)/2.0);
        ans = max(ans, pre_ans);
    }

    
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int h,w,a,b;

int main(){
    cin>>h>>w>>a>>b;
    REP(i,h){
        REP(j,w){
            int v = (i<b) ^ (j<a);
            putchar(v+'0');
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 1280
/*
                ____________    ______________       __
               / _________  /\ /_____   _____/\     / /\
              / /\       / /  \\    /  /\    \ \   / /  \
             / /  \_____/ /   / \__/  /  \____\/  / /   /
            / /   /    / /   /    /  /   /       / /   /
           / /   /    / /   /    /  /   /       / /   /
          / /   /    / /   /    /  /   /       / /   /
         / /___/____/ /   /    /  /   /       / /___/________
        /____________/   /    /__/   /       /______________/\
        \            \  /     \  \  /        \              \ \
         \____________\/       \__\/          \______________\/
           ___       ___               ___    __________
          /  /\     /  /\             /  /\  /_______  /\
         /  /__\___/  /  \           /  /  \ \      /  /  \
        /____    ____/   /          /  /   /  \____/  /   /
        \   /   /\   \  /          /  /   /       /  /   /
         \_/   /  \___\/ ___      /  /   /       /  /   /
          /   /   /     /  /\    /  /   /       /  /   /
         /   /   /     /  /__\__/  /   /       /  /___/____
        /___/   /     /___________/   /       /___________/\
        \   \  /      \           \  /        \           \ \
         \___\/        \___________\/          \___________\/
       
          A FAN OF FIZZYDAVID
           
*/

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define forn(i,l,r) for(int i=(l);i<=(r);i++)
#define nrof(i,r,l) for(int i=(r);i>=(l);i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-20
#define pi 3.1415926535897932384626433832795
#define orz int
#define yjz main
#define fizzydavid return
#define ak 0
#define la ;
#define debug puts("OK");
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int iinf=1e9+7;
const LL linf=1ll<<60;
const flt dinf=1e10;

template <typename T>
inline void scf(T &x)
{
	bool f=0; x=0; char c=getchar();
	while((c<'0' || c>'9') && c!='-') c=getchar();
	if(c=='-') { f=1; c=getchar(); }
	while(c>='0' && c<='9') { x=x*10+c-'0'; c=getchar(); }
	if(f) x=-x; return;
}

template <typename T1,typename T2>
void scf(T1 &x,T2 &y) { scf(x); return scf(y); }

template <typename T1,typename T2,typename T3>
void scf(T1 &x,T2 &y,T3 &z) { scf(x); scf(y); return scf(z); }

//---------------------------head----------------------------

const int N=2e5+100;

int n,x;
int a[N];
bool used[N];

orz yjz()
{
	scf(n,x);
	if(x==1 || x==2*n-1){ puts("No"); fizzydavid ak la }
	a[n]=x;
	a[n-1]=x-1; a[n+1]=x+1;
	used[x-1]=used[x]=used[x+1]=1;
	int j=1;
	forn(i,1,2*n-1)
	{
		if(a[i]) continue;
		while(used[j]) j++;
		a[i]=j; used[j]=1;
	}
	puts("Yes");
	forn(i,1,2*n-1) printf("%d\n",a[i]);
	fizzydavid ak la
}

Measured memory_bytes: 2432
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

char incrementChar(char x){
    return static_cast<char>(x + 1);
}

int weekToInt(string x){
    int num;
    if(x == "SUN"){
        num = 1;
    }else if(x == "MON"){
        num = 2;
    }else if(x == "TUE"){
        num = 3;
    }else if(x == "WED"){
        num = 4;
    }else if(x == "THU"){
        num = 5;
    }else if(x == "FRI"){
        num = 6;
    }else if(x == "SAT"){
        num = 7;
    }else{
        num = 0;
    }

    return num;
}

// vector<int> v;
// auto it = v.begin();
// 
// it = v.insert(it, A + B);
// it = v.insert(it, A - B);
// it = v.insert(it, A * B);
// 
// int max = *max_element(v.begin(), v.end());
// int min = *min_element(v.begin(), v.end());

// for(int i=0; i<(int)S.size(); i++){
//     sum += count(S.cbegin(), S.cend(), S[i]);
// }

// string s;
// transform(s.begin(), s.end(), s.begin(), ::toUpper();

int main(){
    int S, K;
    cin >> S >> K;

    string s;
    cin >> s;

    s[K-1] = s[K-1] + 'a' - 'A';
    
    cout << s;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<long long, int> cnt;
int main(){
    cnt[0]++;
    int n;
    cin >> n;
    long long sm = 0;
    long long ans = 0;
    while(n--){
        int x;
        cin >> x;
        sm += x;
        ans += cnt[sm];
        cnt[sm]++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
int main()
{
        long long int n;
        cin >> n;
        long long int a[n];
        int i;
        for(i=0;i<n;i++)
                cin >> a[i];
        long long int x=0,y=0;
        long long int b[n];
        sort(a,a+n);
        x=a[0];
        int j;
        while(true)
        {
                int y=x;
                for(i=0;i<n;i++)
                {
                        if(a[i]%x==0);
                        else
                        {
                                a[i]=a[i]%x;
                                x=a[i]%x;
                        }
                }
                if(y==x)
                        break;
        }
        cout << x << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int a, b, c;
  cin >> a >> b >> c;
  ll x = a;
  for(int i = 0; i < 10e5; i++) {
    if(x % b == c) {
      cout << "YES" << endl;
      return 0;
    } else {
      x = x + a;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, m; cin >> n >> m;
  vector<vector<ll>> G(n);
  rep(i, n+m-1) {
    ll a, b; cin >> a >> b; --a, --b;
    G[a].pb(b);
  }
  vector<ll> cnt(n, 0);
  rep(i, n) each(to, G[i]) ++cnt[to];
  queue<ll> Q;
  vector<ll> ord(n, -1);
  ll next_ord = 0;
  rep(i, n) if (cnt[i] == 0) {
    Q.push(i);
    ord[i] = next_ord++;
  }
  assert(Q.size() == 1);
  while (!Q.empty()) {
    ll v = Q.front(); Q.pop();
    ord[v] = next_ord++;
    each(to, G[v]) {
      if (--cnt[to] == 0) {
        Q.push(to);
      }
    }
  }
  // cout << ord << endl;
  vector<P> par(n, P(-1, 0));
  rep(v, n) {
    each(to, G[v]) {
      chmax(par[to], P(ord[v], v+1));
    }
  }
  each(p, par) cout << p.second << endl;
}


Measured memory_bytes: 9472
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int x, y, z;
	cin >> x >> y >> z;
	cout << (x - z) / (y + z) << endl;
	return 0;
}


Measured memory_bytes: 256
/**
 *
 * AtCoder Regular Contest 058 - Problem D: Iroha and the Grid
 *
 * Count the number of ways Iroha can travel from (1,1) to (H, W) in a H x W grid with bottom A 
 * rows and leftmost B columns blocked.
 *
 * Combinatorial solution: compute the number of ways that we can move from O = (1, 1) to 
 * Pk = (k, B) and multiply for the number of ways from Qk = (k, B + 1) to (H, W), 
 * for k = 1, 2, ..., H - A.
 *
 * -----------------------------------
 * |O                   |            | 
 * |                    |            | 
 * |                  Pk|Qk          | 
 * |                    |            | 
 * |                    |            | 
 * |                    |            | 
 * -----------------------------------
 * |xxxxxxxxxxxxxxxxxxxx|            |
 * |xxxxxxxxxxxxxxxxxxxx|            |
 * |xxxxxxxxxxxxxxxxxxxx|            |
 * |xxxxxxxxxxxxxxxxxxxx|           D|
 * -----------------------------------
 *
 * shape(X, Y) = dimensions of the rectangle with upper left corner A and lower right corner B
 *
 * shape(O, Pk) = (k, B)
 * shape(Qk, D) = (H - k + 1, W - B)
 *
 * The number of ways we can travel from (1, 1) to (N, M) in a rectangular grid moving right or 
 * down only is C(M + N - 2, M - 1) = C(M + N - 2, N - 1), because we must walk (M - 1) steps to 
 * right and * (N - 1) steps down, and we must choose when move forward ou move down.
 */
#include <iostream>

using namespace std;

using ll = long long;

const int MAX { 200010 };
const ll MOD { 1000000007 };

ll fact[MAX], inv[MAX];

ll fast_exp(ll a, ll n)
{
    ll res = 1, base = a;

    while (n)
    {
        if (n & 1)
        {
            res *= base;
            res %= MOD;
        }

        base *= base;
        base %= MOD;

        n >>= 1;
    }

    return res;
}

ll binom(int n, int m)
{
    ll res = (fact[n] * inv[m]) % MOD;
    res = (res * inv[n - m]) % MOD;

    return res;
}

void precomp()
{
    fact[0] = inv[0] = 1;

    for (int n = 1; n < MAX; ++n)
        fact[n] = (n * fact[n - 1]) % MOD;

    // Fermat Theorem to compute inverse mod p
    for (int n = 1; n < MAX; ++n)
        inv[n] = fast_exp(fact[n], MOD - 2);
}

// Ways we can move from (1, 1) to (h, w) 
ll ways(int h, int w)
{
    return binom(h + w - 2, h - 1);
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    int H, W, A, B;
    cin >> H >> W >> A >> B;

    ll total = 0;

    for (int k = 1; k <= H - A; ++k)
    {
        total += (ways(k, B) * ways(H - k + 1, W - B)) % MOD;
        total %= MOD;
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int x,y;
    cin >> x >> y;
    int ans=0;
    if (x<=3) ans+=100000*(4-x);
    if (y<=3) ans+=100000*(4-y);
    if (x==1 && y==1) ans+=400000;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1==m2) {
		cout << 0 << endl;
	} else {
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
import math as mas

for t in sys.stdin:
	i=int(t)
	sum=0
	for j in range(0,600,i):sum+=i*j*j
	print(sum)

#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Measured memory_bytes: 7644
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

int main(){
	int n,m,d[400]={0};
	int a,b,c;
	map<int,vector<pii> > e;
	queue<int> q;
	scanf("%d%d",&n,&m);
	rep(i,m){
		scanf("%d%d%d",&a,&b,&c);
		e[a].push_back(pii(b,c));
	}
	q.push(0);
	while(!q.empty()){
		a=q.front();
		q.pop();
		b=e[a].size();
		rep(i,b){
			pii p=e[a][i];
			if(d[p.first]<d[a]+p.second){
				d[p.first]=d[a]+p.second;
				q.push(p.first);
			}
		}
	}
	printf("%d\n",d[n-1]);
	
	return 0;
}

Measured memory_bytes: 1248
from collections import defaultdict
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n, l = LI()
s = SR(n)
s.sort()
print(''.join(s))


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin>>a[i];
	}
	sort(all(a));
	int ans = 0;
	for (int i = 0; i < n-1; i++){
		ans += a[i+1] - a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,s;
cin>>a>>s;
map<int,int>m={{1,300000},{2,200000},{3,100000}};
long long cou=0;
if(a==1&&s==1)cou+=400000;
cou+=m[a];
cou+=m[s];
cout<<cou;
return 0;}


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

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);
        TaskA solver = new TaskA();
        solver.call(in,out);
        out.close();
    }

    static class TaskA {
        public void call(InputReader in, PrintWriter out) {
            int n ;
            long sum=0;
            n = in.nextInt();
            Long[] arr = new Long[n];
            for (int i = 0; i <n ; i++) {
                arr[i] = in.nextLong();
            }
            Arrays.sort(arr ,Collections.reverseOrder() );
            sum+=arr[0];
            if(n%2==0){
                for (int i = 1; i <n/2 ; i++) {
                    sum+=2*arr[i];
                }
            }
            else{
                for (int i = 1; i <n/2 ; i++) {
                    sum+=2*arr[i];
                }
                sum+=arr[(n/2)];

            }


            out.println(sum);


            
                              

        }
    }

    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 long nextLong() {
            return Long.parseLong(next());
        }


    }
}

Measured memory_bytes: 59748
n = int(input())
s = list(input())

r = s.count('R')
g = s.count('G')
b = s.count('B')

# 1つ目の条件を満たす組の数
p1 = r * g * b

# 1つ目の条件を満たし、2つ目の条件を満たさない組の数
p1_not_p2 = 0
for j in range(n):
    for i in range(j):
        k = 2 * j -i
        if k <= n-1:
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                p1_not_p2 += 1

# 1つ目も2つ目も満たす組の数
print(p1 - p1_not_p2)

Measured memory_bytes: 68072
#include <iostream>
#include <vector>
#include <algorithm>
#include <chrono>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  cout << n * 800 - 200 * (n / 15) << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


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

int *kurai_barasu(int x){
    int y[10];
    for(int i=0;i<10;i++){
        y[i] = x%10;
        x -= y[i];
        x /= 10;
    }
    return y;
}


int main(){
    int n,m;
    cin >> n >> m;
    cout << (n*(n-1)/2)+(m*(m-1)/2) << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {

	var a, b, c int
	fmt.Scan(&a, &b, &c)

	slice := []int{a, b, c}
	sort.Sort(sort.IntSlice(slice))

	ans := "No"

	if slice[0]+slice[1] == slice[2] {
		ans = "Yes"
	}

	fmt.Println(ans)
}

Measured memory_bytes: 1836
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n;

	cin>>n;

	if(n<1000){
		cout<<"ABC"<<endl;
	} else{
		cout<<"ABD"<<endl;
	}
}


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

struct Node
{
    int key;
    Node *right,*left,*parent;
};

Node *root, *NIL;

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL)
    {
        y = x;
        if(z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }

    z->parent = y;
    if(y == NIL)
    {
        root = z;
    }
    else
    {
        if(z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}

void inorder(Node *u)
{
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node*u)
{
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);

}

Node *find(Node *u,int k)
{
    while(u != NIL && k != u->key)
    {
        if(k < u->key)u = u->left;
        else u = u->right;
    }

    return u;
}

Node *treeMinimum(Node *x)
{
    while(x->left != NIL)
    {
        x = x->left;
    }
    return x;
}

Node *treeSuccessor(Node *x)
{
    if(x->right != NIL) return treeMinimum(x->right);
    Node *y = x->parent;
    while(y != NIL && x == y->right)
    {
        x = y;
        y = y->parent;
    }

    return y;
}

void treeDelete(Node *z)
{
    Node *y;
    Node *x;

    if(z->left == NIL || z->right == NIL) y = z;
    else y = treeSuccessor(z);

    if(y->left != NIL)
    {
        x = y->left;
    }
    else
    {
        x = y->right;
    }

    if(x != NIL)
    {
        x->parent = y->parent;
    }

    if(y->parent == NIL)
    {
        root = x;
    }
    else
    {
        if(y == y->parent->left)
        {
            y->parent->left =x;
        }
        else
        {
            y->parent->right = x;
        }

    }

    if(y != z)
    {
        z->key = y->key;
    }

    free(y);
}

int main()
{
    int n,x,i;
    string com;
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        cin >> com;
        if(com[0] == 'f')
        {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }
        if(com == "insert")
        {
            scanf("%d",&x);
            insert(x);
        }
        else if(com == "print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(com == "delete")
        {
            scanf("%d",&x);
            treeDelete(find(root,x));
        }
    }

    return 0;
    
}


Measured memory_bytes: 22108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    int a;
    if (0 == n % x)
    {
        a = 0;
    }
    else
    {
        a = t;
    }
    int ans = (n / x) * t + a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int n,s1,s2,s3,a[303],b[303][303][303],cnt[303][303][303],cnt1;
double f[303][303][303];
double ans1,ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==1)
			s1++;
		if(a[i]==2)
			s2++;
		if(a[i]==3)
			s3++;
	}
	f[0][0][0]=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=0;k<=n;k++)
			{
			//	f[i][j][k]+=(double)(n-i-j-k)/n;
				if(i)
					f[i][j][k]+=(f[i-1][j+1][k])*i/(i+j+k);
				if(j)
					f[i][j][k]+=(f[i][j-1][k+1])*j/(i+j+k);
				if(k)
					f[i][j][k]+=(f[i][j][k-1])*k/(i+j+k);
				if(i || j || k)
					f[i][j][k]+=(double)n/(i+j+k);
			//	cout<<i<<' '<<j<<' '<<k<<' '<<f[i][j][k]<<endl; 
			}
		}
	}
	cout<<fixed<<setprecision(14)<<f[s3][s2][s1]<<endl;
	return 0;
}

Measured memory_bytes: 217344
N = input()
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
C = list(map(int,input().split(" ")))

buffer = 0
sati = 0

for i in A:
  sati += B[i - 1]
  if buffer == 0:
    buffer = i
    continue
  elif buffer == i - 1:
    sati += C[buffer -1]
  buffer = i
print(sati)

Measured memory_bytes: 3064
#include <stdio.h>

#define N 100

int main()
{
  int M[N][N];
  int n,u,k,v;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j] = 0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++) printf("%d ",M[i][j]);
    printf("%d\n",M[i][n-1]);
  }
  return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repn(i,n,m) for(int i=n;i<m;i++)
#define repn1(i,n,m) for(int i=n;i<=m;i++)
using namespace std;

int main(){

	int dp[100] = {0};
	int n;
	
	dp[1] = 1;
	dp[2] = 2;
	dp[3] = 4;

	repn1(i, 4, 30) dp[i] = dp[i-1] + dp[i-2] + dp[i-3];

	while(cin >> n, n){

		cout << dp[n] / 3650 + (dp[n]%3650==0 ? 0 : 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::string> S){
    ll sum =0;
    vector<pair<ll,ll>> left,right;
    for(int i=0;i<N;i++){
        ll l,r;
        l=r=0;
        for(int j=0;j<S[i].size();j++){
            if(S[i][j] =='('){
                l++;
            }else{
                r++;
            }
        }
        sum += (l-r);
        // cerr <<"i="<< i <<"sum =" << sum << endl;
        if((l-r) >=0){
            ll dl,dr;
            dl = dr =0;
            for(int j=0;j<S[i].size();j++){
                if(S[i][j] =='('){
                    dl++;
                }else{
                    if(dl>0){
                        --dl;
                    }else{
                        dr++;
                    }
                }
            }
            left.emplace_back(dr,(l-r));
            continue;
        }else{
            ll dl,dr;
            dl = dr =0;
            for(int j=S[i].size()-1;j>=0;--j){
                if(S[i][j] ==')'){
                    dr++;
                }else{
                    if(dr>0){
                        --dr;
                    }else{
                        dl++;
                    }
                }
            }
            right.emplace_back(dl,r-l);
        }
    }
    if(sum !=0){
        cout << NO <<endl;
        return;
    }
    sort(left.begin(),left.end());
    sort(right.begin(),right.end());
    // leftの評価
    {
        ll suml =0;
        for(int i=0;i<left.size();i++){
            if(left[i].first > suml){
                // cerr << "left i=" << i << "not" << endl;
                cout << NO <<endl;
                return;
            }
            suml += left[i].second;
        }
    }
    // rightの評価
    {
        ll sumr=0;
        for(auto P:right){
            // cerr << "P= " << P.first << " " << P.second << endl;
            if(P.first > sumr){
                // cerr <<"right P=" << P.first << "not" << endl;
                cout << NO <<endl;
                return;
            }
            sumr += P.second;
        }
    }
    cout << YES << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


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

int main() {
  long long N,K;
  cin>>N>>K;
  long long temp;
  if(N%K==0){
    cout<<0<<endl;
    return 0;
  }

  temp=N%K;
  long long ans=min(temp,K-temp);
  cout<<setprecision(20)<<ans<<endl;
  return 0;
}

 

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

using namespace std;
typedef long long ll;

bool judge(vector<pair<int, int>> &p) {
    sort(p.begin(), p.end(), greater());
    int h = 0;
    for (auto e : p) {
        if (h + e.first < 0) return false;
        h += e.second;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<pair<int, int>> pos, neg;
    int hsum = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        int mi = 0, h = 0;
        for (auto c : s[i]) {
            if (c == '(') h++;
            else h--, mi = min(mi, h);
        }
        hsum += h;
        if (h >= 0) pos.push_back({mi, h});
        else neg.push_back({mi - h, -h});
    }
    if (hsum == 0 && judge(pos) && judge(neg)) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 42452
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin >> S ;
    int l = S.length();
    int i;
    int count0 = 0;
    int count1 = 0;
    for(i=0;i<l;i++)
    {
        if(S[i] == '0')
        {
            count0++;
        }
        else
        {
            count1++;
        }
    }
    int ans = 2*min(count0,count1);
    cout << ans << endl;
}

Measured memory_bytes: 1020
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef pair<pair<double,int>,pair<int,int> > P;

class road{
public:
  int to,d,c;
  road(int x,int y,int z){to = x;d = y;c = z;};
};

vector<road> G[31];

int main(){
  int n,m,s,g;
  int x,y,d,c;

  for(;;){
    scanf("%d %d",&n,&m);
    if(!n && !m)break;
    scanf("%d %d",&s,&g);

    double t[31][31][31];
    bool v[31][31][31];

    for(int i=0;i<=n;i++)G[i].clear();
    for(int i=0;i<m;i++){
      scanf("%d %d %d %d",&x,&y,&d,&c);
      G[x].push_back(road(y,d,c));
      G[y].push_back(road(x,d,c));
    }
    
    for(int i=0;i<=n;i++)
      for(int j=0;j<=n;j++)
	for(int k=0;k<=30;k++){
	t[i][j][k] = 1e10;
	v[i][j][k] = false;
      }

    t[s][0][0] = 0.0;
    priority_queue<P,vector<P>,greater<P> > q;
    q.push(P(pair<double,int>(0.0,s),pair<int,int>(0,0)));

    while(q.size()){
      P p = q.top();q.pop();

      double time = p.first.first;
      int now,prv,speed;
      now = p.first.second;
      prv = p.second.first;
      speed = p.second.second;

      if(v[now][prv][speed])continue;
      v[now][prv][speed] = true;

      for(int i=0;i<(int)G[now].size();i++){
	road r = G[now][i];
	if(r.to != prv){
	  for(int dif=-1;dif<=1;dif++){
	    if(speed+dif>0 &&  speed+dif<=r.c){
	      if(!v[r.to][now][speed+dif]){
		if(t[r.to][now][speed+dif] > time+(double)r.d/(speed+dif)){
		  t[r.to][now][speed+dif] = time+(double)r.d/(speed+dif);
		  q.push(P(pair<double,int>(t[r.to][now][speed+dif],r.to),pair<int,int>(now,speed+dif)));
		}
	      }
	    }
	  }
	}
      }
    }

    double ans = 1e10;
    for(int i=0;i<=n;i++)ans = min(ans,t[g][i][1]);
    if(ans==1e10)printf("unreachable\n");
    else printf("%.4lf\n",ans);
  }
}

Measured memory_bytes: 1980
#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>;

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int A, B;
    cin >> A >> B;
    for (int i=0; i<2000; ++i) {
        if (int((double)i * 0.08 + eps) == A && int((double)i * 0.1 + eps) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
BIG_NUM = 2000000000
N = int(input())

table = list(map(int,input().split()))

maximum = -BIG_NUM
minimum = BIG_NUM
total = 0

for x in table:
    if maximum < x:
        maximum = x
    if minimum > x:
        minimum = x
    total += x

print("%d %d %d"%(minimum,maximum,total))


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

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if((c-b-a)<=0){
    cout << "No" << endl;
  }
  else if((4*a*b)<((c-b-a)*(c-b-a))){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>

using namespace std;

vector<pair<string, bool> > rules;
vector<string> legal_packets;

bool match(string pattern, string s) {
    for (int i = 0; i < pattern.size(); i++) {
        if (pattern[i] == '?') continue;
        if (pattern[i] != s[i]) return false;
    }
    return true;
}

bool can_access(string addr) {
    for (int i = rules.size()-1; i >= 0; i--) {
        if (match(rules[i].first, addr)) {
            if (rules[i].second) {
                return true;
            } else {
                return false;
            }
        }
    }
    return false;
}

int main() {
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        rules.clear(), legal_packets.clear();
        for (int i = 0; i < n; i++) {
            string permission, src_pattern, dst_pattern;
            cin >> permission >> src_pattern >> dst_pattern;
            if (permission == "permit") {
                rules.push_back(make_pair(src_pattern + ' ' + dst_pattern, true));
            } else {
                rules.push_back(make_pair(src_pattern + ' ' + dst_pattern, false));
            }
        }

        for (int i = 0; i < m; i++) {
            string src_addr, dst_addr, msg;
            cin >> src_addr >> dst_addr >> msg;
            if (can_access(src_addr + ' ' + dst_addr)) {
                legal_packets.push_back(src_addr + ' ' + dst_addr + ' ' + msg);
            }
        }

        cout << legal_packets.size() << endl;
        for (int i = 0; i < legal_packets.size(); i++) {
            cout << legal_packets[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1020
cucky = [0, 0]
cucky[0], cucky[1], k = map(int, input().split())

for i in range(k):
    tmp = cucky[i % 2] // 2
    cucky[i % 2] //= 2
    cucky[(i + 1) % 2] += tmp

print(cucky[0], cucky[1])

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
f = 1
for i in range(n):
    if a[i]>0:
        f = 0
if f:
    ind = a.index(max(a))
    print(max(a))
    list = []
    for i in range(n,ind+1,-1):
        list.append(i)
    for _ in range(ind):
        list.append(1)
    print(len(list))
    for i in list:
        print(i)
    exit()
g1 = a[1::2]
g2 = a[::2]
ans1,ans2 = 0,0
l1,l2 = [],[]
for i in range(len(g1)):
    if g1[i]>0:
        ans1 += g1[i]
        l1.append(i*2+2)
for i in range(len(g2)):
    if g2[i]>0:
        ans2 += g2[i]
        l2.append(i*2+1)
length = n
if ans1>=ans2:
    print(ans1)
    list = []
    for i in range(n,l1[-1],-1):
        list.append(i)
    length -= n-l1[-1]
    for i in range(l1[-1],l1[0],-2):
        if not i in l1:
            list.append(i)
            length -= 2
    for i in range(l1[0]-1):
        list.append(1)
    length -= l1[0]
    for _ in range(length,0,-2):
        list.append(2)
    print(len(list))
    for i in list:
        print(i)
else:
    print(ans2)
    list = []
    for i in range(n,l2[-1],-1):
        list.append(i)
    length -= n-l2[-1]
    for i in range(l2[-1],l2[0],-2):
        if not i in l2:
            list.append(i)
            length -= 2
    for i in range(l2[0]-1):
        list.append(1)
    length -= l2[0]
    for _ in range(length,0,-2):
        list.append(2)
    print(len(list))
    for i in list:
        print(i)

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin >> n >> s;
    rep(a,2){
        rep(b,2){
            vector<ll> m(n+1);
            m[0] = a;
            m[1] = b;
            ll c;
            if (m[0] == 0){
                if (s[0] == 'o') c = m[1];
                else c = 1-m[1];
            }
            else{
                if (s[0] == 'o') c = 1-m[1];
                else c = m[1];
            }
            rep(i,1,n){
                if (m[i] == 0){
                    if (s[i] == 'o') m[i+1] = m[i-1];
                    else m[i+1] = 1-m[i-1];
                }
                else{
                    if (s[i] == 'o') m[i+1] = 1-m[i-1];
                    else m[i+1] = m[i-1];
                }
            }
            if (a == m[n] && c == m[n-1]){
                string ans = "";
                rep(i,n){
                    if (m[i]) ans += 'W';
                    else ans += 'S';
                }
                PRINT(ans);
                return 0;
            }
        }
    }
    PRINT(-1);
}


Measured memory_bytes: 4712
#include <bits/stdc++.h>
using namespace std;
int main(void){
  // 1文字ずつ走査して、未完成な'('と'('の数を持っておけばいいかな
  // 未完成な'('の数だけ右から')'を足す
  // 未完成')'の数だけ左から'('を足す
  
  int N;
  string S;
  cin >> N >> S;
  
  int q_left = 0;
  int q_right = 0;
  for(int i=0; i<N; i++){
    if(S[i] == '(') q_left++;
    else{
      if(q_left >= 1) q_left--;
      else q_right++;
    }
  }
  string ret = S;
  for(int i=0; i<q_left; i++) ret += ')';
  for(int i=0; i<q_right; i++) ret = '(' + ret;
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    long long int n,m;
    cin>>n>>m;
    long long int a[m],sum=0;
    for(int i=0;i<m;i++){
      cin>>a[i];
      sum+=a[i];
    }
    if(sum>n) cout<<"-1";
    else cout<<n-sum;
    return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cstdio>
#include <vector>
#define pb push_back
std::vector<int> adj[100005];
int app[100005][25];
int dfs(int u, int fa = -1)
{
	int ans = 0;
	for (int v : adj[u])
	{
		if (v == fa)
			continue;
		ans = std::max(ans, dfs(v, u));
		for (int j = 0; j < 20; j++)
			app[u][j] += app[v][j];
	}
	int res = 0;
	for (int i = 19; i >= 0; i--)
	{
		if (app[u][i] > 1)
		{
			res = i + 1;
			break;
		}
	}
	while (app[u][res])
		res++;
	for (int j = 0; j < res; j++)
		app[u][j] = 0;
	app[u][res] = 1;
	return std::max(ans, res);
}
int main()
{
	// freopen("AGC009-D.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[--u].pb(--v);
		adj[v].pb(u);
	}
	printf("%d\n", dfs(0));
	return 0;
}

Measured memory_bytes: 22272