akhauriyash/Code-Regression huggingface dataset:
STABLE = 'Stable'
UNSTABLE = 'Not stable'


def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(' '.join(bubble_sorted))
  print(STABLE)

  print(' '.join(select_sorted))
  print(stability)

  return 0


def order(card_sym):
  order = int(card_sym[1])
  return order


def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements


def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements


if __name__ == '__main__':
  main()

Measured memory_bytes: 7768
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  Int ans=0,cnt=0;
  Int n=s.size();
  for(Int i=0;i<n;i++){
    if(s[i]=='B') cnt++;
    else ans+=cnt;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1152
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int M=1e3+10;
	ll fac[M],facinv[M],Inv[M];ll C(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,M-1) fac[i]=fac[i-1]*i%MOD;
		facinv[M-1]=invm(fac[M-1]);fd(i,M-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,M-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e5+10;
	//------------------FIXED------------------
	
	void main()
	{
		ll x=qread(),y=qread();
		int ans=0;while(x<=y) x*=2,ans++;write(ans);
	}
};//����������
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();//����Ԥ����ģ����
	mine::main();
	debug("\n---------------------Zory---------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n;
	cin>>n;
	map<ll,int>cnt;
	FOR(i,1,101){
		FOR(j,1,101){
			FOR(k,1,101){
				ll po=(i+j+k)*(i+j+k);
				ll mi=i*j+i*k+j*k;
				cnt[po-mi]++;
			}
		}
	}
	FOR(i,1,n+1){
		cout<<cnt[i]<<endl;
	}
	

}

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


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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  map <ll, ll> score;
  set <ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    if (score.count(a)) score.at(a)++;
    else score[a] = 1;
    s.insert(a);
  }
  ll odd = 0;
  for (auto p : score) {
    if (p.second%2 == 0) odd++;
  }
  if (odd%2) cout << s.size()-1 << endl;
  else cout << s.size() << endl;
}

Measured memory_bytes: 11136
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    int x = 0;
    switch(s) {
      case "SUN": x=7; break;
      case "MON": x=6; break;
      case "TUE": x=5; break;
      case "WED": x=4; break;
      case "THU": x=3; break;
      case "FRI": x=2; break;
      case "SAT": x=1; break;
    }
    System.out.println(x);
  }
}

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

int main()
{
    int n, x, q, t, mi, mf;
    cin >> n;
    vector<int> vec;

    while (n--)
    {
        cin >> x;
        vec.push_back(x);
    }

    cin >> q;
    while (q--)
    {
        cin >> t >> mi >> mf;
        if (t == 0)
        {

            cout << *min_element(vec.begin() + mi, vec.begin() + mf) << endl;
        }
        else
        {

            cout << *max_element(vec.begin() + mi, vec.begin() + mf) << endl;
        }
    }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<pair<int, int> > vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first >> vec[i].second;
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n; i++) {
    k -= vec[i].second;
    if (k <= 0) {
      cout << vec[i].first << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
  int n,array[200001],ans[200001],i,j=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&array[i]);
    }
  
  for(i=n-1;i>=0;i-=2)
    {
      ans[j] = array[i];
      j++;
    }
  
  i += 2;
  if(i==0)
    {
      i++;
    }
  else
    {
      i--;
    }
  
  for(;i<n;i+=2)
    {
      ans[j] = array[i];
      j++;
    }
  
  for(j=0;j<n;j++)
    {
      if(j != n-1)
	{
	  printf("%d ",ans[j]);
	}
      else
	{
	  printf("%d\n",ans[j]);
	  return 0;
	}
    }
}


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

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

using namespace std;

int main(){
  string s;cin>>s;
  rep(i, s.size()-1){
    if(s[i]=='A' && s[i+1]=='C'){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);
        int r = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());

        Integer[] gram = new Integer[11];
        gram[0] = x;
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= 10; i++) {
            gram[i] = r * gram[i - 1] - d;
            sb.append(gram[i]);
            if (i <10) {
                sb.append("\n");
            }
        }

        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string S;
  cin >> S;
  int n = SZ(S);
  int p = 0;
  int lev = 0;
  int ans = 0;
  REP(i, n) {
    int np = (S[i] == 'R' ? (p+1)%4 : (p+3)%4);
    if (lev == 0) {
      if (p == 0 && np == 1) lev++;
      else lev = max(0LL, lev-1);
    } else if (lev == 1) {
      if (p == 1 && np == 2) lev++;
      else lev--;
    } else if (lev == 2) {
      if (p == 2 && np == 3) lev++;
      else lev--;
    } else if (lev == 3) {
      if (p == 3 && np == 0) lev = 0, ans++;
      else lev--;
    }
    p = np;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int dp[4010][4010];
string str1, str2;

int main() {
    while (cin >> str1 >> str2) {
        int res = 0;
        
        memset(dp, -1, sizeof(dp));
        for (int i = 0; i < str1.size(); ++i) 
            for (int j = 0; j < str2.size(); ++j) 
                if (str1[i] == str2[j]) 
                    dp[i][j] = 1, res = 1;
        
        for (int i = 0; i < str1.size()-1; ++i) {
            for (int j = 0; j < str2.size()-1; ++j) {
                if (str1[i+1] == str2[j+1] && dp[i][j] != -1) {
                    chmax(dp[i+1][j+1], dp[i][j] + 1);
                    chmax(res, dp[i+1][j+1]);
                }
            }
        }
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 64028
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;
import std.math;

void main() {
  int n, m;
  readf("%d %d\n", &n, &m);
  int m2 = m;
  auto a = readln.chomp.split.map!(to!int);
  int sum = 0;
  foreach(ai; a) sum += ai;
  foreach(ai; a) {
    if(ai*4*m >= sum) m2--;
    if(m2 == 0) {
      writeln("Yes");
      return;
    }
  }
  writeln("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,X,M,SUM;
    M=0;
    SUM=0;
    cin>>N;
    while(N--){
        cin>>X;
        SUM +=X;
        M=max(M,X);
    }
    if(M<(SUM-M)) cout<<"Yes"<<endl;
    else          cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Takahashikun, The Strider
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m > 0, n > 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

/* main */

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

  int g = gcd<int>(360, x);
  printf("%d\n", 360 / g);
  return 0;
}


Measured memory_bytes: 3228
N,M = gets.split.map &:to_i
AC = {}
WA = Hash.new(0)
M.times{
  q,s = gets.split
  case s
  when "AC"
    AC[q] = 1
  when "WA"
	WA[q] += 1 if !AC[q]
  end
}
puts [AC.keys.size, AC.keys.map{ |q| WA[q] }.reduce(0,:+)] * " "

Measured memory_bytes: 17532
//Write and Erase

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int n;cin>>n;
    map<int,int>m{};
    rep(i,0,n){
        int a;cin>>a;
        if(m[a]==0)m[a]=1;
        else if(m[a]==1)m[a]=0;
    }
    int ans = 0;
    irep(i,m){
        if(i->second>0)ans++;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 4864
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int z[22]={0,1,2,3,4,5,6,7,8,9,1},o[22]={1,9,8,7,6,5,4,3,2,1,0};
string s;
char buf[1010101];
int dp[1010101][2];
int main()
{
	scanf("%s",buf);
	s=buf;
	int nw=s[0]-'0';
	dp[0][0]=min(z[nw],o[nw]+1);
	dp[0][1]=min(z[nw+1],o[nw+1]+1);
	for(int i=1;i<s.size();i++)
	{
		nw=s[i]-'0';
		dp[i][0]=min(dp[i-1][0]+min(z[nw],o[nw]+1),dp[i-1][1]+min(o[nw],z[nw]+1));
		dp[i][1]=min(dp[i-1][0]+min(z[nw+1],o[nw+1]+1),dp[i-1][1]+min(o[nw+1],z[nw+1]+1));
	}
	cout<<dp[s.size()-1][0]<<endl;
	return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define intpair pair<int,int>
using namespace std;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int pow(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);} //sort pair in descending order
int main(){
		ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin>>n;
    set<string> dis;
    for(int i=0;i<n;i++){
			cin>>s;
			dis.insert(s);
		}
	cout<<dis.size()<<"\n";
}
 


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

using namespace std;

int flag[105]= {0};
char ch[105];

struct P{
int x,y;
}p[100000];
int ans[100000];
int main()
{
    int h,w,d,q;

    scanf("%d%d%d",&h,&w,&d);
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
        {
            int nub;
            scanf("%d",&nub);
            p[nub].x=i;
            p[nub].y=j;
        }
        for(int i=1;i<=h*w;i++)
        {
            if(i<d) ans[i]=0;
            else{
                ans[i] = ans[i-d] + abs(p[i].x - p[i-d].x) + abs(p[i].y - p[i-d].y);
            }
        }
    scanf("%d",&q);
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        printf("%d\n",ans[r]-ans[l]);
    }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <limits.h>
using namespace std;
typedef long long ll;

int main()
{
	ll start, fin, cnt = 0;
	start = 100;
	cin >> fin;
	while (start < fin)
	{
		cnt++;
		start = (double)start*1.01;
	}
	cout << cnt;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
	char r[5]={'A','B','C','D','E'};
	int s1[5],i,s2[5],m=0,l;
	while(1){
		for(i=0;i<5;i++){
			scanf("%d%d",&s1[i],&s2[i]);
			if(s1[i]==0&&s2[i]==0){
				return 0;
			}
		}
		for(i=0;i<5;i++){
			if(m<s1[i]+s2[i]){
				m=s1[i]+s2[i];
				l=i;
			}
		}
		printf("%c %d\n",r[l],m);
		m=0;
	}
	return 0;
}

Measured memory_bytes: 2580
#include <stdio.h>
#define MAX 1000000000;
int A[500000];
int Lef[500000],Rig[500000];
int count=0;

void Merge(int left,int mid,int right){
  int a,b,i,j,k;	
  a=mid-left;	
 b=right-mid;
   
  for(i=0;i<a;i++)
    {
      Lef[i]=A[left+i];
    }
  for(i=0;i<b;i++)
    {
      Rig[i]=A[mid+i];
    }
  Lef[a]=MAX;
  Rig[b]=MAX;
  i=0;
  j=0;
  for(k=left;k<right;k++)
    {
      count++;
      if(Lef[i]<=Rig[j])
    {
      A[k]=Lef[i];
      i++;
    }
      else
    {
    	  A[k]=Rig[j];
      j++;
    }	
   }	
}	
 	
void Mergesort(int left,int right){
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      Mergesort(left,mid);
      Mergesort(mid,right);
      Merge(left,mid,right);
    }
		}
	
main(){
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
 
  Mergesort(0,n);
 
  for(i=0;i<n;i++)
    {
      printf("%d",A[i]);
      if(i<n-1)
    {
      printf(" ");
    }
    }
  printf("\n");
  printf("%d\n",count);
return 0;
}

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

using namespace std;

int calc(int x, int bit) {
	return (x >> bit) & 1 ? 1 : -1;
}

char ope_c(int x, int bit) {
	return calc(x, bit) == 1 ? '+' : '-';
}

int main() {
	int n, a, b, c, d;
	scanf("%d", &n);
	d = n % 10;
	n /= 10;

	c = n % 10;
	n /= 10;

	b = n % 10;
	n /= 10;

	a = n % 10;

	for (int i = 0; i < 8; i++) {
		int val = a + calc(i, 0) * b + calc(i, 1) * c + calc(i, 2) * d;
		if (val == 7) {
			printf("%d%c%d%c%d%c%d=7\n", a, ope_c(i, 0), b, ope_c(i, 1), c, ope_c(i, 2), d);
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int t[4];
	int i;
	int st;
	int x, y;
	
	st = 0;
	for (i = 0; i < 4; i++) {
		scanf("%d", &t[i]);
		st += t[i];
	}
	x = st / 60;
	y = st % 60;
	
	printf("%d\n%d\n", x, y);
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,1000) {
    string t;
    int x = i;
    rep(j,3) {
      t += '0'+x%10;
      x /= 10;
    }
    int ti = 0;
    rep(j,n) {
      if (s[j] == t[ti]) {
        ++ti;
        if (ti == 3) break;
      }
    }
    if (ti == 3) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int n, m;
//char maze[101][101];
//typedef pair < int, int> P;
//int sx, sy, gx, gy;
//int d[101][101];
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 1,0,-1,0 };

//const ll mod = 1000000007;

int main()
{
	cin >> n;
	int t, a;
	cin >> t >> a;
	vector<int>h(n);
	double answer = INF;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (answer > abs(a - (t - 0.006 * h[i]))) {
			answer = abs(a - (t - 0.006 * h[i]));
			ans = i;
		}
	}
	cout << ans+1 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] listStr = reader.readLine().split(" ");
    int[] list = new int[listStr.length];

    for (int i = 0; i < listStr.length; i++) {
      list[i] = Integer.parseInt(listStr[i]);
    }

    ascendingSort(list);

    System.out.println(Arrays.toString(list).replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(",", ""));

  }

  public static void ascendingSort(int[] array) {
    for (int i = 0; i < array.length; i++) {
      for (int j = 0; j < array.length - 1 - i; j++) {
        if (array[j] > array[j + 1]) {
          int tmp = array[j];
          array[j] = array[j + 1];
          array[j + 1] = tmp;
        }
      }
    }
  }

  public static void descendingSort(int[] array) {
    for (int i = array.length - 1; i >= 0; i--) {
      for (int j = array.length - 1; j > array.length - 1 - i; j--) {
        if (array[j] > array[j - 1]) {
          int tmp = array[j];
          array[j] = array[j - 1];
          array[j - 1] = tmp;
        }
      }
    }
  }

}

Measured memory_bytes: 16900
import sys
input = sys.stdin.readline
D = 10**9+7

N, K = map(int, input().split())
A = list(map(int, input().split()))

afters = [0]*N
alls = [0]*N

for i, key in enumerate(A):
    for j, a in enumerate(A):
        if a < key:
            alls[i] += 1
            if j > i:
                afters[i] += 1

ans = sum(afters)*K + sum(alls)*K*(K-1)//2
print(ans % D)

Measured memory_bytes: 41964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    int N, H; cin >> N >> H;
    
    int maxA = 0;
    vector<pair<int, int>> tmpvec(N);
    for(int i=0; i<N; i++){
        int a, b; cin >> a >> b;
        maxA = max(maxA, a);
        tmpvec[i] = {b, a};
    }

    vector<int> bvec;
    for(int i=0; i<N; i++){
        if(tmpvec[i].first >= maxA){
            bvec.push_back(tmpvec[i].first);
        }
    }

    sort(bvec.begin(), bvec.end(), greater<int>());
    //for(int i=0; i<bvec.size(); i++) cout << bvec[i] << endl;
    int B_sum = 0;
    for(int i=0; i<bvec.size(); i++){
        B_sum += bvec[i];
        if(B_sum >= H){
            cout << i+1 << endl;
            //cout << 55 << endl;
            return 0;
        }
    }

    cout << (H - B_sum - 1) / maxA + 1 + bvec.size() << endl;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register ll i=(a);i<=(b);i++)
#define For(i,a,b) for (register ll i=(a);i>=(b);i--)
#define GO(u) for (register ll j=f[u];j!=-1;j=nxt[j])
#define mem(i,j) memset(i,j,sizeof(i))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll N=2e5+5;
ll n,a[N],b[N],ans=0;
struct data
{
	ll val,pos;
};
bool operator <(data x,data y)
{
	return x.val<y.val;
}
priority_queue <data> q;
inline ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
inline void write(ll x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
	return;
}
inline void no()
{
	write(-1);
	putchar('\n');
	exit(0);
}
int main()
{
	n=read();
	FOR(i,1,n) a[i]=read();
	FOR(i,1,n) b[i]=read();
	FOR(i,1,n) q.push((data){b[i],i});
	while (q.size())
	{
		data tmp=q.top();
		q.pop();
		if (tmp.val==a[tmp.pos]) continue;
		if (tmp.val<a[tmp.pos]) no();
		ll tmpsum=b[tmp.pos+1]+b[tmp.pos-1];
		if (tmp.pos==1) tmpsum+=b[n];
		if (tmp.pos==n) tmpsum+=b[1];
		if (tmpsum>tmp.val-a[tmp.pos]) no();
		ll tms=(tmp.val-a[tmp.pos])/tmpsum;
		ans+=tms;
		b[tmp.pos]-=tms*tmpsum;
		tmp.val=b[tmp.pos];
		q.push(tmp);
	}
	write(ans);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 9200
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;



int par[110000]; //親
int ran[110000]; //木の深さ

// n要素を初期化
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    ran[i]=0;
  }
}

//木の根を求める
int find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(ran[x]<ran[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(ran[x]==ran[y]) ran[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
  return find(x)==find(y);
}

struct edge{
  ll u,v,cost;
};

bool comp(const edge& e1,const edge& e2){
  return e1.cost<e2.cost;
}

edge es[210000];
int V,E; //頂点数と辺数

ll kruskal(){
  sort(es,es+E,comp);
  init(V);
  ll res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res+=e.cost;
    }
  }
  return res;
}



int main(){
  int N;
  P x[110000],y[110000];
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>x[i].first>>y[i].first;
    x[i].second=y[i].second=i;
  } 
  sort(x,x+N); sort(y,y+N);

  for(int i=0;i<N-1;i++){
    es[i].cost=x[i+1].first-x[i].first;
    es[i].u=x[i].second; es[i].v=x[i+1].second;
    
    es[N-1+i].cost=y[i+1].first-y[i].first;
    es[N-1+i].u=y[i].second; es[N-1+i].v=y[i+1].second;
    
  }
  
  V=N;
  E=2*(N-1);
  cout<<kruskal()<<endl;;
  
  
}


Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


int main(){

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    int l = 1;
    int r = 1;

    int sum = 0;
    int cnt = 0;
    while(true){
      if( r >= n ) break;

      while( sum > n ){
        sum -= l;
        l++;
        if( sum == n ) cnt++;
      }

      sum += r;
      r++;
      if( sum == n ) cnt++;
      // cerr << sum << " " << l << " " << r << endl;
    }
    cout << cnt << endl;
  }


  return 0;
}








// EOF

Measured memory_bytes: 3092
#include <stdio.h>

int main() {
  int number_a, number_b;
  scanf("%d %d", &number_a, &number_b);
  if(number_a * number_b % 2 == 0) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int n;
vi g[N], col[2];
bool vis[N];

void dfs(int v, int c) {
	vis[v] = 1;
	col[c].pb(v);
	for(auto it : g[v]) {
		if(!vis[it]) {
			dfs(it, c ^ 1);
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin >> n;
	for(int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1, 0);
	if(col[0].size() > col[1].size()) {
		swap(col[0], col[1]);
	}
	vi ans(n + 1, 0);
	if(col[0].size() <= (n / 3)) {
		int cur = 1;
		for(auto it : col[1]) {
			ans[it] = cur;
			cur++;
			if(cur % 3 == 0) {
				cur++;
			}
			if(cur > n) {
				break;
			}
		}
		cur = 3;
		for(auto it : col[0]) {
			ans[it] = cur;
			cur += 3;
		}
		for(int i = 1; i <= n; i++) {
			if(ans[i] == 0) {
				ans[i] = cur;
				cur += 3;
			}
		}
	}
	else {
		int cur = 1;
		for(int i = 0; i < col[0].size(); i++) {
			ans[col[0][i]] = cur;
			cur += 3;
			if(cur > n) {
				break;
			}
		}
		cur = 2;
		for(int i = 0; i < col[1].size(); i++) {
			ans[col[1][i]] = cur;
			cur += 3;
			if(cur > n) {
				break;
			}
		}
		cur = 3;
		for(int i = 1; i <= n; i++) {
			if(ans[i] == 0) {
				ans[i] = cur;
				cur += 3;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 20588
#include<cstring>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define low(x) (x&(-x)) 
#define maxn 200500
#define inf 1000000000
#define mm 1000000007
#define ll long long
using namespace std;

ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
struct data{int obj,pre,c;
}e[maxn*2];
int head[maxn],s[maxn],p[maxn],n,rt,au,av,tot;
ll ans;
void insert(int x,int y,int c){
	e[++tot].obj=y; e[tot].pre=head[x]; head[x]=tot; e[tot].c=c; 
}
void dfs(int u,int fa){
	s[u]=1;
	int mx=0;
	for (int j=head[u];j;j=e[j].pre){
		int v=e[j].obj;
		if (v==fa) continue;
		dfs(v,u);
		mx=max(mx,s[v]);
		s[u]+=s[v];
		ans+=2LL*min(s[v],n-s[v])*e[j].c;
	}
	mx=max(mx,n-s[u]);
	p[u]=mx;
	if (mx<p[rt]) rt=u,au=rt,av=0;
	else if (mx==p[rt]) av=u;
}
int main(){
//	freopen("in.txt","r",stdin);
	n=read();
	rep(i,1,n-1){
		int x=read(),y=read(),c=read();
		insert(x,y,c); insert(y,x,c);
	}
	rt=0; p[rt]=n;
	dfs(1,0);
	if (au&&av) {
		for (int j=head[au];j;j=e[j].pre){
			int v=e[j].obj;
			if (v==av) ans-=1LL*e[j].c;
		}
	}
	else {
		int mn=inf;
		for (int j=head[au];j;j=e[j].pre){
			mn=min(mn,e[j].c);
		}
		ans-=1LL*mn;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 12160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FORE(i, v) for (auto i : v)
#define fi   first
#define se   second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 1e5 + 5;
vector <int> adj[N], topo;
int dp[N], n, m;
bool mark[N];

void dfs(int u) {
	mark[u] = true;
	FORE(v, adj[u]) if (!mark[v]) dfs(v);
	topo.push_back(u);
}

void input() {
	scanf("%d %d", &n, &m);
	REP(nhi, m) {
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
	}
	memset(dp, 0, sizeof dp);
  	memset(mark, 0, sizeof mark);
}

void solve() {
	FOR(i, 1, n) dfs(i);
	reverse(topo.begin(), topo.end());
	int res = 0;
	FORE(u, topo) {
		FORE(v, adj[u]) dp[v] = max(dp[v], dp[u] + 1);
		res = max(res, dp[u]);
	}
	printf("%d\n", res);
}

int main(int argc, char const *argv[])
{

	input();
	solve();

	return 0;
}


Measured memory_bytes: 9464
#include <stdio.h>

int main()
{
  int i, j, n;
  char buf[16];
  buf[15]=0;
  buf[14]=':';
  fscanf(stdin, "%d", &n);
  unsigned int u, v, val=1;
  for (i=0; i<n; i++) val <<= 1;
  fputs("0:\n", stdout);
  for (u=1; u<val; u++) {
    v = u;
    for (j=13; v>0; j--, v/=10)   buf[j] = '0' + (v%10);
    fputs(buf+j+1, stdout);
    v = u;
    for (i=0; i<n; i++) {
      if (v%2) {
	putc_unlocked(' ', stdout);
	if (i>=10)	putc_unlocked('0' + i/10, stdout);
	putc_unlocked('0' + i%10, stdout);
      }
      v>>=1;
    }
    putc_unlocked('\n',stdout);
  }
  return 0;
}



Measured memory_bytes: 2104
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N;
	cin >> N;

	if (N == 1)
	{
		cout << N << '\n';
		return 0;
	}
	while (N > 0)
	{
		int x;
		x = N;
		while (x > 0)
		{
			if (x % 2 == 0)
			{
				x = x / 2;
			}
			else
			{
				break ;
			}
		}
		if (x == 1)
		{
			cout << N << '\n';
			return 0;
		}
		N--;
	}
	return 0;
}


Measured memory_bytes: 256
e,y=map(int,input().split())
if e==0:
    if 1868<=y<=1911:
        print ("M",y-1867 ,sep="")
    elif 1912<=y<=1925:
        print("T",y-1911,sep="")
    elif 1926<=y<=1988:
        print("S",y-1925,sep="")
    else :
        print("H",y-1988,sep="")
elif e==1:
    print(y+1867)
elif e==2:
    print(y+1911)
elif e==3:
    print(y+1925)
else:
    print (y+1988)
    


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)

#define BR "\n"
#define SP " "

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

  vector<int> A(N);
  rep0(i, N) cin >> A[i];

  int Q;
  cin >> Q;
  rep0(i, Q) {
    int b, e, k;
    int ans = 0;
    cin >> b >> e >> k;
    rep(j, b, e) {
      if (A[j] == k) ans++;
    }
    cout << ans << BR;
  }
  return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
static const int MOD = 10000007;

int N;


int main() {
  char pred[3], real[3];
  rep(i,3) {
    cin >> pred[i];
  }
  rep(i,3) {
    cin >> real[i];
  }
  int cnt;
  rep(i,3){
    if(pred[i] == real[i]) cnt++;
  }
  cout << cnt << endl;
}


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

int64_t mod=1e9+7;
vector<int64_t> fac,finv;

int64_t modpow(int64_t a,int64_t n){
  int64_t ans=1;
  while(n>0){
    if(n&1){
      ans*=a;
      ans%=mod;
    }
    a*=a;
    a%=mod;
    n>>=1;
  }
  return ans;
}

int64_t modinv(int64_t a){
  return modpow(a,mod-2);
}

int64_t com(int64_t n,int64_t r){
  int64_t ans;
  if(n<r){
    return 0;
  }
  if((n<0)||(r<0)){
    return 0;
  }
  ans=fac.at(n)*((finv.at(r)*finv.at(n-r))%mod)%mod;
  return ans;
}

int main(){
  int X,Y;
  int64_t n,m;
  cin >> X >> Y;
  if((X+Y)%3!=0){
    cout << 0 << endl;
    return 0;
  }
  n=(2*Y-X)/3;
  m=Y-2*n;
  if((n<0)||(m<0)){
    cout << 0 << endl;
    return 0;
  }

  fac.resize(n+m+1);
  finv.resize(n+m+1);

  fac.at(0)=1;
  finv.at(0)=1;

  for(int64_t i=1;i<=n+m;i++){
    fac.at(i)=fac.at(i-1)*i;
    fac.at(i)%=mod;
    finv.at(i)=finv.at(i-1)*modinv(i);
    finv.at(i)%=mod;
  }

  int64_t ans=com(n+m,n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10624
# ABC102 C - Linear Approximation
N = int(input())
A = list(map(int, input().split()))

bl = []
for i in range(N):
    bl.append(A[i] - (i+1))
bl.sort()
b = bl[N//2]

ans = 0
for i in range(N):
    ans += abs(A[i] - (b + (i+1)))
print(ans)

Measured memory_bytes: 26708
#include<bits/stdc++.h>
using namespace std;
long long s1[200005],s2[200005];
long long n;
long long a[200005];
long long l,r,mid;
long long ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)s1[i]=s1[i-1]+a[i],s2[i]=s2[i-1]^a[i];
	for(int i=1;i<=n;i++){
		l=i,r=n+1;
		while(l+1<r){
			mid=l+r>>1;
			if(s1[mid]-s1[i-1]==(s2[mid]^s2[i-1]))l=mid;else r=mid;
		}
		ans+=l-i+1;
	}
	cout<<ans;
}

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

int main() {
  string S;
  vector<int> jug(10);
  cin >> S;

  for (int i = 0; i < S.size(); i++) {
    for (int j = i; j < S.size(); j++) {
      if (S.at(j) == 'A' || S.at(j) == 'C' || S.at(j) == 'G' || S.at(j) == 'T') {
        jug.at(i)++;
      }
      else {
        break;
      }
    }  
  }
  sort(jug.begin(), jug.end(), greater<>());
  cout << jug.at(0) << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
    int A, B;
    cin >> A >> B;
    int C = A * B;
    cout << C << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(void){
  int s;
  int i,j;
  
  scanf("%d",&s);
  
  i=s/100;
  j=s-i*100;
  
  if((0<i&&i<=12)&&(0<j&&j<=12)){
    printf("AMBIGUOUS");
  }
  else if(0<i&&i<=12){
    printf("MMYY");
  }
  else if(0<j&&j<=12){
    printf("YYMM");
  }
  else{
    printf("NA");
  }
  
  return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 5;

ll dp[N][2] = {};

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

  int n;
  cin >> n;
  vector < int > a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];

  dp[1][0] = 0;
  dp[1][1] = a[1];
  if (n % 2) {
    for (int i = 2; i <= n; i++) {
      if (i % 2) {
        dp[i][0] = max (dp[i - 2][0] + a[i], dp[i - 1][1]);
        dp[i][1] = a[i] + dp[i - 2][1];
      } else {
        dp[i][0] = max (dp[i - 2][0] + a[i], dp[i - 1][0]);
        dp[i][1] = max (dp[i - 2][1] + a[i], dp[i - 1][1]);
      }
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (i % 2) {
        dp[i][0] = max (dp[i - 2][0] + a[i], dp[i - 1][1]);
        dp[i][1] = a[i] + dp[i - 2][1];
      } else {
        dp[i][0] = max (a[i] + dp[i - 2][0], dp[i - 1][1]);
        dp[i][1] = max (a[i] + dp[i - 2][0], dp[i - 1][1]);
      }
    }
  }

  cout << dp[n][0] << '\n';
}


Measured memory_bytes: 7168
N = int(input())
sel = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if not j == k:
                dp[i+1][k] = max(dp[i+1][k], dp[i][j]+sel[i][k])

print(max(dp[N]))

Measured memory_bytes: 47328
# Aizu Problem CGL_3_A: Area
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def poly_area(polygon, M):
    A = 0
    for i in range(M):
        x1, y1 = polygon[i][0], polygon[i][1]
        x2, y2 = polygon[(i+1)%M][0], polygon[(i+1)%M][1]
        A += (x1 * y2 - x2 * y1)
    return abs(A / 2)

N = int(input())
P = [[int(_) for _ in input().split()] for __ in range(N)]
print(poly_area(P, N))

Measured memory_bytes: 7784
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    if (a + b == 15) {
        cout << "+" << endl;
    } else if (a * b == 15) {
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }

    return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

vector<ll> div(ll x){
  vector<ll> ds;
  for(ll i=1;i<=x;i++){
    if(x%i==0)ds.push_back(i);
  }
  return ds;
}

ll mpow[200010];

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

  ll n;
  string x;
  cin>>n>>x;
  rep(i,n+1)mpow[i]=mod_pow(2,i);
  vector<ll> bx(n);
  rep(i,n)bx[i]=(x[i]=='1'?1:0);
  ll p=1;
  while(n%(2*p)==0){
    p<<=1;
  }
  vector<ll> ds=div(n/p);
  vector<ll> t(n+1,0),cnt(n+1,0);

  for(ll d:ds){
    ll T=d*p*2;
    ll bsz=d*p;

    bool ok=true;
    rep(i,n){
      ll r=i%(2*bsz);
      if(r<bsz){
        if(bx[i]>bx[r]){
          break;
        }else if(bx[i]<bx[r]){
          ok=false;
          break;
        }
      }else{
        if(bx[i]>1-bx[r-bsz]){
          break;
        }else if(bx[i]<1-bx[r-bsz]){
          ok=false;
          break;
        }
      }
    }

    ll sum0=0;
    if(ok){
      sum0=1;
    }
    rep(i,bsz){
      if(bx[i]==1)(sum0+=mpow[bsz-1-i])%=mod;
    }

    t[d]=T;
    cnt[d]=sum0;
  }

  ll res=0;
  repl(i,1,n+1){
    (res+=t[i]*cnt[i]%mod)%=mod;
    for(ll j=i*2;j<=n;j+=i)(cnt[j]+=mod-cnt[i])%=mod;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 6804
#include<stdio.h>
#define N 44

int a[N];
 int  fibonacci(int n){
    if(n==0 || n==1) return a[0]=1;
    if(a[n]!=-1) return a[n];
    return a[n]=fibonacci(n-1)+fibonacci(n-2);
  }

int main(){
  int i,n;
  for(i=0;i<=N;i++){
    a[i]=-1;
  }

  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}

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

int main(){
	int a,b,c;
	int ans;
	bool flg;
	int cnt=0;
	
	while(cin>>a>>b){
		cnt++;flg=false;
		//-----test-----
		if(cnt==110) break;
		//--------------
		c=a+b;
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Usize1},
};

#[fastout]
fn main() {
    input! {
        n : String
    }
    let a : u32 = n.chars().map(|c| c.to_digit(10).unwrap()).sum();
    println!("{}",if a%9 == 0 {"Yes"} else {"No"})
}


Measured memory_bytes: 2400
import numpy as np
ans=0
N=int(input())
s1,s_1,s0=[],[],[]
s=list(map(int,input().split()))
s_=np.array(s)-np.array(range(N))
for i in s_:
    if i<0:
        s_1.append(i)
    elif i==0:
        s0.append(i)
    else:
        s1.append(i)
if len(s1)==len(s_1) or (max(len(s1),len(s_1))<=min(len(s1),len(s_1))+len(s0)):
    print(-1*sum(s_1)+sum(s1))
    exit()
s1=sorted(s1)
s_1=sorted(s_1)
p=len(s1)-len(s_1)-len(s0)
q=len(s_1)-len(s1)-len(s0)
t=(max(p,q)-1)//2
if p>0:
    t=s1[t]
if q>0:
    t=s_1[t*(-1)-1]
ss=s1+s0+s_1
for i in ss:
    ans+=abs(i-t)
print(ans)


Measured memory_bytes: 34224