akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N,i,j;
	char tmp[20];
	cin>>N;
	string S;
	map<char,int> myMap;
	map<char,int>::iterator mit;
	map<string,int> myMap0;
	map<string,int>::iterator mit0;
	for (i=0;i<N;i++){
		cin>>S;
		myMap.clear();
		for (j=0;j<S.size();j++){
			mit=myMap.find(S[j]);
			if (mit==myMap.end()){
				myMap[S[j]]=1;
			}else{
				myMap[S[j]]++;
			}
		}
		S.clear();
		for (mit=myMap.begin();mit!=myMap.end();mit++){
			S+=(*mit).first;
			sprintf(tmp,"%d",(*mit).second);
			S+=tmp;
		}
		mit0=myMap0.find(S);
		if (mit0==myMap0.end()){
			myMap0[S]=1;
		}else{
			myMap0[S]++;
		}
	}
	LL ans=0;
	for (mit0=myMap0.begin();mit0!=myMap0.end();mit0++){
		LL n=(*mit0).second;
		if (n>1){
			ans+=(n*(n-1))/2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13568
'''
問題：
    駐車場があり、以下の二種類のプランのどちらかを選んで駐車できます。
    プラン 1 : T時間駐車した場合、A×T 円が駐車料金となる。
    プラン 2 : 駐車した時間に関わらず B 円が駐車料金となる。
    N時間駐車するとき、駐車料金は最小でいくらになるか求めてください。
'''

'''
制約：
    1 ≦ N ≦ 20
    1 ≦ A ≦ 100
    1 ≦ B ≦ 2000
    入力は全て整数
'''

# 標準入力から N, A, B の値を取得する
n, a, b = map(int, input().split())

result = [n * a, b] # 結果出力用のリスト

print(min(result))


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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) (cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#else
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (0)
#endif
/// }}}--- ///


#define rep(i, a, b) for(ll i = (ll) (a); i < (ll) (b); i++)
#define repi(i, a, b) for(ll i = (ll) (a); i <= (ll) (b); i++)
#define rrep(i, a, b) for(ll i = (ll) (b) - 1; i >= (ll) (a); i--)
#define rrepi(i, a, b) for(ll i = (ll) (b); i >= (ll) (a); i--)

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; string s;
  cin >> n >> s;
  int m = n * 2;

  ll ans = 0;
  for(int i = 0; i < (1 << n); i++) {
    string x, y;
    rep(j, 0, n) if(i & (1 << j)) x += s[j]; else y += s[j];
    string z = x + y;
    dump(z, x, y);
    int cnt = 0;
    vector<vector<ll>> dp(19, vector<ll>(19));
    rrep(j, n, m) {
      repi(k, 0, min((int) x.size(), cnt + 1)) {
        ll l = cnt + 1 - k;
        if(l < 0) continue;
        if(l > y.size()) continue;
        // add x
        if(k && s[j] == x[k-1]) {
          if(cnt) dp[cnt][k] += dp[cnt - 1][k - 1];
          else dp[cnt][k] += 1;
        }
        // add y
        if(l && s[j] == y[l-1]) {
          if(cnt) dp[cnt][k] += dp[cnt - 1][k];
          else dp[cnt][k] += 1;
        }
      }
      cnt++;
    }
    ans += dp[n-1][x.size()];
    dump(dp[n-1][x.size()]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long int h[100005]={0},n,dp[100005]={0};
long long int calc(long long int i)
{
	if(dp[i]!=-1)
		return dp[i];
	else
	{
		long long int a,b;
		a=calc(i-1)+fabs(h[i]-h[i-1]);
		b=calc(i-2)+fabs(h[i]-h[i-2]);
		dp[i]=a<b?a:b;
		return dp[i];
	}
}
int main()
{
	long long int i,ans;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>h[i];
	for(i=0;i<=n;i++)
		dp[i]=-1;
	dp[1]=0;
	dp[2]=fabs(h[2]-h[1]);
	ans=calc(n);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6528
K = int(input())
A = list(map(int,input().split()))

if A[-1] != 2:
    print(-1)
    exit()

A.reverse()
mn = mx = 2
for a,b in zip(A,A[1:]):
    mn += (b - mn%b)%b
    mx += a-1
    mx -= mx%b
    if mn > mx:
        print(-1)
        exit()

mx += A[-1]-1
print(mn,mx)

Measured memory_bytes: 14252
#include <stdio.h>
#include <math.h>


main()
{
int a,b,d;
char c;
while(1){
	scanf("%d %c %d",&a,&c,&b);
	if(c=='?')break;
	if(c=='+')d=a+b;
	if(c=='-')d=a-b;
	if(c=='*')d=a*b;
	if(c=='/')d=a/b;
	printf("%d\n",d);
}
}


Measured memory_bytes: 2104
#include <stdio.h>

int main(){
    int n;
    int a[200];

    int i;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    for(i=n-1; i>0; i--){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[0]);
}


Measured memory_bytes: 2068
n = int(input())
l = []
for i in range(n):
    m,q = map(int,input().split())
    l.append((m,q))
count = 0
flag = 0
for i in range(n):
    if l[i][0] == l[i][1]:
        count += 1
        if count == 3:
            print("Yes")
            flag =1
            break
    else:
        count = 0
        
if flag == 0:
    print("No")


Measured memory_bytes: 9212
import math
n, d = map(int, input().split())
x = []
ans = [i**2 for i in range(1, (n*d)**2)]
for i in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)
cnt = 0
sum_t = 0
for i in range(n):
    for j in range(i+1, n):
        sum_t = 0
        for k in range(d):
            sum_t += (x[i][k]-x[j][k])**2
        if sum_t in ans:
            cnt += 1
print(cnt) 


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	int n, m; cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int A[220000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> A[i]; }
    sort(A, A + N);
    for (int i = 1; i < N; i++) { if (A[i - 1] == A[i]) { fin("NO"); }}
    cout << "YES" << endl;
}

Measured memory_bytes: 1792
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Align
 */

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

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], ps[MAX_N], qs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n);

  for (int i = 0; i < n - 1; i++) {
    if (i & 1) ps[i + 1]++, ps[i]--, qs[i]++, qs[i + 1]--;
    else ps[i]++, ps[i + 1]--, qs[i + 1]++, qs[i]--;
  }
  sort(ps, ps + n);
  sort(qs, qs + n);

  ll sump = 0, sumq;
  for (int i = 0; i < n; i++) {
    sump += ps[i] * as[i];
    sumq += qs[i] * as[i];
  }

  printf("%lld\n", max(sump, sumq));
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll res = max({a*c, b*d});
  ll res2 = max({a*d, b*c});
  cout << max(res, res2) << endl;
}


Measured memory_bytes: 3632
import math
a, b, C = map(float, input().split())
c = math.sqrt(a**2 + b**2 - (2*a*b*math.cos(math.radians(C))))
L = (a+b+c)
s = L/2
S = math.sqrt(s*(s-a)*(s-b)*(s-c))
h = (2*S)/a
print('{:.8f}'.format(S))
print('{:.8f}'.format(L))
print('{:.8f}'.format(h))


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

struct UnionFind {
    vector<int> parents;
    UnionFind(int N) : parents(N+1) {
        for (int i = 0; i < N+1; i++) parents[i] = i;
    }
    int root(int x) {
        if (parents[x] == x) {
            return x;
        } else {
            parents[x] = root(parents[x]);
            return parents[x];
        }
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx != ry) {
            parents[rx] = ry;
        }
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M; cin >> N >> M;
    UnionFind tree(N);
    for (int i = 0; i < M; i++) {
        int x, y, z; cin >> x >> y >> z;
        tree.unite(x, y);
    }
    set<int> roots;
    for(int i = 1; i <= N; i++) {
        roots.insert(tree.root(i));
    }
    cout << roots.size() << endl;
}

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

string A,B;

string rec(string S1,string S2){
    if(S1=="" || S2=="") return "";
    if(S1=="()" || S2=="()") return "";
    int c = 0;
    int N1 = S1.size(),N2 = S2.size();
    string left1,right1;
    string num1;
    for(int i=0;i<N1;i++){
        if(S1[i]=='(') c++;
        if(S1[i]==')') c--;
        if(c==0){
            left1 = S1.substr(1,i-1);
            int id = i+2;
            while(S1[id]!=']'){
                num1 += S1[id];
                id++;
            }
            break;
        }
    }
    for(int i=N1-1;i>=0;i--){
        if(S1[i]=='(') c++;
        if(S1[i]==')') c--;
        if(c==0){
            right1 = S1.substr(i+1,N1-i-2);
            break;
        }
    }
    c = 0;
    string left2,right2;
    string num2;
    for(int i=0;i<N2;i++){
        if(S2[i]=='(') c++;
        if(S2[i]==')') c--;
        if(c==0){
            left2 = S2.substr(1,i-1);
            int id = i+2;
            while(S2[id]!=']'){
                num2 += S2[id];
                id++;
            }
            break;
        }
    }
    for(int i=N2-1;i>=0;i--){
        if(S2[i]=='(') c++;
        if(S2[i]==')') c--;
        if(c==0){
            right2 = S2.substr(i+1,N2-i-2);
            break;
        }
    }
//    cerr << num1 << " " << num2 << endl;
    int n = stoi(num1)+stoi(num2);
    string center = to_string(n);
    return '(' + rec(left1,left2) + ')' + '[' + center + ']' + '(' + rec(right1,right2) + ')';
}

int main(){
    cin >> A >> B;
    cout << rec(A,B) << endl;
}


Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    scanf("%d", &n);
    int max=0;
    for(int i=0;i*i<=n;i++){
        max=i*i;
    }
    for(int i=0;i*i*i<=n;i++){
        if(i*i*i>max){
            max=i*i*i;
        }
    }
    for(int i=0;i*i*i*i<=n;i++){
        if (i*i*i*i>max){
            max=i*i*i*i;
        }
    }
    for(int i=0;i*i*i*i*i<=n;i++){
        if (i*i*i*i*i>max){
            max=i*i*i*i*i;
        }
    }
    for(int i=0;i*i*i*i*i*i<=n;i++){
        if (i*i*i*i*i*i>max){
            max=i*i*i*i*i*i;
        }
    }
    for(int i=0;i*i*i*i*i*i*i<=n;i++){
        if (i*i*i*i*i*i*i>max){
            max=i*i*i*i*i*i*i;
        }
    }
    for(int i=0;i*i*i*i*i*i*i*i<=n;i++){
        if (i*i*i*i*i*i*i*i>max){
            max=i*i*i*i*i*i*i*i;
        }
    }
    printf("%d", max);
}

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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  ll ans = 0;
  vector<bool> d1(10);
  vector<bool> d2(100);
  vector<bool> d3(1000);
  rep(i, N) {
    int d = S.at(i) - '0';
    rep(j, 100) {
      if (d2[j]) {
        d3[j*10+d] = true;
      }
    }
    rep(j, 10) {
      if (d1[j]) {
        d2[10*j+d] = true;
      }
    }
    d1[d] = true;
  }
  rep(i, 1000) {
    if (d3.at(i) == true) {
      ans++;
    }
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	int out=inf;
	rep(i,n){
		int a;
		cin>>a;
		int co=0;
		while(a%2==0){
			a/=2;
			co++;
		}
		out=min(out,co);
	}
	cout<<out<<endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;

signed main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<int> p;
    char now=s[0];
    p.push_back(1);
    int cnt=0;
    for(int i=1;i<n;i++){
        if(s[i]==now)p[p.size()-1]++;
        else {
            p.push_back(1);
            now=s[i];
        }
    }
    cnt=p.size();
    cout<<n-(cnt-min(cnt-1,k*2))<<endl;
    
    return 0;
}


Measured memory_bytes: 1528
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	blues := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&blues[i])
	}
	var m int
	fmt.Scan(&m)
	reds := make([]string, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&reds[i])
	}

	calcScore := func(word string) int {
		score := 0
		for i := range blues {
			if blues[i] == word {
				score++
			}
		}
		for i := range reds {
			if reds[i] == word {
				score--
			}
		}
		return score
	}

	scoreMax := 0
	for i := range blues {
		score := calcScore(blues[i])
		if score > scoreMax {
			scoreMax = score
		}
	}
	fmt.Println(scoreMax)
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<int> vec;
  int sum = 0;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    vec.pb(x);
    sum += x;
  }
  int mini = inf;
  int index = 0;
  for(int i = 0; i < n; i++){
    if(abs(sum - n * vec[i]) < mini){
      mini = abs(sum - n * vec[i]);
      index = i;
    }
  }
  cout << index << endl;
	return 0;
}


Measured memory_bytes: 764
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String A=scan.next();
String B=scan.next();
int a=Integer.parseInt(A);
int b=Integer.parseInt(B);
if(a<b)
System.out.println("a < b");
else if(a>b)
System.out.println("a > b");
else
System.out.println("a == b");
}
}

Measured memory_bytes: 26060
a = int(input())
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
b = a-1
print(list[b])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define ui64 uint64_t
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define kpair pair<int, pair<int,int>
#define lwb lower_bound
#define upb upper_bound
const int mod = 1e9+7;
const int maxn = 1e5;

using namespace std;
ifstream fi("");
ofstream fo("");
int dp[3001][3001];
string s,t;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>s>>t;
    for(int i=1;i<=s.length();i++){
        for(int j=1;j<=t.length();j++){
            dp[i][j] = max(dp[i-1][j-1]+(s[i-1]==t[j-1]),max(dp[i-1][j],dp[i][j-1]));
        }
    }
    int cur = dp[s.length()][t.length()];
    int i=s.length();
    int j=t.length();
    string res;
    while(dp[i][j]>0){
        while(dp[i-1][j]==cur)i--;
        while(dp[i][j-1]==cur)j--;
        res+=s[i-1];
        i--;
        j--;
        cur=dp[i][j];
    }
    for(int i=res.length()-1;i>=0;i--) cout<<res[i];

}






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


int main(){

  int N;

  cin>>N;

  if(1<=N&&N<=9) cout<<"ABC"<<endl;
  if(10<=N&&N<=99) cout<<"ABC"<<endl;
  if(100<=N&&N<=999) cout<<"ABC"<<endl;
  if(1000<=N&&N<=1009){
      N-=999;
      cout<<"ABD"<<endl;
	}
    if(1010<=N&&N<=1099){
      N-=999;
      cout<<"ABD"<<endl;
	}  

       if(1100<=N&&N<=1998){
      N-=999;
      cout<<"ABD"<<endl;
	}  


  return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n: Int = sc.nextInt()


    val motivations = Array(n){LongArray(3)}

    for(i in 0 until n) {
        for(j in 0 until 3) {
           motivations[i][j] = sc.nextLong()
        }
    }

    val dp = Array(n){LongArray(3)}
    dp[0][0] = motivations[0][0]
    dp[0][1] = motivations[0][1]
    dp[0][2] = motivations[0][2]

    for(i in 1 until n) {
        for(j in 0 until 3) {
            val firstIndex = (j+1)  % 3
            val secondIndex = (j+2)  % 3
            dp[i][j] = motivations[i][j] + Math.max(dp[i-1][firstIndex], dp[i-1][secondIndex])
        }
    }

    println(Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2])))

}

Measured memory_bytes: 112596
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    free = 0
    a = [0 for _ in range(8)]
    
    for i in A:
        if i < 400:
            a[0] += 1
        elif i < 800:
            a[1] += 1
        elif i < 1200:
            a[2] += 1
        elif i < 1600:
            a[3] += 1
        elif i < 2000:
            a[4] += 1
        elif i < 2400:
            a[5] += 1
        elif i < 2800:
            a[6] += 1
        elif i < 3200:
            a[7] += 1
        else:
            free += 1
            
    ans = 0
    for i in a:
        if i == 0:
            continue
        if i != 0:
            ans += 1
            
    if ans != 0:
        print("{} {}".format(ans, ans+free))
    else:
        print("{} {}".format(1, ans+free))
    
        
if __name__ == "__main__":
	main()


Measured memory_bytes: 38768
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

const int N=100005;
const int E=N<<1;

int tov[E],nxt[E];
int last[N];
int n,tot,ans;

inline void insert(int x,int y){tov[++tot]=y,nxt[tot]=last[x],last[x]=tot;}

int dfs(int x,int fa=0)
{
	int ret=0,uni=0;
	for (int i=last[x],y,bit;i;i=nxt[i])
		if ((y=tov[i])!=fa) bit=dfs(y,x),uni|=bit&ret,ret|=bit;
	int d=1;
	for (int tmp=uni;tmp;d=tmp<<1,tmp-=tmp&-tmp);
	for (;ret&d;d<<=1);
	int res=0;
	for (int tmp=d;tmp;++res,tmp>>=1);
	ans=max(ans,res-1),ret=(ret^d)&((-1)^(d-1));
	return ret;
}

int main()
{
	//freopen("uninity.in","r",stdin),freopen("uninity.out","w",stdout);
	n=read();
	for (int i=1,x,y;i<n;++i) x=read(),y=read(),insert(x,y),insert(y,x);
	dfs(1),printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 5632
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-02 11:30:44
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  string s; cin >> s;
  int n = s.size();

  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl; return 0;
    }
  }

  for (int i = 0; i < n - 2; ++i) {
    if (s[i] == s[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl; return 0;
    }
  }

  cout << "-1 -1" << endl;

  return 0;
}

Measured memory_bytes: 512
fn main() {
    proconio::input! {
        n: i64,
    }
    let mut val = 100;
    let mut count = 0;
    loop {
        count += 1;
        val = ((val as f64) * 1.01) as i64;
        if val >= n { break };
    }
    println!("{}", count);
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int X;
	cin >> X;

	int result = 0;
	for( int i = 1; i <= X; ++i ) {
		if( i * (i+1) / 2 >= X ) {
			result = i;
			break;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int cnt=0;
  int dx[8]={0,1,1,1,0,-1,-1,-1};
  int dy[8]={-1,-1,0,1,1,1,0,-1};
  int h,w;
  cin>>h>>w;
  char maps[h+1][w+1];
  int d[h+1][w+1];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>maps[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(maps[i][j]=='.'){
        for(int k=0;k<8;k++){
          int ny=i+dy[k];
          int nx=j+dx[k];
          if(0<=nx&&nx<w&&0<=ny&&ny<h&&maps[ny][nx]=='#')cnt++;
        }
        maps[i][j]=(char)cnt+'0';
        cnt=0;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<maps[i][j];
    }
    cout<<endl;
  }
  return(0);
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
void debug(vector<T> &vec) {
    for (auto x : vec) {
        cout << x << " ";
    }
    cout << endl;
    return;
}

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

int main() {
    long double d;
    cin >> d;
    fcout << max<double>(sqrt(2) * d, (double)((int)d + 1)) << endl;
    return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return a;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int main() {
  int n; cin >>n;
  vector<int> p(n);
  rep(i, n) cin >>p.at(i);
  vector<int> vec(n); // vec[i]...p[0]~p[i]までの最小値を格納
  int tmp = p.at(0);
  rep(i, n){
    if (p.at(i) < tmp) tmp = p.at(i);
    vec.at(i) = tmp;
  }
  int ans = 0;
  rep(i, n){
    if (p.at(i) <= vec.at(i)) ans++;
  }

  cout <<ans <<endl;
}

Measured memory_bytes: 1792
import math

N = int(input())
s = [6 ** i for i in range (0,7)]
q = [9 ** j for j in range (0,6)]
m = {}

def f(x):
  if x <= 5:
    return x
  elif x in m:
    return m[x]
  else:
    m_s = max(i for i in s if i <= x)
    m_q = max(j for j in q if j <= x)
    ms = x - m_s
    mq = x - m_q
    m[x] = min(f(ms)+1,f(mq)+1)
    return m[x]
print(f(N))

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

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

#define Debug(x) cout<<(#x)<<" >> "<<(x)<<endl

using namespace std;

ll fastpow(ll angka,ll pangkat,ll MOD){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka)%MOD;
		angka=(angka*angka)%MOD;
		pangkat=pangkat>>1;
	}
	return res;
}

ll fastpow(ll angka,ll pangkat){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka);
		angka=(angka*angka);
		pangkat=pangkat>>1;
	}
	return res;
}

ll gcd(ll angka1,ll angka2){
	while(angka2){
		swap(angka1,angka2);
		angka2=angka2%angka1;
	}
	return angka1;
}

ll lcm(ll angka1,ll angka2){
	return (angka1/gcd(angka1,angka2))*angka2;
}

const ll mod=1000000007;

vector<int>spf;
void precompute_spf(){
	const int n=2000000;
	
	spf.resize(n);
	int batas=sqrt(n);
	for(int i=2;i<n;i++) spf[i]=i;
	for(int i=2;i<=batas;i++){
		if(spf[i]==i){
			int j=i*i;
			while(j<n){
				if(spf[j]==j) spf[j]=i;
				j+=i;
			}
		}
	}
	
//	for(int i=0;i<30;i++) cout<<i<<" "<<spf[i]<<endl;
	
}

void solve(){
	int n;
	cin>>n;
	
	vector<int>v(n);
	for(int i=0;i<n;i++) cin>>v[i];
	
	bool isPairWise=true;
	unordered_map<int,int>um;
	for(auto x:v){
		unordered_set<int>st;
		int val=x;
		while(val>1){
			st.insert(spf[val]);
			val=val/spf[val];
		}
		
		for(auto x:st){
			um[x]++;
			if(um[x]>1){
				isPairWise=false;
				break;
			}
		}
		
		if(!isPairWise) break;
	}
	
	
	if(isPairWise){
		cout<<"pairwise coprime"<<endl;
		return;
	}
	
	int cur=v[0];
	for(int i=0;i<n;i++){
		cur=gcd(cur,v[i]);
//		cout<<cur<<endl;
	}
	if(cur==1) cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;
	
}

int main(){
	
	fastio();
	
	precompute_spf();
	
	int t=1;
//	cin>>t;
	
	for(int tt=0;tt<t;tt++){
//		cout<<"Case "<<tt+1<<":\n";solve();
		solve();
	}
	
	return 0;
}

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

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

int main(){
  int n;
  cin >> n;

  long long a, b;

  cin >> a >> b;
  long long ans = gcd(a,b);
  for(int i=2; i<n; i++){
    cin >> a;
    ans = gcd(ans, a);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools

N , K = map(int, input().split())
A = [] * 100
d = [] * 100
count=0
for i in range(K):    
    d.append(int(input()))
    A.append(list(map(int , input().split())))
A = list(itertools.chain.from_iterable(A))

for k in range(1,N+1):
    if A.count(k) == 0:
        count+=1
print(count)

Measured memory_bytes: 9304
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"C0DEFESTIVAL2O16"# => r#"2"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        s: chars,
    }
    let cf = "CODEFESTIVAL2016".chars().collect::<Vec<char>>();
    let mut ans = 0;

    for i in 0..s.len() {
        if s[i] != cf[i] {
            ans += 1;
        }
    }

    ans.to_string()
}

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

int main(){
	int n,W;
	int v[100],w[100];
	int dp[101][10001] = {};
	cin >> n >> W;
	for(int i = 0;i < n;i++){
		cin >> v[i] >> w[i];
	}
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= W;j++){
			if(j - w[i - 1] < 0) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j],dp[i - 1][j - w[i - 1]] + v[i - 1]);
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len = s.length();
    if(s[len-1]=='s')
    {
        cout<<s<<"es"<<endl;
    }
    else
    {
        cout<<s<<"s"<<endl;
    }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
vector<int> v[1010];
int main()
{
	int n, m;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x;
		scanf("%d",&x);
		if(x == 0)
		{
			int y, z;
			scanf("%d%d",&y,&z);
			v[y].push_back(z);
		}
		else if(x == 1)
		{
			int i, y;
			scanf("%d",&y);
			if(v[y].size()) 
			{
				for(i=0; i<v[y].size() - 1; i++) printf("%d ",v[y][i]);
				printf("%d\n",v[y][v[y].size() - 1]);
			}
			else printf("\n");
		}
		else if(x == 2)
		{
			int y;
			scanf("%d",&y);
			v[y].clear();
		}
	}
	return 0;
}


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

using namespace std;
#define N 200010
#define ll long long
#define ld long double

struct line
{
    ll a=0,b;
}st[4000010+2];

ll vall(line u,ll x)
{
    if(u.a==0)return 1e18;
    return u.a*x+u.b;
}

ll h[N],dp[N],C;
int n;

void update(int id,int l,int r,line high)
{
    if(l>r)return;
    line low=st[id];
    if(vall(high,l)>vall(low,l))swap(high,low);
    if(l==r)
    {
        st[id]=high;
        return;
    }
    if(vall(high,r)<vall(low,r))
    {
        st[id]=high;
        return;
    }
    int mid=(l+r)/2;
    if (vall(high,mid)<vall(low,mid))
    {
        st[id]=high;
        update(id*2+1,mid+1,r,low);
    }else
    {
        st[id]=low;
        update(id*2,l,mid,high);
    }
}

ll query(int id,int l,int r,int x)
{
    //cout<<l<<" "<<r<<" "<<x<<" "<<endl;
    if(r<l||(r<x||l>x))return 1e18;
    if(l==r)return vall(st[id],x);
    int mid=(l+r)/2;
    if(x<=mid)return min(vall(st[id],x),query(id*2,l,mid,x));
        else return min(vall(st[id],x),query(id*2+1,mid+1,r,x));
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>n>>C;
    for(int i=1;i<=n;i++)cin>>h[i];
    dp[1]=0;
    update(1,1,1e6,{-2*h[1],dp[1]+h[1]*h[1]});
    //cout<<"CC\n";
    for(int i=2;i<=n;i++)
    {
        ll u=query(1,1,1e6,h[i]);
        dp[i]=u+h[i]*h[i]+C;
        update(1,1,1e6,{-2*h[i],dp[i]+h[i]*h[i]});
    }
    cout<<dp[n];
    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[100000], s[2];
vector<LL> v[2];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	sort(a, a + n);
	
	inc(k, 2) {
		inc(i, n / 2 - 1) { v[k].PB(-2); }
		inc(i, n / 2 - 1) { v[k].PB(+2); }
		if(n % 2 == 0) {
			v[k].PB(-1);
			v[k].PB(+1);
		} else {
			if(k == 0) {
				v[k].PB(-1);
				v[k].PB(-1);
				v[k].PB(+2);
			} else {
				v[k].PB(-2);
				v[k].PB(+1);
				v[k].PB(+1);
			}
		}
		assert(v[k].size() == n);
		
		sort(ALL(v[k]));
	}
	
	inc(k, 2) {
	inc(i, n) {
		s[k] += a[i] * v[k][i];
	}
	}
	
	cout << max(s[0], s[1]) << endl;
	
	return 0;
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 075_arc_b / Link: https://abc063.contest.atcoder.jp/tasks/arc075_b?lang=en  ----- */
/* ------問題------

あなたが散歩していると、突然 N 体の魔物が出現しました。それぞれの魔物は 体力 という値を持ち、i 体目の魔物の出現時の体力は hi です。体力が 0 以下となった魔物は直ちに消滅します。
幸い、あなたは熟練の魔法使いであり、爆発を引き起こして魔物を攻撃できます。一回の爆発では、以下のように魔物の体力を減らすことができます。
生存している魔物を一体選び、その魔物を中心に爆発を引き起こす。爆発の中心となる魔物の体力は A 減り、その他の魔物の体力はそれぞれ B 減る。ここで、A と B はあらかじめ定まった値であり、A>B である。
すべての魔物を消し去るためには、最小で何回の爆発を引き起こす必要があるでしょうか？

-----問題ここまで----- */
/* -----解説等-----

A>Bなので攻撃回数xがわかればB*xのダメージを与えることができる。
のこったHPは削らないと行けないので中心として選択することでA-Bだけ減らすことができる。
回数が大きいほど倒しやすく、これには単調性があるので解について二分探索できる。
解空間は(L,R].

----解説ここまで---- */

LL N,A,B;

LL ans = 0LL;


bool f(LL x, VL &h) {// x回で倒せるか
	LL cnt = 0;
	FOR(i, 0, N) {
		LL lefth = h[i] - x*B;
		LL atk = (lefth+A-B-1)/(A-B);
		if(lefth>0)cnt += atk;
	}
	return cnt <= x;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N>>A>>B;
	VL h(N);
	FOR(i, 0, N) {
		cin >> h[i];
	}
	RSORT(h);

	LL L = 0; LL R = INF;
	FOR(i, 0, 50) {
		LL mid = (L + R) / 2;
		if (f(mid, h)) {
			R = mid;
		}
		else L = mid;
	}
	cout << R << endl;

	return 0;
}


Measured memory_bytes: 1024
from time import time
start=time()
from copy import deepcopy
from random import randint

d=int(input())
c=list(map(int,input().split())) #scoreを減らす
s=[] #scoreを増やす
for i in range(d):
    t=list(map(int,input().split()))
    s.append(t)
last=[0]*26 #それぞれのコンテストが最後に行われたのは何日目か
ans_lst=[]

for i in range(1,d): #364日、1日目ならi=1
    temp_best=-100000000
    for j in range(26): #それぞれの日において、26個のコンテストを順番にピックアップ
        temp=s[i-1][j]
        for k in range(26): #ピックアップされていないコンテストは、スコアを減らす
            if j!=k:
                temp-=(c[k]*(i-last[k]))
        temp_last=deepcopy(last)
        temp_last[j]=i
        for k in range(26):
            temp+=s[i][k]
            for l in range(26):
                if k!=l:
                    temp-=(c[l]*(i+1-temp_last[l]))
        if temp>temp_best:
            temp_best=temp
            rem=j
    ans_lst.append(rem)
    last[rem]=i
    
temp_best=-100000000 #365日目は、次の日のことは考えなくてよい
for j in range(26): #26個のコンテストを順番にピックアップ
    temp=s[i-1][j]
    for k in range(26): #ピックアップされていないコンテストは、スコアを減らす
        if j!=k:
            temp-=(c[k]*(i-last[k]))
    if temp>temp_best:
        temp_best=temp
        rem=j
ans_lst.append(rem) #AtCoder運営お疲れ様です

score=0
las=[0]*26
for i in range(d):
    for j in range(26):
        las[j]+=1
    score+=s[i][ans_lst[i]]
    las[ans_lst[i]]=0
    for j in range(26):
        score-=c[j]*las[j]

for q in range(1,10):
    for p in range(d-q):
        las=[0]*26
        temp_score=0
        temp_ans_lst=deepcopy(ans_lst)
        temp_ans_lst[p],temp_ans_lst[p+q]=temp_ans_lst[p+q],temp_ans_lst[p]
        for i in range(d):
            for j in range(26):
                las[j]+=1
            temp_score+=s[i][temp_ans_lst[i]]
            las[temp_ans_lst[i]]=0
            for j in range(26):
                temp_score-=c[j]*las[j]
        if temp_score>score:
            score=temp_score
            ans_lst=temp_ans_lst

while time()-start<1.9:
    las=[0]*26
    temp_score=0
    temp_ans_lst=deepcopy(ans_lst)
    a=randint(0,d-2)
    b=randint(0,d-2)
    temp_ans_lst[a],temp_ans_lst[a+1]=temp_ans_lst[a+1],temp_ans_lst[a]
    temp_ans_lst[b],temp_ans_lst[b+1]=temp_ans_lst[b+1],temp_ans_lst[b]
    for i in range(d):
        for j in range(26):
            las[j]+=1
        temp_score+=s[i][temp_ans_lst[i]]
        las[temp_ans_lst[i]]=0
        for j in range(26):
            temp_score-=c[j]*las[j]
    if temp_score>score:
        score=temp_score
        ans_lst=temp_ans_lst

for i in ans_lst:
    print(i+1)

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = min(a, b); i > 0; i--)
    {
        if (a % i == 0 && b % i == 0)
        {
            k--;
            if (k == 0)
            {
                cout << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from decimal import Decimal, getcontext
getcontext().prec = 1000
A, B, C = map(Decimal, readline().split())
half = Decimal(0.5)
EPS = Decimal(1e-100)
print('Yes' if A**half + B**half + EPS< C**half else 'No')

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

namespace ABC098A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,c,d,e,f;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = a + b;

            if (c < a - b)
                c = a - b;

            if (c < a * b)

                c = a * b;
                
            Console.WriteLine(c);

            Console.ReadKey();

            
        }
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        long n = sc.nextLong();

        Stack<Character> stack = new Stack<>();
        while (n > 26) {
            int t = (int)(n % 26);
            if (t == 0) {
                t = 26;
                n -= 26;
            }

            char c = (char)('a' + t - 1);
            //System.out.println(c);
            stack.push(c);
            //n -= 26;
            n /= 26;
        }
        //System.out.println((char)('a' + n - 1));
        stack.push((char)('a' + n - 1));

        PrintWriter pw = new PrintWriter(System.out);
        while (!stack.empty()) {
            pw.print(stack.pop());
        }

        pw.println();
        pw.flush();
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32984