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

using namespace std;

#define pb push_back
const int maxi = 1e6+10;
string s;

int n;
long long m;
long long a[maxi];
long long v;
int p;
long long b[maxi];
long long c[maxi];

int check(int x)
{
    long long ostalo = v*m;

    if (x>=n-p+1) return 1;

    for (int i=1;i<=n;i++)
        b[i] = a[i];
    for (int i=1;i<=n;i++)
        c[i] = m;

    ostalo-=m;
    b[x]+=m;

    int poz = n + 1;
    for (int i=1;i<=n && ostalo;i++)
        if (i!=x)
    {
          if (b[i]>b[x]) {
           b[i]+=min(m, ostalo);
           c[i] = 0;
           ostalo-=min(ostalo, m);
          } else
          {
              long long moze = b[x] - b[i];
              moze = min(moze, m);
              moze = min(moze, ostalo);
              b[i]+=moze;
              ostalo-=moze;
              c[i]-=moze;
           }
    }


        for (int i=n;i>0;i--)
        if (i!=x)
        {
            b[i]+=min(ostalo, c[i]);
            ostalo-=min(ostalo, c[i]);
        }


    int cnt = 0;

    for (int i=1;i<=n;i++)
        if (b[i]>b[x]) cnt++;

    return cnt<p;
}
int main()
{
    cin>>n>>m>>v>>p;

    for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);

   sort(a+1, a+n + 1);

   int l = 0;
   int r = n+ 1;

   while(l<r-1)
   {
      int mid = l + r >> 1;
      if (check(mid)) r = mid; else l = mid;
   }

   cout<<n - l<<endl;
   return 0;
}
//Kalifornija koka(kola) i sjaj


Measured memory_bytes: 9216
A, V = map(int, input().split())  # 座標Aにいて，秒速Vメートル
B, W = map(int, input().split())  # 座標Bにいて，秒速Wメートル
T = int(input())

# 右に移動していく場合
if B > A:
    if B + T*W > A + T*V:
        print("NO")
    else:
        print("YES")
else:
    # 左に移動していく場合
    if B - T*W < A - T*V:
        print("NO")
    else:
        print("YES")


Measured memory_bytes: 9204
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 5e3+10;
int n;
ll dp[N];
struct _ {
	int x,y;
	bool operator < (const _ &rhs) const {
		return x+y<rhs.x+rhs.y;
	}
} a[N];

int main() {
	cin>>n;
	REP(i,1,n) cin>>a[i].x>>a[i].y;
	sort(a+1,1+a+n);
	memset(dp,0x3f,sizeof dp);
	dp[0] = 0;
	REP(i,1,n) {
		PER(j,0,i-1) if (dp[j]<=a[i].x) {
			dp[j+1]=min(dp[j+1],dp[j]+a[i].y);
		}
	}
	PER(i,0,n) if (dp[i]<=1e16) return printf("%d\n",i),0;
}









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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n, m;
  cin >> n >> m;
  cout << (n-1) * (m-1) << endl;

  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>

#define SIZE 100005
#define MOD 1000000007
#define INF 100000000

using namespace std;

class DColoringEdgesOnTree {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n;
        cin >> n;
        vector<vector<int>> tree(n + 1);
        vector<bool> visited(n + 1, false);
        vector<pair<int, int>> colors;
        map<pair<int, int>, int> ans_map;
        ans.resize(n + 1);
        for (int i = 0; i < n - 1; ++i) {
            int a, b;
            cin >> a >> b;
            tree[a].emplace_back(b);
            tree[b].emplace_back(a);
            colors.emplace_back(min(a, b), max(a, b));
        }
        queue<int> que;
        que.push(1);
        visited[1] = true;
        int max_size = 0;
        while (!que.empty()) {
            int color = 1;
            int parent = que.front();
            que.pop();
            max_size = max(max_size, int(tree[parent].size()));
            for (const auto &child : tree[parent]) {
                if (visited[child]) continue;
                visited[child] = true;
                que.push(child);
                if (ans[parent] == color) {
                    color++;
                }
                ans[child] = color;
                ans_map[make_pair(parent, child)] = color;
                color++;
            }
        }
        cout << max_size << endl;
        for (const auto &item : colors) {
            cout << ans_map[make_pair(item.first, item.second)] << endl;
        }
    }

    vector<int> ans;
};


int main() {
    DColoringEdgesOnTree solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 13428
def main():
    H, W = (int(i) for i in input().split())
    _ = int(input())
    A = [int(i) for i in input().split()]
    c = [[0]*W for _ in range(H)]
    i = 1
    cnt = 0
    for h in range(H):
        rangeW = range(W) if h % 2 == 0 else range(W)[::-1]
        for w in rangeW:
            c[h][w] = i
            cnt += 1
            if cnt == A[i-1]:
                i += 1
                cnt = 0
    for row in c:
        print(*row)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42608
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

void update(int64& x, int64 y) {
  x = max(x, y);
}

const int N = 5000 + 10;
int64 dp[N * N];

int main() {
  int n;
  scanf("%d", &n);
  vector<int64> g(2), s(2), b(2);
  for (int k = 0; k < 2; ++k) {
    scanf("%lld%lld%lld", &g[k], &s[k], &b[k]);
  }
  for (int i = 1; i <= n; ++i) {
    if (i >= g[0]) update(dp[i], dp[i - g[0]] + g[1] - g[0]);
    if (i >= s[0]) update(dp[i], dp[i - s[0]] + s[1] - s[0]);
    if (i >= b[0]) update(dp[i], dp[i - b[0]] + b[1] - b[0]);
    dp[i] = max(dp[i], dp[i - 1]);
  }
  n += dp[n];
  memset(dp, 0, sizeof(dp));
  swap(g[0], g[1]);
  swap(s[0], s[1]);
  swap(b[0], b[1]);
  for (int i = 1; i <= n; ++i) {
    if (i >= g[0]) update(dp[i], dp[i - g[0]] + g[1] - g[0]);
    if (i >= s[0]) update(dp[i], dp[i - s[0]] + s[1] - s[0]);
    if (i >= b[0]) update(dp[i], dp[i - b[0]] + b[1] - b[0]);
    dp[i] = max(dp[i], dp[i - 1]);
  }
  printf("%lld\n", dp[n] + n);
  return 0;
}


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

char get_grade(int m, int f, int r)
{
    char grade;
    int sum;
    sum = m + f;

    if (m == -1 || f == -1)  {
        grade = 'F';
    } else if (sum >= 80) {
        grade = 'A';
    } else if (sum >= 65) {
        grade = 'B';
    } else if (sum >= 50) {
        grade = 'C';
    } else if (sum >= 30) {
        if (r >= 50) grade = 'C';
        else grade = 'D';
    } else {
        grade = 'F';
    }
    return grade;
}

int main()
{
    int m, f, r;
    
    while(1) {
        cin >> m >> f >> r;
        if (f == -1 && m == -1 && r == -1)  break;
        cout << get_grade(m, f, r) << '\n';
    }
    return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<vector>
#include<cmath>
#include<algorithm>
#include<tuple>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;

pii operator-(const pii &l, const pii &r){
	return pii(l.first - r.first, l.second - r.second);
}

int operator/(const pii &l, const pii &r){
	return l.first * r.second - l.second * r.first;
}

int sign(pii x){ return pii(0, 0) < x ? 1 : -1; }
double atan2(pii x){ return atan2(x.second, x.first); }

const int MX = 1<<18;
const int MM = 1000000007;

vector<int> G[MX];
int a, b;

struct node{
	node(int v, int mx):v(v), mx(mx){}
	node(){}
	int v, mx;
};

struct Tree{
	node t[MX*2];
	node merge(node l, node r){
		return node(l.v + r.v, max(l.v + r.mx, l.mx));
	}
	void update(int x, int v){
		x += MX;
		t[x].v += v; t[x].mx = v;
		while(x > 1){
			x /= 2;
			t[x] = merge(t[x*2], t[x*2+1]);
		}
	}
	int read(){ 
		return t[1].mx; 
	}
} tree;

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++){
		scanf("%d%d", &a, &b);
		G[a].push_back(b);
	}
	int mx = max(0, N-M), cnt = 0;
	for(int i = 1; i <= M+1; i++) tree.update(i, 1);
	for(int i = 0; i <= M; i++){
		for(int c : G[i]){
			cnt++; 
			tree.update(c+1, -1);
		}
		mx = max(mx, tree.read()+cnt - M-i-1);
	}
	printf("%d\n", mx);
}


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

int main(){
	int n,m;
	cin >>n>>m;
	//モチベ:まず再西端のb(xとする)の一つ西の橋を断ちたい
	//x>aならa<x<bの順に並んでいる，x-1は断たれているのでaとxはつながっていない=>OK
	//x=<a<bならxを更新
	vector<pair<int,int>>p;
	rep(i,m){
	int a,b;
	cin >>a>>b;
	p.push_back(make_pair(b,a));
	}
	sort(p.begin(),p.end());
	int x = p[0].first;
	int cnt=1;
	rep(i,m){//ここをnにしていて死んだ
		if (p[i].second>=x){
			cnt++;
			x=p[i].first;
		}
	}
	cout <<cnt;

}

Measured memory_bytes: 1400
n = int(input())
a = []
b = []
a_b = []
count = 0
for i in range(n):
    c ,d = map(int, input().split())
    a.append(c)
    b.append(d)
    a_b.append((c+d,count))
    count += 1

count = 0
ans = 0
for i in sorted(a_b,reverse=True):
    if count % 2 == 0:
        ans += a[i[1]]
    else:
        ans -= b[i[1]]
    count += 1
print(ans)

Measured memory_bytes: 25984
#include <iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;

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

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


int main(int argc, char const *argv[])
{
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> A[i];
    }

    mergeSort(A, n, 0, n);

    for (i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}




Measured memory_bytes: 6900
s, k = input(), int(input())
 
if len(set(list(s))) == 1:
    print(len(s) * k // 2)
    exit()
 
ans, cnt = [], 1
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 1
else:
    ans.append(cnt)
 
if s[0] != s[-1]:
    ans = [i//2 for i in ans]
    print(sum(ans) * k)
elif s[0] == s[-1]:
    f, m, l = ans[0] // 2, (ans[0] + ans[-1]) // 2, ans[-1] // 2
    ans = [i//2 for i in ans[1:-1]]
    print(f + sum(ans) * k + m * (k - 1) + l)

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

int main() {
  int x ;
  cin >> x;
  vector <bool> a(x+1,false);
  if ( x <=3){
    cout << 1 << endl;
    return 0;
  }
  for ( int i=2 ; i<=x ; i++){
    int v = i*i ; 
    for ( int j=2 ; j<=10 ; j++){
      if ( v > x){
        continue ;
      }else if ( v <=x){
        a.at(v)=true;
        v*=i;
      }
    }
  }
  for ( int i =x ; i>0 ; i--){
    if(a.at(i)) {
      cout << i<< endl;
      return 0 ;
    }
  }
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();

		if(a==7&&b==5&&c==5) {
			System.out.println("YES");
		}else if(a==5&&b==7&&c==5) {
			System.out.println("YES");
		}else if(a==5&&b==5&&c==7) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}

}

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

int main(int argc, char const *argv[])
{
	int r,g,b,n;
	cin>>r>>g>>b>>n;
	long long ans=0LL;
	for (int i = 0; i <= n; ++i)
	{
		if (i*r>n)
		{
			break;
		}
		for (int j = 0; j <= n; ++j)
		{
			if (i*r+j*g>n)
			{
				break;
			}
			if ((n-i*r-j*g)%b==0)
			{
				++ans;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long long int ll;

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

ll a,b,c;

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


Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

typedef vector <vector<int>> Graph;

// 強連結成分分解ライブラリ
class StronglyConnectedComponent {
public:
  Graph G;
  Graph rG;
  Graph cG;
  vector<int> vs;
  vector<bool> used;
  vector<int> componentId;
  int componentCount;
  int V;

  StronglyConnectedComponent(int V) {
    this->V = V;
    used = vector<bool>(V);
    componentId = vector<int>(V);
    G = Graph(V);
    rG = Graph(V);
  }

  void add_edge(int from, int to) {
    assert(0 <= from < V);
    assert(0 <= to < V);

    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void scc() {
    fill(used.begin(), used.end(), false);
    componentCount = 0;
    vs.clear();

    for (int v = 0; v < V; ++v) {
      if (used[v]) continue;

      dfs(v);
    }

    fill(used.begin(), used.end(), false);

    for (int i = vs.size() - 1; i >= 0; --i) {
      int v = vs[i];
      if (used[v]) continue;

      cG.push_back(vector<int>());
      rdfs(v, componentCount++);
    }
  }

private:
  void dfs(int v) {
    used[v] = true;

    for (int i = 0; i < G[v].size(); ++i) {
      int u = G[v][i];

      if (used[u]) continue;

      dfs(u);
    }

    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    componentId[v] = k;
    cG[k].push_back(v);

    for (int i = 0; i < rG[v].size(); ++i) {
      int u = rG[v][i];

      if (used[u]) continue;

      rdfs(u, k);
    }
  }
};

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

  StronglyConnectedComponent scc(N);
  int from, to;
  for (int i = 0; i < M; ++i) {
    cin >> from >> to;
    scc.add_edge(from, to);
  }

  scc.scc();
  int cnt = scc.componentCount;

  cout << cnt << endl;
  for (int i = 0; i < cnt; ++i) {
    vector<int> T = scc.cG[i];
    cout << T.size() << " ";

    for (int j = 0; j < T.size(); ++j) {
      cout << T[j];

      if (j != T.size() - 1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 79528
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int A[N];
	int temp;
	for(int i=0; i<N ;i++)
	{
		cin>>A[i];
	} 
	for(int i=0;i<N;i++)
	{
		temp = A[i];
		int j = i - 1;
		while(j>=0 && A[j]>temp)
		{
			A[j+1] = A[j];
			j--;	
		} 
		A[j+1] = temp;
		for(int h=0;h<N;h++)
		{
			if(h<N-1) 
				cout<<A[h]<<" ";
			else
				cout<<A[h];
		}
		cout<<endl;

	} 
	
 } 


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int k = 0;
  rep(i,n) if(p[i] != i+1) k++;
  if(k <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define INF 10000000000LL
#define abs llabs
using namespace std;
signed main(){
int n,h[100000],dp[100000];
  cin>>n;
  for(int i=0;i<n;++i){
	cin>>h[i];
    dp[i]=INF;
  }
  dp[0]=0;
  for(int i=0;i<n-2;++i){
	dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
    dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
  }
  dp[n-1]=min(dp[n-1],dp[n-2]+abs(h[n-2]-h[n-1]));
  cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo


void solve() {
    int A, B, C; cin >> A >> B >> C;
    int k; cin >> k;
    for(int i = 0; i <= k; ++i) {
        for(int j = 0; j <= k; ++j) {
            for(int q = 0; q <= k; ++q) {
                if (i + j + q <= k && A * (1 << i) < B * (1 << j) && B * (1 << j) < C * (1 << q)) {
                    cout << "Yes";
                    return;
                }
            }
        }
    }
    cout << "No";
}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("travel_restrictions_input.txt", "r", stdin);
//    freopen("A.out", "w", stdout);
//    int test; cin >> test;
//    for(int t = 1; t <= test; ++t) {
//        cout << "Case #" << t << ":" << endl;
        solve();
//    }
    return 0;
}



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

int main()
{
    string s;
    cin >> s;
    int len = s.size();

    string buf = "";
    for (int i = 0; i < len; i++)
    {
        if(s[i] == 'x')continue;
        buf = buf + s[i];
    }
    bool can = true;
    int blen = buf.size();
    for (int i = 0; i <= blen; i++)
    {
        if(buf[i] != buf[blen - i - 1])can = false;
    }
    if(can)
    {
        int ans = 0;
        for (int i = 0; i < len / 2; i++)
        {
            if(s[i] != s[len - 1 - i])
            {
                if(s[i] == 'x')
                {
                    s.insert(len - i, "x");
                }
                if(s[len - 1 - i] == 'x')
                {
                    s.insert(i, "x");
                }
                len++;ans++;
            }
            //cout << s << " " << ans << endl;
        }
        cout << ans << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    
}

Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;


int yakusu(int a){
    int count = 0;
    for(int i = 1; i <= a; i++){
        if(a%i==0) count += 1;
    }
    return count;
}
int main() {
    int n; cin >> n;
    int count = 0;
    for(int i = 1; i <= n; i += 2){
        if(yakusu(i)==8) count += 1;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


int main(){
	int n;
	cin>>n;
	vector<int> v(2*n);
	rep(i,2*n){
		cin>>v[i];
	}
	
	sort(all(v));
	
	
	ll ans=0;
	rep(i,v.size()){
		if(i%2==0)ans+=v[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool a_In_b(char a, string b) {
    return b.find({a}) != string::npos;
}

int count(string a, string b) {
    int count = 0;
    for (char c = 'a'; c <= 'z'; c++) {
        if (a_In_b(c, a) && a_In_b(c, b)) {
            count++;
        }
    }
    return count;
}

int main(void) {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int ans = 0;

    for (int i = 1; i < N; i++) {
        ans = max(ans, count(s.substr(0, i), s.substr(i, N-i)));
    }

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

Measured memory_bytes: 256
S = input()

def zero_start(S):
    cnt = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] != '0':
                cnt += 1
        else :
            if S[i] != '1':
                cnt += 1
    return cnt

def one_start(S):
    cnt = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] != '1':
                cnt += 1
        else :
            if S[i] != '0':
                cnt += 1
    return cnt

paints = [zero_start(S), one_start(S)]

print(min(paints))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
# define ALL(x) (x).begin(), (x).end()
using namespace std;
int main()
{int a,b,c,d,e;
 cin>>a>>b>>c>>d>>e;
 int ans=0;
 ans=(c-a)*60+(d-b)-e;
 cout<<ans<<endl;
    




return 0;
}

Measured memory_bytes: 3636
package main
     
    import "fmt"
     
    func main() {
    	var n, x int
    	fmt.Scan(&n, &x)
    	a := make([]int, n)
    	for i := 0; i < n; i++ {
    		fmt.Scan(&a[i])
    	}
     
    	ans := 0
    	if d := a[0] - x; d > 0 {
    		a[0] -= d
    		ans += d
    	}
     
    	for i := 1; i < n; i++ {
    		if d := (a[i-1] + a[i]) - x; d > 0 {
    			a[i] -= d
    			ans += d
    		}
    	}
     
    	fmt.Println(ans)
    }

Measured memory_bytes: 5504
import sys

n,a,b=(int(n) for n in input().split())

s = a + b

amari = n % s
syou = n // s

if amari == 0:
    print(a*syou)
    sys.exit()

else :
    if amari > a:
        print(a*syou+a)
    else :
        print(a*syou+amari)


Measured memory_bytes: 2940
import math
from decimal import Decimal
a,b,x = list(map(int, input().split()))
ans = 0

#in: 傾き 底面 高さ
#out: 面積
def fb(tilt, a, b):
    #x=0 or y=0
    #y=tilt*x + g
    g=b-a*tilt
    y = g
    x = -g/tilt
    if x>0:
        #(a-a,0) (a-a,b) (x-a,0)
        return abs(0*0 - (x-a)*b)/2
    elif y>0:
        #(a,0) (a,b) (0,y) (0,0)
        return (b+y)*a/2
    else:
        #(a,0) (a,b) (0,0)
        return abs(a*b - a*0)/2
#in: 角度 out: y=axのa
def f(angle):
    a =  math.tan(math.radians(angle))
    return a




high = 90
low = 0
for i in range(1000):
    mid = (high + low) / 2
    m = fb(f(mid), a, b) * a
    if m>x:
        low = mid
    elif m<x:
        high = mid
    else:
        ans = mid
        break

print(mid)

Measured memory_bytes: 5076
# -*- coding: utf-8 -*-
import sys
import copy
from bisect import bisect_left

def main():
	N, T = map(int, input().split(" "))
	CT = []
	isOK = False
	for _ in range(N):
		c, t = map(int, input().split(" "))
		if t <= T:
			isOK = True
			CT.append((c, t))
	
	if isOK == False:
		print("TLE")
		sys.exit()
	
	CT.sort()
	c, t = CT[0]
	print(c)
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 3444
// http://codeforces.com/contest/1315/problem/D
// Greedy
// time complexity limitation
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <deque>

#define ll long long
#define ull unsigned long long

using namespace std;

const int MOD = 1e9+7;
const int inf = 0x3f3f3f3f;
const int PI = acos(-1.0);

const int N = 2e3+10;

int arr[N][N];
int ans[N];
int main() {
	#ifdef local
		if(freopen("/Users/Andrew/Desktop/Problems/data.txt", "r", stdin) == NULL) printf("can't open this file!\n");
	#endif

    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            arr[i][j] = min(abs(j-i), 1+abs(x-i)+abs(j-y));
            ans[arr[i][j]]++;
        }
    }
    for (int i = 1; i <= n-1; ++i) {
        cout << ans[i] << endl;
    }
	#ifdef local
	fclose(stdin);
	#endif
	return 0;
}

Measured memory_bytes: 15360
def solution():
    n, k = map(int, input().split())
    ans = 0
    for i in range(k, n+2):
        smallest = (i-1) * i / 2
        largest = (n-i+1) * i + smallest
        ans += largest - smallest + 1
    ans %= 10 ** 9 + 7
    print(int(ans))

solution()


Measured memory_bytes: 63440
public class Main {
    public static void main(String args[]) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if (A == B) System.out.println(C);
        else if (A == C) System.out.println(B);
        else System.out.println(A);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  int N, T, A;
  int H;
  int ans = 0;
  cin >> N;
  cin >> T >> A;
  vector<double> vec(N);

  for (int i = 0; i < N; i++){
    cin >> H;
    vec.at(i) = (A-(T - H*0.006))*(A-(T - H*0.006));
  }

  std::vector<double>::iterator minIt = std::min_element(vec.begin(), vec.end());
  size_t minIndex = std::distance(vec.begin(), minIt);

  cout << minIndex+1 << endl;

  return 0;
}



Measured memory_bytes: 256
#4
import sys
N = int(input())
x,y,k = 0,0,0

if N == 1:
    print(1)
    sys.exit()
elif N <= 12:
    print(N)
    sys.exit()
x = int(0.8*N)

for i in range(x,N):
    k = str(i*108)
    if int(k[0:-2]) == N:
        print(i)
        y +=1
        break

if y !=1:
    print(":(")


Measured memory_bytes: 9092
from itertools import combinations
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

ans = float("inf")
for i in range(1,n+1):
  for j in combinations(ca,i):
    l = [0]*(m+1)
    for k in j:
      for i2 in range(m+1):
        l[i2] += k[i2]
    if all(l[num] >= x for num in range(1,m+1)):
      ans = min(ans, l[0])
if ans == float("inf"): print(-1)
else: print(ans)

Measured memory_bytes: 9084
#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;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  int n, x,ans = 0,prev;
  cin >> n;
  cin >> x;
  for(int i = 0; i < n-1; i++){
    prev = x;
    cin >> x;
    if(x == prev){ ans++; x = -1;}
  }
  cout << ans << endl;
  return 0;
}


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

// 0回目 A,B,C -- A-B, B-C, C-A
// 1回目 B+C,A+C,A+B -- B-A, C-B, A-C
// 2回目 2A+B+C,A+2B+C,A+B+2C -- A-B, B-C, C-A
// 3回目 2A+3B+3C,3A+2B+3C,3A+3B+2C -- B-A, C-B, A-C
// ...
// n回目 nA, nB, nC -- nA-nB = A-B, nB-nC = B-C, nC-nA = C-A
// (n+1)回目 nB+nC, nA+nC, nA+nB -- nB-nA = B-A, nC-nB = C-B, nA-nC = A-C

int main() {
    long long A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K&1LL) cout << B-A << endl;
    else cout << A-B << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
#define int ll
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;

bool matched[3][3][4005];
string s[3];
void go(int x, int y){
  for(int j = 0; j < s[x].size(); j++){
    bool ok = true;
    for(int k = 0; k < s[y].size() && j + k < s[x].size() && ok; k++){
      ok &= (s[y][k] == s[x][j+k] || (s[y][k] == '?') || (s[x][j+k] == '?'));
    }
    matched[y][x][j] = ok;
  }
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  memset(matched,1,sizeof matched);
  f(i,0,3)  cin >> s[i];
  f(i,0,3)f(j,0,3)go(i,j);
  int p[3] = {0,1,2};
  int ans = s[0].size() + s[1].size() + s[2].size();
  do{

    for(int i = 0; i <= s[p[0]].size(); i++){
      if(matched[p[1]][p[0]][i]){
        for(int j = 0; j <= s[p[1]].size() || i + j <= s[p[0]].size(); j++){
          if(matched[p[2]][p[1]][j] && matched[p[2]][p[0]][i + j]){
            ans = min(ans, max({(int)s[p[0]].size(),i+(int)s[p[1]].size(),i+j+(int)s[p[2]].size()}));
          }
        }
      }
    }

  }while(next_permutation(p,p+3));

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
int main()
{
#ifndef ONLINE_JUDGE
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	ll n,x,tt;
    	cin>>n>>x>>tt;
    	ll rem=n/x;
    	ll xx=n%x;
    	if(xx>0)
    		xx=1;
    	ll tot=(rem+xx)*tt;
    	cout<<tot;
    }
    return 0;
}

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

int main() {
    int N; cin >> N;
    ll p=0;
    map<ll, ll> m;
    m[0]++;
    for (int i = 0; i < N; i++)
    {
        ll A; cin >> A;
        m[A+p]++;
        p = A + p;
    }

    ll ans = 0;
    for (auto iter = m.begin(); iter != m.end(); ++iter)
    {
        //cout << iter->first << " " << iter->second << endl;
        ans += (iter->second) * (iter->second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[][] s = new int[m][n];

        for (int i = 0; i < m; i++) {
            int k = Integer.parseInt(sc.next());
            for (int j = 0; j < k; j++) {
                s[i][j] = Integer.parseInt(sc.next());
            }
        }

        int[] p = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = Integer.parseInt(sc.next());
        }

        int ans = 0;
        for (int i = 0; i < (1 << n); i++) {
            int[] sw = new int[n];
            for (int j = 0; j < n; j++) {
                if ((1 & i >> j) == 1) {
                    sw[j] = 1;
                }
            }

            boolean ok = true;
            for (int j = 0; j < m; j++) {
                int cnt = 0;
                for (int k = 0; k < n; k++) {
                    if (s[j][k] == 0) {
                        break;
                    }
                    if (sw[s[j][k] - 1] == 1) {
                        cnt++;
                    }
                }
                if (cnt % 2 != p[j]) {
                    ok = false;
                }
            }

            if (ok) {
                ans++;
            }
        }

        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 23124
s = int(input())
import math

def is_prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

if is_prime(s) == True:
    print(s)
while is_prime(s) == False:
    s = s +1
    if is_prime(s) == True:
        print(s)
        break


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

int main(){
  int N,p=1,cnt=0;
  cin >> N;
  bool ok=false;
  vector<int> data(N+1);
  data.at(0)=0;
  for(int i=1;i<=N;i++){cin>>data.at(i);}
  for(int i=0;i<=N;i++){
    cnt++;
    if(data.at(p)==2){
      ok=true;
      break;
    }else{
      p=data[p];
    }
  }
  cout<<(ok ? cnt : -1)<<endl;
}


Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PrintLn(X) cout << X << endl

typedef long long ll;
int a[2000];

int main(void)
{
	int N, Z, W;
	cin >> N >> Z >> W;
	Rep(i, N) cin >> a[i];

	int ans = abs(a[N - 1] - W);
	if(N > 1) ans = max(ans, abs(a[N - 2] - a[N - 1]));
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.numeric;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n; readV(n);
  long[] t; readC(n, t);

  writeln(t.reduce!((a, b) => a/gcd(a,b)*b));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100, W = 100000;
long long wt[N], v[N], f[N+1][W+1];

int main(){
	int n, w;
	cin >> n >> w;
	
	for(int i = 0; i < n; i++) cin >> wt[i] >> v[i];
	
	for(int i = 0; i <= n; i++){
	    for(int j = 0; j <= w; j++){
	        if(i == 0 || j == 0) f[i][j] = 0;
	        else if(j-wt[i-1] < 0) f[i][j] = f[i-1][j];
	        else f[i][j] = max(f[i-1][j], f[i-1][j-wt[i-1]] + v[i-1]);

	    }
	}
	cout << f[n][w];
}

Measured memory_bytes: 82512
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
//const int mod = 1000000007;

const int mod = 998244353;
struct mint {
	ll x;
	mint() :x(0) {}
	mint(ll x) :x((x% mod + mod) % mod) {}
	// mint(ll x):x(x){}
	mint& fix() { x = (x % mod + mod) % mod; return *this; }
	mint operator-() const { return mint(0) - *this; }
	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; }
	bool operator<(const mint& a)const { return x < a.x; }
	bool operator==(const mint& a)const { return x == a.x; }
};
istream& operator>>(istream & i, mint & a) { i >> a.x; return i; }
ostream& operator<<(ostream & o, const mint & a) { o << a.x; return o; }
typedef vector<mint> vm;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<ll> d(n);
	vector<ll> mp(n + 1);
	rep(i, n) {
		cin >> d[i];
		mp[d[i]]++;
	}
	if (d[0] != 0) {
		puts("0");
		return 0;
	}
	if (mp[0] != 1) {
		puts("0");
		return 0;
	}
	mint ans = 1;
	mint tmp = 1;
	rrep(i, n) {
		rep(j, mp[i]) ans *= tmp;
		tmp = mp[i];
	}
	dunk(ans);
	return 0;
}


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

int main()
{
	string S;

	cin >> S;

	if (S == "Sunny")
		cout << "Cloudy\n";
	else if (S == "Cloudy")
		cout << "Rainy\n";
	else if (S == "Rainy")
		cout << "Sunny\n";
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    int a = 2*x == w && 2*y == h;
    //cout << (double)((double)w*(double)h/2) << ' ' << a << endl;
    printf("%lf %d\n",(double)w*(double)h/2,a);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		int x=Integer.parseInt(str);
		System.out.println(x*x*x);
	}

}


Measured memory_bytes: 24164
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if(i%3==0){
            cout << " " << i;
            continue;
        }
        int x=i;
        while (x){
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x/=10;
        }
    }
    cout << endl;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  while(b!=0){
    int r=a%b;
    a=b;
    b=r;
  }
  return a;
}
int pow(int a,int b){
  int ans=1;
  for(int i=0; i<b; i++) ans *=a;
  return ans;
}
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> l(n),r(n);//左からi番目までのGCD、右からも同様
  for(int i=0; i<n; i++){
    int tmp;
    cin>>tmp;
    a.at(i)=tmp;
  }
  l.at(0)=a.at(0);
  r.at(n-1)=a.at(n-1);
  for(int i=1; i<n; i++){
    l.at(i)=gcd(l.at(i-1),a.at(i));
    r.at(n-1-i)=gcd(r.at(n-i),a.at(n-i-1));
  }
  int ans=r.at(1);
  for(int i=1; i<n-1; i++){
    int tmp=gcd(l.at(i-1),r.at(i+1));
    if(tmp>ans){
      ans=tmp;
    }
  }
  if(l.at(n-2)>ans) ans=l.at(n-2);
  cout<<ans<<endl;
                  
                    
}
    

Measured memory_bytes: 1408
#include <iostream>

using namespace std;
struct Card {
	char suit, value;
};
void printList(Card C[], int n){
	for(int i=0; i<n-1; i++){
		cout << C[i].suit << C[i].value << ' ';
	}
	cout << C[n-1].suit << C[n-1].value << endl;
}
void bubbleSort(Card C1[], int n){
	int flag = 1;
	for(int i=0; flag; i++){
		flag = 0;
		for (int j=n-1; j>i; j--){
			if(C1[j].value < C1[j-1].value){
				Card t = C1[j];
				C1[j] = C1[j-1];
				C1[j-1] = t;
				flag = 1;
			}
		}
	}
	printList(C1, n);
}
void selectionSort(Card C2[], int n){
	for(int i=0; i<n; i++){
		int minj = i;
		for(int j=i; j<n; j++){
			if(C2[j].value < C2[minj].value)
				minj = j;
		}
		if(minj != i){
			Card t = C2[i];
			C2[i] = C2[minj];
			C2[minj] = t;
		}
	}
	printList(C2, n);
}
void isStable(Card C1[], Card C2[], int n){
	for(int i=0; i<n; i++){
		if(C1[i].suit != C2[i].suit){
			cout << "Not stable" << endl;
			return;
		}
	}
	cout << "Stable" << endl;
}
int main() {
	Card C1[100], C2[100];
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> C1[i].suit >> C1[i].value;
		C2[i] = C1[i];
	}
	bubbleSort(C1, n);
	cout << "Stable" << endl;
	selectionSort(C2, n);
	isStable(C1, C2, n);
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";

#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 5005

template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

//FILE* outFile;

inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
inline int gcd(int a, int b){if(b == 0)return a; return gcd(b, a%b);}
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

int a[2][3];
vi e[2];
ll dp[N * N];
ll cal(int n, vi &e){
    memset(dp, 0, sizeof(dp));
    for(auto &i : e){
        per(j, 1, n+1){
            if(j < a[0][i])break;
            Max(dp[j - a[0][i]], dp[j] + a[1][i]);
        }
    }
    ll ans = 0;
    rep(i, 0, n+1){
        Max(ans, i + dp[i]);
    }
    return ans;
}
int main(){
    int j,k,i,T,ca=0, m = 0, K = 0, n;
    scanf("%d", &n);
    rep(i, 0, 2)rep(j, 0, 3)scanf("%d", &a[i][j]);
    rep(i, 0, 3){
        if(a[0][i] < a[1][i]){
            e[0].pb(i);
        }
        if(a[0][i] > a[1][i]){
            e[1].pb(i);
        }
    }
    ll ans = cal(n, e[0]);
    rep(i, 0, 3)swap(a[0][i], a[1][i]);
    ans = cal(ans, e[1]);
    printf("%lld\n", ans);
}



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

int C[10001] = {};

void CountingSort(vector<int> &A, vector<int> &B, int k){
    
    /* C[i] に i の出現数を記録する */
    for(int i = 0; i < k; i++) {
        C[A[i]]++;
    }

    /* C[i] に i 以下の数の出現数を記録する*/
    for(int i = 1; i <= 10000; i++){
        C[i] = C[i] + C[i-1];
    }

    for(int i = k-1; i >= 0; i--){
        B[--C[A[i]]] = A[i];
    }
}

int main() {

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

    CountingSort(a, b, n);
    
    rep(i, n){
        if(i!=n-1){
            cout << b[i] << " ";
        }
        else{
            cout << b[i] << endl;
        }
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if(r<=x && x<=w-r && r<=y && y<= h-r)cout<< "Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>
int main(){
	int k,a,b,c[10],flag,num=0,i;
	scanf("%d %d",&a,&b);
	
	for(i=a;i<=b;i++){
		k=0; int d = i;
		
		flag=0;
		while(d>0){
		  c[k]=d%10;
		  d=d/10;
		  k++;
	      }
	  for(int j=0;j<k;j++){
	    if(c[j]!=c[k-j-1]){
		  flag=1;
		  break;
	      }
	  }      if(flag==0)
	        num++;
	  
	
	}
		printf("%d",num);
	}

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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int A,B,K;
    cin >> A >> B >> K;

    char turn = 'A';

    for (int i = 0; i < K; i++) {
        if (turn == 'A') {
            if (A%2 != 0) {
                A--;
            }
            B += A/2;
            A /= 2;
            turn = 'B';
        } else {
            if (B%2 != 0) {
                B--;
            }
            A += B/2;
            B /= 2;
            turn = 'A';
        }
        
    }
    cout << A << ' ' << B << endl;
}


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

int dp[1001][1001];
int main () {
  string s1, s2;
  cin >> s1 >> s2;

  int l1 = s1.size(), l2 = s2.size();

  for(int i = 0; i <= l1; i++) dp[i][0] = i;
  for(int j = 0; j <= l2; j++) dp[0][j] = j;

  for(int i = 0; i < l1; i++) {
    for(int j = 0; j < l2; j++) {
      dp[i+1][j+1] = dp[i][j+1] + 1;
      dp[i+1][j+1] = min(dp[i+1][j+1], min(dp[i+1][j] + 1, dp[i][j] + (s1[i] != s2[j])));
    }
  }

  cout << dp[l1][l2] << endl;
  return 0;
}

Measured memory_bytes: 7092
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

const long long INF = (1LL<<62);

LL H, N;
vector<LL> A; //威力
vector<LL> B; //魔力
LL dp[1004][10004] = {INF};


int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> H >> N;
	for(int i=0; i<N; i++){
		LL a, b;
		cin >> a >> b;
		A.push_back(a);
		B.push_back(b);
	}

	for(int i=0; i<1004; i++){
		for(int j=0; j<10004; j++){
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for(int i=0; i<N; i++){
		for(int j=0; j<=H; j++){
			//i番目の魔法を使わない場合
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			//i番目の魔法を使う場合
			dp[i+1][min(j+A[i], H)] = min(dp[i+1][min(j+A[i], H)], dp[i+1][j]+B[i]);
		}
	}
    LL ans = dp[N][H];
	printf("%lld\n", ans);
	return 0;
}


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

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

char H[M][L];

/* 文字から数値に変換 */
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

/* 文字列から数値へ変換して key を生成する */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 17060
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long fa[100005],ans,a;
int n,q,i;
bool r[100005];
char c;
long long find(long long x)
{
	if(r[x]==1)
		return x;
	return find(fa[x]);
}
int main()
{
	fa[1]=1;
	r[1]=1;
	while(1)
	{
		scanf("%d %d",&n,&q);
		if(n==0||q==0)
			return 0;
		ans=0;
		for(i=2;i<=n;i++)
			r[i]=0;
		for(i=2;i<=n;i++)
			scanf("%lld",&fa[i]);
		for(i=1;i<=q;i++)
		{
			scanf("\n%c %lld",&c,&a);
			if(c=='M')
				r[a]=1;
			if(c=='Q')
				ans=ans+find(a);
		}
		printf("%lld\n",ans);
	}
}

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

char s[110];
int i,a,b,x;

int main(){
    while(scanf("%s",s)!=EOF){
        a=b=0;
        for(i=0;i<strlen(s);i++){
            if(s[i]=='I')x=1;
            else if(s[i]=='V')x=5;
            else if(s[i]=='X')x=10;
            else if(s[i]=='L')x=50;
            else if(s[i]=='C')x=100;
            else if(s[i]=='D')x=500;
            else if(s[i]=='M')x=1000;
            if(b>=x)a=x+a;
            else a=a+x-2*b;
            b=x;
        }
        printf("%d\n",a);
    }
    
    return 0;
}


Measured memory_bytes: 1988