akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		var ABC = GetLongs(3);
		var l = GetLongs(N);

		long BOUND = (long)Pow(4, N);
		long min = long.MaxValue;
		for(long s = 0; s < BOUND; s++)
		{
			var cnt = new long[4];
			var sum = new long[4];
			long rest = s;
			for(long i = 0; i < N; i++)
			{
				cnt[rest % 4]++;
				sum[rest % 4] += l[i];
				rest /= 4;
			}

			if(Range(0, 3).Any(x => cnt[x] == 0))
				continue;

			long cost = 0;
			for(long i = 0; i < 3; i++)
				cost += 10 * (cnt[i] - 1) + Abs(ABC[i] - sum[i]);

			chmin(ref min, cost);
		}

		WriteLine(min);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 44148
// D - Mixing Experiment

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

const int I_MAX = 40;
const int W_MAX = 400;

// dp[i][j][k]: i個目までの薬品を考慮したときの、Aがjグラム、Bがkグラムの時の最小予算
int dp[I_MAX+1][W_MAX+1][W_MAX+1];
int a[I_MAX+1], b[I_MAX+1], c[I_MAX+1];

int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	for (int i=1; i<=N; i++) {
		cin >> a[i] >> b[i] >> c[i]; // 1-index
	}

	// INFで初期化
	for (int i=0; i<=N; i++) {
		for (int j=0; j<=W_MAX; j++) {
			for (int k=0; k<=W_MAX; k++) {
				dp[i][j][k] = INF;
			}
		}
	}

	dp[0][0][0] = 0;

	for (int i=1; i<=N; i++) {
		for (int j=0; j<=W_MAX; j++) {
			for (int k=0; k<=W_MAX; k++) {
				// i個目を使う場合
				int prev_j = j - a[i];
				int prev_k = k - b[i];
				if (prev_j >= 0 && prev_k >= 0) {
					if (dp[i-1][prev_j][prev_k] != INF) {
						dp[i][j][k] = min(dp[i][j][k], dp[i-1][prev_j][prev_k] + c[i]);
					}
				}

				// i個目を使わない場合
				dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
			}
		}
	}

	int min_cost = INF;
	// jとkに0を含めないことに注意
	for (int j=1; j<=W_MAX; j++) {
		for (int k=1; k<=W_MAX; k++) {
			if (j * Mb == k * Ma) {
				min_cost = min(dp[N][j][k], min_cost);
			}
		}
	}

	if (min_cost == INF) min_cost = -1;

	cout << min_cost << endl;

	return 0;
}

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



int main() {
ll Q, H, S, D;
cin >> Q >> H >> S >> D;
ll N;
cin >> N;
Q *= 4;
H *= 2;
ll ans;
ll one = min({Q, H, S});
if(N % 2 == 0){
one *= 2;
ll two = min(one, D);
ans = two*(N/2);
}
else{
    int kari = one;
one *= 2;
ll two = min(one, D);
ans = two*(N/2);
ans += kari;
}

cout << ans << endl;
}

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

static const int N=1000;

int lcs(char* X,char* Y){
  int i,j;
  int c[N+1][N+1];
  int m=strlen(X);
  int n=strlen(Y);

  for(i=0;i<=m;i++)c[i][0]=0;
  for(j=1;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-1] >= c[i][j-1]) {
	c[i][j] = c[i-1][j];
      }
      else c[i][j] = c[i][j-1];
    }
  }
  if(i==0 || j==0)return 0;
  else if(i>0 && j>0 && m==n)return c[i-1][j-1];
  else if(i>0 && j>0 && m!=n)return c[m][n];
  return 0;
}

int main(){
  char s[1001],u[1001];
  int n,i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",s,u);
    printf("%d\n",lcs(s,u));
  }
  return 0;
}


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD 1000000007
void bulk(){}template<class H,class...T>void bulk(H&h,T&...t){cin>>h;bulk(t...);}
#define get(...) string __VA_ARGS__; bulk(__VA_ARGS__);

int digsum(int n){if(n<10)return n; return n%10+digsum(n/10);}

int main(){
	get(a,b);
    double t,f=modf(sqrt(stof(a+b)),&t);
    cout<<(f==0.0?"Yes":"No")<<endl;;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val (N,M)=readLine()!!.split(" ").map {it.toInt()}
    val student=(1..N).map {
      val (a,b)=readLine()!!.split(" ").map {it.toInt()}
      Triple(it,a,b)
      }
    val check=(1..M).map {
      val (c,d)=readLine()!!.split(" ").map {it.toInt()}
      Triple(it,c,d)
      }
    student.map{s->
    val d=check.minBy {Math.abs(s.second-it.second)+Math.abs(s.third-it.third)}!!
    check.filter {
      (Math.abs(s.second-it.second)+Math.abs(s.third-it.third))==(Math.abs(s.second-d.second)+Math.abs(s.third-d.third))
    }.minBy {it.first}!!
    }.forEach {
      println("${it.first}")
    }
  }
}

Measured memory_bytes: 29976
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string n;
  cin>>n;
  rep(i,n.size() ){
    if(n[i]=='7'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> enter(N);
  for(int i = 0; i < N; i++) {
    cin >> enter.at(i);
  }
  sort(enter.begin(), enter.end());
  
  int max = enter.at(N - 1);
  int min = enter.at(0);
  int result = max - min;
  
  cout << result << endl;
}
    

Measured memory_bytes: 256
def is_perfect_power(n):
    if n == 1:
        return True
    div = 2
    divs = []
    while n != 1:
        if n % div == 0:
            n //= div
            divs.append(div)
        else:
            div += 1
    divs_d = {d: 0 for d in set(divs)}
    for d in divs:
        divs_d[d] += 1
    divs_s = {n for n in divs_d.values()}
    if min(divs_s) > 1:
        for d in divs_s:
            if d % min(divs_s) != 0:
                return False
    else:
        return False
    return True


X = int(input())
for x in range(X, 0, -1):
    if is_perfect_power(x):
        print(x)
        break


Measured memory_bytes: 3064
#include <iostream>


using namespace std;
int a[100000000];
int largest,n,l,r;
int i,x;
int maxHeapify(int a[],int i){
    l=2*i+1;
    r=2*i+2;
    if(l<=n && a[l]>a[i]){
        largest =l;
    }
    else{
        largest =i;
    }
    if(r<=n && a[r]>a[largest]){
        largest =r;
    }
    if(largest!=i){
        x=a[i];
        a[i]=a[largest];
        a[largest]=x;
        maxHeapify(a,largest);
    }
    return 0;
}
void buildMaxHeap(int a[]){
    for(int i=n/2;i>=0;i--){
        maxHeapify(a,i);
    }
}
int main(void){
    
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    buildMaxHeap(a);
    for(int i=0;i<n;i++){
        cout <<" "<< a[i];
        if(i==n-1){
            cout << endl;
        }
    }
    
}



Measured memory_bytes: 5052
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let a = i.read_vec::<usize>(n);
    writeln!(o, "{}", solve(&a)).unwrap();
}
fn solve(a: &[usize]) -> usize {
    let mut r = 0;
    for &a in a {
        let mut a = a;
        while a % 2 == 0 {
            a /= 2;
            r += 1;
        }
    }
    r
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    string ans;
    while(n > 0) {
        n--;
        ans.push_back('a' + (n % 26));
        n /= 26;
    }
    reverse(all(ans));
    cout << ans << en;
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> L(N);
  for(int i=0;i<N;i++) std::cin >> L[i];
  sort(L.begin(), L.end());
  (L[N - 1] >= accumulate(L.begin(), L.end() - 1, 0)) ? std::cout << "No" << '\n':std::cout << "Yes" << '\n';;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ll N, Y;
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> Y;
  for(ll i = 0; i <= N; ++i) {
    for(ll j = 0; j <= N && i + j <= N; ++j) {
      ll k = N - i - j;
      ll r = i * 10000 + j * 5000 + k * 1000;
      if (r == Y) {
        cout << i << ' ' << j << ' ' << k;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1";
  return 0;
}

Measured memory_bytes: 256
/*Author : Prokash
           JU CSE 48
           CF: epiprokash
           UVa: epiprokash
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    if((a+b+c)>=22)
    {
        cout<<"bust"<<endl;
    }
    else
    {
        cout<<"win"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	int maxx = 0, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; ++ i) {
		cin >> m;
		if (m >= maxx) {
			maxx = m;
			++ ans;
		}
	}
	printf("%d\n", ans);
	return 0;
} 

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

s = b[a[0]-1]

for i in range(1,n):
    if a[i]-a[i-1] == 1:
        s += b[a[i]-1]+c[a[i-1]-1]
    else:
        s += b[a[i]-1]

print(s)

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

signed main(void){

  int n=0,s=0,w=0,e=0;
  string S;
  cin >> S;
  REP(i,(int)S.size()){
    if(S[i] == 'N') n++;
    if(S[i] == 'S') s++;
    if(S[i] == 'W') w++;
    if(S[i] == 'E') e++;
  }
  bool nsok = false;
  bool ewok = false;
  if(n>0||s>0)
    if(n>0&&s>0)
      nsok = true;
  if(n==0&&s==0)nsok = true;
  if(e>0||w>0)
    if(e>0&&w>0)
      ewok = true;
  if(e==0&&w==0)ewok = true;

  if(nsok&&ewok)cout << "Yes" << endl; 
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
  int64_t n, x;
  cin >> n >> x;
  
  vector<int64_t> a(n);
  for (auto&& aa : a) {
    cin >> aa;
  }
  
  int64_t ans = 0;
  for (auto i : irange(1L, n)) {
    if (a[i - 1] + a[i] > x) {
      auto tmp = min(a[i], a[i - 1] + a[i] - x);
      ans += tmp;
      a[i] -= tmp;
      if (a[i - 1] > x) {
        ans += a[i - 1] - x;
        a[i - 1] = x;
      }
    }
  }
  
  cout << ans << endl;  
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int V,E,ans;
ll edge[64];
ll sum_edge[64];
void MDS(int cur,int cost,ll mask){
	if(cost>=ans)return;
	if(mask==(1LL<<V)-1){
		ans=cost;
		return;
	}
	if(cur>=V)return;
	if((mask|sum_edge[cur])!=(1LL<<V)-1)return;
	MDS(cur+1,cost+1,mask|edge[cur]);
	MDS(cur+1,cost,mask);
}
int main(){
	while(cin>>V>>E,V){
		for(int i=0;i<V;i++)edge[i]=(1LL<<i);
		for(int i=0;i<E;i++){
			int A,B;
			cin>>A>>B;
			edge[A]|=(1LL<<B);
			edge[B]|=(1LL<<A);
		}
		for(int i=V-1;i>=0;i--) sum_edge[i] = edge[i];
		for(int i=V-2;i>=0;i--) sum_edge[i] |= sum_edge[i+1];
		ans=1e9;
		MDS(0,0,0);
		cout<<ans<<endl;
	}
}


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

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

int H, W;
vector<string> s(400);
vector<vector<bool>> v(400, vector<bool>(400));

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

void bfs(int x, int y, ll& BLACK, ll& WHITE) {
    queue<P> que;
    que.push(P(x, y));
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        if (s[p.first][p.second] == '#') {
            BLACK++;
        } else {
            WHITE++;
        }
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < H && 0 <= ny && ny < W && !v[nx][ny] &&
                s[p.first][p.second] != s[nx][ny]) {
                que.push(P(nx, ny));
                v[nx][ny] = true;
            }
        }
    }
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }
    ll ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (!v[i][j]) {
                ll BLACK = 0, WHITE = 0;
                v[i][j] = true;
                bfs(i, j, BLACK, WHITE);
                ans += BLACK * WHITE;
            }
        }
    }
    cout << ans << endl;
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
 
const ll MAX = 1e6 + 3;
const ll inf = 1e18;
const ll mod = 1e6 + 3;



int main(){
    fastio;
    ll n;
    string s;
    cin >> n >> s;
    if(n&1) cout << "No\n";
    else{
        string aux = s.substr(0,n/2);
        if(s == aux+aux) cout << "Yes\n";
        else cout << "No\n";
    }

    return 0;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  ll lcm__ = 1;
  rep(i, n){
    lcm__ = lcm(lcm__, a[i]);
  }

  ll tmp = 0;
  rep(i, n){
    tmp += lcm__ / a[i];
  }

  cout << fixed << setprecision(10) << (double)lcm__ / (double)tmp << endl;
	return 0;
}



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

using namespace std;

int main() {
	long long n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	if (c + d == 0) puts(a == b ? "YES" : "NO");
	else puts(max(0LL, (c * (n - 1) - b + a + c + d - 1)/(c + d)) <= min(n - 1, (d * (n - 1) - b + a)/(c + d)) ? "YES" : "NO");
	return 0;
}



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

int main() {
    //
    string str;
    long long num;
    long long sum = 0;

    cin >> num;
    str = to_string(num);
    for (int i = 0; i < str.size(); i++) {
        sum += str.at(i) - '0';
    }

    if(num % sum == 0) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long> v(N);
  for (int i=0; i<N; i++) cin >> v[i];

  sort(v.begin(), v.end());
  if (N==2) {
    cout << v[1] << " " << v[0] << endl;
    return 0;
  }

  int half = v[N-1]/2;
  int lc = lower_bound(v.begin(), v.end()-1, half) - v.begin();

  if (abs(((double)v[N-1]/2) - v[lc]) > abs(((double)v[N-1]/2) - v[lc-1]))
    lc = lc - 1;

  cout << v[N-1] << " " << v[lc] << endl;
}



Measured memory_bytes: 1656
L=int(input());S=bin(L);N=len(S)-2;print(N,2*N+S.count("1")-3)
for i in range(1,N):
 for j in[0,1]:print(i,i+1,j*2**(i-1))
 if int(S[-i]):L^=2**(i-1);print(i,N,L)

Measured memory_bytes: 3060
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    string str;
    cin >> str;
    int k;
    int last = 0;
    int a[2020] = {0};
    a[0] = 1;
    ll ans = 0;
    int l = 1;
    for (int i = (int) str.size() - 1;i >= 0;i --) {
        k = str[i] ^ 48;
        last = (last + k * l) % 2019;
        l = (l * 10) % 2019;
        ans += a[last] ++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3388
#include<cstdio>
#include<algorithm>

using namespace std;
int n,w,d,cnt;
int p[101],s[101];
int pw[201],pd[201];
int sq[101];

int main(void){
	while(1){
		scanf("%d %d %d",&n,&w,&d);
		if(n+w+d==0)break;
		cnt=1;
		for(int i=0;i<n;i++){
			scanf("%d %d",&p[i],&s[i]);
			p[i]--;
		}

		pw[0]=w,pd[0]=d;
		for(int i=0;i<n;i++){
			int j=0;
			while(1){
				if(j%2==0){
					if(s[i]-pw[p[i]]>=0)s[i]-=pw[p[i]];
					else break;
				}else{
					if(s[i]-pd[p[i]]>=0)s[i]-=pd[p[i]];
					else break;
				}
				j=(j+1)%4;
			}
			if(j==0){
				pd[cnt]=pd[cnt+1]=pd[p[i]];
				pw[cnt]=s[i];
				pw[cnt+1]=pw[p[i]]-s[i];
			}
			if(j==1){
				pw[cnt]=pw[cnt+1]=pw[p[i]];
				pd[cnt]=s[i];
				pd[cnt+1]=pd[p[i]]-s[i];
			}
			if(j==2){
				pd[cnt]=pd[cnt+1]=pd[p[i]];
				pw[cnt]=pw[p[i]]-s[i];
				pw[cnt+1]=s[i];
			}
			if(j==3){
				pw[cnt]=pw[cnt+1]=pw[p[i]];
				pd[cnt]=pd[p[i]]-s[i];
				pd[cnt+1]=s[i];
			}
			if(pw[cnt]*pd[cnt]>pw[cnt+1]*pd[cnt+1])swap(pw[cnt],pw[cnt+1]),swap(pd[cnt],pd[cnt+1]);
			for(int j=p[i];j<=cnt;j++){
				pd[j]=pd[j+1];
				pw[j]=pw[j+1];
			}
			cnt++;
		}
		for(int i=0;i<cnt;i++)sq[i]=pd[i]*pw[i];
		sort(sq,sq+cnt);
		for(int i=0;i<cnt;i++)printf("%d%c",sq[i],i==cnt-1?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 1044
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)170 * 80;



int main(void) {
   ll N;
   cin>>N;
   vector<ll> A(N);
   rep(i,0,N) cin>>A[i];
   ll ans = 0;
   ll min = (ll)1e9+100;
   ll now = 0;
   rep(i,0,N) {
      ans += abs(A[i]);
      if (abs(min)> abs(A[i])) min = A[i];
      if (A[i]<0) now++;
   }
   if (now%2==0) cout<<ans<<endl;
   else cout<<ans-abs(min)*2<<endl;
   
   return 0;
}

Measured memory_bytes: 1024
import sys
N = int(input())
a = 1
b = 1
if (N == 1)or(N == 81):
    print("Yes")
elif (2 <= N <= 80):
    for a in range(1,10):
        for b in range(1,10):
            if N == a*b:
                print("Yes")
                sys.exit()
            else:
                None
    print("No")
    sys.exit()
elif 82 <= N:
    print("No")

Measured memory_bytes: 3064
// One Card Poker
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a==1) a=14;
    if(b==1) b=14;
    if(a>b) cout<<"Alice\n";
    if(a==b) cout<<"Draw\n";
    if(a<b) cout<<"Bob\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int MAXV = 1e5 + 5;
void marmot0814() {
    int n, m; cin >> n >> m;
    vector<vector<int>> G(n), revG(n);
    vector<int> deg(n);
    while (m--) {
        int u, v; cin >> u >> v; u--, v--;
        G[u].push_back(v);
        revG[v].push_back(u);
        deg[v]++;
    }
    queue<int> q;
    vector<int> dp(n, -1);
    for (int i = 0 ; i < n ; i++) {
        if (deg[i])
            continue;
        q.push(i);
    }
    while (q.size()) {
        int p = q.front(), maxV = 0; q.pop();
        for (auto &v : revG[p])
            maxV = max(maxV, dp[v]);
        dp[p] = maxV + 1;
        for (auto &v : G[p]) {
            deg[v]--;
            if (deg[v])
                continue;
            q.push(v);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) - 1 << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}

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

int main() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  int dist[n+1];
  for (int i=0; i<n; i++)
    dist[i] = INT_MAX;
  dist[n] = 0;
  int MostLeft[n+1];
  MostLeft[0] = n;
  int next = n-1;
  int left = n;
  int cnt = 0;
  while(true) {
    cnt++;
    int newLeft = left;
    while(next >= left - m && next >= 0) {
      if(s[next] == '0') {
        dist[next] = cnt;
        newLeft = next;
      }
      next--;
    }
    if(newLeft == left) {
      cout << -1 << endl;
      return 0;
    }
    left = newLeft;
    MostLeft[cnt] = left;
    if(next < 0) break;
  }
  cnt = dist[0];
  vector<int> ans;
  int now = 0;
  while(cnt >= 1) {
      cnt--;
      ans.push_back(MostLeft[cnt] - now);
      now = MostLeft[cnt];
  }
  for(int i = 0; i < ans.size(); i++)
      cout << ans[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
int n;
const int max_n = 1000;
int c[max_n],s[max_n],f[max_n];
int ans[max_n];
void solve(){
  int ss = 0;
while(ss<=n-2){
  int pos = 0;
  for(int i=ss ; i<n-1 ; i++){
    if(s[i]>pos){
      pos += s[i] - pos;
    }else{
      int k = s[i];
      while(pos>k){
        k += f[i];
      }
      pos += k - pos;
    }
    pos += c[i];
  }
  ans[ss] = pos;
  ss++;
}
  for(int i=0 ; i<n ; i++){
    cout << ans[i] << endl;
  }
}

int main(){
  cin >> n;
  for(int i=0 ; i<n-1 ; i++){
    cin >> c[i] >> s[i] >> f[i];
  }
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
int n,i;
  int t=0;
  scanf("%d", &n);
  i=n/100;
  if(i==7){
  t++;
  }
  n=n-(i*100);
  i=n/10;
  if(i==7){
  t++;
  }
  n=n-(10*i);
  if(n==7){
  t++;
  }
  if(t==0){
  printf("No\n");
  }
  else{
  printf("Yes\n");
  }
  return 0;
}

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

using namespace std;
int v[109];int w[109];int n,we;long long int dp[109][100009];

long long int fun(int i , int wet)
{
	if(i>=n)
	return(0);
	if(dp[i][wet]!=-1)
	return(dp[i][wet]);
	if(wet<w[i])
	return(dp[i][wet]=fun(i+1,wet));
	else
	return(dp[i][wet]= max(fun(i+1,wet), v[i]+fun(i+1,wet-w[i])));
}

int main()
{
 cin>>n>>we; 
 for(int i = 0 ; i<n; i++)
 {
 	scanf("%i%i",&w[i],&v[i]);
 }
 memset(dp,-1,sizeof(dp));
cout<<fun(0,we);

return(0);
}


Measured memory_bytes: 85376
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)

//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> calc(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
string S, T;
int A, B;
string U;
int main()
{
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;
	if (U == S) {
		A--;
	}
	else {
		B--;
	}
	cout << A << " " << B << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n,int prime[]){
	for(int i=1;i<=n;i++){
		prime[i]=i;
	}
	for(int p=2;p*p<=n;p++){
		if(prime[p]==p){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=min(prime[i],p);
		}
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int z=1000002;
		int prime[z+1];
		sieve(z,prime);
		set<int> marked;
		int n;
		cin>>n;
		int a[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		int gcd=a[0];
		for(int i=0;i<n;i++)
			gcd=__gcd(gcd,a[i]);
		if(gcd!=1){
			cout<<"not coprime";
			return 0;
		}
		bool flag=true;
		for(int i=0;i<n;i++){
			while(1){
				if(a[i]==1)
					break;
				int minPrime=prime[a[i]];
				while(a[i]%minPrime==0)
					a[i]/=minPrime;
				if(marked.count(minPrime))
				{
					flag=false;
					break;
				}
				marked.insert(minPrime);
			}
			if(flag==false)
				break;
		}
		if(flag)
			cout<<"pairwise coprime";
		else
			cout<<"setwise coprime";
	}
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  long long a[n];
  for(int i=0;i<n;i++){
    long long k;
    cin>>k;
    a[i]=k;
  }
  bool t=true;
  long long ans=0;
  for(int i=0;i<n;i++){
    if(i==0){
      if(a[0]!=0)t=false;
    }
    else{
      if(a[i]==a[i-1]+1)ans++;
      else if(a[i]<=a[i-1])ans+=a[i];
      else t=false;
    }
    if(!t)break;
  }
  if(!t)cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <cmath>
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<pair<double, double> > p;
  for(int i=0;i<N;i++){
    double x, y;
    cin >> x >> y;
    p.emplace_back(make_pair(x,y));
  }
  sort(p.begin(), p.end());
  
  vector<int> v(N);
  for(int i=0;i<N;i++) v[i] = i;
  double ans = 0;
  do{
    double dis = 0;
    for(int i=1;i<p.size();i++){
      int b = v[i-1], n = v[i];
      double x = p[b].first -  p[n].first;
      double y = p[b].second - p[n].second;
      dis += sqrt(x*x + y*y);
    }
    ans += dis;
  }while(next_permutation(v.begin(), v.end()));

  double div = 1;
  for(int i=1;i<=N;i++)div *= i;
  
  printf("%.7f\n", ans / div);
  return 0;
}

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

int main() {
  char S;
  cin >> S;
  if (S == 'a' || S == 'e' || S == 'i' || S == 'o' || S == 'u' ){
  cout << "vowel" << endl;
  }
  else {
  cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


struct mint {
	int x;
	mint(int x = 0) :x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD)x -= MOD;
		return *this;
	}
	mint & operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a)const {
		return mint(*this) += a;
	}
	mint operator-(const mint a)const {
		return mint(*this) -= a;
	}
	mint operator*(const mint a)const {
		return mint(*this) *= a;
	}
	mint pow(int t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	//for prime mod
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a)const {
		mint res(*this);
		return res /= a;
	}
};


signed main() {
	int N;
	cin >> N;
	map<int, int>m;
	rep(i, N) {
		int A;
		cin >> A;
		m[A]++;
	}
	bool can = true;
	if (N & 1) {
		if (m[0] != 1)can = false;
		for (int i = 2; i <= N - 1; i += 2)if (m[i] != 2)can = false;
	}
	else {
		for (int i = 1; i <= N - 1; i += 2)if (m[i] != 2)can = false;
	}
	if (!can)cout << 0 << endl;
	else {
		mint ans = 2;
		int n = N / 2;
		ans = ans.pow(n);
		cout << ans.x << endl;
	}
}

Measured memory_bytes: 5376
N=gets.to_i;A=gets.split.map &:to_i;D=[*0..10**6];s=0;2.upto(N-2){|i|s+=A[i];1.upto(A[i]){|j|D.unshift D[j*2-1]}};gets.to_i.times{p (D[x=gets.to_i]||x-s)+A[0]-A[1]}

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

typedef long long ll;
ll tmp;

class DisjointSet{
  public:
    vector<int> num, p;

    DisjointSet(){}
    DisjointSet(int size){
        num.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x){
        p[x] = x;
        num[x] = 1;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(x == y)  return;
        p[y] = x;
        tmp -= (ll)(num[x])*num[y];
        num[x] += num[y];
    }

    int findSet(int x){
        if(x != p[x]){
            // path compression
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n, m;
    cin >> n >> m;

    DisjointSet uf(n);

    int a, b;
    vector<pair<int,int>> v;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--, b--;
        v.push_back({a,b});
    }

    vector<ll> ans(m, 0);
    tmp = (ll)n*(n-1)/2;
    reverse(v.begin(), v.end());

    for(int i = 0; i < m; i++){
        ans[m-1-i] = tmp;
        if(i != m-1){
            uf.unite(v[i].first, v[i].second);
        }
    }

    for(int i = 0; i < m; i++)  cout << ans[i] << endl;
    
    return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int x;
    cin >> x;
    if (x >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3632
S = input()

if S[0] != 'A':
    print('WA')
    exit()

if S[1].isupper() or S[-1].isupper():
    print('WA')
    exit()

C = False
for s in S[2:-1]:
    if s == 'C':
        if not C:
            C = True
            continue
        else:
            print('WA')
            exit()

    if s.isupper():
        print('WA')
        exit()

if C:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3064
from collections import Counter


def main(N=None, S=None):
    if not N or not S:
        N = int(input())
        S = input()
    c = Counter(S)
    ans = c["R"]*c["G"]*c["B"]
    for hop in range(1, N):
        for start in range(N):
            i = start
            j = start + hop
            k = start + hop*2
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans -= 1
            # print(i, j, k, ans)
    print(ans)
    return ans


if __name__ == "__main__":
    # assert main(4, "RRGB") == 1
    # assert main(39, "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB") == 1800
    main()


Measured memory_bytes: 9472
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define INF (1 << 29)
int main(){
  char chair[105];
  int n, m;
  char c;
  while(cin >> n >> m, n){
    fill(chair, chair + n, '#');
    chair[n] = 0;
    for(int i = 0;i < m;i++){
      cin >> c;
      switch(c){
      case 'A':
      left :
	for(int j = 0;j < n;j++){
	  if(chair[j] == '#'){
	    chair[j] = c;
	    break;
	  }
	}
	break;
      case 'B':
	for(int j = n - 1;j >= 0;j--){
	  if((j == 0 || chair[j - 1] != 'A') && chair[j + 1] != 'A' && chair[j] == '#'){
	    chair[j] = c;
	    break;
	  }
	  if(j == 0)goto left;
	}
	break;
      case 'C':
	for(int j = 0;j < n;j++){
	  if(chair[j] != '#'){
	    if(chair[j + 1] == '#'){
	      chair[j + 1] = c;
	      break;
	    }
	    if(j != 0 && chair[j - 1] == '#'){
	      chair[j - 1] = c;
	      break;
	    }
	  }
	  if(j == n - 1){
	    chair[n / 2] = c;
	  }
	}
	break;
      case 'D':
	int p = 0, s = -1;
	for(int j = 0;j < n;j++){
	  if(chair[j] != '#')continue;
	  int t = INF;
	  for(int k = j;k < n;k++){
	    if(chair[k] != '#'){
	      t = k - j;
	      break;
	    }
	  }
	  for(int k = j;k >= 0;k--){
	    if(chair[k] != '#'){
	      t = min(t, j - k);
	      break;
	    }
	  }
	  if(t > s){
	    p = j;
	    s = t;
	  }
	}
	if(p == INF){
	  chair[n - 1] = c;
	}
	else{
	  chair[p] = c;
	}
	break;
      }
    }
    printf("%s\n", chair);
  }
  return 0;
}

Measured memory_bytes: 1124
#include<bits/stdc++.h>
using namespace std;
int n;
vector<long long>a;
vector<long long>pref;
long long mem[401][401];
long long dp(int i,int j)
{
        if(i==j)
            return 0;
        if(mem[i][j]!=-1)
        return mem[i][j];
        mem[i][j]=100000000000000;
        for(int k=i;k<j;k++)
        mem[i][j]=min(mem[i][j],dp(i,k)+dp(k+1,j)+pref[j]-pref[i]+a[i]);
        return mem[i][j];
}
int main()
{
    memset(mem,-1,sizeof(mem));
    cin>>n;
    a.resize(n);
    pref.resize(n);
    int i;
    cin>>a[0];
    pref[0]=a[0];
    for(i=1;i<n;i++)
    {
        cin>>a[i];
        pref[i]=pref[i-1]+a[i];
    }
    cout<<dp(0,n-1);
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <complex>
#include <regex>
#include <random>
using namespace std;

#define rep(i,n)	for(lint i = 0; i < n; i++)
#define repr(i,n)	for(lint i = n - 1; i >= 0; i--)
#define repi(i,ini,n)	for(lint i = ini; i < n; i++)
#define repir(i,ini,n)	for(lint i = n-1; i >= ini; i--)
#define repb(i,start,end)	for(lint i = start; i <= end; i++)
#define repbr(i,start,end)	for(lint i = end; i >= start; i--)

#define bit(n)				(1LL << (n))

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rg(v, ini, end) v.begin() + ini, v.begin()+end

#define ret return 0;
#define chmax(a, b) a=mmax(a,b)
#define chmin(a, b) a=mmin(a,b)

using lint = long long;
using ulint = unsigned long long;
using ld = long double;
struct xy
{
	lint x, y;
	xy() :x(0), y(0) {}
	xy(lint _x, lint _y) : x(_x), y(_y) {}
	xy operator+(const xy& p) const
	{
		return xy(x + p.x, y + p.y);
	}
	bool operator<(xy p) const
	{
		if (y == p.y)
			return x < p.x;
		return y < p.y;
	}
};
struct xyd
{
	ld x, y;
	xyd() :x(0), y(0) {}
	xyd(long double _x, long double _y) : x(_x), y(_y) {}
};
using vec = vector<lint>;
using vecd = vector<ld>;
using vecs = vector<string>;
using vecp = vector<xy>;
template<class T> using vect = vector<T>;
class vec2 : public vector<vector<lint>>
{
public:
	vec2() {}
	vec2(lint n) : vector(n) {}
	vec2(lint h, lint w) : vector(h, vector<lint>(w)) {}
	vec2(lint h, lint w, lint v) : vector(h, vector<lint>(w, v)) {}
};

template<class T> using priq = priority_queue<T>;
template<class T> using rpriq = priority_queue<T, vector<T>, greater<T>>;
template<class Key, class Val> using hashmap = unordered_map<Key, Val>;
template<class Key> using hashset = unordered_set<Key>;

mt19937 mtrand((random_device())());

const double pi = 3.141592653589793238462;
const lint intmax = 9223372036854775807;
const lint inf = 1100100100100100100LL;

constexpr lint div2(lint p, lint q)
{
	return (p + q - 1) / q;
}

#if(__cplusplus < 201703L)

	lint gcd(lint a, lint b) {
		while (1) {
			if (a < b) swap(a, b);
			if (!b) break;
			a %= b;
		}
		return a;
	}

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

#endif

template<class T>
struct nval {
	lint n;		// counts
	T val;
	nval() : n(0) {};
	nval(lint _n, T _val) : n(_n), val(_val) {};
};

template<class It, class It2>
auto spacel(It i, It2 end)
{
	if (i + 1 == end)
	{
		return '\n';
	}
	else
	{
		return ' ';
	}
}

ostream& setp(ostream& ost)
{
	cout << setprecision(60) << fixed;
	return ost;
}

const ulint mod = 1000000007;
//const ulint mod = 998244353;
const ld eps = 0.0000001;


int main()
{
	while (1)
	{
		lint x, y;
		cin >> x >> y;
		if (x == 0 && y == 0)
			break;

		cout << min(x, y) << ' ' << max(x, y) << endl;
	}
	return 0;
}



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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n;
ll x;
ll a[2001];
ll cost[2001][2001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  //stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  //if (stream2 == NULL) return 0;:w
#endif
  cin >> n >> x;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cost[i][j] = LLONG_MAX;
    }
  }
  for (int i = 0; i < n; i++) {
    cost[i][0] = a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n; j++) {
      cost[i][j] = min(cost[i][j - 1], a[(i - j + n) % n]);
    }
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < n; j++) {
  //     cout << cost[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  for (int i = 0; i < n; i++) {
    ll res = i * x;
    for (int j = 0; j < n; j++) {
      res += cost[j][i];
    }
    ans = min(ans, res);
  }
  if (ans <= 0) assert(1);
  cout << ans << endl;
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}

Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(), A.end());

    int maxn = A[N-1]+5;
    vector<int> memo(maxn,0);
    int cnt=0;
    rep(i,N){
    	int num = A[i];
    	if(memo[num]==0){
    		cnt++;
	    	for(int i = num+num; i < maxn; i+=num){
	    		memo[i] = 1;
	    	}
	    }
    }

    vector<int> vec(maxn,0);
  	rep(i,N) vec[A[i]]++;
    //rep(i,maxn) cout << i << ":" << vec[i] << " "; cout << endl;
    rep(i,maxn) if(vec[i]>1 && memo[i]==0) cnt-=vec[i];

    cout << cnt << endl;
}

Measured memory_bytes: 11764
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    string S;
    cin >> S;

    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

typedef long long ll;
const ll MOD = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= MOD;
	if(k%2 == 1){
		ret *= x;
		ret %= MOD;
	}
	return ret;
}

int main(){
	static ll n;
	static ll x[100010];
	scanf("%lld",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%lld",&x[i]);
	}
	
	ll ret = 0;
	ll sum = MOD-1;
	ll t = modpow(2,MOD-2);
	for(int i = 0 ; i < n-1 ; i ++){
		ret += sum*x[i];
		ret %= MOD;
		if(i > 0){
			t *= i; t %= MOD;
			t *= modpow(i+2,MOD-2); t %= MOD;
		}
		sum += t; if(sum >= MOD)sum -= MOD;
		ll y = modpow(n-1-i,MOD-2);
		y *= x[n-1];
		y %= MOD;
		ret += y;
		if(ret >= MOD)ret -= MOD;
	}
	for(int i = 1 ; i < n ; i ++){
		ret *= i;
		ret %= MOD;
	}
	cout << ret << endl;
}


Measured memory_bytes: 1024