akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<int,int> P;
 #include <boost/multiprecision/cpp_int.hpp>

using bint = boost::multiprecision::cpp_int;
 
vector<vector<int>> hw(800,vector<int>(800));
vector<vector<int>> visited(800,vector<int>(800));

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int ans1 = 0;
int ans2 = 0;
void dfs(P v, P p, int h, int w){
    rep(i,4){
        int nx = v.first + dx[i];
        int ny = v.second + dy[i];
        if (nx == p.first && ny == p.second) continue;
        if (nx>=0 && nx < h && ny >= 0 && ny < w && visited[nx][ny] == 0){
            if (hw[nx][ny] != hw[v.first][v.second]){
                visited[nx][ny] = 1;
                if(hw[nx][ny] == 0) ans1++;
                else ans2++;
                dfs(mp(nx,ny),v,h,w);
            }
            
        }
    }
}

int main(){
    int h,w;
    cin >> h >> w;
    rep(i,h){
        string s;
        cin >> s;
        rep(j,w){
            if (s[j] == '.') hw[i][j] = 0;
            else hw[i][j] = 1;
        }
    }
    


    bint res = 0;
    rep(i,h)rep(j,w){
        if(hw[i][j] == 1 && visited[i][j] == 0){
            ans1 = 0;
            ans2 = 1;
            visited[i][j] = 1;
            dfs(mp(i,j),mp(-1,-1),h,w);
            res += (bint) ans1*ans2;
            
        }
    }
    cout << res;
}

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

using namespace std;
typedef long long ll;

const int N = 200'010;
int a[2][N];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &a[0][i]);
    for (int i = 0; i < n; i++) {
        a[1][max(i - a[0][i], 0)]++;
        a[1][min(i + a[0][i] + 1, n)]--;
    }
    for (int i = 1; i < k; i++) {
        int cur = i % 2, next = (i + 1) % 2;
        fill(a[next], a[next] + n, 0);
        int s = 0;
        bool end = 1;
        for (int j = 0; j < n; j++) {
            s += a[cur][j];
            if (s != n) end = 0;
            a[next][max(j - s, 0)]++;
            a[next][min(j + s + 1, n)]--;
        }
        if (end) {
            k = i + 1;
            break;
        }
    }
    int s = 0, cur = k % 2;
    for (int j = 0; j < n; j++) {
        s += a[cur][j];
        printf("%d ", s);
    }
    printf("\n");
}


Measured memory_bytes: 5308
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>

#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)

typedef long long ll;

using namespace std;

int N;
ll X[51], Y[51];

double ret;

void get_radius(double x, double y) {
    double r = 0;
    FOR(i, N) r = max(r, hypot(X[i]-x, Y[i]-y));
    ret = min(ret, r);
}

int main() {
    cin >> N;
    FOR(i, N) cin >> X[i] >> Y[i];
    ret = 1e9;

    FOR(z, N) FOR(y, z) {
        double rx = (X[y] + X[z])/2.0;
        double ry = (Y[y] + Y[z])/2.0;
        get_radius(rx, ry);

        FOR(x, y) {
            double a=hypot(X[y]-X[z], Y[y]-Y[z]);
            double b=hypot(X[z]-X[x], Y[z]-Y[x]);
            double c=hypot(X[x]-X[y], Y[x]-Y[y]);

            if(abs(a+b-c)<1e-9) continue;
            if(abs(a+c-b)<1e-9) continue;
            if(abs(c+b-a)<1e-9) continue;

            double rx=(a*a*(b*b+c*c-a*a)*X[x]+b*b*(a*a+c*c-b*b)*X[y]+c*c*(b*b+a*a-c*c)*X[z])/(a*a*(b*b+c*c-a*a)+b*b*(a*a+c*c-b*b)+c*c*(b*b+a*a-c*c));
			double ry=(a*a*(b*b+c*c-a*a)*Y[x]+b*b*(a*a+c*c-b*b)*Y[y]+c*c*(b*b+a*a-c*c)*Y[z])/(a*a*(b*b+c*c-a*a)+b*b*(a*a+c*c-b*b)+c*c*(b*b+a*a-c*c));
            get_radius(rx, ry);
        }
    }
    printf("%.12lf\n", ret);
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int n,k;
  cin>>n>>k;
  cout<<n-k+1<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

ll const MAX_V = 100005;

struct edge {
    ll to, cost;
};
vector<edge> G[MAX_V];

vector<bool> seen;
vector<ll> costs;
bool flg = true;

void dfs(int start, int v, int p, int cost) {
    seen[v] = true;

    for (auto nv : G[v]) {
        if (nv.to == p) continue;

        // cout << v << "->" << nv.to << ": " << seen[nv.to] << ", "
        //      << cost + nv.cost << endl;

        if (seen[nv.to]) {
            // cout << "[" << nv.to << "]: " << costs[nv.to] << " vs "
            //      << cost + nv.cost << endl;
            if (costs[nv.to] != cost + nv.cost) {
                flg = false;
            }

            continue;
        }

        costs[nv.to] = cost + nv.cost;
        dfs(start, nv.to, v, cost + nv.cost);
    }

    return;
}

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

    ll start = -1;

    for (ll i = 0; i < M; i++) {
        ll s, t, c;
        cin >> s >> t >> c;
        s--;
        t--;
        edge et = {t, c};
        G[s].push_back(et);

        edge es = {s, -c};
        G[t].push_back(es);
    }

    seen.assign(N, false);
    costs.assign(N, 0LL);

    rep(i, N) {
        if (!seen[i]) {
            dfs(i, i, -1, 0);
        }
    }

    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 21232
using System;

namespace B___Cakes_and_Donuts
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            for (var i = 0; i <= n / 4; i++) //ケーキ
            {
                for (var j = 0; j <= n / 7; j++)
                {
                    if (n == (4 * i) + (7 * j))
                    {
                        Console.WriteLine ("Yes");
                        return;
                    }
                }
            }
            Console.WriteLine ("No");
        }
    }
}

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

using namespace std;

using ll = long long int;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(A);
    scanInt(B);
    scanInt(C);
    scanVecInt(L, N);
    vector<char> v(N);
    function<int(int, vector<char>&)> func = [&](int li, vector<char>& v){
        if (N <= li){
            int ret = -30;
            bool a_flag = false;
            bool b_flag = false;
            bool c_flag = false;
            int a_length = 0;
            int b_length = 0;
            int c_length = 0;
            REP(i, N){
                switch (v[i]){
                case 0:
                    a_flag = true;
                    a_length += L[i];
                    ret += 10;
                    break;
                case 1:
                    b_flag = true;
                    b_length += L[i];
                    ret += 10;
                    break;
                case 2:
                    c_flag = true;
                    c_length += L[i];
                    ret += 10;
                    break;
                case 3:
                    break;
                }
            }
            if (!(a_flag && b_flag && c_flag)) return numeric_limits<int>::max();
            return ret + abs(A - a_length) + abs(B - b_length) + abs(C - c_length);
        }
        int min_num = numeric_limits<int>::max();
        REP(i, 4){
            v[li] = i;
            const auto temp = func(li + 1, v);
            min_num = min(temp, min_num);
        }
        return min_num;
    };
    cout << func(0, v) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5;
ll a[N],s[N],t[N];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		s[i]=s[i-1]+a[i];
		t[i]=t[i-1]^a[i];
	}
	ll ans=0;
	for(int l=1,r=1;r<=n;r++) {
		while(s[r]-s[l-1]!=(t[r]^t[l-1])) l++;
		ans+=r-l+1;
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define _ sync_with_stdio(false)
typedef long long ll;
const int MAXN=300000+10;
const long long INF=0x7fffffffffffffff;

priority_queue<ll> q2;
priority_queue<ll,vector<ll>,greater<ll> > q1;

ll a[MAXN];
ll s1[MAXN];
ll s2[MAXN];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=3*n;i++){
		scanf("%lld",a+i);
	}
	for(int i=1;i<=2*n;i++){
		if(i<=n){
			s1[i]=s1[i-1]+a[i];
			q1.push(a[i]);
		}
		else{
			ll temp=q1.top();
			if(temp<a[i]){
				q1.pop();
				q1.push(a[i]);
				s1[i]=s1[i-1]+a[i]-temp;
			}else{
				s1[i]=s1[i-1];
			}
		}
	}
	for(int i=3*n;i>n;i--){
		if(i>2*n){
			s2[i]=s2[i+1]+a[i];
			q2.push(a[i]);
		}else{
			ll temp=q2.top();
			if(temp>a[i]){
				q2.pop();
				q2.push(a[i]);
				s2[i]=s2[i+1]-temp+a[i];
			}else{
				s2[i]=s2[i+1];
			}
		}
	}
	ll MAX=-INF;
	for(int i=n;i<=2*n;i++){
		MAX=max(MAX,s1[i]-s2[i+1]);
	}
	printf("%lld\n",MAX);
}

Measured memory_bytes: 8180
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define pb(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w, h;
	cin >> h >> w;
	char c;
	int cnt = 0;
	REP(i, w) {
		REP(j, h) {
			cin >> c;
			if (c == '#') cnt++;
		}
	}
	if (cnt == h + w - 1) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int k, s;
	cin >> k >> s;
	int ans = 0;
	for (int i=0; i<=k; i++) {
		for (int j=0; j<=k; j++) {
			if (s-i-j >= 0 && s-i-j <= k) ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
N = int(input())
if N == 1:
    print(1)
elif N == 2:
    print(3)
else:
    L1 = 2
    L2 = 1
    L = 0
    for i in range(N-1):
        L = L1 + L2
        L1 = L2
        L2 = L
    print(L)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli count(int a[],int n,int k)
{
	int i,j;
	lli diff,cost;
lli dp[n];
	for(i=1;i<n;i++)
	dp[i]=-1;
	dp[0]=0;
	for(i=0;i<n-1;i++)
	{
	   for(j=1;j<=k;j++)
	   {
	    if((i+j)<n)
	    {
	    diff=abs(a[i+j]-a[i]);	
	    cost=dp[i]+diff;
	    if(dp[i+j]==-1 || cost<dp[i+j])
	    dp[i+j]=cost;
	    }
	    else
	    break;
	   }
	}
//	for(i=0;i<n;i++)
//	cout<<dp[i]<<" ";
	return dp[n-1];	
}

int main()
{
	int n,i,k;
	cin>>n>>k;
	int a[n];
	
	for(i=0;i<n;i++)
	cin>>a[i];
	cout<<count(a,n,k);
	
	return 0;
}

Measured memory_bytes: 4800
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N,M,D; cin>>N>>M>>D;
    vector<pair<ll,ll>> seg;
    ll C[M + 1] = {0};
    ll R[N + 1] = {0};
    ll mx_r = 0;
    ll mx_c = 0;
    
    for(ll i=0;i<D;++i)
    {
        ll x,y; cin>>x>>y;
        seg.push_back({x,y});
        C[y]++;
        R[x]++;
        mx_r = max(mx_r,R[x]);
        mx_c = max(mx_c,C[y]);
    }
    ll one = 0;
    ll two = 0;
    
    for(ll i=1;i<=N;++i)
    {
        if(R[i] == mx_r)
            one++;
    }
    
    for(ll i=1;i<=M;++i)
    {
        if(C[i] == mx_c)
            two++;
    }
    
    ll rem = 0;
    for(auto it: seg)
    {
        if((C[it.second] == mx_c) && (R[it.first] == mx_r))
            rem++;
    }
    
    //cout<<mx_r<<" "<<mx_c<<endl;
    
    if(one*two - rem == 0)
        cout<<(mx_r + mx_c - 1)<<endl;
    else
        cout<<(mx_r + mx_c)<<endl;
}

Measured memory_bytes: 16284
import itertools

N = int(input())
L = list(map(int, input().split()))

L.sort()

ans = 0
edge = list(itertools.combinations(L, 3))
for now in edge:
    if now[0] == now[1] or now[1] == now[2] or now[2] == now[0]:
        continue
    if now[0] + now[1] > now[2]:
        ans += 1

print(ans)


Measured memory_bytes: 20624
#include<iostream>

using namespace std;


int group(int Num)
{
	switch (Num) {
	case 4:
	case 6:
	case 9:
	case 11:
		return 0;

	case 2:
		return 1;

	default:
		return 2;
	}
}


int main()
{
	int x, y;

	cin >> x >> y;

	if (group(x) == group(y)) {
		cout << "Yes" << endl;
		return 0;
	}

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

Measured memory_bytes: 256
/// Thank you tanakh!!!
///  https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        n: usize,
        edges: [(usize1, usize1); n],
        q: usize,
        queries: [(usize1, usize1); q]
    );

    let mut graph = vec![vec![]; n];
    for &(a, b) in edges.iter() {
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut used = vec![false; n];
    let mut stack = Vec::new();
    let result = dfs(&graph, 0, n, &mut used, &mut stack);
    assert!(result != n);

    let mut is_cycle = vec![false; n];
    while let Some(v) = stack.pop() {
        is_cycle[v] = true;
        if v == result {
            break;
        }
    }

    for &(a, b) in queries.iter() {
        if is_cycle[a] && is_cycle[b] {
            println!("2");
        } else {
            println!("1");
        }
    }
}

fn dfs(
    graph: &Vec<Vec<usize>>,
    v: usize,
    p: usize,
    used: &mut Vec<bool>,
    stack: &mut Vec<usize>,
) -> usize {
    if used[v] {
        return v;
    }

    let n = used.len();
    used[v] = true;
    stack.push(v);
    for &next in graph[v].iter() {
        if next == p {
            continue;
        }
        let result = dfs(graph, next, v, used, stack);
        if result != n {
            return result;
        }
    }
    stack.pop();
    used[v] = false;
    n
}



Measured memory_bytes: 26988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    rep(i, n - 1) ans *= k - 1;
    cout << ans << endl;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define R(i,n) for(int i = 0; i < (n); i++)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class T> ostream &operator<<(ostream& os, set<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.FI << "," << P.SE << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 400010;
const int P = 998244353;
int sil[MAX],odw[MAX];
int pot(int a,int w){
  int r = 1;
  while(w){
    if(w & 1){
      r = r * a % P;
    }
    w/=2;
    a = a * a % P;
  }
  return r;
}
int dwu(int a,int b){
  return sil[a] * odw[b] % P * odw[a-b] % P;
}

int n,a,b,k;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> a >> b >> k;
  sil[0] = 1;
  R(i,n){
    sil[i+1] = sil[i] * (i + 1) % P;
  }
  R(i,n+1){
    odw[i] = pot(sil[i],P-2);
  }
  int res = 0;
  R(i,n+1){
    int pom = k - i * a;
    if(pom < 0 || pom % b != 0 || pom / b > n)continue;
    int j = pom / b;
    res += dwu(n,i) * dwu(n,j) % P;
  }
  cout << res % P << "\n";
}




Measured memory_bytes: 6400
X,Y,Z,K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

sums = []

for i in range(X):
    for j in range(Y):
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) > K:
                break
            sums.append(A[i]+B[j]+C[k])

for s in sorted(sums,reverse=True)[:K]:
    print(s)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC146B()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	for (auto& x : S)
	{
		int a = x - 'A';
		int b = (a + N) % 26;
		x = 'A' + b;
	}
	cout << S << endl;
}
int main()
{
	ABC146B();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n,x; cin >> n >> x;
    vector<ll> a(n);
    REP(i,n) cin >> a[i];
    ll ans=0;
    REP(i,n-1) {
        ll tmp = a[i] + a[i+1];
        if (tmp > x) {
            ll eat = tmp - x;
            ans += eat;
            a[i+1] = max(a[i+1] - eat,0LL);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
def shave(n):
    n_root = int(n**0.5)
    candidate = [i for i in range(3,n+1,2)]
    for i in range(3,n_root+2,2):
        candidate = [ j for j in candidate if j == i or j % i != 0]   
    candidate = [2] + candidate
    return candidate


def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist

prime_list = shave(100000)

prime_or_not_prime_list = [ 0 for i in range(10**5+1) ]
like_2017_list = [ 0 for i in range(10**5+1) ]
for i in prime_list:
    prime_or_not_prime_list[i] = 1
    j = (i + 1) // 2
    if prime_or_not_prime_list[j] == 1:
        like_2017_list[i] = 1
like_2017_list_sum = cumsum(like_2017_list)


q = int(input())
for i in range(q):
    l, r = [ int(v) for v in input().split() ]
    l, r = like_2017_list_sum[l-1], like_2017_list_sum[r]
    print(r-l)
    

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n) {
    if ((i + 1) % 2 == 1 && a[i] % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <set>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
int n;set<string> st;
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;++i)
  {
    string s;cin>>s;st.insert(s);
  }
  printf("%d\n",st.size());return 0;
}

Measured memory_bytes: 19312
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, m,n) for (int i = m; i < (int)(n); i++)
int main(){
long long  N,K; cin>>N>>K; long long A,B;
  A=N%K; B=(-1)*(A-K);
  cout<<min(A,B)<<endl;
  
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    rep(i,M) cin >> X.at(i);
    int ans = 0;
    vector<int> dist(M-1);
    sort(X.begin(), X.end());
    rep(i,M-1) {
        dist.at(i) = X.at(i + 1) - X.at(i);
    }
    sort(dist.begin(), dist.end());
    if (N < M) {
        rep(i,M-N) {
            ans += dist.at(i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4028
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;


int main()
{
	int PrefectureNum, CityYear;
	cin >> PrefectureNum >> CityYear;

	vector<int> Prefecture(CityYear), Year(CityYear);

	//入力
	vector<vector<int>> PrefectureYear(PrefectureNum+1);
	for (int i = 0; i < CityYear; i++) {
		cin >> Prefecture[i] >> Year[i];
		PrefectureYear[Prefecture[i]].push_back(Year[i]);
	}

	map<int,int > PrefectureRank;
	for (int i = 1; i <= PrefectureNum;i++) {

		//誕生年のソート
		sort(PrefectureYear[i].begin(), PrefectureYear[i].end());
		for (int j = 0; j < PrefectureYear[i].size(); j++) {
			PrefectureRank[PrefectureYear[i][j]] = j + 1;
		}	
	}

	for (int i= 0; i < CityYear; i++) {
		cout << setfill('0') << std::right << setw(6) << Prefecture[i] << setfill('0') << std::right << setw(6) << PrefectureRank[Year[i]] << "\n";
	}
	
    return 0;
}


Measured memory_bytes: 12416
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
inf = 10 ** 9
dp = [[inf] * W for _ in range(H)]
dp[0][0] = 0 if s[0][0] == '.' else 1

for y in range(H):
    for x in range(W):
        if y < H - 1:
            dp[y + 1][x] = min(dp[y + 1][x], dp[y][x] +
                               (1 if s[y][x] == '.' and s[y + 1][x] == '#' else 0))
        if x < W - 1:
            dp[y][x + 1] = min(dp[y][x + 1], dp[y][x] +
                               (1 if s[y][x] == '.' and s[y][x + 1] == '#' else 0))

print(dp[-1][-1])

Measured memory_bytes: 42608
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,k=gsmi
pp=gsmi
puts pp.min(k).sum

Measured memory_bytes: 14352
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        long ans = 0;
        if(N <= K/2){
            ans = N;
        }else if(N < K){
            ans = K-N;
        }else{
            N = N%K;
            if(N<=K/2){
                ans = N;
            }else{
                ans = K-N;
            }
        }
        System.out.println(ans);
    }

}


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

int main(){
int a,b;
cin >> a >>b;
if(a<b){
cout << "a < b" <<endl;
}

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

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


Measured memory_bytes: 3096
n, m, x, y = gets.split.map(&:to_i)
xmin, xmax = (gets.split.map(&:to_i) << x).minmax
ymin, ymax = (gets.split.map(&:to_i) << y).minmax

if xmax < ymin || ymax < xmin
  puts 'No War'
else
  puts 'War'
end


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

struct UnionFind {
        int n;
        vector<int> parent;
        vector<int> rank;
        vector<int> num;
        int find(int x) {
                if (parent[x] == x) return  x;
                return parent[x] = find(parent[x]);
        }
        UnionFind(int n_) {
                n = n_;
                parent.resize(n);
                for (int i = 0; i < n; i ++) parent[i] = i;
                rank.assign(n, 0);
                num.assign(n, 1);
        }
        void unite(int x, int y) {
                if ((x = find(x)) != (y = find(y))) {
                        if (rank[x] < rank[y]) {
                                parent[x] = y;
                                num[y] += num[x];
                        } else {
                                parent[y] = x;
                                if (rank[x] == rank[y]) rank[x] ++;
                                num[x] += num[y];
                        }
                        n --;
                }
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int get() { return n; }
        int get(int x) { return num[find(x)]; }
};

int main() {
        int i, j;
        int n, k, l;
        cin >> n >> k >> l;
        UnionFind uf1(n), uf2(n);
        for (i = 0; i < k; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                uf1.unite(a, b);
        }
        for (i = 0; i < l; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                uf2.unite(a, b);
        }
        vector<pair<int, int>> p;
        for (i = 0; i < n; i ++) p.emplace_back(uf1.find(i), uf2.find(i));
        sort(p.begin(), p.end());
        for (i = 0; i < n; i ++) {
                pair<int, int> pp = make_pair(uf1.find(i), uf2.find(i));
                int ans = upper_bound(p.begin(), p.end(), pp) - lower_bound(p.begin(), p.end(), pp);
                cout << ans << (i == n - 1 ? '\n' : ' ');
        }
        return 0;
}


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

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int>> min_heap;

// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

int n;
set<string> st;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
    string stt;
    cin >> stt;
    st.insert(stt);}
    cout << st.size() << "\n";
}

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

#define sz 200005

long long int arr[sz];

int main(){

    long long int n,i,x=0;
    cin>>n;
    for(i=1; i<=n; i++){
        cin>>arr[i];
       x= x^arr[i];
    }
    for(i=1; i<=n; i++){
        x= x^arr[i];
        x= x^arr[i-1];
        if(i>1)cout<<' ';
        cout<<x;
    }
    return 0;
}


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

const int MAXN = 55;
const int dx[4] = { 0, 0, 1, -1 };
const int dy[4] = { 1, -1, 0, 0 };
char mp[MAXN][MAXN];
bool se[MAXN][MAXN];
int n, m, dis[MAXN][MAXN];
queue<pair<int, int> > Q;

bool isval(int x, int y) {
	return x >= 0 && y >= 0 && x < n && y < m && mp[x][y] == '.';
}

void BFS(pair<int, int> a) {
	for (int k = 0; k < 4; k++) {
		int x = a.first + dx[k], y = a.second + dy[k];
		if (isval(x, y) && !se[x][y]) {
			se[x][y] = 1;
			Q.push({ x, y });
			dis[x][y] = dis[a.first][a.second] + 1;
		}
	}
}

int main() {
	cin >> n >> m;
	int cnt = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> mp[i][j], cnt += mp[i][j] == '#';
	dis[n - 1][m - 1] = -1;
	Q.push({ 0, 0 });
	se[0][0] = 1;
	dis[0][0] = 1;
	while (!Q.empty())
		BFS(Q.front()), Q.pop();
	if (dis[n - 1][m - 1] == -1)
		return cout << -1, 0;
	cout << n * m - cnt - dis[n - 1][m - 1];
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  int b[m];
  rep(i, m) cin >> b[i];

  int a[m];
  int ans = 0;
  rep(i, n) {
    rep(j, m) cin >> a[j];
    int sum = 0;
    rep(j, m) sum += a[j] * b[j];
    sum += c;
    if (sum > 0) ++ans;
  }

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


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<ll,int> P;

int cnt[200010];

ll f(ll x, ll y){
    while(x%y!=0){
        ll t =y;
        y = x%y;
        x = t;
    }
    return y;
}

int main(){
    ll a, b,c,d;
    cin >> a >> b >> c >> d;
    ll sa = f(c,d);
    ll ma = c*d/sa;
    ll ans = 0;
    ans += b- a + 1;
    ans -= b/c - (a-1)/c;
    ans -= b/d - (a-1)/d;
    ans += b/ma - (a-1)/ma;
    cout << ans << endl;
    // cout << sa << endl;
    // cout << ma << endl;
    // cout << b-a + 1 - (b-a+1)/c - (b-a+1) /d + (b-a+1)/f(c,d) << endl;
    // cout << f(c,d) << endl;
    return 0;
}

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

namespace _2334
{
	class Program
	{
		static bool Judge(Tuple<int, int> a, Tuple<int, int> b, Tuple<int, int> c, Tuple<int, int> d)
		{
			long ta = (c.Item1 - d.Item1) * (a.Item2 - c.Item2) + (c.Item2 - d.Item2) * (c.Item1 - a.Item1);
			long tb = (c.Item1 - d.Item1) * (b.Item2 - c.Item2) + (c.Item2 - d.Item2) * (c.Item1 - b.Item1);
			long tc = (a.Item1 - b.Item1) * (c.Item2 - a.Item2) + (a.Item2 - b.Item2) * (a.Item1 - c.Item1);
			long td = (a.Item1 - b.Item1) * (d.Item2 - a.Item2) + (a.Item2 - b.Item2) * (a.Item1 - d.Item1);

			return tc * td <= 0 && ta * tb <= 0;
		}
		static double Calc(Tuple<int, int> a, Tuple<int, int> b)
		{
			return Math.Sqrt(Math.Pow(a.Item1 - b.Item1, 2) + Math.Pow(a.Item2 - b.Item2, 2));
		}
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			Tuple<int, int>[] a = new Tuple<int, int>[x[0]];
			Tuple<int, int>[] b = new Tuple<int, int>[x[1]];
			for (int i = 0; i < x[0]; i++)
			{
				int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
				a[i] = new Tuple<int, int>(n[0], n[1]);
			}
			for (int i = 0; i < x[1]; i++)
			{
				int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
				b[i] = new Tuple<int, int>(n[0], n[1]);
			}
			double ret = double.MaxValue;
			for (int i = 0; i < x[0]; i++)
			{
				for (int j = 0; j < x[0]; j++)
				{
					if (!Judge(a[0], a[i], b[0], b[1]) && !Judge(a[i], a[j], b[0], b[1]) && !Judge(a[j], a[1], b[0], b[1]))
					{
						ret = Math.Min(ret, Calc(a[0], a[i]) + Calc(a[i], a[j]) + Calc(a[j], a[1])
							+ Calc(b[0], b[1]));
					}
				}
			}
			for (int i = 0; i < x[1]; i++)
			{
				for (int j = 0; j < x[1]; j++)
				{
					if (!Judge(a[0], a[1], b[0], b[i]) && !Judge(a[0], a[1], b[i], b[j]) && !Judge(a[0], a[1], b[j], b[1]))
					{
						ret = Math.Min(ret, Calc(a[0], a[1])
							+ Calc(b[0], b[i]) + Calc(b[i], b[j]) + Calc(b[j], b[1]));
					}
				}
			}
			Console.WriteLine(ret == double.MaxValue ? -1 : ret);
		}
	}
}


Measured memory_bytes: 18488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
const ll INF = 1e17;
 
int V, E;
struct egde{int from, to; ll cost;};
vector<egde> es;
 
ll longest_path(int s){
  vector<ll> d(V,-INF);
  d[s] = 0;
  int c = 0;
  while(c <= V){
    rep(i,E){
      egde e = es[i];
      if(d[e.from] != -INF && d[e.to] < d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
      }
    }
    c++;
  }
  return d[V-1];
}
 
bool find_positive_loop(){
  vector<ll> d(V,-INF);
  rep(i, 2*V){
    rep(j, E){
      egde e = es[j];
      if(d[e.to] < d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        if(i >= V && e.to == V-1) return false;
      }
    }
  }
  return true;
}
 
int main(){
  cin >> V >> E;
  rep(i,E){
    int a, b; ll c;
    cin >> a >> b >> c;
    a--; b--;
    es.push_back({a, b, c});
  }
  if(!find_positive_loop()) cout << "inf" << endl;
  else cout << longest_path(0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string s; cin>>s;

	for(int i=0; i<s.size(); i+=2){
		cout<<s[i];
	}
	puts("");
}


Measured memory_bytes: 512
n=int(input())
c=input()
l=0
r=n-1
score=0
for i in range(n):
  if l>=r:
    break
  if c[l]=="W":
    if c[r]=="R":
      score=score+1
      l=l+1
      r=r-1
    else:
      r=r-1
  else:
    l=l+1
print(score)

Measured memory_bytes: 9464
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>x(n);
    rep(i,n)cin>>x[i];
    ll i=0;
    ll ans=1;
    ll cnt=1;
    REP(i,1,n){
        if(x[i-1]>=2*cnt-1){
            cnt++;
        }else{
            ans*=cnt;
            cnt--;
            ans%=inf;
            i--;
        }
    }
    while(cnt){
        ans*=cnt;
        cnt--;
        ans%=inf;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
use std::io::stdin;

fn main() {
    let mut s = String::new();
    let _ = stdin().read_line(&mut s).unwrap();
    let vec = s.trim().split(' ');
    if vec.clone().filter(|&x| x == "5").count() == 2 && vec.clone().filter(|&x| x == "7").count() == 1 {
        println!("YES");
    } else {
        println!("NO");
    }
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl;
#define CNO cout<<"No"<<endl;

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int m,n;
    cin >> m >> n;
    if(m==0) return 0;
    vector<bool> h(10000000,false);
    int count=0;
    repp(i,m,10000000){
      if(!h[i]){
        count++;
        for(int j=i;j<10000000;j+=i){
          if(!h[j]) h[j]=true;
        }
      }
      if(count==n) break;
    }
    repp(i,m,10000000){
      if(!h[i]){
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}



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

int main(){
    int n; cin >> n;
    for(int i = 1; i < 10; i++){
        if(n % i == 0 && n / i < 10){
            cout << "Yes" << endl;
            return 0;
        }
        //else cout << "No" << endl;
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main(){

  int N;
  long long m;
  vector <int> a;

  cin >> N;

  for(int i = 0;i<N;i++){
    cin >> m;
    a.push_back(m);
  }
  int four = 0,two = 0;
  for(int i = 0;i < N;i++){
    if(a[i] % 4 == 0){
      four++;
    }
    else if((a[i]%4 != 0)&&(a[i]%2==0)){
      two++;
    }
  }

  if((2*four+1) >= N){
    cout << "Yes" << endl; 
  }

  else if((N - 2*four) <= two){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

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

struct UnionFind{
  int n;
  vector<int> r, p;
  UnionFind() {}
  UnionFind(int sz): n(sz), r(sz, 1), p(sz, 0){ iota(p.begin(), p.end(), 0); }
  int find(int x) {
    return (x == p[x] ? x : p[x] = find(p[x]));
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  void unite(int x, int y){
    x = find(x); y = find(y);
    if ( x == y ) return;
    if ( r[x] < r[y] ) swap(x, y);
    r[x] += r[y];
    p[y] = x;
  }
};

struct Edge {
  int cost, to, from;
  bool operator<(const Edge& e) const {
    return cost < e.cost;    
  }  
};

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

  vector<Edge> G;
  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      int cost;
      cin >> cost;
      if ( j > i && cost >= 0 ) G.push_back({cost, i, j});      
    }
  }

  sort(G.begin(), G.end());

  UnionFind uf(n);
  int cnt = 0;
  int sum = 0;
  for ( Edge e: G ) {
    int cost = e.cost, to = e.to, from = e.from;
    if ( uf.same(to, from) ) continue;
    sum += cost;
    if ( ++cnt >= n-1 ) break;
    uf.unite(to, from);    
  }

  cout << sum << endl;
  
  return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MOD 1000000007
typedef long long  ll;

using namespace std;

/* 約数の列挙(O(√N)) */
vector<ll> enum_divisors(ll N) {
	vector<ll> res;
	for (ll i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N / i != i) res.push_back(N / i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

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

	ll n;
	cin >> n;

	vector<ll> vec = enum_divisors(n);

	ll half = vec[(vec.size() - 1) / 2];
	ll ans;
	if (vec.size() % 2 == 0) {
		ans = log10(max(half, n / half)) + 1;
	}
	else {
		ans = log10(half) + 1;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3848
#include <stdio.h>
#include<string>
#include<iostream>
using namespace std;

int main(void)
{
	int N;
	cin >> N;
	int count = 1;
	while (count*count <= N) {
		count++;
	}

	cout << (count-1)*(count-1) << endl;

	return 0;
	
}

Measured memory_bytes: 504
#include <cstdio>
#include <algorithm>

using namespace std;

short dp[5001][5001];

int main()
{
	int N, M;
	
	scanf("%d %d", &N, &M);
	
	for (int i = 0; i < M; i++){
		int a, b, x;
		
		scanf("%d %d %d", &a, &b, &x);
		dp[a - 1][b - 1] = x + 1;
	}
	
	int res = 0;
	for (int i = 0; i < N; i++){
		for (int j = 0; j <= i; j++){
			res += !!dp[i][j];
			dp[i + 1][j] = max((short)(dp[i][j] - 1), dp[i + 1][j]);
			dp[i + 1][j + 1] = max((short)(dp[i][j] - 1), dp[i + 1][j + 1]);
		}
	}
	
	printf("%d\n", res);
	
	return (0);
}

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

int gcd(int A, int B) {
  if (B == 0) return A;
  else return gcd(B, A % B);
}

int main() {
  int A, B, K;
  cin >> A >> B >> K;

  int con = 0;
  for (int i = gcd(A, B); i > 0; i--) {
    if (A % i == 0 && B % i == 0) con++;
    if (con == K) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#define ll long long int
#include <bits/stdc++.h>
//#include <fstream>
using namespace std;
 
#define         ff               first
#define         ss               second
#define         mp               make_pair
#define         pb               push_back
#define         pf               push_front
#define         vi               vector<ll>
#define         pii              pair<ll,ll>
#define         qi               queue<ll>
#define         mem(a,b)         memset(a,b,sizeof(a))
#define         print(a)         cout<<a<<'\n'
#define         sorted(arr)      sort(arr.begin(),arr.end())
#define         gcd(a,b)         gcd((a),(b))
#define         lcm(a,b)         ((a)*(b))/gcd((a),(b))
#define         all(v)           v.begin(),v.end()
#define         read(a)          scanf("%d", &a)
#define         f(a,n)           for(ll i=a;i<n;i++)
#define         in2(n,m,arr)     for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define         debug(a)         cerr<<a<<" ";
#define         debug1(a)        cerr<<a<<'\n'
 
/*typedef tree<int, null_type, less<int>, rb_tree_tag , tree_order_statistics_node_update> Set;*/
 
 
const unsigned ll mod = 1e9 + 7 ;
const ll inf = (ll)1e18 + 2;
const ll N = (ll)1e6 + 2;
 
//template<typename... T>
//void write(T&... args)
//{
//    ((cout << args << ' '), ...);
//}
//ll power ( ll x , unsigned ll y)
//{
//    ll res = 1;
//    while (y > 0)
//    {
//        if (y & 1)
//            res = (res * x) % mod ;
//        y = y >> 1;
//        x = (x * x) % mod;
//    }
//    return res % mod ;
//}
//
//struct node{
//    ll x , y , z;
//};
//map<pair<ll, ll>,ll> c;
//vector<set<ll>> tree;
//vector<ll> ar ;
//set<ll> s;
//ll get(ll x)
//{
//    if(x == ar[x])
//        return x;
//    return ar[x] = get(ar[x]);
//}
//void merge(ll a ,ll b)
//{
//    a = get(a);
//    b = get(b);
//    if(a == b)
//    {
//        return ;
//    }
//    ar[b] = ar[a];
//    //ans[a] += ans[b];
//    //return true;
// }
//
//ll sev[275];
//vector<ll> pri;
//void seive()
//{
//    for(ll i = 2 ; i < 275 ; i ++)
//    {
//        if(!sev[i])
//        {
//            for(ll j = i ; j < 275 ; j += i)
//            {
//                if(!sev[j])
//                    sev[j] = i;
//            }
//        }
//        if(sev[i] == i)
//            pri.pb(i);
//    }
//}
void solve()
{
    ll n , a;
    cin >> n;
    ll ans = 1 , mx = 0 ;
    for(ll i = 0 ; i < n ; i ++)
    {
        cin >> a;
        if(i == 0)
            mx = a;
        else
        {
            if(mx > a)
                ans ++ , mx = a;
        }
    }
    print(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t ;
    t = 1;
    //cin >> t;
    //seive();
    while(t --)
    {
        solve();
    }
    //cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
 


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;


int main(void) {

  string t, p;
  cin >> t >> p;
  if( t.size() < p.size() ) return 0;
  for(int i=0; i<=t.size()-p.size(); i++){
    bool f = true;
    for(int j=0; j<p.size(); j++){
      if( p[j] != t[i+j] ) f = false;
    }
    if( f ) cout << i << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 3204