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

int main() {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));

  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }

  long long ans = 1001001001;
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);

    long long cnt = 0;
    vector<int> sum(M, 0);
    for (int i = 0; i < N; i++) {
      if (s.test(i)) cnt += C.at(i);
      for (int j = 0; j < M; j++) {
        if (s.test(i)) {
          sum.at(j) += A.at(i).at(j);
        }
      }
    }

    bool flag = true;
    for (int i = 0; i < M; i++) {
      if (sum.at(i) < X) flag = false;
    }
    if (flag) ans = min(ans, cnt);
  }

  if (ans == 1001001001)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

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

int main(){
    int k,x;
    cin >> k >> x;

    int max_x = x+k-1;
    int min_x = x-k+1;

    for(int i=min_x;i<max_x;i++)
        cout << i<<" ";
    cout << max_x; 
}

Measured memory_bytes: 256
key = [[".",",","!","?"," "]]
key += [["a","b","c"]]
key += [["d","e","f"]]
key += [["g","h","i"]]
key += [["j","k","l"]]
key += [["m","n","o"]]
key += [["p","q","r","s"]]
key += [["t","u","v"]]
key += [["w","x","y","z"]]

gets.to_i.times {
  inp = gets.split(//).map{|i|i.to_i}
  x = t = 0
  while x < inp.length
    if inp[x] == 0 && t != 0
      case inp[x-1]
      when 1
        print key[inp[x-1]-1][(t-1)%5]
      when 2..6, 8
        print key[inp[x-1]-1][(t-1)%3]
      when 7, 9
        print key[inp[x-1]-1][(t-1)%4]
      end
      t = 0
    elsif inp[x] != 0
      t += 1
    end
    x += 1
  end
  print "\n"
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}


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

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

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

    if(1 <= a and a <= 9 and 1 <= b and b <= 9){
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def main():
    alpha = 'zabcdefghijklmnopqrstuvwxy'
    N = int(input())
    name = ''
 
    while True:
        a = N%26
        name = alpha[a] + name
        N //=26
        if a == 0:
            N-=1
        if N == 0:
            break
    print(name)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void xin(){
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}



int main()
{
  	xin();
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    int ct=0;
    		while(b <= a)
    		{
    			ct++;
    			b *= 2;
    		}
    		while(c <= b)
    		{
    			ct++;
    			c *= 2;
    		}
    if(ct <= k)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
    	
    
    return 0;
} 

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll n, m;

int main() {
    //cout.precision(10);
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(m);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
    }
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    a.push_back(0);
    b.push_back(0);
    for(int i = 1; i < n; i++){
        if(a[i] == a[i - 1]) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 1; i < m; i++) {
        if(b[i] == b[i - 1]) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll stock = 0;
    ll Aindex = 0;
    ll Bindex = 0;
    ll ans = 1;
    for(ll now = n * m; now > 0; now--) {
        if(a[Aindex] == now && b[Bindex] == now) {
            stock = (stock + Aindex + Bindex + 1) % mod;
            stock--;
            Aindex++;
            Bindex++;
            continue;
        }
        if(a[Aindex] == now) {
            ans = (ans * Bindex) % mod;
            stock = (stock + Bindex) % mod;
            stock--;
            Aindex++;
            continue;
        }
        if(b[Bindex] == now) {
            ans = (ans * Aindex) % mod;
            stock = (stock + Aindex) % mod;
            stock--;
            Bindex++;
            continue;
        }
        ans = (ans * stock) % mod;
        stock--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#include <set> 
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 100000000000000
#define endl "\n"
#define precise(x) fixed << setprecision(x) 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int MOD =1000000007;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 ll mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}
 //ll power(ll x, ll y) 
//{ 
  //  ll temp; 
    //if( y == 0) 
     //   return 1; 
    //temp = power(x, y/2); 
    //temp=temp%MOD;
    //if (y%2 == 0) 
     //   return (temp%MOD)*(temp%MOD); 
    //else
      //  return (x%MOD)*(temp%MOD)*(temp%MOD); 
//} 
 
 
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=5e5+1000;
 ll vis[300000];
 vector<ll> v[maxn];
 ll xxx;
 void  dfs(int node)
 {
 	  vis[node]=1;
 	  xxx++;
 	  for(auto child:v[node])
 	  {
 	  	  if(vis[child]==0) 
 	  	  {
 	  	  	dfs(child);
		   }
	   }
 }
 
 
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
     ll t;
    // cin>>t;
   
     t=1;	
     for(ll testcase=0;testcase<t;testcase++)
    {
        ll i1,i2,k,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,m,n;
        ll x,y,z;
        ll total=0,cnt=0;
        ll flag=0;
        y=0;
        ll res,res1,ans,res2,q,sum;
        ans=0,cnt=0;
        res1=0,res=0,sum=0;
        ll flag1=0;
        ll k1,k2,k3;
        k1=1,k2=0;
        k3=0;
        ll required,days,h,w;
        //cin>>n;
        
        //for(it=mp.begin();it!=mp.end(),it++)
        //{
        //	for(int i=0;i<it->second.size();i++) cout<<it->second[i]<<" ";
		//}
		cin>>n>>m;
		for(i=1;i<=m;i++)
		{
			cin>>x>>y;
			v[x].pb(y);
			v[y].pb(x);
		}
	    for(i=1;i<=n;i++)
	    {
	    	if(vis[i]==0)
	    	{
	    		xxx=0;
	    		dfs(i);
	    		cnt=max(cnt,xxx);
	    	}
	    	
		}
		cout<<cnt<<endl;
		
	
    }
}
	

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

namespace ConsoleApp15
{
    class Class118
    {
        static void Main()
        {
            var DN = Console.ReadLine().Split().Select(int.Parse);
            int D = DN.First(), N = DN.Last();
            if (N == 100) N++;
            int ans = (int)Math.Pow(100, D) * N;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
template <class T1, class T2>void print(T1 a[], T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " ";} cout << endl;}
template <class T1, class T2>void print(vector<T1> a, T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl;}
ll modexpo(ll a, ll b, ll m) {if (b == 0) {return 1;} else if (a == 1) {return 1;} if (b % 2 == 0) {ll t = modexpo(a, b / 2, m); t = (t * t) % m; return t;} else {ll t = modexpo(a, b / 2, m); t = (t * t) % m; t = (t * a) % m; return t;}}



int main() {

	// taskkill /IM "cp.exe" /F
	fast
      /*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
*/


	int n;
	cin >> n;
	int a[n], b[n], c[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (int i = 1; i < n; i++) {
		dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]);
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
	// for (int i = 0; i < n; i++)
	// 	print(dp[i], 3);
}

Measured memory_bytes: 2560
foldn :: (a -> a) -> a -> Int -> a
foldn f a n = if n == 0 then a else (foldn f (f a) (n-1))

debt :: Float -> Float
debt = (* 1000) . fromIntegral . ceiling . (* 0.00105)

main = do
    n <- readLn :: IO Int
    
    print . ceiling $ foldn debt 100000 n

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

using namespace std;

typedef long long ll;

int main(){
    string x, y;
    int z[256] = {};
    int zz[256] = {};
    cin >> x >> y;
    for(int a = 0; a < (int)x.size(); a++){
        if(z[(int)x[a]] == 0) z[(int)x[a]] = (int)y[a];
        else if(z[(int)x[a]] != (int)y[a]){
            cout << "No" << endl;
            return 0;
        }
        if(zz[(int)y[a]] == 0) zz[(int)y[a]] = (int)x[a];
        else if(zz[(int)y[a]] != (int)x[a]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 776
n = int(input())
aList = list(map(int, input().split()))
l = []
for i, a in enumerate(aList):
    l.append((a, i))
l = sorted(l, key=lambda x:x[0])
ansList = [a[1] + 1 for a in l]
print(' '.join(map(str, ansList)))

Measured memory_bytes: 28604
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    int n;
    cin >>n ;
    int arr[n];
    bool flag = false;
    for(int i= 0; i<n; i++) {
        cin >> arr[i];
        if(arr[i]%2==0 && (arr[i]%3 != 0 && arr[i]%5 !=0)){
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i++)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 100000000
#define NINF -100000000

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;

template <typename T>
void warshallFloyd(vector<vector<T>> &d)
{
	rep(i, d.size()) rep(j, d.size()) rep(k, d.size()) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

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

	for (char x : N) {
		if (x == '9') {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}



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

	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
     String s = sc.next();
     sc.close();
     String []ss = s.split("");
     
     int a = Integer.parseInt(ss[0]);
     int b = Integer.parseInt(ss[1]);
     int c = Integer.parseInt(ss[2]);
     int d = Integer.parseInt(ss[3]);
     String op1 ="";
     String op2 ="";
     String op3 ="";
      
     if(a+b+c+d ==7) {
    	op1 ="+"; op2 ="+"; op3 ="+";
     }
     else if(a+b-c+d ==7) {
      	op1 ="+"; op2 ="-"; op3 ="+";
       }
     else if(a+b-c-d ==7) {
       	op1 ="+"; op2 ="-"; op3 ="-";
        }
     else if(a+b+c-d ==7) {
        	op1 ="+"; op2 ="+"; op3 ="-";
         }
     else if(a-b+c+d ==7) {
     	op1 ="-"; op2 ="+"; op3 ="+";
      }
     else if(a-b+c-d ==7) {
      	op1 ="-"; op2 ="+"; op3 ="-";
       }
     
     else if(a-b-c+d ==7) {
      	op1 ="-"; op2 ="-"; op3 ="+";
       }
     
    System.out.println((a+op1+b+op2+c+op3+d+"=7"));  
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[1003][1003] = {}, b[1003] = {}, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) for (int j = 1; j < n; j++) cin >> a[i][j];
    for (int i = 1; i <= n; i++) b[i] = 1;
    queue<pair<pii, int>> q;
    for (int i = 1; i <= n; i++) if (a[a[i][1]][1] == i && i < a[i][1]) q.push({{i, a[i][1]}, 1});
    while (!q.empty()) {
        pii x = q.front().first;
        int y = q.front().second;
        z = max(z, y);
        //cout << x.first << ' ' << x.second << ' ' << y << '\n';
        q.pop();
        b[x.first]++;
        int w = a[x.first][b[x.first]];
        if (a[w][b[w]] == x.first) q.push({{x.first, w}, y + 1});
        b[x.second]++;
        w = a[x.second][b[x.second]];
        if (a[w][b[w]] == x.second) q.push({{x.second, w}, y + 1});
    }
    for (int i = 1; i <= n; i++) if (b[i] < n) z = -1;
    cout << z;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

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 long long INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s; cin>>s;
  
  char v = s[0];
  int divCount = 0;
  
  rep(i, s.length()) {
    if (s[i]==v) continue;
    
    v=s[i];
    ++ divCount;
  }
  
  cout<<divCount;
  
  return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;

int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n>>m>>l;
    (m-n==l-m)? cout<<"YES\n":cout<<"NO\n";
    return 0;
}



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

int main() {
    string CF = "CODEFESTIVAL2016";
    string S;
    cin >> S;
    int res = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] != CF[i]) {
            ++res;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  bool visited[n];
  rep(i,n) {
    cin >> a[i];
    a[i]--;
    visited[i] = false;
  }
  visited[0] = true;
  int p = 0;
  int count = 0;
  bool ans = false;

  while (1) {
    p = a[p];
    count++;
    if (p==1) {
      ans = true;
      break;
    }
    if (visited[p]) break;
    visited[p] = true;
  }

  if (ans) cout << count << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
void print(vector<vector<pair<long long int,long long int>>> &dp)
{
    for(int i=0;i<dp.size();i++)
    {
        for(int j=0;j<dp[0].size();j++)
        {
            cout<<dp[i][j].first<<" "<<dp[i][j].second<<"     ";
        }
        cout<<endl;
    }
}
int main() 
{
	long long int n;
	cin>>n;
	vector<long long int> A(n);
	for(long long int i=0;i<n;i++)
	{
	    cin>>A[i];
	}
	vector<vector<pair<long long int,long long int>>> dp(n,vector<pair<long long int,long long int>>(n,make_pair(INT_MAX,INT_MAX)));
	for(long long int size=0;size<n;size++)
	{
	    for(long long int i=0;i<n-size;i++)
	    {
	        long long int j=i+size;
	        if(size==0)
	        {
	            dp[i][j].first=A[i];
	            dp[i][j].second=0;
	            continue;
	        }
	        long long int temp1=dp[i][i].second+dp[i+1][j].second;
	        long long int temp2=dp[i][i].first+dp[i+1][j].first;
	        dp[i][j].second=temp1+temp2;
            dp[i][j].first=temp2;
	        for(long long int k=i;k<j;k++)
	        {
	            long long int temp1=dp[i][k].second+dp[k+1][j].second;
	            long long int temp2=dp[i][k].first+dp[k+1][j].first;
	            if(dp[i][j].second>temp1+temp2)
	            {
                    dp[i][j].second=temp1+temp2;
                    dp[i][j].first=temp2;
	            }
	        }
	    }
	}
	//print(dp);
	cout<<dp[0][n-1].second;
}

Measured memory_bytes: 2816
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		if(S[0]!=T[0]){
			System.out.println("-1");
			System.out.flush();
			return;
		}
		long lcm = getLCM(N, M);
		int n = (int) (lcm / N);
		int m = (int) (lcm / M);
		for(long i=0; i<lcm; i=i+n){
			if(i%n==0 && i%m==0 && S[(int)(i/n)]!=T[(int)(i/m)]){
				System.out.println("-1");
				System.out.flush();
				return;
			}
		}
		System.out.println(lcm);
	}
	private static long getGCD(long m, long n) {
        if(m < n) return getGCD(n, m);
        if(n == 0) return m;
        return getGCD(n, m % n);
    }
    
    private static long getLCM(long m, long n) {
        return m * n / getGCD(m, n);
    }
}

Measured memory_bytes: 28116
import java.util.Scanner;

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

        long H = scanner.nextLong();
        int N = scanner.nextInt();

        long total = 0L;

        for (int i = 0 ; i < N ; i++) {
            total += scanner.nextInt();
        }

        if (H <= total) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 58864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		
		String strNum = null;

		int x = 0;
		//int intAnser = x * x * x;

		try{

			BufferedReader insLine = new BufferedReader(new InputStreamReader(System.in));
			strNum = insLine.readLine();

			x = Integer.parseInt(strNum);

			if (x >=1  && x <= 100) {

				System.out.println(x * x * x);
			}

		}catch (IOException e) {
			System.out.println(e);
		}catch (NumberFormatException e2) {
			System.out.println(e2);
		}
	}

}

Measured memory_bytes: 24068
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}



///////////////////////////

ll summax(vector<ll> a, vector<ll> b, ll N) {
	vector<ll> c(N + 1);
	c[N] = b[N];
	for (int i = N - 1; i >= 0; i--) {
		c[i] = max(b[i], c[i + 1]);
	}

	ll ans = a[0] + c[0];

	repn(i, N) {
		ans = max(ans, a[i] + c[i]);
	}

	return ans;
}




int main() {

	ll N, C;
	cin >> N >> C;

	vector<ll> x(N + 1), v(N + 1);

	repn(i, N) cin >> x[i] >> v[i];

	vector<ll> pre(N + 1), suf(N + 1);
	pre[0] = 0;
	repn(i, N) pre[i] = pre[i - 1] + v[i];//v[1]+...+v[i]

	suf[N] = 0;
	repn(i, N) suf[N - i] = suf[N - i + 1] + v[N - i+1];//v[i+1]+...+v[N]

	vector<ll> a(N + 1), b(N + 1);

	a[0] = 0;
	repn(i, N) a[i] = pre[i] - 2 * x[i];

	b[N] = 0;
	rep(i, N) b[i] = suf[i] + x[i + 1] - C;

	ll ans1 = summax(a, b, N);

	a[0] = 0;
	repn(i, N) a[i] = pre[i] - x[i];
	b[N] = 0;
	rep(i, N) b[i] = suf[i] + 2 * (x[i + 1] - C);

	ll ans2 = summax(a, b, N);

	cout << max(ans1, ans2);
	
		
	system("PAUSE");

}


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

int main(){
    priority_queue<int> que;

    for(int i = 0 ; i < 10 ; ++i){
        int h;
        cin >> h;
        que.push(h);
    }

    for(int i = 0 ; i < 3 ; ++i){
        cout << que.top() << endl;
        que.pop();
    }

    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  ll cnt = 0;
  ll ans = 0;
  for(int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') cnt++;
    else ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll N,M;
ll a,b,x;
ll imos[5002][5002];

int main()
{
	scanf("%lld%lld",&N,&M);
	ll H=N;
	ll W=N;
	rep(i,M){
		scanf("%lld%lld%lld",&a,&b,&x);
		a--;
		--b;
		x++;
		imos[a][b]++;
		imos[a][b+1]--;
		imos[a+x][b]--;
		imos[a+x+1][b+1]++;
		imos[a+x][b+x+1]++;
		imos[a+x+1][b+x+1]--;
	}
	rep(i,H+2) rep(j,W+2){
		if(i>0&&j>0){
			imos[i][j]+=imos[i-1][j-1];
		}
	}
	rep(i,H+2) rep(j,W+2){
		if(i>0){
			imos[i][j]+=imos[i-1][j];
		}
	}
	rep(i,H+2) rep(j,W+2){
		if(j>0){
			imos[i][j]+=imos[i][j-1];
		}
	}
	ll ans=0;
	rep(i,H) rep(j,i+1) if(imos[i][j]>0) ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 198672
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>

using namespace std;
typedef long long ll;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> cities;
    vector<vector<ll>> years(n);
    for(int i = 0; i < m; ++i){
        ll p, y;
        cin >> p >> y;
        cities.push_back(make_pair(p, y));
        years.at(p - 1).push_back(y);
    }

    for(int i = 0; i < n; ++i){
        sort(years.at(i).begin(), years.at(i).end());
    }

    for(auto x : cities){
        const ll p = x.first;
        const ll y = x.second;
        const ll i = lower_bound(
            years.at(p - 1).begin(), years.at(p - 1).end(), y)
            - years.at(p - 1).begin();
        printf("%06lld%06lld\n", p, i + 1);
    }
    return 0;
}


Measured memory_bytes: 8560
#include <stdio.h>

int main() {
    long int a, b, ab, x, y;
    scanf("%ld %ld %ld %ld %ld", &a, &b, &ab, &x, &y);

    long int sum=0;

    if((a+b)>2*ab) {
        if((a>2*ab) && (b>2*ab)) {
            if(x>y) {
                printf("%ld\n", 2*ab*x);
                return 0;
            } else {
                printf("%ld\n", 2*ab*y);
                return 0;
            }
        }

        if(x>y) {
            sum += 2*y*ab;
            x -= y;
            y = 0;
            if(a>2*ab) {
                sum += 2*x*ab;
                printf("%ld\n", sum);
                return 0;
            } else {
                sum += x*a;
                printf("%ld\n", sum);
                return 0;
            }
        } else {
            sum += 2*x*ab;
            y -= x;
            x = 0;
            if(b>2*ab) {
                sum += 2*y*ab;
                printf("%ld\n", sum);
                return 0;
            } else {
                sum += y*b;
                printf("%ld\n", sum);
                return 0;
            }
        }

    } else {
        printf("%ld\n", a*x + b*y);
    }

    return 0;
    
}

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

int bfs(string mas);
bool end(const string& str);
string change(string mas,char cha,char c);
char RGB[] = {'R','G','B'};
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
int W,H;

int main(){
  while(1){
    string str;
    cin >> W >> H;
    if(W==0 && H==0) break; 
    for(int i=0;i<W*H;i++){
      char a;
      cin >> a;
      str += a;
    }
    cout << bfs(str) << endl;
  }
}

int bfs(string mas){
  queue<string> que;
  map<string,int> flag;
  que.push(mas);
  flag[mas] = 0;
  while(!que.empty()){
    string s = que.front();
    que.pop();
    if(end(s)) return flag[s];
    for(int i=0;i<3;i++){
      string newstr = change(s,s[0],RGB[i]);
      if(flag.find(newstr) != flag.end()) continue;
      flag[newstr] = flag[s] + 1;
      que.push(newstr);
    }
  }
  return -1;
}

bool end(const string& str){
  for(int i=0;i<3;i++){
    if(count(str.begin(),str.end(),RGB[i]) == W*H) return true;
  }
  return false;
}

string change(string mas,char cha,char c){
  if(cha == c) return mas;
  queue<int> que;
  que.push(0);
  mas[0] = c;
  while(!que.empty()){
    int p = que.front();
    que.pop();
    for(int i=0;i<4;i++){
      int nx = (p%W) + dx[i];
      int ny = (p/W) + dy[i];
      if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      int z = nx + ny * W;
      if(mas[z] != cha) continue;
      mas[z] = c;
      que.push(z);
    }
  }
  return mas;
}
    

Measured memory_bytes: 2648
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;



int main() {
    ll n; cin >> n;
    ll l = 0;
    ll i = 26, keta = 1;
    while (l+i < n) {
        l += i;
        ++keta;
        i *= 26;
    } 
    n -= l+1;
    string ans(keta, 'a'); 
    do {
        ans[keta-1] = n%26 + 'a';
        n /= 26;
        --keta;
    } while (n); 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  ll N,D;  cin>>N>>D;
  ll n = 0;
  rep(i,0,N){
    ll x,y;  cin>>x>>y;
    if(x*x+y*y <= D*D){
      n++;
    }
  }
  cout<<n<<endl;
  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
char x;
  cin >>x;
  if((x=='a') ||(x=='i') ||(x=='u') ||(x=='e') ||(x=='o')) {
cout <<"vowel" << endl;
  }
else {
cout << "consonant" << endl;
}
}


Measured memory_bytes: 256
//package TaskD;

import java.io.FileInputStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

import static java.lang.Math.*;

public class Main {
    long N;

    void solve() throws Exception {
        Scanner sc = new Scanner(System.in);
        N = sc.nextLong();
        long res = 0;
        Set<Long> st = new HashSet<>();
        for(long a=1; a<=sqrt(N); a++){
            if(N % a == 0){
                long b = N/a;

                if(a>1 && !st.contains(a-1)){
                    //res += a - 1;
                    st.add(a-1);
                }

                if(b>1 && !st.contains(b-1)){
                    //res += b - 1;
                    st.add(b-1);
                }
            }
        }
        for(long a : st){
            if(N/a == N%a){
                res+=a;
            }
        }
        //System.out.println(st);
        System.out.println(res);
    }

    public static void main(String[] args) throws Exception{
        //System.setIn(new FileInputStream("inputs/d.in"));
        Main s = new Main();
        s.solve();
    }
}


Measured memory_bytes: 23356
import math
A,B,H,M = map(int,input().split())
k = max(H*30+M*0.5,M*6)-min(H*30+M*0.5,M*6)
if k >= 180:
  k = 360-k
print(math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(k))))

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

#define DUMP(x) cerr << #x << " = " << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

ll N, L, T;
vector<ll> X, W;

ll collision_count(int a, int b)
{
    if (W[a] == 1 && W[b] == 2) {
        ll diff = (X[b] - X[a]);
        if (diff <= 2*T) {
            return 1 + (2*T - diff) / L;
        }
    } else if (W[a] == 2 && W[b] == 1) {
        ll diff = L - (X[b] - X[a]);
        if (diff <= 2*T) {
            return 1 + (2*T - diff) / L;
        }
    }

    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> N >> L >> T;
    X.resize(N), W.resize(N);
    rep(i, N) cin >> X[i] >> W[i];

    ll collision_sum = 0;
    REP(i, 1, N) collision_sum = (collision_sum + collision_count(0, i)) % N;

    ll last_num, last_dir;
    if (W[0] == 1) {
        last_num = collision_sum % N;
        last_dir = (collision_sum % 2 == 0 ? 1 : 2);
    } else {
        last_num = (N - collision_sum) % N;
        last_dir = (collision_sum % 2 == 0 ? 2 : 1);
    }

    assert(last_num >= 0LL);

    vector<ll> last_pos(N);
    rep(i, N) {
        if (W[i] == 1) {
            last_pos[i] = (X[i] + (T%L)) % L;
        } else {
            last_pos[i] = (X[i] - (T%L) + L) % L;
        }
        assert(last_pos[i] >= 0LL);
    }
    ll p = last_pos[0];
    sort(ALL(last_pos));

    int p_idx = -1;
    rep(i, N) {
        if (last_pos[i] == p) {
            p_idx = i;
            if (W[0] == 2) break;
        }
    }

    vector<ll> ans(N);
    rep(i, N) ans[(last_num + i) % N] = last_pos[(p_idx + i) % N];
    rep(i, N) cout << ans[i] << endl;
}


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

int h,w,n;
vector<string> s(50);

bool sim(void){
  //for(int i=0;i<h;i++)cout << s[i] << endl;
  //cout << endl;

  int num = 0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(s[i][j]=='.')num++;
  if(num == h*w)return true;

  for(int j=0;j<w;j++){
    for(int i=h-1;i>=0;i--){
      if(s[i][j] != '.'){
	int d = 1;
	while(i+d<h && s[i+d][j] == '.'){swap(s[i+d][j],s[i+d-1][j]);d++;}
      }
    }
  }

  bool u[50][50];
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)u[i][j] = false;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j] != '.'){
	int d = 0;
	while(i+d<h && s[i][j] == s[i+d][j])d++;
	if(d>=n)for(int k=0;k<d;k++)u[i+k][j] = true;

	d = 0;
	while(j+d<w && s[i][j] == s[i][j+d])d++;
	if(d>=n)for(int k=0;k<d;k++)u[i][j+k] = true;
      }
    }
  }

  num = 0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(u[i][j]){s[i][j] = '.'; num++;}
  if(!num)return false;

  return sim();
}

int main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++)cin >> s[i];
  vector<string> tmp = s;

  bool f = false;
  for(int i=0;i<h;i++){
    for(int j=1;j<w;j++){
      swap(s[i][j-1],s[i][j]);
      f = sim();
      if(f)break;
      s = tmp;
    }
    if(f)break;
  }

  if(f)cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int H,W,K;
	cin>>H>>W>>K;
	
	int xs,ys,xt,yt;
	cin>>xs>>ys>>xt>>yt;
	xs--,ys--,xt--,yt--;
	
	vector<string> S(H);
	for(int i=0;i<H;i++)cin>>S[i];
	
	vector<set<int>> S1(H),S2(W);
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			S1[i].insert(j);
			S2[j].insert(i);
		}
	}
	
	vector<vector<int>> dis(H,vector<int>(W,Inf));
	queue<pair<int,int>> Q;
	Q.emplace(xs,ys);
	dis[xs][ys] = 0;
	S1[xs].erase(ys);
	S2[ys].erase(xs);
	
	while(Q.size()!=0){
		int x = Q.front().first;
		int y = Q.front().second;
		Q.pop();
		auto it = S1[x].lower_bound(y);
		while(it!=S1[x].end()){
			int yy = *it;
			if(abs(y-yy)>K)break;
			if(S[x][yy]=='@')break;
			dis[x][yy] = dis[x][y]+1;
			Q.emplace(x,yy);
			it = S1[x].erase(it);
			S2[yy].erase(x);
		}
		it = S1[x].lower_bound(y);
		while(it!=S1[x].begin()){
			it--;
			int yy = *it;
			if(abs(y-yy)>K)break;
			if(S[x][yy]=='@')break;
			dis[x][yy] = dis[x][y]+1;
			Q.emplace(x,yy);
			it = S1[x].erase(it);
			S2[yy].erase(x);
		}
		
		it = S2[y].lower_bound(x);
		while(it!=S2[y].end()){
			int xx = *it;
			if(abs(x-xx)>K)break;
			if(S[xx][y]=='@')break;
			dis[xx][y] = dis[x][y]+1;
			Q.emplace(xx,y);
			it = S2[y].erase(it);
			S1[xx].erase(y);
		}
		it = S2[y].lower_bound(x);
		while(it!=S2[y].begin()){
			it--;
			int xx = *it;
			if(abs(x-xx)>K)break;
			if(S[xx][y]=='@')break;
			dis[xx][y] = dis[x][y] + 1;
			Q.emplace(xx,y);
			it = S2[y].erase(it);
			S1[xx].erase(y);
		}
	}
	
	if(dis[xt][yt]==Inf)cout<<-1<<endl;
	else cout<<dis[xt][yt]<<endl;
	
	return 0;
}

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

int main(void) {
	int N; cin >> N;
	int A[N], i, j;

	for (i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (j = 0; j < 52; j++) {
		for (i = 0; i < N; i++) {
			if (A[i] % 2 == 0) {
				A[i] /= 2;
			}
			else { goto Er; }
		}
	}

	Er:
	cout << j<< endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<u32>();

    let mut count = 0;
    for i in 0..n {
        for j in (i + 1..n).rev() {
            if a[j] < a[j - 1] {
                let tmp = a[j];
                a[j] = a[j - 1];
                a[j - 1] = tmp;
                count += 1;
            }
        }
    }

    let ans = a
        .into_iter()
        .map(|i| i.to_string())
        .collect::<Vec<String>>()
        .join(" ");
    println!("{}\n{}", ans, count);
}



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

string s[10010];
int cnt[10010];

int main(){
	int n; cin >> n;
	long long ans = 0;
	long long cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < n; i++){
		cin >> s[i];
		for (int j = 1; j < s[i].length(); j++){
			ans += s[i][j - 1] == 'A' && s[i][j] == 'B';
		}
		if (s[i][0] == 'B' && s[i].back() == 'A') cnt1++;
		else if (s[i][0] == 'B') cnt2++;
		else if (s[i].back() == 'A')cnt3++;
	}
	if (cnt1 == 0){
		printf("%lld\n", ans + min(cnt2, cnt3));
		return 0;
	}
	ans += cnt1 - 1;
	if (cnt3) ans++, cnt3--;
	if (cnt2) ans++, cnt2--;
	ans += min(cnt3, cnt2);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    struct P
    {
        public int num;
        public string str;
        public P(int num,string str)
        {
            this.num = num;
            this.str = str;
        }
        public override string ToString()
        {
            return $"{str}{num}";
        }
    }
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var input = ReadLine().Split(' ');

        var ar = input.Select(i => new P(int.Parse(i.Substring(1)), i.Substring(0, 1))).ToArray();
        var ar2 = new P[num];
        Array.Copy(ar, ar2, ar.Length);
        for (var i = 0; i < num; i++)
        {
            var minj = i;
            for (var j = i; j < num; j++)
                if (ar[j].num < ar[minj].num)
                    minj = j;
            var t = ar[i];
            ar[i] = ar[minj];
            ar[minj] = t;
        }

        for(var i = 0; i < num - 1; i++)
        {
            for(var j = num - 1; j > i; j--)
            {
                if (ar2[j].num < ar2[j - 1].num)
                {
                    var t = ar2[j];
                    ar2[j] = ar2[j - 1];
                    ar2[j - 1] = t;
                }
            }
        }
        var str = "";
        for(var i = 0; i < num; i++)
        {
            if (ar[i].ToString() != ar2[i].ToString())
            {
                str = "Not stable";
            }
        }
        if (str == String.Empty) str = "Stable";
        WriteLine($"{string.Join(" ", ar2.Select(p => p.ToString()).ToArray())}\nStable\n{string.Join(" ", ar.Select(p => p.ToString()).ToArray())}\n{str}");
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}



Measured memory_bytes: 18520
// Problem : D - Alter Altar
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	string str;
	cin>>str;
	vi rl(N),wr(N);
	if(str[0]=='W')
		rl[0]=1;
	F0R(x,N-1)
	{
		rl[x+1]=rl[x];
		if(str[x+1]=='W')
			rl[x+1]++;
		 // bug(rl[x+1]);
	}
	if(str.back()=='R')
		wr.back()=1;
	F0Rd(x,N-1)
	{
		wr[x]=wr[x+1];
		if(str[x]=='R')
			wr[x]++;
		// bug(wr[x]);
	}
	int ans=min(wr[0],rl.back());
	F0R(x,N-1)
	{
		int val=min(wr[x+1],rl[x])+abs(wr[x+1]-rl[x]);
		ckmin(ans,val);
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 5232
using namespace std;
#include <bits/stdc++.h>
 
int main(){
	int k,a,b;
    cin>>k>>a>>b;
    if(k<=(b-a))
    	cout<<"OK"<<endl;
    else
    {
    	bool ispos= false;
    	for(int i=a; i<=b; i++)
        {
        	if(i%k==0)
            {
            	ispos= true;
            }
        }
        
        if(ispos)
        	cout<<"OK"<<endl;
        else
        	cout<<"NG"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if (S[5] == '1' || S[6] >= '5') {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//package AtCoder;
import java.util.*;
class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int a=sc.nextInt();
//		int c=0;
//		int ans=h/a;
//		if(h%a==0)
//			System.out.println(ans);
//		else
//		{
//			ans=ans+1;
//			System.out.println(ans);
//		}
		
		//int[] a=new int[n];
		int sum=0;
		for(int i=0;i<a;i++)
		{
			sum=sum+sc.nextInt();
		}
		
		if(sum>=h)
			System.out.println("Yes");
		else
			System.out.println("No");
		
		
	}

}


Measured memory_bytes: 47588
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int A, B;
    cin >> A >> B;
    for(int i=1; i<10000; i++){
        if(i*8/100==A && i*10/100==B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

int main() {
	double l;cin>>l;

    cout << fixed << setprecision(10);
    cout << (l/3)*(l/3)*(l/3);
  
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	string N;
	cin >> N;
	string ans = "No";
	rep(i, 3) if (N[i] == '7') ans = "Yes";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632