akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
typedef pair<int,int> P;
const int MOD = 998244353;
const ll mod = 1e9 + 7;
const int mxN = 5e5 + 9;

int n;
int bits[mxN];
int a[mxN];
int last[mxN];
pair<int,int> query[mxN];

void update(int i, int add){
	while( i <= n ){
		bits[i] += add;
		i += i&(-i);
	}
}

int sum(int i){
	int sm = 0;
	while(i>0){
		sm += bits[i];
		i -= i&(-i);
	}
	return sm;
}

int range_sum(int L, int R){
    if( L == 1 ) return sum(R);
    return sum(R) - sum(L-1);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int q;
	cin >> n >> q;
	for(int i=1; i <= n; i++) cin >> a[i];
	memset( last, -1, sizeof(last) );
	map<int,vector<pair<int,int> > > m1;
	map<pair<int,int>, int> ans;
	//sorting m1 by R( right end )
	for(int i=1; i <= q; i++){
        int L,R;
        cin >> L >> R;
        query[i] = make_pair(L, R);
        m1[R].push_back( make_pair(L, R) );
	}

    int start = 1;
    for(auto &c: m1){
        int right_end = c.first;
        for(int i=start; i <= right_end; i++){
            if( last[a[i]] == -1 ){
                last[a[i]] = i;
                update(i, 1);
            }
            else{
                update( last[a[i]], -1 );
                last[a[i]] = i;
                update( last[a[i]], 1 );
            }
        }
        start = right_end + 1;

        for(auto &p: m1[right_end]){
            int L = p.first; int R = p.second;
            ans[ make_pair(L, R) ] = range_sum(L, R);
        }
    }

    for(int i=1; i <= q; i++) cout << ans[ query[i] ] << "\n";




}




Measured memory_bytes: 77012
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n;
  int h[21];
  scanf("%d", &n);

  rep(i, n) scanf("%d", &h[i]);

  int border = h[0];
  int ans = 0;
  rep(i, n)
  {
    if (h[i] < border)
      continue;
    border = h[i];
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int H = sc.nextInt();
	int W = sc.nextInt();
	char[][] a = new char[H+2][W+2];
	for(int i = 1; i<H+1; i++) {
	    String str = sc.next();
	    for(int j = 1; j<W+1; j++) {
		a[i][j] = str.charAt(j-1);
	    }
	}
	for(int i = 1; i<H+1; i++) {
	    for(int j = 1; j<W+1; j++) {
		if(a[i][j]=='.') {
		    System.out.print(((int)((a[i-1][j]=='#')?1:0) + (int)((a[i-1][j-1]=='#')?1:0) + (int)((a[i-1][j+1]=='#')?1:0)
				     + (int)((a[i][j]=='#')?1:0) + (int)((a[i][j-1]=='#')?1:0) + (int)((a[i][j+1]=='#')?1:0)
				      + (int)((a[i+1][j]=='#')?1:0) + (int)((a[i+1][j-1]=='#')?1:0) + (int)((a[i+1][j+1]=='#')?1:0)));
		}else {
		    System.out.print('#');
		}
	    }
	    System.out.println();
	}

    }
}

Measured memory_bytes: 23632
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n; int t,k[100],s=1;
	bool q=true;
	cin >> n;
	n--;
	cin>>k[0];
	for (int i = 1; i <= n; i++)
	{
		cin >> k[i];
		t = k[i];
		for (int j = i - 1; j >= 0; j--)
		{
			if (t < k[j]) q = false;
		}
		if (q) s++;
		q = true;
	}
	cout << s;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n)  for (int i = 0; i < n; i++)
#define loop(i,a,n)  for (int i = a; i <= n; i++)
#define deb(x) cout << #x << " = " << x <<'\n'
typedef long long ll;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if((c-a-b > 0) && 4*a*b < (c-a-b)*(c-a-b)){
        cout << "Yes";
    }else
        cout << "No";
    cout << '\n';
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, l;
vector<string> a;

bool cmp(string A, string B){
    return A < B;
}

int main(){
    ios::sync_with_stdio(0);
    cin >> n >> l;
    a.assign(n,string());
    forn(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),cmp);
    forn(i,n) cout << a[i];
    cout << "\n";
    return 0;
}

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

int main()
{
	string S, T;
	int ans = 0;

	cin >> S;
	cin >> T;

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

Measured memory_bytes: 3848
package main

import "fmt"

func main() {
	var str string
	fmt.Scan(&str)

	r := rune(str[len(str)-1])
	switch r {
	case '2', '4', '5', '7', '9':
		fmt.Println("hon")
	case '0', '1', '6', '8':
		fmt.Println("pon")
	case '3':
		fmt.Println("bon")
	}
}


Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
const ll M=1000000007;
//------------------------------------------//

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


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

struct UnionFind {
    UnionFind(int n) {
        parent = vector<int>(n, -1);
        weight = vector<int>(n, 0);
    }
    int find(int x) {
        if (parent[x] < 0)
            return x;
        else
            return parent[x] = find(parent[x]);
    }
    bool isSame(int x, int y) { return find(x) == find(y); }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            weight[x]++;
            return;
        }
        if (parent[x] < parent[y])
            swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        weight[x] += weight[y] + 1;
    }
    int getSize(int x) { return -parent[find(x)]; }
    int getWeight(int x) { return weight[find(x)]; }

private:
    vector<int> parent;
    vector<int> weight;
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    UnionFind UF(N);
    vector<ll> ans(M, N * (N - 1) / 2);
    for (int i = M - 2; i >= 0; i--) {
        if (UF.isSame(A[i + 1], B[i + 1])) {
            ans[i] = ans[i + 1];
        } else {
            ll a = UF.getSize(A[i + 1]);
            ll b = UF.getSize(B[i + 1]);
            ans[i] = ans[i + 1] - a * b;
        }
        UF.unite(A[i + 1], B[i + 1]);
    }

    for (ll& a : ans) {
        cout << a << endl;
    }
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s, t);
  sort(all(s));
  sort(all(t));
  reverse(all(t));

  puts(s < t ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    long MLT1 = 1009;
    long MLT2 = 1007;
    long MOD1 = 1000000007;
    long MOD2 = 1000000009;
    long PAIR = 261;
//    long MLT1 = 11;
//    long MLT2 = 13L;
//    long MOD1 = 23L;
//    long MOD2 = 31L;
//    long PAIR = 59;

    long[] rh1;
    long[] rh2;
    long[] pow1;
    long[] pow2;
    int n;

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        String s = " " + sc.next();
        rh1 = new long[n + 1];
        rh2 = new long[n + 1];
        pow1 = new long[n + 1];
        pow2 = new long[n + 1];

        pow1[0] = pow2[0] = 1;

        for (int i = 1; i <= n; i++) {
            rh1[i] = (rh1[i - 1] * MLT1 + (s.charAt(i) - 'a' + 1)) % MOD1;
            rh2[i] = (rh2[i - 1] * MLT2 + (s.charAt(i) - 'a' + 1)) % MOD2;
            pow1[i] = pow1[i - 1] * MLT1 % MOD1;
            pow2[i] = pow2[i - 1] * MLT2 % MOD2;
        }

//        debug(rh1);
//        debug(rh2);

        long ans = 0;
        HashMap<Pair, long[]> map = new HashMap<>();
        for (int i = 1; i <= n / 2; i++) {
            map.clear();
            for (int j = 0; j <= n - i; j++) {
                long[] g = get(j, j + i);
                Pair p = new Pair(g[0], g[1]);
                long[] set =  map.getOrDefault(p, new long[]{n, 0});
                set[0] = Math.min(set[0], j);
                set[1] = Math.max(set[1], j);
                map.put(p, set);
            }

//            debug(map);

            for (Map.Entry<Pair, long[]> entry : map.entrySet()) {
                if (entry.getValue()[0] != entry.getValue()[1]) {
                    if (entry.getValue()[1] - entry.getValue()[0] >= i) {
                        ans = i;
                    }
                }
            }
        }
        System.out.println(ans);
    }

    long[] get(int l, int r) {
        long t1 = ((rh1[r] - rh1[l] * pow1[r - l]) % MOD1 + MOD1) % MOD1;
        long t2 = ((rh2[r] - rh2[l] * pow2[r - l]) % MOD2 + MOD2) % MOD2;

        return new long[] {t1, t2};
    }

    class Pair implements Comparable<Pair> {
        long s1, s2;
        Pair(long s1, long s2) {
            this.s1 = s1;
            this.s2 = s2;
        }

        @Override
        public int compareTo(Pair o) {
            if (s1 != o.s1) {
                return Long.compare(s1, o.s1);
            }
            return Long.compare(s2, o.s2);
        }

        @Override
        public int hashCode() {
            return Long.hashCode(s1 * PAIR + s2);
        }

        @Override
        public boolean equals(Object obj) {
            if (obj instanceof Pair) {
                Pair o = (Pair) obj;
                return s1 == o.s1 && s2 == o.s2;
            }
            return false;
        }

        @Override
        public String toString() {
            return String.format("(%d, %d)", s1, s2);
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

}


Measured memory_bytes: 274464
#include <stdio.h>
#define MAX 100000

int M[MAX],n;

int par(int p,int r){
    int i,j,x,v;
    
    x = M[r];
    i = p - 1;
    for(j=p;j<r;j++){
        if(M[j] <= x){
            i++;
            v = M[i];
            M[i] = M[j];
            M[j] = v;
        }
    }
    v = M[i+1];
    M[i+1] = M[r];
    M[r] = v;
    return i+1;
}

int main(){
    int i,x;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++)
        scanf("%d",&M[i]);
    
    x = par(0,n-1);
    
    for(i=0;i<n;i++){
        if(i>0) printf(" ");
        if(i==x) printf("[");
        printf("%d",M[i]);
        if(i==x) printf("]");
    }
    printf("\n");
   
    return 0;
}



Measured memory_bytes: 2120
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll h, w;
  cin >> h >> w;
  vs s(h);
  rep(i, h){
    cin >> s[i];
  }
  int di[4] = {1, -1, 0, 0};
  int dj[4] = {0, 0, 1, -1};
  vvi visited(h, vi(w, 0));
  auto dfs = [&](auto& Self, int i, int j) -> ll{
    visited[i][j] = 1;
    ll ret = 1;
    rep(k, 4){
      int ni = i + di[k];
      int nj = j + dj[k];
      if(ni < 0 || ni >= h
      || nj < 0 || nj >= w)
        continue;
      if(s[ni][nj] == '#' && !visited[ni][nj]){
        ret += Self(Self, ni, nj);
      }
    }
    return ret;
  };
  //dfs(dfs, 0, 0);
  rep(i, h)rep(j, w){
    if(s[i][j] == '#' && !visited[i][j] && dfs(dfs, i, j) <= 1){
      Pr(0);
    }
  }
  Pr(1);
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n, m, Sum = 0;
  cin >> n >> m;
  int a[m];
  for (int i = 0; i < m; i++)
  {
    cin >> a[i];
    Sum += a[i];
  }
  if (Sum>n) {
    printf("-1\n");
  } else {
    cout << n - Sum << endl;
  }
}

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

l = []
a = []
for i in range(n):
    s = int(input())
    l.append(s)
    if s%10 != 0:
        a.append(s)

S = sum(l)
    
if S%10 != 0:
    print(S)
elif len(a) >= 1:
    print(S-min(a))
else:
    print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int r, g, b, n;cin>>r>>g>>b>>n;
  int ans=0;
  if(r<g)swap(r, g);
  if(g<b)swap(g, b);
  for(int i=0;i<=(n/r);i++){
    for(int j=0;j<=((n-r*i)/g);j++){
      int num = n-r*i-g*j;
      ans += (num>=0 && num%b == 0);
    }
  }
  cout<<ans<<endl;
}


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

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

using namespace std;

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  if (a < b) {
    if (a + w > b) {
      cout << 0 << endl;
    } else {
      cout << b - (a + w) << endl;
    }
  } else {
    if (b + w > a) {
      cout << 0 << endl;
    } else {
      cout << a - (b + w) << 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;
typedef long long ll;

int a[3][3];
int d[3][3];

int main() {
    rep(i,3)rep(j,3) cin >> a[i][j];
    int n;
    cin >> n;
    rep(ni,n) {
        int x;
        cin >> x;
        rep(i,3)rep(j,3) if (a[i][j] == x) d[i][j] = 1;
    }
    bool ans = false;
    rep(i,3) {
        int cnt = 0;
        rep(j,3) cnt += d[i][j];
        if (cnt == 3) ans = true;
    }
    rep(i,3) {
        int cnt = 0;
        rep(j,3) cnt += d[j][i];
        if (cnt == 3) ans = true;
    }
    {
        int cnt = 0;
        rep(j,3) cnt += d[j][j];
        if (cnt == 3) ans = true;
    }
    {
        int cnt = 0;
        rep(j,3) cnt += d[j][2-j];
        if (cnt == 3) ans = true;
    }
    puts(ans?"Yes":"No");
    return 0;
}

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

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

template<class T>
T Max(T a, T b) {
    return (a < b) ? b : a;
}

template<class T>
T Min(T a, T b) {
    return (a < b) ? a : b;
}

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int dp[100000][3];
int cost[100000][3];

int main() {

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

    ll a, b, c, k; cin>> a>>b>>c>>k;
    ll res = a;
    ll B = b;
    a -= k;
    if(a >= 0) {
        cout << k  << '\n';
    }else {
        k -= res;
        b -= k;
        if(b >= 0) {
            cout << res << '\n';
        }else {
            k -= B;
            cout << res - k << '\n';
        }
    }
    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



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

struct Node {
    int key;
    Node *parent, *left, *right;
};
Node *root, *NIL;

void insert(int k) {
    Node *y = NIL; //xの親
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

string find(int tgt) {
    Node *x = root;
    while (x != NIL) {
        if (tgt == x->key) {
            return "yes";
        } else if (tgt < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    return "no";
}

void inOrder(Node *u) {
    if (u == NIL) return;
    inOrder(u->left);
    cout << " " << u->key;
    inOrder(u->right);
}

void preOrder(Node *u) {
    if (u == NIL) return;
    cout << " " << u->key;
    preOrder(u->left);
    preOrder(u->right);
}

int main() {
    int m, k;
    cin >> m;
    string order;
    for (int i = 0; i < m; i++) {
        cin >> order;
        if (order == "insert") {
            cin >> k;
            insert(k);
        }
        if (order == "print") {
            inOrder(root);
            cout << endl;
            preOrder(root);
            cout << endl;
        }
        if (order == "find") {
            cin >> k;
            cout << find(k) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 21816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n, a, dist[505][505], ans, dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};
bool occ[505][505];

void bfs(int x, int y) {
	queue<pi> q; q.push(pi(x, y));
	while (!q.empty()) {
		auto [x, y] = q.front(); q.pop();
		FOR(i, 0, 3) {
			int nx = x + dx[i], ny = y + dy[i];
			if (nx < 1 or ny < 1 or nx > n or ny > n) continue;
			int nd = dist[x][y] + occ[nx][ny];
			if (nd < dist[nx][ny]) {
				dist[nx][ny] = nd;
				q.push(pi(nx, ny));
			}
		}
	}
}

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) FOR(j, 1, n) {
		dist[i][j] = min({i-1, j-1, n-i, n-j});
		occ[i][j] = 1;
	}
	FOR(i, 1, n*n) {
		cin >> a;
		int r = (a-1)/n + 1, c = (a-1)%n+1;
		ans += dist[r][c];
		dist[r][c]--;
		occ[r][c] = 0;
		bfs(r, c);
	}
	cout << ans;
}


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

int main(){
    int X;  cin >> X;
    int N = 1e6;
    vector<bool> isPrime(N, true);
    isPrime[0] = false;
    isPrime[1] = false;
    isPrime[2] = true;
    for(int i=2; i<N; i++){
        if(!isPrime[i]) continue;
        if(i >= X){
            cout << i << endl;
            return 0;
        }
        for(int n=2; n*i<N; n++){
            isPrime[n*i] = false;
        }
    }
}   

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

using namespace std;

int main()
{
    string name;
    int S, h, m, s;
    
    cin >> S;
    h = S / 3600;
    m = S % 3600 / 60;
    s = S % 3600 % 60;
    
    
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N>> M;
  vector<pair<int ,int>> p(N);
  vector<pair<int ,int>> ch(M);
    for(int i = 0;i <N;i++){
    cin >> p[i].first >> p[i].second;
    }
  for(int i = 0;i <M;i++){
     cin >> ch[i].first >> ch[i].second;
    }
  for(int i = 0;i <N;i++){
    vector<pair<int ,int>> D(M);//各学生とチェックポイントの距離を入れる配列
    for(int j = 0;j <M;j++){
      D[j].first = abs(p[i].first-ch[j].first) + abs(p[i].second-ch[j].second);
      D[j].second = j+1;
    }
    sort(D.begin(), D.end());
    cout << D[0].second << endl;
    D.clear();
  }
      
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	a, _ := strconv.Atoi(stringLineScan())
	b, _ := strconv.Atoi(stringLineScan())
	d := 1000000007
	x := repeatPaw(2, n, d) - 1
	cal, car, cbl, cbr := 1, 1, 1, 1
	for i := 1; i <= a; i++ {
		cal *= n - i + 1
		car *= i
		cal %= d
		car %= d
	}
	for i := 1; i <= b; i++ {
		cbl *= n - i + 1
		cbr *= i
		cbl %= d
		cbr %= d
	}
	ans := (x - cal*modinv(car, d)%d - cbl*modinv(cbr, d)%d) % d
	if ans < 0 {
		ans += d
	}
	fmt.Println(ans)
}
func modinv(a, m int) int {
	b, u, v := m, 1, 0
	for {
		t := a / b
		a -= t * b
		u -= t * v
		a, b, u, v = b, a, v, u
		if b == 0 {
			break
		}
	}
	u %= m
	if u < 0 {
		u += m
	}
	return u
}
func repeatPaw(x, y, d int) int {
	if y == 1 {
		return x
	} else {
		z := repeatPaw(x, y/2, d)
		if y%2 == 0 {
			return z * z % d
		} else {
			return z * z % d * x % d
		}
	}
}


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

const int K = 65;
long long cnt[K][K];

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

    int n;
    cin>>n;

    long long ans = 0;

    for (int i=1; i<=n; i++) {
        double d;
        cin>>d;

        long long x = round(d*1000000000);

        int p2 = 0, p5 = 0;
        while (x%2 == 0) x/=2, p2++;
        while (x%5 == 0) x/=5, p5++;
        cnt[p2][p5]++;
        if (p2>=9 && p5>=9) ans--;
    }

    for (int i2=0; i2<K; i2++) {
        for (int i5=0; i5<K; i5++) {
            if (cnt[i2][i5] == 0)   continue;

            for (int j2=0; j2<K; j2++) {
                for (int j5=0; j5<K; j5++) {
                    if (i2+j2>=18 && i5+j5>=18)
                    ans += cnt[i2][i5]*cnt[j2][j5];
                }
            }
        }
    }
    cout<<ans/2<<endl;
}


Measured memory_bytes: 3764
n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
for i in range(len(a)):
	if a[i] < 0:
		cnt += 1
		a[i] *= -1

if cnt % 2 == 0:
	print(sum(a))
else:
	a[a.index(min(a))] *= -1
	print(sum(a))

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

ll func(ll n){
    if(n==0){
        return 1;
    }else{
        return (n*func(n-1)) % mo;
    }
}

int main(){
    ll N, M;
    cin >> N >> M;
    if(abs(N-M) > 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = func(N)*func(M);
    if(abs(N-M) == 0){
        ans *= 2;
    }

    cout << ans % mo << endl;
}


Measured memory_bytes: 1792
import collections,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n,q=LI()
ab=[LI() for _ in range(n-1)]
px=[LI() for _ in range(q)]
ans=[0]*(n+1)
graph={i:collections.deque() for i in range(1,n+1)}
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
for p,x in px:
    ans[p]+=x
seen=[0]*(n+1)
stack=[]
def dfs():
    seen[1]=1
    stack.append(1)
    while stack:
        s=stack.pop()
        if not graph[s]:
            continue
        for j in range(len(graph[s])):
            gno=graph[s].popleft()
            if seen[gno]:
                continue
            seen[gno]=1
            stack.append(gno)
            ans[gno]+=ans[s]
dfs()
print(*ans[1:])

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

int main()
{
  int i,n,a[100];

  cin>>n;
  for(i=0;i<n;i++)
    cin>>a[i];
  for(i=n-1;i>=0;i--){
    if(i) cout<<a[i]<<" ";
    if(!i) cout<<a[0]<<endl;
  }
}


Measured memory_bytes: 1160
import sys

iN = int(sys.stdin.readline())
dS = {"M":0,"A":0,"R":0,"C":0,"H":0}
for s in [_ for  _ in sys.stdin.readlines() if _[0] in ("M","A","R","C","H")]:
    dS[s[0]] += 1
m = dS["M"]
a = dS["A"]
r = dS["R"]
c = dS["C"]
h = dS["H"]
print(m*a*r + m*a*c + m*a*h + m*r*c+m*r*h + m*c*h + a*r*c + a*r*h +a*c*h+ r*c*h)


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

int main()
{
 int n;
 cin >> n;
 string s[n];
 int a;
 for(a=0;a<n;a++){cin >> s[a];}
 int m;
 cin >> m;
 string t[m];

int max=0;
 for(a=0;a<m;a++){cin >> t[a];}
 for(a=0;a<n;a++){
  int now=0;
  for(int b=0;b<n;b++){
   if(s[a]==s[b]){now++;}
  }
  for(int b=0;b<m;b++){
   if(s[a]==t[b]){now--;}
  }
  if(max<now){max=now;}
 }
cout << max <<endl;
}

Measured memory_bytes: 256
n,m=[int(x) for x in input().rstrip().split()]
flag = 1
l=[-1 for i in range(n)]
for i in range(m):
    s,c = [int(x) for x in input().rstrip().split()]
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        flag =0
        break
        

ans = ""
if flag == 0 or (n!=1 and l[0]==0):
    print(-1)
else:
    for i in range(len(l)):
        if l[i]==-1:
            if i==0 and n!=1:
                ans+=str(1)
            elif i==0 and n==1:
                ans+=str(0)
            else:
                ans+=str(0)
        else:
            ans+=str(l[i])
    print(ans)












Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

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

    if (s == "ABC") {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }

    return 0;
}


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



int main() {
    ll N,A,B;
    cin>>N>>A>>B;
    ll x=N/(A+B),y=N%(A+B);
    ll ans=x*A;
    ans+=min(y,A);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
all = input()
while True:
  try:
    str = raw_input()
    if str == '=':
      print all
      break
    num = input()
    if str == '+':
      all += num
    elif str == '-':
      all -= num
    elif str == '*':
      all = all * num
    elif str == '/':
      all = all / num
  except EOFError:
    break


Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  if(a==25){
    cout<<"Christmas"<<endl;
  }else if(a==22){
    cout<<"Christmas Eve Eve Eve"<<endl;
  }else if(a==23){
    cout<<"Christmas Eve Eve"<<endl;
  }else{
    cout<<"Christmas Eve"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}


int main()
{
    int x; cin >> x;
    vector<int> prime;

    prime.push_back(2);
    int i = 3;
    if (x == 2) {
        cout << 2 << endl; return 0;
    }
    while (true) {
        int flag = 1;
        rep(j,prime.size()) {
            if (i % prime[j] == 0) {
                flag = 0;
                break;
            }
        }
        if (flag) {
            prime.push_back(i);
        }
        i++;

        if (prime[prime.size() - 1] >= x) {
            break;
        }
    }
    cout << prime[prime.size() - 1] << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll par[100005],sz[100005];
ll find(ll i){
	if(par[i]==i)
		return i;
	return par[i]=find(par[i]);
}
void merge(ll x,ll y){
	x=find(x),y=find(y);
	if(x==y)
		return;
	if(sz[x]<sz[y])
		swap(x,y);
	par[y]=x;
	sz[x]+=sz[y];
}
void solve(){
	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=n;i++){
		par[i]=i;
		sz[i]=1;
	}
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		merge(x,y);
	}
	ll res=0;
	for(ll i=1;i<=n;i++)
		if(par[i]==i)
			res++;
	cout<<res-1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

struct UF {
  vector<int> parent_, rank_;

  UF(int N) : parent_(N + 5), rank_(N + 5, 1) {
    for (int i = 0; i <= N; ++i) {
      parent_[i] = i;
    }
  }

  int find_set(int x) {
    if (x != parent_[x]) {
      parent_[x] = find_set(parent_[x]);
    }
    return parent_[x];
  }

  void unite(int x, int y) {
    int a = find_set(x), b = find_set(y);
    if (a == b) { return; }
    if (rank_[a] > rank_[b]) {
      parent_[b] = a;
    }
    else {
      parent_[a] = b;
      if (rank_[a] == rank_[b]) { ++rank_[b]; }
    }
  }

  bool is_connected(int x, int y) {
    return find_set(x) == find_set(y);
  }

};

int main()
{
  int N; scanf("%d", &N);
  vector<pair<ll, int>> X(N), Y(N);
  ll x, y;
  for (int i = 0; i < N; ++i) {
    scanf("%lld %lld", &x, &y);
    X[i] = make_pair(x, i);
    Y[i] = make_pair(y, i);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  vector<pair<ll, pair<int, int>>> edges;
  for (int i = 0; i + 1 < N; ++i) {
    edges.push_back(make_pair(abs(X[i].first - X[i + 1].first),
                              make_pair(X[i].second, X[i + 1].second)));
    edges.push_back(make_pair(abs(Y[i].first - Y[i + 1].first),
                              make_pair(Y[i].second, Y[i + 1].second)));
  }

  sort(edges.begin(), edges.end());
  ll ans = 0;
  UF uf(N + 5);
  for (int i = 0; i < (int)edges.size(); ++i) {
    ll d = edges[i].first;
    int u = edges[i].second.first, v = edges[i].second.second;
    if (uf.is_connected(u, v)) { continue; }
    uf.unite(u, v);
    ans += d;
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
    string S, T;
    cin  >> S >> T;
    vector<int> start(26, -1), goal(26, -1);
    for (int i = 0; i < S.length(); i++){
        int a = S[i] - 'a';
        int b = T[i] - 'a';
        if (start[a] != -1 || goal[b] != -1){
            if (start[a] != b || goal[b] != a){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            start[a] = b;
            goal[b] = a;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <type_traits>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}



template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  //printVec(va.begin(), va.end());
  ll step = 0;
  while (step != N-1) {
    lsort(va);
    for (ll i = step; i < N; i++) {
      if (va[i] == 0) {
	step++;
      }
    }
    for (ll i = step+1; i < N; i++) {
      va[i] %= va[step];
    }
  }

  print(va[N-1]);
  return 0;
}


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

int main() {
	string A, B, C;
	cin >> A >> B >> C;
	string judge = "YES";
	if (A[A.size() - 1] != B[0] || B[B.size() - 1] != C[0]) {
		judge = "NO";
	}
	cout << judge << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Read();
            switch (s)
            {
                case "SUN":
                    WriteLine("7");
                    break;
                case "MON":
                    WriteLine("6");
                    break;
                case "TUE":
                    WriteLine("5");
                    break;
                case "WED":
                    WriteLine("4");
                    break;
                case "THU":
                    WriteLine("3");
                    break;
                case "FRI":
                    WriteLine("2");
                    break;
                case "SAT":
                    WriteLine("1");
                    break;
                default:
                    break;
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
	
typedef long long v;
typedef long long b;

static const int MAX = 200000;


int main() {
	int n;
	cin >> n;
	int x = n, c=0;
	while (x > 0) {
		c += x % 10;
		x = x / 10;
	}
	if (n % c == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}










Measured memory_bytes: 256
n, g = gets.chomp.split.map(&:to_i)
a = Array.new(n) { Array.new }

n.times do |i|
  a[i] = gets.chomp.split
end

sum = 0
for i in 0..n-1 do
  if a[i][1] == 'JPY'
    sum += a[i][0].to_i
  else
    sum += a[i][0].to_f * 380000.0
  end
end

puts sum

Measured memory_bytes: 1788
#include <stdio.h>

int main(){
    int i,j,k,n,b,f,r,v;
    int count[4][5][10]={0};
    
    scanf("%d\n",&n);
    
    for(i=0;i<n;i++){
        scanf("%d %d %d %d\n",&b,&f,&r,&v);
        count[b-1][f-1][r-1] += v;
    }
    
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",count[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3){
            printf("####################\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int GCD(int m,int n){
	int remain;
	if((remain = m % n) == 0)return n;
	else return GCD(n,remain);
}

int main(){
	int n;
	cin >> n;
	ll k,a[n];
	cin >> k;
	REP(i,n) cin >> a[i];
	ll ans = a[0],mx = a[0];
	for(int i = 1; i < n; i++){
		ans = GCD(ans, a[i]);
		mx = max(mx, a[i]);
	}
	if(k % ans == 0 && k <= mx) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: u64 = read();
    let s: Vec<Vec<char>> = (0..n).map(|_| read::<String>().chars().collect()).collect();

    let mut start_b: u64 = 0;
    let mut end_a: u64 = 0;
    let mut both: u64 = 0;
    let mut ret: u64 = 0;

    for c in &s {
        if c[0] == 'B' && c[c.len() -1] == 'A' {
            both += 1;
        } else if c[c.len() - 1] == 'A' {
            end_a += 1;
        } else if c[0] == 'B' {
            start_b += 1;
        }

        for i in 1..(c.len()) {
            if c[i - 1] == 'A' && c[i] == 'B' {
                ret += 1;
            }
        }
    }

    if both == 0 {
        ret += min(start_b, end_a);
    } else if start_b == 0 && end_a == 0 {
        ret += both - 1;
    } else {
        ret += both + min(end_a, start_b);
    }
    println!("{}", ret);
}


Measured memory_bytes: 2736
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
ll sum = 0 ;     ll n,k;
 cin>>n>>k;
vector<int> v(n);
for(int i = 0 ; i<n ; i++) cin>>v[i]; sort(v.begin(),v.end());
for(int i = 0 ;i<k ;i++) sum+=v[i];
cout<<sum<<endl;
}

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

int main() {
  int n;
  int a = 0, b = 0, c = 0, d = 0;
  cin >> n;
  for(int i=0;i<n;i++) {
    string s;
    cin >> s;
    if(s == "AC") a++;
    else if(s == "WA") b++;
    else if(s == "TLE") c++;
    else if(s == "RE") d++;
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

struct State { int b, w, empty; };
State operator+(const State& a, const State& b) {
    return { a.b+b.b, a.w+b.w, a.empty+b.empty };
}
int dir[] = { -1, 0, 1, 0, -1 };

int w, h;
vector<string> A;
vector<vector<int>> vis;

State dfs(int y, int x) {
    if (y < 0 || y >= h || x < 0 || x >= w) return { 0, 0, 0 };
    if (A[y][x] == 'B') return { 1, 0, 0 };
    if (A[y][x] == 'W') return { 0, 1, 0 };
    if (vis[y][x]) return { 0, 0, 0 };
    vis[y][x] = 1;
    if (A[y][x] == '.') {
        State sum = { 0, 0, 1 };
        loop (4, i) sum = sum + dfs(y + dir[i], x + dir[i + 1]);
        return sum;
    }
}

int main()
{
    while (1) {
        cin >> w >> h;
        if (!w) break;
        A = vector<string>(h);
        vis = vector<vector<int>>(h, vector<int>(w));

        loop (h, i) cin >> A[i];

        int ans_b = 0, ans_w = 0;
        loop (h, i) loop (w, j) {
            auto rt = dfs(i, j);
            if (rt.b && rt.w) continue;
            if (rt.b) ans_b += rt.empty;
            if (rt.w) ans_w += rt.empty;
        }

        cout << ans_b << " " << ans_w << endl;
    }
    return 0;
}

Measured memory_bytes: 3432
from collections import deque


def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    A.sort(reverse=True)
    D = deque([A[0]])
    ans = 0
    for i in range(1, n):
        D.extend([A[i], A[i]])
        ans += D.popleft()

    print(ans)


if __name__ == '__main__':
    main()


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

template
<
    typename TYPE,
    std::size_t SIZE
>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a,i,n) for(ll (i) = a ; (i) < (n) ; ++(i))
#define REP(i,n) REPS(0,i,n)

const int INF = 100001;

ll d,n;
vi v;

int main()
{
    cin >> d >> n;
    REPS(1,i,1100001){
        ll tn = i;
        int c = 0;
        while(tn%100==0){
            c++;
            tn /= 100;
        }
        if(c == d){
            v.push_back(i);
        }
    }
    cout << v[n-1] << endl;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

void swap(int& x, int& y) {
  int tmp = x;
  x = y;
  y = tmp;
}

int main() {
  int w, n;
  int ws[30];
  cin >> w;
  REP(i,w) { ws[i] = i+1; }
  cin >> n;
  REP(i,n) { 
    string s;
    int a, b;
    cin>>s;
    a=atoi((s.substr(0,s.find(","))).c_str());
    b=atoi((s.substr(s.find(",")+1)).c_str());
    swap(ws[a-1], ws[b-1]);
  }
  REP(i,w) { cout << ws[i] << endl; }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
long double PI = acos(-1.0L);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, H, M;
    cin >> A >> B >> H >> M;
    long double a = 2 * PI * M / 60;
    long double b = 2 * PI * (H * 60 + M) / (12 * 60);
    cerr << a << " " << b << endl;
    long double theta = a - b;
    long double ans = A * A + B * B - 2 * A * B * cos(theta);
    ans = pow(ans, 0.5);
    cout << fixed << setprecision(30) << ans << endl;
    return 0;
}

Measured memory_bytes: 4108
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        int[] bunpu = new int[110];
        for (int i = 0; i < n; i++) {
            bunpu[p[i]]++;
        }
        for (int i = 105; i >= 0; i--) {
            bunpu[i] += bunpu[i+1];
        }
        for (int i = 105; i > 0; i--) {
            if(bunpu[i] >= i) {
                System.out.println(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 26332
#include <stdio.h>

void is_possible(int A, int B, int X) {

    if(X >= A && X <= (A + B)) {
        printf("YES");
    }

    else {
        printf("NO");
    }

    printf("\n");

}

int main() {
    int A, B, X;

    scanf("%d %d %d", &A, &B, &X);

    is_possible(A, B, X);

    return 0;
}

Measured memory_bytes: 128