akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define ALL(a)  (a).rbegin(),(a).rend()
const int MOD = 1000000007;
int main() {
    string s; cin >> s;
    stack<char> S; S.push('Q');
    rep(i, s.size()) {
        if (s[i] == 'S') S.push('S');
        else if (s[i] == 'T' && (S.top() == 'T' || S.top() == 'Q')) S.push('T');
        else if (s[i] == 'T' && S.top() == 'S')S.pop();
    }
    cout << S.size()  - 1<< endl;
}

Measured memory_bytes: 644
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(){
        
        string[] input = Console.ReadLine().Split(' ');
        
        double n = double.Parse(input[0]);
        double d = double.Parse(input[1]);
        
        d *= 2;
        d++;
        
        double div = n/d;
        
        int ans = (int)div;
        
        if(div-(int)div > 0) ans++;
        
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N, W;
ll P[101];
vector<pair<int, int>> E[101];
pair<int, int> MA[101];
//---------------------------------------------------------------------------------------------------
ll ans = 0;
vector<ll> dfs(int cu, int pa, vector<ll> dp) {
	vector<ll> xs(W + 1, 0); // 連結でない
	vector<ll> xf = dp; // 連結である

	if (dp[W] == 0) {
		if (0 <= MA[cu].first) {
			auto zf = dfs(MA[cu].first, cu, xf);

			rrep(w, W, 0) {
				if (w + MA[cu].second <= W) chmax(xf[w + MA[cu].second], zf[w]);
			}
		}

		fore(p, E[cu]) if (p.first != pa and p.first != MA[cu].first) {
			dfs(p.first, cu, xs);

			vector<ll> zf;
			zf = dfs(p.first, cu, xf);

			rrep(w, W, 0) {
				if (w + p.second <= W) chmax(xf[w + p.second], zf[w]);
			}
		}
		rrep(w, W, 0) xf[w] += P[cu];
		rep(w, 0, W + 1) chmax(ans, xf[w]);
	}
	else {
		fore(p, E[cu]) if (p.first != pa) {
			vector<ll> zf;
			zf = dfs(p.first, cu, xf);

			rrep(w, W, 0) {
				if (w + p.second <= W) chmax(xf[w + p.second], zf[w]);
			}
		}
		rrep(w, W, 0) xf[w] += P[cu];
	}

	return xf;
}
//---------------------------------------------------------------------------------------------------
int dfs2(int cu, int pa) {
	int cnt = 1;

	int to = -1, cst = -1, ma = -1;
	fore(p, E[cu]) if(p.first != pa){
		int c = dfs2(p.first, cu);
		if (ma < c) {
			ma = c;
			to = p.first;
			cst = p.second;
		}
		cnt += c;
	}
	MA[cu].first = to;
	MA[cu].second = cst;

	return cnt;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> W;
	rep(i, 0, N) cin >> P[i];
	rep(i, 0, N - 1) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		E[a].push_back({ b,c });
		E[b].push_back({ a,c });
	}

	dfs2(0, -1);

	vector<ll> dp(W + 1, 0);
	dfs(0, -1, dp);

	cout << ans << endl;
}




Measured memory_bytes: 180012
class My_Queue:

    def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

    def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

    def isEmpty(self):
        return self.head == self.tail

    def isFull(self):
        return self.head == (self.tail + 1) % self.S


def main():
    n, qms = map(int, input().split())
    elapsed_time = 0
    q = My_Queue(n + 1)
    for i in range(n):
        name, time = input().split()
        time = int(time)

        q.enqueue([name, time])

    while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a)

if __name__ == "__main__":
    main()

Measured memory_bytes: 15868
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
string a="abcdefghijklmnopqrstuvwxyz";
int main()
{
       ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long n;
	long long p,c,m=0,s[1000];
	cin>>n;
	p=26;
	while (n!=0)//数制转换，结果存入数组s[m]
	{
	      n-=1;
		c=n%p;
		n=n/p;
		m++;s[m]=c;   //将余数按顺序存入数组s[m]中
	}
	for(int k=m;k>=1;k--)//输出转换后的序列
	{
		cout << a[s[k]];
	}
	return 0;
}



Measured memory_bytes: 3656
n ,m, k = [int(e) for e in input().split()]

def search(n, m, k):
    flag = False
    for n_rows in range(n+1):
        if flag:
            break
        for n_cols in range(m+1):
            blacks = n_rows * m + n_cols * n - 2*n_rows * n_cols
            if blacks == k:
                flag = True
                break
    return flag
if search(n, m, k):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
count = int(input())
poslist = ["0 0 0"]
acheive = True
for n in range(count):
	poslist.append(input())
for i in range(count):
	cur,cx,cy = map(int,poslist[i].split())
	next,nx,ny  = map(int,poslist[i+1].split())
	dif = next - cur
	difx = nx - cx
	dify = ny - cy
	chk = dif- difx -dify
	if chk%2 != 0 or chk < 0:
		acheive = False
		break
if acheive:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 10276
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int a,b,c,d,e;
template<class Type>
Type solve(Type res = Type()){
    int n,m; cin >> n >> m;
    vector<string> d(m);
    for(auto& in:d) cin >> in;
    
    vector<int> E(n+1,0),W(n+1,0);
    
    for(int i = 0; i < n;i++){
        for(int j = 0; j < m;j++){
            E[i+1] += (d[j][i]=='E');
        }
        E[i+1] += E[i];
    }
    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j < m;j++){
            W[i] += (d[j][i]=='W');
        }
        W[i] += W[i+1];
    }
    
    int min_err = INF;
    int boun = -1;
//
//    cout << E << endl;
//    cout << W << endl;
    for(int i = 0; i <= n;i++){
        if(min_err > E[i] + W[i]){
            boun = i;
            min_err = E[i] + W[i];
        }
    }
    cout << boun << " " << boun + 1 << endl;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



Measured memory_bytes: 4532
n = int(input())
arr = list(map(int,input().split()))
ans = [0 for i in range(n)]
ind = 1
for i in range(n):
    ans[arr[i]-1] = ind
    ind += 1

for i in range(n-1):
    print(ans[i],end=" ")
print(ans[-1])

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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i=0; i<N; ++i) cin >> h[i];

    const int INF = 1e9+1;
    vector<int> dp(N, INF);
    dp[0] = 0;
    for (int i=1; i<N; ++i) {
        for (int j=1; j<=K && i-j>=0; ++j) {
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String [] args)
	{
		Scanner stdin = new Scanner (System.in);
		int num = stdin.nextInt();
		if(num >= 1 && num <= 1000 ){
				num = num*num*num;
		}
		System.out.println(num);
	}
}

Measured memory_bytes: 26336
import java.io.*;

class Main{
	
	public static void main(String[] args)throws IOException{
		
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder str = new StringBuilder();
		
		int i = 0;
		
		while(true){
			i++;
			String tmp = input.readLine();
			int x = Integer.parseInt(tmp);
			if(x == 0){
				break;
			}
			str.append("Case " + i + ": " + x + "\n");
		}
		
		System.out.print(str);
		
	}
	
}

Measured memory_bytes: 26992
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main() {
    int n, m;
    bool flag = false;
    cin >> n >> m;
    vector<pair<int, int>> v(m);
    map<int, int> tmp;
    for (size_t i = 0; i < m; i++)
    {
        cin >> v[i].first >> v[i].second;
        if (v[i].first == 1)
        {
            tmp.insert(make_pair(v[i].second, v[i].second));
        }
    }
    for (size_t i = 0; i < m; i++)
    {
        if (tmp.end() != tmp.find(v[i].first) && v[i].second == n)
        {
            flag = true;
        }
    }
    if (flag)
    {
        cout << "POSSIBLE" << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }

}

Measured memory_bytes: 6528
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int count = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        while (true) {
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 != 0) {
                    System.out.println(count);
                    System.exit(0);
                } else {
                    a[i] /= 2;
                }
            }
            count++;
        }
    }
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main() {
    int a, b;
    cin >> a >> b;
    int diff = b - a;
    int re = diff * (diff + 1) / 2;
    cout << re - b << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0032
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int rectangleCnt = 0;
            int rhombusCnt = 0;
            while (true)
            {

                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) break;

                int[] items = Array.ConvertAll(line.Trim().Split(','), e => int.Parse(e));

                if (Math.Pow(items[0], 2) + Math.Pow(items[1], 2) == Math.Pow(items[2], 2)) rectangleCnt++;
                if (items[0] == items[1]) rhombusCnt++;

            }
            Console.WriteLine(rectangleCnt);
            Console.WriteLine(rhombusCnt);
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 13924
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#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 pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
inline int in() { int x; cin>>x; return x;}
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
#define dame {puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
//----------------------------------------------------------------
int main(int argc,char* argv[]){
    fileio
    vvi dp(MX,vi(3,0));
    int n= in();
    dp[0] = {0,0,0};
    rep(i,n){
        vi a(3);
        cin>>a;
        rep(j,3) rep(k,3) if(j!=k){
            maxs(dp[i+1][j],dp[i][k]+a[j]);
        }
    }
    cout<<*max_element(rng(dp[n]))<< endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,ans=0;
  cin >> N;
  for(ll i=1;i*i<N;i++){
    if((N-i)%i==0){
      ll k=(N-i)/i;
      if(N/k==N%k){
        ans+=k;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int H, W, N;
	cin >> H >> W >> N;
	int m = max(H, W);
	int ans = (int)(N/m);
	if (N%m != 0)
		ans++;
	cout << ans << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

#define fi first
#define se second
typedef pair<int,int> PII;

int n, E, T, a[1<<17];
long long dp[1<<17], dp2[1<<17], mdp2 = (1<<30);

int main() {
    cin >> n >> E >> T;
    for (int i = 1; i <= n; i++) cin >> a[i];
    dp2[0] = -2*a[1];
    for (int i = 1, it = 1; i <= n; i++) {
        while (2 * (a[i] - a[it]) > T) it++, mdp2 = min(mdp2, dp2[it-2]);
        dp[i] = min(dp[it-1] + T, mdp2 + 2*a[i]);
        dp2[i] = dp[i] - 2 * a[i+1];
    }
    cout << dp[n] + E;
}


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

int n;
vector<int> d, conf, unconf;

int solve();

int main() {
  cin >> n;
  d.resize(n);
  for (auto& p : d) cin >> p;
  sort(d.begin(), d.end());
  cout << solve() << endl;
  return 0;
}

int solve() {
  int res = 0;
  if (!d[0]) return 0;
  conf.push_back(0);
  for (int i = 0; i < n;) {
    int cnt = 0, now = d[i];
    while (i < n && now == d[i]) ++i, ++cnt;
    if (cnt > 2) return 0;
    if (cnt == 2) {
      conf.push_back(now);
      conf.push_back(24 - now);
    } else
      unconf.push_back(now);
  }
  int len = unconf.size();
  for (int i = 0; i < (1 << len); ++i) {
    vector<int> v = conf;
    for (int j = 0; j < len; ++j)
      if (i >> j & 1)
        v.push_back(unconf[j]);
      else
        v.push_back(24 - unconf[j]);
    sort(v.begin(), v.end());
    int now = 24;
    for (int j = 0; j <= n + 1; ++j)
      now = min({now, abs(v[j] - v[(j + 1) % (n + 1)]),
                 24 - abs(v[j] - v[(j + 1) % (n + 1)])});
    res = max(res, now);
  }
  return res;
}

Measured memory_bytes: 3592
n=int(input())
s=[input() for i in range(n)]
count=0
A=0
B=0
BA=0
for i in range(n):
    for j in range(len(s[i])-1):
        if j==0:
            if s[i][j]=='B':
                B+=1
        if j==len(s[i])-2:
            if s[i][j+1]=='A':
                A+=1
        if s[i][j:j+2]=='AB':
            count+=1
    if s[i][0]=='B' and s[i][-1]=='A':
        BA+=1
        A-=1
        B-=1

if BA==0:
    print(count+min(A,B))
else:
    ans=count+BA-1
    if A>=1 and B>=1:
        print(ans+2+min(A,B)-1)
    elif A>=1 or B>=1:
        print(ans+1)
    else:
        print(ans)

Measured memory_bytes: 47576
#include<bits/stdc++.h>
#define rep(i, n) for ( int i=0;  i<n; i++)
#define REP(i, n) for ( int i=1; i<=n; i++)
#define fi first
#define sc second 
#define pb push_back
#define pf push_front 
#define mod 1000000007
using namespace std;
using f=float; using ll=long long; using ld=long double;
using ull=unsigned long long; using vi=vector<int>; using pii=pair<int, int>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m;
    cin >> n >> m;

    int A[10000]; 
    int sum=0; 
    rep(i, m) {
        cin >> A[i]; 
        sum += A[i];
    }
    if ( n >= sum ) cout << n - sum << endl;
    else cout << -1 << endl; 
    return 0;
} 


Measured memory_bytes: 3692
#include <iostream>
#include<string>
using namespace std;
int main(){
int sx,sy,tx,ty;
cin>>sx>>sy>>tx>>ty;
for(int i=0;i<ty-sy;i++)cout<<'U';
for(int i=0;i<tx-sx;i++)cout<<'R';
for(int i=0;i<ty-sy;i++)cout<<'D';
for(int i=0;i<=tx-sx;i++)cout<<'L';
for(int i=0;i<=ty-sy;i++)cout<<'U';
for(int i=0;i<=tx-sx;i++)cout<<'R';
cout<<"DR";
for(int i=0;i<=ty-sy;i++)cout<<'D';
for(int i=0;i<=tx-sx;i++)cout<<'L';
cout<<"U"<<endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  if ((A + B) == (C + D)) {
      cout << "Balanced" << endl;
  }
  if ((A + B) < (C + D)){
      cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char w[16], t[1024];
  scanf("%s", w);
  int wlen;
  for(wlen = 0; w[wlen] != '\0'; wlen++){}
  int sum = 0;
  while(scanf("%s", t) != EOF){
    int tlen;
    for(tlen = 0; t[tlen] != '\0'; tlen++){}
    if(wlen == tlen){
      int i;
      for(i = 0; i < wlen; i++){
        if(t[i] >= 65 && t[i] <= 90) t[i] = t[i] - 65 + 97;
        if(w[i] != t[i]) break;
      }
      if(i == wlen) sum++;
    }
  }
  printf("%d\n", sum);
}



Measured memory_bytes: 2688
N = int(input())
list1 = list(map(int, input().split()))
count = 0
 
for i in range(N-1):
  if list1[i] > list1[i+1]:
    count += 1

if count == 0:
  print("YES")
elif count == 1:
  count = 0
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      x = i
  a = list1[x] 
  b = list1[x + 1]
  list1[x] = b
  list1[x + 1] = a
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      count += 1
  if count == 0:
    print("YES")
  else:
    print("NO")
elif count >= 3:
  print("NO")
else:
  count = 0
  list2 = []
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      list2.append(i)
  a = list1[list2[0]] 
  b = list1[list2[1] + 1]
  list1[list2[0]] =b
  list1[list2[1] + 1] =a
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      count += 1
  if count == 0:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>

using namespace std;

int main() {

	string S;

	cin >> S;

	int letnum = (int)(S.length());

	string ans = "";

	for (int i = 0; i < letnum; i++) {
		ans.append("x");
	}

	cout << ans << endl;
}



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

bool match(char c){
  if (c=='A'||c=='C'||c=='G'||c=='T'){
    return true;
  }else{
    return false;
  }
}

int main() {
  string s; cin >>s;
  bool cnti = false;
  int ans=0; int cnt=0;
  for (int i=0; i<s.size(); i++){
    if (match(s.at(i))){
      if (cnti) cnt++;
      else{
        cnt++; cnti=true;
      }
    }else{
      cnti=false;
      if (cnt>ans) ans = cnt;
      cnt = 0;
    }
  }
  if (cnti && cnt>ans) ans = cnt;
      
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N;
    double money = 0.0;
    cin >> N;
    vector <double> A(N);
    vector <string> B(N);
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        if(B[i] == "JPY"){
            money += A[i];
        }
        else{
            money += A[i] * 380000.0;  
        }
    }
    cout << money << endl;
}


Measured memory_bytes: 3804
N,Y = map(int, input().split())
"""
・10000x+5000y+1000z=Y
・x+y+z=N
・z=N-(x+y)>=0 x+y<=N
"""

for x in range(N + 1):
    for y in range(N + 1 - x):
        R = Y - 10000 * x - 5000 * y
        z = N - (x + y)
        if 1000 * z == R:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 40556
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> PP;
static const int INF = 1000010000;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
  int to;
};

int main(){
  string s;
  cin >> s;
  s = s.substr(0, s.length() - 1);
  if(s.length() % 2){
    s = s.substr(0, s.length() - 1);
  }
  while(1){
    if(s.substr(0, s.length() / 2) == s.substr(s.length()/2, s.length()/2)){
      cout << s.length() << endl;
      return 0;
    }else{
      s = s.substr(0, s.length() - 2);
    }
  }
  return 0;
}



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

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

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

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

int main(){
  int k,x;cin>>k>>x;
  if(500*k>=x) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
 

}


Measured memory_bytes: 256
from collections import deque
import sys
n = int(input())
deq = deque()
sub_deq = {}
for cmd in sys.stdin.readlines():
    if cmd == 'deleteFirst\n':
        while deq:
            data = deq.pop()
            if data[1]:
                data[1] = 0
                break
    elif cmd == 'deleteLast\n':
        while deq:
            data = deq.popleft()
            if data[1]:
                data[1] = 0
                break
    else:
        cmd, val = cmd.split()
        if cmd == 'insert':
            data = [val, 1]
            deq.append(data)
            if val not in sub_deq:
                sub_deq[val] = [data]
            else:
                sub_deq[val].append(data)
        elif cmd == 'delete':
            if val in sub_deq:
                deq_v = sub_deq[val]
                while deq_v:
                    data = deq_v.pop()
                    if data[1]:
                        data[1] = 0
                        break
sys.stdout.write(" ".join(data[0] for data in reversed(deq) if data[1]))
sys.stdout.write('\n')

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

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

	char ch = s[0];
	int ans = 0;
	for(int i = 1; i < s.length(); i++){
		if(s[i] != ch){
			ans++;
			ch = s[i];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]

A = N%1000
if A ==0:
    print(0)
    sys.exit()
ans = 1000-A

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
print(ans)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
ll MOD = 1e9+7;
#define int ll

ll binpow(ll a, ll b){
	ll res = 1;
	while(b){
		if(b%2)
			res = (res*a)%MOD;
		a = (a*a)%MOD;
		b>>=1;
	}
	return res;
}



vector<ll> fact(3e6+5, 1);
vector<ll> ifact(3e6+5, 1);

ll choose(ll a, ll b){
	if(b == 0 || a == b)
		return 1;
	if(b < 0 || b > a)
		return 0;
	return ((fact[a]*ifact[b])%MOD)*ifact[a-b]%MOD;
}
signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	ll r1,r2,c2,c1; 
	cin>>r1>>c1>>r2>>c2;
	for(int i = 2; i < 3e6+1; i++){
		fact[i] = (fact[i-1]*i)%MOD;
		ifact[i] = binpow(fact[i], MOD-2);
	}
	ll tot = 0;
	for(int i = r1+1; i <= r2+1; i++){
		ll dist = c2 + i;
		tot = (tot + choose(dist, i)) % MOD;
	}	
	for(int i = r1+1; i <= r2+1; i++){
		ll dist = c1 -1+ i;
		tot = (((tot - choose(dist, i)) % MOD) + MOD)%  MOD ;
		
	}	
	cout<<tot;
}


Measured memory_bytes: 47104
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL dp[2][13];
int main(){
    string s;R(s);
    int now=0,nxt=1;
    dp[now][0]=1;
    REP(i,SZ(s)){
        MS0(dp[nxt]);
        if(s[i]=='?'){
            REP(j,13){
                REP(k,10){
                    ADD(dp[nxt][(j*10+k)%13],dp[now][j]);
                }
            }
        }
        else{
            REP(j,13){
                ADD(dp[nxt][(j*10+s[i]-'0')%13],dp[now][j]);
            }
        }
        swap(nxt,now);
    }
    W(dp[now][5]);
    return 0;
}


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

using namespace std;

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

    int n, k;

    cin >> n >> k;
    int cnt = k;
    for (int i = 1; i < n; ++i)
        cnt *= (k - 1);

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
s = input()
ans = 0
n = len(s)-1
for x in range(2 ** n):
    l = 0
    for i in range(n):
        if x & (1<<i):
            ans += int(s[l:i+1])
            l = i+1
    ans += int(s[l:n+1])
print(ans)

    


Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

int N;
pii A[1000];

int main(void) {
  while(cin >> N, N) {
    REP(i, 0, N) cin >> A[i].fi >> A[i].se;
    sort(A, A + N);

    int s1 = 0, s2 = 0;
    REP(i, 0, N - 1) s1 += A[i].fi;
    REP(i, 0, N) s2 += A[i].se;

    if(s1 >= A[N - 1].fi) {
      cout << A[N - 1].fi + s1 + s2 << endl;
    } else {
      int d = A[N - 1].fi - s1;
      bool dp[N][d + 1];
      REP(i, 0, N) REP(j, 0, d + 1) dp[i][j] = false;
      dp[0][0] = true;
      int m = 0;
      REP(i, 0, N - 1) REP(j, 0, d + 1) if(dp[i][j]) {
        dp[i + 1][j] = true;
        if(j + A[i].se <= d) {
          dp[i + 1][j + A[i].se] = true;
          m = max(m, j + A[i].se);
        }
      }
      cout << A[N - 1].fi * 2 + (s2 - m) << endl;
    }
  }

  return 0;
}

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

using namespace std;

void solve(void)
{
	long a, b, x;
	cin >> a >> b >> x;
	cout << (b / x - max(0L, a - 1) / x + (a == 0L)) << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    
    int k = stdIn.nextInt();
    int x = stdIn.nextInt();
    
    if (500 * k >= x) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define mp make_pair
#define pii pair<int, int>
#define PB push_back
#define F first
#define S second
#define Task ""
using namespace std;
const int N=200005;
const int mod=1000000007;
int n, a[N], dp[N], sum[N], cnt;

void setup() {
    cin >> n;
    rep(i, 1, n) {
        int x; cin >> x;
        if(x!=a[cnt]) {
            a[++cnt]=x;
        }
    }
}

int add(int &a, int b) {
    a=(a+b)%mod;
    return a;
}

void calc() {
    dp[0]=1;
    rep(i, 1, cnt) {
        add(dp[i], dp[i-1]);
        add(dp[i], sum[a[i]]);
        add(sum[a[i]], dp[i-1]);
    }
    cout << dp[cnt];
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    setup();
    calc();
    return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void chmin(int &a, int b){
  if(a > b)
    a = b;
}
void chmax(int &a, int b){
  if(a < b)
    a = b;
}

void llchmin(ll &a, ll b){
  if(a > b)
    a = b;
}
void llchmax(ll &a, ll b){
  if(a < b)
    a = b;
}

int main(){
  int n, k;
  cin >> n >> k;
  vi p(n);
  rep(i, 0, n)
    cin >> p[i];
  
  sort(p.begin(), p.end());
  
  int ans = 0;
  
  rep(i, 0, k)
    ans += p[i];
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3684
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        //総和は変わらない
        //最大値をmaxとすると、n / max<sumであればよくて
        //総和の約数の中で実現可能かを調べる
        var sum = a.Sum();
        var possibleMax = sum / n;
        var candidates = Factors(sum).OrderBy(x => x).Reverse().ToArray();
        foreach (var cand in candidates)
        {
            var mods = a.Select(x => x % cand).ToArray();
            var upCount = mods.Sum() / cand;
            var step = mods.OrderByDescending(x => x).Skip((int)upCount).Sum();
            if (step <= k)
            {
                Console.WriteLine(cand);
                return;
            }
        }
    }


    static IEnumerable<long> Factors(long n)
    {
        int i = 1;
        while (i * i <= n)
        {
            if (n % i == 0)
            {
                yield return i;
                yield return n / i;
            }
            i++;
        }
    }
}


Measured memory_bytes: 15688
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
s=0
for i in range(m):
    p=list(map(int,input().split()))
    b.append(p)
    s+=p[0]
b.sort(key=lambda x:-x[1])
a.sort()
if s>n:
    s=n
c=[]
i=0
sun=0
while sun<s:
    for j in range(b[i][0]):
        c.append(b[i][1])
    sun+=b[i][0]
    i+=1
for u in range(s):
    if a[u]<c[u]:
        a[u]=c[u]
    
print(sum(a))

Measured memory_bytes: 36076
A,B,K = list(map(int,input().split()))
for i in range(K):
    if i % 2 == 0:
        if A % 2 != 0:
            A -= 1
        A //=2
        B += A
    else:
        if B % 2 != 0:
            B -= 1
        B //=2
        A += B
print(str(A)+' '+str(B))

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[100][100] = { -1 }, f[10000], g[10000], h[10000], m[100] = { 0 }, counto = 0, x[100] = { 0 }, y = 0, z = 0;
long long ab[100000], abc = 0,abcd=0;
pair<int, int>manji[100], daburu[100];
char rikka, toka[50][50];
string saya, homu, kyok, mami[100], mado[100];
bool gg = false;
vector<char>uc;
vector<int>gachi;
int main() {
	cin >> abc;
	abcd = 1;
	if (abc == 0) {
		cout << '0' << endl;
		return 0;
	}

	while(abc!=0){
		if (abc%(abcd*2) == 0) {
			saya += '0';
			//cout << '0' << endl;
		}
		else {
			saya += '1';
			abc -= abcd;
			//cout << '1' << endl;
		}
		abcd = abcd * (-2);
	}
	for (int i = 0; i < saya.length(); i++) {
		
			cout << saya[saya.length() - i-1];
		
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Girls' Party
public class Main{

	int N, res;
	Set<String>[] v;
	
	void dfs(int nb, int ng, int z, String s){
		if(nb<=res)return;
		if(ng==0){
			res = nb; return;
		}
		if(v[z].contains(s))return;
		v[z].add(s);
		int n = s.length(), d = (N-1)%n;
		if(s.charAt(d)=='B'){
			dfs(nb-1, ng, z, s.substring(d+1)+s.substring(0, d));
		}
		else{
			dfs(nb, ng-1, z, s.substring(d+1)+s.substring(0, d));
		}
		if(z==1)return;
		d = N%n;
		if(s.charAt(d)=='B'){
			dfs(nb-1, ng, 1, s.substring(d+1)+s.substring(0, d));
		}
		else{
			dfs(nb, ng-1, 1, s.substring(d+1)+s.substring(0, d));
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			N = sc.nextInt();
			String s = sc.next();
			v = new Set[2];
			v[0] = new HashSet<String>(); v[1] = new HashSet<String>();
			res = 0;
			int nb = 0, ng = 0;
			for(char c:s.toCharArray())
				if(c=='B')nb++; 
				else ng++;
			dfs(nb, ng, 0, s);
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17000
using System;

class Program {
  public static void Main() {
    long n = long.Parse(Console.ReadLine());
    long sum = 0;
    double count = 0;
    
    do {
      n = n / 2;
      sum += (long)Math.Pow(2.0, count);
      
      count++;
    } while (n >= 1);
    
    Console.WriteLine(sum);
  }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

bool pred(string a, string b) {
  int i;
  for (i=0; a[i] == '0'; i++);
  a = a.substr(i);
  for (i=0; b[i] == '0'; i++);
  b = b.substr(i);
  if (a.length()!=b.length()) return a.length() < b.length();
  return a < b;
}

int main() {  
  int w, h;
  while(cin >> w >> h, w+h) {
    char ba[w][h];
    REP(y,h)
      REP(x,w)
        cin >> ba[x][y];
    
    string dp[w][h];
    string ans;
    REP(y, h) {
      REP(x, w) {
        if (isalpha(ba[x][y])) continue;
        if (x>0) dp[x][y] = dp[x-1][y];
        if (y>0&&pred(dp[x][y], dp[x][y-1])) dp[x][y] = dp[x][y-1];
        dp[x][y] += ba[x][y];

        if (pred(ans, dp[x][y])) ans = dp[x][y];
      }
    }
    int i;
    for(i=0;ans[i]=='0';i++);
    cout << ans.substr(i) << endl;
  }
}

Measured memory_bytes: 1016
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

void swap(int *a, int *b) {
    int tmp = *a;
    a = b; *b = tmp;
}

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i = 0; i<n1; i++) L[i] = A[left + i];
    for( i = 0; i<n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k<right; k++) {
        if(L[i].value <= R[j].value) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left , int right) {
    int mid;
    if(left+1 < right) {
        mid = (left+right) / 2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}

int partition(struct Card A[], int n, int p, int r) {
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p-1;
    for( j=p; j < r; j++) {
        if(A[j].value <= x.value) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
	
    return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
    int q;
    if(p < r) {
        q = partition(A,n,p,r);
        quickSort(A,n,p,q-1);
        quickSort(A,n,q+1,r);
    }
}

int main() {
    int n, i, v;
    struct Card A[MAX],B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d", &n);
    
    for(i = 0; i<n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }
    
    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);
    
    for(i=0; i<n; i++) {
        if(A[i].suit != B[i].suit) stable = 0;
    }
    
    if(stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0; i<n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    	//printf("%c %d\n", A[i].suit, A[i].value);
    }
    
    return 0;
}


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

int main(){
  int A,B;
  cin>>A>>B;
  if (B%A==0){
    cout<<(A+B)<<endl;
    return 0;
  }else{
    cout<<(B-A)<<endl;
    return 0;
  }
  
  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 ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
 
int main() {
  string N;
  cin >> N;

  int n = atoi(N.c_str());
  int x = 0;

  rep(i, N.length()) {
    x += ctoi(N[i]);
  }

  if (x == 0) return 0;

  if (n % x == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a={}
a[0]=100000
aa=[0]
for i in map(int,input().split()):
  if i not in a:
    a[i]=1
    aa+=[i]
  else:
    a[i]+=1
aa.sort(reverse=1)
bc=[[100000,0]]
for i in range(m):
  b,c=map(int,input().split())
  bc+=[[b,c]]
bc.sort(key=lambda x:x[1],reverse=1)
ans=0
i,j=0,0
k=n
while k>0:
  if bc[j][1]>aa[i]:
    if k>bc[j][0]:
      ans+=bc[j][1]*bc[j][0]
      k-=bc[j][0]
      j+=1
    else:
      ans+=bc[j][1]*k
      k=0
  else:
    if k>a[aa[i]]:
      ans+=aa[i]*a[aa[i]]
      k-=a[aa[i]]
      i+=1
    else:
      ans+=aa[i]*k
      k=0
print(ans)

Measured memory_bytes: 31340
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            double x = double.Parse(s[0]);
            double y = double.Parse(s[1]);

            int d = a / b;
            int r = a % b;
            double f = x / y;
            string f2 = string.Format("{0:f8}", f);

            Console.WriteLine(d + " " + r + " " + f2);

        }
    }
}

Measured memory_bytes: 19968
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }
int hash(int key, int i){ return (h1(key)+i*h2(key))%M;}

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0;; i++){
    h = hash(key, i);
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    h = hash(key, i);
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}


int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str) ){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}






Measured memory_bytes: 17020