akhauriyash/Code-Regression huggingface dataset:
// AOJ ALDS1_13_C 15 Puzzle
// 2018.5.8 bal4u

#include <stdio.h>

typedef unsigned long long ull;

#define QMAX 100000
typedef struct { ull s; char x, v; char t; } QUE;  // t:ステップ数
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r;
	int min;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		QUE t = que[i]; que[i] = que[min]; que[min] = t;
		min_heapify(min);
	}
}

void deq()
{
  que[0] = que[--qsize];
  min_heapify(0);
}

void enq(ull s, int x, int v, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].x = x, que[i].v = v, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i]; que[i] = que[min]; que[min] = qt;
		i = min;
	}
}

#define HASHSIZ 700057
typedef struct { ull s; char v; } HASH;
HASH hash [HASHSIZ+3], *hashend  = hash +HASHSIZ;

int lookup(ull s)
{
	HASH *hp = hash + (int)(s % HASHSIZ);
	while (hp->s) {
		if (hp->s == s) return hp->v;
		if (++hp == hashend) hp = hash;
	}
	return -1;
}


void insert(ull s, char v)
{
	HASH *hp = hash + (int)(s % HASHSIZ);
	while (hp->s) {
		if (hp->s == s) { hp->v = v; break; }
		if (++hp == hashend) hp = hash;
	}
	hp->s = s, hp->v = v;
}

#define GOAL 0x123456789ABCDEF0LL
#define ABS(a) ((a)>=0?(a):-(a))

int hi[16] = {2,3,3,2,3,4,4,3,3,4,4,3,2,3,3,2};
int to[16][4] = {
{1,4},{0,2,5},{1,3,6},{2,7},
{0,5,8},{1,4,6,9},{2,5,7,10},{3,6,11},
{4,9,12},{5,8,10,13},{6,9,11,14},{7,10,15},
{8,13},{9,12,14},{10,13,15},{11,14}};
double magic = 1;

void toArray(char *p16, ull s)
{
	int i;
	
	for (i = 15; i >= 0; i--) {
		p16[i] = s & 0xf, s >>= 4;
	}
}

ull swap(char *p16, int zero, int nx)
{
	int i;
	ull res;
	
	res = 0;
	for (i = 0; i < 16; i++) {
		res <<= 4;
		if      (i == zero) res |= p16[nx];
		else if (i == nx)   res |= p16[zero];
		else                res |= p16[i];
	}
	return res;
}

int eval(ull s)
{
	int i, r1, c1, r2, c2;
	int e, t;

	e = 0;
	for (i = 15; i >= 0; i--) {
		t = s & 0xf, s >>= 4;
		if (t) {
			t--;
			r1 = i >> 2, c1 = i & 3;
			r2 = t >> 2, c2 = t & 3;
			e += ABS(r1-r2) + ABS(c1-c2);
		}
	}
	return (int)(e*magic);

}

int main()
{
	int i, x, nx, v, nv, t;
	ull s, ns;
	char p16[16];

	s = 0; for (i = 0; i < 16; i++) {
		scanf("%d", &t);
		p16[i] = t, s <<= 4, s |= t;
		if (t == 0) x = i;
	}
	qsize = 0;
	t = eval(s);
	if      (t <= 22) magic = 1.1;
	else if (t <= 25) magic = 1.15;
	else              magic = 1.25;

	enq(s, x, 0, (int)(t*magic));

	insert(s, 0);
	while (qsize) {
		s = que[0].s, x = que[0].x, v = que[0].v, deq();
		if (s == GOAL) break;
		if (lookup(s) < v) continue;

		toArray(p16, s);
		for (i = 0; i < hi[x]; i++) {
			nx = to[x][i];
			ns = swap(p16, x, nx), nv = v+1;
			t = lookup(ns);
			if (t < 1 || nv < t) {
				enq(ns, nx, nv, eval(ns)+v);
				insert(ns,  nv);
			}
		}
	}
	printf("%d\n", v);
	return 0;
}



Measured memory_bytes: 14076
#include<stdio.h>
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long f(long n,long long a,long long b){
  return n-n/a-n/b+n/lcm(a,b);
}
int main(){
  long long a,b,c,d;
  scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
  printf("%lld\n",f(b,c,d)-f(a-1,c,d));
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

size_t ldistance(string s, string t) {
    /* Levenshtein Distance */
    size_t slen=s.length(), tlen=t.length();
    vector<vector<size_t>> dp(slen+1, vector<size_t>(tlen+1));

    for (size_t i=0; i<=slen; ++i)
        dp[i][0] = i;

    for (size_t j=0; j<=tlen; ++j)
        dp[0][j] = j;

    for (size_t i=1; i<=slen; ++i)
        for (size_t j=1; j<=tlen; ++j) {
            size_t cost=(s[i-1]!=t[j-1]);
            dp[i][j] = min(min(dp[i-1][j], dp[i][j-1])+1, dp[i-1][j-1]+cost);
        }

    return dp[slen][tlen];
}

int main() {
    char buf[1024];
    scanf("%s", buf);
    string s1(buf);

    scanf("%s", buf);
    string s2(buf);

    printf("%zu\n", ldistance(s1, s2));
    return 0;
}

Measured memory_bytes: 10364
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;

int gcd(int a,int b){
    if(b==0)return a;
    else return gcd(b,a%b);
}

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
    }
    vector<int>l(n),r(n);
    
    rep(i,n-1)l[i+1]=gcd(l[i],a[i]);
    for(int i=n-2;i>=0;i--)r[i]=gcd(r[i+1],a[i+1]);
    int ans=0;
    rep(i,n)ans=max(ans,gcd(l[i],r[i]));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;






int main(void) {
    ll N;
    string A, B, C;
    cin >>N>>A>>B>>C;
    ll ans=0;
    for(ll i=0; i<N; i++) {
        if(A[i]==B[i]&&B[i]==C[i]);
        else if(A[i]==B[i]) ans++;
        else if(B[i]==C[i]) ans++;
        else if(C[i]==A[i]) ans++;
        else ans+=2;
    }
    
    pt(ans);
    
    
}

























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int h, m, h2, m2, k, sum1, sum2;
 cin >> h >> m >> h2 >> m2 >> k;
 if (h <= h2)
 {
  sum1 = (h * 60) + m;
  sum2 = (h2 * 60) + m2;
  cout << sum2 - sum1 - k;
 }
 else
 {
  sum1 = (h * 60) + m;
  sum2 = (h2 * 60) + m2;
  cout<<1440-(sum1+sum2-k);
 }
  
 return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int N;
	while(cin>>N,N){
		int ans=0,sum;
		REP(i,1,500){
			sum=i;
			REP(j,i+1,501){
				sum+=j;
				if(sum==N){
					ans++;
					break;
				}
				if(sum>N) break;
			}
		}
		p(ans);
	}
	return 0;
}

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

using namespace std;

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

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

	ll n, d, a;
	cin >> n >> d >> a;

	vector<pil> v(n);
	rep(i, n) cin >> v[i].first >> v[i].second;	
	sort(v.begin(), v.end());

	vector<int> x(n);
	rep(i, n) x[i] = v[i].first;
	sort(x.begin(), x.end());

	vector<ll> dmg(n+1, 0);
	ll ans = 0;
	for(int i = 0; i < n; i++){

		ll h = v[i].second;

		if(h > dmg[i]){

			ll bom = (h - dmg[i] + a - 1) / a * a;
			ans += (h - dmg[i] + a - 1) / a;

			auto itr = upper_bound(x.begin(), x.end(), x[i] + 2 * d);
			int r = distance(x.begin(), itr);
			dmg[i] += bom;
			dmg[r] -= bom;
		}

		dmg[i+1] += dmg[i];
	}

	cout << ans << endl;
}


Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main()
{
  int N, X;
  cin >> N >> X;
  int min_m = 1001;
  int ans = N;
  for (int i = 0; i < N; i++) {
    int m;
    cin >> m;
    if (m < min_m) min_m = m;
    X -= m;
  }
  ans += (X / min_m);
  cout << ans << endl;
  return 0;
}


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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int K ;
    cin >> K;
    int maxi ;
    int total= A + B + C;
    
    maxi = max(max(A,B),C);
    
    if(maxi == A){
        total -=A; 
    }else if(maxi == B){
        total -=B;
    }else if(maxi == C){
        total -=C;
    }

    for(int i = 0;i<K;i++){
        maxi = maxi * 2;
    }

    cout << total + maxi;

}

Measured memory_bytes: 256
#include <iostream>
#include <map>

int main(int argc, char const *argv[]) {
        long N;
        std::cin >> N;

        std::map<long,long> lucaTable;
        lucaTable[0] = 2;
        lucaTable[1] = 1;
        for(int i = 2 ; i <= N ; i++)
        {
            lucaTable[i] = lucaTable[i-2] + lucaTable[i-1];
        }
        std::cout << lucaTable[N] << '\n';

        return 0;
}

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

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int maxN = 6010;

int ptr[maxN];
string s, best[maxN];

inline void solve(int k, int L, int R)
{
	if(s[L] == 'a')
	{
		vector <int> va, vb;
		for (int i=L; i<R; i++)
			if(s[i] == 'a') va.pb(i);
			else vb.pb(i);

		int p = 0, len = (R - L)/2;
		while(p < len)
		{
			best[k] += "ab";
			int q = p;
			while(q < len && va[q] < vb[p]) q++;
			p = q;
		}
		return ;
	}else
	{
		for (int i=L/2; i<R/2; i++)
		{
			string curr = "";
			for (int j=L; j<R; j++)
				if(ptr[j] >= i) curr += s[j];
			best[k] = max(best[k], curr);
		}
		return ;
	}
}

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

	int n; cin >> n;
	cin >> s;

	for (int cnt1=0, cnt2=0, i=0; i<2*n; i++)
		if(s[i] == 'a') ptr[i] = cnt1 ++;
		else ptr[i] = cnt2 ++;

	int a = 0, b = 0, td = 0, L = 0;
	for (int i=0; i<2*n; i++)
	{
		if(s[i] == 'a') a++;
		else b++;

		if(a == b)
		{
			a = b = 0;
			solve(td, L, i + 1);
			td ++;
			L = i + 1;
		}
	}

	string ans = "";
	for (int i=td-1; i>=0; i--)
		ans = max(ans, best[i] + ans);
	cout << ans << endl;

}


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

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

	if (b - a <= 0) {
		cout << "delicious" << endl;
	}
	else if (b - a <= x) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<bool> dp;
vector<int> a;
int n, k;


int main(){
  
  cin >> n >> k;
  a.resize(n+1);
  rep(i, n) cin >> a[i+1];
  dp.resize(k+1);
  rep2(i, 1, k+1){
    rep2(j, 1, n+1) {
      if(i - a[j] >= 0 && dp[i-a[j]] == 0)dp[i] = 1;
    }
  }
  if(dp[k] == 0) cout << "Second" << endl;
  else cout << "First" << endl;
  
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

void warshallFloyd(vector<vector<int>>& path, int n) {
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				path[i][j] = min(path[i][j], path[i][k] + path[k][j]);
			}
		}
	}
}

int main() {

	int n, m, R;
	cin >> n >> m >> R;
	vector<int> r(R);
	rep(i, R) cin >> r[i];
	vector<vector<int>> path(n, vector<int>(n, inf));
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		path[a - 1][b - 1] = path[b - 1][a - 1] = c;
	}

	// ワーシャルフロイド
	// からの全探索 良い問題
	warshallFloyd(path, n);

	int ans = inf;

	// next_permutation
	sort(allof(r));
	do {
		int score = 0;
		rep(i, R - 1) {
			score += path[r[i] - 1][r[i + 1] - 1];
		}
		ans = min(ans, score);
	} while (next_permutation(allof(r)));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
k = gets.to_i
if k % 2 == 0 || k % 5 == 0
  puts -1
else
  cnt = 1
  n = 7
  k.times do
    break if n % k == 0
    n = (n * 10 + 7) % k
    cnt += 1
  end
  puts cnt
end

Measured memory_bytes: 14320
# AGC032 Problem-C
def special_case() :
    #Check 辺が4本出ているノードが2つあるケース
    #　　　2ノード間に4本の辺がある場合はNG
    #　　　2ノード間に2本の辺がある場合はOK (自分に戻るループがある)
    st = -1
    for i in range(0,n) :
        if check[i] == 4 :
            st = i
            break
    
    for i in edge[st] :
        p0 = st
        p1 = i
        while (check[p1]==2) :
            t1, t2 = edge[p1]
            if t1 == p0 :
                p0 = p1
                p1 = t2
            else: 
                p0 = p1
                p1 = t1
        if p1 == st :
            return 0
    return -1

n, m = map(int,input().split())

check = [0 for i in range(0,n)]
edge  = [[] for i in range(0,n)]
#table = [[0 for i in range (0,n)] for j in range (0,n)]
for i in range(0,m) :
    a, b = map(int,input().split())
    check[a-1] += 1
    check[b-1] += 1
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
#print (check)
#print(edge)

node4 = 0
node6 = 0
node_odd = 0
for i in range(0,n):
    if check[i] % 2 == 0:
        if check[i]==4 :
            node4 += 1
        if check[i]>=6 :
            node6 +=1
    else:
        node_odd += 1

if (node_odd != 0) :
    print ("No")
else :
    if ((node4 >= 3) or (node6 >=1)) :
        print ("Yes")
    elif (node4 == 2) :
        if special_case() == 0 :
            print ("Yes")
        else :
            print ("No")
    else :
        print ("No")


Measured memory_bytes: 21960
#include<bits/stdc++.h>
using namespace std;
vector<int> v;
int main()
{
	string s;
	int n,q,a,b;
	cin>>n>>q;
	cin>>s;
	for(int i=0;i<n-1;i++){
		if(s.substr(i,2)=="AC")v.push_back(i);
	}
	for(int i=0;i<q;i++){
		cin>>a>>b;
		a--;
		b--;
		int x=lower_bound(v.begin(),v.end(),b)-v.begin();
		int y=lower_bound(v.begin(),v.end(),a)-v.begin();
		cout<<x-y<<endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

inline int read() {
  int f = 1;
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f = (ch == '-') ? -1 : 1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}

const int N = 1e6 + 5;
const int P = 1e9 + 7;

inline int mul(int a, int b) {
  return (long long) a * b % P;
}
inline int sub(int a, int b) {
  return a - b < 0 ? a - b + P : a - b;
}
inline int add(int a, int b) {
  return a + b >= P ? a + b - P : a + b;
}
inline int modexp(int a, int x) {
  int ret = 1;
  while (x) {
    if (x & 1) {
      ret = mul(ret, a);
    }
    a = mul(a, a);
    x >>= 1;
  }
  return ret;
}

int n;
int fac[N];
int inv[N];

inline int calc(int m, int n) {
  int k = 2 * m - n;
  if (k >= 0 && m - k >= 0) {
    return mul(fac[m], mul(inv[k], inv[m - k]));
  } else {
    return 0;
  }
}

inline int C(int n, int m) {
  return mul(fac[n], mul(inv[m], inv[n - m]));
}

int main() {
  n = read();
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = mul(fac[i - 1], i);
  }
  inv[n] = modexp(fac[n], P - 2);
  for (int i = n - 1; i >= 0; --i) {
    inv[i] = mul(inv[i + 1], i + 1);
  }
  int ans = mul(fac[n - 1], n);
  for (int i = (n + 1) / 2; i < n; ++i) {
    ans = sub(ans, mul(fac[n - i - 1], mul(C(i - 1, n - i - 1), fac[i])));
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	int m = 0;
	for( auto c : s ){
		if( c == 'I' ) ++m;
		else --m;
		ans = max(m, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
using namespace std;

int main()	
{
	int a,b;
	cin >> a >> b;
	if(2*b>=a)	cout << 0 << endl;
	else cout << a-2*b << endl;
	return 0;
}

Measured memory_bytes: 3616
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);int h,b,i;for(String x;(x=s.next()).length()>1;System.out.println(h+" "+b)){char[]y=s.next().toCharArray();for(h=b=i=0;i<4;++i)if(x.charAt(i)==y[i])++h;else if(x.contains(""+y[i]))++b;}}}

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

dist = [0 for i in [0]*(n+1)]
idx = 1
d = 1
while not dist[idx] and d<k+1:
    dist[idx] = d
    idx = a[idx-1]
    d += 1
    #print(dist)
if d==k+1:
    print(idx)
else:
    rem = dist[idx] - 1
    cyc = d - dist[idx]
    k -= rem
    k %= cyc
    for i in range(k):
        idx = a[idx-1]
    print(idx)

Measured memory_bytes: 32368
#include<stdio.h>
 
int main(){
 
  int i,j,n,mini,si,a1[37],a2[37],count=1,f=0;
  char sc,c1[37],c2[37];
 
  //load N
  scanf("%d",&n);
 
  //load number
  for(i=1;i<=n;i++){
    scanf(" %c%d",&c1[i],&a1[i]);
    a2[i]=a1[i];
    c2[i]=c1[i];
  }
 
 
 
  //BubbleSort
  for(i=1;i<=n;i++){
    for(j=n;j>=i+1;j--){
      //swap
      if(a1[j]<a1[j-1]){
        si=a1[j];
        a1[j]=a1[j-1];
        a1[j-1]=si;
    sc=c1[j];
    c1[j]=c1[j-1];
    c1[j-1]=sc;
 
    }
    }
  }
  //print
  for(i=1;i<=n;i++){
    printf("%c%d",c1[i],a1[i]);
    if(i!=n){
      printf(" ");
    }
  }
    printf("\n");
 
    //stability
    printf("Stable\n");
 
  //SelectionSort
  for(i=1;i<=n;i++){
    mini=i;
    for(j=i;j<=n;j++){
      if(a2[j]<a2[mini]){
        mini=j;
      }
    }
      //swap
      si=a2[i];
      a2[i]=a2[mini];
      a2[mini]=si;
      sc=c2[i];
      c2[i]=c2[mini];
      c2[mini]=sc;
  }
 
 
  //print
  for(i=1;i<=n;i++){
    printf("%c%d",c2[i],a2[i]);
    if(i!=n){
      printf(" ");
    }
  }
  printf("\n");
 
  //stability
  f=0;
  for(i=1;i<=n;i++){
    if(c2[i]!=c1[i]){
      printf("Not stable\n");
      f=1;
      break;
    }
  }  
  if(f==0)printf("Stable\n");
   
   
   
 
  return 0;
 
}


Measured memory_bytes: 2104
#include<iostream>

using namespace std;

int ans[11][331];
int used[10];

void calc(int depth, int sum){
	if(depth==11)return;
	for(int i=0;i<10;i++){
		if(used[i]==0){
			ans[depth][sum+depth*i]++;
			used[i]=1;
			calc(depth+1,sum+depth*i);
			used[i]=0;
		}
	}
}

int main(){
	calc(1,0);
	int n,s;
	while(cin>>n>>s){
		if(s>330) cout<<0<<endl;
		else cout<<ans[n][s]<<endl;
	}
}

Measured memory_bytes: 1172
#include <iostream>

using namespace std;

int main() {
  long long X, K, D;
  cin >> X >> K >> D;
  
  X = abs(X);
  if (X / D > K) {
  	cout << X - K * D << endl;
  } else {
    K -= X / D;
    if (K % 2 == 0) cout << X % D << endl;
    else cout << abs(X % D - D) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
	int w, l, h;
	int n;
	int i;
	int x;
	
	while (1){
		scanf("%d %d %d", &w, &l, &h);
		if (w == 0 && l == 0 && h == 0){
			break;
		}
		
		if (w > h){
			w += h;
			h = w - h;
			w -= h;
		}
		if (l > h){
			l += h;
			h = h -l;
			l -= h;
		}
		if (w > l){
			w += l;
			l = w - l;
			w -= l;
		}
		scanf ("%d", &n);
		
		for (i = 0; i < n; i++){
			scanf("%d", &x);
			if (w * w + l * l < x * 4 * x ){
				printf("OK\n");
			}else {
				printf("NA\n");
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,l; cin >> n >> l;
	vi t(n);
	rep(i,n) t[i]=l+i;
	int mn_ptr;
	int mn=INF;
	rep(i,n){
		int now = abs(t[i]);
		if(now<mn){
			mn_ptr = i;
			mn = now;
		}
	}
	int ans = 0;
	rep(i,n){
		if(i==mn_ptr) continue;
		ans += t[i];
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n, q;
	vector<int> data(300001, 0);
	cin >> n >> q;
	int a;
	int MAX = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		MAX = max(MAX, a);
		data[a] = 1;
	}
	for (int i = 0; i < q; i++) {
		cin >> a;
		bool hantei = false;
		for (int j = a-1; j >= 0; j--) {
			for (int k = 0; a*k+j <= MAX; k++) {
				if (data[a*k+j] == 1) {
					cout << j << endl;
					hantei = true;
					break;
				}
			}
			if (hantei) {
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2328
M, K = map(int, input().split())

if K >= 2**M:
    anss = []
else:
    if M == 0:
        anss = [0,0]
    elif M == 1:
        if K == 0:
            anss = [0,0,1,1]
        else:
            anss = []
    else:
        Bs = [i for i in range(2**M) if i != K]
        anss = Bs+[K]+Bs[::-1]+[K]

if not anss:
    print(-1)
else:
    print(' '.join(map(str, anss)))


Measured memory_bytes: 28428
# standard library# {{{
import sys
import os
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
# }}}


def solve():
    N = int(input())

    S = [0]*5
    for s in range(N):
        s = input()
        if s[0] == 'M':
            S[0] += 1
        if s[0] == 'A':
            S[1] += 1
        if s[0] == 'R':
            S[2] += 1
        if s[0] == 'C':
            S[3] += 1
        if s[0] == 'H':
            S[4] += 1

    res = 0
    for c in itertools.combinations([0,1,2,3,4], 3):
        i,j,k = c
        res += S[i] * S[j] * S[k]

    print(res)

if __name__ == "__main__":
    solve()




Measured memory_bytes: 24524
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
function gcd(m, n) {
    if (m < n) [m, n] = [n, m]
    let r
    while (n > 0) {
        r = m % n
        m = n
        n = r
    }
    return m
}
const Main = () => {
    let n = nextInt()
    let a = nextIntArray()
    let ans = gcd(a[0], a[1])
    for(let i = 2; i<a.length; i++){
        ans = gcd(ans, a[i])
    }
    console.log(ans)
}
Main()



Measured memory_bytes: 40200
#include <stdio.h>
int solve(int,int);
int n,a[200];
int main(){
    int q,b[200],i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&b[i]);
    }
    
    for(i=0;i<q;i++){
        if(solve(0,b[i]) == 1){
            printf("yes\n");
        }
        else{
            printf("no\n");
        }
    }
}

int solve(int i,int m){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    return solve(i+1,m) || solve(i+1,m-a[i]);
}



Measured memory_bytes: 2048
// 0176
#include <iostream>
#include <string>
#define  N   255
using namespace std;

int c_table[8][3] = {{0,0,0}, {0,0,N}, {0,N,0}, {0,N,N}, {N,0,0}, {N,0,N}, {N,N,0}, {N,N,N}};

int conv_16(char c){
	if((c >= '0') && (c <= '9'))
		return c-'0';
	else if((c >= 'a') && (c <= 'f'))
		return c-'a'+10;
}

int dk(int co1[3], int co2[3]){
	int d = 0;

	for(int i=0;i<3;i++)
		d += (co1[i]-co2[i])*(co1[i]-co2[i]);

	return d;
}

int main(){
	while(1){
		string str;
		cin>>str;

		if(str == "0")
			break;

		int rgb[3], d=3*N*N, color=0;
		for(int i=0;i<3;i++)
			rgb[i] = 16*conv_16(str[2*i+1]) + conv_16(str[2*i+2]);
	
		
		for(int i=0;i<8;i++)
			if(d > dk(c_table[i], rgb)){
				d = dk(c_table[i], rgb);
				color = i;
			}

		if(color == 0)
			cout<<"black"<<endl;
		else if(color == 1)
			cout<<"blue"<<endl;
		else if(color == 2)
			cout<<"lime"<<endl;
		else if(color == 3)
			cout<<"aqua"<<endl;
		else if(color == 4)
			cout<<"red"<<endl;
		else if(color == 5)
			cout<<"fuchsia"<<endl;
		else if(color == 6)
			cout<<"yellow"<<endl;
		else if(color == 7)
			cout<<"white"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1184
n_even, n_odd = gets().chomp.split("\s").map{|x| x.to_i}

list = []
(1..n_even).each do |x|
  list.push(2)
end
(1..n_odd).each do |x|
  list.push(1)
end

cnt = 0
list.each_with_index do |l, i|
  list.each_with_index do |l2, i2|
    next if i >= i2
    cnt += 1 if (l + l2).even?
  end
end

puts cnt

Measured memory_bytes: 14268
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

a, c, ans = [0] * 3
for i in range(N):
    b = B[i]
    a = bisect.bisect_left(A, b, a, N)
    c = bisect.bisect_right(C, b, c, N)
    ans += a * (N-c)

print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

const int MAX = 14;

int n;
char buf[125];
string s[MAX];
string t[MAX];
bool alive[MAX];
// now, visited
string dp[MAX][1<<MAX];
int g[MAX][MAX];

int main(){
  while(true){
    scanf("%d",&n);
    if(!n)break;
    REP(i,n){
      scanf("%s",buf);
      s[i] = string(buf);
    }
    REP(i,n)alive[i]=true;
    REP(i,n)REP(j,n){
      if(j==i)continue;
      if(s[i].size() > s[j].size())continue;
      int x = s[i].size();
      int y = s[j].size();
      FOR(k,0,y-x+1){
        if(s[j].substr(k,x)==s[i]){
          alive[i] = false;
          break;
        }
      }
    }
    int it = 0;
    REP(i,n)if(alive[i])t[it++]=s[i];
    n = it;
    REP(i,n)s[i]=t[i];
    REP(i,n)REP(j,n){
      string &ss = s[i];
      string &tt = s[j];
      int ovv = 0;
      int k = min(ss.size(),tt.size());
      FOR(x,1,k+1){
        if(ss.substr(ss.size()-x) == tt.substr(0,x))ovv=x;
      }
      g[i][j] = ovv;
    }
    REP(i,n)REP(j,1<<n)dp[i][j] = "#";
    dp[0][0] = "";
    REP(msk,(1<<n))REP(i,n){
      if(dp[i][msk]=="#")continue;
      string &ss = dp[i][msk];
      REP(to,n){
        if((msk>>to)&1)continue;
        int nmsk = msk | (1<<to);
        if(msk==0){
          // not override
          dp[to][nmsk] = s[to];
        }else{
          int ovv = g[i][to];
          string nxt = ss + s[to].substr(ovv);
          if(dp[to][nmsk]=="#" || dp[to][nmsk].size() > nxt.size() ||
            (dp[to][nmsk].size()==nxt.size() && dp[to][nmsk] > nxt)){
            dp[to][nmsk] = nxt;
          }
        }
      }
    }
    string ans = "#";
    REP(i,n){
      string po = dp[i][(1<<n)-1];
      if(ans=="#" || ans.size() > po.size() ||
        (ans.size()==po.size() && ans > po)){
        ans = po;
      }
    }
    // printf("%s\n", ans.c_str());
    printf("%d\n",ans.size());
  }
  return 0;
}

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

using namespace std;

int main(){
    int N,Y;
    cin >> N >> Y;
    
    int res10000 = -1;
    int res5000 = -1;
    int res1000 = -1;

    for(int a=0; a<=N; a++){
        for(int b=0; b<=N-a; b++){
            int c = N - a - b;
            if(a*10000 + b*5000 + c*1000 == Y){
                res10000 = a;
                res5000 = b;
                res1000 = c;
                break;
            }
        }
    }

    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 3564
from collections import Counter

N = int(input())
*A, = map(int, input().split())
like = [(i, j) if i < j else (j, i) for i, j in zip(range(1, N+1), A)]
cnt = Counter(like)
ans = 0
for v in cnt.values():
    ans += v // 2
print(ans)

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

int main() {
  int n, nex = 1, a = 0;
  double ans = 0;
  cin >> n;
  vector<int> x(n), y(n), v(n);
  for(int i = 0; i < n; i++) {
    nex *= n - i;
    cin >> x.at(i) >> y.at(i);
    v.at(i) = i;
  }
  do{
    for(int i = 0; i < n - 1; i++){
      ans += sqrt((x.at(v.at(i)) - x.at(v.at(i + 1))) * (x.at(v.at(i)) - x.at(v.at(i + 1))) + (y.at(v.at(i)) - y.at(v.at(i + 1))) * (y.at(v.at(i)) - y.at(v.at(i + 1))));
      //cout << ans << " ";
    }
    //cout << endl;
  }while(next_permutation(v.begin(),v.end())); 
  
  cout << fixed << setprecision(15) << ans / nex << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>
 
#define N 305
#define M 8000005
 
#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)
 
#define mk make_pair
#define pb push_back
#define fi first
#define se second
 
#define Mo 1000000007
#define g 3
 
using namespace std;

int f[N*2][N][N],cnt,i,j,m,n,p,k,a[N*2],vis[N*2];

void jia(int &x,int y)
{
		x+=y; if (x>=Mo) x-=Mo;
}

int main()
{
		scanf("%d",&n);
		for (i=1;i<=2*n;++i)
		{
				scanf("%d",&a[i]);
				if (a[i]!=-1) a[i]=2*n-a[i]+1;
		}
		for (i=1;i<=2*n;i+=2) 
				if (a[i]!=-1&&a[i+1]!=-1) vis[a[i]]=vis[a[i+1]]=1;
				else if (a[i]!=-1) vis[a[i]]=2;
				else if (a[i+1]!=-1) vis[a[i+1]]=2;
				else cnt++;
		f[0][0][0]=1;
		int P=0,L=0;
		for (i=1;i<=2*n;++i)
		{
			for (j=0;j<=cnt;++j)
				for (k=0;k<=n;++k)
					if (f[i-1][j][k])
					{
							if (vis[i]==1) f[i][j][k]=f[i-1][j][k];
							else if (vis[i]==2)
							{
									int rest=P-(2*j+L-k);
									if (rest>0) jia(f[i][j][k],f[i-1][j][k]);
									jia(f[i][j][k+1],f[i-1][j][k]);
							}
							else
							{
									jia(f[i][j][k],f[i-1][j][k]);
									if (k>0)  
									jia(f[i][j][k-1],1ll*k*f[i-1][j][k]%Mo);
									int rest=P-(2*j+L-k);
									if (rest>0&&cnt>j) jia(f[i][j+1][k],1ll*f[i-1][j][k]*(cnt-j)%Mo);
							}
					}
			if (vis[i]==0) P++;
			if (vis[i]==2) L++;
		}
	   printf("%d\n",f[2*n][cnt][0]);
}


Measured memory_bytes: 217344
N = int(input())
*A, = map(int, input().split())
ans = 0
now = A[0]
temp = 0
for a in A[1:]:
    if now >= a:
        temp += 1
    else:
        ans = max(temp, ans)
        temp = 0
    now = a
ans = max(temp, ans)
print(ans)

Measured memory_bytes: 14252
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

int tx[] = {1,0};
int ty[] = {0,1};


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

	vector<P> points(n);
	int a,b,c,d;
	while(~scanf("%d %d %d %d",&a,&b,&c,&d)){
		points[a-1].second = a;
		points[b-1].second = b;
		if(c>d){
			points[a-1].first += 3;
			
		}
		else if(c<d){
			points[b-1].first += 3;
		}
		else{
			points[a-1].first += 1;
			points[b-1].first += 1;
		}
	}

	sort(points.begin(),points.end(),greater<P>());

	vector<int> rank(n);

	int maxV = INF;
	int idx=0;
	int tmp=1;
	for(int i=0;i<points.size();i++){
		if(maxV > points[i].first){
			idx+=tmp;
			tmp=1;
			maxV = points[i].first;
			rank[points[i].second-1] = idx;
		}
		else if(maxV == points[i].first){
			rank[points[i].second-1] = idx;
			tmp++;
		}
	}

	for(int i=0;i<rank.size();i++){
		printf("%d\n",rank[i]);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>

using namespace std;

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

	int n;
	int ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i += 2) {
		vector<int> yak;
		for (int j = 1; j <= i; j++) {
			if (i%j == 0) {
				yak.emplace_back(j);
			}
		}
		if (yak.size() == 8) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int X; cin >> X;
    int N; cin >> N;
    int ans = 0;
    if(N == 0){
        ans = X;
    }
    else{
        vector <int> data(N);
        int flag = 0;
        for(int i = 0; i < N; i++){
            int tmp; cin >> tmp;
            data[i] = tmp;
            if(tmp == X){
                flag = 1;
            }
        }
        if(flag == 0){
            ans = X;
        }
        else{
            sort(data.begin(), data.end());
            int num = 0;
            //Xと同じ数字がどこにあるかをnumに保存
            for(int i = 0; i < N; i++){
                int tmp = data[i];
                if(tmp == X){
                    num = i;
                    break;
                }
            }

            //+
            int j = 1;
            int kari_j = X + 1;
            int ans_j;
            int ze_j;
            while(true){
                int f1 = 0;
                for(int i = num; i < N; i++){
                    if(data[i] == kari_j){
                        f1 = 1;
                        j ++;
                        kari_j ++;
                        break;
                    }
                    /*if(i == N - 1){
                        ans_j = data[N-1] + 1;
                        kari_j ++;
                        break;
                    }*/
                }
                if(f1 == 0){
                    ans_j = kari_j;
                    ze_j = j;
                    break;
                }
            }

            //-
            int k = 1;
            int kari_k = X - 1;
            int ans_k;
            int ze_k;
            while(true){
                int f2 = 0;
                for(int i = num; -1 < i; i--){
                    if(data[i] == kari_k){
                        f2 = 1;
                        k ++;
                        kari_k --;
                        break;
                    }
                }
                if(f2 == 0){
                    ans_k = kari_k;
                    ze_k = k;
                    break;
                }
            }

            if(ze_j == ze_k){
                ans = kari_k;
            }
            if(ze_j > ze_k){
                ans = kari_k;
            }
            if(ze_j < ze_k){
                ans = kari_j;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
ll dp[N][2][2];
int n;

ll call(int pos, int ze, int ni)
{
    if (pos == n)
    {
        if (ze && ni) return 1;
        return 0;
    }
    if (dp[pos][ze][ni] != -1) return dp[pos][ze][ni];
    ll res = 0;
    for (int i = 0; i <= 9; i++)
    {
        if (i == 0) res += call(pos + 1, 1, ni);
        else if (i == 9) res += call(pos + 1, ze, 1);
        else res += call(pos + 1, ze, ni);
        res %= mod;
    }
    return dp[pos][ze][ni] = res;
}

void solve()
{
    cin >> n;
    memset(dp, -1, sizeof(dp));
    cout << call(0, 0, 0);
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL);
    /*int tc; cin >> tc;
    while (tc--)*/
        solve();

    return 0;
}


Measured memory_bytes: 96916
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, K;
    string S;
    cin >> N >> S >> K;
    rep(i, N) {
        if (S[K-1] != S[i]) S[i] = '*';
    }
    print(S);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin>>A>>B;
    if((A+B)%2==1)cout<<"IMPOSSIBLE"<<endl;
    else cout<<(A+B)/2<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	while (a != 0 || b != 0)  {
		if (a < b) 
			cout << a << " " << b << endl;
		else 
			cout << b << " " << a << endl;
		cin >> a >> b;				 
	} 
	return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MOD 1000000009

ll h, w;
int alpha[26];

int main(){
    cin.sync_with_stdio(false);
    cin >> h >> w;

    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            alpha[s[j] - 'a']++;
        }
    }

    char panel[h][w];
    if (h % 2 == 0 && w % 2 == 0) {
        bool ok = true;
        rep(i, 26) {
            if (alpha[i] % 4 != 0) ok = false;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else if (h % 2 == 0 && w % 2 == 1) {
        ll cnt = 0, odd = 0;
        rep(i, 26) {
            cnt += alpha[i] / 4;
            if (alpha[i] % 2 == 1) odd = 1;
        }
        if (odd == 0 && cnt >= h * (w - 1) / 4) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else if (h % 2 == 1 && w % 2 == 0) {
        ll cnt = 0, odd = 0;
        rep(i, 26) {
            cnt += alpha[i] / 4;
            if (alpha[i] % 2 == 1) odd = 1;
        }
        if (odd == 0 && cnt >= (h - 1) * w / 4) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        ll cnt = 0, odd = 0;
        rep(i, 26) {
            cnt += alpha[i] / 4;
            if (alpha[i] % 2 == 1) odd++;
        }
        if (odd == 1 && cnt >= (h - 1) * (w - 1) / 4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}

int N, M, K, H, W, L, R, X;
//string S, T;
signed main(){
  cin >> N;
  vi a(N+2,0);
  rep1(i,N+1) cin >> a[i];
  vi L(N+2,0), R(N+2,0);
  rep1(i,N+1) L[i] = gcd(L[i-1],a[i]); 
  for(int i = N; i>0; i--) R[i] = gcd(R[i+1],a[i]);

  int ans = 0;
  rep1(i,N+1){
    if(i != N) ans = max(ans, gcd(L[i-1],R[i+1]));
    else ans = max(ans, L[i-1]);
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 5548
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

bool* checkTable;

void func(int N,int a, int b){

	int count = 0,a_limit;

	a_limit = N/a;

	for(int i = 1; i <= a_limit; i++){
		checkTable[a*i] = true;
	}
	for(int i = b; i <= N; i++){
		if(i % b == 0 || checkTable[i-b] == true){
			checkTable[i] = true;
		}
	}


	for(int i = 1; i <= N; i++){
		if(checkTable[i] == false)count++;
	}

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

}

int main(){

	int N,a,b;
	checkTable = new bool[1000001];

	while(true){
		scanf("%d %d %d",&N,&a,&b);
		if(N == 0 && a == 0 && b == 0)break;

		for(int i =1; i <= N; i++)checkTable[i] = false;

		func(N,a,b);
	}
	return 0;
}

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

int main()
{
	long long n, m;

	cin >> n >> m;

	if (n >= 2 && m >= 2)
	{
		long long ans;
		ans = (n - 2)*(m - 2);
		cout << ans << endl;
	}
	else
	{
		if (n == 1 && m == 1)
		{
			cout << 1 << endl;
	    }
		else
		{
			cout << max(n, m) - 2 << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926


int main(){
    string s, t;
    cin >> s >> t;
    int br=0;
    for(int i = 0;i < 3; i++)
        if(s[i]==t[i])
            br++;
    cout << br;
}

    

	


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

int main(){
    ll N, H, W;
    cin >> N >> H >> W;
    int cnt=0;
    for(int i=0; i<N; i++){
        ll A, B;
        cin >> A >> B;
        if(A>=H && B>=W) cnt++;
    }
    cout << cnt;
}

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

int n, ans;
string s;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> s;
	ans = n = s.size();
	for (int i = 0; i < n - 1; ++i) {
		if (s[i] != s[i + 1])
			ans = min(ans, max(n - i - 1, i + 1));
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3884
from collections import deque
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == "x":
            continue
        q = deque()
        q.append((h, w))
        shw = S[h][w]
        bl = wh = 0
        while len(q):
            i, j = q.popleft()
            if not 0 <= i < H or not 0 <= j < W:
                continue
            if S[i][j] == "x":
                continue
            dist = i + j - h - w
            if dist % 2 == 0 and shw != S[i][j]:
                continue
            if dist % 2 == 1 and shw == S[i][j]:
                continue
            if S[i][j] == "#":
                bl += 1
            else:
                wh += 1
            S[i][j] = "x"
            q.append((i-1, j))
            q.append((i+1, j))
            q.append((i, j-1))
            q.append((i, j+1))
        ans += bl * wh

print(ans)


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

using ll = long long;
using cd = complex<double>;

class aint {
    int n;
    vector<ll> v;
public:
    aint(int N): n(N), v(2 * n, 0x3f3f3f3f3f3f3f3fll){}
    void update(int poz, ll val){
        poz += n;
        v[poz] = min(v[poz], val);
        for(poz /= 2; poz; poz /= 2)
            v[poz] = min(v[2*poz], v[2*poz+1]);
    }
    ll query(int st, int dr){
        ll ret = 0x3f3f3f3f3f3f3f3fll;
        for(st += n, dr += n+1; st < dr; st /= 2, dr /= 2){
            if(st%2) ret = min(ret, v[st++]);
            if(dr%2) ret = min(ret, v[--dr]);
        }
        return ret;
    }
};

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

    vector<vector<pair<int, ll>>> by_rhs(n + 1);

    for(int i = 0, l, r, c; i < m; ++i){
        cin >> l >> r >> c;
        by_rhs[r].emplace_back(l, c);
    }

    aint a(n + 1);

    a.update(1, 0);

    for(int i = 2; i <= n; ++i)
        for(auto x : by_rhs[i])
            a.update(i, min(a.query(x.first, i) + x.second, 0x3f3f3f3f3f3f3f3fll));

    cout << (a.query(n, n) == 0x3f3f3f3f3f3f3f3fll ? -1 : a.query(n, n)) << endl;
}


Measured memory_bytes: 7168
X, K, D = map(int, input().split())

if X > D:
    t = min(X // D, K)
    K -= t
    X -= t * D
else:
    t = min(-X // D, K)
    K -= t
    X += t * D

K %= 2

if K == 0:
    print(abs(X))
else:
    if abs(X + D) < abs(X - D):
        print(abs(X + D))
    else:
        print(abs(X - D))


Measured memory_bytes: 9052
#include "bits/stdc++.h"
using namespace std;
const int INF = 1e9;

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

    int min_sum = INF;
    for(int i=0; i<1000; ++i) {
        int sum = 0;
        for(int j=0; j<N; ++j){
            sum += (x[j] - (i+1)) * (x[j] - (i+1));
        }
        // cout << sum << endl;
        if(sum < min_sum) min_sum = sum;
    }

    cout << min_sum << endl;

}

Measured memory_bytes: 256