akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int dfs(int idx,const vector<int> &cnt,vector<int>& table){
    if(idx==13){
        int res=24;
        for(int i=0;i<table.size();i++){
            for(int j=i+1;j<table.size();j++){
                if(table[i] && table[j]){
                    res=min(res,min(j-i,24-(j-i)));
                }
            }
        }
        return res;
    }
    if(cnt[idx]==0) return dfs(idx+1,cnt,table);
    else if(cnt[idx]==1){
        table[idx]=true;
        int ret=dfs(idx+1,cnt,table);
        table[idx]=false;
        table[24-idx]=true;
        ret=max(ret,dfs(idx+1,cnt,table));
        table[24-idx]=false;
        return ret;
    }
    else{
        table[idx]=table[24-idx]=true;
        int ret=dfs(idx+1,cnt,table);
        table[idx]=table[24-idx]=false;
        return ret;
    }
    
}
int main(){
    int n;
    cin>>n;
    vector<int> d(n);
    for(int i=0;i<n;i++) cin>>d[i];
    vector<int> cnt(13,0);
    for(int i=0;i<n;i++){
        cnt[d[i]]++;
    }
    if(cnt[0] || *max_element(cnt.begin(),cnt.end())>=3 || cnt[12]>=2){
        cout<<0<<endl;
        return 0;
    }
    vector<int> table(24,0);
    table[0]=true;
    cout<<dfs(0,cnt,table)<<endl;
    return 0;
}

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

int cmp(int a,int b)
{
    return a>b;
}

int main()
{
    int a[3];
    for(int i = 0; i < 3; i++)
        scanf("%d",&a[i]);
    sort(a,a+3,cmp);
    printf("%d\n",a[0]*10+a[1]+a[2]);
    return 0;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int main() {
  
  int n;
  cin>>n;
  map<string,int>mps;
  while(n--){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    mps[s]++;
  }
  ll cnt=0;
  for(auto i:mps){
    ll temp = i.S;
    cnt+=(temp*(temp-1))/2;
  }
  cout<<cnt;
return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <sstream>
#include <set>
#include <algorithm>

using namespace std;
typedef unsigned long long ull;


int main()
{
	int q;

	while (cin >> q && q)
	{
		for (int i = 0; i < q; i++)
		{
			string n;
			cin >> n;

			int sum = 0;
			set<ull> f;

			while (1)
			{
				ull tmp = atoi(n.c_str());
				if (f.count(tmp))
				{
					cout << -1 << endl;
					break;
				}
				else
				{
					f.insert(tmp);
				}
				
				if (sum >= 1e5)
				{
					cout << -1 << endl;
					break;
				}

				if (n.size() == 1)
				{
					cout << sum << endl;
					break;
				}
				else
				{
					ull Max = 0;
					for (int j = 1; j < n.size(); j++)
					{
						ull tmp = atoi(n.substr(0, j).c_str());
						ull tmp2 = atoi(n.substr(j, n.size() - j).c_str());
						Max = max(Max, tmp*tmp2);
					}
					stringstream nextN;
					nextN << Max;
					n = nextN.str();

					sum++;
				}
			}


		}
	}
	

	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000000;

int N, K, R, S, P;
string T;

int main(){
    cin >> N >> K >> R >> S >> P >> T;
    int A[4];
    A[0] = S; A[2] = P; A[3] = R;
    int ans = 0;
    for(int i = 0; i < K; i++){
        stack<pair<char,int> > S;
        S.emplace(T[i],1);
        int j = i+K;
        pair<char,int> p = S.top();
        while(j < N){
            p = S.top();
            S.pop();
            if(p.first != T[j]){
                ans += A[p.first - 'p'] * ((p.second+1)/2);
                S.emplace(T[j], 1);
            }
            else{
                p.second++;
                S.push(p);
            }
            j += K;
        }
        p = S.top();
        ans += A[p.first - 'p'] * ((p.second+1)/2);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.math.*;
class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] coins = new int[m];
		for(int i = 0; i < m; i++){
			coins[i] = sc.nextInt();
		}
		int[] times = new int[n+1];
		times[0] = 0;
		for(int j = 1; j<= n; j++){
			times[j] = Integer.MAX_VALUE;
		}
		for(int j = 1; j <= n; j++){
			for(int i = 0; i < m; i++){
				if(j - coins[i] >= 0){
					times[j] = Math.min(times[j], times[j-coins[i]]+1);
				}
			}
		}
		System.out.println(times[n]);
	}
}

Measured memory_bytes: 27084
#include <bits/stdc++.h>
//↓✟MLE魔、TLE魔✟
#define int long long
//↑✟MLE魔、TLE魔✟
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return t[n]=Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
    int gets(int a){
        return s[a];
    }
};
signed main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i = 0;i<a;i++)
using namespace std;
int main(void){
    int a[3][3];
    rep(i,3)rep(j,3)cin>>a[i][j];
    int ans[3][3],an=0,f=0;
    rep(i,3)rep(j,3)ans[i][j]=0;
    int n;
    cin>>n;
    int b;
    rep(i,n){
        cin>>b;
        rep(i,3)rep(j,3)if(a[i][j]==b)ans[i][j]=1;
        
    }
    rep(i,3){
        rep(j,3)if(ans[i][j]==0)f=1;
        if(f==0){
            cout<<"Yes"<<endl;
            return 0;
        }
    f=0;
    }
    rep(i,3){
        rep(j,3)if(ans[j][i]==0)f=1;
        if(f==0){
            cout<<"Yes"<<endl;
            return 0;
        }
    f=0;
    }
    if(ans[0][0]==1&&ans[1][1]==1&&ans[2][2]==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(ans[0][2]==1&&ans[1][1]==1&&ans[2][0]==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    ll s = S.size();
    map<char,ll> letter;
    string ans = "";
    rep(i,s){
        letter[S[i]]++;
    }
    if(s != 26){
        cout << S;
        for(char c = 'a';c <= 'z';c++){
            if(letter[c] == 0){
                cout << c << "\n";
                return 0;
            }
        }
    }
    if(S == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << "\n";
        return 0;
    }
    string T = S;
    next_permutation(all(S));
    rep(i,26){
        cout << S[i];
        if(T[i] != S[i]){
            cout << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
ds=LI()
s=sorted(ds)
ans=s[n//2]-s[n//2-1]
print(ans)
    

Measured memory_bytes: 52764
I[]={0x01059a25,0x109b0906,0x04069807,0x07059e99,0x0706089f,0x92029d9c,0x11059093,0x01009103};
unsigned char*C="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?",*strchr(),*L="68443586484588538455886888366866",*B=I;
b,l;
main(c){
	for(;c=getchar(),c+1;)
		if(c-10)
			for(c=strchr(C,c)-C,b=b<<(L[c]-48)|B[c],l+=L[c]-48;l>4;putchar(C[b>>l&31]))
				l-=5;
		else l&&putchar(C[(b<<=5-l)&31]),l=0,putchar(c);
	exit(0);
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline


N, A, B, C = map(int, input().split())
Ss = [input().rstrip() for _ in range(N)]



ok = True
ans = []
for i, S in enumerate(Ss):
    if S == "AC":
        if A > C:
            T = "C"
            C += 1
            A -= 1
        elif A < C:
            T = "A"
            A += 1
            C -= 1
        elif i != N-1:
            if "A" in Ss[i+1]:
                T = "A"
                A += 1
                C -= 1
            else:
                T = "C"
                A -= 1
                C += 1
        else:
            T = "A"
            A += 1
            C -= 1
    elif S == "AB":
        if A > B:
            T = "B"
            B += 1
            A -= 1
        elif A < B:
            T = "A"
            A += 1
            B -= 1
        elif i != N-1:
            if "A" in Ss[i+1]:
                T = "A"
                A += 1
                B -= 1
            else:
                T = "B"
                A -= 1
                B += 1
        else:
            T = "A"
            A += 1
            B -= 1
    else:
        if B > C:
            T = "C"
            C += 1
            B -= 1
        elif B < C:
            T = "B"
            B += 1
            C -= 1
        elif i != N-1:
            if "B" in Ss[i+1]:
                T = "B"
                B += 1
                C -= 1
            else:
                T = "C"
                B -= 1
                C += 1
        else:
            T = "B"
            B += 1
            C -= 1
    if A < 0 or B < 0 or C < 0:
        ok = False
        break
    ans.append(T)

if ok:
    print("Yes")
    print("\n".join(ans))
else:
    print("No")

Measured memory_bytes: 81020
n = int(input())
w = [input() for _ in range(n)]
ans = 'Yes'
for i in range(n-1):
  if w[i][-1] != w[i+1][0]:
    ans = 'No'
    break
w.sort()
for i in range(n-1):
  if w[i] == w[i+1]:
    ans = 'No'
    break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    vector<int> aa(3);
    cin >> aa[0] >> aa[1] >> aa[2];
    sort(aa.begin(), aa.end(), greater<int>());

    int ans = aa[0]*10 + aa[1] + aa[2];

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

Measured memory_bytes: 256
while True:
    m,f,r = [int(x) for x in input().split()]
    if (m,f,r) == (-1,-1,-1):
        break
    if   m < 0 or f < 0: 
        print('F')
    elif m + f <  30:    
        print('F')
    elif m + f >= 80:    
        print('A')
    elif m + f >= 65:    
        print('B')
    elif m + f >= 50:    
        print('C')
    elif r    >= 50:    
        print('C')
    else:                
        print('D')


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

int chk(int a) {
    if (a < 400) return 0;
    if (a < 800) return 1;
    if (a < 1200) return 2;
    if (a < 1600) return 3;
    if (a < 2000) return 4;
    if (a < 2400) return 5;
    if (a < 2800) return 6;
    if (a < 3200) return 7;
    return 8;
}


int main() {
    vector< int> v(9, 0);
    int n;
    cin >> n;
    while (n--) {
        int a;
        cin >> a;
        v[chk(a)]++;
    }

    int minn = 0;
    for (int i = 0; i < 8; ++i) if (v[i]) minn++;
    cout << max(1, minn) << ' ' << minn + v[8] << endl;
}

Measured memory_bytes: 256
/*
https://algo-logic.info/abc155d/
勉強させていただいたサイト
*/

#include <bits/stdc++.h>

using namespace std;

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

const ll LongINF=1e18;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int N;
ll K;
vector<ll> P,M,Z;

bool judge_m(ll mid){
    ll sum=0;
    rep(i,int(P.size())){
        ll d=(mid-P[i]+1)/P[i];
        //cout<<d<<" ";
        sum+=upper_bound(M.begin(),M.end(),d)-M.begin();
    }
    //cout<<sum<<" ";
    return sum>=K;
}

bool judge_p(ll mid)
{
    ll sum=0;
    rep(i,P.size()){
        ll d=mid/P[i];
        ll tmp=upper_bound(ALL(P),d)-P.begin();
        if(i<tmp)tmp--;
        sum+=tmp;
    }
    rep(i,M.size()){
        ll d=mid/M[i];
        ll tmp=upper_bound(ALL(M),d)-M.begin();
        if(i<tmp)tmp--;
        sum+=tmp;
    }
    sum/=2;
    return sum>=K;
}

int main(){
    cin>>N>>K;
    rep(i,N){
        ll x;
        cin>>x;
        if(x>0)P.pb(x);
        else if(x<0)M.pb(x);
        else Z.pb(x);
    }

    ll p=P.size(),m=M.size(),z=Z.size();
    ll minus=p*m,zero=z*(z-1)/2+z*p+z*m,plus=p*p+m*m;
    //cout<<minus<<" "<<zero<<" "<<plus<<endl;
    if(K<=minus){
        sort(ALL(M));
        ll l=-LongINF,u=-1;
        while(u-l>1){
            ll mid=(u+l)/2;
            if(judge_m(mid)){
                u=mid;
            }else{
                l=mid;
            }
            //cout<<u<<" "<<l<<" "<<mid<<endl;
        }
        cout<<u<<endl;
    }else if(K<=minus+zero){
        cout<<0<<endl;
    }else{
        K-=(minus+zero);
        rep(i,m)M[i]=abs(M[i]);
        sort(ALL(P));
        sort(ALL(M));
        ll l=-1,u=1e18;
        while(u-l>1){
            ll mid=(u+l)/2;
            if(judge_p(mid)){
                u=mid;
            }else{
                l=mid;
            }
        }
        cout<<u<<endl;
    }

    return 0;
}

//a=97,z=122

Measured memory_bytes: 2548
#include<cstdio>
int main()
{
	int n;
	scanf("%d",&n);
	int ans=0,x;
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&x);
		ans+=x-1;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, string> P;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
struct prod{
	double prof;
	string name;
};
bool sorter(const prod& a, const prod& b){
	if(a.prof==b.prof)return a.name < b.name;
	else return a.prof > b.prof;
}
vector<prod> ps;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		ps.clear();
		rep(i,n){
			string name;
			int p,a,b,c,d,e,f,s,m;
			cin>>name;
			cin>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			double prof=(double)(f*m*s-p)/(double)(a+b+c+(d+e)*m);
			ps.pb(((prod){prof,name}));
		}
		sort(all(ps),sorter);
		rep(i,n){
			cout<<ps[i].name<<endl;
		}
		cout<<"#"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;

LL inf = 1000000000000;
LL mod = 1000000007;

int main()
{
	LL a[32] = {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};
	LL k;
	cin >> k;
	cout << a[k-1] << "\n";
}

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

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> v(m);
    for(int i=0; i<m; i++) cin >> v[i];

    int cnt = 0;
    for(int i=0; i<n; i++){
        int ans = c;
        for(int j=0; j<m; j++){
            int a;
            cin >> a;
            ans += v[j] * a;
        }
        if(ans > 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long w;
   int n;
   scanf("%d %lld",&n,&w);
   vector<long long> wt(n);
   vector<int> value(n);
   for(int i=0;i<n;i++)
   {
      scanf("%lld %d",&wt[i],&value[i]);
   }
   int sum=0;
   for(auto x:value)sum+=x;
   vector<long long> dp(sum+1,1e18+5);
   dp[0]=0;
   for(int i=0;i<n;i++)
   {
       for(int j=sum-value[i];j>=0;j--)
       dp[j+value[i]]=min(dp[j+value[i]],dp[j]+wt[i]);
   }
   int ans=0;
   for(int i=0;i<=sum;i++)
   if(dp[i]<=w){
       ans=max(ans,i);
   }
   cout<<ans;
}

Measured memory_bytes: 1024
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
n, m = map(int,input().split())
s = input()
t = input()
j = 0
a = gcd(n, m)
for i, c in enumerate(s):
	if i % (n // a) == 0:
		if c != t[(i // (n // a)) * (m // a)]:
			j = -1
			break
if j >= 0:
	j = lcm(n, m)
print(j)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
//setprecision(15)

int main() {
	int A, B; cin >> A >> B;
	int tmp = A * 100 / 8;
	int tmp2 = B * 100 / 10;
	int mi = min(tmp, tmp2);
	int ma = max(tmp, tmp2);
	for (int ii = mi-1; ii <= ma+1; ii++) {
		if ((ii*8/100 == A) && (ii*10/100 == B)) {
			cout << ii << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=1e5+20;

int A,B,C,D;

struct node {
	int A,B;
	int times;
	node(int _A=0,int _B=0,int _times=0){ A=_A; B=_B; times=_times;}
};
vector<node> T;

inline void init()
{
	A=read();B=read();C=read();D=read();
	T.clear();
	if(A==B)T={node(1,1,A)};
	else if(A==B+1)T={node(1,1,B),node(1,0,1)};
	else if(B==A+1)T={node(0,1,1),node(1,1,A)};
	else 
	{
		int mx=max(A,B),mn=min(A,B);
		int c=mx/(mn+1),num=0;
		if((mx+c-1)/c>mn+1)c++;
		assert((mx+c-1)/c<=mn+1);

		function<int()>get_num =[&]() {
			int l=0,r=min(A/c,B);
			int nA,nB;
			while(l<r)
			{
				int mid=l+r+1>>1;
				nA=A-mid*c; nB=B-mid;
				if((ll)nA*c>=nB)l=mid;
				else r=mid-1;
			}
			return l;
		};
		num=get_num();
		if(num)T.push_back(node(c,1,num));
		A-=num*c; B-=num; num=0;
		if(A>0 || B>0)
		{
			if(!B)T.push_back(node(A,0,1));
			else if(A*c<B)
				T.push_back(node(0,B-A*c,1)),T.push_back(node(1,c,A));
			else {
				int s=((A+1)*c-B)/c; assert(s<=c);
				T.push_back(node(1,0,s)); A-=s;
				T.push_back(node(0,1,B-A*c)); assert(A*c<=B);
				T.push_back(node(1,c,A));
			}
		}
	}
	int times=0;
	for(node t:T)
	{
		int round=(t.A+t.B),num=t.times;
		int L=times+1,R=times+round*num;
		int tC=max(C,L),tD=min(D,R);
		if(tC<=tD)
		{
			int st=tC-L+1;
			REP(i,1,tD-tC+1)
			{
				int s=(st-1)%round+1;
				if(s<=t.A)printf("A");
				else printf("B");
				st++;
			}
		}
		times=R;
	}
	puts("");
}

int main()
{
	int q=read();
	while(q--)
	{
		init();
	}
	return 0;
}


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

using namespace std;

int dp[10010][10010];
int n, W, v[10010], w[10010];

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

    for (int i = 0; i < n; i++) cin >> v[i] >> w[i];

    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i][j] = dp[i+1][j];
            }
            else {
                dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
            }
        }
    }

    cout << dp[0][W] << endl;
}



Measured memory_bytes: 7032
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
vector<pair<ll, ll>> vp;
int main() {
    cin>>n;
    REP(i, 0, n){
        ll x, y;
        cin>>x>>y;
        vp.emplace_back(make_pair(x, y));
    }

    double sum=0;
    sort(vp.begin(), vp.end());
    do{
        REP(i, 0, n-1){
            sum+=sqrt((vp[i].first-vp[i+1].first)*(vp[i].first-vp[i+1].first)
                    + (vp[i].second-vp[i+1].second)*(vp[i].second-vp[i+1].second));
        }
    }while(next_permutation(vp.begin(), vp.end()));

    double fact=1;
    REP(i, 2, n+1){
        fact*=i;
    }
    printf("%.8lf\n", sum/fact);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
#include <map>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll N;
    cin >> N;
    ll ans=0;
    for (ll j=1; j<=N; ++j) {
        ll q = N/j;
        ans += (1+q)*q*j/2;
    }
    cout << ans << endl;
    return 0;
}


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

int i,mynum,mycount;

int main(){
    scanf("%d", &mynum);
    for(i = 1; i <= mynum; i++){
        if(to_string(i).length() % 2 != 0){
            mycount++;
        }
    }      
    printf("%d\n", mycount);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


int main() {
  int a,b;
  cin >> a >> b;
  cout << a-b+1 << endl;


}

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

int main(){
  int n;
  int c;

  while(1){
    cin >> n;
    if(!n)break;

    c = 0;
    while(1){
      if(n==1)break;

      if(n%2){
	n*=3;
	n++;
      }else{
	n/=2;
      }
      c++;
    }

    cout << c << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main(){
  int n;
  cin >> n;
  int a[n];
  int M = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    M = max(M, a[i]);
  }
  int m = INF, ans;
  if(M % 2){
    int l = M/2, r = M/2 + 1;
    for(int i = 0; i < n; i++){
      int d = min(abs(l-a[i]), abs(r-a[i]));
      if(d < m && a[i] < M){
        m = d;
        ans = a[i];
      }
    }
  } else {
    for(int i = 0; i < n; i++){
      int d = abs(a[i] - M/2);
      if(d < m && a[i] < M){
        m = d;
        ans = a[i];
      }
    }
  }
  cout << M << " " << ans << endl;
  return 0;
}

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

int main(){
	string a,b,c;
	cin>>a>>b>>c;	

	stack<char> s1,s2,s3;
	for(int i=a.length() - 1; i >= 0; i--)
		s1.push(a[i]);

	for(int i=b.length() - 1; i >= 0; i--)
		s2.push(b[i]);

        for(int i=c.length() - 1; i >= 0; i--)
		s3.push(c[i]);

	char res;
	char curr = s1.top();
	s1.pop();
	while(!s1.empty() || !s2.empty() || !s3.empty())
	{
		if(curr == 'a' ){
			if(s1.empty()){ res = 'A'; break; }
			curr = s1.top();
			s1.pop();
		}
		else if(curr == 'b'){
			if(s2.empty()){ res = 'B'; break; }
			curr = s2.top();
			s2.pop();
		}
		else if(curr == 'c'){
		 	if(s3.empty()){	res = 'C'; break; }
			curr = s3.top();
			s3.pop();
			
		}
//		cout<< (curr) <<'\n';
	}

	printf("%c\n", res );

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define int long long
int tree[1001000],a[200100],pre[200100],n,Ans;
void build(int t,int l,int r){
	if(l==r){
		tree[t]=a[l];
		return;
	}
	int mid=(l+r)/2;
	build(t*2,l,mid);
	build(t*2+1,mid+1,r);
	tree[t]=tree[t*2]|tree[t*2+1];
}
int query(int t,int l,int r,int L,int R){
	if(L>r||l>R)return 0;
	if(L<=l&&r<=R)return tree[t];
	int mid=(l+r)/2;
	return query(t*2,l,mid,L,R)|query(t*2+1,mid+1,r,L,R);
}
bool check(int l,int r){
	return (pre[r]-pre[l-1]==query(1,1,n,l,r));
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	pre[0]=0;
	for(int i=1;i<=n;i++)
		pre[i]=pre[i-1]+a[i];
	build(1,1,n);
	for(int i=1;i<=n;i++){
		int L=i,R=n,ans=i;
		while(L<=R){
			int mid=(L+R)/2;
			if(check(i,mid))L=mid+1,ans=mid;
			else R=mid-1;
		}
		Ans+=ans-i+1;
	}
	printf("%lld\n",Ans);
}

Measured memory_bytes: 10364
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    ll n, m, ans=0;
    cin >> n >> m;
    vector<int> x(m), a;
    rep(i, m)cin >> x.at(i);
    sort(all(x));
    REP(i, m-1)a.push_back(x.at(i)-x.at(i-1));
    sort(all(a));
    for(int i = 0; i < max(m-n, 0LL); i++)ans+=a.at(i);
    cout << ans;
}

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

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

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    int L,R,D; cin >> L >> R >> D;
    int ans=0;
    for(int i=L;i<=R;i++){
        if(i%D==0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int l = fs.nextInt();
		
		double thirdDivide = (double)l / 3;
		System.out.println(thirdDivide*(thirdDivide*thirdDivide));
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 21076
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int i = in.nextInt();
        int j = in.nextInt();

        if(i < 9 && j < 9) {
            System.out.println("Yay!");
        }
        else {
            System.out.println(":(");
        }
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
int main(){
int a,b,c,n;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
n = b;
b = a;
a = n;
}
if(b>c){
n = b;
b = c;
c = n;
}
if(a>b){
n = b;
b = a;
a = n;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

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

// グローバル変数
ll n;
vector<ll> a;

// 関数プロトタイプ
void input();
void solve();
ll is_overflow(ll, ll);

int main(void)
{
    input();
    solve();  
}

// 標準入力
void input() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n;i++) {
        cin >> a[i];
    }
}

void solve() {
    sort(a.begin(), a.end(), greater<int>());
    ll ans = a[0];
    for (int i = 0; i < n;i++) {
        if(a[i] == 0) {
            ans = 0;
        }
    }
    for (int i = 1; i < n; i++) {
        if(ans == 0 || ans == -1) {
            break;
        }
        ans = is_overflow(ans, a[i]);  
    }
        cout << ans << endl;
}


ll is_overflow(ll a, ll b) {
    ll check = stoll(to_string(a * b));
    ll ret = 0;
  
    if(check / b != a) {
        ret = -1;
    } else {
        ret = a * b;      
    }
    if(ret > 1000000000000000000 || ret < 0) {
        ret = -1;
    }
    return ret;
}


Measured memory_bytes: 4040
s = input()
t = input()
S = []
T = []

for i in range(len(s)):
    S.append(s[i])
    
for i in range(len(t)):
    T.append(t[i])
    
S.sort()
T.sort()
T.reverse()

if S == T:
    print('No')
    
elif min(S, T) == S:
    print('Yes')

else:
    print('No')

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


int main(){
    ll n,t;
    cin>>n>>t;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    for(int i=0;i<n-1;i++){
        if(a[i+1]-a[i]>t) ans+=t;
        else ans+=a[i+1]-a[i];
    }
    ans+=t;
    cout<<ans<<endl;
}

Measured memory_bytes: 4780
#include <stdio.h>
int main(){
  char s[101],p[101],temp,i,j;
  int ec,ef;
  scanf("%s",s);
  scanf("%s",p);
  int sl=strlen(s),pl=strlen(p);
  for(i=0;i<sl;i++){
    ef=0;
    ec=0;
    temp=s[sl-1];
    for(j=sl-1;j>=0;j--){
      s[j]=s[j-1];
    }
    s[0]=temp;
    for(j=0;j<pl;j++){
      if(s[j]==p[j])ec++;
    }
    if(ec==pl){
	ef=1;
	break;
    }
  }
  if(ef)printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 524
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
ll gcd(ll a,ll b){
   if (a%b == 0){
        return(b);
    }
    
   else{
       return(gcd(b, a%b));
    }
}
int main(){
  ll n,q;cin>>n;
  string s;cin>>s;
  cin>>q;
  ll t=s.size();
  vector<set<ll> > vs(26);
  
  rep(i,0,t){
    ll tmp=s[i]-'a';
    vs[tmp].insert(i);
  }
  
  rep(i,0,q){
    ll a;cin>>a;
    if(a==1){
      ll m;char c;
      cin>>m>>c;
      vs[s[m-1]-'a'].erase(m-1);
      vs[c-'a'].insert(m-1);
      s[m-1]=c;
    }
    else {
      ll l,r;cin>>l>>r;
      l--;r--;
      ll tmp=0;
      rep(j,0,26){
        auto it=vs[j].lower_bound(l);
        if(it!=vs[j].end()&&*it<=r){tmp++;}
      }
      cout<<tmp<<endl;
    }
  }
}



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

using namespace std;


int main(){
	int n;
	cin>>n;
	vector<int> a(n+1);
	for(int i = 1 ; i < n ; i++){
		int t;
		cin>>t;
		a[t]++;
	}
	for(int i = 1 ; i <= n ; i++) cout<<a[i]<<endl;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 200003
#define pc(x) putchar_unlocked(x);

long long n,a[mx],pref[mx],k,tree[mx*4],maks[mx*4],jaw,di[mx];
vector<int>ve;
bool cmp(int x,int y){
	return pref[x]<pref[y];
}

void upd(int idx,int l,int r,int in,int di,int t){
	if(in>r || in<l)return;
	if(l==r){
		if(t==1)maks[idx]=pref[di];
		if(t==1)tree[idx]++;
		else tree[idx]--;
		return;
	}
	upd(idx*2,l,MID,in,di,t);
	upd(idx*2+1,MID+1,r,in,di,t);	
	tree[idx]=(tree[idx*2]+tree[idx*2+1]);
	maks[idx]=max(maks[idx*2],maks[idx*2+1]);
}

int cari(int idx,int l,int r,long long val){
	if(l==r && maks[idx]>=val)return tree[idx];
	if(l==r)return 0;
	if(maks[2*idx]>=val)return cari(idx*2,l,MID,val)+tree[2*idx+1];
	return cari(2*idx+1,MID+1,r,val);
}

int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]-=k;
		pref[i]=pref[i-1]+a[i];
		ve.pb(i);
	}
	sort(ALL(ve),cmp);
	int cnt=0;
	for(int i:ve){
		++cnt;
		di[i]=cnt;
		upd(1,1,n,cnt,i,1);
	}
	long long sem=0;
	for(int i=1;i<=n;i++){
		if(i>1){
			upd(1,1,n,di[i-1],0,0);
			sem=sem+a[i-1];
			//debug(di[i-1]);
		}
		jaw=jaw+cari(1,1,n,sem);
	//	debug(jaw);
	//	debug(sem);
	}
/*	for(int i=1;i<=n;i++){
		long long aa=0;
		for(int j=i;j<=n;j++){
			aa+=a[j];
	//		if(aa>=0)jaw++;
		}
	//	debug(jaw);
	}*/
	cout<<jaw;
}




Measured memory_bytes: 18292
#include<bits/stdc++.h>
using namespace std;
char str[100010];
int n;
int o[100010];
int shee[100010];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d",&n);
	scanf("%s",str);
	for(int i=0;i<n;i++){
		o[i+1]=(str[i]!='o');
	}
	o[n+1]=o[1];
	for(int mask=0;mask<8;mask++){
		shee[0]=((mask)&1);
		shee[1]=((mask>>1)&1);
		shee[2]=((mask>>2)&1);
		for(int j=2;j<=n+1;j++){
			shee[j+1]=(shee[j-2]^o[j]);
		}
		if(shee[0]^shee[n]^shee[1]^shee[n+1]||shee[1]^shee[n+1]^shee[2]^shee[n+2])
			continue;
		for(int i=1;i<=n;i++)
			cout<<((shee[i]^shee[i-1])?'W':'S');
		return 0;
	}
	cout<<-1;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

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

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

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

	int main(){
		IOS;
		int x ,y;
		cin >> x >> y;
		dump(x + y / 2);
	}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	b := readBytes()

	for i := range b {
		b[i] = byte((int(b[i])-int('A')+n)%26 + int('A'))
	}

	fmt.Println(string(b))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
# time complexity: O(HW)
# space complexity: O(1)

import sys
fin = sys.stdin.readline
from copy import deepcopy


def warshall_floyd(w):
    num_vertices = len(w)
    dp = deepcopy(w)
    for k in range(num_vertices):
        for i in range(num_vertices):
            for j in range(num_vertices):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    return dp


H, W = [int(elem) for elem in fin().split()]
c_list = [[int(elem) for elem in fin().split()] for _ in range(10)]
assert len(c_list[0]) == 10

A_list = [[int(elem) for elem in fin().split()] for _ in range(H)]
assert len(A_list[0]) == W

total_cost = 0
min_costs = warshall_floyd(c_list)
for A_row in A_list:
    for A in A_row:
        if A != -1 and A != 1:
            total_cost += min_costs[A][1]

print(total_cost)


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,x[25],y[25],p[25],tot;
struct Line{
	bool f;//f=0:x=k f=1:y=k
	int k;
}l[25];
ll ans=0;
ll Calc(){
	ll r=0;
	for(int i=1;i<=n;i++){
		int minn=1e9;
		for(int j=1;j<=tot;j++){
			if(l[j].f)minn=min(minn,abs(l[j].k-y[i]));
			else minn=min(minn,abs(l[j].k-x[i]));
		}
		r+=1ll*minn*p[i];
		if(r>=ans)return r;
	}
	return r;
}
void dfs(int now,int nd){
	if(n-now+1<nd)return ;
	if(!nd)return ans=min(ans,Calc()),void();
	dfs(now+1,nd);
	l[++tot]={0,x[now]};
	dfs(now+1,nd-1);
	l[tot]={1,y[now]};
	dfs(now+1,nd-1);
	tot--;
}
int main() {
	//for(int i=1;i<=15;i++)cout<<rand()%15<<' '<<rand()%15<<' '<<rand()%15<<'\n';
	cin>>n;
	for(int i=1;i<=n;i++)cin>>x[i]>>y[i]>>p[i];
	for(int i=1;i<=n;i++)ans+=1ll*min(abs(x[i]),abs(y[i]))*p[i];
	cout<<ans<<endl;
	l[1]={0,0},l[1]={1,0};
	for(int i=1,F=0;i<=n;i++){
		tot=2;
		if(!F)dfs(1,i);
		cout<<ans<<endl;
		if(!ans)F=1;
	}
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long long LL;

struct Guide {
  int index;
  int P;

  bool operator<(const auto &right) const {
    if (P == right.P) return index < right.index;
    else return P < right.P;
  }
};

int main() {
  int N; std::cin >> N;
  std::map<std::string, std::vector<Guide>> m;
  for (int i = 1; i <= N; ++i) {
    std::string S; std::cin >> S;
    int P; std::cin >> P;

    m[S].push_back({i, P});
  }

  for (auto a : m) {
    std::sort(a.second.rbegin(), a.second.rend());
    for (auto v : a.second) {
      std::cout << v.index << std::endl;;
    }
  }
}


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

struct TMatrixInfo
{
	int RowSize;
	int ColSize;
	TMatrixInfo(int ARowSize, int AColSize)
	{
		RowSize = ARowSize;
		ColSize = AColSize;
	}
	TMatrixInfo()
	{
	}
};

vector<vector<int> > TableResize(int n)
{
	vector<vector<int> > CostCountTable;
	CostCountTable.resize(n);
	for(int i = 0; i < n; i++){
		CostCountTable[i].resize(n);
	}
	return CostCountTable;
}

int Cost(TMatrixInfo A, TMatrixInfo B)
{
	return A.RowSize * A.ColSize * B.ColSize;
}

TMatrixInfo M(int Index1, int Index2, const vector<TMatrixInfo>& MatrixChain)
{
	TMatrixInfo Matrix(MatrixChain[Index1].RowSize, MatrixChain[Index2].ColSize);
	return Matrix;
}

int GetCellValue(const vector<vector<int> >& CostCountTable, const vector<TMatrixInfo>& MatrixChain, int Row, int Col)
{
	if(Col == Row){
		return 0;
	}else{
		int CurrentMinCost;
		for(int i = Row; i < Col; i++){
			int CurrentCost = CostCountTable[Row][i] + Cost(M(Row, i, MatrixChain), M(i+1, Col, MatrixChain)) + CostCountTable[i+1][Col];
			if(i == Row || CurrentCost < CurrentMinCost){
				CurrentMinCost = CurrentCost;
			}
		}
		return CurrentMinCost;
	}
}

void CalcSlantingLine(vector<vector<int> >& CostCountTable, const vector<TMatrixInfo>& MatrixChain, int Col)
{
	int n = MatrixChain.size();
	for(int i = 0; i < n-Col; i++){
		CostCountTable[i][Col+i] = GetCellValue(CostCountTable, MatrixChain, i, Col+i);
	}
}

int MinCalcCost(const vector<TMatrixInfo>& MatrixChain)
{
	int n = MatrixChain.size();
	vector<vector<int> > CostCountTable = TableResize(n);
	for(int i = 0; i < n; i++){
		CalcSlantingLine(CostCountTable, MatrixChain, i);
	}
	return CostCountTable[0][n-1];
}

int main()
{
	int n;
	cin >> n;
	vector<TMatrixInfo> MatrixChain(n);
	for(int i = 0; i < n; i++){
		cin >> MatrixChain[i].RowSize;
		cin >> MatrixChain[i].ColSize;
	}
	cout << MinCalcCost(MatrixChain) << endl;
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

int main()
{
    ll x;
    cin >> x;

    ll i;
    for(i = 1; i <= x; i ++)
    {
    	ll check = i * (i + 1);
    	if(check >= 2 * x)
    	{
    		cout << i << endl;
    		break;
    	}
    }
}

Measured memory_bytes: 256
n,y=map(int,input().split())
for i in range(n+1):
  for j in range(n+1-i):
    if i*10000 + j*5000 + (n-i-j)*1000==y:
      print(i, j, n-i-j)
      exit()
print("-1 -1 -1")

Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define int long long
using namespace std;
const long long maxn = 200100, mod = 1e9 + 7, maxa = 3e6 + 100, maxb = 23, base = 737, base2 = 3079, mod2 = 242121643;
const long long inf = 2e18 + 13;
long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

long double p[maxn];
long double a[maxn];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long double n;
    cin >> n;
    n *= 2;
    for(int i = 0; i < n; i++){cin >> a[i];}
    sort(a, a + (int)n);
    long double ans = 0;
    for(long double i = n - 1; i >= 0; i--)
    {
        long double pr = (long double)i;
        //cout << pr << endl;
        ans += (long double)(pr * (long double)a[(int)i]);
        //cout << ans << endl;
    }
    //cout << ans << ' ' << n - 1 << endl;
    ans = (long double)ans / (long double)(n - 1.0);

    cout << fixed << setprecision(9) << ans << endl;
    return 0;
}












Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<math.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){

	ll n,a,b,h[100001];
	ll biggest = 0;

	scanf("%lld %lld %lld",&n,&a,&b);
	FOR(i,0,n){
		scanf("%lld",&h[i]);
		if(biggest < h[i]) biggest = h[i];
	}

	ll min = 0,mid,max = biggest / b + 1;

	while(min +1 < max){
		mid = (min + max) / 2;
		ll T = 0,t[100001];
		FOR(i,0,n){
			t[i] = h[i];
			t[i] -= b * mid;
			if(t[i] < 0) t[i] = 0;
		}
		FOR(i,0,n){
			T += t[i] / (a-b);
			if(t[i] % (a-b) != 0) T++;
		}

		if(T > mid) min = mid;
		else max = mid;
	}

	printf("%lld\n",max);
}

Measured memory_bytes: 1664
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    S = [list(input()[:-1]) for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                continue

            flg = True
            if i-1>=0 and S[i-1][j]=='#':
                flg = False
            if i+1<H and S[i+1][j]=='#':
                flg = False
            if j-1>=0 and S[i][j-1]=='#':
                flg = False
            if j+1<W and S[i][j+1]=='#':
                flg = False
            
            if flg:
                print('No')
                return
    
    print('Yes')


if __name__ == '__main__':
    main()

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

namespace ABC045A___台形
{
    class Program
    {
        static void Main(string[] args)
        {
            int upperButtom = int.Parse(Console.ReadLine());
            int lowerButtom = int.Parse(Console.ReadLine());
            int height = int.Parse(Console.ReadLine());

            int trapezoidArea = (upperButtom + lowerButtom) * height / 2;

            Console.WriteLine(trapezoidArea.ToString());
        }
    }
}


Measured memory_bytes: 13140