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

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const ll INF = 1e18;
const ll mod = 1e9+7;

//初期化
vector<int> value; // ノードの値を持つ配列
int N; // 葉の数

void update(int i, int x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = value[i * 2 + 1]|value[i * 2 + 2]; // 左右の子の min を計算しなおす
    }
}

int query(int a, int b, int k, int l, int r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return 0; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b) に完全に含まれる
    else {
        // 一部だけ範囲が被る場合は左右の子に委託する
        int c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        int c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return c1|c2; // 左右の子の値の min を取る
    }
}


int main(void) {
    int n,q; // 数列のサイズとクエリの数
    string s;
    cin>>n>>s;
    cin >>q;
    N = 1;
    while (N < n) N *= 2; // 葉の数を計算（n以上の最小の2冪数）


    value = vector<int>(2 * N - 1);
    rep(i,n){
      int now=s[i]-'a';
  //    cout<<s[i]<<' '<<now<<endl;
      update(i,1<<now);
    }

    for (int j = 0; j < q; j++) {
        int c;
        cin >> c;
        if (c == 2) {
            // update(i, x)
            int i, x;
            cin >> i >> x;
            i--;x--;
            int ans= query(i, x + 1, 0, 0, N);

            cout<<__builtin_popcount(ans)<<endl;;
        } else {
            // find(s, t)
            int i,x;
            char c;
            cin >> i >> c;
            i--;
            int now=c-'a';
            x=1<<now;
            update(i, x);

        }
    }

}


Measured memory_bytes: 4996
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> Mat;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
ll pow_10[20];
ll M;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % M;
	}
	return (a * mod_pow(a, n - 1)) % M;
}
Mat operator*(const Mat& a, const Mat& b) {
	Mat ret(a.size(), vector<ll>(b[0].size()));
	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < b[0].size(); j++) {
			for (int k = 0; k < a[0].size(); k++) {
				(ret[i][j] += a[i][k] * b[k][j] % M) %= M;
			}
		}
	}
	return ret;
}
Mat mat_pow(const Mat& a, ll n) {
	Mat ret;
	if (n == 0) {
		ret = Mat(a.size(), vector<ll>(a[0].size()));
		for (int i = 0; i < a.size(); i++) ret[i][i] = 1;
		return ret;
	}
	if (n % 2 == 0) {
		Mat t = mat_pow(a, n / 2);
		ret = t * t;
	}
	else {
		Mat t = mat_pow(a, n / 2);
		ret = t * t;
		ret = ret * a;
	}
	return ret;
}
int main() {
	ll L, A, B;
	cin >> L >> A >> B >> M;
	pow_10[0] = 1;
	for (int i = 1; i <= 18; i++) {
		pow_10[i] = pow_10[i - 1] * 10;
	}
	ll X = 0, s = A % M;
	for (int i = 0; i < 18; i++) {
		ll l, r;
		if (pow_10[i] <= A) l = 0;
		else l = (pow_10[i] - A + B - 1) / B;
		if (pow_10[i + 1] <= A) r = 0;
		else r = (pow_10[i + 1] - A + B - 1) / B;
		if (l == r) continue;
		if (l >= L) break;
		r = min(r, L);
		Mat P(3, vector<ll>(3));
		P[0][0] = pow_10[i + 1] % M;
		P[0][1] = 1;
		P[1][1] = 1;
		P[1][2] = B % M;
		P[2][2] = 1;
		Mat Q = mat_pow(P, r - l);
		Mat v(3, vector<ll>(1));
		v[0][0] = X;
		v[1][0] = s;
		v[2][0] = 1;
		Mat R = Q * v;
		X = R[0][0];
		s = R[1][0];
	}
	cout << X << endl;
}

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

string s;
int x,y,t;
int x1,x2,y3,y2;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
bool dp1[17002];
bool dp2[17002];
bool dp3[17002];
bool dp4[17002];

main(){
  cin>>s;
  cin>>x>>y;
  x+=8100;y+=8100;
  vector<int>v[2];
  int d=1,p=0,u=0;
  s+='@';
  while((int)s.size()&&s[0]=='F')p++,s.erase(s.begin()+0);
  int ii=0;
  while(ii<=s.size()){
    if(s[ii]=='@')break;
    int c=0;
    while(s[ii]=='T')t++,ii++;
    while(s[ii]=='F')c++,ii++;
    v[t%2].push_back(c);
  }
  dp1[p+8100]=1;
  r(i,v[0].size()){
    memset(dp2,0,sizeof(dp2));
    r(j,17000){
      if(dp1[j]){
        int a=j;
        if(a-v[0][i]>=0)dp2[a-v[0][i]]=1;
        dp2[a+v[0][i]]=1;
      }
    }
   // cout<<dp2[8104]<<endl;
    memset(dp1,0,sizeof(dp1));
    r(j,17000)if(dp2[j])dp1[j]=1;
    //cout<<dp1[8104]<<endl;
  }
  //cout<<dp1[8104]<<endl;

  dp3[8100]=1;
  r(i,v[1].size()){
    memset(dp4,0,sizeof(dp4));
    r(j,17000){
      if(dp3[j]){
        int a=j;
        if(a-v[1][i]>=0)dp4[a-v[1][i]]=1;
        dp4[a+v[1][i]]=1;
      }
    }
    memset(dp3,0,sizeof(dp3));
    r(j,17000)if(dp4[j])dp3[j]=1;
  }

  if(dp1[x]&&dp3[y])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 384
/* Atcoder abc167a
 * See tasks at: https://atcoder.jp/contests/abc167/tasks/abc167_a
 */
#include <bits/stdc++.h>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = long long;
int main()
{
    string s, t;
    cin >> s >> t;

    if (t.substr(0, t.length() - 1) == s)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
    
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,k;
vector<int>v;
double EPS=1e-9;
double pre[200010],a[200010],sieve[1000001];

int main()
{
long long  n,k;
cin>>n>>k;
cout<<min(n%k,abs(n%k-k));
return 0;
}


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

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int     MOD = (int) 1E9 + 7;
    
    public static void main(String[] args) {
        int N = nint();
        int even = N/2;
        double ans = (double) (N - even) / N;
        System.out.println(ans);
    }
    
    private static int nint() {
        return sc.nextInt();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static double ndouble() {
        return sc.nextDouble();
    }

    private static double[] ndoubles(int n) {
        return ndoubles(n, 0, 0);
    }

    private static double[] ndoubles(int n, int padL, int padR) {
        double[] d = new double[n + padL + padR];
        for (int i = 0; i < n; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0, 0);
    }

    private static char[][] nchars2(int h, int w, int padLU, int padRD) {
        char[][] a2 = new char[h + padLU + padRD][w + padLU + padRD];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, w);
        return a2;
    }

    private static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }

    private static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }

    private static long abs(long a, long b) {
        return Math.abs(a - b);
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main () {
  int n,cnt = 0,cnt2 = 0;
  string s;
  cin >> s;
  n = s.size();
  vector<int> m(n);
  for (int i = 0; i < n; i++){
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
      for (int j = 0; i < n; i++){
        if (s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T'){
          break;
        }
        cnt++;
      }
    }
    if (cnt > cnt2){
      cnt2 = cnt;
    }
    cnt = 0;
  }
  cout << cnt2 << '\n';
  return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define lli long long int
#define timesave ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;


void solve()
{
    int n;
    cin >> n;

    vector< pair<int,int> > v[n+5];

    for(int i = 0; i < n; i++){
        int a, x, y;
        cin >> a;

        while(a--){
            cin >> x >> y;
            v[i].push_back({x, y});
        }
    }

    int mx = 0;

    for(int i = 0; i < (1<<n); i++){
        int flag = 0;

        for(int j = 0; j < n; j++){
            if((i & (1<<j))){
                int l = v[j].size();

                for(int k = 0; k < l; k++){
                    int x = v[j][k].first, y = v[j][k].second;
                    int d;
                    if((i & (1<<(x-1)))) d = 1;
                    else d = 0;
                    if(d != y) {flag = 1; break;}
                }
                if(flag) break;
            } 
        }

        if(!flag){
            //cout << i << "\n";
            int cnt = __builtin_popcount(i);
            mx = max(mx, cnt);
        }
    }

    cout << mx << "\n";
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //timesave; 
    
    int tc = 1;
    //cin >> tc;
    while(tc--) solve();
 
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned int a,b,c,d,z,x;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    z=a*b;
    x=c*d;
    if(z>x)
        printf("%d",z);
   else if(z<x)
        printf("%d",x);
    else
        printf("%d",x);

}


Measured memory_bytes: 256
n, m = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(m)]
l = []
r = []
for i in range(m):
  l.append(lr[i][0])
  r.append(lr[i][1])
lm = max(l)
rm = min(r)
ans = 0
for i in range(1, n+1):
  if lm <= i <= rm:
    ans += 1
print(ans)

Measured memory_bytes: 28672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// 情報の数を取得
		Scanner sc = new Scanner(System.in);
		int information = sc.nextInt();

		// informationの中身
		// building = 棟
		int building = 0;
		// floor = 階
		int floor = 0;
		// room = 番
		int room = 0;
		// visitor = 人数
		int visitor = 0;

		// 部屋をつくる
		int[][][] resident = new int[][][] {
			{
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
			},
			{
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
			},
			{
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
			},
			{
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
				{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
			}
			};

		// 入力した情報から各部屋にv人を入れる
		for (int cnt = 1; cnt <= information; cnt++) {
			building = (sc.nextInt()-1);
			floor = (sc.nextInt()-1);
			room = (sc.nextInt()-1);
			visitor = sc.nextInt();
			resident[building][floor][room] = resident[building][floor][room] + visitor;
		}

		//入居者数を出力
		for (building = 0; building < 4; ++building) {
			for (floor = 0; floor < 3; ++floor) {
				for (room = 0; room < 10; ++room) {
					//1棟目
					if(building == 0){
					System.out.print(" " + resident[building][floor][room]);
					}

					//2棟目
					if(building == 1){
					System.out.print(" " + resident[building][floor][room]);
					}

					//3棟目
					if(building == 2){
					System.out.print(" " + resident[building][floor][room]);
					}

					//4棟目
					if(building == 3){
					System.out.print(" " + resident[building][floor][room]);
					}
				}System.out.println("");
			}
			if(building != 3){
			System.out.println("####################");
			}
		}
	}
}



Measured memory_bytes: 29592
#include <iostream>
#define MAX 100002
using namespace std;

int range[MAX][3];
int number[MAX];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> range[i][0] >> range[i][1];
    range[i][2] = 1;
  }
  
  for (int i = 2; i <= MAX; i++)
    number[i] = 1;

  for (int i = 0; i < n; i++) {
    for (int j = range[i][0]; j <= range[i][1]; j++) {
      number[j]++;
    }
  }

  int ans = 0;
  for (int i = 2; i <= n + 1; i++) {
    if (number[i] >= i) ans = i - 1;
  }
  cout << ans << endl;
    
  return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    string s; cin >> s;
    if(s <= "2019/04/30") cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7704
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a))
#define foreasy(i,a,b) for(i=a;i<b;i++)
#define IN 1
#define OUT 0
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=200000+5;

int s[maxn];
int a[maxn];
using namespace std;

bool cmp(int a, int b)
{
    return a>b;
}

int solve(int n)
{
    if(n<=0) return 1;
    else  return n*solve(n-1);
}
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    int n, k, maxnum = -1, temp, add = 0, difnum = 0;
    memset(a,0,sizeof(a));
    scanf("%d%d", &n, &k);
    for(int i = 1; i<=n; i++)
    {
        scanf("%d", &s[i]);
        if(maxnum<s[i]) maxnum = s[i];
        a[s[i]]++;
    }

    for(int i= 1; i <= maxnum; i++)
    {
        if(a[i]>0) difnum++;
    }
    if(difnum == k) printf("%d", add);
    else
    {
        sort(a+1,a+maxnum+1);
            if(difnum > k)
            {
                for(int i = 1; i<=maxnum; i++)
                {
                    if(a[i])
                    {
                        add+=a[i];
                    difnum--;
                    if(difnum==k) printf("%d", add);
                    }
                }
            }
            else
            {
                printf("%d", add);
            }
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
    int a, b, k;
    cin >> a >> b >> k;
    
    for(int i = min(a, b); i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            k--;
            if(k == 0){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N_MAX 1001

char a[N_MAX], b[N_MAX];
int c[N_MAX][N_MAX];

int main() {
    int q, i, j;
    scanf("%d", &q);
    while(q--) {
        scanf("%s%s", a, b);
        for(i=0; a[i]!='\0'; i++)
            for(j=0; b[j]!='\0'; j++)
                if(a[i] == b[j]) c[i+1][j+1] = c[i][j] + 1;
                else if(c[i+1][j] > c[i][j+1]) c[i+1][j+1] = c[i+1][j];
                else c[i+1][j+1] = c[i][j+1];
        printf("%d\n", c[i][j]);
    }
}



Measured memory_bytes: 5776
H,N=map(int,input().split())
A=[]
B=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

dp=[[10**9 for i in range(H+1)] for j in range(N+1)]
dp[0][0]=0
for i in range(N):
    for j in range(H+1):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        dp[i+1][min(j+A[i],H)]=min(dp[i+1][min(H,j+A[i])],dp[i+1][j]+B[i])
print(dp[-1][-1])

Measured memory_bytes: 126064
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
  string sa,sb,sc;
  cin >> sa >> sb >>sc;
  char ch=sa[0];
  int ia=1,ib=0,ic=0;
  while(1){
      if(ch=='a'){
          if(ia>=sa.length()){
              cout << "A"<<endl;
              return 0;
          }
          ch = sa[ia];
          ia++;
      }
      else if(ch=='b'){
          if(ib>=sb.length()){
              cout << "B"<<endl;
              return 0;
          }
          ch = sb[ib];
          ib++;
      }
      else if(ch=='c'){
          if(ic>=sc.length()){
              cout << "C"<<endl;
              return 0;
          }
          ch = sc[ic];
          ic++;
      }
  }
}


Measured memory_bytes: 256
s = list(str(input()))

kekka = []

for i in range(len(s)):
    
    if s[0]=="B":
        pass
            
    if s[i]=="B" :
        if not kekka==[]:
            kekka.pop()
    else:
        kekka.append(s[i])

print(''.join(kekka))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

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

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return 
#define endl         "\n" 

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2) 

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***




void solve()
{
    int n;rd(n);
    int a[n]; read(a,n);
    int i=0;
    ll money = 1000;
    ll q = 0;
    while(i+1<n){
        while(i+1<n and a[i+1]<=a[i])i++;
        if(i!=n-1){
            q = money/a[i];
            money -= q*a[i];
            int j = i + 1;
            while(j+1<n and a[j+1]>a[j])j++;
            money += a[j]*q;
            q = 0;
            i = j + 1;
        }
    }
    cout<<money<<endl;
    
}


void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    return 0;
}

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

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

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(N), B(M);
    for (auto &i : A) cin >> i;
    for (auto &i : B) cin >> i;

    vector<ll> sumA(N+1), sumB(M+1);
    rep(i, N) sumA[i+1] = sumA[i] + A[i];
    rep(i, M) sumB[i+1] = sumB[i] + B[i];

    int ans = 0;
    int j = M;
    rep(i, N+1) {
        while (0 < j && K < sumA[i] + sumB[j]) {
            j--;
        }
        if (sumA[i] + sumB[j] <= K) chmax(ans, i + j);
    }

    cout << ans << endl;
}

Measured memory_bytes: 8008
#include <iostream>

int main()
{
    int s, hour, minute, second;
    std::cin >> s;
    hour = s / 3600;
    minute = s % 3600 / 60;
    second = s % 3600 % 60;
    std::cout << hour << ":" << minute << ":" << second << std::endl;
}


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

using namespace std;

int main() {
  int n, c, k; cin >> n >> c >> k;
  vector<int> T(n);
  for(int &t:T) cin >> t;
  sort(T.begin(), T.end());

  int res = 0;
  int i = 0;
  int t = 0;
  vector<int> cur;
  while (i < T.size()) {
    if (T[i] == t) {
      cur.push_back(T[i]);
      i++;
    }
    if (cur.size() >= c || (cur.size()>0 && cur[0]+k == t) || i == n) {
      cur.clear();
      res++;
    }
    if (T[i] > t) {
      t++;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 640
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

h,w = map(int,input().split())
li = []
for i in range(h):
    c = input()
    li.append(c)
for i in range(h):
    print(li[i])
    print(li[i])


Measured memory_bytes: 13208
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 2e6 + 10;
const int inf = 0x7ffffff;

void solve()
{
    int A, B;
    cin >> A >> B;
    for (int i = 1; i <= maxn;i++)
    {
        if(floor(0.08*i)==A  && floor(0.1*i)==B)
        {
            cout << i << "\n";
            return;
        }
    }
    cout << "-1\n";
}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 256
def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0] * (2 * N)
    for i in range(2 * N):
        if i < N:
            B[i] += A[i]
        else:
            B[i] = A[i-N] + K

    ans = float('inf')

    for i in range(N):
        ans = min(ans, B[i + N - 1] - B[i])

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 82528
n=int(input())
k=int(input())
l=len(str(n))
a=(l-1)*(l-2)*(l-3)//6*9**3
if k==2:
  a=(l-1)*(l-2)//2*9*9
elif k==1:
  a=(l-1)*9
sn=list(str(n))
c=0
for i in range(l):
  p=sn[i]
  if p != "0":
    if k-c == 3:
      a+=(l-i-1)*(l-i-2)//2*(int(p)-1)*9*9
    elif k-c == 2:
      a+=(l-i-1)*(int(p)-1)*9
      if not k==2:
        a+=(l-i-1)*(l-i-2)//2*9*9
    elif k-c == 1:
      a+=int(p)
      if not k==1:
        a+=(l-i-1)*9
    c+=1
    if c==k:
      break
print(a)


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

int main()
{
  int n;
  cin >> n;
  int a[n];
  int s = 0;
  REP(i, n)
  {
    cin >> a[i];
    s ^= a[i];
  }
  REP(i, n)
  {
    cout << (s ^ a[i]) << " "; 
  }
    
  return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1e5;
int n;
vi A(MAX + 1), L(MAX + 1, 0);
int lis() {
	L[0] = A[0];
	int length = 1;
	rep(i, 1, n) {
		if(L[length - 1] < A[i]) L[length++] = A[i];
		else *lower_bound(L.begin(), L.begin() + length, A[i]) = A[i];
	}
	return length;
}
int main() {
	cin >> n;
	rep(i, 0, n) cin >> A[i];
	P(lis());
	return 0;
}

Measured memory_bytes: 3512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    int a,b;
    a = 10 * (s[0] - '0') + (s[1] - '0');
    b = 10 * (s[2] - '0') + (s[3] - '0');
    bool flag1 = false ,flag2 = false;
    if(1 <= a && a <= 12) flag1 = true;
    if(1 <= b && b <= 12) flag2 = true;
    if(flag1 & flag2) cout << "AMBIGUOUS" << endl;
    else if(flag1) cout << "MMYY" << endl;
    else if(flag2) cout << "YYMM" << endl;
    else cout << "NA" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, K;
    cin >> N >> K;
    int p[N];
    rep(i, N) cin >> p[i];
    sort(p, p+N);
    int ans = 0;
    rep(i, K) ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
#define umap unordered_map
#define all(x) x.begin(), x.end()
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M ;
    }
    return res%M;
}
lli solve(){
    lli n;
    cin>>n;
    vll A(n);
    lli xr = 0;
    loop(i, 0, n){
        cin>>A[i];
        xr = xr ^ A[i];
    }
    loop(i, 0, n)
        cout<<(xr ^ A[i])<<" ";
    cout<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
	// cin>>t;
    t = 1;
    while(t>0){ 
        t--;
        solve();
    }
}

Measured memory_bytes: 4708
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int A[110000],B[110000],n;
const int mo=1e9+7;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	for (int i=1;i<=n;i++) scanf("%d",&B[i]);
	if (A[n]!=B[1]) {printf("0\n"); return 0;}
	int where=1;
	for (int i=1;i<=n;i++)
		if (A[i]>A[where]) where=i;
	if (A[where]!=B[where]){
		printf("0\n"); return 0;
	}
	int ans=1;
	for (int i=2;i<=where;i++)
		if (A[i]==A[i-1]) ans=1ll*ans*A[i]%mo;
	for (int i=where+1;i<n;i++)
		if (B[i]==B[i+1]) ans=1ll*ans*B[i]%mo;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>

using namespace std;

const double PI = 3.14159265358979;

/*
maxHeapify(A, i)
2      l = left(i)
3      r = right(i)
4      // select the node which has the maximum value
5      if l ≤ H and A[l] > A[i]
6          largest = l
7      else
8          largest = i
9      if r ≤ H and A[r] > A[largest]
10         largest = r
11
12     if largest ≠ i　// value of children is larger than that of i
13         swap A[i] and A[largest]
14         maxHeapify(A, largest) // call recursively
*/

int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }

void maxHeapify(int a[], int len, int i) {
	int l = left(i);
	int r = right(i);
	int largest = -1;
	if (l <= len && a[l] > a[i])
		largest = l;
	else
		largest = i;

	if (r <= len && a[r] > a[largest])
		largest = r;

	if (largest != i) {
		swap(a[i], a[largest]);
		maxHeapify(a, len, largest);
	}
}

/*
1 buildMaxHeap(A)
2    for i = H/2 downto 1
3        maxHeapify(A, i)
*/

void buildMaxHeap(int a[], int len) {
	for (int i = len / 2; i >= 1; i--) {
		maxHeapify(a, len, i);
	}
}

int main() {

	int n;  cin >> n;
	
	int* heap = new int[n + 1];

	for (int i = 1; i <= n; i++)	{
		scanf("%d", &heap[i]);
	}
	buildMaxHeap(heap, n);
	
	for (int i = 1; i <= n; i++) {
		printf(" %d", heap[i]);
	}
	printf("\n");

	delete[] heap;
	return 0;
}



Measured memory_bytes: 4664
#include <stdio.h>
#define N 100000
int LinerSearch(int A[], int n, int key){
        int i=0;
        A[n]=key;
        while(A[i]!=key) {
                i++;
        }
        return i != n;
}

int main(){
        int i,n,A[N+1],q,key,Sum=0;
        scanf("%d",&n);
        for(i=0; i<n; i++) {
                scanf("%d",&A[i]);
        }
        scanf("%d",&q);
        for(i=0; i<q; i++) {
                scanf("%d",&key);
                if(LinerSearch(A,n,key)) {
                        Sum++;
                }
        }
        printf("%d\n",Sum);
        return 0;
}



Measured memory_bytes: 2140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

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

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    void solve() throws IOException {
        int n = readInt();
        int[][] all = new int[n][3];
        int[][] res = new int[n][3];
        for(int i=0;i<n;i++) {
            all[i][0] = readInt();
            all[i][1] = readInt();
            all[i][2] = readInt();
        }
        res[0][0]=all[0][0];
        res[0][1]=all[0][1];
        res[0][2]=all[0][2];
        for(int i=1;i<n;i++){
            for(int k=0;k<3;k++) {
                int max = 0;
                for (int j = 0; j < 3; j++) {
                    if (k == j)
                        continue;
                    if (res[i - 1][j] > max)
                        max = res[i - 1][j];
                }
                res[i][k] = all[i][k]+max;
            }
        }
        System.out.println(Math.max(res[n-1][0], Math.max(res[n-1][1], res[n-1][2])));
    }
}


Measured memory_bytes: 52100
//#include <stdio.h>
#include <iostream>
using namespace std;

int bubbleSort(int A[], int N){
	int sw=0;
	for(int flag=0;flag<N-1;flag++){
		
		for(int i=N-1;i>flag;i--){	
			if(A[i-1] > A[i]){
				int temp = A[i-1];
	     		A[i-1] = A[i];
		  	    A[i]=temp;
		  	    sw++;
			}   
	    }
    }
    return sw;
}




int main(){
	int A[100],N,sw;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	sw = bubbleSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i==N-1){
			cout<<A[i]<<endl;
		}
		else{ 
			cout<<A[i]<<" ";
		}
	
	}

    cout<<sw<<endl; 
    return 0;
}










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

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;

int main() {
  int n; cin >> n;
  int a[n]; REP(i,n) cin >> a[i];
  ll sum1, sum2; ll ans1=0; ll ans2=0;
  REP(i,n) {
    sum1 += a[i];
    sum2 += a[i];
    if(i%2) {
      ans1 += max((ll)1-sum1, (ll)0); sum1 = max((ll)1, sum1);
      ans2 += max((ll)1+sum2, (ll)0); sum2 = min((ll)-1,sum2);
    } else {
      ans1 += max((ll)1+sum1, (ll)0); sum1 = min((ll)-1,sum1);
      ans2 += max((ll)1-sum2, (ll)0); sum2 = max((ll)1, sum2);
    }
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0;i < n;i++)cin >> s[i];
  sort(s.begin(),s.end());

  string ans = "";
  for(int i = 0;i < n;i++)ans += s[i];

  cout << ans << endl;
}

Measured memory_bytes: 256
l = input().split(" ")
n= int(l[0])
m= int(l[1])
x= int(l[2])
y= int(l[3])
xcon=[]
ycon= []

xcon = input().split(" ")
for i in range(n):
    xcon[i] = int(xcon[i])

ycon = input().split(" ")
for i in range(m):
    ycon[i]=int(ycon[i])

xcon = sorted(xcon)
ycon = sorted(ycon)

if max(x,xcon[-1]) < min(ycon[0],y):
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
a = input()
b = input()
c = input()

# 文字のマッチング(?はワイルドカード)
def match(a, b):
    return a=="?" or b=="?" or a==b

ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか？
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか？
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか？

def check(a, b, ab):
    for i in range(len(a)):
        for j in range(len(b)):
            if not match(a[i], b[j]):
                ab[i-j+50000] = False

check(a, b, ab)
check(a, c, ac)
check(b, c, bc)

len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)

ans = len_a + len_b + len_c

# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
    # j = CをAに対していくつスライドして置くか
    for j in range(-2 * len_max, 2 * len_max + 1):
        if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
            left = min(0, i, j)
            right = max(len_a, len_b+i, len_c+j)
            ans = min(ans, right - left)

print(ans)


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

int W,H;
char board[61][31];

const int INF=1e9;

#define mkt make_tuple
int dist[61][31][61][31][2];

int dijkstra(){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;k<H;k++){
                for(int l=0;l<W;l++){
                    dist[i][j][k][l][0]=INF;
                    dist[i][j][k][l][1]=INF;
                }
            }
        }
    }
    priority_queue<tuple<int,int,int,int,int,int>> PQ;
    for(int i=0;i<W;i++){
        if(board[0][i]=='S'){
            dist[0][i][0][0][0]=0;
            dist[0][0][0][i][1]=0;
            PQ.push(mkt(0,0,i,0,0,0));
            PQ.push(mkt(0,0,0,0,i,1));
        }
    }

    while(!PQ.empty()){
        auto f=PQ.top();
        PQ.pop();

        int co,lx,ly,rx,ry,p;
        co=-get<0>(f);
        lx=get<1>(f);
        ly=get<2>(f);
        rx=get<3>(f);
        ry=get<4>(f);
        p=get<5>(f);

        if(dist[lx][ly][rx][ry][p]<co) continue;

        if(board[lx][ly]=='T'||board[rx][ry]=='T') return co;

        for(int i=1;i<=3;i++){
            for(int j=i-3;j<=3-i;j++){
                int dx=j,dy=i;
                int nlx=lx,nly=ly,nrx=rx,nry=ry;
                int neco=0;
                if(p==0){
                    nrx=nlx+dx;
                    nry=nly+dy;
                    if(nrx<0||nrx>=H||nry<0||nry>=W) continue;
                    if(board[nrx][nry]=='X'||board[nrx][nry]=='S') continue;
                    if(board[nrx][nry]!='T') neco+=board[nrx][nry]-'0';
                }else{
                    nlx=nrx+dx;
                    nly=nry-dy;
                    if(nlx<0||nlx>=H||nly<0||nly>=W) continue;
                    if(board[nlx][nly]=='X'||board[nlx][nly]=='S') continue;
                    if(board[nlx][nly]!='T') neco+=board[nlx][nly]-'0';
                }

                if(dist[nlx][nly][nrx][nry][1-p]<co+neco) continue;
                dist[nlx][nly][nrx][nry][1-p]=co+neco;
                PQ.push(mkt(-(co+neco),nlx,nly,nrx,nry,1-p));
            }
        }
    }
    return -1;
}

void solve(){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>board[H-i-1][j];
        }
    }

    int ans=dijkstra();
    cout<<ans<<endl;
}

int main(){
  while(1){
      cin>>W>>H;
      if(W==0&&H==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 39148
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	string t;
	if(n % 2 != 0){
		cout<<"No"<<endl;
		return 0;
	}
	t = s.substr(0, n / 2);
	string r;
	r += t;
	r += t;
	if(r == s){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

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

int main() {

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

if(a > 2 * b){
  ans = a - 2 * b;
}
else{
  ans = 0;
}

cout << ans;

}

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

int main() {
  int N;
  cin >>N;
  for(int i=0;i<N;i++){
    string S;
    cin >>S;
    if(S=="Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i==N-1){
      cout << "Three" << endl;
      break;
    }
  }
}    

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int ans = ((n * (n -1)) + (m * (m - 1))) / 2;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (x, y) = (v[0], v[1]);
    let mut ans = (x.abs() - y.abs()).abs();
    if x == 0 {
        if y < 0 {
            ans += 1;
        }
    } else if y == 0 {
        if x > 0 {
            ans += 1;
        }
    } else if x * y >= 0 {
        if x > y {
            ans += 2;
        }
    } else {
        ans += 1;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = (c - (a + b));
    cout << ((d > 0 && d * d - 4 * a * b > 0) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<iostream>
#define INF 0x3f3f3f3f
using namespace std;
int n,m,k;
int a[300][300];
int b[300];
void floyd()
{
     int i,j,k;
     for(k=1;k<=n;k++)
     {
          for(i=1;i<=n;i++)
          {
               for(j=1;j<=n;j++)
               {
                    a[i][j]=min(a[i][k]+a[k][j],a[i][j]);
               }
          }
     }
}
int main(void)
{
     int i,j;
     while(scanf("%d%d%d",&n,&m,&k)==3)
     {
          for(i=0;i<=n;i++)
          {
               for(j=0;j<=n;j++)
               {
                    if(i==j)
                         a[i][j]=0;
                    else
                         a[i][j]=INF;
               }
          }
          for(i=0;i<k;i++)
               scanf("%d",&b[i]);
          int x,y,z;
          for(i=1;i<=m;i++)
          {
               scanf("%d%d%d",&x,&y,&z);
               if(a[x][y]>z||a[y][x]>z)
                    a[x][y]=a[y][x]=z;
          }
          floyd();
          sort(b,b+k);
          int ans=INF;
          do
          {
               int sum=0;
               for(i=0;i<k-1;i++)
               {
                    sum+=a[b[i]][b[i+1]];
               }
               ans=min(ans,sum);
          }while(next_permutation(b,b+k));
          printf("%d\n",ans);
     }
     return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  cout << min(b, c) << " " << max((ll)0, b + c - a) << endl;
}

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

int main(){
  int D;
  cin>>D;
  if(D==24){
    cout<<"Christmas Eve"<<endl;
    return 0;
  }
  else if(D==25){
    cout<<"Christmas"<<endl;
    return 0;
  }
  else if(D==23){
     cout<<"Christmas Eve Eve"<<endl;
    return 0;
  }  
  else if(D==22){
     cout<<"Christmas Eve Eve Eve"<<endl;
    return 0;
  }      
      
  
  
  
  return 0;
}

  



  
  
    

Measured memory_bytes: 3548
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, d; cin >> n >> d;
	vector<vector<double>> points;
	forl(i, 0, n) {
		vector<double> temp(d);
		fore(e, temp) cin >> e;
		points.push_back(temp);
	}
	int ans = 0;
	forl(i, 0, n) {
		forl(j, i+1, n) {
			double dis = 0;
			forl(k, 0, d) dis += (points[i][k]-points[j][k])*(points[i][k]-points[j][k]);
			dis = sqrt(dis);
			if(abs(dis-((int)dis)) < .0000001) ans++;
		}
	}
	println(ans);
}


Measured memory_bytes: 256