akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll a[maxn];
int main()
{
    ll i,j,k,m,n;
    cin>>n;
    ll cnt=0,ans=0,sum=0;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if((2*sum)%(n*(n+1))!=0)
        
    {
        cout<<"NO"<<endl;
        return 0;
    }
    else
    {
        ans=(2*sum)/(n*(n+1));
        for(i=1; i<=n; i++)
        {
            if(i==n)
            {
                if((a[i]-a[1]+ans)%n!=0||(a[i]-a[1]+ans)<0)
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
            else
            {
                if((a[i]-a[i+1]+ans)%n!=0||(a[i]-a[i+1]+ans)<0)
                {
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
        }
        cout<<"YES"<<endl;
    }
    return 0;
}


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

int main() {
	int a, b, c; cin >> a >> b >> c;
	int maxN = 3 * max({ a,b,c });
	int rest = maxN - a - b - c;

	if (rest % 2 == 0)cout << rest / 2 << endl;
	else cout << (rest + 3) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        try (final Scanner sc = new Scanner(System.in)) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            if ((A < C && C < B) || (B < C && C < A)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

}


Measured memory_bytes: 24148
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val tree0 = new Array[Int](500001)
  val tree1 = new Array[Int](500001)
  val tree2 = new Array[Int](500001)
  val out:BufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0

  def insert(i:Int, j:Int):Unit =
    if(tree0(i) > tree0(j)) {
      if(tree1(i) == -1) tree1(i) = j
      else insert(tree1(i), j)
    } else {
      if(tree2(i) == -1) tree2(i) = j
      else insert(tree2(i), j)
    }

  def inOrder():Unit = {
    var stack:List[Int] = Nil
    var curr = 0
    var flg = true

    while(flg) {
      while(curr != -1) {
        stack = curr::stack
        curr = tree1(curr)
      }
      if(curr == -1 && stack != Nil) {
        val item = stack.head
        stack = stack.tail
        out.write(" ")
        out.write(tree0(item).toString)
        if(count<100) count += 1
        else {
          out.flush
          count = 0
        }
        curr = tree2(item)
      } else {
        flg = false
      }
    }
  }

  def scan(list:List[Int]):Unit = {
    list match {
      case Nil => ()
      case hd::tl => {
        out.write(" ")
        out.write(tree0(hd).toString)
        if(count<100) count += 1
        else {
          out.flush
          count = 0
        }
        val hd2 =
          if(tree2(hd) != -1 && tree1(hd) != -1) tree1(hd)::tree2(hd)::tl
          else if(tree2(hd) != -1 && tree1(hd) == -1) tree2(hd)::tl
          else if(tree2(hd) == -1 && tree1(hd) != -1) tree1(hd)::tl
          else tl
        scan(hd2)
      }
    }
  }

  def preOrder(i:Int):Unit =
    if(i == -1) return
    else scan(i::Nil)

  def main(args:Array[String]) = {
    val n = readInt
    var j = 0

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" => {
          tree0(j) = s(1).toInt
          tree1(j) = -1
          tree2(j) = -1
          if(j!=0) insert(0, j)
          j+=1
        }
        case _ => {
          inOrder()
          out.write("\n")
          out.flush()
          preOrder(0)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll N; cin >> N;
    vector<string> S(N); REP(i, N) cin >> S[i];
    string T; cin >> T;
    
    ll maxi = 1;
    ll mini = N+1;
    REP(i, N) {
        {
            string temp = S[i];
            replace(ALL(temp), '?', 'a');
            if (temp < T) maxi++;
        }
        {
            string temp = S[i];
            replace(ALL(temp), '?', 'z');
            if (temp > T) mini--;
        }
    }
    if (mini > maxi) swap(mini, maxi);
    
    vector<ll> ans(maxi - mini + 1);
    iota(ALL(ans), mini);
    cout << join(ans) << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 60;
const long long limit = 1500000000;
struct edge {
    int to; long long cost;
};
struct state {
    int pos, tp; long long cost;
};
bool operator<(const state& s1, const state& s2) {
    return s1.cost != s2.cost ? s1.cost > s2.cost : s1.pos * 2 + s1.tp < s2.pos * 2 + s2.tp;
}
long long dist[100003][2];
bool visited[100003][2];
vector<edge> G[100003];
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> P(N), C(N), J(N);
    for (int i = 0; i < N; ++i) cin >> P[i];
    for (int i = 0; i < N; ++i) cin >> C[i], --C[i];
    for (int i = 0; i < N; ++i) cin >> J[i];
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c; --a, --b;
        G[a].push_back(edge{ b, c });
        G[b].push_back(edge{ a, c });
    }
    for (int i = 0; i < N; ++i) {
        dist[i][0] = dist[i][1] = inf;
    }
    dist[0][0] = 0;
    priority_queue<state> que;
    que.push(state{ 0, 0, 0 });
    while (!que.empty()) {
        state u = que.top(); que.pop();
        if(visited[u.pos][u.tp]) continue;
        visited[u.pos][u.tp] = true;
        long long d = dist[u.pos][u.tp];
        for (edge e : G[u.pos]) {
            if (dist[e.to][u.tp] > d + e.cost) {
                dist[e.to][u.tp] = d + e.cost;
                que.push(state{ e.to, u.tp, dist[e.to][u.tp] });
            }
        }
        if (u.tp == 0 && dist[u.pos][1] > d + limit - P[u.pos]) {
            dist[u.pos][1] = d + limit - P[u.pos];
            que.push(state{ u.pos, 1, dist[u.pos][1] });
        }
    }
    vector<long long> ans(K, -inf);
    for (int i = 0; i < N; ++i) {
        ans[C[i]] = max(ans[C[i]], limit - (dist[i][0] + dist[i][1]) + J[i]);
    }
    for (int i = 0; i < K; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}



Measured memory_bytes: 22228
#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#ifdef ilyes
	#define dump(x ...) cerr  <<  "|dumping| "  <<  # x  <<  "  =  ", _dump(x) 
#else
	#define dump(...) 1998
#endif
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
// #define all(x) x.begin(),x.end()
#define size(x) (int)x.size()
#define ln '\n'
#define __ ' '
#define LL long long
#define pii pair<int,int>
const int INF = 1e9;
const int N = 2e5;

#define all(x) begin(x),end(x)
#define begin(x) x.begin()
#define end(x) x.end()
#define empty(x) x.empty()

string str;
int n;
vector<int> pos[26];
char nxt[N+3];
int dp[N+3];

int main(){ FAST
	cin >> str;
	n = size(str);
	for(int i=0; i<=size(str)-1; ++i){
		pos[str[i]-'a'].emplace_back(i+1);
	}
	
	for(char c='a'; c<='z'; ++c){
		if(empty(pos[c-'a'])){
			cout << c << ln;
			return 0;
		}
	}

	for(int i=n; i>=1; --i){
		map<char, int> nxtAns;
		for(char c='a'; c<='z'; ++c){
			auto it = upper_bound(all(pos[c-'a']), i);
			if(it == end(pos[c-'a'])) nxtAns[c] = 0;
			else nxtAns[c] = dp[*it];
		}

		nxt[i] = 'a';
		for(char c='a'; c<='z'; ++c) if(nxtAns[c] < nxtAns[nxt[i]]) nxt[i] = c;

		dp[i] = 1 + nxtAns[nxt[i]];
	}

	int st = 'a';
	for(char c='a'; c<='z'; ++c){
		if(dp[*begin(pos[c-'a'])] < dp[*begin(pos[st-'a'])]) st = c;
	}

	int ind = *begin(pos[st-'a']);
	while(true){
		cout << str[ind-1];
		auto it = upper_bound(all(pos[nxt[ind]-'a']), ind);
		if(it == end(pos[nxt[ind]-'a'])){
			cout << nxt[ind];
			break;
		}
		else ind = *it;
	}
	cout << ln;

}

Measured memory_bytes: 2452
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn pow(base: i64, mut exp: usize) -> i64 {
    let mut acc = 1;
    while exp > 0 {
        acc = acc * base;
        exp -= 1;
    }
    return acc
}

fn main() {
    let n: usize = read();
    let ai: Vec<i64> = (0..n).map(|_| read()).collect();

    let mut ans = std::i64::MAX;
    for i in 0..100 {
        let p = i + 1;
        let v: i64 = ai.clone().iter().map(|a| pow(a - (p as i64), 2)).sum();
        if v < ans {
            ans = v;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		int num = a * (int)Math.pow(10, (int)Math.log10(b)+1) + b;
		int sqrt = (int)Math.sqrt(num);
		if(num == sqrt * sqrt)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 21844
# import numpy as np
# import scipy as sp
# import sys
# input = sys.stdin.readline
# print(a,b,c,sep="") # 半角スペースなしで出力(abc)
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=list(map(int, input().split()))  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# a=[int(input()) for _ in range (n)]  #リスト入力  改行でa1 ... anのとき
# s=[list(map(str,list(input()))) for i in range(h)]  # 文字列の二次元配列入力
# s = [list(map(int, input().split())) for i in range(n)] # 数値の二次元配列入力
# a = b[:], a = [x[:] for x in b] # deepcopy
# chr(ord('a') + 1) # chrのインクリメント
# s.sort(key=lambda x: x[1], reverse=False) # 2番目の要素で昇順にソート（Trueなら降順）
#　

import math
n, m = list(map(int, input().split()))


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


ans = 0
if m >= 2:
    ans += combinations_count(m, 2)
if n >= 2:
    ans += combinations_count(n, 2)
print(ans)


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

// 最大公約数
long long gcd(long long a, long long b){
    while(b != 0){
        long long tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

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

    vector<long long> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    vector<double> p(n);
    for(int i=0; i<n; ++i){
        cin >> p[i];
        p[i] /= 100.0;
    }

    double ret = 0.0;
    for(int i=1; i<(1<<n); ++i){
        bitset<20> use(i);
        long long x = 1; // 選択された数字の最小公倍数
        for(int j=0; j<n; ++j){
            if(use[j]){
                x /= gcd(x, a[j]);
                if(LLONG_MAX / x < a[j]){
                    x = -1;
                    break;
                }
                x *= a[j];
            }
        }

        if(x == -1)
            continue;
        long long y = m / x; // xで割り切れる整数の個数

        double q = 1.0;
        for(int j=0; j<n; ++j){
            if(use[j])
                q *= p[j];
        }

        if(use.count() % 2 == 0)
            ret -= y * q;
        else
            ret += y * q;
    }

    printf("%.10f\n", ret);

    return 0;
}

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

using namespace std;

#define fo(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define lli long long int
#define all(c) c.begin(),c.end()
#define lower(c) tolower(c)
#define upper(c) toupper(c)
#define MAX(c) *max_element(c.begin(),c.end())
#define MIN(c) *min_element(c.begin(),c.end())
#define len(c) c.size()
const int MOD = 1000000007;
const int MX = 2e5 + 5;
const int INF = 1e9 + 10;
const lli LINF = 1e18;

void solve() {
	int n;
	cin >> n;
	vi a;
	fo(i,n){int t;cin>> t;a.pb(t);}
	sort(all(a));
	int ans = 0;
	fo(i,n){
		for(int j = 0;j<i;j++){
			for(int k=0;k<j;k++){
				if(a[k]!=a[j]&&a[i]!=a[j]&&a[k]+a[j]>a[i]){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 3608
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;
 
 
#define prec(i) cout << fixed << setprecision(i)
 
const long long int MOD = 1000000007;
 
long long int fact(long long int k) {
	long long int sum = 1;
	for (long long int i = 2; i <= k; i++)
		sum *= i;
 
	return sum;
}
 
int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}
 
long long int pow_mod(int a, int b) {
	long long int  ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;
 
	return ans;
}
 
 
int main()
{
	long long int n, cnt = 0;
	string s, t;
 
	cin >> n;
	cin >> s >> t;
	
	for (int i = 0; i < n; i++) {
		cout << s[i] << t[i];
	}
	cout << endl;
 
 
 
 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
#define int long long int
int32_t main()
{
	int n,k;
	cin>>n>>k;
	int count[n+1]={0};
	int j;
	for(j=1;j<=k;j++)
    {
		int m;
		cin>>m;
		int i;
		for(i=0;i<m;i++)
		{
			int x;
			cin>>x;
			count[x]++;
		}
	}
	int answer=0;
	for(j=1;j<=n;j++)
	{
		if(count[j]==0)
		  answer++;
	}
	cout<<answer<<endl;
}


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

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

    map<ll, int> mp;
    for (int i = 0; i < N; ++i) {
        ll a;
        int b;
        cin >> a >> b;

        if (mp.count(a) == 0) {
            mp[a] = b;
        }
        else {
            mp[a] += b;
        }
    }

    int cnt = 0;
    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if (cnt + itr->second > M) {
            ans = ans + (M - cnt) * itr->first;
            break;
        }
        else {
            cnt += itr->second;
            ans = ans + itr->first * itr->second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no = 1;
#define w(x) int x; cin>>x; while(x--)

int main() {
	FIO
	string S;
	cin >> S;
	int n = S.size(), ans = 0;
	for(int i = 0; i < n; i++) {
		ans += (S[i] - '0');
	}
	if(ans % 9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int countT = 0;
    int countA = 0;
    while (c > 0){
        c = c - b;
        countA++;
    }
    while ( a > 0){
        a = a - d;
        countT++;
    }
    
    if ( countT >= countA){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>m>>str;
    n=sz(str);
    rep(i,0,n-1){
        int a=str[i]-'A';
        a=(a+m)%26;
        char c=a+'A';
        cout<<c;
    }
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define int long long
#define hh puts("")
#define pc putchar
#define ite vector<int>::iterator
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
using namespace std;
int n,m,use,now;
char a[100005],b[100005];
vector<int> v[1005];
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+ch-'0';ch=getchar();}
    return ret*ff;
}
void write(int x){
    if(x<0){x=-x;putchar('-');}
    if(x>9) write(x/10);
    putchar(x%10+48);
}
signed main(){
	scanf("%s",a+1);
	scanf("%s",b+1);
	n=strlen(a+1);
	m=strlen(b+1);
	for(int i=1;i<=n;i++) v[a[i]-'a'].push_back(i);
	for(int i=1;i<=m;i++){
		if(!v[b[i]-'a'].size()){
			printf("-1");
			return 0;
		}
	}
	now=v[b[1]-'a'][0];
	for(int i=2;i<=m;i++){
		ite it=upper_bound(v[b[i]-'a'].begin(),v[b[i]-'a'].end(),now);
		if(it==v[b[i]-'a'].end()){
			use++;
			now=v[b[i]-'a'][0];
		}
		else now=*it;
	}
	printf("%lld",use*n+now);
    return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n,m,k;
int p[N], rk[N], sz[N];
int ct[N];
int find(int x){
    return p[x] == x ? x : p[x] = find(p[x]);
}
void unionset(int x, int y){
    x = find(x), y=  find(y);
    if (x == y) return ;
    if (rk[x] < rk[y]) swap(x,y);
    p[y] = x;
    sz[x] += sz[y];
    if (rk[x] == rk[y]) rk[x]++;
}
int main(){
    scanf("%d%d%d",&n,&m,&k);
    iota(p,p+N,0);
    fill(sz,sz+N,1);
    for (int i = 0; i < m; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        unionset(a,b);
        ct[a]--,ct[b]--;
    }
    for (int i = 1; i <= n; i++){
        ct[i] += sz[find(i)]-1;
    }
    for (int i = 0; i < k; i++){
        int c,d;
        scanf("%d%d",&c,&d);
        if (find(c) == find(d)){
            ct[c]--;
            ct[d]--;
        }
    }
    for (int i = 1; i <= n; i++){
        printf("%d ",ct[i]);
    }
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;

}

signed main() {
	string s;

	cin >> s;

	ll now = 0;
	ll cnt = 0;
	ll ans = 0;
	
	if (s.size() < 3) {
		cout << 0 << endl;
		return 0;
	}

	while (now < s.size() - 2) {
		if (s[now] != 'A') {
			now++;
			cnt = 0;
			continue;
		}

		string ss = s.substr(now, 3);
		
		if (ss == "ABC") {
			ans += cnt + 1;
			now += 2;
			s[now] = 'A';
		}
		else {
			cnt++;
			now++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#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>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}


struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;

bool solve(){
    vector<L> a, b;
    a.push_back(L(P(xa1, ya1), P(xa2, ya1)));
    a.push_back(L(P(xa2, ya1), P(xa2, ya2)));
    a.push_back(L(P(xa2, ya2), P(xa1, ya2)));
    a.push_back(L(P(xa1, ya2), P(xa1, ya1)));
    b.push_back(L(P(xb1, yb1), P(xb2, yb1)));
    b.push_back(L(P(xb2, yb1), P(xb2, yb2)));
    b.push_back(L(P(xb2, yb2), P(xb1, yb2)));
    b.push_back(L(P(xb1, yb2), P(xb1, yb1)));
    REP(i, a.size()) REP(j, b.size()) if(intersectSS(a[i], b[j])) return true;
    if(xa1 <= xb1 && ya1 <= yb1 && xa2 >= xb2 && ya2 >= yb2) return true;
    if(xb1 <= xa1 && yb1 <= ya1 && xb2 >= xa2 && yb2 >= ya2) return true;
    return false;
}

int main() {
  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &xa1, &ya1, &xa2, &ya2, &xb1, &yb1, &xb2, &yb2) != EOF) cout <<(solve() ? "YES" : "NO") <<endl;
  return 0;
}

Measured memory_bytes: 1256
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    A,B,C,X,Y = i_map()

    Z = max(X,Y)

    ans = INF
    C *= 2

    for i in range(0,Z+1):
        trial = i*C
        At = X - i
        Bt = Y - i
        if At > 0:
            trial += At*A
        if Bt > 0:
            trial += Bt*B
        ans = min(ans, trial)
    print(ans)

  
  
 
  
if __name__=="__main__":
    main()


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
 string N;
  cin >> N;
  if(N[2] == N[3] && N[4] == N[5]) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

	static void exec(Scanner in, PrintStream out) {
		int A = in.nextInt();
		int B = in.nextInt();
		int C = in.nextInt();
		int X = in.nextInt();
		int Y = in.nextInt();
		if (C * 2 < A + B) {
			int price = C * 2 * Math.min(X, Y);
			if (X < Y) {
				if (C * 2 < B) {
					price += C * 2 * (Y - X);
				} else {
					price += B * (Y - X);
				}
			} else if (X > Y) {
				if (C * 2 < A) {
					price += C * 2 * (X - Y);
				} else {
					price += A * (X - Y);
				}
			}
			out.println(price);
		} else {
			out.println(A * X + B * Y);
		}
	}

	public static void main(String[] args) {
		exec(new Scanner(System.in), System.out);
	}

}


Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int book[100];
int cnt;
char s[10];
int main()
{cin>>n;
	for(int i=1;i<=n;++i)
	{
		scanf("%s",s);
		if(!book[s[0]-'A'])cnt++;
		book[s[0]-'A']++;
	}
	if(cnt==3)printf("Three\n");
	else printf("Four\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
C = list(input())

l = 0
r = N-1
ans = 0

while l < r:
    while C[l] == 'R' and l + 1 < N:
        l += 1
    while C[r] == 'W' and r + 1 >= 0:
        r -= 1
    if l < r:
        ans += 1
        l += 1
        r -= 1

print(ans)

Measured memory_bytes: 10776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll X;
    cin >> X;
    ll now = 100, ans = 0;
    while (now < X)
    {
        now *= 1.01;
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3608
def solve(s: str) -> int:
    ans = 0
    s_cnt = 0
    for c in s:
        if c == 'S':
            s_cnt += 1
        else:
            if s_cnt > 0:
                s_cnt -= 1
            else:
                ans += 1
    return ans + s_cnt

print(solve(input().strip()))

Measured memory_bytes: 3500
n = int(input())
ans = 0
for i in range(1,n+1):
    cnt = 0
    if i%2==0:
        continue
    for j in range(1,int(i**(1/2))+1):
        if i%j == 0:
            if j == i//j:
                cnt += 1
            else:
                cnt += 2
    if cnt == 8:
        ans += 1
print(ans)

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S,T;
  cin >> S;
  cin >> T;
  int ans = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] != T[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3924
#include <iostream>

using namespace std;

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

    return 0;
}



Measured memory_bytes: 3116
s = list(input())
s_set = set(s)

s_unique = list(s_set)
s_unique.sort()

s_unique_len = len(s_unique)

if s_unique_len == 4:
  print('Yes')
elif s_unique_len == 2:
  if s_unique[0] == 'E' and s_unique[1] == 'W':
    print('Yes')
  elif s_unique[0] == 'N' and s_unique[1] == 'S':
    print('Yes')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <functional>
typedef long long ll;
using namespace std;

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

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  auto is_odd=[](Int z){return z&1;};

  Int k,x,y;
  cin>>k>>x>>y;

  Int fx=1,fy=1;
  if(x<0) x*=-1,fx=-1;
  if(y<0) y*=-1,fy=-1;
  auto print=[&](Int p,Int q){cout<<(p*fx)<<" "<<(q*fy)<<endl;};

  if(!is_odd(k)&&is_odd(x+y)) drop(-1);

  if(x+y==k){
    cout<<1<<endl;
    print(x,y);
    return 0;
  }

  if(x+y<k&&is_odd(x+y)){
    cout<<3<<endl;
    Int diff=(3*k-(x+y))/2;
    assert(k<diff && diff<k*2);
    print(-k,0);
    Int val=diff-k;
    print(-k+(k-val),-val);
    print(x,y);
  }else{
    Int n=(x+y+k-1)/k;
    if(x+y<k) n=2;
    if(is_odd((n*k)-(x+y))) n++;
    Int diff=(n*k-(x+y))/2;

    cout<<n<<endl;
    Int px=0,py=0;
    for(Int i=0;i<n;i++){
      if(diff>0){
        if(x-px<y-py){
          Int dx=min(diff,k);
          Int dy=k-dx;
          diff-=dx;
          px-=dx;
          py+=dy;
        }else{
          Int dy=min(diff,k);
          Int dx=k-dy;
          diff-=dy;
          px+=dx;
          py-=dy;
        }
        print(px,py);
      }else{
        Int dx=min(x-px,k);
        Int dy=k-dx;
        px+=dx;
        py+=dy;
        print(px,py);
      }
    }
    //assert(x==px&&y==py);
  }
  return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    std::cin >> s;
    if(s=="AAA"||s=="BBB"){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
static const ll Z = 1 << 21;
#define rep(i,s,n)for(ll i = s;i<n;i++)
char s[Z];
char t[Z];

int main() {
	cin >> s;
	char* S = &s[0];

	char T[11] = { '\0' };
	int p = 0;

	while (*S) {
		switch (*S) {
		case '0': T[p++] = '0'; break;
		case '1': T[p++] = '1'; break;
		case 'B':
			p = (p == 0) ? p : p - 1;
			T[p] = '\0';
			break;
		}

		S++;
	}
	cout << T << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

int main()
{
    ll N, M;
    cin >> N >> M;
    mat V(M);
    REP(i,0,N) {
        ll a, b;
        cin >> a >> b;
        if(a <= M) V[M-a].pb(b);
    }

    priority_queue<ll> Q;
    ll sum = 0;
    for(ll i=M-1; i>=0; --i) {
        FORR(b,V[i]) Q.push(b);
        if(!Q.empty()) {
            sum += Q.top();
            Q.pop();
        }
    }    

    PR(sum);

    return 0;
}

/*



*/

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

vector<int> D,F;

int dfs(int p,int num,int H,int W,vector<vector<int>>& M,vector<vector<int>>& D){
	int u=p%W,v=p/W;
	D[v][u] = num;
	if(u>0 && M[v][u-1] && D[v][u-1]==-1){
		dfs(u-1+v*W,num,H,W,M,D);
	}
	if(u<W-1 && M[v][u+1] && D[v][u+1]==-1){
		dfs(u+1+v*W,num,H,W,M,D);
	}
	if(v>0 && M[v-1][u] && D[v-1][u]==-1){
		dfs(u+(v-1)*W,num,H,W,M,D);
	}
	if(v<H-1 && M[v+1][u] && D[v+1][u]==-1){
		dfs(u+(v+1)*W,num,H,W,M,D);
	}

	if(u>0 && v>0 && M[v-1][u-1] && D[v-1][u-1]==-1){
		dfs(u-1+(v-1)*W,num,H,W,M,D);
	}
	if(u<W-1 && v<H-1 && M[v+1][u+1] && D[v+1][u+1]==-1){
		dfs(u+1+(v+1)*W,num,H,W,M,D);
	}
	if(v>0 && u<W-1 && M[v-1][u+1] && D[v-1][u+1]==-1){
		dfs(u+1+(v-1)*W,num,H,W,M,D);
	}
	if(v<H-1 && u>0 && M[v+1][u-1] && D[v+1][u-1]==-1){
		dfs(u-1+(v+1)*W,num,H,W,M,D);
	}
	return 0;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	while(true){
		int W=in(),H=in();
		if(!W && !H) break;

		vector<vector<int>> M(H,vector<int>(W,0)),D(H,vector<int>(W,-1));
		REP(i,H){
			REP(j,W){
				M[i][j]=in();
			}
		}

		int num=0;
		REP(i,H){
			REP(j,W){
				if(M[i][j] && D[i][j]==-1){
					dfs(j+i*W,++num,H,W,M,D);
				}
			}
		}
		out(num);
	}

	return 0;
}



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

typedef long long ll;
const ll mod = 1e9 + 7;

ll po[200005] = {};
ll inv[200005] = {};

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

ll nCm(ll n, ll m, ll p = 1e9+7){
    ll ret = 1;
    ret *= po[n];
    ret %= p;
    ret *= inv[n-m];
    ret %= p;
    ret *= inv[m];
    ret %= p;
    return ret;
}

int main(){
    po[0] = 1;
    for(int i = 1; i < 200005; i++){
        po[i] = po[i-1] * i;
        po[i] %= mod;
    }
    inv[0] = 1;
    for(int i = 1; i < 200005; i++){
        inv[i] = modpow(po[i], mod-2, mod);
    }

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    ll ans = 0;
    int hei = h-1-a;
    
    for(int wid = b; wid < w; wid++){
        ans += nCm(wid+hei, wid) * nCm(a-1+w-1-wid, a-1);
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
# string
# a, b, c = input().split()
# str_list = list(input().split())

# number
# a, b, c = map(int, input().split())
# num_list = list(map(int, input().split()))

# lows
# str_list = [input() for _ in range(n)]

# many inputs
# num_list = []
# for i in range(n): num_list.append(list(map(int, input().split())))

from collections import deque

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())

ch -= 1
cw -= 1
dh -= 1
dw -= 1

dx = [1,0,-1,0]
dy = [0,1,0,-1]

s = []
for i in range(h): s.append(list(input()))

inf = int(1e9)
dist = [[inf for j in range(w)] for i in range(h)]
dist[ch][cw] = 0

q = deque()
q.append([ch,cw])

while len(q) != 0:
    i, j = map(int, q.popleft())
    d = dist[i][j]
    
    for v in range(4):
        ni = i + dx[v]
        nj = j + dy[v]

        if ni < 0 or ni >= h or nj < 0 or nj >= w:
            continue
        
        if s[ni][nj] == "#":
            continue

        if dist[ni][nj] <= d:
            continue
        
        dist[ni][nj] = d
        q.appendleft([ni, nj])
    
    for ei in range(-2, 3):
        for ej in range(-2, 3):
            ni = i + ei
            nj = j + ej

            if ni < 0 or ni >= h or nj < 0 or nj >= w:
                continue
        
            if s[ni][nj] == "#":
                continue

            if dist[ni][nj] <= d+1:
                continue

            dist[ni][nj] = d+1
            q.append([ni, nj])

ans = dist[dh][dw]
if ans == inf:
    ans = -1
print(ans)


Measured memory_bytes: 142048
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

bool initArray(int **array, int n);
void insertionSort(int *array, int n);
void printArray(int *array, int n);

bool initArray(int **array, int n) {
    if((*array = malloc(n * sizeof(int))) == NULL) {
        return false;
    }

    return true;
}

void insertionSort(int *array, int n) {
    for(int i = 1; i < n; i++) {
        printArray(array, n);
        int temp = array[i];
        int j = i - 1;
        for(; j >= 0 && array[j] > temp; j--) {
            array[j + 1] = array[j];
        }
        array[j + 1] = temp;
    }
    
    printArray(array, n);
}

void printArray(int *array, int n) {
    for(int i = 0; i < n;) {
        printf("%d", array[i]);
        i++;
        if(i < n) {
            printf(" ");
        }
    }
    printf("\n");
}

int main(void) {
    int *array;
    int n;

    scanf("%d", &n);
    
    initArray(&array, n);

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

    insertionSort(array, n);

    free(array);
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, D;
    cin >> N >> D;
    long long x[N][D];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++) cin >> x[i][j];
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            double d = 0;
            for(int k = 0; k < D; k++){
                d += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            int t = sqrt(d);
            if(sqrt(d) == t) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
li=list(map(int,input().split()))
ans=[]
a=li[0]*li[2]
b=li[0]*li[3]
c=li[1]*li[2]
d=li[1]*li[3]
ans.append(a)
ans.append(b)
ans.append(c)
ans.append(d)

print(max(ans))


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

#define X first
#define Y second

using namespace std;
#define INFLL 1223372036854775808
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< int > vi;
typedef vector< ll > vl;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
#define f(i,a,b) for(int i=a;i<b;i++)
const int MOD = 1e9+7;

ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD)a%=MOD;b>>=1;}return ret;}
ll inv(ll x) {return power(x,MOD-2);}

const int N = 1e5+5;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s,s1;int k;
	cin>>s>>k;
	map<char,set<int> >mp;
	map<char,set<int> >::iterator it;
	set<int>st;
	set<int>::iterator it1;
	set<string>::iterator it2;
	set<string>st1;
	for(int i=0;i<s.length();i++)
    {
        mp[s[i]].insert(i);
    }
    int ctr=1,cnt=0;
    for(it=mp.begin();it!=mp.end();it++)
    {
        st=it->second;

        for(it1=st.begin();it1!=st.end();it1++)
        {

                s1="";
            int x=*it1,i=x;
                ctr++;

            while(i<s.length() && i<=x+5)
             {
                 s1+=s[i];
                 st1.insert(s1);
                 i++;
             }


        }


    }
    for(it2=st1.begin();it2!=st1.end();it2++)
    {
        cnt++;
        if(cnt==k)
        {
            cout<<*it2;
            break;
        }
    }
}


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

int main(void){

    int i,j;
    int n;
    char a[3][3];

    for(i=0;i<3;i++){
        scanf("%s",&a[i][0]);
    }

    printf("%c%c%c\n",a[0][0],a[1][1],a[2][2]);     
}

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

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> h(n);
    std::vector<int> dp(n+2,2000000000);     //dp[i] : 足場iに行くための最小コスト

    for(int i=0;i<n;i++)std::cin>>h[i];
    dp[0] = 0;
    for(int i=0;i<n;i++){
        dp[i+1] = std::min(dp[i] + std::abs(h[i] - h[i+1]),dp[i+1]);
        dp[i+2] = std::min(dp[i] + std::abs(h[i] - h[i+2]),dp[i+2]);
    }
    std::cout<<dp[n-1]<<std::endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
   
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>

const int MOD = 1e9+7;
const int N = 1e5+10;

vi g[N];
int n;
int u,v;
int dp[N][2];

void dfs(int node,int par = -1)
{
    for(auto x : g[node])
        if(x != par) dfs(x,node);
    
    dp[node][0] = dp[node][1] = 1;
        
    for(auto x : g[node])
        if(x != par) dp[node][0] = (dp[node][0]*(dp[x][0] + dp[x][1]))%MOD;
    
    for(auto x : g[node])
        if(x != par) dp[node][1] = (dp[node][1]*( dp[x][0]))%MOD;
}

void solve()
{
    cin >> n;
    
    f(i,n-1)
    {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    
    dfs(1);
    
    cout << (dp[1][0] + dp[1][1])%MOD;    
}

signed main()
{
    fast;    
    solve();
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n, m, d; cin >> n >> m >> d;
    ld res=0.0;
    if(!d)  res = (m-1.0)/n; 
    else    res = (m-1)*2.0*(n-d)/(n*n);

    
    cout << fixed << setprecision(20) << res << endl;
    
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    ll ans = t[0];
    
    reps(i, 1, n) {
        ans = lcm(ans, t[i]);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256