akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin>>n;
  cout<<fixed;
  cout<<setprecision(10);
  vector<double>a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  vector<vector<double>>dp(n+1,vector<double>(n+1,0.0));
  dp[0][0]=1;
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<=i;j++)
    {
      if(j==0)
        dp[i][j]=dp[i-1][j]*(1-a[i-1]);
      else
        dp[i][j]=dp[i-1][j]*(1-a[i-1])+dp[i-1][j-1]*(a[i-1]);
    }
  }
  double ans=0.0;
  for(int i=n;i>(n/2);i--)
    ans+=dp[n][i];
  cout<<ans;
  return 0;
}


Measured memory_bytes: 70784
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int Partition(int *A,int p,int r){
	int x =A[r];
	int i =p-1;
	for(int j =p;j <=r-1;j++){
		if(A[j]<=x){
			i++;
			swap(A[i],A[j]);
			/*for(int k =0; k <n;k++){
				if(k==i){
					cout <<" ["<<A[k]<<"]";
				}else if(i==0){
					cout <<A[k];
				}else{
					cout <<" "<<A[k];
				}
			}
			cout <<endl;*/
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}
int main(){
	int d[100100];
	cin>>n;
	for(int i =0;i < n;i++){
		cin>>d[i];
	}
	int t =Partition(d, 0, n-1);
	for(int i =0; i <n;i++){
		if(i==t){
			cout <<" ["<<d[i]<<"]";
		}else if(i==0){
			cout <<d[i];
		}else{
			cout <<" "<<d[i];
		}
	}
	cout <<endl;
	return 0;
}

Measured memory_bytes: 1548
N=int(input())
h=list(map(int,input().split()))

#dp[i]はh[i]までにかかるコストの最小値
dp=[float('inf') for _ in range(N)] 
dp[0]=0

for i in range(N):
    if i>=1:
        dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i>=2:
        dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	char C[n + 1];
	for(int i = 0; i < n; i++)
		cin >> C[i];
	int cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(C[i] == 'o')
			cnt = 0;
		else
			cnt++;
		if(cnt == 2)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << n << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
vector<pii> adj[100005];
int color[100005];
void dfs(int current)
{
	for (int i = 0; i < adj[current].size(); ++i) {
		int next = adj[current][i].first, len = adj[current][i].second;
		if (!color[next]) {
			color[next] = (len & 1)? 0 - color[current]: color[current];
			dfs(next);
		}
	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int temp = n;
	while (--temp) {
		int a, b, len;
		cin >> a >> b >> len;
		adj[a].push_back(pii(b, len));
		adj[b].push_back(pii(a, len));
	}
	color[1] = 1;
	dfs(1);
	for (int i = 1; i <= n; ++i) {
		if (color[i] == 1)
			cout << "1\n";
		else
			cout << "0\n";
	}
	return 0;
}

Measured memory_bytes: 8448
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC116A
{
    class Program
    {
        static void Main(string[] args)
        {
            int AB, BC,CA;
            var word = Console.ReadLine().Split(' ');
            AB = int.Parse(word[0]);
            BC = int.Parse(word[1]);
            CA = int.Parse(word[2]);

           
                Console.Write(AB*BC/2);
          
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
H, W = map(int, input().split())

tmp = []
for i in range(H):
    row = input()
    if '#' in row:
        tmp.append(row)

res = [''] * len(tmp)
for col in zip(*tmp):
    if '#' in col:
        for j in range(len(tmp)):
            res[j] += col[j]

print(*res, sep='\n')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<int> number(N);
  
  for(int64_t i = 0; i < N; i++){
    cin >> number.at(i);
    
  }
  
  sort(number.begin(), number.end());
  
  int64_t count = 0;
  
  for(int64_t i = 0; i < N - 1; i++){
    if(number.at(i) == number.at(i + 1)){
      count++;
    }
  }
  
  if(count > 0){
    cout << "NO" << endl;
    
  }
  
  else{
    cout << "YES" <<  endl;
  }
  
    
  }


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

static const int MAX = 1500000+10;

int main(){

    while(1){
        int h[1500+10],w[1500+10];
        int N,M;
        cin>>N>>M;
        if(N == 0 && M == 0) break;
        for(int i=0; i<N; i++) cin>>h[i];
        for(int i=0; i<M; i++) cin>>w[i];

        vector<int> H(MAX,0),W(MAX,0);
        
        for(int i=0; i<N; i++){
            int tmp = 0;
            for(int j=i; j<N; j++){
                tmp += h[j];
                H[tmp]++;
            }
        }

        for(int i=0; i<M; i++){
            int tmp = 0;
            for(int j=i; j<M; j++){
                tmp += w[j];
                W[tmp]++;
            }
        }

        int ans = 0;

        for(int i=0; i<MAX; i++){
            ans += (W[i]*H[i]);
        }

        cout<<ans<<endl;

    }

    return 0;
}


Measured memory_bytes: 14504
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, sum, last, cnt, ans,a[100010],b[100010];
string str,ss;
struct Edge { LL to, cost; };
vector<LL>v;
bool f;
char c;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	rep(i, n) {
		cin >> b[i];
		sum += b[i];
	}
	if (n == 1)f = 1;
	m = sum;
	sum /= ((n + 1)*n) / 2;
	rep(i, n) {
		a[i] = b[(i + 1) % n] - b[i];
		cnt += a[i];
		if (a[i] < sum) {
			if ((sum-a[i]) % n == 0)
				q += (sum-a[i]) / n;
			else {
				YN(0);
				return 0;
			}
		}
		else if (a[i] > sum) {
			YN(0);
			return 0;
		}
	}
	
	if (q == sum&&m % (((n + 1)*n) / 2) == 0&&cnt==0)f = 1;
	YN(f);
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int min2(int a, int b){return a>b?b:a;}
int n, i;
int x, m, min;
int main(){
  scanf("%d%d", &n, &x);
  min=1024;
  for(i=0; i<n; i++){
    scanf("%d", &m);
    x -= m;
    min = min2(min, m);
  }
  printf("%d\n", n+x/min);
}

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



int main()
{
	//freopen("imput.txt","r",stdin);
	//freopen("output1.txt","w",stdout);
	int n ; 
	cin>> n ;
	int a[n] ; 
	int b[n] ; 
	for(int i =0 ; i< n ;i ++ ) {cin>>a[i];b[i] = a[i]  ;}

int ans =0  ;
	sort(b,b+n);

	for(int i =0 ; i<n ;i++){
		if (a[i]!=b[i]){
			ans++;

		}
	}
	if (ans<=2){cout<<"YES"<<endl;}
	else{cout<<"NO"<<endl;}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
typedef pair<ll,ll> pint;
bool cmp(pint a, pint b) { return a.second < b.second; }
int main(){
    int n;
    std::cin >> n;
    std::vector<pair<ll,ll>> a(n);
    rep(i,n){
        ll j,jj;
        std::cin >> j>>jj;
        a[i].fi=j-jj;
        a[i].se=j+jj;
    }
    sort(all(a),cmp);
 //   rep(i,n)std::cout << a[i].fi<<a[i].se << std::endl;
    ll res = 0;
    ll endtime = -INF;
    for (int i = 0; i < n; ++i) {
        if (a[i].first >= endtime) {
            endtime = a[i].second;
            ++res;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
char sex[100010][10];
int n, m, i, j, k, t, low, high, guess[30];
char gender[20];
int main(){
	cin>>n;
	low=0;
	high=n;
	guess[0]=0;
	cout<<guess[0]<<endl;
	cout<<flush;
	scanf("%s", &sex[0]);
	for(i=0;i<=9;i++) sex[n][i]=sex[0][i];
	if(sex[0][0]=='V') return 0;
	for(i=1;i<=20;i++){
		guess[i]=(low+high)/2;
		cout<<guess[i]<<endl;
		cout<<flush;
		scanf("%s" ,&sex[guess[i]]);
		if(sex[guess[i]][0]=='V') return 0;
		if(((sex[low][0]==sex[guess[i]][0])&&((guess[i]-low)%2==1))||((sex[low][0]!=sex[guess[i]][0])&&((guess[i]-low)%2==0))) high=guess[i];
		else low=guess[i];
	}
	return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int counter[30]={0};
	char s;
	while(scanf("%c",&s)!=EOF){
		if(('a'<=s)&&(s<='z')) counter[s-'a']++;
		if(('A'<=s)&&(s<='Z')) counter[s-'A']++;

	}
	REP(i,26){
		char c='a'+i;
		cout << c << " : "<<counter[i]<<endl;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1000000000+7;
const int MAX_N=50;
const int MAX_M=MAX_N*(MAX_N-1)/2;

int N,M;
int a[MAX_N];
int b[MAX_N];

struct UnionFind {
    vector<int> data;
    //size_分のデータを用意
    UnionFind(int size_) : data(size_, -1) { }
    //xとyの属する集合を併合
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    //xとyが同じ集合に属するか
    bool findSet(int x, int y) { return root(x) == root(y); }
    //xの根を求める
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    //
    int size(int x) { return -data[root(x)]; }
};

int main(){
	cin>>N>>M;
	REP(i,M){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
	}
	int count=0;
	REP(i,M){
		UnionFind uf(N);
		REP(j,M){
			if(i==j)continue;
			uf.unionSet(a[j],b[j]);
		}
		bool flag=false;
		REP(s,N){
			REP(t,N){
				if(!uf.findSet(s,t))flag=true;
			}
		}
		if(flag)count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a <= M)]
    if i == 0:
        s = set(list(a))
    else:
        _s = set(list(a))
        s &= _s

print(len(s))

Measured memory_bytes: 26960
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll a,b;
cin>>a>>b;
ll ans=(a+b)/2;
if((a+b)%2>0){
    ans++;
}
cout<<ans<<endl;
}









Measured memory_bytes: 256
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


#include <bits/stdc++.h>
using namespace std ;
 
 
typedef long long                ll;
typedef long double              ld;
typedef unsigned long long       ull;
typedef pair <int,int>           pii;
typedef pair <ll,ll>             pll;
typedef vector <int>             vi;
typedef vector <ll>              vll;
typedef vector <vector <int> >   vvi;
 
inline int    Int(){int x; cin >> x; return x;}
inline ll     Long(){ll x; cin >> x; return x;}
inline float  Float(){float x; cin >> x; return x;}
inline double Double(){double x; cin >> x; return x;}
inline void   Yes(){cout << "Yes" << endl;}
inline void   No(){cout << "No" << endl;}
inline void   YES(){cout << "YES" << endl;}
inline void   NO(){cout << "NO" << endl;}
 
const int N             =(int)2e5 + 5;
const int maxN          =(int)1e6 + 6;
const ll  Mod           =(ll)1e9 + 7;
const int inf           =(int)2e9;
const ll  Inf           =(ll)1e18;
 
#define     T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i=(b); i!=(e+1)-2*(b > e); i =i+1-2*(b > e))
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
#define     biday       return 0 
 
 
int main(){
	int A,B;
	cin >> A >> B;
	
	if((A+B)%2==0)
		cout << (A+B)/2 << endl;
	else
		cout << "IMPOSSIBLE" << endl;
    

    biday;
}
 
//...............BYE BYE................

Measured memory_bytes: 256
# https://atcoder.jp/contests/arc081/tasks/arc081_a

from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)

ans = 0
rec = []
for k, v in c.items():
    if v >= 2:
        rec.append(k)
    if v >= 4:
        ans = max(ans, k ** 2)

if len(rec) >= 2:
    rec.sort(reverse=True)
    ans = max(ans, rec[0] * rec[1])
print(ans)

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

char S[3][100];

int main()
{
    for(int i = 0; i < 3 ; i++)
    {
        scanf("%s",S[i]);
    }
    printf("%c%c%c\n",S[0][0] - 'a' + 'A' ,S[1][0] - 'a' + 'A',S[2][0] - 'a' + 'A');
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,M,K;
	int a=0;
	scanf("%d%d%d",&N,&M,&K);
	for(int i=0;i<N;i++){
	for(int j=0;j<M;j++)
		if((i*j+(N-i)*(M-j))==K)a++;
	}
	if(a>0||N==1||M==1||K==0)printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = max({ a * c,a * d,b * c,b * d });
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	char A[101][101];
	int i;
	for(i=0;i<3;i++){
		scanf("%s",A[i]);
	}
	printf("%c%c%c\n",A[0][0],A[1][0],A[2][0]);
	return 0;
}

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

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

int isOk(ll n, ll a) {
	while (n % a == 0) {
		n /= a;
	}

	return n % a == 1;
}

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

	ll n;
	cin >> n;

	ll N = n;
	ll res = 0;

	for (ll x = 1; x * x <= N; x++) {
		if (N % x == 0) {
			if (x > 1 && isOk(n, x)) {
				res++;
			}

			if (x * x != n && isOk(n, n / x)) {
				res++;
			}
		}
	}

	N = n - 1;

	for (ll x = 1; x * x <= N; x++) {
		if (N % x == 0) {
			if (x > 1) {
				res++;
			}

			if (N != x * x) {
				res++;
			}
		}
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
	ll A,B,C;
	cin >> A>>B>>C;
	if(A==B && A!=C){
		cout<< "Yes"<<endl;
	}
	else if(A==C && B!=C ){
		cout<< "Yes"<<endl;
	}
	else if(B==C && A!=C){
		cout<< "Yes"<<endl;
	}
	else{
		cout<< "No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		new Main().exec();
	}

	void exec() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int act = 0;
		int result = 0;

		for (int i = 0; i < n; i++) {
			if (act > h[i]) {
				act = h[i];
			}else {
				result += h[i] - act;
				act = h[i];
			}
		}

		System.out.println(result);
		sc.close();
	}
}


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

using namespace std;

int main(){
  int a, b, c;
  int S1,S2,S3;

  cin >> a >> b >> c;

  S1 = a + b;
  S2 = a + c;
  S3 = b + c;

  cout << min(S1, min(S2, S3)) << endl;

  return 0;
}


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

int main(void)
{
  int N;
  cin >> N;
  long long sum = 0;
  for (int i = 1; i <= N; i++)
  {
    if (i % 3 == 0 &&
        i % 5 == 0)
    {
      continue;
    }
    else if (i % 3 == 0)
    {
      continue;
    }
    else if (i % 5 == 0)
    {
      continue;
    }
    else
    {
      sum += i;
    }
  }

  cout << sum << endl;
  return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a>9||b>9) cout << -1 << endl;
    else cout << a*b << endl;
    return 0;
}

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

using namespace std;

#define rep(i, start, end) for (int(i) = (start); (i) < (end); (i)++)
#define rep_r(i, end, start) for (int(i) = (end); (i) >= (start); i--)
#define len(ar) (sizeof(ar) / sizeof(ar[0]))

int main() {
  int N, K;
  cin >> N >> K;
  int a[200001] = {0};
  set<int> s;

  rep(i, 0, N) {
    int n;
    cin >> n;
    a[n]++;
    if (s.find(n) == s.end()) s.insert(n);
  }

  if (s.size() <= K) {
    cout << 0;
    return 0;
  }

  int uniqN = s.size();
  int ans = 0;
  sort(a, a + 200001);

  for (int i = 0; i < 200001; i++) {
    if (a[i] > 0) {
      ans += a[i];
      uniqN--;
      if (uniqN <= K) break;
    }
  }

  cout << ans;
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int c = 0;
  for(int i = 1; i <= n; i += 2){
    int count = 0;
    for(int j = 1; j <= i; j++){
      if(i % j == 0){
        count++;
      }
    }
    if(count == 8){
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589
#define endl "\n"
#define int long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define fr(i,a,b) for (int i = (a); i < (b); ++i)

void solve(){
    int n;
    cin >> n;
    int dp[n + 1][3];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    fr(i, 1, n + 1){
        int a, b, c;
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a;
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b;
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c;
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    t = 1;
    //cin >> t;
    while(t--) {solve();}
    return 0;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int cont[4];
  m0(cont);
  for (int i = 0; i < 3; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    cont[a]++;
    cont[b]++;
  }

  for (int i = 0; i < 4; i++) {
    if (cont[i] >= 3) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 998244353;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    vector<vector<mint>> dp(513, vector<mint>(501, 0));
    vector<vector<mint>> dp2(513, vector<mint>(501, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {

        for (int j = 0; j < 513; ++j) {
            for (int i = 1; i < 501; ++i) {
                dp[j][i] += dp[j][i - 1];
            }
        }

        for (int j = 0; j < 513; ++j) {
            for (int k = 0; k < 501; ++k) {
                if ((j ^ k) < 513)
                    dp2[j][k] += dp[j ^ k][k];
            }
        }
        swap(dp, dp2);
        dp2.assign(513, vector<mint>(501, 0));
    }
    mint ret = 0;
    for (int i = 0; i <= x; ++i) {
        ret += dp[x][i];
    }
    cout << ret << "\n";
    return 0;
}


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

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n);
    rep(i,n){
        vector<int>dist(n,inf);
        queue<int> q;
        auto push = [&](int v, int d){
            if(dist[v] != inf) return;
            dist[v] = d;
            q.push(v);
        };
        push(i,0);
        
        while(!q.empty()){
            int v=q.front();
            int d=dist[v];
            q.pop();
            if(v+1 < n){
                push(v+1,d+1);
            }
            if(v>=0){
                push(v-1,d+1);
            }
            if(v == x){
                push(y,d+1);
            }
            if(v == y){
                push(x,d+1);
            }
        }
        rep(i,n) ans[dist[i]]++;  
    }
    rep(i,n){
        ans[i]/= 2;
    }
    for(int i=1; i<n; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    p = LIR(n)
    q = LIR(n)
    s = [(p[i][0],p[i][1],0) for i in range(n)]+[(q[i][0],q[i][1],1) for i in range(n)]
    s.sort()
    q = []
    ans = 0
    for x,y,i in s:
        if not i:
            q.append(y)
            q.sort()
        else:
            j = bisect.bisect_left(q,y)-1
            if j >= 0:
                q.pop(j)
                ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    while(1){
        int a, b, c;
        cin >> a >> b >> c;
        if (a == -1 && b == -1 && c == -1){
            break;
        }
        else if (a == -1 || b == -1){
            cout << 'F' << endl;
        }
        else if (a + b >= 80){
            cout << 'A' << endl;
        }
        else if (65 <= a + b){
            cout << 'B' << endl;
        }
        else if (50 <= a + b){
            cout << 'C' << endl;
        }
        else if ((30 <= a + b) && c >= 50){
            cout << 'C' << endl;
        }
        else if ((30 <= a + b) && c < 50){
            cout << 'D' << endl;
        }    
        else{
            cout << 'F' << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main()

 {
   long long a,b,c,k,s;
   cin>>a>>b>>c>>k;
  // if(a==k)
  //  cout<<a<<endl;
  // else
    if(a<=k){
   {
       if((k-(a+b))>0)
      s=(a*1+b*0+((k-(a+b))*-1));
      else if((k-(a+b))==0)
       s=(a*1+b*0);
   }
   cout<<s<<endl;
 }
   else if (a>k)
   cout<<k<<endl;
   return 0;
}

Measured memory_bytes: 3620
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def l(): return list(sp())
def sp(): return map(int, data().split())


def calculate(string):
    result = 0
    while string:
        c = bin(string)[2:].count('1')
        string = string % c
        result += 1
    return result


n = int(data())
s = list(data())
ones = []
powers = []
for i in range(n):
    if s[i] == '1':
        ones.append(i)
length = len(ones)
powers = [[0, 0] for i in range(n)]
for i in range(n):
    if length - 1 > 0:
        powers[i][0] = pow(2, i, length-1)
    powers[i][1] = pow(2, i, length + 1)
powers = powers[::-1]
s1, s2 = 0, 0
for i in ones:
    if length - 1 > 0:
        s1 = (s1 + powers[i][0])
    s2 = (s2 + powers[i][1])
for i in range(n):
    if s[i] == '1':
        if length - 1 <= 0:
            out("0\n")
            continue
        temp = s1
        temp = (temp - powers[i][0] + length - 1) % (length - 1)
    else:
        temp = s2
        temp = (temp + powers[i][1]) % (length + 1)
    out(str(calculate(temp)+1)+"\n")


Measured memory_bytes: 119000
#include<stdio.h>
int main()
  {
    int i,count=1;
  float n,a;
    scanf("%f",&n);
    if(n==1)
    {
      printf("1");
    }
  else
  {
    for(i=2;i<=n;i++)
      { 
      if(i%2==1)
        { 
        count++;
        }
      }
     a=count/n;
     printf("%.10f",a);
  }
 
  return 0;
  }

  


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    vector<int> a(3);
    for (int i = 0; i < 3; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    cout << a[0] + a[1] + a[2] * 10 << endl;
}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<utility>
#include<climits>

#define INF INT_MAX/2
#define EPS 1.0e-7

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef pair<int,PII> PIII;

int N;

vector<PII> compress(vector<PIII> &v, vector<PIII> &s, vector<PIII> &e){

    vector<PIII> cv(v.size());

    for(unsigned int i=0;i<v.size();++i)cv[i] = v[i];
    sort(cv.begin(),cv.end());
    int n = unique(cv.begin(),cv.end()) - cv.begin();

    vector<PII> ret(v.size()/2);
    for(unsigned int i=0;i<v.size()/2;++i){
        int si = lower_bound(cv.begin(),cv.begin()+n,s[i]) - cv.begin();
        int ei = lower_bound(cv.begin(),cv.begin()+n,e[i]) - cv.begin();
        ret[i] = make_pair(si,ei);
    }

    return ret;

}

int main(){

    cin.sync_with_stdio(false);

    while(cin >> N,N){

        vector<PIII> v(2*N);
        vector<PIII> s(N);
        vector<PIII> e(N);

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

            int h,m,sec;
            string st,et;

            cin >> st >> et;

            sscanf(st.c_str(),"%d:%d:%d",&h,&m,&sec);
            v[2*i] = make_pair(h,make_pair(m,sec));
            s[i] = v[2*i];

            sscanf(et.c_str(),"%d:%d:%d",&h,&m,&sec);
            v[2*i+1] = make_pair(h,make_pair(m,sec));
            e[i] = v[2*i+1];

        }

        vector<PII> p = compress(v,s,e);

        vector<int> cnt(2*N);

        for(int i=0;i<N;++i){
            cnt[p[i].first]++;
            cnt[p[i].second]--;
        }

        for(int i=1;i<2*N;++i)
            cnt[i] += cnt[i-1];

        int ans=0;

        for(int i=0;i<2*N;++i)
            ans = max(ans,cnt[i]);

        cout << ans << endl;

    }

    return 0;

}

Measured memory_bytes: 2028
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


	int w,h;
	const int MAX=INT_MAX/10;
struct node{
    int y,x,cost;
    node(int y,int x,int cost):y(y),x(x),cost(cost){}
    bool operator<(const node& other)const{
        return cost>other.cost;
    }
};
const int NONE=-1;
int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int search(vs &field,vvi &time,pii start,pii goal){
    priority_queue<node> q;
	q.push(node(start.first,start.second,0));
    vvi cost(h,vi(w,MAX));
    cost[start.first][start.second]=0;
    while(!q.empty()){
        node cnode=q.top();q.pop();
		if(cost[cnode.y][cnode.x]<cnode.cost){
            continue;
        }
		REP(d,4){
			int xx=cnode.x+dx[d];
			int yy=cnode.y+dy[d];
			if(xx>=0&&yy>=0&&xx<w&&yy<h&&field[yy][xx]!='#'){
				int newcost=cnode.cost+time[cnode.y][cnode.x];
				if(cost[yy][xx]>newcost){
					cost[yy][xx]=newcost;
					q.push(node(yy,xx,newcost));
				}
            }
        }
    }
	return cost[goal.first][goal.second];
}
int main(){
	cin>>w>>h;
	vs field(h);
	vector<pii> points;
	REP(i,h){
		cin>>field[i];
	}
	REP(i,h){
		REP(j,w){
			if(field[i][j]=='M'){
				points.push_back(make_pair(i,j));
			}
		}
	}
	REP(i,h){
		REP(j,w){
			if(field[i][j]=='S'){
				points.push_back(make_pair(i,j));
			}
		}
	}
	REP(i,h){
		REP(j,w){
			if(field[i][j]=='G'){
				points.push_back(make_pair(i,j));
			}
		}
	}

	vvi time(h,vi(w,1));
	REP(i,h){
		REP(j,w){
			int nearest=MAX;
			FOR(x,-3,3+1){
				FOR(y,-3,3+1){
					if(x==0&&y==0)continue;
					int yy=i+y,xx=j+x;
					if(yy>=0&&xx>=0&&yy<h&&xx<w&&field[i+y][j+x]=='#'){
						nearest=min(nearest,max(abs(x),abs(y)));
					}
				}
			}
			if(nearest!=MAX){
				time[i][j]=4-nearest;
			}
		}
	}
	vvi dist(points.size(),vi(points.size()));
	REP(i,points.size()){
		REP(j,points.size()){
			if(i!=j){
				dist[i][j]=search(field,time,points[i],points[j]);
			}
		}
	}
	vi order(points.size()-2);
	REP(i,order.size()){
		order[i]=i;
	}
	int ans=MAX;
	do{
		int cost=0;
		cost+=dist[order.size()][order[0]];
		REP(i,order.size()-1){
			cost+=dist[order[i]][order[i+1]];
		}
		cost+=dist[order[order.size()-1]][order.size()+1];
		ans=min(ans,cost);
	}while(next_permutation(ALL(order)));
	cout<<ans<<endl;
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n{},c{};
    cin>>n;
    for(int i=1;i<=n;i++){
        int temp{};
        temp = log10(i)+1;
        if(temp&1){
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> g(n, vector<bool>(n, false));
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        g[u][v] = g[v][u] = true;
    }

    vector<int> v(n - 1);
    for (int i = 0; i < n - 1; ++i) {
        v[i] = i + 1;
    }
    int ans = 0;
    do
    {
        int p = 0;
        bool ok = true;
        for (auto& i : v) {
            ok &= g[p][i];
            p = i;
        }
        if (ok) ++ans;

    } while (next_permutation(v.begin(), v.end()));
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,4);
  var N = input[0];
  var P = input[1];
  if(isPrime(P)){
     myout(1);
    return;
  }
  var pf = getPrimeFactorization(P);
  var pfKeys = Array.from(Object.keys(pf));
  var output = 1;
  for(var i = 0; i < pfKeys.length; i++){
    if(pf[pfKeys[i]] >= N){
       output *= Math.pow(pfKeys[i],Math.floor(pf[pfKeys[i]] / N));
    }
  }
  myerr(pf);
  myout(output);
}
function getPrimeFactorization(val){
  var primeList = {};
  var div = 2;
  while(val != 1){
    if(val % div == 0){
      (primeList[div] == null)  ? primeList[div] = 1 : primeList[div]++;
      val /= div;
      if(isPrime(val)){
        (primeList[val] == null)  ? primeList[val] = 1 : primeList[val]++;
        break;
      }
    }else{
      div = (div == 2) ? div + 1 : div + 2;
    }
  }
  return primeList;
}
function isPrime(val){
        if(val <= 1 || (val != 2 && val % 2 == 0)){
                return false;
        }else if(val == 2){
                return true;
        }
        var root = Math.floor(Math.sqrt(val));
        for(var i = 3; i <= root; i += 2){
                if(val % i == 0){
                        return false;
                }
        }
        return true;
}
Main(myin());


Measured memory_bytes: 8524
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <utility>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

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


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

int main() {
  long long n,d,x,sum;
  cin >> n >> d;
  x=n-d+1;
  sum=x*(x-1)/2+d-1;
  if(d>1) sum+=x-2;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3072