akhauriyash/Code-Regression huggingface dataset:
import sys
import copy
from collections import deque
import collections
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x = ni()

if x>=30:
    print("Yes")
else:
    print("No")




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

using namespace std;

int main() {
  int n;
  cin >> n;
  bool first = false;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    if (a % 2) first = true;
  }
  if (first) cout << "first";
  else cout << "second";
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){
	char s[5];

	scanf("%s",s);
	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';
	if(a+b+c+d==7)printf("%d+%d+%d+%d=7\n",a,b,c,d);
	else if (a + b + c - d == 7)printf("%d+%d+%d-%d=7\n", a, b, c, d);
	else if (a + b - c + d == 7)printf("%d+%d-%d+%d=7\n", a, b, c, d);
	else if (a + b - c - d == 7)printf("%d+%d-%d-%d=7\n", a, b, c, d);
	else if (a - b + c + d == 7)printf("%d-%d+%d+%d=7\n", a, b, c, d);
	else if (a - b + c - d == 7)printf("%d-%d+%d-%d=7\n", a, b, c, d);
	else if (a - b - c + d == 7)printf("%d-%d-%d+%d=7\n", a, b, c, d);
	else if (a - b - c - d == 7)printf("%d-%d-%d-%d=7\n", a, b, c, d);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	deque<ll> dq;
	ll b;
	cin>>b;
	dq.push_back(b);
	rep(i,0,n-1){
		ll a;
		cin>>a;
		if(i%2==0){
			dq.push_back(a);
		}
		else{
			dq.push_front(a);
		}
	}
	vector<ll> v(all(dq));
	if(n%2==0){
		reverse(all(v));
	}
	rep(i,0,n){
		cout << v[i];
		if(i!=n-1)cout << " ";
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
const int INF=1e9;

int main(){
    string s;cin>>s;
    vector<bool> used(26,false);
    for(int i=0;i<(int)s.size();i++){
        used[(int)(s[i]-'a')]=true;
    }
    for(int i=0;i<26;i++)if(!used[i]){
        cout<<s+(char)(i+'a')<<endl;
        return 0;
    }
    fill(used.begin(),used.end(),false);
    for(int i=(int)s.size()-1;i>=0;i--){
        for(int j=(int)(s[i]-'a');j<26;j++){
            if(used[j]){
            cout<<s.substr(0,i)+(char)(j+'a')<<endl;
            return 0;
            }
        }
        used[(int)(s[i]-'a')]=true;
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

A = input()
N = len(A)
dp = [0] * N
dp[0] = 1
d = defaultdict(int)
d[A[0]] = 1

for i in range(1, N):
  a = A[i]
  dp[i] = dp[i-1]
  dp[i] += i - d[a]
  d[a] += 1

print(dp[-1])

Measured memory_bytes: 12772
/**
 * 関節点 : https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_A
 * 橋 : https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_B
 * */

#include <bits/stdc++.h>
using namespace std;
#define INF 1<<29
#define all(v) (v).begin(), (v).end()

int V, E; //頂点数 辺の数
vector<vector<int>> G(V); //頂点の隣接リスト
vector<int> ord_pre(V, INF); //行きがけ順の記録
vector<int> lowlink(V, INF); //lowlinkの記録
vector<pair<int, int>> Bridges; //橋のリスト
vector<int> ArticulationPoints; //関節点のリスト

int pre = 0; //行きがけ順序

void recdfs(int p, int u){ //p : uの親
  ord_pre[u] = pre++; //uの番号を確定する
  lowlink[u] = ord_pre[u];

  int cnt = 0; //DFS木次数カウント
  bool isArt = false; //関節点か否か

  for(int v: G[u]){ //uから行ける頂点vについて
    if(ord_pre[v]==INF){ //未訪問ならばuの子なので
      cnt++;

      recdfs(u, v); //uの子であるvの番号を確定させる //vのlowlinkも確定
      lowlink[u] = min(lowlink[u], lowlink[v]);

      if(ord_pre[u] < lowlink[v])Bridges.push_back({u,v}); //橋の判定してリストに入れる
      if(p!=-1 && ord_pre[u]<=lowlink[v])isArt = true; //根以外の関節点判定

    }else if( v != p ){
      //このとき uv が後退辺
      lowlink[u] = min(lowlink[u], ord_pre[v]);
    }
  }
  if(p==-1 && cnt>1)isArt = true; //根の関節点判定
  if(isArt)ArticulationPoints.push_back(u); //関節点だったらリストに入れる
}


int main(){
  cin>>V>>E;
  G.resize(V);
  for(int i=0; i<E; i++){
    int s,t;
    cin>>s>>t; //s--;t--;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  ord_pre.assign(V, INF);
  lowlink.assign(V,INF);
  pre = 0;
  recdfs(-1, 0);

  /* 3a
  sort(all(ArticulationPoints));
  for(int x: ArticulationPoints)cout<<x<<endl;
  //*/

  //* 3b
  for(auto &x: Bridges){
    if(x.first>x.second)swap(x.first, x.second);
  }
  sort(all(Bridges));
  for(auto x: Bridges)cout<<x.first<<" "<<x.second<<endl;
  //*/
}


Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(16)//use fixed before stp
#define endl '\n'
ll a[2000000];
int main()
{  
    FAST
    ld n;
    ll k;
    cin>>n>>k;
    ld d=0.0;
    for(ll i=1;i<=n;i++)
    {
        ld x;
        ld q=0;
        ll z=i;
        while(z<k)
        {
            z*=2;
            q+=1.0;
        }
        x=(1.0/n)*(pow(0.5,q));
        d+=x;
    }
    cout<<fixed<<stp<<d;
}

Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;

int main() {
    abdelrahman010
    long double r;
    cin >> r;
    cout << fixed << setprecision(9) << 44 * r / 7;
    return 0;
}

Measured memory_bytes: 3804
btc=380000
N=int(input())
number=[0]*N
string=[0]*N
for i in range(N):
    list=input().split()
    number[i]=float(list[0])
    string[i]=list[1]

sum=0
for i in range(N):
    if string[i]=="JPY":
        sum=sum+number[i]
    else:
        sum=sum+number[i]*btc
print(sum)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define pr(p) printf("%d\n",p)
const int oo=2139063143;
const int N=1010000;
const int mod=1000000007;
using namespace std;
typedef long long LL;
inline void sc (int &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
char s[N];
int main()
{
	//freopen (".in","r",stdin);
	//freopen (".out","w",stdout);
	scanf ("%s",s+1);
	int n=strlen (s+1);
	if (s[1]==s[n]) puts ((n&1)?"Second":"First");
	else            puts ((n&1)?"First":"Second");
	return 0;
}


Measured memory_bytes: 384
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())

YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = False
show_flg = True


def main():
    N, K, S = MI()
    cur = 0
    ans = [0] * N

    for i in range(N):
        if cur < K:
            ans[i] = S
            cur += 1
        else:
            if S == 10 ** 9:
                ans[i] = 10 ** 9 - 1
            else:
                ans[i] = S + 1

    print(*ans)


if __name__ == '__main__':
    main()


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

using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second
#define int 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; }
void put_double(double obj){printf("%.12f",obj);};
//lambda: [](int x, int y){return x<y;}

using pdouble = pair<double, double>;

double distance(pdouble p1, pdouble p2){
  double dx,dy;
  dx=p1.first-p2.first;
  dy=p1.second-p2.second;
  return sqrt(dx*dx+dy*dy);
}

signed main(void){
    int n;cin>>n;
    double ans=0;
    vector<pdouble> t(n);
    vpin(t);
    vector<double> dis;
    rep(i,n-1){
        repi(j,i+1,n){
            dis.push_back(distance(t[i],t[j]));
        }
    }
    rfor(d,dis)ans+=d;
    ans/=dis.size();
    put_double(ans*(n-1));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	string s;int n;cin>>s>>n;
	for(int i = 0; s.size() > i; i++){
		if(s[i] != 'a' && ('z'-s[i])+1 <= n){
			n -= ('z'-s[i])+1;
			s[i] = 'a';
		}
	}
	if(n){
		s[s.size()-1] = (((s[s.size()-1]-'a')+n)%26)+'a';
	}
	cout << s << endl;
}

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

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

using namespace std;

template <class T> int find_index(T x, const std::vector<T> &v) {
    auto it = std::find(v.begin(), v.end(), x);
    if (it != v.end()) { return (int)std::distance(v.begin(), it); }
    return -1;
}
template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }

template <class T> void print(T x) {
    std::cout << x << std::endl;
}
// 4近傍（右, 下, 左, 上）
const vector<int> dy = { 0, -1, 0, 1 };
const vector<int> dx = { 1, 0, -1, 0 };


int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int K;
    cin >> K;

    vector<vector<pair<int, int>>> graph(K);
    FOR(i, 0, K) {
        graph[i].emplace_back(make_pair((i + 1) % K, 1));
        graph[i].emplace_back(make_pair((i * 10) % K, 0));
    }

    vector<int> cost(K, INT_MAX);
    cost[1] = 1;

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

    while (not que.empty()) {
        int now = que.front(); que.pop();
        int now_cost = cost[now];


        FOE(p, graph[now]) {
            int to = p.first;

            if (cost[to] > now_cost + p.second) {
                cost[p.first] = now_cost + p.second;
                que.push(p.first);
            }
        }
    }

    print(cost[0]);

    return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <cmath>

using namespace std;

inline double calc(int n) {
    return 0.5 + 0.5 * n;
}

int main() {
    int n;
    int k;
    cin >> n >> k;
    vector<int> dice(n);

    for (int &d : dice) {
        cin >> d;
    }

    vector<double> e(n);
    e[0] = calc(dice[0]);
    for (int i = 1; i < n; i++) {
        e[i] = e[i - 1] + calc(dice[i]);
    }

    double max = e[k - 1];
    for (int i = 0; i < n - k; i++) {
        double sum = e[i + k] - e[i];
        //cerr << sum << " ";
        if (sum > max) {
            max = sum;
        }
    }
    //cerr << endl;

    printf("%lf\n", max);
    return 0;
}

Measured memory_bytes: 2560
n=int(input())
m=int(n**(1/2))

F=[]
n1=n
k=2
#rangeで処理していたのを変更：for i in range(m):
while k<=m:
    if n%k==0:
        F.append(k)
        n//=k
        #print(n)
        while n%k==0:
            F.append(k)
            n//=k
    k+=1

if n>m:
    F.append(n)
print(n1,end=": ")
print(*F)



Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
long long c[200001];
int h[200001],n;
int lowbit(int x)
{
	return x&(-x);
}
void updatemax(int index,long long value)
{
	while(index<=n&&value>c[index])
	{
		c[index]=value;
		index+=lowbit(index);
	}
}
long long maxrange(int index)
{
	long long maxv=0;
	while(index)
	{
		maxv=max(maxv,c[index]);
		index-=lowbit(index);
	}
	return maxv;
}
int main()
{
	int a,i;
	long long t,maxv=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a);
		t=maxrange(h[i]-1)+a;
		maxv=max(maxv,t);
		updatemax(h[i],t);
	}
	printf("%lld",maxv);
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll R, C, K;
    cin >> R >> C >> K;
    map<pair<ll,ll>,ll> S;
    REP(i,0,K) {
        ll r, c, v;
        cin >> r >> c >> v;
        S[{r, c}] = v;
    }

    vector<vector<vector<ll>>> dp(R+1, vector<vector<ll>>(C+1, vector<ll>(4)));
    REP(i,0,R+1) REP(j,0,C+1) REP(k,0,4) dp[i][j][k] = 0;
    REP(i,1,R+1) {
        REP(j,1,C+1) {
            ll x = 0;
            if(S.count({i, j}) > 0) x = S[{i, j}];
            dp[i][j][0] = MAX(dp[i][j][0],dp[i][j-1][0]);
            REP(k,0,4) dp[i][j][0] = MAX(dp[i][j][0],dp[i-1][j][k]);
            REP(k,1,4) dp[i][j][k] = MAX(dp[i][j][0],dp[i][j-1][k]);
            dp[i][j][1] = MAX(dp[i][j][1],dp[i][j-1][0]+x);
            REP(k,0,4) dp[i][j][1] = MAX(dp[i][j][1],dp[i-1][j][k]+x);
            REP(k,2,4) dp[i][j][k] = MAX(dp[i][j][k],dp[i][j-1][k-1]+x);
        }
    }
    
    ll ans = MAX(dp[R][C][0],dp[R][C][1]);
    ans = MAX(ans,dp[R][C][2]);
    ans = MAX(ans,dp[R][C][3]);
    PR(ans);

    return 0;
}

/*



*/


Measured memory_bytes: 649076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define nl '\n'
#define ff first
#define ss second
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

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

  int n; cin >> n;
  char s[1+n];
  cin >> 1+s;
  int lW[2+n], rE[2+n];
  memset(lW, 0, sizeof lW);
  memset(rE, 0, sizeof lW);

  for(int i=1; i<=n; i++) {
    lW[i] = lW[i-1];
    if(s[i] == 'W') lW[i]++;
  }

  for(int i=n; i>=1; i--) {
    rE[i] = rE[i+1];
    if(s[i] == 'E') rE[i]++;
  }

  int ans = n+1;
  for(int i=1; i<=n; i++) {
    ans = min(ans, lW[i-1]+rE[i+1]);
  }
  cout << ans << nl ;
  

  return 0;
}

/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 2944
#include <iostream>
#include <iomanip>

using namespace std;

int main() {

  int a, c;int b;
  cin >> a >> b >> c; //>> b >> c;
  double ans, ra, rb;
  string dolphinManJotaro;
  if(a != b && b != c && a != c){
    cout << 3;
  }else if(a == b && b == c){
    cout << 1;
  }else{
    cout << 2;
  }
  return 0;
}


Measured memory_bytes: 3588
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		ArrayList<String> array = new ArrayList<String>();
		String str[] = sc.nextLine().split(" ");
		for(int i = 0;i < str.length;i++){
			for(int j = 0;j < array.size();j++){
				if(array.get(j).equals(str[i])){
					map.put(str[i],map.get(str[i]) + 1);
					break;
				}if(j == array.size()-1){
					if(array.get(j) != str[i]){
						array.add(str[i]);
						map.put(str[i], 0);
					}
				}
			}if(array.size() == 0){
				array.add(str[i]);
				map.put(str[i], 1);
			}
		}
		int max = 0;
		String maxw = "";
		String lon = "";
		for(int i = 0;i < array.size();i++){
			if(array.get(i).length() > lon.length()){
				lon = array.get(i);
			}if(map.get(array.get(i)) > max){
				max = map.get(array.get(i));
				maxw = array.get(i);
			}
		}
		System.out.println(maxw+" "+lon);
	}
    public static void main(String[] args) {
    	new Main().doIt();
    }
}

Measured memory_bytes: 17152
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

int n,ar[N],x;


int main()
{
    fast;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>ar[i];
        x+=ar[i];
    }
    sort(ar+1,ar+n+1);
    x-=ar[n];
    if(x>ar[n])
        cout<<"Yes";
    else
        cout<<"No";
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)   for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr int64_t MOD = 1000000007;

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

  size_t n;
  cin >> n;
  string s;
  cin >> s;

  rep (i, n)
  {
    s [i * 2] ^= 'W' ^ 'B';
  }

  ll ans = 1, cnt = 0;
  rep (i, n * 2)
  {
    if (s [i] == 'W')
    {
      ++ cnt;
    }
    else
    {
      if (cnt == 0)
      {
        goto failed;
      }
      ans *= cnt --;
      ans %= MOD;
    }
  }
  if (cnt != 0)
  {
failed:
    cout << 0 << endl;
  }
  else
  {
    auto kaijo = [&] (auto self, auto x) -> ll {
      return (x == 0) ? 1 : (x * self (self, x - 1)) % MOD;
    };
    ans *= kaijo (kaijo, static_cast <ll> (n));
    ans %= MOD;
    cout << ans << endl;
  }
}


Measured memory_bytes: 1616
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mpr make_pair
#define MX 100010
#define ui unsigned int
#define ll long long
#define ld long double 
#define fi first
#define se second
#define endl '\n'
#define debug(bug) cout<<"akshat"<<" "<<bug<<endl
#define printarray(Aneveruse,neverusen) for(int neveruse=0;neveruse<neverusen;neveruse++) cout<<Aneveruse[neveruse]<<" "; cout<<endl
#define printvector(Aneveruse,neverusen) for(int neveruse=0;neveruse<neverusen;neveruse++) cout<<Aneveruse[neveruse]<<" "; cout<<endl
#define dd long double 
#define timetaken cerr<<clock()/double(CLOCKS_PER_SEC)<<endl
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)
const ll inf=1000000000000;
const int mod=1000000007;
// priority_queue <int, vector<int>, greater<int> > pq; //minimum priority queue
int n;
dd A[MX];
dd dp[3000][3000];
int main()
{
  fast_io;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>A[i];
  }
  dp[0][0]=(1-A[0]);
  dp[0][1]=A[0];

  for(int i=1;i<n;i++)
  {
    for(int j=0;j<=i+1;j++)
    {
        dp[i][j]=dp[i-1][j]*(1-A[i])+(j-1<0?0:dp[i-1][j-1])*A[i];
    }
  }


  dd ans=0;

  for(int i=0;i<=n;i++)
  {
    int j=n-i;
    if(i>j)
     ans+=dp[n-1][i];
  }
  cout<<fixed;
  cout<<setprecision(10);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 139776
#include <stdio.h>
int f(int a){
    if(a==0||a==1||a==-1){return 1;}
    else{return a*f(a-2);}
}
int main(void){
int h,w,x,y,z,i,j,k,l,p,q,r,n,m;
n=0;
scanf("%d%d",&h,&w);
char a[h][w];
for(i=0;i<h;i++){
    scanf("%s",a[i]);
}
int b[w],c[h],d[w];
if(w%2==0)m=w-1;
if(w%2==1)m=w;
for(i=0;i<f(m);i++){
    x=i;
    for(j=0;j<w;j++){b[j]=-1;}
    for(j=0;j<(w+1)/2;j++){
        y=x/f(m-(j+1)*2);
        z=x%f(m-(j+1)*2);
        x=z;k=0;
        if(j==0&&w%2==1){b[y]=(w-1)/2;}else{
        while(b[k]!=-1){k++;}
        b[k]=j-w%2;p=0;
        while (p!=y+1){
            k++;
            if(b[k]==-1)p++;
        }
        b[k]=w-1-j+w%2;}
    }
    for(j=0;j<w;j++){
        d[b[j]]=j;
    }
   for(j=0;j<w;j++){
       b[j]=d[j];
   } 
    for(j=0;j<h;j++){c[j]=0;}
    k=0;
    for(k=0;k<h;k++){
    if(c[k]==0){
    for(l=k+1;l<h;l++){
        if(c[l]==0){
            q=0;
            for(p=0;p<w;p++){
                if(a[k][b[p]]==a[l][b[w-1-p]])q++;
            }
            if(q==w){c[k]=1;c[l]=1;l=h;}
        }
    }}}q=0;
    for(j=0;j<h;j++){
      q+=c[j];  
    }
    if(q==h-1){
        k=0;r=0;
        while(c[k]!=0){k++;}
        for(p=0;p<w;p++){
            if(a[k][b[p]]==a[k][b[w-1-p]])r++;
        }
        if(r==w)c[k]=1;
    }q=0;
    for(j=0;j<h;j++){
        q+=c[j];
    }
    if(q==h)n++;
}
if(n>0)printf("YES\n");
if(n==0)printf("NO\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int n;
vector<vector<int>> to;
vector<bool> seen;
void dfs(int v, int& cnt) {
    seen[v] = true;
    bool flag = true;
    rep(i, n) if (!seen[i]) flag = false;
    if (flag) cnt++;
    for (int i = 0; i < to[v].size(); ++i) {
        int nv = to[v][i];
        if (seen[nv]) continue;
        dfs(nv, cnt);
    }
    seen[v] = false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int m;
    cin >> n >> m;
    to.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    seen.resize(n, false);
    int cnt = 0;
    dfs(0, cnt);
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include <math.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

int main(void) {
    int n, x;
    cin >> n >> x;
    vi a(n, 0);
    vi origin(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        origin[i] = a[i];
    }

    for (int i = 0; i < n - 1; ++i) {
        if (a[i] > x) {
            int diff = a[i] - x;
            a[i] = x;
        }

        if (a[i] + a[i + 1] > x) {
            int diff = x - a[i];
            a[i + 1] = diff;
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (ll) (origin[i] -a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

M,K = MI()

if K >= 2**M or (M == 1 and K == 1):
    print(-1)
elif M == 1 and K == 0:
    print(*[0,0,1,1])
else:
    A = [i for i in range(2**M) if i != K]
    ANS = A + [K] + list(reversed(A)) + [K]
    print(*ANS)


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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)

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


int main()
{
    int n;

    cin >>n; 
    int c=0; 
    for(int i=1;i<=n/2;i++)
    {
        if(n-i == i)
            continue;
        else
        {
            c++; 
        }
    }
    cout<<c<<endl; 

    return 0; 
}



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

using namespace std;

int main(void) {
    string S;
    cin >> S;
    if(S == "SUN") cout << 7 << endl;
    if(S == "MON") cout << 6 << endl;
    if(S == "TUE") cout << 5 << endl;
    if(S == "WED") cout << 4 << endl;
    if(S == "THU") cout << 3 << endl;
    if(S == "FRI") cout << 2 << endl;
    if(S == "SAT") cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
const double PI=3.14159265358979323846;
const long long INF = 1LL << 60;

int main() {
	int64_t N;
	cin >> N;
	int64_t a=100, b=0, c=0, x, y, z;

	while (a < N) {
		a += a / 100;
		b++;
	}
	std::cout << b << '\n';
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1001001001;
const double EPS = 1e-10;
struct Edge { ll from, to, cost; };
using Graph = vector<vector<Edge>>;

int is_prime[101010];

bool f(int a){
    if(is_prime[a]!=-1)return is_prime[a];
    for(int i=2;i*i<=a;i++){
        if(a!=i&&a%i==0)return is_prime[a]=false;
    }
    return is_prime[a]=true;
}

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

    fill(is_prime,is_prime+101010,-1);
    is_prime[0]=is_prime[1]=false;
    int c_sum[101010]={};
    for(int x=1;x<101010;x++){
        if(x%2==0){
            c_sum[x]=c_sum[x-1];
            continue;
        }
        int y=(x+1)/2;
        if(f(x)&&f(y))c_sum[x]=(x>1?c_sum[x-2]:0)+1;
        else c_sum[x]=(x>1?c_sum[x-2]:0);
    }
    int q;
    cin>>q;
    for(int i=0,l,r;i<q;i++){
        cin>>l>>r;
        cout<<c_sum[r]-c_sum[l-1]<<endl;
    }
}

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

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

int main() {
	int N;
	int max = 0;
	map<string, int> mp;
	vector<string> name;
	cin >> N;
	string str;
	rep(i, N) {
		cin >> str;
		mp[str] += 1;
		name.push_back(str);
		if(mp[str] > max) {
			max = mp[str];
		}
	}

	sort(all(name));
	name.erase(unique(all(name)), name.end());
	for(auto it = name.begin(); it != name.end(); ++it) {
		if(mp[*it] == max) {
			cout << *it << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 26736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            String[] values = line.split(" ");
            int h = Integer.parseInt(values[0]);
            int m = Integer.parseInt(values[1]);
            int s = Integer.parseInt(values[2]);
            if (h == -1 && m == -1 && s == -1) {
                break;
            }
            int time = (h * 60 + m) * 60 + s;
            int rest = 120 * 60 - time;
            out.println(format(rest));
            out.println(format(rest * 3));
        }
    }

    private static String format(int time) {
        int h = time / 3600;
        int m = (time / 60) % 60;
        int s = time % 60;
        return String.format("%02d:%02d:%02d", h, m, s);
    }
}

Measured memory_bytes: 12000
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  string s;
  cin>>s;
  ll w=0,ans=0;
  rep(i,s.size()) if(s[i]=='W') w++;
  rep(i,s.size()) if(s[i]=='W') ans+=i;
  if(w==0) cout<<0<<endl;
  else cout<<ans-w*(w-1)/2<<endl;
}

Measured memory_bytes: 720
import collections
N = int(input())
li = [input() for x in range(N)]
ans = 0
di = dict()
for k in li:
    word = ''.join(sorted(list(k)))
    if word in di.keys():
        ans += di[word]
        di[word] += 1
    else:
        di[word] = 1
print(ans)

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

int main() {
	int N;
	cin >> N;
	vector<int> cnt(9, 0);
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a >= 3200)
			cnt[8]++;
		else
			cnt[a/400]++;
	}
	int min_ans = 0;
	for (int i = 0; i < 8; i++) {
		if (cnt[i] > 0) {
			min_ans++;
		}
	}
	int max_ans = min_ans + cnt[8];
	if (min_ans == 0) min_ans = 1;
	cout << min_ans << ' ' << max_ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        x: u64, y: u64
    }
    let mut cnt = 1;
    let mut k = x;
    loop {
        if k * 2 > y {
            break;
        } else {
            cnt += 1;
            k *= 2;
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
x, y = [int(i)  for i in input().split()]

for i in range(x):
  Y=x-i
  #print(i,Y,2*i + 4*Y)
  if 2*i + 4*Y == y:
    print("Yes")
    exit()
for i in range(x):
  X=x-i
  #print(X,i,4*i + 2*X)
  if 4*i + 2*X == y:
    print("Yes")
    exit()
    
print("No")

Measured memory_bytes: 9192
/*
  donttttttt use vector 
  run n = 1 and n = MAXN before submit
  try to AC within one submission
*/
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
     
typedef long long lo;
 
template<typename tp> inline void read(tp &x) {
	x = 0; char c = getchar(); int f = 0;
	for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
	for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if (f) x = -x;
}
const int N = 3e5 + 233;
const int lgN = 20;
int n, mx[N], ans[N], dep[N];
vector <int> G[N];
int dfn[N], out[N], clk, id[N], tf[N], sum[N], fa[N][lgN + 2];

inline void dfs(int u, int fat) {
	dep[u] = dep[fa[u][0] = fat] + 1;
	id[dfn[u] = ++clk] = u;
	mx[u] = max(mx[u], max(fat, mx[fat]));
	rep (i, lgN) fa[u][i] = fa[fa[u][i - 1]][i - 1];
	for (int v : G[u]) if (v != fat) dfs(v, u);
	out[u] = clk;
}

int main(void) {
	read(n);
	rep (i, n - 1) {
		int x, y; read(x); read(y);
		G[x].emplace_back(y);
		G[y].emplace_back(x);
	}
	dfs(1, 0);
	// rep (i, n) cout << fa[i] << " \n"[i == n];
	rep (_, n) {
		int i = id[_];
		if (i == 1) continue;
		int t = i;
		// for (int u = i; fa[u][0] && dep[u] >= dep[tf[fa[i][0]]]; u = fa[u][0])
		// 	if (mx[u] > i) t = u;
		for (int u = i, k = lgN; ~k; k--)
			if (fa[u][k] && dep[fa[u][k]] >= dep[tf[fa[i][0]]] && mx[fa[u][k]] > i)
				t = u = fa[u][k];
		tf[i] = t;
		// for (int k = dfn[t]; k <= out[t]; k++) ++ans[id[k]];
		sum[dfn[t]]++; sum[out[t] + 1]--;
	}
	rep (i, n) sum[i] += sum[i - 1];
	for (int i = 2; i <= n; i++) cout << sum[dfn[i]] << " \n"[i == n];
}


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

int main() {
    int n;
    cin>>n;
    double N=n;
    cout<< fixed << setprecision(10);
    if(n%2==1){
        cout<< ((n/2)+1)/N <<endl;
    }
    else cout<< (n/2)/N <<endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let s = i.read_line().as_bytes();
    let r = s.iter().filter(|&&x| x == b'R').count();
    let b = n - r;
    let ans = if r > b { "Yes" } else { "No" };

    writeln!(o, "{}", ans).unwrap();
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int selectionSort(int A[],int N){
    int i, j, t, sw = 0,minj;
    for(i = 0; i < N-1; i++){
        minj=i;
        for(j = i; j < N; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    if(i != minj){
        sw++;
    }
    }
    return sw;
}

int main(){
    int A[100],i,N,sw;

    scanf("%d",&N);
    for (i = 0; i < N; i++)
    {
        scanf("%d",&A[i]);
    }
    
    sw = selectionSort(A,N);

    for(i=0;i<N;i++){
        if(i>0){
            printf(" ");
        }
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int a, b;
  cin >> a >> b;
  int ans = 0;
  while (a <= b) ans++, a *= 2;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3616
n = int(input())
t, a = map(int, input().split())
hl = list(map(int, input().split()))

dt = 10**9
num = 0
for i in range(n):
    ti = t - hl[i] * 0.006
    if abs(a - ti) <= dt:
        dt = abs(a - ti)
        num = i

print(num + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long A, long long B){
    if (B % A == 0){
        cout << A+B << endl;
    } else {
        cout << B-A << endl;
    }
}

int main(){

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}



Measured memory_bytes: 256
def parser(l, r):
    if all(S[i].isdigit() for i in range(l, r + 1)):
        return int(S[l:r + 1]) // 2 + 1
    ret = []
    cnt = 0
    start = 0
    for i in range(l, r + 1):
        if S[i] == '[':
            cnt += 1
            if cnt == 1:
                start = i
        elif S[i] == ']':
            if cnt == 1:
                ret.append(parser(start + 1, i - 1))
            cnt -= 1
    ret.sort()
    return sum(ret[:len(ret) // 2 + 1])


N = int(input())
for _ in range(N):
    S = input()
    print(parser(0, len(S) - 1))

Measured memory_bytes: 7712
a = int(input())
b = int(input())
if a == 1:
    if b ==2:
        print(3)
    else:
        print(2)
elif a == 2:
    if b == 1:
        print(3)
    else:
        print(1)
else:
    if b == 1:
        print(2)
    else:
        print(1)

Measured memory_bytes: 3060
p=int(input())
a=list(map(int,input().split()))
b=[0]*p
for i in range(p):
    T_0=0
    T_1=0
    for j in range(p):
        if j>i:
            T_0+=a[j]
        else:
            T_1+=a[j]
    b[i]=abs(T_0-T_1)
print(min(b))

Measured memory_bytes: 3060
### constant

MAX_Z = 1111

### subroutines

def lower_bound(arr, key, i0 = 0, i1 = arr.length)
  lb = i0 - 1
  ub = i1

  while lb + 1 < ub
    m = (lb + ub) / 2
    if arr[m] >= key
      ub = m
    else
      lb = m
    end
  end
  ub
end

### main

cbs = (0..MAX_Z).map{|z| z * z * z}

loop do
  z = gets.to_i
  break if z == 0
  #p z

  max_x3y3 = 0
  z3 = cbs[z]

  for x in (1...z)
    x3 = cbs[x]
    y = lower_bound(cbs, z3 - x3) - 1
    y3 = cbs[y]
    x3y3 = x3 + y3 
    max_x3y3 = x3y3 if max_x3y3 < x3y3
    #p [z3, x3, y3]
  end

  puts (z3 - max_x3y3)
end

Measured memory_bytes: 6112
n = int(input())
l = sorted(list(map(int,input().split())))

cnt = 0
for i in range(n-2):
  for j in range(i,n-1):
    if l[i]==l[j]:
      continue
    for k in range(j,n):
      if l[k]==l[j]:
        continue
      if l[k]<l[i]+l[j]:
        cnt+=1
print(cnt)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

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

    ll n;
    cin >> n;
    ll ans = 0;
    vll a(n);
    REP(i,n) cin >> a[i];
    sort(ALL(a));
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int l=j+1;l<n;l++){
                if(a[i] != a[j] && a[j] != a[l] && a[l] != a[i]){
                    if(a[i] + a[j] > a[l]) ans++;
                }
            }
        }
    }
    cout << ans <<endl;

    
    return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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>
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...));
}
int n;
vector<vector<pair<int, ll>>> g;
vector<int> ans;
void dfs(int now, int pre = -1, ll dep = 0) {
    ans[now] = dep % 2;
    for (auto p : g[now]) {
        int nxt;
        ll w;
        tie(nxt, w) = p;
        if (nxt == pre) continue;
        dfs(nxt, now, dep + w);
    }
}
int main() {
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        u--;
        v--;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    ans.resize(n);
    dfs(0);
    rep(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;
typedef pair<int, int> ii;
const int Nmax  = 900;

int n, m, k, d[Nmax][Nmax], ans = 1e9 + 10;
char a[Nmax][Nmax];
ii s, mv[] = {ii(-1, 0), ii(1, 0), ii(0, -1), ii(0, 1)};
queue<ii> qu;

void visit() {
    qu.push(s);
    while(!qu.empty()) {
        ii u = qu.front(); qu.pop();
        if (d[u.first][u.second] == k) continue;
        for(int i = 0; i < 4; ++i) {
            int x = u.first + mv[i].first, y = u.second + mv[i].second;
            if (a[x][y] == '#') continue;
            if (x == 1 || x == n+1 || y == 1 || y == m+1) continue;
            if (d[x][y] == -1) {
                d[x][y] = d[u.first][u.second] + 1;
                qu.push(ii(x, y));
            }
        }
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    memset(d, -1, sizeof(d));
    cin >> n >> m >> k;
    FOR(i, 1, n) FOR(j, 1, m) {
        cin >> a[i][j];
        if (a[i][j] == 'S') s = ii(i, j);
    }
    d[s.first][s.second] = 0;
    visit();
    FOR(i, 1, n) FOR(j, 1, m) {
        if (d[i][j] == -1) continue;
        int tmp = min(min(i-1, n-i), min(j-1, m-j));
        tmp = ceil(float(tmp)/k);
        ans = min(ans, 1 + tmp);
    }
    cout << ans;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> vec(h);
    rep(i, h){
             cin >> vec.at(i);
    }
    rep(i, w+2) cout << '#';
    cout << endl;
    rep(i, h) {
             cout << '#' << vec.at(i) << '#' << endl;
    }
    rep(i, w+2) cout << '#';
    cout << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2;
    return 0;
}

Measured memory_bytes: 256