akhauriyash/Code-Regression huggingface dataset:
# frozen_string_literal: true


# union find
class UnionFind
  attr_reader :size

  def initialize(n)
    @parents = Array.new(n) { |i| i }
    @ranks = Array.new(n) { 0 }
    @size = Array.new(n) { 1 }
  end

  def root(x)
    if @parents[x] == x
      x
    else
      @parents[x] = root(@parents[x])
    end
  end

  def unite(x, y)
    root_x = root(x)
    root_y = root(y)
    return if root_x == root_y

    if @ranks[root_x] < @ranks[root_y]
      @parents[root_x] = root_y
      @size[root_y] += @size[root_x]
      @size[root_x] = 0
    else
      @parents[root_y] = root_x
      @size[root_x] += @size[root_y]
      @size[root_y] = 0
      @ranks[root_x] += 1 if @ranks[root_x] == @ranks[root_y]
    end
  end

  def same?(x, y)
    root(x) == root(y)
  end
end

n, m = gets.split.map(&:to_i)
ab = m.times.map { gets.split.map(&:to_i) }

u = UnionFind.new(n)

ab.each do |e|
  u.unite(e[0] - 1, e[1] - 1)
end

puts u.size.max


Measured memory_bytes: 33024
/*
AizuOnline A0107
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
#include <float.h>
#include <math.h>
//#include <limits.h>
//Global data section
int x,y,z;
int h1,h2;
int n;
int r;
double t; //taikakusen
//
main()
{
  int i;

  while(EOF != scanf("%d %d %d ",&x,&y,&z) && (x||y||z))
    {
      if(x >= y && x >= z)
	t=sqrt((double)(y*y+z*z));
      else if(y >= x && y >= z)
	t=sqrt((double)(x*x+z*z));
      else if(z >= x && z >= y)
	t=sqrt((double)(x*x+y*y));
      //printf("%lf",t);      
      scanf("%d",&n);
      for(i=0;i<n;i++)
	{
	  scanf("%d",&r);
	  if((double)r*2 > t)
	    printf("OK\n");
	  else
	    printf("NA\n");
	}
    }
  return(0);
} 

Measured memory_bytes: 588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int a,b;

int main(){
	cin >> a >> b;
	if(a*b%2)cout << "Odd" << endl;
	else cout << "Even" << endl;
}

Measured memory_bytes: 256
r, c = map(int, input().split())
sheet = [[int(n) for n in input().split()] for i in range(r)]
sheet_sum = [[0 for i in range(c + 1)] for j in range(r + 1)]
for i in range(r):
    for j in range(c):
        sheet_sum[i][j] = sheet[i][j]
    sheet_sum[i][c] = sum(sheet[i])
for i in range(c + 1):
    for j in range(r):
        sheet_sum[r][i] += sheet_sum[j][i]
for i in range(r + 1):
    for j in range(c + 1):
        if j == c:
            print(sheet_sum[i][j])
        else:
            print(sheet_sum[i][j], end = " ")

Measured memory_bytes: 8220
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int k;
    cin >> k;

    cout << (k/2)*(k/2+k%2) << endl;
    return 0;
}

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

using namespace std;

int main(void) {
	string s;

	int x = 0, maxx = 0, n;

	cin >>n>> s;

	for (int n = 0; n < s.size(); n++)
	{
		if (s[n] == 'I')x++;
		if (s[n] == 'D')x--;
		maxx = max(maxx, x);
	}

	cout << maxx << "\n";

	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for _ in [0]*M]

ans = ["*"]*N
for s,c in SC:
    if ans[s-1] == str(c) : continue
    if ans[s-1] != "*" :
        ans = ["-1"]
        break
    ans[s-1] = str(c)

if ans[0] == "0" and N!=1:
    ans = ["-1"]
if ans[0] == "*":
    if N==1:ans[0] = "0"
    else:ans[0] = "1"
for i,_ in enumerate(ans[1:],1):
    if ans[i] == "*":
        ans[i] = "0"
print("".join(ans))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
    int c[1001001],p[1010],n,m,cnt,i,j,tmp,ans,pnt;
    int *point;
    cin >> n >> m;
    while(n!=0 && m!=0){
        cnt = 0;
        ans = 0;
        p[0]=0;
        for(i=1; i<=n; i++){
            cin >> p[i];
        }
        m++;
        for(i=0; i<=n; i++){
            for(j=i; j<=n; j++){
                if(p[i]+p[j]<m){
                    c[cnt] = p[i]+p[j];
                    cnt++;
                }
            }
        }
        sort(c,c+cnt);
        for(i=0; i<cnt; i++){
            point = lower_bound(c,c+cnt,m-c[i]);
            pnt = (int)(point-c);
            if(pnt>0){
                pnt--;
                tmp = c[i]+c[pnt];
                ans = max(ans,tmp);
            }
        }
        cout << ans <<endl;
        cin >> n >> m;
    }
    return 0;
}

Measured memory_bytes: 4816
#include<iostream>
using namespace std;
void caluclate(double [],int);
int main()
{
	int n;
	cin>>n;
	double a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	caluclate(a,n);
	return 0;	
}

void caluclate(double a[],int n)
{
	double mul=1;
	for(int i=0;i<n;i++)
	{
		mul*=a[i];
	}
	double sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=mul/a[i];
	}
	//cout<<mul;
	//cout<<sum;
	cout<<(double)(mul/sum);
}


Measured memory_bytes: 256
import numpy as np


def main():
    n, k = map(int, input().split())
    Counts = [0] * (10**5 + 1)
    for _ in range(n):
        a, b = map(int, input().split())
        Counts[a] += b
    cumsum = np.cumsum(Counts)
    for i in range(10**5+1):
        if cumsum[i] >= k:
            ans = i
            break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 30912
import sys
from collections import deque

def convert_a_to_i(char):

	if char == 'A':
		return 1

	elif char == 'C':
		return 2

	elif char == 'G':
		return 3

	else:
		return 4

def hash_calc(word):

	hash = 0
	p = 1
	for i in range(len(word)):

		hash += convert_a_to_i(word[i]) * p
		p *= 5

	return hash

def find(dictionary,word):

	if dictionary[hash_calc(word)-1] == 1:
		return True
	else:
		return False

def insert(dictionary,word):

	dictionary[hash_calc(word)-1] = 1

def test():

	n = int(sys.stdin.readline())

	dictionary = [0] * (4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4 * 4)


	for i in range(n):

		operation = list(sys.stdin.readline().split())

		if operation[0] == 'insert':

			insert(dictionary,operation[1])
		else:

			result = find(dictionary,operation[1])
			if result == True:
				print("yes")
#				with open("out.txt",mode='a') as f:
#					f.write("yes " + operation[1] + "\n")
			else:
				print("no")
#				with open("out.txt",mode='a') as f:
#					f.write("no " + operation[1] + "\n")


if __name__ == "__main__":
	test()



Measured memory_bytes: 137580
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define MOD 1000000007
using namespace std;
typedef long long int LL;


int main(){
  LL N;
  cin >> N;
  LL k[63] = {};
  REP(i, N){
    LL A;
    cin >> A;
    for(int i = 0;A != 0; ++i) {
      if((A & 1) != 0) { k[i]++; }
      A = A >> 1;
    }
  }
  LL ret = 0;
  REP(i, 63) {
    LL m = (1LL << i) % MOD;
    LL c = k[i] * (N - k[i]) % MOD;
    ret += m * c;
    ret = ret % MOD;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
islands = [set() for i in range(n)]
for i in range(m):
    a, b = [int(i) for i in input().split()]
    islands[a-1].add(b)
    islands[b-1].add(a)
f = False
for i in islands[n-1]:
    if 1 in islands[i-1]: f = True
print("POSSIBLE" if f else "IMPOSSIBLE")

Measured memory_bytes: 67736
//ALDS1_2_A 「Bubble Sort」
#include <bits/stdc++.h>
//一括include
using namespace std;

void out(int array[], int x) //表示
{
    printf("%d", array[0]);
    for (int num = 1; num < x; num++)
    {
        printf(" %d", array[num]);
    }
    printf("\n");
}

int bubbleSort(int A[], int N)
{
    int flag = 1;
    int count = 0;
    while (flag)
    {
        flag = 0;
        for (int j = N - 1; 0 < j; j--)
        {
            if (A[j] < A[j - 1])
            {
                swap(A[j], A[j - 1]);
                flag = 1;
                count++;
            }
        }
    }
    out(A, N);
    return count;
}

int main()
{
    int n;
    int a[100] = {};
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    printf("%d\n", bubbleSort(a, n));
}



Measured memory_bytes: 3232
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJDPL_1_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var NW = ReadInt();
            int N = NW[0];
            int W = NW[1];

            int[] v = new int[N];
            int[] w = new int[N];
            for (int i = 0; i < N; i++)
            {
                var input = ReadInt();
                v[i] = input[0];
                w[i] = input[1];
            }

            int[,] dp = new int[N + 1, W + 1];
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < W + 1; j++)
                {
                    dp[i + 1, j] = Math.Max(dp[i, j], dp[i + 1, j]);
                    if (j + w[i] <= W) dp[i + 1, j + w[i]] = Math.Max(dp[i + 1, j + w[i]], dp[i, j] + v[i]);
                }
            }

            Console.WriteLine(dp[N, W]);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}



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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  
  int temp;
  
  temp = a;
  a = b;
  b = temp;
  
  temp = a;
  a = c;
  c = temp;
  
  cout << a << " " << b << " " << c << endl;
  return 0;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp

class Stack(object):
    def __init__(self, num):
        self.list = []
        self.num = num
    
    def push(self, x):
        self.list.append(x)

    def pop(self):
        return self.list.pop(-1)
    
    def isEmpty(self):
        return len(self.list) == 0
    
    def isFull(self):
        return self.num <= len(self.list)



def main():
    li = list(input().split(' '))

    stack = Stack(999999)
    OPERANDS = ['+', '-', '*']
    
    for x in li:
        if not (x in OPERANDS):
            stack.push(int(x))
        else:
            b = stack.pop()
            a = stack.pop()

            if x == '+':
                stack.push(a + b)
            elif x == '-':
                stack.push(a - b)
            elif x == '*':
                stack.push(a * b)
        # print(stack.list)

    ans = stack.pop()
    print(ans)


        

main()


Measured memory_bytes: 5596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long x = sc.nextLong();
		long t = sc.nextLong();
		if(n <= x) {
			System.out.println(t);
			return;
		}
		long ans = 0;
		ans += (n / x) * t;
		n %= x;
		if(n > 0) {
			ans += t;
		}

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

	}
}



Measured memory_bytes: 35576
#include<cstdio>
#include<algorithm>
#include<vector>
long long xy[400000];
typedef std::pair<long long,long long> pii;
int main(){
    int n;
    scanf("%d",&n);
    std::vector<pii> vp;
    for(int i=0;i<n;i++){
        long long x,y;
        scanf("%lld%lld",&x,&y);
        xy[2*i]=x;
        xy[2*i+1]=y;
        if(x<y)vp.push_back({x,y});
        else vp.push_back({y,x});
    }
    std::sort(xy,xy+(2*n));
    long long xy_min=xy[0], xy_max=xy[2*n-1], smaller_max=0, larger_min=1e15;
    for(int i=0;i<n;i++){
        if(vp[i].first>smaller_max)smaller_max=vp[i].first;
        if(vp[i].second<larger_min)larger_min=vp[i].second;
    }
    long long ans1=(smaller_max-xy_min)*(xy_max-larger_min);
    std::sort(vp.begin(),vp.end());
    long long choice_min=1e15, choice_max=0, choice_dif=vp[n-1].first-vp[0].first;
    for(int i=0;i<n-1;i++){
        if(vp[i].second<choice_min)choice_min=vp[i].second;
        if(vp[i].second>choice_max)choice_max=vp[i].second;
        long long dif_tmp=std::max(choice_max,vp[n-1].first)-std::min(choice_min,vp[i+1].first);
        if(dif_tmp<choice_dif)choice_dif=dif_tmp;
    }
    long long ans2=(xy_max-xy_min)*choice_dif;
    if(ans1<ans2)ans2=ans1;
    printf("%lld\n",ans2);
    return 0;
}

Measured memory_bytes: 8432
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
  
  string s,t;
  cin>>s>>t;
  int ans=0;
  rep(i,0,3) if(s[i]==t[i])ans++;
  cout<<ans;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

signed main(){
    int N; cin>>N;
    string s,t; cin>>s>>t;
    IREP(i,N+1){
        if(s.substr(N-i,i)==t.substr(0,i)){
            cout<<2*N-i<<endl;
          break;
        }
    }
}

Measured memory_bytes: 256
/*
                        Author: Ankit Kaul
    **********************Code Belongs to Respective Author Only************************************
    */
    /*#pragma GCC optimize("O3")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
    #include <bits/stdc++.h>
    #define endl       '\n'
    #define PI          3.141592653589
    #define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #define M           1000000007
    #define int         long long int
    #define inf         INT_MAX
    #define pb          emplace_back
    #define pf          emplace_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    using namespace std;
                
    int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
    int power(int x,int n){
            int result=1;
            while(n>0)
            {   if(n % 2 ==1)
                result=(result * x) % M;
                x=(x*x)% M;
                n=n/2;
            }
        return result % M;
        }     
    signed main()
    {	int n;
    	cin>>n;
    	for(int i=1;i<=9;i++)
	   {	for(int j=1;j<=9;j++)
			{	if(i*j==n)
				{	cout<<"Yes";
					return 0;
				}
			}
	   }
	   cout<<"No";
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  rep(i, t.size()) { cout << s[i] << t[i]; }
  if(s.size() > t.size()) cout << s.back();
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

typedef pair<int,int> P;

vector<int> t[100002];

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

  for (int i = 0; i < n; i++) {
    P p;
    cin >> p.second >> p.first;
    if (m - p.second >= 0) {
      t[m - p.second].push_back(p.first);
    }
  }

  priority_queue<int,vector<int>,greater<int>> que;
  for (int i = 0; i < m; i++) {
    if (t[i].size() == 0) {
      continue;
    }
    
    for (int j = 0; j < t[i].size(); j++) {
      que.push(t[i][j]);
      if (que.size() > i + 1) {
        que.pop();
      }
    }
  }
  int ans = 0;
  while (!que.empty()) {
    ans += que.top(); que.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 6268
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	if (x == 1 || x == 2 * n - 1) {
		cout << "No" << endl;
		return 0;
	}
	if (n == 2) {
		if (x == 1 || x == 3) {
			cout << "No" << endl;
		}
		else
		printf("Yes\n1\n2\n3\n");
		return 0;

	}

	vector<int> res(2 * n - 1);
	res[n-1] = x;
	if (x == 2) {
		int now = 3;
		for (int i = 0; i < 2 * n - 1; i++) {
			if (i == n-1)
				continue;
			res[i] = (i == n - 2 ? 1 : now++);
		}
	}
	else if (x == 2 * n - 2) {
		int now = 1;
		for (int i = 0; i < 2 * n - 1; i++) {
			if (i == n-1)
				continue;
			res[i] = (i == n - 2 ? 2 * n - 1 : now++);
		}
	}
	else {
		int now = 1;

		res[n - 3] = x - 1, res[n - 2] = x + 1, res[n] = x - 2, res[n + 1] = x + 2;
		for (int i = 0; i < 2 * n - 1; i++) {
			if (now == x - 2)
				now = x + 3;
			if (abs(n-1- i) <= 2)
				continue;
			res[i] = now++;

		}
	}

	cout << "Yes" << endl;
	for (auto t : res) {
		cout << t << endl;
	}

	return 0;
}

Measured memory_bytes: 2304
A, B = map(int, input().split())

if A == 0:
  print(B)
  exit()
  
a = A - 1
rlt = ((B+1)//2 - (a+1)//2) % 2

for i in range(1, 40):
  pw1 = 2**i
  pw2 = pw1*2
  cnta = max(a % pw2 - pw1 + 1, 0)
  cntB = max(B % pw2 - pw1 + 1, 0)
  rlt += ((cntB - cnta) % 2)*pw1
  
print(rlt)

Measured memory_bytes: 61908
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var A, B, K int
	fmt.Scan(&A, &B, &K)
	rA := A - min(A, K)
	if rA > 0 {
		fmt.Println(rA, B)
	} else {
		rB := B - min(B, K-A)
		fmt.Println(0, rB)
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,k,store[200010];
queue<int> que;
signed main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>store[i];
	for(int i=0;i<k;i++)que.push(store[i]);
	for(int i=k;i<n;i++){
		int val=store[i];
		if(val<=que.front()){
			cout<<"No"<<endl;
		}
		if(val>que.front()){
			cout<<"Yes"<<endl;
		}
		que.pop();que.push(val);
	}
	return 0;
}

Measured memory_bytes: 5224
<?php

while ($line = trim(fgets(STDIN))) {
	$cards = explode(' ', $line);
	rsort($cards);
	$score = 0;
	$eleven = false;
	foreach ($cards as $c) {
		if (10 <= $c && $c <= 13) {
			$score += 10;
		} elseif (2 <= $c && $c <= 9) {
			$score += $c;
		} elseif ($c == 1) {
			if ($score + 11 <= 21) {
				$score += 11;
				$eleven = true;
			} else {
				$score += 1;
			}
		}
	}
	if ($score > 21 && $eleven) {
		$score -= 10;
	}
	if ($score > 21) {
		$score = 0;
	}
	echo $score . "\n";
}

Measured memory_bytes: 6632
while true
  h,w = gets.split.map(&:to_i)
  if h == 0 && w == 0 then break end
    arr = []
  w.times  do |i|
    if i == 0 || i.even?
      arr << "#"
    else
      arr << "."
    end
  end
   arr2 = arr.map{|x| x=="#" ? "." : "#"}.join
   arr = arr.join
  h.times do |i|
    if i == 0 || i.even?
      puts arr
    else
      puts arr2
    end
  end
    puts "\n"
end


Measured memory_bytes: 8900
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  ll mx=1000;
  ll mxnum=0;
  rep(i,0,n-1){
    chmax(mxnum,mx/a[i]);
    if(a[i]<a[i+1]){
      mx+=mxnum*(a[i+1]-a[i]);
    }
  }
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 3648
n = gets.to_i
arr = gets.chomp.split.map(&:to_i)
sum = arr.inject(:+)
a, min = 0, nil
0.upto(n-2){|i|
    a += arr[i]
    sum -= arr[i]
    diff = (a - sum).abs
    min = diff if min.nil? || min > diff
}
puts min

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

int main(){

    int N;
    cin >> N;
    vector<long long> a(N);
    for (int i=0; i<N; i++) cin >> a.at(i);

    bool flg = true;
    long long cnt = 0;

    for (int i=0; i<N; i++){
        while(a.at(i)%2 == 0){
            a.at(i) /= 2;
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3712
S = input()

atgc = ['A','T','G','C']

max_count = 0
count = 0
for i in range(len(S)):
    if S[i] in atgc:
        count+=1
    else:
        max_count = max(max_count,count)
        count = 0
max_count = max(max_count,count)
print(max_count)


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        if (!(cin >> s))
            return 0;
        int n = s.size();

        vector<vector<int> > dp(n, vector<int>(n, 0));
        vector<vector<int> > next(n, vector<int>(n, -1));
        for(int i=0; i<n; ++i)
            dp[i][i] = 1;
        for(int len=2; len<=n; ++len){
            for(int a=0; a+len-1<n; ++a){
                int b = a + len - 1;
                dp[a][b] = dp[a+1][b];
                if(dp[a][b-1] > dp[a][b]){
                    dp[a][b] = dp[a][b-1];
                    next[a][b] = 1;
                }
                if(s[a] == s[b] && dp[a+1][b-1] + 2 > dp[a][b]){
                    dp[a][b] = dp[a+1][b-1] + 2;
                    next[a][b] = 0;
                }
            }
        }

        string ret;
        int a = 0;
        int b = n-1;
        while(a < b){
            if(next[a][b] == -1){
                ++ a;
            }else if(next[a][b] == 1){
                -- b;
            }else{
                ret += s[a];
                ++ a;
                -- b;
            }
        }

        string t = ret;
        reverse(t.begin(), t.end());
        if(a == b)
            ret += s[a];
        ret += t;

        cout << ret << endl;
    }
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int n, a, ans;
	
	cin >> n;
	cin >> a;
	ans = a;
	for (int i = 1; i < n; i++)
	{
		cin >> a;
		ans = gcd(a, ans);
	}
	cout << ans << endl;
}


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

long long MOD=1000000007ll;

long long fac[200010],finv[200010],inv[200010];

void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<200010;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

long long COM(int n,int k){
	if(n<k)return 0;
	if(n<0 || k<0)return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
	int N,M,K;
	cin >> N >> M >> K;
	long long ans=0;
	COMinit();
	
	for(int d=1;d<=N;d++){
		ans+=1LL*(N-d)*M*M*d;
		ans%=MOD;
	}
	for(int d=1;d<=M;d++){
		ans+=1LL*(M-d)*N*N*d;
		ans%=MOD;
	}
	
	ans*=COM(N*M-2,K-2);
	ans%=MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long int
using namespace std;
main() 
{
	// int t;
	// cin >> t;
	// while(t--)
	// {
		int n, k, i = 1;
		cin >> n >> k;
		int hash[n+1] = {0};
		while(k--)
		{
			int d, x;
			cin >> d;
			while(d--)
			{
				cin >> x;
				hash[x] = i;
			}
			i++;
		}
		int count = 0;
		for(int i=1;i<=n;i++)
		{
			if(!hash[i])
				count++;
		}
		cout << count << endl;
	// }
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;

ll binary_searchA(vector<int>&a, int key){
    int left = -1;
    int right = a.size();
    int mid;
    while(right - left > 1){
	mid = left + (right - left)/2;
	if(a[mid] >= key)   right = mid;
	else		    left = mid;
    }
    return left + 1;
}

ll binary_searchC(vector<int>&c, int key){
    int left = -1;
    int right = c.size();
    int mid;
    while(right - left > 1){
	mid = left + (right - left)/2;
	if(c[mid] > key)   right = mid;
	else		    left = mid;
    }
    return c.size() - right;
}

int main(){
    /*input*/
    int n;  cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n);
    rep(i, n)	cin >> a[i];
    rep(i, n)	cin >> b[i];
    rep(i, n)	cin >> c[i];
    /*calculation*/
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0; 
    rep(j, b.size()){
	ans += binary_searchA(a, b[j])*binary_searchC(c, b[j]);
    }
    /*output*/
    cout << ans << endl;
}



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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  int n, maxw;
  cin >> n >> maxw;
  vecll v(n), w(n);
  rep(i,n){
    cin >> v[i] >> w[i];
  }

  vecll2(dp, n+1, maxw+1);

  rep(i,n){
    rep(j,maxw+1){
      if(j-w[i]>=0){
        dp[i+1][j] = max(v[i] + dp[i][j-w[i]], dp[i][j]);
      } else {
        dp[i+1][j] = dp[i][j];
      }
    }
  }

  prt(dp[n][maxw]);

}



Measured memory_bytes: 10828
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 17;
LL n, x;

struct exam
{
	LL l, r, b;
	LL top;
	void read()
	{
		cin >> b >> l >> r;
		top = r * x - (r - l) * b;
	}
};

exam a[N];

int cmp(exam l, exam r)
{
	return l.top > r.top;
}

LL skiky(exam e, LL treba)
{
	if (treba > e.top)
		return INF;
		
	if (treba <= e.l * e.b)
		return (treba + e.l - 1) / e.l;
		
	return (treba + e.b * (e.r - e.l) + e.r - 1) / e.r;
}

LL solve1(LL treba)
{
	LL ans = 0;
	
	int last_full = -1;
	for(int i = 0; i < n && treba > 0; ++i)
	{
		if (treba >= a[i].top)
		{
			last_full = i;
			treba -= a[i].top;
			ans += x;
			continue;
		}
		
		break;				
	}
	
	LL tut = INF;
	
	FOR(i, last_full + 1, n)
		tut = min(tut, skiky(a[i], treba));
	
	if (last_full == n - 1)
		tut = 0;
		
	ans += tut;
	return ans;
}

LL get(exam e, LL vykyn)
{
	assert(e.top >= vykyn);
	if (vykyn <= e.r * (x - e.b))
		return vykyn / e.r;
	
	return x - (e.r * (x - e.b) + e.l * e.b - vykyn + e.l - 1) / e.l;
}

LL solve2(LL treba)
{
	LL ans = 0;
	
	int last_full = -1;
	for(int i = 0; i < n && treba > 0; ++i)
	{
		if (treba >= a[i].top)
		{
			last_full = i;
			treba -= a[i].top;
			ans += x;
			continue;
		}
		
		break;				
	}
	
	if (last_full == n - 1)
	{
		assert(treba <= 0);
		return ans;
	}
	
	treba -= a[last_full + 1].top;
	ans += x;
	
	LL vykyn = -treba;
	
	LL best = 0;
	FOR(i, 0, last_full + 1)	
		best = max(best, get(a[i], vykyn));
		
	assert(best < x);
	ans -= best;
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);

	cin >> n >> x;
	FOR(i, 0, n)
		a[i].read();
	
	LL treba = 0;
	sort(a, a + n, cmp);
	FOR(i, 0, n)
		treba += a[i].l * a[i].b;
	
	cout << min(solve1(treba), solve2(treba)) << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main() {
	int X; cin >> X;
	int res_500 = (X / 500) * 1000;
	X %= 500;
	int res_5 = (X / 5) * 5;
	cout << (res_500 + res_5) << endl;
	return 0;
}

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

int main(void) {

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

  while(n > 0){
    if(n % 10 == 7){
      printf("Yes");
      return 0;
    }
    n/=10;
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 1736
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 1e5 + 500;

vector < int > v[N], put;
int n, bio[N], m;

void dfs(int x){
    bio[x] = 1;
    put.push_back(x);
    for(int y : v[x]){
        if(bio[y]) continue;
        dfs(y);
        return;
    }
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i = 0;i<m;i++){
        int x, y;scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1);
    reverse(put.begin(), put.end());
    for(int y : v[1]){
        if(bio[y]) continue;
        dfs(y);
        break;
    }
    printf("%d\n", put.size());
    for(int x : put)
        printf("%d ", x);
    printf("\n");

}


Measured memory_bytes: 10104
import java.util.*;

public class Main {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }

        long ans = solve3(N, A);

        System.out.println(ans);
    }

    private static int solve(int N, int[] A) {
        int sad = Integer.MAX_VALUE;

        int minB = A[0]-1, maxB = A[0]-1;
        for (int i=1; i<N; i++) {
            int b = A[i] - (i+1);
            minB = Math.min(minB, b);
            maxB = Math.max(maxB, b);
        }


        for (int b=minB; b<=maxB; b++) {
            sad = Math.min(sad, calcSad(N, A, b));
        }

        return sad;
    }

    private static int solve2(int N, int[] A) {
        int minSad = Integer.MAX_VALUE;

        for (int i=0; i<N; i++) {
            int b = A[i] - (i+1);
            minSad = Math.min(minSad, calcSad(N, A, b));
        }

        return minSad;
    }

    private static long solve3(int N, int[] A) {
        for (int i=0; i<N; i++) {
            A[i] -= i+1;
        }
        Arrays.sort(A);

        long minSad = calcSad2(N, A, A[N/2]);

        return minSad;
    }

    private static int calcSad(int N, int[] A, int b) {
        int sad = 0;

        for (int i=0; i<N; i++) {
            sad += Math.abs(A[i] - (b+i+1));
        }

        return sad;
    }

    private static long calcSad2(int N, int[] A, int b) {
        long sad = 0;

        for (int i=0; i<N; i++) {
            sad += Math.abs(A[i] - b);
        }

        return sad;
    }
}


Measured memory_bytes: 64400
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 61;
const lli INF = 1e18;
const lli MOD = 13;
const double EPS=1e-4;

bool m[N];
vi primes(1,2);
void sieve(){
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7


int main(){_
	string s,t; cin>>s>>t;
	int u = 0;
	fore(i,0,sz(s)){
		if(i>=sz(t))u++;
		else if(s[i]!=t[i])u++;
	}
	cout<<u<<ENDL;

}


Measured memory_bytes: 3768
#include <stdio.h>

struct Card {
	char suit, value;
};

void bubbleSort(struct Card C[],int N);
void selectionSort(struct Card C[],int N);
int isStable(struct Card C1[], struct Card C2[], int N);



int main(void)
{
	int i,n;
	scanf("%d", &n);
	struct Card a1[n],a2[n];
	
	for(i=0; i<n; i++){
		scanf(" %c %c", &a1[i].suit,&a1[i].value);
	}
	
	for(i = 0; i<n; i++){
		a2[i]=a1[i];
	}
	
	bubbleSort(a1,n);
	selectionSort(a2,n);
	
	for(i=0; i<n; i++){
		if(i < n-1){
			printf("%c%c ",a1[i].suit,a1[i].value);
		}
		else{
			printf("%c%c\n",a1[i].suit,a1[i].value);
		}
	}
	printf("Stable\n");
	
	for(i=0; i<n; i++){
		if(i < n-1){
			printf("%c%c ",a2[i].suit,a2[i].value);
		}
		else{
			printf("%c%c\n",a2[i].suit,a2[i].value);
		}
	}
	
	if(isStable(a1,a2,n) == 1){
		printf("Not stable\n");
	}
	else{
		printf("Stable\n");
	}
	return 0;
}

void bubbleSort(struct Card C[],int N)
{
	int i,j;
	struct Card tmp;
	for(i=0; i<=N-1; i++){
		for(j=N-1; j>=1; j--){
			if(C[j].value < C[j-1].value){
				tmp=C[j];
				C[j]=C[j-1];
				C[j-1]=tmp;
			}
		}
	}
}


void selectionSort(struct Card C[],int N)
{
	int i,j,minj;
	struct Card tmp;
	for(i=0; i<=N-1; i++){
		minj=i;
		for(j=i; j<=N-1; j++){
			if(C[j].value < C[minj].value){
				minj=j;
			}
		}
		tmp=C[i];
		C[i]=C[minj];
		C[minj]=tmp;
	}
}

int isStable(struct Card C1[], struct Card C2[], int N)
{
	int i;
	for(i=0; i<N; i++){
		if(C1[i].suit != C2[i].suit){
			return 1;
		}
	}
	return 0;
}



Measured memory_bytes: 2092
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long int ll;
ll gcd(ll a,ll b){
  if(a<b) gcd(b,a);
  while(1){
    ll r=a%b;
    if(r==0) break;
    a=b;
    b=r;
  }
  return b;
}
int main(){
  ll n,x,cnt;
  cin >> n>>x;
  ll xx[n+1];
  xx[0]=x;
  ll d[n];
  for(int i=1;i<n+1;i++){
    cin >>xx[i];
  }
  sort(xx,xx+n+1);
  ll c=1e9;
  for(int i=0;i<n;i++){
    ll t=abs(xx[i+1]-xx[i]);
    if(i==0) c=t;
    else c=gcd(t,c);
  }
  cout <<c<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n,count;
  n = s.size();
  count = 0;
  if(n % 2 == 0){
    for(int i=0;i<(n+1)/2;i++){
      if(s.at(i)!=s.at(n-i-1)){
        count++;
      }
    }
  }else{
    for(int j=0;j<(n-1)/2;j++){
      if(s.at(j)!=s.at(n-j-1)){
        count++;
      }
    }
  }
    cout << count << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
char c[20][20];
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(c-1)/max(a,b)+1<<endl;
}


Measured memory_bytes: 256
def five(x):
    cnt1 = 0
    while x%5==0:
        cnt1+= 1
        x = x//5
    cnt2 = 0
    while x%2==0:
        cnt2+= 1
        x = x//2
    return (min2(cnt1,18), min2(cnt2,18))

def min2(x,y):
    return x if x < y else y

import sys
input = sys.stdin.readline

N = int(input())
F = []
for i in range(N):
    A = float(input())
    A = round(A*(10**9))
    F.append(five(A))

F.sort()
j = 0
temp = 0
dp = [0]*19
k = 0
for i in range(N-1):
    if N-1-j < i:
        dp[min2(F[i][1], 18)] -= 1
    while N-1-j> i and F[i][0]+F[N-1-j][0] >= 18:
        dp[min2(F[N-1-j][1],18)] += 1
        j += 1
    k = sum(dp[:18-F[i][1]])
    temp += min2(j, N-i-1) - k

print(temp)


Measured memory_bytes: 86820
#include <iostream>
#include <array>

using ll = long long;
using namespace std;

int main() {
    array<int, 101> A = {};
    fill(A.begin()+1, A.end(), 10000);
    int n;
    cin >> n;
    int B[2] = {4, 7};
    for (int i = 1; i < 101; ++i) {
        for (auto &&b : B) {
            if(b <= i && A[i-b] != 10000){
                A[i] = min(A[i-b] + 1, A[i]);
            }
        }
    }

    cout << (A[n] < 10000 ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef long long unsigned int llu;
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define YUGEN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lp(i,start,end) for(int i=start;i<end;i++)
#define MAX 105
#define test() ll t; cin>>t; while(t--)
using namespace std;
ll gcd(ll a,ll b) {if (a==0) return b;return gcd(b%a,a);}
int main()
 {
    YUGEN;
    ll n,x,t;
    cin>>n>>x>>t;
        if(n%x!=0)
        cout<<((n/x)+1)*t;
        else
            cout<<(n/x)*t;

}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define INF 100000000;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	cin >> s;
	ll ans = 0,tmp;
	for (int bit = 0; bit < (1 << (s.size()-1)); ++bit) {
		tmp = s[0]-'0';
		//bit全探索
		for (int i = 0; i < (s.size()-1); ++i) {
			// + ならそれまでの数値をansに代入し、tmpは次の数値に更新
			if ((bit >> i) & 1) {
				ans += tmp;
				tmp =s[i+1]-'0';
			}
			else tmp= tmp * 10 + (s[i+1] - '0');
		}
		ans += tmp;
	}
	cout << ans << endl;

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int h, w;
  cin >> h >> w;
  vstr s(h);
  cin >> s;
  using P = tuple<int, int, int>;
  queue<P> q;
  vector<vi32> dp(h, vi32(w, 1e9));
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#') {
      q.emplace(i, j, 0);
    }
  }
  while (q.size()) {
    int x, y, c;
    tie(x, y, c) = q.front();
    q.pop();
    if (dp[x][y] != 1e9) {
      continue;
    }
    dp[x][y] = c;
    rep(i, 4) {
      int wx = x + dx[i];
      int wy = y + dy[i];
      if (wx < 0 || wx >= h || wy < 0 || wy >= w) continue;
      q.emplace(wx, wy, c + 1);
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) {
    amax(ans, dp[i][j]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 53576