akhauriyash/Code-Regression huggingface dataset:
/**
 * B - Two Anagrams
 */

#include <iostream>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
alp = [chr(i) for i in range(65,65 +26)]
i = 0
l = []
while i < len(s):
  num = alp.index(s[i])
  l.append(alp[(num + n)%26])
  i += 1
print(''.join(l))

Measured memory_bytes: 3188
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main()  {
	var h, w int
	fmt.Scan(&h, &w)

	scanner := bufio.NewScanner(os.Stdin)
	s := make([]string, h)
	l, r, u, d := make([][]int, h),  make([][]int, h),  make([][]int, h),  make([][]int, h)
	for i:=0;i<h;i++ {
		l[i], r[i], u[i], d[i] = make([]int, w),  make([]int, w),  make([]int, w),  make([]int, w)
		scanner.Scan()
		s[i] = scanner.Text()
	}
	for i:=0;i<h;i++ {
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				l[i][j] = 0
			} else if j == 0 {
				l[i][j] = 1
			} else {
				l[i][j] = l[i][j-1] + 1
			}

			if s[i][j] == '#' {
				u[i][j] = 0
			} else if i == 0 {
				u[i][j] = 1
			} else {
				u[i][j] = u[i-1][j] + 1
			}
			if s[h-1-i][w-1-j] == '#' {
				r[h-1-i][w-1-j] = 0
			} else if j == 0 {
				r[h-1-i][w-1-j] = 1
			} else {
				r[h-1-i][w-1-j] = r[h-1-i][w-j]+1
			}
			if s[h-1-i][w-1-j] == '#' {
				d[h-1-i][w-1-j] = 0
			} else if i == 0 {
				d[h-1-i][w-1-j] = 1
			} else {
				d[h-1-i][w-1-j] = d[h-i][w-1-j]+1
			}
		}
	}

	max := 0
	for i:=0;i<h;i++ {
		for j:=0;j<w;j++ {
			max = int(math.Max(float64(max), float64(l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)))
		}
	}
	fmt.Println(max)
}

Measured memory_bytes: 138240
A=[1,3,5,7,8,10,12]
B=[4,6,9,11]
C=[2]
x,y=map(int,input().split())

if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
    print("Yes")
else:
    print("No")

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

int main(int argc, const char * argv[]) {
    int n;
    string s, ans;
    
    stack<char> st;
    pair<int, int> cnt;
    
    //初期化
    cnt.first = cnt.second = 0;
    
    //入力
    cin >> n;
    cin >> s;
    
    for (int i = 0; i < n; i++) {
        if (s[i] == '(') {
            st.push(s[i]);
        }else if(s[i] == ')'){
            if (st.empty() == true) {
                cnt.first++;
            }else if (st.top() == ')') {
                cnt.first++;
            }else if(st.top() == '('){
                st.pop();
            }
        }
    }
    if (st.empty()!=true) {
        cnt.second = st.size();
    }
    
    for (int i = 0; i < cnt.first; i++) {
        cout << '(';
    }
    cout << s;
    for (int i = 0; i < cnt.second; i++) {
        cout << ')';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

inline int readin(){
	int x=0,c;
	bool f=0;
	for (;(c=getchar())<'0'||c>'9';f|=c=='-');
	for (;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+c-48;
	return f?-x:x;
}

int a[200005];

int main(){
	int n=readin(),k=readin();
	int x=-233,ans=2147483647;
	for (int i=1;i<=n;i++){
		a[i]=readin();
		if (!a[i]) x=i;
		if (x==-233&&a[i]>0){
			x=i;
			a[i+1]=a[i];
			a[i++]=0;
			k++,n++;
		}
	}
	if (x==-233) a[x=++n]=0,k++;
	for (int i=x;i;i--) if (i+k-1<=n){
		int tmp=a[i+k-1]-a[i]*2;
		if (tmp<ans) ans=tmp;
	}
	for (int i=x;i<=n;i++) if (i-k+1>=1){
		int tmp=a[i]*2-a[i-k+1];
		if (tmp<ans) ans=tmp;
	}
	printf("%d",ans);
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int X, W, Y, Z, n, A[CMax], B[CMax], ats;

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

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    Y = A[n-1];
    ats = abs(Y - Z);

    if (n > 1) X = A[n-2];
    for (int i = n-2; i > 0; i--) {
        if (abs(A[i] - Y) > ats && abs(A[i] - Y) <= abs(X - Y)) {
            ats = abs(A[i] - Y);
            X = A[i];
        }
    }

    printf("%d\n", ats);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;

void solve()
  {
     int n;
     cin>>n;
     int a[n];
     int sum = 0;
     loop(i,0,n)
      cin>>a[i];
     loop(i,0,n)
      {
        loop(j,0,n)
         if(i!=j)
           sum += a[i]*a[j];
      }
    cout<<sum/2;
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 

     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map> 
#include<bitset>
#include<vector>
using namespace std;
#define re register int
inline int read(){
    int x=0,ff=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return x*ff;
}
int x,s,n,y;
signed main(){
	x=read();n=read();
	for(re i=1;i<=n;i++){y=read();s+=y;}
	if(s>=x)puts("Yes");
	else puts("No");
   	return 0;
}


Measured memory_bytes: 256
import sys
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
ans=0
if n==1:
    print(a1[0]+a2[0])
    sys.exit()
for i in range(n-1):
    tmp=a2[n-1]
    for j in range(i+1):
        tmp+=a1[j]
    for k in range(i,n-1):
        tmp+=a2[k]
    if tmp>ans:
        ans=tmp
print(ans)

Measured memory_bytes: 3064
n = int(input())
ans = []
if n % 2 == 0:
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            if j != n-i+1:
                ans.append([i,j])
else:
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if j != n-i:
                ans.append([i,j])
print(len(ans))
for i, j in ans:
    print(i,j)

Measured memory_bytes: 4124
#include <bits/stdc++.h>
using namespace std;
int N,W;vector<int64_t>dp(100010,0);
void solve(){
    cin>>N>>W;
	for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        for(int j=W;j>=a;j--)dp[j]=max(dp[j],dp[j-a]+b);
    }
    cout<<dp[W]<<endl;
}

int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
	char start = '0';
	int cnt1 = 0, cnt2 = 0;
	string s;
	cin >> s;
	for(int i = 0 ; i < (int)s.size() ; i++){
		cnt1 += s[i] != start;
		if(start == '0') 	start = '1';
		else 				start = '0';
	}

	start = '1';
	for(int i = 0 ; i < (int)s.size() ; i++){
		cnt2 += s[i] != start;
		if(start == '0') 	start = '1';
		else 				start = '0';
	}

	cout << min(cnt1, cnt2);
	return 0;
}


Measured memory_bytes: 512
n = input()
t = ["dream", "dreamer", "erase", "eraser"]

while True:
  if not n:
    status = "YES"
    break

  elif n[-5:] in t:
    n = n[:-5]
    
  elif n[-6:] in t:
    n = n[:-6]
  
  elif n[-7:] in t:
    n = n[:-7]
    
  else:
    status = "NO"
    break
    
print(status)

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N;
string S;
unordered_map<char, ll> M;

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

  cin >> N;
  cin >> S;
  rep(i, N){
   char s = S[i];
   if (M.count(s) > 0){
     M[s]+=1ll;
   } else {
     M[s]=1ll;
   }
  }

  ll cnt = 1ll;

  for (auto it=M.begin(); it !=M.end(); ++it){
    ll v = it->second;
    cnt*=(v+1);
    cnt %= MOD;
  }
  cnt+=MOD-1;
  cnt%=MOD;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    in >> N;
    //vector<ll> X(N);
    if(N==1){
        out << 1 << endl;
    }else{
        out << pow(N,3) << endl;
    }
    

}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,m,d=map(int,input().split())
    ans=0
    if d==0:
        print((m-1)/n)
    else:
        print(2*(n-d)*(m-1)/n**2)

if __name__=='__main__':
    main()

Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}

int main() {
	int n, x;
	int a[100];
	scanf("%d %d", &n, &x);
	REP(i, n) {
		scanf("%d", &a[i]);
	}
	QSort(a, 0, n - 1, 1);
	int ans = 0;
	REP(i, n) {
		if (x < a[i]) break;
		if (i == n - 1 && x != a[i]) break;
		x -= a[i];
		ans++;
	}
	PRINTD(ans);
}

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 


#define PI 3.14159265358979323846264

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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

int main(){

    bool flag=false;

    double ans=0,sum=0;
    
    double a,b,x;
    cin >>a>>b>>x;
    double theta=0;

    if(x >= a*a*b/2){

        double p = (a*a*b-x)/(a*a*a/2);
        theta = atan(p);



    }else{
        double p = a*b*b/(2*x);
        theta = atan(p);
    }

    ans = (theta/(2*PI))*360;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout <<fixed<<setprecision(16)<< ans << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
//#include <io.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <fstream>
#define pi acos(-1.0)

using namespace std;

int a[100005];

int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int gcc;
    int ma=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        gcc=i?gcd(a[i],gcc):a[i];
        ma=max(ma,a[i]);
    }
    if(k<=ma&&gcd(k,gcc)==gcc)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");

    return 0;
}

Measured memory_bytes: 640
program example
	implicit none

	integer :: A,B,C,count=0
    
    read(*,*) A,B,C
    
    if (A==B .or. B==C .or. A==C) then
    	if (A==B) then
        	count=count+1
        end if
        
        
        if (B==C) then
        	count=count+1
        end if
        
        if (A==C) then
        	count=count+1
        end if
    end if
    
    if (count==1) then
    	write(*,*) "Yes"
    else
    	write(*,*) "No"
    end if
  
end program example

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

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define pb push_back

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

const int N = 1e6 + 5;

int d, g;
int p[11], c[11];
short dp[10][11000001];
short solve(int idx, int lft){
    if(lft <= 0)return 0;
    if(idx == d)return 10 * 100;
    short &ret = dp[idx][lft];
    if(~ret)return ret;
    ret = 10 * 100;
    for(int j = 0; j <= p[idx]; j++){
        ret = min(ret, (short)(solve(idx+1,lft - (idx + 1) * j - (c[idx] * (j==p[idx]))) + j));
    }
    return ret;
}
int main(){

    cin >> d >> g;
    g /= 100;
    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    memset(dp,-1,sizeof dp);
    cout << solve(0,g) << '\n';
    return 0;
}


Measured memory_bytes: 215040
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                    continue
                if L[i] + L[j] > L[k]:
                    ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()

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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define dbg(x) #x << ": " << x <<
#define sz(x) ((int)x.size())

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

	char c; cin >> c; cout << (char)(c + 1);
}

Measured memory_bytes: 256
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  string s = to_string(N);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '7') {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3708
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
typedef long long lnt;
const int INF = (~0U) >> 2;
const lnt INFLL = (~0ULL) >> 2;
int n, a[10010], ans, top = INF;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 2; i <= n; i++) {
		if (a[i] == a[i - 1]) {
			ans++;
			a[i] = top--;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int N, s = 0;
  cin >> N;
  vector<int> R(N);
  for (int i = 0; i < N; i++) {
    cin >> R.at(i);
  }
  for (int j = 0; j < N; j++) {
    if (R.at(j) == 0) {
      continue;
    }
    else {
      for (int k = 0; k < N; k++) {
        if(j == k) {
          continue;
        }
        else if (R.at(j) == R.at(k)) {
          R.at(k) = 0;
        }
      }
    }
    s += 1;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = Integer.parseInt(sc.nextLine());
			for (int i = 0; i < n; i++) {
				String strNum = sc.nextLine();
				System.out.println( min_max_diff(strNum) );
			}

	}

	private static int min_max_diff(String strNum) {
		Integer[] nums = new Integer[strNum.length()];

			for (int i = 0; i < strNum.length(); i++) {
				nums[i] = Integer.parseInt(String.valueOf(strNum.charAt(i)));
			}

		Arrays.sort(nums, Comparator.naturalOrder());
		int biggest = toInt(nums);

		Arrays.sort(nums, Comparator.reverseOrder());
		int smallest = toInt(nums);

		return biggest - smallest;
	}

	private static int toInt(Integer[] nums) {
		int sum = 0;

		for (int i = nums.length - 1; i >= 0; i--) {
			sum += (int)Math.pow(10, i) * nums[i];
		}


		return sum;
	}

}


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

int main() {
  int N, a, b, c, d;
  cin >> N;
  
  a = N/1000;
  b = (N/100) - (a*10);
  c = (N/10) - (a*100) - (b*10);
  d = N - (a*1000) - (b*100) - (c*10);
  
  if ( (b-c)!=0 ) {
  cout << "No" << endl;
  }
  if ( (b-c)==0 ) {
    if ( ( (a-b)==0 ) || ( (c-d)==0 ) ) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int N_MAX = 1030;
int h, w;
int ch, cw;
int dh, dw;
vector<string> m(N_MAX);
vector<vector<int>> res(N_MAX, vector<int>(N_MAX, INT_MAX));
vector<int> X = {-1, 0, 0, 1};
vector<int> Y = {0, 1, -1, 0};
queue<pair<int, int>> q, visited;


bool is_in_map(int i, int j) {
    return 0 <= i && i < h && 0<= j && j < w;
}

int main() {
    cin >> h >> w >> ch >> cw >> dh >> dw;
    rp(i, 0, h) cin >> m[i];
    ch--; cw--; dh--; dw--;
    res[ch][cw] = 0;
    q.emplace(ch, cw);
    while(!q.empty() || !visited.empty()) {
        if(!q.empty()) {
            int now_x = q.front().first; int now_y = q.front().second;
            q.pop();
            visited.push(make_pair(now_x, now_y));
            rp(i, 0, 4) {
                int next_x = now_x + X[i]; int next_y = now_y + Y[i];
                if(is_in_map(next_x, next_y)) {
                    if(m[next_x][next_y] == '.') {
                        if(chmin(res[next_x][next_y], res[now_x][now_y])) q.push(make_pair(next_x, next_y));
                    }
                }
            }
        }
        else {
            int x = visited.front().first; int y = visited.front().second; visited.pop();
            rp(i, -2, 3) {
                rp(j, -2, 3) {
                    if(is_in_map(x+i, y+j)) {
                        if(m[x+i][y+j] == '.') {
                            if(chmin(res[x+i][y+j], res[x][y] + 1)) q.push(make_pair(x+i, y+j));
                        }
                    }
                }
            }
        }
    }
    // rp(i, 0, h) {
    //     rp(j, 0, w) {
    //         if(res[i][j] == INT_MAX) printf("-1 ");
    //         else printf("%d ", res[i][j]);
    //     }
    //     cout << endl;
    // }
    if(res[dh][dw] == INT_MAX) cout << -1 << endl;
    else cout << res[dh][dw] << endl;
    return 0;
}

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

int main()
{
    int a,b,c,d;
    string s;cin>>s;
    a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';

    if(a+b+c+d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a+b+c-d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }
    else if(a+b-c+d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a-b+c+d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a-b-c+d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a-b+c-d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }
    else if(a+b-c-d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }
    else if(a-b-c-d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }
}

///Checked All possibities of operator between 4 Number for making 7


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int main() {
	int n;
	cin >> n;
	VI h(n);
	REP(i, n)
		cin >> h[i];
	if (n == 0) {
		cout << "Yes";
		return 0;
	}
	for (int i = n - 1; i >= 1; i--) {
		if (h[i] < h[i - 1] - 1) {
			cout << "No";
			return 0;
		}
		else if (h[i] < h[i - 1]) {
			h[i - 1]--;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


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

    int ans = 0;
    REP(i, n/2){
        if (s[i] != s[n - i - 1]) ans++;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  char str;
  int n,a=0,b=0;

  cin>>n;

  for(int i=0;i<n;i++){
    cin>>str>>b;
    
    if(str=='(')
      a+=b;
    else
      a-=b;
    
    if(a<0)
      break;
  }
  
  if(a<0 || a!=0)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
}



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

// 各桁の和を計算する関数
int kakuketa(int n){
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}
int main() {
  int N,sum;
cin>>N;
  sum=kakuketa(N);
  if(N%sum==0){
    cout<<"Yes"<<endl;
  }
  else{
  cout<<"No"<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int N;

int tatamikomi(int n)
{
    return min(n, N - 1 - n);
}

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

    REP(i, K)
    {
        int a,b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        a = tatamikomi(a);
        b = tatamikomi(b);
        if(a > b)
        {
            a = b;
        }
        cout << (a % 3 + 1) << endl;
    }

    return 0;
}




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

class UnionFind{
private:
    std::vector<int> parent;
public:
    UnionFind(int n) : parent(n, -1){}
    bool isSame(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        if(parent[x] < 0){
            return x;
        }else{
            return parent[x] = root(parent[x]);
        }
    }
    bool unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false;
        if(parent[rx] > parent[ry]) std::swap(rx, ry);
        parent[rx] += parent[ry];
        parent[ry] = rx;
        return true;
    }
    int size(int x){
        return -parent[root(x)];
    }
};

int friends[100010];
std::vector<int> block[100010];

int main(){
    int n, m, k;
    std::cin >> n >> m >> k;
    UnionFind uf(n);
    for(int i = 0; i < m; i++){
        int a, b;
        std::cin >> a >> b;
        a--; b--;
        friends[a]++; friends[b]++;
        uf.unite(a, b);
    }
    for(int i = 0; i < k; i++){
        int c, d;
        std::cin >> c >> d;
        c--; d--;
        block[c].push_back(d);
        block[d].push_back(c);
    }
    for(int i = 0; i < n; i++){
        int ans = uf.size(i) - 1 - friends[i];
        for(int j : block[i]){
            if(uf.isSame(i, j)){
                ans--;
            }
        }
        std::cout << ans << " ";
    }
    std::cout << std::endl;
    return 0;
}


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

using namespace std;

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

    int n, b, f, r, v, room[4][3][10] = {0};
    
    cin >> n;
    
    while (n--) {
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] += v;
    }
    
    
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << ' ' << room[i][j][k];
            }
            cout << endl;
        }
        if (i != 3) {
            cout << "####################" << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3216
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int X;
signed main(){
    scanf("%lld",&X);
    if(X>=30)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int seconds = in.nextInt();
        System.out.println(watch(seconds));
    }

    private static String watch(int seconds) {
        int h = seconds / (60*60);
        seconds = seconds % (60*60);
        int m = seconds / 60;
        int s = seconds % 60;
        return h + ":" + m + ":" + s;
    }
}


Measured memory_bytes: 26252
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

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

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    cout << s1[0] << s2[1] << s3[2] << endl;
}

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

int main() {
  string s;
  cin >> s;
  int k=0;
  int n=s.size();
  for(int i=0;i<n;i++){
    if(i%2 == 0 && s.at(i) == 'L'){
      k = -1;
      break;
    }
    else if(i%2 == 1 && s.at(i) == 'R'){
      k = -1;
      break;
    }
  }
  
  if(k== -1){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int m = N / 2;
	vector<int> B(N);
	B[N] = { 0 };
	for (int i = 0; i < N; i++) {
		B[A[i]]++;
	}
	bool flag = true;
	if (N % 2 == 0) {
		for (int i = 0; i < m; i++) {
			if (B[2 * i+1] != 2) {
				flag = false;
			}
		}
	}
	else {
		for (int i = 1; i <= m; i++) {
			if (B[0] != 1) {
				flag = false;
			}
			if (B[2 * i] != 2) {
				flag = false;
			}
		}
	}
		if (flag == false) {
			cout << 0;
		}
		else {
			long long res = 1;
			for (int i = 0; i < m; i++) {
				res = res * 2 % 1000000007;
			}
			cout << res;
		}
		return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define foreach(c,itr) for(__typeof(c)::iterator itr=c.begin();itr!=c.end();itr++)
typedef long long ll;
typedef long double ld;
int i,j;

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

    int n;
    cin>>n;
    ll ans=0;
    for(i=1;i<n;i++){
    	ans+=(n-1)/i;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
int partition(int A[],int p,int r);
int main(void){
	int i,n,x;
	int A[100000];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	x=partition(A,0,n-1);
	
	for(i=0;i<n;i++){
		if(i==x){
			printf("[");
		}
		printf("%d",A[i]);
		if(i==x){
			printf("]");
		}
		if(i!=n-1){
			printf(" ");
		}
	}
	
	printf("\n");
	
	return 0;
}

int partition(int A[],int p,int r){
	int i,j,x,tmp;
	
	x=A[r];
	i=p-1;
	for(j=p;j<=r-1;j++){
		if(A[j]<=x){
			i=i+1;
			tmp=A[i];
			A[i]=A[j];
			A[j]=tmp;
		}
	}
	tmp=A[i+1];
	A[i+1]=A[r];
	A[r]=tmp;
	
	return i+1;
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
 int A,B;cin>>A>>B;
  cout<<(A+B)%24<<endl;
  
}
  
   





Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define repeat2(n) for (int j = 0; j < n; ++j)
#define all(x) x.begin(), x.end()
#define llcast static_cast<long long int>

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

    stringstream ss;
    while (n > 0) {
        n -= 1;
        char c = 'a' + (n % 26);
        ss << c;
        n /= 26;
    }

    auto ans = ss.str();
    reverse(all(ans));

    cout << ans;
    
    return 0;
}

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

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n,a,b,c,d;
ll pa[1005];
ll dp[1005][1005];
ll p(ll a, ll x) {
  ll res = 1;
  while(x > 0) {
  if(x & 1) res = (res * a) % mod;
  a = a * a % mod;
  x >>= 1;
  }
  return res;
}


ll r(ll x) {
  return p(x,mod - 2);
}

ll P(ll a, ll b) {
  return pa[a] * r(pa[a-b]) % mod;
}

int main() {
  cin >> n >> a >> b >> c >> d;
  pa[0] = 1;
  for(int i = 1; i <= n; i++) pa[i] = pa[i-1] * i % mod;
  dp[a-1][0] = 1;

  for(ll k = a; k <= b; k++) {
    for(ll i = 0; i <= n; i++) dp[k][i] = dp[k-1][i];
    for(ll i = c; i <= d; i++) {
      for(ll j = k * i; j <= n; j++) {
	dp[k][j] = (dp[k][j] + (dp[k-1][j-k*i] * P(j,k*i) % mod) * r(p(pa[k],i) * pa[i] % mod) % mod) % mod;
      }
    }
  }

  cout << dp[b][n] << endl;
}
	

  


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    if (ans * 2 < ans + K) ans *= 2;
    else ans += K;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	vector<int>v; int n, p;cin >> n;
	for (int i = 0; i < n; i++) { 
	    cin >> p; v.push_back(p);
	}
	cin >> n;
	for (int i = 0; i < n; i++) { 
	    cin >> p; v.push_back(p);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++) {
		if (i + 1 < v.size() && v[i] == v[i + 1])i++;
		else cout << v[i] << endl;
	}
}


Measured memory_bytes: 7064
#include<bits/stdc++.h>
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 loop(i,L,R) for(int i=(L);i<=(R);i++)
const int maxn=1e3+5;
char a[maxn][maxn];
int vis[maxn][maxn];
int h,w;
bool in(int i,int j)
{
    if(i>=0&&i<h&&j>=0&&j<w&&a[i][j]=='.'&&!vis[i][j])
    {
        vis[i][j]=1;
        return true;
    }
    return false;
}
struct node
{
    int x,y;
    node(int x=0,int y=0):x(x),y(y) {}
};
queue<node>q;
int main()
{
    memset(vis,0,sizeof(vis));
    scanf("%d%d",&h,&w);
    int ans=0;
    rep(i,h) scanf("%s",a[i]);
    rep(i,h)
    {
        rep(j,w)
        {
            if(a[i][j]=='#')
            {
                if(in(i+1,j))
                    q.push(node(i+1,j));
                if(in(i,j-1))
                    q.push(node(i,j-1));
                if(in(i,j+1))
                    q.push(node(i,j+1));
                if(in(i-1,j))
                    q.push(node(i-1,j));
            }
        }
    }
    while(!q.empty())
    {
        ans++;
        int n=q.size(),i,j;
        node now;
        bool flag=false;
        while(n--)
        {
            now=q.front();
            q.pop();
            i=now.x,j=now.y;
            if(in(i+1,j))
                q.push(node(i+1,j)),flag=true;
            if(in(i,j-1))
                q.push(node(i,j-1)),flag=true;
            if(in(i,j+1))
                q.push(node(i,j+1)),flag=true;
            if(in(i-1,j))
                q.push(node(i-1,j)),flag=true;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P[i];
  int ans = 0;
  for (int i = 1; i < N-1; i++) {
    if ((P[i] != max({P[i-1], P[i], P[i+1]})) && (P[i] != min({P[i-1], P[i], P[i+1]}))) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());

	string t;
	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

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


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
        else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
        else if ( b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
        else if (c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;
        else if ( c <= a && a <= b )
        cout << c << " " << a << " " << b << endl;


 

}
 


Measured memory_bytes: 3092
import java.util.Scanner;

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

        int count = 0;
        for (int i = 0; i < n; i++) {
            int h = in.nextInt();

            if (h >= k) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 46976
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
int mod=1e9+7;
bool prime(ll n)
{
    if(n==1)
        return false;
    if(n==2)
        return true;
    for(ll i=2; i*i<=n; i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll gcd(ll x,ll y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
ll fp(ll b,ll p)
{
    if(p==0)
        return 1;
    ll  z=fp(b,p/2);
    if(p%2==0)
        return (z*z)%mod;
    else
        return (((z*z)%mod)*(b%mod))%mod;
}
long long  Factorial(long long n)
{
    if(n > 1)
        return n * Factorial(n - 1);
    else
        return 1;
}
const int m=1e6+1;
ll fact[m],inv[m];
void fn()
{
    fact[0]=1,inv[0]=1;
    for(int i=1; i<=1e6; i++)
    {
        fact[i]=(i*fact[i-1])%mod;
        inv[i]=fp(fact[i],mod-2);
    }
}

long long  nCr(ll N, ll R)
{
    return (((fact[N]*inv[N-R])%mod)*inv[R])%mod;
}
vector<int>v;
void primeFactors(int n)
{
    while (n%2 == 0)
    {
        v.push_back(2);
        n = n/2;

    }

    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            v.push_back(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.push_back(n);
}
long long  NCR(long long N, long long R)
{
    return (Factorial(N)) / ((Factorial(N-R)) * Factorial(R));
}
int const n=3009;
ld ans[n][n];
int main()
{
    int x;
    cin>>x;
    ld arr[x];
    for(int i=0;i<x;i++){
        cin>>arr[i];
    }
    ans[0][0]=1-arr[0];
    ans[0][1]=arr[0];
    for(int i=1;i<x;i++){
        for(int j=0;j<=i+1;j++){
           ans[i][j]=0;

            if(j){
                ans[i][j]+=ans[i-1][j-1]*(arr[i])+ans[i-1][j]*(1-arr[i]);
            }
            else{
                ans[i][j]+=ans[i-1][j]*(1-arr[i]);
            }

        }
    }
    ld y=0;
    for(int i=ceil((ld)(x)/2);i<=x;i++){
        y+=ans[x-1][i];
    }
    cout<<fixed<<setprecision(9)<<y<<endl;
    return 0;
}


Measured memory_bytes: 141824
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N;  cin >> N;
    string S; cin >> S;
    
    int white = 0, black = 0;
    REP(i,N) {
        if (S[i] == '#') black++;
        else white++;
    }

    int ans = INF;
    int w = 0, b = 0;
    string T = "B" + S + "E";
    FOR(i,0,N+1) {
        if (T[i] == '#') b++;
        else if (T[i] == '.') w++;

        // rising edge
        if (T[i]!='#' && T[i+1]!='.') {
            ans = min(ans, b + white - w);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 788
package main

import (
	"fmt"
	"strings"
)

func main() {

	var s string
	fmt.Scan(&s)

	s_len := len(s)

	if s_len == 1 {
		fmt.Println(0)
	} else if s_len % 2 == 0 {
		zenhan := s[: (s_len / 2)]
		kouhan := s[ (s_len /2 ):]

		c := check(zenhan, kouhan)

		fmt.Println(c)
	} else {
		zenhan := s[: (s_len / 2)]
		kouhan := s[ (s_len /2 ) + 1:]
		c := check(zenhan, kouhan)

		fmt.Println(c)
	}

}

func check(a string, b string) int {

	rev := reverse(b)

	a_list := strings.Split(a, "")
	b_list := strings.Split(rev, "")

	count := 0

	for i := 0; i < len(a); i++ {
		if a_list[i] != b_list[i] {
			count = count + 1
		}
	}

	return count
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


Measured memory_bytes: 640
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
int a[100005];

void nope() {
	cout << "No" << endl;
	exit(0);
}

void yep() {
	cout << "Yes" << endl;
	exit(0);
}

int main() {
	//freopen("x.in", "r", stdin);
	
	cin >> n;
	F0(i, n) {
		cin >> a[i];
	}
	int n1 = *min_element(a, a + n);
	int n2 = *max_element(a, a + n);
	if (n2 - n1 > 1) nope();

	int c1 = count(a, a + n, n1);
	int c2 = count(a, a + n, n2);

	if (n1 == n2) {
		if (n1 == n - 1) yep();
		if (2 * n1 <= n) yep();
		nope();
	}

	if (c1 + c2 / 2 >= n2 && c2 > 1 && c1 < n2) yep();
	nope();

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#define llint long long
#define inf 1000000000000000000

using namespace std;
typedef pair<llint, llint> P;

llint n;
string s;
vector<llint> G[2005];
llint cnt[2005], sum[2005], rem[2005];

llint cntdfs(llint v, llint p)
{
	cnt[v] = s[v]-'0';
	for(llint i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		cnt[v] += cntdfs(G[v][i], v);
	}
	return cnt[v];
}

llint sumdfs(llint v, llint p)
{
	sum[v] = 0;
	for(llint i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		sum[v] += sumdfs(G[v][i], v) + cnt[G[v][i]];
	}
	return sum[v];
}

llint remdfs(llint v, llint p)
{
	llint Sum = 0, Max = 0, Max_u;
	for(llint i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		if(u == p) continue;
		remdfs(u, v);
		Sum += sum[u] + cnt[u];
		if(Max < sum[u] + cnt[u]){
			Max = sum[u] + cnt[u];
			Max_u = u;
		}
	}
	//cout << v << " " << p << "  " << Sum << " " << Max << endl;
	if(Max <= Sum/2) return rem[v] = 0;
	return rem[v] = max(0LL, rem[Max_u]+cnt[Max_u] - (Sum-Max));
}

int main(void)
{
	cin >> n >> s;
	s = "#" + s;
	llint u, v;
	for(llint i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	llint ans = inf;
	for(llint i = 1; i <= n; i++){
		cntdfs(i, -1), sumdfs(i, -1), remdfs(i, -1);
		//cout << i << " " << sum[i] << " " << rem[i] << endl;
		//for(int j = 1; j <= n; j++) cout << rem[j] << " "; cout << endl;
		if(sum[i] % 2 == 0 && rem[i] <= 0) ans = min(ans, sum[i]/2);
	}
	if(ans >= inf) ans = -1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640