akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  int ret = 0;
  if(A >= B){
    ret = ret + A;
    A = A - 1;
  }
  else{
    ret = ret + B;
    B = B - 1;
  }

  if(A >= B){
    ret = ret + A;
    A = A - 1;
  }
  else{
    ret = ret + B;
    B = B - 1;
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iterator>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include<functional>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <numeric>
//#include<unordered_map>
#define inf  2e9
#define seed 131
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define lrtnb srand(unsigned(time(NULL)))
#define lrtlh ios::sync_with_stdio(0)
#define lowb(a,n,x) lower_bound(a,a+n,x) - a
#define uppb(a,n,x) upper_bound(a,a+n,x) - a
#define lson l,mid,i<<1;
#define rson mid+1,r,i<<1|1;
#define ALL(x) x.begin(),x.end()
#define inv inline void
#define INS(x) inserter(x,x.begin())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> Si;
typedef set<ll> Sl;
ll gcd(ll n, ll m) { long long r; if (n < m)swap(n, m); while (m) { r = n % m; n = m; m = r; }return n; }
ll lcm(ll b, ll y) { return b * y / gcd(b, y); }
double dis(double x1, double y1, double x2, double y2) { double ans = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); return sqrt(ans); }
double random(double start, double en) { return start + (en - start)*rand() / (RAND_MAX + 1.0); }
void read(int &n) { char c = '+'; int x = 0; bool flag = 0; while (c<'0' || c>'9') { c = getchar(); if (c == '-')flag = 1; }while (c >= '0'&&c <= '9')x = x * 10 + c - 48, c = getchar(); n = flag == 1 ? -x : x; }
string a[110];
int main() {
	int n, l;
	cin >> n >> l;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++)
		cout << a[i];
	cout << endl;
}

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

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

    int ans = 1000000000;
    for (int i = 0; i < n - k + 1; i++) {
        if (abs(x[i]) >= abs(x[i + k - 1])) {
            ans = min(ans, abs(x[i + k - 1]) + abs(x[i] - x[i + k - 1]));
        } else {
            ans = min(ans, abs(x[i]) + abs(x[i] - x[i + k - 1]));
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main () {
    
    for (int i = 0;; i++) {
        int x, y;
        cin >> x >> y;

        if (x == 0 && y == 0) break;

        if (x > y) cout << y << " " << x << endl;
        else cout << x << " " << y << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 998244353;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const ll MAX = 200000;
ll inv[MAX], fac[MAX], finv[MAX];
 


ll dp[3100][3100] = {0};
vector<int> a;
int n, s;

int main(){
    cin >> n >> s;
    a.resize(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    dp[0][0] = 1;
    for(int i = 0; i < n; i++) {
        for(int j = s; j >= 0; j--) {
            dp[i+1][j] += dp[i][j]*2;
            if(j-a[i]>=0) dp[i+1][j] += dp[i][j-a[i]];
            dp[i+1][j]%=MOD;
        }
    }
    ll ans = dp[n][s];
    cout << ans << endl;
}

Measured memory_bytes: 76312
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
    int q,i,a,b,j,s1;
    char str[1000],t[7],rep[1000],p[1000];
    scanf("%s",str);
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%s",t);
        if(strcmp(t,"print")==0){
            scanf("%d %d",&a,&b);
            for(j=a;j<=b;j++){
                printf("%c",str[j]);
                if(j==b){
                    printf("\n");
                }
            }
        }
        strcpy(rep,str);
        if (strcmp(t,"reverse")==0){
            scanf("%d %d",&a,&b);
            s1=b-a+1;
            for(j=0;j<s1;j++){
                str[a+j]=rep[b-j];
            }
        }
        if(strcmp(t,"replace")==0){
            scanf("%d %d %s",&a,&b,p);
            for(j=0;j<b-a+1;j++){
                str[a+j] = p[j];
            }
        }
    }
    return 0;
}

Measured memory_bytes: 588
N=int(input())
A=list(map(int,input().split()))
from collections import defaultdict
cnt=defaultdict(int)
for a in A:
    cnt[a]+=1

twice=0
ans=0
for i,j in cnt.items():
    if j>=2:
        ans+=(j-1)//2
        twice+=(j-1)%2
ans+=(twice+1)//2
print(N-2*ans)

Measured memory_bytes: 17652
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]

is_cont = False
cnt = 0
for d in D:
    d1, d2 = d
    if d1 == d2:
        is_cont = True
        if is_cont:
            cnt += 1
            if cnt >= 3:
                print("Yes")
                exit()
        else:
            cnt = 1
    else:
        is_cont = False
        cnt = 0
print("No")


Measured memory_bytes: 67200
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int N;
    cin >> N;
    vector<int> v(N), origin(N);
    REP(i, 0, N) {
        cin >> v[i];
        origin[i] = v[i];
    }
    sort(begin(v), end(v));
    REP(i, 0, N) {
        int ind = lower_bound(begin(v), end(v), origin[i]) - begin(v);
        if (ind < N / 2) {
            cout << v[N / 2] << endl;
        } else {
            cout << v[N / 2 - 1] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3712
# https://atcoder.jp/contests/abc097/tasks/abc097_b
x = int(input())
m = int(x ** 0.5)
r = [1]
for i in range(2, m + 1):
    c = 2
    while x >= i ** c:
        r.append(i ** c)
        c += 1
print(sorted(r)[-1])


Measured memory_bytes: 2940
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI A(N);
	int ans = 0, cnt = 0;
	REP(i, N) {
		int a;
		cin >> a;
		if (a < 0)cnt++;
		ans += abs(a);
		A[i] = abs(a);
		//cout << ans << endl;
	}
	SORT(A);
	//cout << ans << " " << A[0] << endl;
	if (cnt % 2 == 0) {
		cout << ans << endl;
	}
	else {
		cout << ans - 2 * A[0] << endl;
	}
	return 0;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> cost;
    cost.push_back(1);
    ll buf = 9;
    while (buf <= 100000) {
        cost.push_back(buf);
        buf *= 9;
    }
    buf = 6;
    while (buf <= 100000) {
        cost.push_back(buf);
        buf *= 6;
    }
    sort(cost.begin(), cost.end());
    vector<int> dp(n+1);
    for (int i=1; i<n+1; i++) {
        int buf = 10000001;
        for (int j=0; j<cost.size(); j++) {
            if (i >= cost.at(j)) {
                buf = min(buf, dp.at(i-cost.at(j)) + 1); 
            }
            else break;
        }
        dp.at(i) = buf;
    }
    cout << dp.at(n) << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#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; }
//(a+b-1)/b

#define len (1<<18)
vi seg(len*2,0);

int get(int ind){
	ind+=len;
	int ans=0;
	while(true){
		if(ind==0)break;
		ans+=seg[ind];
		ind/=2;
	}
	return ans;
}

void add(int l,int r,int x){
	l+=len; r+=len;
	while(l<r){
		if(l%2==1){
			seg[l]+=x;
			l++;
		}
		l/=2;
		if(r%2==1){
			seg[r-1]+=x;
			--r;
		}
		r/=2;
	}
}

signed main(){
	int n,q; cin>>n>>q;
	vi ans(0);
	rep(i,0,q){
		int com; cin>>com;
		if(com==0){
			int l,r,x; cin>>l>>r>>x;
			add(l,r+1,x);
		}
		if(com==1){
			int ind; cin>>ind;
			ans.push_back(get(ind));
		}
	}
	rep(i,0,ans.size())cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 5492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

const int INF = 1e9;

int main() {
    int n;
    while (cin >> n && n) {
        vector<int> ct(n), ch;
        for (int i = 1; i <= 2 * n; i++) ch.push_back(i);
        for (int i = 0, c; i < n; i++) {
            cin >> c;
            ct.push_back(c);
            int idx = lower_bound(ch.begin(), ch.end(), c) - ch.begin();
            ch[idx] = INF;
            sort(ch.begin(), ch.end());
        }
        int top = 0, taro = n, hanako = n;
        bool taro_win = false;
        while (1) {
            sort(ct.begin(), ct.end());
            sort(ch.begin(), ch.end());
            auto itr = upper_bound(ct.begin(), ct.end(), top);
            if (itr != ct.end()) {
                int idx = itr - ct.begin();
                if (ct[idx] != INF) {
                    top = ct[idx];
                    ct[idx] = INF;
                    taro--;
                    if (taro == 0) {
                        taro_win = true;
                        break;
                    }
                } else top = 0;
            } else top = 0;
            auto itr2 = upper_bound(ch.begin(), ch.end(), top);
            if (itr2 != ch.end()) {
                int idx2 = itr2 - ch.begin();
                if (ch[idx2] != INF) {
                    top = ch[idx2];
                    ch[idx2] = INF;
                    hanako--;
                    if (hanako == 0) break;
                } else top = 0;
            } else top = 0;
        }
        if (taro_win) cout << hanako << '\n' << 0 << endl;
        else cout << 0 << '\n' << taro << endl;
    }
}


Measured memory_bytes: 3152
#include<cstdio>

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

Measured memory_bytes: 1028
i,c,a[2000];
main(n,m){
	for(;scanf("%d%d",&n,&m),n;i=0){
		for(;n+m-i;scanf("%d",a+i++));
		for(i=c=0;c<n-1&(c+=a[c])<n-1;c+=a[n+i++]);
		printf("%d\n",i);
	}
	exit(0);
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> v(n), vm(n), vp(n), vc(3*n);

    rep(i, n){
        cin >> v[i];
        vm[i] = v[i] - 1;
        vp[i] = v[i] + 1;
    }
    rep(i, n){
        vc[i] = v[i];
        vc[n+i] = vm[i];
        vc[2*n+i] = vp[i];
    }

    sort(all(vc));
    vc.push_back(INF);

    ll cnt = 1;
    ll ans = -INF;
    rep(i, 3*n){
        if(vc[i] == vc[i+1]){
            cnt++;
        }else{
            ans = max(ans, cnt);
            cnt=1;
        }
    }

    cout << ans;
}

Measured memory_bytes: 9088
import heapq

N, M = map(int, input().split())
priceList = [(-1)*int(i) for i in input().split()]
heapq.heapify(priceList)

while M > 0:
    maxPrice = -heapq.heappop(priceList)
    maxPrice = maxPrice // 2
    M -= 1
    heapq.heappush(priceList, -maxPrice)

sum = 0
for i in range(N):
    sum += priceList[i]

print(-sum)

Measured memory_bytes: 72216
A,B = map(int,input().split())

if A>B:
    getcoin=A
    A=A-1
elif A ==B:
    getcoin=A
    A=A-1
else:
    getcoin=B
    B=B-1

    
if A>B:
    getcoin+=A
elif A==B:
    getcoin+=A
else:
    getcoin+=B

print(getcoin)


    


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

struct UnionFind{
	int *par;

	UnionFind(int N){
		par = (int *)malloc(N*sizeof(int));
		rep(i,N)par[i]=i;
	}

	int root(int x){
		if(par[x] == x)return x;
		return par[x] =  root(par[x]);
	}

	void unite(int x, int y){
		int rx = root(x);
		int ry = root(y);
		if(rx == ry)return;
		if(rx < ry)par[ry]=rx;
		else par[rx] = ry;
	}

	bool same(int x, int y){
		return root(x) == root(y);
	}
};

int main(void){
	int N;
	cin>>N;

	bool flag=true,flag2=true;

	ll ans=0;
	ll min;
	cin>>min;
	if(min == 0){
		flag=true;
		flag2=false;
	}
	if(min<-1 && flag2)flag=!flag;
	min = abs(min);
	rep(i,N-1){
		ll tmp;
		cin>>tmp;
		if(tmp == 0){
			flag=true;
			flag2=false;
		}
		if(tmp<-1 && flag2)flag=!flag;
		if(abs(tmp) < min){
			ans+=min;
			min = abs(tmp);
		}
		else ans+=abs(tmp);
	}
	if(flag)ans+=min;
	else ans-=min;

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int count;
	int a,b,c,d;
	
	while(scanf("%d",&n) != EOF)
	{
		count = 0;
		
		for(a=0;a<10;a++)
		{
			for(b=0;b<10;b++)
			{
				for(c=0;c<10;c++)
				{
					for(d=0;d<10;d++)
					{
						if(a+b+c+d == n)
						{
							count++;
						}
					}
				}
			}
		}
		printf("%d\n",count);
	}
	
	return 0;
}


Measured memory_bytes: 1912
n = int(input())

if n>=64:
    print(64)
elif 32<=n<64:
    print(32)
elif 16<=n<32:
    print(16)
elif 8<=n<16:
    print(8)
elif 4<=n<8:
    print(4)
elif 2<=n<4:
    print(2)
else:
    print(1)

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

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

  int a = N / 1000;
  N = N - a * 1000;
  int b = N / 100;
  N = N - b * 100;
  int c = N / 10;
  int d = N % 10;

  if ((a == b && b == c) || (b == c && c == d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

int getHammingDistance(string S, string T, int i) {
    int ans = 0;
    S = S.substr(i, T.size());
    for  (int i = 0; i < T.size(); i++) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    return ans;
}

int main() {
    string S, T; cin >> S >> T;
    int ans = 1001;
    for (int i = 0; i <= S.size() - T.size(); i++) {
        ans = min(ans, getHammingDistance(S, T, i));
    }
    cout << ans << endl;
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    for(int i=1;i<s.size();i++){
        if(1<i && s[i-2]==s[i]){
            cout << i-1 << " " << i+1 << endl;
            return 0;
        }

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

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

Measured memory_bytes: 512
//
//  main.cpp
//  hitachi2020B
//
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
    int ans;
    int d_price=200001;
    int d_x,d_y,d_c;
    int A,B,M;
    int r_min=100007;
    int m_min=100007;
    cin >>A>>B>>M;
    vector<int>r(A);
    vector<int>m(B);
    for (int i=0; i<A; i++) {
        cin >> r[i];
        r_min=min(r_min,r[i]);
    }
    for (int j=0; j<B; j++) {
        cin >> m[j];
        m_min=min(m_min,m[j]);
    }
    ans=r_min+m_min;
    for (int k=0; k<M; k++) {
        cin >> d_x>>d_y>>d_c;
        d_price=r[d_x-1]+m[d_y-1]-d_c;
        ans=min(ans,d_price);
    }
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
	
	while(1){
		int n;
		int p1,p2;
		scanf("%d",&n);
		if(n==0){
			break;
		}
		p1=p2=0;
		for(int i=0;i<n;i++){
			int a,b;
			scanf("%d%d",&a,&b);
			if(a>b){
				p1+=a+b;
			}else if(a<b){
				p2+=a+b;
			}else{
				p1+=a;
				p2+=b;
			}
		}
		printf("%d %d\n",p1,p2);
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

int main() {
    int n, m, w;
    cin >> n;
    vector<int> s(n), l(n), p(n);
    for (int i = 0; i < n; i++) cin >> s.at(i) >> l.at(i) >> p.at(i);
    vector<vector<int>> dp(n + 1, vector<int>(394));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 394; j++) {
            int d = dp.at(i).at(j);
            for (int k = s.at(i); k <= l.at(i); k++) {
                if (j < k) break;
                d = max(d, dp.at(i + 1).at(j - k) + p.at(i));
            }
            dp.at(i + 1).at(j) = d;
        }
    }
    cin >> m;
    vector<int> ans(m);
    for (int i = 0; i < m; i++) {
        cin >> w;
        ans.at(i) = dp.at(n).at(w);
        if (ans.at(i) == 0) ans.at(0) = 0;
    }
    for (int i = 0; i < m; i++) {
        if (ans.at(i) == 0) {
            cout << -1 << endl;
            break;
        }
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 3424
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int N;
    cin >> N;

    double ans = 0;
    REP(i, N) {
        double x;
        string s;
        cin >> x >> s;

        if (s == "JPY") ans += x;
        else ans += x * double(380000);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,m;
vl a;

int main(){
	cin>>n>>m;
	a=vl(n);
	vl b(m+1);
	for(int i=0;i<n;i++) cin>>a[i];
	vpll c;
	vl d;
	for(int i=1;i<n;i++){
		ll A=a[i-1],B=a[i];
		if(A<B){
			ll tmp=B-A;
			b[0]+=tmp;
			b[A]-=tmp;
			b[B]+=tmp;
			b[m]-=tmp;
			c.push_back({A,tmp});
			d.push_back(B);
		}
		else{
			ll tmp=m-A+B;
			b[B]+=tmp;
			b[A]-=tmp;
			c.push_back({0,tmp-m+A});
			c.push_back({A,tmp});
			d.push_back(B);
			d.push_back(m);
		}
	}
	for(int i=1;i<=m;i++) b[i]+=b[i-1];
	sort(c.begin(),c.end());
	sort(d.begin(),d.end());
	int IC=0,ID=0,C=c.size(),D=d.size();
	ll num=0,sum=0;
	for(int i=0;i<m;i++){
		while(IC<C&&c[IC].first==i){
			sum+=c[IC].second;
			num++;
			IC++;
		}
		while(ID<D&&d[ID]==i){
			num--;
			ID++;
		}
		b[i]+=sum;
		sum-=num;
	}
	ll res=INF;
	for(int i=0;i<m;i++) res=min(res,b[i]);
	cout<<res<<endl;
}

Measured memory_bytes: 8556
def main(N, A, B):
    if abs(A - B) % 2 == 0:
        return abs(A - B) // 2
    A, B = min(A, B), max(A, B)
    res1 = A+(B-A-1)//2

    A, B = N - B + 1, N - A + 1
    res2 = A+(B-A-1)//2
    return min(res1, res2)


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    ans = main(N, A, B)
    print(ans)


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

long long int maxm[3001][3001];

long long int recursivedp(long long int arr[],long long int i,long long int j,long long int sum)
{
    
    if((i+1)==j)
        return max(arr[i],arr[j]);
    else if (maxm[i][j]!=-1)
        return maxm[i][j];
    else
    {
        maxm[i][j]=max(sum-recursivedp(arr,i+1,j,sum-arr[i]),sum-recursivedp(arr,i,j-1,sum-arr[j]));
    }
    return maxm[i][j];
        
}

int main()
{
    long long int t,n,k,ans,i,j,sum,a[3001],ans2;
    
    for(i=0;i<3001;i++)
    {
        for(j=0;j<3001;j++)
        {
            maxm[i][j]=-1;
        }
    }
    cin>>n;
    sum=0;
    for(i=0;i<n;i++)
        {cin>>a[i];
        sum+=a[i];}
    if (n==1)
        cout<<a[0]<<endl;
    else{
    ans=recursivedp(a,0,n-1,sum);
    ans2=sum-ans;
    
    cout<<ans-ans2<<endl;
    }
    
    
}

Measured memory_bytes: 71040
import math
X = int(input())
max_num = 1

for i in range(2, int(math.sqrt(X))+1) :
    for j in range(2, int(math.log2(X))+1) :
        if (i**j <= X):
            max_num = max(max_num, i**j)
        else:
            break
print(max_num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int n,m;
int a[100100],b[100100];
int alr[100100];
int ans[400100];
int st,en;
vector<int> edge[100100];
int check(int t){
	for(int i=0;i<edge[t].size();i++){
		if(!alr[edge[t][i]]){
			return edge[t][i];
		}
	}
	return -1;
}
int main(){
	REP(i,400100)ans[i]=-1;
	cin>>n>>m;
	REP(i,m){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
		edge[a[i]].push_back(b[i]);
		edge[b[i]].push_back(a[i]);
	}
	st=200000,en=200001;
	ans[st]=a[0];
	ans[en]=b[0];
	alr[a[0]]=1;
	alr[b[0]]=1;
	while(1){
		int t1=check(ans[st]);
		if(t1!=-1){
			st--;
			ans[st]=t1;
			alr[t1]=1;
		}
		int t2=check(ans[en]);
		if(t2!=-1){
			en++;
			ans[en]=t2;
			alr[t2]=1;
		}
		if(check(ans[st])==-1&&check(ans[en])==-1)break;
	}
	cout<<en-st+1<<endl;
	for(int i=st;i<=en;i++){
		cout<<ans[i]+1<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 9088
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
#define deg_to_rad(deg)			(((deg)/180)*M_PI)
#define rad_to_deg(rad)			((rad*180)/M_PI)
#define prique(T)				priority_queue<T, vector<T>, greater<T>>

typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<int, int> P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
#define N_MAX	(200 * 1000)
#define K_MAX	(10)
#define M_MAX	(10)
#define H_MAX	(1000)
#define W_MAX	(1000)

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

	int ans = 0;
	REPN(i, 1, N + 1) {
		int keta = 0;
		int val = i;
		while (0 < val) {
			val /= 10;
			keta++;
		}
		if (IsOdd(keta)) {
			ans++;
		}
	}
	cout << ans;
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
object Main extends App{
  val n = readInt
  val p = readLine.split(" ").toList.map(_.toInt)
  val q = readLine.split(" ").toList.map(_.toInt)
  val l = (1 to n).toList.permutations.toList
  println( (l.indexOf(p)-l.indexOf(q)).abs )
}

Measured memory_bytes: 40704
import sys

f_i = sys.stdin

n = int(f_i.readline())

adj = [[]] * n
for x in f_i:
    x = list(map(int, x.split()))
    adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]

import heapq

def dijkstra():
    PQ = [(0, 0)]
    isVisited = [False] * n
    distance = [999900001] * n

    distance[0] = 0
    
    while PQ:
        uc = heapq.heappop(PQ)
        u = uc[1]

        if uc[0] > distance[u]:
            continue

        isVisited[u] = True
        
        for vc in adj[u]:
            v = vc[1]
            if isVisited[v] == True:
                continue
            t_cost = distance[u] + vc[0]
            if t_cost < distance[v]:
                distance[v] = t_cost
                heapq.heappush(PQ, (t_cost, v))

    for v, d in enumerate(distance):
        print(v, d)


dijkstra()

Measured memory_bytes: 70488
#include <stdio.h>
int main(void){
    int a = 0, i, x;
    scanf("%d", &x);
    
    for( i = 1; i < 2000; i++ ){
        a += x;
        if( a % 360 == 0 ){
            printf("%d\n", i);
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1684
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= putStrLn . which "Yes" "No" . ( == "abc" ) . sort

Measured memory_bytes: 380
#include <iostream>
#include <vector>

using namespace std;

int N;
vector<vector<int>> t;
vector<bool> used;
int eval(int root) {
	int ret = 0;
	for (int i = 0; i < t[root].size(); i++) {
		int node = t[root][i];
		if (!used[root] && t[node].size() == 0) {
			used[root] = used[node] = true;
			ret++;
		} else ret += eval(node);
		if (!used[root] && !used[node]) {
			used[root] = used[node] = true;
			ret++;
		}
	}
	return ret;
}
int main(void) {
	cin >> N;
	t = vector<vector<int>>(N+1, vector<int>(0));
	for (int i = 1; i <= N; i++) {
		int pi;
		cin >> pi;
		used = vector<bool>(N+1, false);
		t[pi].push_back(i);
		cout << eval(0) << endl;
	}
}

Measured memory_bytes: 3252
N,K = map(int,input().split())
import math
ans = 0.
for c in range(1,N+1):
    if c >= K:
        req = 0
    else:
        req = math.log2(K/c)
        if req != int(req):
            req = int(req) + 1
        else:
            req = int(req)
    ans += (1/N)*((1/2)**req)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#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 ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    int sum = 0;
    REP(i, n) cin >> a.at(i);
    REP(i, n) cin >> b.at(i);
    REP(i, n-1) cin >> c.at(i);
    REP(i, n-1){
        sum += b.at(a.at(i) - 1);
        if(a.at(i+1) - a.at(i) == 1) sum += c.at(a.at(i)-1);
    }
    sum += b.at(a.at(n-1)-1);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
t=0
s=10
for i in range(5):
    k=int(input())
    if k%10==0:
        t+=k
    else:
        t+=((k//10)+1)*10
        if k%10<s:
            s=k%10

if s!=10:
    print(t-10+s)
else:
    print(t)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,x;
    cin>>n>>m>>x;
    map<int,int>mp;
    for(int i=0;i<m;i++){
        int a;cin>>a;
        mp[a]++;
    }
    ll ans=INF;
    ll sum=0;
    for(int i=x;i<=n;i++){
        sum+=mp[i];
    }
    chmin(ans,sum);
    sum=0;
    for(int i=x;i>0;i--){
        sum+=mp[i];
    }
    chmin(ans,sum);
    cout<<ans<<endl;


}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long length[] = {sc.nextInt(), sc.nextInt()};
		String st[] = {sc.next(), sc.next()};
		long gcd = gcd(length[0], length[1]);
		boolean ok = true;
		for(int i = 0; i < gcd; i ++) {
			if(st[0].charAt((int)(length[0] / gcd * i)) != st[1].charAt((int)(length[1] / gcd * i))) {
				ok = false;
				break;
			}
		}
		System.out.println(ok ? length[0] * length[1] / gcd : -1);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}

Measured memory_bytes: 27860
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    vector<int> last(26, -1);
    auto calc = [&](int day, int type) {
        int ret = 0;
        ret += s[day][type];
        rep(i, 26) if (i != type) ret -= c[i] * (day - last[i]);
        return ret;
    };
    int score = 0;
    vector<int> t(d);
    rep(i, d) {
        int MAX = -INF;
        rep(j, 26) if (chmax(MAX, calc(i, j))) t[i] = j;
        last[t[i]] = i;
        score += MAX;
    }
    rep(i, d) cout << t[i] + 1 << '\n';
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define  int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int32_t main()
{
    IOS;
    int m1,m2,d1,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1==m2)
    {
        if(d2==(d1+1))
        {
            cout<<0<<endl;
        }
        else
            cout<<0<<endl;
        
    }
    else
    {
        cout<<1<<endl;
    }
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

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

using namespace std;
using pii=pair<int,char>;


int num[27];

int main(void){
	int n;
	string s;
	cin >> n >> s;


	rep(i,n){
		if(i%2==1) continue;
		int idx=s[i]-'a';
		num[idx]++;
	}
	sort(num,num+26);

	int ci=0,cj=0;
	while(num[ci]==0) ci++,cj++;

	int ans=0;
	bool init=true;

	while(ci<26){
		while(num[ci]==num[cj]) cj++;

		if(init) 
			init=false;
		else
			ans++;

		int num2=cj-ci;
		if(num[ci]>=2){
			ans+=2;
			if(num2>=2) ans+=2;
		}
		ans+=2*num2-1;

		ci=cj;
	}
	cout << ans << endl;
	return 0;
}

// 3*a+4*b+5*c

// 3*a+3*b 7
// 3*(a+b) 7
// 3*a+3*b+3*c 11 
// 3*(a+b+c) 
// 3*a+4*b+4*c
// 3*(a+b+c)+b+c

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define ll long long

using namespace std;

struct pair_hash {
    template <class T1, class T2>
    size_t operator () (const pair<T1,T2> &p) const {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);

        return h1 ^ h2;
    }
};

string s;

unordered_map< pair<string, string>, ll, pair_hash > m;

int main() {
   // freopen("a.in", "r", stdin);
 //  freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n >> s;
    for(int i = 0; i < (1 << n); i ++) {
        string a, b;
        for(int j = n; j < 2 * n; j ++) {
            if(i & (1 << (j - n)))
                a.push_back(s[j]);
            else
                b.push_back(s[j]);
        }
        reverse(b.begin(), b.end());  /// ramane ne vazut
        m[{a, b}] ++;
    }
    ll sol = 0;
    for(int i = 0; i < (1 << n); i ++) {
        string a, b;
        for(int j = 0; j < n; j ++) {
            if(i & (1 << j))
                a.push_back(s[j]);
            else
                b.push_back(s[j]);
        }
        reverse(b.begin(), b.end());
        sol += m[{b, a}];
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 90612
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {

	string s, t;
	char a[100], b[100];
	cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.rbegin(), t.rend());

	if (s < t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll res = - INF;
    chmax(res, a*c);
    chmax(res, a*d);
    chmax(res, b*c);
    chmax(res, b*d);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){
    int a, b, ans; cin >> a >> b;
    if(a > b) ans = 2 * a - 1;
    else if(a < b) ans = 2 * b - 1;
    else ans = 2 * a;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	int ans=N;
	
	for(int i=0;i<=N;i++){
		int count=0;
		int tmp=i;
		
		while(tmp>0){
			count+=tmp%6;
			tmp/=6;
		}
		
		tmp=N-i;
		
		while(tmp>0){
			count+=tmp%9;
			tmp/=9;
		}
		
		if(count<ans)ans=count;
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# 左端点から右端点に行くパターン
# 右端点から左端点に行くパターン
# 求めるのはDの最大値
# 差のgcdとか？

N, X =  map(int, sys.stdin.readline().split())
L =  list(map(int, sys.stdin.readline().split()))
L.append(X)
L = sorted(L)
D = [x2 - x1 for x1, x2 in zip(L , L[1::])]
print(reduce(gcd, D))

Measured memory_bytes: 86292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n,k;cin>>n>>k;
  vector<int> l(n);
  rep(i,n)cin>>l[i];
  sort(all(l));
  reverse(all(l));
  int cnt=0;
  rep(i,k){
    cnt+=l[i];
  }
  cout<<cnt<<endl;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

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

int main()
{
	int n;
	cin >> n;
	cout << "ai1";
	REP(i,(n/100)+3)cout << 3;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3084
tile = gets.chomp.chars.map(&:to_i)
cnt0 = 0
cnt1 = 0

tile.size.times do |i|
  if tile[i] == 0
    if i % 2 == 0
      cnt1 += 1
    else
      cnt0 += 1
    end
  else #tile[i] == 1
    if i % 2 == 0
      cnt0 += 1
    else
      cnt1 += 1
    end
  end
end

puts [cnt0, cnt1].min


Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

string s;
int k;
int n;
ll dp[2][110][50];
int main(){
    cin>>s;
    n=s.size();
    cin>>k;
    dp[0][0][0]=1;
    REP(id,2){
        REP(i,n){
            REP(j,4){
                ll lim=s[i]-'0';
                if(id)lim=9;
                for(ll x=0;x<=lim;x++){
                    dp[id||(x<lim)][i+1][j+(x!=0)]+=dp[id][i][j];
                }
            }
        }
    }
    cout<<dp[0][n][k]+dp[1][n][k]<<endl;
    return 0;
}

Measured memory_bytes: 384
unittest
{
	assert( [ "3" ].solve == 3 );
	assert( [ "100" ].solve == 473 );
	assert( [ "1000000" ].solve == 13969985 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	auto ans = 0L;
	foreach( a; 1L .. n + 1 )
	{
		foreach( b; 1L .. n + 1 )
		{
			if( n <= a * b ) break;
			ans++;
		}
	}
	return ans;
}


Measured memory_bytes: 2780