akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while (!(line = br.readLine()).equals("0 0")) {
            int w = Integer.parseInt(line.substring(0, line.indexOf(' ')));
            int h = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
            char[][] map = new char[h + 2][w + 2];

            ArrayDeque<int[]> queue = new ArrayDeque<int[]>();
            int count = 0;

            for (int i = 1; i < h + 1; i++) {
                line = br.readLine();
                for (int j = 1; j < w + 1; j++) {
                    map[i][j] = line.charAt(j - 1);
                    if (map[i][j] == '@') {
                        queue.offer(new int[]{i, j});
                        map[i][j] = '#';
                        count++;
                    }
                }
            }

            int[][] dir = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
            while (queue.size() > 0) {

                int[] curr = queue.poll();
                char tile;
                for (int i = 0; i < dir.length; i++) {
                    tile = map[curr[0] + dir[i][0]][curr[1] + dir[i][1]];
                    if (tile == '.') {
                        queue.offer(new int[]{
                                curr[0] + dir[i][0], curr[1] + dir[i][1]
                        });
                        map[curr[0] + dir[i][0]][curr[1] + dir[i][1]] = '#';
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}

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


int main()
{
    int n, d;
    cin >> n >> d;
    int x[10][10];
    for (int i=0; i < n; ++i) {
        for (int j=0; j < d; ++j) {
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i=0; i < n; ++i) {
        for (int j=i+1; j < n; ++j) {
            int sum = 0;
            for (int k=0; k < d; ++k) {
                int t = x[i][k] - x[j][k];
                sum += t*t;
            }
            for (int k=0; k*k <= sum; ++k) {
                if (k*k == sum) {
                    ++ans;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  string s, t;
  cin >> s >> t;

  string ss = s + s;
  bool match = false;
  re(i, s.size()) {
    string u;
    re(j, s.size()) u += ss[i+j];
    if(u == t) match = true;
  }
  if(match) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
S=list(map(int,input().split()))
n=int(input())
 
for i in range(n):
  q=list(map(int,input().split()))
  if q in [[S[3],S[1]],[S[1],S[2]],[S[2],S[4]],[S[4],S[3]]]:
           print(S[0])
            
  if q in [[S[0],S[3]],[S[3],S[5]],[S[5],S[2]],[S[2],S[0]]]:
           print(S[1])
            
  if q in [[S[0],S[1]],[S[1],S[5]],[S[5],S[4]],[S[4],S[0]]]:
           print(S[2])
            
  if q in [[S[4],S[5]],[S[5],S[1]],[S[1],S[0]],[S[0],S[4]]]:
           print(S[3])
            
  if q in [[S[0],S[2]],[S[2],S[5]],[S[5],S[3]],[S[3],S[0]]]:
           print(S[4])
   
  if q in [[S[2],S[1]],[S[1],S[3]],[S[3],S[4]],[S[4],S[2]]]:
           print(S[5])


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

#define MP make_pair
#define FF first
#define SS second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pie;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const ll LINF = 4e18;
const ll delta = 1634569;

const int N = 1e6 + 20;
ll dp[N], n, sum;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	dp[0] = 1;
	dp[1] = n;
	sum = n + 1;
	for (int i = 2; i <= n; i++) {
		dp[i] = ((n - i + 1) * n + (i - 2) * (n - 1) + sum - dp[i - 2] + MOD) % MOD;
		sum = (sum + dp[i]) % MOD;
	}
	cout << dp[n] << endl;
}



Measured memory_bytes: 8064
#include <stdio.h>
#include <math.h>
int line[101],line1[1001];
int main(void){
    int sum,min,i,o;
    for(;min=1000000,scanf("%d",&sum),sum;){
        for(i=0;i<101;i++){
            if(!line[i])
                line[i]=(int)pow(i,3);
            if(line[i]>sum)
                break;
            for(o=0;o<1001;o++){
                if(!line1[o])
                    line1[o]=(int)pow(o,2);
                if(line[i]+line1[o] > sum)
                    break;
                if(sum-line[i]-line1[o]+i+o < min)
                    min=(sum-line[i]-line1[o]+i+o);
            }
        }
        printf("%d\n",min);
    }
    return 0;
}

Measured memory_bytes: 664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int n,k,a[maxn],ans=0;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> k;
	rep(n) cin >> a[i];
	rep(n) ans+=a[i]>=k;
	print1(ans);
	return 0;
}

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

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

char s[10];
int ask(int n) {
	printf("%d\n", n);
	fflush(stdout);
	scanf("%s", s);
	if (s[0] == 'V') return -1;
	if (s[0] == 'M') return 1;
	return 0;
}

int main() {
	start = clock();

	int n;
	scanf("%d", &n);
	int l = 0, r = n, ends[2];
	ends[0] = ask(0);
	ends[1] = ends[0];
	if (ends[0] == -1) return 0;

	while (abs(l - r) > 1) {
		int m = (l + r) / 2;
		int t = ask(m);
		if (t == -1) break;
		if ((((m - l) % 2) ^ t ^ ends[0]) == 0) {
			l = m;
			ends[0] = t;
		}
		else {
			ends[1] = t;
			r = m;
		}
	}

	Time(false);
	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll ans=0;
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    ans+=a[i]/2;
  }
  ll temp=0;
  for(ll i=0;i<n;i++) {
    temp+=a[i]%2;
    if(a[i]==0) {
      ans+=temp/2;
      temp=0;
    }
  }
  ans+=temp/2;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  vector<ll> cnt(5, 0);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    switch (s[0]) {
      case 'M':
      cnt[0]++;
      break;
      case 'A':
      cnt[1]++;
      break;
      case 'R':
      cnt[2]++;
      break;
      case 'C':
      cnt[3]++;
      break;
      case 'H':
      cnt[4]++;
      break;
    }
  }
  ll ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 4; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

while True:
    n = int(input())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split()
        x[k] = v
    y = []
    for i in range(int(input())):
        a = sys.stdin.readline().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Measured memory_bytes: 8692
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define dmin(x, y) ((x) < (y) ? (x) : (y))
#define dmax(x, y) ((x) > (y) ? (x) : (y))
#define checkmax(x, y) ((x) < (y) ? ((x) = (y)) : (x))
#define checkmin(x, y) ((x) > (y) ? ((x) = (y)) : (x))
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
  int aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
ll rdll() {
  ll aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
const int MAXN = 110;
int n, k;
inline void work() {
  n = rdint();
  k = rdint();
  int m = n * (n - 1) / 2 - k;
  if(m < n - 1) {
    m = -1;
  }
  printf("%d\n", m);
  if(m != -1) {
    int tmp = n - 1;
    while(m > 0) {
      Forx(i, n - tmp + 1, min(n, n - tmp + m)) {
        printf("%d %d\n", n - tmp, i);
      }
      m -= tmp--;
    }
  }
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}


Measured memory_bytes: 256
'use strict'

const Main = (input) => {
  const tmp = input.trim().split('\n')
  const N = parseInt(tmp[0])
  const aArr = tmp[1].split(' ').map(Number)

  let result = 0

  for (let i = 0; i < N; i++) {
    let tmpNum = aArr[i]
    let loop = true
    while (loop) {
      if ((tmpNum % 2) === 0) {
        tmpNum = tmpNum / 2
        result += 1
      } else {
        loop = false
      }
    }
  }

  console.log(result)
  return result
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 21320
import itertools

def resolve():
    n, m = map(int, input().split())
    S = [[0]*n for i in range(n)]

    for i in range(m):
        a, b = map(int, input().split())
        S[a-1][b-1] = 1
        S[b-1][a-1] = 1

    ans = 0
    for p in itertools.permutations(range(n)):
        if p[0] != 0:
            break
        tmp = 1
        for i in range(n-1):
            tmp *= S[p[i]][p[i+1]]
        ans += tmp

    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3064
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

/// Number of k-combinations
T combination(T = long)(T n, T k)
{
    assert(0 <= k);
    assert(0 <= n);
    if (n < k)
        return 0;
    k = min(n - k, k);
    if (k == 0)
        return 1;
    if (k == 1)
        return n;
    return memoize!combination(n - 1, k - 1) + memoize!combination(n - 1, k);
}

void main()
{
    long N, M;
    scan(N, M);
    auto dist = new long[](N);
    auto roots = iota(N).array();
    long root(long x)
    {
        if (roots[x] == x)
            return x;
        long parent = roots[x];
        roots[x] = root(parent);
        dist[x] += dist[parent];
        return roots[x];
    }

    foreach (_; 0 .. M)
    {
        long L, R, D;
        scan(L, R, D);
        L--;
        R--;
        long rL = root(L);
        long rR = root(R);
        if (rL != rR)
        {
            roots[rR] = rL;
            dist[rR] = dist[rL] + D + (dist[L] - dist[R]);
        }
        else if (dist[L] + D != dist[R])
        {
            writeln("No");
            return;
        }
    }
    // writeln(dist);
    writeln("Yes");
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const long double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,m;
vl a;

int main(){
	cin>>n>>m;
	a=vl(n);
	for(auto &i:a) cin>>i;
	long double X=0,Y=0;
	for(int i=0;i<n;i++){
		int t=n-2;
		for(int j=(i+1)%n;t;j=(j+1)%n){
			long double arg=pi*(a[i]+a[j]+(j<i?m:0))/m;
			X+=cos(arg)*t;
			Y+=sin(arg)*t;
			t--;
		}
	}
	X/=n*(n-1)*(n-2)/6;
	Y/=n*(n-1)*(n-2)/6;
	cout<<syosu(11)<<X<<' '<<Y<<endl;
}

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

int main(void)
{
  int a, b ,c ,k;
  cin >> a >> b >> c >> k;
  if(a >= k)
  {
    cout << k << endl;
  }else if(a + b >= k){
    cout << a << endl;
  }else if(a + b + c >= k){
    cout << a -(k - a -b) << endl;
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, yen;
	cin >> n >> yen;

	int x = -1, y = -1, z = -1;

	rep(i, n + 1)rep(j, n + 1) {
		if (i + j > n)continue;
		int k = n - i - j;
		if ((ll)i * 10000 + j * 5000 + k * 1000 == yen) {
			x = i, y = j, z = k;
			break;
		}
	}
	
	cout << x << " " << y << " " << z << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
//一点更新区間取得
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	function<T(T,T)>calcfn;
	function<T(T,T)>updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree():n(0){};
	segtree(int n_,T defvalue_=numeric_limits<T>::max(),
		function<T(T,T)>calcfn_=[](T a,T b){return a<b?a:b;},
		function<T(T,T)>updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		init(n_);
	};
	void init(int n_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(vector<T>v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i++)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query_(int a,int b,int i,int l,int r)
	{
		if(r<=a||b<=l)return defvalue;
		else if(a<=l&&r<=b)return dat[i];
		else
		{
			return calcfn(
				query_(a,b,i*2+1,l,(l+r)/2),
				query_(a,b,i*2+2,(l+r)/2,r)
			);
		}
	}
	T query(int a,int b)//[a,b)
	{
		return query_(a,b,0,0,n);
	}
};
main()
{
	int n,q;cin>>n>>q;
	segtree<int>rmq(n);
	for(int i=0;i<q;i++)
	{
		int c,x,y;cin>>c>>x>>y;
		if(c)cout<<rmq.query(x,y+1)<<endl;
		else rmq.update(x,y);
	}
}


Measured memory_bytes: 3896
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	n=n%1000;
	if(n==0){
		printf("0\n");
	}
	else{
		printf("%d\n",1000-n);
	}
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll a, ll b){
   if(b == 0) return a;
   return gcd(b, a % b);
}
int main(){
   int n; cin >> n;
   vector<int> p(n);
   rep(i,n) cin >> p[i];
   vector<int> q(n + 1);
   for(int i = 1; i < n + 1; i++){
      q[i] = p[i - 1] + q[i - 1];
   }
   int diff_min = N;
   int ans = 0;
   for(int i = 1; i < n + 1; i++){
      if(q[i] - q[i - 1] < diff_min){
         ans++;
         diff_min = q[i] - q[i - 1];
      }
   }
   cout << ans << endl;
}

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

int main(){
  
    int N,sum=0,x,ans=0;
    cin>>N;
    vector<int> S(N);
    for(int i=0;i<N;i++){
        cin>>S.at(i);
        sum+=S.at(i);
    }
    if(sum>=0){
        if(sum-sum/N*N<=((sum/N+1)*N-sum)) x=sum/N;
        else x=sum/N+1;
    }
    else{
        if(sum/N*N-sum<=(sum-(sum/N-1)*N)) x=sum/N;
        else x=sum/N-1;
    }
    for(int i=0;i<N;i++){
        ans+=((S.at(i)-x)*(S.at(i)-x));
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main(){
    int n;
    int num;
    int i;

    vector<int> a;

    cin >> n;

    for(i = 0; i < n; i++){
        cin >> num;
        a.push_back(num);
    }
    for(i = 0; i < n; i++){
        if(i == (n-1)){
            cout << a[n-(i+1)];
        }else{
            cout << a[n-(i+1)] << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	string a, b, c;
	cin >> a >> b >> c;
	char d = 'A' - 'a';
	char aa = a[0] + d;
	char bb = b[0] + d;
	char cc= c[0] + d; 
	cout << aa<<bb<<cc <<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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


const int BIG_NUM = 1e8;

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b;

}

Measured memory_bytes: 3628
//https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_b
//B - Red or Blue
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N; cin>>N;
    string s; cin>>s;
    ll r=0,b=0;
    for(auto& c:s){
        if(c=='R')++r;
        else ++b;
    }
    cout<<(r>b?"Yes":"No")<<endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    int D; cin >> D;
    if (m.count(D)) m[D]++;
    else m[D] = 1;
  }
  int M; cin >> M;
  vector<int> T(M);
  for (int i = 0; i < M; i++) cin >> T.at(i);
  bool can = true;
  for (int i = 0; i < M; i++) {
    if (m.count(T.at(i)) && m[T.at(i)] > 0) {
      m[T.at(i)]--;
      continue;
    }
    can = false;
  }
  if (can) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main () {
    int N;
    cin >> N;
    bool flag = false;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (N == i*j) flag = true;
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,M;
  cin>>N>>M;
  ll H[N];
  int A[M],B[M];
  rep(i,N) cin>>H[i];
  rep(i,M){
    cin>>A[i]>>B[i];
  }
  int best[N];
  rep(i,N)best[i]=1;
  rep(i,M){
    if(H[A[i]-1]>=H[B[i]-1])
      best[B[i]-1]=0;
    if(H[A[i]-1]<=H[B[i]-1])
      best[A[i]-1]=0;
  }
  int ans=0;
  rep(i,N){
    if(best[i]==1)
      ans+=1;
  }
  cout<<ans<<endl;
      

}


Measured memory_bytes: 5600
n = int(input())
button_list = []
for i in range(n):
    a = int(input())
    button_list.append(a)

status = 1
count = 0


def press_button(n):
    status = button_list[n-1]
    return status

while status != 2:
    status = press_button(status)
    count += 1
    if count >= 100000:
        print(-1)
        exit()


print(count)

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int mod = 1e9 + 7;
int main()
{
	SPEED
	int H, W;
	cin >> H >> W;
	char ch;
	vector<vector<int>> grid(H, vector<int>(W,0));
	vector<vector<int>> visited(H, vector<int>(W,0));
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			cin >> ch;
			if (ch=='#')
			{
				grid[i][j] = -1;
			}
		}
	}
	grid[0][0] = 1;
	queue<pair<int, int>> q;
	q.push(mp(0,0));
	pair<int, int> temp1, temp2;
	while(!q.empty())
	{
		temp1 = q.front();
		q.pop();
		int curr_i = temp1.fi;
		int curr_j = temp1.se;
		if (curr_i < H-1)
		{
			if (grid[curr_i+1][curr_j]!=-1)
			{
				grid[curr_i+1][curr_j] += grid[curr_i][curr_j];
				grid[curr_i+1][curr_j] %= mod;
				if (visited[curr_i+1][curr_j]==0)
				{
					q.push(mp(curr_i+1, curr_j));
					visited[curr_i+1][curr_j] = 1;
				}
			}
			
		}
		if (curr_j < W-1)
		{
			if (grid[curr_i][curr_j+1]!=-1)
			{
				grid[curr_i][curr_j+1] += grid[curr_i][curr_j];
				grid[curr_i][curr_j+1] %= mod;
				if (visited[curr_i][curr_j+1]==0)
				{
					q.push(mp(curr_i, curr_j+1));
					visited[curr_i][curr_j+1] = 1;
				}
				
			}
			
		}
	}
	/*
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			cout << grid[i][j] << " ";
		}
		cout << '\n';
	}*/

	cout << grid[H-1][W-1];
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
long long a[N];
int main()
{
	int n;
	cin >>n;
	for(int i=1;i<=n;i++)
		cin >>a[i];
	int max1=0,cnt=0;
	for(int i=1;i<n;i++){
		if(a[i]>=a[i+1]){
			cnt++;
			if(cnt>max1) 
				max1=cnt;
		} 
		else{	
			cnt=0;
		}	
	}
	cout<<max1<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vvi imos(1010, vi(1010));
    for (int i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        imos[x1][y1]++;
        imos[x1][y2]--;
        imos[x2][y1]--;
        imos[x2][y2]++;
    }
    for (int i = 0; i < 1010; i++) {
        for (int j = 0; j < 1010 - 1; j++) {
            imos[i][j + 1] += imos[i][j];
        }
    }
    for (int i = 0; i < 1010 - 1; i++) {
        for (int j = 0; j < 1010; j++) {
            imos[i + 1][j] += imos[i][j];
        }
    }

    i64 nax = 0;
    for (int i = 0; i < 1010; i++) {
        for (int j = 0; j < 1010; j++) {
            nax = max(nax, imos[i][j]);
        }
    }
    cout << nax << endl;
}


Measured memory_bytes: 10828
import itertools
n,m,x =map(int,input().split())
lists=[]
understand=[0]*m
num= [0,1]
ans = 10**10000
patterns = list(itertools.product(num, repeat=n))
for i in range(n):
    lists.append(list(map(int,input().split())))
total =0
#本を買う組み合わせ
for i in patterns:
    pattern = list(i)
    total =0
    understand=[0]*m
    for l in range(n):
        if pattern[l] ==1:
            total += lists[l][0]
            for k in range(m):
                understand[k] += lists[l][k+1]
    understand.sort()
    if understand[0] >= x:
        ans = min(ans,total)
if ans == 10**10000:
    print(-1)
else:
    print(ans)




Measured memory_bytes: 9544
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] c = new char[h][w];
        int[] dx = {1,0,-1,0,1,-1,-1,1};
        int[] dy = {0,1,0,-1,1,1,-1,-1};
        for (int i=0;i<h;i++){
            c[i]=sc.next().toCharArray();
        }
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++){
                if (c[i][j]!='#'){
                    int num = 0;
                    for (int d=0;d<8;d++){
                        int ni = i +dy[d];
                        int nj = j +dx[d];
                        if (ni<0||h<=ni)continue;
                        if (nj<0||w<=nj)continue;
                        if (c[ni][nj]=='#')num++;
                    }
                    c[i][j] = (char)(num+'0');
                }
                System.out.print(c[i][j]);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 36436
#include<iostream>
#include <vector>
#include<cstdio>
using namespace std;

vector<vector<int>> beki(int n){
    vector<vector<int>> vc;
    vector<int> org;
    for(int i=0; i<n; i++){
        org.push_back(i);
    }
    for (int i=0; i<(1<<n); i++){
        vector<int> v;
        for (int j=0; j<n; j++){
            if ((i>>j) & 1){
                v.push_back(org.at(j));
            }
        }
        vc.push_back(v);
    }
    return vc;
}

int count(char ar[6][6], int h, int w){
    int cnt = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(ar[i][j] == '#') cnt++;
        }
    }
    return cnt;
}

void cp(char ar[6][6], char orig[6][6], int h, int w){
        for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            ar[i][j] = orig[i][j];
        }
    }
}
 
int main(){
  int h,w,k;
  char ar[6][6] = {{}};
  char tmp[6][6] = {{}};

  cin >> h >> w >> k;
  for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
          cin >> ar[i][j];
      }
  }

  vector<vector<int>> vvh = beki(h);
  vector<vector<int>> vvw = beki(w);
  int cnt = 0;

  for(int i=0; i<vvh.size(); i++){
      for(int j=0; j<vvw.size(); j++){
            cp(tmp, ar, h, w);
            vector<int> vh = vvh.at(i);
            vector<int> vw = vvw.at(j);
            for(int k=0; k<vh.size(); k++){
                for(int l=0; l<w; l++){
                    tmp[vh.at(k)][l] = 'x';
                }
            }
            for(int k=0; k<vw.size(); k++){
                for(int l=0; l<h; l++){
                    tmp[l][vw.at(k)] = 'x';
                }   
            }
            if(count(tmp, h, w) == k) cnt++;
      }
  }
  cout << cnt << endl;
}

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

constexpr int INF = 1e9;

struct edge {
    int to, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

int main() {
    int N, M, C;
    while(cin >> N >> M >> C, N) {
        graph g(N);
        for(int i=0; i<M; ++i) {
            int f, t, c;
            cin >> f >> t >> c;
            f--; t--;
            g[f].push_back(edge{t, c});
        }
        vector<vector<int>> d(N, vector<int>(N, INF));
        d[0][0] = 0;
        using state = tuple<int, int, int>;
        priority_queue<state, vector<state>, greater<state>> que;
        que.push(make_tuple(0, 0, 0));
        while(!que.empty()) {
            int cd, cnt, v;
            tie(cd, cnt, v) = que.top();
            que.pop();
            if(d[cnt][v] < cd) {
                continue;
            }
            for(auto& e : g[v]) {
                if(cnt + 1 < N && e.cost != 0 && d[cnt+1][e.to] > d[cnt][v]) {
                    d[cnt+1][e.to] = d[cnt][v];
                    que.push(make_tuple(d[cnt+1][e.to], cnt+1, e.to));
                }
                if(d[cnt][e.to] > d[cnt][v] + e.cost) {
                    d[cnt][e.to] = d[cnt][v] + e.cost;
                    que.push(make_tuple(d[cnt][e.to], cnt, e.to));
                }
            }
        }
        int res = N+1;
        for(int i=0; i<N; ++i) {
            if(d[i][N-1] <= C) {
                res = i;
                break;
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3164
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

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

    int n;
    while(cin>>n,n){
        int d;cin>>d;
        vector<string> name(n);
        for(int i=0;i<n;i++) cin>>name[i];
        sort(name.begin(),name.end());
        vector<set<string>> s(n);
        for(int i=0;i<n;i++){
            int len=name[i].length();

            // delete
            s[i].insert(name[i].substr(0,len-1));
            s[i].insert(name[i].substr(1,len-1));
            for(int j=1;j<len-1;j++){
                string tmp=name[i].substr(0,j);
                tmp+=name[i].substr(j+1,len-1-j);
                s[i].insert(tmp);
            }

            // swap
            for(int j=1;j<len;j++){
                string tmp=name[i];
                char c=tmp[j];
                tmp[j]=tmp[j-1];
                tmp[j-1]=c;
                s[i].insert(tmp);
            }

            // insert
            for(char c='a';c<='z';c++){
                string tmp=""; tmp+=c;
                tmp+=name[i];
                s[i].insert(tmp);

                tmp=name[i]; tmp+=c;
                s[i].insert(tmp);
            }
            for(int j=1;j<len;j++){
                for(char c='a';c<='z';c++){
                    string tmp=name[i].substr(0,j);
                    tmp+=c;
                    tmp+=name[i].substr(j,len-j);
                    s[i].insert(tmp);
                }
            }

            // replace
            for(int j=0;j<len;j++){
                for(char c='a';c<='z';c++){
                    if(name[i][j]==c) continue;
                    string tmp=name[i];
                    tmp[j]=c;
                    s[i].insert(tmp);
                    //cout<<tmp<<endl;
                }
            }
            //cout<<s[i].size()<<endl;
            
        }
        int res=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                bool one=false,two=false;
                if(s[j].find(name[i])!=s[j].end()) one=true;
                if(s[i].find(name[j])!=s[i].end()) one=true;

                for(auto itr=s[i].begin();itr!=s[i].end();itr++){
                    string ss=*itr;
                    if(s[j].find(ss)!=s[j].end()) two=true;
                }

                if(d==1){
                    if(one){
                        cout<<name[i]<<","<<name[j]<<endl;
                        res++;
                    }
                }
                else{
                    if(one || two){
                        cout<<name[i]<<","<<name[j]<<endl;
                        res++;
                    }
                }
            }
        }
        cout<<res<<endl;
    }
}


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

int main() {
  long n, k;
  double ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    double kak = 1;
    long j = i + 1;
    while (j < k) {
      kak *= 0.5;
      j *= 2;
    }
    ans += kak / n;
  }
  cout << fixed << setprecision(9);
  cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int m,d,i;
  scanf("%d %d",&m,&d);

  while(m!=0){

    int day=0;

    for(i=0;i<m;i++){
      if(i!=0){day+=30;}
      if(i%2==1 && i<8){day++;}
      else if(i==2){day--;}
      else if(i==8){day++;}
      else if(i%2==0 && i>8){day++;}
    }
  
    day+=d;
  
    if(day%7==0){puts("Wednesday");}
    else if(day%7==1){puts("Thursday");}
    else if(day%7==2){puts("Friday");}
    else if(day%7==3){puts("Saturday");}
    else if(day%7==4){puts("Sunday");}
    else if(day%7==5){puts("Monday");}
    else if(day%7==6){puts("Tuesday");}

    scanf("%d %d",&m,&d);
  }
  
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

int main() {
	int N;
	cin >> N;
	char s[100];

	for (int i = 0; i < N; i++) {
		cin >> s[i];
		if (s[i] == 'Y') {
			cout << "Four";
			return 0;
		}
	}
	cout << "Three";
}

Measured memory_bytes: 256
data = input()
l = data.split()
l = list(map(int, l))
p = l[1] - l[2]

points = [p for i in range(l[0])]

for i in range(l[2]):
    a = int(input()) - 1
    points[a] += 1

for p in points:
    if p <= 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 6592
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
using namespace std;

#define max_n 100000
#define max_m 100
#define max_w 10000
#define max_h 1000
#define INF 1000000000

typedef long long lint;





int main()
{
    char s[max_n];
    cin>>s;
    size_t len=strlen(s);
    for(int i=len-1;0<=i;){
        if(s[i]=='r'){
            if(s[i-1]=='e'&&s[i-2]=='m'){
                if(s[i-3]=='a'&&s[i-4]=='e'&&s[i-5]=='r'&&s[i-6]=='d'){
                    i-=7;
                }else{
                    cout<<"NO"<<endl;
                    break;
                }
            }else if(s[i-1]=='e'&&s[i-2]=='s'){
                if(s[i-3]=='a'&&s[i-4]=='r'&&s[i-5]=='e'){
                    i-=6;
                }else{
                    cout<<"NO"<<endl;
                    break;
                }
            }else{
                cout<<"NO"<<endl;
                break;
            }
        }else if(s[i]=='m'){
            if(s[i-1]=='a'&&s[i-2]=='e'&&s[i-3]=='r'&&s[i-4]=='d'){
                i-=5;
            }else{
                cout<<"NO"<<endl;
                break;
            }
        }else if(s[i]=='e'){
            if(s[i-1]=='s'&&s[i-2]=='a'&&s[i-3]=='r'&&s[i-4]=='e'){
                i-=5;
            }else{
                cout<<"NO"<<endl;
                break;
            }
        }else{
            cout<<"NO"<<endl;
            break;
        }
        if(i==-1){
            cout<<"YES"<<endl;
            break;
        }
            
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<int> A(N);
	map<int,ll> ct;
	for (int i=0; i<N; i++)
		cin>>A[i], ct[A[i]]++;
	ll cur=0;
	for (auto it : ct)
		cur+=(it.second*(it.second-1))/2;
	for (int i=0; i<N; i++) {
		ll tmp=ct[A[i]];
		cout<<cur-tmp*(tmp-1)/2+(tmp-1)*(tmp-2)/2<<"\n";
	}
	return 0;
}

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

int main(){
//srandom((unsigned long)time(NULL));
long long n;
cin>>n;
vector<tuple<long long,long long>> a;
for(long long i=0;i<n;i++){
    long long x;
    cin>>x;
    a.emplace_back(x,i);

}
sort(a.begin(),a.end());
//1-4,3-9,    99-3
long long s,t,u,v;
tie(s,t)=a[n-1];
tie(u,v)=a[n-2];
for(long long i=0;i<n;i++){

    if(i==t){
        cout<<u<<endl;
    }else{
        cout<<s<<endl;
    }
}

return 0;
}

Measured memory_bytes: 6000
#include <stdio.h>

typedef struct{
  char suit;
  int value;
} Card;

void bubbleSort(Card*,int);
void selectionSort(Card* ,int);
void printSort(Card*,int);
int stableSort(Card*,Card*,int);

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

void selectionSort(Card A[], int N){
  int i, j, minj=0;
  Card t;
  for(i=0; i<N; i++){
    minj = i;
    for(j=i; j<N; j++){
      if(A[j].value < A[minj].value)
        minj = j;
    }
    t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void printSort(Card A[], int N){
  int i;
  for(i=0; i<N; i++){
    if(i>0) printf(" ");
    printf("%c%d", A[i].suit, A[i].value);
  }
  printf("\n");
}

int stableSort(Card c1[], Card c2[], int N){
  int i;
  for(i=0; i<N; i++){
    if(c1[i].suit != c2[i].suit) return 0;
  }
  return 1;
}

int main(){
  Card c1[100], c2[100];
  int N, i, x=999;
  char ch[2];

  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf("%s", ch);
    c1[i].suit = ch[0];
    c1[i].value = (int)(ch[1]-48);
    }
  for(i=0; i<N; i++) c2[i] = c1[i];

  bubbleSort(c1,N);
  selectionSort(c2,N);

  printSort(c1,N);
  printf("Stable\n");
  printSort(c2,N);
  if(stableSort(c1,c2,N) == 1){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}

Measured memory_bytes: 612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long m = in.nextLong();
		long d = in.nextLong();
		long numPattern = calculatePattern(n,d);
		double ave = (double)numPattern * (m-1)/n/n;
		System.out.println(ave);
	}
	
	public static long calculatePattern(long n,long d) {
		if(d==0) {
			return n;
		}else {
			return 2*(n-d);
		}
	}

}

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

#define M 1046527
//#define NIL -1
#define L 14

char H[M][L]; // hash table

int m;

//Convert char to int
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;
    else return 0;
}

//Generate key by converting char to int
long long getKey(char str[]) {
    long long sum = 0, p = 1;
    for (int i = 0; i < strlen(str); i++) {
        sum += p*(getChar(str[i]));
        p *= 5; // pow(5, i) makes each string have unique key
    }
    return sum;
}

int h1(int key)
{
    return key % M;
}

int h2(int key)
{
    return 1 + (key % (M-1)); 
    /* maximum value == M-1, which means 
     * h(hash) function can generate arbitrary values
     */
}

int find(char str[]) /* found = 1, not_found = 0 */
{
    long long key, h;
    key = getKey(str); // convert string to int
    for (int 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 h(int key, int i){
    return (h1(key) + i * h2(key)) % m;
}

int insert(char str[])
{
    long long key, h;
    key = getKey(str); // convert string to int
    for (int 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() {
    int n, h;
    char str[L], com[9];
    
    for (int i = 0; i < M; i++) H[i][0] = '\0';
    
    scanf("%d", &n); // # of operations
    
    for(int i = 0; i < n; i++){
        scanf("%s %s", com, str);
        
        if (com[0] == 'i') { // 'insert'
            insert(str);
        } else { // 'find'
            if (find(str)) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}


Measured memory_bytes: 17060
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int,input().split()))
l = [i for i in range(102)]
for i in p:
    l.remove(i)
a = 100
for i in l:
    a = min(a,abs(x-i))
for i in l:
    if abs(x-i) == a:
        print(i)
        exit()

Measured memory_bytes: 9196
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int h,w,H,W;
	scanf("%d %d",&H,&W);
	scanf("%d %d",&h,&w);
	printf("%d\n",H*W-h*W-H*w+w*h);
 	return 0;
 }


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int max,a,i,ans;
  scanf("%d",&a);
int b[a];

  ans=0;
  
  for(i=0;i<a;++i)
  {scanf("%d",&b[i]);
   ans=ans+b[i]-1;
  }

  
  printf("%d",ans);
  
return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
H = list(map(int, input().split()))
g = [[] for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

cnt = 0
for n in range(1,N+1):
    for i in g[n]:
        if H[n-1] <= H[i-1]:
            break
    else:
        cnt += 1

print(cnt)


Measured memory_bytes: 29464
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int H, W, D;
  scanf("%d %d %d", &H, &W, &D);

  // 整数iが書かれたマス(trout[i][0], trout[i][1])
  int trout[MAX][2]; 
  int a;
  rep(hi, 0, H) {
    rep(wi, 0, W) {
      scanf("%d", &a);
      trout[a][0] = hi;
      trout[a][1] = wi;
    }
  }

  // dist[i]: 整数iが書かれたマスまでの距離
  int dist[MAX] = {0};
  for ( int d = 1; d <= D; d++ ) {
    int bh = trout[d][0];
    int bw = trout[d][1]; 
    dist[d] = bh + bw;
    for ( int l = d + D; l <= H * W; l += D ) {
      int nh = trout[l][0];
      int nw = trout[l][1];
      dist[l] = dist[l - D] + abs(bh - nh) + abs(bw - nw);
      bh = nh; bw = nw;
    }
  }
  

  int Q, L, R;
  scanf("%d", &Q);
  rep(qi, 0, Q) {
    scanf("%d %d", &L, &R);
    // printf("dist[R]=%d dist[L]=%d\n", dist[R],  dist[L]); 
    printf("%d\n", dist[R] - dist[L]);
  }
  return 0;
}


Measured memory_bytes: 2176
n, m = map(int, input().split())
stw = [list(map(int, input().split())) for _ in range(m)]
stw = sorted(stw, key=lambda x:x[2])

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return 
    if self.root[x] > self.root[y]:
      x, y = y, x
    self.root[x] += self.root[y]
    self.root[y] = x 
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): # xが属するグループのサイズを返す
    return -self.root[self.Find_Root(x)]
  def Members(self, x): # xが属するグループに属する要素をリストで返す
    return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
  def Roots(self): # 全ての根の要素をリストで返す
    return [i for i, x in enumerate(self.root) if x < 0]
  def Group_Count(self): # グループの数を返す
    return len(self.Roots())

def kruskal():
  res = 0 
  uf = UnionFind(n)
  for i in range(m):
    s, t, w = stw[i]
    if not uf.isSameGroup(s, t):
      uf.Unite(s, t)
      res += w 
  
  return res

print(kruskal())



Measured memory_bytes: 28984
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int N, M;
string A[100], B[100];

int main() {
  cin >> N >> M;
  rep(i, 0, N) { cin >> A[i]; }
  rep(i, 0, M) { cin >> B[i]; }
  rep(i, 0, N) {
    rep(j, 0, N) {
      bool ok = true;
      rep(k, 0, M) {
        rep(l, 0, M) {
          if (B[k][l] != A[i + k][j + l]) {
            ok = false;
            break;
          }
        }
        if (!ok) break;
      }
      if (ok) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}


Measured memory_bytes: 3628