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

bool cmp(int a, int b)
{
    if (a > b)
        return true;
    else
        return false;
}

int main()
{
    int k;
    cin >> k;
    priority_queue<int> pq;
    int d = 1;
    int beg = 0;
    int i = 0;
    vector<string> num;
    while (true)
    {
        if (i == 0)
        {
            for (int j = 1; j < 10; j++)
            {
                num.push_back(to_string(j));
            }
        }
        else
        {
            int end = num.size();
            for (int j = beg; j < end; j++)
            {
                char last = num[j][num[j].length() - 1];
                if (last == '9')
                {
                    num.push_back(num[j] + '8');
                    num.push_back(num[j] + last);
                }
                else if (last == '0')
                {
                    num.push_back(num[j] + last);
                    num.push_back(num[j] + '1');
                }
                else
                {
                    char a = last - 1;
                    char b = last + 1;
                    num.push_back(num[j] + a);
                    num.push_back(num[j] + last);
                    num.push_back(num[j] + b);
                }
            }
            beg = end;
        }
        if (num.size() > k)
        {
            cout << num[k - 1];
            return 0;
        }

        i++;
    }

    return 0;
}

Measured memory_bytes: 13936
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()


class UnionFind {
public:
    vector<int> par;
    vector<int> siz;

    UnionFind(int n) : par(n) , siz(n, 1){
        for(int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;      // root
        return par[x] = root(par[x]);   // 経路圧縮
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //同じ木にない時：rxをryにつける
        siz[ry] += siz[rx];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x){
        return siz[root(x)];
    }
};

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

    UnionFind frt(n);
    vector<int> counter(n, 0);

    // friend
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        frt.unite(a, b);
        counter[a]--;
        counter[b]--;
    }

    // block
    for(int i=0; i<k; i++){
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        // そもそも友達候補に入ってなければ除外する必要なし
        if(frt.same(c, d)){
            counter[c]--;
            counter[d]--;
        }
    }

    // output
    for(int i=0; i<n; i++){
        cout << frt.size(i) + counter[i] - 1 << " ";
    }
    cout << endl;
}

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

using namespace std ;

int main()
{
    long n ;
    cin >> n ;
    
    long a[n] , b[n] , c[n] ;
    
    for( long i=0 ; i<n ; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    
    long dp[n][3] ;
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    for( long i=1 ; i<n ; i++)
    {
        dp[i][0] = a[i] + max( dp[i-1][1] , dp[i-1][2] );
        dp[i][1] = b[i] + max( dp[i-1][0] , dp[i-1][2] );
        dp[i][2] = c[i] + max( dp[i-1][0] , dp[i-1][1] );
    }
    
    cout << max( dp[n-1][0] , max( dp[n-1][1] , dp[n-1][2] ) );
    
}

Measured memory_bytes: 4992
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    
    cout << abs(a[1] - a[0]) + abs(a[2] - a[1]) << endl;
    
    return 0;
}

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

#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp                       __builtin_popcountll

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}


int32_t main()
{
    speed upp
	int n,ans=0;
    cin>>n;
    f(i,1,n)
    {
        f(j,1,n)
        {
            f(k,1,n)
            {
                ans+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
using namespace std;
 
int main() {
  int n; cin>>n;
  long long mymax=-1000000,mymin=1000000,mysum=0;
  long long a;
  for(int i=0;i<n;i++){
  	cin>>a;
   	if(mymax<a) mymax=a;
    if(mymin>a) mymin=a;
    mysum +=a;
  }
  cout<<mymin<<" "<<mymax<<" "<<mysum<<endl;
}



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


void solve(long long N, long long X, long long Y){
    std::vector<std::vector<long long>> dist(N, std::vector<long long>(N));
    std::vector<long long> cnt(N, 0);

    int in_range = 0;
    for(long long i = 0; i < N; i++){
        for(long long j = 0; j < N; j++){
            dist[i][j] = abs(j - i);
            //cout << "[" << i << "][" << j << "], " << in_range << " " << dist[i][j] << endl;
            if( (i <= X-1) && (j >= Y-1) ){
                dist[i][j] -= (Y-X-1);
            }
            //cout << "[" << i+1 << "][" << j+1 << "], " << in_range << " " << dist[i][j] << endl;
        }
    }

    for(long long i = 0; i < N; i++){
        for(long long j = 0; j < N; j++){
            if(i < j){
                if( dist[i][j] > dist[i][X-1]+dist[X-1][j] ){
                    dist[i][j] = dist[i][X-1]+dist[X-1][j];
                }
                if( dist[i][j] > dist[i][Y-1]+dist[Y-1][j] ){
                    dist[i][j] = dist[i][Y-1]+dist[Y-1][j];
                }
                
                cnt[dist[i][j]-1]++;
            }

            //if(i < j){
            //    cout << "[" << i+1 << "][" << j+1 << "], " << in_range << " " << dist[i][j] << endl;
            //}
        }
    }

    for(long long k = 0; k < N-1; k++){
        cout << cnt[k] << endl;
    }


}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(N, X, Y);
    return 0;
}


Measured memory_bytes: 31616
def main():
    n, y = map(int, open(0).read().split())
    y //= 1000
    found = False
    for i in range(n+1):
        for j in range(n+1):
            k = n - i - j
            if k < 0:
                continue
            if 10 * i + 5 * j + k == y:
                found = True
                break
        if found:
            break
    else:
        i, j, k = -1, -1, -1
    print(i, j, k)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
using namespace std;


int main() {
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
			if (i * (m - j) + j * (n - i) == k) {
				printf("Yes\n");
				return 0;
			}
	printf("No\n");
}

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

int main() {
	int N;
	ll M;
	cin >> N >> M;
	vector<ll> A(N);
	for(auto &a: A) cin >> a;
	vector<ll> B(N, 0);
	B[0] = A[0];
	for(int i=1;i<N;i++) {
		B[i] = A[i] + B[i-1];
	}
	map<ll,ll> rest;
	for(int i=0;i<N;i++) {
		rest[B[i]%M]++;
	}
	ll ans = 0;
	for(auto &tmp : rest) {
		ll num = tmp.first;
		ll cnt = tmp.second;
		if(num == 0) ans += cnt;
		ans += cnt*(cnt-1)/2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;

vector<vector<int>> edges;
vector<bool> v;

void dfs(int ver) {
	v[ver] = 1;
	for (int nb : edges[ver]) {
		if (!v[nb]) dfs(nb);
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	edges.resize(n + 1);
	v.resize(n + 1);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		edges[x].push_back(y);
		edges[y].push_back(x);
	}
	
	int ans{-1};
	for (int i = 1; i <= n; i++) {
		if (!v[i]) dfs(i), ans++;
	}
	cout << ans;
}

Measured memory_bytes: 9220
n = int(input())
al = list(int(input()) for _ in range(n))
al_s = sorted(list(set(al)), reverse=True)

if al.count(al_s[0]) == 1:
    for a in al:
        if a != al_s[0]:
            print(al_s[0])
        else:
            print(al_s[1])
else:
    for i in range(n):
        print(al_s[0])


Measured memory_bytes: 17176
import java.io.*;
public class Main {
	public static void main(String[] args) {
		try {
	        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	        String param = new String(in.readLine());
	        String[] params = param.split(" ");
	        int n = Integer.parseInt(params[0]);
	        int a = Integer.parseInt(params[1]);
	        int b = Integer.parseInt(params[2]);
		
			int max = a < b ? a : b;
			int min;
			if ((a + b) < n) {
				min = 0;
			} else {
				min = (a + b) - n;
			}
			System.out.println(String.valueOf(max) + " " + String.valueOf(min));
		} catch (Exception ex) {}
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n,k;cin>>n>>k;
    vector<int> v(k);
    rep(i,0,k){
        cin>>v[i];
    }
    while(1){
        int nn=n;
        bool f=true;
        while(nn>0){
            rep(i,0,k){
                if(v[i]==nn%10){
                    f=false;
                }
            }
            nn/=10;
        }
        if(f){
            cout<<n<<endl;
            return 0;   
        }
        n++;
    }
    
    return 0;
}




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

using namespace std;

const int N = 1e5 + 10;
long long dp[N];

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

  int n, W;
  cin >> n >> W;
  for (int i = 0; i < n; ++i) {
    int w, v;
    cin >> w >> v;
    for (int j = W - w; j >= 0; --j) {
      dp[j + w] = max(dp[j + w], dp[j] + v);
    }
  }
  cout << *max_element(dp, dp + N);

  return 0;
}

Measured memory_bytes: 1024
import sys
b=0
a=[{},{}]
for e in sys.stdin:
 if'\n'==e:b=1
 else:c=int(e.split(',')[0]);a[b].setdefault(c,0);a[b][c]+=1
for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])


Measured memory_bytes: 5604
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    ll n;
    cin >> n;
    vector<long long> vec(n);
    vector<long long> s(n + 1);
    rep(i, n){
        cin >> vec[i];
        s[i+1] = vec[i] + s[i];
    }
    vector<long long> s_zan(n);
    rep(i, n){
        s_zan[i] = s[n] - s[i];
    }

    ll ans = -1;
    rep(i, n){
        ans = ans < 0 ? abs(s[i] - s_zan[i]) : min(ans, abs(s[i] - s_zan[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        if (n == 1) { Console.WriteLine(1); goto end; }
        var k = int.Parse(line[1]);
        var a = new long[n - 1];
        var pre = int.Parse(Console.ReadLine().Trim());
        var t0 = pre;
        var last = 0L;
        for (int i = 0; i < n - 1; i++)
        {
            var w = int.Parse(Console.ReadLine().Trim());
            a[i] = w - pre - 1;
            pre = w;
            if (i == n - 2) last = w;
        }
        var ret = last - t0 + 1 - a.OrderByDescending(x => x).Take(k - 1).Sum();
        Console.WriteLine(ret);
        end:;
    }
}



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

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);


void init() {
     
}

void solve() {
    int n, a, b;
    scanf(III,&n,&a,&b);
    int d = abs(a-b);
    if (d % 2 == 0) {
        printf(IN,d/2);
    } else {
        printf(IN,min((a+b)/2,(n+n-a-b+1)/2));
    }
}


#ifdef ENABLE_LL
#undef int
#endif
int main(){
    init();
    solve();
    return 0;
}


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

int n,u,v;
long long ans;

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

	for(int i=1;i<=n;i++) ans+=1ll*i*(n-i+1);

	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&u,&v);
		if(u>v) swap(u,v);
		ans-=1ll*u*(n-v+1);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 3780
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;
//const int N = 10001;
const int N = 1e5 + 10;
//const int N = (2 * (1e5)) + 2;



int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;

        vector<double> a(n);
        for (int i = 0; i < n; i++)
            cin >> a[i];

        vector<double> dp(n + 1);  
        dp[0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j >= 0; j--) { 
                dp[j] = (j == 0 ? 0 : dp[j - 1] * a[i]) + dp[j] * (1 - a[i]);
            }
        }

        double answer = 0;
        for (int heads = ceil(n / 2.0); heads <= n; heads++) {
            answer += dp[heads];
        }

        cout << fixed << setprecision(9) << answer;
    }
    return 0;

}






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

int main()
{	
	int n, m;

	cin >> n >> m;

	while (n > 0 || m > 0) {
		queue<int> a;

		for (int i = 1; i <= n; i++)
			a.push(i);

		for (int j = 0; j < n - 1; j++) {
			for (int i = 0; i < m - 1; i++) {
				int p = a.front();
				a.pop();
				a.push(p);
			}

			a.pop();
		}

		cout << a.front() << endl;

		cin >> n >> m;
	}

	return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0), cin.tie(0);

	vector<pair<int, int>> e;
	for (int u, v, i = 0; i < 3; ++i)
	{
		cin >> u >> v;
		e.push_back({ min(u, v), max(u, v) });
	}

	vector<int> ord(4);
	iota(ord.begin(), ord.end(), 1);

	bool ok = false;
	do
	{
		int c = 0;
		for (int i = 0; i < 3; ++i)
		{
			int u = ord[i], v = ord[i+1];
			if (u > v) swap(u, v);
			for (auto k : e)
				if (k.F == u && k.S == v)
				{
					++c;
					break;
				}
		}

		if (c == 3)
			ok = true;

	} while (next_permutation(ord.begin(), ord.end()));

	if (ok)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}


int n, a[100010];
int cnt;

signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	if (a[n - 1] - a[0] > 1) {
		cout << "No" << endl;
		ggr
	}
	if (a[n - 1] == a[0]) {
		if (n - a[0] == 1 || n >= a[0] * 2)cout << "Yes" << endl;
		else cout << "No" << endl;
		ggr
	}
	rep(i, n) {
		if (a[0] == a[i])cnt++;
		else break;
	}
	if (a[n - 1] - cnt > 0 && (n - cnt) / (a[n - 1] - cnt) >= 2)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1024
n,a,b=map(int,input().split())
s=input()
c,d=0,0
for i in range(n):
  if s[i]=="a":
    if c+1<=a+b:
      print("Yes")
      c+=1
    else:
      print("No")
  elif s[i]=="b":
    if c+1<=a+b and d+1<=b:
      print("Yes")
      c+=1
      d+=1
    else:
      print("No")
  else:
    print("No")

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int A[M], B[M];
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }
  int cost = 0;
  int maxV = 0;
  for (int i = 0; i < M; i++) {
    cost += max(0, N - A[i]);
    maxV = max(maxV, N - A[i]);
  }
  cost -= maxV;
  cout << cost << "\n";
  return 0;
}


Measured memory_bytes: 3140
#include <iostream>
using namespace std;
int main(){
    
    int n,x,a[4][13]={0};
    char ch;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ch>>x;
        if(ch=='S'){a[0][x-1]=1;}
        if(ch=='H'){a[1][x-1]=1;}
        if(ch=='C'){a[2][x-1]=1;}
        if(ch=='D'){a[3][x-1]=1;}
    }
    for(int k=0;k<4;k++){
        for(int j=0;j<13;j++){
            if(a[k][j]!=1&&k==0){cout<<"S "<<j+1<<endl;}
            if(a[k][j]!=1&&k==1){cout<<"H "<<j+1<<endl;}
            if(a[k][j]!=1&&k==2){cout<<"C "<<j+1<<endl;}
            if(a[k][j]!=1&&k==3){cout<<"D "<<j+1<<endl;}
        }
        
    }
    return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(void) {

	int n,i;
	int min = 1000000;
	int max = -1000000;
	long int sum = 0;
	int a[10000];
	
	scanf("%d\n",&n);

	for (i = 0; i < n; i++) {
		scanf("%d ", &a[i]);

		sum += a[i];

		if (min > a[i]) {
			min = a[i];
		}

		if (max < a[i]) {
			max = a[i];
		}
		
	}

	printf("%d %d %ld\n", min, max, sum);
	
	return(0);

}


Measured memory_bytes: 2104
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t A, B;
  string S;
  cin >> A >> B >> S;
  const int32_t length = static_cast<int32_t>(S.length());

  bool is_okay = true;
  if (S.c_str()[A] != '-') {
    is_okay = false;
  }
  for (int32_t i = 0; i < A; ++i) {
    if (S.c_str()[i] >= '0' && S.c_str()[i] <= '9') {
      // do nothing
    } else {
      is_okay = false;
    }
  }
  for (int32_t i = A + 1; i < length; ++i) {
    if (S.c_str()[i] >= '0' && S.c_str()[i] <= '9') {
      // do nothing
    } else {
      is_okay = false;
    }
  }
  if (is_okay) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2);
}

void solve()
{
	int n , k;
	
	cin >> n >> k;
	
	if(n >= 10) {
		cout <<k;
	}
	else {
		cout << k + 100*(10-n);
	}
}

signed main() {
    fast;
    
    int t = 1;
    
    //cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3576
N=int(input())

cnt=[[0]*10 for _ in range(10)]

for i in range(1,N+1):
    s=str(i)
    up=int(s[0])
    down=int(s[-1])
    cnt[up][down]+=1

ans=0
for i in range(1,10):
    for j in range(1,10):
        a=cnt[i][j]
        if i==j:
            ans+=a**2
        else:
            b=cnt[j][i]
            ans+=a*b

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin >>n;
    vector<long> x(10000);
    x[0]=n;
    
    for(int i=1;i<10000;i++){
        if(n%2==0) n/=2;
        else n = 3*n+1;
    
    for(int j=0;j<i;j++){
        if(n==x[j]){
            cout << i+1 << endl;
            return 0;
        } 
    }
    x[i]=n;
    }
}


Measured memory_bytes: 384
// DP
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

int n, q;
vector<int> A;
vector<vector<int> > dp;

bool solve(int i, int m) {
    if (m == 0) return true;
    else if (i >= n) return false;
    else if(solve(i+1, m)) return true;
    else if (solve(i+1, m - A[i])) return true;
    else return false ;
}

int main() {
    cin >> n;
    A.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    cin >> q;
    for (int j = 0; j < q; ++j) {
        int m;
        cin >> m;
        dp.resize(n);
        for (int i = 0; i < n; ++i) {
            dp[i].resize(m);
        }
        bool ans = solve(0, m);
        if(ans) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}



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

using namespace std;

typedef long long ll;

const ll inf = 1e18;

int N;
vector<ll> a, p;
vector<vector<ll>> dp;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++)
        cin >> a[i];
    p.resize(N + 1);
    for (int i = 1; i <= N; i++)
        p[i] = p[i - 1] + a[i - 1];
    dp.assign(N, vector<ll>(N, inf));
    for (int i = 0; i < N; i++)
        dp[i][i] = 0;
    for (int w = 2; w <= N; w++)
        for (int l = 0, r = w - 1; r < N; l++, r++)
            for (int m = l; m < r; m++)
                dp[l][r] = min(dp[l][r], p[r + 1] - p[l] + dp[l][m] + dp[m + 1][r]);
    cout << dp[0][N - 1] << endl;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main(void) {
  int n, k, index_one;

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 1) {
      index_one = i;
    }
  }
  int left, right;
  int ans = 100000;
  for (int i = 0; i < k; i++) {
    right = index_one + i;
    left = right - (k - 1);
    int x = 1 + ceil((double)(n - 1 - right) / (double)(k - 1)) +
            ceil((double)left / (double)(k - 1));
    ans = min(ans, x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (a == 1)
    {
        a = 14;
    }
    if (b == 1)
    {
        b = 14;
    }
    if (a == b)
    {

        cout << "Draw" << endl;
    }
    else if (a > b)
    {

        cout << "Alice" << endl;
    }
    else
    {

        cout << "Bob" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        grid: [String;h],
    }
    let grid: Vec<Vec<char>> = grid
        .into_iter()
        .map(|row_str| row_str.chars().collect::<Vec<char>>())
        .collect();
    let mut count_row: Vec<i64> = vec![0; h];
    let mut count_col: Vec<i64> = vec![0; w];
    for i in 0..h {
        for j in 0..w {
            if grid[i][j] == '#' {
                count_row[i] += 1;
                count_col[j] += 1;
            }
        }
    }

    let mut ans: i64 = 0;
    for mut row_comb in 0..(1 << h) {
        let mut count: i64 = grid
            .iter()
            .flatten()
            .fold(0, |acc, g| if *g == '#' { acc + 1 } else { acc });
        let mut check_row: Vec<bool> = vec![false; h];
        for row in 0..h {
            if row_comb & 1 == 1 {
                check_row[row] = true;
                count -= count_row[row];
            }
            row_comb >>= 1;
        }
        for mut col_comb in 0..(1 << w) {
            let mut count2 = count;
            for col in 0..w {
                if col_comb & 1 == 1 {
                    count2 -= count_col[col];
                    for (idx, check) in check_row.iter().enumerate() {
                        if *check {
                            if grid[idx][col] == '#' {
                                count2 += 1;
                            }
                        }
                    }
                }
                col_comb >>= 1;
            }
            if count2 == k as i64 {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int N;
	cin >> N;
	vector<int> dp(3,0);
	for (int i = 0; i < N; i++) {
		vector<int> a(3),dpdp(3);
		for (int j = 0; j < 3; j++) cin >> a[j];
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j==k) continue;
				dpdp[k] = max(dpdp[k],dp[j]+a[k]);
				//debug(k); debug(dpdp[k]); cerr<<endl;
			}
		}
		dp = dpdp;
	}
	//for (auto it: dp) debug(it);
	cout << max({dp[0],dp[1],dp[2]});
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ESP 1e-5

int main(void){
    int x, y;
    cin >> x >> y;
    for(int a = 0; a <= x; a++){
	int b = x - a;
	if(2 * a + 4 * b == y){
	    cout << "Yes" << endl;
	    return 0;
	}
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    int ans = 0, ans1 = 0;
    int n = SZ(s);
    string a, b;
    for(int i = 0; i < n; i++){
        if(i & 1) a += '0', b += '1';
        else a += '1', b += '0';
    }
    for(int i = 0; i < n; i++){
        ans += (s[i] != a[i]);
        ans1 += (s[i] != b[i]);
    }
    cout << min(ans, ans1);
    return 0;
}


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

using namespace std;

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

bool solve(string s){
	int n = (int)s.length();
	int cnt[26] = {0};
	rep (i, n){
		++cnt[(int)(s[i] - 'a')];
	} // end rep

	int res = 0;
	int cand = -1;
	rep (i, 26){
		if (res < cnt[i]){
			res = cnt[i];
			cand = i;
		} // end if
	} // end rep

//	cerr << "res: " << res << endl;
//	cerr << "cand: " << (char)(cand + 'a') << endl;

	return (res > n / 2);
}

P solve_small(string s){
	int n = (int)s.length();
	P res = P(-1,-1);
	rep (i, n){
		for (int j = i + 2; j <= n; ++j){
			string t = s.substr(i, j - i);
//			cerr << "t: " << t << endl;
			if (solve(t)){
				res.first = i + 1;
				res.second = j;
 				break;
			} // end if
		} // end for
		if (res.first != -1){
			break;
		} // end if
	} // end rep
	return res;
}

P solve_large(string s){
	int n = (int)s.length();

	if (n == 2){
		if (s[0] == s[1]){
			return P(0+1,1+1);
		} // end if
	} // end if
	
	// search pattern 1.(XX)
	for (int i = 1; i < n; ++i){
		if (s[i-1] == s[i]){
			if (i + 1 < n){
				return P(i-1+1, i+1+1);
			}else{			
				return P(i-2+1,i+1);
			} // end if
		} // end if
	} // end for

	// search pattern 2.(XYX){
	for (int i = 2; i < n; ++i){
		if (s[i-2] == s[i]){
			return P(i-2+1,i+1);
		} // end if
	} // end for
	
	return P(-1,-1);
}		
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	string s; cin >> s;
	P res = solve_large(s);
	cout << res.first << ' ' << res.second << endl;

	return 0;
}

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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define rep0(i,n) for (int i=0; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%ld "; return r + "\n"; }
#define debug(...) do { printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__); } while(0)
#define fast_ios() do {} while(0);
#else //_DEBUG
#define debug(...) do {} while(0)
#define fast_ios() do { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } while(0)
#endif //_DEBUG

int n;
int s[200000];

int popcount(int x) {
    int popcnt = 0;
    while (x != 0) {
        if (x&1) popcnt++;
        x >>= 1;
    }
    return popcnt;
}

int popcount_mod_s(int popcnt) {
    int a = 0;
    for (int j=0; j<n; j++) {
        a = ((a<<1) + s[j]) % popcnt;
    }
    return a;
}

int pow_2_mod_inc[200000];
int pow_2_mod_dec[200000];

int main() {
    fast_ios();

    cin >> n;
    string ss;
    cin >> ss;

    int popcnt_x = 0;
    for (int i=0; i<n; i++) {
        s[i] = ss[i] - '0';
        popcnt_x += s[i];
    }
    int pp = popcnt_x + 1;
    int pn = popcnt_x - 1;

    int x=0, y=0;
    rep0(j,n) {
        x = ((x<<1) + s[j]) % pp;
        if (pn) y = ((y<<1) + s[j]) % pn;
        debug(popcnt_x,x,y);
    }
    int inc=1, dec=1;
    rep0(j,n) {
        pow_2_mod_dec[j] = dec;
        pow_2_mod_inc[j] = inc;
        inc = (inc<<1) % pp;
        if (pn) dec = (dec<<1) % pn;
        debug(inc, dec);
    }

    rep0(i,n) {
        int popcnt = popcnt_x + (s[i] == 1 ? -1 : 1);
        int cnt = 0;
        if (popcnt > 0) {
            int a = ((s[i] == 1) ? (y - pow_2_mod_dec[n-1-i] + popcnt) : (x + pow_2_mod_inc[n-1-i])) % popcnt;
            cnt = 1;
            debug(a, popcnt, cnt);
            while (popcnt > 0 && a > 0) {
                popcnt = popcount(a);
                debug(a, popcnt, cnt);
                a %= popcnt;
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}


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

int n;
pair<int, int> a[100007];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1, [](auto a, auto b) -> bool { return a.first < b.first; });
    for (int i = 1; i <= n; i++) {
        cout << a[i].second << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4384
# coding: utf-8
k, n = map(int, input().split())
a = list(map(int, input().split()))
max = 0

for i in range(n-1):
    l = a[i+1] - a[i]
    if l > max:
        max = l
l = a[0] - a[n-1] + k
if l > max:
    max = l
print(k - max)

Measured memory_bytes: 26436
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000000000LL
using namespace std;

int main(){
  ll limit = 1e5+1;
  int N;
  ll a[limit];
  //ll nDown[limit];
  ll nUp[limit];
  ll nAns[limit];
  cin >> N;
  for (int i=0; i<=N; i++)
    cin >> a[i];
    
  // handle corner cases
  if (a[0]>0){
    if(a[0]==1 and N==0){
      cout << 1 << endl;
      return 0;
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  // compute n's downwards
  //nDown[0] = 1;
  //for (int i=0; i<N; i++)
  //  nDown[i+1] = min(2*nDown[i] - a[i+1], INF);
  // compute n's upwards 
  nUp[N] = 0;
  for (int i=N; 0<i; i--)
    nUp[i-1] = nUp[i] + a[i];
  //when tree is not realizable
  //if (nDown[N]<0){// or (nUp[0]<0)){
  //  cout << -1 << endl;
  //  return 0;
  //}
  // 
  //for (int i=0; i<=N; i++){
  //  nAns[i] = min(nUp[i], nDown[i]);
  //  sum += nAns[i] + a[i];
  //}
  ll sum = 1;
  nAns[0] = 1;
  for (int i=1; i<=N; i++){
    nAns[i] = min(nUp[i], 2*nAns[i-1]-a[i]);
    sum += nAns[i] + a[i];
    if (nAns[i]<0){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 5932
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):  # 確かめるのはnの平方根までで大丈夫
        if not is_prime[i]:  # すでにfalseなら次のiへ
            continue
            """
            bool(not False)はTrueになる
            """
        for j in range(i * 2, n + 1, i):  # iずつ大きくなる(つまりiの倍数をみる)
            is_prime[j] = False  # i自身を除くiの倍数を全てFalseにする
    return [i for i in range(n + 1) if is_prime[i]]  # Trueのものだけ列挙して返す


while 1:
    N, P = map(int, input().split())
    if N == -1:
        exit()
    prime_numbers = [i for i in primes(120000) if i > N]

    prime_wa = []
    for i in range(P+1):
        for j in range(i, int(P+1)):
            prime_wa.append(prime_numbers[i]+prime_numbers[j])

    prime_wa.sort()

    print(prime_wa[P-1])



Measured memory_bytes: 7748
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]


    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

def main():
    N, M = map(int, input().split())
    B = [tuple(map(int, input().split())) for _ in range(M)]
    U = UnionFind(N)
    t = N * (N - 1) // 2
    R = [t]
    for a, b in reversed(B):
        a, b = a - 1, b - 1
        if U.find(a) != U.find(b):
            t -= U.size(a) * U.size(b)
            U.union(a, b)
        R.append(t)
    R.pop()
    print('\n'.join(str(i) for i in reversed(R)))
            
main()


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

string s, res;

int main() {
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') res += "0";
        if (s[i] == '1') res += "1";
        if (s[i] == 'B') res = res.substr(0, res.size()-1);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  int n;
  cin >> n;
  int a[n];
  double sum = 0LL;
  //ll ans = 1e9+7;

  REP(i, n) {
    cin >> a[i];
    sum += a[i];    
  }

  int mean  = ceil(sum/n);
  int mean2 = float(sum/n);

  ll ans = 0LL;
  ll ans2 = 0LL;
  //if(mean < 0 && sum/n < mean){    
  //  mean--;
  //}   
    
  
  REP(i, n){
    ans  += (a[i]-mean)*(a[i]-mean);
    ans2 += (a[i]-mean2)*(a[i]-mean2);
  }

  cout << min(ans, ans2) << endl;
  
  
  /*
  FOR(i, -100, 101){
    ll temp = 0LL;
    REP(j, n){
      temp += (i - a[j])*(i - a[j]);
    }
    ans = min(ans, temp);
  }
  cout << ans << endl;

  */
  
  return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int A, B;
  cin >> A >> B;
  if (A > 8 || B > 8) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
struct T{int a,b;}A[3333];
long P[3333],M=1e9+7,F[2<<17],I[2<<17];
i,j,k;
c(a,b)struct T*a,*b;{return a->a-b->a?:a->b-b->b;}
p(a,b){return b?p(a%M*a%M,b/2)%M*(b%2?a:1)%M:1;}
f(a,b){return F[a+b]*I[a]%M*I[b]%M;}
main(y)
{
	for(*F=*I=1;++k<2<<17;)I[k]=p(F[k]=F[k-1]*k%M,M-2);
	for(k=A;~scanf("%d",k);k+=4)i++-1||gets(P);
	for(qsort(A,i/=2,8,c);j<i;j++)
		for(P[k=j]=f(A[j].a-1,A[j].b-1);k--;)(y=A[j].b-A[k].b)>=0?P[j]=(P[j]-f(A[j].a-A[k].a,y)*P[k]%M+M)%M:0;
	printf("%d",P[i-1]);
}

Measured memory_bytes: 4480
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	n, _ := strconv.Atoi(s[:2])
	m, _ := strconv.Atoi(s[2:])

	if 1 <= n && n <= 12 {
		if 1 <= m && m <= 12 {
			fmt.Println("AMBIGUOUS")
		} else {
			fmt.Println("MMYY")
		}
	} else {
		if 1 <= m && m <= 12 {
			fmt.Println("YYMM")
		} else {
			fmt.Println("NA")
		}
	}
}


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

using namespace std;

typedef long long ll;

#define REP(i,p,q) for(ll i = p; i < q; i++)

int main(void){
    ll x,y;
    cin >> x >> y;
    bool isExsist = false;
    REP(i,0,101){
        if(i > x) break;
        if(2*i + 4*(x - i) == y){
            isExsist = true;
            break;
        }
    }
    cout << (isExsist ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3620
// 問題: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0034
#include <iostream>
#include <vector>

bool input(std::vector<int> & l, int & v1, int & v2)
{
	char comma;
	if (!(std::cin >> l[0])) return false;
	for (int i = 1; i < 10; i++) {
		std::cin >> comma >> l[i];
	}
	std::cin >> comma >> v1 >> comma >> v2;
	return true;
}
int sum_of_length(std::vector<int> l) // 全体の道のり(距離)
{
	int sum = 0;
	for (std::vector<int>::size_type i = 0; i < l.size(); i++) {
		sum += l[i];
	}
	return sum;
}
double left_length(int v1, int v2, std::vector<int> l)
{		
	// 全体の道のり.(ふたつの列車の走る合計の距離)
	int    distance = sum_of_length(l);
	// ふたつの列車がすれ違った時の時間(=走る時間はふたつの列車共同じ)
	double hour     = static_cast<double>(distance) / (v1 + v2);
	// 左の列車がどれくらいの距離を走ったか
	return v1 * hour;
}
int get_sect(std::vector<int> l, const double left_length)
{
	int sum = 0;
	for (std::vector<int>::size_type i = 0; i < l.size(); i++) {
		sum += l[i];
		if (left_length <= sum) return i + 1;
	}
	return -1;
}
int main()
{
	int              v1, v2;    // 左からの列車の速さ, 右からの列車の速さ
	std::vector<int> l(10, 0); // 各区間の距離x10
	while (input(l, v1, v2)) {
		std::cout << get_sect(l, left_length(v1, v2, l)) << std::endl;
	}
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(void){
	int N,ans(0),i;
	scanf("%d",&N);
	for(i = 0;;i ++){
		if(int(pow(10.,double(i))) <= N && int(pow(10.,double(i + 1))) <= N && 0 == i % 2){
			ans += int(pow(10.,double(i + 1)) - pow(10.,double(i)));
		}
		if(int(pow(10.,double(i))) <= N && int(pow(10.,double(i + 1))) > N && 0 == i % 2){
			ans += N - int(pow(10.,double(i))) + 1;
			break;
		}
		if(int(pow(10.,i)) > N){
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
char c[111];
int a, b, i;
int main(){
    scanf("%d %d\n", &a, &b);
    scanf("%s",c);
    for( i=0; i<a; i++){
    	if ('0' <= c[i] && c[i] <= '9')
    			;
    		else {
    			puts("No");
    			return 0;
    		}
    }
    if (c[a]!='-')	{
    			puts("No");
    			return 0;
    }
	
	for( i=a+1; i<a+b+1; i++){
    	if ('0' <= c[i] && c[i] <= '9')
    			;
    		else{
    			puts("No");
    			return 0;
    		}
    }
    puts("Yes");
 
    
    return 0;
}

Measured memory_bytes: 256
n,ma,mb = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]

dp = [[[float("INF")]*(n*10+2) for i in range(n*10+2)] for j in range(n+1)]

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

for i in range(n):
    a,b,c = l[i]
    
    for j in range(n*10+1):
        for k in range(n*10+1):
            
            if j >= a and k >= b:
                dp[i+1][j][k] = min(dp[i][j][k],dp[i][j-a][k-b]+c)
            elif dp[i][j][k] != float("INF"):
                dp[i+1][j][k] = dp[i][j][k]
ans = float("INF")

for i in range(1,n*10+1):
    j = i*mb/ma
    if j%1 == 0 and j < n*10:
        ans = min(ans,dp[-1][i][int(j)])
if ans == float("INF"):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 135516
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
typedef pair<ll,ll> p;

int main() {
   string t;
   cin>>t;
   for(int i=0;i<t.size();i++)
   {
       if(t[i]=='?' && i>0 && t[i-1]=='P')
       t[i]='D';
       else if(t[i]=='?')
       t[i]='D';
       
   }
   cout<<t<<endl;
}

Measured memory_bytes: 3756
is_odd, cntr = false, 0

n = gets.chomp.to_i
ary = gets.chomp.split(" ").map(&:to_i)
while true
  ary.each_with_index do |e, i|
    if e.odd?
      is_odd = true
      break
    else
      ary[i] = e/2
    end
  end
  
  break if is_odd
  cntr += 1
end

puts "#{cntr}"

Measured memory_bytes: 1916
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

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

ll N, A[112345], B[112345];

int main() {

	scanf("%lld", &N);
	rep(i, N) scanf("%lld", &A[i]);

	rep(i, N - 1) {
		if (A[i] < 0) {
			A[i] *= -1;
			A[i + 1] *= -1;
		}
	}

	ll a = 0;
	if (A[N - 1] >= 0) {
		rep(i, N) {
			a += A[i];
		}
	}
	else {
		ll smallest = 1123456789;
		rep(i, N) smallest = min(smallest, abs(A[i]));

		rep(i, N) {
			a += abs(A[i]);
		}
		a -= smallest * 2;
	}

	printf("%lld\n", a);

	return 0;
}


Measured memory_bytes: 1024