akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
char X[1001], Y[1001];
int  c[1001][1001];
int m, n;
int LCSLength(void)
{
  int i, j;
  m = strlen(X);
  n = strlen(Y);
 
  for( i=1 ; i<=m ; i++ )
    c[i][0] = 0;
  for( j=0 ; j<n ; j++ )
    c[0][j] = 0;
  for( i=1 ; i<=m ; i++ ){
    for( j=1 ; j<=n ; j++ ){
      if(X[i-1]==Y[j-1])
    c[i][j] = c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1])
    c[i][j] = c[i-1][j];
      else
    c[i][j] = c[i][j-1];
    }
  }
  return c[i-1][j-1];
} 
int main()
{
  int a[150];
  int i, j, k, q;
  scanf("%d",&q);
  for( i=0 ; i<q ; i++ ){
    scanf("%s",X);
    scanf("%s",Y);
    LCSLength();
    a[i] = LCSLength();
  }
  for( i=0 ; i<q ; i++ ){
    printf("%d\n",a[i]);
  }
 
  return 0;
}




Measured memory_bytes: 5720
#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
LL dp[2];
int n,P;
int main(){
	scanf("%d %d",&n,&P);
	dp[0]=1;
	while (n--){
		int x; scanf("%d",&x); x%=2;
		if (!x) dp[0]*=2,dp[1]*=2;
		else{
			LL a0=dp[0],a1=dp[1];
			dp[0]+=a1; dp[1]+=a0;
		}
	}
	cout<<dp[P];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,x,y;
  cin >> N;
  int a=0;
  
  for(int i; i<N; i++){
    int x,y;
    cin >>x >>y;
    a +=y-x+1;
  }
  cout <<a <<endl;
}

Measured memory_bytes: 256
import math, itertools
N = int(input())
Ax = []
Ay = []
for _ in range(N):
    x, y = map(int, input().split())
    Ax.append(x)
    Ay.append(y)

Nperm = 1
for i in range(1, N + 1):
    Nperm *= i

    
Ncomb = N * (N - 1) // 2

Npair = Nperm * (N - 1) // Ncomb

ans = 0
for c in itertools.combinations(range(N), 2):
    p1, p2 = c
    ans += math.sqrt((Ax[p1] - Ax[p2])**2 + (Ay[p1] - Ay[p2])**2) * Npair

print(ans / Nperm)

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<long>a(n);
  vector<pair<long, long>>cb(m);
  for(int i=0; i<n; i++)cin >> a[i];
  for(int i=0; i<m; i++){
    long b, c;
    cin >> b >> c;
    cb[i]=make_pair(c, b);
  }
  sort(a.begin(), a.end());
  sort(cb.rbegin(), cb.rend());
  int cbi=0, ai=0;
  while(cbi<n && cb[cbi].first>a[ai]){
    a[ai]=cb[cbi].first;
    ai++;
    cb[cbi].second--;
    if(cb[cbi].second==0)cbi++;
  }
  cout << accumulate(a.begin(), a.end(), 0L);
  return 0;
}
  

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long num,no;
    vector<string> list;
    string fin="", a;
    cin >> num >> no;
    for (long long i=0; i<num; i++) {cin >> a; list.push_back(a);}
    sort(list.begin(),list.end());
    for (long long i=0; i<num; i++) {fin+=list[i];}
    cout << fin;}

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

constexpr int N = 16;
int n, a[N][N];
long long dp[1 << N], cost[1 << N];
bool done[1 << N];

long long go(int msk) {
    if(msk == 0) return 0;
    if(done[msk]) return dp[msk];
    for(int s = msk; s; s = (s - 1) & msk) {
        dp[msk] = max(dp[msk], cost[s] + go(msk ^ s));
    }
    done[msk] = true;
    return dp[msk];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }
    for(int s = 0; s < (1 << n); ++s) {
        for(int j = 0; j < n; ++j) {
            for(int k = 0; k < j; ++k) {
                if(((1 << j) & s) && ((1 << k) & s)) {
                    cost[s] += a[j][k];
                }
            }
        }
    }
    cout << go((1 << n) - 1) << '\n';
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int k,q[5000005][2];
int from[100005][50][2];
int sta[100005],top;
int main(){
	scanf("%d",&k);
	q[1][0]=0; q[1][1]=0;
	memset(from,-1,sizeof(from));
	from[0][0][0]=1;
	int h=0,t=1;
	while (h!=t){
		int x=q[++h][0],y=q[h][1];
		for (int i=0;i<=9;i++){
			int xx=(x*10+i)%k,yy=y+i;
			if (yy>=50) continue;
			if (from[xx][yy][0]==-1){
				from[xx][yy][0]=x;
				from[xx][yy][1]=i;
				q[++t][0]=xx; q[t][1]=yy;
				//printf("%d %d %d %d\n",xx,yy,x,y,i);
			}
		}
	}
	for (int i=1;i<=60;i++)
		if (from[0][i][0]!=-1){
			printf("%d\n",i); 
			return 0;
		}
}

Measured memory_bytes: 77696
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b;
  std::cin >> a >> b;
  if(a<=0||a>=10||b<=0||b>=10){
    std::cout << -1 << '\n';
    return 0;
  }
  std::cout << a * b << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int out = 0;
    if(c <= a+b){
        out += c;
        out += b;
    }else{
        out += b+a+b+1;
    }

    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define M_PI 3.141592653589793


int main(void) {

	int i = 0, j, k;
	int sum;
	char fin[2] = "0";

	char str[1000][10000];

	while (1) {
		scanf("%s", str[i]);
		//printf("%d,%d\n", strlen(str[i]), atoi(str[i]));
		if ((int)strlen(str[i]) == 1 && (int)atoi(str[i]) == 0) {
			break;
		}
		i++;
	}
	

	for (j = 0; j < i; j++) {
		sum = 0;
		for (k = 0; k < strlen(str[j]); k++) {
			sum += str[j][k] - '0';
		}
		printf("%d\n", sum);
	}
	

	return 0;

}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

int x[110],y[110],h[110];

signed main(){
  int N;cin>>N;
  for(int t=0;t<N;t++){
    int X,Y,H;cin>>X>>Y>>H;
    x[t]=X;y[t]=Y;h[t]=H;
  }

  for(int X=0;X<=100;X++){
    for(int Y=0;Y<=100;Y++){
      int H;

      for(int t=0;t<N;t++){
        if(h[t]!=0){
            H=h[t]+abs(X-x[t])+abs(Y-y[t]);
            break;
        }
      }

      bool flag=true;
      for(int t=0;t<N;t++){

        if(h[t]==0){
          if(H-abs(X-x[t])-abs(Y-y[t])>0){
            flag=false;
            break;
          }
        }

        if(H!=h[t]+abs(X-x[t])+abs(Y-y[t])&&h[t]!=0){
            flag=false;
            break;
        }

      }

      if(flag){
        cout<<X<<" "<<Y<<" "<<H<<"\n";
        return 0;
      }

    }
  }

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

zero = 0
minus = 0
for i in range(n):
    if a[i] == 0:
        zero = 1
    elif a[i] < 0:
        minus += 1
    a[i] = abs(a[i])

a.sort()
if zero or minus%2 == 0:
    print(sum(a))
else:
    print(sum(a[1:])-a[0])

Measured memory_bytes: 64880
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]
d = Counter(S)
for t in T:
    if t in d:
        d[t]+=-1
    else:
        d[t]=-1
print(d.most_common()[0][1] if d.most_common()[0][1]>0 else 0)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
ll n , k;
ll a[1002];
vector<ll > v;
map<ll,ll> dp;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n >> k;
        for(ll i=1;i<=n;i++ ) cin >> a[i];
        for(ll i=1;i<=n;i++) {
                ll s=0;
                for(ll j=i;j<=n;j++) {
                        s += a[j];
                        v.pb(s);
                }
        }
        sort(v.begin(), v.end());
        //for(auto i : v) cout << i << endl;
        ll cur = 0;
        for(ll i=63;i>=0;i--) {
                vector<ll> t;
                t.clear();
                for(auto j : v) {
                        if(j&(1LL << i)) t.pb(j);
                }
                if((ll)t.size() >= k) {
                        //cout << i << " " << t.size() << endl;
                        cur += (1LL << i);
                        v = t;
                }
        }
        cout << cur << endl;
        return 0;
}


Measured memory_bytes: 6512
import sys
def input(): return sys.stdin.readline().rstrip()
class UnionFind():
    def __init__(self, n):
        self.n=n
        self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
    def find(self,x):
        #グループの根を返す
        if self.parents[x]<0:return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        #要素x,yのグループを併合
        x,y=self.find(x),self.find(y)
        if x==y:return
        if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x #要素数が大きい方に併合
    def size(self,x):
        #xが属するグループの要素数
        return -self.parents[self.find(x)]
    def same(self,x,y):
        #xとyが同じグループ？
        return self.find(x)==self.find(y)
def main():
    n,m=map(int,input().split())
    AB=[tuple(map(int,input().split())) for i in range(m)]
    ANS=[0]*(m+1)
    ANS[0]=n*(n-1)//2
    uf=UnionFind(n)
    i=0
    for a,b in AB[::-1]:
        a-=1
        b-=1
        if uf.same(a,b):
            ANS[i+1]=ANS[i]
        else:
            na=uf.size(a)
            nb=uf.size(b)
            ANS[i+1]=ANS[i]-na*nb
            uf.unite(a,b)
        i+=1
    for i in range(m):
        print(ANS[-2-i])


if __name__=='__main__':
    main()

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){if(a < b) a = b;}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	map<string, int> mp;
	rep(i, n){
		string s;
		cin >>s;
		mp[s]++;
	}
	
	vector<pair<int, string>> v;
	for(auto x: mp) v.push_back(make_pair(x.second, x.first));
	sort(all(v), [](auto l, auto r){
		return l.first == r.first? l.second < r.second: l.first > r.first;
	});
	
	int su=v[0].first;
	for(auto x: v){
		if(su == x.first) cout << x.second <<"\n";
	}
	
	return 0;
}


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


bool myfunc(long long i, long long j){return (i>j);}

int main(){
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<long long> p(a), q(b), r(c);
	for (long long i = 0; i < a; i++){
		cin >> p[i];
	}
	for (long long i = 0; i < b; i++){
		cin >> q[i];
	}
	for (long long i = 0; i < c; i++){
		cin >> r[i];
	}
	sort(p.begin(), p.end(), myfunc);
	sort(q.begin(), q.end(), myfunc);

	for (long long i = 0; i < x; i++){
		r.push_back(p[i]);
	}
	for (long long i = 0; i < y; i++){
		r.push_back(q[i]);
	}
	
	sort(r.begin(), r.end(), myfunc);
	
	long long result = 0;

	for (long long i = 0; i < (x+y); i++){
		result += r[i];
	}
	
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  sort(a.begin(), a.end());
  ull ans;
  if(a[0] == 0) ans = 0;
  else{
    ans = 1;
    for(int i = 0; i < n; i++){
      ull temp = ans;
      ans *= a[i];
      if(temp != ans / a[i]){
        cout << -1 << endl;
        return 0;
      }
      if(ans > 1000000000000000000){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
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);
}

inline int64 modPow(int64 x, int64 n) {
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

inline int64 modInv(int64 a) {
  return (modPow(a, mod - 2));
}

inline int64 modCombination(int p, int q) {
  static int64 fact[202020], rfact[202020];
  if(fact[0] == 0) {
    fact[0] = rfact[0] = 1;
    for(int i = 1; i < 102020; i++) {
      fact[i] = fact[i - 1] * i % mod;
      rfact[i] = modInv(fact[i]);
    }
  }
  if(q < 0 || p < q) return (0);
  return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
}

inline int64 count2_1(int n, int k) {
  return (modCombination(n + k - 1, k - 1));
}

int main() {
  int N, K;
  cin >> N >> K;
  cout << count2_1(N, K) << endl;
}






Measured memory_bytes: 4800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		int H,W;

		Scanner sc = new Scanner(System.in);

		while(true) {
			H = sc.nextInt();
			W = sc.nextInt();

			if(H==0 && W==0) break;

			for ( int i = 0; i < H; i++ ){
			    for ( int j = 0; j < W; j++ ){
			        if((i==0 || j==0) || (i==H-1 || j==W-1)){
			            System.out.print("#");
			        } else {
			            System.out.print(".");
			        }
			    }
			    System.out.println();
			}
			System.out.println();
		}
	}

}



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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int x,y,z;cin>>x>>y>>z&&x|y|z;){
		multiset<string> s;
		rep(_,x) s.insert("a");
		rep(_,y) s.insert("b");
		rep(_,z) s.insert("c");
		while(s.size()>1){
			auto i=begin(s),j=--end(s);
			s.insert(*i+*j);
			s.erase(i);
			s.erase(j);
		}
		cout<<*begin(s)<<endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

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

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		boolean[] a = new boolean[N + 1];
		boolean[] b = new boolean[N + 1];
		for (int i = 0; i < M; i++) {
			int a_i = sc.nextInt();
			int b_i = sc.nextInt();

			if (a_i == 1) {
				a[b_i] = true;
			}
			if (b_i == 1) {
				a[a_i] = true;
			}
			if (a_i == N) {
				b[b_i] = true;
			}
			if (b_i == N) {
				b[a_i] = true;
			}
		}
		boolean answer = false;
		for (int i = 1; i <= N; i++) {
			if (a[i] && b[i]) {
				answer = true;
				break;
			}
		}
		if (answer) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 94320
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next(),b=sc.next(),c=sc.next();
		String pre="a";
		for(;;) {
			if(pre.equals("a")) {

				if(a.length()==0) {
					System.out.println("A");
					break;
				}else {
					pre=a.charAt(0)+"";
					a=a.substring(1);
				}
			}else if(pre.equals("b")) {

				if(b.length()==0) {
					System.out.println("B");
					break;
				}else {
					pre=b.charAt(0)+"";
					b=b.substring(1);
				}
			}else if(pre.equals("c")) {

				if(c.length()==0) {
					System.out.println("C");
					break;
				}else {
					pre=c.charAt(0)+"";
					c=c.substring(1);
				}
			}
		}

		sc.close();
	}
}

Measured memory_bytes: 23892
import scala.io.StdIn

object Main extends App {
  val Array(x, y) = StdIn.readLine().split(' ').map(_.toLong)

  def loop(cnt: Long, xi: Long): Long = {
    if (xi > y) cnt
    else {
      loop(cnt + 1, x * scala.math.pow(2, cnt + 1).toLong)
    }
  }

  println(loop(0, x))

}

Measured memory_bytes: 27324
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int ans=100000;
string str;
int main(){
	cin>>str;
	for (char l='a';l<='z';l++){
		string s=str+l;
		int le=0,maxi=0;
		for (int i=0;i<s.size();i++){
			if (s[i]!=l){
				le++;
			}else{
				if (le>maxi) maxi=le;
				le=0;
			}
		}
		if (maxi<ans) ans=maxi;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
hash = {}
%w|M A R C H|.each{ |c| hash[c] = 0 }

gets.to_i.times do
  char = gets.chars[0]
  if %w|M A R C H|.include?(char)
    hash[char] += 1
  end
end

m, a, r, c, h = hash["M"], hash["A"], hash["R"], hash["C"], hash["H"]
puts m * a * (r + c + h) + (m + a) * (r * c + r * h + c * h) + r * c * h


Measured memory_bytes: 1788
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for b in range(1,N+1):
    p = N//b
    ans += p*max(b-K,0)
    r = N % b
    ans += max(r-K+1,0)
if K == 0:
    ans = N**2
print(ans)

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

int main() {
    int a, b, c, k;
    scanf("%d%d%d%d", &a, &b, &c, &k);
    rep(i, k) {
        if (a < b && b < c) break;
        else if (a >= b) b *= 2;
        else if (b >= c) c *= 2;
    }
    if (a < b && b < c) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 3708
#include <stdio.h>
#include <string.h>
int main(){
	int n,t=0;
	scanf("%d",&n);
	int a[n+1];
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<n-1;i++){
		if((a[i]>a[i-1]&&a[i]<a[i+1]) || (a[i]<a[i-1]&&a[i]>a[i+1]))
			t++;
	}
	printf("%d",t);
	return 0;
}

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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a[] = new int[2];
        a[0] = sc.nextInt();
        a[1] = sc.nextInt();
        Arrays.sort(a);
        int ans = 3;
        if (a[0] != 1) {
            ans = 1;
        } else if (a[1] != 2) {
            ans = 2;
        }
        System.out.println(ans);
        sc.close();
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long

int main() {
  int k,x;cin>>k>>x;
  for(int i=x-k+1;i<x+k;i++)
  {
    cout<<i;
    cout<<' ';
  }
}

Measured memory_bytes: 256
/* Author- Abhijeet Trigunait */

#include<bits/stdc++.h>
#define lld long long int
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define mod 1e9+7
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define gcd(x,y) __gcd(x,y)
#define endl '\n'

using namespace std;
lld dp[100010] = {0};


lld minCost(lld *arr, lld n, lld k) {
	for (lld i = 1; i < n; ++i) {
		dp[i] = INT_MAX;

		for (lld j = i - 1; j >= 0 and (i - j) <= k; --j) {
			dp[i] = min(abs(arr[i] - arr[j]) + dp[j], dp[i]);
		}
	} return dp[n - 1];
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	lld n, k;
	cin >> n >> k;
	lld arr[n];
	for (lld i = 0; i < n; ++i)cin >> arr[i];
	cout << minCost(arr, n, k) << endl;
}

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

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

int ans = INT_MAX;

int n, a, b, c;
int inp[10];
int arr[10];
void dfs(int x)
{
    if (x == n) {
        int s[3] = {0};
        int cnt[3] = {0};
        for (int i = 0; i < n; i++)
            if (arr[i] >= 1)
                s[arr[i] - 1] += inp[i], cnt[arr[i] - 1]++;
        for (int i = 0; i < 3; i++)
            if (s[i] == 0)
                return;
        int diff = abs(s[0] - a) + abs(s[1] - b) + abs(s[2] - c);
        for (int i = 0; i < 3; i++)
            if (cnt[i] > 1)
                diff += 10 * (cnt[i] - 1);

        if (ans > diff) {
            /*
                        printf("diff %d\n", diff);
            for (int i = 0; i < n; i++)
                printf("%d ", arr[i]);
            printf("\n");
            for (int i = 0; i < 3; i++)
                printf("%d %d %d\n", i, s[i], cnt[i]);
                        */
        }
        ans = min(ans, diff);

        return;
    }

    for (int i = 0; i < 4; i++) {
        arr[x] = i;
        dfs(x + 1);
    }
}

int main()
{
    /*
    5 100 90 80
    98 80 40 30 21
     */

    scanf("%d %d %d %d", &n, &a, &b, &c);
    for (int i = 0; i < n; i++)
        scanf("%d", &inp[i]);

    dfs(0);

    printf("%d\n", ans);

    return 0;
}


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

using namespace std;

int main(){ 
	cin.tie(0);
	ios::sync_with_stdio(0);
	int a,b;
	vector<int> deg(4,0);
	for(int i=0;i<3;i++){ 
		cin>>a>>b;
		a--;
		b--;
		deg[a]++;
		deg[b]++;
	} 
	for(int i=0;i<4;i++){ 
		if(deg[i]==0 or deg[i]>=3){ 
			cout<<"NO";
			return 0;
		}
	} 
	cout<<"YES";

	return 0;
}



Measured memory_bytes: 256
N,W = map(int, input().split())
table = []
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(N):
    v,w = map(int, input().split())
    table.append((v,w))

for i in range(N):
    for j in range(W+1):
        v,w = table[i]
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
        if j+w<=W:
            dp[i+1][j+w] = max(dp[i+1][j+w],dp[i][j]+v)
print(max(dp[-1]))


Measured memory_bytes: 41884
H, W = map(int, input().split())
lines = [input() for _ in range(H)]

rs = [list("#" + (W-2) * ("#" if i%2==0 else ".") + ".") for i in range(H)]
bs = [list("." + (W-2) * ("#" if i%2==1 else ".") + "#") for i in range(H)]

for i, line in enumerate(lines):
    for j, c in enumerate(line):
        if c=="#":
            rs[i][j] = "#"
            bs[i][j] = "#"

print("\n".join(["".join(r) for r in rs]), end="\n"*2)
print("\n".join(["".join(b) for b in bs]), end="\n"*2)

Measured memory_bytes: 9096
#include <iostream>
#include <algorithm>
#define INF 1001001001
using namespace std;

int num[21],dp[1<<20],rui[100010][21];
int main(){
	int N,M;
	cin>>N>>M;
	int tmp;
	for(int i=1;i<=N;i++){
		cin>>tmp;
		rui[i][tmp-1]++;
		num[tmp-1]++;
	}
	for(int i=1;i<=N;i++){
		for(int j=0;j<M;j++){
			rui[i][j]+=rui[i-1][j];
		}
	}

	fill(dp,dp+(1<<M),INF);
	dp[0]=0;
	int cnt;
	for(int i=0;i<(1<<M);i++){
		cnt=0;
		for(int j=0;j<M;j++){
			if(i&(1<<j)){
				cnt+=num[j];
			}
		}
		for(int j=0;j<M;j++){
			if(!(i&(1<<j))){
				int hog=(i|(1<<j));
				dp[hog]=min(dp[hog],dp[i]+num[j]-(rui[cnt+num[j]][j]-rui[cnt][j]));
			}
		}
	}
	cout<<dp[(1<<M)-1]<<endl;
	return 0;
}

Measured memory_bytes: 15404
#include <stdio.h>

int main(){

  int i,j,k,q,n,l,m[101][101],p[101];
  
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d%d",&p[i-1],&p[i]);
  
  for(i=1;i<=n;i++)m[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=10000000;
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(m[i][j]>q)m[i][j]=q;
      }

    }
  }
  
  printf("%d\n",m[1][n]);
  
  return 0;
}



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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<string,int>Psi;

int main(){
  int a,b;
  cin>>a>>b;
  if(a>=13){
    cout<<b<<endl;
  }else if(a<=5){
    cout<<0<<endl;
  }else{
    cout<<b/2<<endl;
  }
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [0] * m
for i in range(m):
    ab[i] = list(map(int, input().split()))
roads = [0] * n
for a, b in ab:
    roads[a-1] += 1
    roads[b-1] += 1
for i in roads:
    print(i)


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

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

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a+b > c+d){
        cout << "Left" << endl; 
    }
    else if(a+b<c+d){
        cout << "Right" << endl;
    }
    else{
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x = read::<usize>();
    let a = read::<usize>();
    let b = read::<usize>();
    if b <= a {
        println!("delicious");
    } else if b <= a + x {
        println!("safe");
    } else {
        println!("dangerous");
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[][] a = new int[2][n];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = Integer.parseInt(sc.next());
            }
        }

        // 主処理
        int[][] dp = new int[2][n];

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

        dp[1][0] = dp[0][0] + a[1][0];
        for (int i = 1; i < n; i++) {
            dp[1][i] = Math.max(dp[1][i - 1] + a[1][i], dp[0][i] + a[1][i]);
        }

        int result = dp[1][n - 1];

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21844
/*
      author  : nishi5451
      created : 15.08.2020 13:54:38
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        cout << 'x';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> arr;
typedef vector<arr> matrix;
typedef vector<ll> longarr;
typedef vector<longarr> longmat;

void lengthLCS(string x, string y, matrix &dp) {
	for (int i = 1; i <= x.size(); ++i) {
		for (int j = 1; j <= y.size(); ++j) {
			dp[i][j] = (x[i - 1] == y[j - 1]) ? (1 + dp[i - 1][j - 1]) : max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
}

void makeLCS(matrix &dp, string x, string y, int i, int j, int index, string &ans) {
	if (index == -1) return;
	if (x[i - 1] == y[j - 1]) {
		ans[index] = x[i - 1];
		makeLCS(dp, x, y, i - 1, j - 1, index - 1, ans);
	}
	else {
		if (dp[i - 1][j] > dp[i][j - 1]) makeLCS(dp, x, y, i - 1, j, index, ans);
		else makeLCS(dp, x, y, i, j - 1, index, ans);
	}
}
string LCS(string x, string y, matrix dp) {
	int len = dp[x.size()][y.size()];
	string ans(len, ' ');
	makeLCS(dp, x, y, x.size(), y.size(), len - 1, ans);
	return ans;
}

int main() {

	string x; string y;
	cin >> x >> y;
	matrix dp(x.size() + 1, arr(y.size() + 1, 0));
	lengthLCS(x, y, dp);
	// for (int i = 0; i <= x.size(); ++i) {
	// 	for (int j = 0; j <= y.size(); ++j) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << LCS(x, y, dp);
}

Measured memory_bytes: 103448
#include <iostream>

using namespace std;

int appartient(long t[],long nb, long e) {
  // repond 1 si e est dans le tableau t de longueur nb
  if ((e < t[0]) || (e > t[nb-1]))
    return 0;
  else if (e == t[nb-1])
    return 1;
  else {
    long a,b,m;
    a = 0;
    b = nb-1;
    // t[a] <= e < t[b]
    while ((b-a) > 1) {
       m = (a+b)/2;
       if (t[m] <= e)
        a = m;
       else
        b = m;
    }
    return (t[a] == e);
  }
}

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

  long nb_R;
  long nb_G;
  long nb_B;
  long R[4000],G[4000],B[4000];



   long i,j,k,result;

   // lire

   nb_R = 0;
   nb_G = 0;
   nb_B = 0;
   for (i=0;i<N;i++) {
     if (S[i] == 'R') {
       R[nb_R] = i;
       nb_R++;
     }
     else if (S[i] == 'G') {
       G[nb_G] = i;
       nb_G++;
     }
     else {
       B[nb_B] = i;
       nb_B++;
     }
   }

   result = nb_R*nb_G*nb_B;
  // on enleve les milieux
   for (i=0;i<nb_R;i++)
    for (j=0;j<nb_G;j++) {
      k = R[i]+G[j];
      if ((k % 2) == 0)
        if (appartient(B,nb_B,k/2))
          result--;
    }
    for (i=0;i<nb_R;i++)
     for (j=0;j<nb_B;j++) {
       k = R[i]+B[j];
       if ((k % 2) == 0)
         if (appartient(G,nb_G,k/2))
           result--;
     }
     for (i=0;i<nb_G;i++)
      for (j=0;j<nb_B;j++) {
        k = G[i]+B[j];
        if ((k % 2) == 0)
          if (appartient(R,nb_R,k/2))
            result--;
      }


    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

bool f(int n) {
  if( n/100 == n%10 && (n%100)/10 == n%10 ) return true;
  else return false;
}

int main() {
  int n;
  cin >> n;
  while( !f(n) ) {
    n++;
  }
  dump(n);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b;
char list2[100];
void judge() {
	for(int i=0; i<a; i++) {
		if(list2[i]<'0'||list2[i]>'9') {
			printf("No\n");
			return;
		}
	}
	if(list2[a]!='-') {
		printf("No\n");
		return;
	}
	for(int i=a+1; i<a+b+1; i++) {
		if(list2[i]<'0'||list2[i]>'9') {
			printf("No\n");
			return;
		}
	}
	puts("Yes");
	return;
}
int main() {
	scanf("%d%d",&a,&b);
	scanf("%s",list2);
	judge();
	return 0;
}

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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    for (int i = 0; i < N; i++) {
        cin >> V.at(i);
    }
    int ans = 0;
    for (int i = 1; i <= min(N, K); i++) {
        for (int j = 0; j <= i; j++) {
            vector<int> vec;
            for (int k = 0; k < j; k++) {
                vec.push_back(V.at(k));
            }
            for (int k = 0; k < i - j; k++) {
                vec.push_back(V.at(V.size() - 1 - k));
            }
            sort(vec.begin(), vec.end());
            int score = accumulate(vec.begin(), vec.end(), 0);
            for (int k = 0; k < min((int) vec.size(), K - i); k++) {
                if (vec.at(k) >= 0) {
                    break;
                }
                score -= vec.at(k);
            }
            ans = max(ans, score);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	cnt := map[int]int{
		1: 0,
		2: 0,
		4: 0,
	}
	for i := 0; i < N; i++ {
		a := nextInt()
		if a%2 == 1 {
			cnt[1]++
		} else if a%4 == 0 {
			cnt[4]++
		} else {
			cnt[2]++
		}
	}
	// fmt.Println(cnt)
	if cnt[2] == 0 {
		cnt[4]++
	}
	if cnt[4] >= cnt[1] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
	// if cnt[2] == 0 {
	// 	if cnt[4]+1 >= cnt[1] {
	// 		fmt.Println("Yes")
	// 	} else {
	// 		fmt.Println("No")
	// 	}
	// } else {
	// 	if cnt[4] >= cnt[1] {
	// 		fmt.Println("Yes")
	// 	} else {
	// 		fmt.Println("No")
	// 	}
	// }
	// if (cnt[4]*2 >= cnt[1] && cnt[2]%2 == 0) || cnt[4]*2 >= cnt[1]+cnt[2] {
	// 	fmt.Println("Yes")
	// } else {
	// 	fmt.Println("No")
	// }
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 3200
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int N, Q; std::cin >> N >> Q;
  std::string S; std::cin >> S;
  std::vector<int> l(Q), r(Q);
  for (int i = 0; i < Q; ++i) {
    std::cin >> l[i] >> r[i];
  }

  std::vector<int> a(N);
  a[0] = 0;
  for (int i = 1; i < S.length(); ++i) {
    a[i] = a[i-1];
    if (S[i-1] == 'A' && S[i] == 'C') {
      ++a[i];
    }
  }


  for (int i = 0; i < Q; ++i) {
    std::cout << a[r[i]-1] - a[l[i]-1] << std::endl;
  }
}


Measured memory_bytes: 2176
while True:
    n = int(input())
    if n == 0:
        exit()

    dp = [0] * (n+1)
    dp[0] = 1

    for i in range(1, n+1):
        dp[i] += dp[i-1]
        if i > 1:
            dp[i] += dp[i - 2]
        if i > 2:
            dp[i] += dp[i - 3]
    print((dp[-1]//10 + 1) // 365 + 1)



Measured memory_bytes: 5600
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int N; cin >> N;
    map<string, int> m;
    string tmp;
    rep(i,N){
        cin >> tmp;
        m[tmp] = 1;
    }
    cout << m.size() << endl;
}

Measured memory_bytes: 19256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(l,k,h) for(int l = k; l <= h; ++l)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    string s;
    cin >> s;
    regex r("A?KIHA?BA?RA?");
    cout << (regex_match(s,r)?"YES":"NO");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int A,B,C,D;
  	cin>>A>>B>>C>>D;
  	int X=(A+D-1)/D;
  	int Y=(C+B-1)/B;
	cout<<(X>=Y?"Yes":"No")<<"\n";
 
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, N, SR, SC;
    string S, T;
    cin >> H >> W >> N >> SR >> SC >> S >> T;
    int left = 1, right = W;
    for (int i = N - 1; i >= 0; i--) {
        if (T[i] == 'L') right = min(right + 1, W);
        else if (T[i] == 'R') left = max(left - 1, 1);
        if (S[i] == 'L') left++;
        else if (S[i] == 'R') right--;
        if (left > right) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (left > SC || right < SC) {
        cout << "NO" << endl;
        return 0;
    }
    left = 1, right = H;
    for (int i = N - 1; i >= 0; i--) {
        if (T[i] == 'U') right = min(right + 1, H);
        else if (T[i] == 'D') left = max(left - 1, 1);
        if (S[i] == 'U') left++;
        else if (S[i] == 'D') right--;
        if (left > right) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (left > SR || right < SR) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 920
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n,L;
    bool ansb = false;
    int ansi;
    int count = 0;
    int c[100000];
    int tmp;
    cin >> n ;
    rep (i,n){
        cin >> c[i];
    }
    rep (j,n){
        rep(k,n){
            tmp = c[k];
            c[k] = c[j];
            c[j] = tmp;
            rep(i,n-1){
                if(c[i] > c[i+1]){
                    break;
                }
                if(i == n-2){
                    ansb = true;
                }
            }

            tmp = c[j];
            c[j] = c[k];
            c[k] = tmp;
        }
    }
    if(ansb){
        cout << "YES" << endl;
    }else{
        cout << "NO"<< endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l=1;
  cin>>n;
  int a[n];
  vector<int> v;
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++){
    if(a[i]==l){
      v.push_back(l);
      l++;
    }
  }
  if(v.empty())
    cout<<"-1";
  else
    cout<<n-v.size();
  return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define int long long

using namespace std;

const int N = 1e3 + 5, mod = 1e9 + 7;

int dp[N], a, b, c, d, n, fc[N], ans = 0, old[N], Fc[N], D[N][N];

inline int binpow (int a, int b)
{
    if (b == 0)
        return 1;
    if (b & 1)
        return a * binpow(a, b - 1) % mod;

    int x = binpow(a, b >> 1);

    return x * x % mod;
}
inline int Cnk (int n, int k, int l)
{
    return fc[n] * D[l][k] % mod * Fc[n - k * l] % mod * Fc[l] % mod;
}
main ()
{
    cin >> n >> a >> b >> c >> d;

    fc[0] = 1;
    Fc[0] = 1;

    for (int i = 1; i <= n; i++)
        fc[i] = i * fc[i - 1] % mod,
        Fc[i] = binpow( fc[i], mod - 2 );


    for (int j = 1; j <= n; j++)
    {
        D[0][j] = 1;
        for (int i = 1; i <= d; i++)
            D[i][j] = D[i - 1][j] * fc[j] % mod;
        for (int i = 1; i <= d; i++)
            D[i][j] = binpow(D[i][j], mod - 2);
    }
    dp[0] = 1;
    old[0] = 1;

    for (int i = a; i <= b; i++)
    {
        for (int j = c; j <= d; j++)
        {
            for (int l = i * j; l <= n; l++)
            {
                dp[l] += old[l - i * j] * Cnk( n - l + i * j, i,  j );
                dp[l] %= mod;
            }
        }
        for (int l = 1; l <= n; l++)
            old[l] = dp[l];
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int M = 5*1e5+5;
#define pi acos(-1)
#define INF 1e10
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
int main()
{
	int n;sd(n);
	LL sum = 0;
	for(int i=1;i<=n;++i)
	{
		if(i%3 != 0 && i%5 != 0) sum += 1LL*i;
	}
	plr(sum);
	//system("pause");
	return 0;
}

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

int x,a,b,c;

int main()
{
	cin>>a>>b>>c>>x;
	int ans=0;
	for(int i=0;i<=a;++i)
		for(int j=0;j<=b;++j)
		{
			if(x<500*i+100*j) break;
			if((x-500*i-100*j)/50<=c) ans++;
		}
		cout<<ans;
}
*/
#include <bits/stdc++.h>
using namespace std;

int n;
int sum[101][2];

int main()
{
	cin>>n;
	int x;
	sum[0][0]=sum[0][1]=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&x);
		sum[i][0]=sum[i-1][0]+x;
	}
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&x);
		sum[i][1]=sum[i-1][1]+x;
	}
	int ans=0;
	for(int i=1;i<=n;++i) ans=max(ans,sum[i][0]+sum[n][1]-sum[i-1][1]);
		printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int pow(int b, int e) {
  if(e == 0) return 1;
  if(e % 2 == 1) return pow(b, e - 1) * b;
  int m = pow(b, e >> 1);
  return m * m;
}
const int A = 0, B = 1, C = 2, NO = 3;
const int INF = 100000;
int main() {
  int n;
  int L[3];
  cin >> n >> L[0] >> L[1] >> L[2];
  vector<int> len(n);
  rep(i, n) cin >> len[i];
  vector<ll> into(n);

  int ans = INF;
  rep(cand, pow(4, n)) {
    rep(i, n) into[i] = (cand / pow(4, i)) % 4;

    int sl[3] = {0, 0, 0};
    int cnt[3] = {0, 0, 0};
    rep(bamboo, 3) rep(i, n) {
      if(into[i] == bamboo) {
        sl[bamboo] += len[i];
        cnt[bamboo] = cnt[bamboo] + 1;
      }
    }

    bool ok = true;
    rep(bamboo, 3) ok &= (cnt[bamboo] != 0);
    if(!ok) continue;

    int now = 0;
    rep(bamboo, 3) {
      now += abs(L[bamboo] - sl[bamboo]);
      now += 10 * (cnt[bamboo] - 1);
    }
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
end_a = 0
start_b = 0
a_and_b = 0
count = 0
for i in range(N):
    s = input()
    count += s.count('AB')
    s.replace('AB', '')
    if s[0] == 'B' and s[-1] == 'A':
        a_and_b += 1
    elif s[0] == 'B':
        start_b += 1
    elif s[-1] == 'A':
        end_a += 1


if a_and_b == 0:
    print(count + min(end_a, start_b))
elif end_a + start_b == 0:
    print(count + a_and_b - 1)
else:
    print(count + a_and_b + min(end_a, start_b))



Measured memory_bytes: 44008
fun main(args: Array<String>) {
    val (x, y) = readInputLine().split(" ").map { it.toInt() }

    if (x > 0 && y > 0) {
        if (y >= x) {
            println(y - x)
        } else {
            println(x - y + 2)
        }
    } else if (x < 0 && y < 0) {
        if (y >= x) {
            println(y - x)
        } else {
            println(-y + x + 2)
        }
    } else if (x > 0 && y < 0) {
        if (-y >= x) {
            println(-y - x + 1)
        } else {
            println(x + y + 1)
        }
    } else if (x < 0 && y > 0) {
        if (-x <= y) {
            println(y + x + 1)
        } else {
            println(-x - y + 1)
        }
    } else if (x == 0) {
        if (y >= 0) {
            println(y)
        } else {
            println(-y + 1)
        }
    } else {
        if (x > 0) {
            println(x + 1)
        } else {
            println(-x)
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

main(){
    while(1){
        int n;
        cin >> n;
        if(!n) break;
        vector<string> s(n);
        rep(i, n) cin >> s[i];
        int ans = 0;
        rep(i, n / 2) {
            if(s[i * 2][0] != s[i * 2 + 1][0]) ans++;
        }
        cout << ans << "\n";
    }
}



Measured memory_bytes: 3148
import java.util.Scanner;
class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int Thp = scan.nextInt();
        int Tattack = scan.nextInt();
        int Ahp = scan.nextInt();
        int Aattack = scan.nextInt();
        while(true){
            if((Ahp - Tattack) > 0){
                Ahp = Ahp - Tattack;
             }else{
                 System.out.println("Yes");
                 break;     
             }
             if((Thp - Aattack) > 0){
                 Thp = Thp - Aattack;
             }else{
                 System.out.println("No");
                 break;
             }
                    }
    }
}

Measured memory_bytes: 35920