akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main(void) {
  int n;
  int a[110];
  
  cin >> n;
  for(int i = 0;i < n;i++) {
    cin >> a[i];
  }
  sort(a, a + n, greater<int>());
  
  int current = a[0];
  int count = 1;
  for (int i = 1;i < n;i++) {
    // cout << "a[i]:" << a[i] << " current:" << current << endl;
    if (a[i] < current) {
      count++;
      current = a[i];
    }
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
N, K=list(map(int, input().split()))
p=list(map(int, input().split()))

p_cum = []
temp=0
for elm in p:
    temp+=elm
    p_cum.append(temp)

max=0
temp=0
for k in range(N-K+1):
    temp_max = (p_cum[k+K-1]-temp+K)/2.0
    if max < temp_max:
        max=temp_max
    temp=p_cum[k]
print(max)


Measured memory_bytes: 25060
#include <cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int cnt[4001]={};
	rep(i,1001) rep(j,1001) cnt[i+j]++;

	for(int n;~scanf("%d",&n);){
		int ans=0;
		rep(i,n+1) ans+=cnt[i]*cnt[n-i];
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1048
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

C1,C2 = B1-A1, B2-A2

if C1 > 0:
    if C1*T1+C2*T2 > 0:
        ans = 0
    elif C1*T1+C2*T2 == 0:
        ans = 'infinity'
    else:
        d = abs(C1*T1+C2*T2)
        if C1*T1%d==0:
            ans = 2*C1*T1//d
        else:
            ans = 2*(C1*T1//d)+1
else:
    if C1*T1+C2*T2 < 0:
        ans = 0
    elif C1*T1+C2*T2 == 0:
        ans = 'infinity'
    else:
        d = abs(C1*T1+C2*T2)
        dd = abs(C1*T1)
        if dd%d==0:
            ans = 2*dd//d
        else:
            ans = 2*(dd//d)+1
        
print(ans)

Measured memory_bytes: 38384
x,n=map(int,input().split())
if n!=0:
    l=list(map(int,input().split()))
    if x not in l:
        print(x)
    else:
        for i in range(120):
            if x - i not in l:
                print(x-i)
                break
            if x + i not in l:
                print(x+i)
                break
else:
    print(x)
    

Measured memory_bytes: 9184
#include <string.h>
#include <stdio.h>
int main (){
	int modulo,range1, range2,a=0 ;
	scanf("%d %d %d",&range1, &range2,&modulo);
	for (int i=range1;i<=range2;i++){
		if (i % modulo == 0 ){
		    a++ ;
		}
	}
	printf("%d",a);
}

Measured memory_bytes: 1688
S = input()
T = input()


m = len(S)
for i in range(0,len(S)-len(T)+1):
    tgt = S[i:i+len(T)]
    if tgt != T:
        cnt = 0
        for j in range(len(tgt)):
            if tgt[j] != T[j]:
                cnt += 1
        m = min(cnt,m)
    else:
        m = 0
        break

print(m)

Measured memory_bytes: 8984
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, M, C;
int A[50][50];
int B[50];

signed main()
{
	cin >> N >> M >> C;
	REP(i, M) cin >> B[i];
	REP(n, N)
	{
		REP(m, M)
		{
			cin >> A[n][m];
		}
	}

	int ans = 0;
	REP(n, N)
	{
		int sum = 0;
		REP(m, M)
		{
			sum += A[n][m] * B[m];
		}
		sum += C;
		if (sum > 0)
		{
			ans++;
		}
	}

	cout << ans << endl;
}









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

typedef long long ll;
using namespace std;

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

    int x = floor(n / 1.08);
    if (floor(x * 1.08) == n) {
        cout << x << endl;
    } else if (floor((x - 1) * 1.08) == n) {
        cout << x - 1 << endl;
    } else if (floor((x + 1) * 1.08) == n) {
        cout << x + 1 << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<map>
using namespace std;
int main()
{
	int n,a,sum;
	while(~scanf("%d",&n)){
        sum=0;
        map<int,int>m;
        while(n--){
            scanf("%d",&a);
            m[a]++;
        }
        for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
            sum+=((*it).second)%2;
        printf("%d\n",sum);
	}
	return 0;
}


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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ms memset
//#define MAXN 10005
//#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

int R;

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

	cin >> R;

	cout << 2*pi*R << "\n";

	return 0;	
}

Measured memory_bytes: 3752
x,y,z,k = map(int,input().split())
a = []
for i in input().split():
	a.append(int(i))
b = []
for i in input().split():
	b.append(int(i))
c = []
for i in input().split():
	c.append(int(i))

#a.reverse()
#b.reverse()
#c.reverse()

a_bsum = []

for i in range(x):
	for j in range(y):
			a_bsum.append(a[i]+b[j])
a_bsum.sort()
a_bsum.reverse()

a_bsum = a_bsum[0:k]

sum = []

c.sort()
c.reverse()
c = c[0:k]

for i in a_bsum:
	for j in c:
		sum.append(i+j)

sum.sort()
sum.reverse()

for i in range(k):
	print(sum[i])

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

int N;
vector<int> A(105);
vector<int> B(105);

int main(){

    cin >> N;
    for (int i=0; i<N-1; i++){
        cin >> B.at(i);
        A.at(i) = B.at(i);
    }
    A.at(N-1) = B.at(N-2);

    for (int i=0; i<N-1; i++){
        if (max(A.at(i), A.at(i+1)) > B.at(i)){
            if (A.at(i) > B.at(i)){
                A.at(i) = B.at(i);
            }
            if (A.at(i+1) > B.at(i)){
                A.at(i+1) = B.at(i);
            }
        }
    }

    int sum = 0;
    for (int i=0; i<N; i++){
        sum += A.at(i);
    }

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

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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    string s, t; cin >> s >> t;
    int lens = s.length(), lent = t.length();
    int S[lens], T[lent];
    rep(i, lens) S[i] = s[i];
    rep(i, lent) T[i] = t[i];
    sort(S, S+lens); sort(T, T+lent);
    reverse(T, T+lent);

    int ans = -1;
    //rep(i, lens) cout << S[i]; cout << endl;
    //rep(i, lent) cout << T[i]; cout << endl;
    rep(i, min(lens, lent)){
        if(S[i] < T[i]){
            ans = 0;
            break;
        }
        else if(S[i] > T[i]){
            ans = 1;
            break;
        }
    }
    if(ans == -1){
        if(lens == max(lens, lent)) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    else if(ans == 0){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
A,B = map(int,input().split())
h = 96
w = 99
S = [["." for _ in range(w)] for _ in range(h)]
for i in range(48,h):
    for j in range(w):
        S[i][j] = "#"
cnt = 0
while cnt<B-1:
    for i in range(16):
        for j in range(33):
            S[3*i+1][3*j+1]="#"
            cnt += 1
            if cnt==B-1:break
        if cnt==B-1:break
    if cnt==B-1:break
cnt = 0
while cnt<A-1:
    for i in range(16):
        for j in range(33):
            S[48+3*i+1][3*j+1]="."
            cnt += 1
            if cnt==A-1:break
        if cnt==A-1:break
    if cnt==A-1:break
print(h,w)
for i in range(h):
    print("".join(S[i]))

Measured memory_bytes: 39408
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int t;
	cin >> t;
	for (int tt = 0; tt < t; tt++) {
		int n;
		cin >> n;
		vector<int> vk(n, 0);
		vector<long long int> vl(n, 0), vr(n, 0);
		long long int res = 0;
		vector<pair<int, int>> vp1, vp2;
		for (int i = 0; i < n; i++) {
			cin >> vk[i] >> vl[i] >> vr[i];
			res += max(vl[i], vr[i]);
			if (vl[i] > vr[i]) {
				vp1.push_back(make_pair(abs(vl[i] - vr[i]), i));
			}
			if (vl[i] < vr[i]) {
				vp2.push_back(make_pair(abs(vr[i] - vl[i]), i));
			}
		}
		set<int> s1, s2;
		for (int i = 0; i < vp1.size(); i++) {
			s1.insert(i + 1);
		}
		for (int i = 0; i < vp2.size(); i++) {
			s2.insert(i + 1);
		}
		sort(vp1.begin(), vp1.end());
		reverse(vp1.begin(), vp1.end());
		sort(vp2.begin(), vp2.end());
		reverse(vp2.begin(), vp2.end());
		for (int i = 0; i < vp1.size(); i++) {
			int diff = vp1[i].first, index = vp1[i].second;
			auto it = s1.lower_bound(vk[index]);
			if (it == s1.end()) {
				s1.erase(*s1.rbegin());
			} else {
				if (*it == vk[index]) {
					s1.erase(*it);
				}
				else if (it != s1.begin()) {
					it--;
					s1.erase(*it);
				} else {
					res -= diff;
				}
			}
		}
		for (int i = 0; i < vp2.size(); i++) {
			int diff = vp2[i].first, index = vp2[i].second;
			auto it = s2.lower_bound(n - vk[index]);
			if (it == s2.end()) {
				s2.erase(*s2.rbegin());
			} else {
				if (*it == n - vk[index]) {
					s2.erase(*it);
				}
				else if (it != s2.begin()) {
					it--;
					s2.erase(*it);
				} else {
					res -= diff;
				}
			}
		}
		cout << res << endl;
	}
}


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

void Main() {
  double R;
  cin >> R;

  cout << 3.1415926535897932 * R * 2 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 3804
import java.io.*;
import java.util.*;
import java.lang.*;


public class Main {
    static String rep(String s, int n){
        String ans = "";
        for(int i=0; i<n; i++) ans = ans + s;
        return ans;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String x = rep(Integer.toString(a), b);
        String y = rep(Integer.toString(b), a);
        System.out.println(x.compareTo(y)>0 ? y : x);

    }


}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

int main()
{
	ll N, T; cin >> N >> T;
	vector<ll> t(N+1, INF);
	for(int i = 0; i < N; i++) cin >> t[i];
	ll time = 0;
	for(int i = 0; i < N; i++) {
		time += min(T, t[i+1] - t[i]);
	}
	cout << time << endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a > b) {
			System.out.println("a > b");
		}else if(a < b) {
			System.out.println("a < b");
		}else {
			System.out.println("a == b");
		}
	}

}

Measured memory_bytes: 26088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1e9+7;

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
    string s;
    cin >> s;
    int n = sz(s);
    ll dp[100050][4] = {};
    dp[n][3] = 1;
    dp[n][2] = 0;
    dp[n][1] = 0;
    dp[n][0] = 0;
    per(i,0,n) {
        if(s[i] == '?') {
            dp[i][3] = dp[i+1][3]*3 % MOD;
        } else {
            dp[i][3] = dp[i+1][3];
        }
        rep(j,0,3) {
            if(s[i] == '?') {
                dp[i][j] += 3*dp[i+1][j];
            } else {
                dp[i][j] += dp[i+1][j];
            }
            if(s[i] == "ABC"[j] || s[i] == '?') {
                dp[i][j] += dp[i+1][j+1];
            }

            dp[i][j] %= MOD;
        }
    }
    cout << dp[0][0] << '\n';
	return 0;
}


Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_L = 100000;

// エラトステネスの篩
// n以下の素数の数を返す O(n*loglogn)
int sieve(int n, bool is_prime[], int prime[]) {
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;

    is_prime[0] = is_prime[1] = false;

    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }

    return p;
}

// 素数判定機
bool check_prime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

int main() {
    ll Q;
    cin >> Q;
    ll l[Q], r[Q];

    rep(i, Q) { cin >> l[i] >> r[i]; }

    bool is_prime[MAX_L + 1];
    int prime[MAX_L];  // i番目の素数
    sieve(MAX_L, is_prime, prime);

    ll a[MAX_L];
    rep(i, MAX_L) {
        a[i] = 0;

        if (i % 2 == 0) continue;

        if (is_prime[i] && is_prime[(i + 1) / 2]) a[i] = 1;
    }

    ll s[MAX_L + 1];
    rep(i, MAX_L + 1) { s[i] = 0; }
    rep(i, MAX_L) { s[i + 1] = s[i] + a[i]; }

    rep(i, Q) { cout << s[r[i] + 1] - s[l[i]] << endl; }

    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

ll dp[2][100001];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,W;
	cin>>n>>W;
	vl w(n),v(n);
	rep(i,n){
		cin>>w[i]>>v[i];
	}
	bool pn=false;
	rep(i,n){
		pn=!pn;
		rep(j,100001){
			if(j-w[i]>=0)dp[pn][j]=max(dp[pn][j],dp[!pn][j-w[i]]+v[i]);
			dp[pn][j]=max(dp[pn][j],dp[!pn][j]);
		}
	}
	cout<<dp[pn][W]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, K;
  cin >> N >> K;
  vector <int> item(N);
  for (int i = 0; i < N; ++i){
    cin >> item.at(i);
  }
  sort(item.begin(),item.end());
  int sum = 0;
  for(int i = 0; i < K; ++i){
    sum += item.at(i);
  }
  cout << sum << endl;
}



Measured memory_bytes: 3628
while True:
    x=input().split()
    a=int(x[0])
    b=int(x[1])
    c=a-2
    d=b-2
    if a ==0 and b==0:
        break
    print("#"*b)
    for i in range(c):
        print("#"+"."*d+"#")
    print("#"*b)
    print("")


Measured memory_bytes: 5616
def sieve(n=10**6):
  p=[1]*(n+1)
  for i in range(2,n+1):
    if p[i]:
      for j in range(2*i,n+1,i):p[j]=0
  p[0],p[1]=0,0
  return p
while True:
  try:print(sum(sieve(int(input()))))
  except:break




Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  
  int n,h;
  cin>>n>>h;
  int a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  pair<int,int> P[n],Q[n];
  for(int i=0;i<n;i++){
    P[i].first=a[i];
    P[i].second=b[i];
    Q[i].first=b[i];
    Q[i].second=a[i];
  }
  sort(P,P+n);
  sort(Q,Q+n);
  int ans=0;
  for(int i=n-1;i>=0;i--){
    if(P[n-1].first<Q[i].first){
      h-=Q[i].first;
      ans++;
    }
    if(h<=0) break; 
  }
  if(h>0) ans+=(h+P[n-1].first-1)/P[n-1].first;
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  uint32_t N = 0, K = 0;
  std::cin >> N >> K;

  std::vector<uint32_t> v(N);

  for (size_t i = 0; i < K; i++) {
    uint32_t d = 0;
    std::cin >> d;
    for (size_t j = 0; j < d; j++) {
      uint32_t a = 0;
      std::cin >> a;
      v[a - 1]++;
    }
  }

  uint32_t ans = 0;
  for (auto &&v_n : v) {
    if (v_n == 0) ans++;
  }
  std::cout << ans << std::endl;

  return 0;
}

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

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

vector<vector<ii>> g;
vector<int> ans;
int mx = 0;
void dfs(int u, int p, int usedColor)
{
    int idx = 1;
    for (auto cur : g[u]) {
        int v = cur.first;
        int edgeNumber = cur.second;
        if (v == p) // skip parent
            continue;
        if (usedColor == idx)
            idx++;
        mx = max(mx, idx);
        ans[edgeNumber] = idx;
        dfs(v, u, idx);
        idx++;
    }
}

int main()
{
    int n;
    scanf("%d", &n);

    g = vector<vector<ii>>(n, vector<ii>());
    ans = vector<int>(n - 1, -1);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--;
        v--;

        g[u].push_back(ii(v, i));
        g[v].push_back(ii(u, i));
    }

    dfs(0, -1, -1);

    printf("%d\n", mx);
    for (int i = 0; i < n - 1; i++)
        printf("%d\n", ans[i]);

    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a != 3 && b != 3) cout << 3 << endl;
    else if (a != 2 && b != 2) cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}

Measured memory_bytes: 3636
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}


//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

//ABC158のE見る
int main() {
	ll s, w; cin >> s >> w;
	if (w >= s)cout << "unsafe" << endl;
	else cout << "safe" << endl;
}

Measured memory_bytes: 11032
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, ze=0, tmp;
	vector<int> v;

	cin>> n;
	v.resize(n+1);
	for(int i=1;i<=n;i++){
		cin>> v[i];
		if(v[i]==0) ze++;
	}

	sort(v.begin(), v.end());

	if(ze==n){
		cout<< "Yes" <<endl;
		return 0;
	}

	/*if(ze*2==n){
		if(v[n/2+1]==v[n]){
			cout<< "Yes" <<endl;
			return 0;
		}else{
			cout<< "No" <<endl;
			return 0;
		}
	}*/
			

	if(n%3!=0){
		cout<< "No" <<endl;
		return 0;
	}		

	if(v[1]==v[n/3] && v[1+n/3]==v[2*n/3] && v[1+2*n/3]==v[n]){
		tmp=v[n/3]^v[2*n/3];
		if(tmp==v[n]){
			cout<< "Yes" <<endl;
			return 0;
		}
	}

	cout<< "No" <<endl;

}

Measured memory_bytes: 640
import math as m

a, b = map(int, input().split())
cost = -1
flg = 0

while flg == 0 and cost < 10 ** 6 / 1.5:
    cost += 1
    aAns = m.floor(cost * 0.08)
    bAns = m.floor(cost * 0.1)
    if aAns == a and bAns == b:
        flg = 1
    if a - aAns < 0 or b - bAns < 0:
        break

print(cost if flg == 1 else -1)


Measured memory_bytes: 3060
import java.util.*;
public class Main {
  static String S;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    S = sc.next();
    char[] s = S.toCharArray();
    int o = 0;
    for(int i = 0; i < s.length; i++)
      if(s[i] == 'o')
        o++;
    System.out.println(700 + o * 100);
  }
}

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

int main() {
    string s;
    cin >> s;
    int count = 0;
    if (s[0] == '1') count++;
    if (s[1] == '1') count++;
    if (s[2] == '1') count++;

    cout << count << endl;
}

Measured memory_bytes: 3568
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long p = 1;
		for(int i = 1; i <= N; i++) {
			p = p % 1000000007 * i;
		}
		System.out.println(p % 1000000007);
	}

}


Measured memory_bytes: 23124
#include <stdio.h>

int main(void){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    if(A + B + C != 17){
        printf("NO\n" );
    }else if(A * B * C != 175){
        printf("NO\n" );
    }else{
        printf("YES\n");
    }
    return 0;   
}

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

vector<int> memo(20);

int solve(int r,int d,int x,int a){
    if(a<=0) return x;
    else if(memo[a]!=0) return memo[a];
    else{
        return memo[a]=r*solve(r,d,x,a-1)-d;
    }
}

int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    memo[10]=solve(r,d,x,10);
    for(int i=1;i<11;i++) cout<<memo[i]<<endl;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ep emplace_back
int main(void) 
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie();
	int a,b; 
	cin >> a >> b; 
	if (a<=0 || a>=10 || b<=0 || b>=10) cout << "-1\n";
	else cout << a*b<<'\n';

		

	return false; 
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int ok(char *s)
{
    int n=strlen(s);
    int i;
    for (i=0; i<n/2; ++i)
        if (s[i] != s[n-i-1]) return 0;
    return 1;
}
int main(void)
{
    char buf[128];
    int res = 0;
    while (scanf("%s", buf) != EOF) {
        if (ok(buf)) res++;
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 0
class Dice:
  def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6):
    self.d = {"TOP":top, "FRONT":front, "LEFT":left, "RIGHT":right, "BACK":back, "BOTTOM":bottom}

  def roll_x(self):
    self._roll("TOP", "FRONT", "BOTTOM", "BACK")
  
  def roll_y(self):
    self._roll("FRONT", "LEFT", "BACK", "RIGHT")
  
  def roll_z(self):
    self._roll("TOP", "LEFT", "BOTTOM", "RIGHT")
  
  def _roll(self, a, b, c, d):
    self.d[a], self.d[b], self.d[c], self.d[d] = \
    self.d[b], self.d[c], self.d[d], self.d[a]

  def all_rolls(self):
      ret = []
      for i in range(6):
        if i%2:
          self.roll_x()
        else:
          self.roll_y()
        for j in range(4):
          self.roll_z()
          t = self.d.copy()
          ret.append(t)
      return ret

d = list(map(int, input().split()))
dd = Dice(d[0], d[1], d[3], d[2], d[4], d[5])
l = dd.all_rolls()
q = int(input())
for i in range(q):
  t, f = list(map(int, input().split()))
  for ele in l:
    if ele["TOP"]==t and ele["FRONT"]==f:
      print(ele["RIGHT"])
      break


Measured memory_bytes: 5600
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		Map<Integer, Integer> soinsu = new HashMap<Integer, Integer>();
		for (int i = 2; i <= n; i++) {
			bunkai(soinsu, i);
		}

		int ans = 0;
		Integer[] array = soinsu.keySet().toArray(new Integer[0]);

		int cnt3 = 0;
		int cnt5 = 0;
		int cnt15 = 0;
		int cnt25 = 0;
		int cnt75 = 0;
		for (int key : array) {
			int cnt = soinsu.get(key);
			if (cnt >= 2) cnt3++;
			if (cnt >= 4) cnt5++;
			if (cnt >= 14) cnt15++;
			if (cnt >= 24) cnt25++;
			if (cnt >= 74) cnt75++;
		}

		// 75*1
		ans += cnt75;

		// 25*3
		ans += Math.max(cnt25 * (cnt3 - 1), 0);

		// 15*5
		ans += Math.max(cnt15 * (cnt5 - 1), 0);

		// 5*5*3
		ans += Math.max(cnt5 * (cnt5 - 1) / 2 * (cnt3 - 2), 0);

		System.out.println(ans);
	}

	static void bunkai(Map<Integer, Integer> soinsu, int n) {
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
			} else {
				d++;
			}
		}
	}
}


Measured memory_bytes: 21844
import Data.List
import Data.Vector as V hiding (map,sum,reverse) 
main = do
  getLine 
  a <- map read . words <$> getLine 
  let a' = sort a
      b = reverse a'
      a'' = fromList b
      ans = sum [a'' ! i | i <- [0,2 .. V.length a''-1]] - sum [a'' ! i | i <- [1,3 .. V.length a''-1]]
  print ans


Measured memory_bytes: 1020
#include <stdio.h>
#define NIL -1
#define MAX 500001 


int n;
int r, l, p;

void swap(int *x, int *y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
} 

void maxHeap(int T[], int i) {
    l  =  left(i);
    r  =  right(i);
    p  =  parent(i);
    int max;
    if (l  <= n && T[l] > T[i]) max = l;
    else max = i;
    if (r <= n && T[r] > T[max]) max = r;
    if (max != i){
        swap(&T[i], &T[max]);
        maxHeap(T, max);
    }
}

void buildMaxHeap(int T[]){
    int i;
    for(i = n/2; i > 0; i--)
        maxHeap(T, i);
}


int parent(int i) {
    return i/2;
}

int left(int i) {
    return 2*i;
}

int right(int i) {
    return 2*i + 1;
}

int main() {

    int i = 1;
    int T[MAX];

    while(i < MAX+1) {
        T[i] = NIL;
        i++;
    }

    scanf("%d", &n);
    for(i = 1; i < n+1; i++) {
        scanf("%d", &T[i]);
    }
    buildMaxHeap(T);
    for(i = 1; i < n; i++) {
        printf(" %d", T[i]);
    }
    printf(" %d\n", T[n]);
    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string S;
  cin >> S;

  cout << S.substr(0,S.size()-8) << endl;
  
  return 0;
}



Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln endl
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inp freopen("input.txt", "r", stdin)
#define outp freopen("output.txt", "w", stdout)
#define dbgm(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 2e5+5, MOD = 1e9+7, EPS = 1e-9;
int t,n,m,k,x,y;


const int MAX_N = 50; // Fibonacci matrix, increase/decrease this value as needed

struct Matrix { ll mat[MAX_N][MAX_N]; }; // we will return a 2D array

Matrix matMul(Matrix a, Matrix b) {
	Matrix ans; int i, j, k;
	for (i = 0; i < MAX_N; i++)
	for (j = 0; j < MAX_N; j++)
	for (ans.mat[i][j] = k = 0; k < MAX_N; k++){
		ans.mat[i][j] += a.mat[i][k] * b.mat[k][j];
		ans.mat[i][j]%=MOD;
	}
	return ans; 
}

// if necessary, use modulo arithmetic

Matrix matPow(Matrix base, ll p) {
	// O(n^3 log p)
	Matrix ans; int i, j;
	for (i = 0; i < MAX_N; i++) for (j = 0; j < MAX_N; j++) 
	ans.mat[i][j] = (i == j); // prepare identity matrix
	while (p) {
		// iterative version of Divide & Conquer exponentiation
		if (p & 1) ans = matMul(ans, base);	// if p is odd (last bit is on)
		base = matMul(base, base);	// square the base
		p >>= 1;
		// divide p by 2
	}
	return ans; 
}



int main(){
	fastio;
	ll n,k;
	cin>>n>>k;
	Matrix m;
	forn(i,n){
		forn(j,n){
			cin>>m.mat[i][j];
		}
	}
	Matrix p = matPow(m,k);
	ll ans=0;
	forn(i,n){
		forn(j,n){
			ans+=p.mat[i][j];
		}
	}
	ans%=MOD;
	cout<<ans<<ln;
	return 0;
}

Measured memory_bytes: 384
S = input()

flag = 0
for i in range(len(S)):
    if i%2!=0:
        if S[i] not in ["L","U","D"]:
            flag = 1
    else:
        if S[i] not in ["R","U","D"]:
            flag = 1
if flag==1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 2940
N, M = map(int, input().split())
s = input()
C = [[0, 0] for _ in range(N)]
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    if s[b-1] == 'A':
        C[a-1][0]+=1
    else:
        C[a-1][1]+=1
    if s[a-1] == 'A':
        C[b-1][0]+=1
    else:
        C[b-1][1]+=1
    G[a-1].append(b-1)
    G[b-1].append(a-1)
que = []
deleted = [False]*N
for i in range(N):
    if C[i][0] == 0 or C[i][1] == 0:
        que.append(i)
        deleted[i] = True
while que:
    v = que.pop()
    if s[v] == 'A':
        i = 0
    else:
        i = 1
    for nv in G[v]:
        if deleted[nv]:
            continue
        C[nv][i]-=1
        if C[nv][i]==0:
            que.append(nv)
            deleted[nv] = True
if all(f for f in deleted):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 98060
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


//複数のソート
void sort2vectors(vector<int> &av, vector<int> &bv)
{
        int n = av.size();
        vector<int> p(n), av2(n), bv2(n);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](int a, int b) { return av[a] < av[b]; });
        for (int i = 0; i < n; i++) {
                av2[i] = av[p[i]];
                bv2[i] = bv[p[i]];
        }
        av = av2;
        bv = bv2;
}


int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int isPrime(int x){
  int i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if( x%2 == 0) return 0;
  for(i = 3; i*i <= 2; i += 2){
    if(x%i == 0) return 0;
  }
  return 1;
}


const int pmax = 10000000;
bool isPrime_table[pmax];
//constがないと配列宣言できない

void eratos(void){
  int i, j;
  double sqrtmax=sqrt(pmax);

  REP(k, pmax) isPrime_table[k] = true; /* Initialization */

  /* Sieve process  */
  isPrime_table[0] = false;
  isPrime_table[1] = false;
          /* 0 and 1 are not prime. */
  for (i=2; i <= sqrtmax; i++){
    if (isPrime_table[i]==true){   /* i is prime. */
      for (j=i; i*j<pmax; j++){
        isPrime_table[i*j] = false; /* multiples of i are not prime. */
      }
    }
  }
}

//漸化式敵に記述も可能
//abs(dx[i]+dy[j])==1で四方
int dx[3]={-1, 0, 1};
int dy[3]={-1, 0, 1};
int W0, H0;
int  masu0[100][100]={0};
int cnt0;

int dfs(int a, int b){
  masu0[a][b] = 2;
  REP(i, 3)REP(j, 3){
    a = a+dx[i];
    b = b+dy[j];
    if(masu0[a][b]== 1 && a >= 0 && a < W0 && b >= 0 && b < H0){
    dfs(a, b);
  }
  }
  return 1;
}

//文字列取り出し　str.substr(i, 5)
//文字数字変換 stoi, stod とto_string
//初期化memset
//複数配列のソート
//dp
const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
const long long int MOD = 1000000007;

int main(void){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int A[2];
  int cnt5 = 0;
  int cnt7 = 0;
  REP(i, 3){
    cin >> A[i];
    if(A[i] == 5) cnt5++;
    else if(A[i] == 7 ) cnt7++; 
}
if(cnt5 == 2 && cnt7 == 1) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}


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

#define llint long long int

using namespace std;

int main(){
    int N, M;

    cin >> N >> M;

    vector<int> H(N);

    for(int i = 0; i < N; i ++){
        cin >> H[i];
    }
    vector<bool> NG(N, false);

    for(int i = 0; i < M; i ++){
        int A, B;

        cin >> A >> B;

        if(H[A - 1] <= H[B - 1]){
            NG[A - 1] = true;
        }
        if(H[B - 1] <= H[A - 1]){
            NG[B - 1] = true;
        }
    }
    int ans = 0;

    for(int i = 0; i < N; i ++){
        if(NG[i] == false){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3788
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
  std::cout<<std::fixed<<std::setprecision(10);
  int n,i;cin >> n;
  long double s = 0.000000,a;
  for (i=0;i<n;i++){
    cin >> a;
    s += 1.000000/a;
  }
  cout << 1/s << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

struct BIT {
    vector<ll> data;
    int N;

    BIT(int n) {
        N = n;
        data = vector<ll>(N+1);
    }

    void add(int i, ll x) {
        for (int k = i; k <= N; k += k&-k) data[k] += x;
    }

    ll sum(int i) {
        ll res = 0;
        for (int k = i; k > 0; k -= k&-k) res += data[k];
        return res;
    }
};

ll inversion(vi a) {
    BIT bit(2*a.size());
    ll res = 0;
    for (int i = 0; i < a.size(); i++) {
        res += i-bit.sum(a[i]-1);
        bit.add(a[i], 1);
    }
    return res;
}

const int MAX = 3e5+10;

int N;
vi S;
int cnt[26], cnt2[26], sm[26];
queue<int> idx[26];

bool check() {
    int odd = 0;
    REP (i, 26) odd += (cnt[i]&1);
    return odd <= 1;
}

ll solve() {
    if (!check()) {
        return -1;
    }

    vi ord(N), res;
    int left = 0, right = 0;
    int r = (N+1)/2;
    REP (i, N) {
        int c = S[i];
        cnt2[c]++;
        if (cnt2[c]*2-1 == cnt[c]) {
            ord[i] = r;
        } else if (cnt2[c] <= cnt[c]/2) {
            ord[i] = ++left;
            idx[c].push(left);
        } else {
            ord[i] = ++right + r;
        }
    }
    REPR (i, N) {
        int c = S[i];
        if (!idx[c].empty()) {
            res.PB(idx[c].front());
            idx[c].pop();
        }
    }
    return inversion(ord) + inversion(res);
}

int main() {
    string s;
    cin >> s;
    N = s.size();
    REP (i, N) {
        int c = s[i]-'a';
        S.PB(c);
        cnt[c]++;
    }
    cout << solve() << endl;
}

Measured memory_bytes: 10484
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n,i,j,k,x;
    cin>>n;k=0;
    vector<long long> a(n);
    for(auto &x:a)
        cin>>x;
    for(i=1;i<n;i++)
        if(a[i]<a[i-1])
        {
            k+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    cout<<k<<'\n';
    return 0;
}


Measured memory_bytes: 4836
l = [1]
p = [1]
N, X = map(int, input().split())
for i in range(N):
    l.append(l[i] * 2 + 3)
    p.append(p[i] * 2 + 1)


def calc(n, x):
    if l[n] <= x:
        return p[n]
    if x == 0 or x == 1:
        return 0
    if x <= l[n] // 2:
        return calc(n - 1, x - 1)
    elif x == l[n] // 2 + 1:
        return p[n - 1] + 1
    else:
        return p[n - 1] + 1 + calc(n - 1, x - (l[n - 1] + 2))

print(calc(N, X))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    if (mp.size() <= k) {
        cout << 0 << endl;
        return 0;
    }
    vector<p> v;
    for (auto e : mp) {
        v.push_back(p(e.second, e.first));
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    ll sum = 0;
    for (int i = k; i < v.size(); i++) {
        sum += v[i].first;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 12536
"""def problem1():
    N,K = map(int,input().split())
    S = list(input())
    S[K-1] = S[K-1].swapcase()
    print("".join(S))

def problem3():
    N,K = map(int,input().split())
    prob = 0
    for i in range(1,N+1):
        point = i
        count = 0
        while(point < K):
            point *= 2
            count += 1
        prob += 1/N * (1/2)**count
    print(prob)
"""
S = input()
a = int(S[0:2])
b = int(S[2:4])
LIST = [False,False]

if 1 <= b <= 12 and a >= 0:#YYMM
    LIST[0] = True 
if 1 <= a <= 12 and b >= 0:#MMYY
    LIST[1] = True 

if LIST[0] and LIST[1]:
    print("AMBIGUOUS")
elif LIST[0] and not LIST[1]:
    print("YYMM")
elif not LIST[0] and LIST[1]:
    print("MMYY")
else:
    print("NA")











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

using namespace std;
using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x) REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n) REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x) REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m) REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw`(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
using mint = static_modint<MOD>;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

int op(int a,int b){ return max(a,b);}
int e() {return -1;}
int target;
bool f(int v){ return v<target;}

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

void solve(){
  int N,M; cin>>N>>M;
  
  dsu d(N);
  REP(i,M){
    int a,b; cin>>a>>b;
    --a; --b;
    d.merge(a,b);
  }
  cout << d.groups().size()-1<<"\n";

}

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  solve();
  return 0;
}


Measured memory_bytes: 9008
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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 ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> cnt(4);
    rep(i,n){
        string s;
        cin >> s;
        if(s=="AC") cnt[0]++;
        else if(s=="WA") cnt[1]++;
        else if(s=="TLE") cnt[2]++;
        else cnt[3]++;
    }
    cout << "AC" << " x " << cnt[0] << endl;
    cout << "WA" << " x " << cnt[1] << endl;
    cout << "TLE" << " x " << cnt[2] << endl;
    cout << "RE" << " x " << cnt[3] << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#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++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b;
    cin >> a >> b;



    cout << max(0, a - 2 * b) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#pragma warning(disable:4996)

int d[50];
int main() {
	int n;
	while (scanf("%d", &n) != -1) {
		memset(d, 0, sizeof(d));
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d", &d[i]);
		}
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				sum += d[i] * d[j];
			}
		}
		printf("%lld\n", sum);
	}
	return 0;
}

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

int main(){
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  int ans = 0;
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    int j=0;
    while(1+A.at(i)*j<=D){
      ans++;
      j++;
    }
  }
  ans=ans+X;
  cout << ans << endl;
}

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

using namespace std;

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

    int k;
    cin >> k;

    vector<string> vt;
    for (int st = 0; st < s.size(); ++st) {
        for (int len = 1; len <= k and st + len <= s.size(); ++len) {
            vt.push_back(s.substr(st, len));
        }
    }

    sort(vt.begin(), vt.end());
    vt.erase(unique(vt.begin(), vt.end()), vt.end());

    cout << vt[k - 1] << endl;
    return 0;
}

Measured memory_bytes: 1660